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