Mercurial > hg > mgallery
annotate mgallery.inc.php @ 344:0f14a20f48ca
Improve gallery settings validation, etc.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 27 Aug 2023 05:34:20 +0300 |
parents | d6422e856ecd |
children | 9fbec6399cdd |
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> |
326 | 6 // (C) Copyright 2015-2022 Tecnic Software productions (TNSP) |
0 | 7 // |
8 | |
331 | 9 $mgProgVersion = "v0.9.13"; |
0 | 10 $mgProgInfo = "Programmed by Matti 'ccr' Hamalainen"; |
11 $mgProgEmail = "<ccr@tnsp.org>"; | |
326 | 12 $mgProgCopyright = "2015-2022 Tecnic Software productions (TNSP)"; |
0 | 13 |
297
77f85b1f35f2
Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
14 $mgProgConfigFile = "mgallery.cfg"; |
77f85b1f35f2
Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
15 |
274
b1d004a6d3f1
Remove obsolete debug setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
16 $mgalDebug = FALSE; |
0 | 17 |
275 | 18 |
0 | 19 // |
106
a3b8cd4183e6
Change {album,image}_navigation setting to *_flags.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
20 // Navigation control defines |
a3b8cd4183e6
Change {album,image}_navigation setting to *_flags.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
21 // |
136 | 22 define("MGF_JAVASCRIPT" , 0x01); |
23 define("MGF_BREADCRUMBS" , 0x10); | |
24 define("MGF_CAPTIONS" , 0x20); | |
106
a3b8cd4183e6
Change {album,image}_navigation setting to *_flags.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
25 |
a3b8cd4183e6
Change {album,image}_navigation setting to *_flags.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
26 // |
0 | 27 // Constants for different value types |
28 // | |
136 | 29 define("MG_STR" , 1); |
303
6bb434968623
Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents:
298
diff
changeset
|
30 define("MG_STR_LC" , 2); |
322
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
318
diff
changeset
|
31 define("MG_STR_ARRAY" , 3); |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
318
diff
changeset
|
32 define("MG_INT" , 4); |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
318
diff
changeset
|
33 define("MG_DVA" , 5); |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
318
diff
changeset
|
34 define("MG_BOOL" , 6); |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
318
diff
changeset
|
35 define("MG_FLAGS" , 7); |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
318
diff
changeset
|
36 define("MG_DATE" , 8); |
344
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
37 define("MG_CALLABLE" , 9); |
0 | 38 |
344
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
39 $mgValueTypes = [ |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
40 MG_STR => "string", |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
41 MG_STR_LC => "string lc", |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
42 MG_STR_ARRAY => "string array", |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
43 MG_INT => "int", |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
44 MG_DVA => "dva", |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
45 MG_BOOL => "bool", |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
46 MG_FLAGS => "flags", |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
47 MG_DATE => "date", |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
48 MG_CALLABLE => "callable", |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
49 ]; |
0 | 50 |
51 | |
114
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
52 $mgGFlags = [ |
136 | 53 "javascript" => MGF_JAVASCRIPT, |
54 "breadcrumbs" => MGF_BREADCRUMBS, | |
55 "captions" => MGF_CAPTIONS, | |
114
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
56 ]; |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
57 |
c803235bd0f9
Implement flag config option type.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
58 |
0 | 59 function mgPathName($path) |
60 { | |
61 $tmp = mgCleanPathArray(TRUE, 0, func_num_args(), func_get_args()); | |
62 if (count($tmp) > 0) | |
63 return implode("/", array_splice($tmp, 0, -1))."/"; | |
64 else | |
65 return $path; | |
66 } | |
67 | |
322
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
318
diff
changeset
|
68 |
0 | 69 // |
70 // Configuration settings and their default values | |
71 // | |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
72 $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
|
73 "timezone" => [MG_STR, NULL], |
0 | 74 |
141
18061527d1cd
Reorder some settings in configuration data.
Matti Hamalainen <ccr@tnsp.org>
parents:
137
diff
changeset
|
75 "clean_urls" => [MG_BOOL, FALSE], |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
76 "base_path" => [MG_STR, mgPathName(mgRealPath($_SERVER["SCRIPT_FILENAME"]))], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
77 "base_url" => [MG_STR, mgPathName($_SERVER["PHP_SELF"])], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
78 "image_url" => [MG_STR, mgPathName($_SERVER["PHP_SELF"])], |
324
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
79 "mgallery_php" => [MG_STR, ""], |
250
3af3b3f50cb0
Add settings for med_format and tn_format (currently allowed values are
Matti Hamalainen <ccr@tnsp.org>
parents:
241
diff
changeset
|
80 "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
|
81 "captions_file" => [MG_STR, "captions.txt"], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
82 "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
|
83 "info_file" => [MG_STR, "mgallery.info"], |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
84 "cache_file" => [MG_STR, ".mgallery.cache"], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
85 |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
86 "cover_images" => [MG_BOOL, TRUE], |
324
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
87 "album_icon" => [MG_STR, NULL], |
141
18061527d1cd
Reorder some settings in configuration data.
Matti Hamalainen <ccr@tnsp.org>
parents:
137
diff
changeset
|
88 |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
89 "title_prefix" => [MG_STR, ""], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
90 "title_sep" => [MG_STR, " - "], |
224 | 91 "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
|
92 |
322
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
318
diff
changeset
|
93 "css" => [MG_STR_ARRAY, NULL], |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
318
diff
changeset
|
94 "js_file" => [MG_STR_ARRAY, NULL], |
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
318
diff
changeset
|
95 "urchin_file" => [MG_STR_ARRAY, FALSE], |
0 | 96 |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
97 "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
|
98 "image_flags" => [MG_FLAGS, MGF_JAVASCRIPT | MGF_BREADCRUMBS, &$mgGFlags], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
99 "album_flags" => [MG_FLAGS, MGF_JAVASCRIPT | MGF_BREADCRUMBS, &$mgGFlags], |
0 | 100 |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
101 "tn_path" => [MG_STR, "tn/"], |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
102 "med_path" => [MG_STR, "med/"], |
0 | 103 |
303
6bb434968623
Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents:
298
diff
changeset
|
104 "tn_format" => [MG_STR_LC, "jpeg"], |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
105 "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
|
106 "tn_height" => [MG_INT, 100], |
289
13cff35dfbec
Change default thumbnail/medium formats from JPEG to WEBP.
Matti Hamalainen <ccr@tnsp.org>
parents:
285
diff
changeset
|
107 "tn_quality" => [MG_INT, 90], // JPEG/WEBP quality percent |
0 | 108 |
303
6bb434968623
Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents:
298
diff
changeset
|
109 "med_format" => [MG_STR_LC, "jpeg"], |
324
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
110 "med_width" => [MG_INT, 1200], |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
111 "med_height" => [MG_INT, 900], |
162
3c2674dbd185
Increase the generated mid- and thumbnail images JPEG quality slightly.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
112 "med_quality" => [MG_INT, 90], |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
113 ]; |
0 | 114 |
115 | |
344
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
116 // |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
117 // Gallery album settings |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
118 // |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
119 $mgAlbumDefaults = [ |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
120 "show_keywords" => [MG_CALLABLE, FALSE, "mgParseShowKeywords"], |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
121 "hide" => [MG_BOOL, FALSE], |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
122 "hide_contents" => [MG_BOOL, FALSE], |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
123 "albumpic" => [MG_STR, FALSE], |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
124 "tn_format" => [MG_STR_LC, "jpeg"], |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
125 "med_format" => [MG_STR_LC, "jpeg"], |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
126 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
127 "header" => [MG_STR_ARRAY, FALSE], |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
128 "caption" => [MG_STR_ARRAY, FALSE], |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
129 "title" => [MG_STR_ARRAY, FALSE], |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
130 ]; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
131 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
132 |
0 | 133 function mgDebug($msg) |
134 { | |
274
b1d004a6d3f1
Remove obsolete debug setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
135 global $mgalDebug; |
b1d004a6d3f1
Remove obsolete debug setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
136 if ($mgalDebug) |
b1d004a6d3f1
Remove obsolete debug setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
137 { |
275 | 138 echo "<p>MGAL[debug]: ".htmlspecialchars($msg)."</p>"; |
274
b1d004a6d3f1
Remove obsolete debug setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
139 error_log("MGAL[debug]: ".$msg); |
b1d004a6d3f1
Remove obsolete debug setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
140 } |
0 | 141 } |
142 | |
143 | |
144 function mgFatal($msg) | |
145 { | |
146 die("MGAL[fatal]: ".$msg); | |
147 } | |
148 | |
149 | |
150 function mgError($msg) | |
151 { | |
275 | 152 error_log("MGAL[error]: ".$msg); |
0 | 153 return FALSE; |
154 } | |
155 | |
156 | |
157 function mgCArg($index, $clip = FALSE) | |
158 { | |
159 global $argc, $argv; | |
160 if ($index < $argc) | |
161 { | |
162 $str = $argv[$index]; | |
163 return ($clip !== FALSE) ? substr($str, 0, $clip) : $str; | |
164 } | |
165 else | |
166 return FALSE; | |
167 } | |
168 | |
169 | |
170 function mgCArgLC($index, $clip = FALSE) | |
171 { | |
172 global $argc, $argv; | |
173 if ($index < $argc) | |
174 { | |
175 $str = strtolower($argv[$index]); | |
176 return ($clip !== FALSE) ? substr($str, 0, $clip) : $str; | |
177 } | |
178 else | |
179 return FALSE; | |
180 } | |
181 | |
182 | |
183 function mgGetSetting($key, $default = NULL) | |
184 { | |
185 global $mgSettings, $mgDefaults; | |
186 | |
187 if (!array_key_exists($key, $mgDefaults)) | |
188 mgFatal("Setting '".$key."' does not exist.\n"); | |
189 | |
190 if (array_key_exists($key, $mgSettings)) | |
191 $val = $mgSettings[$key]; | |
192 else | |
193 $val = $mgDefaults[$key][1]; | |
194 | |
195 if (!isset($val) || $val === NULL) | |
196 { | |
197 if ($default !== NULL) | |
198 $val = $default; | |
199 else | |
200 mgFatal("Setting '".$key."' is not set, but is required to be configured.\n"); | |
201 } | |
202 | |
203 return $val; | |
204 } | |
205 | |
206 | |
293
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
290
diff
changeset
|
207 function mgGetAlbumSetting(&$data, $key, $default = NULL) |
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
290
diff
changeset
|
208 { |
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
290
diff
changeset
|
209 if (array_key_exists($key, $data)) |
305
b816e80bc002
Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
210 $val = $data[$key]; |
293
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
290
diff
changeset
|
211 else |
305
b816e80bc002
Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
212 $val = mgGetSetting($key, $default); |
b816e80bc002
Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
213 |
b816e80bc002
Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
214 // XXX This is a rather silly place for this check, but since any album can |
b816e80bc002
Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
215 // set their own formats, we can't do this check globally without scanning |
b816e80bc002
Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
216 // all the sub-albums etc .. maybe we'll do that some day. |
b816e80bc002
Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
217 if (($key == "tn_format" || $key == "med_format") && |
b816e80bc002
Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
218 $val == "webp" && version_compare(PHP_VERSION, "7.1.0") < 0) |
b816e80bc002
Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
219 { |
307
a09452ac196e
Improve WebP PHP 7.1 requirement error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
306
diff
changeset
|
220 mgFatal("WebP image format support requires PHP version 7.1 or later.\n"); |
305
b816e80bc002
Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
221 } |
b816e80bc002
Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
222 |
b816e80bc002
Add a check for that we are running on PHP 7.1 or later if WebP format images are being used.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
223 return $val; |
293
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
290
diff
changeset
|
224 } |
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
290
diff
changeset
|
225 |
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
290
diff
changeset
|
226 |
0 | 227 function mgGetPath($path, $key) |
228 { | |
229 $val = mgGetSetting($key); | |
230 return ($val !== FALSE) ? $path."/".$val : FALSE; | |
231 } | |
232 | |
233 | |
344
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
234 function mgParseShowKeywords($val) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
235 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
236 return preg_split("/\s*[,|]\s*/", $val, -1, PREG_SPLIT_NO_EMPTY); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
237 } |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
238 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
239 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
240 function mgInvalidType(&$defaults, $key, $val) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
241 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
242 global $mgValueTypes; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
243 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
244 mgFatal("Invalid value type '".gettype($val)."' for setting '".$key."', expected '". |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
245 $mgValueTypes[$defaults[$key][0]]."', value: '".$val."'.\n"); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
246 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
247 return FALSE; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
248 } |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
249 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
250 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
251 function mgParseConfigSetting(&$settings, &$defaults, $key, $val) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
252 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
253 if (!array_key_exists($key, $defaults)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
254 return mgFatal("Unknown setting key '".$key."'.\n"); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
255 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
256 switch ($defaults[$key][0]) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
257 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
258 case MG_STR: |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
259 if (!is_string($val)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
260 return mgInvalidType($defaults, $key, $val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
261 break; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
262 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
263 case MG_STR_LC: |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
264 if (!is_string($val)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
265 return mgInvalidType($defaults, $key, $val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
266 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
267 $val = strtolower($val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
268 break; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
269 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
270 case MG_STR_ARRAY: |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
271 if (is_string($val)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
272 $val = array($val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
273 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
274 if (!is_array($val)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
275 return mgInvalidType($defaults, $key, $val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
276 break; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
277 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
278 case MG_INT: |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
279 if (!is_int($val)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
280 return mgInvalidType($defaults, $key, $val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
281 break; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
282 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
283 case MG_BOOL: |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
284 if (is_string($val)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
285 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
286 switch (strtolower(trim($val))) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
287 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
288 case "yes": case "on": case "true": case "1": |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
289 $val = true; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
290 break; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
291 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
292 case "no": case "off": case "false": case "0": |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
293 $val = false; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
294 break; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
295 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
296 default: |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
297 mgInvalidType($defaults, $key, $val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
298 } |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
299 } |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
300 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
301 if (!is_bool($val) && !is_int($val)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
302 return mgInvalidType($defaults, $key, $val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
303 break; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
304 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
305 case MG_FLAGS: |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
306 if (is_string($val)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
307 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
308 $flags = $mgDefaults[$key][2]; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
309 $cval = preg_split("/\s*[,|]\s*/", strtolower($val), -1, PREG_SPLIT_NO_EMPTY); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
310 $nval = 0; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
311 foreach ($cval as $qval) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
312 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
313 if (array_key_exists($qval, $flags)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
314 $nval |= $flags[$qval]; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
315 else |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
316 return mgFatal("Invalid flag value for '".$key."': '".$qval."'."); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
317 } |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
318 $val = $nval; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
319 } else |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
320 return mgInvalidType($defaults, $key, $val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
321 break; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
322 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
323 case MG_CALLABLE: |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
324 if (!is_callable($defaults[$key][2])) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
325 return mgInvalidType($defaults, $key, $val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
326 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
327 $val = call_user_func($defaults[$key][2], $val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
328 break; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
329 } |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
330 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
331 $settings[$key] = $val; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
332 return TRUE; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
333 } |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
334 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
335 |
324
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
336 function mgReadOneConfig(&$searchPaths, $pathList) |
0 | 337 { |
344
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
338 global $mgSettings, $mgDefaults, $mgProgConfigFile; |
324
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
339 $found = FALSE; |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
340 |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
341 foreach (array_unique($pathList) as $path) |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
342 { |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
343 $filename = $path.$mgProgConfigFile; |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
344 $searchPaths[] = $filename; |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
345 |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
346 if (!$found) |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
347 { |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
348 mgDebug("Checking '".$filename."' for configuration ..\n"); |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
349 |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
350 if (file_exists($filename) && |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
351 ($data = parse_ini_file($filename, FALSE)) !== FALSE) |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
352 { |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
353 mgDebug("Found '".$filename."' config.\n"); |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
354 foreach ($data as $dkey => &$dval) |
344
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
355 mgParseConfigSetting($mgSettings, $mgDefaults, $dkey, $dval); |
0 | 356 |
324
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
357 $found = TRUE; |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
358 } |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
359 } |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
360 } |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
361 |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
362 return $found; |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
363 } |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
364 |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
365 |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
366 function mgReadSettings(&$searchPaths) |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
367 { |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
368 global $mgSettings; |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
369 $mgSettings = []; |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
370 $searchPaths = []; |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
371 |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
372 // System-wide |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
373 $ok = mgReadOneConfig($searchPaths, ["/etc/", "/usr/local/etc/"]); |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
374 |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
375 // User-specific |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
376 $spaths = []; |
0 | 377 if (($tmp = getenv("HOME")) !== FALSE && strlen($tmp) > 0) |
378 { | |
379 $spaths[] = $tmp."/.config/mgallery/"; | |
380 $spaths[] = $tmp."/."; | |
381 } | |
382 else | |
383 { | |
384 $data = posix_getpwuid(posix_getuid()); | |
385 if ($data !== FALSE && isset($data["dir"])) | |
386 { | |
387 $tmp = $data["dir"]; | |
388 $spaths[] = $tmp."/.config/mgallery/"; | |
389 $spaths[] = $tmp."/."; | |
390 } | |
391 } | |
324
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
392 $ok |= mgReadOneConfig($searchPaths, $spaths); |
297
77f85b1f35f2
Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
393 |
324
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
394 // Album/directory-local |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
395 $ok |= mgReadOneConfig($searchPaths, [ dirname(__FILE__)."/", getcwd()."/" ]); |
0 | 396 |
324
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
397 $searchPaths = array_unique($searchPaths); |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
398 return $ok; |
0 | 399 } |
400 | |
401 | |
402 function mgRealPath($path) | |
403 { | |
404 return realpath($path); | |
405 } | |
406 | |
407 | |
285
25324e33fc78
Refactor gallery path handling somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
408 function mgCleanPathStr($path) |
25324e33fc78
Refactor gallery path handling somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
409 { |
25324e33fc78
Refactor gallery path handling somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
410 return str_replace("//", "/", $path); |
25324e33fc78
Refactor gallery path handling somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
411 } |
25324e33fc78
Refactor gallery path handling somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
412 |
25324e33fc78
Refactor gallery path handling somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
413 |
0 | 414 function mgCleanPathArray($refs, $start, $argc, $argv) |
415 { | |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
416 $path = []; |
0 | 417 $first = TRUE; |
418 for ($n = $start; $n < $argc; $n++) | |
419 { | |
420 foreach (explode("/", $argv[$n]) as $piece) | |
421 { | |
422 switch ($piece) | |
423 { | |
424 case ".": | |
425 case "": | |
426 if ($first) | |
427 $path[] = $piece; | |
428 break; | |
429 | |
430 case "..": | |
431 if ($refs && count($path) > 0) | |
432 array_pop($path); | |
433 break; | |
434 | |
435 default: | |
436 $path[] = $piece; | |
437 break; | |
438 } | |
439 $first = FALSE; | |
440 } | |
441 } | |
285
25324e33fc78
Refactor gallery path handling somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
442 return mgCleanPathStr($path); |
0 | 443 } |
444 | |
445 | |
446 function mgCleanPath($refs) | |
447 { | |
448 return implode("/", mgCleanPathArray($refs, 1, func_num_args(), func_get_args())); | |
449 } | |
450 | |
451 | |
452 function mgGetArr($data, $skeys, $sfmt1 = "%1", $sfmt2 = "", $func = NULL) | |
453 { | |
47
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
454 global $pageLang; |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
455 |
0 | 456 if (!is_array($skeys)) |
457 $skeys = array($skeys); | |
458 | |
459 foreach ($skeys as $skey) | |
344
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
460 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
461 if (!array_key_exists($skey, $data)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
462 return $sfmt2; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
463 } |
0 | 464 |
465 $str = $sfmt1; | |
466 for ($i = 1; $i <= sizeof($skeys); $i++) | |
467 { | |
468 $val = $data[$skeys[$i - 1]]; | |
47
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
469 if (is_array($val)) |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
470 $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
|
471 else |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
472 $vtmp = $val; |
0 | 473 |
474 if (is_callable($func)) | |
77
fcfd635d7abf
Oops, fix format string callback functions ..
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
475 $vtmp = call_user_func($func, $vtmp); |
0 | 476 |
47
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
477 $str = str_replace("%".$i, $vtmp, $str); |
0 | 478 } |
479 | |
480 return $str; | |
481 } | |
482 | |
483 | |
484 ?> |