From b56f59b313b826e95a63b26d2e66f33fb440d020 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 1 May 2014 16:26:57 +0200 Subject: [PATCH] Perf: Avoid to isntantiate object 'form' into 'subform' classes when already available. Qual: Better information into xdebug page. --- htdocs/admin/system/xdebug.php | 19 ++++++++++++++++--- htdocs/cashdesk/tpl/facturation1.tpl.php | 9 ++++----- htdocs/cashdesk/tpl/validation1.tpl.php | 2 -- htdocs/core/class/extrafields.class.php | 20 +++++++++++--------- htdocs/core/class/html.form.class.php | 4 ++-- htdocs/core/class/html.formactions.class.php | 9 +++++---- htdocs/core/class/html.formfile.class.php | 5 +++-- htdocs/core/class/html.formmail.class.php | 6 +++--- htdocs/core/class/html.formorder.class.php | 12 ++++++------ htdocs/core/class/html.formother.class.php | 8 ++++---- htdocs/core/class/html.formsms.class.php | 9 +++++---- 11 files changed, 59 insertions(+), 44 deletions(-) diff --git a/htdocs/admin/system/xdebug.php b/htdocs/admin/system/xdebug.php index 704bb777374..53a6aaa1f67 100644 --- a/htdocs/admin/system/xdebug.php +++ b/htdocs/admin/system/xdebug.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2009-2014 Laurent Destailleur * * 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 @@ -53,13 +53,27 @@ if (function_exists('socket_create')) $port = ini_get('xdebug.remote_port')?ini_get('xdebug.remote_port'):9000; print "Current xdebug setup:
\n"; + print "* Remote debug setup:
\n"; + print 'xdebug.remote_enable = '.ini_get('xdebug.remote_enable')."
\n"; print 'xdebug.remote_host = '.$address."
\n"; print 'xdebug.remote_port = '.$port."
\n"; - print 'xdebug.profiler_output_dir = '.ini_get('xdebug.profiler_output_dir')."
\n"; + print "* Profiler setup "; + if (function_exists('xdebug_get_profiler_filename')) print xdebug_get_profiler_filename()?"(currently on into file ".xdebug_get_profiler_filename().")":"(currently off)"; + else print "(currenlty not available)"; + print ":
\n"; print 'xdebug.profiler_enable = '.ini_get('xdebug.profiler_enable')."
\n"; print 'xdebug.profiler_enable_trigger = '.ini_get('xdebug.profiler_enable_trigger')."
\n"; + print 'xdebug.profiler_output_dir = '.ini_get('xdebug.profiler_output_dir')."
\n"; + print 'xdebug.profiler_output_name = '.ini_get('xdebug.profiler_output_name')."
\n"; + print 'xdebug.profiler_append = '.ini_get('xdebug.profiler_append')."
\n"; print "
\n"; + echo "To run a debug session, add parameter
"; + echo "* XDEBUG_SESSION_START=aname on your URL. To stop, remove cookie XDEBUG_SESSION_START.
\n"; + echo "To run a profiler session (when xdebug.profiler_enable_trigger=1), add parameter
\n"; + echo "* XDEBUG_PROFILE=aname on each URL.
"; + print "
"; + print "Test debugger server (Eclipse for example):
\n"; $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if (empty($socket)) die('Unable to prepare a socket'); @@ -94,7 +108,6 @@ xdebug.auto_trace=0 XDebug with same port than in php.ini
Allow Remote debug=yes or prompt
'."\n"; print "
\n"; - echo "Then, to run a debug session (when xdebug.profiler_enable_trigger=1), add parameter XDEBUG_SESSION_START=aname on your URL. To stop, remove cookie XDEBUG_SESSION_START.\n"; } else { diff --git a/htdocs/cashdesk/tpl/facturation1.tpl.php b/htdocs/cashdesk/tpl/facturation1.tpl.php index eb35a9e05d5..bb638918dd5 100644 --- a/htdocs/cashdesk/tpl/facturation1.tpl.php +++ b/htdocs/cashdesk/tpl/facturation1.tpl.php @@ -195,11 +195,10 @@ $langs->load("cashdesk"); " onclick="javascript: verifClic('DIF');" /> - trans("DateEcheance"); ?> : -select_date(-1,'txtDatePaiement'); -?> + trans("DateEcheance").' :'; + print $form->select_date(-1,'txtDatePaiement'); + ?> diff --git a/htdocs/cashdesk/tpl/validation1.tpl.php b/htdocs/cashdesk/tpl/validation1.tpl.php index 2542993b314..5b02cb597d7 100644 --- a/htdocs/cashdesk/tpl/validation1.tpl.php +++ b/htdocs/cashdesk/tpl/validation1.tpl.php @@ -14,7 +14,6 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * */ $langs->load("main"); @@ -105,7 +104,6 @@ $langs->load("main");

trans("BankToPay"). "
"; - $form = new Form($db); $form->select_comptes($selected,'cashdeskbank',0,$filtre); ?>

diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 93cd55e31ca..df302f0ffad 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -27,6 +27,7 @@ * \brief File of class to manage extra fields */ + /** * Class to manage standard extra fields */ @@ -581,7 +582,7 @@ class ExtraFields */ function showInputField($key,$value,$moreparam='',$keyprefix='') { - global $conf,$langs,$db; + global $conf,$langs; $label=$this->attribute_label[$key]; $type =$this->attribute_type[$key]; @@ -612,17 +613,18 @@ class ExtraFields { $tmp=explode(',',$size); $newsize=$tmp[0]; - if(!class_exists('Form')) - require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; - $formstat = new Form($db); $showtime = in_array($type,array('datetime')) ? 1 : 0; - // Do not show current date when field not required (see select_date() method) - if(!$required && $value == '') - $value = '-1'; - $out = $formstat->select_date($value, 'options_'.$key.$keyprefix, $showtime, $showtime, $required, '', 1, 1, 1, 0, 1); - // TODO Missing to add $moreparam + // Do not show current date when field not required (see select_date() method) + if (!$required && $value == '') $value = '-1'; + + require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; + global $form; + if (! is_object($form)) $form=new Form($this->db); + + // TODO Must also support $moreparam + $out = $form->select_date($value, 'options_'.$key.$keyprefix, $showtime, $showtime, $required, '', 1, 1, 1, 0, 1); } elseif (in_array($type,array('int'))) { diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 0c5fe571eda..c26c4d3b8c0 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -3783,7 +3783,7 @@ class Form /** - * Show a select form from an array + * Return a HTML select string, built from an array of key+value. * * @param string $htmlname Name of html select area * @param array $array Array with key+value @@ -3799,7 +3799,7 @@ class Form * @param string $morecss Add more class to css styles * @return string HTML select string */ - function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $option='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='') + static function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $option='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='') { global $langs; diff --git a/htdocs/core/class/html.formactions.class.php b/htdocs/core/class/html.formactions.class.php index 89cc3d2535a..522b2c30662 100644 --- a/htdocs/core/class/html.formactions.class.php +++ b/htdocs/core/class/html.formactions.class.php @@ -144,7 +144,7 @@ class FormActions global $bc; require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; - + $listofactions=ActionComm::getActions($this->db, $socid, $object->id, $typeelement); if (! is_array($listofactions)) dol_print_error($this->db,'FailedToGetActions'); @@ -217,12 +217,13 @@ class FormActions */ function select_type_actions($selected='',$htmlname='actioncode',$excludetype='',$onlyautoornot=0) { - global $langs,$user; + global $langs,$user,$form; + if (! is_object($form)) $form=new Form($db); + require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; $caction=new CActionComm($this->db); - $form=new Form($this->db); // Suggest a list with manual events or all auto events $arraylist=$caction->liste_array(1, 'code', $excludetype, $onlyautoornot); @@ -231,7 +232,7 @@ class FormActions if ($selected == 'manual') $selected='AC_OTH'; if ($selected == 'auto') $selected='AC_OTH_AUTO'; - + print $form->selectarray($htmlname, $arraylist, $selected); if ($user->admin && empty($onlyautoornot)) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); } diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 6788174bc97..73aa3742206 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -257,8 +257,10 @@ class FormFile */ function showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$maxfilenamelength=28,$noform=0,$param='',$title='',$buttonlabel='',$codelang='',$morepicto='') { - global $langs,$conf,$hookmanager,$user,$bc; + global $langs,$conf,$hookmanager,$user,$form,$bc; + if (! is_object($form)) $form=new Form($this->db); + // filedir = $conf->...->dir_ouput."/".get_exdir(id) include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -446,7 +448,6 @@ class FormFile $headershown=1; - $form = new Form($this->db); $buttonlabeltoshow=$buttonlabel; if (empty($buttonlabel)) $buttonlabel=$langs->trans('Generate'); diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 9539fe130a7..d0f3010b0c5 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -219,8 +219,10 @@ class FormMail */ function get_form($addfileaction='addfile',$removefileaction='removefile') { - global $conf, $langs, $user, $hookmanager; + global $conf, $langs, $user, $hookmanager, $form; + if (! is_object($form)) $form=new Form($this->db); + $langs->load("other"); $langs->load("mails"); @@ -248,8 +250,6 @@ class FormMail if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]); if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]); - $form=new Form($this->db); - $out.= "\n\n"; if ($this->withform == 1) { diff --git a/htdocs/core/class/html.formorder.class.php b/htdocs/core/class/html.formorder.class.php index b13b0343964..8985428f192 100644 --- a/htdocs/core/class/html.formorder.class.php +++ b/htdocs/core/class/html.formorder.class.php @@ -97,7 +97,7 @@ class FormOrder /** * Return list of input method (mode used to receive order, like order received by email, fax, online) - * List found into table c_input_method + * List found into table c_input_method. * * @param string $selected Id of preselected input method * @param string $htmlname Name of HTML select list @@ -106,12 +106,12 @@ class FormOrder */ function selectInputMethod($selected='',$htmlname='source_id',$addempty=0) { - global $conf,$langs; - $listofmethods=array(); - - require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; - $form=new Form($this->db); + global $conf,$langs,$form; + if (! is_object($form)) $form=new Form($this->db); + + $listofmethods=array(); + $sql = "SELECT rowid, code, libelle as label"; $sql.= " FROM ".MAIN_DB_PREFIX."c_input_method"; $sql.= " WHERE active = 1"; diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 416ee790282..18b765390e0 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -900,7 +900,8 @@ class FormOther /** - * Show a HTML Tab with boxes of a particular area including personalized choices of user + * Show a HTML Tab with boxes of a particular area including personalized choices of user. + * Class 'Form' must be known. * * @param User $user Object User * @param String $areacode Code of area for pages (0=value for Home page) @@ -933,9 +934,8 @@ class FormOther if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')'; $arrayboxtoactivatelabel[$box->id]=$label; // We keep only boxes not shown for user, to show into combo list } - - $form=new Form($db); - $selectboxlist=$form->selectarray('boxcombo', $arrayboxtoactivatelabel,'',1); + // Class Form must have been already loaded + $selectboxlist=Form::selectarray('boxcombo', $arrayboxtoactivatelabel,'',1); } // Javascript code for dynamic actions diff --git a/htdocs/core/class/html.formsms.class.php b/htdocs/core/class/html.formsms.class.php index 910460b4884..d34cc9b1bfb 100644 --- a/htdocs/core/class/html.formsms.class.php +++ b/htdocs/core/class/html.formsms.class.php @@ -24,7 +24,7 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/html.form.class.php'; -/** +/** * Classe permettant la generation du formulaire d'envoi de Sms * Usage: $formsms = new FormSms($db) * $formsms->proprietes=1 ou chaine ou tableau de valeurs @@ -83,20 +83,21 @@ class FormSms } /** - * Show the form to input an sms + * Show the form to input an sms. * * @param string $width Width of form * @return void */ function show_form($width='180px') { - global $conf, $langs, $user; + global $conf, $langs, $user, $form; + + if (! is_object($form)) $form=new Form($this->db); $langs->load("other"); $langs->load("mails"); $langs->load("sms"); - $form=new Form($this->db); $soc=new Societe($this->db); if (!empty($this->withtosocid) && $this->withtosocid > 0) {