Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Tue, Feb 25, 5:22 AM

in-portal

Index: branches/5.2.x/core/kernel/languages/phrases_cache.php
===================================================================
--- branches/5.2.x/core/kernel/languages/phrases_cache.php (revision 15735)
+++ branches/5.2.x/core/kernel/languages/phrases_cache.php (revision 15736)
@@ -1,363 +1,363 @@
<?php
/**
* @version $Id$
* @package In-Portal
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class PhrasesCache extends kBase {
var $Phrases = Array();
var $Ids = Array();
var $OriginalIds = Array(); //for comparing cache
var $LanguageId = null;
/**
* Administrator's language, when visiting site (from frame)
*
* @var int
*/
var $AdminLanguageId = null;
var $fromTag = false;
/**
* Allows to edit existing phrases
*
* @var bool
*/
var $_editExisting = false;
/**
* Allows to edit missing phrases
*
* @var bool
*/
var $_editMissing = false;
/**
* Template, used for phrase adding/editing
*
* @var string
*/
var $_phraseEditTemplate = 'languages/phrase_edit';
/**
* Use simplified form for phrase editing
*
* @var bool
*/
var $_simpleEditingMode = false;
/**
* HTML tag used to translate phrases
*
* @var string
*/
var $_translateHtmlTag = 'a';
/**
* Phrases, that are in cache, but are not in database
*
* @var Array
*/
var $_missingPhrases = Array ();
/**
* Mask for editing link
*
* @var string
*/
var $_editLinkMask = '';
/**
* Escape phrase name, before placing it in javascript translation link
* @var bool
*/
var $_escapePhraseName = true;
/**
* Sets phrase editing mode, that corresponds current editing mode
*
*/
function setPhraseEditing()
{
if (!$this->Application->isAdmin && (EDITING_MODE == EDITING_MODE_CONTENT)) {
// front-end viewed in content mode
$this->_editExisting = true;
$this->_editMissing = true;
$this->_simpleEditingMode = !$this->Application->isDebugMode();
$this->_translateHtmlTag = 'span';
}
$this->_editLinkMask = 'javascript:translate_phrase(\'#LABEL#\', \'' . $this->_phraseEditTemplate . '\', {event: \'OnPreparePhrase\', simple_mode: ' . ($this->_simpleEditingMode ? 'true' : 'false') . '});';
if (defined('DEBUG_MODE') && DEBUG_MODE && !$this->Application->GetVar('admin')) {
// admin and front-end while not viewed using content mode (via admin)
$this->_editMissing = defined('DBG_PHRASES') && DBG_PHRASES;
if (!$this->Application->isAdmin) {
$this->_phraseEditTemplate = 'phrases_edit';
$url_params = Array (
'm_opener' => 'd',
'phrases_label' => '#LABEL#',
'phrases_event' => 'OnPreparePhrase',
'next_template' => urlencode('external:' . $_SERVER['REQUEST_URI']),
'pass' => 'm,phrases'
);
$this->_escapePhraseName = false;
$this->_editLinkMask = $this->Application->HREF($this->_phraseEditTemplate, '', $url_params);
}
}
}
/**
* Loads phrases from current language
* Method is called manually (not from kFactory class) too
*
* @param string $prefix
* @param string $special
* @param int $language_id
* @param Array $phrase_ids
*/
public function Init($prefix, $special = '', $language_id = null, $phrase_ids = null)
{
parent::Init($prefix, $special);
if (kUtil::constOn('IS_INSTALL')) {
$this->LanguageId = 1;
}
else {
if ( !isset($language_id) ) {
if ($this->Application->isAdmin) {
$language_id = $this->Application->Session->GetField('Language');
$this->AdminLanguageId = $language_id; // same languages, when used from Admin Console
}
else {
$language_id = $this->Application->GetVar('m_lang');
}
}
$this->LanguageId = $language_id;
if (!$this->Application->isAdmin && $this->Application->GetVar('admin')) {
$admin_session = $this->Application->recallObject('Session.admin');
/* @var $admin_session Session */
$this->AdminLanguageId = $admin_session->GetField('Language');
}
}
$this->LoadPhrases($phrase_ids);
}
function LoadPhrases($ids)
{
if ( !is_array($ids) || !implode('', $ids) ) {
return ;
}
$sql = 'SELECT l' . $this->LanguageId . '_Translation AS Translation, l' . $this->LanguageId . '_HintTranslation AS HintTranslation, l' . $this->LanguageId . '_ColumnTranslation AS ColumnTranslation, PhraseKey
FROM ' . TABLE_PREFIX . 'LanguageLabels
WHERE PhraseId IN (' . implode(',', $ids) . ') AND l' . $this->LanguageId . '_Translation IS NOT NULL';
$this->Phrases = $this->Conn->Query($sql, 'PhraseKey');
$this->Ids = $this->OriginalIds = $ids;
}
function AddCachedPhrase($label, $value, $allow_editing = true)
{
// uppercase phrase name for cases, when this method is called outside this class
$cache_key = ($allow_editing ? '' : 'NE:') . mb_strtoupper($label);
$this->Phrases[$cache_key] = Array ('Translation' => $value, 'HintTranslation' => $value, 'ColumnTranslation' => $value);
}
function NeedsCacheUpdate()
{
return is_array($this->Ids) && count($this->Ids) > 0 && $this->Ids != $this->OriginalIds;
}
/**
* Returns translation of given label
*
* @param string $label
* @param bool $allow_editing return translation link, when translation is missing on current language
* @param bool $use_admin use current Admin Console language to translate phrase
* @return string
* @access public
*/
public function GetPhrase($label, $allow_editing = true, $use_admin = false)
{
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';
}
// cut exclamation marks - deprecated form of passing phrase name from templates
$label = preg_replace('/^!(.*)!$/', '\\1', $label);
if ( strlen($label) == 0 ) {
return '';
}
$original_label = $this->_escapePhraseName ? addslashes($label) : $label;
$label = mb_strtoupper($label);
if ( substr($label, 0, 5) == 'HINT:' || substr($label, 0, 7) == 'COLUMN:' ) {
// don't just check for ":" since phrases could have ":" in their names (e.g. advanced permission labels)
list ($field_prefix, $label) = explode(':', $label, 2);
$translation_field = mb_convert_case($field_prefix, MB_CASE_TITLE) . 'Translation';
}
else {
$translation_field = 'Translation';
}
$cache_key = ($allow_editing ? '' : 'NE:') . $label;
if ( isset($this->Phrases[$cache_key]) ) {
$translated_label = $this->Phrases[$cache_key][$translation_field];
if ($this->_editExisting && $allow_editing && !array_key_exists($label, $this->_missingPhrases)) {
// option to change translation for Labels
$original_label = explode(':', $original_label, 2);
$edit_url = 'javascript:translate_phrase(\'' . end($original_label) . '\', \'' . $this->_phraseEditTemplate . '\', {event: \'OnPreparePhrase\', simple_mode: ' . ($this->_simpleEditingMode ? 'true' : 'false') . '});';
$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, $allow_editing, $use_admin);
return $this->GetPhrase($original_label, $allow_editing);
}
function LoadPhraseByLabel($label, $original_label, $allow_editing = true, $use_admin = false)
{
if ( !$allow_editing && !$use_admin && !isset($this->_missingPhrases[$label]) && isset($this->Phrases[$label]) ) {
// label is aready translated, but it's version without on the fly translation code is requested
$this->Phrases['NE:' . $label] = $this->Phrases[$label];
return true;
}
$language_id = $use_admin ? $this->AdminLanguageId : $this->LanguageId;
$sql = 'SELECT PhraseId, l' . $language_id . '_Translation AS Translation, l' . $language_id . '_HintTranslation AS HintTranslation, l' . $language_id . '_ColumnTranslation AS ColumnTranslation
FROM ' . TABLE_PREFIX . 'LanguageLabels
WHERE (PhraseKey = ' . $this->Conn->qstr($label) . ') AND (l' . $language_id . '_Translation IS NOT NULL)';
$res = $this->Conn->GetRow($sql);
if ($res === false || count($res) == 0) {
$translation = '!' . $label . '!';
if ($this->_editMissing && $allow_editing) {
$original_label = explode(':', $original_label, 2);
$edit_url = str_replace('#LABEL#', end($original_label), $this->_editLinkMask);
$translation = '<' . $this->_translateHtmlTag . ' href="' . $edit_url . '" name="cms-translate-phrase" title="Translate">!' . $label . '!</' . $this->_translateHtmlTag . '>';
if ($this->fromTag) {
$translation = $this->escapeTagReserved($translation);
}
$this->_missingPhrases[$label] = true; // add as key for faster accessing
}
// add it as already cached, as long as we dont need to cache not found phrase
$this->AddCachedPhrase($label, $translation, $allow_editing);
return false;
}
$cache_key = ($allow_editing ? '' : 'NE:') . $label;
$this->Phrases[$cache_key] = $res;
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|null $force_escaping force escaping, not escaping of resulting string
* @return mixed
* @access public
*/
public function ReplaceLanguageTags($text, $force_escaping = null)
{
$this->fromTag = true;
if( isset($force_escaping) ) {
$this->fromTag = $force_escaping;
}
- preg_match_all("(!(la|lu)[^!]+!)", $text, $res, PREG_PATTERN_ORDER);
+ preg_match_all("(!(la|lu|lc)[^!]+!)", $text, $res, PREG_PATTERN_ORDER);
$language_tags = $res[0];
uasort($language_tags, Array(&$this, 'CmpParams'));
$i = 0;
$values = Array();
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
Index: branches/5.2.x/core/units/permission_types/permission_types_config.php
===================================================================
--- branches/5.2.x/core/units/permission_types/permission_types_config.php (revision 15735)
+++ branches/5.2.x/core/units/permission_types/permission_types_config.php (revision 15736)
@@ -1,107 +1,107 @@
<?php
/**
* @version $Id$
* @package In-Portal
* @copyright Copyright (C) 1997 - 2011 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
$config = Array (
'Prefix' => 'permission-type',
'ItemClass' => Array ('class' => 'kDBItem', 'file' => '', 'build_event' => 'OnItemBuild'),
'ListClass' => Array ('class' => 'kDBList', 'file' => '', 'build_event' => 'OnListBuild'),
'EventHandlerClass' => Array ('class' => 'PermissionTypeEventHandler', 'file' => 'permission_type_eh.php', 'build_event' => 'OnBuild'),
'TagProcessorClass' => Array ('class' => 'kDBTagProcessor', 'file' => '', 'build_event' => 'OnBuild'),
'AutoLoad' => true,
'QueryString' => Array (
1 => 'id',
2 => 'Page',
3 => 'event',
4 => 'mode',
),
'IDField' => 'PermissionConfigId',
'TableName' => TABLE_PREFIX . 'CategoryPermissionsConfig',
'TitleField' => 'PermissionName',
'TitlePresets' => Array (
'default' => Array (
'new_status_labels' => Array ('permission-type' => '!la_title_AddingPermissionType!'),
'edit_status_labels' => Array ('permission-type' => '!la_title_EditingPermissionType!'),
),
'permission_type_list' => Array ('prefixes' => Array ('permission-type_List'), 'format' => "!la_tab_PermissionTypes! (#permission-type_recordcount#)"),
'permission_type_edit' => Array ('prefixes' => Array ('permission-type'), 'format' => "#permission-type_status# '#permission-type_titlefield#'"),
),
'PermSection' => Array('main' => 'in-portal:permission_types'),
'Sections' => Array (
'in-portal:permission_types' => Array(
'parent' => 'in-portal:website_setting_folder',
'icon' => 'permission_types',
'label' => 'la_tab_PermissionTypes',
'url' => Array('t' => 'permission_types/permission_type_list', 'pass' => 'm'),
'permissions' => Array('view', 'add', 'edit', 'delete'),
'priority' => 13,
'type' => stTREE,
),
),
'ListSQLs' => Array (
'' => ' SELECT %1$s.* %2$s FROM %1$s',
),
'ListSortings' => Array (
'' => Array (
'Sorting' => Array ('PermissionName' => 'asc'),
)
),
'Fields' => Array (
'PermissionConfigId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
'PermissionName' => Array (
'type' => 'string', 'max_len' => 30,
'not_null' => 1, 'unique' => Array (), 'required' => 1, 'default' => '',
),
'Description' => Array (
'type' => 'string', 'max_len' => 255,
- 'formatter' => 'kFormatter', 'regexp' => '/^(la|lu)_[A-Z\d:_\-\.]+$/i',
+ 'formatter' => 'kFormatter', 'regexp' => '/^(la|lu|lc)_[A-Z\d:_\-\.]+$/i',
'not_null' => 1, 'required' => 1, 'default' => '',
),
'ModuleId' => Array (
'type' => 'string', 'max_len' => 20,
'formatter' => 'kOptionsFormatter', 'options' => Array ('Admin' => 'Admin', 'Front' => 'Front'), 'options_sql' => 'SELECT Name AS Id, Name FROM ' . TABLE_PREFIX . 'Modules', 'option_key_field' => 'Id', 'option_title_field' => 'Name',
'not_null' => 1, 'required' => 1, 'default' => '',
),
'IsSystem' => Array (
'type' => 'int',
'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Yes', 0 => 'la_No'), 'use_phrases' => 1,
'not_null' => 1, 'default' => 0,
),
),
'Grids' => Array (
'Default' => Array (
'Fields' => Array (
'PermissionConfigId' => Array ('title' => 'column:la_fld_Id', 'data_block' => 'grid_checkbox_td', 'filter_block' => 'grid_range_filter', 'width' => 80),
'PermissionName' => Array ('title' => 'column:la_fld_Name', 'filter_block' => 'grid_like_filter', 'width' => 225),
'Description' => Array ('filter_block' => 'grid_like_filter', 'as_label' => 1, 'width' => 225),
'ModuleId' => Array ('title' => 'column:la_fld_Module', 'filter_block' => 'grid_options_filter'),
'IsSystem' => Array ('filter_block' => 'grid_options_filter'),
),
),
),
);

Event Timeline