Qual: Optimize substitution engine
This commit is contained in:
parent
87f01b0c18
commit
311339b0ca
@ -138,15 +138,15 @@ else
|
|||||||
'%MONTH%'=>$month,
|
'%MONTH%'=>$month,
|
||||||
'%DAY%'=>$day
|
'%DAY%'=>$day
|
||||||
);
|
);
|
||||||
|
complete_substitutions_array($substitutionarray, $langs);
|
||||||
|
|
||||||
// For business cards
|
// For business cards
|
||||||
if (empty($mode) || $mode=='card' || $mode=='cardlogin')
|
if (empty($mode) || $mode=='card' || $mode=='cardlogin')
|
||||||
{
|
{
|
||||||
$textleft=make_substitutions($conf->global->ADHERENT_CARD_TEXT, $substitutionarray, $langs);
|
$textleft=make_substitutions($conf->global->ADHERENT_CARD_TEXT, $substitutionarray);
|
||||||
$textheader=make_substitutions($conf->global->ADHERENT_CARD_HEADER_TEXT, $substitutionarray, $langs);
|
$textheader=make_substitutions($conf->global->ADHERENT_CARD_HEADER_TEXT, $substitutionarray);
|
||||||
$textfooter=make_substitutions($conf->global->ADHERENT_CARD_FOOTER_TEXT, $substitutionarray, $langs);
|
$textfooter=make_substitutions($conf->global->ADHERENT_CARD_FOOTER_TEXT, $substitutionarray);
|
||||||
$textright=make_substitutions($conf->global->ADHERENT_CARD_TEXT_RIGHT, $substitutionarray, $langs);
|
$textright=make_substitutions($conf->global->ADHERENT_CARD_TEXT_RIGHT, $substitutionarray);
|
||||||
|
|
||||||
if (is_numeric($foruserid) || $foruserlogin)
|
if (is_numeric($foruserid) || $foruserlogin)
|
||||||
{
|
{
|
||||||
@ -175,7 +175,7 @@ else
|
|||||||
if ($mode == 'label')
|
if ($mode == 'label')
|
||||||
{
|
{
|
||||||
$conf->global->ADHERENT_ETIQUETTE_TEXT="%PRENOM% %NOM%\n%ADRESSE%\n%CP% %VILLE%\n%PAYS%";
|
$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='';
|
$textheader='';
|
||||||
$textfooter='';
|
$textfooter='';
|
||||||
$textright='';
|
$textright='';
|
||||||
|
|||||||
@ -199,7 +199,7 @@ class Adherent extends CommonObject
|
|||||||
$infos.= $langs->transnoentities("Public").": ".yn($this->public);
|
$infos.= $langs->transnoentities("Public").": ".yn($this->public);
|
||||||
|
|
||||||
// Substitutions
|
// Substitutions
|
||||||
$substit=array(
|
$substitutionarray=array(
|
||||||
'%DOL_MAIN_URL_ROOT%'=>DOL_MAIN_URL_ROOT,
|
'%DOL_MAIN_URL_ROOT%'=>DOL_MAIN_URL_ROOT,
|
||||||
'%INFOS%'=>$msgishtml?dol_htmlentitiesbr($infos):$infos,
|
'%INFOS%'=>$msgishtml?dol_htmlentitiesbr($infos):$infos,
|
||||||
'%CIVILITE%'=>$this->getCivilityLabel($msgishtml?0:1),
|
'%CIVILITE%'=>$this->getCivilityLabel($msgishtml?0:1),
|
||||||
@ -217,7 +217,9 @@ class Adherent extends CommonObject
|
|||||||
'%PASSWORD%'=>$msgishtml?dol_htmlentitiesbr($this->pass):$this->pass
|
'%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();
|
accessforbidden();
|
||||||
|
|
||||||
$substitutionarrayfortest=array(
|
$substitutionarrayfortest=array(
|
||||||
|
'__LOGIN__' => $user->login,
|
||||||
'__ID__' => 'TESTIdRecord',
|
'__ID__' => 'TESTIdRecord',
|
||||||
'__EMAIL__' => 'TESTEMail',
|
'__EMAIL__' => 'TESTEMail',
|
||||||
'__LASTNAME__' => 'TESTLastname',
|
'__LASTNAME__' => 'TESTLastname',
|
||||||
'__FIRSTNAME__' => 'TESTFirstname'
|
'__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
|
if ($_POST['action'] == 'sendhtml') $msgishtml=1; // Force message to HTML
|
||||||
|
|
||||||
// Pratique les substitutions sur le sujet et message
|
// Pratique les substitutions sur le sujet et message
|
||||||
$subject=make_substitutions($subject,$substitutionarrayfortest,$langs);
|
$subject=make_substitutions($subject,$substitutionarrayfortest);
|
||||||
$body=make_substitutions($body,$substitutionarrayfortest,$langs);
|
$body=make_substitutions($body,$substitutionarrayfortest);
|
||||||
|
|
||||||
require_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
|
require_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
|
||||||
$mailfile = new CMailFile($subject,$sendto,$email_from,$body,
|
$mailfile = new CMailFile($subject,$sendto,$email_from,$body,
|
||||||
@ -716,6 +718,7 @@ else
|
|||||||
$formmail->withtopicreadonly=0;
|
$formmail->withtopicreadonly=0;
|
||||||
$formmail->withfile=2;
|
$formmail->withfile=2;
|
||||||
$formmail->withbody=(isset($_POST['message'])?$_POST['message']:$langs->trans("PredefinedMailTestHtml"));
|
$formmail->withbody=(isset($_POST['message'])?$_POST['message']:$langs->trans("PredefinedMailTestHtml"));
|
||||||
|
//$formmail->withbody='Test <b>aaa</b> __LOGIN__';
|
||||||
$formmail->withbodyreadonly=0;
|
$formmail->withbodyreadonly=0;
|
||||||
$formmail->withcancel=1;
|
$formmail->withcancel=1;
|
||||||
$formmail->withdeliveryreceipt=1;
|
$formmail->withdeliveryreceipt=1;
|
||||||
|
|||||||
@ -108,7 +108,8 @@ if ($action == 'send' && ! $_POST['cancel'])
|
|||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
// Make substitutions into message
|
// 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");
|
require_once(DOL_DOCUMENT_ROOT."/lib/CSMSFile.class.php");
|
||||||
|
|
||||||
|
|||||||
@ -191,8 +191,9 @@ if ($_REQUEST["action"] == 'sendallconfirmed' && $_REQUEST['confirm'] == 'yes')
|
|||||||
);
|
);
|
||||||
|
|
||||||
$substitutionisok=true;
|
$substitutionisok=true;
|
||||||
$newsubject=make_substitutions($subject,$substitutionarray,$langs);
|
complete_substitutions_array($substitutionarray, $langs);
|
||||||
$newmessage=make_substitutions($message,$substitutionarray,$langs);
|
$newsubject=make_substitutions($subject,$substitutionarray);
|
||||||
|
$newmessage=make_substitutions($message,$substitutionarray);
|
||||||
|
|
||||||
$arr_file = array();
|
$arr_file = array();
|
||||||
$arr_mime = array();
|
$arr_mime = array();
|
||||||
|
|||||||
@ -412,7 +412,7 @@ class FormMail
|
|||||||
// Topic
|
// Topic
|
||||||
if ($this->withtopic)
|
if ($this->withtopic)
|
||||||
{
|
{
|
||||||
$this->withtopic=make_substitutions($this->withtopic,$this->substit,$langs);
|
$this->withtopic=make_substitutions($this->withtopic,$this->substit);
|
||||||
|
|
||||||
print "<tr>";
|
print "<tr>";
|
||||||
print "<td width=\"180\">".$langs->trans("MailTopic")."</td>";
|
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_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendOrder"); }
|
||||||
if ($this->param["models"]=='order_supplier_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendSupplierOrder"); }
|
if ($this->param["models"]=='order_supplier_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendSupplierOrder"); }
|
||||||
if ($this->param["models"]=='invoice_supplier_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendSupplierInvoice"); }
|
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"];
|
if (isset($_POST["message"])) $defaultmessage=$_POST["message"];
|
||||||
$defaultmessage=str_replace('\n',"\n",$defaultmessage);
|
$defaultmessage=str_replace('\n',"\n",$defaultmessage);
|
||||||
|
|
||||||
|
|||||||
@ -238,38 +238,11 @@ function limitChars(textarea, limit, infodiv)
|
|||||||
print "</td></tr>\n";
|
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
|
// Message
|
||||||
if ($this->withbody)
|
if ($this->withbody)
|
||||||
{
|
{
|
||||||
$defaultmessage='';
|
$defaultmessage='';
|
||||||
if ($this->param["models"]=='body') { $defaultmessage=$this->withbody; }
|
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);
|
$defaultmessage=make_substitutions($defaultmessage,$this->substit,$langs);
|
||||||
if (isset($_POST["message"])) $defaultmessage=$_POST["message"];
|
if (isset($_POST["message"])) $defaultmessage=$_POST["message"];
|
||||||
$defaultmessage=str_replace('\n',"\n",$defaultmessage);
|
$defaultmessage=str_replace('\n',"\n",$defaultmessage);
|
||||||
|
|||||||
@ -353,21 +353,22 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
|||||||
$socobject=$object->client;
|
$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
|
// Line of free text
|
||||||
$newfreetext='';
|
$newfreetext='';
|
||||||
$paramfreetext='FACTURE_FREE_TEXT';
|
$paramfreetext='FACTURE_FREE_TEXT';
|
||||||
if (! empty($conf->global->$paramfreetext))
|
if (! empty($conf->global->$paramfreetext))
|
||||||
{
|
{
|
||||||
// Make substitution
|
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
|
||||||
$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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open and load template
|
// Open and load template
|
||||||
|
|||||||
@ -1051,7 +1051,7 @@ function dol_print_phone($phone,$country="FR",$cid=0,$socid=0,$addlink=0,$separ=
|
|||||||
'__PHONETO__'=>urlencode($phone),
|
'__PHONETO__'=>urlencode($phone),
|
||||||
'__LOGIN__'=>urlencode($user->clicktodial_login),
|
'__LOGIN__'=>urlencode($user->clicktodial_login),
|
||||||
'__PASS__'=>urlencode($user->clicktodial_password));
|
'__PASS__'=>urlencode($user->clicktodial_password));
|
||||||
$url = make_substitutions($url, $substitarray, $langs);
|
$url = make_substitutions($url, $substitarray);
|
||||||
$newphonesav=$newphone;
|
$newphonesav=$newphone;
|
||||||
$newphone ='<a href="'.$url.'"';
|
$newphone ='<a href="'.$url.'"';
|
||||||
if (! empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) $newphone.=' target="_blank"';
|
if (! empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) $newphone.=' target="_blank"';
|
||||||
@ -3571,16 +3571,11 @@ function dol_textishtml($msg,$option=0)
|
|||||||
* - From $substitutionarray (oldval=>newval)
|
* - From $substitutionarray (oldval=>newval)
|
||||||
* - From special constants (__XXX__=>f(objet->xxx)) by substitutions modules
|
* - From special constants (__XXX__=>f(objet->xxx)) by substitutions modules
|
||||||
* @param chaine Source string in which we must do substitution
|
* @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
|
* @return string Output string after subsitutions
|
||||||
*/
|
*/
|
||||||
function make_substitutions($chaine,$substitutionarray,$outputlangs,$object='')
|
function make_substitutions($chaine,$substitutionarray)
|
||||||
{
|
{
|
||||||
global $conf,$user;
|
if (! is_array($substitutionarray)) return 'ErrorBadParametersCalling_make_substitutions';
|
||||||
|
|
||||||
complete_substitutions_array($substitutionarray,$outputlangs,$object);
|
|
||||||
|
|
||||||
// Make substitition
|
// Make substitition
|
||||||
foreach ($substitutionarray as $key => $value)
|
foreach ($substitutionarray as $key => $value)
|
||||||
|
|||||||
@ -470,8 +470,8 @@ function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_bass
|
|||||||
'__TOTAL_HT__' => $object->total_ht,
|
'__TOTAL_HT__' => $object->total_ht,
|
||||||
'__TOTAL_VAT__' => $object->total_vat
|
'__TOTAL_VAT__' => $object->total_vat
|
||||||
);
|
);
|
||||||
|
complete_substitutions_array($substitutionarray,$outputlangs,$object);
|
||||||
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray,$outputlangs,$object);
|
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
|
||||||
$line.=$outputlangs->convToOutputCharset($newfreetext);
|
$line.=$outputlangs->convToOutputCharset($newfreetext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -146,11 +146,13 @@ if ($resql)
|
|||||||
'__OTHER5__' => $other5
|
'__OTHER5__' => $other5
|
||||||
);
|
);
|
||||||
|
|
||||||
$substitutionisok=true;
|
$substitutionarray=complete_substitutions_array($substitutionarray,$langs);
|
||||||
$newsubject=make_substitutions($subject,$substitutionarray,$langs);
|
$newsubject=make_substitutions($subject,$substitutionarray);
|
||||||
$newmessage=make_substitutions($message,$substitutionarray,$langs);
|
$newmessage=make_substitutions($message,$substitutionarray);
|
||||||
|
|
||||||
// Fabrication du mail
|
$substitutionisok=true;
|
||||||
|
|
||||||
|
// Fabrication du mail
|
||||||
$mail = new CMailFile($newsubject, $sendto, $from, $newmessage,
|
$mail = new CMailFile($newsubject, $sendto, $from, $newmessage,
|
||||||
array(), array(), array(),
|
array(), array(), array(),
|
||||||
'', '', 0, $msgishtml, $errorsto);
|
'', '', 0, $msgishtml, $errorsto);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user