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