Mercurial > hg > mgallery
annotate mgallery.php @ 38:3f16beb79f9e
Add image title string to certain images.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 03 May 2016 13:44:51 +0300 |
parents | 985596db0f01 |
children | c1188641c5b7 |
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"]; |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
204 $atmp = $galImageURL.implode("/", mgCleanPathArray(TRUE, 0, count($ptmp), $ptmp)); |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
205 } |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
206 else |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
207 // No album cover, use default |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
208 $atmp = $galAlbumIcon; |
985596db0f01
Implement recursive depth album covers.
Matti Hamalainen <ccr@tnsp.org>
parents:
34
diff
changeset
|
209 |
0 | 210 echo |
24 | 211 " <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
|
212 "<img class=\"albumIcon\" src=\"".$atmp."\" alt=\"".chentities($data["caption"])."\" />\n". |
24 | 213 " <div class=\"albumTitle\">".chentities($data["caption"])."</div></a>\n"; |
0 | 214 } |
215 | |
19
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
216 if ($galUseTables) |
0 | 217 { |
19
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
218 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
|
219 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
|
220 { |
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
221 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
|
222 $n = 0; |
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
223 } |
0 | 224 } |
19
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
225 else |
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
226 echo " </div>\n"; |
0 | 227 } |
19
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
228 |
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
229 if ($galUseTables) |
0 | 230 { |
19
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
231 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
|
232 { |
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
233 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
|
234 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
|
235 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
|
236 } |
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
237 echo "</table>\n"; |
0 | 238 } |
20
12916fcdb8b8
Improve the non-tabled mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
239 else |
12916fcdb8b8
Improve the non-tabled mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
240 echo "</div>\n"; |
12916fcdb8b8
Improve the non-tabled mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
19
diff
changeset
|
241 |
0 | 242 return $index; |
243 } | |
244 | |
245 | |
246 function mgTimeStr($str) | |
247 { | |
248 $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
|
249 return date_format($tmp, "d M Y (H:i:s)"); |
0 | 250 } |
251 | |
252 | |
253 function mgPrintPageInfoFooter() | |
254 { | |
255 if (($str = mgGetSetting("page_info")) !== FALSE) | |
256 echo "<div class=\"pageInfoFooter\">".$str."</div>"; | |
257 } | |
258 | |
259 | |
31
300396947f04
Remove slight code duplication by factoring to a helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
260 function mgGetBreadCrump($class, &$pdata) |
300396947f04
Remove slight code duplication by factoring to a helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
261 { |
300396947f04
Remove slight code duplication by factoring to a helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
262 return |
300396947f04
Remove slight code duplication by factoring to a helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
263 "<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
|
264 chentities($pdata["caption"])."</a>"; |
300396947f04
Remove slight code duplication by factoring to a helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
265 } |
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 |
0 | 268 function mgPrintBreadCrumbs($galData) |
269 { | |
270 $res = array(); | |
271 if ($galData["caption"]) | |
31
300396947f04
Remove slight code duplication by factoring to a helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
272 $res[] = mgGetBreadCrump("naviBreadCrumbCurr", $galData); |
0 | 273 |
274 $tmp = $galData; | |
275 while (isset($tmp["parent"])) | |
276 { | |
277 $pdata = $tmp["parent"]; | |
31
300396947f04
Remove slight code duplication by factoring to a helper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
29
diff
changeset
|
278 $res[] = mgGetBreadCrump("naviBreadCrumbItem", $pdata); |
0 | 279 $tmp = $tmp["parent"]; |
280 } | |
281 | |
282 if (count($res) > 1) | |
283 { | |
284 echo | |
285 "<div class=\"naviBreadCrumbs\">". | |
286 implode("<span class=\"naviBreadCrumbSep\"></span>", array_reverse($res)). | |
287 "</div>\n"; | |
288 } | |
289 } | |
290 | |
291 | |
292 // | |
293 // Get gallery settings | |
294 // | |
295 mgReadSettings(); | |
296 | |
297 $pageCSS = mgGetSetting("css"); | |
298 $pageCSSSelect = mgGetSetting("css_select"); | |
299 $galBasePath = mgGetSetting("base_path"); | |
300 $galBaseURL = mgGetSetting("base_url"); | |
301 $galImageURL = mgGetSetting("image_url", mgGetSetting("base_url")); | |
302 | |
17
3f7bc4202df3
Add new configuration setting 'cover_images' to disable/enable sub-album
Matti Hamalainen <ccr@tnsp.org>
parents:
13
diff
changeset
|
303 $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
|
304 $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
|
305 |
0 | 306 $galAlbumIcon = mgGetSetting("album_icon"); |
307 $galCleanURLS = mgGetSetting("clean_urls"); | |
308 $galTNPath = mgGetSetting("tn_path"); | |
309 $galMedSuffix = mgGetSetting("med_suffix"); | |
310 $galTitlePrefix = mgGetSetting("title_prefix"); | |
311 $galTitleSep = mgGetSetting("title_sep"); | |
312 | |
313 $galMode = stGetRequestItem("mode", "view", TRUE); | |
314 $galPath = stGetRequestItem("path", ".", TRUE); | |
315 $galPageIndex = intval(stGetRequestItem("index", 0, TRUE)); | |
316 $galImage = stGetRequestItem("image", FALSE, TRUE); | |
317 | |
318 if (is_string($galImage)) | |
319 $galImage = basename($galImage); | |
320 | |
321 | |
322 // | |
323 // Attempt to read the data cache file | |
324 // | |
325 $filename = mgGetPath(mgCleanPath(TRUE, $galBasePath, $galPath), "cache_file"); | |
326 $filename2 = mgGetPath(mgCleanPath(FALSE, $galBasePath, $galPath), "cache_file"); | |
327 if ($filename == $filename2 && file_exists($filename) && ($fp = @fopen($filename, "rb")) !== FALSE) | |
328 { | |
329 if (flock($fp, LOCK_SH)) | |
330 { | |
331 require($filename); | |
332 flock($fp, LOCK_UN); | |
333 } | |
334 fclose($fp); | |
335 } | |
336 | |
337 | |
338 // If no data available, show an error page | |
339 if (!isset($galData) || !isset($galEntries) || | |
340 !isset($galAlbumsIndex) || !isset($galImagesIndex)) | |
341 { | |
342 cmPrintPageHeader(mgGetVal(array("title_prefix", "title_sep"), "%1%2")."ERROR!"); | |
343 | |
344 echo | |
345 "<h1>Gallery error</h1>\n". | |
346 "<p>Gallery path <b>".chentities($galPath)."</b> does not exist or is invalid.</p>\n"; | |
347 | |
12
79987aa7ee9a
Change some debugging (commented out).
Matti Hamalainen <ccr@tnsp.org>
parents:
7
diff
changeset
|
348 //echo "<p>filename=: '".$filename."', X: galData=".intval(isset($galData)).", galEntries=".intval(isset($galEntries))."\n"; |
0 | 349 |
350 mgPrintPageInfoFooter(); | |
351 cmPrintPageFooter(TRUE); | |
352 exit; | |
353 } | |
354 | |
355 | |
356 // | |
357 // Print page header, etc. | |
358 // | |
359 if (($index = array_search($galImage, $galImagesIndex)) !== FALSE) | |
360 { | |
361 // | |
362 // Single image mode | |
363 // | |
364 $naviFlags = mgGetSetting("image_navigation"); | |
365 $data = $galEntries[$galImage]; | |
366 | |
367 $pageTitle = $galTitlePrefix.$galTitleSep.$galData["caption"]." - ".$galImage; | |
368 cmPrintPageHeader($pageTitle); | |
369 echo "<h1>".chentities($pageTitle)."</h1>\n"; | |
370 | |
371 if ($naviFlags & GNAV_BREADCRUMBS) | |
372 mgPrintBreadCrumbs($galData); | |
373 | |
374 if ($naviFlags & GNAV_TOP) | |
375 echo mgGetNaviControls($galImagesIndex, $index, $naviFlags); | |
376 | |
377 echo | |
378 "<div class=\"imageCBox\">\n". | |
379 mgGetNaviControlImageBox($galImagesIndex, $index, "prev", -1). | |
380 "<div class=\"imageBox\">\n". | |
381 "<a target=\"_blank\" href=\"".$galImageURL.$galPath."/".$galImage."\">". | |
382 "<img src=\"".mgGetImageURL($galTNPath, $data["base"].$galMedSuffix.$data["ext"])."\" alt=\"". | |
383 chentities($data["base"].$galMedSuffix.$data["ext"])."\"></a>\n". | |
384 "</div>\n". | |
385 mgGetNaviControlImageBox($galImagesIndex, $index, "next", 1). | |
386 "</div>\n". | |
387 "<div class=\"imageCaption\">".mgGetArr($data, "caption", "%1", "")."</div>\n"; | |
388 | |
389 $list = array( | |
390 mgGetArr($data, array("width", "height"), "<span class=\"infoDimensions\"><b>%1</b> x <b>%2</b> px</span>", NULL), | |
391 mgGetArr($data, "model", "<span class=\"infoModel\"><b>%1</b></span>", NULL), | |
392 mgGetArr($data, "fnumber", "<span class=\"infoFNumber\"><b>f/%1</b></span>", NULL), | |
393 mgGetArr($data, "exposure", "<span class=\"infoExposure\"><b>%1</b> sec</span>", NULL, NULL), | |
394 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
|
395 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
|
396 mgGetArr($data, "lensmodel", "<span class=\"infoLensModel\"><i>%1</i></span>", NULL), |
0 | 397 ); |
398 | |
399 echo | |
400 "<div class=\"infoBox\">\n". | |
401 mgGetArr($data, "datetime", "<span class=\"infoDateTime\">%1</span>", "", "mgTimeStr"). | |
402 implode(", ", array_filter($list, function($a) { return $a !== NULL; })). | |
403 "</div>\n"; | |
404 | |
405 if ($naviFlags & GNAV_BOTTOM) | |
406 echo mgGetNaviControls($galImagesIndex, $index, $naviFlags); | |
407 | |
408 // Javascript navigation | |
409 if ($naviFlags & GNAV_JAVASCRIPT) | |
410 { | |
411 $prevActive = mgGetNaviActive($galImagesIndex, $index, -1, $res, $prevURL, FALSE); | |
412 $nextActive = mgGetNaviActive($galImagesIndex, $index, 1, $res, $nextURL, FALSE); | |
413 echo | |
414 "<script type=\"text/javascript\">\n". | |
415 "var mgalPrevURL = \"".($prevActive ? $prevURL : "")."\";\n". | |
416 "var mgalNextURL = \"".($nextActive ? $nextURL : "")."\";\n". | |
417 "\n"; | |
418 ?> | |
419 function mgalNavigateTo(url) | |
420 { | |
421 if (url != "") | |
422 window.location = url; | |
423 } | |
424 | |
425 | |
426 function mgalProcessKeyPress(ev) | |
427 { | |
428 ev = ev || window.event; | |
429 var key = ev.keyCode ? ev.keyCode : ev.which; | |
430 switch (key) | |
431 { | |
432 case 37: | |
433 case 65: | |
434 // left | |
435 mgalNavigateTo(mgalPrevURL); | |
436 break; | |
437 | |
438 case 39: | |
439 case 68: | |
440 // right | |
441 mgalNavigateTo(mgalNextURL); | |
442 break; | |
443 } | |
444 } | |
445 | |
446 document.onkeypress = mgalProcessKeyPress; | |
447 <? | |
448 echo | |
449 "</script>\n"; | |
450 } | |
451 } | |
452 else | |
453 { | |
454 // | |
455 // Gallery mode | |
456 // | |
457 // - needs sub-modes / handling of order shit | |
458 // - Javascript stuff for picture data updates | |
459 // | |
460 $pageTitle = $galTitlePrefix.mgGetArr($galData, "caption", " - %1", "", "chentities"); | |
461 cmPrintPageHeader($pageTitle); | |
462 echo "<h1>".$pageTitle."</h1>\n"; | |
463 | |
464 $naviFlags = mgGetSetting("album_navigation"); | |
465 if ($naviFlags & GNAV_BREADCRUMBS) | |
466 mgPrintBreadCrumbs($galData); | |
467 | |
468 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
|
469 { |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
470 // 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
|
471 $baseURL = mgGetSetting("image_url"); |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
472 |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
473 $headerText = preg_replace_callback( |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
474 "@href\s*=\s*\"([^\"]+)\"@i", |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
475 function ($matches) use($galPath, $baseURL) |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
476 { |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
477 $mstmp = $matches[1]; |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
478 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
|
479 { |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
480 if ($mstmp[0] != "/") |
28
2d8112d6c3bc
Fix relative links re-parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
481 $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
|
482 } |
28
2d8112d6c3bc
Fix relative links re-parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
483 return "href=\"".$mstmp."\""; |
13
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
484 }, |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
485 $galData["header"]); |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
486 |
951752fb1c21
Add translation of relative URLs in header text blocks.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
487 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
|
488 } |
0 | 489 |
490 mgPrintTable("albumTable", $galEntries, $galAlbumsIndex, 0, FALSE); | |
491 mgPrintTable("imageTable", $galEntries, $galImagesIndex, 0, FALSE); | |
492 } | |
493 | |
494 mgPrintPageInfoFooter(); | |
495 cmPrintPageFooter(TRUE); | |
496 ?> |