-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRsg2ImageRoutes.php
More file actions
261 lines (212 loc) · 7.13 KB
/
Rsg2ImageRoutes.php
File metadata and controls
261 lines (212 loc) · 7.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<?php
/**
* Class Rsg2ImageRoutes
* Contains functions to create jroute(s) url paths to different image views
* The functions return links to be used in Jroute() to image views inside galleries
* Example: image from random image view need <A> link to parent gallery
* @copyright (C) 2015 RSGallery2 Team
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @version 4.0.6
*/
class Rsg2ImageRoutes
{
/**
* @var int|null $RSG2MenuId
*/
public $RSG2MenuId = Null;
/**
* Get RSGallery2 Itemid from first component menu item for use in links
* Use PageIdx if the needed menu item is not the first one
* @param int $PageIdx Wanted to nth-1 occurrence of gallery view in joomla menu
* @return int|null
*/
public function getRsg2MenuId ($PageIdx=0)
{
$this->RSG2MenuId = Null;
$database = JFactory::getDbo();
$query = $database->getQuery(true);
$query->select('id')
->from('#__menu')
->where('published = 1')
//->where($db->quoteName('published') . ' LIKE '. $db->quote('\'%1%\''));
->where("link like 'index.php?option=com_rsgallery2%'")
->order('link');
$database->setQuery($query);
try {
$RSG2ItemIdObj = $database->loadObjectList();
if (count($RSG2ItemIdObj) > $PageIdx) {
$this->RSG2MenuId = $RSG2ItemIdObj[$PageIdx]->id;
}
}
catch (Exception $e)
{
// ToDo: enque message
// echo 'Exception abgefangen: ', $e->getMessage(), "\n";
}
return $this->RSG2MenuId;
}
/* ToDo: check following to improve above */
private function Rsg2MenuIdTmp ()
{
//------------------------------------------------------------------------
$db = JFactory::getDBO();
// for sef ?
$lang =& JFactory::getLanguage()->getTag();
$uri = 'index.php?option=com_search&view=search';
$db->setQuery('SELECT id FROM #__menu WHERE link LIKE ' . $db->Quote($uri . '%')
. ' AND language=' . $db->Quote($lang) . ' LIMIT 1');
$itemId = ($db->getErrorNum()) ? 0 : intval($db->loadResult());
//------------------------------------------------------------------------
$db = JFactory::getDBO();
$defaultRedirect = 'index.php?option=com_myapp&view=cpanel';
$db->setQuery('SELECT `id` FROM #__menu WHERE `link` LIKE '
. $db->Quote($defaultRedirect) . ' LIMIT 1');
$itemId = ($db->getErrorNum()) ? 0 : intval($db->loadResult());
if ($itemId) {
$rpath = JRequest::getString('return',
base64_encode(JRoute::_('index.php?Itemid=' . $itemId)));
} else {
$rpath = JRequest::getString('return',
base64_encode(JRoute::_('index.php?option=com_myapp&view=cpanel')));
}
}
/**
* Link to parent gallery view with image set including given image
* @param int $GalleryId parent gallery id of image
* @param int $ImagePosition Position of image when available
* images are displayed. Example: on first page are 9
* pictures displayed ($ImagePosition 0..8). For the
* first image on page two the $ImagePosition is 9.
* Use sql image order -1 -> $image['ordering'] -1
* $ImagePosition != $ImageId as some images may be
* deleted already
* @return string link for Jroute
*/
public function Link2ParentGallery ($GalleryId, $ImagePosition)
{
$url = '';
// Joomla gallery menu part
if ($this->RSG2MenuId == Null)
{
$this->getRsg2MenuId ();
}
$url = 'index.php?option=com_rsgallery2'
. '&Itemid='.$this->RSG2MenuId
. '&catid=' . $GalleryId
. '/itemPage/'.$ImagePosition
;
return $url;
}
/**
* Link to gallery single image view
* @param int $GalleryId parent gallery id of image
* @param int $ImageId image id
* @return string link for Jroute
*/
public function Link2GallerySingleImageView ($GalleryId, $ImageId)
{
$url = '';
// Joomla gallery menu part
if ($this->RSG2MenuId == Null)
{
$this->getRsg2MenuId ();
}
$url = 'index.php?option=com_rsgallery2'
. '&Itemid='.$this->RSG2MenuId
. '&catid=' . $GalleryId
. '&id=' . $ImageId
;
return $url;
}
/**
* Link to gallery single image view
* @param int $GalleryId parent gallery id of image
* @return string link for Jroute
*/
public function Link2GallerySlideshowView ($GalleryId)
{
$url = '';
// Joomla gallery menu part
if ($this->RSG2MenuId == Null)
{
$this->getRsg2MenuId ();
}
$url = 'index.php?option=com_rsgallery2'
. '&Itemid='.$this->RSG2MenuId
. '&catid=' . $GalleryId
. '/asSlideshow'
;
return $url;
}
/**
* Link to gallery single image view
* @param int $GalleryId parent gallery id of image
* @param int $ImageId image id
* @return string link for Jroute
*/
public function Link2ImageOriginalSize ($GalleryId, $imageName)
{
$url = '';
// Joomla gallery menu part
if ($this->RSG2MenuId == Null)
{
$this->getRsg2MenuId ();
}
// echo ($imageName);
//http://localhost/joomla3x/images/rsgallery/original/DSC_0849.jpg
//localhost/joomla3x/images/rsgallery//DSC_0849.jpg.jpg
$url = 'images/rsgallery/original/'
. $imageName
;
return $url;
}
/**
* Link to gallery single image view
* @param int $GalleryId parent gallery id of image
* @param int $ImageId image id
* @return string link for Jroute
*/
public function Link2ImageDisplaySize ($GalleryId, $imageName)
{
$url = '';
// Joomla gallery menu part
if ($this->RSG2MenuId == Null)
{
$this->getRsg2MenuId ();
}
//http://localhost/joomla3x/images/rsgallery/display/DSC_0849.jpg.jpg
$url = 'images/rsgallery/display/'
. $imageName
. ".jpg"
;
return $url;
}
/**
* Link to gallery single image view
* @param int $GalleryId parent gallery id of image
* @param int $ImageId image id
* @return string link for Jroute
*/
public function Link2ImageThumbSize ($imageName)
{
$url = '';
// Joomla gallery menu part
if ($this->RSG2MenuId == Null)
{
$this->getRsg2MenuId ();
}
//http://localhost/joomla3x/images/rsgallery/thumb/DSC_0849.jpg.jpg
$url = 'images/rsgallery/thumb/'
. $imageName
. ".jpg"
;
return $url;
}
public function __toString()
{
$OutTxt = 'Rsg2ImageRoutes::$RSG2MenuId= "';
$OutTxt .= ($this->RSG2MenuId === null) ? 'null' : $this->RSG2MenuId;
$OutTxt .= '"';
return $OutTxt;
}
}