Index: core/units/helpers/mod_rewrite_helper.php IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- core/units/helpers/mod_rewrite_helper.php (revision 15805) +++ core/units/helpers/mod_rewrite_helper.php (revision ) @@ -29,26 +29,20 @@ */ public function RewriteListener($rewrite_mode = REWRITE_MODE_BUILD, $prefix, &$params, &$url_parts, $keep_events = false) { - static $parsed = false; - if ($rewrite_mode == REWRITE_MODE_BUILD) { return $this->_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; + $params['pass'][] = $module_prefix; - $rewrite_processor->modulePrefix = $module_prefix; + $rewrite_processor->setModulePrefix($module_prefix); - } + } - $parsed = true; - } - 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,7 +250,7 @@ $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'); @@ -262,12 +258,7 @@ 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 @@ -299,6 +290,34 @@ } return false; + } + + /** + * 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; } /** Index: core/kernel/managers/rewrite_url_processor.php IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- core/kernel/managers/rewrite_url_processor.php (revision 15856) +++ core/kernel/managers/rewrite_url_processor.php (revision ) @@ -35,10 +35,10 @@ /** * Category item prefix, that was found * - * @var string|bool - * @access public + * @var string|boolean + * @access protected */ - public $modulePrefix = false; + protected $modulePrefix = false; /** * Template aliases for current theme @@ -112,6 +112,18 @@ } /** + * Sets module prefix. + * + * @param string $prefix Unit config prefix. + * + * @return void + */ + public function setModulePrefix($prefix) + { + $this->modulePrefix = $prefix; + } + + /** * Parses url * * @return void @@ -399,6 +411,7 @@ $url_parts = $string ? explode('/', mb_strtolower($string)) : Array (); + $this->setModulePrefix(false); $this->_partsToParse = $url_parts; if ( ($this->HTTPQuery->Get('rewrite') == 'on') || !$url_parts ) { \ No newline at end of file