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