Index: trunk/core/kernel/languages/phrases_cache.php
===================================================================
diff -u -N -r3282 -r4758
--- trunk/core/kernel/languages/phrases_cache.php (.../phrases_cache.php) (revision 3282)
+++ trunk/core/kernel/languages/phrases_cache.php (.../phrases_cache.php) (revision 4758)
@@ -1,23 +1,23 @@
LanguageId = $this->Application->GetVar('m_lang');
- $this->LoadPhrases( $this->GetCachedIds() );
+ if (isset($this->Application->Caches['PhraseList'])) {
+ $this->LoadPhrases( $this->Application->Caches['PhraseList'] );
+ }
}
-
+
function GetCachedIds()
{
- $query = sprintf("SELECT PhraseList FROM %s WHERE Template = %s",
+ $query = sprintf("SELECT PhraseList, ConfigVariables FROM %s WHERE Template = %s",
TABLE_PREFIX.'PhraseCache',
- $this->Conn->Qstr(md5($this->Application->GetVar('t'))));
- $phrases_ids = $this->Conn->GetOne($query);
- return ($phrases_ids === false) ? Array() : explode(',', $phrases_ids);
+ $this->Conn->Qstr(md5($this->Application->GetVar('t').$this->Application->GetVar('m_theme').$this->Application->GetVar('m_lang'))));
+ $res = $this->Conn->GetRow($query);
+
+ if ($res && $res['ConfigVariables']) {
+ $this->Application->OriginalConfigCacheIds = explode(',', $res['ConfigVariables']);
+ $this->Application->ConfigCacheIds = $this->Application->OriginalConfigCacheIds;
+ }
+
+ return ($res === false) ? Array() : explode(',', $res['PhraseList']);
}
-
+
function LoadPhrases($ids)
{
if ( !is_array($ids) || !implode('', $ids) ) return;
- $query = sprintf("SELECT Translation,Phrase FROM %s WHERE LanguageId = %s AND PhraseId IN (%s)",
+ $query = sprintf("SELECT Translation,UPPER(Phrase) AS Phrase FROM %s WHERE LanguageId = %s AND PhraseId IN (%s)",
TABLE_PREFIX.'Phrase',
$this->LanguageId,
join(',', $ids));
- $phrases = $this->Conn->GetCol($query,'Phrase');
- foreach($phrases as $phrase => $tanslation)
+ $this->Phrases = $this->Conn->GetCol($query,'Phrase');
+ /*foreach($phrases as $phrase => $tanslation)
{
$this->AddCachedPhrase(strtoupper($phrase), $tanslation);
- }
+ }*/
$this->Ids = $ids;
$this->OriginalIds = $ids;
}
-
+
function AddCachedPhrase($label, $value)
{
$label = strtoupper($label);
$this->Phrases[$label] = $value;
}
-
+
+ function NeedsCacheUpdate()
+ {
+ return is_array($this->Ids) && count($this->Ids) > 0 && $this->Ids != $this->OriginalIds;
+ }
+
function UpdateCache()
{
- if (!is_array($this->Ids) || count($this->Ids) == 0) return;
- if ($this->Ids == $this->OriginalIds) return; //nothing changed
- $query = sprintf("REPLACE %s (PhraseList, CacheDate, Template)
- VALUES (%s, %s, %s)",
- TABLE_PREFIX.'PhraseCache',
- $this->Conn->Qstr(join(',', $this->Ids)),
- adodb_mktime(),
- $this->Conn->Qstr(md5($this->Application->GetVar('t'))));
- $this->Conn->Query($query);
+ $update = false;
+ //something changed
+ $update = $update || (is_array($this->Ids) && count($this->Ids) > 0 && $this->Ids != $this->OriginalIds);
+ $update = $update || (count($this->Application->ConfigCacheIds) && $this->Application->ConfigCacheIds != $this->Application->OriginalConfigCacheIds);
+ if ($update) {
+ $query = sprintf("REPLACE %s (PhraseList, CacheDate, Template, ConfigVariables)
+ VALUES (%s, %s, %s, %s)",
+ TABLE_PREFIX.'PhraseCache',
+ $this->Conn->Qstr(join(',', $this->Ids)),
+ adodb_mktime(),
+ $this->Conn->Qstr(md5($this->Application->GetVar('t').$this->Application->GetVar('m_theme').$this->Application->GetVar('m_lang'))),
+ $this->Conn->qstr(implode(',', array_unique($this->Application->ConfigCacheIds))));
+ $this->Conn->Query($query);
+ }
}
-
+
function GetPhrase($label)
{
if (ereg("^!.+!$", $label) > 0)
{
$label = substr($label, 1, -1); //cut exclamation marks
}
-
+
if( strlen($label) == 0 ) return '';
-
+
$original_label = $label;
$label = strtoupper($label);
if( isset($this->Phrases[$label]) )
{
$translated_label = $this->Phrases[$label];
- if($this->Application->isDebugMode() && dbg_ConstOn('DBG_PHRASES_HILIGHT') && !$this->Application->IsAdmin())
+ if(defined('DEBUG_MODE') && DEBUG_MODE && dbg_ConstOn('DBG_PHRASES_HILIGHT') && !$this->Application->IsAdmin())
$translated_label = ''.$translated_label.' '.$original_label.'';
return $translated_label;
}
-
+
$this->LoadPhraseByLabel($label, $original_label);
return $this->GetPhrase($label);
}
-
+
function LoadPhraseByLabel($label, $original_label)
{
$query = sprintf("SELECT PhraseId, Translation FROM %s WHERE LanguageId = %s AND UPPER(Phrase) = UPPER(%s)",
@@ -110,21 +128,21 @@
if( $this->Application->isDebugMode() && dbg_ConstOn('DBG_PHRASES') )
{
list($edit_tpl, $index_file) = $this->Application->IsAdmin() ? Array('regional/phrases_edit', 'index4.php') : Array('phrases_edit', 'index.php');
-
+
$edit_url = $this->Application->HREF($edit_tpl,'',Array('m_opener'=>'d','phrases_label'=>$original_label,'phrases_event'=>'OnNew', 'pass'=>'all,phrases'), $index_file );
$translation = '!'.$label.'!';
if($this->fromTag) $translation = $this->escapeTagReserved($translation);
}
$this->AddCachedPhrase($label, $translation); //add it as already cached, as long as we dont need to cache not found phrase
return false;
}
-
+
$this->Phrases[$label] = $res['Translation'];
array_push($this->Ids, $res['PhraseId']);
$this->Ids = array_unique($this->Ids); //just to make sure
- return true;
+ return true;
}
-
+
/**
* Sort params by name and then by length
*
@@ -140,7 +158,7 @@
if ($a_len == $b_len) return 0;
return $a_len > $b_len ? -1 : 1;
}
-
+
/**
* Replace language tags in exclamation marks found in text
*
@@ -156,7 +174,7 @@
preg_match_all("(!(la|lu)[^!]+!)", $text, $res, PREG_PATTERN_ORDER);
$language_tags = $res[0];
uasort($language_tags, Array(&$this, 'CmpParams') );
-
+
$values = Array();
$i = 0;
foreach ($language_tags as $label) {
@@ -168,7 +186,7 @@
$this->fromTag = false;
return preg_replace($language_tags, $values, $text);
}
-
+
/**
* Escape chars in phrase translation, that could harm parser to process tag
*