Code comment

This commit is contained in:
Laurent Destailleur 2011-08-17 21:39:08 +00:00
parent 78e351cc7c
commit ebc4ed58a4
2 changed files with 34 additions and 26 deletions

View File

@ -23,7 +23,7 @@
* \brief File for Tanslate class
* \author Eric Seigne
* \author Laurent Destailleur
* \version $Id: translate.class.php,v 1.50 2011/08/15 23:17:14 eldy Exp $
* \version $Id: translate.class.php,v 1.51 2011/08/17 21:41:24 eldy Exp $
*/
@ -35,17 +35,17 @@ class Translate {
var $dir; // Directories that contains /langs subdirectory
var $defaultlang; // Langue courante en vigueur de l'utilisateur
var $defaultlang; // Current language for current user
var $direction = 'ltr'; // Left to right or Right to left
var $tab_translate=array(); // Tableau des traductions
var $tab_loaded=array(); // Array to store result after loading each language file
var $cache_labels=array(); // Cache for labels
var $charset_inputfile=array(); // To store charset encoding used for language
var $charset_output='UTF-8'; // Codage used by "trans" method outputs
var $tab_translate=array(); // Array of all translations key=>value
var $tab_loaded=array(); // Array to store result after loading each language file
var $cache_labels=array(); // Cache for labels return by trans method
/**
* Constructor
@ -62,7 +62,6 @@ class Translate {
}
/**
* Set accessor for this->defaultlang
*
@ -220,7 +219,7 @@ class Translate {
// Using a memcached server
if (! empty($conf->memcached->enabled) && ! empty($conf->global->MEMCACHED_SERVER))
{
$usecachekey=$newdomain.'_'.$langofdir.'_'.$file_lang;
$usecachekey=$newdomain.'_'.$langofdir.'_'.md5($file_lang); // Should not contains special chars
}
// Using cache with shmop. Speed gain: 40ms - Memory overusage: 200ko (Size of session cache file)
else if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02))
@ -268,7 +267,7 @@ class Translate {
}
elseif ($key == 'DIRECTION') // This is to declare direction of language
{
if ($alt < 2 || empty($this->tab_translate[$key])) // We load direction only for primary files or if not yer load
if ($alt < 2 || empty($this->tab_translate[$key])) // We load direction only for primary files or if not yet loaded
{
$this->tab_translate[$key]=$value;
@ -279,7 +278,7 @@ class Translate {
else
{
// On stocke toujours dans le tableau Tab en UTF-8
if (empty($this->charset_inputfile[$newdomain]) || $this->charset_inputfile[$newdomain] == 'ISO-8859-1') $value=utf8_encode($value);
if (! empty($this->charset_inputfile[$newdomain]) && $this->charset_inputfile[$newdomain] == 'ISO-8859-1') $value=utf8_encode($value);
//print 'XX'.$key;
$this->tab_translate[$key]=$value;
@ -296,11 +295,16 @@ class Translate {
if ($usecachekey && sizeof($tabtranslatedomain))
{
require_once(DOL_DOCUMENT_ROOT ."/lib/memory.lib.php");
$size=dol_setcache($usecachekey,$tabtranslatedomain);
$ressetcache=dol_setcache($usecachekey,$tabtranslatedomain);
if ($ressetcache < 0)
{
$error='Failed to set cache for usecachekey='.$usecachekey.' result='.$ressetcache;
dol_syslog($error, LOG_ERR);
}
}
//exit;
if (empty($conf->global->MAIN_FORCELANGDIR)) break; // Break loop on each root dir. If a module has forced, we do not stop loop.
if (empty($conf->global->MAIN_FORCELANGDIR)) break; // Break loop on each root dir. If a module has forced dir, we do not stop loop.
}
}
}

View File

@ -19,7 +19,7 @@
/**
* \file htdocs/lib/memory.lib.php
* \brief Set of function for memory/cache management
* \version $Id: memory.lib.php,v 1.11 2011/07/31 23:25:11 eldy Exp $
* \version $Id: memory.lib.php,v 1.12 2011/08/17 21:39:08 eldy Exp $
*/
global $shmkeys,$shmoffset;
@ -34,10 +34,11 @@ $shmoffset=100;
/**
* \brief Save data into a memory area shared by all users, all sessions on server
* \param $memoryid Memory id of shared area
* \param $data Data to save
* \return int <0 if KO, Nb of bytes written if OK
* Save data into a memory area shared by all users, all sessions on server
*
* @param $memoryid Memory id of shared area
* @param $data Data to save
* @return int <0 if KO, Nb of bytes written if OK
*/
function dol_setcache($memoryid,$data)
{
@ -52,7 +53,8 @@ function dol_setcache($memoryid,$data)
$tmparray=explode(':',$conf->global->MEMCACHED_SERVER);
$result=$m->addServer($tmparray[0], $tmparray[1]?$tmparray[1]:11211);
//$m->setOption(Memcached::OPT_COMPRESSION, false);
$m->add($memoryid,$data);
//print "Add memoryid=".$memoryid;
$m->add($memoryid,$data); // This fails if key already exists
$rescode=$m->getResultCode();
if ($rescode == 0)
{
@ -70,7 +72,7 @@ function dol_setcache($memoryid,$data)
$tmparray=explode(':',$conf->global->MEMCACHED_SERVER);
$result=$m->addServer($tmparray[0], $tmparray[1]?$tmparray[1]:11211);
//$m->setOption(Memcached::OPT_COMPRESSION, false);
$result=$m->add($memoryid,$data);
$result=$m->add($memoryid,$data); // This fails if key already exists
if ($result)
{
return sizeof($data);
@ -90,9 +92,10 @@ function dol_setcache($memoryid,$data)
}
/**
* \brief Read a memory area shared by all users, all sessions on server
* \param $memoryid Memory id of shared area
* \return int <0 if KO, data if OK
* Read a memory area shared by all users, all sessions on server
*
* @param $memoryid Memory id of shared area
* @return int <0 if KO, data if OK
*/
function dol_getcache($memoryid)
{
@ -106,9 +109,10 @@ function dol_getcache($memoryid)
$tmparray=explode(':',$conf->global->MEMCACHED_SERVER);
$result=$m->addServer($tmparray[0], $tmparray[1]?$tmparray[1]:11211);
//$m->setOption(Memcached::OPT_COMPRESSION, false);
//print "Get memoryid=".$memoryid;
$data=$m->get($memoryid);
$rescode=$m->getResultCode();
//print "memoryid=".$memoryid." - rescode=".$rescode." - date=".sizeof($data)."\n<br>";
//print "memoryid=".$memoryid." - rescode=".$rescode." - data=".sizeof($data)."\n<br>";
//var_dump($data);
if ($rescode == 0)
{
@ -127,7 +131,7 @@ function dol_getcache($memoryid)
$result=$m->addServer($tmparray[0], $tmparray[1]?$tmparray[1]:11211);
//$m->setOption(Memcached::OPT_COMPRESSION, false);
$data=$m->get($memoryid);
//print "memoryid=".$memoryid." - rescode=".$rescode." - date=".sizeof($data)."\n<br>";
//print "memoryid=".$memoryid." - rescode=".$rescode." - data=".sizeof($data)."\n<br>";
//var_dump($data);
if ($data)
{