Qual: Try to reduce call to convToOutputCharset

This commit is contained in:
Laurent Destailleur 2011-12-07 18:10:24 +01:00
parent 53181aa0c1
commit 1b2c0120da
7 changed files with 74 additions and 80 deletions

View File

@ -98,7 +98,7 @@ body {
</div>
<div class="infos">
<p class="address"><?php echo $mysoc->name; ?><br>
<?php print dol_nl2br(dol_format_address($langs,$mysoc)); ?><br>
<?php print dol_nl2br(dol_format_address($mysoc)); ?><br>
</p>
<p class="date_heure"><?php

View File

@ -864,17 +864,17 @@ class ActionComm extends CommonObject
//print $datestart.'x'; exit;
$dateend=$this->db->jdate($obj->datep2);
$duration=$obj->durationp;
$event['summary']=$langs->convToOutputCharset($obj->label.($obj->socname?" (".$obj->socname.")":""));
$event['desc']=$langs->convToOutputCharset($obj->note);
$event['summary']=$obj->label.($obj->socname?" (".$obj->socname.")":"");
$event['desc']=$obj->note;
$event['startdate']=$datestart;
$event['duration']=$duration; // Not required with type 'journal'
$event['enddate']=$dateend; // Not required with type 'journal'
$event['author']=$obj->firstname.($obj->name?" ".$obj->name:"");
$event['priority']=$obj->priority;
$event['fulldayevent']=$obj->fulldayevent;
$event['location']=$langs->convToOutputCharset($obj->location);
$event['location']=$obj->location;
$event['transparency']='TRANSPARENT'; // OPAQUE (busy) or TRANSPARENT (not busy)
$event['category']=$langs->convToOutputCharset($obj->libelle); // libelle type action
$event['category']=$obj->libelle; // libelle type action
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',$dolibarr_main_url_root);
$url=$urlwithouturlroot.DOL_URL_ROOT.'/comm/action/fiche.php?id='.$obj->id;
$event['url']=$url;
@ -898,21 +898,21 @@ class ActionComm extends CommonObject
// Define title and desc
$more='';
if ($login) $more=$langs->transnoentities("User").' '.$langs->convToOutputCharset($login);
if ($logina) $more=$langs->transnoentities("ActionsAskedBy").' '.$langs->convToOutputCharset($logina);
if ($logint) $more=$langs->transnoentities("ActionsToDoBy").' '.$langs->convToOutputCharset($logint);
if ($logind) $more=$langs->transnoentities("ActionsDoneBy").' '.$langs->convToOutputCharset($logind);
if ($login) $more=$langs->transnoentities("User").' '.$login;
if ($logina) $more=$langs->transnoentities("ActionsAskedBy").' '.$logina;
if ($logint) $more=$langs->transnoentities("ActionsToDoBy").' '.$logint;
if ($logind) $more=$langs->transnoentities("ActionsDoneBy").' '.$logind;
if ($more)
{
$title=$langs->convToOutputCharset('Dolibarr actions '.$mysoc->name).' - '.$more;
$title='Dolibarr actions '.$mysoc->name.' - '.$more;
$desc=$more;
$desc.=$langs->convToOutputCharset(' ('.$mysoc->name.' - built by Dolibarr)');
$desc.=' ('.$mysoc->name.' - built by Dolibarr)';
}
else
{
$title=$langs->convToOutputCharset('Dolibarr actions '.$mysoc->name);
$title='Dolibarr actions '.$mysoc->name;
$desc=$langs->transnoentities('ListOfActions');
$desc.=$langs->convToOutputCharset(' ('.$mysoc->name.' - built by Dolibarr)');
$desc.=' ('.$mysoc->name.' - built by Dolibarr)';
}
// Create temp file

View File

@ -1242,7 +1242,7 @@ class Form
}
}
$opt.= '>';
$opt.= $langs->convToOutputCharset($objp->ref).' - '.$langs->convToOutputCharset(dol_trunc($label,32)).' - ';
$opt.= $objp->ref.' - '.dol_trunc($label,32).' - ';
$objRef = $objp->ref;
if ($filterkey && $filterkey != '') $objRef=preg_replace('/('.preg_quote($filterkey).')/i','<strong>$1</strong>',$objRef,1);
@ -1459,9 +1459,9 @@ class Form
$label = $objp->label;
if ($filterkey && $filterkey != '') $label=preg_replace('/('.preg_quote($filterkey).')/i','<strong>$1</strong>',$label,1);
$opt.=$langs->convToOutputCharset($objp->ref).' ('.$langs->convToOutputCharset($objp->ref_fourn).') - ';
$opt.=$objp->ref.' ('.$objp->ref_fourn.') - ';
$outval.=$objRef.' ('.$objRefFourn.') - ';
$opt.=$langs->convToOutputCharset(dol_trunc($objp->label,18)).' - ';
$opt.=dol_trunc($objp->label,18).' - ';
$outval.=dol_trunc($label,18).' - ';
if ($objp->fprice != '') // Keep != ''

View File

@ -1290,12 +1290,13 @@ class Ldap
/**
* \brief Convert a string into output/memory charset
* \param str String to convert
* \param pagecodefrom Page code of src string
* \return string Converted string
* Convert a string into output/memory charset
*
* @param str String to convert
* @param pagecodefrom Page code of src string
* @return string Converted string
*/
function convToOutputCharset($str,$pagecodefrom='UTF-8')
private function convToOutputCharset($str,$pagecodefrom='UTF-8')
{
global $conf;
if ($pagecodefrom == 'ISO-8859-1' && $conf->file->character_set_client == 'UTF-8') $str=utf8_encode($str);
@ -1304,10 +1305,11 @@ class Ldap
}
/**
* \brief Convert a string from output/memory charset
* \param str String to convert
* \param pagecodeto Page code for result string
* \return string Converted string
* Convert a string from output/memory charset
*
* @param str String to convert
* @param pagecodeto Page code for result string
* @return string Converted string
*/
function convFromOutputCharset($str,$pagecodeto='UTF-8')
{
@ -1316,16 +1318,16 @@ class Ldap
if ($pagecodeto == 'UTF-8' && $conf->file->character_set_client == 'ISO-8859-1') $str=utf8_encode($str);
return $str;
}
/**
* Return available value of group GID
* Return available value of group GID
* @return int gid number
*/
*/
function getNextGroupGid()
{
global $conf;
$search='('.$conf->global->LDAP_KEY_GROUPS.'=*)';
$result = $this->search($this->groups,$search);
if($result)
@ -1337,11 +1339,11 @@ class Ldap
$gids[] = $result[$i]['gidnumber'][0];
}
rsort($gids);
return $gids[0]+1;
}
return 0;
return 0;
}
}

View File

@ -384,7 +384,7 @@ class Translate {
* @param string $param2 chaine de param2
* @param string $param3 chaine de param3
* @param string $param4 chaine de param4
* @param int $maxsize taille max
* @param int $maxsize Max length of text
* @return string Translated string (encoded into HTML entities and UTF8)
*/
function trans($key, $param1='', $param2='', $param3='', $param4='', $maxsize=0)
@ -412,8 +412,9 @@ class Translate {
}
else // Translation is not available
{
$str=$this->getTradFromKey($key);
//$str=$this->getTradFromKey($key);
//return $this->convToOutputCharset($str);
return $this->getTradFromKey($key);
}
}
@ -424,25 +425,16 @@ class Translate {
* et si toujours pas trouve, il est retourne tel quel.
* Parameters of this method must not contains any HTML tags.
*
* @param key key of string to translate
* @param param1 chaine de param1
* @param param2 chaine de param2
* @param param3 chaine de param3
* @param param4 chaine de param4
* @return string chaine traduite
* @param string $key Key to translate
* @param string $param1 chaine de param1
* @param string $param2 chaine de param2
* @param string $param3 chaine de param3
* @param string $param4 chaine de param4
* @return string Translated string (encoded into UTF8)
*/
function transnoentities($key, $param1='', $param2='', $param3='', $param4='')
{
if (! empty($this->tab_translate[$key]))
{
// Si la traduction est disponible
$newstr=sprintf($this->tab_translate[$key],$param1,$param2,$param3,$param4);
}
else
{
$newstr=$this->getTradFromKey($key);
}
return $this->convToOutputCharset($newstr);
return $this->convToOutputCharset($this->transnoentitiesnoconv($key, $param1, $param2, $param3, $param4));
}
@ -453,25 +445,26 @@ class Translate {
* No convert to encoding charset of lang object is done.
* Parameters of this method must not contains any HTML tags.
*
* @param key key of string to translate
* @param param1 chaine de param1
* @param param2 chaine de param1
* @param param3 chaine de param1
* @param param4 chaine de param1
* @return string chaine traduite
* @param string $key Key to translate
* @param string $param1 chaine de param1
* @param string $param2 chaine de param2
* @param string $param3 chaine de param3
* @param string $param4 chaine de param4
* @return string Translated string
*/
function transnoentitiesnoconv($key, $param1='', $param2='', $param3='', $param4='')
{
if (! empty($this->tab_translate[$key]))
if (! empty($this->tab_translate[$key])) // Translation is available
{
// Si la traduction est disponible
$newstr=sprintf($this->tab_translate[$key],$param1,$param2,$param3,$param4);
$str=$this->tab_translate[$key];
$str=sprintf($str,$param1,$param2,$param3,$param4);
}
else
{
$newstr=$this->getTradFromKey($key);
$str=$this->getTradFromKey($key);
}
return $newstr;
return $str;
}
@ -650,7 +643,7 @@ class Translate {
$sql = "SELECT ".$fieldlabel." as label";
$sql.= " FROM ".MAIN_DB_PREFIX.$tablename;
$sql.= " WHERE ".$fieldkey." = '".$key."'";
dol_syslog('Translate::getLabelFromKey sql='.$sql,LOG_DEBUG);
dol_syslog(get_class($this).'::getLabelFromKey sql='.$sql,LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
@ -664,7 +657,7 @@ class Translate {
else
{
$this->error=$db->lasterror();
dol_syslog("Translate::getLabelFromKey error=".$this->error,LOG_ERR);
dol_syslog(get_class($this).'::getLabelFromKey error='.$this->error,LOG_ERR);
return -1;
}
}

View File

@ -735,34 +735,33 @@ function dolibarr_print_date($time,$format='',$to_gmt=false,$outputlangs='',$enc
/**
* Return a formated address (part address/zip/town/state) according to country rules
*
* @param outputlangs Output langs object
* @param object A company or contact object
* @return string Formated string
* @param Object $object A company or contact object
* @return string Formated string
*/
function dol_format_address($outputlangs,$object)
function dol_format_address($object)
{
$ret='';
$countriesusingstate=array('US','IN');
// Address
$ret .= $outputlangs->convToOutputCharset($object->address);
$ret .= $object->address;
// Zip/Town/State
if (in_array($object->country_code,array('US'))) // US: town, state, zip
{
$ret .= ($ret ? "\n" : '' ).$outputlangs->convToOutputCharset($object->town);
$ret .= ($ret ? "\n" : '' ).$object->town;
if ($object->state && in_array($object->country_code,$countriesusingstate))
{
$ret.=", ".$outputlangs->convToOutputCharset($object->departement);
$ret.=", ".$object->departement;
}
if ($object->zip) $ret .= ', '.$outputlangs->convToOutputCharset($object->zip);
if ($object->zip) $ret .= ', '.$object->zip;
}
else // Other: zip town, state
{
$ret .= ($ret ? "\n" : '' ).$outputlangs->convToOutputCharset($object->zip);
$ret .= ' '.$outputlangs->convToOutputCharset($object->town);
$ret .= ($ret ? "\n" : '' ).$object->zip;
$ret .= ' '.$object->town;
if ($object->state && in_array($object->country_code,$countriesusingstate))
{
$ret.=", ".$outputlangs->convToOutputCharset($object->state);
$ret.=", ".$object->state;
}
}
@ -4418,7 +4417,7 @@ function printCommonFooter($zone='private')
{
global $conf;
global $micro_start_time;
if ($zone == 'private') print "\n".'<!-- Common footer for private page -->'."\n";
else print "\n".'<!-- Common footer for public page -->'."\n";

View File

@ -190,7 +190,7 @@ function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$target
if ($mode == 'source')
{
$stringaddress .= ($stringaddress ? "\n" : '' ).dol_format_address($outputlangs,$sourcecompany)."\n";
$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($sourcecompany))."\n";
// Tel
if ($sourcecompany->tel) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ".$outputlangs->convToOutputCharset($sourcecompany->tel);
@ -207,13 +207,13 @@ function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$target
if ($usecontact)
{
$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset($targetcontact->getFullName($outputlangs,1));
$stringaddress .= ($stringaddress ? "\n" : '' ).dol_format_address($outputlangs,$targetcontact)."\n";
$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($targetcontact))."\n";
// Country
if ($targetcontact->pays_code && $targetcontact->pays_code != $sourcecompany->pays_code) $stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcontact->pays_code))."\n";
}
else
{
$stringaddress .= ($stringaddress ? "\n" : '' ).dol_format_address($outputlangs,$targetcompany)."\n";
$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($targetcompany))."\n";
// Country
if ($targetcompany->pays_code && $targetcompany->pays_code != $sourcecompany->pays_code) $stringaddress.=$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$targetcompany->pays_code))."\n";
}
@ -250,7 +250,7 @@ function pdf_build_address($outputlangs,$sourcecompany,$targetcompany='',$target
if ($mode == 'delivery') // for a delivery address (address + phone/fax)
{
$stringaddress .= ($stringaddress ? "\n" : '' ).dol_format_address($outputlangs,$deliverycompany)."\n";
$stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->convToOutputCharset(dol_format_address($deliverycompany))."\n";
// Tel
if ($deliverycompany->phone) $stringaddress .= ($stringaddress ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ".$outputlangs->convToOutputCharset($deliverycompany->phone);
@ -1213,7 +1213,7 @@ function pdf_getlinetotalwithtax($object,$i,$outputlangs,$hidedetails=0)
}
else
{
if (empty($hidedetails) || $hidedetails > 1) return
if (empty($hidedetails) || $hidedetails > 1) return
price(($object->lines[$i]->total_ht) + ($object->lines[$i]->total_ht)*($object->lines[$i]->tva_tx)/100);
}
}