Mercurial > hg > mgallery
annotate mgallery.php @ 4:014e1d6991a3
Oops, fix the last breadcrumb.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 15 May 2015 16:29:38 +0300 |
parents | c85f630a4198 |
children | 1bf73b49fc91 |
rev | line source |
---|---|
0 | 1 <?php |
2 // | |
3 // Yet Another Image Gallery | |
4 // (C) Copyright 2015 Tecnic Software productions (TNSP) | |
5 // | |
6 require "msitegen.inc.php"; | |
7 require "mgallery.inc.php"; | |
8 | |
9 | |
10 // | |
11 // Various utility functions | |
12 // | |
13 function mgGetImageURL() | |
14 { | |
15 global $galImageURL, $galPath; | |
16 return $galImageURL.$galPath."/".implode("", func_get_args()); | |
17 } | |
18 | |
19 | |
20 function mgGetURL($path, $image, $entities = TRUE) | |
21 { | |
22 global $galBaseURL, $galCleanURLS; | |
23 $amp = $entities ? "&" : "&"; | |
24 | |
25 if ($galCleanURLS) | |
26 { | |
27 return $galBaseURL.$path."/".($image !== FALSE ? $image : ""); | |
28 } | |
29 else | |
30 { | |
31 return | |
32 $galBaseURL.mgGetSetting("mgallery_php")."?path=". | |
33 $path.($image !== FALSE ? $amp."image=".$image : ""); | |
34 } | |
35 } | |
36 | |
37 | |
38 function mgGetNaviActive(&$galIndex, $index, $delta, &$res, &$url, $entities) | |
39 { | |
40 global $galPath; | |
41 $res = $index + $delta; | |
42 if ($res >= 0 && $res <= sizeof($galIndex) - 1) | |
43 { | |
44 $url = mgGetURL($galPath, $galIndex[$res], $entities); | |
45 return TRUE; | |
46 } | |
47 else | |
48 return FALSE; | |
49 } | |
50 | |
51 | |
52 function mgGetNaviControlImage(&$galIndex, $index, $class, $url) | |
53 { | |
54 global $galTNPath; | |
55 | |
56 $img = "<div class=\"imageCtrl ".$class."\">"; | |
57 | |
58 if ($url !== FALSE) | |
59 { | |
60 $img .= | |
61 "<a href=\"".$url."\"><img src=\"". | |
62 mgGetImageURL($galTNPath, $galIndex[$index]). | |
63 "\" alt=\"".$galIndex[$index]."\" /></a>"; | |
64 } | |
65 | |
66 return $img."</div>\n"; | |
67 } | |
68 | |
69 | |
70 function mgGetNaviControlImageBox(&$galIndex, $index, $class, $delta) | |
71 { | |
72 if (!mgGetNaviActive($galIndex, $index, $delta, $res, $url, TRUE)) | |
73 $url = FALSE; | |
74 | |
75 return mgGetNaviControlImage($galIndex, $res, $class, $url); | |
76 } | |
77 | |
78 | |
79 function mgGetControl($str, $class, &$galIndex, $index, $delta, $naviFlags) | |
80 { | |
81 $active = mgGetNaviActive($galIndex, $index, $delta, $res, $url, TRUE); | |
82 if ($active && ($naviFlags & GNAV_IMG)) | |
83 $img = mgGetNaviControlImage($galIndex, $res, $class, $url); | |
84 else | |
85 $img = ""; | |
86 | |
87 if ($naviFlags & GNAV_TEXT) | |
88 $str = "<span class=\"naviControl ".$class."\">[".($active ? "<a href=\"".$url."\">".$str."</a>" : $str)."]</span>"; | |
89 else | |
90 $str = ""; | |
91 | |
92 if ($delta < 0) | |
93 return $img.$str; | |
94 else | |
95 return $str.$img; | |
96 } | |
97 | |
98 | |
99 function mgGetNaviControls(&$galIndex, $index, $naviFlags) | |
100 { | |
101 global $galPath; | |
102 | |
103 return | |
104 "<div class=\"naviControls\">". | |
105 mgGetControl("<<", "prev", $galIndex, $index, -1, $naviFlags). | |
106 "[<a href=\"".mgGetURL($galPath, FALSE)."\">^^</a>]". | |
107 mgGetControl(">>", "next", $galIndex, $index, 1, $naviFlags). | |
108 "</div>\n"; | |
109 } | |
110 | |
111 | |
112 function mgPrintTable($class, &$galEntries, &$galIndex, $start, $limit) | |
113 { | |
114 global $galAlbumIcon, $galPath, $galTNPath; | |
115 | |
116 $galCount = count($galIndex); | |
117 if ($start >= $galCount) | |
118 return $start; | |
119 | |
120 $end = ($limit === FALSE) ? $galCount : $start + $limit; | |
121 if ($end > $galCount) $end = $galCount; | |
122 | |
123 $rowLimit = mgGetSetting("album_row_limit"); | |
124 $n = 0; | |
125 | |
126 echo "<table class=\"".$class."\">\n"; | |
127 for ($index = $start; $index < $end; $index++) | |
128 { | |
129 $filename = &$galIndex[$index]; | |
130 $data = &$galEntries[$filename]; | |
131 | |
132 if ($n == 0) echo " <tr>\n"; | |
133 | |
134 echo | |
135 " <td id=\"cd".$data["base"]."\">\n"; | |
136 | |
137 if ($data["type"] == 0) | |
138 { | |
139 echo | |
140 "<div class=\"imageBox\"><a href=\"".mgGetURL($galPath, $filename)."\">". | |
141 "<img src=\"".mgGetImageURL($galTNPath, $filename)."\" alt=\"". | |
142 chentities($filename)."\"></a>". | |
143 "</div>". | |
144 mgGetArr($data, "caption", "<div class=\"imageCaption\">%1</div>", "", "chentities"); | |
145 /* | |
146 if ($mode == "") | |
147 { | |
148 echo | |
149 " <select class=\"dropdown\" id=\"dd".$data["base"]."\" name=\"dd".$data["base"]. | |
150 "\" onchange=\"galPhotoDataChanged('".$data["base"]."');\">\n"; | |
151 | |
152 foreach ($picChoices as $name => $value) | |
153 { | |
154 echo " <option value=\"$value\"".($value == $data["id"] ? " selected=\"selected\"" : "").">".chentities($name)."</option>\n"; | |
155 } | |
156 echo | |
157 " </select>\n"; | |
158 } | |
159 */ | |
160 } | |
161 else | |
162 { | |
163 echo | |
164 " <a href=\"".mgGetURL(mgCleanPath(TRUE, $galPath, $data["base"]), FALSE)."\">". | |
165 "<img class=\"albumIcon\" src=\"".$galAlbumIcon."\" alt=\"".chentities($data["caption"])."\" />\n". | |
166 "<div class=\"albumTitle\">".chentities($data["caption"])."</div></a>\n"; | |
167 } | |
168 | |
169 echo | |
170 " </td>\n"; | |
171 | |
172 if (++$n >= $rowLimit) | |
173 { | |
174 echo " </tr>\n"; | |
175 $n = 0; | |
176 } | |
177 } | |
178 if ($n > 0) | |
179 { | |
180 while ($n++ < $rowLimit) | |
181 echo " <td></td>\n"; | |
182 echo " </tr>\n"; | |
183 } | |
184 echo "</table>\n"; | |
185 return $index; | |
186 } | |
187 | |
188 | |
189 function mgTimeStr($str) | |
190 { | |
191 $tmp = date_create_from_format("Y:m:d H:i:s", $str); | |
192 return date_format($tmp, "d M Y (H:i)"); | |
193 } | |
194 | |
195 | |
196 function mgPrintPageInfoFooter() | |
197 { | |
198 if (($str = mgGetSetting("page_info")) !== FALSE) | |
199 echo "<div class=\"pageInfoFooter\">".$str."</div>"; | |
200 } | |
201 | |
202 | |
203 function mgPrintBreadCrumbs($galData) | |
204 { | |
205 $res = array(); | |
206 if ($galData["caption"]) | |
4
014e1d6991a3
Oops, fix the last breadcrumb.
Matti Hamalainen <ccr@tnsp.org>
parents:
3
diff
changeset
|
207 $res[] = "<a class=\"naviBreadCrumbCurr\" href=\"".mgGetURL($galData["path"], FALSE)."\">".chentities($galData["caption"])."</a>"; |
0 | 208 |
209 $tmp = $galData; | |
210 while (isset($tmp["parent"])) | |
211 { | |
212 $pdata = $tmp["parent"]; | |
3
c85f630a4198
Improve bread crumb navigation by making the current album a link as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
213 $res[] = "<a class=\"naviBreadCrumbItem\" href=\"".mgGetURL($pdata["path"], FALSE)."\">".chentities($pdata["caption"])."</a>"; |
0 | 214 $tmp = $tmp["parent"]; |
215 } | |
216 | |
217 if (count($res) > 1) | |
218 { | |
219 echo | |
220 "<div class=\"naviBreadCrumbs\">". | |
221 implode("<span class=\"naviBreadCrumbSep\"></span>", array_reverse($res)). | |
222 "</div>\n"; | |
223 } | |
224 } | |
225 | |
226 | |
227 // | |
228 // Get gallery settings | |
229 // | |
230 mgReadSettings(); | |
231 | |
232 $pageCSS = mgGetSetting("css"); | |
233 $pageCSSSelect = mgGetSetting("css_select"); | |
234 $galBasePath = mgGetSetting("base_path"); | |
235 $galBaseURL = mgGetSetting("base_url"); | |
236 $galImageURL = mgGetSetting("image_url", mgGetSetting("base_url")); | |
237 | |
238 $galAlbumIcon = mgGetSetting("album_icon"); | |
239 $galCleanURLS = mgGetSetting("clean_urls"); | |
240 $galTNPath = mgGetSetting("tn_path"); | |
241 $galMedSuffix = mgGetSetting("med_suffix"); | |
242 $galTitlePrefix = mgGetSetting("title_prefix"); | |
243 $galTitleSep = mgGetSetting("title_sep"); | |
244 | |
245 $galMode = stGetRequestItem("mode", "view", TRUE); | |
246 $galPath = stGetRequestItem("path", ".", TRUE); | |
247 $galPageIndex = intval(stGetRequestItem("index", 0, TRUE)); | |
248 $galImage = stGetRequestItem("image", FALSE, TRUE); | |
249 | |
250 if (is_string($galImage)) | |
251 $galImage = basename($galImage); | |
252 | |
253 | |
254 // | |
255 // Attempt to read the data cache file | |
256 // | |
257 $filename = mgGetPath(mgCleanPath(TRUE, $galBasePath, $galPath), "cache_file"); | |
258 $filename2 = mgGetPath(mgCleanPath(FALSE, $galBasePath, $galPath), "cache_file"); | |
259 if ($filename == $filename2 && file_exists($filename) && ($fp = @fopen($filename, "rb")) !== FALSE) | |
260 { | |
261 if (flock($fp, LOCK_SH)) | |
262 { | |
263 require($filename); | |
264 flock($fp, LOCK_UN); | |
265 } | |
266 fclose($fp); | |
267 } | |
268 | |
269 | |
270 // If no data available, show an error page | |
271 if (!isset($galData) || !isset($galEntries) || | |
272 !isset($galAlbumsIndex) || !isset($galImagesIndex)) | |
273 { | |
274 cmPrintPageHeader(mgGetVal(array("title_prefix", "title_sep"), "%1%2")."ERROR!"); | |
275 | |
276 echo | |
277 "<h1>Gallery error</h1>\n". | |
278 "<p>Gallery path <b>".chentities($galPath)."</b> does not exist or is invalid.</p>\n"; | |
279 | |
280 //echo "<p>".$filename."</p><p>".$filename2."</p>"; | |
281 | |
282 mgPrintPageInfoFooter(); | |
283 cmPrintPageFooter(TRUE); | |
284 exit; | |
285 } | |
286 | |
287 | |
288 // | |
289 // Print page header, etc. | |
290 // | |
291 if (($index = array_search($galImage, $galImagesIndex)) !== FALSE) | |
292 { | |
293 // | |
294 // Single image mode | |
295 // | |
296 $naviFlags = mgGetSetting("image_navigation"); | |
297 $data = $galEntries[$galImage]; | |
298 | |
299 $pageTitle = $galTitlePrefix.$galTitleSep.$galData["caption"]." - ".$galImage; | |
300 cmPrintPageHeader($pageTitle); | |
301 echo "<h1>".chentities($pageTitle)."</h1>\n"; | |
302 | |
303 if ($naviFlags & GNAV_BREADCRUMBS) | |
304 mgPrintBreadCrumbs($galData); | |
305 | |
306 if ($naviFlags & GNAV_TOP) | |
307 echo mgGetNaviControls($galImagesIndex, $index, $naviFlags); | |
308 | |
309 echo | |
310 "<div class=\"imageCBox\">\n". | |
311 mgGetNaviControlImageBox($galImagesIndex, $index, "prev", -1). | |
312 "<div class=\"imageBox\">\n". | |
313 "<a target=\"_blank\" href=\"".$galImageURL.$galPath."/".$galImage."\">". | |
314 "<img src=\"".mgGetImageURL($galTNPath, $data["base"].$galMedSuffix.$data["ext"])."\" alt=\"". | |
315 chentities($data["base"].$galMedSuffix.$data["ext"])."\"></a>\n". | |
316 "</div>\n". | |
317 mgGetNaviControlImageBox($galImagesIndex, $index, "next", 1). | |
318 "</div>\n". | |
319 "<div class=\"imageCaption\">".mgGetArr($data, "caption", "%1", "")."</div>\n"; | |
320 | |
321 $list = array( | |
322 mgGetArr($data, array("width", "height"), "<span class=\"infoDimensions\"><b>%1</b> x <b>%2</b> px</span>", NULL), | |
323 mgGetArr($data, "model", "<span class=\"infoModel\"><b>%1</b></span>", NULL), | |
324 mgGetArr($data, "fnumber", "<span class=\"infoFNumber\"><b>f/%1</b></span>", NULL), | |
325 mgGetArr($data, "exposure", "<span class=\"infoExposure\"><b>%1</b> sec</span>", NULL, NULL), | |
326 mgGetArr($data, "iso", "<span class=\"infoISO\">ISO <b>%1</b></span>", NULL), | |
327 ); | |
328 | |
329 echo | |
330 "<div class=\"infoBox\">\n". | |
331 mgGetArr($data, "datetime", "<span class=\"infoDateTime\">%1</span>", "", "mgTimeStr"). | |
332 implode(", ", array_filter($list, function($a) { return $a !== NULL; })). | |
333 "</div>\n"; | |
334 | |
335 if ($naviFlags & GNAV_BOTTOM) | |
336 echo mgGetNaviControls($galImagesIndex, $index, $naviFlags); | |
337 | |
338 // Javascript navigation | |
339 if ($naviFlags & GNAV_JAVASCRIPT) | |
340 { | |
341 $prevActive = mgGetNaviActive($galImagesIndex, $index, -1, $res, $prevURL, FALSE); | |
342 $nextActive = mgGetNaviActive($galImagesIndex, $index, 1, $res, $nextURL, FALSE); | |
343 echo | |
344 "<script type=\"text/javascript\">\n". | |
345 "var mgalPrevURL = \"".($prevActive ? $prevURL : "")."\";\n". | |
346 "var mgalNextURL = \"".($nextActive ? $nextURL : "")."\";\n". | |
347 "\n"; | |
348 ?> | |
349 function mgalNavigateTo(url) | |
350 { | |
351 if (url != "") | |
352 window.location = url; | |
353 } | |
354 | |
355 | |
356 function mgalProcessKeyPress(ev) | |
357 { | |
358 ev = ev || window.event; | |
359 var key = ev.keyCode ? ev.keyCode : ev.which; | |
360 switch (key) | |
361 { | |
362 case 37: | |
363 case 65: | |
364 // left | |
365 mgalNavigateTo(mgalPrevURL); | |
366 break; | |
367 | |
368 case 39: | |
369 case 68: | |
370 // right | |
371 mgalNavigateTo(mgalNextURL); | |
372 break; | |
373 } | |
374 } | |
375 | |
376 document.onkeypress = mgalProcessKeyPress; | |
377 <? | |
378 echo | |
379 "</script>\n"; | |
380 } | |
381 } | |
382 else | |
383 { | |
384 // | |
385 // Gallery mode | |
386 // | |
387 // - needs sub-modes / handling of order shit | |
388 // - Javascript stuff for picture data updates | |
389 // | |
390 $pageTitle = $galTitlePrefix.mgGetArr($galData, "caption", " - %1", "", "chentities"); | |
391 cmPrintPageHeader($pageTitle); | |
392 echo "<h1>".$pageTitle."</h1>\n"; | |
393 | |
394 $naviFlags = mgGetSetting("album_navigation"); | |
395 if ($naviFlags & GNAV_BREADCRUMBS) | |
396 mgPrintBreadCrumbs($galData); | |
397 | |
398 if (isset($galData["header"]) && strlen($galData["header"]) > 0) | |
399 echo "<div class=\"albumHeaderText\">".$galData["header"]."</div>\n"; | |
400 | |
401 mgPrintTable("albumTable", $galEntries, $galAlbumsIndex, 0, FALSE); | |
402 mgPrintTable("imageTable", $galEntries, $galImagesIndex, 0, FALSE); | |
403 } | |
404 | |
405 mgPrintPageInfoFooter(); | |
406 cmPrintPageFooter(TRUE); | |
407 ?> |