Index: branches/5.2.x/core/units/helpers/mod_rewrite_helper.php =================================================================== diff -u -N -r15293 -r15862 --- branches/5.2.x/core/units/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 15293) +++ branches/5.2.x/core/units/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 15862) @@ -1,6 +1,6 @@ _buildCategoryItemUrl($prefix, $params, $keep_events); } - if (!$parsed) { + $module_prefix = $this->_parseCategoryItemUrl($url_parts, $params, $prefix); + + if ($module_prefix !== false) { $rewrite_processor = $this->Application->recallObject('kRewriteUrlProcessor'); /* @var $rewrite_processor kRewriteUrlProcessor */ - $module_prefix = $this->_parseCategoryItemUrl($url_parts, $params); - - if ($module_prefix !== false) { - $params['pass'][] = $module_prefix; - $rewrite_processor->modulePrefix = $module_prefix; - } - - $parsed = true; + $params['pass'][] = $module_prefix; + $rewrite_processor->setModulePrefix($module_prefix); } return true; @@ -236,10 +230,12 @@ * * @param Array $url_parts * @param Array $vars - * @return bool|string + * @param string $prefix Prefix, that listener uses for system integration + * + * @return boolean|string * @access protected */ - protected function _parseCategoryItemUrl(&$url_parts, &$vars) + protected function _parseCategoryItemUrl(&$url_parts, &$vars, $prefix) { if ( !$url_parts ) { return false; @@ -254,20 +250,15 @@ $rewrite_processor = $this->Application->recallObject('kRewriteUrlProcessor'); /* @var $rewrite_processor kRewriteUrlProcessor */ - if ( preg_match('/^bb_([\d]+)/', $item_filename, $regs) ) { + if ( $prefix == 'bb' && preg_match('/^bb_([\d]+)/', $item_filename, $regs) ) { // process topics separately, because they don't use item filenames array_pop($url_parts); $rewrite_processor->partParsed($item_filename, 'rtl'); return $this->_parseTopicUrl($regs[1], $vars); } - // locating the item in CategoryItems by filename to detect its ItemPrefix and its category ParentPath - $sql = 'SELECT ci.ItemResourceId, ci.ItemPrefix, c.ParentPath, ci.CategoryId - FROM ' . TABLE_PREFIX . 'CategoryItems AS ci - LEFT JOIN ' . TABLE_PREFIX . 'Categories AS c ON c.CategoryId = ci.CategoryId - WHERE (ci.CategoryId = ' . (int)$vars['m_cat_id'] . ') AND (ci.Filename = ' . $this->Conn->qstr($item_filename) . ')'; - $cat_item = $this->Conn->GetRow($sql); + $cat_item = $this->findCategoryItem((int)$vars['m_cat_id'], $item_filename, $prefix); if ( $cat_item !== false ) { // item found @@ -302,6 +293,34 @@ } /** + * Locating the item in CategoryItems by filename to detect its ItemPrefix and its category ParentPath. + * + * @param integer $category_id Category. + * @param string $filename Filename. + * @param string $prefix Prefix, that listener uses for system integration + * + * @return string + */ + protected function findCategoryItem($category_id, $filename, $prefix) + { + static $cache = array(); + + $cache_key = $category_id . ':' . $filename; + + if ( !isset($cache[$cache_key]) ) { + $sql = 'SELECT ci.ItemResourceId, ci.ItemPrefix, c.ParentPath, ci.CategoryId + FROM ' . TABLE_PREFIX . 'CategoryItems AS ci + LEFT JOIN ' . TABLE_PREFIX . 'Categories AS c ON c.CategoryId = ci.CategoryId + WHERE (ci.CategoryId = ' . $category_id . ') AND (ci.Filename = ' . $this->Conn->qstr($filename) . ')'; + $cache[$cache_key] = $this->Conn->GetRow($sql); + } + + $category_item = $cache[$cache_key]; + + return $category_item && $category_item['ItemPrefix'] == $prefix ? $category_item : false; + } + + /** * Set's template and topic id corresponding to topic given in url * * @param int $topic_id