Qual: Optimize substitution engine
This commit is contained in:
parent
87f01b0c18
commit
311339b0ca
@ -138,15 +138,15 @@ else
|
||||
'%MONTH%'=>$month,
|
||||
'%DAY%'=>$day
|
||||
);
|
||||
|
||||
complete_substitutions_array($substitutionarray, $langs);
|
||||
|
||||
// For business cards
|
||||
if (empty($mode) || $mode=='card' || $mode=='cardlogin')
|
||||
{
|
||||
$textleft=make_substitutions($conf->global->ADHERENT_CARD_TEXT, $substitutionarray, $langs);
|
||||
$textheader=make_substitutions($conf->global->ADHERENT_CARD_HEADER_TEXT, $substitutionarray, $langs);
|
||||
$textfooter=make_substitutions($conf->global->ADHERENT_CARD_FOOTER_TEXT, $substitutionarray, $langs);
|
||||
$textright=make_substitutions($conf->global->ADHERENT_CARD_TEXT_RIGHT, $substitutionarray, $langs);
|
||||
$textleft=make_substitutions($conf->global->ADHERENT_CARD_TEXT, $substitutionarray);
|
||||
$textheader=make_substitutions($conf->global->ADHERENT_CARD_HEADER_TEXT, $substitutionarray);
|
||||
$textfooter=make_substitutions($conf->global->ADHERENT_CARD_FOOTER_TEXT, $substitutionarray);
|
||||
$textright=make_substitutions($conf->global->ADHERENT_CARD_TEXT_RIGHT, $substitutionarray);
|
||||
|
||||
if (is_numeric($foruserid) || $foruserlogin)
|
||||
{
|
||||
@ -175,7 +175,7 @@ else
|
||||
if ($mode == 'label')
|
||||
{
|
||||
$conf->global->ADHERENT_ETIQUETTE_TEXT="%PRENOM% %NOM%\n%ADRESSE%\n%CP% %VILLE%\n%PAYS%";
|
||||
$textleft=make_substitutions($conf->global->ADHERENT_ETIQUETTE_TEXT, $substitutionarray, $langs);
|
||||
$textleft=make_substitutions($conf->global->ADHERENT_ETIQUETTE_TEXT, $substitutionarray);
|
||||
$textheader='';
|
||||
$textfooter='';
|
||||
$textright='';
|
||||
|
||||
@ -199,7 +199,7 @@ class Adherent extends CommonObject
|
||||
$infos.= $langs->transnoentities("Public").": ".yn($this->public);
|
||||
|
||||
// Substitutions
|
||||
$substit=array(
|
||||
$substitutionarray=array(
|
||||
'%DOL_MAIN_URL_ROOT%'=>DOL_MAIN_URL_ROOT,
|
||||
'%INFOS%'=>$msgishtml?dol_htmlentitiesbr($infos):$infos,
|
||||
'%CIVILITE%'=>$this->getCivilityLabel($msgishtml?0:1),
|
||||
@ -217,7 +217,9 @@ class Adherent extends CommonObject
|
||||
'%PASSWORD%'=>$msgishtml?dol_htmlentitiesbr($this->pass):$this->pass
|
||||
);
|
||||
|
||||
return make_substitutions($text,$substit,$langs);
|
||||
$substitutionarray=complete_substitutions_array($substitutionarray, $langs);
|
||||
|
||||
return make_substitutions($text,$substitutionarray);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -38,11 +38,13 @@ if (!$user->admin)
|
||||
accessforbidden();
|
||||
|
||||
$substitutionarrayfortest=array(
|
||||
'__LOGIN__' => $user->login,
|
||||
'__ID__' => 'TESTIdRecord',
|
||||
'__EMAIL__' => 'TESTEMail',
|
||||
'__LASTNAME__' => 'TESTLastname',
|
||||
'__FIRSTNAME__' => 'TESTFirstname'
|
||||
);
|
||||
complete_substitutions_array($substitutionarrayfortest, $langs);
|
||||
|
||||
|
||||
/*
|
||||
@ -204,8 +206,8 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'sendhtml')
|
||||
if ($_POST['action'] == 'sendhtml') $msgishtml=1; // Force message to HTML
|
||||
|
||||
// Pratique les substitutions sur le sujet et message
|
||||
$subject=make_substitutions($subject,$substitutionarrayfortest,$langs);
|
||||
$body=make_substitutions($body,$substitutionarrayfortest,$langs);
|
||||
$subject=make_substitutions($subject,$substitutionarrayfortest);
|
||||
$body=make_substitutions($body,$substitutionarrayfortest);
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
|
||||
$mailfile = new CMailFile($subject,$sendto,$email_from,$body,
|
||||
@ -716,6 +718,7 @@ else
|
||||
$formmail->withtopicreadonly=0;
|
||||
$formmail->withfile=2;
|
||||
$formmail->withbody=(isset($_POST['message'])?$_POST['message']:$langs->trans("PredefinedMailTestHtml"));
|
||||
//$formmail->withbody='Test <b>aaa</b> __LOGIN__';
|
||||
$formmail->withbodyreadonly=0;
|
||||
$formmail->withcancel=1;
|
||||
$formmail->withdeliveryreceipt=1;
|
||||
|
||||
@ -108,7 +108,8 @@ if ($action == 'send' && ! $_POST['cancel'])
|
||||
if (! $error)
|
||||
{
|
||||
// Make substitutions into message
|
||||
$body=make_substitutions($body,$substitutionarrayfortest,$langs);
|
||||
complete_substitutions_array($substitutionarrayfortest, $langs);
|
||||
$body=make_substitutions($body,$substitutionarrayfortest);
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/CSMSFile.class.php");
|
||||
|
||||
|
||||
@ -191,8 +191,9 @@ if ($_REQUEST["action"] == 'sendallconfirmed' && $_REQUEST['confirm'] == 'yes')
|
||||
);
|
||||
|
||||
$substitutionisok=true;
|
||||
$newsubject=make_substitutions($subject,$substitutionarray,$langs);
|
||||
$newmessage=make_substitutions($message,$substitutionarray,$langs);
|
||||
complete_substitutions_array($substitutionarray, $langs);
|
||||
$newsubject=make_substitutions($subject,$substitutionarray);
|
||||
$newmessage=make_substitutions($message,$substitutionarray);
|
||||
|
||||
$arr_file = array();
|
||||
$arr_mime = array();
|
||||
|
||||
@ -412,7 +412,7 @@ class FormMail
|
||||
// Topic
|
||||
if ($this->withtopic)
|
||||
{
|
||||
$this->withtopic=make_substitutions($this->withtopic,$this->substit,$langs);
|
||||
$this->withtopic=make_substitutions($this->withtopic,$this->substit);
|
||||
|
||||
print "<tr>";
|
||||
print "<td width=\"180\">".$langs->trans("MailTopic")."</td>";
|
||||
@ -473,7 +473,7 @@ class FormMail
|
||||
if ($this->param["models"]=='order_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendOrder"); }
|
||||
if ($this->param["models"]=='order_supplier_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendSupplierOrder"); }
|
||||
if ($this->param["models"]=='invoice_supplier_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendSupplierInvoice"); }
|
||||
$defaultmessage=make_substitutions($defaultmessage,$this->substit,$langs);
|
||||
$defaultmessage=make_substitutions($defaultmessage,$this->substit);
|
||||
if (isset($_POST["message"])) $defaultmessage=$_POST["message"];
|
||||
$defaultmessage=str_replace('\n',"\n",$defaultmessage);
|
||||
|
||||
|
||||
@ -238,38 +238,11 @@ function limitChars(textarea, limit, infodiv)
|
||||
print "</td></tr>\n";
|
||||
}
|
||||
|
||||
// Topic
|
||||
/*
|
||||
if ($this->withtopic)
|
||||
{
|
||||
$this->withtopic=make_substitutions($this->withtopic,$this->substit,$langs);
|
||||
|
||||
print "<tr>";
|
||||
print "<td width=\"180\">".$langs->trans("MailTopic")."</td>";
|
||||
print "<td>";
|
||||
if ($this->withtopicreadonly)
|
||||
{
|
||||
print $this->withtopic;
|
||||
print "<input type=\"hidden\" size=\"60\" name=\"subject\" value=\"".$this->withtopic."\">";
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<input type=\"text\" size=\"60\" name=\"subject\" value=\"". (isset($_POST["subject"])?$_POST["subject"]:$this->withtopic) ."\">";
|
||||
}
|
||||
print "</td></tr>\n";
|
||||
}*/
|
||||
|
||||
// Message
|
||||
if ($this->withbody)
|
||||
{
|
||||
$defaultmessage='';
|
||||
if ($this->param["models"]=='body') { $defaultmessage=$this->withbody; }
|
||||
/*if ($this->param["models"]=='facture_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendInvoice"); }
|
||||
if ($this->param["models"]=='facture_relance') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendInvoiceReminder"); }
|
||||
if ($this->param["models"]=='propal_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendProposal"); }
|
||||
if ($this->param["models"]=='order_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendOrder"); }
|
||||
if ($this->param["models"]=='order_supplier_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendSupplierOrder"); }
|
||||
if ($this->param["models"]=='invoice_supplier_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendSupplierInvoice"); } */
|
||||
$defaultmessage=make_substitutions($defaultmessage,$this->substit,$langs);
|
||||
if (isset($_POST["message"])) $defaultmessage=$_POST["message"];
|
||||
$defaultmessage=str_replace('\n',"\n",$defaultmessage);
|
||||
|
||||
@ -103,7 +103,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
||||
$invoice_source->fetch($object->fk_facture_source);
|
||||
}
|
||||
$alreadypayed=price($object->getSommePaiement(),'MT');
|
||||
|
||||
|
||||
return array(
|
||||
'object_id'=>$object->id,
|
||||
'object_ref'=>$object->ref,
|
||||
@ -129,7 +129,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
||||
'object_remain_to_pay'=>price($object->total_ttc - $alreadypayed,'MT')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Define array with couple substitution key => substitution value
|
||||
*
|
||||
@ -353,23 +353,24 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
||||
$socobject=$object->client;
|
||||
}
|
||||
|
||||
// Make substitution
|
||||
$substitutionarray=array(
|
||||
'__FROM_NAME__' => $this->emetteur->nom,
|
||||
'__FROM_EMAIL__' => $this->emetteur->email,
|
||||
'__TOTAL_TTC__' => $object->total_ttc,
|
||||
'__TOTAL_HT__' => $object->total_ht,
|
||||
'__TOTAL_VAT__' => $object->total_vat
|
||||
);
|
||||
complete_substitutions_array($substitutionarray, $langs, $object);
|
||||
|
||||
// Line of free text
|
||||
$newfreetext='';
|
||||
$paramfreetext='FACTURE_FREE_TEXT';
|
||||
if (! empty($conf->global->$paramfreetext))
|
||||
{
|
||||
// Make substitution
|
||||
$substitutionarray=array(
|
||||
'__FROM_NAME__' => $this->emetteur->nom,
|
||||
'__FROM_EMAIL__' => $this->emetteur->email,
|
||||
'__TOTAL_TTC__' => $object->total_ttc,
|
||||
'__TOTAL_HT__' => $object->total_ht,
|
||||
'__TOTAL_VAT__' => $object->total_vat
|
||||
);
|
||||
|
||||
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray,$outputlangs,$object);
|
||||
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
|
||||
}
|
||||
|
||||
|
||||
// Open and load template
|
||||
require_once(DOL_DOCUMENT_ROOT.'/includes/odtphp/odf.php');
|
||||
$odfHandler = new odf($srctemplatepath, array(
|
||||
@ -384,7 +385,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
||||
//print html_entity_decode($odfHandler->__toString());
|
||||
//print exit;
|
||||
|
||||
|
||||
|
||||
// Make substitutions into odt
|
||||
if ($newfreetext)
|
||||
{
|
||||
|
||||
@ -1051,7 +1051,7 @@ function dol_print_phone($phone,$country="FR",$cid=0,$socid=0,$addlink=0,$separ=
|
||||
'__PHONETO__'=>urlencode($phone),
|
||||
'__LOGIN__'=>urlencode($user->clicktodial_login),
|
||||
'__PASS__'=>urlencode($user->clicktodial_password));
|
||||
$url = make_substitutions($url, $substitarray, $langs);
|
||||
$url = make_substitutions($url, $substitarray);
|
||||
$newphonesav=$newphone;
|
||||
$newphone ='<a href="'.$url.'"';
|
||||
if (! empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) $newphone.=' target="_blank"';
|
||||
@ -3571,16 +3571,11 @@ function dol_textishtml($msg,$option=0)
|
||||
* - From $substitutionarray (oldval=>newval)
|
||||
* - From special constants (__XXX__=>f(objet->xxx)) by substitutions modules
|
||||
* @param chaine Source string in which we must do substitution
|
||||
* @param substitutionarray Array substitution old value => new value value
|
||||
* @param outputlangs If we want substitution from special constants, we provide a language
|
||||
* @param object If we want substitution from special constants, we provide data in a source object
|
||||
* @return string Output string after subsitutions
|
||||
*/
|
||||
function make_substitutions($chaine,$substitutionarray,$outputlangs,$object='')
|
||||
function make_substitutions($chaine,$substitutionarray)
|
||||
{
|
||||
global $conf,$user;
|
||||
|
||||
complete_substitutions_array($substitutionarray,$outputlangs,$object);
|
||||
if (! is_array($substitutionarray)) return 'ErrorBadParametersCalling_make_substitutions';
|
||||
|
||||
// Make substitition
|
||||
foreach ($substitutionarray as $key => $value)
|
||||
|
||||
@ -470,8 +470,8 @@ function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_bass
|
||||
'__TOTAL_HT__' => $object->total_ht,
|
||||
'__TOTAL_VAT__' => $object->total_vat
|
||||
);
|
||||
|
||||
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray,$outputlangs,$object);
|
||||
complete_substitutions_array($substitutionarray,$outputlangs,$object);
|
||||
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
|
||||
$line.=$outputlangs->convToOutputCharset($newfreetext);
|
||||
}
|
||||
|
||||
@ -1032,7 +1032,7 @@ function pdf_getlineqty_keeptoship($object,$i,$outputlangs,$hidedetails=0)
|
||||
function pdf_getlineremisepercent($object,$i,$outputlangs,$hidedetails=0)
|
||||
{
|
||||
include_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
|
||||
|
||||
|
||||
if ($object->lines[$i]->special_code != 3)
|
||||
{
|
||||
if (! empty($object->hooks['objectcard']) && ( ($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code) ) || ! empty($object->lines[$i]->fk_parent_line) ) )
|
||||
|
||||
@ -146,11 +146,13 @@ if ($resql)
|
||||
'__OTHER5__' => $other5
|
||||
);
|
||||
|
||||
$substitutionisok=true;
|
||||
$newsubject=make_substitutions($subject,$substitutionarray,$langs);
|
||||
$newmessage=make_substitutions($message,$substitutionarray,$langs);
|
||||
$substitutionarray=complete_substitutions_array($substitutionarray,$langs);
|
||||
$newsubject=make_substitutions($subject,$substitutionarray);
|
||||
$newmessage=make_substitutions($message,$substitutionarray);
|
||||
|
||||
// Fabrication du mail
|
||||
$substitutionisok=true;
|
||||
|
||||
// Fabrication du mail
|
||||
$mail = new CMailFile($newsubject, $sendto, $from, $newmessage,
|
||||
array(), array(), array(),
|
||||
'', '', 0, $msgishtml, $errorsto);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user