annotate mgallery.inc.php @ 280:8297c895f22e

Remove the obsolete code for checking undefined config settings completely.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 16 May 2019 21:48:24 +0300
parents 6770ef8b3575
children 25324e33fc78
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 <?php
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
007921f59d98 Bump copyright version.
Matti Hamalainen <ccr@tnsp.org>
parents: 267
diff changeset
6 // (C) Copyright 2015-2019 Tecnic Software productions (TNSP)
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
266
92ce2185bbb3 Bump version.
Matti Hamalainen <ccr@tnsp.org>
parents: 259
diff changeset
9 $mgProgVersion = "v0.9.8";
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 $mgProgInfo = "Programmed by Matti 'ccr' Hamalainen";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 $mgProgEmail = "<ccr@tnsp.org>";
272
007921f59d98 Bump copyright version.
Matti Hamalainen <ccr@tnsp.org>
parents: 267
diff changeset
12 $mgProgCopyright = "2015-2019 Tecnic Software productions (TNSP)";
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
274
b1d004a6d3f1 Remove obsolete debug setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
14 $mgalDebug = FALSE;
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
275
bc7bda1d1410 Comments and cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 274
diff changeset
16
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
20 define("MGF_JAVASCRIPT" , 0x01);
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
21 define("MGF_BREADCRUMBS" , 0x10);
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 // Constants for different value types
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 //
136
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
27 define("MG_STR" , 1);
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
28 define("MG_INT" , 2);
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
29 define("MG_DVA" , 3);
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
30 define("MG_BOOL" , 4);
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
31 define("MG_FLAGS" , 5);
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
32 define("MG_DATE" , 6);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
136
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
35 define("yes" , 1);
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
36 define("no" , 0);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
114
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
39 $mgGFlags = [
136
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
40 "javascript" => MGF_JAVASCRIPT,
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
41 "breadcrumbs" => MGF_BREADCRUMBS,
b1134ff9256b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 function mgPathName($path)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 $tmp = mgCleanPathArray(TRUE, 0, func_num_args(), func_get_args());
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 if (count($tmp) > 0)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 return implode("/", array_splice($tmp, 0, -1))."/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 return $path;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 //
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 // Configuration settings and their default values
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
77e72455c99f "Powered by MGallery" ..
Matti Hamalainen <ccr@tnsp.org>
parents: 219
diff changeset
77 "page_info" => [MG_STR, "Powered by <b>MGallery ".$mgProgVersion."</b> &copy; 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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
bc7bda1d1410 Comments and cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 274
diff changeset
93 "tn_quality" => [MG_INT, 85], // JPEG/WEBP quality percent
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
f3098855ad58 Add debug option setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 185
diff changeset
99
127
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
100 ];
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 function mgDebug($msg)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
bc7bda1d1410 Comments and cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 274
diff changeset
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 function mgFatal($msg)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 die("MGAL[fatal]: ".$msg);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 function mgError($msg)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 {
275
bc7bda1d1410 Comments and cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 274
diff changeset
122 error_log("MGAL[error]: ".$msg);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 return FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 function mgCArg($index, $clip = FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 global $argc, $argv;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 if ($index < $argc)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 $str = $argv[$index];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 return ($clip !== FALSE) ? substr($str, 0, $clip) : $str;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 return FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 function mgCArgLC($index, $clip = FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 global $argc, $argv;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 if ($index < $argc)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 $str = strtolower($argv[$index]);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 return ($clip !== FALSE) ? substr($str, 0, $clip) : $str;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 return FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 function mgGetSetting($key, $default = NULL)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 global $mgSettings, $mgDefaults;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 if (!array_key_exists($key, $mgDefaults))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 mgFatal("Setting '".$key."' does not exist.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 if (array_key_exists($key, $mgSettings))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 $val = $mgSettings[$key];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 $val = $mgDefaults[$key][1];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 if (!isset($val) || $val === NULL)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 if ($default !== NULL)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 $val = $default;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 mgFatal("Setting '".$key."' is not set, but is required to be configured.\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 return $val;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 function mgGetPath($path, $key)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 $val = mgGetSetting($key);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 return ($val !== FALSE) ? $path."/".$val : FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 function mgReadSettings($filename = "mgallery.cfg")
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 global $mgSettings, $mgDefaults;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206
127
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
207 $spaths = [];
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 $spaths[] = getcwd()."/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 if (($tmp = getenv("HOME")) !== FALSE && strlen($tmp) > 0)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 $spaths[] = $tmp."/.config/mgallery/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 $spaths[] = $tmp."/.";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 else
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 $data = posix_getpwuid(posix_getuid());
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 if ($data !== FALSE && isset($data["dir"]))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 $tmp = $data["dir"];
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 $spaths[] = $tmp."/.config/mgallery/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 $spaths[] = $tmp."/.";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 $spaths[] = dirname(__FILE__)."/";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 foreach (array_unique($spaths) as $path)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 $file = $path.$filename;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 mgDebug("Checking '".$file."' for configuration ..\n");
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 if (file_exists($file) &&
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 ($mgSettings = parse_ini_file($file, FALSE)) !== FALSE)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237
127
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
238 $mgSettings = [];
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 return FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 function mgRealPath($path)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 return realpath($path);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 function mgCleanPathArray($refs, $start, $argc, $argv)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 {
127
3ee66c432081 Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
251 $path = [];
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 $first = TRUE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 for ($n = $start; $n < $argc; $n++)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 foreach (explode("/", $argv[$n]) as $piece)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 switch ($piece)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 case ".":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 case "":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 if ($first)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 $path[] = $piece;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 case "..":
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 if ($refs && count($path) > 0)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 array_pop($path);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 default:
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 $path[] = $piece;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 break;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 $first = FALSE;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 return $path;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 function mgCleanPath($refs)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 return implode("/", mgCleanPathArray($refs, 1, func_num_args(), func_get_args()));
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 function mgGetArr($data, $skeys, $sfmt1 = "%1", $sfmt2 = "", $func = NULL)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 {
47
1e2b55775a84 Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
289 global $pageLang;
1e2b55775a84 Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
290
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 if (!is_array($skeys))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 $skeys = array($skeys);
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 foreach ($skeys as $skey)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 if (!array_key_exists($skey, $data))
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 return $sfmt2;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 $str = $sfmt1;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 for ($i = 1; $i <= sizeof($skeys); $i++)
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 $val = $data[$skeys[$i - 1]];
47
1e2b55775a84 Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
302 if (is_array($val))
1e2b55775a84 Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
303 $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
304 else
1e2b55775a84 Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
305 $vtmp = $val;
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 if (is_callable($func))
77
fcfd635d7abf Oops, fix format string callback functions ..
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
308 $vtmp = call_user_func($func, $vtmp);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309
47
1e2b55775a84 Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
310 $str = str_replace("%".$i, $vtmp, $str);
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 return $str;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316
114
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
317 function mgGetDValStr($mdef, $val)
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 {
114
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
319 switch ($mdef[0])
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 {
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 case MG_STR : return "\"".$val."\"";
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 case MG_BOOL : return $val ? "yes" : "no";
114
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
323 case MG_FLAGS:
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
324 {
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
325 $mstr = [];
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
326 foreach ($mdef[2] as $vkey => $vval)
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
327 {
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
328 if ($val & $vval)
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
329 $mstr[] = $vkey;
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 return implode($mstr, " | ");
c803235bd0f9 Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
332 }
0
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 case MG_INT :
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334 default : return (string) $val;
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 }
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337
ac688606ec4b Initial import of code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 ?>