Index: branches/5.0.x/core/units/categories/categories_event_handler.php =================================================================== diff -u -N -r12809 -r12877 --- branches/5.0.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 12809) +++ branches/5.0.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 12877) @@ -1,6 +1,6 @@ Name == 'OnResetCMSMenuCache') { + // events from "Tools -> System Tools" section are controlled via that section "edit" permission + + $perm_helper =& $this->Application->recallObject('PermissionsHelper'); + /* @var $perm_helper kPermissionsHelper */ + + $perm_value = $this->Application->CheckPermission('in-portal:service.edit'); + + return $perm_helper->finalizePermissionCheck($event, $perm_value); + } + if (!$this->Application->isAdmin) { if ($event->Name == 'OnSetSortingDirect') { // allow sorting on front event without view permission @@ -471,6 +482,7 @@ $type_clauses['menu']['include'] = '%1$s.IsMenu = 1'; $type_clauses['menu']['except'] = '%1$s.IsMenu = 0'; + $type_clauses['menu']['having_filter'] = false; if (in_array('search', $types) || in_array('search', $except_types)) { $event_mapping = Array ( @@ -602,7 +614,7 @@ $updater->OneStepRun(); } - $event->CallSubEvent('OnResetMenuCache'); + $this->_resetMenuCache(); $this->Application->RemoveVar('PermCache_UpdateRequired'); @@ -799,7 +811,7 @@ } $this->Application->StoreVar('RefreshStructureTree', 1); - $event->CallSubEvent('OnResetMenuCache'); + $this->_resetMenuCache(); if ($is_editing) { // 2. send email event to category owner, when it's status is changed (from admin) @@ -1017,7 +1029,7 @@ $priority_helper->recalculatePriorities($event, 'ParentId = ' . $parent_id); $this->Application->StoreVar('RefreshStructureTree', 1); - $event->CallSubEvent('OnResetMenuCache'); + $this->_resetMenuCache(); } /** @@ -1139,7 +1151,6 @@ $priority_helper =& $this->Application->recallObject('PriorityHelper'); /* @var $priority_helper kPriorityHelper */ - if ($clipboard_data['cut']) { $priority_helper->recalculatePriorities($event, 'ParentId = '.$source_category_id); } @@ -1160,7 +1171,7 @@ $event->redirect = 'categories/cache_updater'; } - $event->CallSubEvent('OnResetMenuCache'); + $this->_resetMenuCache(); $this->Application->StoreVar('RefreshStructureTree', 1); } } @@ -1780,11 +1791,68 @@ * * @param kEvent $event */ - function OnResetMenuCache(&$event) + function OnResetCMSMenuCache(&$event) { - $this->Conn->Query('DELETE FROM '.TABLE_PREFIX.'Cache WHERE VarName IN ("cms_menu", "StructureTree")'); + if ($this->Application->GetVar('ajax') == 'yes') { + $event->status = erSTOP; + } + + $this->_resetMenuCache(); } + function _resetMenuCache() + { + // reset cms menu cache + $sql = 'DELETE FROM ' . TABLE_PREFIX . 'Cache + WHERE VarName IN ("cms_menu", "StructureTree")'; + $this->Conn->Query($sql); + + // build structure template mapping + $sql = 'SELECT + IF(c.IsSystem, CONCAT(c.Template, ":", c.ThemeId), CONCAT("id:", c.CategoryId)) AS SrcTemplate, + LOWER( + IF( + c.SymLinkCategoryId IS NOT NULL, + (SELECT cc.NamedParentPath FROM ' . TABLE_PREFIX . 'Category AS cc WHERE cc.CategoryId = c.SymLinkCategoryId), + c.NamedParentPath + ) + ) AS DstTemplate, + c.UseExternalUrl, c.ExternalUrl + FROM ' . TABLE_PREFIX . 'Category AS c + WHERE c.Status = ' . STATUS_ACTIVE; + $pages = $this->Conn->Query($sql, 'SrcTemplate'); + + $mapping = Array (); + $base_url = $this->Application->BaseURL(); + + foreach ($pages as $src_template => $page) { + // process external url, before placing in cache + if ($page['UseExternalUrl']) { + $external_url = $page['ExternalUrl']; + + if (!preg_match('/^(.*?):\/\/(.*)$/', $external_url)) { + // url without protocol will be relative url to our site + $external_url = $base_url . $external_url; + } + + $dst_template = 'external:' . $external_url; + } + else { + $dst_template = preg_replace('/^Content\//i', '', $page['DstTemplate']); + } + + $mapping[$src_template] = $dst_template; + } + + $fields_hash = Array ( + 'VarName' => 'template_mapping', + 'Data' => serialize($mapping), + 'Cached' => adodb_mktime(), + ); + + $this->Conn->doInsert($fields_hash, TABLE_PREFIX . 'Cache', 'REPLACE'); + } + /** * Updates structure config * @@ -1974,7 +2042,7 @@ $updater->OneStepRun(); } - $event->CallSubEvent('OnResetMenuCache'); + $this->_resetMenuCache(); if ($error_count) { // allow user to review error after structure page creation @@ -2023,7 +2091,7 @@ $this->clearSelectedIDs($event); $this->Application->StoreVar('RefreshStructureTree', 1); - $event->CallSubEvent('OnResetMenuCache'); + $this->_resetMenuCache(); } /** @@ -2038,7 +2106,7 @@ $parent_id = $this->Application->GetVar('m_cat_id'); $priority_helper->recalculatePriorities($event, 'ParentId = ' . $parent_id); - $event->CallSubEvent('OnResetMenuCache'); + $this->_resetMenuCache(); } /**