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