Optimize require.php (#7286)
Load the auto_loader first Use config object to find config.conf file and declare global Use database object and declare global Use settings object and declare global
This commit is contained in:
parent
d9827f8800
commit
da6471df5f
|
|
@ -24,66 +24,35 @@
|
||||||
Mark J Crane <markjcrane@fusionpbx.com>
|
Mark J Crane <markjcrane@fusionpbx.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//find the config.conf file
|
//class auto loader
|
||||||
if (file_exists('/usr/local/etc/fusionpbx/config.conf')) {
|
if (!class_exists('auto_loader')) {
|
||||||
$config_file = '/usr/local/etc/fusionpbx/config.conf';
|
require_once __DIR__ . "/classes/auto_loader.php";
|
||||||
}
|
$autoload = new auto_loader();
|
||||||
elseif (file_exists('/etc/fusionpbx/config.conf')) {
|
|
||||||
$config_file = '/etc/fusionpbx/config.conf';
|
|
||||||
}
|
|
||||||
elseif (file_exists(getenv('SystemDrive') . DIRECTORY_SEPARATOR . 'ProgramData' . DIRECTORY_SEPARATOR . 'fusionpbx' . DIRECTORY_SEPARATOR . 'config.conf')) {
|
|
||||||
$config_file = getenv('SystemDrive') . DIRECTORY_SEPARATOR . 'ProgramData' . DIRECTORY_SEPARATOR . 'fusionpbx' . DIRECTORY_SEPARATOR . 'config.conf';
|
|
||||||
}
|
|
||||||
elseif (file_exists(__DIR__ . '/config.php')) {
|
|
||||||
//set a custom config_file variable after the config.php has been validated
|
|
||||||
$file_content = trim(file_get_contents(__DIR__ . '/config.php'));
|
|
||||||
$pattern = '/^<\?php\s+\$config_file\s+=\s+[\'"](.+?)[\'"];\s+\?>$/';
|
|
||||||
if (preg_match($pattern, $file_content, $matches) && file_exists($matches[1])) {
|
|
||||||
$config_file = $matches[1];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//load config file
|
||||||
|
global $config;
|
||||||
|
$config = config::load();
|
||||||
|
|
||||||
//config.conf file not found re-direct the request to the install
|
//config.conf file not found re-direct the request to the install
|
||||||
if (empty($config_file)) {
|
if ($config->is_empty()) {
|
||||||
header("Location: /core/install/install.php");
|
header("Location: /core/install/install.php");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
//parse the config.conf file
|
//compatibility settings - planned to deprecate
|
||||||
$conf = parse_ini_file($config_file);
|
global $conf, $db_type, $db_host, $db_port, $db_name, $db_username, $db_password;
|
||||||
|
$conf = $config->configuration();
|
||||||
//set the include path
|
$db_type = $config->get('database.0.type');
|
||||||
set_include_path($conf['document.root']);
|
$db_host = $config->get('database.0.host');
|
||||||
|
$db_port = $config->get('database.0.port');
|
||||||
//set document root
|
$db_name = $config->get('database.0.name');
|
||||||
$_SERVER["DOCUMENT_ROOT"] = substr($conf['document.root'], -1) === '/' ? substr($conf['document.root'], 0, -1) : $conf['document.root'];
|
$db_username = $config->get('database.0.username');
|
||||||
|
$db_password = $config->get('database.0.password');
|
||||||
//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
|
//set the error reporting
|
||||||
ini_set('display_errors', '1');
|
ini_set('display_errors', '1');
|
||||||
if (isset($conf['error.reporting'])) {
|
$error_reporting_scope = $config->get('error.reporting', 'user');
|
||||||
$error_reporting_scope = $conf['error.reporting'];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$error_reporting_scope = 'user';
|
|
||||||
}
|
|
||||||
switch ($error_reporting_scope) {
|
switch ($error_reporting_scope) {
|
||||||
case 'user':
|
case 'user':
|
||||||
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);
|
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);
|
||||||
|
|
@ -106,37 +75,38 @@
|
||||||
//$db_username = $settings['database']['username'];
|
//$db_username = $settings['database']['username'];
|
||||||
//$db_password = $settings['database']['password'];
|
//$db_password = $settings['database']['password'];
|
||||||
|
|
||||||
//get the database connection settings
|
|
||||||
$db_type = $conf['database.0.type'];
|
|
||||||
$db_host = $conf['database.0.host'];
|
|
||||||
$db_port = $conf['database.0.port'];
|
|
||||||
$db_name = $conf['database.0.name'];
|
|
||||||
$db_username = $conf['database.0.username'];
|
|
||||||
$db_password = $conf['database.0.password'];
|
|
||||||
|
|
||||||
//debug info
|
//debug info
|
||||||
//echo "Include Path: ".get_include_path()."\n";
|
//echo "Include Path: ".get_include_path()."\n";
|
||||||
//echo "Document Root: ".$_SERVER["DOCUMENT_ROOT"]."\n";
|
//echo "Document Root: ".$_SERVER["DOCUMENT_ROOT"]."\n";
|
||||||
//echo "Project Root: ".$_SERVER["PROJECT_ROOT"]."\n";
|
//echo "Project Root: ".$_SERVER["PROJECT_ROOT"]."\n";
|
||||||
|
|
||||||
//class auto loader
|
|
||||||
if (!class_exists('auto_loader')) {
|
//include global functions
|
||||||
require_once "resources/classes/auto_loader.php";
|
require_once __DIR__ . "/functions.php";
|
||||||
$autoload = new auto_loader();
|
|
||||||
|
//connect to the database
|
||||||
|
global $database;
|
||||||
|
$database = database::new(['config' => $config]);
|
||||||
|
|
||||||
|
//if not using the command line required files
|
||||||
|
global $no_session;
|
||||||
|
if (!defined('STDIN') && empty($no_session)) {
|
||||||
|
require_once __DIR__ . '/php.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
//additional includes
|
//load settings
|
||||||
if (!defined('STDIN')) {
|
global $settings;
|
||||||
require_once "resources/php.php";
|
$settings = new settings(['database' => $database, 'domain_uuid' => $_SESSION['domain_uuid'] ?? '', 'user_uuid' => $_SESSION['domain_uuid'] ?? '']);
|
||||||
}
|
|
||||||
require_once "resources/functions.php";
|
//check if the cidr range is valid
|
||||||
if (is_array($conf) && count($conf) > 0) {
|
global $no_cidr;
|
||||||
if (!defined('STDIN')) {
|
if (!defined('STDIN') && empty($no_cidr)) {
|
||||||
require_once "resources/cidr.php";
|
require_once __DIR__ . '/cidr.php';
|
||||||
}
|
|
||||||
if (file_exists($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/resources/switch.php")) {
|
|
||||||
require_once "resources/switch.php";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//include switch functions when available
|
||||||
|
if (file_exists(__DIR__ . '/switch.php')) {
|
||||||
|
require_once __DIR__ . '/switch.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
//change language on the fly - for translate tool (if available)
|
//change language on the fly - for translate tool (if available)
|
||||||
|
|
@ -147,9 +117,6 @@
|
||||||
//change the domain
|
//change the domain
|
||||||
if (!empty($_GET["domain_uuid"]) && is_uuid($_GET["domain_uuid"]) && $_GET["domain_change"] == "true" && permission_exists('domain_select')) {
|
if (!empty($_GET["domain_uuid"]) && is_uuid($_GET["domain_uuid"]) && $_GET["domain_change"] == "true" && permission_exists('domain_select')) {
|
||||||
|
|
||||||
//connect to the database
|
|
||||||
$database = database::new();
|
|
||||||
|
|
||||||
//include domains
|
//include domains
|
||||||
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/domains/app_config.php") && !permission_exists('domain_all')) {
|
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/domains/app_config.php") && !permission_exists('domain_all')) {
|
||||||
include_once "app/domains/domains.php";
|
include_once "app/domains/domains.php";
|
||||||
|
|
@ -183,5 +150,3 @@
|
||||||
$domain = new domains();
|
$domain = new domains();
|
||||||
$domain->set();
|
$domain->set();
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue