Skip to content

Commit

Permalink
Fix: Fix a lot of regression. There still a lot of new bugs to fix (l…
Browse files Browse the repository at this point in the history
…ike compatibility through proxy, or restore performance by avoiding huge number of fil_exists).
  • Loading branch information
eldy committed Dec 19, 2010
1 parent a214910 commit 1e151d9
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 134 deletions.
28 changes: 6 additions & 22 deletions htdocs/admin/boxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,23 +279,15 @@
{
$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)
Expand Down Expand Up @@ -390,23 +382,15 @@
{
$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))
Expand Down
4 changes: 2 additions & 2 deletions htdocs/admin/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@
{
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;';
}
Expand All @@ -395,7 +395,7 @@
}
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>';
}
Expand Down
23 changes: 4 additions & 19 deletions htdocs/boxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,7 @@ function listBoxes($zone,$user)
$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
{
Expand Down Expand Up @@ -288,23 +281,15 @@ function listBoxes($zone,$user)
{
$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;
Expand Down
12 changes: 2 additions & 10 deletions htdocs/compta/facture.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,11 +687,7 @@

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);
Expand Down Expand Up @@ -1397,11 +1393,7 @@
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);
Expand Down
58 changes: 14 additions & 44 deletions htdocs/core/class/commonobject.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1284,38 +1284,22 @@ function callHooks($type='objectcard')
$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');
}
}
}
Expand Down Expand Up @@ -1388,24 +1372,10 @@ function showLinkedObjectBlock($objecttype,$objectid,$somethingshown=0)
//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;
}
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/class/conf.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function setValues($db)
{
$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))
Expand Down
8 changes: 4 additions & 4 deletions htdocs/includes/menus/standard/auguria.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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']))
{
Expand Down
8 changes: 4 additions & 4 deletions htdocs/includes/menus/standard/eldy.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion htdocs/install/inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@

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
Expand Down
12 changes: 12 additions & 0 deletions htdocs/lib/functions.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 1 addition & 8 deletions htdocs/lib/security.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 2 additions & 9 deletions htdocs/main.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion htdocs/master.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
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"]))
{
Expand Down
10 changes: 1 addition & 9 deletions htdocs/user/passwordforgotten.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,7 @@
{
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);
Expand Down

0 comments on commit 1e151d9

Please sign in to comment.