Mercurial > hg > mgallery
annotate mgallery.inc.php @ 111:9da8bab49711
Bump copyright years.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 19 Jan 2017 09:43:31 +0200 |
parents | 71de97240799 |
children | 4f95ed80583c |
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> |
111 | 6 // (C) Copyright 2015-2017 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>"; | |
111 | 12 $mgProgCopyright = "2015-2017 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), | |
107
71de97240799
Add support for urchin file.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
66 "urchin_file" => array(MG_STR, FALSE), |
0 | 67 "album_icon" => array(MG_STR, "album_sm.png"), |
68 | |
106
a3b8cd4183e6
Change {album,image}_navigation setting to *_flags.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
69 "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
|
70 "album_flags" => array(MG_FLAGS, MGF_JAVASCRIPT | MGF_BREADCRUMBS), |
0 | 71 "album_row_limit" => array(MG_INT, 5), |
72 | |
73 "med_suffix" => array(MG_STR, ".med"), | |
74 "tn_path" => array(MG_STR, "tn/"), | |
75 | |
76 "tn_width" => array(MG_INT, 140), // In pixels, applies as bounding box for w/h | |
77 "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
|
78 "tn_quality" => array(MG_INT, 77), // JPEG quality percent |
0 | 79 |
95
b8c6e3909972
Adjust the default thumb/mid image size and quality settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
80 "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
|
81 "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
|
82 "med_quality" => array(MG_INT, 88), |
0 | 83 ); |
84 | |
85 | |
86 function mgDebug($msg) | |
87 { | |
88 // echo "MGAL[debug]: ".$msg; | |
89 } | |
90 | |
91 | |
92 function mgFatal($msg) | |
93 { | |
94 die("MGAL[fatal]: ".$msg); | |
95 } | |
96 | |
97 | |
98 function mgError($msg) | |
99 { | |
100 echo "MGAL[error]: ".$msg; | |
101 return FALSE; | |
102 } | |
103 | |
104 | |
105 function mgCArg($index, $clip = FALSE) | |
106 { | |
107 global $argc, $argv; | |
108 if ($index < $argc) | |
109 { | |
110 $str = $argv[$index]; | |
111 return ($clip !== FALSE) ? substr($str, 0, $clip) : $str; | |
112 } | |
113 else | |
114 return FALSE; | |
115 } | |
116 | |
117 | |
118 function mgCArgLC($index, $clip = FALSE) | |
119 { | |
120 global $argc, $argv; | |
121 if ($index < $argc) | |
122 { | |
123 $str = strtolower($argv[$index]); | |
124 return ($clip !== FALSE) ? substr($str, 0, $clip) : $str; | |
125 } | |
126 else | |
127 return FALSE; | |
128 } | |
129 | |
130 | |
131 function mgGetSetting($key, $default = NULL) | |
132 { | |
133 global $mgSettings, $mgDefaults; | |
134 | |
135 if (!array_key_exists($key, $mgDefaults)) | |
136 mgFatal("Setting '".$key."' does not exist.\n"); | |
137 | |
138 if (array_key_exists($key, $mgSettings)) | |
139 $val = $mgSettings[$key]; | |
140 else | |
141 $val = $mgDefaults[$key][1]; | |
142 | |
143 if (!isset($val) || $val === NULL) | |
144 { | |
145 if ($default !== NULL) | |
146 $val = $default; | |
147 else | |
148 mgFatal("Setting '".$key."' is not set, but is required to be configured.\n"); | |
149 } | |
150 | |
151 return $val; | |
152 } | |
153 | |
154 | |
155 function mgGetPath($path, $key) | |
156 { | |
157 $val = mgGetSetting($key); | |
158 return ($val !== FALSE) ? $path."/".$val : FALSE; | |
159 } | |
160 | |
161 | |
162 function mgReadSettings($filename = "mgallery.cfg") | |
163 { | |
164 global $mgSettings, $mgDefaults; | |
165 | |
166 $spaths = array(); | |
167 $spaths[] = getcwd()."/"; | |
168 if (($tmp = getenv("HOME")) !== FALSE && strlen($tmp) > 0) | |
169 { | |
170 $spaths[] = $tmp."/.config/mgallery/"; | |
171 $spaths[] = $tmp."/."; | |
172 } | |
173 else | |
174 { | |
175 $data = posix_getpwuid(posix_getuid()); | |
176 if ($data !== FALSE && isset($data["dir"])) | |
177 { | |
178 $tmp = $data["dir"]; | |
179 $spaths[] = $tmp."/.config/mgallery/"; | |
180 $spaths[] = $tmp."/."; | |
181 } | |
182 } | |
183 $spaths[] = dirname(__FILE__)."/"; | |
184 | |
185 foreach (array_unique($spaths) as $path) | |
186 { | |
187 $file = $path.$filename; | |
188 mgDebug("Checking '".$file."' for configuration ..\n"); | |
189 if (file_exists($file) && | |
190 ($mgSettings = parse_ini_file($file, FALSE)) !== FALSE) | |
191 { | |
192 mgDebug("Found '".$file."' config.\n"); | |
193 | |
194 // Validate settings | |
195 $ok = TRUE; | |
196 foreach ($mgSettings as $setting => $val) | |
197 { | |
198 if (!array_key_exists($setting, $mgDefaults)) | |
199 { | |
200 mgError("Setting '".$setting."' does not exist.\n"); | |
201 $ok = FALSE; | |
202 } | |
203 } | |
204 return $ok; | |
205 } | |
206 } | |
207 | |
208 $mgSettings = array(); | |
209 return FALSE; | |
210 } | |
211 | |
212 | |
213 function mgRealPath($path) | |
214 { | |
215 return realpath($path); | |
216 } | |
217 | |
218 | |
219 function mgCleanPathArray($refs, $start, $argc, $argv) | |
220 { | |
221 $path = array(); | |
222 $first = TRUE; | |
223 for ($n = $start; $n < $argc; $n++) | |
224 { | |
225 foreach (explode("/", $argv[$n]) as $piece) | |
226 { | |
227 switch ($piece) | |
228 { | |
229 case ".": | |
230 case "": | |
231 if ($first) | |
232 $path[] = $piece; | |
233 break; | |
234 | |
235 case "..": | |
236 if ($refs && count($path) > 0) | |
237 array_pop($path); | |
238 break; | |
239 | |
240 default: | |
241 $path[] = $piece; | |
242 break; | |
243 } | |
244 $first = FALSE; | |
245 } | |
246 } | |
247 return $path; | |
248 } | |
249 | |
250 | |
251 function mgCleanPath($refs) | |
252 { | |
253 return implode("/", mgCleanPathArray($refs, 1, func_num_args(), func_get_args())); | |
254 } | |
255 | |
256 | |
47
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
257 function mgGetTrans($val, $che = FALSE) |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
258 { |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
259 global $pageLang; |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
260 |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
261 if (is_array($val)) |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
262 $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
|
263 else |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
264 $str = $val; |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
265 |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
266 return $che ? chentities($str) : $str; |
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 |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
269 |
0 | 270 function mgGetArr($data, $skeys, $sfmt1 = "%1", $sfmt2 = "", $func = NULL) |
271 { | |
47
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
272 global $pageLang; |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
273 |
0 | 274 if (!is_array($skeys)) |
275 $skeys = array($skeys); | |
276 | |
277 foreach ($skeys as $skey) | |
278 if (!array_key_exists($skey, $data)) | |
279 return $sfmt2; | |
280 | |
281 $str = $sfmt1; | |
282 for ($i = 1; $i <= sizeof($skeys); $i++) | |
283 { | |
284 $val = $data[$skeys[$i - 1]]; | |
47
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
285 if (is_array($val)) |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
286 $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
|
287 else |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
288 $vtmp = $val; |
0 | 289 |
290 if (is_callable($func)) | |
77
fcfd635d7abf
Oops, fix format string callback functions ..
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
291 $vtmp = call_user_func($func, $vtmp); |
0 | 292 |
47
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
293 $str = str_replace("%".$i, $vtmp, $str); |
0 | 294 } |
295 | |
296 return $str; | |
297 } | |
298 | |
299 | |
300 function mgGetVal($skeys, $sfmt1 = "%1", $sfmt2 = "", $func = NULL) | |
301 { | |
302 } | |
303 | |
304 | |
305 function mgGetDValStr($type, $val) | |
306 { | |
307 switch ($type) | |
308 { | |
309 case MG_STR : return "\"".$val."\""; | |
310 case MG_BOOL : return $val ? "yes" : "no"; | |
311 case MG_INT : | |
312 default : return (string) $val; | |
313 } | |
314 } | |
315 | |
316 | |
317 ?> |