From 9a6a6ec75de6e122b748e55507e4065031bfc8ad Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Fri, 18 Jan 2013 13:50:24 +0000 Subject: [PATCH] Arbitrary placement of _ss_environment.php in parent folders Removes hardcoding to three levels --- core/Core.php | 25 ++++++++++++++----------- dev/install/install.php5 | 19 ++++++++++++++----- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/core/Core.php b/core/Core.php index bafb24023..27da1a28b 100644 --- a/core/Core.php +++ b/core/Core.php @@ -46,19 +46,22 @@ error_reporting(E_ALL | E_STRICT); /** * Include _ss_environment.php files */ -$envFiles = array( - '_ss_environment.php', - '../_ss_environment.php', - '../../_ss_environment.php', - '../../../_ss_environment.php'); - -foreach($envFiles as $envFile) { - if(@file_exists($envFile)) { - define('SS_ENVIRONMENT_FILE', $envFile); - include_once($envFile); +//define the name of the environment file +$envFile = '_ss_environment.php'; +//define the dir to start scanning from (have to add the trailing slash) +$dir = '.'; +//check this dir and every parent dir (until we hit the base of the drive) +do { + $dir = realpath($dir) . '/'; + //if the file exists, then we include it, set relevant vars and break out + if (file_exists($dir . $envFile)) { + define('SS_ENVIRONMENT_FILE', $dir . $envFile); + include_once(SS_ENVIRONMENT_FILE); break; } -} +//here we need to check that the real path of the last dir and the next one are +// not the same, if they are, we have hit the root of the drive +} while (realpath($dir) != realpath($dir .= '../')); /////////////////////////////////////////////////////////////////////////////// // GLOBALS AND DEFINE SETTING diff --git a/dev/install/install.php5 b/dev/install/install.php5 index 818d4d6b4..7d4956977 100644 --- a/dev/install/install.php5 +++ b/dev/install/install.php5 @@ -31,15 +31,24 @@ if (function_exists('session_start')) { // Include environment files $usingEnv = false; $envFileExists = false; -$envFiles = array('_ss_environment.php', '../_ss_environment.php', '../../_ss_environment.php'); -foreach($envFiles as $envFile) { - if(@file_exists($envFile)) { - include_once($envFile); +//define the name of the environment file +$envFile = '_ss_environment.php'; +//define the dir to start scanning from +$dir = '.'; +//check this dir and every parent dir (until we hit the base of the drive) +do { + $dir = realpath($dir) . '/'; + //if the file exists, then we include it, set relevant vars and break out + if (file_exists($dir . $envFile)) { + include_once($dir . $envFile); $envFileExists = true; + //legacy variable assignment $usingEnv = true; break; } -} +//here we need to check that the real path of the last dir and the next one are +// not the same, if they are, we have hit the root of the drive +} while (realpath($dir) != realpath($dir .= '../')); if($envFileExists) { if(!empty($_REQUEST['useEnv'])) {