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