Mercurial > hg > mgallery
annotate mgallery.inc.php @ 348:596196f2b0c5 default tip
Improve relative URL translation in header text blobs.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 20 Dec 2023 09:17:55 +0200 |
parents | 7da360685721 |
children |
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> |
345 | 6 // (C) Copyright 2015-2023 Tecnic Software productions (TNSP) |
0 | 7 // |
8 | |
346 | 9 $mgProgVersion = "v0.9.14"; |
0 | 10 $mgProgInfo = "Programmed by Matti 'ccr' Hamalainen"; |
11 $mgProgEmail = "<ccr@tnsp.org>"; | |
345 | 12 $mgProgCopyright = "2015-2023 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], |
347
7da360685721
Implement show_keywords setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
346
diff
changeset
|
88 "show_keywords" => [MG_CALLABLE, FALSE, "mgParseShowKeywords"], |
141
18061527d1cd
Reorder some settings in configuration data.
Matti Hamalainen <ccr@tnsp.org>
parents:
137
diff
changeset
|
89 |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
90 "title_prefix" => [MG_STR, ""], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
91 "title_sep" => [MG_STR, " - "], |
224 | 92 "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
|
93 |
322
2f4e3e458714
Improve configuration handling, and add "string array" configuration item type.
Matti Hamalainen <ccr@tnsp.org>
parents:
318
diff
changeset
|
94 "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
|
95 "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
|
96 "urchin_file" => [MG_STR_ARRAY, FALSE], |
0 | 97 |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
98 "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
|
99 "image_flags" => [MG_FLAGS, MGF_JAVASCRIPT | MGF_BREADCRUMBS, &$mgGFlags], |
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
100 "album_flags" => [MG_FLAGS, MGF_JAVASCRIPT | MGF_BREADCRUMBS, &$mgGFlags], |
0 | 101 |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
102 "tn_path" => [MG_STR, "tn/"], |
185
cb7019690a73
Separate medium image and thumbnail directories / handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
103 "med_path" => [MG_STR, "med/"], |
0 | 104 |
303
6bb434968623
Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents:
298
diff
changeset
|
105 "tn_format" => [MG_STR_LC, "jpeg"], |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
106 "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
|
107 "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
|
108 "tn_quality" => [MG_INT, 90], // JPEG/WEBP quality percent |
0 | 109 |
303
6bb434968623
Add new MG_STR_LC setting type, which is string but automatically lowercased.
Matti Hamalainen <ccr@tnsp.org>
parents:
298
diff
changeset
|
110 "med_format" => [MG_STR_LC, "jpeg"], |
324
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
111 "med_width" => [MG_INT, 1200], |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
112 "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
|
113 "med_quality" => [MG_INT, 90], |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
114 ]; |
0 | 115 |
116 | |
344
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
117 // |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
118 // Gallery album settings |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
119 // |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
120 $mgAlbumDefaults = [ |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
121 "show_keywords" => [MG_CALLABLE, FALSE, "mgParseShowKeywords"], |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
122 "hide" => [MG_BOOL, FALSE], |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
123 "hide_contents" => [MG_BOOL, FALSE], |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
124 "albumpic" => [MG_STR, FALSE], |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
125 "tn_format" => [MG_STR_LC, "jpeg"], |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
126 "med_format" => [MG_STR_LC, "jpeg"], |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
127 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
128 "header" => [MG_STR_ARRAY, FALSE], |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
129 "caption" => [MG_STR_ARRAY, FALSE], |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
130 "title" => [MG_STR_ARRAY, FALSE], |
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 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
133 |
0 | 134 function mgDebug($msg) |
135 { | |
274
b1d004a6d3f1
Remove obsolete debug setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
136 global $mgalDebug; |
b1d004a6d3f1
Remove obsolete debug setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
137 if ($mgalDebug) |
b1d004a6d3f1
Remove obsolete debug setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
138 { |
275 | 139 echo "<p>MGAL[debug]: ".htmlspecialchars($msg)."</p>"; |
274
b1d004a6d3f1
Remove obsolete debug setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
140 error_log("MGAL[debug]: ".$msg); |
b1d004a6d3f1
Remove obsolete debug setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
141 } |
0 | 142 } |
143 | |
144 | |
145 function mgFatal($msg) | |
146 { | |
147 die("MGAL[fatal]: ".$msg); | |
148 } | |
149 | |
150 | |
151 function mgError($msg) | |
152 { | |
275 | 153 error_log("MGAL[error]: ".$msg); |
0 | 154 return FALSE; |
155 } | |
156 | |
157 | |
158 function mgCArg($index, $clip = FALSE) | |
159 { | |
160 global $argc, $argv; | |
161 if ($index < $argc) | |
162 { | |
163 $str = $argv[$index]; | |
164 return ($clip !== FALSE) ? substr($str, 0, $clip) : $str; | |
165 } | |
166 else | |
167 return FALSE; | |
168 } | |
169 | |
170 | |
171 function mgCArgLC($index, $clip = FALSE) | |
172 { | |
173 global $argc, $argv; | |
174 if ($index < $argc) | |
175 { | |
176 $str = strtolower($argv[$index]); | |
177 return ($clip !== FALSE) ? substr($str, 0, $clip) : $str; | |
178 } | |
179 else | |
180 return FALSE; | |
181 } | |
182 | |
183 | |
184 function mgGetSetting($key, $default = NULL) | |
185 { | |
186 global $mgSettings, $mgDefaults; | |
187 | |
188 if (!array_key_exists($key, $mgDefaults)) | |
189 mgFatal("Setting '".$key."' does not exist.\n"); | |
190 | |
191 if (array_key_exists($key, $mgSettings)) | |
192 $val = $mgSettings[$key]; | |
193 else | |
194 $val = $mgDefaults[$key][1]; | |
195 | |
196 if (!isset($val) || $val === NULL) | |
197 { | |
198 if ($default !== NULL) | |
199 $val = $default; | |
200 else | |
201 mgFatal("Setting '".$key."' is not set, but is required to be configured.\n"); | |
202 } | |
203 | |
204 return $val; | |
205 } | |
206 | |
207 | |
293
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
290
diff
changeset
|
208 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
|
209 { |
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
290
diff
changeset
|
210 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
|
211 $val = $data[$key]; |
293
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
290
diff
changeset
|
212 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
|
213 $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
|
214 |
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 // 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
|
216 // 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
|
217 // 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
|
218 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
|
219 $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
|
220 { |
307
a09452ac196e
Improve WebP PHP 7.1 requirement error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
306
diff
changeset
|
221 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
|
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 |
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
|
224 return $val; |
293
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 |
486398fb60ea
Allow album-specific {tn,med}_{width,height,format} settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
290
diff
changeset
|
227 |
0 | 228 function mgGetPath($path, $key) |
229 { | |
230 $val = mgGetSetting($key); | |
231 return ($val !== FALSE) ? $path."/".$val : FALSE; | |
232 } | |
233 | |
234 | |
344
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
235 function mgParseShowKeywords($val) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
236 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
237 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
|
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 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
241 function mgInvalidType(&$defaults, $key, $val) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
242 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
243 global $mgValueTypes; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
244 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
245 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
|
246 $mgValueTypes[$defaults[$key][0]]."', value: '".$val."'.\n"); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
247 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
248 return FALSE; |
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 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
252 function mgParseConfigSetting(&$settings, &$defaults, $key, $val) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
253 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
254 if (!array_key_exists($key, $defaults)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
255 return mgFatal("Unknown setting key '".$key."'.\n"); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
256 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
257 switch ($defaults[$key][0]) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
258 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
259 case MG_STR: |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
260 if (!is_string($val)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
261 return mgInvalidType($defaults, $key, $val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
262 break; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
263 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
264 case MG_STR_LC: |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
265 if (!is_string($val)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
266 return mgInvalidType($defaults, $key, $val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
267 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
268 $val = strtolower($val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
269 break; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
270 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
271 case MG_STR_ARRAY: |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
272 if (is_string($val)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
273 $val = array($val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
274 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
275 if (!is_array($val)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
276 return mgInvalidType($defaults, $key, $val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
277 break; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
278 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
279 case MG_INT: |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
280 if (!is_int($val)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
281 return mgInvalidType($defaults, $key, $val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
282 break; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
283 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
284 case MG_BOOL: |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
285 if (is_string($val)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
286 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
287 switch (strtolower(trim($val))) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
288 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
289 case "yes": case "on": case "true": case "1": |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
290 $val = true; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
291 break; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
292 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
293 case "no": case "off": case "false": case "0": |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
294 $val = false; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
295 break; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
296 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
297 default: |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
298 mgInvalidType($defaults, $key, $val); |
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 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
302 if (!is_bool($val) && !is_int($val)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
303 return mgInvalidType($defaults, $key, $val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
304 break; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
305 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
306 case MG_FLAGS: |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
307 if (is_string($val)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
308 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
309 $flags = $mgDefaults[$key][2]; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
310 $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
|
311 $nval = 0; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
312 foreach ($cval as $qval) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
313 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
314 if (array_key_exists($qval, $flags)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
315 $nval |= $flags[$qval]; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
316 else |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
317 return mgFatal("Invalid flag value for '".$key."': '".$qval."'."); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
318 } |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
319 $val = $nval; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
320 } else |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
321 return mgInvalidType($defaults, $key, $val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
322 break; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
323 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
324 case MG_CALLABLE: |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
325 if (!is_callable($defaults[$key][2])) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
326 return mgInvalidType($defaults, $key, $val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
327 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
328 $val = call_user_func($defaults[$key][2], $val); |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
329 break; |
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 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
332 $settings[$key] = $val; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
333 return TRUE; |
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 |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
336 |
324
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
337 function mgReadOneConfig(&$searchPaths, $pathList) |
0 | 338 { |
344
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
339 global $mgSettings, $mgDefaults, $mgProgConfigFile; |
324
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
340 $found = FALSE; |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
341 |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
342 foreach (array_unique($pathList) as $path) |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
343 { |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
344 $filename = $path.$mgProgConfigFile; |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
345 $searchPaths[] = $filename; |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
346 |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
347 if (!$found) |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
348 { |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
349 mgDebug("Checking '".$filename."' for configuration ..\n"); |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
350 |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
351 if (file_exists($filename) && |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
352 ($data = parse_ini_file($filename, FALSE)) !== FALSE) |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
353 { |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
354 mgDebug("Found '".$filename."' config.\n"); |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
355 foreach ($data as $dkey => &$dval) |
344
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
356 mgParseConfigSetting($mgSettings, $mgDefaults, $dkey, $dval); |
0 | 357 |
324
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
358 $found = TRUE; |
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 |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
363 return $found; |
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 |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
367 function mgReadSettings(&$searchPaths) |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
368 { |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
369 global $mgSettings; |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
370 $mgSettings = []; |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
371 $searchPaths = []; |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
372 |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
373 // System-wide |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
374 $ok = mgReadOneConfig($searchPaths, ["/etc/", "/usr/local/etc/"]); |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
375 |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
376 // User-specific |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
377 $spaths = []; |
0 | 378 if (($tmp = getenv("HOME")) !== FALSE && strlen($tmp) > 0) |
379 { | |
380 $spaths[] = $tmp."/.config/mgallery/"; | |
381 $spaths[] = $tmp."/."; | |
382 } | |
383 else | |
384 { | |
385 $data = posix_getpwuid(posix_getuid()); | |
386 if ($data !== FALSE && isset($data["dir"])) | |
387 { | |
388 $tmp = $data["dir"]; | |
389 $spaths[] = $tmp."/.config/mgallery/"; | |
390 $spaths[] = $tmp."/."; | |
391 } | |
392 } | |
324
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
393 $ok |= mgReadOneConfig($searchPaths, $spaths); |
297
77f85b1f35f2
Improve configuration file handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
394 |
324
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
395 // Album/directory-local |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
396 $ok |= mgReadOneConfig($searchPaths, [ dirname(__FILE__)."/", getcwd()."/" ]); |
0 | 397 |
324
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
398 $searchPaths = array_unique($searchPaths); |
d598b2320878
Improvements and fixes to configuration handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
322
diff
changeset
|
399 return $ok; |
0 | 400 } |
401 | |
402 | |
403 function mgRealPath($path) | |
404 { | |
405 return realpath($path); | |
406 } | |
407 | |
408 | |
285
25324e33fc78
Refactor gallery path handling somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
409 function mgCleanPathStr($path) |
25324e33fc78
Refactor gallery path handling somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
410 { |
25324e33fc78
Refactor gallery path handling somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
411 return str_replace("//", "/", $path); |
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 |
25324e33fc78
Refactor gallery path handling somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
414 |
0 | 415 function mgCleanPathArray($refs, $start, $argc, $argv) |
416 { | |
127
3ee66c432081
Use modern PHP array syntax.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
417 $path = []; |
0 | 418 $first = TRUE; |
419 for ($n = $start; $n < $argc; $n++) | |
420 { | |
421 foreach (explode("/", $argv[$n]) as $piece) | |
422 { | |
423 switch ($piece) | |
424 { | |
425 case ".": | |
426 case "": | |
427 if ($first) | |
428 $path[] = $piece; | |
429 break; | |
430 | |
431 case "..": | |
432 if ($refs && count($path) > 0) | |
433 array_pop($path); | |
434 break; | |
435 | |
436 default: | |
437 $path[] = $piece; | |
438 break; | |
439 } | |
440 $first = FALSE; | |
441 } | |
442 } | |
285
25324e33fc78
Refactor gallery path handling somewhat.
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
443 return mgCleanPathStr($path); |
0 | 444 } |
445 | |
446 | |
447 function mgCleanPath($refs) | |
448 { | |
449 return implode("/", mgCleanPathArray($refs, 1, func_num_args(), func_get_args())); | |
450 } | |
451 | |
452 | |
453 function mgGetArr($data, $skeys, $sfmt1 = "%1", $sfmt2 = "", $func = NULL) | |
454 { | |
47
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
455 global $pageLang; |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
456 |
0 | 457 if (!is_array($skeys)) |
458 $skeys = array($skeys); | |
459 | |
460 foreach ($skeys as $skey) | |
344
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
461 { |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
462 if (!array_key_exists($skey, $data)) |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
463 return $sfmt2; |
0f14a20f48ca
Improve gallery settings validation, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
343
diff
changeset
|
464 } |
0 | 465 |
466 $str = $sfmt1; | |
467 for ($i = 1; $i <= sizeof($skeys); $i++) | |
468 { | |
469 $val = $data[$skeys[$i - 1]]; | |
47
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
470 if (is_array($val)) |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
471 $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
|
472 else |
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
473 $vtmp = $val; |
0 | 474 |
475 if (is_callable($func)) | |
77
fcfd635d7abf
Oops, fix format string callback functions ..
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
476 $vtmp = call_user_func($func, $vtmp); |
0 | 477 |
47
1e2b55775a84
Begin implementation of translated caption/title support.
Matti Hamalainen <ccr@tnsp.org>
parents:
36
diff
changeset
|
478 $str = str_replace("%".$i, $vtmp, $str); |
0 | 479 } |
480 | |
481 return $str; | |
482 } | |
483 | |
484 | |
485 ?> |