diff --git a/ChangeLog b/ChangeLog index 68cbd8313af..61e335890ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -77,6 +77,9 @@ For developers: - Log files contains more information (PHP_SELD added and OS user used for log of command lines scripts) - Can protect a module to not being enabled if javascript disabled. +- If module numberwords is installed, code can use langs->getLabelFromNumber + to get value of an amount in text. +- A module can add subsitution keys in makesubsitutions() functions. ***** Changelog for 2.6 compared to 2.5 ***** diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index 73b91665c2b..246ecad5a09 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -2763,13 +2763,34 @@ function dol_textishtml($msg,$option=0) } /** - * \brief Effectue les substitutions des mots cles par les donnees en fonction du tableau - * \param chaine Chaine dans laquelle faire les substitutions - * \param substitutionarray Tableau cle substitution => valeur a mettre - * \return string Chaine avec les substitutions effectuees + * \brief Add substitution required by external modules then make substitutions in array substitutionarray + * \param chaine Source string in which we must do substitution + * \param substitutionarray Array substitution old value => new value value + * \param outputlangs If we want to add more substitution, we provide a language + * \param object If we want to add more substitution, we provide a source object + * \return string Output string after subsitutions */ -function make_substitutions($chaine,$substitutionarray) +function make_substitutions($chaine,$substitutionarray,$outputlangs='',$object='') { + global $conf,$user; + + // Check if there is external substitution to do asked by plugins + // We look files into the includes/modules/substitutions directory + // By default, there is no such external plugins. + foreach ($conf->file->dol_document_root as $dirroot) + { + $dir=$dirroot."/includes/modules/substitutions"; + $fonc='numberwords'; // For the moment only one file scan + if (file_exists($dir.'/functions_'.$fonc.'.lib.php')) + { + dol_syslog("Library functions_".$fonc.".lib.php found into ".$dir); + require_once($dir."/functions_".$fonc.".lib.php"); + numberwords_completesubstitutionarray($substitutionarray,$outputlangs,$object); + break; + } + } + + // Make substitition foreach ($substitutionarray as $key => $value) { $chaine=ereg_replace("$key","$value",$chaine); // We must keep the " to work when value is 123.5 for example diff --git a/htdocs/lib/pdf.lib.php b/htdocs/lib/pdf.lib.php index ac323ffe1da..1e877a75336 100644 --- a/htdocs/lib/pdf.lib.php +++ b/htdocs/lib/pdf.lib.php @@ -116,7 +116,7 @@ function pdf_bank(&$pdf,$outputlangs,$curx,$cury,$account) */ function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_basse,$marge_gauche,$page_hauteur,$object) { - global $conf; + global $conf,$user; $outputlangs->load("dict"); $ligne=''; @@ -132,7 +132,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); + + $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray,$outputlangs,$object); $ligne.=$outputlangs->convToOutputCharset($newfreetext); } diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php index 57af97dbe44..feb2d1b6cb3 100644 --- a/htdocs/master.inc.php +++ b/htdocs/master.inc.php @@ -157,7 +157,7 @@ $conf->file->dol_document_root=array(DOL_DOCUMENT_ROOT); if (! empty($dolibarr_main_document_root_alt)) { // dolibarr_main_document_root_alt contains several directories - $values=split(';',$dolibarr_main_document_root_alt); + $values=split('[;,]',$dolibarr_main_document_root_alt); foreach($values as $value) { $conf->file->dol_document_root[]=$value; diff --git a/htdocs/translate.class.php b/htdocs/translate.class.php index 94dfd00a7d4..f244d0432b7 100644 --- a/htdocs/translate.class.php +++ b/htdocs/translate.class.php @@ -574,18 +574,32 @@ class Translate { * \return string Label translated in UTF8 (but without entities) * 10 if setDefaultLang was en_US => ten * 123 if setDefaultLang was fr_FR => cent vingt trois + * \remarks This function need module "numberwords" to be installed. If not it will return + * same number (this module is not provided by default as it use non GPL source code). */ function getLabelFromNumber($number,$isamount=0) { + global $conf; + $outlang=$this->defaultlang; // Output language we want $outlangarray=split('_',$outlang,2); // If lang is xx_XX, then we use xx if (strtolower($outlangarray[0]) == strtolower($outlangarray[1])) $outlang=$outlangarray[0]; - // TODO + $newnumber=$number; + foreach ($conf->file->dol_document_root as $dirroot) + { + $dir=$dirroot."/includes/modules/substitutions"; + $fonc='numberwords'; + if (file_exists($dir.'/functions_'.$fonc.'.lib.php')) + { + include_once($dir.'/functions_'.$fonc.'.lib.php'); + $newnumber=numberwords_getLabelFromNumber($this,$number,$isamount); + break; + } + } - - return $number; + return $newnumber; }