comparison mgallery.php @ 0:ac688606ec4b

Initial import of code.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 13 May 2015 07:27:40 +0300
parents
children c85f630a4198
comparison
equal deleted inserted replaced
-1:000000000000 0:ac688606ec4b
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 ? "&amp;" : "&";
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("&lt;&lt;", "prev", $galIndex, $index, -1, $naviFlags).
106 "[<a href=\"".mgGetURL($galPath, FALSE)."\">^^</a>]".
107 mgGetControl("&gt;&gt;", "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"])
207 $res[] = chentities($galData["caption"]);
208
209 $tmp = $galData;
210 while (isset($tmp["parent"]))
211 {
212 $pdata = $tmp["parent"];
213 $res[] = "<a href=\"".mgGetURL($pdata["path"], FALSE)."\">".chentities($pdata["caption"])."</a>";
214 $tmp = $tmp["parent"];
215 }
216
217 if (count($res) > 1)
218 {
219 $res = array_map(function ($a) { return "<span class=\"naviBreadCrumbItem\">".$a."</span>"; }, $res);
220 echo
221 "<div class=\"naviBreadCrumbs\">".
222 implode("<span class=\"naviBreadCrumbSep\"></span>", array_reverse($res)).
223 "</div>\n";
224 }
225 }
226
227
228 //
229 // Get gallery settings
230 //
231 mgReadSettings();
232
233 $pageCSS = mgGetSetting("css");
234 $pageCSSSelect = mgGetSetting("css_select");
235 $galBasePath = mgGetSetting("base_path");
236 $galBaseURL = mgGetSetting("base_url");
237 $galImageURL = mgGetSetting("image_url", mgGetSetting("base_url"));
238
239 $galAlbumIcon = mgGetSetting("album_icon");
240 $galCleanURLS = mgGetSetting("clean_urls");
241 $galTNPath = mgGetSetting("tn_path");
242 $galMedSuffix = mgGetSetting("med_suffix");
243 $galTitlePrefix = mgGetSetting("title_prefix");
244 $galTitleSep = mgGetSetting("title_sep");
245
246 $galMode = stGetRequestItem("mode", "view", TRUE);
247 $galPath = stGetRequestItem("path", ".", TRUE);
248 $galPageIndex = intval(stGetRequestItem("index", 0, TRUE));
249 $galImage = stGetRequestItem("image", FALSE, TRUE);
250
251 if (is_string($galImage))
252 $galImage = basename($galImage);
253
254
255 //
256 // Attempt to read the data cache file
257 //
258 $filename = mgGetPath(mgCleanPath(TRUE, $galBasePath, $galPath), "cache_file");
259 $filename2 = mgGetPath(mgCleanPath(FALSE, $galBasePath, $galPath), "cache_file");
260 if ($filename == $filename2 && file_exists($filename) && ($fp = @fopen($filename, "rb")) !== FALSE)
261 {
262 if (flock($fp, LOCK_SH))
263 {
264 require($filename);
265 flock($fp, LOCK_UN);
266 }
267 fclose($fp);
268 }
269
270
271 // If no data available, show an error page
272 if (!isset($galData) || !isset($galEntries) ||
273 !isset($galAlbumsIndex) || !isset($galImagesIndex))
274 {
275 cmPrintPageHeader(mgGetVal(array("title_prefix", "title_sep"), "%1%2")."ERROR!");
276
277 echo
278 "<h1>Gallery error</h1>\n".
279 "<p>Gallery path <b>".chentities($galPath)."</b> does not exist or is invalid.</p>\n";
280
281 //echo "<p>".$filename."</p><p>".$filename2."</p>";
282
283 mgPrintPageInfoFooter();
284 cmPrintPageFooter(TRUE);
285 exit;
286 }
287
288
289 //
290 // Print page header, etc.
291 //
292 if (($index = array_search($galImage, $galImagesIndex)) !== FALSE)
293 {
294 //
295 // Single image mode
296 //
297 $naviFlags = mgGetSetting("image_navigation");
298 $data = $galEntries[$galImage];
299
300 $pageTitle = $galTitlePrefix.$galTitleSep.$galData["caption"]." - ".$galImage;
301 cmPrintPageHeader($pageTitle);
302 echo "<h1>".chentities($pageTitle)."</h1>\n";
303
304 if ($naviFlags & GNAV_BREADCRUMBS)
305 mgPrintBreadCrumbs($galData);
306
307 if ($naviFlags & GNAV_TOP)
308 echo mgGetNaviControls($galImagesIndex, $index, $naviFlags);
309
310 echo
311 "<div class=\"imageCBox\">\n".
312 mgGetNaviControlImageBox($galImagesIndex, $index, "prev", -1).
313 "<div class=\"imageBox\">\n".
314 "<a target=\"_blank\" href=\"".$galImageURL.$galPath."/".$galImage."\">".
315 "<img src=\"".mgGetImageURL($galTNPath, $data["base"].$galMedSuffix.$data["ext"])."\" alt=\"".
316 chentities($data["base"].$galMedSuffix.$data["ext"])."\"></a>\n".
317 "</div>\n".
318 mgGetNaviControlImageBox($galImagesIndex, $index, "next", 1).
319 "</div>\n".
320 "<div class=\"imageCaption\">".mgGetArr($data, "caption", "%1", "")."</div>\n";
321
322 $list = array(
323 mgGetArr($data, array("width", "height"), "<span class=\"infoDimensions\"><b>%1</b> x <b>%2</b> px</span>", NULL),
324 mgGetArr($data, "model", "<span class=\"infoModel\"><b>%1</b></span>", NULL),
325 mgGetArr($data, "fnumber", "<span class=\"infoFNumber\"><b>f/%1</b></span>", NULL),
326 mgGetArr($data, "exposure", "<span class=\"infoExposure\"><b>%1</b> sec</span>", NULL, NULL),
327 mgGetArr($data, "iso", "<span class=\"infoISO\">ISO <b>%1</b></span>", NULL),
328 );
329
330 echo
331 "<div class=\"infoBox\">\n".
332 mgGetArr($data, "datetime", "<span class=\"infoDateTime\">%1</span>", "", "mgTimeStr").
333 implode(", ", array_filter($list, function($a) { return $a !== NULL; })).
334 "</div>\n";
335
336 if ($naviFlags & GNAV_BOTTOM)
337 echo mgGetNaviControls($galImagesIndex, $index, $naviFlags);
338
339 // Javascript navigation
340 if ($naviFlags & GNAV_JAVASCRIPT)
341 {
342 $prevActive = mgGetNaviActive($galImagesIndex, $index, -1, $res, $prevURL, FALSE);
343 $nextActive = mgGetNaviActive($galImagesIndex, $index, 1, $res, $nextURL, FALSE);
344 echo
345 "<script type=\"text/javascript\">\n".
346 "var mgalPrevURL = \"".($prevActive ? $prevURL : "")."\";\n".
347 "var mgalNextURL = \"".($nextActive ? $nextURL : "")."\";\n".
348 "\n";
349 ?>
350 function mgalNavigateTo(url)
351 {
352 if (url != "")
353 window.location = url;
354 }
355
356
357 function mgalProcessKeyPress(ev)
358 {
359 ev = ev || window.event;
360 var key = ev.keyCode ? ev.keyCode : ev.which;
361 switch (key)
362 {
363 case 37:
364 case 65:
365 // left
366 mgalNavigateTo(mgalPrevURL);
367 break;
368
369 case 39:
370 case 68:
371 // right
372 mgalNavigateTo(mgalNextURL);
373 break;
374 }
375 }
376
377 document.onkeypress = mgalProcessKeyPress;
378 <?
379 echo
380 "</script>\n";
381 }
382 }
383 else
384 {
385 //
386 // Gallery mode
387 //
388 // - needs sub-modes / handling of order shit
389 // - Javascript stuff for picture data updates
390 //
391 $pageTitle = $galTitlePrefix.mgGetArr($galData, "caption", " - %1", "", "chentities");
392 cmPrintPageHeader($pageTitle);
393 echo "<h1>".$pageTitle."</h1>\n";
394
395 $naviFlags = mgGetSetting("album_navigation");
396 if ($naviFlags & GNAV_BREADCRUMBS)
397 mgPrintBreadCrumbs($galData);
398
399 if (isset($galData["header"]) && strlen($galData["header"]) > 0)
400 echo "<div class=\"albumHeaderText\">".$galData["header"]."</div>\n";
401
402 mgPrintTable("albumTable", $galEntries, $galAlbumsIndex, 0, FALSE);
403 mgPrintTable("imageTable", $galEntries, $galImagesIndex, 0, FALSE);
404 }
405
406 mgPrintPageInfoFooter();
407 cmPrintPageFooter(TRUE);
408 ?>