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

@@ -106,7 +106,7 @@ class plugin_database {
//initialize a template object
$view = new template();
$view->engine = 'smarty';
$view->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/core/authentication/resources/views/';
$view->template_dir = dirname(__DIR__, 5) . '/core/authentication/resources/views/';
$view->cache_dir = sys_get_temp_dir();
$view->init();
@@ -210,7 +210,7 @@ class plugin_database {
$user_authorized = false;
//check if contacts app exists
$contacts_exists = file_exists($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/core/contacts/') ? true : false;
$contacts_exists = file_exists(dirname(__DIR__, 5) . '/core/contacts/') ? true : false;
//check the username and password if they don't match then redirect to the login
$sql = "select ";

View File

@@ -101,7 +101,7 @@ class plugin_email {
//initialize a template object
$view = new template();
$view->engine = 'smarty';
$view->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/core/authentication/resources/views/';
$view->template_dir = dirname(__DIR__, 5) . '/core/authentication/resources/views/';
$view->cache_dir = sys_get_temp_dir();
$view->init();
@@ -335,7 +335,7 @@ class plugin_email {
//initialize a template object
$view = new template();
$view->engine = 'smarty';
$view->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/core/authentication/resources/views/';
$view->template_dir = dirname(__DIR__, 5) . '/core/authentication/resources/views/';
$view->cache_dir = sys_get_temp_dir();
$view->init();
@@ -416,7 +416,7 @@ class plugin_email {
unset($_POST['authentication_code']);
//check if contacts app exists
$contacts_exists = file_exists($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/core/contacts/') ? true : false;
$contacts_exists = file_exists(dirname(__DIR__, 5) . '/core/contacts/') ? true : false;
//get the user details
if ($auth_valid) {

View File

@@ -72,7 +72,7 @@ class plugin_ldap {
//initialize a template object
$view = new template();
$view->engine = 'smarty';
$view->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/core/authentication/resources/views/';
$view->template_dir = dirname(__DIR__, 5).'/core/authentication/resources/views/';
$view->cache_dir = sys_get_temp_dir();
$view->init();

View File

@@ -113,7 +113,7 @@ class plugin_totp {
//initialize a template object
$view = new template();
$view->engine = 'smarty';
$view->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/core/authentication/resources/views/';
$view->template_dir = dirname(__DIR__, 5) . '/core/authentication/resources/views/';
$view->cache_dir = sys_get_temp_dir();
$view->init();
@@ -214,7 +214,7 @@ class plugin_totp {
//initialize a template object
$view = new template();
$view->engine = 'smarty';
$view->template_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/core/authentication/resources/views/';
$view->template_dir = dirname(__DIR__, 5) . '/core/authentication/resources/views/';
$view->cache_dir = sys_get_temp_dir();
$view->init();
@@ -347,7 +347,7 @@ class plugin_totp {
unset($_POST['authentication_code']);
//check if contacts app exists
$contacts_exists = file_exists($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/core/contacts/') ? true : false;
$contacts_exists = file_exists(dirname(__DIR__, 5) . '/core/contacts/') ? true : false;
//get the user details
if ($auth_valid) {

View File

@@ -253,10 +253,10 @@
}
echo button::create(['type'=>'button','label'=>$text['button-qr_code'],'icon'=>'qrcode','collapse'=>'hide-sm-dn','onclick'=>"$('#qr_code_container').fadeIn(400);"]);
echo button::create(['type'=>'button','label'=>$text['button-vcard'],'icon'=>'address-card','collapse'=>'hide-sm-dn','link'=>'contacts_vcard.php?id='.urlencode($contact_uuid).'&type=download']);
if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/invoices')) {
if (is_dir(dirname(__DIR__, 2).'/app/invoices')) {
echo button::create(['type'=>'button','label'=>$text['button-invoices'],'icon'=>'file-invoice-dollar','collapse'=>'hide-sm-dn','link'=>'../invoices/invoices.php?id='.urlencode($contact_uuid)]);
}
if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/certificates')) {
if (is_dir(dirname(__DIR__, 2).'/app/certificates')) {
echo button::create(['type'=>'button','label'=>$text['button-certificate'],'icon'=>'certificate','collapse'=>'hide-sm-dn','link'=>'../certificates/index.php?name='.urlencode($contact_name_given." ".$contact_name_family)]);
}
if (!empty($contact_user_uuid) && permission_exists('user_edit') && is_uuid($contact_user_uuid)) {

View File

@@ -201,7 +201,7 @@ if (!empty($_GET)) {
}
//include
require_once $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/qr/qrcode.php";
require_once dirname(__DIR__, 2)."/resources/qr/qrcode.php";
//error correction level
//QR_ERROR_CORRECT_LEVEL_L : $e = 0;

View File

@@ -174,7 +174,7 @@ if ($domains_processed == 1) {
unset($sql, $parameters);
//add the dashboards
$dashboard_config_file = glob($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/core/dashboard/resources/dashboard/config.php');
$dashboard_config_file = glob(dirname(__DIR__, 2).'/core/dashboard/resources/dashboard/config.php');
$x = 0;
foreach($dashboard_config_file as $file) {
include ($file);
@@ -224,7 +224,7 @@ if ($domains_processed == 1) {
unset($sql, $parameters);
//add the dashboard widgets
$config_files = glob($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/*/*/resources/dashboard/config.php');
$config_files = glob(dirname(__DIR__, 2).'/*/*/resources/dashboard/config.php');
$x = 0;
foreach($config_files as $file) {
include ($file);

View File

@@ -523,7 +523,7 @@
//build the $widget_tools array
$i = 0;
foreach(glob($_SERVER["DOCUMENT_ROOT"].'/*/*/resources/dashboard/*.php') as $value) {
foreach(glob(dirname(__DIR__, 2).'/*/*/resources/dashboard/*.php') as $value) {
//skip adding config.php to the array
if (basename($value) === 'config.php') {
@@ -534,14 +534,14 @@
$value = str_replace('\\', '/', $value);
//prepare the key
$key_replace[] = $_SERVER["DOCUMENT_ROOT"].'/core/';
$key_replace[] = $_SERVER["DOCUMENT_ROOT"].'/app/';
$key_replace[] = dirname(__DIR__, 2).'/core/';
$key_replace[] = dirname(__DIR__, 2).'/app/';
$key_replace[] = 'resources/dashboard/';
$key_replace[] = '.php';
$key = str_replace($key_replace, '', $value);
//prepare the value
$value_replace[] = $_SERVER["DOCUMENT_ROOT"].'/';
$value_replace[] = dirname(__DIR__, 2).'/';
$value = str_replace($value_replace, '', $value);
//build the array
@@ -847,8 +847,8 @@ document.addEventListener('DOMContentLoaded', function() {
echo " <tr id='tr_widget_icon' ".(!in_array('widget_icon', $widget_settings) ? "style='display: none;'" : null).">\n";
echo " <td class='vncell'>".$text['label-icon']."</td>\n";
echo " <td class='vtable' style='vertical-align: bottom;'>\n";
if (file_exists($_SERVER["PROJECT_ROOT"].'/resources/fontawesome/fa_icons.php')) {
include $_SERVER["PROJECT_ROOT"].'/resources/fontawesome/fa_icons.php';
if (file_exists(dirname(__DIR__, 2).'/resources/fontawesome/fa_icons.php')) {
include dirname(__DIR__, 2).'/resources/fontawesome/fa_icons.php';
}
if (!empty($font_awesome_icons) && is_array($font_awesome_icons)) {
echo "<table cellpadding='0' cellspacing='0' border='0'>\n";

View File

@@ -397,8 +397,8 @@
elseif ($category == "domain" && $subcategory == "template" && $name == "name" ) {
echo " <select class='formfld' id='default_setting_value' name='default_setting_value' style=''>\n";
//add all the themes to the list
$theme_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes';
if ($handle = opendir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes')) {
$theme_dir = dirname(__DIR__, 2).'/themes';
if ($handle = opendir(dirname(__DIR__, 2).'/themes')) {
while (false !== ($dir_name = readdir($handle))) {
if ($dir_name != "." && $dir_name != ".." && $dir_name != ".svn" && $dir_name != ".git" && is_dir($theme_dir.'/'.$dir_name)) {
$dir_label = str_replace('_', ' ', $dir_name);

View File

@@ -212,7 +212,7 @@
//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) {
include($config_path);

View File

@@ -481,8 +481,8 @@
echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value' style=''>\n";
echo " <option value=''></option>\n";
//add all the themes to the list
$theme_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes';
if ($handle = opendir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes')) {
$theme_dir = dirname(__DIR__, 2).'/themes';
if ($handle = opendir(dirname(__DIR__, 2).'/themes')) {
while (false !== ($dir_name = readdir($handle))) {
if ($dir_name != "." && $dir_name != ".." && $dir_name != ".svn" && $dir_name != ".git" && is_dir($theme_dir.'/'.$dir_name)) {
$dir_label = str_replace('_', ' ', $dir_name);

View File

@@ -472,7 +472,7 @@
}
//if single-tenant and variables exist, update variables > domain value to match new domain
if (count($_SESSION['domains']) == 1 && file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/vars/")) {
if (count($_SESSION['domains']) == 1 && file_exists(dirname(__DIR__, 2)."/app/vars/")) {
$sql = "update v_vars set ";
$sql .= "var_value = :var_value ";
$sql .= "where var_name = 'domain' ";

View File

@@ -74,7 +74,7 @@
}
//get the domains
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/domains/app_config.php") && !is_cli()){
if (file_exists(dirname(__DIR__, 2)."/app/domains/app_config.php") && !is_cli()){
require_once "app/domains/resources/domains.php";
}

View File

@@ -30,7 +30,7 @@
require_once "resources/paging.php";
//redirect admin to app instead
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/domains/app_config.php") && !permission_exists('domain_all') && !is_cli()) {
if (file_exists(dirname(__DIR__, 2)."/app/domains/app_config.php") && !permission_exists('domain_all') && !is_cli()) {
header("Location: ".PROJECT_PATH."/app/domains/domains.php");
exit;
}

View File

@@ -64,7 +64,7 @@ class permission {
function delete() {
//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__, 4) . "/*/*/app_config.php");
$x = 0;
foreach ($config_list as $config_path) {
include($config_path);
@@ -165,7 +165,7 @@ class permission {
$this->database_group_permissions = $this->database->select($sql, null, 'all');
//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__, 4) . "/*/*/app_config.php");
$x = 0;
foreach ($config_list as $config_path) {
include($config_path);

View File

@@ -27,8 +27,8 @@
//set the include path
$document_root = dirname(__DIR__, 2);
set_include_path($document_root);
$_SERVER["DOCUMENT_ROOT"] = $document_root;
$_SERVER["PROJECT_ROOT"] = $document_root;
//defined for backwards compatibility
define("PROJECT_PATH", '');
//includes files
@@ -172,7 +172,7 @@
sleep(1);
//add the database schema
$output = shell_exec('cd '.$_SERVER["DOCUMENT_ROOT"].' && php /var/www/fusionpbx/core/upgrade/upgrade_schema.php');
$output = shell_exec('cd '.dirname(__DIR__, 2).' && php /var/www/fusionpbx/core/upgrade/upgrade_schema.php');
//connect to the database
$database = new database;
@@ -222,7 +222,7 @@
$_SESSION['domain_name'] = $domain_name;
//app defaults
$output = shell_exec('cd '.$_SERVER["DOCUMENT_ROOT"].' && php /var/www/fusionpbx/core/upgrade/upgrade_domains.php');
$output = shell_exec('cd '.dirname(__DIR__, 2).' && php /var/www/fusionpbx/core/upgrade/upgrade_domains.php');
//prepare the user settings
$admin_username = $_SESSION['install']['admin_username'];
@@ -306,7 +306,7 @@
}
#app defaults
$output = shell_exec('cd '.$_SERVER["DOCUMENT_ROOT"].' && php /var/www/fusionpbx/core/upgrade/upgrade_domains.php');
$output = shell_exec('cd '.dirname(__DIR__, 2).' && php /var/www/fusionpbx/core/upgrade/upgrade_domains.php');
//install completed - prompt the user to login
header("Location: /logout.php");
@@ -330,7 +330,7 @@
//initialize a template object
$view = new template();
$view->engine = 'smarty';
$view->template_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/core/install/resources/views/';
$view->template_dir = dirname(__DIR__, 2).'/core/install/resources/views/';
$view->cache_dir = sys_get_temp_dir();
$view->init();

View File

@@ -72,7 +72,7 @@ class install {
$system_drive = getenv('SystemDrive');
$config_path = $system_drive . DIRECTORY_SEPARATOR . 'ProgramData' . DIRECTORY_SEPARATOR . 'fusionpbx';
$config_file = $config_path . DIRECTORY_SEPARATOR . 'config.conf';
$document_root = $_SERVER["DOCUMENT_ROOT"];
$document_root = dirname(__DIR__, 4);
$conf_dir = $_SERVER['ProgramFiles'] . DIRECTORY_SEPARATOR . 'freeswitch' . DIRECTORY_SEPARATOR . 'conf';
$sounds_dir = $_SERVER['ProgramFiles'] . DIRECTORY_SEPARATOR . 'freeswitch' . DIRECTORY_SEPARATOR . 'sounds';
@@ -82,7 +82,7 @@ class install {
$voicemail_dir = $_SERVER['ProgramFiles'] . DIRECTORY_SEPARATOR . 'freeswitch' . DIRECTORY_SEPARATOR . 'voicemail';
$scripts_dir = $_SERVER['ProgramFiles'] . DIRECTORY_SEPARATOR . 'freeswitch' . DIRECTORY_SEPARATOR . 'scripts';
$php_dir = dirname(PHP_BINARY);
$cache_location = dirname($_SERVER['DOCUMENT_ROOT']) . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'fusionpbx';
$cache_location = dirname(dirname(__DIR__, 4)) . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'fusionpbx';
break;
}

View File

@@ -423,8 +423,8 @@
echo " <tr>";
echo " <td class='vncell'>".$text['label-icon']."</td>";
echo " <td class='vtable' style='vertical-align: bottom;'>";
if (file_exists($_SERVER["PROJECT_ROOT"].'/resources/fontawesome/fa_icons.php')) {
include $_SERVER["PROJECT_ROOT"].'/resources/fontawesome/fa_icons.php';
if (file_exists(dirname(__DIR__, 2).'/resources/fontawesome/fa_icons.php')) {
include dirname(__DIR__, 2).'/resources/fontawesome/fa_icons.php';
}
if (!empty($font_awesome_icons) && is_array($font_awesome_icons)) {
echo "<table cellpadding='0' cellspacing='0' border='0'>\n";

View File

@@ -54,7 +54,7 @@
$language = $settings->get('domain', 'language', 'en-us');
//find optional apps with repos
$updateable_repos = git_find_repos($_SERVER["PROJECT_ROOT"]."/app");
$updateable_repos = git_find_repos(dirname(__DIR__, 2)."/app");
if (!empty($updateable_repos) && is_array($updateable_repos) && @sizeof($updateable_repos) != 0) {
foreach ($updateable_repos as $app_path => $repo) {
//set the value
@@ -97,7 +97,7 @@
//run source update
if (!empty($action["upgrade_source"]) && permission_exists("upgrade_source") && !is_dir("/usr/share/examples/fusionpbx")) {
$project_update_status = git_pull($_SERVER["PROJECT_ROOT"]);
$project_update_status = git_pull(dirname(__DIR__, 2));
$_SESSION["response"]["upgrade_source"] = $project_update_status['message'];
@@ -289,7 +289,7 @@
echo "<br /><br />";
echo "<div class='card'>\n";
if (permission_exists("upgrade_source") && !is_dir("/usr/share/examples/fusionpbx") && is_writeable($_SERVER["PROJECT_ROOT"]."/.git")) {
if (permission_exists("upgrade_source") && !is_dir("/usr/share/examples/fusionpbx") && is_writeable(dirname(__DIR__, 2)."/.git")) {
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr onclick=\"$('#tr_applications').slideToggle('fast');\">\n";
echo " <td width='30%' class='vncellreq' style='vertical-align: middle;'>\n";
@@ -318,7 +318,7 @@
echo " <input type='checkbox' name='action[upgrade_source]' id='do_source' value='1' onclick=\"event.stopPropagation(); if (this.checked == false) { document.getElementById('view_source_code_options').checked = false; }\">\n";
echo " &nbsp;".$text['description-upgrade_source']."<br />\n";
//show current git version info
chdir($_SERVER["PROJECT_ROOT"]);
chdir(dirname(__DIR__, 2));
exec("git rev-parse --abbrev-ref HEAD 2>&1", $git_current_branch, $branch_return_value);
$git_current_branch = $git_current_branch[0];
exec("git log --pretty=format:'%H' -n 1 2>&1", $git_current_commit, $commit_return_value);

View File

@@ -67,7 +67,7 @@
$system_drive = getenv('SystemDrive');
$config_path = $system_drive . DIRECTORY_SEPARATOR . 'ProgramData' . DIRECTORY_SEPARATOR . 'fusionpbx' ;
$config_file = $config_path.DIRECTORY_SEPARATOR.'config.conf';
$document_root = $_SERVER["DOCUMENT_ROOT"];
$document_root = dirname(__DIR__, 2);
$conf_dir = $_SERVER['ProgramFiles'].DIRECTORY_SEPARATOR.'freeswitch'.DIRECTORY_SEPARATOR.'conf';
$sounds_dir = $_SERVER['ProgramFiles'].DIRECTORY_SEPARATOR.'freeswitch'.DIRECTORY_SEPARATOR.'sounds';
@@ -77,7 +77,7 @@
$voicemail_dir = $_SERVER['ProgramFiles'].DIRECTORY_SEPARATOR.'freeswitch'.DIRECTORY_SEPARATOR.'voicemail';
$scripts_dir = $_SERVER['ProgramFiles'].DIRECTORY_SEPARATOR.'freeswitch'.DIRECTORY_SEPARATOR.'scripts';
$php_dir = dirname(PHP_BINARY);
$cache_location = dirname($_SERVER['DOCUMENT_ROOT']).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'fusionpbx';
$cache_location = dirname(dirname(__DIR__, 2)).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'fusionpbx';
}
//make the config directory

View File

@@ -28,7 +28,6 @@
if(defined('STDIN')) {
//includes files
require_once dirname(__DIR__, 2) . "/resources/require.php";
$_SERVER["DOCUMENT_ROOT"] = $document_root;
$display_type = 'text'; //html, text
}
else if (!$included) {

View File

@@ -446,8 +446,8 @@ if (!empty($_POST) && empty($_POST["persistformvar"])) {
echo " <select class='formfld' id='user_setting_value' name='user_setting_value' style=''>\n";
echo " <option value=''></option>\n";
//add all the themes to the list
$theme_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes';
if ($handle = opendir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes')) {
$theme_dir = dirname(__DIR__, 2).'/themes';
if ($handle = opendir(dirname(__DIR__, 2).'/themes')) {
while (false !== ($dir_name = readdir($handle))) {
if ($dir_name != "." && $dir_name != ".." && $dir_name != ".svn" && $dir_name != ".git" && is_dir($theme_dir.'/'.$dir_name)) {
$dir_label = str_replace('_', ' ', $dir_name);

View File

@@ -163,7 +163,7 @@ if ($domains_processed == 1) {
}
//insert default password reset email template
if (file_exists($_SERVER['DOCUMENT_ROOT'].'/app/email_templates')) {
if (file_exists(dirname(__DIR__, 2).'/app/email_templates')) {
//add the email templates to the database
$sql = "select count(*) as num_rows from v_email_templates ";

View File

@@ -578,7 +578,7 @@
settings::clear_cache();
//if call center installed
if ($action == 'edit' && permission_exists('user_edit') && file_exists($_SERVER["PROJECT_ROOT"]."/app/call_centers/app_config.php")) {
if ($action == 'edit' && permission_exists('user_edit') && file_exists(dirname(__DIR__, 2)."/app/call_centers/app_config.php")) {
//get the call center agent uuid
$sql = "select call_center_agent_uuid from v_call_center_agents ";
$sql .= "where domain_uuid = :domain_uuid ";

View File

@@ -464,7 +464,7 @@
settings::clear_cache();
//if call center installed
if ($action == 'edit' && file_exists($_SERVER["PROJECT_ROOT"]."/app/call_centers/app_config.php")) {
if ($action == 'edit' && file_exists(dirname(__DIR__, 2)."/app/call_centers/app_config.php")) {
//get the call center agent uuid
$sql = "select call_center_agent_uuid from v_call_center_agents ";
$sql .= "where domain_uuid = :domain_uuid ";