2
0
forked from Wavyzz/dolibarr

New: Change to allow a module to add subsitutions keys.

Change to be compatible with numberwords plugin.
This commit is contained in:
Laurent Destailleur
2009-08-25 20:57:54 +00:00
parent d05847a838
commit c3d045227b
5 changed files with 50 additions and 11 deletions

View File

@@ -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 *****

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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;
}