Mercurial > hg > mgallery
annotate mgallery.inc.php @ 127:3ee66c432081
Use modern PHP array syntax.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 01 Sep 2017 00:42:51 +0300 |
parents | eac2cf04261a |
children | f825d644cf7a |
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 | |
121 | 9 $mgProgVersion = "v0.8.5"; |
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); |
114
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
20 define("MGF_CAPTIONS" , 0x20); |
106
a3b8cd4183e6
Change {album,image}_navigation setting to *_flags.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
21 |
a3b8cd4183e6
Change {album,image}_navigation setting to *_flags.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
22 // |
0 | 23 // Constants for different value types |
24 // | |
25 define("MG_STR", 1); | |
26 define("MG_INT", 2); | |
27 define("MG_DVA", 3); | |
28 define("MG_BOOL", 4); | |
114
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
29 define("MG_FLAGS", 5); |
124
eac2cf04261a
Change how date timestamps are stored and handled. This breaks cache file
Matti Hamalainen <ccr@tnsp.org>
parents:
121
diff
changeset
|
30 define("MG_DATE", 6); |
0 | 31 |
32 | |
33 define("yes", 1); | |
34 define("no", 0); | |
35 | |
36 | |
114
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
37 $mgGFlags = [ |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
38 "javascript" => MGF_JAVASCRIPT, |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
39 "breadcrumbs" => MGF_BREADCRUMBS, |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
40 "captions" => MGF_CAPTIONS, |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
41 ]; |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
42 |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
43 |
0 | 44 function mgPathName($path) |
45 { | |
46 $tmp = mgCleanPathArray(TRUE, 0, func_num_args(), func_get_args()); | |
47 if (count($tmp) > 0) | |
48 return implode("/", array_splice($tmp, 0, -1))."/"; | |
49 else | |
50 return $path; | |
51 } | |
52 | |
53 // | |
54 // Configuration settings and their default values | |
55 // | |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
56 $mgDefaults = [ |
0 | 57 |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
58 "base_path" => [MG_STR, mgPathName(mgRealPath($_SERVER["SCRIPT_FILENAME"]))], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
59 "base_url" => [MG_STR, mgPathName($_SERVER["PHP_SELF"])], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
60 "image_url" => [MG_STR, mgPathName($_SERVER["PHP_SELF"])], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
61 "mgallery_php" => [MG_STR, "mgallery.php"], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
62 "format_exts" => [MG_STR, "\.jpg|\.png|\.gif|\.jpeg"], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
63 "captions_file" => [MG_STR, "captions.txt"], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
64 "header_file" => [MG_STR, "header.txt"], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
65 "info_file" => [MG_STR, "gallery.info"], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
66 "cache_file" => [MG_STR, ".mgallery.cache"], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
67 |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
68 "cover_images" => [MG_BOOL, TRUE], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
69 "use_tables" => [MG_BOOL, TRUE], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
70 "clean_urls" => [MG_BOOL, FALSE], |
0 | 71 |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
72 "title_prefix" => [MG_STR, ""], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
73 "title_sep" => [MG_STR, " - "], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
74 "page_info" => [MG_STR, "<b>MGallery ".$mgProgVersion."</b> © Copyright ".$mgProgCopyright], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
75 "css_select" => [MG_BOOL, FALSE], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
76 "css" => [MG_STR, NULL], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
77 "urchin_file" => [MG_STR, FALSE], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
78 "album_icon" => [MG_STR, "album_sm.png"], |
0 | 79 |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
80 "global_flags" => [MG_FLAGS, MGF_JAVASCRIPT | MGF_BREADCRUMBS | MGF_CAPTIONS, &$mgGFlags], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
81 "image_flags" => [MG_FLAGS, MGF_JAVASCRIPT | MGF_BREADCRUMBS, &$mgGFlags], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
82 "album_flags" => [MG_FLAGS, MGF_JAVASCRIPT | MGF_BREADCRUMBS, &$mgGFlags], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
83 "album_row_limit" => [MG_INT, 5], |
0 | 84 |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
85 "med_suffix" => [MG_STR, ".med"], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
86 "tn_path" => [MG_STR, "tn/"], |
0 | 87 |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
88 "tn_width" => [MG_INT, 140], // In pixels, applies as bounding box for w/h |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
89 "tn_height" => [MG_INT, 100], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
90 "tn_quality" => [MG_INT, 77], // JPEG quality percent |
0 | 91 |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
92 "med_width" => [MG_INT, 960], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
93 "med_height" => [MG_INT, 640], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
94 "med_quality" => [MG_INT, 88], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
95 ]; |
0 | 96 |
97 | |
98 function mgDebug($msg) | |
99 { | |
100 // echo "MGAL[debug]: ".$msg; | |
101 } | |
102 | |
103 | |
104 function mgFatal($msg) | |
105 { | |
106 die("MGAL[fatal]: ".$msg); | |
107 } | |
108 | |
109 | |
110 function mgError($msg) | |
111 { | |
112 echo "MGAL[error]: ".$msg; | |
113 return FALSE; | |
114 } | |
115 | |
116 | |
117 function mgCArg($index, $clip = FALSE) | |
118 { | |
119 global $argc, $argv; | |
120 if ($index < $argc) | |
121 { | |
122 $str = $argv[$index]; | |
123 return ($clip !== FALSE) ? substr($str, 0, $clip) : $str; | |
124 } | |
125 else | |
126 return FALSE; | |
127 } | |
128 | |
129 | |
130 function mgCArgLC($index, $clip = FALSE) | |
131 { | |
132 global $argc, $argv; | |
133 if ($index < $argc) | |
134 { | |
135 $str = strtolower($argv[$index]); | |
136 return ($clip !== FALSE) ? substr($str, 0, $clip) : $str; | |
137 } | |
138 else | |
139 return FALSE; | |
140 } | |
141 | |
142 | |
143 function mgGetSetting($key, $default = NULL) | |
144 { | |
145 global $mgSettings, $mgDefaults; | |
146 | |
147 if (!array_key_exists($key, $mgDefaults)) | |
148 mgFatal("Setting '".$key."' does not exist.\n"); | |
149 | |
150 if (array_key_exists($key, $mgSettings)) | |
151 $val = $mgSettings[$key]; | |
152 else | |
153 $val = $mgDefaults[$key][1]; | |
154 | |
155 if (!isset($val) || $val === NULL) | |
156 { | |
157 if ($default !== NULL) | |
158 $val = $default; | |
159 else | |
160 mgFatal("Setting '".$key."' is not set, but is required to be configured.\n"); | |
161 } | |
162 | |
114
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
163 switch ($mgDefaults[$key][0]) |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
164 { |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
165 case MG_FLAGS: |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
166 if (is_string($val)) |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
167 { |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
168 $flags = $mgDefaults[$key][2]; |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
169 $cval = preg_split("/\s*[,|]\s*/", strtolower($val), -1, PREG_SPLIT_NO_EMPTY); |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
170 $nval = 0; |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
171 foreach ($cval as $qval) |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
172 { |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
173 if (array_key_exists($qval, $flags)) |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
174 $nval |= $flags[$qval]; |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
175 else |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
176 mgFatal("Invalid flag value for '".$key."': '".$qval."'."); |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
177 } |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
178 } |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
179 break; |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
180 } |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
181 |
0 | 182 return $val; |
183 } | |
184 | |
185 | |
186 function mgGetPath($path, $key) | |
187 { | |
188 $val = mgGetSetting($key); | |
189 return ($val !== FALSE) ? $path."/".$val : FALSE; | |
190 } | |
191 | |
192 | |
193 function mgReadSettings($filename = "mgallery.cfg") | |
194 { | |
195 global $mgSettings, $mgDefaults; | |
196 | |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
197 $spaths = []; |
0 | 198 $spaths[] = getcwd()."/"; |
199 if (($tmp = getenv("HOME")) !== FALSE && strlen($tmp) > 0) | |
200 { | |
201 $spaths[] = $tmp."/.config/mgallery/"; | |
202 $spaths[] = $tmp."/."; | |
203 } | |
204 else | |
205 { | |
206 $data = posix_getpwuid(posix_getuid()); | |
207 if ($data !== FALSE && isset($data["dir"])) | |
208 { | |
209 $tmp = $data["dir"]; | |
210 $spaths[] = $tmp."/.config/mgallery/"; | |
211 $spaths[] = $tmp."/."; | |
212 } | |
213 } | |
214 $spaths[] = dirname(__FILE__)."/"; | |
215 | |
216 foreach (array_unique($spaths) as $path) | |
217 { | |
218 $file = $path.$filename; | |
219 mgDebug("Checking '".$file."' for configuration ..\n"); | |
220 if (file_exists($file) && | |
221 ($mgSettings = parse_ini_file($file, FALSE)) !== FALSE) | |
222 { | |
223 mgDebug("Found '".$file."' config.\n"); | |
224 | |
225 // Validate settings | |
226 $ok = TRUE; | |
227 foreach ($mgSettings as $setting => $val) | |
228 { | |
229 if (!array_key_exists($setting, $mgDefaults)) | |
230 { | |
231 mgError("Setting '".$setting."' does not exist.\n"); | |
232 $ok = FALSE; | |
233 } | |
234 } | |
235 return $ok; | |
236 } | |
237 } | |
238 | |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
239 $mgSettings = []; |
0 | 240 return FALSE; |
241 } | |
242 | |
243 | |
244 function mgRealPath($path) | |
245 { | |
246 return realpath($path); | |
247 } | |
248 | |
249 | |
250 function mgCleanPathArray($refs, $start, $argc, $argv) | |
251 { | |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
252 $path = []; |
0 | 253 $first = TRUE; |
254 for ($n = $start; $n < $argc; $n++) | |
255 { | |
256 foreach (explode("/", $argv[$n]) as $piece) | |
257 { | |
258 switch ($piece) | |
259 { | |
260 case ".": | |
261 case "": | |
262 if ($first) | |
263 $path[] = $piece; | |
264 break; | |
265 | |
266 case "..": | |
267 if ($refs && count($path) > 0) | |
268 array_pop($path); | |
269 break; | |
270 | |
271 default: | |
272 $path[] = $piece; | |
273 break; | |
274 } | |
275 $first = FALSE; | |
276 } | |
277 } | |
278 return $path; | |
279 } | |
280 | |
281 | |
282 function mgCleanPath($refs) | |
283 { | |
284 return implode("/", mgCleanPathArray($refs, 1, func_num_args(), func_get_args())); | |
285 } | |
286 | |
287 | |
113 | 288 function mgGetTrans($val, $useEntities = FALSE) |
47
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
289 { |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
290 global $pageLang; |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
291 |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
292 if (is_array($val)) |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
293 $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
|
294 else |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
295 $str = $val; |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
296 |
113 | 297 return $useEntities ? chentities($str) : $str; |
47
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
298 } |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
299 |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
300 |
0 | 301 function mgGetArr($data, $skeys, $sfmt1 = "%1", $sfmt2 = "", $func = NULL) |
302 { | |
47
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
303 global $pageLang; |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
304 |
0 | 305 if (!is_array($skeys)) |
306 $skeys = array($skeys); | |
307 | |
308 foreach ($skeys as $skey) | |
309 if (!array_key_exists($skey, $data)) | |
310 return $sfmt2; | |
311 | |
312 $str = $sfmt1; | |
313 for ($i = 1; $i <= sizeof($skeys); $i++) | |
314 { | |
315 $val = $data[$skeys[$i - 1]]; | |
47
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
316 if (is_array($val)) |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
317 $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
|
318 else |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
319 $vtmp = $val; |
0 | 320 |
321 if (is_callable($func)) | |
77
fcfd635d7abf
Oops, fix format string callback functions ..
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
322 $vtmp = call_user_func($func, $vtmp); |
0 | 323 |
47
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
324 $str = str_replace("%".$i, $vtmp, $str); |
0 | 325 } |
326 | |
327 return $str; | |
328 } | |
329 | |
330 | |
114
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
331 function mgGetDValStr($mdef, $val) |
0 | 332 { |
114
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
333 switch ($mdef[0]) |
0 | 334 { |
335 case MG_STR : return "\"".$val."\""; | |
336 case MG_BOOL : return $val ? "yes" : "no"; | |
114
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
337 case MG_FLAGS: |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
338 { |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
339 $mstr = []; |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
340 foreach ($mdef[2] as $vkey => $vval) |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
341 { |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
342 if ($val & $vval) |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
343 $mstr[] = $vkey; |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
344 } |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
345 return implode($mstr, " | "); |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
346 } |
0 | 347 case MG_INT : |
348 default : return (string) $val; | |
349 } | |
350 } | |
351 | |
352 | |
353 ?> |