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