# HG changeset patch # User Matti Hamalainen # Date 1564739691 -10800 # Node ID 77f85b1f35f2a9f6a9de500fcfda47c7497a4377 # Parent f14ed58ef72b921d5436fc8feadfc6ed97557a2c Improve configuration file handling. diff -r f14ed58ef72b -r 77f85b1f35f2 mgallery.inc.php --- 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 = ""; $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) diff -r f14ed58ef72b -r 77f85b1f35f2 mgallery.php --- 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 + "

Internal error!

\n". + "

Could not find MGallery configuration file.

"; + + mgPrintPageFooter(); + exit; +} $pageCSS = mgGetSetting("css"); $pageJSFile = mgGetSetting("js_file"); diff -r f14ed58ef72b -r 77f85b1f35f2 mgtool.php --- 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)