Fix: Fix a lot of regression. There still a lot of new bugs to fix (like compatibility through proxy, or restore performance by avoiding huge number of fil_exists).

This commit is contained in:
Laurent Destailleur 2010-12-19 02:42:53 +00:00
parent a2149100a6
commit 1e151d9864
14 changed files with 55 additions and 134 deletions

View File

@ -279,23 +279,15 @@ if ($resql)
{
$boxname = $regs[1];
$module = $regs[2];
if (file_exists(DOL_DOCUMENT_ROOT."/".$module."/inc/boxes/".$boxname.".php"))
{
$sourcefile = DOL_DOCUMENT_ROOT."/".$module."/inc/boxes/".$boxname.".php";
}
else
{
$sourcefile = DOL_DOCUMENT_EXTMODULE."/".$module."/inc/boxes/".$boxname.".php";
}
$sourcefile = "/".$module."/inc/boxes/".$boxname.".php";
}
else
{
$boxname=preg_replace('/.php$/i','',$obj->file);
$sourcefile = DOL_DOCUMENT_ROOT."/includes/boxes/".$boxname.".php";
$sourcefile = "/includes/boxes/".$boxname.".php";
}
include_once($sourcefile);
dol_include_once($sourcefile);
$box=new $boxname($db,$obj->note);
// if (in_array($obj->rowid, $actives) && $box->box_multiple <> 1)
@ -390,23 +382,15 @@ if ($resql)
{
$boxname = $regs[1];
$module = $regs[2];
if (file_exists(DOL_DOCUMENT_ROOT."/".$module."/inc/boxes/".$boxname.".php"))
{
$sourcefile = DOL_DOCUMENT_ROOT."/".$module."/inc/boxes/".$boxname.".php";
}
else
{
$sourcefile = DOL_DOCUMENT_EXTMODULE."/".$module."/inc/boxes/".$boxname.".php";
}
$sourcefile = "/".$module."/inc/boxes/".$boxname.".php";
}
else
{
$boxname=preg_replace('/.php$/i','',$obj->file);
$sourcefile = DOL_DOCUMENT_ROOT."/includes/boxes/".$boxname.".php";
$sourcefile = "/includes/boxes/".$boxname.".php";
}
include_once($sourcefile);
dol_include_once($sourcefile);
$box=new $boxname($db,$obj->note);
if (preg_match('/^([^@]+)@([^@]+)$/i',$box->boximg))

View File

@ -376,7 +376,7 @@ if ($mode != 4)
{
if (preg_match('/^([^@]+)@([^@]+)$/i',$urlpage,$regs))
{
if (file_exists(DOL_URL_ROOT.'/'.$regs[2].'/admin/'.$regs[1]))
if (! defined('DOL_URL_EXTMODULE') || ! DOL_URL_EXTMODULE || file_exists(DOL_URL_ROOT.'/'.$regs[2].'/admin/'.$regs[1]))
{
print '<a href="'.DOL_URL_ROOT.'/'.$regs[2].'/admin/'.$regs[1].'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"),"setup").'</a>&nbsp;';
}
@ -395,7 +395,7 @@ if ($mode != 4)
}
else if (preg_match('/^([^@]+)@([^@]+)$/i',$objMod->config_page_url,$regs))
{
if (file_exists(DOL_URL_ROOT.'/'.$regs[2].'/admin/'.$regs[1]))
if (! defined('DOL_URL_EXTMODULE') || ! DOL_URL_EXTMODULE || file_exists(DOL_URL_ROOT.'/'.$regs[2].'/admin/'.$regs[1]))
{
print '<td align="right" valign="top"><a href="'.DOL_URL_ROOT.'/'.$regs[2].'/admin/'.$regs[1].'" title="'.$langs->trans("Setup").'">'.img_picto($langs->trans("Setup"),"setup").'</a></td>';
}

View File

@ -220,14 +220,7 @@ class InfoBox
$boxname = $regs[1];
$module = $regs[2];
if (file_exists(DOL_DOCUMENT_ROOT."/".$module."/inc/boxes/".$boxname.".php"))
{
$sourcefile = DOL_DOCUMENT_ROOT."/".$module."/inc/boxes/".$boxname.".php";
}
else
{
$sourcefile = DOL_DOCUMENT_EXTMODULE."/".$module."/inc/boxes/".$boxname.".php";
}
dol_include_once("/".$module."/inc/boxes/".$boxname.".php");
}
else
{
@ -288,23 +281,15 @@ class InfoBox
{
$boxname = $regs[1];
$module = $regs[2];
if (file_exists(DOL_DOCUMENT_ROOT."/".$module."/inc/boxes/".$boxname.".php"))
{
$sourcefile = DOL_DOCUMENT_ROOT."/".$module."/inc/boxes/".$boxname.".php";
}
else
{
$sourcefile = DOL_DOCUMENT_EXTMODULE."/".$module."/inc/boxes/".$boxname.".php";
}
$sourcefile = "/".$module."/inc/boxes/".$boxname.".php";
}
else
{
$boxname=preg_replace('/.php$/i','',$obj->file);
$sourcefile = DOL_DOCUMENT_ROOT."/includes/boxes/".$boxname.".php";
$sourcefile = "/includes/boxes/".$boxname.".php";
}
include_once($sourcefile);
dol_include_once($sourcefile);
$box=new $boxname($db,$obj->note);
$box->rowid=$obj->rowid;

View File

@ -687,11 +687,7 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer)
if ($facid > 0)
{
if (file_exists(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php')) {
require_once(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php');
} else {
require_once(DOL_DOCUMENT_EXTMODULE.'/'.$element.'/class/'.$subelement.'.class.php');
}
dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
$classname = ucfirst($subelement);
$srcobject = new $classname($db);
@ -1397,11 +1393,7 @@ if ($_GET['action'] == 'create')
if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; }
if ($element == 'contract') { $element = $subelement = 'contrat'; }
if (file_exists(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php')) {
require_once(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php');
} else {
require_once(DOL_DOCUMENT_EXTMODULE.'/'.$element.'/class/'.$subelement.'.class.php');
}
dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
$classname = ucfirst($subelement);
$objectsrc = new $classname($db);

View File

@ -1284,38 +1284,22 @@ class CommonObject
$daofile = 'dao_'.$module.'.class.php';
$pathroot = '';
// Include class and library of thirdparty module
if (file_exists(DOL_DOCUMENT_ROOT.$path.$actionfile) && file_exists(DOL_DOCUMENT_ROOT.$path.$daofile))
{
$pathroot = DOL_DOCUMENT_ROOT;
}
else if (file_exists(DOL_DOCUMENT_EXTMODULE.$path.$actionfile) && file_exists(DOL_DOCUMENT_EXTMODULE.$path.$daofile))
{
$pathroot = DOL_DOCUMENT_EXTMODULE;
}
if ($pathroot)
{
// Include actions class (controller)
require_once($pathroot.$path.$actionfile);
// Include actions class (controller)
dol_include_once($path.$actionfile);
// Include dataservice class (model)
require_once($pathroot.$path.$daofile);
// Include dataservice class (model)
dol_include_once($path.$daofile);
// Instantiate actions class (controller)
$controlclassname = 'Actions'.ucfirst($module);
$objModule = new $controlclassname($this->db);
$this->hooks[$objModule->module_number] = $objModule;
// Instantiate actions class (controller)
$controlclassname = 'Actions'.ucfirst($module);
$objModule = new $controlclassname($this->db);
$this->hooks[$objModule->module_number] = $objModule;
// Instantiate dataservice class (model)
$modelclassname = 'Dao'.ucfirst($module);
$this->hooks[$objModule->module_number]->object = new $modelclassname($this->db);
}
// Instantiate dataservice class (model)
$modelclassname = 'Dao'.ucfirst($module);
$this->hooks[$objModule->module_number]->object = new $modelclassname($this->db);
if (file_exists($pathroot.'/'.$module.'/lib/'.$module.'.lib.php'))
{
require_once($pathroot.'/'.$module.'/lib/'.$module.'.lib.php');
}
dol_include_once('/'.$module.'/lib/'.$module.'.lib.php');
}
}
}
@ -1388,24 +1372,10 @@ class CommonObject
//print $classfile." - ".$classpath." - ".$tplpath;
if(!class_exists($classname))
{
if (file_exists(DOL_DOCUMENT_ROOT."/".$classpath."/".$classfile.".class.php"))
{
require(DOL_DOCUMENT_ROOT."/".$classpath."/".$classfile.".class.php");
}
else
{
require(DOL_DOCUMENT_EXTMODULE."/".$classpath."/".$classfile.".class.php");
}
dol_include_once("/".$classpath."/".$classfile.".class.php");
}
$linkedObjectBlock = new $classname($this->db);
if (file_exists(DOL_DOCUMENT_ROOT.'/'.$tplpath.'/tpl/linkedobjectblock.tpl.php'))
{
include(DOL_DOCUMENT_ROOT.'/'.$tplpath.'/tpl/linkedobjectblock.tpl.php');
}
else
{
include(DOL_DOCUMENT_EXTMODULE.'/'.$tplpath.'/tpl/linkedobjectblock.tpl.php');
}
dol_include_once('/'.$tplpath.'/tpl/linkedobjectblock.tpl.php');
return $num;
}

View File

@ -143,7 +143,7 @@ class Conf
{
$modulename = strtolower($reg[1]);
if ($value == 1) $this->triggers_modules[] = DOL_DOCUMENT_ROOT.'/'.$modulename.'/inc/triggers/';
else if ($value == 2) $this->triggers_modules[] = DOL_DOCUMENT_EXTMODULE.'/'.$modulename.'/inc/triggers/';
else if ($value == 2) $this->triggers_modules[] = DOL_DOCUMENT_ROOT_ALT.'/'.$modulename.'/inc/triggers/';
}
// If this is constant for login method activated by a module
elseif (preg_match('/^MAIN_MODULE_([A-Z_]+)_LOGIN_METHOD$/i',$key,$reg))

View File

@ -64,8 +64,8 @@ function print_auguria_menu($db,$atarget,$type_user)
else
{
preg_match('/^([^<]+\.php)/i',$tabMenu[$i]['url'],$regs);
if (file_exists(DOL_DOCUMENT_ROOT.$regs[1])) $url=DOL_URL_ROOT.$tabMenu[$i]['url'];
else $url=DOL_URL_EXTMODULE.$tabMenu[$i]['url'];
$url=DOL_URL_ROOT.$tabMenu[$i]['url'];
if (defined('DOL_URL_EXTMODULE') && DOL_URL_EXTMODULE && ! file_exists(DOL_DOCUMENT_ROOT.$tabMenu[$i]['url'])) $url=DOL_URL_EXTMODULE.$tabMenu[$i]['url'];
if (! preg_match('/\?/',$url)) $url.='?';
else $url.='&';
if (! preg_match('/mainmenu/i',$url) || ! preg_match('/leftmenu/i',$url))
@ -278,8 +278,8 @@ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after)
// Add mainmenu in GET url. This make to go back on correct menu even when using Back on browser.
preg_match('/^([^<]+\.php)/i',$menu_array[$i]['url'],$regs);
if (file_exists(DOL_DOCUMENT_ROOT.$regs[1])) $url=DOL_URL_ROOT.$menu_array[$i]['url'];
else $url=DOL_URL_EXTMODULE.$menu_array[$i]['url'];
$url=DOL_URL_ROOT.$menu_array[$i]['url'];
if (defined('DOL_URL_EXTMODULE') && DOL_URL_EXTMODULE && ! file_exists(DOL_DOCUMENT_ROOT.$regs[1])) $url=DOL_URL_EXTMODULE.$menu_array[$i]['url'];
if (! preg_match('/mainmenu=/i',$menu_array[$i]['url']))
{

View File

@ -453,8 +453,8 @@ function print_eldy_menu($db,$atarget,$type_user)
}
else
{
if (file_exists(DOL_DOCUMENT_ROOT.$tabMenu[$i]['url'])) $url=DOL_URL_ROOT.$tabMenu[$i]['url'];
else $url=DOL_URL_EXTMODULE.$tabMenu[$i]['url'];
$url=DOL_URL_ROOT.$tabMenu[$i]['url'];
if (defined('DOL_URL_EXTMODULE') && DOL_URL_EXTMODULE && ! file_exists(DOL_DOCUMENT_ROOT.$tabMenu[$i]['url'])) $url=DOL_URL_EXTMODULE.$tabMenu[$i]['url'];
if (! preg_match('/\?/',$url)) $url.='?';
else $url.='&';
if (! preg_match('/mainmenu/i',$url) || ! preg_match('/leftmenu/i',$url))
@ -1387,8 +1387,8 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after)
// For external modules
preg_match('/^([^<]+\.php)/i',$menu_array[$i]['url'],$regs);
if (file_exists(DOL_DOCUMENT_ROOT.$regs[1])) $url=DOL_URL_ROOT.$menu_array[$i]['url'];
else $url=DOL_URL_EXTMODULE.$menu_array[$i]['url'];
$url=DOL_URL_ROOT.$menu_array[$i]['url'];
if (defined('DOL_URL_EXTMODULE') && DOL_URL_EXTMODULE && ! file_exists(DOL_DOCUMENT_ROOT.$regs[1])) $url=DOL_URL_EXTMODULE.$menu_array[$i]['url'];
// Menu niveau 0
if ($menu_array[$i]['level'] == 0)

View File

@ -125,7 +125,7 @@ define('MAIN_DB_PREFIX',(isset($dolibarr_main_db_prefix)?$dolibarr_main_db_prefi
define('DOL_DATA_ROOT',(isset($dolibarr_main_data_root)?$dolibarr_main_data_root:''));
define('DOL_CLASS_PATH', 'class/'); // Filsystem path to class dir
define('DOL_DOCUMENT_EXTMODULE', (isset($dolibarr_main_document_root_alt)?$dolibarr_main_document_root_alt:'')); // Filesystem path to external modules dir
define('DOL_DOCUMENT_ROOT_ALT', (isset($dolibarr_main_document_root_alt)?$dolibarr_main_document_root_alt:'')); // Filesystem path to external root dir (external modules)
define('DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root)?$dolibarr_main_url_root:'')); // URL relative root
$uri=preg_replace('/^http(s?):\/\//i','',constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http*
$suburi = strstr ($uri, '/'); // $suburi contains url without domain

View File

@ -62,6 +62,18 @@ function GETPOST($paramname,$check='',$method=0)
return $out;
}
/**
* Make an include_once using default root and alternate root if it fails.
* @param relpath Relative path to file (Ie: mydir/myfile, ../myfile, ...)
* @return int Result
*/
function dol_include_once($relpath)
{
$res=@include_once(DOL_DOCUMENT_ROOT.$relpath);
if (! $res && defined('DOL_DOCUMENT_ROOT_ALT')) $res=@include_once(DOL_DOCUMENT_ROOT_ALT.$relpath);
return $res;
}
/**
* Create a clone of instance of object (new instance with same properties)
* This function works for both PHP4 and PHP5.

View File

@ -159,14 +159,7 @@ function dol_loginfunction($langs,$conf,$mysoc)
{
$rowspan++;
if(file_exists(DOL_DOCUMENT_ROOT.'/multicompany/class/actions_multicompany.class.php'))
{
$res=@include_once(DOL_DOCUMENT_ROOT.'/multicompany/class/actions_multicompany.class.php');
}
else
{
$res=@include_once(DOL_DOCUMENT_EXTMODULE.'/multicompany/class/actions_multicompany.class.php');
}
$res=dol_include_once('/multicompany/class/actions_multicompany.class.php');
if ($res)
{
$mc = new ActionsMulticompany($db);

View File

@ -1068,15 +1068,8 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a
{
if ($user->admin && ! $user->entity)
{
if(file_exists(DOL_DOCUMENT_ROOT.'/multicompany/class/actions_multicompany.class.php'))
{
$res=@include_once(DOL_DOCUMENT_ROOT.'/multicompany/class/actions_multicompany.class.php');
}
else
{
$res=@include_once(DOL_DOCUMENT_EXTMODULE.'/multicompany/class/actions_multicompany.class.php');
}
$res=@dol_include_once('/multicompany/class/actions_multicompany.class.php');
if ($res)
{
//$mc = new ActionsMulticompany($db);

View File

@ -104,7 +104,7 @@ if (empty($dolibarr_main_data_root))
define('DOL_DOCUMENT_ROOT', $dolibarr_main_document_root); // Filesystem core php (htdocs)
define('DOL_DATA_ROOT', $dolibarr_main_data_root); // Filesystem data (documents)
define('DOL_CLASS_PATH', 'class/'); // Filesystem path to class dir
define('DOL_DOCUMENT_EXTMODULE', $dolibarr_main_document_root_alt); // Filesystem path to external modules dir
define('DOL_DOCUMENT_ROOT_ALT', $dolibarr_main_document_root_alt); // Filesystem path to external modules dir
// If dolibarr_main_url_root = auto (Hidden feature for developers only), we try to forge it.
if ($dolibarr_main_url_root == 'auto' && ! empty($_SERVER["SCRIPT_URL"]) && ! empty($_SERVER["SCRIPT_URI"]))
{

View File

@ -216,15 +216,7 @@ if (! empty($conf->global->MAIN_MODULE_MULTICOMPANY) && ! $disabled)
{
global $db;
if(file_exists(DOL_DOCUMENT_ROOT.'/multicompany/class/actions_multicompany.class.php'))
{
$res=@include_once(DOL_DOCUMENT_ROOT.'/multicompany/class/actions_multicompany.class.php');
}
else
{
$res=@include_once(DOL_DOCUMENT_EXTMODULE.'/multicompany/class/actions_multicompany.class.php');
}
$res=dol_include_once('/multicompany/class/actions_multicompany.class.php');
if ($res)
{
$mc = new ActionsMulticompany($db);