Phrases = Array(); $this->LanguageId = $LanguageId; $this->LoadPhrases( $this->GetCachedIds() ); } function GetCachedIds() { $query = sprintf("SELECT PhraseList FROM %s WHERE Template = %s", 'PhraseCache', $this->Conn->Qstr($this->Application->GetVar('t'))); $phrases_ids = $this->Conn->GetOne($query); if ($phrases_ids === false) return Array(); return explode(',', $phrases_ids); } function LoadPhrases($ids) { if (!is_array($ids) || count($ids) == 0) return; $query = sprintf("SELECT Translation,Phrase FROM %s WHERE LanguageId = %s AND PhraseId IN (%s)", 'Phrase', $this->LanguageId, join(',', $ids)); $phrases = $this->Conn->GetCol($query,'Phrase'); foreach($phrases as $phrase => $tanslation) { $this->AddCachedPhrase(strtoupper($phrase), $tanslation); } $this->Ids = $ids; } function AddCachedPhrase($label, $value) { $label = strtoupper($label); $this->Phrases[$label] = $value; } function UpdateCache() { if (!is_array($this->Ids) || count($Ids) == 0) return; $query = sprintf("REPLACE %s (PhraseList, CacheDate, Template) VALUES (%s, %s, %s)", 'PhraseCache', $this->Conn->Qstr(join(',', $this->Ids)), mktime(), $this->Conn->Qstr($this->Application->GetVar('t'))); $this->Conn->Query($query); } function GetPhrase($label) { $label = strtoupper($label); if (array_key_exists($label, $this->Phrases)) return $this->Phrases[$label]; $this->LoadPhraseByLabel($label); return $this->GetPhrase($label); } function LoadPhraseByLabel($label) { $query = sprintf("SELECT PhraseId, Translation FROM %s WHERE LanguageId = %s AND UPPER(Phrase) = UPPER(%s)", Phrase, $this->LanguageId, $this->Conn->qstr($label)); $res = $this->Conn->GetRow($query); if ($res === false || count($res) == 0) { $this->AddCachedPhrase($label, '!'.$label.'!'); //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; } } ?>