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