Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Tue, Nov 11, 10:21 PM

in-portal

Index: branches/unlabeled/unlabeled-1.10.2/kernel/units/phrases/phrases_event_handler.php
===================================================================
--- branches/unlabeled/unlabeled-1.10.2/kernel/units/phrases/phrases_event_handler.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.10.2/kernel/units/phrases/phrases_event_handler.php (revision 6094)
@@ -0,0 +1,89 @@
+<?php
+
+ class PhrasesEventHandler extends InpDBEventHandler
+ {
+
+ function CheckPermission(&$event)
+ {
+ if (!$this->Application->IsAdmin() && $event->Name == 'OnCreate' && $this->Application->isDebugMode() && constOn('DBG_PHRASES')) {
+ if ($event->Name == 'OnCreate') {
+ // allow create phrases from front end in debug mode with DBG_PHRASES
+ return true;
+ }
+ }
+ }
+
+ /**
+ * 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);
+ $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).'|' );
+ }
+ }
+
+ /**
+ * 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);
+ }
+
+ $cookie_path = $this->Application->IsAdmin() ? BASE_PATH.'/admin' : BASE_PATH;
+ setcookie('last_module', $object->GetDBField('Module'), $cookie_path, '.'.SERVER_NAME);
+ }
+ }
+
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.10.2/kernel/units/phrases/phrases_event_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.10
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.10.2/core/units/categories/categories_item.php
===================================================================
--- branches/unlabeled/unlabeled-1.10.2/core/units/categories/categories_item.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.10.2/core/units/categories/categories_item.php (revision 6094)
@@ -0,0 +1,179 @@
+<?php
+
+ class CategoriesItem extends kDBItem
+ {
+ function Create($force_id=false, $system_create=false)
+ {
+ if (!$this->Validate()) return false;
+
+ $this->SetDBField('ResourceId', $this->Application->NextResourceId());
+ $this->SetDBField('CreatedById', $this->Application->GetVar('u_id') );
+ $this->SetDBField('CreatedOn_date', adodb_mktime() );
+ $this->SetDBField('CreatedOn_time', adodb_mktime() );
+
+ $this->checkFilename();
+ $this->generateFilename();
+
+ $this->SetDBField('ParentId', $this->Application->GetVar('m_cat_id') );
+ $ret = parent::Create($force_id, $system_create);
+ if ($ret) {
+ $sql = 'UPDATE %s SET ParentPath = %s WHERE CategoryId = %s';
+ $parent_path = $this->buildParentPath();
+ $this->Conn->Query( sprintf($sql, $this->TableName, $this->Conn->qstr($parent_path), $this->GetID() ) );
+
+ $this->SetDBField('ParentPath', $parent_path);
+ }
+ return $ret;
+
+ }
+
+ function Update($id=null, $system_update=false)
+ {
+ $this->checkFilename();
+ $this->generateFilename();
+
+ $ret = parent::Update($id, $system_update);
+ return $ret;
+ }
+
+ function buildParentPath()
+ {
+ $parent_id = $this->GetDBField('ParentId');
+
+ if ($parent_id == 0) {
+ $parent_path = '|';
+ }
+ else {
+ $cat_table = $this->Application->getUnitOption($this->Prefix, 'TableName');
+ $sql = 'SELECT ParentPath FROM '.$cat_table.' WHERE CategoryId = %s';
+ $parent_path = $this->Conn->GetOne( sprintf($sql, $parent_id) );
+ }
+
+ return $parent_path.$this->GetID().'|';
+ }
+
+ /**
+ * replace not allowed symbols with "_" chars + remove duplicate "_" chars in result
+ *
+ * @param string $string
+ * @return string
+ */
+ function stripDisallowed($string)
+ {
+ $not_allowed = Array( ' ', '\\', '/', ':', '*', '?', '"', '<', '>', '|', '`',
+ '~', '!', '@', '#', '$', '%', '^', '&', '(', ')', '~',
+ '+', '=', '-', '{', '}', ']', '[', "'", ';', '.', ',');
+
+ $string = str_replace($not_allowed, '_', $string);
+ $string = preg_replace('/(_+)/', '_', $string);
+ $string = $this->checkAutoFilename($string);
+
+ return $string;
+ }
+
+ function checkFilename()
+ {
+ if( !$this->GetDBField('AutomaticFilename') )
+ {
+ $filename = $this->GetDBField('Filename');
+ $this->SetDBField('Filename', $this->stripDisallowed($filename) );
+ }
+ }
+
+ function checkAutoFilename($filename)
+ {
+ if(!$filename) return $filename;
+
+ $item_id = !$this->GetID() ? 0 : $this->GetID();
+
+ // check temp table
+ $sql_temp = 'SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE Filename = '.$this->Conn->qstr($filename);
+ $found_temp_ids = $this->Conn->GetCol($sql_temp);
+
+ // check live table
+ $sql_live = 'SELECT '.$this->IDField.' FROM '.$this->Application->GetLiveName($this->TableName).' WHERE Filename = '.$this->Conn->qstr($filename);
+ $found_live_ids = $this->Conn->GetCol($sql_live);
+
+ $found_item_ids = array_unique( array_merge($found_temp_ids, $found_live_ids) );
+
+ $has_page = preg_match('/(.*)_([\d]+)([a-z]*)$/', $filename, $rets);
+
+ $duplicates_found = (count($found_item_ids) > 1) || ($found_item_ids && $found_item_ids[0] != $item_id);
+ if ($duplicates_found || $has_page) // other category has same filename as ours OR we have filename, that ends with _number
+ {
+ $append = $duplicates_found ? '_a' : '';
+ if($has_page)
+ {
+ $filename = $rets[1].'_'.$rets[2];
+ $append = $rets[3] ? $rets[3] : '_a';
+ }
+
+ // check live & temp table
+ $sql_temp = 'SELECT '.$this->IDField.' FROM '.$this->TableName.' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$item_id.')';
+ $sql_live = 'SELECT '.$this->IDField.' FROM '.$this->Application->GetLiveName($this->TableName).' WHERE (Filename = %s) AND ('.$this->IDField.' != '.$item_id.')';
+ while ( $this->Conn->GetOne( sprintf($sql_temp, $this->Conn->qstr($filename.$append)) ) > 0 ||
+ $this->Conn->GetOne( sprintf($sql_live, $this->Conn->qstr($filename.$append)) ) > 0 )
+ {
+ if (substr($append, -1) == 'z') $append .= 'a';
+ $append = substr($append, 0, strlen($append) - 1) . chr( ord( substr($append, -1) ) + 1 );
+ }
+
+ return $filename.$append;
+ }
+
+ return $filename;
+ }
+
+ /**
+ * Generate item's filename based on it's title field value
+ *
+ * @return string
+ */
+ function generateFilename()
+ {
+ if ( !$this->GetDBField('AutomaticFilename') && $this->GetDBField('Filename') ) return false;
+
+ $ml_formatter =& $this->Application->recallObject('kMultiLanguage');
+ $name = $this->stripDisallowed( $this->GetDBField( $ml_formatter->LangFieldName('Name', true) ) );
+
+ if ( $name != $this->GetDBField('Filename') ) $this->SetDBField('Filename', $name);
+ }
+
+ /**
+ * Allows to detect if root category being edited
+ *
+ * @param Array $params
+ */
+ function IsRoot()
+ {
+ $category_id = $this->Application->GetVar($this->getPrefixSpecial().'_id');
+ if (is_numeric($category_id) && $category_id == 0) {
+ $sql = 'SELECT '.$this->IDField.'
+ FROM '.$this->TableName.'
+ WHERE '.$this->IDField.' = '.$category_id;
+ if ($this->Conn->GetOne($sql) === false) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Sets correct name to Home category while editing it
+ *
+ * @return bool
+ */
+ function IsNewItem()
+ {
+ if ($this->IsRoot()) {
+ $title_field = $this->Application->getUnitOption($this->Prefix, 'TitleField');
+ $category_name = $this->Application->Phrase( $this->Application->ConfigValue('Root_Name') );
+ $this->SetDBField($title_field, $category_name);
+ return false;
+ }
+ return parent::IsNewItem();
+ }
+ }
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.10.2/core/units/categories/categories_item.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.10
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.10.2/core/units/phrases/phrases_event_handler.php
===================================================================
--- branches/unlabeled/unlabeled-1.10.2/core/units/phrases/phrases_event_handler.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.10.2/core/units/phrases/phrases_event_handler.php (revision 6094)
@@ -0,0 +1,89 @@
+<?php
+
+ class PhrasesEventHandler extends InpDBEventHandler
+ {
+
+ function CheckPermission(&$event)
+ {
+ if (!$this->Application->IsAdmin() && $event->Name == 'OnCreate' && $this->Application->isDebugMode() && constOn('DBG_PHRASES')) {
+ if ($event->Name == 'OnCreate') {
+ // allow create phrases from front end in debug mode with DBG_PHRASES
+ return true;
+ }
+ }
+ }
+
+ /**
+ * 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);
+ $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).'|' );
+ }
+ }
+
+ /**
+ * 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);
+ }
+
+ $cookie_path = $this->Application->IsAdmin() ? BASE_PATH.'/admin' : BASE_PATH;
+ setcookie('last_module', $object->GetDBField('Module'), $cookie_path, '.'.SERVER_NAME);
+ }
+ }
+
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.10.2/core/units/phrases/phrases_event_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.10
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

Event Timeline