comparison mgallery.inc.php @ 297:77f85b1f35f2

Improve configuration file handling.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 02 Aug 2019 12:54:51 +0300
parents df66529eff47
children cf166dcc6e77
comparison
equal deleted inserted replaced
296:f14ed58ef72b 297:77f85b1f35f2
8 8
9 $mgProgVersion = "v0.9.10"; 9 $mgProgVersion = "v0.9.10";
10 $mgProgInfo = "Programmed by Matti 'ccr' Hamalainen"; 10 $mgProgInfo = "Programmed by Matti 'ccr' Hamalainen";
11 $mgProgEmail = "<ccr@tnsp.org>"; 11 $mgProgEmail = "<ccr@tnsp.org>";
12 $mgProgCopyright = "2015-2019 Tecnic Software productions (TNSP)"; 12 $mgProgCopyright = "2015-2019 Tecnic Software productions (TNSP)";
13
14 $mgProgConfigFile = "mgallery.cfg";
13 15
14 $mgalDebug = FALSE; 16 $mgalDebug = FALSE;
15 17
16 18
17 // 19 //
212 $val = mgGetSetting($key); 214 $val = mgGetSetting($key);
213 return ($val !== FALSE) ? $path."/".$val : FALSE; 215 return ($val !== FALSE) ? $path."/".$val : FALSE;
214 } 216 }
215 217
216 218
217 function mgReadSettings($filename = "mgallery.cfg") 219 function mgReadSettings(&$spaths)
218 { 220 {
219 global $mgSettings, $mgDefaults; 221 global $mgSettings, $mgDefaults;
220 222
221 $spaths = []; 223 $spaths = [];
222 $spaths[] = getcwd()."/"; 224 $spaths[] = getcwd()."/";
235 $spaths[] = $tmp."/."; 237 $spaths[] = $tmp."/.";
236 } 238 }
237 } 239 }
238 $spaths[] = dirname(__FILE__)."/"; 240 $spaths[] = dirname(__FILE__)."/";
239 241
240 foreach (array_unique($spaths) as $path) 242 $spaths = array_map(function ($path)
241 { 243 {
242 $file = $path.$filename; 244 global $mgProgConfigFile;
245 return $path.$mgProgConfigFile;
246 }, $spaths);
247
248 foreach (array_unique($spaths) as $file)
249 {
243 mgDebug("Checking '".$file."' for configuration ..\n"); 250 mgDebug("Checking '".$file."' for configuration ..\n");
244 if (file_exists($file) && 251 if (file_exists($file) &&
245 ($mgSettings = parse_ini_file($file, FALSE)) !== FALSE) 252 ($mgSettings = parse_ini_file($file, FALSE)) !== FALSE)
246 { 253 {
247 mgDebug("Found '".$file."' config.\n"); 254 mgDebug("Found '".$file."' config.\n");