From 56e11e52faeb70c42c2ff42aae0ef00a7416abda Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 25 Jan 2013 19:12:54 +0100 Subject: [PATCH] New: hookmanager class is used frequently and is a factory object, so we can move it during init of environment and use it globally. --- htdocs/adherents/class/adherent.class.php | 4 +-- .../adherents/class/adherent_type.class.php | 4 +-- htdocs/adherents/fiche.php | 2 -- htdocs/adherents/type.php | 2 -- htdocs/admin/dict.php | 2 -- htdocs/categories/categorie.php | 2 -- htdocs/comm/action/class/actioncomm.class.php | 10 +++---- htdocs/comm/action/fiche.php | 2 -- htdocs/comm/addpropal.php | 2 -- htdocs/comm/list.php | 2 -- htdocs/comm/mailing/fiche.php | 2 -- htdocs/comm/propal.php | 2 -- htdocs/comm/propal/list.php | 2 -- htdocs/comm/prospect/list.php | 2 -- htdocs/commande/class/commande.class.php | 8 +----- htdocs/commande/fiche.php | 2 -- htdocs/compta/deplacement/fiche.php | 2 -- htdocs/compta/dons/fiche.php | 2 -- htdocs/compta/facture.php | 2 -- htdocs/compta/facture/class/facture.class.php | 4 +-- htdocs/compta/facture/list.php | 2 -- htdocs/compta/tva/fiche.php | 2 -- htdocs/contact/class/contact.class.php | 4 +-- htdocs/contact/fiche.php | 2 -- htdocs/contrat/fiche.php | 2 -- htdocs/core/class/commonobject.class.php | 8 ++---- htdocs/core/class/html.formfile.class.php | 12 ++------- htdocs/core/class/html.formmail.class.php | 11 +------- htdocs/core/lib/files.lib.php | 27 ++----------------- htdocs/core/lib/security2.lib.php | 5 ---- htdocs/expedition/fiche.php | 2 -- htdocs/fichinter/fiche.php | 2 -- htdocs/fourn/commande/fiche.php | 2 -- htdocs/fourn/facture/fiche.php | 2 -- htdocs/fourn/liste.php | 2 -- htdocs/index.php | 2 -- htdocs/main.inc.php | 14 +--------- htdocs/master.inc.php | 10 ++++--- htdocs/product/class/product.class.php | 4 +-- htdocs/product/fiche.php | 2 -- htdocs/product/fournisseurs.php | 2 -- htdocs/projet/fiche.php | 2 -- htdocs/projet/tasks.php | 2 -- htdocs/projet/tasks/task.php | 2 -- htdocs/public/demo/index.php | 2 -- htdocs/societe/agenda.php | 2 -- htdocs/societe/class/societe.class.php | 6 +---- htdocs/societe/info.php | 2 -- htdocs/societe/soc.php | 2 -- htdocs/user/class/user.class.php | 4 +-- htdocs/user/fiche.php | 2 -- htdocs/user/passwordforgotten.php | 5 ---- 52 files changed, 27 insertions(+), 183 deletions(-) diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 61edd3bee05..0eea1c6f5d7 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -394,7 +394,7 @@ class Adherent extends CommonObject */ function update($user,$notrigger=0,$nosyncuser=0,$nosyncuserpass=0,$nosyncthirdparty=0,$action='update') { - global $conf, $langs; + global $conf, $langs, $hookmanager; $nbrowsaffected=0; $error=0; @@ -462,8 +462,6 @@ class Adherent extends CommonObject $nbrowsaffected+=$this->db->affected_rows($resql); // Actions on extra fields (by external module) - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($this->db); $hookmanager->initHooks(array('memberdao')); $parameters=array('id'=>$this->id); $action=''; diff --git a/htdocs/adherents/class/adherent_type.class.php b/htdocs/adherents/class/adherent_type.class.php index ead494783aa..d829c5a84f9 100644 --- a/htdocs/adherents/class/adherent_type.class.php +++ b/htdocs/adherents/class/adherent_type.class.php @@ -98,6 +98,8 @@ class AdherentType extends CommonObject */ function update($user) { + global $hookmanager; + $this->libelle=trim($this->libelle); $sql = "UPDATE ".MAIN_DB_PREFIX."adherent_type "; @@ -114,8 +116,6 @@ class AdherentType extends CommonObject if ($result) { // Actions on extra fields (by external module or standard code) - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($this->db); $hookmanager->initHooks(array('membertypedao')); $parameters=array('membertype'=>$this->id); $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index 02e0af3a768..f84990b94e5 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -107,8 +107,6 @@ if ($rowid) } // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('membercard')); diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php index 592695130b3..369f925bc7e 100644 --- a/htdocs/adherents/type.php +++ b/htdocs/adherents/type.php @@ -67,8 +67,6 @@ if (GETPOST('button_removefilter')) // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('membertypecard')); /* diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 56f4f6140bb..b5c49355672 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -64,8 +64,6 @@ $pageprev = $page - 1; $pagenext = $page + 1; // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('admin')); // This page is a generic page to edit dictionnaries diff --git a/htdocs/categories/categorie.php b/htdocs/categories/categorie.php index fb4ba30a269..d3a06304e46 100644 --- a/htdocs/categories/categorie.php +++ b/htdocs/categories/categorie.php @@ -86,8 +86,6 @@ if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user,$objecttype,$objectid,$dbtablename,'','',$fieldid); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('categorycard')); diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 5e7a77c6ca2..43278dbaaa2 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -106,8 +106,8 @@ class ActionComm extends CommonObject */ function add($user,$notrigger=0) { - global $langs,$conf; - + global $langs,$conf,$hookmanager; + $error=0; $now=dol_now(); @@ -210,8 +210,6 @@ class ActionComm extends CommonObject $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."actioncomm","id"); // Actions on extra fields (by external module or standard code) - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($this->db); $hookmanager->initHooks(array('actioncommdao')); $parameters=array('actcomm'=>$this->id); $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks @@ -430,7 +428,7 @@ class ActionComm extends CommonObject */ function update($user,$notrigger=0) { - global $langs,$conf; + global $langs,$conf,$hookmanager; $error=0; @@ -482,8 +480,6 @@ class ActionComm extends CommonObject { // Actions on extra fields (by external module or standard code) - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($this->db); $hookmanager->initHooks(array('actioncommdao')); $parameters=array('actcomm'=>$this->id); $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks diff --git a/htdocs/comm/action/fiche.php b/htdocs/comm/action/fiche.php index 60233a20650..782d7444429 100644 --- a/htdocs/comm/action/fiche.php +++ b/htdocs/comm/action/fiche.php @@ -66,8 +66,6 @@ $extrafields = new ExtraFields($db); //var_dump($_POST); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('actioncard')); diff --git a/htdocs/comm/addpropal.php b/htdocs/comm/addpropal.php index b2d5285d849..8c5a07df0c3 100644 --- a/htdocs/comm/addpropal.php +++ b/htdocs/comm/addpropal.php @@ -46,8 +46,6 @@ $origin=GETPOST('origin','alpha'); $originid=GETPOST('originid','int'); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('propalcard')); /* diff --git a/htdocs/comm/list.php b/htdocs/comm/list.php index 496b9217059..fd7ea79f345 100755 --- a/htdocs/comm/list.php +++ b/htdocs/comm/list.php @@ -58,8 +58,6 @@ $search_categ = GETPOST("search_categ",'int'); $catid = GETPOST("catid",'int'); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('customerlist')); diff --git a/htdocs/comm/mailing/fiche.php b/htdocs/comm/mailing/fiche.php index 680790ff04e..310a48eb935 100644 --- a/htdocs/comm/mailing/fiche.php +++ b/htdocs/comm/mailing/fiche.php @@ -47,8 +47,6 @@ $result=$object->fetch($id); $extrafields = new ExtraFields($db); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('mailingcard')); // Tableau des substitutions possibles diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index f1850014a48..08a03ff8866 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -99,8 +99,6 @@ else } // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('propalcard')); diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php index 95e549c0b1d..b2f1f8dcc44 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -77,8 +77,6 @@ $result = restrictedArea($user, $module, $objectid, $dbtable); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('propalcard')); diff --git a/htdocs/comm/prospect/list.php b/htdocs/comm/prospect/list.php index a093f73c57b..69aaab9e68e 100755 --- a/htdocs/comm/prospect/list.php +++ b/htdocs/comm/prospect/list.php @@ -148,8 +148,6 @@ $sts = array(-1,0,1,2,3); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('prospectlist')); diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 481b51400a5..28d56fcf3a2 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -880,8 +880,7 @@ class Commande extends CommonOrder */ function createFromProposal($object) { - global $conf,$user,$langs; - global $hookmanager; + global $conf,$user,$langs,$hookmanager; $error=0; @@ -945,11 +944,6 @@ class Commande extends CommonOrder if ($ret > 0) { // Actions hooked (by external module) - if (! is_object($hookmanager)) - { - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($this->db); - } $hookmanager->initHooks(array('orderdao')); $parameters=array('objFrom'=>$object); diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index e3fd1029326..b6e7b821495 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -84,8 +84,6 @@ if ($id > 0 || ! empty($ref)) } // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('ordercard')); diff --git a/htdocs/compta/deplacement/fiche.php b/htdocs/compta/deplacement/fiche.php index d13880f7559..1e20d91c350 100644 --- a/htdocs/compta/deplacement/fiche.php +++ b/htdocs/compta/deplacement/fiche.php @@ -49,8 +49,6 @@ $mesg = ''; $object = new Deplacement($db); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('tripsandexpensescard')); diff --git a/htdocs/compta/dons/fiche.php b/htdocs/compta/dons/fiche.php index 51550f41ebd..6ba13a19631 100644 --- a/htdocs/compta/dons/fiche.php +++ b/htdocs/compta/dons/fiche.php @@ -50,8 +50,6 @@ $donation_date=dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOS $result = restrictedArea($user, 'don', $id); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('doncard')); diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 34b501f73c9..f15762b97bf 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -95,8 +95,6 @@ if ($id > 0 || ! empty($ref)) } // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('invoicecard')); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index cf7b89be7aa..1637524cfce 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -637,7 +637,7 @@ class Facture extends CommonInvoice */ function createFromOrder($object) { - global $conf,$user,$langs; + global $conf,$user,$langs,$hookmanager; $error=0; @@ -701,8 +701,6 @@ class Facture extends CommonInvoice if ($ret > 0) { // Actions hooked (by external module) - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($this->db); $hookmanager->initHooks(array('invoicedao')); $parameters=array('objFrom'=>$object); diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 12d653e5b26..796bf769698 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -97,8 +97,6 @@ $usehm=(! empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?$conf->global->MA $object=new Facture($db); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('invoicecard')); $now=dol_now(); diff --git a/htdocs/compta/tva/fiche.php b/htdocs/compta/tva/fiche.php index 45dc91263ad..c8139c5575f 100644 --- a/htdocs/compta/tva/fiche.php +++ b/htdocs/compta/tva/fiche.php @@ -41,8 +41,6 @@ if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'tax', '', '', 'charges'); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('taxvatcard')); diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index c1eb6426c7b..14c8630e1e5 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -210,7 +210,7 @@ class Contact extends CommonObject */ function update($id, $user=0, $notrigger=0, $action='update') { - global $conf, $langs; + global $conf, $langs, $hookmanager; $error=0; @@ -266,8 +266,6 @@ class Contact extends CommonObject unset($this->state); // Actions on extra fields (by external module or standard code) - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($this->db); $hookmanager->initHooks(array('contactdao')); $parameters=array('socid'=>$this->id); $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index 0233c367b07..9097584bfb5 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -65,8 +65,6 @@ if (! empty($canvas)) $result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', '', $objcanvas); // If we create a contact with no company (shared contacts), no check on write permission // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('contactcard')); diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php index 50c30e4be2b..d3a7f48c24b 100644 --- a/htdocs/contrat/fiche.php +++ b/htdocs/contrat/fiche.php @@ -59,8 +59,6 @@ $result=restrictedArea($user,'contrat',$id); $usehm=(! empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE:0); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('contractcard')); $object = new Contrat($db); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 8b6002c29c5..344507971bb 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2468,16 +2468,12 @@ abstract class CommonObject */ function showLinkedObjectBlock($hookmanager=false) { - global $conf,$langs,$bc; + global $conf,$langs,$hookmanager; + global $bc; $this->fetchObjectLinked(); // Bypass the default method - if (! is_object($hookmanager)) - { - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($this->db); - } $hookmanager->initHooks(array('commonobject')); $parameters=array(); $reshook=$hookmanager->executeHooks('showLinkedObjectBlock',$parameters,$this,$action); // Note that $action and $object may have been modified by hook diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 8e43669b2e8..83818285265 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -590,18 +590,10 @@ class FormFile */ function list_of_documents($filearray,$object,$modulepart,$param='',$forcedownload=0,$relativepath='',$permtodelete=1,$useinecm=0,$textifempty='',$maxlength=0,$title='',$url='') { - global $user, $conf, $langs; - global $bc, $hookmanager; + global $user, $conf, $langs, $hookmanager; + global $bc; global $sortfield, $sortorder, $maxheightmini; - if (! is_object($hookmanager)) - { - if (! class_exists('HookManager')) { - // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array - require DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($this->db); - } - } $hookmanager->initHooks(array('formfile')); $parameters=array( diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index c221cc33c07..f499bcb6b68 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -216,20 +216,11 @@ class FormMail */ function get_form($addfileaction='addfile',$removefileaction='removefile') { - global $conf, $langs, $user; - global $hookmanager; + global $conf, $langs, $user, $hookmanager; $langs->load("other"); $langs->load("mails"); - if (! is_object($hookmanager)) - { - if (! class_exists('HookManager')) { - // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array - require DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($this->db); - } - } $hookmanager->initHooks(array('formmail')); $parameters=array( diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index c257b00e56d..b480184808f 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -65,15 +65,8 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil $path=preg_replace('/([\\/]+)$/i','',$path); $newpath=dol_osencode($path); - if (! $nohook) { - if (! is_object($hookmanager)) - { - if (! class_exists('HookManager')) { - // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array - require DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($db); - } - } + if (! $nohook) + { $hookmanager->initHooks(array('fileslib')); $parameters=array( @@ -653,14 +646,6 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable return -2; } - if (! is_object($hookmanager)) - { - if (! class_exists('HookManager')) { - // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array - require DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - } - $hookmanager=new HookManager($db); - } $hookmanager->initHooks(array('fileslib')); $parameters=array('filename' => $file_name, 'varfiles' => $varfiles, 'allowoverwrite' => $allowoverwrite); @@ -722,14 +707,6 @@ function dol_delete_file($file,$disableglob=0,$nophperrors=0,$nohook=0,$object=n if (empty($nohook)) { - if (! is_object($hookmanager)) - { - if (! class_exists('HookManager')) { - // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array - require DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($db); - } - } $hookmanager->initHooks(array('fileslib')); $parameters=array( diff --git a/htdocs/core/lib/security2.lib.php b/htdocs/core/lib/security2.lib.php index b7196ba228f..6aa41576c01 100644 --- a/htdocs/core/lib/security2.lib.php +++ b/htdocs/core/lib/security2.lib.php @@ -131,11 +131,6 @@ function dol_loginfunction($langs,$conf,$mysoc) global $smartphone,$hookmanager; // Instantiate hooks of thirdparty module only if not already define - if (! is_object($hookmanager)) - { - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($db); - } $hookmanager->initHooks(array('mainloginpage')); $langcode=(GETPOST('lang')?((is_object($langs)&&$langs->defaultlang)?$langs->defaultlang:'auto'):GETPOST('lang')); diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index 7e9a24be0f9..1d34aea5d0c 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -59,8 +59,6 @@ if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user, $origin, $origin_id); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('expeditioncard')); $action = GETPOST('action','alpha'); diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index 755b68b5af1..86230754ef3 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -60,8 +60,6 @@ if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'ficheinter', $id, 'fichinter'); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('interventioncard')); $object = new Fichinter($db); diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index bbe46c9a21a..ed5c7483c64 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -70,8 +70,6 @@ if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'commande_fournisseur', $id,''); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('ordersuppliercard')); $object = new CommandeFournisseur($db); diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 241c17b7cef..abec49e0e89 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -61,8 +61,6 @@ if (! empty($user->societe_id)) $socid=$user->societe_id; $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture'); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('invoicesuppliercard')); $object=new FactureFournisseur($db); diff --git a/htdocs/fourn/liste.php b/htdocs/fourn/liste.php index 3c50b16cb4f..13361f10eb2 100644 --- a/htdocs/fourn/liste.php +++ b/htdocs/fourn/liste.php @@ -57,8 +57,6 @@ if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="nom"; // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('supplierlist')); /* diff --git a/htdocs/index.php b/htdocs/index.php index ba3cbf1b05f..8119e3a83be 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -34,8 +34,6 @@ $_GET['mainmenu']=GETPOST('mainmenu', 'alpha')?GETPOST('mainmenu', 'alpha'):'hom $action=GETPOST('action'); -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('index')); diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 58f1ac48d02..ec82c9e7e41 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -603,8 +603,6 @@ if (! defined('NOLOGIN')) // Hooks on successfull login $action=''; - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($db); $hookmanager->initHooks(array('login')); $parameters=array('dol_authmode'=>$dol_authmode); $reshook=$hookmanager->executeHooks('afterLogin',$parameters,$user,$action); // Note that $action and $object may have been modified by some hooks @@ -1194,12 +1192,7 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a global $dolibarr_main_authentication; global $hookmanager,$menumanager; - // Instantiate hooks of thirdparty module only if not already define - if (! is_object($hookmanager)) - { - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($db); - } + // Instantiate hooks of thirdparty module $hookmanager->initHooks(array('toprightmenu')); $toprightmenu=''; @@ -1426,11 +1419,6 @@ function left_menu($menu_array_before, $helppagename='', $moresearchform='', $me $bookmarks=''; // Instantiate hooks of thirdparty module - if (! is_object($hookmanager)) - { - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($db); - } $hookmanager->initHooks(array('searchform','leftblock')); if (empty($_SESSION['dol_hide_leftmenu'])) diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php index 6d6ce8680b8..b023f7110b0 100644 --- a/htdocs/master.inc.php +++ b/htdocs/master.inc.php @@ -186,9 +186,7 @@ if (! empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) } } -/* - * Create object $mysoc (A thirdparty object that contains properties of companies managed by Dolibarr. - */ +// Create object $mysoc (A thirdparty object that contains properties of companies managed by Dolibarr. if (! defined('NOREQUIREDB') && ! defined('NOREQUIRESOC')) { require_once DOL_DOCUMENT_ROOT .'/societe/class/societe.class.php'; @@ -207,6 +205,12 @@ if (! defined('NOREQUIRETRAN')) $langs->setDefaultLang((! empty($conf->global->MAIN_LANG_DEFAULT)?$conf->global->MAIN_LANG_DEFAULT:'')); } + +// Create the global $hookmanager object +include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; +$hookmanager=new HookManager($db); + + if (! defined('MAIN_LABEL_MENTION_NPR') ) define('MAIN_LABEL_MENTION_NPR','NPR'); // We force feature to help debug diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index a9c0439b220..8f91e30b257 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -418,7 +418,7 @@ class Product extends CommonObject */ function update($id, $user, $notrigger=false, $action='update') { - global $langs, $conf; + global $langs, $conf, $hookmanager; $error=0; @@ -500,8 +500,6 @@ class Product extends CommonObject } // Actions on extra fields (by external module or standard code) - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($this->db); $hookmanager->initHooks(array('productdao')); $parameters=array('id'=>$this->id); $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index 74aa705eeab..1ccc7e2c8b3 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -78,8 +78,6 @@ $fieldtype = (! empty($ref) ? 'ref' : 'rowid'); $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype,$objcanvas); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('productcard')); diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index b8b30184af9..43929c96b0c 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -59,8 +59,6 @@ if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'produit|service&fournisseur',$fieldvalue,'product&product','','',$fieldtype); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('pricesuppliercard')); diff --git a/htdocs/projet/fiche.php b/htdocs/projet/fiche.php index f5870301860..fc518e29d27 100644 --- a/htdocs/projet/fiche.php +++ b/htdocs/projet/fiche.php @@ -50,8 +50,6 @@ if ($user->societe_id > 0) $socid=$user->societe_id; $result = restrictedArea($user, 'projet', $id); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('projectcard')); $object = new Project($db); diff --git a/htdocs/projet/tasks.php b/htdocs/projet/tasks.php index 934bf9b238e..55055d0f467 100644 --- a/htdocs/projet/tasks.php +++ b/htdocs/projet/tasks.php @@ -55,8 +55,6 @@ if ($user->societe_id > 0) $socid = $user->societe_id; $result = restrictedArea($user, 'projet', $id); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('projecttaskcard')); $progress=GETPOST('progress', 'int'); diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php index def739e31f1..94034e9b541 100644 --- a/htdocs/projet/tasks/task.php +++ b/htdocs/projet/tasks/task.php @@ -42,8 +42,6 @@ if ($user->societe_id > 0) $socid = $user->societe_id; if (! $user->rights->projet->lire) accessforbidden(); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('projecttaskcard')); $object = new Task($db); diff --git a/htdocs/public/demo/index.php b/htdocs/public/demo/index.php index b8a240b44b6..40c499d5469 100644 --- a/htdocs/public/demo/index.php +++ b/htdocs/public/demo/index.php @@ -38,8 +38,6 @@ global $dolibarr_main_demo; if (empty($dolibarr_main_demo)) accessforbidden('Parameter dolibarr_main_demo must be defined in conf file with value "default login,default pass" to enable the demo entry page',1,1,1); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('demo')); $demoprofiles=array( diff --git a/htdocs/societe/agenda.php b/htdocs/societe/agenda.php index 9e373a97158..bc9b11b3149 100644 --- a/htdocs/societe/agenda.php +++ b/htdocs/societe/agenda.php @@ -38,8 +38,6 @@ if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'societe', $socid, '&societe'); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('agendathirdparty')); diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 6ea29526c00..95c16965fb5 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -380,7 +380,7 @@ class Societe extends CommonObject */ function update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmodcodefournisseur=0, $action='update', $nosyncmember=1) { - global $langs,$conf; + global $langs,$conf,$hookmanager; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; $error=0; @@ -612,8 +612,6 @@ class Societe extends CommonObject $this->AddFournisseurInCategory($this->fournisseur_categorie); // Actions on extra fields (by external module or standard code) - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($this->db); $hookmanager->initHooks(array('thirdpartydao')); $parameters=array('socid'=>$this->id); $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks @@ -1064,8 +1062,6 @@ class Societe extends CommonObject if (! $error) { // Additionnal action by hooks - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($this->db); $hookmanager->initHooks(array('thirdpartydao')); $parameters=array(); $action='delete'; $reshook=$hookmanager->executeHooks('deleteThirdparty',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks diff --git a/htdocs/societe/info.php b/htdocs/societe/info.php index 82eab7da454..8f0d0836ed4 100644 --- a/htdocs/societe/info.php +++ b/htdocs/societe/info.php @@ -38,8 +38,6 @@ if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'societe', $socid, '&societe'); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('infothirdparty')); diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index d2f816cd1ca..9a9900df23e 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -70,8 +70,6 @@ if (! empty($canvas)) $result = restrictedArea($user, 'societe', $socid, '&societe', '', 'fk_soc', 'rowid', $objcanvas); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('thirdpartycard')); diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index daf7b7ade4c..678be6bf873 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -1079,7 +1079,7 @@ class User extends CommonObject */ function update($user,$notrigger=0,$nosyncmember=0,$nosyncmemberpass=0) { - global $conf, $langs; + global $conf, $langs, $hookmanager; $nbrowsaffected=0; $error=0; @@ -1218,8 +1218,6 @@ class User extends CommonObject } // Actions on extra fields (by external module or standard code) - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($this->db); $hookmanager->initHooks(array('userdao')); $parameters=array('socid'=>$this->id); $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks diff --git a/htdocs/user/fiche.php b/htdocs/user/fiche.php index 7ce2640710a..4d79b687c60 100644 --- a/htdocs/user/fiche.php +++ b/htdocs/user/fiche.php @@ -84,8 +84,6 @@ $object = new User($db); $extrafields = new ExtraFields($db); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); $hookmanager->initHooks(array('usercard')); diff --git a/htdocs/user/passwordforgotten.php b/htdocs/user/passwordforgotten.php index a3bbcea980a..61ac2f373fc 100644 --- a/htdocs/user/passwordforgotten.php +++ b/htdocs/user/passwordforgotten.php @@ -52,11 +52,6 @@ $passwordmd5 = GETPOST('passwordmd5'); $conf->entity = (GETPOST('entity') ? GETPOST('entity') : 1); // Instantiate hooks of thirdparty module only if not already define -if (! is_object($hookmanager)) -{ - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($db); -} $hookmanager->initHooks(array('passwordforgottenpage'));