Index: branches/5.2.x/core/units/helpers/list_helper.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/helpers/list_helper.php (.../list_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/list_helper.php (.../list_helper.php) (revision 14628) @@ -88,7 +88,7 @@ if ($config_mapping) { if (!array_key_exists('PerPage', $config_mapping)) { - trigger_error('Incorrect mapping of PerPage key in config for prefix ' . $event->Prefix . '', E_USER_WARNING); + trigger_error('Incorrect mapping of PerPage key in config for prefix ' . $prefix . '', E_USER_WARNING); } $per_page = $this->Application->ConfigValue($config_mapping['PerPage']); Index: branches/5.2.x/core/kernel/session/session_storage.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/kernel/session/session_storage.php (.../session_storage.php) (revision 14585) +++ branches/5.2.x/core/kernel/session/session_storage.php (.../session_storage.php) (revision 14628) @@ -1,7 +1,7 @@ DirectVars); } - function StoreSession($to_database = true) + /** + * Stores session to database + * + * @param bool $to_database + * + * @return void + * @access public + */ + public function StoreSession($to_database = true) { - if (defined('IS_INSTALL') && IS_INSTALL && $to_database && !$this->Application->TableFound($this->TableName)) { - return false; + if ( defined('IS_INSTALL') && IS_INSTALL && $to_database && !$this->Application->TableFound($this->TableName) ) { + return; } $fields_hash = $this->GetSessionDefaults(); - if ($to_database) { + if ( $to_database ) { $this->Conn->doInsert($fields_hash, $this->TableName); } @@ -206,39 +214,48 @@ //return $this->Conn->Query('UPDATE '.$this->TableName.' SET '.$var_name.' = '.$this->Conn->qstr($value).' WHERE '.$this->IDField.' = '.$this->Conn->qstr($this->Session->GetID()) ); } - function SaveData() + /** + * Saves changes in session to database using single REPLACE query + * + * @return void + * @access public + */ + public function SaveData() { - if(!$this->Session->SID) return false; // can't save without sid + if ( !$this->Session->SID ) { + // can't save without sid + return ; + } + $replace = ''; $ses_data = $this->Session->Data->GetParams(); - $replace = ''; - foreach ($ses_data as $key => $value) - { - if ( isset($this->OriginalData[$key]) && $this->OriginalData[$key] == $value) - { + foreach ($ses_data as $key => $value) { + if ( isset($this->OriginalData[$key]) && $this->OriginalData[$key] == $value ) { continue; //skip unchanged session data } - else - { - $replace .= sprintf("(%s, %s, %s),", - $this->Conn->qstr($this->Session->SID), - $this->Conn->qstr($key), - $this->Conn->qstr($value)); + else { + $replace .= sprintf("(%s, %s, %s),", $this->Conn->qstr($this->Session->SID), $this->Conn->qstr($key), $this->Conn->qstr($value)); } } + $replace = rtrim($replace, ','); - if ($replace != '') { - $query = ' REPLACE INTO '.$this->SessionDataTable. ' ('.$this->IDField.', '.$this->DataVarField.', '.$this->DataValueField.') VALUES '.$replace; + + if ( $replace != '' ) { + $query = ' REPLACE INTO ' . $this->SessionDataTable . ' (' . $this->IDField . ', ' . $this->DataVarField . ', ' . $this->DataValueField . ') VALUES ' . $replace; $this->Conn->Query($query); } - if ($this->ChangedDirectVars) { - $changes = array(); + if ( $this->ChangedDirectVars ) { + $changes = Array (); + foreach ($this->ChangedDirectVars as $var) { - $changes[] = $var.' = '.$this->Conn->qstr($this->DirectVars[$var]); + $changes[] = $var . ' = ' . $this->Conn->qstr($this->DirectVars[$var]); } - $query = 'UPDATE '.$this->TableName.' SET '.implode(',', $changes).' WHERE '.$this->IDField.' = '.$this->Conn->qstr($this->Session->GetID()); + + $query = ' UPDATE ' . $this->TableName . ' + SET ' . implode(',', $changes) . ' + WHERE ' . $this->IDField . ' = ' . $this->Conn->qstr($this->Session->GetID()); $this->Conn->Query($query); } } Index: branches/5.2.x/core/units/images/image_event_handler.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/images/image_event_handler.php (.../image_event_handler.php) (revision 14244) +++ branches/5.2.x/core/units/images/image_event_handler.php (.../image_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ GetObject(); - switch ($type) - { - case 'before' : - if ($object->GetDBField('LocalImage')) - { - $object->SetDBField('Url', ''); - } - else - { - $object->SetDBField('LocalPath', ''); - } + $object =& $event->getObject(); + /* @var $object kDBItem */ - if ($object->GetDBField('LocalThumb')) - { - $object->SetDBField('ThumbUrl', ''); + if ( $event->Name == 'OnMassDelete' && $type == 'before' ) { + $ids = $event->getEventParam('ids'); + + $parent_info = $object->getLinkedInfo($event->Special); + + $sql = 'SELECT ImageId + FROM ' . $object->TableName . ' + WHERE DefaultImg = 1 AND ' . $parent_info['ForeignKey'] . ' = ' . $parent_info['ParentId']; + $primary_file_id = $this->Conn->GetOne($sql); + + if ( $primary_file_id ) { + $file_id_index = array_search($primary_file_id, $ids); + + if ( $file_id_index ) { + // allow deleting of primary product file, when there is another file to make primary + $sql = 'SELECT COUNT(*) + FROM ' . $object->TableName . ' + WHERE DefaultImg = 0 AND ' . $parent_info['ForeignKey'] . ' = ' . $parent_info['ParentId']; + $non_primary_file_count = $this->Conn->GetOne($sql); + + if ( $non_primary_file_count ) { + unset($ids[$file_id_index]); + } } - else - { - $object->SetDBField('ThumbPath', ''); - } + } - if ($object->GetDBField('SameImages')) - { + $event->setEventParam('ids', $ids); + } + + switch ( $type ) { + case 'before' : + // empty unused fields + $object->SetDBField($object->GetDBField('LocalImage') ? 'Url' : 'LocalPath', ''); + $object->SetDBField($object->GetDBField('LocalThumb') ? 'ThumbUrl' : 'ThumbPath', ''); + + if ( $object->GetDBField('SameImages') ) { $object->SetDBField('LocalImage', 1); $object->SetDBField('LocalPath', ''); $object->SetDBField('Url', ''); } break; - case 'after' : - if ($object->GetDBField('DefaultImg') ) - { - $sql = 'UPDATE '.$object->TableName.' SET DefaultImg=0 WHERE ResourceId='. - $object->GetDBField('ResourceId').' AND ImageId<>'. - $object->GetId(); - $res = $this->Conn->Query($sql); + + case 'after': + // make sure, that there is only one primary image for the item + if ( $object->GetDBField('DefaultImg') ) { + $sql = 'UPDATE ' . $object->TableName . ' + SET DefaultImg = 0 + WHERE ResourceId = ' . $object->GetDBField('ResourceId') . ' AND ImageId <> ' . $object->GetID(); + $this->Conn->Query($sql); } break; - default: } } - function ImageAction(&$event) + /** + * Performs temp-table related action on current image record + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function ImageAction(&$event) { $id = $event->getEventParam('id'); @@ -194,114 +224,96 @@ return $new_name; } - /** - * Enter description here... + /** + * Sets primary image of user/category/category item * * @param kEvent $event + * @return void + * @access protected */ - function OnSetPrimary(&$event) + protected function OnSetPrimary(&$event) { $object =& $event->getObject(); + /* @var $object kDBItem */ + $object->SetDBField('DefaultImg', 1); $object->Update(); } /** - * Enter description here... + * Occurs before updating item * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemUpdate(&$event) + protected function OnBeforeItemUpdate(&$event) { - $object =& $event->getObject(); -// $parent_info = $object->getLinkedInfo(); - $id = $object->GetDBField('ResourceId'); -// $id = $parent_info['ParentId'] ? $parent_info['ParentId'] : $this->Application->GetVar('p_id'); - $sql = 'SELECT ImageId FROM '.$object->TableName.' WHERE ResourceId='.$id.' AND DefaultImg=1'; - if(!$this->Conn->GetOne($sql)) - { - $object->SetDBField('DefaultImg', 1); - } - if($object->GetDBField('DefaultImg') && $object->Validate()) - { + parent::OnBeforeItemUpdate($event); - $sql = 'UPDATE '.$object->TableName.' - SET DefaultImg = 0 - WHERE ResourceId = '.$id.' AND ImageId <> '.$object->GetDBField('ImageId'); - $this->Conn->Query($sql); - $object->SetDBField('Enabled', 1); - } + $this->processImageStatus($event); } - function OnAfterItemCreate(&$event) + /** + * Occurs after creating item + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnAfterItemCreate(&$event) { - $event->CallSubEvent('OnBeforeItemUpdate'); + parent::OnAfterItemCreate($event); + + $this->processImageStatus($event); + $object =& $event->getObject(); + /* @var $object kDBItem */ + $object->Update(); } /** - * Deletes all selected items. - * Automatically recurse into sub-items using temp handler, and deletes sub-items - * by calling its Delete method if sub-item has AutoDelete set to true in its config file + * Occurs before item changed * * @param kEvent $event */ - function OnMassDelete(&$event) + function processImageStatus(&$event) { - if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { - $event->status = kEvent::erFAIL; - return; - } + $object =& $event->getObject(); + /* @var $object kDBItem */ - $event->status=kEvent::erSUCCESS; + $id = $object->GetDBField('ResourceId'); - $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); + $sql = 'SELECT ImageId + FROM ' . $object->TableName . ' + WHERE ResourceId = ' . $id . ' AND DefaultImg = 1'; + $primary_image_id = $this->Conn->GetOne($sql); - $event->setEventParam('ids', $this->StoreSelectedIDs($event) ); - $this->customProcessing($event, 'before'); - $ids = $event->getEventParam('ids'); - - $object =& $event->getObject(); - $sql = 'SELECT ImageId FROM '.$object->TableName.' WHERE DefaultImg=1'; - $primary = $this->Conn->GetOne($sql); - if( $primary && ($key = array_search($primary, $ids)) ) - { - $sql = 'SELECT ImageId FROM '.$object->TableName.' WHERE DefaultImg=0'; - $res = $this->Conn->Query($sql); - if($res) - { - unset($ids[$key]); - } + if ( !$primary_image_id ) { + $object->SetDBField('DefaultImg', 1); } - if($ids) - { - $temp->DeleteItems($event->Prefix, $event->Special, $ids); + if ( $object->GetDBField('DefaultImg') && $object->Validate() ) { + $sql = 'UPDATE ' . $object->TableName . ' + SET DefaultImg = 0 + WHERE ResourceId = ' . $id . ' AND ImageId <> ' . $object->GetDBField('ImageId'); + $this->Conn->Query($sql); + + $object->SetDBField('Enabled', 1); } - $this->clearSelectedIDs($event); } - /*function OnAfterItemLoad(&$event) + /** + * Apply any custom changes to list's sql query + * + * @param kEvent $event + * @return void + * @access protected + * @see kDBEventHandler::OnListBuild() + */ + protected function SetCustomQuery(&$event) { - $object =& $event->getObject(); - - if ( $object->GetDBField('ThumbPath') || $object->GetDBField('SameImages') ) - { - // return local image or url - $path = $object->GetDBField('LocalThumb') ? PROTOCOL.SERVER_NAME.BASE_PATH.$object->GetDBField('ThumbPath') : $object->GetDBField('ThumbUrl'); - if ( $object->GetDBField('LocalThumb') && !file_exists(FULL_PATH.$object->GetDBField('ThumbPath')) ) $path = ''; - } - else { // if we need full which is not the same as thumb - $path = $object->GetDBField('LocalImage') ? PROTOCOL.SERVER_NAME.BASE_PATH.$object->GetDBField('LocalPath') : $object->GetDBField('Url'); - if ( $object->GetDBField('LocalImage') && !file_exists(FULL_PATH.$object->GetDBField('LocalPath')) ) $path = ''; - } - - $object->SetDBField('ImageUrl', $path); - }*/ - - function SetCustomQuery(&$event) - { parent::SetCustomQuery($event); $object =& $event->getObject(); Index: branches/5.2.x/core/units/helpers/language_import_helper.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/units/helpers/language_import_helper.php (.../language_import_helper.php) (revision 14585) +++ branches/5.2.x/core/units/helpers/language_import_helper.php (.../language_import_helper.php) (revision 14628) @@ -1,6 +1,6 @@ Application->getUnitOption($prefix, 'IDField'); + $id_field = $this->Application->getUnitOption($prefix, 'IDField'); $table = $this->Application->getUnitOption($prefix,'TableName'); $temp_table = $this->Application->GetTempName($table); @@ -633,7 +637,7 @@ $this->Conn->Query($sql); $sql = 'ALTER TABLE %1$s CHANGE %2$s %2$s INT(11) NOT NULL DEFAULT "0"'; - $this->Conn->Query( sprintf($sql, $temp_table, $idfield) ); + $this->Conn->Query( sprintf($sql, $temp_table, $id_field) ); switch ($prefix) { case 'phrases': Index: branches/5.2.x/core/units/user_profile/user_profile_tp.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/user_profile/user_profile_tp.php (.../user_profile_tp.php) (revision 14244) +++ branches/5.2.x/core/units/user_profile/user_profile_tp.php (.../user_profile_tp.php) (revision 14628) @@ -1,6 +1,6 @@ Application->GetVar($params['counter']); + $counter = (int)$this->Application->GetVar( $params['counter'] ); - return $counter < $this->ProfileFieldCount(); + return $counter < $this->ProfileFieldCount($params); } /** - * Because of persistant session table doesn't have ids, we use user id as id for each record + * Because of persistent session table doesn't have ids, we use user id as id for each record * * @param Array $params * @return Array (id,field) Index: branches/5.2.x/core/units/skins/skin_eh.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/skins/skin_eh.php (.../skin_eh.php) (revision 14244) +++ branches/5.2.x/core/units/skins/skin_eh.php (.../skin_eh.php) (revision 14628) @@ -1,6 +1,6 @@ getObject( Array('skip_autoload' => true) ); + $object =& $event->getObject( Array ('skip_autoload' => true) ); + /* @var $object kDBItem */ + $object->SwitchToLive(); $ids = $event->MasterEvent->getEventParam('ids'); - if (!is_array($ids)) { - $ids = explode(',', $ids); + if ( !is_array($ids) ) { + $ids = explode(',', $ids); } - if (!$ids) { - return false; + if ( !$ids ) { + return ; } $skin_helper =& $this->Application->recallObject('SkinHelper'); /* @var $skin_helper SkinHelper */ - foreach($ids as $id) { + foreach ($ids as $id) { $object->Load($id); $skin_helper->compile($object); } } - } \ No newline at end of file Index: branches/5.2.x/core/units/files/file_eh.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/files/file_eh.php (.../file_eh.php) (revision 14244) +++ branches/5.2.x/core/units/files/file_eh.php (.../file_eh.php) (revision 14628) @@ -1,6 +1,6 @@ getObject(); + /* @var $object kDBItem */ + $object->SetDBField('CreatedById', $this->Application->RecallVar('user_id')); } /** * Resets primary file mark when more then one file is marked as primary * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemUpdate(&$event) + protected function OnBeforeItemUpdate(&$event) { + parent::OnBeforeItemUpdate($event); + $object =& $event->getObject(); + /* @var $object kDBItem */ - if (!$object->GetDBField('FileName')) { + if ( !$object->GetDBField('FileName') ) { $object->SetDBField('FileName', basename($object->GetDBField('FilePath'))); } } - function SetCustomQuery(&$event) + /** + * Apply any custom changes to list's sql query + * + * @param kEvent $event + * @return void + * @access protected + * @see kDBEventHandler::OnListBuild() + */ + protected function SetCustomQuery(&$event) { parent::SetCustomQuery($event); $object =& $event->getObject(); - + /* @var $object kDBList */ + if (!$this->Application->isAdminUser) { $object->addFilter('active_filter', '%1$s.Status = '.STATUS_ACTIVE); } Index: branches/5.2.x/core/units/helpers/custom_fields_helper.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/helpers/custom_fields_helper.php (.../custom_fields_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/custom_fields_helper.php (.../custom_fields_helper.php) (revision 14628) @@ -1,6 +1,6 @@ ', '%3$s'), Array (TABLE_PREFIX, $this->Application->GetVar('m_lang')), $valueString) ); Index: branches/5.2.x/core/units/helpers/modules_helper.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/helpers/modules_helper.php (.../modules_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/modules_helper.php (.../modules_helper.php) (revision 14628) @@ -1,6 +1,6 @@ Application->recallObject('Session'); + /* @var $session Session */ + return $session->CookiesEnabled; } @@ -196,27 +198,30 @@ /** * Get all modules, that don't require licensing * + * @param Array $vars * @return Array + * @access protected */ - function _getFreeModules($vars) + protected function _getFreeModules($vars) { $skip_modules = Array ('.', '..'); $domain = $this->_GetDomain($vars); - if (!$this->_IsLocalSite($domain)) { - array_push($skip_modules, 'in-commerce', 'in-auction'); - } + if ( !$this->_IsLocalSite($domain) ) { + array_push($skip_modules, 'in-commerce', 'in-auction'); + } $ret = Array (); - $folder = dir(MODULES_PATH); + $folder = dir(MODULES_PATH); - if ($folder === false) { - return Array (); - } + if ( $folder === false ) { + return Array (); + } - while (($entry = $folder->read()) !== false) { + while ( ($entry = $folder->read()) !== false ) { $entry_lowercased = strtolower($entry); - if (!is_dir($folder->path . '/' . $entry) || in_array($entry_lowercased, $skip_modules)) { + + if ( !is_dir($folder->path . '/' . $entry) || in_array($entry_lowercased, $skip_modules) ) { continue; } Index: branches/5.2.x/core/units/images/image_tag_processor.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/units/images/image_tag_processor.php (.../image_tag_processor.php) (revision 14585) +++ branches/5.2.x/core/units/images/image_tag_processor.php (.../image_tag_processor.php) (revision 14628) @@ -1,6 +1,6 @@ ImageSrc($block_params); - if (!$image_url) { + if ( !$image_url ) { return ; } $parent_prefix = $this->Application->getUnitOption($object->Prefix, 'ParentPrefix'); + $parent_item =& $this->Application->recallObject($parent_prefix); + /* @var $parent_item kDBItem */ $block_params['img_path'] = $image_url; $image_dimensions = $this->ImageSize($block_params); - $block_params['img_size'] = $image_dimensions ? $image_dimensions : ' width="'.$block_params['DefaultWidth'].'"'; - $block_params['alt'] = $object->GetField('AltName')? $object->GetField('AltName') : htmlspecialchars($this->getItemTitle($parent_item)); + $block_params['img_size'] = $image_dimensions ? $image_dimensions : ' width="' . $block_params['DefaultWidth'] . '"'; + $block_params['alt'] = $object->GetField('AltName') ? $object->GetField('AltName') : htmlspecialchars($this->getItemTitle($parent_item)); $block_params['align'] = array_key_exists('align', $block_params) ? $block_params['align'] : 'left'; } @@ -45,10 +49,12 @@ * * @param kDBItem $object * @return string + * @access protected */ - function getItemTitle(&$object) + protected function getItemTitle(&$object) { $title_field = $this->Application->getUnitOption($object->Prefix, 'TitleField'); + return $object->GetField($title_field); } @@ -425,31 +431,34 @@ * * @param Array $params * @return string + * @access protected */ - function Image($params) + protected function Image($params) { $image_url = $this->ImageSrc($params); - if (!$image_url) { - return ; + + if ( !$image_url ) { + return ''; } $object =& $this->getObject($params); + /* @var $object kDBItem */ + $params['img_path'] = $image_url; $image_dimensions = $this->ImageSize($params); - $params['img_size'] = $image_dimensions ? $image_dimensions : ' width="'.$params['DefaultWidth'].'"'; + $params['img_size'] = $image_dimensions ? $image_dimensions : ' width="' . $params['DefaultWidth'] . '"'; $params['alt'] = htmlspecialchars($object->GetField('AltName')); // really used ? $params['name'] = $this->SelectParam($params, 'block,render_as'); $params['align'] = array_key_exists('align', $params) ? $params['align'] : 'left'; $params['no_editing'] = 1; - if (!$object->isLoaded() && !$this->SelectParam($params, 'default_image,DefaultImage')) { - return false; + if ( !$object->isLoaded() && !$this->SelectParam($params, 'default_image,DefaultImage') ) { + return ''; } return $this->Application->ParseBlock($params); } - /** * Returns url for image in case when image source is url (for admin) * Index: branches/5.2.x/core/units/helpers/mailing_list_helper.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/helpers/mailing_list_helper.php (.../mailing_list_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/mailing_list_helper.php (.../mailing_list_helper.php) (revision 14628) @@ -1,6 +1,6 @@ 0) { + $email_address = $name = ''; + + if ( $mailing_data['PortalUserId'] > 0 ) { $sender =& $this->Application->recallObject('u.-item', null, Array ('skip_autoload' => true)); /* @var $sender UsersItem */ $sender->Load($mailing_data['PortalUserId']); $email_address = $sender->GetDBField('Email'); - $name = trim( $sender->GetDBField('FirstName') . ' ' . $sender->GetDBField('LastName') ); + $name = trim($sender->GetDBField('FirstName') . ' ' . $sender->GetDBField('LastName')); $is_root = false; } - if ($is_root || !$email_address) { + if ( $is_root || !$email_address ) { $email_address = $this->Application->ConfigValue('Smtp_AdminMailFrom'); } - if ($is_root || !$name) { - $name = strip_tags( $this->Application->ConfigValue('Site_Name') ); + if ( $is_root || !$name ) { + $name = strip_tags($this->Application->ConfigValue('Site_Name')); } return Array ($name, $email_address); @@ -149,7 +153,7 @@ } if ($recipient_type != 'u' && $recipient_type != 'g') { - // theese are already emails + // these are already emails return $recipient_ids; } @@ -166,6 +170,10 @@ LEFT JOIN ' . TABLE_PREFIX . 'PortalUser u ON u.PortalUserId = ug.PortalUserId WHERE (ug.GroupId IN (' . implode(',', $recipient_ids) . ')) AND (u.Email <> "")'; break; + + default: + $sql = ''; + break; } return $this->Conn->GetCol($sql); Index: branches/5.2.x/core/kernel/nparser/template_cache.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/kernel/nparser/template_cache.php (.../template_cache.php) (revision 14244) +++ branches/5.2.x/core/kernel/nparser/template_cache.php (.../template_cache.php) (revision 14628) @@ -1,6 +1,6 @@ getObject(); $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); + /* @var $ml_formatter kMultiLanguage */ + $object->addCalculatedField('CategoryName', 'c.'.$ml_formatter->LangFieldName('CachedNavbar')); } @@ -55,8 +59,11 @@ * Apply custom processing to item * * @param kEvent $event + * @param string $type + * @return void + * @access protected */ - function customProcessing(&$event, $type) + protected function customProcessing(&$event, $type) { if($event->Name == 'OnMassDelete') { @@ -108,29 +115,36 @@ * In case if item is deleted from it's last category, then delete item too. * * @param kEvent $event + * @return void + * @access protected */ - function OnDeleteFromCategory(&$event) + protected function OnDeleteFromCategory(&$event) { $category_ids = $event->getEventParam('category_ids'); - if(!$category_ids) return false; + if ( !$category_ids ) { + return ; + } + $item_prefix = $event->getEventParam('item_prefix'); - $item =& $this->Application->recallObject($item_prefix.'.-item', null, Array('skip_autoload' => true)); + $item =& $this->Application->recallObject($item_prefix . '.-item', null, Array ('skip_autoload' => true)); + /* @var $item kCatDBItem */ $ci_table = $this->Application->getUnitOption($event->Prefix, 'TableName'); $item_table = $this->Application->getUnitOption($item_prefix, 'TableName'); - $sql = 'SELECT ItemResourceId, CategoryId FROM %1$s INNER JOIN %2$s ON (%1$s.ResourceId = %2$s.ItemResourceId) WHERE CategoryId IN (%3$s)'; - $category_items = $this->Conn->Query( sprintf($sql, $item_table, $ci_table, implode(',', $category_ids) ) ); + $sql = 'SELECT ItemResourceId, CategoryId + FROM %1$s + INNER JOIN %2$s ON (%1$s.ResourceId = %2$s.ItemResourceId) + WHERE CategoryId IN (%3$s)'; + $category_items = $this->Conn->Query( sprintf($sql, $item_table, $ci_table, implode(',', $category_ids)) ); - $item_hash = Array(); - foreach($category_items as $ci_row) - { + $item_hash = Array (); + foreach ($category_items as $ci_row) { $item_hash[ $ci_row['ItemResourceId'] ][] = $ci_row['CategoryId']; } - foreach($item_hash as $item_resource_id => $delete_category_ids) - { + foreach ($item_hash as $item_resource_id => $delete_category_ids) { $item->Load($item_resource_id, 'ResourceId'); $item->DeleteFromCategories($delete_category_ids); } Index: branches/5.2.x/core/kernel/utility/formatters/password_formatter.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/kernel/utility/formatters/password_formatter.php (.../password_formatter.php) (revision 14244) +++ branches/5.2.x/core/kernel/utility/formatters/password_formatter.php (.../password_formatter.php) (revision 14628) @@ -1,6 +1,6 @@ GetFieldOptions($field_name); $flip_count = 0; $fields_set = true; + $password_field = $verify_field = ''; $fields = Array ('master_field', 'verify_field'); - + // 1. collect values from both Password and VerifyPassword fields while ($flip_count < 2) { if ( getArrayValue($options, $fields[0]) ) { Index: branches/5.2.x/core/units/statistics/statistics_event_handler.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/statistics/statistics_event_handler.php (.../statistics_event_handler.php) (revision 14244) +++ branches/5.2.x/core/units/statistics/statistics_event_handler.php (.../statistics_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ getObject(); + /* @var $object kDBList */ if ($event->Special == 'summary') { $object->addFilter('summary_filter', '%1$s.AdminSummary = 1'); Index: branches/5.2.x/core/kernel/utility/formatters/options_formatter.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/kernel/utility/formatters/options_formatter.php (.../options_formatter.php) (revision 14244) +++ branches/5.2.x/core/kernel/utility/formatters/options_formatter.php (.../options_formatter.php) (revision 14628) @@ -1,6 +1,6 @@ GetFieldOptions($field_name); $use_phrases = getArrayValue($options, 'use_phrases'); - $found = false; foreach ($options['options'] as $option_key => $option_value) { - if ($use_phrases) { + if ( $use_phrases ) { $option_value = $this->Application->Phrase($option_value); } - if ($option_value == $value) { + if ( $option_value == $value ) { $found = true; break; } Index: branches/5.2.x/core/units/helpers/controls/edit_picker_helper.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/helpers/controls/edit_picker_helper.php (.../edit_picker_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/controls/edit_picker_helper.php (.../edit_picker_helper.php) (revision 14628) @@ -1,6 +1,6 @@ GetFieldOptions($store_field); - $constrain = array_key_exists('option_constrain', $field_options) ? $field_options['option_constrain'] : false; + $constrain = array_key_exists('option_constrain', $field_options) ? $field_options['option_constrain'] + : false; - if ($mode == 'filter') { + if ( $mode == 'filter' ) { // filter on edit form return $constrain; } - elseif ($constrain) { + elseif ( $constrain ) { // load or save return sprintf($field_options['options_sql'], $field_options['option_key_field']); } Index: branches/5.2.x/core/units/helpers/themes_helper.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/helpers/themes_helper.php (.../themes_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/themes_helper.php (.../themes_helper.php) (revision 14628) @@ -1,6 +1,6 @@ Application->ModuleInfo; } else { @@ -162,13 +163,13 @@ /* @var $language_import_helper LanguageImportHelper */ foreach ($modules as $module_name => $module_info) { - if ($module_name == 'In-Portal') { + if ( $module_name == 'In-Portal' ) { continue; } $lang_file = $theme_path . '/' . $module_info['TemplatePath'] . '_install/english.lang'; - if (file_exists($lang_file)) { + if ( file_exists($lang_file) ) { $language_import_helper->performImport($lang_file, '|0|', '', LANG_SKIP_EXISTING); } } @@ -179,26 +180,28 @@ * * @param int $theme_id * @param string $theme_path + * @return Array + * @access protected */ - function getTemplateAliases($theme_id, $theme_path) + protected function getTemplateAliases($theme_id, $theme_path) { $template_aliases = Array (); $xml_parser =& $this->Application->recallObject('kXMLHelper'); /* @var $xml_parser kXMLHelper */ foreach ($this->Application->ModuleInfo as $module_name => $module_info) { - if ($module_name == 'In-Portal') { + if ( $module_name == 'In-Portal' ) { continue; } $xml_file = $theme_path . '/' . $module_info['TemplatePath'] . '_install/theme.xml'; - if (file_exists($xml_file)) { + if ( file_exists($xml_file) ) { $xml_data = file_get_contents($xml_file); $root_node =& $xml_parser->Parse($xml_data); - if (!is_object($root_node) || !is_a($root_node, 'kXMLNode') || !$root_node->Children) { + if ( !is_object($root_node) || !is_a($root_node, 'kXMLNode') || !$root_node->Children ) { // broken xml OR no aliases defined continue; } @@ -207,22 +210,20 @@ do { $template_path = trim($current_node->Data); - $alias = '#' . $module_info['TemplatePath'] . strtolower($current_node->Name). '#'; + $alias = '#' . $module_info['TemplatePath'] . strtolower($current_node->Name) . '#'; // remember alias in global theme mapping $template_aliases[$alias] = $template_path; // store alias in theme file record to use later in design dropdown - $t_parts = Array ( - 'path' => dirname($template_path) == '.' ? '' : '/' . dirname($template_path), - 'file' => basename($template_path), - ); + $t_parts = Array ('path' => dirname($template_path) == '.' ? '' + : '/' . dirname($template_path), 'file' => basename($template_path),); $sql = 'UPDATE ' . TABLE_PREFIX . 'ThemeFiles SET TemplateAlias = ' . $this->Conn->qstr($alias) . ' WHERE (ThemeId = ' . $theme_id . ') AND (FilePath = ' . $this->Conn->qstr($t_parts['path']) . ') AND (FileName = ' . $this->Conn->qstr($t_parts['file'] . '.tpl') . ')'; $this->Conn->Query($sql); - } while (($current_node =& $current_node->NextSibling())); + } while ( ($current_node =& $current_node->NextSibling()) ); } } Index: branches/5.2.x/core/units/statistics/statistics_tag_processor.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/statistics/statistics_tag_processor.php (.../statistics_tag_processor.php) (revision 14244) +++ branches/5.2.x/core/units/statistics/statistics_tag_processor.php (.../statistics_tag_processor.php) (revision 14628) @@ -1,6 +1,6 @@ Application->recallObject('lang.current'); + /* @var $lang LanguagesItem */ + $value = $lang->formatNumber($value, $this->PostFormattingParams['precision']); break; @@ -102,6 +104,7 @@ } $object =& $this->getObject(); + /* @var $object kDBItem */ list($tag_name, $tag_params) = explode(' ', $tag, 2); // 1st - function, 2nd .. nth - params preg_match_all('/([\${}a-zA-Z0-9_.-]+)=(["\']{1,1})(.*?)(?" type="" precision="2" $lang =& $this->Application->recallObject('lang.current'); + /* @var $lang LanguagesItem */ + switch ($tag_params['type']) { case 'date': $this->PostFormatting = $lang->GetDBField('DateFormat'); Index: branches/5.2.x/core/units/category_items/category_items_tag_processor.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/category_items/category_items_tag_processor.php (.../category_items_tag_processor.php) (revision 14244) +++ branches/5.2.x/core/units/category_items/category_items_tag_processor.php (.../category_items_tag_processor.php) (revision 14628) @@ -1,6 +1,6 @@ Application->recallObject( $this->getPrefixSpecial() ); + $object =& $this->getObject(); $table_info = $object->getLinkedInfo(); + return $table_info['ParentId']; } } \ No newline at end of file Index: branches/5.2.x/core/units/agents/agent_eh.php =================================================================== diff -u -r14588 -r14628 --- branches/5.2.x/core/units/agents/agent_eh.php (.../agent_eh.php) (revision 14588) +++ branches/5.2.x/core/units/agents/agent_eh.php (.../agent_eh.php) (revision 14628) @@ -1,6 +1,6 @@ Name == 'OnMassDelete' && $type == 'before') { if ($this->Application->isDebugMode()) { Index: branches/5.2.x/core/units/favorites/favorites_eh.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/favorites/favorites_eh.php (.../favorites_eh.php) (revision 14244) +++ branches/5.2.x/core/units/favorites/favorites_eh.php (.../favorites_eh.php) (revision 14628) @@ -1,6 +1,6 @@ getObject(); /* @var $object kDBItem */ Index: branches/5.2.x/core/units/theme_files/theme_file_eh.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/theme_files/theme_file_eh.php (.../theme_file_eh.php) (revision 14244) +++ branches/5.2.x/core/units/theme_files/theme_file_eh.php (.../theme_file_eh.php) (revision 14628) @@ -1,6 +1,6 @@ Name == 'OnLoadBlock' || $event->Name == 'OnSaveBlock') { return $this->Application->isAdminUser; @@ -51,8 +53,10 @@ * Loads template contents into virtual field * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterItemLoad(&$event) + protected function OnAfterItemLoad(&$event) { parent::OnAfterItemLoad($event); @@ -61,7 +65,7 @@ $filename = $this->_getTemplatePath($object); - if (file_exists($filename)) { + if ( file_exists($filename) ) { $object->SetDBField('FileContents', file_get_contents($filename)); } else { @@ -73,8 +77,10 @@ * Trim contents of edited template * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemUpdate(&$event) + protected function OnBeforeItemUpdate(&$event) { parent::OnBeforeItemUpdate($event); Index: branches/5.2.x/core/units/helpers/menu_helper.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/units/helpers/menu_helper.php (.../menu_helper.php) (revision 14585) +++ branches/5.2.x/core/units/helpers/menu_helper.php (.../menu_helper.php) (revision 14628) @@ -1,6 +1,6 @@ _prepareMenu(); $cat = $this->_getCategoryId($params); @@ -52,7 +55,7 @@ if (array_key_exists('level', $params) && $params['level'] > count($levels)) { // current level is deeper, then requested level - return ; + return ''; } $level = max(array_key_exists('level', $params) ? $params['level'] - 1 : count($levels) - 1, 0); Index: branches/5.2.x/core/units/helpers/category_helper.php =================================================================== diff -u -r14560 -r14628 --- branches/5.2.x/core/units/helpers/category_helper.php (.../category_helper.php) (revision 14560) +++ branches/5.2.x/core/units/helpers/category_helper.php (.../category_helper.php) (revision 14628) @@ -1,6 +1,6 @@ Application->getCache($cache_key); - if ($cached_path === false) { + if ( $cached_path === false ) { $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); + /* @var $ml_formatter kMultiLanguage */ + $navbar_field = $ml_formatter->LangFieldName('CachedNavBar'); $id_field = $this->Application->getUnitOption('c', 'IDField'); $table_name = $this->Application->getUnitOption('c', 'TableName'); $this->Conn->nextQueryCachable = true; - $sql = 'SELECT '.$navbar_field.', ParentPath - FROM '.$table_name.' - WHERE '.$id_field.' = '.$main_category_id; + $sql = 'SELECT ' . $navbar_field . ', ParentPath + FROM ' . $table_name . ' + WHERE ' . $id_field . ' = ' . $main_category_id; $category_data = $this->Conn->GetRow($sql); $cached_path = Array (); $skip_category = $this->Application->getBaseCategory(); - if ($category_data) { + if ( $category_data ) { $category_names = explode('&|&', $category_data[$navbar_field]); $category_ids = explode('|', substr($category_data['ParentPath'], 1, -1)); foreach ($category_ids as $category_index => $category_id) { - if ($category_id == $skip_category) { + if ( $category_id == $skip_category ) { continue; } @@ -326,26 +328,31 @@ return $cached_path; } - /** - * Not tag, method for parameter - * selection from list in this TagProcessor + /** + * Not tag. Method for parameter selection from list in this TagProcessor * * @param Array $params - * @param string $possible_names + * @param Array $possible_names + * * @return string - * @access public + * @access protected */ - function SelectParam($params, $possible_names) + protected function SelectParam($params, $possible_names) { - if (!is_array($params)) return; - if (!is_array($possible_names)) + if ( !is_array($params) ) { + return ''; + } + if ( !is_array($possible_names) ) { + $possible_names = explode(',', $possible_names); + } - $possible_names = explode(',', $possible_names); - foreach ($possible_names as $name) - { - if( isset($params[$name]) ) return $params[$name]; + foreach ($possible_names as $name) { + if ( isset($params[$name]) ) { + return $params[$name]; + } } - return false; + + return ''; } /** Index: branches/5.2.x/core/install/install_toolkit.php =================================================================== diff -u -r14428 -r14628 --- branches/5.2.x/core/install/install_toolkit.php (.../install_toolkit.php) (revision 14428) +++ branches/5.2.x/core/install/install_toolkit.php (.../install_toolkit.php) (revision 14628) @@ -1,6 +1,6 @@ setToolkit($this); } @@ -702,8 +705,9 @@ { static $fields = null; - if (!isset($fields)) { + if ( !isset($fields) ) { $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); + /* @var $ml_formatter kMultiLanguage */ $fields['name'] = $ml_formatter->LangFieldName('Name'); $fields['description'] = $ml_formatter->LangFieldName('Description'); @@ -722,12 +726,12 @@ $category_fields['ParentId'] = $this->Application->getBaseCategory(); - if (isset($category_template)) { + if ( isset($category_template) ) { $category_fields['Template'] = $category_template; $category_fields['CachedTemplate'] = $category_template; } - if (isset($category_icon)) { + if ( isset($category_icon) ) { $category_fields['UseMenuIconUrl'] = 1; $category_fields['MenuIconUrl'] = $category_icon; } @@ -784,7 +788,7 @@ $module_folder = strtolower($module_folder); $module_name = $module_folder; - if ($module_folder == 'kernel') { + if ( $module_folder == 'kernel' ) { $module_name = 'in-portal'; $module_folder = 'core'; } @@ -810,6 +814,8 @@ // create correct columns in CustomData table $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); + /* @var $ml_helper kMultiLanguageHelper */ + $ml_helper->createFields($prefix . '-cdata', true); } @@ -918,7 +924,7 @@ * Upgrades primary skin to the latest version * * @param Array $module_info - * @return string + * @return string|bool */ function upgradeSkin($module_info) { @@ -933,7 +939,7 @@ foreach ($matches as $index => $match) { $version_int = $this->ConvertModuleVersion($match[2][0]); - if ($version_int < $from_version_int) { + if ( $version_int < $from_version_int ) { // only process versions, that were released after currently used version continue; } @@ -949,7 +955,7 @@ ); } - if (!$versions) { + if ( !$versions ) { // not skin changes -> quit return true; } @@ -959,9 +965,9 @@ $primary_skin->Load(1, 'IsPrimary'); - if (!$primary_skin->isLoaded()) { + if ( !$primary_skin->isLoaded() ) { // we always got primary skin, but just in case - return ; + return false; } $temp_handler =& $this->Application->recallObject('skin_TempHandler', 'kTempTablesHandler'); @@ -970,15 +976,15 @@ // clone current skin $cloned_ids = $temp_handler->CloneItems('skin', '', Array ($primary_skin->GetID())); - if (!$cloned_ids) { + if ( !$cloned_ids ) { // can't clone - return ; + return false; } $skin =& $this->Application->recallObject('skin.tmp', null, Array ('skip_autoload' => true)); /* @var $skin kDBItem */ - $skin->Load( $cloned_ids[0] ); + $skin->Load($cloned_ids[0]); // save css to temp file (for patching) $skin_file = tempnam('/tmp', 'skin_css_'); @@ -1009,18 +1015,18 @@ $has_errors = false; foreach ($output as $version => $version_output) { - $version_errors = trim( preg_replace("/(^|\n)(patching file .*?|Hunk #.*?\.)(\n|$)/m", '', $version_output) ); + $version_errors = trim(preg_replace("/(^|\n)(patching file .*?|Hunk #.*?\.)(\n|$)/m", '', $version_output)); - if ($version_errors) { + if ( $version_errors ) { $has_errors = true; - $output[$version] = trim( preg_replace("/(^|\n)(patching file .*?)(\n|$)/m", '', $output[$version]) ); + $output[$version] = trim(preg_replace("/(^|\n)(patching file .*?)(\n|$)/m", '', $output[$version])); } else { unset($output[$version]); } } - if (!$has_errors) { + if ( !$has_errors ) { // copy patched css back to primary skin $primary_skin->SetDBField('CSS', $skin->GetDBField('CSS')); $primary_skin->Update(); Index: branches/5.2.x/core/kernel/processors/main_processor.php =================================================================== diff -u -r14603 -r14628 --- branches/5.2.x/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 14603) +++ branches/5.2.x/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 14628) @@ -1,6 +1,6 @@ Application->ConfigValue($config_name); } - function ConfigEquals($params) + /** + * Compares configuration variable to a given value + * + * @param Array $params + * @return bool + * @deprecated + * @access protected + */ + protected function ConfigEquals($params) { $option = $this->SelectParam($params, 'name,option,var'); - return $this->Application->ConfigValue($option) == getArrayValue($params, 'value'); + + return $this->Application->ConfigValue($option) == $params['value']; } /** @@ -442,9 +451,9 @@ * * @param Array $params * @return string - * @access public + * @access protected */ - function DumpSystemInfo($params) + protected function DumpSystemInfo($params) { $actions =& $this->Application->recallObject('kActions'); /* @var $actions Params */ @@ -756,7 +765,7 @@ { $perm_helper =& $this->Application->recallObject('PermissionsHelper'); /* @var $perm_helper kPermissionsHelper */ - + return $perm_helper->TagPermissionCheck($params); } @@ -848,20 +857,26 @@ } } - function IsMember($params) + /** + * Checks, that user belongs to a group with a given name + * + * @param Array $params + * @return bool + */ + protected function IsMember($params) { - $group = getArrayValue($params, 'group'); - $sql = 'SELECT GroupId - FROM '.TABLE_PREFIX.'PortalGroup - WHERE Name = '.$this->Conn->qstr($group); + FROM ' . TABLE_PREFIX . 'PortalGroup + WHERE Name = ' . $this->Conn->qstr($params['group']); $group_id = $this->Conn->GetOne($sql); - if ($group_id) { + if ( $group_id ) { $groups = explode(',', $this->Application->RecallVar('UserGroups')); - $group_access = in_array($group_id, $groups); + + return in_array($group_id, $groups); } - return $group_access; + + return false; } /** @@ -871,9 +886,9 @@ * If called without params forces https right away. If called with by_config="1" checks the * Require SSL setting from General Config and if it is ON forces https * - * @param unknown_type $params + * @param Array $params */ - function CheckSSL($params) + protected function CheckSSL($params) { $ssl = $this->Application->isAdmin ? $this->Application->ConfigValue('AdminSSL_URL') : false; @@ -929,7 +944,7 @@ if ( $this->Application->GetVar('__KEEP_SSL__') ) { return; } - + // $pass_more = Array ('pass' => 'm', 'm_cat_id' => 0, '__SSL__' => 0); $pass['__SSL__'] = 0; $this->Application->Redirect('', $pass); // $pass_more Index: branches/5.2.x/core/kernel/utility/http_query.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/kernel/utility/http_query.php (.../http_query.php) (revision 14585) +++ branches/5.2.x/core/kernel/utility/http_query.php (.../http_query.php) (revision 14628) @@ -1,6 +1,6 @@ $file_info) - { - if( is_array($file_info['error']) ) - { - $tmp[$file_name] = $this->getArrayLevel( $file_info['error'], $file_name ); + foreach ($_FILES as $file_name => $file_info) { + if ( is_array($file_info['error']) ) { + $tmp[$file_name] = $this->getArrayLevel($file_info['error'], $file_name); } - else - { + else { $normal_files[$file_name] = $file_info; } } - if(!$tmp) return false; + if ( !$tmp ) { + return ; + } $files = $_FILES; - $_FILES = Array(); + $_FILES = Array (); - foreach($tmp as $prefix => $prefix_files) - { + foreach ($tmp as $prefix => $prefix_files) { $anchor =& $_FILES; - foreach($prefix_files['keys'] as $key) - { + foreach ($prefix_files['keys'] as $key) { $anchor =& $anchor[$key]; } - foreach($prefix_files['value'] as $field_name) - { - unset($inner_anchor); - unset($copy); + + foreach ($prefix_files['value'] as $field_name) { + unset($inner_anchor, $copy); $work_copy = $prefix_files['keys']; - foreach($file_keys as $file_key) - { + + foreach ($file_keys as $file_key) { $inner_anchor =& $files[$prefix][$file_key]; - if (isset($copy)) - { + + if ( isset($copy) ) { $work_copy = $copy; } - else - { + else { $copy = $work_copy; } + array_shift($work_copy); - foreach($work_copy as $prefix_file_key) - { + foreach ($work_copy as $prefix_file_key) { $inner_anchor =& $inner_anchor[$prefix_file_key]; } + $anchor[$field_name][$file_key] = $inner_anchor[$field_name]; } } } - // keys: img_temp, 0, values: LocalPath, ThumbPath } @@ -493,17 +487,21 @@ } /** - * Owerwrites GET events with POST events in case if they are set and not empty + * Overwrites GET events with POST events in case if they are set and not empty * + * @return void + * @access protected */ - function convertPostEvents() + protected function convertPostEvents() { - $events = $this->Get('events'); - if (is_array($events)) { + $events = $this->Get('events', Array ()); + /* @var $events Array */ + + if ( is_array($events) ) { + $events = array_filter($events); + foreach ($events as $prefix_special => $event_name) { - if ($event_name) { - $this->Set($prefix_special.'_event', $event_name); - } + $this->Set($prefix_special . '_event', $event_name); } } } @@ -535,6 +533,8 @@ function processRewriteURL() { $mod_rw_helper =& $this->Application->recallObject('ModRewriteHelper'); + /* @var $mod_rw_helper kModRewriteHelper */ + $mod_rw_helper->processRewriteURL(); } @@ -807,37 +807,39 @@ { $log_file = (defined('RESTRICTED') ? RESTRICTED : FULL_PATH) . '/' . $filename; - if ( is_writable( dirname($log_file) ) ) { + if ( is_writable(dirname($log_file)) ) { $fp = fopen($log_file, 'a'); - if ($fp) { + if ( $fp ) { $session =& $this->Application->recallObject('Session'); + /* @var $session Session */ + $user_id = $session->GetField('PortalUserId'); $admin_mark = $this->Application->isAdmin ? 'ADMIN' : 'FRONT'; - $data = '['.date('D M d H:i:s Y').'] '.$admin_mark.'; ip: '.$_SERVER['REMOTE_ADDR'].'; user_id: '.$user_id.'; sid: '.$this->Application->GetSID().'; request: '."\n"; - if ($this->Get) { - $data .= "_GET:\n".print_r($this->Get, true); + $data = '[' . date('D M d H:i:s Y') . '] ' . $admin_mark . '; ip: ' . $_SERVER['REMOTE_ADDR'] . '; user_id: ' . $user_id . '; sid: ' . $this->Application->GetSID() . '; request: ' . "\n"; + if ( $this->Get ) { + $data .= "_GET:\n" . print_r($this->Get, true); } - if ($this->Post) { - $data .= "_POST:\n".print_r($this->Post, true); + if ( $this->Post ) { + $data .= "_POST:\n" . print_r($this->Post, true); } - if ($this->Cookie) { - $data .= "_COOKIE:\n".print_r($this->Cookie, true); + if ( $this->Cookie ) { + $data .= "_COOKIE:\n" . print_r($this->Cookie, true); } - $data .= str_repeat('=', 100)."\n"; + $data .= str_repeat('=', 100) . "\n"; fwrite($fp, $data); fclose($fp); } else { - trigger_error('Requrest Log directory not writable', E_USER_WARNING); + trigger_error('Request Log directory not writable', E_USER_WARNING); } } else { - trigger_error('Requrest Log directory not writable', E_USER_WARNING); + trigger_error('Request Log directory not writable', E_USER_WARNING); } } Index: branches/5.2.x/core/units/custom_data/custom_data_event_handler.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/units/custom_data/custom_data_event_handler.php (.../custom_data_event_handler.php) (revision 14585) +++ branches/5.2.x/core/units/custom_data/custom_data_event_handler.php (.../custom_data_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ createCustomFields($event->MasterEvent->Prefix); } - function scanCustomFields($prefix) + /** + * Returns list of custom fields for a given $prefix + * + * @param $prefix + * + * @return Array|bool + * @access protected + */ + protected function scanCustomFields($prefix) { static $custom_fields = Array (); @@ -107,44 +115,52 @@ * Fills cloned cdata config with data from it's parent * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterConfigRead(&$event) + protected function OnAfterConfigRead(&$event) { $main_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); - if (!$main_prefix) { - return false; + if ( !$main_prefix ) { + return ; } $custom_fields = $this->scanCustomFields($main_prefix); - if (!$custom_fields) { - return false; + if ( !$custom_fields ) { + return ; } // 2. create fields (for customdata item) - $fields = $this->Application->getUnitOption($event->Prefix, 'Fields', Array()); - $field_options = Array('type' => 'string', 'formatter' => 'kMultiLanguage', 'db_type' => 'text', 'default' => ''); + $fields = $this->Application->getUnitOption($event->Prefix, 'Fields', Array ()); + $field_options = Array ('type' => 'string', 'formatter' => 'kMultiLanguage', 'db_type' => 'text', 'default' => ''); + foreach ($custom_fields as $custom_id => $custom_params) { - if (isset($fields['cust_'.$custom_id])) continue; - $fields['cust_'.$custom_id] = $field_options; - $fields['cust_'.$custom_id]['force_primary'] = !$custom_params['MultiLingual']; + if ( isset($fields['cust_' . $custom_id]) ) { + continue; + } + $fields['cust_' . $custom_id] = $field_options; + $fields['cust_' . $custom_id]['force_primary'] = !$custom_params['MultiLingual']; } + $this->Application->setUnitOption($event->Prefix, 'Fields', $fields); } /** * Creates "cust_" virtual fields for main item * * @param string $prefix + * @return void + * @access protected */ - function createCustomFields($prefix) + protected function createCustomFields($prefix) { $custom_fields = $this->scanCustomFields($prefix); - if (!$custom_fields) { - return false; + if ( !$custom_fields ) { + return; } - $calculated_fields = Array(); - $virtual_fields = $this->Application->getUnitOption($prefix, 'VirtualFields', Array()); + $calculated_fields = Array (); + $virtual_fields = $this->Application->getUnitOption($prefix, 'VirtualFields', Array ()); $cf_helper =& $this->Application->recallObject('InpCustomFieldsHelper'); /* @var $cf_helper InpCustomFieldsHelper */ @@ -153,16 +169,16 @@ foreach ($custom_fields as $custom_id => $custom_params) { $custom_name = $custom_params['FieldName']; - $field_options = Array('type' => 'string', 'default' => $custom_params['DefaultValue']); + $field_options = Array ('type' => 'string', 'default' => $custom_params['DefaultValue']); // raises warnings during 4.3.9 -> 5.0.0 upgrade, no fatal sqls though if ( $custom_params['IsRequired'] ) { $field_options['required'] = 1; } - $calculated_fields['cust_' . $custom_name] = 'cust.l' . $this->Application->GetDefaultLanguageId() .'_cust_' . $custom_id; + $calculated_fields['cust_' . $custom_name] = 'cust.l' . $this->Application->GetDefaultLanguageId() . '_cust_' . $custom_id; - switch ($custom_params['ElementType']) { + switch ( $custom_params['ElementType'] ) { case 'date': unset($field_options['options']); $field_options['formatter'] = 'kDateFormatter'; @@ -178,7 +194,7 @@ case 'select': case 'multiselect': case 'radio': - if ($custom_params['ValueList']) { + if ( $custom_params['ValueList'] ) { // $is_install check prevents 335 bad phrase sql errors on upgrade to 5.1.0 $field_options['options'] = $is_install ? Array () : $cf_helper->GetValuesHash($custom_params['ValueList']); $field_options['formatter'] = 'kOptionsFormatter'; @@ -187,7 +203,7 @@ break; default: - if ($custom_params['MultiLingual']) { + if ( $custom_params['MultiLingual'] ) { $field_options['formatter'] = 'kMultiLanguage'; $calculated_fields['cust_' . $custom_name] = 'cust.l%2$s_cust_' . $custom_id; } @@ -201,9 +217,9 @@ $custom_fields[$custom_id] = $custom_name; } - $config_calculated_fields = $this->Application->getUnitOption($prefix, 'CalculatedFields', Array()); + $config_calculated_fields = $this->Application->getUnitOption($prefix, 'CalculatedFields', Array ()); foreach ($config_calculated_fields as $special => $special_fields) { - if ($special == '-virtual') { + if ( $special == '-virtual' ) { continue; } Index: branches/5.2.x/core/units/forms/form_fields/form_field_eh.php =================================================================== diff -u -r14572 -r14628 --- branches/5.2.x/core/units/forms/form_fields/form_field_eh.php (.../form_field_eh.php) (revision 14572) +++ branches/5.2.x/core/units/forms/form_fields/form_field_eh.php (.../form_field_eh.php) (revision 14628) @@ -1,6 +1,6 @@ Application->TemplatesCache->TemplateExists($t)) { $cms_handler =& $this->Application->recallObject('st_EventHandler'); - /* @var $cms_handler StructureEventHandler */ + /* @var $cms_handler CategoriesEventHandler */ $t = ltrim($cms_handler->GetDesignTemplate($t), '/'); } @@ -173,8 +173,9 @@ // 1. get location of movable areas $mask = ''; $start_pos = 0; - $elements = Array (); + $elements = $area = Array (); $areas = $this->_getDivPairs($data, 'movable-area'); + foreach ($areas as $area_index => $area) { // 1.1. get locations of all movable elements inside given area $area_content = substr($area['data'], $area['open_len'], -$area['close_len']); Index: branches/5.2.x/core/kernel/utility/temp_handler.php =================================================================== diff -u -r14572 -r14628 --- branches/5.2.x/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 14572) +++ branches/5.2.x/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 14628) @@ -1,6 +1,6 @@ Application->getUnitOption($prefix, 'ParentTableKey'); }*/ - $this->FinalRefs[ $tables['TableName'] ] = $tables['TableId']; // don't forget to add main table to FinalRefs too + $this->FinalRefs[ $tables['TableName'] ] = $tables['TableId']; // don't forget to add main table to FinalRefs too - $SubItems = $this->Application->getUnitOption($prefix,'SubItems'); - if (is_array($SubItems)) { - foreach ($SubItems as $prefix) { + $sub_items = $this->Application->getUnitOption($prefix, 'SubItems', Array ()); + /* @var $sub_items Array */ + + if ( is_array($sub_items) ) { + foreach ($sub_items as $prefix) { $this->AddTables($prefix, $tables); } } + $this->SetTables($tables); } @@ -194,7 +205,7 @@ function AddTables($prefix, &$tables) { - if (!$this->Application->prefixRegistred($prefix)) { + if ( !$this->Application->prefixRegistred($prefix) ) { // allows to skip subitem processing if subitem module not enabled/installed return ; } @@ -213,25 +224,23 @@ $this->FinalRefs[ $tmp['TableName'] ] = $tmp['TableId']; - $constrain = $this->Application->getUnitOption($prefix,'Constrain'); - if ($constrain) - { + $constrain = $this->Application->getUnitOption($prefix, 'Constrain'); + if ( $constrain ) { $tmp['Constrain'] = $constrain; - $this->FinalRefs[ $tmp['TableName'].$tmp['Constrain'] ] = $tmp['TableId']; + $this->FinalRefs[ $tmp['TableName'] . $tmp['Constrain'] ] = $tmp['TableId']; } - $SubItems = $this->Application->getUnitOption($prefix,'SubItems'); - $same_sub_counter = 1; - if( is_array($SubItems) ) - { - foreach($SubItems as $prefix) - { + $sub_items = $this->Application->getUnitOption($prefix, 'SubItems', Array ()); + /* @var $sub_items Array */ + + if ( is_array($sub_items) ) { + foreach ($sub_items as $prefix) { $this->AddTables($prefix, $tmp); } } if ( !is_array(getArrayValue($tables, 'SubTables')) ) { - $tables['SubTables'] = array(); + $tables['SubTables'] = Array (); } $tables['SubTables'][] = $tmp; @@ -247,7 +256,7 @@ } $object =& $this->Application->recallObject($prefix.'.'.$special, $prefix, Array('skip_autoload' => true)); - /* @var $object kDBItem */ + /* @var $object kCatDBItem */ $object->PopulateMultiLangFields(); @@ -509,64 +518,85 @@ } } - function DoCopyTempToOriginal($master, $parent_prefix = null, $current_ids = Array()) + /** + * Copies data from temp to live table and returns IDs of copied records + * + * @param Array $master + * @param string $parent_prefix + * @param Array $current_ids + * @return Array + * @access public + */ + public function DoCopyTempToOriginal($master, $parent_prefix = null, $current_ids = Array()) { - if (!$current_ids) { - $query = 'SELECT '.$master['IdField'].' FROM '.$this->GetTempName($master['TableName']); - if (isset($master['Constrain'])) $query .= ' WHERE '.$master['Constrain']; + if ( !$current_ids ) { + $query = 'SELECT ' . $master['IdField'] . ' FROM ' . $this->GetTempName($master['TableName']); + + if ( isset($master['Constrain']) ) { + $query .= ' WHERE ' . $master['Constrain']; + } + $current_ids = $this->Conn->GetCol($query); } - $table_sig = $master['TableName'].(isset($master['Constrain']) ? $master['Constrain'] : ''); + $table_sig = $master['TableName'] . (isset($master['Constrain']) ? $master['Constrain'] : ''); if ($current_ids) { // delete all ids from live table - for MasterTable ONLY! // because items from Sub Tables get deteleted in CopySubTablesToLive !BY ForeignKey! - if ($master['TableName'] == $this->MasterTable) { - $this->RaiseEvent( 'OnBeforeDeleteFromLive', $master['Prefix'], '', $current_ids ); + if ( $master['TableName'] == $this->MasterTable ) { + $this->RaiseEvent('OnBeforeDeleteFromLive', $master['Prefix'], '', $current_ids); - $query = 'DELETE FROM '.$master['TableName'].' WHERE '.$master['IdField'].' IN ('.join(',', $current_ids).')'; + $query = 'DELETE FROM ' . $master['TableName'] . ' WHERE ' . $master['IdField'] . ' IN (' . join(',', $current_ids) . ')'; $this->Conn->Query($query); } if ( getArrayValue($master, 'SubTables') ) { - if( in_array($table_sig, $this->CopiedTables) || $this->FinalRefs[$table_sig] != $master['TableId'] ) return; + if ( in_array($table_sig, $this->CopiedTables) || $this->FinalRefs[$table_sig] != $master['TableId'] ) { + return Array (); + } - foreach($current_ids AS $id) - { - $this->RaiseEvent( 'OnBeforeCopyToLive', $master['Prefix'], '', Array($id) ); + foreach ($current_ids AS $id) { + $this->RaiseEvent('OnBeforeCopyToLive', $master['Prefix'], '', Array ($id)); //reset negative ids to 0, so autoincrement in live table works fine - if($id < 0) - { - $query = 'UPDATE '.$this->GetTempName($master['TableName']).' - SET '.$master['IdField'].' = 0 - WHERE '.$master['IdField'].' = '.$id; - if (isset($master['Constrain'])) $query .= ' AND '.$master['Constrain']; + if ( $id < 0 ) { + $query = ' UPDATE ' . $this->GetTempName($master['TableName']) . ' + SET ' . $master['IdField'] . ' = 0 + WHERE ' . $master['IdField'] . ' = ' . $id; + + if ( isset($master['Constrain']) ) { + $query .= ' AND ' . $master['Constrain']; + } + $this->Conn->Query($query); $id_to_copy = 0; } - else - { + else { $id_to_copy = $id; } //copy current id_to_copy (0 for new or real id) to live table - $query = 'INSERT INTO '.$master['TableName'].' - SELECT * FROM '.$this->GetTempName($master['TableName']).' - WHERE '.$master['IdField'].' = '.$id_to_copy; + $query = ' INSERT INTO ' . $master['TableName'] . ' + SELECT * FROM ' . $this->GetTempName($master['TableName']) . ' + WHERE ' . $master['IdField'] . ' = ' . $id_to_copy; $this->Conn->Query($query); + $insert_id = $id_to_copy == 0 ? $this->Conn->getInsertID() : $id_to_copy; - $this->saveID($master['Prefix'], '', array($id => $insert_id)); - $this->RaiseEvent( 'OnAfterCopyToLive', $master['Prefix'], '', Array($insert_id), null, array('temp_id' => $id) ); + $this->saveID($master['Prefix'], '', array ($id => $insert_id)); + $this->RaiseEvent('OnAfterCopyToLive', $master['Prefix'], '', Array ($insert_id), null, Array ('temp_id' => $id)); $this->UpdateForeignKeys($master, $insert_id, $id); //delete already copied record from master temp table - $query = 'DELETE FROM '.$this->GetTempName($master['TableName']).' - WHERE '.$master['IdField'].' = '.$id_to_copy; - if (isset($master['Constrain'])) $query .= ' AND '.$master['Constrain']; + $query = ' DELETE FROM ' . $this->GetTempName($master['TableName']) . ' + WHERE ' . $master['IdField'] . ' = ' . $id_to_copy; + + if ( isset($master['Constrain']) ) { + $query .= ' AND ' . $master['Constrain']; + } + $this->Conn->Query($query); } @@ -575,70 +605,77 @@ // when all of ids in current master has been processed, copy all sub-tables data $this->CopySubTablesToLive($master, $current_ids); } - elseif( !in_array($table_sig, $this->CopiedTables) && ($this->FinalRefs[$table_sig] == $master['TableId']) ) { //If current master doesn't have sub-tables - we could use mass operations - // We don't need to delete items from live here, as it get deleted in the beggining of the method for MasterTable + elseif ( !in_array($table_sig, $this->CopiedTables) && ($this->FinalRefs[$table_sig] == $master['TableId']) ) { //If current master doesn't have sub-tables - we could use mass operations + // We don't need to delete items from live here, as it get deleted in the beginning of the method for MasterTable // or in parent table processing for sub-tables + $live_ids = Array (); $this->RaiseEvent('OnBeforeCopyToLive', $master['Prefix'], '', $current_ids); - $live_ids = array(); foreach ($current_ids as $an_id) { - if ($an_id > 0) { + if ( $an_id > 0 ) { $live_ids[$an_id] = $an_id; // positive (already live) IDs will be copied in on query all togather below, // so we just store it here continue; } - else { // zero or negaitve ids should be copied one by one to get their InsertId - // reseting to 0 so it get inserted into live table with autoincrement - $query = 'UPDATE '.$this->GetTempName($master['TableName']).' - SET '.$master['IdField'].' = 0 - WHERE '.$master['IdField'].' = '.$an_id; + else { // zero or negative ids should be copied one by one to get their InsertId + // resetting to 0 so it get inserted into live table with autoincrement + $query = ' UPDATE ' . $this->GetTempName($master['TableName']) . ' + SET ' . $master['IdField'] . ' = 0 + WHERE ' . $master['IdField'] . ' = ' . $an_id; // constrain is not needed here because ID is already unique $this->Conn->Query($query); // copying - $query = 'INSERT INTO '.$master['TableName'].' - SELECT * FROM '.$this->GetTempName($master['TableName']).' - WHERE '.$master['IdField'].' = 0'; + $query = ' INSERT INTO ' . $master['TableName'] . ' + SELECT * FROM ' . $this->GetTempName($master['TableName']) . ' + WHERE ' . $master['IdField'] . ' = 0'; $this->Conn->Query($query); + $live_ids[$an_id] = $this->Conn->getInsertID(); //storing newly created live id //delete already copied record from master temp table - $query = 'DELETE FROM '.$this->GetTempName($master['TableName']).' - WHERE '.$master['IdField'].' = 0'; + $query = ' DELETE FROM ' . $this->GetTempName($master['TableName']) . ' + WHERE ' . $master['IdField'] . ' = 0'; $this->Conn->Query($query); $this->UpdateChangeLogForeignKeys($master, $live_ids[$an_id], $an_id); } } // copy ALL records to live table - $query = 'INSERT INTO '.$master['TableName'].' - SELECT * FROM '.$this->GetTempName($master['TableName']); - if (isset($master['Constrain'])) $query .= ' WHERE '.$master['Constrain']; + $query = ' INSERT INTO ' . $master['TableName'] . ' + SELECT * FROM ' . $this->GetTempName($master['TableName']); + + if ( isset($master['Constrain']) ) { + $query .= ' WHERE ' . $master['Constrain']; + } + $this->Conn->Query($query); $this->CopiedTables[] = $table_sig; $this->RaiseEvent('OnAfterCopyToLive', $master['Prefix'], '', $live_ids); $this->saveID($master['Prefix'], '', $live_ids); - // no need to clear temp table - it will be dropped by next statement } } - if ($this->FinalRefs[ $master['TableName'] ] != $master['TableId']) return; + if ( $this->FinalRefs[ $master['TableName'] ] != $master['TableId'] ) { + return Array (); + } /*if ( is_array(getArrayValue($master, 'ForeignKey')) ) { //if multiple ForeignKeys if ( $master['ForeignKey'][$parent_prefix] != end($master['ForeignKey']) ) { return; // Do not delete temp table if not all ForeignKeys have been processed (current is not the last) } }*/ + $this->DropTempTable($master['TableName']); $this->Application->resetCounters($master['TableName']); - if (!isset($this->savedIDs[ $master['Prefix'] ])) { - $this->savedIDs[ $master['Prefix'] ] = Array(); + if ( !isset($this->savedIDs[ $master['Prefix'] ]) ) { + $this->savedIDs[ $master['Prefix'] ] = Array (); } return $this->savedIDs[ $master['Prefix'] ]; @@ -655,6 +692,8 @@ if (!isset($connection)) { $connection =& $this->Application->makeClass( 'kDBConnection', Array (SQL_TYPE, Array (&$this->Application, 'handleSQLError')) ); + /* @var $connection kDBConnection */ + $connection->debugMode = $this->Application->isDebugMode(); $connection->Connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB, true); } @@ -761,26 +800,40 @@ } } - function RaiseEvent($name, $prefix, $special, $ids, $foreign_key = null, $add_params = null) + /** + * Raises event using IDs, that are currently being processed in temp handler + * + * @param string $name + * @param string $prefix + * @param string $special + * @param Array $ids + * @param string $foreign_key + * @param Array $add_params + * @return bool + * @access protected + */ + protected function RaiseEvent($name, $prefix, $special, $ids, $foreign_key = null, $add_params = null) { - if ( !is_array($ids) ) return ; + if ( !is_array($ids) ) { + return true; + } - $event_key = $prefix.($special ? '.' : '').$special.':'.$name; + $event_key = $prefix . ($special ? '.' : '') . $special . ':' . $name; $event = new kEvent($event_key); - if (isset($foreign_key)) { + if ( isset($foreign_key) ) { $event->setEventParam('foreign_key', $foreign_key); } $set_temp_id = ($name == 'OnAfterCopyToLive') && (!is_array($add_params) || !array_key_exists('temp_id', $add_params)); - foreach($ids as $index => $id) { + foreach ($ids as $index => $id) { $event->setEventParam('id', $id); - if ($set_temp_id) { + if ( $set_temp_id ) { $event->setEventParam('temp_id', $index); } - if (is_array($add_params)) { + if ( is_array($add_params) ) { foreach ($add_params as $name => $val) { $event->setEventParam($name, $val); } @@ -820,7 +873,7 @@ $sleep_count = 0; do { - // aquire lock + // acquire lock $conn->ChangeQuery('LOCK TABLES '.TABLE_PREFIX.'Semaphores WRITE'); $sql = 'SELECT SessionKey Index: branches/5.2.x/core/units/translator/translator_event_handler.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/translator/translator_event_handler.php (.../translator_event_handler.php) (revision 14244) +++ branches/5.2.x/core/units/translator/translator_event_handler.php (.../translator_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ getPrefixAndField($event); @@ -63,13 +65,23 @@ return Array($prefix, $field); } - function OnLoad(&$event) + /** + * Loads record to be translated + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnLoad(&$event) { list($obj_prefix, $field) = $this->getPrefixAndField($event); $object =& $this->Application->recallObject($obj_prefix); - $translator =& $this->Application->recallObject($event->getPrefixSpecial()); + /* @var $object kDBItem */ + $translator =& $event->getObject(); + /* @var $translator kDBItem */ + $def_lang = $this->Application->GetDefaultLanguageId(); $current_lang = $translator->GetDBField('Language'); @@ -88,46 +100,73 @@ $translator->SetDBField('Translation', $object->GetDBField('l'.$current_lang.'_'.$field)); $cur_lang =& $this->Application->recallObject('lang.current'); + /* @var $cur_lang LanguagesItem */ + $cur_lang->Load($current_lang); $translator->SetDBField('Charset', $cur_lang->GetDBField('Charset')); $event->redirect = false; } - function OnSaveAndClose(&$event) + /** + * Saves changes into temporary table and closes editing window + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnSaveAndClose(&$event) { $event->CallSubEvent('OnPreSave'); - $this->finalizePopup($event); + + $event->SetRedirectParam('opener', 'u'); } - function OnPreSave(&$event) + /** + * Saves edited item into temp table + * If there is no id, new item is created in temp table + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnPreSave(&$event) { - $translator =& $this->Application->recallObject($event->getPrefixSpecial()); + $translator =& $event->getObject(); + /* @var $translator kDBItem */ - $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); - if($items_info) $field_values = array_shift($items_info); + $translator->SetFieldsFromHash( $this->getSubmittedFields($event) ); - $translator->SetFieldsFromHash($field_values); - list($obj_prefix, $field) = $this->getPrefixAndField($event); $object =& $this->Application->recallObject($obj_prefix); /* @var $object kDBItem */ $lang = $translator->GetDBField('Language'); - $object->SetFieldOptions('l'.$lang.'_'.$field, Array ()); - $object->SetDBField('l'.$lang.'_'.$field, $translator->GetDBField('Translation')); + $object->SetFieldOptions('l' . $lang . '_' . $field, Array ()); + $object->SetDBField('l' . $lang . '_' . $field, $translator->GetDBField('Translation')); $this->RemoveRequiredFields($object); $object->Update(); } - function OnChangeLanguage(&$event) + /** + * Changes current language in translation popup + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnChangeLanguage(&$event) { $event->CallSubEvent('OnPreSave'); - $translator =& $this->Application->recallObject($event->getPrefixSpecial()); - $translator->SetDBField('Language', $translator->GetDBField('SwitchLanguage')); + + $object =& $event->getObject(); + /* @var $object kDBItem */ + + $object->SetDBField('Language', $object->GetDBField('SwitchLanguage')); + $event->CallSubEvent('OnLoad'); $event->redirect = false; } Index: branches/5.2.x/core/units/relationship/relationship_event_handler.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/relationship/relationship_event_handler.php (.../relationship_event_handler.php) (revision 14244) +++ branches/5.2.x/core/units/relationship/relationship_event_handler.php (.../relationship_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ getObject(); + /* @var $object kDBItem */ + $table_info = $object->getLinkedInfo(); $object->SetDBField('SourceId', $table_info['ParentId']); @@ -59,73 +61,81 @@ function OnProcessSelected(&$event) { $dst_field = $this->Application->RecallVar('dst_field'); - if ($dst_field == 'TargetId') { + + if ( $dst_field == 'TargetId' ) { // prepare target_id & target_type - $object =& $event->getObject( Array('skip_autoload' => true) ); + $object =& $event->getObject(Array ('skip_autoload' => true)); - $selected_ids = $this->Application->GetVar('selected_ids'); + $target_id = 0; $target_prefix = false; + $selected_ids = $this->Application->GetVar('selected_ids'); + foreach ($selected_ids as $selected_prefix => $target_id) { - if ($target_id > 0) { + if ( $target_id > 0 ) { $target_prefix = $selected_prefix; break; } } - if (!$target_prefix) { - $this->finalizePopup($event); + if ( !$target_prefix ) { + $event->SetRedirectParam('opener', 'u'); return; } $sql = 'SELECT ResourceId - FROM '.$this->Application->getUnitOption($target_prefix, 'TableName').' - WHERE '.$this->Application->getUnitOption($target_prefix, 'IDField').' IN ('.$target_id.')'; + FROM ' . $this->Application->getUnitOption($target_prefix, 'TableName') . ' + WHERE ' . $this->Application->getUnitOption($target_prefix, 'IDField') . ' IN (' . $target_id . ')'; $target_id = $this->Conn->GetOne($sql); $target_type = $this->Application->getUnitOption($target_prefix, 'ItemType'); // don't add same relation twice $table_info = $object->getLinkedInfo(); $sql = 'SELECT TargetId - FROM '.$object->TableName.' - WHERE (SourceId = '.$table_info['ParentId'].') AND (TargetId = '.$target_id.')'; + FROM ' . $object->TableName . ' + WHERE (SourceId = ' . $table_info['ParentId'] . ') AND (TargetId = ' . $target_id . ')'; $duplicate_relation = $this->Conn->GetOne($sql) == $target_id; - $this->finalizePopup($event); + $event->SetRedirectParam('opener', 'u'); - if (!$duplicate_relation) { + if ( !$duplicate_relation ) { // place correct template in opener stack $source_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); - $template = $this->Application->getUnitOption($source_prefix, 'AdminTemplatePath').'/relations_edit'; + $template = $this->Application->getUnitOption($source_prefix, 'AdminTemplatePath') . '/relations_edit'; - $redirect_params = Array($event->Prefix.'_event' => 'OnNew', 'target_id' => $target_id, 'm_opener' => 's', 'target_type' => $target_type); - $this->Application->EventManager->openerStackPush($template, $redirect_params, 'all,'.$event->Prefix); + $redirect_params = Array ($event->Prefix . '_event' => 'OnNew', 'target_id' => $target_id, 'm_opener' => 's', 'target_type' => $target_type); + $this->Application->EventManager->openerStackPush($template, $redirect_params, 'all,' . $event->Prefix); } } else { - $this->finalizePopup($event); + $event->SetRedirectParam('opener', 'u'); } } /** * Set ItemName & ItemType virtual fields based on loaded item data * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterItemLoad(&$event) + protected function OnAfterItemLoad(&$event) { + parent::OnAfterItemLoad($event); + $object =& $event->getObject(); + /* @var $object kDBItem */ $sql = 'SELECT Prefix - FROM '.TABLE_PREFIX.'ItemTypes - WHERE ItemType = '.$object->GetDBField('TargetType'); + FROM ' . TABLE_PREFIX . 'ItemTypes + WHERE ItemType = ' . $object->GetDBField('TargetType'); $target_prefix = $this->Conn->GetOne($sql); $title_field = $this->getTitleField($target_prefix); $title_phrase = $this->Application->getUnitOption($target_prefix, 'TitlePhrase'); - $sql = 'SELECT '.$title_field.' - FROM '.$this->Application->getUnitOption($target_prefix, 'TableName').' - WHERE ResourceId = '.$object->GetDBField('TargetId'); + $sql = 'SELECT ' . $title_field . ' + FROM ' . $this->Application->getUnitOption($target_prefix, 'TableName') . ' + WHERE ResourceId = ' . $object->GetDBField('TargetId'); $object->SetDBField('ItemName', $this->Conn->GetOne($sql)); $object->SetDBField('ItemType', $this->Application->Phrase($title_phrase)); Index: branches/5.2.x/core/units/stylesheets/stylesheets_item.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/stylesheets/stylesheets_item.php (.../stylesheets_item.php) (revision 14244) +++ branches/5.2.x/core/units/stylesheets/stylesheets_item.php (.../stylesheets_item.php) (revision 14628) @@ -1,6 +1,6 @@ Application->recallObject('selectors.item', 'selectors', Array('live_table'=>true, 'skip_autoload' => true) ); + /* @var $selector_item SelectorsItem */ + $parent_field = $this->Application->getUnitOption($selector_item->Prefix, 'ForeignKey'); $sql_template = 'SELECT '.$selector_item->IDField.' FROM '.$selector_item->TableName.' WHERE '.$parent_field.' = %s ORDER BY SelectorName ASC'; Index: branches/5.2.x/core/units/email_events/email_events_event_handler.php =================================================================== diff -u -r14572 -r14628 --- branches/5.2.x/core/units/email_events/email_events_event_handler.php (.../email_events_event_handler.php) (revision 14572) +++ branches/5.2.x/core/units/email_events/email_events_event_handler.php (.../email_events_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ Application->GetVar('module'); @@ -76,10 +78,11 @@ * Apply any custom changes to list's sql query * * @param kEvent $event + * @return void * @access protected - * @see OnListBuild + * @see kDBEventHandler::OnListBuild() */ - function SetCustomQuery(&$event) + protected function SetCustomQuery(&$event) { $object =& $event->getObject(); /* @var $object kDBList */ @@ -96,11 +99,13 @@ } /** - * Sets event id + * Set default headers * * @param kEvent $event + * @return void + * @access protected */ - function OnPreCreate(&$event) + protected function OnPreCreate(&$event) { parent::OnPreCreate($event); @@ -649,22 +654,24 @@ } /** - * Raised when email message shoul be sent + * Raised when email message should be sent * * @param kEvent $event + * @return void + * @access protected */ - function OnEmailEvent(&$event) + protected function OnEmailEvent(&$event) { $email_event_name = $event->getEventParam('EmailEventName'); - if (strpos($email_event_name, '_') !== false) { + if ( strpos($email_event_name, '_') !== false ) { throw new Exception('Invalid email event name ' . $email_event_name . '. Use only UPPERCASE characters and dots as email event names'); } $object =& $this->_getEmailEvent($event); - if (!is_object($object)) { + if ( !is_object($object) ) { // email event not found OR it's won't be send under given circumstances - return false; + return ; } // additional parameters from kApplication->EmailEvent @@ -677,15 +684,15 @@ // 2. prepare message to be sent $message_language = $this->_getSendLanguage($send_params); $message_template = $this->_getMessageBody($event, $message_language); - if (!trim($message_template)) { + if ( !trim($message_template) ) { trigger_error('Message template is empty', E_USER_WARNING); - return false; + return ; } list ($message_headers, $message_body) = $this->ParseMessageBody($message_template, $send_params); - if (!trim($message_body)) { + if ( !trim($message_body) ) { trigger_error('Message template is empty after parsing', E_USER_WARNING); - return false; + return ; } // 3. set headers & send message @@ -695,8 +702,8 @@ $message_subject = isset($message_headers['Subject']) ? $message_headers['Subject'] : 'Mail message'; $esender->SetSubject($message_subject); - if ($this->Application->isDebugMode()) { - // set special header with event name, so it will be easier to determite what's actually was received + if ( $this->Application->isDebugMode() ) { + // set special header with event name, so it will be easier to determine what's actually was received $message_headers['X-Event-Name'] = $email_event_name . ' - ' . ($object->GetDBField('Type') == EmailEvent::EVENT_TYPE_ADMIN ? 'ADMIN' : 'USER'); } @@ -708,23 +715,23 @@ $event->status = $esender->Deliver() ? kEvent::erSUCCESS : kEvent::erFAIL; - if ($event->status == kEvent::erSUCCESS) { + if ( $event->status == kEvent::erSUCCESS ) { // all keys, that are not used in email sending are written to log record $send_keys = Array ('from_email', 'from_name', 'to_email', 'to_name', 'message'); foreach ($send_keys as $send_key) { unset($send_params[$send_key]); } $fields_hash = Array ( - 'fromuser' => $from_name.' ('.$from_email.')', - 'addressto' => $to_name.' ('.$to_email.')', + 'fromuser' => $from_name . ' (' . $from_email . ')', + 'addressto' => $to_name . ' (' . $to_email . ')', 'subject' => $message_subject, 'timestamp' => adodb_mktime(), 'event' => $email_event_name, 'EventParams' => serialize($send_params), ); - $this->Conn->doInsert($fields_hash, TABLE_PREFIX.'EmailLog'); + $this->Conn->doInsert($fields_hash, TABLE_PREFIX . 'EmailLog'); } } @@ -741,19 +748,20 @@ { static $prev_language_id = null; - if (!isset($language_id)) { + if ( !isset($language_id) ) { // restore language $language_id = $prev_language_id; } $this->Application->SetVar('m_lang', $language_id); + $language =& $this->Application->recallObject('lang.current'); - /* @var $lang_object kDBItem */ + /* @var $language LanguagesItem */ $language->Load($language_id); $this->Application->Phrases->LanguageId = $language_id; - $this->Application->Phrases->Phrases = Array(); + $this->Application->Phrases->Phrases = Array (); $prev_language_id = $language_id; // for restoring it later } @@ -870,8 +878,10 @@ * Fixes default recipient type * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterItemLoad(&$event) + protected function OnAfterItemLoad(&$event) { parent::OnAfterItemLoad($event); @@ -1011,8 +1021,10 @@ * Don't allow to enable/disable events in non-debug mode * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemCreate(&$event) + protected function OnBeforeItemCreate(&$event) { parent::OnBeforeItemCreate($event); @@ -1023,8 +1035,10 @@ * Don't allow to enable/disable events in non-debug mode * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemUpdate(&$event) + protected function OnBeforeItemUpdate(&$event) { parent::OnBeforeItemUpdate($event); Index: branches/5.2.x/core/units/helpers/minifiers/minify_helper.php =================================================================== diff -u -r14572 -r14628 --- branches/5.2.x/core/units/helpers/minifiers/minify_helper.php (.../minify_helper.php) (revision 14572) +++ branches/5.2.x/core/units/helpers/minifiers/minify_helper.php (.../minify_helper.php) (revision 14628) @@ -1,6 +1,6 @@ Application->GetVar($params['to'], ''); $this->Application->SetVar($params['to'], $files . '|' . $params['files']); return ''; } - if (array_key_exists('from', $params)) { + if ( array_key_exists('from', $params) ) { // get from queue $files = $this->Application->GetVar($params['from']); } @@ -82,32 +83,32 @@ $was_compressed = array_key_exists($hash, $this->compressInfo); - if ($was_compressed) { + if ( $was_compressed ) { $current_file = WRITEABLE . '/' . sprintf($file_mask, $this->compressInfo[$hash]); - if (!file_exists($current_file)) { + if ( !file_exists($current_file) ) { // when info exists, but file doesn't -> re-compress $was_compressed = false; } - if ($this->debugMode) { + if ( $this->debugMode ) { // check if any of listed files was changed since compressed file was created (only, when in debug mode) foreach ($files as $file) { - if (filemtime($file) > $this->compressInfo[$hash]) { + if ( filemtime($file) > $this->compressInfo[$hash] ) { $was_compressed = false; break; } } } } - if (!$was_compressed) { + if ( !$was_compressed ) { $string = ''; $path_length = strlen(FULL_PATH) + 1; foreach ($files as $file) { // add filename before for easier debugging - if ($this->debugMode) { + if ( $this->debugMode ) { $string .= '/* === File: ' . substr($file, $path_length) . ' === */' . "\n"; $string .= '/* ' . str_repeat('=', strlen(substr($file, $path_length)) + 14) . ' */' . "\n\n"; } @@ -117,8 +118,8 @@ } // remove previous version of compressed file - if (isset($current_file)) { - if (file_exists($current_file)) { + if ( isset($current_file) ) { + if ( file_exists($current_file) ) { unlink($current_file); } } @@ -131,7 +132,7 @@ // compress collected data $this->compressInfo[$hash] = adodb_mktime(); - if (!$this->debugMode) { + if ( !$this->debugMode ) { // don't compress merged js/css file in debug mode to allow js/css debugging $this->compressString($string, $extension); } Index: branches/5.2.x/core/kernel/nparser/nparser.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/kernel/nparser/nparser.php (.../nparser.php) (revision 14585) +++ branches/5.2.x/core/kernel/nparser/nparser.php (.../nparser.php) (revision 14628) @@ -1,6 +1,6 @@ Application->recallObject($prefix.'_TagProcessor'); + static $processors = Array (); + + if ( !isset($processors[$prefix]) ) { + $processors[$prefix] = $this->Application->recallObject($prefix . '_TagProcessor'); } - return $Processors[$prefix]; + return $processors[$prefix]; } - function SelectParam($params, $possible_names) + /** + * Not tag. Method for parameter selection from list in this TagProcessor + * + * @param Array $params + * @param Array $possible_names + * + * @return string + * @access protected + */ + protected function SelectParam($params, $possible_names) { - if (!is_array($params)) return; - if (!is_array($possible_names)) + if ( !is_array($params) ) { + return ''; + } - $possible_names = explode(',', $possible_names); - foreach ($possible_names as $name) - { - if( isset($params[$name]) ) return $params[$name]; + if ( !is_array($possible_names) ) { + $possible_names = explode(',', $possible_names); } - return false; + + foreach ($possible_names as $name) { + if ( isset($params[$name]) ) { + return $params[$name]; + } + } + + return ''; } function SetParams($params) Index: branches/5.2.x/core/units/helpers/user_helper.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/units/helpers/user_helper.php (.../user_helper.php) (revision 14585) +++ branches/5.2.x/core/units/helpers/user_helper.php (.../user_helper.php) (revision 14628) @@ -1,6 +1,6 @@ verifySuperAdmin(); if ($this->Application->isAdmin && ($username == 'root') || ($super_admin && $username == 'super-root')) { $root_password = $this->Application->ConfigValue('RootPass'); + $password_formatter =& $this->Application->recallObject('kPasswordFormatter'); + /* @var $password_formatter kPasswordFormatter */ if ($root_password != $password_formatter->EncryptPassword($password, 'b38')) { return LoginResult::INVALID_PASSWORD; @@ -214,13 +216,18 @@ } $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), Array ('InPortalSyncronize')); + /* @var $sync_manager UsersSyncronizeManager */ + $sync_manager->performAction('LogoutUser'); $this->Application->HandleEvent($dummy, 'u:OnBeforeLogout'); $user_id = USER_GUEST; $this->Application->SetVar('u.current_id', $user_id); + $object =& $this->Application->recallObject('u.current', null, Array('skip_autoload' => true)); + /* @var $object UsersItem */ + $object->Load($user_id); $this->Application->DestroySession(); @@ -285,20 +292,23 @@ $this->event->SetRedirectParam('js_redirect', 1); } - // syncronize login + // synchronize login $sync_manager =& $this->Application->recallObject('UsersSyncronizeManager', null, Array(), Array ('InPortalSyncronize')); + /* @var $sync_manager UsersSyncronizeManager */ + $sync_manager->performAction('LoginUser', $username, $password); } /** - * Sets correct interface language after sucessful login, based on user settings + * Sets correct interface language after successful login, based on user settings * - * @param kEvent $event + * @return void + * @access protected */ - function _processInterfaceLanguage() + protected function _processInterfaceLanguage() { - if (!$this->Application->isAdmin) { - return ; + if ( !$this->Application->isAdmin ) { + return; } $is_root = $this->Application->RecallVar('user_id') == USER_ROOT; @@ -315,9 +325,9 @@ $language_info = $this->Conn->GetRow($sql); $language_id = $language_info && $language_info['LanguageId'] ? $language_info['LanguageId'] : $user_language_id; - if ($user_language_id != $language_id) { - // first admin login OR language was delelted or disabled - if ($is_root) { + if ( $user_language_id != $language_id ) { + // first admin login OR language was deleted or disabled + if ( $is_root ) { $this->Application->StorePersistentVar('AdminLanguage', $language_id); } else { @@ -342,15 +352,18 @@ } /** - * Returns user object, used during login processings + * Returns user object, used during login processing * * @return UsersItem + * @access public */ - function &getUserObject() + public function &getUserObject() { $prefix_special = $this->Application->isAdmin ? 'u.current' : 'u'; // "u" used on front not to change theme + $object =& $this->Application->recallObject($prefix_special, null, Array('skip_autoload' => true)); - + /* @var $object UsersItem */ + return $object; } Index: branches/5.2.x/core/units/helpers/brackets_helper.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/helpers/brackets_helper.php (.../brackets_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/brackets_helper.php (.../brackets_helper.php) (revision 14628) @@ -1,6 +1,6 @@ getObject(); + /* @var $object kDBItem */ $temp = $this->getBrackets($event); - foreach($temp as $id => $record) - { - if( $record[$this->max_field] == '∞' ) - { + foreach ($temp as $id => $record) { + if ( $record[$this->max_field] == '∞' ) { $temp[$id][$this->max_field] = -1; } } @@ -352,23 +357,22 @@ } // sort brackets by 2nd column (Max values) - uasort($temp, Array(&$this, 'compareBrackets') ); + uasort($temp, Array (&$this, 'compareBrackets')); reset($temp); $first_item = each($temp); $first_item_key = $first_item['key']; $linked_info = $object->getLinkedInfo(); $sql = 'SELECT %s FROM %s WHERE %s = %s'; $ids = $this->Conn->GetCol( sprintf($sql, $object->IDField, $object->TableName, $linked_info['ForeignKey'], $linked_info['ParentId']) ); - if( is_array($ids) ) - { - usort($ids, Array(&$this, 'sortBracketIDs') ); + + if ( is_array($ids) ) { + usort($ids, Array (&$this, 'sortBracketIDs')); } // $min_id = min( min($ids) - 1, -1 ); - foreach($temp as $key => $record) - { + foreach ($temp as $key => $record) { $temp[$key][$this->min_field] = $start; $start = $temp[$key][$this->max_field]; } @@ -455,14 +459,18 @@ } /** - * Replate infinity mark with -1 before saving to db + * Replace infinity mark with -1 before saving to db * * @param kEvent $event */ function replaceInfinity(&$event) { $object =& $event->getObject(); - if($object->GetDBField($this->max_field) == '∞') $object->SetDBField($this->max_field, -1); + /* @var $object kDBItem */ + + if ( $object->GetDBField($this->max_field) == '∞' ) { + $object->SetDBField($this->max_field, -1); + } } } \ No newline at end of file Index: branches/5.2.x/core/units/helpers/minifiers/js_minify_helper.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/helpers/minifiers/js_minify_helper.php (.../js_minify_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/minifiers/js_minify_helper.php (.../js_minify_helper.php) (revision 14628) @@ -68,6 +68,9 @@ /** * Perform minification, return result + * + * @param string $input + * @return string */ public function minify($input) { @@ -110,6 +113,10 @@ * ACTION_KEEP_A = Output A. Copy B to A. Get the next B. * ACTION_DELETE_A = Copy B to A. Get the next B. * ACTION_DELETE_A_B = Get the next B. + * + * @param int $command + * @return void + * @access protected */ protected function action($command) { @@ -224,6 +231,10 @@ /** * Is $c a letter, digit, underscore, dollar sign, escape, or non-ASCII? + * + * @param string $c + * @return bool + * @access protected */ protected function isAlphaNum($c) { @@ -244,6 +255,8 @@ return $get; } } + + return ''; } protected function multipleLineComment() @@ -270,6 +283,8 @@ } $comment .= $get; } + + return ''; } /** Index: branches/5.2.x/core/kernel/utility/unit_config_reader.php =================================================================== diff -u -r14575 -r14628 --- branches/5.2.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 14575) +++ branches/5.2.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 14628) @@ -1,6 +1,6 @@ configData[$prefix]; - $deps = getArrayValue($config, '_Dependencies'); + $dependencies = getArrayValue($config, '_Dependencies'); + /* @var $dependencies Array */ - if (!$deps) { + if ( !$dependencies ) { return ; } - foreach ($deps as $real_class => $requires) { + foreach ($dependencies as $real_class => $requires) { foreach ($requires as $class) { $this->Application->registerDependency($real_class, $class); } @@ -720,9 +721,9 @@ function postProcessConfig($prefix, $config_key, $dst_prefix_var) { $main_config =& $this->configData[$prefix]; - $sub_configs = isset($main_config[$config_key]) && $main_config[$config_key] ? $main_config[$config_key] : false; // getArrayValue($main_config, $config_key); - if (!$sub_configs) { - return array(); + $sub_configs = isset($main_config[$config_key]) && $main_config[$config_key] ? $main_config[$config_key] : Array (); + if ( !$sub_configs ) { + return Array (); } unset($main_config[$config_key]); @@ -766,7 +767,7 @@ $config_found = file_exists(FULL_PATH . $filename) && $this->configAllowed($filename); if (defined('DEBUG_MODE') && DEBUG_MODE && defined('DBG_PROFILE_INCLUDES') && DBG_PROFILE_INCLUDES) { - if ( in_array($filename, get_required_files()) ) { + if ( in_array($filename, get_included_files()) ) { return ''; } Index: branches/5.2.x/core/kernel/constants.php =================================================================== diff -u -r14437 -r14628 --- branches/5.2.x/core/kernel/constants.php (.../constants.php) (revision 14437) +++ branches/5.2.x/core/kernel/constants.php (.../constants.php) (revision 14628) @@ -1,6 +1,6 @@ isAdmin) { - // don't show debugger buttons on front (if not overrided in "debug.php") + // don't show debugger buttons on front (if not overridden in "debug.php") kUtil::safeDefine('DBG_TOOLBAR_BUTTONS', 0); } Index: branches/5.2.x/core/units/logs/session_logs/session_log_eh.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/units/logs/session_logs/session_log_eh.php (.../session_log_eh.php) (revision 14585) +++ branches/5.2.x/core/units/logs/session_logs/session_log_eh.php (.../session_log_eh.php) (revision 14628) @@ -1,6 +1,6 @@ Name == 'OnMassDelete' && $type == 'before') { $ids = $event->getEventParam('ids'); Index: branches/5.2.x/core/units/configuration/configuration.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/configuration/configuration.php (.../configuration.php) (revision 14244) +++ branches/5.2.x/core/units/configuration/configuration.php (.../configuration.php) (revision 14628) @@ -1,6 +1,6 @@ Application->GetVar('section'); - $keys_hash[$this->IDField] = $this->ID; - return parent::GetKeyClause($method, $keys_hash); - } + /** + * Returns part of SQL WHERE clause identifying the record, ex. id = 25 + * + * @param string $method Child class may want to know who called GetKeyClause, Load(), Update(), Delete() send its names as method + * @param Array $keys_hash alternative, then item id, keys hash to load item by + * @see kDBItem::Load() + * @see kDBItem::Update() + * @see kDBItem::Delete() + * + * @return string + * @access protected + */ + protected function GetKeyClause($method = null, $keys_hash = null) + { + $keys_hash['Section'] = $this->Application->GetVar('section'); + $keys_hash[$this->IDField] = $this->GetID(); - /** - * Set's field error, if pseudo passed not found then create it with message text supplied. - * Don't owerrite existing pseudo translation. - * - * @param string $field - * @param string $pseudo - * @param string $error_label - */ - function SetError($field, $pseudo, $error_label = null, $error_params = null) - { - if (!parent::SetError($field, $pseudo, $error_label, $error_params)) { - // this field already has an error -> don't overwrite it - return false; - } + return parent::GetKeyClause($method, $keys_hash); + } - $list_errors = $this->Application->GetVar('errors_' . $this->getPrefixSpecial(), Array ()); - $list_errors[ $this->GetDBField('VariableName') ] = $this->GetErrorMsg($field); - $this->Application->SetVar('errors_' . $this->getPrefixSpecial(), $list_errors); + /** + * Set's field error, if pseudo passed not found then create it with message text supplied. + * Don't overwrite existing pseudo translation. + * + * @param string $field + * @param string $pseudo + * @param string $error_label + * @param Array $error_params + * + * @return bool + * @access public + */ + public function SetError($field, $pseudo, $error_label = null, $error_params = null) + { + if ( !parent::SetError($field, $pseudo, $error_label, $error_params) ) { + // this field already has an error -> don't overwrite it + return false; } - } \ No newline at end of file + $list_errors = $this->Application->GetVar('errors_' . $this->getPrefixSpecial(), Array ()); + $list_errors[ $this->GetDBField('VariableName') ] = $this->GetErrorMsg($field); + $this->Application->SetVar('errors_' . $this->getPrefixSpecial(), $list_errors); + + return true; + } +} \ No newline at end of file Index: branches/5.2.x/core/kernel/db/cat_event_handler.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 14585) +++ branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ getObject(); + /* @var $object kDBItem */ + $id = $this->getPassedID($event); - if ($object->Load($id)) { + + if ( $object->Load($id) ) { $actions =& $this->Application->recallObject('kActions'); - $actions->Set($event->getPrefixSpecial().'_id', $object->GetID() ); + /* @var $actions Params */ + $actions->Set($event->getPrefixSpecial() . '_id', $object->GetID()); + $use_pending_editing = $this->Application->getUnitOption($event->Prefix, 'UsePendingEditing'); - if ($use_pending_editing && $event->Special != 'original') { - $this->Application->SetVar($event->Prefix.'.original_id', $object->GetDBField('OrgId')); + + if ( $use_pending_editing && $event->Special != 'original' ) { + $this->Application->SetVar($event->Prefix . '.original_id', $object->GetDBField('OrgId')); } } else { @@ -62,11 +70,13 @@ } /** - * Checks permissions of user + * Checks user permission to execute given $event * * @param kEvent $event + * @return bool + * @access public */ - function CheckPermission(&$event) + public function CheckPermission(&$event) { if (!$this->Application->isAdmin) { if ($event->Name == 'OnSetSortingDirect') { @@ -204,11 +214,16 @@ * Add selected items to clipboard with mode = COPY (CLONE) * * @param kEvent $event + * @return void + * @access protected */ - function OnCopy(&$event) + protected function OnCopy(&$event) { $this->Application->RemoveVar('clipboard'); + $clipboard_helper =& $this->Application->recallObject('ClipboardHelper'); + /* @var $clipboard_helper kClipboardHelper */ + $clipboard_helper->setClipboard($event, 'copy', $this->StoreSelectedIDs($event)); $this->clearSelectedIDs($event); } @@ -217,11 +232,15 @@ * Add selected items to clipboard with mode = CUT * * @param kEvent $event + * @return void + * @access protected */ - function OnCut(&$event) + protected function OnCut(&$event) { $this->Application->RemoveVar('clipboard'); $clipboard_helper =& $this->Application->recallObject('ClipboardHelper'); + /* @var $clipboard_helper kClipboardHelper */ + $clipboard_helper->setClipboard($event, 'cut', $this->StoreSelectedIDs($event)); $this->clearSelectedIDs($event); } @@ -250,30 +269,33 @@ * Performs category item paste * * @param kEvent $event + * @return void + * @access protected */ - function OnPaste(&$event) + protected function OnPaste(&$event) { - if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1) || !$this->_checkPastePermission($event)) { + if ( $this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1) || !$this->_checkPastePermission($event) ) { $event->status = kEvent::erFAIL; return; } $clipboard_data = $event->getEventParam('clipboard_data'); - if (!$clipboard_data['cut'] && !$clipboard_data['copy']) { - return false; + if ( !$clipboard_data['cut'] && !$clipboard_data['copy'] ) { + return; } - if ($clipboard_data['copy']) { - $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); + if ( $clipboard_data['copy'] ) { + $temp =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler'); /* @var $temp kTempTablesHandler */ $this->Application->SetVar('ResetCatBeforeClone', 1); // used in "kCatDBEventHandler::OnBeforeClone" $temp->CloneItems($event->Prefix, $event->Special, $clipboard_data['copy']); } - if ($clipboard_data['cut']) { - $object =& $this->Application->recallObject($event->getPrefixSpecial().'.item', $event->Prefix, Array('skip_autoload' => true)); + if ( $clipboard_data['cut'] ) { + $object =& $this->Application->recallObject($event->getPrefixSpecial() . '.item', $event->Prefix, Array ('skip_autoload' => true)); + /* @var $object kCatDBItem */ foreach ($clipboard_data['cut'] as $id) { $object->Load($id); @@ -288,44 +310,54 @@ * by calling its Delete method if sub-item has AutoDelete set to true in its config file * * @param kEvent $event + * @return void + * @access protected */ - function OnMassDelete(&$event) + protected function OnMassDelete(&$event) { - if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { + if ( $this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1) ) { $event->status = kEvent::erFAIL; return; } - $event->status=kEvent::erSUCCESS; - $ids = $this->StoreSelectedIDs($event); - $to_delete = array(); - if ($recycle_bin = $this->Application->ConfigValue('RecycleBinFolder')) { - $rb =& $this->Application->recallObject('c.recycle', null, array('skip_autoload' => true)); + $to_delete = Array (); + + if ( $recycle_bin = $this->Application->ConfigValue('RecycleBinFolder') ) { + $rb =& $this->Application->recallObject('c.recycle', null, array ('skip_autoload' => true)); + /* @var $rb CategoriesItem */ + $rb->Load($recycle_bin); - $object =& $this->Application->recallObject($event->Prefix.'.recycleitem', null, Array ('skip_autoload' => true)); + + $object =& $this->Application->recallObject($event->Prefix . '.recycleitem', null, Array ('skip_autoload' => true)); + /* @var $object kCatDBItem */ + foreach ($ids as $id) { $object->Load($id); - if (preg_match('/^'.preg_quote($rb->GetDBField('ParentPath'),'/').'/', $object->GetDBField('ParentPath'))) { + + if ( preg_match('/^' . preg_quote($rb->GetDBField('ParentPath'), '/') . '/', $object->GetDBField('ParentPath')) ) { $to_delete[] = $id; continue; } + $object->MoveToCat($recycle_bin); } + $ids = $to_delete; } - $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); + $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler'); + /* @var $temp_handler kTempTablesHandler */ $event->setEventParam('ids', $ids); $this->customProcessing($event, 'before'); $ids = $event->getEventParam('ids'); - if($ids) - { - $temp->DeleteItems($event->Prefix, $event->Special, $ids); + if ( $ids ) { + $temp_handler->DeleteItems($event->Prefix, $event->Special, $ids); } + $this->clearSelectedIDs($event); } @@ -464,6 +496,8 @@ } $p_item =& $this->Application->recallObject($related_prefix.'.current', null, Array('skip_autoload' => true)); + /* @var $p_item kCatDBItem */ + $p_item->Load( (int)$id ); $p_resource_id = $p_item->GetDBField('ResourceId'); @@ -542,11 +576,14 @@ } /** - * Apply filters to list + * Apply any custom changes to list's sql query * * @param kEvent $event + * @return void + * @access protected + * @see kDBEventHandler::OnListBuild() */ - function SetCustomQuery(&$event) + protected function SetCustomQuery(&$event) { parent::SetCustomQuery($event); @@ -697,17 +734,21 @@ /** * Adds calculates fields for item statuses * - * @param kCatDBItem $object + * @param kDBItem|kDBList $object * @param kEvent $event + * @return void + * @access protected */ - function prepareObject(&$object, &$event) + protected function prepareObject(&$object, &$event) { $this->prepareItemStatuses($event); $object->addCalculatedField('CachedNavbar', 'l'.$this->Application->GetVar('m_lang').'_CachedNavbar'); if ($event->Special == 'export' || $event->Special == 'import') { $export_helper =& $this->Application->recallObject('CatItemExportHelper'); + /* @var $export_helper kCatDBItemExportHelper */ + $export_helper->prepareExportColumns($event); } } @@ -763,24 +804,32 @@ } - function CalculateHotLimit(&$event) + /** + * Calculates hot limit for current item's table + * + * @param kEvent $event + * @return float + * @access protected + */ + protected function CalculateHotLimit(&$event) { $property_map = $this->Application->getUnitOption($event->Prefix, 'ItemPropertyMappings'); - if (!$property_map) { - return; + if ( !$property_map ) { + return 0.00; } $click_field = $property_map['ClickField']; $last_hot = $this->Application->ConfigValue($property_map['MaxHotNumber']) - 1; - $sql = 'SELECT '.$click_field.' FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' - ORDER BY '.$click_field.' DESC - LIMIT '.$last_hot.', 1'; + $sql = 'SELECT ' . $click_field . ' + FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + ORDER BY ' . $click_field . ' DESC + LIMIT ' . $last_hot . ', 1'; $res = $this->Conn->GetCol($sql); $hot_limit = (double)array_shift($res); - if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) { + if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) { $serial_name = $this->Application->incrementCacheSerial($event->Prefix, null, false); $this->Application->setCache($property_map['HotLimit'] . '[%' . $serial_name . '%]', $hot_limit); } @@ -795,8 +844,10 @@ * Moves item to preferred category, updates item hits * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemUpdate(&$event) + protected function OnBeforeItemUpdate(&$event) { parent::OnBeforeItemUpdate($event); @@ -805,62 +856,74 @@ // update hits field $property_map = $this->Application->getUnitOption($event->Prefix, 'ItemPropertyMappings'); - if ($property_map) { + if ( $property_map ) { $click_field = $property_map['ClickField']; - if( $this->Application->isAdminUser && ($this->Application->GetVar($click_field.'_original') !== false) && - floor($this->Application->GetVar($click_field.'_original')) != $object->GetDBField($click_field) ) - { - $sql = 'SELECT MAX('.$click_field.') FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' - WHERE FLOOR('.$click_field.') = '.$object->GetDBField($click_field); - $hits = ( $res = $this->Conn->GetOne($sql) ) ? $res + 0.000001 : $object->GetDBField($click_field); + if ( $this->Application->isAdminUser && ($this->Application->GetVar($click_field . '_original') !== false) && floor($this->Application->GetVar($click_field . '_original')) != $object->GetDBField($click_field) ) { + $sql = 'SELECT MAX(' . $click_field . ') + FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + WHERE FLOOR(' . $click_field . ') = ' . $object->GetDBField($click_field); + $hits = ($res = $this->Conn->GetOne($sql)) ? $res + 0.000001 : $object->GetDBField($click_field); + $object->SetDBField($click_field, $hits); } } // change category $target_category = $object->GetDBField('CategoryId'); - if ($object->GetOriginalField('CategoryId') != $target_category) { + if ( $object->GetOriginalField('CategoryId') != $target_category ) { $object->MoveToCat($target_category); } } /** - * Load price from temp table if product mode is temp table + * Occurs after loading item, 'id' parameter + * allows to get id of item that was loaded * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterItemLoad(&$event) + protected function OnAfterItemLoad(&$event) { + parent::OnAfterItemLoad($event); + $special = substr($event->Special, -6); $object =& $event->getObject(); /* @var $object kCatDBItem */ - if ($special == 'import' || $special == 'export') { + if ( $special == 'import' || $special == 'export' ) { $image_data = $object->getPrimaryImageData(); - if ($image_data) { + if ( $image_data ) { $thumbnail_image = $image_data[$image_data['LocalThumb'] ? 'ThumbPath' : 'ThumbUrl']; - if ($image_data['SameImages']) { + if ( $image_data['SameImages'] ) { $full_image = ''; } else { $full_image = $image_data[$image_data['LocalImage'] ? 'LocalPath' : 'Url']; } + $object->SetDBField('ThumbnailImage', $thumbnail_image); $object->SetDBField('FullImage', $full_image); $object->SetDBField('ImageAlt', $image_data['AltName']); } } - // substituiting pending status value for pending editing - if ($object->HasField('OrgId') && $object->GetDBField('OrgId') > 0 && $object->GetDBField('Status') == -2) { - $options = $object->GetFieldOption('Status', 'options'); + // substituting pending status value for pending editing + if ( $object->HasField('OrgId') && $object->GetDBField('OrgId') > 0 && $object->GetDBField('Status') == -2 ) { + $new_options = Array (); + $options = $object->GetFieldOption('Status', 'options', false, Array ()); + foreach ($options as $key => $val) { - if ($key == 2) $key = -2; + if ( $key == 2 ) { + $key = -2; + } + $new_options[$key] = $val; } + $object->SetFieldOption('Status', 'options', $new_options); } @@ -878,23 +941,29 @@ $file_helper->LoadItemFiles($object); } - if ( array_key_exists('MoreCategories', $object->VirtualFields) ) { + if ( $object->isVirtualField('MoreCategories') ) { // set item's additional categories to virtual field (used in editing) $item_categories = $this->getItemCategories($object->GetDBField('ResourceId')); - $object->SetDBField('MoreCategories', $item_categories ? '|'.implode('|', $item_categories).'|' : ''); + $object->SetDBField('MoreCategories', $item_categories ? '|' . implode('|', $item_categories) . '|' : ''); } } + /** + * Occurs after updating item + * + * @param kEvent $event + * @access public + */ function OnAfterItemUpdate(&$event) { $this->CalculateHotLimit($event); - if ( substr($event->Special, -6) == 'import') { + if ( substr($event->Special, -6) == 'import' ) { $this->setCustomExportColumns($event); } $object =& $event->getObject(); - /* @var $object kDBItem */ + /* @var $object kCatDBItem */ if ( !$this->Application->isAdmin ) { $image_helper =& $this->Application->recallObject('ImageHelper'); @@ -909,40 +978,44 @@ // process file upload in virtual fields $file_helper->SaveItemFiles($object); - if ($event->Special != '-item') { + if ( $event->Special != '-item' ) { // don't touch categories during cloning $this->processAdditionalCategories($object, 'update'); } } $recycle_bin = $this->Application->ConfigValue('RecycleBinFolder'); - if ($this->Application->isAdminUser && $recycle_bin) { + if ( $this->Application->isAdminUser && $recycle_bin ) { $sql = 'SELECT CategoryId FROM ' . $this->Application->getUnitOption('ci', 'TableName') . ' WHERE ItemResourceId = ' . $object->GetDBField('ResourceId') . ' AND PrimaryCat = 1'; $primary_category = $this->Conn->GetOne($sql); - if ($primary_category == $recycle_bin) { + if ( $primary_category == $recycle_bin ) { $event->CallSubEvent('OnAfterItemDelete'); } } } /** - * sets values for import process + * Sets values for import process * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterItemCreate(&$event) + protected function OnAfterItemCreate(&$event) { - if ( substr($event->Special, -6) == 'import') { + parent::OnAfterItemCreate($event); + + if ( substr($event->Special, -6) == 'import' ) { $this->setCustomExportColumns($event); } if ( !$this->Application->isAdmin ) { $object =& $event->getObject(); - /* @var $object kDBItem */ + /* @var $object kCatDBItem */ $image_helper =& $this->Application->recallObject('ImageHelper'); /* @var $image_helper ImageHelper */ @@ -956,7 +1029,7 @@ // process file upload in virtual fields $file_helper->SaveItemFiles($object); - if ($event->Special != '-item') { + if ( $event->Special != '-item' ) { // don't touch categories during cloning $this->processAdditionalCategories($object, 'create'); } @@ -1001,6 +1074,8 @@ $keywords = kUtil::unhtmlentities( trim($this->Application->GetVar('keywords')) ); $query_object =& $this->Application->recallObject('HTTPQuery'); + /* @var $query_object kHTTPQuery */ + $sql = 'SHOW TABLES LIKE "'.$search_table.'"'; if(!isset($query_object->Get['keywords']) && @@ -1054,12 +1129,11 @@ $search_config_map = Array(); foreach ($field_list as $key => $field) { - $options = $object->getFieldOptions($field); $local_table = TABLE_PREFIX.$search_config[$field]['TableName']; $weight_sum += $search_config[$field]['Priority']; // counting weight sum; used when making relevance clause // processing multilingual fields - if (getArrayValue($options, 'formatter') == 'kMultiLanguage') { + if ( $object->GetFieldOption($field, 'formatter') == 'kMultiLanguage' ) { $field_list[$key.'_primary'] = 'l'.$this->Application->GetDefaultLanguageId().'_'.$field; $field_list[$key] = 'l'.$lang.'_'.$field; @@ -1289,9 +1363,11 @@ function OnAdvancedSearch(&$event) { $query_object =& $this->Application->recallObject('HTTPQuery'); - if(!isset($query_object->Post['andor'])) - { - return; // used when navigating by pages or changing sorting in search results + /* @var $query_object kHTTPQuery */ + + if ( !isset($query_object->Post['andor']) ) { + // used when navigating by pages or changing sorting in search results + return; } $this->Application->RemoveVar('keywords'); @@ -1305,7 +1381,10 @@ $search_config = $this->Conn->Query($sql); $lang = $this->Application->GetVar('m_lang'); + $object =& $event->getObject(); + /* @var $object kDBList */ + $object->SetPage(1); $items_table = $this->Application->getUnitOption($event->Prefix, 'TableName'); @@ -1342,13 +1421,11 @@ $condition_mode = 'WHERE'; // field processing - - $options = $object->getFieldOptions($field); $local_table = TABLE_PREFIX.$record['TableName']; $weight_sum += $record['Priority']; // counting weight sum; used when making relevance clause // processing multilingual fields - if (getArrayValue($options, 'formatter') == 'kMultiLanguage') { + if ( $object->GetFieldOption($field, 'formatter') == 'kMultiLanguage' ) { $field_name = 'l'.$lang.'_'.$field; } else { @@ -1644,8 +1721,20 @@ return $condition; } - function getHuman($type, $search_data) + /** + * Returns human readable representation of searched data to be placed in search log + * @param string $type + * @param Array $search_data + * @return string + * @access protected + */ + protected function getHuman($type, $search_data) { + // all 3 variables are retrieved from $search_data array + /* @var $search_config Array */ + /* @var $verb string */ + /* @var $value string */ + $type = ucfirst(strtolower($type)); extract($search_data); @@ -1686,10 +1775,10 @@ return '"'.$ret.'"'; break; } + + return ''; } - - /** * Set's correct page for list * based on data provided with event @@ -1864,20 +1953,25 @@ * Create/Update primary image record in info found in imported data * * @param kEvent $event + * @return void + * @access protected */ - function restorePrimaryImage(&$event) + protected function restorePrimaryImage(&$event) { $object =& $event->getObject(); + /* @var $object kCatDBItem */ $has_image_info = $object->GetDBField('ImageAlt') && ($object->GetDBField('ThumbnailImage') || $object->GetDBField('FullImage')); - if (!$has_image_info) { - return false; + if ( !$has_image_info ) { + return ; } $image_data = $object->getPrimaryImageData(); - $image =& $this->Application->recallObject('img', null, Array('skip_autoload' => true)); - if ($image_data) { + $image =& $this->Application->recallObject('img', null, Array ('skip_autoload' => true)); + /* @var $image kDBItem */ + + if ( $image_data ) { $image->Load($image_data['ImageId']); } else { @@ -1889,23 +1983,23 @@ $image->SetDBField('AltName', $object->GetDBField('ImageAlt')); - if ($object->GetDBField('ThumbnailImage')) { - $thumbnail_field = $this->isURL( $object->GetDBField('ThumbnailImage') ) ? 'ThumbUrl' : 'ThumbPath'; - $image->SetDBField($thumbnail_field, $object->GetDBField('ThumbnailImage') ); + if ( $object->GetDBField('ThumbnailImage') ) { + $thumbnail_field = $this->isURL($object->GetDBField('ThumbnailImage')) ? 'ThumbUrl' : 'ThumbPath'; + $image->SetDBField($thumbnail_field, $object->GetDBField('ThumbnailImage')); $image->SetDBField('LocalThumb', $thumbnail_field == 'ThumbPath' ? 1 : 0); } - if (!$object->GetDBField('FullImage')) { + if ( !$object->GetDBField('FullImage') ) { $image->SetDBField('SameImages', 1); } else { $image->SetDBField('SameImages', 0); - $full_field = $this->isURL( $object->GetDBField('FullImage') ) ? 'Url' : 'LocalPath'; - $image->SetDBField($full_field, $object->GetDBField('FullImage') ); + $full_field = $this->isURL($object->GetDBField('FullImage')) ? 'Url' : 'LocalPath'; + $image->SetDBField($full_field, $object->GetDBField('FullImage')); $image->SetDBField('LocalImage', $full_field == 'LocalPath' ? 1 : 0); } - if ($image->isLoaded()) { + if ( $image->isLoaded() ) { $image->Update(); } else { @@ -1927,8 +2021,10 @@ { parent::OnNew($event); - if ($event->Special == 'import' || $event->Special == 'export') { + if ( $event->Special == 'import' || $event->Special == 'export' ) { $export_helper =& $this->Application->recallObject('CatItemExportHelper'); + /* @var $export_helper kCatDBItemExportHelper */ + $export_helper->setRequiredFields($event); } } @@ -1940,13 +2036,14 @@ */ function OnProcessSelected(&$event) { + $dst_field = $this->Application->RecallVar('dst_field'); $selected_ids = $this->Application->GetVar('selected_ids'); - $dst_field = $this->Application->RecallVar('dst_field'); - - if ($dst_field == 'ItemCategory') { + if ( $dst_field == 'ItemCategory' ) { // Item Edit -> Categories Tab -> New Categories $object =& $event->getObject(); + /* @var $object kCatDBItem */ + $category_ids = explode(',', $selected_ids['c']); foreach ($category_ids as $category_id) { $object->assignToCategory($category_id); @@ -1956,12 +2053,10 @@ if ($dst_field == 'ImportCategory') { // Tools -> Import -> Item Import -> Select Import Category $this->Application->StoreVar('ImportCategory', $selected_ids['c']); -// $this->Application->StoreVar($event->getPrefixSpecial().'_ForceNotValid', 1); // not to loose import/export values on form refresh $url_params = Array ( $event->getPrefixSpecial() . '_id' => 0, $event->getPrefixSpecial() . '_event' => 'OnExportBegin', -// 'm_opener' => 's', ); $this->Application->EventManager->openerStackChange($url_params); @@ -1978,18 +2073,21 @@ function OnSaveSettings(&$event) { $event->redirect = false; - $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); - if ($items_info) { + $items_info = $this->Application->GetVar($event->getPrefixSpecial(true)); + + if ( $items_info ) { list($id, $field_values) = each($items_info); - $object =& $event->getObject( Array('skip_autoload' => true) ); + $object =& $event->getObject(Array ('skip_autoload' => true)); + /* @var $object kDBItem */ + $object->SetFieldsFromHash($field_values); $field_values['ImportFilename'] = $object->GetDBField('ImportFilename'); //if upload formatter has renamed the file during moving !!! $field_values['ImportSource'] = 2; $field_values['ImportLocalFilename'] = $object->GetDBField('ImportFilename'); $items_info[$id] = $field_values; - $this->Application->StoreVar($event->getPrefixSpecial().'_ItemsInfo', serialize($items_info)); + $this->Application->StoreVar($event->getPrefixSpecial() . '_ItemsInfo', serialize($items_info)); } } @@ -2003,9 +2101,15 @@ $this->Application->StoreVar('ImportCategory', $this->Application->getBaseCategory()); } + /** + * Cancels item editing + * @param kEvent $event + * @return void + * @todo Used? + */ function OnCancelAction(&$event) { - $event->setRedirectParams(Array('pass' => 'all,'.$event->GetPrefixSpecial()), true); + $event->setRedirectParams(Array ('pass' => 'all,' . $event->getPrefixSpecial()), true); $event->redirect = $this->Application->GetVar('cancel_template'); } @@ -2021,101 +2125,120 @@ function cacheItemOwner(&$event, $id_field, $cached_field) { $object =& $event->getObject(); + /* @var $object kDBItem */ $user_id = $object->GetDBField($id_field); $options = $object->GetFieldOptions($id_field); - if (isset($options['options'][$user_id])) { + + if ( isset($options['options'][$user_id]) ) { $object->SetDBField($cached_field, $options['options'][$user_id]); } else { $id_field = $this->Application->getUnitOption('u', 'IDField'); $table_name = $this->Application->getUnitOption('u', 'TableName'); $sql = 'SELECT Login - FROM '.$table_name.' - WHERE '.$id_field.' = '.$user_id; + FROM ' . $table_name . ' + WHERE ' . $id_field . ' = ' . $user_id; $object->SetDBField($cached_field, $this->Conn->GetOne($sql)); } } /** - * Saves item beeing edited into temp table + * Saves edited item into temp table + * If there is no id, new item is created in temp table * * @param kEvent $event + * @return void + * @access protected */ - function OnPreSave(&$event) + protected function OnPreSave(&$event) { parent::OnPreSave($event); + $use_pending_editing = $this->Application->getUnitOption($event->Prefix, 'UsePendingEditing'); - if ($event->status == kEvent::erSUCCESS && $use_pending_editing) { + + if ( $event->status == kEvent::erSUCCESS && $use_pending_editing ) { // decision: clone or not clone $object =& $event->getObject(); - if ($object->GetID() == 0 || $object->GetDBField('OrgId') > 0) { + /* @var $object kCatDBItem */ + + if ( $object->GetID() == 0 || $object->GetDBField('OrgId') > 0 ) { // new items or cloned items shouldn't be cloned again - return true; + return ; } + $perm_helper =& $this->Application->recallObject('PermissionsHelper'); + /* @var $perm_helper kPermissionsHelper */ + $owner_field = $this->getOwnerField($event->Prefix); - if ($perm_helper->ModifyCheckPermission($object->GetDBField($owner_field), $object->GetDBField('CategoryId'), $event->Prefix) == 2) { + if ( $perm_helper->ModifyCheckPermission($object->GetDBField($owner_field), $object->GetDBField('CategoryId'), $event->Prefix) == 2 ) { // 1. clone original item - $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); - $cloned_ids = $temp_handler->CloneItems($event->Prefix, $event->Special, Array($object->GetID()), null, null, null, true); - $ci_table = $this->Application->GetTempName(TABLE_PREFIX.'CategoryItems'); + $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler'); + /* @var $temp_handler kTempTablesHandler */ + $cloned_ids = $temp_handler->CloneItems($event->Prefix, $event->Special, Array ($object->GetID()), null, null, null, true); + $ci_table = $this->Application->GetTempName(TABLE_PREFIX . 'CategoryItems'); + // 2. delete record from CategoryItems (about cloned item) that was automatically created during call of Create method of kCatDBItem $sql = 'SELECT ResourceId - FROM '.$object->TableName.' - WHERE '.$object->IDField.' = '.$cloned_ids[0]; + FROM ' . $object->TableName . ' + WHERE ' . $object->IDField . ' = ' . $cloned_ids[0]; $clone_resource_id = $this->Conn->GetOne($sql); - $sql = 'DELETE FROM '.$ci_table.' - WHERE ItemResourceId = '.$clone_resource_id.' AND PrimaryCat = 1'; + $sql = 'DELETE FROM ' . $ci_table . ' + WHERE ItemResourceId = ' . $clone_resource_id . ' AND PrimaryCat = 1'; $this->Conn->Query($sql); // 3. copy main item categoryitems to cloned item - $sql = ' INSERT INTO '.$ci_table.' (CategoryId, ItemResourceId, PrimaryCat, ItemPrefix, Filename) - SELECT CategoryId, '.$clone_resource_id.' AS ItemResourceId, PrimaryCat, ItemPrefix, Filename - FROM '.$ci_table.' - WHERE ItemResourceId = '.$object->GetDBField('ResourceId'); + $sql = ' INSERT INTO ' . $ci_table . ' (CategoryId, ItemResourceId, PrimaryCat, ItemPrefix, Filename) + SELECT CategoryId, ' . $clone_resource_id . ' AS ItemResourceId, PrimaryCat, ItemPrefix, Filename + FROM ' . $ci_table . ' + WHERE ItemResourceId = ' . $object->GetDBField('ResourceId'); $this->Conn->Query($sql); // 4. put cloned id to OrgId field of item being cloned - $sql = 'UPDATE '.$object->TableName.' - SET OrgId = '.$object->GetID().' - WHERE '.$object->IDField.' = '.$cloned_ids[0]; + $sql = 'UPDATE ' . $object->TableName . ' + SET OrgId = ' . $object->GetID() . ' + WHERE ' . $object->IDField . ' = ' . $cloned_ids[0]; $this->Conn->Query($sql); // 5. substitute id of item being cloned with clone id - $this->Application->SetVar($event->getPrefixSpecial().'_id', $cloned_ids[0]); + $this->Application->SetVar($event->getPrefixSpecial() . '_id', $cloned_ids[0]); $selected_ids = $this->getSelectedIDs($event, true); $selected_ids[ array_search($object->GetID(), $selected_ids) ] = $cloned_ids[0]; $this->StoreSelectedIDs($event, $selected_ids); // 6. delete original item from temp table - $temp_handler->DeleteItems($event->Prefix, $event->Special, Array($object->GetID())); + $temp_handler->DeleteItems($event->Prefix, $event->Special, Array ($object->GetID())); } } } /** - * Sets default expiration based on module setting + * Sets item's owner field * * @param kEvent $event + * @return void + * @access protected */ - function OnPreCreate(&$event) + protected function OnPreCreate(&$event) { parent::OnPreCreate($event); - if ($event->status == kEvent::erSUCCESS) { - $object =& $event->getObject(); - $owner_field = $this->getOwnerField($event->Prefix); - - $object->SetDBField($owner_field, $this->Application->RecallVar('user_id')); + if ( $event->status != kEvent::erSUCCESS ) { + return ; } + + $object =& $event->getObject(); + /* @var $object kDBItem */ + + $owner_field = $this->getOwnerField($event->Prefix); + $object->SetDBField($owner_field, $this->Application->RecallVar('user_id')); } /** @@ -2129,16 +2252,21 @@ } /** - * Occures before an item is cloneded - * Id of ORIGINAL item is passed as event' 'id' param - * Do not call object' Update method in this event, just set needed fields! + * Occurs before an item has been cloned + * Id of newly created item is passed as event' 'id' param * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeClone(&$event) + protected function OnBeforeClone(&$event) { - if ($this->Application->GetVar('ResetCatBeforeClone')) { + parent::OnBeforeClone($event); + + if ( $this->Application->GetVar('ResetCatBeforeClone') ) { $object =& $event->getObject(); + /* @var $object kDBItem */ + $object->SetDBField('CategoryId', null); } } @@ -2147,16 +2275,20 @@ * Set status for new category item based on user permission in category * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemCreate(&$event) + protected function OnBeforeItemCreate(&$event) { + parent::OnBeforeItemCreate($event); + $object =& $event->getObject(); - /* @var $object kDBItem */ + /* @var $object kCatDBItem */ $is_admin = $this->Application->isAdminUser; $owner_field = $this->getOwnerField($event->Prefix); - if ((!$object->IsTempTable() && !$is_admin) || ($is_admin && !$object->GetDBField($owner_field))) { + if ( (!$object->IsTempTable() && !$is_admin) || ($is_admin && !$object->GetDBField($owner_field)) ) { // Front-end OR owner not specified -> set to currently logged-in user $object->SetDBField($owner_field, $this->Application->RecallVar('user_id')); } @@ -2165,7 +2297,7 @@ $object->SetDBField('ResourceId', $this->Application->NextResourceId()); } - if (!$this->Application->isAdmin) { + if ( !$this->Application->isAdmin ) { $this->setItemStatusByPermission($event); } } @@ -2184,7 +2316,7 @@ } $object =& $event->getObject(); - /* @var $object kDBItem */ + /* @var $object kCatDBItem */ $perm_helper =& $this->Application->recallObject('PermissionsHelper'); /* @var $perm_helper kPermissionsHelper */ @@ -2402,32 +2534,34 @@ } /** - * Apply same processing to each item beeing selected in grid + * Apply same processing to each item being selected in grid * * @param kEvent $event - * @access private + * @return void + * @access protected */ - function iterateItems(&$event) + protected function iterateItems(&$event) { - if ($event->Name != 'OnMassApprove' && $event->Name != 'OnMassDecline') { - return parent::iterateItems($event); + if ( $event->Name != 'OnMassApprove' && $event->Name != 'OnMassDecline' ) { + parent::iterateItems($event); } - if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { + if ( $this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1) ) { $event->status = kEvent::erFAIL; - return; + return ; } - $object =& $event->getObject( Array('skip_autoload' => true) ); - /* @var $object kCatDBItem */ + $object =& $event->getObject(Array ('skip_autoload' => true)); + /* @var $object kCatDBItem */ $ids = $this->StoreSelectedIDs($event); - if ($ids) { + if ( $ids ) { foreach ($ids as $id) { + $ret = true; $object->Load($id); - switch ($event->Name) { + switch ( $event->Name ) { case 'OnMassApprove': $ret = $object->ApproveChanges(); break; @@ -2437,7 +2571,7 @@ break; } - if (!$ret) { + if ( !$ret ) { $event->status = kEvent::erFAIL; $event->redirect = false; break; @@ -2580,11 +2714,11 @@ { $remove_sortings = Array (); - if (!$this->Application->isAdmin) { + if ( !$this->Application->isAdmin ) { // remove Pick sorting on Front-end, when not required - $config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping'); + $config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping', Array ()); - if (!isset($config_mapping['ForceEditorPick']) || !$this->Application->ConfigValue($config_mapping['ForceEditorPick'])) { + if ( !isset($config_mapping['ForceEditorPick']) || !$this->Application->ConfigValue($config_mapping['ForceEditorPick']) ) { $remove_sortings[] = 'EditorsPick'; } } @@ -2593,11 +2727,12 @@ $remove_sortings = array_merge($remove_sortings, Array ('Priority', 'EditorsPick')); } - if (!$remove_sortings) { - return ; + if ( !$remove_sortings ) { + return; } $list_sortings = $this->Application->getUnitOption($event->Prefix, 'ListSortings', Array ()); + /* @var $list_sortings Array */ foreach ($list_sortings as $special => $sorting_fields) { foreach ($remove_sortings as $sorting_field) { @@ -2616,7 +2751,7 @@ function OnDownloadFile(&$event) { $object =& $event->getObject(); - /* @var $object kDBItem */ + /* @var $object kCatDBItem */ $event->status = kEvent::erSTOP; @@ -2650,7 +2785,7 @@ /* @var $rating_helper RatingHelper */ $object =& $event->getObject( Array ('skip_autoload' => true) ); - /* @var $object kDBItem */ + /* @var $object kCatDBItem */ $object->Load( $this->Application->GetVar('id') ); Index: branches/5.2.x/core/units/helpers/deployment_helper.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/units/helpers/deployment_helper.php (.../deployment_helper.php) (revision 14585) +++ branches/5.2.x/core/units/helpers/deployment_helper.php (.../deployment_helper.php) (revision 14628) @@ -1,6 +1,6 @@ Application->getUnitOption($prefix, 'TableName'); - return $temp ? $this->Application->GetTempName($table_name, 'prefix:'.$prefix) : $table_name; + + return $temp ? $this->Application->GetTempName($table_name, 'prefix:' . $prefix) : $table_name; } function prepareMInputXML($records, $use_fields) @@ -112,7 +114,8 @@ $root_node =& $xml_helper->Parse($xml); $root_node =& $root_node->FindChild('records'); - if (!$root_node || !$root_node->firstChild) { + + if ( !$root_node || !$root_node->firstChild ) { return false; } @@ -121,17 +124,16 @@ /* @var $current_node kXMLNode */ do { - $record = Array(); + $record = Array (); $sub_node =& $current_node->firstChild; /* @var $current_node kXMLNode */ do { - $record[$sub_node->Attributes['NAME']] = $sub_node->Data; + $record[ $sub_node->Attributes['NAME'] ] = $sub_node->Data; + } while ( ($sub_node =& $sub_node->NextSibling()) ); - }while ( ($sub_node =& $sub_node->NextSibling()) ); - $records[] = $record; - } while (($current_node =& $current_node->NextSibling())); + } while ( ($current_node =& $current_node->NextSibling()) ); return $records; } @@ -195,10 +197,12 @@ function SaveValues(&$sub_event, $store_field) { $main_object =& $sub_event->MasterEvent->getObject(); + /* @var $main_object kDBItem */ + $affected_field = $main_object->GetDBField($store_field); - $object =& $this->Application->recallObject($sub_event->getPrefixSpecial(), null, Array('skip_autoload' => true)); - /*@var $object kDBItem*/ + $object =& $this->Application->recallObject($sub_event->getPrefixSpecial(), null, Array ('skip_autoload' => true)); + /* @var $object kDBItem */ $sub_table = $object->TableName; $foreign_key = $this->Application->getUnitOption($sub_event->Prefix, 'ForeignKey'); Index: branches/5.2.x/core/units/permissions/permissions_event_handler.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/permissions/permissions_event_handler.php (.../permissions_event_handler.php) (revision 14244) +++ branches/5.2.x/core/units/permissions/permissions_event_handler.php (.../permissions_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ Application->CheckPermission('in-portal:user_groups.advanced:manage_permissions', 1)) { + if ( !$this->Application->CheckPermission('in-portal:user_groups.advanced:manage_permissions', 1) ) { // no permission to save permissions - return false; + return ; } $permissions = $this->Application->GetVar($event->getPrefixSpecial(true)); - if (!$permissions) { - return false; + if ( !$permissions ) { + return ; } - $object =& $event->getObject( Array('skip_autoload' => true) ); + $object =& $event->getObject( Array ('skip_autoload' => true) ); + /* @var $object kDBItem */ + $group_id = $this->Application->GetVar('g_id'); $permissions_helper =& $this->Application->recallObject('PermissionsHelper'); /* @var $permissions_helper kPermissionsHelper */ $permissions_helper->LoadPermissions($group_id, 0, 1, 'g'); - $delete_ids = Array(); - $create_sql = Array(); - $create_mask = '(%s,%s,'.$group_id.',%s,1,0)'; + $delete_ids = $create_sql = Array (); + $create_mask = '(%s,%s,' . $group_id . ',%s,1,0)'; - $new_id = (int)$this->Conn->GetOne('SELECT MIN('.$object->IDField.') FROM '.$object->TableName); - if($new_id > 0) $new_id = 0; + $new_id = (int)$this->Conn->GetOne('SELECT MIN(' . $object->IDField . ') FROM ' . $object->TableName); + if ( $new_id > 0 ) { + $new_id = 0; + } --$new_id; $sections_helper =& $this->Application->recallObject('SectionsHelper'); + /* @var $sections_helper kSectionsHelper */ + foreach ($permissions as $section_name => $section_permissions) { $section_data =& $sections_helper->getSectionData($section_name); - if ($section_data && isset($section_data['perm_prefix'])) { + if ( $section_data && isset($section_data['perm_prefix']) ) { // using permission from other prefix - $section_name = $this->Application->getUnitOption($section_data['perm_prefix'].'.main', 'PermSection'); + $section_name = $this->Application->getUnitOption($section_data['perm_prefix'] . '.main', 'PermSection'); } foreach ($section_permissions as $perm_name => $perm_value) { - - if (!$permissions_helper->isOldPermission($section_name, $perm_name)) { - $perm_name = $section_name.'.'.$perm_name; + if ( !$permissions_helper->isOldPermission($section_name, $perm_name) ) { + $perm_name = $section_name . '.' . $perm_name; } $db_perm_value = $permissions_helper->getPermissionValue($perm_name); - if ($db_perm_value == 1 && $perm_value == 0) { + + if ( $db_perm_value == 1 && $perm_value == 0 ) { // permission was disabled => delete it's record $delete_ids[] = $permissions_helper->getPermissionID($perm_name); } - elseif ($db_perm_value == 0 && $perm_value == 1) { + elseif ( $db_perm_value == 0 && $perm_value == 1 ) { // permission was enabled => created it's record $create_sql[$perm_name] = sprintf($create_mask, $new_id--, $this->Conn->qstr($perm_name), $this->Conn->qstr($perm_value)); } // permission state was not changed in all other cases } } - $this->UpdatePermissions($event, $create_sql, Array(), $delete_ids); + $this->UpdatePermissions($event, $create_sql, Array (), $delete_ids); - if ($this->Application->GetVar('advanced_save') == 1) { + if ( $this->Application->GetVar('advanced_save') == 1 ) { // advanced permission popup [save button] $this->finalizePopup($event); // $event->redirect = 'incs/just_close'; } - elseif ($this->Application->GetVar('section_name') != '') { + elseif ( $this->Application->GetVar('section_name') != '' ) { // save simple permissions before opening advanced permission popup $event->redirect = false; } - } /** @@ -230,14 +237,16 @@ */ function OnBeforeDeleteFromLive(&$event) { - if ($event->Prefix == 'c-perm') { + if ( $event->Prefix == 'c-perm' ) { // only when saving category permissions, not group permissions $foreign_keys = $event->getEventParam('foreign_key'); - if ((count($foreign_keys) == 1) && ($foreign_keys[0] == 0)) { + if ( (count($foreign_keys) == 1) && ($foreign_keys[0] == 0) ) { // parent item has zero id $temp_object =& $this->Application->recallObject('c'); - if ($temp_object->isLoaded()) { + /* @var $temp_object CategoriesItem */ + + if ( $temp_object->isLoaded() ) { // category with id = 0 found in temp table $event->status = kEvent::erFAIL; } Index: branches/5.2.x/core/units/config_search/config_search_event_handler.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/config_search/config_search_event_handler.php (.../config_search_event_handler.php) (revision 14244) +++ branches/5.2.x/core/units/config_search/config_search_event_handler.php (.../config_search_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ Application->GetVar('module'); $main_prefix = $this->Application->findModule('Name', $module, 'Var'); $section = $this->Application->getUnitOption($main_prefix.'.search', 'PermSection'); $event->setEventParam('PermSection', $section); + return parent::CheckPermission($event); } /** * Apply any custom changes to list's sql query * * @param kEvent $event + * @return void * @access protected - * @see OnListBuild + * @see kDBEventHandler::OnListBuild() */ - function SetCustomQuery(&$event) + protected function SetCustomQuery(&$event) { $object =& $event->getObject(); - + /* @var $object kDBList */ + // show only items that belong to selected module $module = $this->Application->GetVar('module'); $object->addFilter('module_filter', '%1$s.ModuleName = '.$this->Conn->qstr($module)); @@ -75,33 +80,46 @@ $event->SetRedirectParam('section', $this->Application->GetVar('section')); } + /** + * Cancels kDBItem Editing/Creation + * + * @param kEvent $event + * @return void + * @access protected + */ function OnCancel(&$event) { parent::OnCancel($event); + $event->SetRedirectParam('opener', 's'); } /** - * [HOOK] Enter description here... + * [HOOK] Creates search config record corresponding to custom field, that was just created * * @param kEvent $event + * @return void + * @access protected */ - function OnCreateCustomField(&$event) + protected function OnCreateCustomField(&$event) { $custom_field =& $event->MasterEvent->getObject(); - if ($custom_field->GetDBField('Type') == 6 || $custom_field->GetDBField('IsSystem') == 1) { + /* @var $custom_field kDBItem */ + + if ( $custom_field->GetDBField('Type') == 6 || $custom_field->GetDBField('IsSystem') == 1 ) { // user & system custom fields are not searchable - return false; + return ; } - $object =& $event->getObject( Array('skip_autoload' => true) ); + $object =& $event->getObject(Array ('skip_autoload' => true)); + /* @var $object kDBItem */ $custom_id = $custom_field->GetID(); - if (!$object->isLoaded() || ($object->GetDBField('CustomFieldId') != $custom_id)) { + if ( !$object->isLoaded() || ($object->GetDBField('CustomFieldId') != $custom_id) ) { $object->Load($custom_id, 'CustomFieldId'); } - $cf_search = Array(); + $cf_search = Array (); $element_type = $custom_field->GetDBField('ElementType'); $cf_search['DisplayOrder'] = $custom_field->GetDBField('DisplayOrder'); @@ -114,14 +132,19 @@ $cf_search['TableName'] = 'CustomField'; $sql = 'SELECT Module - FROM '.TABLE_PREFIX.'ItemTypes - WHERE ItemType = '.$custom_field->GetDBField('Type'); + FROM ' . TABLE_PREFIX . 'ItemTypes + WHERE ItemType = ' . $custom_field->GetDBField('Type'); - $cf_search['ModuleName'] = $this->Conn->GetOne($sql); + $cf_search['ModuleName'] = $this->Conn->GetOne($sql); $object->SetFieldsFromHash($cf_search); $object->SetDBField('CustomFieldId', $custom_id); - $result = $object->isLoaded() ? $object->Update() : $object->Create(); + if ( $object->isLoaded() ) { + $object->Update(); + } + else { + $object->Create(); + } } } \ No newline at end of file Index: branches/5.2.x/core/units/helpers/mailbox_helper.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/helpers/mailbox_helper.php (.../mailbox_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/mailbox_helper.php (.../mailbox_helper.php) (revision 14628) @@ -1,6 +1,6 @@ decodeMime($message, $include_attachment_contents); Index: branches/5.2.x/core/units/categories/categories_item.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/units/categories/categories_item.php (.../categories_item.php) (revision 14585) +++ branches/5.2.x/core/units/categories/categories_item.php (.../categories_item.php) (revision 14628) @@ -1,6 +1,6 @@ GetDBField('ParentId') > 0 ? $this->GetDBField('ParentId') : $this->Application->GetVar('m_cat_id'); @@ -52,7 +61,16 @@ } - function Update($id=null, $system_update = false) + /** + * Updates previously loaded record with current item' values + * + * @access public + * @param int $id Primary Key Id to update + * @param bool $system_update + * @return bool + * @access public + */ + public function Update($id = null, $system_update = false) { $this->checkFilename(); $this->generateFilename(); @@ -183,16 +201,23 @@ /** * Generate item's filename based on it's title field value * - * @return string + * @return void + * @access protected */ - function generateFilename() + protected function generateFilename() { - if ( !$this->GetDBField('AutomaticFilename') && $this->GetDBField('Filename') ) return false; + if ( !$this->GetDBField('AutomaticFilename') && $this->GetDBField('Filename') ) { + return ; + } $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); - $name = $this->stripDisallowed( $this->GetDBField( $ml_formatter->LangFieldName('Name', true) ) ); + /* @var $ml_formatter kMultiLanguage */ - if ( $name != $this->GetDBField('Filename') ) $this->SetDBField('Filename', $name); + $name = $this->stripDisallowed( $this->GetDBField($ml_formatter->LangFieldName('Name', true)) ); + + if ( $name != $this->GetDBField('Filename') ) { + $this->SetDBField('Filename', $name); + } } /** Index: branches/5.2.x/core/units/helpers/recursive_helper.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/helpers/recursive_helper.php (.../recursive_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/recursive_helper.php (.../recursive_helper.php) (revision 14628) @@ -1,6 +1,6 @@ Conn->Query($sql); $temp_handler =& $this->Application->recallObject($prefix.'_TempHandler', 'kTempTablesHandler'); - + /* @var $temp_handler kTempTablesHandler */ + // 2. delete items this have this category as primary $delete_ids = $this->getCategoryItems($category_id, true); @@ -106,9 +107,10 @@ } /** - * Complete cloning or category with subcategories and subitems + * Complete cloning or category with subcategories and sub-items * * @param int $category_id + * @param string $prefix */ function PasteCategory($category_id, $prefix = 'c') { @@ -117,16 +119,16 @@ $src_parent_path = $this->_getParentPath($category_id); $dst_parent_path = $this->_getParentPath($backup_category_id); - if (substr($dst_parent_path, 0, strlen($src_parent_path)) == $src_parent_path) { + if ( substr($dst_parent_path, 0, strlen($src_parent_path)) == $src_parent_path ) { // target path contains source path -> recursion - return ; + return; } // 1. clone category - $temp_handler =& $this->Application->recallObject($prefix.'_TempHandler', 'kTempTablesHandler'); + $temp_handler =& $this->Application->recallObject($prefix . '_TempHandler', 'kTempTablesHandler'); /* @var $temp_handler kTempTablesHandler*/ - $temp_handler->BuildTables($prefix, Array($category_id)); - $new_category_id = array_pop( $temp_handler->CloneItems($prefix, '', Array($category_id)) ); + $temp_handler->BuildTables($prefix, Array ($category_id)); + $new_category_id = array_pop($temp_handler->CloneItems($prefix, '', Array ($category_id))); $this->Application->SetVar('m_cat_id', $new_category_id); $id_field = $this->Application->getUnitOption($prefix, 'IDField'); @@ -136,12 +138,14 @@ $paste_ids = $this->getCategoryItems($category_id, false); foreach ($paste_ids as $item_prefix => $resource_ids) { - if (!$item_prefix) { + if ( !$item_prefix ) { // not ItemPrefix filled -> old categoryitem linking continue; } - $item_object =& $this->Application->recallObject($item_prefix.'.-item', null, Array('skip_autoload' => true)); + $item_object =& $this->Application->recallObject($item_prefix . '.-item', null, Array ('skip_autoload' => true)); + /* @var $item_object kCatDBItem */ + foreach ($resource_ids as $item_resource_id) { $item_object->Load($item_resource_id, 'ResourceId'); $item_object->assignToCategory($new_category_id, false); @@ -152,7 +156,7 @@ $paste_ids = $this->getCategoryItems($category_id, true); foreach ($paste_ids as $item_prefix => $resource_ids) { - if (!$item_prefix) { + if ( !$item_prefix ) { // not ItemPrefix filled -> old categoryitem linking continue; } @@ -164,12 +168,12 @@ } // 4. do same stuff for each subcategory - $sql = 'SELECT '.$id_field.' - FROM '.$table_name.' - WHERE ParentId = '.$category_id; + $sql = 'SELECT ' . $id_field . ' + FROM ' . $table_name . ' + WHERE ParentId = ' . $category_id; $sub_categories = $this->Conn->GetCol($sql); - if ($sub_categories) { + if ( $sub_categories ) { foreach ($sub_categories as $sub_category_id) { $this->PasteCategory($sub_category_id, $prefix); } Index: branches/5.2.x/core/kernel/db/cat_tag_processor.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/kernel/db/cat_tag_processor.php (.../cat_tag_processor.php) (revision 14585) +++ branches/5.2.x/core/kernel/db/cat_tag_processor.php (.../cat_tag_processor.php) (revision 14628) @@ -1,6 +1,6 @@ Prefix.'-rev'; - $review_tag_processor =& $this->Application->recallObject($prefix.'.item_TagProcessor'); + $prefix = $this->Prefix . '-rev'; + + $review_tag_processor =& $this->Application->recallObject($prefix . '.item_TagProcessor'); + /* @var $review_tag_processor kDBTagProcessor */ + return $review_tag_processor->PrintList($params); } function ReviewCount($params) { $review_tag_processor =& $this->Application->recallObject('rev.item_TagProcessor'); + /* @var $review_tag_processor kDBTagProcessor */ + return $review_tag_processor->TotalRecords($params); } @@ -609,50 +614,53 @@ */ function LastUpdated($params) { - $category_id = (int)$this->Application->GetVar('m_cat_id'); - $local = array_key_exists('local', $params) && ($category_id > 0) ? $params['local'] : false; + $category_id = (int)$this->Application->GetVar('m_cat_id'); + $local = array_key_exists('local', $params) && ($category_id > 0) ? $params['local'] : false; $serial_name1 = $this->Application->incrementCacheSerial('c', $local ? $category_id : null, false); $serial_name2 = $this->Application->incrementCacheSerial($this->Prefix, null, false); $cache_key = 'categoryitems_last_updated[%' . $serial_name1 . '%][%' . $serial_name2 . '%]'; $row_data = $this->Application->getCache($cache_key); - if ($row_data === false) { - if ($local && ($category_id > 0)) { + if ( $row_data === false ) { + if ( $local && ($category_id > 0) ) { // scan only current category & it's children - list ($tree_left, $tree_right) = $this->Application->getTreeIndex($category_id); + list ($tree_left, $tree_right) = $this->Application->getTreeIndex($category_id); - $sql = 'SELECT MAX(item_table.Modified) AS ModDate, MAX(item_table.CreatedOn) AS NewDate + $sql = 'SELECT MAX(item_table.Modified) AS ModDate, MAX(item_table.CreatedOn) AS NewDate FROM ' . $this->Application->getUnitOption($this->Prefix, 'TableName') . ' item_table LEFT JOIN ' . TABLE_PREFIX . 'CategoryItems ci ON (item_table.ResourceId = ci.ItemResourceId) LEFT JOIN ' . TABLE_PREFIX . 'Category c ON c.CategoryId = ci.CategoryId WHERE c.TreeLeft BETWEEN ' . $tree_left . ' AND ' . $tree_right; - } + } else { // scan all categories in system $sql = 'SELECT MAX(Modified) AS ModDate, MAX(CreatedOn) AS NewDate FROM ' . $this->Application->getUnitOption($this->Prefix, 'TableName'); - } + } - $this->Conn->nextQueryCachable = true; + $this->Conn->nextQueryCachable = true; $row_data = $this->Conn->GetRow($sql); $this->Application->setCache($cache_key, $row_data); } - if (!$row_data) { - return ''; - } + if ( !$row_data ) { + return ''; + } - $date = $row_data[ $row_data['NewDate'] > $row_data['ModDate'] ? 'NewDate' : 'ModDate' ]; + $date = $row_data[$row_data['NewDate'] > $row_data['ModDate'] ? 'NewDate' : 'ModDate']; - // format date - $format = isset($params['format']) ? $params['format'] : '_regional_DateTimeFormat'; - if (preg_match("/_regional_(.*)/", $format, $regs)) { + // format date + $format = isset($params['format']) ? $params['format'] : '_regional_DateTimeFormat'; + + if ( preg_match("/_regional_(.*)/", $format, $regs) ) { $lang =& $this->Application->recallObject('lang.current'); - if ($regs[1] == 'DateTimeFormat') { + /* @var $lang LanguagesItem */ + + if ( $regs[1] == 'DateTimeFormat' ) { // combined format - $format = $lang->GetDBField('DateFormat').' '.$lang->GetDBField('TimeFormat'); + $format = $lang->GetDBField('DateFormat') . ' ' . $lang->GetDBField('TimeFormat'); } else { // simple format Index: branches/5.2.x/core/units/custom_fields/custom_fields_event_handler.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/custom_fields/custom_fields_event_handler.php (.../custom_fields_event_handler.php) (revision 14244) +++ branches/5.2.x/core/units/custom_fields/custom_fields_event_handler.php (.../custom_fields_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ getObject(); /* @var $object kDBList */ @@ -57,7 +60,7 @@ } if ($item_type) { - $hidden_fields = array_map(Array(&$this->Conn, 'qstr'), $this->_getHiddenFiels($event)); + $hidden_fields = array_map(Array(&$this->Conn, 'qstr'), $this->_getHiddenFields($event)); if ($hidden_fields) { $object->addFilter('hidden_filter', '%1$s.FieldName NOT IN (' . implode(',', $hidden_fields) . ')'); @@ -95,20 +98,22 @@ * * @param kEvent $event * @return Array + * @access protected */ - function _getHiddenFiels(&$event) + protected function _getHiddenFields(&$event) { $prefix = $this->_getSourcePrefix($event); + $hidden_fields = Array (); $virtual_fields = $this->Application->getUnitOption($prefix, 'VirtualFields', Array ()); $custom_fields = $this->Application->getUnitOption($prefix, 'CustomFields', Array ()); + /* @var $custom_fields Array */ - $hidden_fields = Array (); foreach ($custom_fields as $custom_field) { $check_field = 'cust_' . $custom_field; $show_mode = array_key_exists('show_mode', $virtual_fields[$check_field]) ? $virtual_fields[$check_field]['show_mode'] : true; - if (($show_mode === false) || (($show_mode === smDEBUG) && !(defined('DEBUG_MODE') && DEBUG_MODE))) { + if ( ($show_mode === false) || (($show_mode === smDEBUG) && !(defined('DEBUG_MODE') && DEBUG_MODE)) ) { $hidden_fields[] = $custom_field; } } @@ -120,25 +125,29 @@ * Prevents from duplicate item creation * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemCreate(&$event) + protected function OnBeforeItemCreate(&$event) { + parent::OnBeforeItemCreate($event); + $object =& $event->getObject(); + /* @var $object kDBItem */ - $live_table = $this->Application->getUnitOption($event->Prefix, 'TableName'); $sql = 'SELECT COUNT(*) - FROM '.$live_table.' - WHERE FieldName = '.$this->Conn->qstr($object->GetDBField('FieldName')).' AND Type = '.$object->GetDBField('Type'); + FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + WHERE FieldName = ' . $this->Conn->qstr($object->GetDBField('FieldName')) . ' AND Type = ' . $object->GetDBField('Type'); $found = $this->Conn->GetOne($sql); - if ($found) { + if ( $found ) { $event->status = kEvent::erFAIL; $object->SetError('FieldName', 'duplicate', 'la_error_CustomExists'); } } /** - * Occurse after deleting item, id of deleted item + * Occurs after deleting item, id of deleted item * is stored as 'id' param of event * * @param kEvent $event @@ -147,42 +156,50 @@ function OnAfterItemDelete(&$event) { $object =& $event->getObject(); - $main_prefix = $this->getPrefixByItemType($object->GetDBField('Type')); + /* @var $object kDBItem */ + $main_prefix = $this->getPrefixByItemType( $object->GetDBField('Type') ); + $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); /* @var $ml_helper kMultiLanguageHelper */ // call main item config to clone cdata table $this->Application->getUnitOption($main_prefix, 'TableName'); - $ml_helper->deleteField($main_prefix.'-cdata', $event->getEventParam('id')); + $ml_helper->deleteField($main_prefix . '-cdata', $event->getEventParam('id')); } /** * Get config prefix based on item type * - * @param unknown_type $item_type - * @return unknown + * @param int $item_type + * @return string + * @access protected */ - function getPrefixByItemType($item_type) + protected function getPrefixByItemType($item_type) { $sql = 'SELECT Prefix - FROM '.TABLE_PREFIX.'ItemTypes - WHERE ItemType = '.$item_type; + FROM ' . TABLE_PREFIX . 'ItemTypes + WHERE ItemType = ' . $item_type; + return $this->Conn->GetOne($sql); } /** - * Enter description here... + * Creates new database columns, once custom field is successfully created * * @param kEvent $event + * @return void + * @access protected */ - function OnSaveCustomField(&$event) + protected function OnSaveCustomField(&$event) { - if ($event->MasterEvent->status != kEvent::erSUCCESS) { - return false; + if ( $event->MasterEvent->status != kEvent::erSUCCESS ) { + return ; } $object =& $event->getObject(); + /* @var $object kDBItem */ + $main_prefix = $this->getPrefixByItemType($object->GetDBField('Type')); $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); @@ -191,13 +208,23 @@ // call main item config to clone cdata table define('CUSTOM_FIELD_ADDED', 1); // used in cdata::scanCustomFields method $this->Application->getUnitOption($main_prefix, 'TableName'); - $ml_helper->createFields($main_prefix.'-cdata'); + $ml_helper->createFields($main_prefix . '-cdata'); } - function OnMassDelete(&$event) + /** + * Deletes all selected items. + * Automatically recurse into sub-items using temp handler, and deletes sub-items + * by calling its Delete method if sub-item has AutoDelete set to true in its config file + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnMassDelete(&$event) { parent::OnMassDelete($event); - $event->setRedirectParams(Array('opener' => 's'), true); + + $event->SetRedirectParam('opener', 's'); } /** @@ -206,40 +233,46 @@ * done in OnPreSaveCreated * * @param kEvent $event + * @return void + * @access protected */ - function OnPreCreate(&$event) + protected function OnPreCreate(&$event) { parent::OnPreCreate($event); $object =& $event->getObject(); + /* @var $object kDBItem */ + $object->SetDBField('Type', $this->Application->GetVar('cf_type')); } /** * Prepares ValueList field's value as xml for editing * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterItemLoad(&$event) + protected function OnAfterItemLoad(&$event) { parent::OnAfterItemLoad($event); $object =& $event->getObject(); /* @var $object kDBItem */ - if (!in_array($object->GetDBField('ElementType'), $this->_getMultiElementTypes())) { + if ( !in_array($object->GetDBField('ElementType'), $this->_getMultiElementTypes()) ) { return ; } $custom_field_helper =& $this->Application->recallObject('InpCustomFieldsHelper'); /* @var $custom_field_helper InpCustomFieldsHelper */ - $options = $custom_field_helper->GetValuesHash( $object->GetDBField('ValueList'), VALUE_LIST_SEPARATOR, false ); + $options = $custom_field_helper->GetValuesHash($object->GetDBField('ValueList'), VALUE_LIST_SEPARATOR, false); $records = Array (); $option_key = key($options); - if ($option_key === '' || $option_key == 0) { + if ( $option_key === '' || $option_key == 0 ) { // remove 1st empty option, and add it later, when options will be saved, but allow string option keys unset($options[$option_key]); // keep index, don't use array_unshift! } @@ -258,9 +291,10 @@ /** * Returns custom field element types, that will use minput control * - * @return unknown + * @return Array + * @access protected */ - function _getMultiElementTypes() + protected function _getMultiElementTypes() { return Array ('select', 'multiselect', 'radio'); } @@ -269,15 +303,17 @@ * Saves minput content to ValueList field * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemUpdate(&$event) + protected function OnBeforeItemUpdate(&$event) { parent::OnBeforeItemUpdate($event); $object =& $event->getObject(); /* @var $object kDBItem */ - if (!in_array($object->GetDBField('ElementType'), $this->_getMultiElementTypes())) { + if ( !in_array($object->GetDBField('ElementType'), $this->_getMultiElementTypes()) ) { return ; } @@ -287,13 +323,13 @@ $ret = $object->GetDBField('ElementType') == 'select' ? Array ('' => '=+') : Array (); $records = $minput_helper->parseMInputXML($object->GetDBField('Options')); - if ($object->GetDBField('SortValues')) { + if ( $object->GetDBField('SortValues') ) { usort($records, Array (&$this, '_sortValues')); ksort($records); } foreach ($records as $record) { - if (substr($record['OptionKey'], 0, 3) == 'SQL') { + if ( substr($record['OptionKey'], 0, 3) == 'SQL' ) { $ret[] = $record['OptionTitle']; } else { Index: branches/5.2.x/core/units/helpers/mod_rewrite_helper.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/units/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 14585) +++ branches/5.2.x/core/units/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 14628) @@ -1,6 +1,6 @@ Application->getUnitOption($prefix, 'QueryString'); - if (!$query_vars) { + $query_vars = $this->Application->getUnitOption($prefix, 'QueryString', Array ()); + /* @var $query_vars Array */ + + if ( !$query_vars ) { // given prefix doesn't use "env" variable to pass it's data return false; } $event_key = array_search('event', $query_vars); - if ($event_key) { + if ( $event_key ) { // pass through event of this prefix unset($query_vars[$event_key]); } - if (array_key_exists($prefix_special . '_event', $params) && !$params[$prefix_special . '_event']) { + if ( array_key_exists($prefix_special . '_event', $params) && !$params[$prefix_special . '_event'] ) { // if empty event, then remove it from url - unset( $params[$prefix_special . '_event'] ); + unset($params[$prefix_special . '_event']); } // if pass events is off and event is not implicity passed - if (!$keep_events && !array_key_exists($prefix_special . '_event', $params)) { + if ( !$keep_events && !array_key_exists($prefix_special . '_event', $params) ) { unset($params[$prefix_special . '_event']); // remove event from url if requested //otherwise it will use value from get_var } $processed_params = Array (); - foreach ($query_vars as $index => $var_name) { + foreach ($query_vars as $var_name) { // if value passed in params use it, otherwise use current from application $var_name = $prefix_special . '_' . $var_name; $processed_params[$var_name] = array_key_exists($var_name, $params) ? $params[$var_name] : $this->Application->GetVar($var_name); - if (array_key_exists($var_name, $params)) { + + if ( array_key_exists($var_name, $params) ) { unset($params[$var_name]); } } Index: branches/5.2.x/core/units/helpers/count_helper.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/helpers/count_helper.php (.../count_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/count_helper.php (.../count_helper.php) (revision 14628) @@ -1,6 +1,6 @@ Application->getCache($cache_key); @@ -159,8 +160,9 @@ * * @param bool $url * @return string + * @access protected */ - function _getStylesheetPath($url = false) + protected function _getStylesheetPath($url = false) { if ($url) { return $this->Application->BaseURL( str_replace(DIRECTORY_SEPARATOR, '/', WRITEBALE_BASE) ) . 'user_files'; @@ -172,15 +174,16 @@ /** * Returns full path to primary admin skin using given or last compiled date * - * @param string $url + * @param string|bool $url * @param int $compile_date * @return string + * @access public */ - function getSkinPath($url = false, $compile_date = null) + public function getSkinPath($url = false, $compile_date = null) { $style_info = $this->_getStyleInfo(); - if (!isset($compile_date)) { + if ( !isset($compile_date) ) { $compile_date = $style_info['LastCompiled']; } Index: branches/5.2.x/core/kernel/managers/url_manager.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/kernel/managers/url_manager.php (.../url_manager.php) (revision 14585) +++ branches/5.2.x/core/kernel/managers/url_manager.php (.../url_manager.php) (revision 14628) @@ -1,6 +1,6 @@ Application->recallObject('Session'); + /* @var $session Session */ + $ssl = isset($params['__SSL__']) ? $params['__SSL__'] : 0; $sid = $session->NeedQueryString() && !$this->Application->RewriteURLs($ssl) ? $this->Application->GetSID() : ''; // if (getArrayValue($params,'admin') == 1) $sid = $this->Application->GetSID(); @@ -495,39 +497,46 @@ * @param string $prefix_special item's prefix & [special] * @param Array $params url params * @param bool $pass_events + * @return string + * @access protected */ - function BuildModuleEnv($prefix_special, &$params, $pass_events = false) + protected function BuildModuleEnv($prefix_special, &$params, $pass_events = false) { list($prefix) = explode('.', $prefix_special); - $query_vars = $this->Application->getUnitOption($prefix, 'QueryString'); + $query_vars = $this->Application->getUnitOption($prefix, 'QueryString', Array ()); + /* @var $query_vars Array */ - //if pass events is off and event is not implicity passed - if( !$pass_events && !isset($params[$prefix_special.'_event']) ) { - $params[$prefix_special.'_event'] = ''; // remove event from url if requested + //if pass events is off and event is not implicitly passed + if ( !$pass_events && !isset($params[$prefix_special . '_event']) ) { + $params[$prefix_special . '_event'] = ''; // remove event from url if requested //otherwise it will use value from get_var } - if(!$query_vars) return ''; + if ( !$query_vars ) { + return ''; + } - $tmp_string = Array(0 => $prefix_special); - foreach($query_vars as $index => $var_name) - { + $tmp_string = Array (0 => $prefix_special); + foreach ($query_vars as $index => $var_name) { //if value passed in params use it, otherwise use current from application - $var_name = $prefix_special.'_'.$var_name; - $tmp_string[$index] = isset( $params[$var_name] ) ? $params[$var_name] : $this->Application->GetVar($var_name); - if ( isset($params[$var_name]) ) unset( $params[$var_name] ); + $var_name = $prefix_special . '_' . $var_name; + $tmp_string[$index] = isset($params[$var_name]) ? $params[$var_name] : $this->Application->GetVar($var_name); + + if ( isset($params[$var_name]) ) { + unset($params[$var_name]); + } } - $escaped = array(); + $escaped = array (); foreach ($tmp_string as $tmp_val) { - $escaped[] = str_replace(Array('-',':'), Array('\-','\:'), $tmp_val); + $escaped[] = str_replace(Array ('-', ':'), Array ('\-', '\:'), $tmp_val); } $ret = implode('-', $escaped); - if ($this->Application->getUnitOption($prefix, 'PortalStyleEnv') == true) - { - $ret = preg_replace('/^([a-zA-Z]+)-([0-9]+)-(.*)/','\\1\\2-\\3', $ret); + if ( $this->Application->getUnitOption($prefix, 'PortalStyleEnv') == true ) { + $ret = preg_replace('/^([a-zA-Z]+)-([0-9]+)-(.*)/', '\\1\\2-\\3', $ret); } + return $ret; } Index: branches/5.2.x/core/units/permissions/permissions_tag_processor.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/permissions/permissions_tag_processor.php (.../permissions_tag_processor.php) (revision 14244) +++ branches/5.2.x/core/units/permissions/permissions_tag_processor.php (.../permissions_tag_processor.php) (revision 14628) @@ -1,6 +1,6 @@ Application->recallObject('SectionsHelper'); + /* @var $sections_helper kSectionsHelper */ + $section_data =& $sections_helper->getSectionData($section_name); return array_search($params['perm_name'], $section_data['permissions']) !== false; @@ -31,6 +33,8 @@ $section_name = $params['section_name']; $sections_helper =& $this->Application->recallObject('SectionsHelper'); + /* @var $sections_helper kSectionsHelper */ + $section_data =& $sections_helper->getSectionData($section_name); $ret = false; @@ -49,6 +53,8 @@ $perm_name = $params['perm_name']; $sections_helper =& $this->Application->recallObject('SectionsHelper'); + /* @var $sections_helper kSectionsHelper */ + $section_data =& $sections_helper->getSectionData($section_name); if ($section_data && isset($section_data['perm_prefix'])) { @@ -57,6 +63,8 @@ } $permissions_helper =& $this->Application->recallObject('PermissionsHelper'); + /* @var $permissions_helper kPermissionsHelper */ + if (!$permissions_helper->isOldPermission($section_name, $perm_name)) { $perm_name = $section_name.'.'.$perm_name; } @@ -181,25 +189,29 @@ * Returns category name by ID * * @param Array $params + * @return string + * @access protected */ - function CategoryPath($params) + protected function CategoryPath($params) { $category_id = $params['cat_id']; $cache_key = 'category_paths[%CIDSerial:' . $category_id . '%][%PhrasesSerial%][Adm:' . (int)$this->Application->isAdmin . ']'; $category_path = $this->Application->getCache($cache_key); - if ($category_path === false) { - // not chached - if ($category_id > 0) { + if ( $category_path === false ) { + // not cached + if ( $category_id > 0 ) { $id_field = $this->Application->getUnitOption('c', 'IDField'); $table_name = $this->Application->getUnitOption('c', 'TableName'); + $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); + /* @var $ml_formatter kMultiLanguage */ - $sql = 'SELECT '.$ml_formatter->LangFieldName('CachedNavbar').' - FROM '.$table_name.' - WHERE '.$id_field.' = '.$category_id; + $sql = 'SELECT ' . $ml_formatter->LangFieldName('CachedNavbar') . ' + FROM ' . $table_name . ' + WHERE ' . $id_field . ' = ' . $category_id; $cached_navbar = preg_replace('/^Content(&\|&){0,1}/i', '', $this->Conn->GetOne($sql)); - $category_path = trim($this->CategoryPath( Array('cat_id' => 0) ).' > '.str_replace('&|&', ' > ', $cached_navbar), ' > '); + $category_path = trim($this->CategoryPath(Array ('cat_id' => 0)) . ' > ' . str_replace('&|&', ' > ', $cached_navbar), ' > '); } else { $category_path = $this->Application->Phrase(($this->Application->isAdmin ? 'la_' : 'lu_') . 'rootcategory_name'); Index: branches/5.2.x/core/kernel/utility/formatters/ccdate_formatter.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/kernel/utility/formatters/ccdate_formatter.php (.../ccdate_formatter.php) (revision 14244) +++ branches/5.2.x/core/kernel/utility/formatters/ccdate_formatter.php (.../ccdate_formatter.php) (revision 14628) @@ -1,6 +1,6 @@ setVirtualFields($add_fields); } - function UpdateSubFields($field, $value, &$options, &$object) + /** + * Used for split fields like timestamp -> date, time + * Called from DBItem to update sub fields values after loading item + * + * @param string $field + * @param string $value + * @param Array $options + * @param kDBItem $object + * @return void + * @access public + */ + public function UpdateSubFields($field, $value, &$options, &$object) { - if(!$value) return false; + if ( !$value ) { + return ; + } + $date = explode('/', $value); - $object->SetDBField( $options['month_field'], $date[0] ); - $object->SetDBField( $options['year_field'], $date[1] ); + $object->SetDBField($options['month_field'], $date[0]); + $object->SetDBField($options['year_field'], $date[1]); } /** * Will work in future if we could attach 2 formatters to one field * - * @param string $value + * @param mixed $value * @param string $field_name * @param kDBItem $object - * @return string + * @return mixed + * @access public */ - function Parse($value, $field_name, &$object) + public function Parse($value, $field_name, &$object) { -// if ( is_null($value) ) return ''; - $options = $object->GetFieldOptions($field_name); $month = $object->GetDirtyField($options['month_field']); $year = $object->GetDirtyField($options['year_field']); - if( !(int)$month && !(int)$year ) return NULL; + if ( !(int)$month && !(int)$year ) { + return NULL; + } + $is_valid = ($month >= 1 && $month <= 12) && ($year >= 0 && $year <= 99); - if (!$is_valid) { + if ( !$is_valid ) { $object->SetError($field_name, 'bad_type'); } - return $month.'/'.$year; + + return $month . '/' . $year; } } \ No newline at end of file Index: branches/5.2.x/core/kernel/session/session.php =================================================================== diff -u -r14572 -r14628 --- branches/5.2.x/core/kernel/session/session.php (.../session.php) (revision 14572) +++ branches/5.2.x/core/kernel/session/session.php (.../session.php) (revision 14628) @@ -1,6 +1,6 @@ Mode == self::smGET_ONLY) { + if ( $this->Mode == self::smGET_ONLY ) { //we don't need to bother checking if we would not use it $this->CookiesEnabled = false; - return; + return false; } $http_query =& $this->Application->recallObject('HTTPQuery'); + /* @var $http_query kHTTPQuery */ + $cookies_on = array_key_exists('cookies_on', $http_query->Cookie); // not good here $get_sid = getArrayValue($http_query->Get, $this->GETName); - if (($this->IsHTTPSRedirect() && $get_sid) || $this->getFlashSID()) { // Redirect from http to https on different domain OR flash uploader + if ( ($this->IsHTTPSRedirect() && $get_sid) || $this->getFlashSID() ) { // Redirect from http to https on different domain OR flash uploader $this->OriginalMode = $this->Mode; $this->SetMode(self::smGET_ONLY); } - if (!$cookies_on || $this->IsHTTPSRedirect() || $this->getFlashSID()) { + if ( !$cookies_on || $this->IsHTTPSRedirect() || $this->getFlashSID() ) { //If referer is our server, but we don't have our cookies_on, it's definetly off $is_install = defined('IS_INSTALL') && IS_INSTALL; - if (!$is_install && $this->_checkCookieReferer() && !$this->Application->GetVar('admin') && !$this->IsHTTPSRedirect()) { + if ( !$is_install && $this->_checkCookieReferer() && !$this->Application->GetVar('admin') && !$this->IsHTTPSRedirect() ) { $this->CookiesEnabled = false; } else { @@ -476,6 +479,8 @@ if (!$get_sid) { $http_query =& $this->Application->recallObject('HTTPQuery'); + /* @var $http_query kHTTPQuery */ + $get_sid = getArrayValue($http_query->Get, $this->GETName); } Index: branches/5.2.x/core/units/fck/fck_tp.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/fck/fck_tp.php (.../fck_tp.php) (revision 14244) +++ branches/5.2.x/core/units/fck/fck_tp.php (.../fck_tp.php) (revision 14628) @@ -1,6 +1,6 @@ Application->recallObject('FCKHelper'); - /* @var fck_helper fckFCKHelper*/ + /* @var $fck_helper fckFCKHelper */ $default_folders = defined('FCK_DEFAULT_FOLDERS') ? FCK_DEFAULT_FOLDERS : Array ('Files', 'Images', 'Flash', 'Media', 'Documents'); Index: branches/5.2.x/core/units/custom_fields/custom_fields_tag_processor.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/units/custom_fields/custom_fields_tag_processor.php (.../custom_fields_tag_processor.php) (revision 14585) +++ branches/5.2.x/core/units/custom_fields/custom_fields_tag_processor.php (.../custom_fields_tag_processor.php) (revision 14628) @@ -1,6 +1,6 @@ Application->recallObject($source_prefix, null, Array ('raise_warnings' => 0)); // it's possible, that in some cases object will not be loaded /* @var $source_object kCatDBItem */ - $display_original = $this->Application->ProcessParsedTag($source_prefix, 'DisplayOriginal', Array('display_original' => $this->setParamValue($params, 'display_original'))); + $display_original = $this->Application->ProcessParsedTag($source_prefix, 'DisplayOriginal', Array ('display_original' => $this->setParamValue($params, 'display_original'))); } - if ($display_original) { + if ( $display_original ) { $block_params['display_original'] = $display_original; $block_params['original_title'] = $this->setParamValue($params, 'original_title'); - $original_object =& $this->Application->recallObject($source_prefix.'.original', null, Array ('raise_warnings' => 0)); // it's possible, that in some cases object will not be loaded + + $original_object =& $this->Application->recallObject($source_prefix . '.original', null, Array ('raise_warnings' => 0)); // it's possible, that in some cases object will not be loaded + /* @var $original_object kCatDBItem */ } if ($this->Special == 'general') { $list->groupRecords('Heading'); } $i = 0; - while (!$list->EOL()) - { + while ( !$list->EOL() ) { $block_params['is_last'] = ($i == $list->GetSelectedCount() - 1); $block_params['not_last'] = !$block_params['is_last']; // for front-end - $this->Application->SetVar( $this->getPrefixSpecial().'_id', $list->GetDBField($id_field) ); // for edit/delete links using GET + $this->Application->SetVar($this->getPrefixSpecial() . '_id', $list->GetDBField($id_field)); // for edit/delete links using GET - if ($source_prefix) { + if ( $source_prefix ) { $field_name = 'cust_' . $list->GetDBField('FieldName'); - + $formatter = $source_object->GetFieldOption($field_name, 'formatter'); $language_prefix = $formatter == 'kMultiLanguage' ? 'l' . $this->Application->GetVar('m_lang') . '_' : ''; - - $list->SetDBField($params['value_field'], $source_object->GetDBField($language_prefix . 'cust_'.$list->GetDBField('FieldName'))); - if ($display_original) { - $list->SetDBField('OriginalValue', $original_object->GetField('cust_'.$list->GetDBField('FieldName'))); + $list->SetDBField($params['value_field'], $source_object->GetDBField($language_prefix . 'cust_' . $list->GetDBField('FieldName'))); + + if ( $display_original ) { + $list->SetDBField('OriginalValue', $original_object->GetField('cust_' . $list->GetDBField('FieldName'))); } - $block_params['field'] = $block_params['virtual_field'] = 'cust_'.$list->GetDBField('FieldName'); - $block_params['show_heading'] = ($prev_heading != $list->GetDBField('Heading') ) ? 1 : 0; + $block_params['field'] = $block_params['virtual_field'] = 'cust_' . $list->GetDBField('FieldName'); + $block_params['show_heading'] = ($prev_heading != $list->GetDBField('Heading')) ? 1 : 0; $list->SetDBField('DirectOptions', $source_object->GetFieldOption($field_name, 'options')); } - $o.= $this->Application->ParseBlock($block_params); + $o .= $this->Application->ParseBlock($block_params); $prev_heading = $list->GetDBField('Heading'); $list->GoNext(); $i++; } - $this->Application->SetVar( $this->getPrefixSpecial().'_id', ''); + $this->Application->SetVar($this->getPrefixSpecial() . '_id', ''); + return $o; } Index: branches/5.2.x/core/units/images/images.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/images/images.php (.../images.php) (revision 14244) +++ branches/5.2.x/core/units/images/images.php (.../images.php) (revision 14628) @@ -1,6 +1,6 @@ Load($id); - $local_path = FULL_PATH.$this->GetDBField('LocalPath'); - $thumb_path = FULL_PATH.$this->GetDBField('ThumbPath'); - if(file_exists($local_path)) - { - unlink($local_path); - } - if(file_exists($thumb_path)) - { - unlink($thumb_path); - } - return parent::Delete($id); + /** + * Deletes the record from database + * + * @param int $id + * @return bool + * @access public + */ + public function Delete($id) + { + $this->Load($id); + $local_path = FULL_PATH . $this->GetDBField('LocalPath'); + $thumb_path = FULL_PATH . $this->GetDBField('ThumbPath'); + + if ( file_exists($local_path) ) { + unlink($local_path); } - } \ No newline at end of file + if ( file_exists($thumb_path) ) { + unlink($thumb_path); + } + + return parent::Delete($id); + } +} \ No newline at end of file Index: branches/5.2.x/core/units/helpers/email_message_helper.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/helpers/email_message_helper.php (.../email_message_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/email_message_helper.php (.../email_message_helper.php) (revision 14628) @@ -10,6 +10,7 @@ */ function parseTemplate($text) { + $line_id = 1; $ret = Array ('Subject' => '', 'Headers' => '', 'Body' => ''); $headers = Array(); $lines = explode("\n", $text); // "\n" is lost in process Index: branches/5.2.x/core/units/forms/submission_log/submission_log_eh.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/forms/submission_log/submission_log_eh.php (.../submission_log_eh.php) (revision 14244) +++ branches/5.2.x/core/units/forms/submission_log/submission_log_eh.php (.../submission_log_eh.php) (revision 14628) @@ -1,6 +1,6 @@ getSection(); $form_id = $this->Application->GetVar('form_id'); @@ -75,7 +76,8 @@ /* @var $form_submission_helper FormSubmissionHelper */ $form =& $form_submission_helper->getForm($form_submission); - + /* @var $form kDBItem */ + $from_email = $form->GetDBField('ReplyFromEmail'); $to_email = $form_submission_helper->getFieldByRole($form_submission, SubmissionFormField::COMMUNICATION_ROLE_EMAIL); @@ -233,8 +235,10 @@ * Updates last operation dates for log record * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemCreate(&$event) + protected function OnBeforeItemCreate(&$event) { parent::OnBeforeItemCreate($event); @@ -246,8 +250,10 @@ * Updates last operation dates for log record * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemUpdate(&$event) + protected function OnBeforeItemUpdate(&$event) { parent::OnBeforeItemUpdate($event); @@ -392,8 +398,10 @@ * Updates last update time for submission * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterItemCreate(&$event) + protected function OnAfterItemCreate(&$event) { parent::OnAfterItemCreate($event); @@ -405,11 +413,11 @@ $this->_updateSubmission($event); $reply_to = $object->GetDBField('ReplyTo'); - if (!$reply_to) { + if ( !$reply_to ) { $reply_to = $this->_getLastMessageId($event, !$this->Application->GetVar('client_mode')); } - if ($reply_to) { + if ( $reply_to ) { // this is reply to other message -> mark it as replied $org_message =& $this->Application->recallObject($event->Prefix . '.-item', null, Array ('skip_autoload' => true)); /* @var $org_message kDBItem */ @@ -419,7 +427,7 @@ $org_message->Update(); } - if ($this->Application->GetVar('client_mode')) { + if ( $this->Application->GetVar('client_mode') ) { // new reply from client received -> send notification about it $this->Application->EmailEventAdmin('FORM.SUBMISSION.REPLY.FROM.USER'); } Index: branches/5.2.x/core/units/themes/themes_eh.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/themes/themes_eh.php (.../themes_eh.php) (revision 14244) +++ branches/5.2.x/core/units/themes/themes_eh.php (.../themes_eh.php) (revision 14628) @@ -1,6 +1,6 @@ Name == 'OnItemBuild') { // check permission without using $event->getSection(), @@ -107,12 +109,14 @@ * Also rebuilds theme files, when enabled theme is saved * * @param kEvent $event + * @return void + * @access protected */ - function OnSave(&$event) + protected function OnSave(&$event) { parent::OnSave($event); - if (($event->status != kEvent::erSUCCESS) || !$event->getEventParam('ids')) { + if ( ($event->status != kEvent::erSUCCESS) || !$event->getEventParam('ids') ) { return ; } @@ -126,7 +130,7 @@ WHERE ' . $id_field . ' IN (' . $ids . ') AND (Enabled = 1)'; $enabled_themes = $this->Conn->GetOne($sql); - if ($enabled_themes) { + if ( $enabled_themes ) { $rebuild_event = new kEvent('adm:OnRebuildThemes'); $this->Application->HandleEvent($rebuild_event); } @@ -163,8 +167,11 @@ * Apply system filter to themes list * * @param kEvent $event + * @return void + * @access protected + * @see kDBEventHandler::OnListBuild() */ - function SetCustomQuery(&$event) + protected function SetCustomQuery(&$event) { parent::SetCustomQuery($event); Index: branches/5.2.x/core/kernel/processors/tag_processor.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/kernel/processors/tag_processor.php (.../tag_processor.php) (revision 14244) +++ branches/5.2.x/core/kernel/processors/tag_processor.php (.../tag_processor.php) (revision 14628) @@ -1,6 +1,6 @@ ProcessParsedTag($tag->Tag, $tag->NP, $tag->getPrefixSpecial()); } - function CheckTag($tag, $prefix) + /** + * Checks, that tag is implemented in this tag processor + * + * @param string $tag + * @param string $prefix + * + * @return bool + * @access public + */ + public function CheckTag($tag, $prefix) { - $Method = $tag; - if(method_exists($this, $Method)) - { + $method = $tag; + + if ( method_exists($this, $method) ) { return true; } - else { - if ($this->Application->hasObject('TagsAggregator')) { - $aggregator =& $this->Application->recallObject('TagsAggregator'); - $tmp = $this->Application->processPrefix($prefix); - $tag_mapping = $aggregator->GetArrayValue($tmp['prefix'], $Method); - if ($tag_mapping) { - return true; - } + + if ( $this->Application->hasObject('TagsAggregator') ) { + $aggregator =& $this->Application->recallObject('TagsAggregator'); + /* @var $aggregator kArray */ + + $tmp = $this->Application->processPrefix($prefix); + $tag_mapping = $aggregator->GetArrayValue($tmp['prefix'], $method); + + if ( $tag_mapping ) { + return true; } } + + return false; } function FormCacheKey($tag, $params, $prefix) @@ -84,6 +97,7 @@ list ($prefix_only, ) = explode('.', $prefix); $this->Application->Parser->PrefixesInUse[$prefix_only] = 1; + $cache_key = ''; $backup_prefix = $this->Prefix; $backup_special = $this->Special; @@ -133,15 +147,18 @@ function processAggregatedTag($tag, $params, $prefix, $file = 'unknown', $line = 0) { - if ($this->Application->hasObject('TagsAggregator')) { + if ( $this->Application->hasObject('TagsAggregator') ) { $Method = $tag; $aggregator =& $this->Application->recallObject('TagsAggregator'); + /* @var $aggregator kArray */ + $tmp = $this->Application->processPrefix($prefix); $tag_mapping = $aggregator->GetArrayValue($tmp['prefix'], $Method); - if ($tag_mapping) { + + if ( $tag_mapping ) { // aggregated tag defined $tmp = $this->Application->processPrefix($tag_mapping[0]); - $__tag_processor = $tmp['prefix'].'_TagProcessor'; + $__tag_processor = $tmp['prefix'] . '_TagProcessor'; $processor =& $this->Application->recallObject($__tag_processor); /* @var $processor kTagProcessor */ @@ -151,7 +168,7 @@ $params['original_tag'] = $Method; // allows to define same method for different aggregated tags in same tag processor $params['PrefixSpecial'] = $this->getPrefixSpecial(); // $prefix; $ret = $processor->ProcessParsedTag($tag_mapping[1], $params, $prefix); - if (isset($params['result_to_var'])) { + if ( isset($params['result_to_var']) ) { $this->Application->Parser->SetParam($params['result_to_var'], $ret); $ret = ''; } @@ -213,46 +230,46 @@ } - /** - * Not tag, method for parameter - * selection from list in this TagProcessor - * - * @param Array $params - * @param string $possible_names - * @return string - * @access public - */ - function SelectParam($params, $possible_names = null) - { - if (!isset($possible_names)) { - // select 1st parameter non-empty parameter value - $possible_names = explode(',', $params['possible_names']); - foreach ($possible_names as $param_name) { - $value = $this->Application->Parser->GetParam($param_name); - if (((string)$value != '') && ((string)$value != '0')) { - return $value; + /** + * Not tag, method for parameter + * selection from list in this TagProcessor + * + * @param Array $params + * @param string $possible_names + * @return string|bool + * @access protected + */ + protected function SelectParam($params, $possible_names = null) + { + if ( !isset($possible_names) ) { + // select 1st parameter non-empty parameter value + $possible_names = explode(',', $params['possible_names']); + + foreach ($possible_names as $param_name) { + $value = $this->Application->Parser->GetParam($param_name); + $string_value = (string)$value; + + if ( ($string_value != '') && ($string_value != '0') ) { + return $value; + } } + + return false; } - return ''; - } + if ( !is_array($possible_names) ) { + $possible_names = explode(',', $possible_names); + } - if (!is_array($params)) { - // really happens? - return; - } + foreach ($possible_names as $name) { + if ( isset($params[$name]) ) { + return $params[$name]; + } + } - if (!is_array($possible_names)) { - $possible_names = explode(',', $possible_names); + return false; } - foreach ($possible_names as $name) { - if( isset($params[$name]) ) return $params[$name]; - } - - return false; - } - /** * Returns templates path for module, which is gathered from prefix module * Index: branches/5.2.x/core/kernel/managers/cache_manager.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/kernel/managers/cache_manager.php (.../cache_manager.php) (revision 14585) +++ branches/5.2.x/core/kernel/managers/cache_manager.php (.../cache_manager.php) (revision 14628) @@ -1,6 +1,6 @@ Application->isCachingType(CACHING_TYPE_MEMORY) ) { Index: branches/5.2.x/core/units/logs/change_logs/changes_formatter.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/logs/change_logs/changes_formatter.php (.../changes_formatter.php) (revision 14244) +++ branches/5.2.x/core/units/logs/change_logs/changes_formatter.php (.../changes_formatter.php) (revision 14628) @@ -1,6 +1,6 @@ $data) { - $fld_translation = $this->Application->Phrase('la_fld_'.$field); + foreach ($changes as $field => $data) { + $fld_translation = $this->Application->Phrase('la_fld_' . $field); - // remove translation link (added in debug mode) - $fld_translation = preg_replace('/(.*?)<\/a>/', '\\2', $fld_translation); + // remove translation link (added in debug mode) + $fld_translation = preg_replace('/(.*?)<\/a>/', '\\2', $fld_translation); - if ($fld_translation == '!'.strtoupper('la_fld_'.$field).'!') { - // when phrase is not translated use field name as label - $fld_translation = $field; + if ( $fld_translation == '!' . strtoupper('la_fld_' . $field) . '!' ) { + // when phrase is not translated use field name as label + $fld_translation = $field; + } + + if ( is_array($data) ) { + if ( $format == 'auto_cut' ) { + $data = array_map(Array (&$this, 'cutValue'), $data); } - if (is_array($data)) { - if ($format == 'auto_cut') { - $data = array_map(Array (&$this, 'cutValue'), $data); - } - - if (array_key_exists('old', $data) && array_key_exists('new', $data)) { - $res .= "$fld_translation: {$data['old']} => {$data['new']}
\n"; - } - else { - $res .= "$fld_translation: {$data['new']}
\n"; - } + if ( array_key_exists('old', $data) && array_key_exists('new', $data) ) { + $res .= "$fld_translation: {$data['old']} => {$data['new']}
\n"; } else { - if ($format == 'auto_cut') { - $data = $this->cutValue($data); - } - - $res .= "$fld_translation: {$data}
\n"; + $res .= "$fld_translation: {$data['new']}
\n"; } + } + else { + if ( $format == 'auto_cut' ) { + $data = $this->cutValue($data); + } + $res .= "$fld_translation: {$data}
\n"; } - return $res; } - function cutValue($data) - { - if (strlen($data) > 200) { - $data = substr($data, 0, 50) . ' ...'; - } + return $res; + } - return $data; + function cutValue($data) + { + if ( strlen($data) > 200 ) { + $data = substr($data, 0, 50) . ' ...'; } - } \ No newline at end of file + + return $data; + } +} \ No newline at end of file Index: branches/5.2.x/core/units/thesaurus/thesaurus_eh.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/thesaurus/thesaurus_eh.php (.../thesaurus_eh.php) (revision 14244) +++ branches/5.2.x/core/units/thesaurus/thesaurus_eh.php (.../thesaurus_eh.php) (revision 14628) @@ -1,6 +1,6 @@ _Params[$name] = $val; } @@ -79,11 +80,11 @@ * Gets parameter value by parameter name * * @param string $name Name of variable to retrieve - * @param int $default default value returned in case if varible not present + * @param mixed $default default value returned in case if variable not present * @return string * @access public */ - function Get($name, $default = false) + public function Get($name, $default = false) { return isset($this->_Params[$name]) ? $this->_Params[$name] : $default; } Index: branches/5.2.x/core/units/content/content_eh.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/content/content_eh.php (.../content_eh.php) (revision 14244) +++ branches/5.2.x/core/units/content/content_eh.php (.../content_eh.php) (revision 14628) @@ -1,6 +1,6 @@ Application->recallObject('PermissionsHelper'); /* @var $perm_helper kPermissionsHelper */ Index: branches/5.2.x/core/units/admin/admin_tag_processor.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 14585) +++ branches/5.2.x/core/units/admin/admin_tag_processor.php (.../admin_tag_processor.php) (revision 14628) @@ -1,6 +1,6 @@ Application->GetVar('section_name'); + $sections_helper =& $this->Application->recallObject('SectionsHelper'); + /* @var $sections_helper kSectionsHelper */ + $section_data =& $sections_helper->getSectionData($section_name); $block_params = array_merge($section_data, Array('name' => $params['render_as'], 'section_name' => $section_name)); @@ -326,8 +329,7 @@ $params[$param_name] = kUtil::replaceModuleSection($param_value); } - $m =& $this->Application->recallObject('m_TagProcessor'); - return $m->ModuleInclude($params); + return $this->Application->ProcessParsedTag('m', 'ModuleInclude', $params); } function TodayDate($params) @@ -493,71 +495,83 @@ // user can override default parameters (except pass_through of course) $params = array_merge($default_params, $params); - $main_processor =& $this->Application->recallObject('m_TagProcessor'); - return $main_processor->T($params); + return $this->Application->ProcessParsedTag('m', 'T', $params); } function TimeFrame($params) { $w = adodb_date('w'); $m = adodb_date('m'); $y = adodb_date('Y'); + //FirstDayOfWeek is 0 for Sunday and 1 for Monday $fdow = $this->Application->ConfigValue('FirstDayOfWeek'); - if ($fdow && $w == 0) $w = 7; - $today_start = adodb_mktime(0,0,0,adodb_date('m'),adodb_date('d'),$y); - $first_day_of_this_week = $today_start - ($w - $fdow)*86400; - $first_day_of_this_month = adodb_mktime(0,0,0,$m,1,$y); - $this_quater = ceil($m/3); - $this_quater_start = adodb_mktime(0,0,0,$this_quater*3-2,1,$y); - switch ($params['type']) { + if ( $fdow && $w == 0 ) { + $w = 7; + } + $today_start = adodb_mktime(0, 0, 0, adodb_date('m'), adodb_date('d'), $y); + $first_day_of_this_week = $today_start - ($w - $fdow) * 86400; + $first_day_of_this_month = adodb_mktime(0, 0, 0, $m, 1, $y); + $this_quater = ceil($m / 3); + $this_quater_start = adodb_mktime(0, 0, 0, $this_quater * 3 - 2, 1, $y); + + switch ( $params['type'] ) { case 'last_week_start': - $timestamp = $first_day_of_this_week - 86400*7; + $timestamp = $first_day_of_this_week - 86400 * 7; break; + case 'last_week_end': $timestamp = $first_day_of_this_week - 1; break; case 'last_month_start': - $timestamp = $m == 1 ? adodb_mktime(0,0,0,12,1,$y-1) : adodb_mktime(0,0,0,$m-1,1,$y); + $timestamp = $m == 1 ? adodb_mktime(0, 0, 0, 12, 1, $y - 1) : adodb_mktime(0, 0, 0, $m - 1, 1, $y); break; + case 'last_month_end': - $timestamp = $first_day_of_this_month = adodb_mktime(0,0,0,$m,1,$y) - 1; + $timestamp = $first_day_of_this_month = adodb_mktime(0, 0, 0, $m, 1, $y) - 1; break; case 'last_quater_start': - $timestamp = $this_quater == 1 ? adodb_mktime(0,0,0,10,1,$y-1) : adodb_mktime(0,0,0,($this_quater-1)*3-2,1,$y); + $timestamp = $this_quater == 1 ? adodb_mktime(0, 0, 0, 10, 1, $y - 1) : adodb_mktime(0, 0, 0, ($this_quater - 1) * 3 - 2, 1, $y); break; + case 'last_quater_end': $timestamp = $this_quater_start - 1; break; case 'last_6_months_start': - $timestamp = $m <= 6 ? adodb_mktime(0,0,0,$m+6,1,$y-1) : adodb_mktime(0,0,0,$m-6,1,$y); + $timestamp = $m <= 6 ? adodb_mktime(0, 0, 0, $m + 6, 1, $y - 1) : adodb_mktime(0, 0, 0, $m - 6, 1, $y); break; case 'last_year_start': - $timestamp = adodb_mktime(0,0,0,1,1,$y-1); + $timestamp = adodb_mktime(0, 0, 0, 1, 1, $y - 1); break; + case 'last_year_end': - $timestamp = adodb_mktime(23,59,59,12,31,$y-1); + $timestamp = adodb_mktime(23, 59, 59, 12, 31, $y - 1); break; + + default: + $timestamp = 0; + break; } - - if (isset($params['format'])) { + if ( isset($params['format']) ) { $format = $params['format']; - if(preg_match("/_regional_(.*)/", $format, $regs)) - { + + if ( preg_match("/_regional_(.*)/", $format, $regs) ) { $lang =& $this->Application->recallObject('lang.current'); + /* @var $lang LanguagesItem */ + $format = $lang->GetDBField($regs[1]); } + return adodb_date($format, $timestamp); } return $timestamp; - } /** @@ -813,14 +827,21 @@ return $skin_helper->AdminSkinTag($params); } - function PrintCompileErrors($params) + /** + * Prints errors, discovered during mass template compilation + * + * @param $params + * @return string + * @access protected + */ + protected function PrintCompileErrors($params) { $block_params = $this->prepareTagParams($params); $block_params['name'] = $params['render_as']; $errors = $this->Application->RecallVar('compile_errors'); - if (!$errors) { - return ; + if ( !$errors ) { + return ''; } $ret = ''; Index: branches/5.2.x/core/units/category_items/category_items_dbitem.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/category_items/category_items_dbitem.php (.../category_items_dbitem.php) (revision 14244) +++ branches/5.2.x/core/units/category_items/category_items_dbitem.php (.../category_items_dbitem.php) (revision 14628) @@ -1,6 +1,6 @@ getLinkedInfo(); + return '(CategoryId=' . $this->GetID() . ' AND ' . $table_info['ForeignKey'] . '=' . $table_info['ParentId'] . ')'; + } - /** - * Returns part of SQL WHERE clause identifing the record, ex. id = 25 - * - * @access public - * @param string $method Child class may want to know who called GetKeyClause, Load(), Update(), Delete() send its names as method - * @return void - * @see kDBItem::Load() - * @see kDBItem::Update() - * @see kDBItem::Delete() - */ - function GetKeyClause($method=null) - { - $table_info = $this->getLinkedInfo(); - return '(CategoryId='.$this->ID.' AND '.$table_info['ForeignKey'].'='.$table_info['ParentId'].')'; - } - - /** - * Generate and set new temporary id - * - * @access private - */ - function setTempID() - { - // don't set temp id for this item - } - - } \ No newline at end of file + /** + * Generate and set new temporary id + * + * @return void + * @access public + */ + public function setTempID() + { + // don't set temp id for this item + } +} \ No newline at end of file Index: branches/5.2.x/core/units/selectors/selectors_event_handler.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/selectors/selectors_event_handler.php (.../selectors_event_handler.php) (revision 14244) +++ branches/5.2.x/core/units/selectors/selectors_event_handler.php (.../selectors_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ Init($event->Prefix, '-item'); + $object =& $event->getObject(); + /* @var $object kDBItem */ $title_field = 'SelectorName'; $new_name = $object->GetDBField($title_field); $original_checked = false; $foreign_key = $event->getEventParam('foreign_key'); // in case if whole stylesheet is cloned - if($foreign_key === false) $foreign_key = $object->GetDBField('StylesheetId'); // in case if selector is copied ifself + if ( $foreign_key === false ) { + $foreign_key = $object->GetDBField('StylesheetId'); + } // in case if selector is copied ifself do { if ( preg_match('/(.*)-([\d]+)/', $new_name, $regs) ) { - $new_name = $regs[1].'-'.($regs[2]+1); + $new_name = $regs[1] . '-' . ($regs[2] + 1); } - elseif ($original_checked) { - $new_name = $new_name.'-1'; + elseif ( $original_checked ) { + $new_name = $new_name . '-1'; } // if we are cloning in temp table this will look for names in temp table, // since object' TableName contains correct TableName (for temp also!) // if we are cloning live - look in live - $query = ' SELECT '.$title_field.' - FROM '.$object->TableName.' - WHERE '.$title_field.' = '.$this->Conn->qstr($new_name).' AND StylesheetId = '.$foreign_key; + $query = ' SELECT ' . $title_field . ' + FROM ' . $object->TableName . ' + WHERE ' . $title_field . ' = ' . $this->Conn->qstr($new_name) . ' AND StylesheetId = ' . $foreign_key; $res = $this->Conn->GetOne($query); @@ -79,20 +87,24 @@ }*/ $original_checked = true; - } while ($res !== false); + } while ( $res !== false ); $object->SetDBField($title_field, $new_name); } /** * Show base styles or block styles * * @param kEvent $event + * @return void + * @access protected + * @see kDBEventHandler::OnListBuild() */ - function SetCustomQuery(&$event) + protected function SetCustomQuery(&$event) { $object =& $event->getObject(); - switch ($event->Special) - { + /* @var $object kDBList */ + + switch ( $event->Special ) { case 'base': $object->addFilter('type_filter', '%1$s.Type = 1'); break; @@ -104,22 +116,30 @@ } /** - * Enter description here... + * Occurs before updating item * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemUpdate(&$event) + protected function OnBeforeItemUpdate(&$event) { + parent::OnBeforeItemUpdate($event); + $this->SerializeSelectorData($event); } /** - * Enter description here... + * Occurs before creating item * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemCreate(&$event) + protected function OnBeforeItemCreate(&$event) { + parent::OnBeforeItemCreate($event); + $this->SerializeSelectorData($event); } @@ -134,17 +154,21 @@ } /** - * Enter description here... + * Occurs after creating item * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterItemCreate(&$event) + protected function OnAfterItemCreate(&$event) { + parent::OnAfterItemCreate($event); + $this->UnserializeSelectorData($event); } /** - * Get's special of main item for linking with subitem + * Gets special of main item for linking with sub-item * * @param kEvent $event * @return string @@ -173,19 +197,22 @@ function SaveChanges(&$event) { $object =& $event->getObject( Array('skip_autoload' => true) ); + /* @var $object kDBItem */ - $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); - if($items_info) - { - list($id,$field_values) = each($items_info); - if ($id == 0) { - $parent_id = getArrayValue($field_values,'ParentId'); - if($parent_id) $object->Load($parent_id); + $items_info = $this->Application->GetVar($event->getPrefixSpecial(true)); + if ( $items_info ) { + list($id, $field_values) = each($items_info); + + if ( $id == 0 ) { + $parent_id = getArrayValue($field_values, 'ParentId'); + if ( $parent_id ) { + $object->Load($parent_id); + } $object->SetFieldsFromHash($field_values); $object->Create(); - $this->Application->SetVar($event->getPrefixSpecial().'_id', $object->GetID() ); + $this->Application->SetVar($event->getPrefixSpecial() . '_id', $object->GetID()); } else { $object->Load($id); @@ -214,20 +241,26 @@ * Extract styles * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterItemLoad(&$event) + protected function OnAfterItemLoad(&$event) { + parent::OnAfterItemLoad($event); + $object =& $event->getObject(); + /* @var $object kDBItem */ + $selector_data = $object->GetDBField('SelectorData'); - if($selector_data) - { + + if ( $selector_data ) { $selector_data = unserialize($selector_data); $object->SetDBField('SelectorData', $selector_data); } - else - { - $selector_data = Array(); + else { + $selector_data = Array (); } + $this->AddParentProperties($event, $selector_data); } @@ -239,12 +272,18 @@ function SerializeSelectorData(&$event) { $object =& $event->getObject(); + /* @var $object kDBItem */ + $selector_data = $object->GetDBField('SelectorData'); - if(!$selector_data) $selector_data = Array(); + if ( !$selector_data ) { + $selector_data = Array (); + } $selector_data = $this->RemoveParentProperties($event, $selector_data); - if( !kUtil::IsSerialized($selector_data) ) $selector_data = serialize($selector_data); + if ( !kUtil::IsSerialized($selector_data) ) { + $selector_data = serialize($selector_data); + } $object->SetDBField('SelectorData', $selector_data); } @@ -257,10 +296,18 @@ function UnserializeSelectorData(&$event) { $object =& $event->getObject(); + /* @var $object kDBItem */ + $selector_data = $object->GetDBField('SelectorData'); - if(!$selector_data) $selector_data = Array(); - if( kUtil::IsSerialized($selector_data) ) $selector_data = unserialize($selector_data); + if ( !$selector_data ) { + $selector_data = Array (); + } + + if ( kUtil::IsSerialized($selector_data) ) { + $selector_data = unserialize($selector_data); + } + $selector_data = $this->AddParentProperties($event, $selector_data); $object->SetDBField('SelectorData', $selector_data); @@ -291,33 +338,37 @@ function RemoveParentProperties(&$event, $selector_data) { $object =& $event->getObject(); + /* @var $object kDBItem */ + $parent_id = $object->GetDBField('ParentId'); - if($parent_id) - { - $sql = 'SELECT SelectorData FROM '.$object->TableName.' WHERE '.$object->IDField.' = '.$parent_id; + + if ( $parent_id ) { + $sql = 'SELECT SelectorData + FROM ' . $object->TableName . ' + WHERE ' . $object->IDField . ' = ' . $parent_id; $base_selector_data = $this->Conn->GetOne($sql); - if( kUtil::IsSerialized($base_selector_data) ) $base_selector_data = unserialize($base_selector_data); + if ( kUtil::IsSerialized($base_selector_data) ) { + $base_selector_data = unserialize($base_selector_data); + } - foreach($selector_data as $prop_name => $prop_value) - { - if( !$prop_value || getArrayValue($base_selector_data,$prop_name) == $prop_value ) - { + foreach ($selector_data as $prop_name => $prop_value) { + if ( !$prop_value || getArrayValue($base_selector_data, $prop_name) == $prop_value ) { unset($selector_data[$prop_name]); } } - $object->SetDBField('SelectorData', $selector_data); - return $selector_data; } - else - { - foreach($selector_data as $prop_name => $prop_value) - { - if(!$prop_value) unset($selector_data[$prop_name]); + else { + foreach ($selector_data as $prop_name => $prop_value) { + if ( !$prop_value ) { + unset($selector_data[$prop_name]); + } } - $object->SetDBField('SelectorData', $selector_data); - return $selector_data; } + + $object->SetDBField('SelectorData', $selector_data); + + return $selector_data; } /** @@ -328,20 +379,26 @@ function AddParentProperties(&$event, $selector_data) { $object =& $event->getObject(); + /* @var $object kDBItem */ + $parent_id = $object->GetDBField('ParentId'); - if($parent_id) - { - $sql = 'SELECT SelectorData FROM '.$object->TableName.' WHERE '.$object->IDField.' = '.$parent_id; + if ( $parent_id ) { + $sql = 'SELECT SelectorData + FROM ' . $object->TableName . ' + WHERE ' . $object->IDField . ' = ' . $parent_id; $base_selector_data = $this->Conn->GetOne($sql); - if( kUtil::IsSerialized($base_selector_data) ) $base_selector_data = unserialize($base_selector_data); + if ( kUtil::IsSerialized($base_selector_data) ) { + $base_selector_data = unserialize($base_selector_data); + } - $selector_data = kUtil::array_merge_recursive($base_selector_data,$selector_data); - + $selector_data = kUtil::array_merge_recursive($base_selector_data, $selector_data); $object->SetDBField('SelectorData', $selector_data); + return $selector_data; } - return $selector_data; + + return Array (); } /** @@ -352,10 +409,12 @@ function OnResetToBase(&$event) { $object =& $event->getObject(); + /* @var $object SelectorsItem */ + $object->SetFieldsFromHash( $this->getSubmittedFields($event) ); $object->ResetStyle(); - $event->SetRedirectParam('pass', 'all,'.$event->getPrefixSpecial()); + $event->SetRedirectParam('pass', 'all,' . $event->getPrefixSpecial()); } /** @@ -366,14 +425,14 @@ function OnMassResetToBase(&$event) { $object =& $event->getObject( Array('skip_autoload' => true) ); + /* @var $object SelectorsItem */ $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); - if($items_info) - { - foreach($items_info as $id => $field_values) - { + + if ( $items_info ) { + foreach ($items_info as $id => $field_values) { $object->Load($id); - $object->ResetStyle(); + $object->ResetStyle(); } } } Index: branches/5.2.x/core/units/configuration/configuration_event_handler.php =================================================================== diff -u -r14572 -r14628 --- branches/5.2.x/core/units/configuration/configuration_event_handler.php (.../configuration_event_handler.php) (revision 14572) +++ branches/5.2.x/core/units/configuration/configuration_event_handler.php (.../configuration_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ setEventParam('PermSection', $this->Application->GetVar('section')); return parent::CheckPermission($event); @@ -31,10 +33,11 @@ * Apply any custom changes to list's sql query * * @param kEvent $event + * @return void * @access protected - * @see OnListBuild + * @see kDBEventHandler::OnListBuild() */ - function SetCustomQuery(&$event) + protected function SetCustomQuery(&$event) { $object =& $event->getObject(); /* @var $object kDBList */ @@ -57,50 +60,55 @@ } /** - * Enter description here... + * Performs validation of configuration variable value * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemUpdate(&$event) + protected function OnBeforeItemUpdate(&$event) { static $default_field_options = null; + parent::OnBeforeItemUpdate($event); + $object =& $event->getObject(); /* @var $object kDBItem */ // ability to validate each configuration variable separately - if (!isset($default_field_options)) { + if ( !isset($default_field_options) ) { $default_field_options = $object->GetFieldOptions('VariableValue'); } $new_field_options = $default_field_options; $validation = $object->GetDBField('Validation'); - if ($validation) { + + if ( $validation ) { $new_field_options = array_merge($new_field_options, unserialize($validation)); } + $object->SetFieldOptions('VariableValue', $new_field_options); // if password field is empty, then don't update - if ($object->GetDBField('ElementType') == 'password') { - if (trim($object->GetDBField('VariableValue')) == '') { + if ( $object->GetDBField('ElementType') == 'password' ) { + if ( trim($object->GetDBField('VariableValue')) == '' ) { $field_options = $object->GetFieldOptions('VariableValue'); $field_options['skip_empty'] = 1; $object->SetFieldOptions('VariableValue', $field_options); - }else { + } + else { $password_formatter =& $this->Application->recallObject('kPasswordFormatter'); + /* @var $password_formatter kPasswordFormatter */ + $object->SetDBField('VariableValue', $password_formatter->EncryptPassword($object->GetDBField('VariableValue'), 'b38')); } } - $field_values = $this->Application->GetVar( $event->getPrefixSpecial(true) ); - - $state_country_hash = Array ( - 'Comm_State' => 'Comm_Country', - 'Comm_Shipping_State' => 'Comm_Shipping_Country' - ); - $field_name = $object->GetDBField('VariableName'); - if (array_key_exists($field_name, $state_country_hash)) { + $field_values = $this->Application->GetVar($event->getPrefixSpecial(true)); + $state_country_hash = Array ('Comm_State' => 'Comm_Country', 'Comm_Shipping_State' => 'Comm_Shipping_Country'); + + if ( array_key_exists($field_name, $state_country_hash) ) { // if this is state field $sql = 'SELECT VariableId FROM ' . $this->Application->getUnitOption('conf', 'TableName') . ' @@ -110,16 +118,16 @@ $check_state = $object->GetDBField('VariableValue'); $check_country = $field_values[$country_variable_id]['VariableValue']; - if (!$check_country || !$check_state) { - return true; + if ( !$check_country || !$check_state ) { + return; } $cs_helper =& $this->Application->recallObject('CountryStatesHelper'); /* @var $cs_helper kCountryStatesHelper */ $state_iso = $cs_helper->getStateIso($check_state, $check_country); - if ($state_iso !== false) { + if ( $state_iso !== false ) { $object->SetDBField('VariableValue', $state_iso); } else { @@ -128,13 +136,12 @@ } } - if ($object->GetDBField('VariableName') == 'AdminConsoleInterface') { + if ( $object->GetDBField('VariableName') == 'AdminConsoleInterface' ) { $can_change = $this->Application->ConfigValue('AllowAdminConsoleInterfaceChange'); - if (($object->GetDBField('VariableValue') != $object->GetOriginalField('VariableValue')) && !$can_change) { + if ( ($object->GetDBField('VariableValue') != $object->GetOriginalField('VariableValue')) && !$can_change ) { $object->SetError('VariableValue', 'not_allowed', 'la_error_OperationNotAllowed'); } - } } Index: branches/5.2.x/core/kernel/utility/formatters/customfield_formatter.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/kernel/utility/formatters/customfield_formatter.php (.../customfield_formatter.php) (revision 14244) +++ branches/5.2.x/core/kernel/utility/formatters/customfield_formatter.php (.../customfield_formatter.php) (revision 14628) @@ -1,6 +1,6 @@ GetFieldOptions($field_name); Index: branches/5.2.x/core/units/helpers/rating_helper.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/helpers/rating_helper.php (.../rating_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/rating_helper.php (.../rating_helper.php) (revision 14628) @@ -1,6 +1,6 @@ Application->getUnitOption($object->Prefix, 'PermItemPrefix'); $static = !$this->Application->CheckPermission($perm_prefix . '.RATE', 0, $object->GetDBField('CategoryId')); @@ -60,47 +62,47 @@ /* @var $spam_helper SpamHelper */ $config_mapping = $this->Application->getUnitOption($object->Prefix, 'ConfigMapping'); - $review_settings = $config_mapping['RatingDelayValue'].':'.$config_mapping['RatingDelayInterval']; + $review_settings = $config_mapping['RatingDelayValue'] . ':' . $config_mapping['RatingDelayInterval']; $spam_helper->InitHelper($object->GetDBField('ResourceId'), 'Rating', $review_settings, $object->GetCol('ResourceId')); $user_voted = $spam_helper->InSpamControl(); // now draw the rating bar - $unit_selected_width = $additional_style? $this->ratingSmallUnitWidth : $this->ratingUnitWidth; + $unit_selected_width = $additional_style ? $this->ratingSmallUnitWidth : $this->ratingUnitWidth; $rating_width = $total_votes ? @number_format($total_rating / $total_votes, 2) * $unit_selected_width : 0; $rating1 = $total_votes ? @number_format($total_rating / $total_votes, 1) : 0; $rating2 = $total_votes ? @number_format($total_rating / $total_votes, 2) : 0; $rater = '
'; // this part is disabled for now, will be addressed once properly review // $rater .= '

' . - $this->_replaceInPhrase('vote_title', Array(''.$rating1.'', $this->ratingMaximal)) . ' ('. $this->_replaceInPhrase('vote_count', Array($total_votes)) . ')

'; + $this->_replaceInPhrase('vote_title', Array ('' . $rating1 . '', $this->ratingMaximal)) . ' (' . $this->_replaceInPhrase('vote_count', Array ($total_votes)) . ')

'; - $rater .= ' '.$additional_msg.''; + $rater .= ' ' . $additional_msg . ''; - if ($show_div) { + if ( $show_div ) { // adds div around rating stars (when drawing rating first time) $rater = '
' . $rater . '
'; } Index: branches/5.2.x/core/kernel/managers/request_manager.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/kernel/managers/request_manager.php (.../request_manager.php) (revision 14244) +++ branches/5.2.x/core/kernel/managers/request_manager.php (.../request_manager.php) (revision 14628) @@ -1,6 +1,6 @@ Application->EventManager->verifyEventPrefix($event, true) ) { - return ; + $false = false; + + return $false; } $event->setEventParam('top_prefix', $this->Application->GetTopmostPrefix($event->Prefix, true)); $event_handler =& $this->Application->recallObject($event->Prefix . '_EventHandler'); /* @var $event_handler kEventHandler */ - if (($this->Application->RecallVar('user_id') == USER_ROOT) || $event_handler->CheckPermission($event)) { + if ( ($this->Application->RecallVar('user_id') == USER_ROOT) || $event_handler->CheckPermission($event) ) { $this->Application->HandleEvent($event); } Index: branches/5.2.x/core/units/selectors/selectors_tag_processor.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/selectors/selectors_tag_processor.php (.../selectors_tag_processor.php) (revision 14244) +++ branches/5.2.x/core/units/selectors/selectors_tag_processor.php (.../selectors_tag_processor.php) (revision 14628) @@ -1,6 +1,6 @@ Application->recallObject( $this->getPrefixSpecial(), $this->Prefix, $params ); + $object =& $this->getObject($params); + /* @var $object SelectorsItem */ + $style_data = $object->GetDBField( $params['field'] ); $ret = $object->CompileStyleBody( getArrayValue($params,'inline') ? STYLE_INLINE : STYLE_PREVIEW ); @@ -62,34 +64,50 @@ return $ret; } - function PredefinedOptions($params) + /** + * Prints list a all possible field options + * + * @param Array $params + * @return string + * @access protected + */ + protected function PredefinedOptions($params) { $field = $params['field']; - $object =& $this->Application->recallObject($this->getPrefixSpecial(),$this->Prefix, $params); + $object =& $this->getObject($params); + /* @var $object kDBItem */ + $value = $object->GetDBField($field); - $subfield = getArrayValue($params,'subfield'); - if($subfield && $subfield != '$subfield') $value = $value[$subfield]; + $subfield = getArrayValue($params, 'subfield'); + + if ( $subfield && $subfield != '$subfield' ) { + $value = $value[$subfield]; + } - $value_field = getArrayValue($params,'value_field'); - if(!$value_field) $value_field = $field; + $value_field = getArrayValue($params, 'value_field'); + if ( !$value_field ) { + $value_field = $field; + } - $options = $object->GetFieldOptions($value_field); - $block_params['name'] = $params['block']; $block_params['field'] = $params['field']; $block_params['pass_params'] = 'true'; $selected_param_name = getArrayValue($params, 'selected_param'); - if (!$selected_param_name) $selected_param_name = $params['selected']; + if ( !$selected_param_name ) { + $selected_param_name = $params['selected']; + } $selected = $params['selected']; $o = ''; - foreach ($options['options'] as $key => $val) { + $options = $object->GetFieldOption($value_field, 'options'); + + foreach ($options as $key => $val) { $block_params['key'] = $key; $block_params['option'] = $val; $block_params['field_name'] = $this->InputName($params); - $block_params[$selected_param_name] = ( $key == $value ? ' '.$selected : ''); + $block_params[$selected_param_name] = ($key == $value ? ' ' . $selected : ''); $block_params['PrefixSpecial'] = $this->getPrefixSpecial(); $o .= $this->Application->ParseBlock($block_params, 1); } Index: branches/5.2.x/core/units/helpers/filenames_helper.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/units/helpers/filenames_helper.php (.../filenames_helper.php) (revision 14585) +++ branches/5.2.x/core/units/helpers/filenames_helper.php (.../filenames_helper.php) (revision 14628) @@ -1,6 +1,6 @@ SelectParam($params, 'name,field'); - $object =& $this->Application->recallObject($this->getPrefixSpecial(),$this->Prefix, $params); + $object =& $this->getObject($params); + /* @var $object kDBItem */ - $value = $object->GetDBField($field); + $value = $object->GetDBField($this->SelectParam($params, 'name,field')); - if ($value) return 'checked'; - if (is_null($value)) return $params['default']; + if ( $value ) { + return 'checked'; + } + + if ( is_null($value) ) { + return $params['default']; + } return ''; } function MaxUploadSize($params) { - return round(MAX_UPLOAD_SIZE/1024/1024).' Mb'; + return round(MAX_UPLOAD_SIZE / 1024 / 1024) . ' Mb'; } } \ No newline at end of file Index: branches/5.2.x/core/units/reviews/reviews_event_handler.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 14244) +++ branches/5.2.x/core/units/reviews/reviews_event_handler.php (.../reviews_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ Name == 'OnAddReview' || $event->Name == 'OnCreate') { $perm_helper =& $this->Application->recallObject('PermissionsHelper'); @@ -87,9 +89,13 @@ $res = $this->Application->CheckPermission($perm_prefix . '.ADD', 0, $perm_category) || $this->Application->CheckPermission($perm_prefix . '.MODIFY', 0, $perm_category); break; + + default: + $res = false; + break; } - if (!$res) { + if ( !$res ) { $event->status = kEvent::erPERM_FAIL; } @@ -167,54 +173,50 @@ * @access protected * @see OnListBuild */ - function SetCustomQuery(&$event) + protected function SetCustomQuery(&$event) { $object =& $event->getObject(); /* @var $object kDBList */ - if (!$this->Application->isAdminUser) { - $object->addFilter('active', '%1$s.Status = '.STATUS_ACTIVE); + if ( !$this->Application->isAdminUser ) { + $object->addFilter('active', '%1$s.Status = ' . STATUS_ACTIVE); } - switch ($event->Special) - { + switch ( $event->Special ) { case 'showall': $object->clearFilters(); break; case 'item': // used ? $object->clearFilters(); - $info = $object->getLinkedInfo(); - $this->Application->setUnitOption($info['ParentPrefix'], 'AutoLoad', true); - $parent =& $this->Application->recallObject($info['ParentPrefix']); - $object->addFilter('item_reviews', '%1$s.ItemId = '.$parent->GetDBField('ResourceId')); + $parent_info = $object->getLinkedInfo(); + + $parent =& $this->Application->recallObject($parent_info['ParentPrefix']); + /* @var $parent kDBItem */ + + $object->addFilter('item_reviews', '%1$s.ItemId = ' . $parent->GetDBField('ResourceId')); break; - case 'products': // used in In-Portal (Sturcture & Data -> Reviews section) - $object->removeFilter('parent_filter'); // this is important + case 'products': // used in In-Portal (Structure & Data -> Reviews section) + $object->removeFilter('parent_filter'); // this is important $object->addFilter('product_reviews', 'pr.ResourceId IS NOT NULL'); break; - - /*case 'product': - $object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId'); // for LEFT JOIN - break;*/ } - if (preg_match('/(.*)-rev/', $event->Prefix, $regs)) { + if ( preg_match('/(.*)-rev/', $event->Prefix, $regs) ) { // "Structure & Data" -> "Reviews" (section in K4) $item_type = $this->Application->getUnitOption($regs[1], 'ItemType'); $object->addFilter('itemtype_filter', '%1$s.ItemType = ' . $item_type); - if ($this->Application->isAdmin) { + if ( $this->Application->isAdmin ) { // temporarily solution so we can see sub-items on separate grid in Admin $object->removeFilter('parent_filter'); - } + } } - if ($event->getEventParam('type') == 'current_user') { -// $object->removeFilter('active'); - $object->addFilter('current_user', '%1$s.CreatedById = '.$this->Application->RecallVar('user_id')); - $object->addFilter('current_ip', '%1$s.IPAddress = "'.$_SERVER['REMOTE_ADDR'].'"'); + if ( $event->getEventParam('type') == 'current_user' ) { + $object->addFilter('current_user', '%1$s.CreatedById = ' . $this->Application->RecallVar('user_id')); + $object->addFilter('current_ip', '%1$s.IPAddress = "' . $_SERVER['REMOTE_ADDR'] . '"'); } } @@ -256,9 +258,13 @@ * Prefills all fields on front-end * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemCreate(&$event) + protected function OnBeforeItemCreate(&$event) { + parent::OnBeforeItemCreate($event); + $object =& $event->getObject(); /* @var $object kDBItem */ @@ -269,7 +275,7 @@ $object->SetDBField('ItemType', $item_type); $object->SetDBField('Module', $this->Application->findModule('Var', $parent_info['ParentPrefix'], 'Name')); - if ($this->Application->isAdminUser) { + if ( $this->Application->isAdminUser ) { // don't perform spam control on admin return ; } @@ -279,14 +285,14 @@ $spam_helper->InitHelper($parent_info['ParentId'], 'Review', 0); - if ($spam_helper->InSpamControl()) { + if ( $spam_helper->InSpamControl() ) { $event->status = kEvent::erFAIL; $object->SetError('ReviewText', 'too_frequent', 'lu_ferror_review_duplicate'); - return ; + return; } $rating = $object->GetDBField('Rating'); - if ($rating < 1 || $rating > 5) { + if ( $rating < 1 || $rating > 5 ) { $object->SetDBField('Rating', null); } @@ -301,13 +307,19 @@ * Sets correct rating value * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemUpdate(&$event) + protected function OnBeforeItemUpdate(&$event) { + parent::OnBeforeItemUpdate($event); + $object =& $event->getObject(); + /* @var $object kDBItem */ $rating = $object->GetDBField('Rating'); - if (!$rating) { + + if ( !$rating ) { $object->SetDBField('Rating', null); } } @@ -316,27 +328,33 @@ * Updates item review counter * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterItemCreate(&$event) + protected function OnAfterItemCreate(&$event) { + parent::OnAfterItemCreate($event); + $this->updateSubitemCounters($event); - if (!$this->Application->isAdminUser) { + if ( !$this->Application->isAdminUser ) { $spam_helper =& $this->Application->recallObject('SpamHelper'); /* @var $spam_helper SpamHelper */ $object =& $event->getObject(); + /* @var $object kDBItem */ + $parent_info = $object->getLinkedInfo(); $config_mapping = $this->Application->getUnitOption($event->Prefix, 'ConfigMapping'); - $review_settings = $config_mapping['ReviewDelayValue'].':'.$config_mapping['ReviewDelayInterval']; + $review_settings = $config_mapping['ReviewDelayValue'] . ':' . $config_mapping['ReviewDelayInterval']; $spam_helper->InitHelper($parent_info['ParentId'], 'Review', $review_settings); $spam_helper->AddToSpamControl(); $review_status = $object->GetDBField('Status'); - if ($review_status == STATUS_ACTIVE || $review_status == STATUS_PENDING) { + if ( $review_status == STATUS_ACTIVE || $review_status == STATUS_PENDING ) { $email_event = $this->getPermPrefix($event) . '.REVIEW.' . ($review_status == STATUS_ACTIVE ? 'ADD' : 'ADD.PENDING'); $this->Application->EmailEventUser($email_event, $object->GetDBField('CreatedById')); $this->Application->EmailEventAdmin($email_event); Index: branches/5.2.x/core/units/languages/languages_event_handler.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/units/languages/languages_event_handler.php (.../languages_event_handler.php) (revision 14585) +++ branches/5.2.x/core/units/languages/languages_event_handler.php (.../languages_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ Name == 'OnItemBuild') { // check permission without using $event->getSection(), @@ -204,18 +206,21 @@ } /** - * Occurse before updating item + * Occurs before updating item * * @param kEvent $event - * @access public + * @return void + * @access protected */ - function OnBeforeItemUpdate(&$event) + protected function OnBeforeItemUpdate(&$event) { $object =& $event->getObject(); + /* @var $object kDBItem */ + $status_fields = $this->Application->getUnitOption($event->Prefix, 'StatusField'); $status_field = array_shift($status_fields); - if ($object->GetDBField('PrimaryLang') == 1 && $object->GetDBField($status_field) == 0) { + if ( $object->GetDBField('PrimaryLang') == 1 && $object->GetDBField($status_field) == 0 ) { $object->SetDBField($status_field, 1); } } @@ -224,8 +229,11 @@ * Shows only enabled languages on front * * @param kEvent $event + * @return void + * @access protected + * @see kDBEventHandler::OnListBuild() */ - function SetCustomQuery(&$event) + protected function SetCustomQuery(&$event) { $object =& $event->getObject(); /* @var $object kDBList */ @@ -255,8 +263,10 @@ * Copy labels from another language * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterItemCreate(&$event) + protected function OnAfterItemCreate(&$event) { parent::OnAfterItemCreate($event); @@ -265,14 +275,14 @@ $src_language = $object->GetDBField('CopyFromLanguage'); - if ($object->GetDBField('CopyLabels') && $src_language) { + if ( $object->GetDBField('CopyLabels') && $src_language ) { $dst_language = $object->GetID(); // 1. schedule data copy after OnSave event is executed $var_name = $event->getPrefixSpecial() . '_copy_data' . $this->Application->GetVar('m_wid'); $pending_actions = $this->Application->RecallVar($var_name, Array ()); - if ($pending_actions) { + if ( $pending_actions ) { $pending_actions = unserialize($pending_actions); } @@ -286,24 +296,28 @@ * Saves language from temp table to live * * @param kEvent $event + * @return void + * @access protected */ - function OnSave(&$event) + protected function OnSave(&$event) { parent::OnSave($event); - if ($event->status != kEvent::erSUCCESS) { - return ; + if ( $event->status != kEvent::erSUCCESS ) { + return; } $var_name = $event->getPrefixSpecial() . '_copy_data' . $this->Application->GetVar('m_wid'); $pending_actions = $this->Application->RecallVar($var_name, Array ()); - if ($pending_actions) { + if ( $pending_actions ) { $pending_actions = unserialize($pending_actions); } // create multilingual columns for phrases & email events table first (actual for 6+ language) $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); + /* @var $ml_helper kMultiLanguageHelper */ + $ml_helper->createFields('phrases'); $ml_helper->createFields('emailevents'); @@ -333,16 +347,22 @@ * done in OnPreSaveCreated * * @param kEvent $event + * @return void + * @access protected */ - function OnPreCreate(&$event) + protected function OnPreCreate(&$event) { parent::OnPreCreate($event); $object =& $event->getObject(); + /* @var $object kDBItem */ + $object->SetDBField('CopyLabels', 1); - $live_table = $this->Application->getUnitOption($event->Prefix, 'TableName'); - $primary_lang_id = $this->Conn->GetOne('SELECT '.$object->IDField.' FROM '.$live_table.' WHERE PrimaryLang = 1'); + $sql = 'SELECT ' . $object->IDField . ' + FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' + WHERE PrimaryLang = 1'; + $primary_lang_id = $this->Conn->GetOne($sql); $object->SetDBField('CopyFromLanguage', $primary_lang_id); } @@ -351,18 +371,21 @@ * Sets new language mark * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeDeleteFromLive(&$event) + protected function OnBeforeDeleteFromLive(&$event) { + parent::OnBeforeDeleteFromLive($event); + $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); - $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); $sql = 'SELECT ' . $id_field . ' - FROM ' . $table_name . ' + FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' WHERE ' . $id_field . ' = ' . $event->getEventParam('id'); $id = $this->Conn->GetOne($sql); - if (!$id) { + if ( !$id ) { $this->Application->SetVar('new_language', 1); } } @@ -556,11 +579,10 @@ */ function OnBeforeItemDelete(&$event) { - $del_id = $event->getEventParam('id'); - $object =& $event->getObject(array('skip_autload' => true)); - $object->Load($del_id); + $object =& $event->getObject(); + /* @var $object kDBItem */ - if ($object->GetDBField('PrimaryLang') || $object->GetDBField('AdminInterfaceLang') || $del_id == $this->Application->GetVar('m_lang')) { + if ( $object->GetDBField('PrimaryLang') || $object->GetDBField('AdminInterfaceLang') || $object->GetID() == $this->Application->GetVar('m_lang') ) { $event->status = kEvent::erFAIL; } } Index: branches/5.2.x/core/units/user_groups/user_groups_dbitem.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/user_groups/user_groups_dbitem.php (.../user_groups_dbitem.php) (revision 14244) +++ branches/5.2.x/core/units/user_groups/user_groups_dbitem.php (.../user_groups_dbitem.php) (revision 14628) @@ -1,6 +1,6 @@ getLinkedInfo($this->Special, true); - if ($table_info) { - // we have parent info, then use it - $keys_hash = Array( - $this->IDField => $this->ID, - $table_info['ForeignKey'] => $table_info['ParentId'], - ); - } - return parent::GetKeyClause($method, $keys_hash); + /** + * Returns part of SQL WHERE clause identifying the record, ex. id = 25 + * + * @param string $method Child class may want to know who called GetKeyClause, Load(), Update(), Delete() send its names as method + * @param Array $keys_hash alternative, then item id, keys hash to load item by + * @see kDBItem::Load() + * @see kDBItem::Update() + * @see kDBItem::Delete() + * + * @return string + * @access protected + */ + protected function GetKeyClause($method = null, $keys_hash = null) + { + $table_info = $this->getLinkedInfo($this->Special, true); + + if ( $table_info ) { + // we have parent info, then use it + $keys_hash = Array ($this->IDField => $this->GetID(), $table_info['ForeignKey'] => $table_info['ParentId']); } - } \ No newline at end of file + return parent::GetKeyClause($method, $keys_hash); + } +} \ No newline at end of file Index: branches/5.2.x/core/units/helpers/form_submission_helper.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/helpers/form_submission_helper.php (.../form_submission_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/form_submission_helper.php (.../form_submission_helper.php) (revision 14628) @@ -1,6 +1,6 @@ Application->recallObject('form', null, Array ('skip_autoload' => true)); /* @var $form kDBItem */ - if (!$form->isLoaded() || ($form->GetID() != $form_id)) { + if ( !$form->isLoaded() || ($form->GetID() != $form_id) ) { $form->Load($form_id); } Index: branches/5.2.x/core/units/helpers/permissions_helper.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/helpers/permissions_helper.php (.../permissions_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/permissions_helper.php (.../permissions_helper.php) (revision 14628) @@ -1,6 +1,6 @@ Application->recallObject($prefix.'_EventHandler'); + /* @var $event_handler kEventHandler */ + return $event_handler->CheckPermission( new kEvent($perm_event) ); } Index: branches/5.2.x/core/units/fck/fck_eh.php =================================================================== diff -u -r14572 -r14628 --- branches/5.2.x/core/units/fck/fck_eh.php (.../fck_eh.php) (revision 14572) +++ branches/5.2.x/core/units/fck/fck_eh.php (.../fck_eh.php) (revision 14628) @@ -1,6 +1,6 @@ Application->isAdminUser) { // this limits all event execution only to logged-in users in admin @@ -101,15 +103,15 @@ } $fck_helper =& $this->Application->recallObject('FCKHelper'); - /* @var fck_helper fckFCKHelper*/ + /* @var $fck_helper fckFCKHelper*/ - if (!$fck_helper->IsAllowedExtension($folder, $new_name)) { + if ( !$fck_helper->IsAllowedExtension($folder, $new_name) ) { echo 203; return; } - if (!rename($sServerDir.$old_name,$sServerDir.$new_name)) { - // echo $sServerDir.$old_name.' -> '.$sServerDir.$new_name; + if ( !rename($sServerDir . $old_name, $sServerDir . $new_name) ) { +// echo $sServerDir.$old_name.' -> '.$sServerDir.$new_name; echo 205; return; } @@ -192,16 +194,24 @@ } } - function OnUploadFile(&$event) + /** + * Uploads a file from FCK file browser + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnUploadFile(&$event) { $event->status = kEvent::erSTOP; - if ($this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1)) { + if ( $this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1) ) { return; } $fck_helper =& $this->Application->recallObject('FCKHelper'); - /* @var fck_helper fckFCKHelper*/ + /* @var $fck_helper fckFCKHelper*/ + $fck_helper->UploadFile(); } } \ No newline at end of file Index: branches/5.2.x/core/kernel/event_manager.php =================================================================== diff -u -r14428 -r14628 --- branches/5.2.x/core/kernel/event_manager.php (.../event_manager.php) (revision 14428) +++ branches/5.2.x/core/kernel/event_manager.php (.../event_manager.php) (revision 14628) @@ -1,6 +1,6 @@ Application->recallObject('kActions'); - $actions->Set('events['.$prefix_special.']',$event_name); + /* @var $actions Params */ + + $actions->Set('events[' . $prefix_special . ']', $event_name); } /** Index: branches/5.2.x/core/kernel/session/inp_session.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/kernel/session/inp_session.php (.../inp_session.php) (revision 14244) +++ branches/5.2.x/core/kernel/session/inp_session.php (.../inp_session.php) (revision 14628) @@ -1,6 +1,6 @@ SessionTimeout = $this->Application->ConfigValue('SessionTimeout'); @@ -24,40 +32,49 @@ $this->SetCookiePath($path); $cookie_name = $this->Application->ConfigValue('SessionCookieName'); - if (!$cookie_name) { + + if ( !$cookie_name ) { $cookie_name = 'sid'; } $admin_session = ($this->Application->isAdmin && $special !== 'front') || ($special == 'admin'); - if ($admin_session) { + if ( $admin_session ) { $cookie_name = 'adm_' . $cookie_name; } $this->SetCookieName($cookie_name); - $this->SetCookieDomain(SERVER_NAME); - if ($admin_session) { + if ( $admin_session ) { $mode = self::smAUTO; } - elseif (defined('IS_INSTALL') && IS_INSTALL) { + elseif ( defined('IS_INSTALL') && IS_INSTALL ) { $mode = self::smCOOKIES_ONLY; } else { $ses_mode = $this->Application->ConfigValue('CookieSessions'); - if ($ses_mode == 2) $mode = self::smAUTO; - if ($ses_mode == 1) $mode = self::smCOOKIES_ONLY; - if ($ses_mode == 0) $mode = self::smGET_ONLY; + if ( $ses_mode == 2 ) { + $mode = self::smAUTO; + } + elseif ( $ses_mode == 1 ) { + $mode = self::smCOOKIES_ONLY; + } + elseif ( $ses_mode == 0 ) { + $mode = self::smGET_ONLY; + } + else { + $mode = self::smAUTO; + } } $this->SetMode($mode); parent::Init($prefix, $special); - if (!$this->Application->isAdmin && $this->GetField('PortalUserId') <= 0) { - $group_list = $this->Application->ConfigValue('User_GuestGroup').','.$this->Application->ConfigValue('User_LoggedInGroup'); + if ( !$this->Application->isAdmin && $this->GetField('PortalUserId') <= 0 ) { + $group_list = $this->Application->ConfigValue('User_GuestGroup') . ',' . $this->Application->ConfigValue('User_LoggedInGroup'); $this->SetField('GroupId', $this->Application->ConfigValue('User_GuestGroup')); $this->SetField('GroupList', $group_list); } Index: branches/5.2.x/core/units/reviews/reviews_tag_processor.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/reviews/reviews_tag_processor.php (.../reviews_tag_processor.php) (revision 14244) +++ branches/5.2.x/core/units/reviews/reviews_tag_processor.php (.../reviews_tag_processor.php) (revision 14628) @@ -1,6 +1,6 @@ SelectParam($params, 'name,field'); - $object =& $this->Application->recallObject($this->getPrefixSpecial(),$this->Prefix, $params); + + $object =& $this->getObject($params); + /* @var $object kDBItem */ if ($field == 'ReviewText') { if ($object->GetDBField('TextFormat') == 1) { Index: branches/5.2.x/core/units/related_searches/related_searches_event_handler.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/related_searches/related_searches_event_handler.php (.../related_searches_event_handler.php) (revision 14244) +++ branches/5.2.x/core/units/related_searches/related_searches_event_handler.php (.../related_searches_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ getObject(); + /* @var $object kDBItem */ $table_info = $object->getLinkedInfo(); Index: branches/5.2.x/core/units/languages/languages_tag_processor.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/languages/languages_tag_processor.php (.../languages_tag_processor.php) (revision 14244) +++ branches/5.2.x/core/units/languages/languages_tag_processor.php (.../languages_tag_processor.php) (revision 14628) @@ -1,6 +1,6 @@ Application->GetTopmostPrefix($this->Prefix); if( substr($this->Application->GetVar($top_prefix.'_mode'), 0, 1) == 't' && !$edit_direct ) { - $object =& $this->getObject(); + $object =& $this->getObject($params); + /* @var $object kDBItem */ + return $object->GetDBField('Charset'); } + $lang_current =& $this->Application->recallObject('lang.current'); + /* @var $lang_current LanguagesItem */ + return $lang_current->GetDBField('Charset'); } @@ -98,17 +103,18 @@ /** * Returns path where exported languages should be saved * - * @param unknown_type $params + * @param Array $params + * @return string + * @access protected */ - function ExportPath($params) + protected function ExportPath($params) { + $ret = EXPORT_PATH . '/'; - $ret = EXPORT_PATH.'/'; - - if( getArrayValue($params,'as_url') ) - { - $ret = str_replace( FULL_PATH.'/', $this->Application->BaseURL(), $ret); + if ( getArrayValue($params, 'as_url') ) { + $ret = str_replace(FULL_PATH . '/', $this->Application->BaseURL(), $ret); } + return $ret; } Index: branches/5.2.x/core/units/helpers/sections_helper.php =================================================================== diff -u -r14560 -r14628 --- branches/5.2.x/core/units/helpers/sections_helper.php (.../sections_helper.php) (revision 14560) +++ branches/5.2.x/core/units/helpers/sections_helper.php (.../sections_helper.php) (revision 14628) @@ -1,6 +1,6 @@ Application->isCachingType(CACHING_TYPE_MEMORY) ) { $data = $this->Application->getCache('master:sections_parsed', false, CacheSettings::$sectionsParsedRebuildTime); @@ -105,10 +106,11 @@ foreach ($prefixes as $prefix) { $config =& $this->Application->UnitConfigReader->configData[$prefix]; - if (array_key_exists('ConfigPriority', $config)) { + if ( array_key_exists('ConfigPriority', $config) ) { $prioritized_prefixes[$prefix] = $config['ConfigPriority']; continue; } + $this->_processPrefixSections($prefix); } @@ -118,20 +120,24 @@ $this->_processPrefixSections($prefix); } - // 2. apply section ajustments + // 2. apply section adjustments foreach ($prefixes as $prefix) { $config =& $this->Application->UnitConfigReader->configData[$prefix]; - $section_ajustments = getArrayValue($config, 'SectionAdjustments'); - if (!$section_ajustments) continue; + $section_adjustments = getArrayValue($config, 'SectionAdjustments'); + /* @var $section_adjustments Array */ - foreach ($section_ajustments as $section_name => $ajustment_params) { - if (is_array($ajustment_params)) { - if (!array_key_exists($section_name, $this->Tree)) { - // don't process ajustments for non-existing sections + if ( !$section_adjustments ) { + continue; + } + + foreach ($section_adjustments as $section_name => $adjustment_params) { + if ( is_array($adjustment_params) ) { + if ( !array_key_exists($section_name, $this->Tree) ) { + // don't process adjustments for non-existing sections continue; } - $this->Tree[$section_name] = kUtil::array_merge_recursive($this->Tree[$section_name], $ajustment_params); + $this->Tree[$section_name] = kUtil::array_merge_recursive($this->Tree[$section_name], $adjustment_params); } else { // then remove section @@ -146,52 +152,46 @@ $parent_section = $section_params['parent']; $section_order = "{$section_params['priority']}"; - if (!isset($parent_section)) { + if ( !isset($parent_section) ) { // don't process parent section of "in-portal:root" section continue; } - if (!array_key_exists('children', $this->Tree[$parent_section])) { + if ( !array_key_exists('children', $this->Tree[$parent_section]) ) { $this->Tree[$parent_section]['children'] = Array (); } - if (array_key_exists($section_order, $this->Tree[$parent_section]['children'])) { - trigger_error( - 'Section "' . $section_name . '" has replaced section "' . - $this->Tree[$parent_section]['children'][$section_order] . - '" (parent section: "' . $parent_section . - '"; duplicate priority: ' . $section_order . ')', - E_USER_WARNING - ); + if ( array_key_exists($section_order, $this->Tree[$parent_section]['children']) ) { + trigger_error('Section "' . $section_name . '" has replaced section "' . $this->Tree[$parent_section]['children'][$section_order] . '" (parent section: "' . $parent_section . '"; duplicate priority: ' . $section_order . ')', E_USER_WARNING); } $this->Tree[$parent_section]['children'][$section_order] = $section_name; - if ($section_params['type'] == stTAB) { + if ( $section_params['type'] == stTAB ) { // if this is tab, then mark parent section as TabOnly $this->Tree[$parent_section]['tabs_only'] = true; } - // 3.2. process icons here, because they also can be ajusted - if (isset($section_params['icon']) && preg_match('/([^:]+):(.*)/', $section_params['icon'], $regs)) { + // 3.2. process icons here, because they also can be adjusted + if ( isset($section_params['icon']) && preg_match('/([^:]+):(.*)/', $section_params['icon'], $regs) ) { $this->Tree[$section_name]['icon'] = $regs[2]; $this->Tree[$section_name]['icon_module'] = $regs[1]; // set "icon_module" used in "combined_header" block - $module_folder = trim( $this->Application->findModule('Name', $regs[1], 'Path'), '/'); + $module_folder = trim($this->Application->findModule('Name', $regs[1], 'Path'), '/'); - if ($module_folder == '') { + if ( $module_folder == '' ) { $module_folder = 'core'; } } else { $module_folder = $this->Application->getUnitOption($section_params['SectionPrefix'], 'ModuleFolder'); - if (!array_key_exists('icon_module', $section_params)) { + if ( !array_key_exists('icon_module', $section_params) ) { // set "icon_module" used in "combined_header" block $this->Tree[$section_name]['icon_module'] = $this->Application->findModule('Path', $module_folder . '/', 'Name'); } } // this is to display HELP icon instead of missing one.. can be replaced with some other icon to draw attention - $icon_file = $module_folder.'/admin_templates/img/icons/icon24_'.$this->Tree[$section_name]['icon']; + $icon_file = $module_folder . '/admin_templates/img/icons/icon24_' . $this->Tree[$section_name]['icon']; /*$core_file = FULL_PATH.'/core/admin_templates/img/icons/icon24_' . $this->Tree[$section_name]['icon'].'.png'; if ($module_folder != 'core' && file_exists($core_file) && file_exists(FULL_PATH.'/'.$icon_file.'.png')) { @@ -200,13 +200,13 @@ } }*/ - if (!file_exists(FULL_PATH . '/' . $icon_file . '.png')) { + if ( !file_exists(FULL_PATH . '/' . $icon_file . '.png') ) { $this->Tree[$section_name]['icon'] = 'help'; $this->Tree[$section_name]['icon_module'] = 'core'; } } - $this->Application->HandleEvent( new kEvent('adm:OnAfterBuildTree') ); + $this->Application->HandleEvent(new kEvent('adm:OnAfterBuildTree')); if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) { $this->Application->setCache('master:sections_parsed', serialize($this->Tree)); @@ -220,12 +220,12 @@ { $config =& $this->Application->UnitConfigReader->configData[$prefix]; $sections = getArrayValue($config, 'Sections'); - if (!$sections) { + /* @var $sections Array */ + + if ( !$sections ) { return ; } -// echo 'Prefix: ['.$prefix.'] has ['.count($sections).'] sections
'; - foreach ($sections as $section_name => $section_params) { // we could also skip not allowed sections here in future if ( isset($section_params['SectionPrefix']) ) { @@ -237,35 +237,37 @@ else { $section_prefix = $prefix; } + $section_params['SectionPrefix'] = $section_prefix; $section_params['url']['m_opener'] = 'r'; $section_params['url']['no_pass_through'] = 1; $pass_section = getArrayValue($section_params, 'url', 'pass_section'); - if ($pass_section) { + if ( $pass_section ) { unset($section_params['url']['pass_section']); $section_params['url']['section'] = $section_name; - if (!isset($section_params['url']['module'])) { - $module_name = $this->Application->findModule('Path', $config['ModuleFolder'].'/', 'Name'); + + if ( !isset($section_params['url']['module']) ) { + $module_name = $this->Application->findModule('Path', $config['ModuleFolder'] . '/', 'Name'); $section_params['url']['module'] = $module_name; } } - if (!isset($section_params['url']['t'])) { + if ( !isset($section_params['url']['t']) ) { $section_params['url']['t'] = 'index'; } - if (!isset($section_params['onclick'])) { + if ( !isset($section_params['onclick']) ) { $section_params['onclick'] = 'checkEditMode()'; } - if (!isset($section_params['container'])) { + if ( !isset($section_params['container']) ) { $section_params['container'] = 0; // for js tree printing to xml } - $current_data = isset($this->Tree[$section_name]) ? $this->Tree[$section_name] : Array(); + $current_data = isset($this->Tree[$section_name]) ? $this->Tree[$section_name] : Array (); - if ($current_data) { + if ( $current_data ) { trigger_error('Section "' . $section_name . '" declaration (originally defined in "' . $current_data['SectionPrefix'] . '") was overwriten from "' . $prefix . '"', E_USER_WARNING); } @@ -294,19 +296,21 @@ * Returns first child, that is not a folder * * @param string $section_name - * @param Array $tree - * @return stirng + * @param bool $check_permission + * @return string + * @access public */ - function getFirstChild($section_name, $check_permission = false) + public function getFirstChild($section_name, $check_permission = false) { $section_data =& $this->getSectionData($section_name); - $children = isset($section_data['children']) && $section_data['children'] ? $section_data['children'] : false; - if ($children) { + /* @var $children Array */ + + if ( $children ) { // get 1st child ksort($children, SORT_NUMERIC); - foreach ($children as $child_priority => $child_section) { - if (!$this->sectionVisible($child_section, $check_permission)) { + foreach ($children as $child_section) { + if ( !$this->sectionVisible($child_section, $check_permission) ) { continue; } Index: branches/5.2.x/core/units/groups/groups_event_handler.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/groups/groups_event_handler.php (.../groups_event_handler.php) (revision 14244) +++ branches/5.2.x/core/units/groups/groups_event_handler.php (.../groups_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ getObject(); /* @var $object kDBList */ @@ -53,8 +56,10 @@ * Refreshes left tree on save * * @param kEvent $event + * @return void + * @access protected */ - function OnSave(&$event) + protected function OnSave(&$event) { parent::OnSave($event); Index: branches/5.2.x/core/units/visits/visits_event_handler.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/visits/visits_event_handler.php (.../visits_event_handler.php) (revision 14244) +++ branches/5.2.x/core/units/visits/visits_event_handler.php (.../visits_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ Application->isAdmin || !$this->Application->ConfigValue('UseVisitorTracking')) { - // admin logins are not registred in visits list - return true; + if ( $this->Application->isAdmin || !$this->Application->ConfigValue('UseVisitorTracking') || $this->Application->RecallVar('visit_id') ) { + // admin logins are not registered in visits list + return ; } - if ($this->Application->RecallVar('visit_id')) { - return true; - } + $object =& $event->getObject(Array ('skip_autoload' => true)); + /* @var $object kDBItem */ - $object =& $event->getObject( Array('skip_autoload' => true) ); - $object->SetDBField('VisitDate_date', adodb_mktime() ); - $object->SetDBField('VisitDate_time', adodb_mktime() ); - $object->SetDBField('Referer', getArrayValue($_SERVER, 'HTTP_REFERER') ); - $object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR'] ); + $object->SetDBField('VisitDate_date', adodb_mktime()); + $object->SetDBField('VisitDate_time', adodb_mktime()); + $object->SetDBField('Referer', getArrayValue($_SERVER, 'HTTP_REFERER')); + $object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']); - if ($object->Create()) { - $this->Application->StoreVar('visit_id', $object->GetID() ); - $this->Application->SetVar('visits_id', $object->GetID() ); + if ( $object->Create() ) { + $this->Application->StoreVar('visit_id', $object->GetID()); + $this->Application->SetVar('visits_id', $object->GetID()); } } /** * Apply any custom changes to list's sql query * * @param kEvent $event + * @return void * @access protected - * @see OnListBuild + * @see kDBEventHandler::OnListBuild() */ - function SetCustomQuery(&$event) + protected function SetCustomQuery(&$event) { $object =& $event->getObject(); + /* @var $object kDBList */ $types = $event->getEventParam('types'); - if($types == 'myvisitors') - { + if ( $types == 'myvisitors' ) { $user_id = $this->Application->RecallVar('user_id'); - $object->addFilter('myitems_user1','au.PortalUserId = '.$user_id); - $object->addFilter('myitems_user2','au.PortalUserId >0'); + $object->addFilter('myitems_user1', 'au.PortalUserId = ' . $user_id); + $object->addFilter('myitems_user2', 'au.PortalUserId >0'); //$object->AddGroupByField('VisitDate'); $object->AddGroupByField('%1$s.VisitId'); - } - if($types == 'myvisitororders' && $event->Special == 'incommerce') - { + if ( $types == 'myvisitororders' && $event->Special == 'incommerce' ) { $user_id = $this->Application->RecallVar('user_id'); - $object->addFilter('myitems_orders','ord.OrderId IS NOT NULL'); - $object->addFilter('myitems_user1','au.PortalUserId = '.$user_id); - $object->addFilter('myitems_user2','au.PortalUserId >0'); - $object->addFilter('myitems_orders_processed','ord.Status = 4'); + $object->addFilter('myitems_orders', 'ord.OrderId IS NOT NULL'); + $object->addFilter('myitems_user1', 'au.PortalUserId = ' . $user_id); + $object->addFilter('myitems_user2', 'au.PortalUserId >0'); + $object->addFilter('myitems_orders_processed', 'ord.Status = 4'); } } /** - * Apply some special processing to - * object beeing recalled before using - * it in other events that call prepareObject + * Apply some special processing to object being + * recalled before using it in other events that + * call prepareObject * - * @param kBase $object + * @param kDBItem|kDBList $object * @param kEvent $event + * @return void * @access protected */ - function prepareObject(&$object, &$event) + protected function prepareObject(&$object, &$event) { $types = $event->getEventParam('types'); if(method_exists($object, 'AddGroupByField')) Index: branches/5.2.x/core/units/helpers/geocode_helper.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/helpers/geocode_helper.php (.../geocode_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/geocode_helper.php (.../geocode_helper.php) (revision 14628) @@ -1,6 +1,6 @@ GetFromCache($address, $city, $state, $zip); -// $zip_info = $this->GetFromCache($address, $city, $state, $zip); - if (!$zip_info && !$force_cache) { + if ( !$zip_info && !$force_cache ) { list($lon, $lat, $zip4, $dpbc, $carrier, $geocode_answer) = $this->QueryCoordinatesFromGoogle($address, $city, $state, $zip); - if ($lon != '' && $lat != '') { + if ( $lon != '' && $lat != '' ) { // valid position returned by geocode => add to cache $fields_hash = Array( - 'zipcode' => $zip4, - 'address' => $address, - 'city' => $city, - 'state' => $state, - 'lat' => $lat, - 'lon' => $lon, - 'zip4' => $zip4, - 'dpbc' => $dpbc, - 'carrier' => $carrier, - 'geocode_answer' => $geocode_answer, - ); - $this->Conn->doInsert($fields_hash, TABLE_PREFIX.'ZipCodes'); - return Array($lon, $lat, $zip4, $dpbc, $carrier); + 'zipcode' => $zip4, + 'address' => $address, + 'city' => $city, + 'state' => $state, + 'lat' => $lat, + 'lon' => $lon, + 'zip4' => $zip4, + 'dpbc' => $dpbc, + 'carrier' => $carrier, + 'geocode_answer' => $geocode_answer, + ); + + $this->Conn->doInsert($fields_hash, TABLE_PREFIX . 'ZipCodes'); + return Array ($lon, $lat, $zip4, $dpbc, $carrier); } else { // bad case, rie call failed => no data retrieved return false; } } - return Array($zip_info['lon'], $zip_info['lat'], getArrayValue($zip_info, 'zip4'), getArrayValue($zip_info, 'dpbc'), getArrayValue($zip_info, 'carrier')); + return Array ($zip_info['lon'], $zip_info['lat'], getArrayValue($zip_info, 'zip4'), getArrayValue($zip_info, 'dpbc'), getArrayValue($zip_info, 'carrier')); } /** @@ -173,14 +176,14 @@ * @param string $city * @param string $state * @param int $zip - * @return Array (lon, lat) + * @return Array|bool (lon, lat) */ function GetFromCache($address, $city, $state, $zip) { $zip = substr($zip, 0, 5); // use only first 5 digits $sql = 'SELECT lon, lat - FROM '.TABLE_PREFIX.'ZipCodes - WHERE zipcode = '.$this->Conn->qstr($zip); + FROM ' . TABLE_PREFIX . 'ZipCodes + WHERE zipcode = ' . $this->Conn->qstr($zip); return $this->Conn->GetRow($sql); } } \ No newline at end of file Index: branches/5.2.x/core/kernel/utility/formatters/filesize_formatter.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/kernel/utility/formatters/filesize_formatter.php (.../filesize_formatter.php) (revision 14244) +++ branches/5.2.x/core/kernel/utility/formatters/filesize_formatter.php (.../filesize_formatter.php) (revision 14628) @@ -1,6 +1,6 @@ = 1099511627776) { Index: branches/5.2.x/core/units/email_events/email_event_tp.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/email_events/email_event_tp.php (.../email_event_tp.php) (revision 14244) +++ branches/5.2.x/core/units/email_events/email_event_tp.php (.../email_event_tp.php) (revision 14628) @@ -1,6 +1,6 @@ Application->isDebugMode()) { - $grids = $this->Application->getUnitOption($this->Prefix, 'Grids'); + if ( !$this->Application->isDebugMode() ) { + $grids = $this->Application->getUnitOption($this->Prefix, 'Grids', Array ()); + /* @var $grids Array */ foreach ($grids as $grid_name => $grid_data) { - if (array_key_exists('Enabled', $grid_data['Fields'])) { + if ( array_key_exists('Enabled', $grid_data['Fields']) ) { unset($grids[$grid_name]['Fields']['Enabled']); } } Index: branches/5.2.x/core/units/helpers/country_states_helper.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/helpers/country_states_helper.php (.../country_states_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/country_states_helper.php (.../country_states_helper.php) (revision 14628) @@ -1,6 +1,6 @@ Conn->GetOne($sql); } + /** + * Checks, that entered state matches entered country + * + * @param kEvent $event + * @param string $state_field + * @param string $country_field + * @param bool $auto_required + * @return void + */ function CheckStateField(&$event, $state_field, $country_field, $auto_required = true) { $object =& $event->getObject(); /* @var $object kDBItem */ $country_iso = $object->GetDBField($country_field); - if ($auto_required) { + if ( $auto_required ) { $object->setRequired($state_field, $this->CountryHasStates($country_iso)); } $state = $object->GetDBField($state_field); - if ($country_iso && $state) { + if ( $country_iso && $state ) { $state_iso = $this->getStateIso($state, $country_iso); - if ($state_iso !== false) { + if ( $state_iso !== false ) { // replace state name with it's ISO code $object->SetDBField($state_field, $state_iso); } Index: branches/5.2.x/core/units/helpers/spam_helper.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/helpers/spam_helper.php (.../spam_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/spam_helper.php (.../spam_helper.php) (revision 14628) @@ -1,6 +1,6 @@ ExpirationCache[$this->DataType] = $this->Conn->GetCol($sql, 'ItemResourceId'); } + else { + $key_clause = ''; + } $cache =& $this->ExpirationCache[$this->DataType]; $expires = array_key_exists($this->ResourceId, $cache) ? $cache[$this->ResourceId] : false; Index: branches/5.2.x/core/units/helpers/image_helper.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/units/helpers/image_helper.php (.../image_helper.php) (revision 14585) +++ branches/5.2.x/core/units/helpers/image_helper.php (.../image_helper.php) (revision 14628) @@ -1,6 +1,6 @@ extensionMatch($value['name'], $options['file_types']) ) { // match by file extensions $error_params = Array ( 'file_name' => $value['name'], 'file_types' => $options['file_types'], ); + $object->SetError($field_name, 'bad_file_format', 'la_error_InvalidFileFormat', $error_params); } - elseif (getArrayValue($options, 'allowed_types') && !in_array($value['type'], $options['allowed_types'])) { + elseif ( getArrayValue($options, 'allowed_types') && !in_array($value['type'], $options['allowed_types']) ) { // match by mime type provided by web-browser $error_params = Array ( 'file_type' => $value['type'], 'allowed_types' => $options['allowed_types'], ); + $object->SetError($field_name, 'bad_file_format', 'la_error_InvalidFileFormat', $error_params); } - elseif ($value['size'] > $max_filesize) { + elseif ( $value['size'] > $max_filesize ) { $object->SetError($field_name, 'bad_file_size', 'la_error_FileTooLarge'); } - elseif (!is_writable($this->FullPath)) { + elseif ( !is_writable($this->FullPath) ) { $object->SetError($field_name, 'cant_save_file', 'la_error_cant_save_file'); } else { $real_name = $this->_ensureUniqueFilename($this->FullPath, $value['name']); - $file_name = $this->FullPath.$real_name; - if (!move_uploaded_file($value['tmp_name'], $file_name)) { + $file_name = $this->FullPath . $real_name; + if ( !move_uploaded_file($value['tmp_name'], $file_name) ) { $object->SetError($field_name, 'cant_save_file', 'la_error_cant_save_file'); } else { @chmod($file_name, 0666); - if (getArrayValue($options, 'size_field')) { + + if ( getArrayValue($options, 'size_field') ) { $object->SetDBField($options['size_field'], $value['size']); } - if (getArrayValue($options, 'orig_name_field')) { + + if ( getArrayValue($options, 'orig_name_field') ) { $object->SetDBField($options['orig_name_field'], $value['name']); } - if (getArrayValue($options, 'content_type_field')) { + + if ( getArrayValue($options, 'content_type_field') ) { $object->SetDBField($options['content_type_field'], $value['type']); } - $ret = getArrayValue($options, 'upload_dir') ? $real_name : $this->DestinationPath.$real_name; + $ret = getArrayValue($options, 'upload_dir') ? $real_name : $this->DestinationPath . $real_name; + // delete previous file, when new file is uploaded under same field /*$previous_file = isset($value['upload']) ? $value['upload'] : false; if ($previous_file && file_exists($this->FullPath.$previous_file)) { @@ -178,7 +187,7 @@ } } - if ((count($value) > 1) && $value['error'] && ($value['error'] != UPLOAD_ERR_NO_FILE)) { + if ( (count($value) > 1) && $value['error'] && ($value['error'] != UPLOAD_ERR_NO_FILE) ) { $object->SetError($field_name, 'cant_save_file', 'la_error_cant_save_file', $value); } Index: branches/5.2.x/core/units/helpers/json_helper.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/helpers/json_helper.php (.../json_helper.php) (revision 14244) +++ branches/5.2.x/core/units/helpers/json_helper.php (.../json_helper.php) (revision 14628) @@ -1,6 +1,6 @@ getType($data); - switch ($type) { + switch ( $type ) { case 'object': - $data = '{'.$this->processData($data, $type).'}'; + $data = '{' . $this->processData($data, $type) . '}'; break; case 'array': - $data = '['.$this->processData($data, $type).']'; + $data = '[' . $this->processData($data, $type) . ']'; break; default: - if (is_int($data) || is_float($data)) { + if ( is_int($data) || is_float($data) ) { $data = (string)$data; - } elseif (is_string($data)) { - $data = '"'.$this->escape($data).'"'; - } elseif (is_bool($data)) { + } + elseif ( is_string($data) ) { + $data = '"' . $this->escape($data) . '"'; + } + elseif ( is_bool($data) ) { $data = $data ? 'true' : 'false'; - } else { + } + else { $data = 'null'; } } + return $data; } /** * Enter description here... * - * @param unknown_type $input - * @param unknown_type $type - * @return unknown + * @param Array $data + * @param string $type + * @return string */ function processData($data, $type) { - $output = Array(); + $output = Array (); // If data is an object - it should be converted as a key => value pair - if ($type == 'object'){ - foreach($data as $key => $value) { - $output[] = '"'.$key.'": '.$this->encode($value); + if ( $type == 'object' ) { + foreach ($data as $key => $value) { + $output[] = '"' . $key . '": ' . $this->encode($value); } - } else { - foreach($data as $key => $value) { + } + else { + foreach ($data as $value) { $output[] = $this->encode($value); } } - return implode(',', $output);; + + return implode(',', $output); } /** * Function determines type of variable * - * @param unknown_type $data - * @return unknown + * @param mixed $data + * @return string */ function getType(&$data) { Index: branches/5.2.x/core/kernel/application.php =================================================================== diff -u -r14609 -r14628 --- branches/5.2.x/core/kernel/application.php (.../application.php) (revision 14609) +++ branches/5.2.x/core/kernel/application.php (.../application.php) (revision 14628) @@ -1,6 +1,6 @@ ModuleInfo as $module_name => $module_info) { - $contants_file = FULL_PATH . '/' . $module_info['Path'] . 'constants.php'; + $constants_file = FULL_PATH . '/' . $module_info['Path'] . 'constants.php'; - if (file_exists($contants_file)) { - kUtil::includeOnce($contants_file); + if (file_exists($constants_file)) { + kUtil::includeOnce($constants_file); } } Index: branches/5.2.x/core/units/visits/visits_tag_processor.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/visits/visits_tag_processor.php (.../visits_tag_processor.php) (revision 14244) +++ branches/5.2.x/core/units/visits/visits_tag_processor.php (.../visits_tag_processor.php) (revision 14628) @@ -1,6 +1,6 @@ Application->recallObject( $this->getPrefixSpecial(), $this->Prefix, $params ); + + $object =& $this->getObject($params); + /* @var $object kDBItem */ + return !in_array( $object->GetDBField( $params['user_field'] ) , $virtual_users ); } - - function UserLink($params) + /** + * Returns link for user editing + * + * @param Array $params + * + * @return string + * @access protected + */ + protected function UserLink($params) { - $object =& $this->Application->recallObject( $this->getPrefixSpecial(), $this->Prefix, $params ); + $object =& $this->getObject($params); + /* @var $object kDBItem */ + $user_id = $object->GetDBField( $params['user_field'] ); - if ($user_id) { - $url_params = Array ( - 'm_opener' => 'd', - 'u_mode' => 't', - 'u_event' => 'OnEdit', - 'u_id' => $user_id, - 'pass' => 'all,u' - ); - - return $this->Application->HREF($params['edit_template'], '', $url_params); + if (!$user_id) { + return ''; } + + $url_params = Array ( + 'm_opener' => 'd', + 'u_mode' => 't', + 'u_event' => 'OnEdit', + 'u_id' => $user_id, + 'pass' => 'all,u' + ); + + return $this->Application->HREF($params['edit_template'], '', $url_params); } function getDateLimitClause($field) Index: branches/5.2.x/core/units/categories/categories_tag_processor.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 14585) +++ branches/5.2.x/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 14628) @@ -1,6 +1,6 @@ Application->recallObject($this->getPrefixSpecial(), $this->Prefix.'_List'); + /* @var $cat_object kDBList */ + $sql = 'SELECT '.$this->getTitleField().' FROM '.$cat_object->TableName.' WHERE CategoryId = '.(int)$this->Application->GetVar('m_cat_id'); @@ -213,13 +215,16 @@ function getTitleField() { $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); + /* @var $ml_formatter kMultiLanguage */ + return $ml_formatter->LangFieldName('Name'); } /** * Returns symlinked category for given category * - * @param $category_id + * @param int $category_id + * @return int */ function getCategorySymLink($category_id) { @@ -536,42 +541,41 @@ * * @param Array $params * @return string + * @access protected */ - function SaveWarning($params) + protected function SaveWarning($params) { - if ($this->Prefix == 'st') { + if ( $this->Prefix == 'st' ) { // don't use this method for other prefixes then Category, that use this tag processor return parent::SaveWarning($params); } $main_prefix = getArrayValue($params, 'main_prefix'); - if ($main_prefix && $main_prefix != '$main_prefix') { + if ( $main_prefix && $main_prefix != '$main_prefix' ) { $top_prefix = $main_prefix; } else { $top_prefix = $this->Application->GetTopmostPrefix($this->Prefix); } - $temp_tables = substr($this->Application->GetVar($top_prefix.'_mode'), 0, 1) == 't'; - $modified = $this->Application->RecallVar($top_prefix.'_modified'); + $temp_tables = substr($this->Application->GetVar($top_prefix . '_mode'), 0, 1) == 't'; + $modified = $this->Application->RecallVar($top_prefix . '_modified'); - if (!$temp_tables) { - $this->Application->RemoveVar($top_prefix.'_modified'); + if ( !$temp_tables ) { + $this->Application->RemoveVar($top_prefix . '_modified'); return ''; } $block_name = $this->SelectParam($params, 'render_as,name'); - if ($block_name) { + if ( $block_name ) { $block_params = $this->prepareTagParams($params); $block_params['name'] = $block_name; $block_params['edit_mode'] = $temp_tables ? 1 : 0; $block_params['display'] = $temp_tables && $modified ? 1 : 0; return $this->Application->ParseBlock($block_params); } - else { - return $temp_tables && $modified ? 1 : 0; - } - return ; + + return $temp_tables && $modified ? 1 : 0; } /** @@ -602,6 +606,8 @@ function IsRootCategory($params) { $object =& $this->getObject($params); + /* @var $object CategoriesItem */ + return $object->IsRoot(); } @@ -681,19 +687,19 @@ { static $current_path = null; - if (!isset($current_path)) { + if ( !isset($current_path) ) { $sql = 'SELECT ParentPath FROM ' . TABLE_PREFIX . 'Category WHERE CategoryId = ' . (int)$this->Application->GetVar('m_cat_id'); $current_path = $this->Conn->GetOne($sql); } - if (array_key_exists('parent_path', $params)) { + if ( array_key_exists('parent_path', $params) ) { $test_path = $params['parent_path']; } else { $template = $params['template']; - if ($template) { + if ( $template ) { // when using from "c:CachedMenu" tag $sql = 'SELECT ParentPath FROM ' . TABLE_PREFIX . 'Category @@ -703,16 +709,18 @@ else { // when using from "c:PrintList" tag $cat_id = array_key_exists('cat_id', $params) && $params['cat_id'] ? $params['cat_id'] : false; - if ($cat_id === false) { + if ( $cat_id === false ) { // category not supplied -> get current from PrintList $category =& $this->getObject($params); } else { - if ("$cat_id" == 'Root') { + if ( "$cat_id" == 'Root' ) { $cat_id = $this->Application->findModule('Name', $params['module'], 'RootCat'); } $category =& $this->Application->recallObject($this->Prefix . '.-c' . $cat_id, $this->Prefix, Array ('skip_autoload' => true)); + /* @var $category CategoriesItem */ + $category->Load($cat_id); } @@ -769,8 +777,8 @@ $row_data = $this->Application->getCache($cache_key); - if ($row_data === false) { - if ($local && ($category_id > 0)) { + if ( $row_data === false ) { + if ( $local && ($category_id > 0) ) { // scan only current category & it's children list ($tree_left, $tree_right) = $this->Application->getTreeIndex($category_id); @@ -789,17 +797,20 @@ $this->Application->setCache($cache_key, $row_data); } - if (!$row_data) { + if ( !$row_data ) { return ''; } - $date = $row_data[ $row_data['NewDate'] > $row_data['ModDate'] ? 'NewDate' : 'ModDate' ]; + $date = $row_data[$row_data['NewDate'] > $row_data['ModDate'] ? 'NewDate' : 'ModDate']; // format date $format = isset($params['format']) ? $params['format'] : '_regional_DateTimeFormat'; - if (preg_match("/_regional_(.*)/", $format, $regs)) { + + if ( preg_match("/_regional_(.*)/", $format, $regs) ) { $lang =& $this->Application->recallObject('lang.current'); - if ($regs[1] == 'DateTimeFormat') { + /* @var $lang LanguagesItem */ + + if ( $regs[1] == 'DateTimeFormat' ) { // combined format $format = $lang->GetDBField('DateFormat') . ' ' . $lang->GetDBField('TimeFormat'); } @@ -902,19 +913,20 @@ * * @param Array $params * @return string + * @access protected */ - function SpellingSuggestions($params) + protected function SpellingSuggestions($params) { $keywords = kUtil::unhtmlentities( trim($this->Application->GetVar('keywords')) ); - if (!$keywords) { - return ; + if ( !$keywords ) { + return ''; } // 1. try to get already cached suggestion $cache_key = 'search.suggestion[%SpellingDictionary%]:' . $keywords; $suggestion = $this->Application->getCache($cache_key); - if ($suggestion !== false) { + if ( $suggestion !== false ) { return $suggestion; } @@ -927,8 +939,9 @@ WHERE MisspelledWord = ' . $this->Conn->qstr($keywords); $suggestion = $this->Conn->GetOne($sql); - if ($suggestion !== false) { + if ( $suggestion !== false ) { $this->Application->setCache($cache_key, $suggestion); + return $suggestion; } @@ -939,22 +952,20 @@ $curl_helper =& $this->Application->recallObject('CurlHelper'); /* @var $curl_helper kCurlHelper */ - $xml_data = $curl_helper->Send($url . urlencode($keywords)); + $xml_data = $curl_helper->Send( $url . urlencode($keywords) ); $xml_helper =& $this->Application->recallObject('kXMLHelper'); /* @var $xml_helper kXMLHelper */ $root_node =& $xml_helper->Parse($xml_data); + /* @var $root_node kXMLNode */ $result = $root_node->FindChild('RESULT'); /* @var $result kXMLNode */ - if (is_object($result)) { + if ( is_object($result) ) { // webservice responded -> save in local database - $fields_hash = Array ( - 'MisspelledWord' => $keywords, - 'SuggestedCorrection' => $result->Data, - ); + $fields_hash = Array ('MisspelledWord' => $keywords, 'SuggestedCorrection' => $result->Data); $this->Conn->doInsert($fields_hash, $table_name); $this->Application->setCache($cache_key, $result->Data); @@ -1075,7 +1086,7 @@ * Returns page object based on requested params * * @param Array $params - * @return PagesItem + * @return CategoriesItem */ function &_getPage($params) { @@ -1323,14 +1334,14 @@ /** * Includes admin css and js, that are required for cms usage on Front-Edn * - * * @param Array $params * @return string + * @access protected */ - function EditingScripts($params) + protected function EditingScripts($params) { - if ($this->Application->GetVar('admin_scripts_included') || !EDITING_MODE) { - return ; + if ( $this->Application->GetVar('admin_scripts_included') || !EDITING_MODE ) { + return ''; } $this->Application->SetVar('admin_scripts_included', 1); @@ -1344,17 +1355,16 @@ $js_url . '/../incs/cms.css', ); - $css_compressed = $minify_helper->CompressScriptTag( Array ('files' => implode('|', $to_compress)) ); + $css_compressed = $minify_helper->CompressScriptTag(Array ('files' => implode('|', $to_compress))); $ret = '' . "\n"; - if (EDITING_MODE == EDITING_MODE_DESIGN) { + if ( EDITING_MODE == EDITING_MODE_DESIGN ) { $ret .= ' '; } - $ret .= '' . "\n"; $ret .= '' . "\n"; @@ -1389,19 +1399,19 @@ $ret .= "var \$use_popups = " . ($use_popups > 0 ? 'true' : 'false') . ";\n"; $ret .= "var \$modal_windows = " . ($use_popups == 2 ? 'true' : 'false') . ";\n"; - if (EDITING_MODE != EDITING_MODE_BROWSE) { + if ( EDITING_MODE != EDITING_MODE_BROWSE ) { $ret .= "var base_url = '" . $this->Application->BaseURL() . "';" . "\n"; $ret .= 'TB.closeHtml = \'close
\';' . "\n"; - $url_params = Array('m_theme' => '', 'pass' => 'm', 'm_opener' => 'r', '__NO_REWRITE__' => 1, 'no_amp' => 1); + $url_params = Array ('m_theme' => '', 'pass' => 'm', 'm_opener' => 'r', '__NO_REWRITE__' => 1, 'no_amp' => 1); $browse_url = $this->Application->HREF('catalog/catalog', ADMIN_DIRECTORY, $url_params, 'index.php'); $browse_url = preg_replace('/&(admin|editing_mode)=[\d]/', '', $browse_url); $ret .= ' var topmost = window.top; topmost.document.title = document.title + \' - ' . addslashes($this->Application->Phrase('la_AdministrativeConsole', false)) . '\'; - t = \''.$this->Application->GetVar('t').'\'; + t = \'' . $this->Application->GetVar('t') . '\'; if (window.parent.frames["menu"] != undefined) { if ( $.isFunction(window.parent.frames["menu"].SyncActive) ) { @@ -1413,7 +1423,7 @@ $ret .= '' . "\n"; - if (EDITING_MODE != EDITING_MODE_BROWSE) { + if ( EDITING_MODE != EDITING_MODE_BROWSE ) { // add form, so admin scripts could work $ret .= '
Index: branches/5.2.x/core/units/forms/drafts/draft_eh.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/forms/drafts/draft_eh.php (.../draft_eh.php) (revision 14244) +++ branches/5.2.x/core/units/forms/drafts/draft_eh.php (.../draft_eh.php) (revision 14628) @@ -1,6 +1,6 @@ Name == 'OnItemBuild') { // check permission without using $event->getSection(), @@ -104,21 +106,21 @@ */ function LoadItem(&$event) { - if ($this->Application->isAdmin) { + if ( $this->Application->isAdmin ) { // don't load domain data from cache parent::LoadItem($event); - return ; + return; } $object =& $event->getObject(); /* @var $object kDBItem */ $id = (int)$this->getPassedID($event); - if ($object->isLoaded() && ($object->GetID() == $id)) { + if ( $object->isLoaded() && ($object->GetID() == $id) ) { // object is already loaded by same id - return ; + return; } $site_helper =& $this->Application->recallObject('SiteHelper'); @@ -127,9 +129,11 @@ $site_domains = $site_helper->getSiteDomains(); $domain_data = array_key_exists($id, $site_domains) ? $site_domains[$id] : false; - if ($object->LoadFromHash($domain_data)) { + if ( $object->LoadFromHash($domain_data) ) { $actions =& $this->Application->recallObject('kActions'); - $actions->Set($event->getPrefixSpecial().'_id', $object->GetID() ); + /* @var $actions Params */ + + $actions->Set($event->getPrefixSpecial() . '_id', $object->GetID()); } else { $object->setID($id); @@ -162,8 +166,9 @@ $this->Application->setUnitOption($event->Prefix, 'Fields', $fields); // remove grid columns - $grids = $this->Application->getUnitOption($event->Prefix, 'Grids'); - + $grids = $this->Application->getUnitOption($event->Prefix, 'Grids', Array ()); + /* @var $grids Array */ + foreach ($grids as $grid_name => $grid_info) { foreach ($remove_fields as $remove_field) { if (array_key_exists($remove_field, $grid_info['Fields'])) { @@ -180,12 +185,14 @@ * Delete cached information about site domains * * @param kEvent $event + * @return void + * @access protected */ - function OnSave(&$event) + protected function OnSave(&$event) { parent::OnSave($event); - if ($event->status == kEvent::erSUCCESS) { + if ( $event->status == kEvent::erSUCCESS ) { $this->_deleteCache(); } } @@ -207,11 +214,13 @@ } /** - * Set's required fields based on redirect mode + * Sets required fields based on redirect mode * * @param kEvent $event + * @return void + * @access protected */ - function OnAfterItemLoad(&$event) + protected function OnAfterItemLoad(&$event) { parent::OnAfterItemLoad($event); @@ -222,8 +231,10 @@ * Set's required fields based on redirect mode * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemCreate(&$event) + protected function OnBeforeItemCreate(&$event) { parent::OnBeforeItemCreate($event); @@ -234,8 +245,10 @@ * Set's required fields based on redirect mode * * @param kEvent $event + * @return void + * @access protected */ - function OnBeforeItemUpdate(&$event) + protected function OnBeforeItemUpdate(&$event) { parent::OnBeforeItemUpdate($event); Index: branches/5.2.x/core/units/country_states/country_state_eh.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/country_states/country_state_eh.php (.../country_state_eh.php) (revision 14244) +++ branches/5.2.x/core/units/country_states/country_state_eh.php (.../country_state_eh.php) (revision 14628) @@ -1,6 +1,6 @@ Name == 'OnMassDelete' && $type == 'before') { $ids = $event->getEventParam('ids'); Index: branches/5.2.x/core/kernel/utility/formatters/left_formatter.php =================================================================== diff -u -r14585 -r14628 --- branches/5.2.x/core/kernel/utility/formatters/left_formatter.php (.../left_formatter.php) (revision 14585) +++ branches/5.2.x/core/kernel/utility/formatters/left_formatter.php (.../left_formatter.php) (revision 14628) @@ -1,6 +1,6 @@ GetFieldOptions($field_name); - if ( isset($format) ) $options['format'] = $format; + if ( isset($format) ) { + $options['format'] = $format; + } - if( !isset($options['options'][$value]) ) - { + if ( !isset($options['options'][$value]) ) { // required option is not defined in config => query for it - $sql = sprintf($options['left_sql'],$options['left_title_field'],$options['left_key_field'], $db->escape($value)); + $sql = sprintf($options['left_sql'], $options['left_title_field'], $options['left_key_field'], $this->Conn->escape($value)); $options['options'][$value] = $this->Conn->GetOne($sql); - if ($options['options'][$value] === false) return $value; + + if ( $options['options'][$value] === false ) { + return $value; + } } + return $options['options'][$value]; } /** - * Parse value from form submit + * Performs basic type validation on form field value * * @param mixed $value * @param string $field_name * @param kDBItem $object * @return mixed + * @access public */ - function Parse($value, $field_name, &$object) + public function Parse($value, $field_name, &$object) { - if ($value == '') return NULL; + if ( $value == '' ) { + return NULL; + } $options = $object->GetFieldOptions($field_name); $found = isset($options['options']) ? array_search($value, $options['options']) : false; - if ($found !== false) { + + if ( $found !== false ) { // requested option found among field options return $found; } // requested option is not found in field options -> query for it - $sql = sprintf($options['left_sql'], $options['left_key_field'], $options['left_title_field'], $db->escape($value)); + $sql = sprintf($options['left_sql'], $options['left_key_field'], $options['left_title_field'], $this->Conn->escape($value)); $found = $this->Conn->GetOne($sql); - if ($found !== false) { + + if ( $found !== false ) { // option successfully retrieved from db -> cache it $options['options'][$found] = $value; } $skip_errors = array_key_exists('skip_errors', $options) && $options['skip_errors']; - if ($found === false && !$skip_errors) { + + if ( $found === false && !$skip_errors ) { // option not found at all -> return not formatted value & set error $object->SetError($field_name, 'invalid_option', 'la_error_InvalidOption'); return $value; Index: branches/5.2.x/core/units/stylesheets/stylesheets_event_handler.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/units/stylesheets/stylesheets_event_handler.php (.../stylesheets_event_handler.php) (revision 14244) +++ branches/5.2.x/core/units/stylesheets/stylesheets_event_handler.php (.../stylesheets_event_handler.php) (revision 14628) @@ -1,6 +1,6 @@ getObject( Array('skip_autoload' => true) ); - $object->SwitchToLive(); + /** + * [HOOK] Compile stylesheet file based on theme definitions + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnCompileStylesheet(&$event) + { + $object =& $event->getObject( Array ('skip_autoload' => true) ); + /* @var $object StylesheetsItem */ - $ids = explode(',', $event->MasterEvent->getEventParam('ids') ); + $object->SwitchToLive(); - if(!$ids) return false; - foreach($ids as $id) - { - $object->Load($id); - $object->Compile(); - } + $ids = explode(',', $event->MasterEvent->getEventParam('ids')); + + if ( !$ids ) { + return ; } - } \ No newline at end of file + + foreach ($ids as $id) { + $object->Load($id); + $object->Compile(); + } + } +} \ No newline at end of file Index: branches/5.2.x/core/kernel/utility/filters.php =================================================================== diff -u -r14244 -r14628 --- branches/5.2.x/core/kernel/utility/filters.php (.../filters.php) (revision 14244) +++ branches/5.2.x/core/kernel/utility/filters.php (.../filters.php) (revision 14628) @@ -1,6 +1,6 @@ Application->UnitConfigReader->loadConfig($regs[1]); $this->Application->UnitConfigReader->runAfterConfigRead($prefix); @@ -171,52 +172,55 @@ $table_name = $this->Application->getUnitOption($prefix, 'TableName'); $this->curFields = $this->Application->getUnitOption($prefix, 'Fields'); - if (!($table_name && $this->curFields) || ($table_name && !$this->Conn->TableFound($table_name))) { + if ( !($table_name && $this->curFields) || ($table_name && !$this->Conn->TableFound($table_name)) ) { // invalid config found or prefix not found - return true; + return ; } $this->initLanguageCount(); - $sqls = Array(); + $sqls = Array (); $this->readTableStructure($table_name, $refresh); - foreach($this->curFields as $field_name => $field_options) - { - if (getArrayValue($field_options, 'formatter') == 'kMultiLanguage') { - if (isset($field_options['master_field'])) { + foreach ($this->curFields as $field_name => $field_options) { + if ( getArrayValue($field_options, 'formatter') == 'kMultiLanguage' ) { + if ( isset($field_options['master_field']) ) { unset($this->curFields[$field_name]); continue; } $this->setSourceField($field_name); - if ($this->languageCount > 0) { + if ( $this->languageCount > 0 ) { // `l77_Name` VARCHAR( 255 ) NULL DEFAULT '0'; - $field_mask = Array(); - $field_mask['name'] = 'l%s_'.$field_name; + $field_mask = Array (); + $field_mask['name'] = 'l%s_' . $field_name; $field_mask['null'] = getArrayValue($field_options, 'not_null') ? 'NOT NULL' : 'NULL'; - if ($this->curSourceField) { - $default_value = $this->getFieldParam('Default') != 'NULL' ? $this->Conn->qstr($this->getFieldParam('Default')) : $this->getFieldParam('Default'); + if ( $this->curSourceField ) { + $default_value = $this->getFieldParam('Default') != 'NULL' + ? $this->Conn->qstr($this->getFieldParam('Default')) + : $this->getFieldParam('Default'); $field_mask['type'] = $this->getFieldParam('Type'); } else { - $default_value = is_null($field_options['default']) ? 'NULL' : $this->Conn->qstr($field_options['default']); + $default_value = is_null($field_options['default']) ? 'NULL' + : $this->Conn->qstr($field_options['default']); $field_mask['type'] = $field_options['db_type']; } - $field_mask['default'] = ($field_mask['null'] == 'NOT NULL' && $default_value == 'NULL') ? '' : 'DEFAULT '.$default_value; + $field_mask['default'] = ($field_mask['null'] == 'NOT NULL' && $default_value == 'NULL') ? '' + : 'DEFAULT ' . $default_value; - if (strtoupper($field_mask['type']) == 'TEXT') { + if ( strtoupper($field_mask['type']) == 'TEXT' ) { // text fields in mysql doesn't have default value - $field_mask = $field_mask['name'].' '.$field_mask['type'].' '.$field_mask['null']; + $field_mask = $field_mask['name'] . ' ' . $field_mask['type'] . ' ' . $field_mask['null']; } else { - $field_mask = $field_mask['name'].' '.$field_mask['type'].' '.$field_mask['null'].' '.$field_mask['default']; + $field_mask = $field_mask['name'] . ' ' . $field_mask['type'] . ' ' . $field_mask['null'] . ' ' . $field_mask['default']; } $alter_sqls = $this->generateAlterSQL($field_mask, 1, $this->languageCount); - if ($alter_sqls) { - $sqls[] = 'ALTER TABLE '.$table_name.' '.$alter_sqls; + if ( $alter_sqls ) { + $sqls[] = 'ALTER TABLE ' . $table_name . ' ' . $alter_sqls; } } } @@ -233,15 +237,17 @@ * @param string $prefix * @param int $src_language * @param int $dst_language + * @return void + * @access public */ - function copyMissingData($prefix, $src_language, $dst_language) + public function copyMissingData($prefix, $src_language, $dst_language) { $table_name = $this->Application->getUnitOption($prefix, 'TableName'); $this->curFields = $this->Application->getUnitOption($prefix, 'Fields'); - if (!($table_name && $this->curFields) || ($table_name && !$this->Conn->TableFound($table_name))) { + if ( !($table_name && $this->curFields) || ($table_name && !$this->Conn->TableFound($table_name)) ) { // invalid config found or prefix not found - return true; + return ; } foreach ($this->curFields as $field_name => $field_options) {