X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/15a1666f8a1e19c338015fccd502be6cfd5c24df..77e287f66918296b9461470a7846e22ec1f36a08:/lib/lib.php diff --git a/lib/lib.php b/lib/lib.php index 753159d2..7760f695 100644 --- a/lib/lib.php +++ b/lib/lib.php @@ -1,26 +1,44 @@ load($sProjectDir.'/.env'); + if ($sDefault !== null && !$sValue) { + return $sDefault; } - $dotenv->load(CONST_DataDir.'/settings/env.defaults'); + + return $sValue; +} + +function getSettingBool($sConfName) +{ + $sVal = strtolower(getSetting($sConfName)); + + return strcmp($sVal, 'yes') == 0 + || strcmp($sVal, 'true') == 0 + || strcmp($sVal, '1') == 0; } -function getSetting($sConfName) +function getSettingConfig($sConfName, $sSystemConfig) { - return $_ENV['NOMINATIM_'.$sConfName]; + $sValue = $_SERVER['NOMINATIM_'.$sConfName]; + + if (!$sValue) { + return CONST_DataDir.'/settings/'.$sSystemConfig; + } + + return $sValue; } function fail($sError, $sUserError = false) @@ -112,6 +130,24 @@ function addQuotes($s) return "'".$s."'"; } +function fwriteConstDef($rFile, $sConstName, $value) +{ + $sEscapedValue; + + if (is_bool($value)) { + $sEscapedValue = $value ? 'true' : 'false'; + } elseif (is_numeric($value)) { + $sEscapedValue = strval($value); + } elseif (!$value) { + $sEscapedValue = 'false'; + } else { + $sEscapedValue = addQuotes(str_replace("'", "\\'", (string)$value)); + } + + fwrite($rFile, "@define('CONST_$sConstName', $sEscapedValue);\n"); +} + + function parseLatLon($sQuery) { $sFound = null;