Mercurial > hg > mgallery
annotate mgallery.inc.php @ 102:f8e6e0f2471d
Use CSS id instead of generic selector.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 19 Sep 2016 19:29:11 +0300 |
parents | f83d8a2e7260 |
children | 7728b586a421 |
rev | line source |
---|---|
0 | 1 <?php |
2 // | |
3 // Yet Another Image Gallery | |
69
7777887bc515
Update header/copyright blurbs.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
4 // -- Common functions and data include |
7777887bc515
Update header/copyright blurbs.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
5 // Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
32 | 6 // (C) Copyright 2015-2016 Tecnic Software productions (TNSP) |
0 | 7 // |
8 | |
97 | 9 $mgProgVersion = "v0.8.0"; |
0 | 10 $mgProgInfo = "Programmed by Matti 'ccr' Hamalainen"; |
11 $mgProgEmail = "<ccr@tnsp.org>"; | |
32 | 12 $mgProgCopyright = "2015-2016 Tecnic Software productions (TNSP)"; |
0 | 13 |
14 | |
15 // | |
16 // Constants for different value types | |
17 // | |
18 define("MG_STR", 1); | |
19 define("MG_INT", 2); | |
20 define("MG_DVA", 3); | |
21 define("MG_BOOL", 4); | |
22 | |
23 | |
24 define("yes", 1); | |
25 define("no", 0); | |
26 | |
27 | |
28 // | |
29 // Navigation control defines | |
30 // | |
31 define("GNAV_TOP" , 0x01); | |
32 define("GNAV_BOTTOM" , 0x02); | |
33 define("GNAV_IMG" , 0x04); | |
34 define("GNAV_TEXT" , 0x08); | |
35 define("GNAV_SIDE_IMG" , 0x10); | |
36 define("GNAV_JAVASCRIPT" , 0x20); | |
37 define("GNAV_BREADCRUMBS", 0x40); | |
38 | |
39 | |
40 function mgPathName($path) | |
41 { | |
42 $tmp = mgCleanPathArray(TRUE, 0, func_num_args(), func_get_args()); | |
43 if (count($tmp) > 0) | |
44 return implode("/", array_splice($tmp, 0, -1))."/"; | |
45 else | |
46 return $path; | |
47 } | |
48 | |
49 // | |
50 // Configuration settings and their default values | |
51 // | |
52 $mgDefaults = array( | |
53 "base_path" => array(MG_STR, mgPathName(mgRealPath($_SERVER["SCRIPT_FILENAME"]))), | |
54 "base_url" => array(MG_STR, mgPathName($_SERVER["PHP_SELF"])), | |
55 "image_url" => array(MG_STR, mgPathName($_SERVER["PHP_SELF"])), | |
56 "mgallery_php" => array(MG_STR, "mgallery.php"), | |
57 "format_exts" => array(MG_STR, "\.jpg|\.png|\.gif|\.jpeg"), | |
58 "captions_file" => array(MG_STR, "captions.txt"), | |
59 "header_file" => array(MG_STR, "header.txt"), | |
60 "info_file" => array(MG_STR, "gallery.info"), | |
61 "cache_file" => array(MG_STR, ".mgallery.cache"), | |
62 | |
17
3f7bc4202df3
Add new configuration setting 'cover_images' to disable/enable sub-album
Matti Hamalainen <ccr@tnsp.org>
parents:
14
diff
changeset
|
63 "cover_images" => array(MG_BOOL, TRUE), |
19
59075f5e7a62
Add configuration setting to enable and disable use of HTML table elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
64 "use_tables" => array(MG_BOOL, TRUE), |
0 | 65 "clean_urls" => array(MG_BOOL, FALSE), |
66 | |
67 "title_prefix" => array(MG_STR, ""), | |
68 "title_sep" => array(MG_STR, " - "), | |
69 "page_info" => array(MG_STR, "<b>MGallery ".$mgProgVersion."</b> © Copyright ".$mgProgCopyright), | |
70 "css_select" => array(MG_BOOL, FALSE), | |
71 "css" => array(MG_STR, NULL), | |
72 "album_icon" => array(MG_STR, "album_sm.png"), | |
73 | |
74 "image_navigation" => array(MG_INT, GNAV_TOP | GNAV_BOTTOM | GNAV_SIDE_IMG | GNAV_TEXT | GNAV_JAVASCRIPT | GNAV_BREADCRUMBS), | |
75 "album_navigation" => array(MG_INT, GNAV_BREADCRUMBS), | |
76 | |
7
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
77 "navi_ctrl_up" => array(MG_STR, "^^"), |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
78 "navi_ctrl_prev" => array(MG_STR, "<<"), |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
79 "navi_ctrl_next" => array(MG_STR, ">>"), |
dec931d9e860
Implement configurable navigation controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
80 |
0 | 81 "album_row_limit" => array(MG_INT, 5), |
82 | |
83 "med_suffix" => array(MG_STR, ".med"), | |
84 "tn_path" => array(MG_STR, "tn/"), | |
85 | |
86 "tn_width" => array(MG_INT, 140), // In pixels, applies as bounding box for w/h | |
87 "tn_height" => array(MG_INT, 100), | |
95
b8c6e3909972
Adjust the default thumb/mid image size and quality settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
88 "tn_quality" => array(MG_INT, 77), // JPEG quality percent |
0 | 89 |
95
b8c6e3909972
Adjust the default thumb/mid image size and quality settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
90 "med_width" => array(MG_INT, 960), |
b8c6e3909972
Adjust the default thumb/mid image size and quality settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
91 "med_height" => array(MG_INT, 640), |
b8c6e3909972
Adjust the default thumb/mid image size and quality settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
92 "med_quality" => array(MG_INT, 88), |
0 | 93 ); |
94 | |
95 | |
96 function mgDebug($msg) | |
97 { | |
98 // echo "MGAL[debug]: ".$msg; | |
99 } | |
100 | |
101 | |
102 function mgFatal($msg) | |
103 { | |
104 die("MGAL[fatal]: ".$msg); | |
105 } | |
106 | |
107 | |
108 function mgError($msg) | |
109 { | |
110 echo "MGAL[error]: ".$msg; | |
111 return FALSE; | |
112 } | |
113 | |
114 | |
115 function mgCArg($index, $clip = FALSE) | |
116 { | |
117 global $argc, $argv; | |
118 if ($index < $argc) | |
119 { | |
120 $str = $argv[$index]; | |
121 return ($clip !== FALSE) ? substr($str, 0, $clip) : $str; | |
122 } | |
123 else | |
124 return FALSE; | |
125 } | |
126 | |
127 | |
128 function mgCArgLC($index, $clip = FALSE) | |
129 { | |
130 global $argc, $argv; | |
131 if ($index < $argc) | |
132 { | |
133 $str = strtolower($argv[$index]); | |
134 return ($clip !== FALSE) ? substr($str, 0, $clip) : $str; | |
135 } | |
136 else | |
137 return FALSE; | |
138 } | |
139 | |
140 | |
141 function mgGetSetting($key, $default = NULL) | |
142 { | |
143 global $mgSettings, $mgDefaults; | |
144 | |
145 if (!array_key_exists($key, $mgDefaults)) | |
146 mgFatal("Setting '".$key."' does not exist.\n"); | |
147 | |
148 if (array_key_exists($key, $mgSettings)) | |
149 $val = $mgSettings[$key]; | |
150 else | |
151 $val = $mgDefaults[$key][1]; | |
152 | |
153 if (!isset($val) || $val === NULL) | |
154 { | |
155 if ($default !== NULL) | |
156 $val = $default; | |
157 else | |
158 mgFatal("Setting '".$key."' is not set, but is required to be configured.\n"); | |
159 } | |
160 | |
161 return $val; | |
162 } | |
163 | |
164 | |
165 function mgGetPath($path, $key) | |
166 { | |
167 $val = mgGetSetting($key); | |
168 return ($val !== FALSE) ? $path."/".$val : FALSE; | |
169 } | |
170 | |
171 | |
172 function mgReadSettings($filename = "mgallery.cfg") | |
173 { | |
174 global $mgSettings, $mgDefaults; | |
175 | |
176 $spaths = array(); | |
177 $spaths[] = getcwd()."/"; | |
178 if (($tmp = getenv("HOME")) !== FALSE && strlen($tmp) > 0) | |
179 { | |
180 $spaths[] = $tmp."/.config/mgallery/"; | |
181 $spaths[] = $tmp."/."; | |
182 } | |
183 else | |
184 { | |
185 $data = posix_getpwuid(posix_getuid()); | |
186 if ($data !== FALSE && isset($data["dir"])) | |
187 { | |
188 $tmp = $data["dir"]; | |
189 $spaths[] = $tmp."/.config/mgallery/"; | |
190 $spaths[] = $tmp."/."; | |
191 } | |
192 } | |
193 $spaths[] = dirname(__FILE__)."/"; | |
194 | |
195 foreach (array_unique($spaths) as $path) | |
196 { | |
197 $file = $path.$filename; | |
198 mgDebug("Checking '".$file."' for configuration ..\n"); | |
199 if (file_exists($file) && | |
200 ($mgSettings = parse_ini_file($file, FALSE)) !== FALSE) | |
201 { | |
202 mgDebug("Found '".$file."' config.\n"); | |
203 | |
204 // Validate settings | |
205 $ok = TRUE; | |
206 foreach ($mgSettings as $setting => $val) | |
207 { | |
208 if (!array_key_exists($setting, $mgDefaults)) | |
209 { | |
210 mgError("Setting '".$setting."' does not exist.\n"); | |
211 $ok = FALSE; | |
212 } | |
213 } | |
214 return $ok; | |
215 } | |
216 } | |
217 | |
218 $mgSettings = array(); | |
219 return FALSE; | |
220 } | |
221 | |
222 | |
223 function mgRealPath($path) | |
224 { | |
225 return realpath($path); | |
226 } | |
227 | |
228 | |
229 function mgCleanPathArray($refs, $start, $argc, $argv) | |
230 { | |
231 $path = array(); | |
232 $first = TRUE; | |
233 for ($n = $start; $n < $argc; $n++) | |
234 { | |
235 foreach (explode("/", $argv[$n]) as $piece) | |
236 { | |
237 switch ($piece) | |
238 { | |
239 case ".": | |
240 case "": | |
241 if ($first) | |
242 $path[] = $piece; | |
243 break; | |
244 | |
245 case "..": | |
246 if ($refs && count($path) > 0) | |
247 array_pop($path); | |
248 break; | |
249 | |
250 default: | |
251 $path[] = $piece; | |
252 break; | |
253 } | |
254 $first = FALSE; | |
255 } | |
256 } | |
257 return $path; | |
258 } | |
259 | |
260 | |
261 function mgCleanPath($refs) | |
262 { | |
263 return implode("/", mgCleanPathArray($refs, 1, func_num_args(), func_get_args())); | |
264 } | |
265 | |
266 | |
47
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
267 function mgGetTrans($val, $che = FALSE) |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
268 { |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
269 global $pageLang; |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
270 |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
271 if (is_array($val)) |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
272 $str = array_key_exists($pageLang, $val) ? $val[$pageLang] : reset($val); |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
273 else |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
274 $str = $val; |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
275 |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
276 return $che ? chentities($str) : $str; |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
277 } |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
278 |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
279 |
0 | 280 function mgGetArr($data, $skeys, $sfmt1 = "%1", $sfmt2 = "", $func = NULL) |
281 { | |
47
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
282 global $pageLang; |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
283 |
0 | 284 if (!is_array($skeys)) |
285 $skeys = array($skeys); | |
286 | |
287 foreach ($skeys as $skey) | |
288 if (!array_key_exists($skey, $data)) | |
289 return $sfmt2; | |
290 | |
291 $str = $sfmt1; | |
292 for ($i = 1; $i <= sizeof($skeys); $i++) | |
293 { | |
294 $val = $data[$skeys[$i - 1]]; | |
47
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
295 if (is_array($val)) |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
296 $vtmp = array_key_exists($pageLang, $val) ? $val[$pageLang] : reset($val); |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
297 else |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
298 $vtmp = $val; |
0 | 299 |
300 if (is_callable($func)) | |
77
fcfd635d7abf
Oops, fix format string callback functions ..
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
301 $vtmp = call_user_func($func, $vtmp); |
0 | 302 |
47
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
303 $str = str_replace("%".$i, $vtmp, $str); |
0 | 304 } |
305 | |
306 return $str; | |
307 } | |
308 | |
309 | |
310 function mgGetVal($skeys, $sfmt1 = "%1", $sfmt2 = "", $func = NULL) | |
311 { | |
312 } | |
313 | |
314 | |
315 function mgGetDValStr($type, $val) | |
316 { | |
317 switch ($type) | |
318 { | |
319 case MG_STR : return "\"".$val."\""; | |
320 case MG_BOOL : return $val ? "yes" : "no"; | |
321 case MG_INT : | |
322 default : return (string) $val; | |
323 } | |
324 } | |
325 | |
326 | |
327 ?> |