Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Wed, Apr 30, 4:50 AM

in-portal

Index: branches/5.0.x/core/units/phrases/phrases_config.php
===================================================================
--- branches/5.0.x/core/units/phrases/phrases_config.php (revision 12613)
+++ branches/5.0.x/core/units/phrases/phrases_config.php (revision 12614)
@@ -1,229 +1,205 @@
<?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.net/license/ for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
$config = Array (
'Prefix' => 'phrases',
'Clones' => Array (
'phrases-single' => Array (
'ForeignKey' => false,
'ParentTableKey' => false,
'ParentPrefix' => false,
'Sections' => Array (
// "Phrases"
'in-portal:phrases' => Array (
'parent' => 'in-portal:site',
'icon' => 'phrases_labels',
'label' => 'la_title_Phrases',
'url' => Array ('t' => 'languages/phrase_list', 'pass' => 'm'),
'permissions' => Array ('view', 'add', 'edit', 'delete'),
// 'perm_prefix' => 'lang',
'priority' => 4,
// 'show_mode' => smSUPER_ADMIN,
'type' => stTREE,
),
),
)
),
'ItemClass' => Array ('class' => 'kDBItem', 'file' => '', 'build_event' => 'OnItemBuild'),
'ListClass' => Array ('class' => 'kDBList', 'file' => '', 'build_event' => 'OnListBuild'),
'EventHandlerClass' => Array ('class' => 'PhrasesEventHandler', 'file' => 'phrases_event_handler.php', 'build_event' => 'OnBuild'),
'TagProcessorClass' => Array ('class' => 'PhraseTagProcessor', 'file' => 'phrase_tp.php', 'build_event' => 'OnBuild'),
'AutoLoad' => true,
- 'Hooks' => Array (
- Array (
- 'Mode' => hBEFORE,
- 'Conditional' => false,
- 'HookToPrefix' => 'phrases',
- 'HookToSpecial' => '',
- 'HookToEvent' => Array('OnCreate'),
- 'DoPrefix' => 'phrases',
- 'DoSpecial' => '',
- 'DoEvent' => 'OnBeforePhraseCreate',
- ),
-
- Array (
- 'Mode' => hAFTER,
- 'Conditional' => false,
- 'HookToPrefix' => 'phrases',
- 'HookToSpecial' => '',
- 'HookToEvent' => Array('OnBeforeItemCreate', 'OnBeforeItemUpdate'),
- 'DoPrefix' => 'phrases',
- 'DoSpecial' => '',
- 'DoEvent' => 'OnSetLastUpdated',
- ),
- ),
-
'QueryString' => Array (
1 => 'id',
2 => 'page',
3 => 'event',
4 => 'label',
5 => 'mode', // labels can be edited directly
),
'IDField' => 'PhraseId',
'TitleField' => 'Phrase',
'TitlePresets' => Array (
'default' => Array (
'new_status_labels' => Array ('phrases' => '!la_title_Adding_Phrase!'),
'edit_status_labels' => Array ('phrases' => '!la_title_Editing_Phrase!'),
),
'phrase_edit' => Array (
'prefixes' => Array ('phrases'), 'format' => '#phrases_status# #phrases_titlefield#',
'toolbar_buttons' => Array ('select', 'cancel', 'reset_edit', 'prev', 'next'),
),
// for separate phrases list
'phrases_list_st' => Array (
'prefixes' => Array ('phrases.st_List'), 'format' => "!la_title_Phrases!",
'toolbar_buttons' => Array ('new_item', 'edit', 'delete', 'view', 'dbl-click'),
),
'phrase_edit_single' => Array (
'prefixes' => Array ('phrases'), 'format' => '#phrases_status# #phrases_titlefield#',
'toolbar_buttons' => Array ('select', 'cancel', 'reset_edit', 'prev', 'next'),
),
),
'FilterMenu' => Array (
'Groups' => Array (
Array ('mode' => 'AND', 'filters' => Array ('show_front', 'show_admin', 'show_both'), 'type' => WHERE_FILTER),
Array ('mode' => 'AND', 'filters' => Array ('translated', 'not_translated'), 'type' => WHERE_FILTER),
),
'Filters' => Array (
'show_front' => Array ('label' =>'la_PhraseType_Front', 'on_sql' => '', 'off_sql' => '%1$s.PhraseType != 0'),
'show_admin' => Array ('label' => 'la_PhraseType_Admin', 'on_sql' => '', 'off_sql' => '%1$s.PhraseType != 1'),
'show_both' => Array ('label' => 'la_PhraseType_Both', 'on_sql' => '', 'off_sql' => '%1$s.PhraseType != 2'),
's1' => Array (),
'translated' => Array ('label' => 'la_PhraseTranslated', 'on_sql' => '', 'off_sql' => '%1$s.Translation = pri.Translation'),
'not_translated' => Array ('label' => 'la_PhraseNotTranslated', 'on_sql' => '', 'off_sql' => '%1$s.Translation != pri.Translation'),
)
),
'TableName' => TABLE_PREFIX . 'Phrase',
'CalculatedFields' => Array (
'' => Array (
'PrimaryTranslation' => 'pri.Translation',
),
'st' => Array (
'PackName' => 'lang.PackName',
),
),
'ListSQLs' => Array(
'' => ' SELECT %1$s.* %2$s
FROM %1$s
LEFT JOIN ' . TABLE_PREFIX . 'Phrase pri ON (%1$s.Phrase = pri.Phrase) AND (pri.LanguageId = 1)',
'st' => 'SELECT %1$s.* %2$s
FROM %1$s
LEFT JOIN ' . TABLE_PREFIX . 'Language lang ON (%1$s.LanguageId = lang.LanguageId)',
),
'ListSortings' => Array (
'' => Array (
'Sorting' => Array ('Phrase' => 'asc'),
)
),
'ForeignKey' => 'LanguageId',
'ParentTableKey' => 'LanguageId',
'ParentPrefix' => 'lang',
'AutoDelete' => true,
'AutoClone' => true,
'Fields' => Array (
'Phrase' => Array (
'type' => 'string',
'required' => 1, 'unique' => Array ('LanguageId'),
'not_null' => 1, 'default' => ''
),
-
+ 'PhraseKey' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => NULL),
'Translation' => Array ('type' => 'string', 'formatter' => 'kFormatter', 'required' => 1, 'not_null' => 1, 'using_fck' => 1, 'default' => ''),
'PhraseType' => Array ('type' => 'int', 'required'=>1,'formatter' => 'kOptionsFormatter', 'options'=>Array (0=>'la_PhraseType_Front',1=>'la_PhraseType_Admin',2=>'la_PhraseType_Both'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 0),
'PhraseId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
'LanguageId' => Array (
'type' => 'int',
'formatter' => 'kOptionsFormatter', 'options_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Language ORDER BY LocalName', 'option_key_field' => 'LanguageId', 'option_title_field' => 'LocalName',
'not_null' => 1, 'default' => 0
),
'LastChanged' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'not_null' => 1, 'default' => 0),
'LastChangeIP' => Array ('type' => 'string', 'not_null' => 1, 'default' => ''),
'Module' => Array (
'type' => 'string',
'formatter' => 'kOptionsFormatter', 'options'=>Array ('' => ''), 'options_sql' => 'SELECT %s FROM '.TABLE_PREFIX.'Modules WHERE Loaded = 1 ORDER BY LoadOrder', 'option_key_field' => 'Name', 'option_title_field' => 'Name',
'not_null' => 1, 'default' => 'In-Portal'
),
),
'VirtualFields' => Array (
'PrimaryTranslation' => Array (),
'LangFile' => Array (),
'ImportOverwrite' => Array ('type' => 'int', 'default' => 0),
'DoNotEncode' => Array (),
'PackName' => Array (
'type' => 'string',
'formatter' => 'kOptionsFormatter',
'options_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Language ORDER BY PackName', 'option_title_field' => 'PackName', 'option_key_field' => 'PackName',
),
),
'Grids' => Array (
'Default' => Array (
'Icons' => Array (
'default' => 'icon16_item.png',
0 => 'icon16_disabled.png',
1 => 'icon16_item.png',
),
'Fields' => Array (
'PhraseId' => Array ('title' => 'la_col_Id', 'data_block' => 'grid_checkbox_td', 'filter_block' => 'grid_range_filter', 'width' => 50),
'Phrase' => Array ('title' => 'la_col_Label', 'data_block' => 'grid_checkbox_td', 'width' => 200),
'Translation' => Array ('title' => 'la_col_Phrase', 'width' => 200),
'PrimaryTranslation' => Array ('title' => 'la_col_PrimaryValue', 'width' => 200),
'PhraseType' => Array ('title' => 'la_col_PhraseType', 'filter_block' => 'grid_options_filter', 'width' => 60),
'LastChanged' => Array ('title' => 'la_col_Modified', 'filter_block' => 'grid_date_range_filter', 'width' => 150),
'Module' => Array ('title' => 'la_col_Module', 'filter_block' => 'grid_options_filter', 'width' => 100),
),
),
'Phrases' => Array (
'Icons' => Array (
'default' => 'icon16_item.png',
0 => 'icon16_disabled.png',
1 => 'icon16_item.png',
),
'Fields' => Array (
'PhraseId' => Array ('title' => 'la_col_Id', 'data_block' => 'grid_checkbox_td', 'filter_block' => 'grid_range_filter', 'width' => 50),
'Phrase' => Array ('title' => 'la_col_Label', 'filter_block' => 'grid_like_filter', 'width' => 170),
'Translation' => Array ('title' => 'la_col_Phrase', 'filter_block' => 'grid_like_filter', 'width' => 180),
'PackName' => Array ('title' => 'la_col_Language', 'filter_block' => 'grid_options_filter', 'width' => 95),
'PhraseType' => Array ('title' => 'la_col_Location', 'filter_block' => 'grid_options_filter', 'width' => 80),
'LastChanged' => Array ('title' => 'la_col_Modified', 'filter_block' => 'grid_date_range_filter', 'width' => 145),
'Module' => Array ('title' => 'la_col_Module', 'filter_block' => 'grid_options_filter', 'width' => 100),
),
),
),
);
\ No newline at end of file
Index: branches/5.0.x/core/units/phrases/phrases_event_handler.php
===================================================================
--- branches/5.0.x/core/units/phrases/phrases_event_handler.php (revision 12613)
+++ branches/5.0.x/core/units/phrases/phrases_event_handler.php (revision 12614)
@@ -1,173 +1,213 @@
<?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.net/license/ for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class PhrasesEventHandler extends kDBEventHandler
{
/**
* Apply some special processing to
* object beeing recalled before using
* it in other events that call prepareObject
*
* @param Object $object
* @param kEvent $event
* @access protected
*/
function prepareObject(&$object, &$event)
{
// don't call parent
}
/**
* 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')) {
$allow_events = Array ('OnCreate', 'OnUpdate');
if (in_array($event->Name, $allow_events)) {
return true;
}
}
return parent::CheckPermission($event);
}
function mapPermissions()
{
parent::mapPermissions();
$permissions = Array (
'OnItemBuild' => Array('self' => true, 'subitem' => true),
'OnNew' => Array('self' => true, 'subitem' => true),
'OnPrepareUpdate' => 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->GetVar('m_lang'));
$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).'|' );
}
}
/**
* Prepares existing phrase editing
*
* @param kEvent $event
*/
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 = '.(int)$language_id;
$this->Application->SetVar($event->getPrefixSpecial() . '_id', $this->Conn->GetOne($sql));
$event->redirect = false;
}
/**
* Forces create to use live table
*
* @param kEvent $event
*/
- function OnBeforePhraseCreate(&$event)
+ function OnCreate(&$event)
{
- $edit_direct = $this->Application->GetVar($event->Prefix.'_label');
- if ($edit_direct) {
+ if ( $this->Application->GetVar($event->Prefix . '_label') ) {
$object =& $event->getObject( Array('skip_autoload' => true) );
+
if ($this->Application->GetVar('m_lang') != $this->Application->GetVar('lang_id')) {
$object->SwitchToLive();
}
}
+
+ parent::OnCreate($event);
+ }
+
+ /**
+ * Set last change info, when phrase is created
+ *
+ * @param kEvent $event
+ */
+ function OnBeforeItemCreate(&$event)
+ {
+ parent::OnBeforeItemCreate($event);
+
+ $this->_setPhraseKey($event);
+ $this->_setLastUpdated($event);
+ }
+
+ /**
+ * Update last change info, when phrase is updated
+ *
+ * @param kEvent $event
+ */
+ function OnBeforeItemUpdate(&$event)
+ {
+ parent::OnBeforeItemUpdate($event);
+
+ $this->_setPhraseKey($event);
+ $this->_setLastUpdated($event);
+ }
+
+ /**
+ * Set's phrase key, used for phrase updating and loading
+ *
+ * @param kEvent $event
+ */
+ function _setPhraseKey(&$event)
+ {
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
+
+ $object->SetDBField('PhraseKey', mb_strtoupper($object->GetDBField('Phrase')));
}
/**
* Save phrase change date & ip translation was made from
*
* @param kEvent $event
*/
- function OnSetLastUpdated(&$event)
+ function _setLastUpdated(&$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');
+ /* @var $object kDBItem */
+
+ if ($object->GetOriginalField('Translation') != $object->GetDBField('Translation')) {
$object->SetDBField('LastChanged_date', adodb_mktime() );
$object->SetDBField('LastChanged_time', adodb_mktime() );
- $object->SetDBField('LastChangeIP', $ip_address);
+ $object->SetDBField('LastChangeIP', $_SERVER['REMOTE_ADDR']);
}
$this->Application->Session->SetCookie('last_module', $object->GetDBField('Module'));
}
/**
* Changes default module to custom (when available)
*
* @param kEvent $event
*/
function OnAfterConfigRead(&$event)
{
parent::OnAfterConfigRead($event);
if ($this->Application->findModule('Name', 'Custom')) {
$fields = $this->Application->getUnitOption($event->Prefix, 'Fields');
$fields['Module']['default'] = 'Custom';
$this->Application->setUnitOption($event->Prefix, 'Fields', $fields);
}
}
}
\ No newline at end of file

Event Timeline