Changeset View
Standalone View
core/units/categories/categories_event_handler.php
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | |||||
* @return bool | * @return bool | ||||
* @access public | * @access public | ||||
*/ | */ | ||||
public function CheckPermission(kEvent $event) | public function CheckPermission(kEvent $event) | ||||
{ | { | ||||
if ( $event->Name == 'OnResetCMSMenuCache' ) { | if ( $event->Name == 'OnResetCMSMenuCache' ) { | ||||
// events from "Tools -> System Tools" section are controlled via that section "edit" permission | // events from "Tools -> System Tools" section are controlled via that section "edit" permission | ||||
/** @var kPermissionsHelper $perm_helper */ | |||||
$perm_helper = $this->Application->recallObject('PermissionsHelper'); | $perm_helper = $this->Application->recallObject('PermissionsHelper'); | ||||
/* @var $perm_helper kPermissionsHelper */ | |||||
$perm_value = $this->Application->CheckPermission('in-portal:service.edit'); | $perm_value = $this->Application->CheckPermission('in-portal:service.edit'); | ||||
return $perm_helper->finalizePermissionCheck($event, $perm_value); | return $perm_helper->finalizePermissionCheck($event, $perm_value); | ||||
} | } | ||||
if ( !$this->Application->isAdmin ) { | if ( !$this->Application->isAdmin ) { | ||||
if ( $event->Name == 'OnSetSortingDirect' ) { | if ( $event->Name == 'OnSetSortingDirect' ) { | ||||
// allow sorting on front event without view permission | // allow sorting on front event without view permission | ||||
return true; | return true; | ||||
} | } | ||||
if ( $event->Name == 'OnItemBuild' ) { | if ( $event->Name == 'OnItemBuild' ) { | ||||
$category_id = $this->getPassedID($event); | $category_id = $this->getPassedID($event); | ||||
if ( $category_id == 0 ) { | if ( $category_id == 0 ) { | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if ( in_array($event->Name, $this->_getMassPermissionEvents()) ) { | if ( in_array($event->Name, $this->_getMassPermissionEvents()) ) { | ||||
$items = $this->_getPermissionCheckInfo($event); | $items = $this->_getPermissionCheckInfo($event); | ||||
/** @var kPermissionsHelper $perm_helper */ | |||||
$perm_helper = $this->Application->recallObject('PermissionsHelper'); | $perm_helper = $this->Application->recallObject('PermissionsHelper'); | ||||
/* @var $perm_helper kPermissionsHelper */ | |||||
if ( ($event->Name == 'OnSave') && array_key_exists(0, $items) ) { | if ( ($event->Name == 'OnSave') && array_key_exists(0, $items) ) { | ||||
// adding new item (ID = 0) | // adding new item (ID = 0) | ||||
$perm_value = $perm_helper->AddCheckPermission($items[0]['ParentId'], $event->Prefix) > 0; | $perm_value = $perm_helper->AddCheckPermission($items[0]['ParentId'], $event->Prefix) > 0; | ||||
} | } | ||||
else { | else { | ||||
// leave only items, that can be edited | // leave only items, that can be edited | ||||
$ids = Array (); | $ids = Array (); | ||||
Show All 12 Lines | |||||
$perm_value = true; | $perm_value = true; | ||||
$event->setEventParam('ids', $ids); // will be used later by "kDBEventHandler::StoreSelectedIDs" method | $event->setEventParam('ids', $ids); // will be used later by "kDBEventHandler::StoreSelectedIDs" method | ||||
} | } | ||||
return $perm_helper->finalizePermissionCheck($event, $perm_value); | return $perm_helper->finalizePermissionCheck($event, $perm_value); | ||||
} | } | ||||
if ( $event->Name == 'OnRecalculatePriorities' ) { | if ( $event->Name == 'OnRecalculatePriorities' ) { | ||||
/** @var kPermissionsHelper $perm_helper */ | |||||
$perm_helper = $this->Application->recallObject('PermissionsHelper'); | $perm_helper = $this->Application->recallObject('PermissionsHelper'); | ||||
/* @var $perm_helper kPermissionsHelper */ | |||||
$category_id = $this->Application->GetVar('m_cat_id'); | $category_id = $this->Application->GetVar('m_cat_id'); | ||||
return $perm_helper->AddCheckPermission($category_id, $event->Prefix) || $perm_helper->ModifyCheckPermission(0, $category_id, $event->Prefix); | return $perm_helper->AddCheckPermission($category_id, $event->Prefix) || $perm_helper->ModifyCheckPermission(0, $category_id, $event->Prefix); | ||||
} | } | ||||
if ( $event->Name == 'OnPasteClipboard' ) { | if ( $event->Name == 'OnPasteClipboard' ) { | ||||
// forces permission check to work by current category for "Paste In Category" operation | // forces permission check to work by current category for "Paste In Category" operation | ||||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Line(s) | |||||
/** | /** | ||||
* Adds selected link to listing | * Adds selected link to listing | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnProcessSelected($event) | function OnProcessSelected($event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$selected_ids = $this->Application->GetVar('selected_ids'); | $selected_ids = $this->Application->GetVar('selected_ids'); | ||||
$this->RemoveRequiredFields($object); | $this->RemoveRequiredFields($object); | ||||
$object->SetDBField($this->Application->RecallVar('dst_field'), $selected_ids['c']); | $object->SetDBField($this->Application->RecallVar('dst_field'), $selected_ids['c']); | ||||
$object->Update(); | $object->Update(); | ||||
$event->SetRedirectParam('opener', 'u'); | $event->SetRedirectParam('opener', 'u'); | ||||
} | } | ||||
/** | /** | ||||
* Apply system filter to categories list | * Apply system filter to categories list | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
* @see kDBEventHandler::OnListBuild() | * @see kDBEventHandler::OnListBuild() | ||||
*/ | */ | ||||
protected function SetCustomQuery(kEvent $event) | protected function SetCustomQuery(kEvent $event) | ||||
{ | { | ||||
parent::SetCustomQuery($event); | parent::SetCustomQuery($event); | ||||
/** @var kDBList $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBList */ | |||||
// don't show "Content" category in advanced view | // don't show "Content" category in advanced view | ||||
$object->addFilter('system_categories', '%1$s.Status <> 4'); | $object->addFilter('system_categories', '%1$s.Status <> 4'); | ||||
// show system templates from current theme only + all virtual templates | // show system templates from current theme only + all virtual templates | ||||
$object->addFilter('theme_filter', '%1$s.ThemeId = ' . $this->_getCurrentThemeId() . ' OR %1$s.ThemeId = 0'); | $object->addFilter('theme_filter', '%1$s.ThemeId = ' . $this->_getCurrentThemeId() . ' OR %1$s.ThemeId = 0'); | ||||
if ($event->Special == 'showall') { | if ($event->Special == 'showall') { | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | |||||
if (!$prefix_special) { | if (!$prefix_special) { | ||||
$prefix_special = $this->Application->Parser->GetParam('PrefixSpecial'); | $prefix_special = $this->Application->Parser->GetParam('PrefixSpecial'); | ||||
} | } | ||||
$id = false; | $id = false; | ||||
if ($prefix_special !== false) { | if ($prefix_special !== false) { | ||||
$processed_prefix = $this->Application->processPrefix($prefix_special); | $processed_prefix = $this->Application->processPrefix($prefix_special); | ||||
if ($processed_prefix['prefix'] == $related_prefix) { | if ($processed_prefix['prefix'] == $related_prefix) { | ||||
// printing related categories within list of items (not on details page) | // printing related categories within list of items (not on details page) | ||||
Lint: CodingStandard.Commenting.InlineComment.InvalidEndChar: Inline comments must end in full-stops, exclamation marks, or question marks | |||||
Inline comments must start with a capital letter Lint: CodingStandard.Commenting.InlineComment.NotCapital: Inline comments must start with a capital letter | |||||
/** @var kDBList $list */ | |||||
$list = $this->Application->recallObject($prefix_special); | $list = $this->Application->recallObject($prefix_special); | ||||
/* @var $list kDBList */ | |||||
$id = $list->GetID(); | $id = $list->GetID(); | ||||
} | } | ||||
} | } | ||||
if ($id === false) { | if ($id === false) { | ||||
// printing related categories for single item (possibly on details page) | // printing related categories for single item (possibly on details page) | ||||
if ($related_prefix == 'c') { | if ($related_prefix == 'c') { | ||||
$id = $this->Application->GetVar('m_cat_id'); | $id = $this->Application->GetVar('m_cat_id'); | ||||
} | } | ||||
else { | else { | ||||
$id = $this->Application->GetVar($related_prefix . '_id'); | $id = $this->Application->GetVar($related_prefix . '_id'); | ||||
} | } | ||||
} | } | ||||
/** @var kCatDBItem $p_item */ | |||||
$p_item = $this->Application->recallObject($related_prefix . '.current', null, Array('skip_autoload' => true)); | $p_item = $this->Application->recallObject($related_prefix . '.current', null, Array('skip_autoload' => true)); | ||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
Line exceeds 120 characters; contains 127 characters Lint: Generic.Files.LineLength.TooLong: Line exceeds 120 characters; contains 127 characters | |||||
/* @var $p_item kCatDBItem */ | |||||
$p_item->Load( (int)$id ); | $p_item->Load( (int)$id ); | ||||
$p_resource_id = $p_item->GetDBField('ResourceId'); | $p_resource_id = $p_item->GetDBField('ResourceId'); | ||||
$sql = 'SELECT SourceId, TargetId FROM '.$rel_table.' | $sql = 'SELECT SourceId, TargetId FROM '.$rel_table.' | ||||
WHERE | WHERE | ||||
(Enabled = 1) | (Enabled = 1) | ||||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Line(s) | |||||
// processing keyword_string param of ListProducts tag | // processing keyword_string param of ListProducts tag | ||||
$this->Application->SetVar('keywords', $keywords); | $this->Application->SetVar('keywords', $keywords); | ||||
$type = 'simple'; | $type = 'simple'; | ||||
} | } | ||||
$search_event = $event_mapping[$type]; | $search_event = $event_mapping[$type]; | ||||
$this->$search_event($event); | $this->$search_event($event); | ||||
/** @var kDBList $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBList */ | |||||
$search_sql = ' FROM ' . $search_helper->getSearchTable() . ' search_result | $search_sql = ' FROM ' . $search_helper->getSearchTable() . ' search_result | ||||
JOIN %1$s ON %1$s.ResourceId = search_result.ResourceId'; | JOIN %1$s ON %1$s.ResourceId = search_result.ResourceId'; | ||||
$sql = str_replace('FROM %1$s', $search_sql, $object->GetPlainSelectSQL()); | $sql = str_replace('FROM %1$s', $search_sql, $object->GetPlainSelectSQL()); | ||||
$object->SetSelectSQL($sql); | $object->SetSelectSQL($sql); | ||||
$object->addCalculatedField('Relevance', 'search_result.Relevance'); | $object->addCalculatedField('Relevance', 'search_result.Relevance'); | ||||
Show All 20 Lines | |||||
return; | return; | ||||
} | } | ||||
if ( $this->Application->RecallVar('user_id') == USER_ROOT ) { | if ( $this->Application->RecallVar('user_id') == USER_ROOT ) { | ||||
// for "root" CATEGORY.VIEW permission is checked for items lists too | // for "root" CATEGORY.VIEW permission is checked for items lists too | ||||
$view_perm = 1; | $view_perm = 1; | ||||
} | } | ||||
else { | else { | ||||
/** @var kCountHelper $count_helper */ | |||||
$count_helper = $this->Application->recallObject('CountHelper'); | $count_helper = $this->Application->recallObject('CountHelper'); | ||||
/* @var $count_helper kCountHelper */ | |||||
list ($view_perm, $view_filter) = $count_helper->GetPermissionClause($object->Prefix, 'perm'); | list ($view_perm, $view_filter) = $count_helper->GetPermissionClause($object->Prefix, 'perm'); | ||||
$object->addFilter('perm_filter2', $view_filter); | $object->addFilter('perm_filter2', $view_filter); | ||||
} | } | ||||
$object->addFilter('perm_filter', 'perm.PermId = ' . $view_perm); // check for CATEGORY.VIEW permission | $object->addFilter('perm_filter', 'perm.PermId = ' . $view_perm); // check for CATEGORY.VIEW permission | ||||
} | } | ||||
/** | /** | ||||
* Returns current theme id | * Returns current theme id | ||||
* | * | ||||
* @return int | * @return int | ||||
*/ | */ | ||||
function _getCurrentThemeId() | function _getCurrentThemeId() | ||||
{ | { | ||||
/** @var kThemesHelper $themes_helper */ | |||||
$themes_helper = $this->Application->recallObject('ThemesHelper'); | $themes_helper = $this->Application->recallObject('ThemesHelper'); | ||||
/* @var $themes_helper kThemesHelper */ | |||||
return (int)$themes_helper->getCurrentThemeId(); | return (int)$themes_helper->getCurrentThemeId(); | ||||
} | } | ||||
/** | /** | ||||
* Returns ID of current item to be edited | * Returns ID of current item to be edited | ||||
* by checking ID passed in get/post as prefix_id | * by checking ID passed in get/post as prefix_id | ||||
* or by looking at first from selected ids, stored. | * or by looking at first from selected ids, stored. | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | |||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function prepareObject(&$object, kEvent $event) | protected function prepareObject(&$object, kEvent $event) | ||||
{ | { | ||||
if ( $this->_isVirtual($event) ) { | if ( $this->_isVirtual($event) ) { | ||||
return; | return; | ||||
} | } | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(Array ('skip_autoload' => true)); | $object = $event->getObject(Array ('skip_autoload' => true)); | ||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
/* @var $object kDBItem */ | |||||
$object->addCalculatedField( | $object->addCalculatedField( | ||||
'IsNew', | 'IsNew', | ||||
' IF(%1$s.NewItem = 2, | ' IF(%1$s.NewItem = 2, | ||||
IF(%1$s.CreatedOn >= (UNIX_TIMESTAMP() - '. | IF(%1$s.CreatedOn >= (UNIX_TIMESTAMP() - '. | ||||
$this->Application->ConfigValue('Category_DaysNew'). | $this->Application->ConfigValue('Category_DaysNew'). | ||||
'*3600*24), 1, 0), | '*3600*24), 1, 0), | ||||
%1$s.NewItem | %1$s.NewItem | ||||
Show All 30 Lines | |||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnAfterCopyToLive(kEvent $event) | protected function OnAfterCopyToLive(kEvent $event) | ||||
{ | { | ||||
parent::OnAfterCopyToLive($event); | parent::OnAfterCopyToLive($event); | ||||
/** @var CategoriesItem $object */ | |||||
$object = $this->Application->recallObject($event->Prefix . '.-item', null, Array ('skip_autoload' => true, 'live_table' => true)); | $object = $this->Application->recallObject($event->Prefix . '.-item', null, Array ('skip_autoload' => true, 'live_table' => true)); | ||||
Line exceeds maximum limit of 140 characters; contains 143 characters Lint: Generic.Files.LineLength.MaxExceeded: Line exceeds maximum limit of 140 characters; contains 143 characters | |||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
/* @var $object CategoriesItem */ | |||||
$parent_path = false; | $parent_path = false; | ||||
$object->Load($event->getEventParam('id')); | $object->Load($event->getEventParam('id')); | ||||
if ( $event->getEventParam('temp_id') == 0 ) { | if ( $event->getEventParam('temp_id') == 0 ) { | ||||
if ( $object->isLoaded() ) { | if ( $object->isLoaded() ) { | ||||
// update path only for real categories (not including "Home" root category) | // update path only for real categories (not including "Home" root category) | ||||
$fields_hash = $object->buildParentBasedFields(); | $fields_hash = $object->buildParentBasedFields(); | ||||
$this->Conn->doUpdate($fields_hash, $object->TableName, 'CategoryId = ' . $object->GetID()); | $this->Conn->doUpdate($fields_hash, $object->TableName, 'CategoryId = ' . $object->GetID()); | ||||
$parent_path = $fields_hash['ParentPath']; | $parent_path = $fields_hash['ParentPath']; | ||||
} | } | ||||
} | } | ||||
else { | else { | ||||
$parent_path = $object->GetDBField('ParentPath'); | $parent_path = $object->GetDBField('ParentPath'); | ||||
} | } | ||||
if ( $parent_path ) { | if ( $parent_path ) { | ||||
/** @var kPermCacheUpdater $cache_updater */ | |||||
$cache_updater = $this->Application->makeClass('kPermCacheUpdater', Array (null, $parent_path)); | $cache_updater = $this->Application->makeClass('kPermCacheUpdater', Array (null, $parent_path)); | ||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
/* @var $cache_updater kPermCacheUpdater */ | |||||
$cache_updater->OneStepRun(); | $cache_updater->OneStepRun(); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Set cache modification mark if needed | * Set cache modification mark if needed | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnBeforeDeleteFromLive(kEvent $event) | protected function OnBeforeDeleteFromLive(kEvent $event) | ||||
{ | { | ||||
parent::OnBeforeDeleteFromLive($event); | parent::OnBeforeDeleteFromLive($event); | ||||
$id = $event->getEventParam('id'); | $id = $event->getEventParam('id'); | ||||
// loading anyway, because this object is needed by "c-perm:OnBeforeDeleteFromLive" event | // loading anyway, because this object is needed by "c-perm:OnBeforeDeleteFromLive" event | ||||
Inline comments must end in full-stops, exclamation marks, or question marks Lint: CodingStandard.Commenting.InlineComment.InvalidEndChar: Inline comments must end in full-stops, exclamation marks, or question marks | |||||
Inline comments must start with a capital letter Lint: CodingStandard.Commenting.InlineComment.NotCapital: Inline comments must start with a capital letter | |||||
/** @var CategoriesItem $temp_object */ | |||||
$temp_object = $event->getObject(Array ('skip_autoload' => true)); | $temp_object = $event->getObject(Array ('skip_autoload' => true)); | ||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
/* @var $temp_object CategoriesItem */ | |||||
$temp_object->Load($id); | $temp_object->Load($id); | ||||
if ( $id == 0 ) { | if ( $id == 0 ) { | ||||
if ( $temp_object->isLoaded() ) { | if ( $temp_object->isLoaded() ) { | ||||
// new category -> update cache (not loaded when "Home" category) | // new category -> update cache (not loaded when "Home" category) | ||||
$this->Application->StoreVar('PermCache_UpdateRequired', 1); | $this->Application->StoreVar('PermCache_UpdateRequired', 1); | ||||
} | } | ||||
return ; | return ; | ||||
} | } | ||||
// existing category was edited, check if in-cache fields are modified | // existing category was edited, check if in-cache fields are modified | ||||
Inline comments must end in full-stops, exclamation marks, or question marks Lint: CodingStandard.Commenting.InlineComment.InvalidEndChar: Inline comments must end in full-stops, exclamation marks, or question marks | |||||
Inline comments must start with a capital letter Lint: CodingStandard.Commenting.InlineComment.NotCapital: Inline comments must start with a capital letter | |||||
/** @var CategoriesItem $live_object */ | |||||
$live_object = $this->Application->recallObject($event->Prefix . '.-item', null, Array ('live_table' => true, 'skip_autoload' => true)); | $live_object = $this->Application->recallObject($event->Prefix . '.-item', null, Array ('live_table' => true, 'skip_autoload' => true)); | ||||
Line exceeds maximum limit of 140 characters; contains 148 characters Lint: Generic.Files.LineLength.MaxExceeded: Line exceeds maximum limit of 140 characters; contains 148 characters | |||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
/* @var $live_object CategoriesItem */ | |||||
$live_object->Load($id); | $live_object->Load($id); | ||||
$cached_fields = Array ('l' . $this->Application->GetDefaultLanguageId() . '_Name', 'Filename', 'Template', 'ParentId', 'Priority'); | $cached_fields = Array ('l' . $this->Application->GetDefaultLanguageId() . '_Name', 'Filename', 'Template', 'ParentId', 'Priority'); | ||||
foreach ($cached_fields as $cached_field) { | foreach ($cached_fields as $cached_field) { | ||||
if ( $live_object->GetDBField($cached_field) != $temp_object->GetDBField($cached_field) ) { | if ( $live_object->GetDBField($cached_field) != $temp_object->GetDBField($cached_field) ) { | ||||
// use session instead of REQUEST because of permission editing in category can contain | // use session instead of REQUEST because of permission editing in category can contain | ||||
// multiple submits, that changes data before OnSave event occurs | // multiple submits, that changes data before OnSave event occurs | ||||
Show All 35 Lines | |||||
*/ | */ | ||||
protected function OnPreCreate(kEvent $event) | protected function OnPreCreate(kEvent $event) | ||||
{ | { | ||||
// 1. for permission editing of Home category | // 1. for permission editing of Home category | ||||
$this->Application->RemoveVar('IsRootCategory_' . $this->Application->GetVar('m_wid')); | $this->Application->RemoveVar('IsRootCategory_' . $this->Application->GetVar('m_wid')); | ||||
parent::OnPreCreate($event); | parent::OnPreCreate($event); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
// 2. preset template | // 2. preset template | ||||
$category_id = $this->Application->GetVar('m_cat_id'); | $category_id = $this->Application->GetVar('m_cat_id'); | ||||
$root_category = $this->Application->getBaseCategory(); | $root_category = $this->Application->getBaseCategory(); | ||||
if ( $category_id == $root_category ) { | if ( $category_id == $root_category ) { | ||||
$object->SetDBField('Template', $this->_getDefaultDesign()); | $object->SetDBField('Template', $this->_getDefaultDesign()); | ||||
} | } | ||||
Show All 11 Lines | |||||
*/ | */ | ||||
protected function OnSave(kEvent $event) | protected function OnSave(kEvent $event) | ||||
{ | { | ||||
// get data from live table before it is overwritten by parent OnSave method call | // get data from live table before it is overwritten by parent OnSave method call | ||||
$ids = $this->getSelectedIDs($event, true); | $ids = $this->getSelectedIDs($event, true); | ||||
$is_editing = implode('', $ids); | $is_editing = implode('', $ids); | ||||
$old_statuses = $is_editing ? $this->_getCategoryStatus($ids) : Array (); | $old_statuses = $is_editing ? $this->_getCategoryStatus($ids) : Array (); | ||||
/** @var CategoriesItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object CategoriesItem */ | |||||
parent::OnSave($event); | parent::OnSave($event); | ||||
if ( $event->status != kEvent::erSUCCESS ) { | if ( $event->status != kEvent::erSUCCESS ) { | ||||
return; | return; | ||||
} | } | ||||
if ( $this->Application->RecallVar('PermCache_UpdateRequired') ) { | if ( $this->Application->RecallVar('PermCache_UpdateRequired') ) { | ||||
Show All 17 Lines | |||||
} | } | ||||
} | } | ||||
} | } | ||||
// change opener stack in case if edited category filename was changed | // change opener stack in case if edited category filename was changed | ||||
$filename_changes = $this->Application->GetVar($event->Prefix . '_filename_changes', Array ()); | $filename_changes = $this->Application->GetVar($event->Prefix . '_filename_changes', Array ()); | ||||
if ( $filename_changes ) { | if ( $filename_changes ) { | ||||
/** @var kOpenerStack $opener_stack */ | |||||
$opener_stack = $this->Application->makeClass('kOpenerStack'); | $opener_stack = $this->Application->makeClass('kOpenerStack'); | ||||
/* @var $opener_stack kOpenerStack */ | |||||
list ($template, $params, $index_file) = $opener_stack->pop(); | list ($template, $params, $index_file) = $opener_stack->pop(); | ||||
foreach ($filename_changes as $change_info) { | foreach ($filename_changes as $change_info) { | ||||
$template = str_ireplace($change_info['from'], $change_info['to'], $template); | $template = str_ireplace($change_info['from'], $change_info['to'], $template); | ||||
} | } | ||||
$opener_stack->push($template, $params, $index_file); | $opener_stack->push($template, $params, $index_file); | ||||
Show All 23 Lines | |||||
* stores item id in App vars and Session on success | * stores item id in App vars and Session on success | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnPreSaveCreated(kEvent $event) | protected function OnPreSaveCreated(kEvent $event) | ||||
{ | { | ||||
/** @var CategoriesItem $object */ | |||||
$object = $event->getObject( Array ('skip_autoload' => true) ); | $object = $event->getObject( Array ('skip_autoload' => true) ); | ||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
Space after opening parenthesis of function call prohibited Lint: PSR2.Methods.FunctionCallSignature.SpaceAfterOpenBracket: Space after opening parenthesis of function call prohibited | |||||
Expected 0 spaces before closing bracket; 1 found Lint: PSR2.Methods.FunctionCallSignature.SpaceBeforeCloseBracket: Expected 0 spaces before closing bracket; 1 found | |||||
Space after opening parenthesis of function call prohibited Lint: CodingStandard.Functions.FunctionCallSignature.SpaceAfterOpenBracket: Space after opening parenthesis of function call prohibited | |||||
Expected 0 spaces before closing bracket; 1 found Lint: CodingStandard.Functions.FunctionCallSignature.SpaceBeforeCloseBracket: Expected 0 spaces before closing bracket; 1 found | |||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
/* @var $object CategoriesItem */ | |||||
if ( $object->IsRoot() ) { | if ( $object->IsRoot() ) { | ||||
// don't create root category while saving permissions | // don't create root category while saving permissions | ||||
return; | return; | ||||
} | } | ||||
parent::OnPreSaveCreated($event); | parent::OnPreSaveCreated($event); | ||||
} | } | ||||
/** | /** | ||||
* Deletes sym link to other category | * Deletes sym link to other category | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnAfterItemDelete(kEvent $event) | protected function OnAfterItemDelete(kEvent $event) | ||||
{ | { | ||||
parent::OnAfterItemDelete($event); | parent::OnAfterItemDelete($event); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$sql = 'UPDATE ' . $object->TableName . ' | $sql = 'UPDATE ' . $object->TableName . ' | ||||
SET SymLinkCategoryId = NULL | SET SymLinkCategoryId = NULL | ||||
WHERE SymLinkCategoryId = ' . $object->GetID(); | WHERE SymLinkCategoryId = ' . $object->GetID(); | ||||
$this->Conn->Query($sql); | $this->Conn->Query($sql); | ||||
// delete direct subscriptions to category, that was deleted | // delete direct subscriptions to category, that was deleted | ||||
$sql = 'SELECT SubscriptionId | $sql = 'SELECT SubscriptionId | ||||
FROM ' . TABLE_PREFIX . 'SystemEventSubscriptions | FROM ' . TABLE_PREFIX . 'SystemEventSubscriptions | ||||
WHERE CategoryId = ' . $object->GetID(); | WHERE CategoryId = ' . $object->GetID(); | ||||
$ids = $this->Conn->GetCol($sql); | $ids = $this->Conn->GetCol($sql); | ||||
if ( $ids ) { | if ( $ids ) { | ||||
/** @var kTempTablesHandler $temp_handler */ | |||||
$temp_handler = $this->Application->recallObject('system-event-subscription_TempHandler', 'kTempTablesHandler'); | $temp_handler = $this->Application->recallObject('system-event-subscription_TempHandler', 'kTempTablesHandler'); | ||||
Line exceeds 120 characters; contains 128 characters Lint: Generic.Files.LineLength.TooLong: Line exceeds 120 characters; contains 128 characters | |||||
/* @var $temp_handler kTempTablesHandler */ | |||||
$temp_handler->DeleteItems('system-event-subscription', '', $ids); | $temp_handler->DeleteItems('system-event-subscription', '', $ids); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Exclude root categories from deleting | * Exclude root categories from deleting | ||||
* | * | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Line(s) | |||||
return; | return; | ||||
} | } | ||||
$to_delete = Array (); | $to_delete = Array (); | ||||
$ids = $this->StoreSelectedIDs($event); | $ids = $this->StoreSelectedIDs($event); | ||||
$recycle_bin = $this->Application->ConfigValue('RecycleBinFolder'); | $recycle_bin = $this->Application->ConfigValue('RecycleBinFolder'); | ||||
if ( $recycle_bin ) { | if ( $recycle_bin ) { | ||||
/** @var CategoriesItem $rb */ | |||||
$rb = $this->Application->recallObject('c.recycle', null, Array ('skip_autoload' => true)); | $rb = $this->Application->recallObject('c.recycle', null, Array ('skip_autoload' => true)); | ||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
/* @var $rb CategoriesItem */ | |||||
$rb->Load($recycle_bin); | $rb->Load($recycle_bin); | ||||
/** @var CategoriesItem $cat */ | |||||
$cat = $event->getObject(Array ('skip_autoload' => true)); | $cat = $event->getObject(Array ('skip_autoload' => true)); | ||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
/* @var $cat CategoriesItem */ | |||||
foreach ($ids as $id) { | foreach ($ids as $id) { | ||||
$cat->Load($id); | $cat->Load($id); | ||||
if ( preg_match('/^' . preg_quote($rb->GetDBField('ParentPath'), '/') . '/', $cat->GetDBField('ParentPath')) ) { | if ( preg_match('/^' . preg_quote($rb->GetDBField('ParentPath'), '/') . '/', $cat->GetDBField('ParentPath')) ) { | ||||
// already in "Recycle Bin" -> delete for real | // already in "Recycle Bin" -> delete for real | ||||
$to_delete[] = $id; | $to_delete[] = $id; | ||||
continue; | continue; | ||||
} | } | ||||
// just move into "Recycle Bin" category | // just move into "Recycle Bin" category | ||||
$cat->SetDBField('ParentId', $recycle_bin); | $cat->SetDBField('ParentId', $recycle_bin); | ||||
$cat->Update(); | $cat->Update(); | ||||
} | } | ||||
$ids = $to_delete; | $ids = $to_delete; | ||||
} | } | ||||
$event->setEventParam('ids', $ids); | $event->setEventParam('ids', $ids); | ||||
$this->customProcessing($event, 'before'); | $this->customProcessing($event, 'before'); | ||||
$ids = $event->getEventParam('ids'); | $ids = $event->getEventParam('ids'); | ||||
if ( $ids ) { | if ( $ids ) { | ||||
/** @var kRecursiveHelper $recursive_helper */ | |||||
$recursive_helper = $this->Application->recallObject('RecursiveHelper'); | $recursive_helper = $this->Application->recallObject('RecursiveHelper'); | ||||
/* @var $recursive_helper kRecursiveHelper */ | |||||
foreach ($ids as $id) { | foreach ($ids as $id) { | ||||
$recursive_helper->DeleteCategory($id, $event->Prefix); | $recursive_helper->DeleteCategory($id, $event->Prefix); | ||||
} | } | ||||
} | } | ||||
$this->clearSelectedIDs($event); | $this->clearSelectedIDs($event); | ||||
$this->_ensurePermCacheRebuild($event); | $this->_ensurePermCacheRebuild($event); | ||||
} | } | ||||
/** | /** | ||||
* Add selected items to clipboard with mode = COPY (CLONE) | * Add selected items to clipboard with mode = COPY (CLONE) | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnCopy($event) | function OnCopy($event) | ||||
{ | { | ||||
$this->Application->RemoveVar('clipboard'); | $this->Application->RemoveVar('clipboard'); | ||||
/** @var kClipboardHelper $clipboard_helper */ | |||||
$clipboard_helper = $this->Application->recallObject('ClipboardHelper'); | $clipboard_helper = $this->Application->recallObject('ClipboardHelper'); | ||||
/* @var $clipboard_helper kClipboardHelper */ | |||||
$clipboard_helper->setClipboard($event, 'copy', $this->StoreSelectedIDs($event)); | $clipboard_helper->setClipboard($event, 'copy', $this->StoreSelectedIDs($event)); | ||||
$this->clearSelectedIDs($event); | $this->clearSelectedIDs($event); | ||||
} | } | ||||
/** | /** | ||||
* Add selected items to clipboard with mode = CUT | * Add selected items to clipboard with mode = CUT | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnCut($event) | function OnCut($event) | ||||
{ | { | ||||
$this->Application->RemoveVar('clipboard'); | $this->Application->RemoveVar('clipboard'); | ||||
/** @var kClipboardHelper $clipboard_helper */ | |||||
$clipboard_helper = $this->Application->recallObject('ClipboardHelper'); | $clipboard_helper = $this->Application->recallObject('ClipboardHelper'); | ||||
/* @var $clipboard_helper kClipboardHelper */ | |||||
$clipboard_helper->setClipboard($event, 'cut', $this->StoreSelectedIDs($event)); | $clipboard_helper->setClipboard($event, 'cut', $this->StoreSelectedIDs($event)); | ||||
$this->clearSelectedIDs($event); | $this->clearSelectedIDs($event); | ||||
} | } | ||||
/** | /** | ||||
* Controls all item paste operations. Can occur only with filled clipboard. | * Controls all item paste operations. Can occur only with filled clipboard. | ||||
* | * | ||||
Show All 13 Lines | |||||
/** | /** | ||||
* Checks permission for OnPaste event | * Checks permission for OnPaste event | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
function _checkPastePermission($event) | function _checkPastePermission($event) | ||||
{ | { | ||||
/** @var kPermissionsHelper $perm_helper */ | |||||
$perm_helper = $this->Application->recallObject('PermissionsHelper'); | $perm_helper = $this->Application->recallObject('PermissionsHelper'); | ||||
/* @var $perm_helper kPermissionsHelper */ | |||||
$category_id = $this->Application->GetVar('m_cat_id'); | $category_id = $this->Application->GetVar('m_cat_id'); | ||||
if ($perm_helper->AddCheckPermission($category_id, $event->Prefix) == 0) { | if ($perm_helper->AddCheckPermission($category_id, $event->Prefix) == 0) { | ||||
// no items left for editing -> no permission | // no items left for editing -> no permission | ||||
return $perm_helper->finalizePermissionCheck($event, false); | return $perm_helper->finalizePermissionCheck($event, false); | ||||
} | } | ||||
return true; | return true; | ||||
Show All 26 Lines | |||||
if ( $clipboard_data['cut'] ) { | if ( $clipboard_data['cut'] ) { | ||||
$sql = 'SELECT ParentId | $sql = 'SELECT ParentId | ||||
FROM ' . $table_name . ' | FROM ' . $table_name . ' | ||||
WHERE ' . $id_field . ' = ' . $clipboard_data['cut'][0]; | WHERE ' . $id_field . ' = ' . $clipboard_data['cut'][0]; | ||||
$source_category_id = $this->Conn->GetOne($sql); | $source_category_id = $this->Conn->GetOne($sql); | ||||
} | } | ||||
/** @var kRecursiveHelper $recursive_helper */ | |||||
$recursive_helper = $this->Application->recallObject('RecursiveHelper'); | $recursive_helper = $this->Application->recallObject('RecursiveHelper'); | ||||
/* @var $recursive_helper kRecursiveHelper */ | |||||
if ( $clipboard_data['cut'] ) { | if ( $clipboard_data['cut'] ) { | ||||
$recursive_helper->MoveCategories($clipboard_data['cut'], $this->Application->GetVar('m_cat_id')); | $recursive_helper->MoveCategories($clipboard_data['cut'], $this->Application->GetVar('m_cat_id')); | ||||
} | } | ||||
if ( $clipboard_data['copy'] ) { | if ( $clipboard_data['copy'] ) { | ||||
// don't allow to copy/paste system OR theme-linked virtual pages | // don't allow to copy/paste system OR theme-linked virtual pages | ||||
$sql = 'SELECT ' . $id_field . ' | $sql = 'SELECT ' . $id_field . ' | ||||
FROM ' . $table_name . ' | FROM ' . $table_name . ' | ||||
WHERE ' . $id_field . ' IN (' . implode(',', $clipboard_data['copy']) . ') AND (`Type` = ' . PAGE_TYPE_VIRTUAL . ') AND (ThemeId = 0)'; | WHERE ' . $id_field . ' IN (' . implode(',', $clipboard_data['copy']) . ') AND (`Type` = ' . PAGE_TYPE_VIRTUAL . ') AND (ThemeId = 0)'; | ||||
$allowed_ids = $this->Conn->GetCol($sql); | $allowed_ids = $this->Conn->GetCol($sql); | ||||
if ( !$allowed_ids ) { | if ( !$allowed_ids ) { | ||||
return; | return; | ||||
} | } | ||||
foreach ($allowed_ids as $id) { | foreach ($allowed_ids as $id) { | ||||
$recursive_helper->PasteCategory($id, $event->Prefix); | $recursive_helper->PasteCategory($id, $event->Prefix); | ||||
} | } | ||||
} | } | ||||
/** @var kPriorityHelper $priority_helper */ | |||||
$priority_helper = $this->Application->recallObject('PriorityHelper'); | $priority_helper = $this->Application->recallObject('PriorityHelper'); | ||||
/* @var $priority_helper kPriorityHelper */ | |||||
if ( $clipboard_data['cut'] ) { | if ( $clipboard_data['cut'] ) { | ||||
$ids = $priority_helper->recalculatePriorities($event, 'ParentId = ' . $source_category_id); | $ids = $priority_helper->recalculatePriorities($event, 'ParentId = ' . $source_category_id); | ||||
if ( $ids ) { | if ( $ids ) { | ||||
$priority_helper->massUpdateChanged($event->Prefix, $ids); | $priority_helper->massUpdateChanged($event->Prefix, $ids); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Line(s) | |||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnBeforeItemCreate(kEvent $event) | protected function OnBeforeItemCreate(kEvent $event) | ||||
{ | { | ||||
parent::OnBeforeItemCreate($event); | parent::OnBeforeItemCreate($event); | ||||
/** @var CategoriesItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object CategoriesItem */ | |||||
if ( $object->GetDBField('ParentId') <= 0 ) { | if ( $object->GetDBField('ParentId') <= 0 ) { | ||||
// no parent category - use current (happens during import) | // no parent category - use current (happens during import) | ||||
$object->SetDBField('ParentId', $this->Application->GetVar('m_cat_id')); | $object->SetDBField('ParentId', $this->Application->GetVar('m_cat_id')); | ||||
} | } | ||||
$this->_beforeItemChange($event); | $this->_beforeItemChange($event); | ||||
if ( $this->Application->isAdmin || $event->Prefix == 'st' ) { | if ( $this->Application->isAdmin || $event->Prefix == 'st' ) { | ||||
// don't check category permissions when auto-creating structure pages | // don't check category permissions when auto-creating structure pages | ||||
return ; | return ; | ||||
} | } | ||||
/** @var kPermissionsHelper $perm_helper */ | |||||
$perm_helper = $this->Application->recallObject('PermissionsHelper'); | $perm_helper = $this->Application->recallObject('PermissionsHelper'); | ||||
/* @var $perm_helper kPermissionsHelper */ | |||||
$new_status = false; | $new_status = false; | ||||
$category_id = $this->Application->GetVar('m_cat_id'); | $category_id = $this->Application->GetVar('m_cat_id'); | ||||
if ( $perm_helper->CheckPermission('CATEGORY.ADD', 0, $category_id) ) { | if ( $perm_helper->CheckPermission('CATEGORY.ADD', 0, $category_id) ) { | ||||
$new_status = STATUS_ACTIVE; | $new_status = STATUS_ACTIVE; | ||||
} | } | ||||
else { | else { | ||||
Show All 38 Lines | |||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnBeforeItemUpdate(kEvent $event) | protected function OnBeforeItemUpdate(kEvent $event) | ||||
{ | { | ||||
parent::OnBeforeItemUpdate($event); | parent::OnBeforeItemUpdate($event); | ||||
$this->_beforeItemChange($event); | $this->_beforeItemChange($event); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
if ( $object->GetChangedFields() ) { | if ( $object->GetChangedFields() ) { | ||||
$object->SetDBField('ModifiedById', $this->Application->RecallVar('user_id')); | $object->SetDBField('ModifiedById', $this->Application->RecallVar('user_id')); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Creates needed sql query to load item, | * Creates needed sql query to load item, | ||||
* if no query is defined in config for | * if no query is defined in config for | ||||
* special requested, then use list query | * special requested, then use list query | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return string | * @return string | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function ItemPrepareQuery(kEvent $event) | protected function ItemPrepareQuery(kEvent $event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$sqls = $object->getFormOption('ItemSQLs', Array ()); | $sqls = $object->getFormOption('ItemSQLs', Array ()); | ||||
$category_special = $this->_getCategorySpecial($event); | $category_special = $this->_getCategorySpecial($event); | ||||
$special = isset($sqls[$category_special]) ? $category_special : ''; | $special = isset($sqls[$category_special]) ? $category_special : ''; | ||||
// preferred special not found in ItemSQLs -> use analog from ListSQLs | // preferred special not found in ItemSQLs -> use analog from ListSQLs | ||||
return isset($sqls[$special]) ? $sqls[$special] : $this->ListPrepareQuery($event); | return isset($sqls[$special]) ? $sqls[$special] : $this->ListPrepareQuery($event); | ||||
} | } | ||||
/** | /** | ||||
* Creates needed sql query to load list, | * Creates needed sql query to load list, | ||||
* if no query is defined in config for | * if no query is defined in config for | ||||
* special requested, then use default | * special requested, then use default | ||||
* query | * query | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return string | * @return string | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function ListPrepareQuery(kEvent $event) | protected function ListPrepareQuery(kEvent $event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$special = $this->_getCategorySpecial($event); | $special = $this->_getCategorySpecial($event); | ||||
$sqls = $object->getFormOption('ListSQLs', Array ()); | $sqls = $object->getFormOption('ListSQLs', Array ()); | ||||
return $sqls[array_key_exists($special, $sqls) ? $special : '']; | return $sqls[array_key_exists($special, $sqls) ? $special : '']; | ||||
} | } | ||||
/** | /** | ||||
* Performs redirect to correct suggest confirmation template | * Performs redirect to correct suggest confirmation template | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnCreate(kEvent $event) | protected function OnCreate(kEvent $event) | ||||
{ | { | ||||
parent::OnCreate($event); | parent::OnCreate($event); | ||||
if ( $this->Application->isAdmin || $event->status != kEvent::erSUCCESS ) { | if ( $this->Application->isAdmin || $event->status != kEvent::erSUCCESS ) { | ||||
// don't sent email or rebuild cache directly after category is created by admin | // don't sent email or rebuild cache directly after category is created by admin | ||||
return; | return; | ||||
} | } | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
/** @var kPermCacheUpdater $cache_updater */ | |||||
$cache_updater = $this->Application->makeClass('kPermCacheUpdater', Array (null, $object->GetDBField('ParentPath'))); | $cache_updater = $this->Application->makeClass('kPermCacheUpdater', Array (null, $object->GetDBField('ParentPath'))); | ||||
Line exceeds 120 characters; contains 129 characters Lint: Generic.Files.LineLength.TooLong: Line exceeds 120 characters; contains 129 characters | |||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
/* @var $cache_updater kPermCacheUpdater */ | |||||
$cache_updater->OneStepRun(); | $cache_updater->OneStepRun(); | ||||
$is_active = ($object->GetDBField('Status') == STATUS_ACTIVE); | $is_active = ($object->GetDBField('Status') == STATUS_ACTIVE); | ||||
$next_template = $is_active ? 'suggest_confirm_template' : 'suggest_pending_confirm_template'; | $next_template = $is_active ? 'suggest_confirm_template' : 'suggest_pending_confirm_template'; | ||||
$event->redirect = $this->Application->GetVar($next_template); | $event->redirect = $this->Application->GetVar($next_template); | ||||
$event->SetRedirectParam('opener', 's'); | $event->SetRedirectParam('opener', 's'); | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
if ( !$this->Application->isAdmin ) { | if ( !$this->Application->isAdmin ) { | ||||
$page_var = $event->getEventParam('page_var'); | $page_var = $event->getEventParam('page_var'); | ||||
if ( $page_var !== false ) { | if ( $page_var !== false ) { | ||||
$page = $this->Application->GetVar($page_var); | $page = $this->Application->GetVar($page_var); | ||||
if ( is_numeric($page) ) { | if ( is_numeric($page) ) { | ||||
/** @var kDBList $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBList */ | |||||
$object->SetPage($page); | $object->SetPage($page); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
Show All 9 Lines | |||||
parent::iterateItems($event); | parent::iterateItems($event); | ||||
} | } | ||||
if ( $this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1) ) { | if ( $this->Application->CheckPermission('SYSTEM_ACCESS.READONLY', 1) ) { | ||||
$event->status = kEvent::erFAIL; | $event->status = kEvent::erFAIL; | ||||
return; | return; | ||||
} | } | ||||
/** @var CategoriesItem $object */ | |||||
$object = $event->getObject(Array ('skip_autoload' => true)); | $object = $event->getObject(Array ('skip_autoload' => true)); | ||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
/* @var $object CategoriesItem */ | |||||
$ids = $this->StoreSelectedIDs($event); | $ids = $this->StoreSelectedIDs($event); | ||||
if ( $ids ) { | if ( $ids ) { | ||||
$status_field = $object->getStatusField(); | $status_field = $object->getStatusField(); | ||||
$propagate_category_status = $this->Application->GetVar('propagate_category_status'); | $propagate_category_status = $this->Application->GetVar('propagate_category_status'); | ||||
foreach ($ids as $id) { | foreach ($ids as $id) { | ||||
Show All 22 Lines | |||||
* Checks, that currently loaded item is allowed for viewing (non permission-based) | * Checks, that currently loaded item is allowed for viewing (non permission-based) | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return bool | * @return bool | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function checkItemStatus(kEvent $event) | protected function checkItemStatus(kEvent $event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
if ( !$object->isLoaded() ) { | if ( !$object->isLoaded() ) { | ||||
return true; | return true; | ||||
} | } | ||||
if ( $object->GetDBField('Status') != STATUS_ACTIVE && $object->GetDBField('Status') != 4 ) { | if ( $object->GetDBField('Status') != STATUS_ACTIVE && $object->GetDBField('Status') != 4 ) { | ||||
if ( !$object->GetDBField('DirectLinkEnabled') || !$object->GetDBField('DirectLinkAuthKey') ) { | if ( !$object->GetDBField('DirectLinkEnabled') || !$object->GetDBField('DirectLinkAuthKey') ) { | ||||
return false; | return false; | ||||
Show All 16 Lines | |||||
protected function SetSorting(kEvent $event) | protected function SetSorting(kEvent $event) | ||||
{ | { | ||||
$types = $event->getEventParam('types'); | $types = $event->getEventParam('types'); | ||||
$types = $types ? explode(',', $types) : Array (); | $types = $types ? explode(',', $types) : Array (); | ||||
if ( in_array('search', $types) ) { | if ( in_array('search', $types) ) { | ||||
$event->setPseudoClass('_List'); | $event->setPseudoClass('_List'); | ||||
/** @var kDBList $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBList */ | |||||
// 1. no user sorting - sort by relevance | // 1. no user sorting - sort by relevance | ||||
$default_sortings = parent::_getDefaultSorting($event); | $default_sortings = parent::_getDefaultSorting($event); | ||||
$default_sorting = key($default_sortings['Sorting']) . ',' . current($default_sortings['Sorting']); | $default_sorting = key($default_sortings['Sorting']) . ',' . current($default_sortings['Sorting']); | ||||
if ( $object->isMainList() ) { | if ( $object->isMainList() ) { | ||||
$sort_by = $this->Application->GetVar('sort_by', ''); | $sort_by = $this->Application->GetVar('sort_by', ''); | ||||
Show All 24 Lines | |||||
/** | /** | ||||
* Removes forced sortings | * Removes forced sortings | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
protected function _removeForcedSortings(kEvent $event) | protected function _removeForcedSortings(kEvent $event) | ||||
{ | { | ||||
/** @var Array $list_sortings */ | |||||
$list_sortings = $this->Application->getUnitOption($event->Prefix, 'ListSortings', Array ()); | $list_sortings = $this->Application->getUnitOption($event->Prefix, 'ListSortings', Array ()); | ||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
/* @var $list_sortings Array */ | |||||
foreach ($list_sortings as $special => $sortings) { | foreach ($list_sortings as $special => $sortings) { | ||||
unset($list_sortings[$special]['ForcedSorting']); | unset($list_sortings[$special]['ForcedSorting']); | ||||
} | } | ||||
$this->Application->setUnitOption($event->Prefix, 'ListSortings', $list_sortings); | $this->Application->setUnitOption($event->Prefix, 'ListSortings', $list_sortings); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | |||||
* @access public | * @access public | ||||
*/ | */ | ||||
public function GetDesignTemplate($t = null) | public function GetDesignTemplate($t = null) | ||||
{ | { | ||||
if ( !isset($t) ) { | if ( !isset($t) ) { | ||||
$t = $this->Application->GetVar('t'); | $t = $this->Application->GetVar('t'); | ||||
} | } | ||||
/** @var CategoriesItem $page */ | |||||
$page = $this->Application->recallObject($this->Prefix . '.-virtual', null, Array ('page' => $t)); | $page = $this->Application->recallObject($this->Prefix . '.-virtual', null, Array ('page' => $t)); | ||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
/* @var $page CategoriesItem */ | |||||
if ( $page->isLoaded() ) { | if ( $page->isLoaded() ) { | ||||
$real_t = $page->GetDBField('CachedTemplate'); | $real_t = $page->GetDBField('CachedTemplate'); | ||||
$this->Application->SetVar('m_cat_id', $page->GetDBField('CategoryId')); | $this->Application->SetVar('m_cat_id', $page->GetDBField('CategoryId')); | ||||
if ( $page->GetDBField('FormId') ) { | if ( $page->GetDBField('FormId') ) { | ||||
$this->Application->SetVar('form_id', $page->GetDBField('FormId')); | $this->Application->SetVar('form_id', $page->GetDBField('FormId')); | ||||
} | } | ||||
} | } | ||||
else { | else { | ||||
$this->Application->UrlManager->show404(); | $this->Application->UrlManager->show404(); | ||||
} | } | ||||
// replace alias in form #alias_name# to actual template used in this theme | // replace alias in form #alias_name# to actual template used in this theme | ||||
if ( $this->Application->isAdmin ) { | if ( $this->Application->isAdmin ) { | ||||
/** @var kThemesHelper $themes_helper */ | |||||
$themes_helper = $this->Application->recallObject('ThemesHelper'); | $themes_helper = $this->Application->recallObject('ThemesHelper'); | ||||
/* @var $themes_helper kThemesHelper */ | |||||
// only, used when in "Design Mode" | // only, used when in "Design Mode" | ||||
$this->Application->SetVar('theme.current_id', $themes_helper->getCurrentThemeId()); | $this->Application->SetVar('theme.current_id', $themes_helper->getCurrentThemeId()); | ||||
} | } | ||||
/** @var kDBItem $theme */ | |||||
$theme = $this->Application->recallObject('theme.current'); | $theme = $this->Application->recallObject('theme.current'); | ||||
/* @var $theme kDBItem */ | |||||
$template = $theme->GetField('TemplateAliases', $real_t); | $template = $theme->GetField('TemplateAliases', $real_t); | ||||
if ( $template ) { | if ( $template ) { | ||||
return $template; | return $template; | ||||
} | } | ||||
return $real_t; | return $real_t; | ||||
Show All 16 Lines | |||||
/** | /** | ||||
* Prepares template paths | * Prepares template paths | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function _beforeItemChange($event) | function _beforeItemChange($event) | ||||
{ | { | ||||
/** @var CategoriesItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object CategoriesItem */ | |||||
$now = adodb_mktime(); | $now = adodb_mktime(); | ||||
if ( !$this->Application->isDebugMode() && strpos($event->Special, 'rebuild') === false ) { | if ( !$this->Application->isDebugMode() && strpos($event->Special, 'rebuild') === false ) { | ||||
$object->SetDBField('Type', $object->GetOriginalField('Type')); | $object->SetDBField('Type', $object->GetOriginalField('Type')); | ||||
$object->SetDBField('Protected', $object->GetOriginalField('Protected')); | $object->SetDBField('Protected', $object->GetOriginalField('Protected')); | ||||
if ( $object->GetDBField('Protected') ) { | if ( $object->GetDBField('Protected') ) { | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | |||||
* @param kDBItem $object | * @param kDBItem $object | ||||
* @param string $field | * @param string $field | ||||
* @author Alex | * @author Alex | ||||
*/ | */ | ||||
function _saveTitleField(&$object, $field) | function _saveTitleField(&$object, $field) | ||||
{ | { | ||||
$value = $object->GetField($field, 'no_default'); // current value of target field | $value = $object->GetField($field, 'no_default'); // current value of target field | ||||
/** @var kMultiLanguage $ml_formatter */ | |||||
$ml_formatter = $this->Application->recallObject('kMultiLanguage'); | $ml_formatter = $this->Application->recallObject('kMultiLanguage'); | ||||
/* @var $ml_formatter kMultiLanguage */ | |||||
$src_field = $ml_formatter->LangFieldName('Name'); | $src_field = $ml_formatter->LangFieldName('Name'); | ||||
$dst_field = $ml_formatter->LangFieldName($field); | $dst_field = $ml_formatter->LangFieldName($field); | ||||
$dst_field_not_changed = $object->GetOriginalField($dst_field) == $value; | $dst_field_not_changed = $object->GetOriginalField($dst_field) == $value; | ||||
if ($value == '' || preg_match('/^_Auto: (.*)/', $value) || (($object->GetOriginalField($src_field) == $value) && $dst_field_not_changed)) { | if ($value == '' || preg_match('/^_Auto: (.*)/', $value) || (($object->GetOriginalField($src_field) == $value) && $dst_field_not_changed)) { | ||||
// target field is empty OR target field value starts with "_Auto: " OR (source field value | // target field is empty OR target field value starts with "_Auto: " OR (source field value | ||||
// before change was equals to current target field value AND target field value wasn't changed) | // before change was equals to current target field value AND target field value wasn't changed) | ||||
$object->SetField($dst_field, $object->GetField($src_field)); | $object->SetField($dst_field, $object->GetField($src_field)); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Don't allow to delete system pages, when not in debug mode | * Don't allow to delete system pages, when not in debug mode | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnBeforeItemDelete(kEvent $event) | protected function OnBeforeItemDelete(kEvent $event) | ||||
{ | { | ||||
parent::OnBeforeItemDelete($event); | parent::OnBeforeItemDelete($event); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
if ( $object->GetDBField('Protected') && !$this->Application->isDebugMode(false) ) { | if ( $object->GetDBField('Protected') && !$this->Application->isDebugMode(false) ) { | ||||
$event->status = kEvent::erFAIL; | $event->status = kEvent::erFAIL; | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Creates category based on given TPL file | * Creates category based on given TPL file | ||||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Line(s) | |||||
} | } | ||||
if (array_key_exists(implode('||', $category_path), $category_ids)) { | if (array_key_exists(implode('||', $category_path), $category_ids)) { | ||||
return $category_ids[ implode('||', $category_path) ]; | return $category_ids[ implode('||', $category_path) ]; | ||||
} | } | ||||
$backup_category_id = $this->Application->GetVar('m_cat_id'); | $backup_category_id = $this->Application->GetVar('m_cat_id'); | ||||
/** @var CategoriesItem $object */ | |||||
$object = $this->Application->recallObject($this->Prefix . '.rebuild-path', null, Array ('skip_autoload' => true)); | $object = $this->Application->recallObject($this->Prefix . '.rebuild-path', null, Array ('skip_autoload' => true)); | ||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
Line exceeds 120 characters; contains 127 characters Lint: Generic.Files.LineLength.TooLong: Line exceeds 120 characters; contains 127 characters | |||||
/* @var $object CategoriesItem */ | |||||
$parent_id = $base_category; | $parent_id = $base_category; | ||||
/** @var kFilenamesHelper $filenames_helper */ | |||||
$filenames_helper = $this->Application->recallObject('FilenamesHelper'); | $filenames_helper = $this->Application->recallObject('FilenamesHelper'); | ||||
/* @var $filenames_helper kFilenamesHelper */ | |||||
$safe_category_path = array_map(Array (&$filenames_helper, 'replaceSequences'), $category_path); | $safe_category_path = array_map(Array (&$filenames_helper, 'replaceSequences'), $category_path); | ||||
foreach ($category_path as $category_order => $category_name) { | foreach ($category_path as $category_order => $category_name) { | ||||
$this->Application->SetVar('m_cat_id', $parent_id); | $this->Application->SetVar('m_cat_id', $parent_id); | ||||
// get virtual category first, when possible | // get virtual category first, when possible | ||||
$sql = 'SELECT ' . $object->IDField . ' | $sql = 'SELECT ' . $object->IDField . ' | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Line(s) | |||||
if (defined('IS_INSTALL') && IS_INSTALL) { | if (defined('IS_INSTALL') && IS_INSTALL) { | ||||
// skip any processing, because Categories table doesn't exists until install is finished | // skip any processing, because Categories table doesn't exists until install is finished | ||||
$this->addViewPermissionJoin($event); | $this->addViewPermissionJoin($event); | ||||
return ; | return ; | ||||
} | } | ||||
/** @var SiteConfigHelper $site_config_helper */ | |||||
$site_config_helper = $this->Application->recallObject('SiteConfigHelper'); | $site_config_helper = $this->Application->recallObject('SiteConfigHelper'); | ||||
/* @var $site_config_helper SiteConfigHelper */ | |||||
$settings = $site_config_helper->getSettings(); | $settings = $site_config_helper->getSettings(); | ||||
$root_category = $this->Application->getBaseCategory(); | $root_category = $this->Application->getBaseCategory(); | ||||
// set root category | // set root category | ||||
$section_adjustments = $this->Application->getUnitOption($event->Prefix, 'SectionAdjustments'); | $section_adjustments = $this->Application->getUnitOption($event->Prefix, 'SectionAdjustments'); | ||||
$section_adjustments['in-portal:browse'] = Array ( | $section_adjustments['in-portal:browse'] = Array ( | ||||
'url' => Array ('m_cat_id' => $root_category), | 'url' => Array ('m_cat_id' => $root_category), | ||||
'late_load' => Array ('m_cat_id' => $root_category), | 'late_load' => Array ('m_cat_id' => $root_category), | ||||
'onclick' => 'checkCatalog(' . $root_category . ', "c")', | 'onclick' => 'checkCatalog(' . $root_category . ', "c")', | ||||
); | ); | ||||
if ( $this->Application->ConfigValue('Catalog_PreselectModuleTab') ) { | if ( $this->Application->ConfigValue('Catalog_PreselectModuleTab') ) { | ||||
$section_adjustments['in-portal:browse']['url']['anchor'] = 'tab-c'; | $section_adjustments['in-portal:browse']['url']['anchor'] = 'tab-c'; | ||||
} | } | ||||
$section_adjustments['in-portal:browse_site'] = Array ( | $section_adjustments['in-portal:browse_site'] = Array ( | ||||
'url' => Array ('editing_mode' => $settings['default_editing_mode']), | 'url' => Array ('editing_mode' => $settings['default_editing_mode']), | ||||
); | ); | ||||
$this->Application->setUnitOption($event->Prefix, 'SectionAdjustments', $section_adjustments); | $this->Application->setUnitOption($event->Prefix, 'SectionAdjustments', $section_adjustments); | ||||
// prepare structure dropdown | // prepare structure dropdown | ||||
Inline comments must start with a capital letter Lint: CodingStandard.Commenting.InlineComment.NotCapital: Inline comments must start with a capital letter | |||||
Inline comments must end in full-stops, exclamation marks, or question marks Lint: CodingStandard.Commenting.InlineComment.InvalidEndChar: Inline comments must end in full-stops, exclamation marks, or question marks | |||||
/** @var CategoryHelper $category_helper */ | |||||
$category_helper = $this->Application->recallObject('CategoryHelper'); | $category_helper = $this->Application->recallObject('CategoryHelper'); | ||||
/* @var $category_helper CategoryHelper */ | |||||
$fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); | $fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); | ||||
$fields['ParentId']['default'] = (int)$this->Application->GetVar('m_cat_id'); | $fields['ParentId']['default'] = (int)$this->Application->GetVar('m_cat_id'); | ||||
$fields['ParentId']['options'] = $category_helper->getStructureTreeAsOptions(); | $fields['ParentId']['options'] = $category_helper->getStructureTreeAsOptions(); | ||||
// limit design list by theme | // limit design list by theme | ||||
$theme_id = $this->_getCurrentThemeId(); | $theme_id = $this->_getCurrentThemeId(); | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | |||||
{ | { | ||||
if ( $this->Application->ConfigValue('CheckViewPermissionsInCatalog') ) { | if ( $this->Application->ConfigValue('CheckViewPermissionsInCatalog') ) { | ||||
$join_clause = 'LEFT JOIN ' . TABLE_PREFIX . 'CategoryPermissionsCache perm ON perm.CategoryId = %1$s.CategoryId'; | $join_clause = 'LEFT JOIN ' . TABLE_PREFIX . 'CategoryPermissionsCache perm ON perm.CategoryId = %1$s.CategoryId'; | ||||
} | } | ||||
else { | else { | ||||
$join_clause = ''; | $join_clause = ''; | ||||
} | } | ||||
/** @var array $list_sqls */ | |||||
$list_sqls = $this->Application->getUnitOption($event->Prefix, 'ListSQLs'); | $list_sqls = $this->Application->getUnitOption($event->Prefix, 'ListSQLs'); | ||||
/* @var $list_sqls array */ | |||||
foreach ($list_sqls as $special => $list_sql) { | foreach ($list_sqls as $special => $list_sql) { | ||||
$list_sqls[$special] = str_replace('{PERM_JOIN}', $join_clause, $list_sql); | $list_sqls[$special] = str_replace('{PERM_JOIN}', $join_clause, $list_sql); | ||||
} | } | ||||
$this->Application->setUnitOption($event->Prefix, 'ListSQLs', $list_sqls); | $this->Application->setUnitOption($event->Prefix, 'ListSQLs', $list_sqls); | ||||
return $this; | return $this; | ||||
Show All 27 Lines | |||||
{ | { | ||||
parent::OnAfterItemLoad($event); | parent::OnAfterItemLoad($event); | ||||
if ( !$this->Application->isAdmin ) { | if ( !$this->Application->isAdmin ) { | ||||
// calculate priorities dropdown only for admin | // calculate priorities dropdown only for admin | ||||
return; | return; | ||||
} | } | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
// remove this category & it's children from dropdown | // remove this category & it's children from dropdown | ||||
$sql = 'SELECT ' . $object->IDField . ' | $sql = 'SELECT ' . $object->IDField . ' | ||||
FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' | FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' | ||||
WHERE ParentPath LIKE "' . $object->GetDBField('ParentPath') . '%"'; | WHERE ParentPath LIKE "' . $object->GetDBField('ParentPath') . '%"'; | ||||
$remove_categories = $this->Conn->GetCol($sql); | $remove_categories = $this->Conn->GetCol($sql); | ||||
$options = $object->GetFieldOption('ParentId', 'options'); | $options = $object->GetFieldOption('ParentId', 'options'); | ||||
Show All 9 Lines | |||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnAfterItemCreate(kEvent $event) | protected function OnAfterItemCreate(kEvent $event) | ||||
{ | { | ||||
parent::OnAfterItemCreate($event); | parent::OnAfterItemCreate($event); | ||||
/** @var CategoriesItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object CategoriesItem */ | |||||
// need to update path after category is created, so category is included in that path | // need to update path after category is created, so category is included in that path | ||||
$fields_hash = $object->buildParentBasedFields(); | $fields_hash = $object->buildParentBasedFields(); | ||||
$this->Conn->doUpdate($fields_hash, $object->TableName, $object->IDField . ' = ' . $object->GetID()); | $this->Conn->doUpdate($fields_hash, $object->TableName, $object->IDField . ' = ' . $object->GetID()); | ||||
$object->SetDBFieldsFromHash($fields_hash); | $object->SetDBFieldsFromHash($fields_hash); | ||||
} | } | ||||
/** | /** | ||||
Show All 15 Lines | |||||
$files = $this->Conn->Query($sql, 'Path'); | $files = $this->Conn->Query($sql, 'Path'); | ||||
if ( !$files ) { | if ( !$files ) { | ||||
// all possible pages are already created | // all possible pages are already created | ||||
return; | return; | ||||
} | } | ||||
kUtil::setResourceLimit(); | kUtil::setResourceLimit(); | ||||
/** @var CategoriesItem $dummy */ | |||||
$dummy = $this->Application->recallObject($event->Prefix . '.rebuild', NULL, Array ('skip_autoload' => true)); | $dummy = $this->Application->recallObject($event->Prefix . '.rebuild', NULL, Array ('skip_autoload' => true)); | ||||
There must be no space between the Array keyword and the opening parenthesis Lint: CodingStandard.Array.Array.SpaceAfterKeyword: There must be no space between the Array keyword and the opening parenthesis | |||||
PHP keywords must be lowercase; expected "array" but found "Array" Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
Line exceeds 120 characters; contains 122 characters Lint: Generic.Files.LineLength.TooLong: Line exceeds 120 characters; contains 122 characters | |||||
TRUE, FALSE and NULL must be lowercase; expected "null" but found "NULL" Lint: Generic.PHP.LowerCaseConstant.Found: TRUE, FALSE and NULL must be lowercase; expected "null" but found "NULL" | |||||
/* @var $dummy CategoriesItem */ | |||||
$error_count = 0; | $error_count = 0; | ||||
foreach ($files as $a_file => $file_info) { | foreach ($files as $a_file => $file_info) { | ||||
$status = $this->_prepareAutoPage($dummy, $a_file, $file_info['ThemeId'], SMS_MODE_FORCE, unserialize($file_info['FileMetaInfo'])); // create system page | $status = $this->_prepareAutoPage($dummy, $a_file, $file_info['ThemeId'], SMS_MODE_FORCE, unserialize($file_info['FileMetaInfo'])); // create system page | ||||
if ( !$status ) { | if ( !$status ) { | ||||
$error_count++; | $error_count++; | ||||
} | } | ||||
} | } | ||||
if ( $this->Application->ConfigValue('CategoryPermissionRebuildMode') == CategoryPermissionRebuild::SILENT ) { | if ( $this->Application->ConfigValue('CategoryPermissionRebuildMode') == CategoryPermissionRebuild::SILENT ) { | ||||
Line exceeds 120 characters; contains 122 characters Lint: Generic.Files.LineLength.TooLong: Line exceeds 120 characters; contains 122 characters | |||||
/** @var kPermCacheUpdater $updater */ | |||||
$updater = $this->Application->makeClass('kPermCacheUpdater'); | $updater = $this->Application->makeClass('kPermCacheUpdater'); | ||||
/* @var $updater kPermCacheUpdater */ | |||||
$updater->OneStepRun(); | $updater->OneStepRun(); | ||||
} | } | ||||
$this->_resetMenuCache(); | $this->_resetMenuCache(); | ||||
if ( $error_count ) { | if ( $error_count ) { | ||||
// allow user to review error after structure page creation | // allow user to review error after structure page creation | ||||
Show All 38 Lines | |||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnUpdatePreviewBlock($event) | function OnUpdatePreviewBlock($event) | ||||
{ | { | ||||
$event->status = kEvent::erSTOP; | $event->status = kEvent::erSTOP; | ||||
$string = $this->Application->unescapeRequestVariable($this->Application->GetVar('preview_content')); | $string = $this->Application->unescapeRequestVariable($this->Application->GetVar('preview_content')); | ||||
/** @var CategoryHelper $category_helper */ | |||||
$category_helper = $this->Application->recallObject('CategoryHelper'); | $category_helper = $this->Application->recallObject('CategoryHelper'); | ||||
/* @var $category_helper CategoryHelper */ | |||||
$string = $category_helper->replacePageIds($string); | $string = $category_helper->replacePageIds($string); | ||||
$this->Application->StoreVar('_editor_preview_content_', $string); | $this->Application->StoreVar('_editor_preview_content_', $string); | ||||
} | } | ||||
/** | /** | ||||
* Makes simple search for categories | * Makes simple search for categories | ||||
* based on keywords string | * based on keywords string | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
*/ | */ | ||||
function OnSimpleSearch($event) | function OnSimpleSearch($event) | ||||
{ | { | ||||
$event->redirect = false; | $event->redirect = false; | ||||
$keywords = $this->Application->unescapeRequestVariable(trim($this->Application->GetVar('keywords'))); | $keywords = $this->Application->unescapeRequestVariable(trim($this->Application->GetVar('keywords'))); | ||||
/** @var kHTTPQuery $query_object */ | |||||
$query_object = $this->Application->recallObject('HTTPQuery'); | $query_object = $this->Application->recallObject('HTTPQuery'); | ||||
/* @var $query_object kHTTPQuery */ | |||||
/** @var kSearchHelper $search_helper */ | /** @var kSearchHelper $search_helper */ | ||||
$search_helper = $this->Application->recallObject('SearchHelper'); | $search_helper = $this->Application->recallObject('SearchHelper'); | ||||
$search_table = $search_helper->getSearchTable(); | $search_table = $search_helper->getSearchTable(); | ||||
$sql = 'SHOW TABLES LIKE "'.$search_table.'"'; | $sql = 'SHOW TABLES LIKE "'.$search_table.'"'; | ||||
if ( !isset($query_object->Get['keywords']) && !isset($query_object->Post['keywords']) && $this->Conn->Query($sql) ) { | if ( !isset($query_object->Get['keywords']) && !isset($query_object->Post['keywords']) && $this->Conn->Query($sql) ) { | ||||
Show All 11 Lines | |||||
$this->Application->StoreVar('keywords', $keywords); | $this->Application->StoreVar('keywords', $keywords); | ||||
$this->saveToSearchLog($keywords, 0); // 0 - simple search, 1 - advanced search | $this->saveToSearchLog($keywords, 0); // 0 - simple search, 1 - advanced search | ||||
$keywords = strtr($keywords, Array('%' => '\\%', '_' => '\\_')); | $keywords = strtr($keywords, Array('%' => '\\%', '_' => '\\_')); | ||||
$event->setPseudoClass('_List'); | $event->setPseudoClass('_List'); | ||||
/** @var kDBList $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBList */ | |||||
$this->Application->SetVar($event->getPrefixSpecial().'_Page', 1); | $this->Application->SetVar($event->getPrefixSpecial().'_Page', 1); | ||||
$lang = $this->Application->GetVar('m_lang'); | $lang = $this->Application->GetVar('m_lang'); | ||||
$items_table = $this->Application->getUnitOption($event->Prefix, 'TableName'); | $items_table = $this->Application->getUnitOption($event->Prefix, 'TableName'); | ||||
$module_name = 'In-Portal'; | $module_name = 'In-Portal'; | ||||
$sql = 'SELECT * | $sql = 'SELECT * | ||||
FROM ' . $this->Application->getUnitOption('confs', 'TableName') . ' | FROM ' . $this->Application->getUnitOption('confs', 'TableName') . ' | ||||
▲ Show 20 Lines • Show All 296 Lines • ▼ Show 20 Line(s) | |||||
*/ | */ | ||||
protected function LoadItem(kEvent $event) | protected function LoadItem(kEvent $event) | ||||
{ | { | ||||
if ( !$this->_isVirtual($event) ) { | if ( !$this->_isVirtual($event) ) { | ||||
parent::LoadItem($event); | parent::LoadItem($event); | ||||
return; | return; | ||||
} | } | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$id = $this->getPassedID($event); | $id = $this->getPassedID($event); | ||||
if ( $object->isLoaded() && !is_array($id) && ($object->GetID() == $id) ) { | if ( $object->isLoaded() && !is_array($id) && ($object->GetID() == $id) ) { | ||||
// object is already loaded by same id | // object is already loaded by same id | ||||
return; | return; | ||||
} | } | ||||
if ( $object->Load($id, null, true) ) { | if ( $object->Load($id, null, true) ) { | ||||
/** @var Params $actions */ | |||||
$actions = $this->Application->recallObject('kActions'); | $actions = $this->Application->recallObject('kActions'); | ||||
/* @var $actions Params */ | |||||
$actions->Set($event->getPrefixSpecial() . '_id', $object->GetID()); | $actions->Set($event->getPrefixSpecial() . '_id', $object->GetID()); | ||||
} | } | ||||
else { | else { | ||||
$object->setID($id); | $object->setID($id); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Returns constrain for priority calculations | * Returns constrain for priority calculations | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @see PriorityEventHandler | * @see PriorityEventHandler | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnGetConstrainInfo(kEvent $event) | protected function OnGetConstrainInfo(kEvent $event) | ||||
{ | { | ||||
$constrain = ''; // for OnSave | $constrain = ''; // for OnSave | ||||
$event_name = $event->getEventParam('original_event'); | $event_name = $event->getEventParam('original_event'); | ||||
$actual_event_name = $event->getEventParam('actual_event'); | $actual_event_name = $event->getEventParam('actual_event'); | ||||
if ( $actual_event_name == 'OnSavePriorityChanges' || $event_name == 'OnAfterItemLoad' || $event_name == 'OnAfterItemDelete' ) { | if ( $actual_event_name == 'OnSavePriorityChanges' || $event_name == 'OnAfterItemLoad' || $event_name == 'OnAfterItemDelete' ) { | ||||
Line exceeds 120 characters; contains 140 characters Lint: Generic.Files.LineLength.TooLong: Line exceeds 120 characters; contains 140 characters | |||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$constrain = 'ParentId = ' . $object->GetDBField('ParentId'); | $constrain = 'ParentId = ' . $object->GetDBField('ParentId'); | ||||
} | } | ||||
elseif ( $actual_event_name == 'OnPreparePriorities' ) { | elseif ( $actual_event_name == 'OnPreparePriorities' ) { | ||||
$constrain = 'ParentId = ' . $this->Application->GetVar('m_cat_id'); | $constrain = 'ParentId = ' . $this->Application->GetVar('m_cat_id'); | ||||
} | } | ||||
elseif ( $event_name == 'OnSave' ) { | elseif ( $event_name == 'OnSave' ) { | ||||
$constrain = ''; | $constrain = ''; | ||||
Show All 39 Lines | |||||
* @param bool $keep_events | * @param bool $keep_events | ||||
* @return string | * @return string | ||||
*/ | */ | ||||
protected function _buildMainUrl($prefix_special, &$params, $keep_events) | protected function _buildMainUrl($prefix_special, &$params, $keep_events) | ||||
{ | { | ||||
$ret = ''; | $ret = ''; | ||||
list ($prefix) = explode('.', $prefix_special); | list ($prefix) = explode('.', $prefix_special); | ||||
/** @var kRewriteUrlProcessor $rewrite_processor */ | |||||
$rewrite_processor = $this->Application->recallObject('kRewriteUrlProcessor'); | $rewrite_processor = $this->Application->recallObject('kRewriteUrlProcessor'); | ||||
/* @var $rewrite_processor kRewriteUrlProcessor */ | |||||
$processed_params = $rewrite_processor->getProcessedParams($prefix_special, $params, $keep_events); | $processed_params = $rewrite_processor->getProcessedParams($prefix_special, $params, $keep_events); | ||||
if ($processed_params === false) { | if ($processed_params === false) { | ||||
return ''; | return ''; | ||||
} | } | ||||
// add language | // add language | ||||
if ($processed_params['m_lang'] && ($processed_params['m_lang'] != $rewrite_processor->primaryLanguageId)) { | if ($processed_params['m_lang'] && ($processed_params['m_lang'] != $rewrite_processor->primaryLanguageId)) { | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Line(s) | |||||
return false; | return false; | ||||
} | } | ||||
$sql = 'SELECT CategoryId, NamedParentPath | $sql = 'SELECT CategoryId, NamedParentPath | ||||
FROM ' . TABLE_PREFIX . 'Categories | FROM ' . TABLE_PREFIX . 'Categories | ||||
WHERE FriendlyURL = ' . $this->Conn->qstr(implode('/', $url_parts)); | WHERE FriendlyURL = ' . $this->Conn->qstr(implode('/', $url_parts)); | ||||
$friendly = $this->Conn->GetRow($sql); | $friendly = $this->Conn->GetRow($sql); | ||||
/** @var kRewriteUrlProcessor $rewrite_processor */ | |||||
$rewrite_processor = $this->Application->recallObject('kRewriteUrlProcessor'); | $rewrite_processor = $this->Application->recallObject('kRewriteUrlProcessor'); | ||||
/* @var $rewrite_processor kRewriteUrlProcessor */ | |||||
if ($friendly) { | if ($friendly) { | ||||
$vars['m_cat_id'] = $friendly['CategoryId']; | $vars['m_cat_id'] = $friendly['CategoryId']; | ||||
$vars['t'] = preg_replace('/^Content\//i', '', $friendly['NamedParentPath']); | $vars['t'] = preg_replace('/^Content\//i', '', $friendly['NamedParentPath']); | ||||
while ($url_parts) { | while ($url_parts) { | ||||
$rewrite_processor->partParsed( array_shift($url_parts) ); | $rewrite_processor->partParsed( array_shift($url_parts) ); | ||||
} | } | ||||
Show All 19 Lines | |||||
$res = false; | $res = false; | ||||
$url_part = array_shift($url_parts); | $url_part = array_shift($url_parts); | ||||
$category_id = 0; | $category_id = 0; | ||||
$last_category_info = false; | $last_category_info = false; | ||||
$category_path = $url_part == 'content' ? '' : 'content'; | $category_path = $url_part == 'content' ? '' : 'content'; | ||||
/** @var kRewriteUrlProcessor $rewrite_processor */ | |||||
$rewrite_processor = $this->Application->recallObject('kRewriteUrlProcessor'); | $rewrite_processor = $this->Application->recallObject('kRewriteUrlProcessor'); | ||||
/* @var $rewrite_processor kRewriteUrlProcessor */ | |||||
do { | do { | ||||
$category_path = trim($category_path . '/' . $url_part, '/'); | $category_path = trim($category_path . '/' . $url_part, '/'); | ||||
// bb_<topic_id> -> forums/bb_2 | // bb_<topic_id> -> forums/bb_2 | ||||
if ( !preg_match('/^bb_[\d]+$/', $url_part) && preg_match('/(.*)_([\d]+)$/', $category_path, $rets) ) { | if ( !preg_match('/^bb_[\d]+$/', $url_part) && preg_match('/(.*)_([\d]+)$/', $category_path, $rets) ) { | ||||
$category_path = $rets[1]; | $category_path = $rets[1]; | ||||
$vars['m_cat_page'] = $rets[2]; | $vars['m_cat_page'] = $rets[2]; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
* Set's new unique resource id to user | * Set's new unique resource id to user | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnAfterItemValidate(kEvent $event) | protected function OnAfterItemValidate(kEvent $event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$resource_id = $object->GetDBField('ResourceId'); | $resource_id = $object->GetDBField('ResourceId'); | ||||
if ( !$resource_id ) { | if ( !$resource_id ) { | ||||
$object->SetDBField('ResourceId', $this->Application->NextResourceId()); | $object->SetDBField('ResourceId', $this->Application->NextResourceId()); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Occurs before an item has been cloned | * Occurs before an item has been cloned | ||||
* Id of newly created item is passed as event' 'id' param | * Id of newly created item is passed as event' 'id' param | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnBeforeClone(kEvent $event) | protected function OnBeforeClone(kEvent $event) | ||||
{ | { | ||||
parent::OnBeforeClone($event); | parent::OnBeforeClone($event); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$object->SetDBField('ResourceId', 0); // this will reset it | $object->SetDBField('ResourceId', 0); // this will reset it | ||||
} | } | ||||
} | } |
Inline comments must end in full-stops, exclamation marks, or question marks