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:
@@ -77,6 +77,9 @@ For developers:
|
|||||||
- Log files contains more information (PHP_SELD added and OS user used for
|
- Log files contains more information (PHP_SELD added and OS user used for
|
||||||
log of command lines scripts)
|
log of command lines scripts)
|
||||||
- Can protect a module to not being enabled if javascript disabled.
|
- 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 *****
|
***** Changelog for 2.6 compared to 2.5 *****
|
||||||
|
|||||||
@@ -2763,13 +2763,34 @@ function dol_textishtml($msg,$option=0)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Effectue les substitutions des mots cles par les donnees en fonction du tableau
|
* \brief Add substitution required by external modules then make substitutions in array substitutionarray
|
||||||
* \param chaine Chaine dans laquelle faire les substitutions
|
* \param chaine Source string in which we must do substitution
|
||||||
* \param substitutionarray Tableau cle substitution => valeur a mettre
|
* \param substitutionarray Array substitution old value => new value value
|
||||||
* \return string Chaine avec les substitutions effectuees
|
* \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)
|
foreach ($substitutionarray as $key => $value)
|
||||||
{
|
{
|
||||||
$chaine=ereg_replace("$key","$value",$chaine); // We must keep the " to work when value is 123.5 for example
|
$chaine=ereg_replace("$key","$value",$chaine); // We must keep the " to work when value is 123.5 for example
|
||||||
|
|||||||
@@ -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)
|
function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_basse,$marge_gauche,$page_hauteur,$object)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf,$user;
|
||||||
|
|
||||||
$outputlangs->load("dict");
|
$outputlangs->load("dict");
|
||||||
$ligne='';
|
$ligne='';
|
||||||
@@ -132,7 +132,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
|
||||||
);
|
);
|
||||||
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
|
|
||||||
|
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray,$outputlangs,$object);
|
||||||
$ligne.=$outputlangs->convToOutputCharset($newfreetext);
|
$ligne.=$outputlangs->convToOutputCharset($newfreetext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ $conf->file->dol_document_root=array(DOL_DOCUMENT_ROOT);
|
|||||||
if (! empty($dolibarr_main_document_root_alt))
|
if (! empty($dolibarr_main_document_root_alt))
|
||||||
{
|
{
|
||||||
// dolibarr_main_document_root_alt contains several directories
|
// 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)
|
foreach($values as $value)
|
||||||
{
|
{
|
||||||
$conf->file->dol_document_root[]=$value;
|
$conf->file->dol_document_root[]=$value;
|
||||||
|
|||||||
@@ -574,18 +574,32 @@ class Translate {
|
|||||||
* \return string Label translated in UTF8 (but without entities)
|
* \return string Label translated in UTF8 (but without entities)
|
||||||
* 10 if setDefaultLang was en_US => ten
|
* 10 if setDefaultLang was en_US => ten
|
||||||
* 123 if setDefaultLang was fr_FR => cent vingt trois
|
* 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)
|
function getLabelFromNumber($number,$isamount=0)
|
||||||
{
|
{
|
||||||
|
global $conf;
|
||||||
|
|
||||||
$outlang=$this->defaultlang; // Output language we want
|
$outlang=$this->defaultlang; // Output language we want
|
||||||
$outlangarray=split('_',$outlang,2);
|
$outlangarray=split('_',$outlang,2);
|
||||||
// If lang is xx_XX, then we use xx
|
// If lang is xx_XX, then we use xx
|
||||||
if (strtolower($outlangarray[0]) == strtolower($outlangarray[1])) $outlang=$outlangarray[0];
|
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 $newnumber;
|
||||||
return $number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user