From 4a577412d5cbb47a4cd435df4d2db8e8552a122e Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 15 Dec 2010 15:12:35 +0000 Subject: [PATCH] New: add directory for external module and other customization --- htdocs/admin/boxes.php | 42 ++++++++++++++++++++++++++++------------ htdocs/boxes.php | 44 +++++++++++++++++++++++++++++------------- htdocs/master.inc.php | 2 +- 3 files changed, 62 insertions(+), 26 deletions(-) diff --git a/htdocs/admin/boxes.php b/htdocs/admin/boxes.php index 98f826cbc61..c9da0a20ab2 100644 --- a/htdocs/admin/boxes.php +++ b/htdocs/admin/boxes.php @@ -277,17 +277,26 @@ if ($resql) if (preg_match('/^([^@]+)@([^@]+)$/i',$obj->file,$regs)) { - $module = $regs[1]; - $sourcefile = "/".$regs[2]."/inc/boxes/".$module.".php"; + $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_EXTMODULE_ROOT."/".$module."/inc/boxes/".$boxname.".php"; + } } else { - $module=preg_replace('/.php$/i','',$obj->file); - $sourcefile = "/includes/boxes/".$module.".php"; + $boxname=preg_replace('/.php$/i','',$obj->file); + $sourcefile = DOL_DOCUMENT_ROOT."/includes/boxes/".$boxname.".php"; } - include_once(DOL_DOCUMENT_ROOT.$sourcefile); - $box=new $module($db,$obj->note); + include_once($sourcefile); + $box=new $boxname($db,$obj->note); // if (in_array($obj->rowid, $actives) && $box->box_multiple <> 1) if (in_array($obj->rowid, $actives)) @@ -379,17 +388,26 @@ if ($resql) if (preg_match('/^([^@]+)@([^@]+)$/i',$obj->file,$regs)) { - $module = $regs[1]; - $sourcefile = "/".$regs[2]."/inc/boxes/".$module.".php"; + $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_EXTMODULE_ROOT."/".$module."/inc/boxes/".$boxname.".php"; + } } else { - $module=preg_replace('/.php$/i','',$obj->file); - $sourcefile = "/includes/boxes/".$module.".php"; + $boxname=preg_replace('/.php$/i','',$obj->file); + $sourcefile = DOL_DOCUMENT_ROOT."/includes/boxes/".$boxname.".php"; } - include_once(DOL_DOCUMENT_ROOT.$sourcefile); - $box=new $module($db,$obj->note); + include_once($sourcefile); + $box=new $boxname($db,$obj->note); if (preg_match('/^([^@]+)@([^@]+)$/i',$box->boximg)) { diff --git a/htdocs/boxes.php b/htdocs/boxes.php index 37cebf36638..c7aff81e61e 100644 --- a/htdocs/boxes.php +++ b/htdocs/boxes.php @@ -1,7 +1,7 @@ * Copyright (C) 2004-2010 Laurent Destailleur - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005-2010 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -217,17 +217,26 @@ class InfoBox if (preg_match('/^([^@]+)@([^@]+)$/i',$obj->file,$regs)) { - $module = $regs[1]; - $sourcefile = "/".$regs[2]."/inc/boxes/".$module.".php"; + $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_EXTMODULE_ROOT."/".$module."/inc/boxes/".$boxname.".php"; + } } else { - $module=preg_replace('/.php$/i','',$obj->file); - $sourcefile = "/includes/boxes/".$module.".php"; + $boxname=preg_replace('/.php$/i','',$obj->file); + $sourcefile = DOL_DOCUMENT_ROOT."/includes/boxes/".$boxname.".php"; } - include_once(DOL_DOCUMENT_ROOT.$sourcefile); - $box=new $module($db,$obj->note); + include_once($sourcefile); + $box=new $boxname($db,$obj->note); $box->rowid=$obj->rowid; $box->box_id=$obj->box_id; @@ -277,17 +286,26 @@ class InfoBox if (preg_match('/^([^@]+)@([^@]+)$/i',$obj->file,$regs)) { - $module = $regs[1]; - $sourcefile = "/".$regs[2]."/inc/boxes/".$module.".php"; + $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_EXTMODULE_ROOT."/".$module."/inc/boxes/".$boxname.".php"; + } } else { - $module=preg_replace('/.php$/i','',$obj->file); - $sourcefile = "/includes/boxes/".$module.".php"; + $boxname=preg_replace('/.php$/i','',$obj->file); + $sourcefile = DOL_DOCUMENT_ROOT."/includes/boxes/".$boxname.".php"; } - include_once(DOL_DOCUMENT_ROOT.$sourcefile); - $box=new $module($db,$obj->note); + include_once($sourcefile); + $box=new $boxname($db,$obj->note); $box->rowid=$obj->rowid; $box->box_id=$obj->box_id; diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php index 922692c8864..6b2926dce5c 100644 --- a/htdocs/master.inc.php +++ b/htdocs/master.inc.php @@ -117,7 +117,7 @@ $suburi = strstr ($uri, '/'); // $suburi contains url without domain if ($suburi == '/') $suburi = ''; // If $suburi is /, it is now '' define('DOL_URL_ROOT', $suburi); // URL relative root ('', '/dolibarr', ...) if (! empty($dolibarr_main_url_root_static)) define('DOL_URL_ROOT_FULL_STATIC', $dolibarr_main_url_root_static); // Used to put static images on another domain - +define('DOL_URL_EXTMODULE', DOL_URL_ROOT . '/custom/modules'); // URL relative for external modules /* * Include functions