Replace the DOCUMENT_ROOT and PROJECT_ROOT variables

Use the __DIR__ constant and dirname as needed
This commit is contained in:
FusionPBX
2025-12-08 14:12:19 -07:00
committed by GitHub
parent df90513f86
commit 6b063f2c28
84 changed files with 217 additions and 210 deletions

View File

@@ -167,7 +167,7 @@
header("Location: ".$settings->get('login', 'destination', ''));
exit;
}
elseif (file_exists($_SERVER["PROJECT_ROOT"]."/core/dashboard/app_config.php")) {
elseif (file_exists(dirname(__DIR__, 1)."/core/dashboard/app_config.php")) {
header("Location: ".PROJECT_PATH."/core/dashboard/");
exit;
}

View File

@@ -66,7 +66,7 @@ class captcha {
$text = $this->code;
// Set the font path
$font_path = $_SERVER["DOCUMENT_ROOT"] . "/resources/captcha/fonts";
$font_path = dirname(__DIR__, 2) . "/resources/captcha/fonts";
// Array of fonts
//$fonts[] = 'ROUGD.TTF';

View File

@@ -19,21 +19,29 @@
* @param string $config_file Configuration file currently in use
* @param string $config_path_and_filename Full path and configuration file currently in use
*
* @internal the @param statements are used because they match the magic __get function that allows those to be
* accessed publicly
* @internal the @param statements are used because they match the magic __get function that allows those to be accessed publicly
*/
final class config {
// Full path and filename of config.conf
/**
* Configuration object used to hold a single instance
*
* @var array
* @var config
*/
public static $config = null;
// The internal array that holds the configuration in the config.conf file
/**
* The full path and file name for the config file.
*
* @var string
*/
private $file;
/**
* The array of settings contained in the config file.
*
* @var array
*/
private $configuration;
/**

View File

@@ -1651,7 +1651,7 @@ class database {
$transaction_type = 'delete';
//log the transaction results
if (file_exists($_SERVER["PROJECT_ROOT"] . "/app/database_transactions/app_config.php")) {
if (file_exists(dirname(__DIR__, 2) . "/app/database_transactions/app_config.php")) {
$sql = "insert into " . self::TABLE_PREFIX . "database_transactions ";
$sql .= "(";
$sql .= "database_transaction_uuid, ";
@@ -1792,7 +1792,7 @@ class database {
$applications = [$schema, self::singular($schema)];
foreach ($directories as $directory) {
foreach ($applications as $application) {
$path = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/$directory/$application/app_config.php";
$path = dirname(__DIR__, 2) . "/$directory/$application/app_config.php";
$app_config_files = glob($path);
if ($app_config_files !== false) {
$config_list = array_merge($config_list, $app_config_files);
@@ -3269,7 +3269,7 @@ class database {
}
//log the transaction results
if ($transaction_save && $database_updated && file_exists($_SERVER["PROJECT_ROOT"] . "/app/database_transactions/app_config.php")) {
if ($transaction_save && $database_updated && file_exists(dirname(__DIR__, 2) . "/app/database_transactions/app_config.php")) {
try {
//build the json string from the array
if (!empty($old_array)) {
@@ -3515,12 +3515,12 @@ class database {
*
* @return null Does not return any values
* @uses PROJECT_PATH Global variable
* @uses $_SERVER['DOCUMENT_ROOT'] Global variable
* @uses dirname(__DIR__, 2) Global variable
* @internal Moved to class to conserve resources.
*/
public static function get_apps() {
//get the $apps array from the installed apps from the core and mod directories
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
$config_list = glob(dirname(__DIR__, 2) . "/*/*/app_config.php");
$x = 0;
if (is_array($config_list)) {
foreach ($config_list as $config_path) {

View File

@@ -340,8 +340,8 @@ class domains {
$config_path = $config->config_file;
//get the list of installed apps from the core and app directories (note: GLOB_BRACE doesn't work on some systems)
$config_list_1 = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
$config_list_2 = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_menu.php");
$config_list_1 = glob(dirname(__DIR__, 2) . "/*/*/app_config.php");
$config_list_2 = glob(dirname(__DIR__, 2) . "/*/*/app_menu.php");
$config_list = array_merge((array)$config_list_1, (array)$config_list_2);
unset($config_list_1, $config_list_2);
$x = 0;
@@ -358,7 +358,7 @@ class domains {
unset($sql);
//get the list of installed apps from the core and mod directories
$default_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_defaults.php");
$default_list = glob(dirname(__DIR__, 2) . "/*/*/app_defaults.php");
//loop through all domains
$domains_processed = 1;
@@ -408,7 +408,7 @@ class domains {
unset($sql);
//get the list of default settings
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
$config_list = glob(dirname(__DIR__, 2) . "/*/*/app_config.php");
$x = 0;
foreach ($config_list as $config_path) {
include($config_path);
@@ -517,7 +517,7 @@ class domains {
unset($result, $row);
//get the $apps array from the installed apps from the core and mod directories
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
$config_list = glob(dirname(__DIR__, 2) . "/*/*/app_config.php");
$x = 0;
if (isset($config_list)) foreach ($config_list as $config_path) {
include($config_path);

View File

@@ -125,8 +125,8 @@ class email {
//includes
require_once('resources/pop3/mime_parser.php');
require_once('resources/pop3/rfc822_addresses.php');
if (file_exists($_SERVER["PROJECT_ROOT"] . "/app/emails/email_transcription.php")) {
require_once($_SERVER["PROJECT_ROOT"] . "/app/emails/email_transcription.php");
if (file_exists(dirname(__DIR__, 2) . "/app/emails/email_transcription.php")) {
require_once(dirname(__DIR__, 2) . "/app/emails/email_transcription.php");
}
//parse the email message

View File

@@ -530,7 +530,7 @@ class groups {
$num_rows = $this->database->select($sql, null, 'column');
if ($num_rows == 0) {
//build the apps array
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
$config_list = glob(dirname(__DIR__, 2) . "/*/*/app_config.php");
$x = 0;
foreach ($config_list as $config_path) {
include($config_path);

View File

@@ -944,7 +944,7 @@ class menu {
public function restore_default() {
//get the $apps array from the installed apps from the core and mod directories
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_menu.php");
$config_list = glob(dirname(__DIR__, 2) . "/*/*/app_menu.php");
$x = 0;
if (is_array($config_list)) {
foreach ($config_list as $config_path) {

View File

@@ -58,7 +58,7 @@ class schema {
$this->database = $setting_array['database'] ?? database::new();
//get the list of installed apps from the core and mod directories
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
$config_list = glob(dirname(__DIR__, 2) . "/*/*/app_config.php");
$x = 0;
foreach ($config_list as $config_path) {
try {

View File

@@ -61,7 +61,7 @@ class sounds {
}
}
//recordings
if ((empty($this->sound_types) || (is_array($this->sound_types) && in_array('recordings', $this->sound_types))) && file_exists($_SERVER["PROJECT_ROOT"] . "/app/recordings/app_config.php")) {
if ((empty($this->sound_types) || (is_array($this->sound_types) && in_array('recordings', $this->sound_types))) && file_exists(dirname(__DIR__, 2) . "/app/recordings/app_config.php")) {
$sql = "select recording_name, recording_filename from v_recordings ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "order by recording_name asc ";
@@ -79,7 +79,7 @@ class sounds {
unset($sql, $parameters, $recordings, $row);
}
//phrases
if ((empty($this->sound_types) || (is_array($this->sound_types) && in_array('phrases', $this->sound_types))) && file_exists($_SERVER["PROJECT_ROOT"] . "/app/phrases/app_config.php")) {
if ((empty($this->sound_types) || (is_array($this->sound_types) && in_array('phrases', $this->sound_types))) && file_exists(dirname(__DIR__, 2) . "/app/phrases/app_config.php")) {
$sql = "select * from v_phrases ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $_SESSION["domain_uuid"];
@@ -94,7 +94,7 @@ class sounds {
unset($sql, $parameters, $phrases, $row);
}
//sounds
if ((empty($this->sound_types) || (is_array($this->sound_types) && in_array('sounds', $this->sound_types))) && file_exists($_SERVER["PROJECT_ROOT"] . "/app/phrases/app_config.php")) {
if ((empty($this->sound_types) || (is_array($this->sound_types) && in_array('sounds', $this->sound_types))) && file_exists(dirname(__DIR__, 2) . "/app/phrases/app_config.php")) {
$file = new file;
$sound_files = $file->sounds();
if (is_array($sound_files) && @sizeof($sound_files) != 0) {

View File

@@ -102,8 +102,8 @@ class text implements clear_cache {
}
//get the global app_languages.php so we can get the list of languages
if (file_exists($_SERVER["PROJECT_ROOT"] . "/resources/app_languages.php")) {
include $_SERVER["PROJECT_ROOT"] . "/resources/app_languages.php";
if (file_exists(dirname(__DIR__, 2) . "/resources/app_languages.php")) {
include dirname(__DIR__, 2) . "/resources/app_languages.php";
}
//get the list of languages, remove en-us, sort it then put en-us in front
@@ -174,7 +174,7 @@ class text implements clear_cache {
//get the app_languages.php
if ($app_path != null) {
$lang_path = $_SERVER["PROJECT_ROOT"] . "/" . $app_path;
$lang_path = dirname(__DIR__, 2) . "/" . $app_path;
} else {
$lang_path = getcwd();
}
@@ -190,8 +190,8 @@ class text implements clear_cache {
}
//get the global app_languages.php
if (!$exclude_global && file_exists($_SERVER["PROJECT_ROOT"] . "/resources/app_languages.php")) {
require $_SERVER["PROJECT_ROOT"] . "/resources/app_languages.php";
if (!$exclude_global && file_exists(dirname(__DIR__, 2) . "/resources/app_languages.php")) {
require dirname(__DIR__, 2) . "/resources/app_languages.php";
}
if (file_exists($lang_path . "/app_languages.php") && ($lang_path != 'resources' or $exclude_global)) {
@@ -241,11 +241,11 @@ class text implements clear_cache {
$languages = [];
//retrieve all the languages
$files = glob($_SERVER["PROJECT_ROOT"] . "/*/*/app_languages.php");
$files = glob(dirname(__DIR__, 2) . "/*/*/app_languages.php");
foreach ($files as $file) {
include $file;
}
include $_SERVER["PROJECT_ROOT"] . "/resources/app_languages.php";
include dirname(__DIR__, 2) . "/resources/app_languages.php";
//check every tag
foreach ($text as $lang_codes) {
@@ -290,7 +290,7 @@ class text implements clear_cache {
if ($app_path == null) {
throw new Exception("\$app_path must be specified");
}
$lang_path = $_SERVER["PROJECT_ROOT"] . "/$app_path/app_languages.php";
$lang_path = dirname(__DIR__, 2) . "/$app_path/app_languages.php";
if (!file_exists($lang_path)) {
throw new Exception("could not find app_languages for '$app_path'");
}
@@ -453,11 +453,11 @@ class text implements clear_cache {
//retrieve all the languages
$text = [];
$files = glob($_SERVER["PROJECT_ROOT"] . "/*/*/app_languages.php");
$files = glob(dirname(__DIR__, 2) . "/*/*/app_languages.php");
foreach ($files as $file) {
include $file;
}
include $_SERVER["PROJECT_ROOT"] . "/resources/app_languages.php";
include dirname(__DIR__, 2) . "/resources/app_languages.php";
//check every tag
foreach ($text as $label_name => $values) {
@@ -471,7 +471,7 @@ class text implements clear_cache {
//retrieve all the menus
$x = 0;
$files = glob($_SERVER["PROJECT_ROOT"] . "/*/*");
$files = glob(dirname(__DIR__, 2) . "/*/*");
foreach ($files as $file) {
if (file_exists($file . "/app_menu.php"))
include $file . "/app_menu.php";

View File

@@ -29,8 +29,8 @@ require_once dirname(__DIR__, 2) . "/resources/require.php";
//load icons
$font_awesome_icons = [];
if (file_exists($_SERVER["PROJECT_ROOT"].'/resources/fontawesome/metadata/icons.json')) {
$icons_json = file_get_contents($_SERVER["PROJECT_ROOT"].'/resources/fontawesome/metadata/icons.json');
if (file_exists(dirname(__DIR__, 2).'/resources/fontawesome/metadata/icons.json')) {
$icons_json = file_get_contents(dirname(__DIR__, 2).'/resources/fontawesome/metadata/icons.json');
if (!empty($icons_json)) {
$icons_array = json_decode($icons_json, true);
if (!empty($icons_array) && is_array($icons_array)) {

View File

@@ -46,10 +46,10 @@
$body = ob_get_contents();
ob_end_clean(); //clean the buffer
//set a default template
//set the default template
if (empty($_SESSION["template_full_path"])) { //build template if session template has no length
//set the template base path
$template_base_path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes';
$template_base_path = dirname(__DIR__, 1).'/themes';
//get the contents of the template and save it to the template variable
$template_full_path = $template_base_path.'/'.$settings->get('domain', 'template', 'default').'/template.php';
@@ -185,7 +185,7 @@
$authenticated = isset($_SESSION['username']) && !empty($_SESSION['username']) ? true : false;
$view->assign('authenticated', $authenticated);
//domains application path
$view->assign('domains_app_path', PROJECT_PATH.(file_exists($_SERVER['DOCUMENT_ROOT'].'/app/domains/domains.php') ? '/app/domains/domains.php' : '/core/domains/domains.php'));
$view->assign('domains_app_path', PROJECT_PATH.(file_exists(dirname(__DIR__, 1).'/app/domains/domains.php') ? '/app/domains/domains.php' : '/core/domains/domains.php'));
//domain count
$view->assign('domain_count', $domain_count);
//domain selector row background colors
@@ -289,7 +289,7 @@
//session timer
if ($authenticated &&
file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH.'/app/session_timer/session_timer.php') &&
file_exists(dirname(__DIR__, 1).'/app/session_timer/session_timer.php') &&
$settings->get('security', 'session_timer_enabled', false)
) {
include_once PROJECT_PATH.'app/session_timer/session_timer.php';

View File

@@ -2457,7 +2457,7 @@ if (!function_exists('import_fonts')) {
correctly.
*/
$file = file_get_contents($_SERVER["DOCUMENT_ROOT"] . $file_to_parse);
$file = file_get_contents(dirname(__DIR__, 1) . $file_to_parse);
$lines = explode("\n", $file);
$style_counter = 0;

View File

@@ -54,7 +54,7 @@
}
//set the template base directory path
$template_base_path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes';
$template_base_path = dirname(__DIR__, 1).'/themes';
//start the output buffer
include $template_base_path.'/'.$settings->get('domain', 'template', 'default').'/config.php';
@@ -111,7 +111,7 @@
ob_start();
//for translate tool (if available)
if (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/translate/translate_header.php")) {
if (file_exists(dirname(__DIR__, 1)."/app/translate/translate_header.php")) {
require_once("app/translate/translate_header.php");
}

View File

@@ -105,7 +105,7 @@ if ($db_type == "sqlite") {
//set the document_root
if (empty($document_root)) {
$document_root = $_SERVER["DOCUMENT_ROOT"];
$document_root = dirname(__DIR__, 1);
}
//prepare the database connection

View File

@@ -77,8 +77,8 @@
//debug info
//echo "Include Path: ".get_include_path()."\n";
//echo "Document Root: ".$_SERVER["DOCUMENT_ROOT"]."\n";
//echo "Project Root: ".$_SERVER["PROJECT_ROOT"]."\n";
//echo "Document Root: ".dirname(__DIR__, 1)."\n";
//echo "Project Root: ".dirname(__DIR__, 1)."\n";
//include global functions
@@ -130,7 +130,7 @@
if (!empty($_GET["domain_uuid"]) && is_uuid($_GET["domain_uuid"]) && !empty($_GET["domain_change"]) && $_GET["domain_change"] == "true" && permission_exists('domain_select')) {
//include domains
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/domains/app_config.php") && !permission_exists('domain_all')) {
if (file_exists(dirname(__DIR__, 1)."/app/domains/app_config.php") && !permission_exists('domain_all')) {
include_once "app/domains/domains.php";
}

View File

@@ -834,7 +834,7 @@ if (!function_exists('save_call_center_xml')) {
$path = "/usr/share/examples/fusionpbx/resources/templates/conf";
}
else {
$path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/switch/resources/conf";
$path = dirname(__DIR__, 1)."/app/switch/resources/conf";
}
//get the contents of the template
@@ -878,7 +878,7 @@ if (!function_exists('switch_conf_xml')) {
$path = "/usr/share/examples/fusionpbx/resources/templates/conf";
}
else {
$path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/switch/resources/conf";
$path = dirname(__DIR__, 1)."/app/switch/resources/conf";
}
$file_contents = file_get_contents($path."/autoload_configs/switch.conf.xml");
@@ -889,7 +889,7 @@ if (!function_exists('switch_conf_xml')) {
$php_bin = 'php.exe';
}
$secure_path = path_join($_SERVER["DOCUMENT_ROOT"], PROJECT_PATH, 'secure');
$secure_path = path_join(dirname(__DIR__, 1), PROJECT_PATH, 'secure');
$v_mail_bat = path_join($secure_path, 'mailto.bat');
$v_mail_cmd = '@' .
@@ -906,7 +906,7 @@ if (!function_exists('switch_conf_xml')) {
}
else {
if (file_exists(PHP_BINDIR.'/php')) { define("PHP_BIN", "php"); }
$v_mailer_app = PHP_BINDIR."/".PHP_BIN." ".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/secure/v_mailto.php";
$v_mailer_app = PHP_BINDIR."/".PHP_BIN." ".dirname(__DIR__, 1)."/secure/v_mailto.php";
$v_mailer_app_args = "-t";
}
@@ -939,7 +939,7 @@ if (!function_exists('xml_cdr_conf_xml')) {
$path = "/usr/share/examples/fusionpbx/resources/templates/conf";
}
else {
$path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/switch/resources/conf";
$path = dirname(__DIR__, 1)."/app/switch/resources/conf";
}
$file_contents = file_get_contents($path."/autoload_configs/xml_cdr.conf.xml");
@@ -1008,10 +1008,10 @@ if (!function_exists('save_sip_profile_xml')) {
//get the xml sip profile template
if ($sip_profile_name == "internal" || $sip_profile_name == "external" || $sip_profile_name == "internal-ipv6") {
$file_contents = file_get_contents($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/sip_profiles/resources/xml/sip_profiles/".$sip_profile_name.".xml");
$file_contents = file_get_contents(dirname(__DIR__, 1)."/app/sip_profiles/resources/xml/sip_profiles/".$sip_profile_name.".xml");
}
else {
$file_contents = file_get_contents($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/sip_profiles/resources/xml/sip_profiles/default.xml");
$file_contents = file_get_contents(dirname(__DIR__, 1)."/app/sip_profiles/resources/xml/sip_profiles/default.xml");
}
//get the sip profile settings
@@ -1063,33 +1063,33 @@ if (!function_exists('save_switch_xml')) {
global $settings;
if (is_readable($settings->get('switch', 'extensions'))) {
if (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/extensions/resources/classes/extension.php")) {
if (file_exists(dirname(__DIR__, 1)."/app/extensions/resources/classes/extension.php")) {
$extension = new extension;
$extension->xml();
}
}
if (is_readable($settings->get('switch', 'conf'))) {
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/settings/app_config.php")) {
if (file_exists(dirname(__DIR__, 1)."/app/settings/app_config.php")) {
save_setting_xml();
}
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/modules/app_config.php")) {
if (file_exists(dirname(__DIR__, 1)."/app/modules/app_config.php")) {
$module = new modules;
$module->xml();
//$msg = $module->msg;
}
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/vars/app_config.php")) {
if (file_exists(dirname(__DIR__, 1)."/app/vars/app_config.php")) {
save_var_xml();
}
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/call_center/app_config.php")) {
if (file_exists(dirname(__DIR__, 1)."/app/call_center/app_config.php")) {
save_call_center_xml();
}
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/gateways/app_config.php")) {
if (file_exists(dirname(__DIR__, 1)."/app/gateways/app_config.php")) {
save_gateway_xml();
}
//if (file_exists($_SERVER["PROJECT_ROOT"]."/app/ivr_menu/app_config.php")) {
//if (file_exists(dirname(__DIR__, 1)."/app/ivr_menu/app_config.php")) {
// save_ivr_menu_xml();
//}
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/sip_profiles/app_config.php")) {
if (file_exists(dirname(__DIR__, 1)."/app/sip_profiles/app_config.php")) {
save_sip_profile_xml();
}
}