Index: branches/5.0.x/core/kernel/languages/phrases_cache.php
===================================================================
diff -u -r12117 -r12298
--- branches/5.0.x/core/kernel/languages/phrases_cache.php (.../phrases_cache.php) (revision 12117)
+++ branches/5.0.x/core/kernel/languages/phrases_cache.php (.../phrases_cache.php) (revision 12298)
@@ -1,6 +1,6 @@
Conn =& $this->Application->GetADODBConnection();
+
+ if (defined('DEBUG_MODE') && DEBUG_MODE && $this->Application->IsAdmin()) {
+ // only has effect in admin, because on front-end phrases are translated in "Content Mode"
+ $this->_editMissing = defined('DBG_PHRASES') && DBG_PHRASES;
+ }
+
+ // now we use admin phrase editing template even on front-end
+ $this->_phraseEditTemplate = 'regional/phrases_edit';
+ $this->_usePopups = $this->Application->ConfigValue('UsePopups');
}
+ /**
+ * Sets phrase editing mode, that corresponds current editing mode
+ *
+ */
+ function setPhraseEditing()
+ {
+ if (!$this->Application->IsAdmin() && (EDITING_MODE == EDITING_MODE_CONTENT)) {
+ $this->_editExisting = true;
+ $this->_editMissing = true;
+ $this->_simpleEditingMode = true;
+ $this->_translateHtmlTag = 'span';
+ }
+ }
+
function Init($prefix, $special = '')
{
if (constOn('IS_INSTALL')) {
@@ -62,11 +127,13 @@
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);
+ $cache_key = md5($this->Application->GetVar('t') . $this->Application->GetVar('m_theme') . $this->Application->GetVar('m_lang'));
+ $sql = 'SELECT PhraseList, ConfigVariables
+ FROM ' . TABLE_PREFIX . 'PhraseCache
+ WHERE Template = ' . $this->Conn->qstr($cache_key);
+ $res = $this->Conn->GetRow($sql);
+
if ($res && $res['ConfigVariables']) {
$this->Application->OriginalConfigCacheIds = explode(',', $res['ConfigVariables']);
$this->Application->ConfigCacheIds = $this->Application->OriginalConfigCacheIds;
@@ -77,16 +144,20 @@
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');
+ if ( !is_array($ids) || !implode('', $ids) ) {
+ return;
+ }
+
+ $sql = 'SELECT Translation, UPPER(Phrase) AS Phrase
+ FROM ' . TABLE_PREFIX . 'Phrase
+ WHERE (LanguageId = ' . $this->LanguageId . ') AND PhraseId IN (' . implode(',', $ids) . ')';
+ $this->Phrases = $this->Conn->GetCol($sql, 'Phrase');
+
/*foreach($phrases as $phrase => $tanslation)
{
$this->AddCachedPhrase(mb_strtoupper($phrase), $tanslation);
}*/
+
$this->Ids = $ids;
$this->OriginalIds = $ids;
}
@@ -125,90 +196,100 @@
}
}
- function GetPhrase($label)
+ function GetPhrase($label, $allow_editing = true)
{
- 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 (!isset($this->LanguageId)) {
+ //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...
+ return 'impossible case';
+ }
- if (ereg("^!.+!$", $label) > 0)
- {
+ if (ereg("^!.+!$", $label) > 0) {
$label = substr($label, 1, -1); //cut exclamation marks
}
- if( strlen($label) == 0 ) return '';
+ if (strlen($label) == 0) {
+ return '';
+ }
$original_label = $label;
$label = mb_strtoupper($label);
- if(isset($this->Phrases[$label])) {
+
+ if (array_key_exists($label, $this->Phrases)) {
$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: '.$label.'; Module: '.$this->Conn->GetOne($sql).'');
-// $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 = ''.$translated_label.' '.$original_label.'';
- }
-
- }
-
- if (defined('DEBUG_MODE') && DEBUG_MODE &&
- (($this->Application->IsAdmin() && constOn('DBG_PHRASES_EDIT_ADMIN')) || (!$this->Application->IsAdmin() && constOn('DBG_PHRASES_EDIT_FRONT')) ) ) {
+ if ($this->_editExisting && $allow_editing) {
// 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')) {
+ if ($this->_usePopups) {
// link to popup when using popups (only in admin)
- $edit_url = 'javascript:translate_phrase(\''.addslashes($translated_label).'\', \''.$edit_tpl.'\');';
+ $edit_url = 'javascript:translate_phrase(\'' . addslashes($original_label) . '\', \'' . $this->_phraseEditTemplate . '\', {event: \'OnPrepareUpdate\', simple_mode: ' . ($this->_simpleEditingMode ? 'true' : 'false') . '});';
}
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 );
+ $url_params = Array(
+ 'm_opener' => 'd',
+ 'phrases_label' => $original_label,
+ 'phrases_event' => 'OnPrepareUpdate',
+ 'simple_mode' => $this->_simpleEditingMode ? 1 : 0,
+ 'pass' => 'all,phrases'
+ );
+
+ $edit_url = $this->Application->HREF($this->_phraseEditTemplate, '', $url_params, 'index.php');
}
- $translated_label = '!'.$translated_label.'!';
+
+ $translated_label = '<' . $this->_translateHtmlTag . ' href="' . $edit_url . '" name="cms-translate-phrase" title="Edit translation">' . $translated_label . '' . $this->_translateHtmlTag . '>';
+
+ if ($this->fromTag) {
+ $translated_label = $this->escapeTagReserved($translated_label);
+ }
}
return $translated_label;
}
- $this->LoadPhraseByLabel($label, $original_label);
+ $this->LoadPhraseByLabel($label, $original_label, $allow_editing);
+
return $this->GetPhrase($label);
}
- function LoadPhraseByLabel($label, $original_label)
+ function LoadPhraseByLabel($label, $original_label, $allow_editing = true)
{
- $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');
+ $sql = 'SELECT PhraseId, Translation
+ FROM ' . TABLE_PREFIX . 'Phrase
+ WHERE (LanguageId = ' . $this->LanguageId . ') AND (UPPER(Phrase) = UPPER(' . $this->Conn->qstr($label) . '))';
+ $res = $this->Conn->GetRow($sql);
- if ($this->Application->IsAdmin() && $this->Application->ConfigValue('UsePopups')) {
+ if ($res === false || count($res) == 0) {
+ $translation = '!' . $label . '!';
+
+ if ($this->_editMissing && $allow_editing) {
+ if ($this->_usePopups) {
// link to popup when using popups (only in admin)
- $edit_url = 'javascript:translate_phrase(\''.addslashes($original_label).'\', \''.$edit_tpl.'\');';
+ $edit_url = 'javascript:translate_phrase(\'' . addslashes($original_label) . '\', \'' . $this->_phraseEditTemplate . '\', {event: \'OnNew\', simple_mode: ' . ($this->_simpleEditingMode ? 'true' : 'false') . '});';
}
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 );
+ $url_params = Array (
+ 'm_opener' => 'd',
+ 'phrases_label' => $original_label,
+ 'phrases_event' => 'OnNew',
+ 'simple_mode' => $this->_simpleEditingMode ? 1 : 0,
+ 'pass' => 'all,phrases'
+ );
+
+ $edit_url = $this->Application->HREF($this->_phraseEditTemplate, '', $url_params, 'index.php');
}
- $translation = '!'.$label.'!';
- if($this->fromTag) $translation = $this->escapeTagReserved($translation);
+ $translation = '<' . $this->_translateHtmlTag . ' href="' . $edit_url . '" class="cms-translate-phrase" title="Translate">!' . $label . '!' . $this->_translateHtmlTag . '>';
+
+ 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
+
+ // add it as already cached, as long as we dont need to cache not found phrase
+ $this->AddCachedPhrase($label, $translation);
+
return false;
}
@@ -259,6 +340,7 @@
$i++;
}
$this->fromTag = false;
+
return preg_replace($language_tags, $values, $text);
}
@@ -276,7 +358,4 @@
return str_replace($reserved,$replacement,$text);
}
-}
-
-
-?>
\ No newline at end of file
+}
\ No newline at end of file