NEW Accept substitution key __[ABC]__ replaced with value of const ABC

This commit is contained in:
Laurent Destailleur 2017-11-25 19:55:31 +01:00
parent 5935ad868a
commit c02528a479
2 changed files with 19 additions and 8 deletions

View File

@ -402,7 +402,7 @@ class FormMail extends Form
$out.= '<table class="border" width="100%">'."\n"; $out.= '<table class="border" width="100%">'."\n";
// Substitution array // Substitution array
if (! empty($this->withsubstit)) // Unset of set ->withsubstit=0 to disable this. if (! empty($this->withsubstit)) // Unset or set ->withsubstit=0 to disable this.
{ {
$out.= '<tr><td colspan="2" align="right">'; $out.= '<tr><td colspan="2" align="right">';
//$out.='<div class="floatright">'; //$out.='<div class="floatright">';
@ -890,8 +890,7 @@ class FormMail extends Form
$defaultmessage = dol_nl2br($defaultmessage); $defaultmessage = dol_nl2br($defaultmessage);
} }
if (isset($_POST["message"]) && ! $_POST['modelselected']) $defaultmessage=$_POST["message"];
if (isset($_POST["message"]) && ! $_POST['modelselected']) $defaultmessage=$_POST["message"];
else else
{ {
$defaultmessage=make_substitutions($defaultmessage,$this->substit); $defaultmessage=make_substitutions($defaultmessage,$this->substit);

View File

@ -5370,7 +5370,8 @@ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $ob
if (empty($exclude) || ! in_array('system', $exclude)) if (empty($exclude) || ! in_array('system', $exclude))
{ {
$substitutionarray['__(AnyTranslationKey)__']=$outputlangs->trans('TranslationKey'); $substitutionarray['__(AnyTranslationKey)__']=$outputlangs->trans('TranslationOfKey');
$substitutionarray['__[AnyConstantKey]__']=$outputlangs->trans('ValueOfConstant');
$substitutionarray['__DOL_MAIN_URL_ROOT__']=DOL_MAIN_URL_ROOT; $substitutionarray['__DOL_MAIN_URL_ROOT__']=DOL_MAIN_URL_ROOT;
} }
if (empty($exclude) || ! in_array('mycompany', $exclude)) if (empty($exclude) || ! in_array('mycompany', $exclude))
@ -5605,7 +5606,7 @@ function make_substitutions($text, $substitutionarray, $outputlangs=null)
// Make substitution for language keys // Make substitution for language keys
if (is_object($outputlangs)) if (is_object($outputlangs))
{ {
while (preg_match('/__\(([^\)]*)\)__/', $text, $reg)) while (preg_match('/__\(([^\)]+)\)__/', $text, $reg))
{ {
// If key is __(TranslationKey|langfile)__, then force load of langfile.lang // If key is __(TranslationKey|langfile)__, then force load of langfile.lang
$tmp=explode('|',$reg[1]); $tmp=explode('|',$reg[1]);
@ -5618,6 +5619,17 @@ function make_substitutions($text, $substitutionarray, $outputlangs=null)
} }
} }
// Make substitution for constant keys. Must be after the substitution of translation, so if text of translation contains a constant,
// it is also converted.
while (preg_match('/__\[([^\]]+)\]__/', $text, $reg))
{
$msgishtml = 0;
if (dol_textishtml($text,1)) $msgishtml = 1;
$newval=empty($conf->global->$reg[1])?'':$conf->global->$reg[1];
$text = preg_replace('/__\['.preg_quote($reg[1], '/').'\]__/', $msgishtml?dol_htmlentitiesbr($newval):$newval, $text);
}
// Make substitition for array $substitutionarray // Make substitition for array $substitutionarray
foreach ($substitutionarray as $key => $value) foreach ($substitutionarray as $key => $value)
{ {
@ -5650,16 +5662,16 @@ function complete_substitutions_array(&$substitutionarray, $outputlangs, $object
// Add a substitution key for each extrafields, using key __EXTRA_XXX__ // Add a substitution key for each extrafields, using key __EXTRA_XXX__
// TODO Remove this. Already available into the getCommonSubstitutionArray used to build the substitution array. // TODO Remove this. Already available into the getCommonSubstitutionArray used to build the substitution array.
if (is_object($object) && is_array($object->array_options)) /*if (is_object($object) && is_array($object->array_options))
{ {
foreach($object->array_options as $key => $val) foreach($object->array_options as $key => $val)
{ {
$keyshort=preg_replace('/^(options|extra)_/','',$key); $keyshort=preg_replace('/^(options|extra)_/','',$key);
$substitutionarray['__EXTRA_'.$keyshort.'__']=$val; $substitutionarray['__EXTRAFIELD_'.$keyshort.'__']=$val;
// For backward compatibiliy // For backward compatibiliy
$substitutionarray['%EXTRA_'.$keyshort.'%']=$val; $substitutionarray['%EXTRA_'.$keyshort.'%']=$val;
} }
} }*/
// Check if there is external substitution to do, requested by plugins // Check if there is external substitution to do, requested by plugins
$dirsubstitutions=array_merge(array(),(array) $conf->modules_parts['substitutions']); $dirsubstitutions=array_merge(array(),(array) $conf->modules_parts['substitutions']);