From 989dd8d1ee4a7fe224683d5156b67e4de38a721e Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sat, 24 Mar 2018 21:28:09 +0100 Subject: [PATCH] [index] Load configuration from file Uses the parse_ini_file function to load the default settings from the default configuration file 'config.default.ini.php'. Optionally loads custom settings from 'config.ini.php' to replace the default values. --- index.php | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/index.php b/index.php index 97a76450..1fe3bf33 100644 --- a/index.php +++ b/index.php @@ -10,19 +10,35 @@ TODO : - implement header('X-Cached-Version: '.date(DATE_ATOM, filemtime($cachefile))); */ +if(!file_exists('config.default.ini.php')) + die('The default configuration file "config.default.ini.php" is missing!'); + +$config = parse_ini_file('config.default.ini.php', true, INI_SCANNER_TYPED); + +if(file_exists('config.ini.php')) { + // Replace default configuration with custom settings + foreach(parse_ini_file('config.ini.php', true, INI_SCANNER_TYPED) as $header => $section) { + foreach($section as $key => $value) { + // Skip unknown sections and keys + if(array_key_exists($header, $config) && array_key_exists($key, $config[$header])) { + $config[$header][$key] = $value; + } + } + } +} + +var_dump($config); + +if(!empty($config['proxy']['url'])) + define('PROXY_URL', $config['proxy']['url']); + +define('PROXY_BYBRIDGE', $config['proxy']['by_bridge']); +define('PROXY_NAME', $config['proxy']['name']); +define('CUSTOM_CACHE_TIMEOUT', $config['cache']['custom_timeout']); + // Defines the minimum required PHP version for RSS-Bridge define('PHP_VERSION_REQUIRED', '5.6.0'); -//define('PROXY_URL', 'tcp://192.168.0.0:28'); -// Set to true if you allow users to disable proxy usage for specific bridges -define('PROXY_BYBRIDGE', false); -// Comment this line or keep PROXY_NAME empty to display PROXY_URL instead -define('PROXY_NAME', 'Hidden Proxy Name'); - -// Allows the operator to specify custom cache timeouts via '&_cache_timeout=3600' -// true: enabled, false: disabled (default) -define('CUSTOM_CACHE_TIMEOUT', false); - date_default_timezone_set('UTC'); error_reporting(0);