Skip to content

Commit

Permalink
NEW Performance enhancement: Replace dirname(__FILE__) with __DIR__
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Mar 6, 2019
1 parent d4409ff commit 0c2a0c6
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 15 deletions.
5 changes: 2 additions & 3 deletions htdocs/core/lib/website.lib.php
Expand Up @@ -22,7 +22,6 @@
*/



/**
* Convert a page content to have correct links (based on DOL_URL_ROOT) into an html content.
* Used to ouput the page on the Preview from backoffice.
Expand Down Expand Up @@ -661,7 +660,7 @@ function dolSavePageContent($filetpl, $object, $objectpage)

$tplcontent ='';
$tplcontent.= "<?php // BEGIN PHP\n";
$tplcontent.= '$websitekey=basename(dirname(__FILE__)); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n";
$tplcontent.= '$websitekey=basename(__DIR__); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n";
$tplcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Not already loaded"."\n";
$tplcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
$tplcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
Expand Down Expand Up @@ -731,7 +730,7 @@ function dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper)
dol_delete_file($fileindex);
$indexcontent = '<?php'."\n";
$indexcontent.= "// BEGIN PHP File generated to provide an index.php as Home Page or alias redirector - DO NOT MODIFY - It is just a generated wrapper.\n";
$indexcontent.= '$websitekey=basename(dirname(__FILE__)); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n";
$indexcontent.= '$websitekey=basename(__DIR__); if (empty($websitepagefile)) $websitepagefile=__FILE__;'."\n";
$indexcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load master if not already loaded\n";
$indexcontent.= 'if (! empty($_GET[\'pageref\']) || ! empty($_GET[\'pagealiasalt\']) || ! empty($_GET[\'pageid\'])) {'."\n";
$indexcontent.= " require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
Expand Down
2 changes: 1 addition & 1 deletion htdocs/holiday/common.inc.php
Expand Up @@ -23,7 +23,7 @@
* \brief Common load of data
*/

require_once realpath(dirname(__FILE__)).'/../main.inc.php';
require_once realpath(__DIR__).'/../main.inc.php';
if (! class_exists('Holiday')) {
require_once DOL_DOCUMENT_ROOT. '/holiday/class/holiday.class.php';
}
Expand Down
2 changes: 1 addition & 1 deletion htdocs/install/upgrade.php
Expand Up @@ -88,7 +88,7 @@
// Test if batch mode
$sapi_type = php_sapi_name();
$script_file = basename(__FILE__);
$path=dirname(__FILE__).'/';
$path=__DIR__.'/';
if (substr($sapi_type, 0, 3) == 'cli')
{
print 'Syntax from command line: '.$script_file." x.y.z a.b.c\n";
Expand Down
2 changes: 1 addition & 1 deletion htdocs/install/upgrade2.php
Expand Up @@ -96,7 +96,7 @@
// Test if batch mode
$sapi_type = php_sapi_name();
$script_file = basename(__FILE__);
$path=dirname(__FILE__).'/';
$path=__DIR__.'/';
if (substr($sapi_type, 0, 3) == 'cli')
{
print 'Syntax from command line: '.$script_file." x.y.z a.b.c [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE...]\n";
Expand Down
2 changes: 1 addition & 1 deletion htdocs/modulebuilder/template/scripts/myobject.php
Expand Up @@ -25,7 +25,7 @@

$sapi_type = php_sapi_name();
$script_file = basename(__FILE__);
$path=dirname(__FILE__).'/';
$path=__DIR__.'/';

// Test if batch mode
if (substr($sapi_type, 0, 3) == 'cgi') {
Expand Down
14 changes: 7 additions & 7 deletions htdocs/website/index.php
Expand Up @@ -920,7 +920,7 @@

/* We disable php code since htmlheader is never executed as an include but only read by fgets_content.
$htmlheadercontent.= "<?php // BEGIN PHP\n";
$htmlheadercontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
$htmlheadercontent.= '$websitekey=basename(__DIR__);'."\n";
$htmlheadercontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Not already loaded"."\n";
$htmlheadercontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
$htmlheadercontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
Expand All @@ -943,8 +943,8 @@
$csscontent ='';

$csscontent.= "<?php // BEGIN PHP\n";
$csscontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
$csscontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once dirname(__FILE__).'/master.inc.php'; } // Not already loaded"."\n"; // For the css, we need to set path of master using the dirname of css file.
$csscontent.= '$websitekey=basename(__DIR__);'."\n";
$csscontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Not already loaded"."\n"; // For the css, we need to set path of master using the dirname of css file.
$csscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
$csscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
$csscontent.= "ob_start();\n";
Expand Down Expand Up @@ -976,8 +976,8 @@
$jscontent ='';

$jscontent.= "<?php // BEGIN PHP\n";
$jscontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
$jscontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once dirname(__FILE__).'/master.inc.php'; } // Not already loaded"."\n"; // For the css, we need to set path of master using the dirname of css file.
$jscontent.= '$websitekey=basename(__DIR__);'."\n";
$jscontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once __DIR__.'/master.inc.php'; } // Not already loaded"."\n"; // For the css, we need to set path of master using the dirname of css file.
$jscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
$jscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
$jscontent.= "ob_start();\n";
Expand Down Expand Up @@ -1009,7 +1009,7 @@
$robotcontent ='';

/*$robotcontent.= "<?php // BEGIN PHP\n";
$robotcontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
$robotcontent.= '$websitekey=basename(__DIR__);'."\n";
$robotcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Not already loaded"."\n";
$robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
$robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
Expand Down Expand Up @@ -1042,7 +1042,7 @@
$htaccesscontent ='';

/*$htaccesscontent.= "<?php // BEGIN PHP\n";
$htaccesscontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
$htaccesscontent.= '$websitekey=basename(__DIR__);'."\n";
$htaccesscontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Not already loaded"."\n";
$htaccesscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
$htaccesscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
Expand Down
2 changes: 1 addition & 1 deletion htdocs/website/samples/wrapper.html
@@ -1,6 +1,6 @@
<?php
// BEGIN PHP File wrapper.php - DO NOT MODIFY - It is just a copy of wrapper.html sample.
$websitekey=basename(dirname(__FILE__));
$websitekey=basename(__DIR__);
if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load master if not already loaded
include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';

Expand Down

0 comments on commit 0c2a0c6

Please sign in to comment.