Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F802682
in-portal
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Feb 24, 11:21 PM
Size
14 KB
Mime Type
text/x-diff
Expires
Wed, Feb 26, 11:21 PM (1 d, 19 h)
Engine
blob
Format
Raw Data
Handle
575567
Attached To
rINP In-Portal
in-portal
View Options
Index: branches/RC/core/kernel/languages/phrases_cache.php
===================================================================
--- branches/RC/core/kernel/languages/phrases_cache.php (revision 11429)
+++ branches/RC/core/kernel/languages/phrases_cache.php (revision 11430)
@@ -1,253 +1,270 @@
<?php
class PhrasesCache extends kBase {
/**
* Connection to database
*
* @var kDBConnection
* @access public
*/
var $Conn;
var $Phrases = Array();
var $Ids = Array();
var $OriginalIds = Array(); //for comparing cache
var $LanguageId = null;
var $fromTag = false;
-
+
function PhrasesCache()
{
parent::kBase();
$this->Conn =& $this->Application->GetADODBConnection();
}
function Init($prefix, $special = '')
{
if (constOn('IS_INSTALL')) {
$this->LanguageId = 1;
}
else {
if ($this->Application->IsAdmin()) {
$id_field = $this->Application->getUnitOption('lang', 'IDField');
$table_name = $this->Application->getUnitOption('lang', 'TableName');
$sql = 'SELECT '.$id_field.'
FROM '.$table_name.'
WHERE AdminInterfaceLang = 1';
$this->LanguageId = $this->Conn->GetOne($sql);
}
else {
$this->LanguageId = $this->Application->GetVar('m_lang');
}
}
if (isset($this->Application->Caches['PhraseList'])) {
$this->LoadPhrases( $this->Application->Caches['PhraseList'] );
}
}
function GetCachedIds()
{
$query = sprintf("SELECT PhraseList, ConfigVariables FROM %s WHERE Template = %s",
TABLE_PREFIX.'PhraseCache',
$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,UPPER(Phrase) AS Phrase FROM %s WHERE LanguageId = %s AND PhraseId IN (%s)",
TABLE_PREFIX.'Phrase',
$this->LanguageId,
join(',', $ids));
$this->Phrases = $this->Conn->GetCol($query,'Phrase');
/*foreach($phrases as $phrase => $tanslation)
{
$this->AddCachedPhrase(mb_strtoupper($phrase), $tanslation);
}*/
$this->Ids = $ids;
$this->OriginalIds = $ids;
}
function AddCachedPhrase($label, $value)
{
$label = mb_strtoupper($label);
$this->Phrases[$label] = $value;
}
function NeedsCacheUpdate()
{
return is_array($this->Ids) && count($this->Ids) > 0 && $this->Ids != $this->OriginalIds;
}
/**
* Copy from Application->UpdateCache method
*
* @deprecated
*/
function UpdateCache()
{
$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 (!isset($this->LanguageId)) return 'impossible case';
+ if (!isset($this->LanguageId)) return 'impossible case';
//actually possible when custom field contains references to language labels and its being rebuilt in OnAfterConfigRead
//which is triggered by Sections rebuild, which in turn read all the configs and all of that happens BEFORE seeting the language...
-
+
if (ereg("^!.+!$", $label) > 0)
{
$label = substr($label, 1, -1); //cut exclamation marks
}
if( strlen($label) == 0 ) return '';
$original_label = $label;
$label = mb_strtoupper($label);
if(isset($this->Phrases[$label])) {
$translated_label = $this->Phrases[$label];
// debug mode is checked directly to improve performance
if (defined('DEBUG_MODE') && DEBUG_MODE && constOn('DBG_PHRASES_HIGHLIGHT')) {
if (!$this->Application->isDebugMode()) return $translated_label;
if ($this->Application->IsAdmin()) {
$sql = 'SELECT Module
FROM '.TABLE_PREFIX.'Phrase
WHERE (LanguageId = '.$this->LanguageId.') AND (Phrase = '.$this->Conn->qstr($label).')';
$this->Application->Debugger->appendHTML('Phrase: <b>'.$label.'</b>; Module: <b>'.$this->Conn->GetOne($sql).'</b>');
// $translated_label = $translated_label.' [m: '.$this->Conn->GetOne($sql).'; l: '.$label.']';
}
else {
// highlight text created via translated phrase (used to detect if text on screen is phrase or not)
$translated_label = '<span style="border: 1px solid #999999; background-color: #cccccc; color: #999999; ">'.$translated_label.'</span></a> <span style="color: red; background-color:#ffffcc">'.$original_label.'</span>';
}
}
+
+ if (defined('DEBUG_MODE') && DEBUG_MODE &&
+ (($this->Application->IsAdmin() && constOn('DBG_PHRASES_EDIT_ADMIN')) || (!$this->Application->IsAdmin() && constOn('DBG_PHRASES_EDIT_FRONT')) ) ) {
+ // option to change translation for Labels
+ list($edit_tpl, $index_file) = $this->Application->IsAdmin() ? Array('regional/phrases_edit', 'index.php') : Array('phrases_edit', 'index.php');
+
+ if ($this->Application->IsAdmin() && $this->Application->ConfigValue('UsePopups')) {
+ // link to popup when using popups (only in admin)
+ $edit_url = 'javascript:translate_phrase(\''.addslashes($translated_label).'\', \''.$edit_tpl.'\');';
+ }
+ else {
+ // direct link, when not using popups OR on frontend
+ $edit_url = $this->Application->HREF($edit_tpl,'',Array('m_opener'=>'d','phrases_label'=>$original_label,'phrases_event'=>'OnPrepareUpdate', 'pass'=>'all,phrases'), $index_file );
+ }
+ $translated_label = '<a href="'.$edit_url.'">!'.$translated_label.'!</a>';
+ }
+
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)",
TABLE_PREFIX.'Phrase',
$this->LanguageId,
$this->Conn->qstr($label));
$res = $this->Conn->GetRow($query);
if ($res === false || count($res) == 0)
{
$translation = '!'.$label.'!';
if($this->Application->isDebugMode() && constOn('DBG_PHRASES')) {
list($edit_tpl, $index_file) = $this->Application->IsAdmin() ? Array('regional/phrases_edit', 'index.php') : Array('phrases_edit', 'index.php');
if ($this->Application->IsAdmin() && $this->Application->ConfigValue('UsePopups')) {
// link to popup when using popups (only in admin)
$edit_url = 'javascript:translate_phrase(\''.addslashes($original_label).'\', \''.$edit_tpl.'\');';
}
else {
// direct link, when not using popups OR on frontend
$edit_url = $this->Application->HREF($edit_tpl,'',Array('m_opener'=>'d','phrases_label'=>$original_label,'phrases_event'=>'OnNew', 'pass'=>'all,phrases'), $index_file );
}
$translation = '<a href="'.$edit_url.'">!'.$label.'!</a>';
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;
}
/**
* Sort params by name and then by length
*
* @param string $a
* @param string $b
* @return int
* @access private
*/
function CmpParams($a, $b)
{
$a_len = mb_strlen($a);
$b_len = mb_strlen($b);
if ($a_len == $b_len) return 0;
return $a_len > $b_len ? -1 : 1;
}
/**
* Replace language tags in exclamation marks found in text
*
* @param string $text
* @param bool $force_escape force escaping, not escaping of resulting string
* @return string
* @access public
*/
function ReplaceLanguageTags($text,$forse_escaping=null)
{
$this->fromTag = true;
if( isset($forse_escaping) ) $this->fromTag = $forse_escaping;
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) {
array_push($values, $this->GetPhrase($label) );
//array_push($values, $this->Application->Phrase($label) );
$language_tags[$i] = '/' . $language_tags[$i] . '/';
$i++;
}
$this->fromTag = false;
return preg_replace($language_tags, $values, $text);
}
/**
* Escape chars in phrase translation, that could harm parser to process tag
*
* @param string $text
* @return string
* @access private
*/
function escapeTagReserved($text)
{
$reserved = Array('"',"'"); // =
$replacement = Array('\"',"\'"); // \=
return str_replace($reserved,$replacement,$text);
}
}
?>
\ No newline at end of file
Property changes on: branches/RC/core/kernel/languages/phrases_cache.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.19.2.3
\ No newline at end of property
+1.19.2.4
\ No newline at end of property
Index: branches/RC/core/units/phrases/phrases_event_handler.php
===================================================================
--- branches/RC/core/units/phrases/phrases_event_handler.php (revision 11429)
+++ branches/RC/core/units/phrases/phrases_event_handler.php (revision 11430)
@@ -1,94 +1,126 @@
<?php
class PhrasesEventHandler extends kDBEventHandler
{
/**
* Allow to create phrases from front end in debug mode with DBG_PHRASES constant set
*
* @param kEvent $event
*/
function CheckPermission(&$event)
{
if (!$this->Application->IsAdmin() && $this->Application->isDebugMode() && constOn('DBG_PHRASES')) {
- if ($event->Name == 'OnNew' || $event->Name == 'OnCreate') {
+ if ($event->Name == 'OnNew' || $event->Name == 'OnCreate' || $event->Name == 'OnPrepareUpdate' || $event->Name == 'OnUpdate') {
return true;
}
}
+
+
return parent::CheckPermission($event);
}
+ function mapPermissions()
+ {
+ parent::mapPermissions();
+ $permissions = Array (
+ 'OnItemBuild' => Array('self' => true, 'subitem' => true),
+ );
+
+ $this->permMapping = array_merge($this->permMapping, $permissions);
+ }
+
/**
* Forces new label in case if issued from get link
*
* @param kEvent $event
*/
function OnNew(&$event)
{
parent::OnNew($event);
$label = $this->Application->GetVar('phrases_label');
$object =& $event->getObject( $label ? Array('live_table'=>true, 'skip_autoload' => true) : Array('skip_autoload' => true) );
if ($label) {
$object->SetDBField('Phrase',$label);
// phrase is created in language, used to display phrases
$object->SetDBField('LanguageId', $this->Application->Phrases->LanguageId);
$object->SetDBField('PhraseType',1);
$primary_language = $this->Application->GetDefaultLanguageId();
$live_table = $this->Application->getUnitOption($event->Prefix, 'TableName');
$sql = 'SELECT Translation FROM %s WHERE Phrase = %s';
$primary_value = $this->Conn->GetOne( sprintf($sql, $live_table, $this->Conn->qstr($label) ) );
$object->SetDBField('PrimaryTranslation', $primary_value);
}
$last_module = $this->Application->GetVar('last_module');
if($last_module) $object->SetDBField('Module', $last_module);
if($event->Special == 'export' || $event->Special == 'import')
{
$object->SetDBField('PhraseType', '|0|1|2|');
$modules = $this->Conn->GetCol('SELECT Name FROM '.TABLE_PREFIX.'Modules');
$object->SetDBField('Module', '|'.implode('|', $modules).'|' );
}
}
+ function OnPrepareUpdate(&$event)
+ {
+ $language_id = $this->Application->GetVar('m_lang');
+ $label = $this->Application->GetVar('phrases_label');
+
+ $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName');
+ $label_idfield = $this->Application->getUnitOption($event->Prefix, 'IDField');
+
+ $sql = 'SELECT '.$label_idfield.' FROM '.$table_name.' WHERE Phrase = '.$this->Conn->qstr($label).' AND LanguageId = '.$language_id;
+ $this->Application->SetVar($event->getPrefixSpecial() . '_id', $this->Conn->GetOne($sql));
+// $event->redirect = false;
+ }
+
+ function OnUpdate(&$event)
+ {
+ parent::OnUpdate($event);
+
+// $event->redirect =
+ }
+
/**
* Forces create to use live table
*
* @param kEvent $event
*/
function OnBeforePhraseCreate(&$event)
{
$edit_direct = $this->Application->GetVar($event->Prefix.'_label');
if ($edit_direct) {
$object =& $event->getObject( Array('skip_autoload' => true) );
if ($this->Application->GetVar('m_lang') != $this->Application->GetVar('lang_id')) {
$object->SwitchToLive();
}
}
}
/**
* Save phrase change date & ip translation was made from
*
* @param kEvent $event
*/
function OnSetLastUpdated(&$event)
{
$object =& $event->getObject();
$prev_translation = $this->Conn->GetOne('SELECT Translation FROM '.$object->TableName.' WHERE '.$object->IDField.' = '.(int)$object->GetId() );
if( $prev_translation != $object->GetDBField('Translation') )
{
$ip_address = getenv('HTTP_X_FORWARDED_FOR') ? getenv('HTTP_X_FORWARDED_FOR') : getenv('REMOTE_ADDR');
$object->SetDBField('LastChanged_date', adodb_mktime() );
$object->SetDBField('LastChanged_time', adodb_mktime() );
$object->SetDBField('LastChangeIP', $ip_address);
}
$this->Application->Session->SetCookie('last_module', $object->GetDBField('Module'));
}
}
?>
\ No newline at end of file
Property changes on: branches/RC/core/units/phrases/phrases_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.14.2.1
\ No newline at end of property
+1.14.2.2
\ No newline at end of property
Event Timeline
Log In to Comment