From 77e4bb9865a5894666c8a0b33b28b9c84d01efaf Mon Sep 17 00:00:00 2001 From: frytimo Date: Tue, 17 Oct 2023 00:54:56 -0300 Subject: [PATCH] Reorder project path and project root defines (#6787) * reorder the project_root and project_path define so isset is called before the config key project.root is used * ensure project path begins with a '/' * rewrite for empty string in project_path * Update require.php --- resources/require.php | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/resources/require.php b/resources/require.php index d5c5d659ef..4424b4726b 100644 --- a/resources/require.php +++ b/resources/require.php @@ -40,11 +40,8 @@ } } -//check if the config file exists - $config_exists = !empty($config_file) ? true : false; - //config.conf file not found re-direct the request to the install - if (!$config_exists) { + if (empty($config_file)) { header("Location: /core/install/install.php"); exit; } @@ -55,19 +52,26 @@ //set the include path set_include_path($conf['document.root']); -//set the server variables and define project path constant - $_SERVER["DOCUMENT_ROOT"] = $conf['document.root']; - $_SERVER["PROJECT_ROOT"] = $conf['document.root']; - $_SERVER["PROJECT_PATH"] = $conf['project.path']; - if (isset($conf['project.path'])) { - $_SERVER["PROJECT_ROOT"] = $conf['document.root'].'/'.$conf['project.path']; - if (!defined('PROJECT_ROOT')) { define("PROJECT_ROOT", $conf['document.root'].'/'.$conf['project.path']); } - if (!defined('PROJECT_PATH')) { define("PROJECT_PATH", $conf['project.path']); } - } - else { - if (!defined('PROJECT_ROOT')) { define("PROJECT_ROOT", $conf['document.root']); } - if (!defined('PROJECT_PATH')) { define("PROJECT_PATH", ''); } +//set document root + $_SERVER["DOCUMENT_ROOT"] = substr($conf['document.root'], -1) === '/' ? substr($conf['document.root'], 0, -1) : $conf['document.root']; + +//set project path + if (isset($conf['project.path']) && !defined('PROJECT_PATH')) { + if (substr($conf['project.path'], 0, 1) === '/') { + define("PROJECT_PATH", $conf['project.path']); + } else { + if (!empty($conf['project.path'])) { + define("PROJECT_PATH", '/' . $conf['project.path']); + } else { + define("PROJECT_PATH", ''); + } + } } + $_SERVER["PROJECT_PATH"] = PROJECT_PATH; + +//set project root using project path + if (!defined('PROJECT_ROOT')) { define("PROJECT_ROOT", $conf['document.root'] . PROJECT_PATH); } + $_SERVER["PROJECT_ROOT"] = PROJECT_ROOT; //set the error reporting ini_set('display_errors', '1');