Mercurial > hg > mgallery
annotate mgallery.php @ 43:fc8e6a056016
Indentation fixes.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 12 May 2016 23:32:21 +0300 |
parents | c1188641c5b7 |
children | bc9da3b71888 |
rev | line source |
---|---|
0 | 1 <?php |
2 // | |
3 // Yet Another Image Gallery | |
32 | 4 // (C) Copyright 2015-2016 Tecnic Software productions (TNSP) |
0 | 5 // |
27 | 6 require "mgeneric.inc.php"; |
0 | 7 require "mgallery.inc.php"; |
8 | |
9 | |
10 // | |
11 // Various utility functions | |
12 // | |
38
3f16beb79f9e
Add image title string to certain images.
Matti Hamalainen <ccr@tnsp.org>
parents:
35
diff
changeset
|
13 function mgGetImageTitleStr($filename, &$data) |
3f16beb79f9e
Add image title string to certain images.
Matti Hamalainen <ccr@tnsp.org>
parents:
35
diff
changeset
|
14 { |
3f16beb79f9e
Add image title string to certain images.
Matti Hamalainen <ccr@tnsp.org>
parents:
35
diff
changeset
|
15 return |
3f16beb79f9e
Add image title string to certain images.
Matti Hamalainen <ccr@tnsp.org>
parents:
35
diff
changeset
|
16 chentities($filename). |
3f16beb79f9e
Add image title string to certain images.
Matti Hamalainen <ccr@tnsp.org>
parents:
35
diff
changeset
|
17 mgGetArr($data, "datetime", " - %1", "", "mgTimeStr"); |
3f16beb79f9e
Add image title string to certain images.
Matti Hamalainen <ccr@tnsp.org>
parents:
35
diff
changeset
|
18 } |
3f16beb79f9e
Add image title string to certain images.
Matti Hamalainen <ccr@tnsp.org>
parents:
35
diff
changeset
|
19 |
3f16beb79f9e
Add image title string to certain images.
Matti Hamalainen <ccr@tnsp.org>
parents:
35
diff
changeset
|
20 |
0 | 21 function mgGetImageURL() |
22 { | |
23 global $galImageURL, $galPath; | |
5
1bf73b49fc91
Beautify the generated URLs by removing occurences of duplicate forward
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
24 return str_replace("//", "/", $galImageURL.$galPath."/".implode("", func_get_args())); |
0 | 25 } |
26 | |
27 | |
28 function mgGetURL($path, $image, $entities = TRUE) | |
29 { | |
30 global $galBaseURL, $galCleanURLS; | |
31 $amp = $entities ? "&" : "&"; | |
32 | |
33 if ($galCleanURLS) | |
34 { | |
5
1bf73b49fc91
Beautify the generated URLs by removing occurences of duplicate forward
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
35 $url = $galBaseURL.$path."/".($image !== FALSE ? $image : ""); |
0 | 36 } |
37 else | |
38 { | |
5
1bf73b49fc91
Beautify the generated URLs by removing occurences of duplicate forward
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
39 $url = |
0 | 40 $galBaseURL.mgGetSetting("mgallery_php")."?path=". |
41 $path.($image !== FALSE ? $amp."image=".$image : ""); | |
42 } | |
5
1bf73b49fc91
Beautify the generated URLs by removing occurences of duplicate forward
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
43 |
1bf73b49fc91
Beautify the generated URLs by removing occurences of duplicate forward
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
44 return str_replace("//", "/", $url); |
0 | 45 } |
46 | |
47 | |
48 function mgGetNaviActive(&$galIndex, $index, $delta, &$res, &$url, $entities) | |
49 { | |
50 global $galPath; | |
51 $res = $index + $delta; | |
52 if ($res >= 0 && $res <= sizeof($galIndex) - 1) | |
53 { | |
54 $url = mgGetURL($galPath, $galIndex[$res], $entities); | |
55 return TRUE; | |
56 } | |
57 else | |
58 return FALSE; | |
59 } | |
60 | |
61 | |
62 function mgGetNaviControlImage(&$galIndex, $index, $class, $url) | |
63 { | |
64 global $galTNPath; | |
65 | |
66 $img = "<div class=\"imageCtrl ".$class."\">"; | |
67 | |
68 if ($url !== FALSE) | |
69 { | |
70 $img .= | |
71 "<a href=\"".$url."\"><img src=\"". | |
72 mgGetImageURL($galTNPath, $galIndex[$index]). | |
73 "\" alt=\"".$galIndex[$index]."\" /></a>"; | |
74 } | |
75 | |
76 return $img."</div>\n"; | |
77 } | |
78 | |
79 | |
80 function mgGetNaviControlImageBox(&$galIndex, $index, $class, $delta) | |
81 { | |
82 if (!mgGetNaviActive($galIndex, $index, $delta, $res, $url, TRUE)) | |
83 $url = FALSE; | |
84 | |
85 return mgGetNaviControlImage($galIndex, $res, $class, $url); | |
86 } | |
87 | |
88 | |
7
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
89 function mgGetControlText($id, $active, $url, $naviFlags) |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
90 { |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
91 if ($naviFlags & GNAV_TEXT) |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
92 { |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
93 $str = chentities(mgGetSetting("navi_ctrl_".$id)); |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
94 return |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
95 "<span class=\"naviControl ".$id."\">[". |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
96 ($active ? "<a href=\"".$url."\">".$str."</a>" : $str). |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
97 "]</span>"; |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
98 } |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
99 else |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
100 return ""; |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
101 } |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
102 |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
103 |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
104 function mgGetControl($id, &$galIndex, $index, $delta, $naviFlags) |
0 | 105 { |
106 $active = mgGetNaviActive($galIndex, $index, $delta, $res, $url, TRUE); | |
107 if ($active && ($naviFlags & GNAV_IMG)) | |
7
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
108 $img = mgGetNaviControlImage($galIndex, $res, $id, $url); |
0 | 109 else |
110 $img = ""; | |
111 | |
7
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
112 $text = mgGetControlText($id, $active, $url, $naviFlags); |
0 | 113 |
114 if ($delta < 0) | |
7
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
115 return $img.$text; |
0 | 116 else |
7
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
117 return $text.$img; |
0 | 118 } |
119 | |
120 | |
121 function mgGetNaviControls(&$galIndex, $index, $naviFlags) | |
122 { | |
123 global $galPath; | |
124 | |
125 return | |
126 "<div class=\"naviControls\">". | |
7
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
127 mgGetControl("prev", $galIndex, $index, -1, $naviFlags). |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
128 mgGetControlText("up", TRUE, mgGetURL($galPath, FALSE), $naviFlags). |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
129 mgGetControl("next", $galIndex, $index, 1, $naviFlags). |
0 | 130 "</div>\n"; |
131 } | |
132 | |
133 | |
134 function mgPrintTable($class, &$galEntries, &$galIndex, $start, $limit) | |
135 { | |
19
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
136 global $galAlbumIcon, $galPath, $galTNPath, $galImageURL, $galUseCoverImages, $galUseTables; |
0 | 137 |
138 $galCount = count($galIndex); | |
139 if ($start >= $galCount) | |
140 return $start; | |
141 | |
142 $end = ($limit === FALSE) ? $galCount : $start + $limit; | |
143 if ($end > $galCount) $end = $galCount; | |
144 | |
145 $rowLimit = mgGetSetting("album_row_limit"); | |
146 $n = 0; | |
147 | |
19
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
148 if ($galUseTables) |
20
12916fcdb8b8
Improve the non-tabled mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
149 echo "<table class=\"galleryTable ".$class."\">\n"; |
12916fcdb8b8
Improve the non-tabled mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
150 else |
12916fcdb8b8
Improve the non-tabled mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
151 echo "<div class=\"galleryTable ".$class."\">\n"; |
19
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
152 |
0 | 153 for ($index = $start; $index < $end; $index++) |
154 { | |
155 $filename = &$galIndex[$index]; | |
156 $data = &$galEntries[$filename]; | |
157 | |
19
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
158 if ($galUseTables && $n == 0) echo " <tr>\n"; |
0 | 159 |
19
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
160 if ($galUseTables) |
20
12916fcdb8b8
Improve the non-tabled mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
161 echo " <td class=\"galleryEntry\" id=\"cd".$data["base"]."\">\n"; |
19
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
162 else |
20
12916fcdb8b8
Improve the non-tabled mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
163 echo " <div class=\"galleryEntry\">\n"; |
0 | 164 |
165 if ($data["type"] == 0) | |
166 { | |
167 echo | |
38
3f16beb79f9e
Add image title string to certain images.
Matti Hamalainen <ccr@tnsp.org>
parents:
35
diff
changeset
|
168 " <div class=\"imageBox\" title=\"".mgGetImageTitleStr($filename, $data). |
3f16beb79f9e
Add image title string to certain images.
Matti Hamalainen <ccr@tnsp.org>
parents:
35
diff
changeset
|
169 "\"><a href=\"".mgGetURL($galPath, $filename)."\">". |
0 | 170 "<img src=\"".mgGetImageURL($galTNPath, $filename)."\" alt=\"". |
24 | 171 chentities($filename)."\"></a></div>\n". |
172 mgGetArr($data, "caption", " <div class=\"imageCaption\">%1</div>\n", "", "chentities"); | |
0 | 173 /* |
174 if ($mode == "") | |
175 { | |
176 echo | |
177 " <select class=\"dropdown\" id=\"dd".$data["base"]."\" name=\"dd".$data["base"]. | |
178 "\" onchange=\"galPhotoDataChanged('".$data["base"]."');\">\n"; | |
179 | |
180 foreach ($picChoices as $name => $value) | |
181 { | |
182 echo " <option value=\"$value\"".($value == $data["id"] ? " selected=\"selected\"" : "").">".chentities($name)."</option>\n"; | |
183 } | |
184 echo | |
185 " </select>\n"; | |
186 } | |
187 */ | |
188 } | |
189 else | |
190 { | |
35
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
191 if ($galUseCoverImages && isset($data["image"])) |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
192 { |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
193 // Recursively determine the album cover image |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
194 $ptmp = [$galPath, $filename]; |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
195 $curr = &$data; |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
196 while (is_array($curr["image"])) |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
197 { |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
198 $curr = &$curr["image"]; |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
199 $ptmp[] = $curr["base"]; |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
200 } |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
201 |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
202 $ptmp[] = $galTNPath; |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
203 $ptmp[] = $curr["image"]; |
39 | 204 |
35
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
205 $atmp = $galImageURL.implode("/", mgCleanPathArray(TRUE, 0, count($ptmp), $ptmp)); |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
206 } |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
207 else |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
208 // No album cover, use default |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
209 $atmp = $galAlbumIcon; |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
210 |
0 | 211 echo |
24 | 212 " <a href=\"".mgGetURL(mgCleanPath(TRUE, $galPath, $filename), FALSE)."\">". |
17
3f7bc4202df3
Add new configuration setting 'cover_images' to disable/enable sub-album
Matti Hamalainen <ccr@tnsp.org>
parents:
13
diff
changeset
|
213 "<img class=\"albumIcon\" src=\"".$atmp."\" alt=\"".chentities($data["caption"])."\" />\n". |
24 | 214 " <div class=\"albumTitle\">".chentities($data["caption"])."</div></a>\n"; |
0 | 215 } |
216 | |
19
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
217 if ($galUseTables) |
0 | 218 { |
19
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
219 echo " </td>\n"; |
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
220 if (++$n >= $rowLimit) |
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
221 { |
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
222 echo " </tr>\n"; |
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
223 $n = 0; |
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
224 } |
0 | 225 } |
19
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
226 else |
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
227 echo " </div>\n"; |
0 | 228 } |
19
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
229 |
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
230 if ($galUseTables) |
0 | 231 { |
19
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
232 if ($n > 0) |
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
233 { |
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
234 while ($n++ < $rowLimit) |
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
235 echo " <td></td>\n"; |
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
236 echo " </tr>\n"; |
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
237 } |
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
238 echo "</table>\n"; |
0 | 239 } |
20
12916fcdb8b8
Improve the non-tabled mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
240 else |
12916fcdb8b8
Improve the non-tabled mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
241 echo "</div>\n"; |
12916fcdb8b8
Improve the non-tabled mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
242 |
0 | 243 return $index; |
244 } | |
245 | |
246 | |
247 function mgTimeStr($str) | |
248 { | |
249 $tmp = date_create_from_format("Y:m:d H:i:s", $str); | |
34
e786771dfaa5
Add seconds to outputted timestamps.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
250 return date_format($tmp, "d M Y (H:i:s)"); |
0 | 251 } |
252 | |
253 | |
254 function mgPrintPageInfoFooter() | |
255 { | |
256 if (($str = mgGetSetting("page_info")) !== FALSE) | |
257 echo "<div class=\"pageInfoFooter\">".$str."</div>"; | |
258 } | |
259 | |
260 | |
31
300396947f04
Remove slight code duplication by factoring to a helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
261 function mgGetBreadCrump($class, &$pdata) |
300396947f04
Remove slight code duplication by factoring to a helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
262 { |
300396947f04
Remove slight code duplication by factoring to a helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
263 return |
300396947f04
Remove slight code duplication by factoring to a helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
264 "<a class=\"".$class."\" href=\"".mgGetURL($pdata["path"], FALSE)."\">". |
300396947f04
Remove slight code duplication by factoring to a helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
265 chentities($pdata["caption"])."</a>"; |
300396947f04
Remove slight code duplication by factoring to a helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
266 } |
300396947f04
Remove slight code duplication by factoring to a helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
267 |
300396947f04
Remove slight code duplication by factoring to a helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
268 |
0 | 269 function mgPrintBreadCrumbs($galData) |
270 { | |
271 $res = array(); | |
272 if ($galData["caption"]) | |
31
300396947f04
Remove slight code duplication by factoring to a helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
273 $res[] = mgGetBreadCrump("naviBreadCrumbCurr", $galData); |
0 | 274 |
275 $tmp = $galData; | |
276 while (isset($tmp["parent"])) | |
277 { | |
278 $pdata = $tmp["parent"]; | |
31
300396947f04
Remove slight code duplication by factoring to a helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
279 $res[] = mgGetBreadCrump("naviBreadCrumbItem", $pdata); |
0 | 280 $tmp = $tmp["parent"]; |
281 } | |
282 | |
283 if (count($res) > 1) | |
284 { | |
285 echo | |
286 "<div class=\"naviBreadCrumbs\">". | |
287 implode("<span class=\"naviBreadCrumbSep\"></span>", array_reverse($res)). | |
288 "</div>\n"; | |
289 } | |
290 } | |
291 | |
292 | |
293 // | |
294 // Get gallery settings | |
295 // | |
296 mgReadSettings(); | |
297 | |
298 $pageCSS = mgGetSetting("css"); | |
299 $pageCSSSelect = mgGetSetting("css_select"); | |
300 $galBasePath = mgGetSetting("base_path"); | |
301 $galBaseURL = mgGetSetting("base_url"); | |
302 $galImageURL = mgGetSetting("image_url", mgGetSetting("base_url")); | |
303 | |
17
3f7bc4202df3
Add new configuration setting 'cover_images' to disable/enable sub-album
Matti Hamalainen <ccr@tnsp.org>
parents:
13
diff
changeset
|
304 $galUseCoverImages = mgGetSetting("cover_images"); |
19
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
305 $galUseTables = mgGetSetting("use_tables"); |
17
3f7bc4202df3
Add new configuration setting 'cover_images' to disable/enable sub-album
Matti Hamalainen <ccr@tnsp.org>
parents:
13
diff
changeset
|
306 |
0 | 307 $galAlbumIcon = mgGetSetting("album_icon"); |
308 $galCleanURLS = mgGetSetting("clean_urls"); | |
309 $galTNPath = mgGetSetting("tn_path"); | |
310 $galMedSuffix = mgGetSetting("med_suffix"); | |
311 $galTitlePrefix = mgGetSetting("title_prefix"); | |
312 $galTitleSep = mgGetSetting("title_sep"); | |
313 | |
314 $galMode = stGetRequestItem("mode", "view", TRUE); | |
315 $galPath = stGetRequestItem("path", ".", TRUE); | |
316 $galPageIndex = intval(stGetRequestItem("index", 0, TRUE)); | |
317 $galImage = stGetRequestItem("image", FALSE, TRUE); | |
318 | |
319 if (is_string($galImage)) | |
320 $galImage = basename($galImage); | |
321 | |
322 | |
323 // | |
324 // Attempt to read the data cache file | |
325 // | |
326 $filename = mgGetPath(mgCleanPath(TRUE, $galBasePath, $galPath), "cache_file"); | |
327 $filename2 = mgGetPath(mgCleanPath(FALSE, $galBasePath, $galPath), "cache_file"); | |
328 if ($filename == $filename2 && file_exists($filename) && ($fp = @fopen($filename, "rb")) !== FALSE) | |
329 { | |
330 if (flock($fp, LOCK_SH)) | |
331 { | |
332 require($filename); | |
333 flock($fp, LOCK_UN); | |
334 } | |
335 fclose($fp); | |
336 } | |
337 | |
338 | |
339 // If no data available, show an error page | |
340 if (!isset($galData) || !isset($galEntries) || | |
341 !isset($galAlbumsIndex) || !isset($galImagesIndex)) | |
342 { | |
343 cmPrintPageHeader(mgGetVal(array("title_prefix", "title_sep"), "%1%2")."ERROR!"); | |
344 | |
345 echo | |
346 "<h1>Gallery error</h1>\n". | |
347 "<p>Gallery path <b>".chentities($galPath)."</b> does not exist or is invalid.</p>\n"; | |
348 | |
12
79987aa7ee9a
Change some debugging (commented out).
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
349 //echo "<p>filename=: '".$filename."', X: galData=".intval(isset($galData)).", galEntries=".intval(isset($galEntries))."\n"; |
0 | 350 |
351 mgPrintPageInfoFooter(); | |
352 cmPrintPageFooter(TRUE); | |
353 exit; | |
354 } | |
355 | |
356 | |
357 // | |
358 // Print page header, etc. | |
359 // | |
360 if (($index = array_search($galImage, $galImagesIndex)) !== FALSE) | |
361 { | |
362 // | |
363 // Single image mode | |
364 // | |
365 $naviFlags = mgGetSetting("image_navigation"); | |
366 $data = $galEntries[$galImage]; | |
367 | |
368 $pageTitle = $galTitlePrefix.$galTitleSep.$galData["caption"]." - ".$galImage; | |
369 cmPrintPageHeader($pageTitle); | |
370 echo "<h1>".chentities($pageTitle)."</h1>\n"; | |
371 | |
372 if ($naviFlags & GNAV_BREADCRUMBS) | |
373 mgPrintBreadCrumbs($galData); | |
374 | |
375 if ($naviFlags & GNAV_TOP) | |
376 echo mgGetNaviControls($galImagesIndex, $index, $naviFlags); | |
377 | |
378 echo | |
379 "<div class=\"imageCBox\">\n". | |
380 mgGetNaviControlImageBox($galImagesIndex, $index, "prev", -1). | |
381 "<div class=\"imageBox\">\n". | |
382 "<a target=\"_blank\" href=\"".$galImageURL.$galPath."/".$galImage."\">". | |
383 "<img src=\"".mgGetImageURL($galTNPath, $data["base"].$galMedSuffix.$data["ext"])."\" alt=\"". | |
384 chentities($data["base"].$galMedSuffix.$data["ext"])."\"></a>\n". | |
385 "</div>\n". | |
386 mgGetNaviControlImageBox($galImagesIndex, $index, "next", 1). | |
387 "</div>\n". | |
388 "<div class=\"imageCaption\">".mgGetArr($data, "caption", "%1", "")."</div>\n"; | |
389 | |
390 $list = array( | |
391 mgGetArr($data, array("width", "height"), "<span class=\"infoDimensions\"><b>%1</b> x <b>%2</b> px</span>", NULL), | |
392 mgGetArr($data, "model", "<span class=\"infoModel\"><b>%1</b></span>", NULL), | |
393 mgGetArr($data, "fnumber", "<span class=\"infoFNumber\"><b>f/%1</b></span>", NULL), | |
394 mgGetArr($data, "exposure", "<span class=\"infoExposure\"><b>%1</b> sec</span>", NULL, NULL), | |
395 mgGetArr($data, "iso", "<span class=\"infoISO\">ISO <b>%1</b></span>", NULL), | |
29
8cf743c7ea23
Add focal length and lens model display.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
396 mgGetArr($data, "focallength", "<span class=\"infoFocalLength\">F-L <b>%1</b>mm</span>", NULL), |
8cf743c7ea23
Add focal length and lens model display.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
397 mgGetArr($data, "lensmodel", "<span class=\"infoLensModel\"><i>%1</i></span>", NULL), |
0 | 398 ); |
399 | |
400 echo | |
401 "<div class=\"infoBox\">\n". | |
402 mgGetArr($data, "datetime", "<span class=\"infoDateTime\">%1</span>", "", "mgTimeStr"). | |
403 implode(", ", array_filter($list, function($a) { return $a !== NULL; })). | |
404 "</div>\n"; | |
405 | |
406 if ($naviFlags & GNAV_BOTTOM) | |
407 echo mgGetNaviControls($galImagesIndex, $index, $naviFlags); | |
408 | |
409 // Javascript navigation | |
410 if ($naviFlags & GNAV_JAVASCRIPT) | |
411 { | |
412 $prevActive = mgGetNaviActive($galImagesIndex, $index, -1, $res, $prevURL, FALSE); | |
413 $nextActive = mgGetNaviActive($galImagesIndex, $index, 1, $res, $nextURL, FALSE); | |
414 echo | |
415 "<script type=\"text/javascript\">\n". | |
416 "var mgalPrevURL = \"".($prevActive ? $prevURL : "")."\";\n". | |
417 "var mgalNextURL = \"".($nextActive ? $nextURL : "")."\";\n". | |
418 "\n"; | |
419 ?> | |
420 function mgalNavigateTo(url) | |
421 { | |
43 | 422 if (url != "") |
423 window.location = url; | |
0 | 424 } |
425 | |
426 | |
427 function mgalProcessKeyPress(ev) | |
428 { | |
43 | 429 ev = ev || window.event; |
430 var key = ev.keyCode ? ev.keyCode : ev.which; | |
431 switch (key) | |
432 { | |
433 case 37: | |
434 case 65: | |
435 // left | |
436 mgalNavigateTo(mgalPrevURL); | |
437 break; | |
0 | 438 |
43 | 439 case 39: |
440 case 68: | |
441 // right | |
442 mgalNavigateTo(mgalNextURL); | |
443 break; | |
444 } | |
0 | 445 } |
446 | |
447 document.onkeypress = mgalProcessKeyPress; | |
448 <? | |
449 echo | |
450 "</script>\n"; | |
451 } | |
452 } | |
453 else | |
454 { | |
455 // | |
456 // Gallery mode | |
457 // | |
458 // - needs sub-modes / handling of order shit | |
459 // - Javascript stuff for picture data updates | |
460 // | |
461 $pageTitle = $galTitlePrefix.mgGetArr($galData, "caption", " - %1", "", "chentities"); | |
462 cmPrintPageHeader($pageTitle); | |
463 echo "<h1>".$pageTitle."</h1>\n"; | |
464 | |
465 $naviFlags = mgGetSetting("album_navigation"); | |
466 if ($naviFlags & GNAV_BREADCRUMBS) | |
467 mgPrintBreadCrumbs($galData); | |
468 | |
469 if (isset($galData["header"]) && strlen($galData["header"]) > 0) | |
13
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
470 { |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
471 // Translate relative URLs in header, if needed |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
472 $baseURL = mgGetSetting("image_url"); |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
473 |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
474 $headerText = preg_replace_callback( |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
475 "@href\s*=\s*\"([^\"]+)\"@i", |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
476 function ($matches) use($galPath, $baseURL) |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
477 { |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
478 $mstmp = $matches[1]; |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
479 if (preg_match("@^[a-z]+://@i", $mstmp) === 0) |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
480 { |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
481 if ($mstmp[0] != "/") |
28
2d8112d6c3bc
Fix relative links re-parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
482 $mstmp = $baseURL."/".$galPath."/".str_replace("//", "/", $mstmp); |
13
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
483 } |
28
2d8112d6c3bc
Fix relative links re-parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
484 return "href=\"".$mstmp."\""; |
13
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
485 }, |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
486 $galData["header"]); |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
487 |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
488 echo "<div class=\"albumHeaderText\">".$headerText."</div>\n"; |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
489 } |
0 | 490 |
491 mgPrintTable("albumTable", $galEntries, $galAlbumsIndex, 0, FALSE); | |
492 mgPrintTable("imageTable", $galEntries, $galImagesIndex, 0, FALSE); | |
493 } | |
494 | |
495 mgPrintPageInfoFooter(); | |
496 cmPrintPageFooter(TRUE); | |
497 ?> |