Mercurial > hg > mgallery
changeset 297:77f85b1f35f2
Improve configuration file handling.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 02 Aug 2019 12:54:51 +0300 |
parents | f14ed58ef72b |
children | cf166dcc6e77 |
files | mgallery.inc.php mgallery.php mgtool.php |
diffstat | 3 files changed, 26 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/mgallery.inc.php Fri Aug 02 09:26:12 2019 +0300 +++ b/mgallery.inc.php Fri Aug 02 12:54:51 2019 +0300 @@ -11,6 +11,8 @@ $mgProgEmail = "<ccr@tnsp.org>"; $mgProgCopyright = "2015-2019 Tecnic Software productions (TNSP)"; +$mgProgConfigFile = "mgallery.cfg"; + $mgalDebug = FALSE; @@ -214,7 +216,7 @@ } -function mgReadSettings($filename = "mgallery.cfg") +function mgReadSettings(&$spaths) { global $mgSettings, $mgDefaults; @@ -237,9 +239,14 @@ } $spaths[] = dirname(__FILE__)."/"; - foreach (array_unique($spaths) as $path) + $spaths = array_map(function ($path) { - $file = $path.$filename; + global $mgProgConfigFile; + return $path.$mgProgConfigFile; + }, $spaths); + + foreach (array_unique($spaths) as $file) + { mgDebug("Checking '".$file."' for configuration ..\n"); if (file_exists($file) && ($mgSettings = parse_ini_file($file, FALSE)) !== FALSE)
--- a/mgallery.php Fri Aug 02 09:26:12 2019 +0300 +++ b/mgallery.php Fri Aug 02 12:54:51 2019 +0300 @@ -447,7 +447,17 @@ // // Read and process gallery settings // -mgReadSettings(); +if (mgReadSettings($searchPaths) === FALSE) +{ + mgPrintPageHeader("Internal error!", "galleryPage"); + + echo + "<h1>Internal error!</h1>\n". + "<p>Could not find MGallery configuration file.</p>"; + + mgPrintPageFooter(); + exit; +} $pageCSS = mgGetSetting("css"); $pageJSFile = mgGetSetting("js_file");
--- a/mgtool.php Fri Aug 02 09:26:12 2019 +0300 +++ b/mgtool.php Fri Aug 02 12:54:51 2019 +0300 @@ -1246,8 +1246,11 @@ } // Check settings -if (mgReadSettings() === FALSE) - die("MGallery is not configured, failed to find a configuration file.\n"); +if (mgReadSettings($searchPaths) === FALSE) +{ + die("MGallery is not configured, failed to find a configuration file.\n". + "Attempted search paths:\n".implode("\n", $searchPaths)."\n"); +} // Configure the timezone if (($pageTimeZone = mgGetSetting("timezone")) !== NULL)