Index: branches/5.2.x/core/kernel/managers/rewrite_url_processor.php =================================================================== diff -u -N -r15716 -r15717 --- branches/5.2.x/core/kernel/managers/rewrite_url_processor.php (.../rewrite_url_processor.php) (revision 15716) +++ branches/5.2.x/core/kernel/managers/rewrite_url_processor.php (.../rewrite_url_processor.php) (revision 15717) @@ -1,6 +1,6 @@ _isTemplateAllowed($template_found, $vars['m_cat_id']) ) { $template_parts = explode('/', $template_path); $vars['t'] = $template_path . ($index_added ? '/index' : ''); @@ -711,6 +711,76 @@ } /** + * Determines if found template can be used in combination with found category + * + * @param int $file_id + * @param int $category_id + * @return bool + * @access protected + */ + protected function _isTemplateAllowed($file_id, $category_id) + { + if ( $this->_isSectionAwareTemplate($file_id) ) { + // template accepts any category from url + return true; + } + + $allowed_categories = Array (0, $this->Application->getBaseCategory()); + + $sql = 'SELECT t.ThemeId, CONCAT(tf.FilePath, "/", tf.FileName) AS Path + FROM ' . TABLE_PREFIX . 'Themes t + JOIN ' . TABLE_PREFIX . 'ThemeFiles tf ON tf.ThemeId = t.ThemeId + WHERE tf.FileId = ' . $file_id; + $template_info = $this->Conn->GetRow($sql); + + if ( $template_info ) { + // this template isn't added to ".smsignore" + $template = preg_replace('/^[\\/]{0,1}(.*)\.tpl$/', "$1", $template_info['Path']); + + $where_clause = Array ( + 'Template = ' . $this->Conn->qstr($template), + 'ThemeId = ' . $template_info['ThemeId'], + '`Type` = ' . PAGE_TYPE_TEMPLATE, + ); + + $sql = 'SELECT CategoryId + FROM ' . TABLE_PREFIX . 'Categories + WHERE (' . implode(') AND (', $where_clause) . ')'; + $template_category_id = $this->Conn->GetOne($sql); + + if ( $template_category_id ) { + // category found for this template + $allowed_categories[] = $template_category_id; + } + } + + return in_array($category_id, $allowed_categories); + } + + /** + * Determines, that template by given $file_id is in fact section agnostic template + * + * @param int $file_id + * @return bool + * @access protected + */ + protected function _isSectionAwareTemplate($file_id) + { + $sql = 'SELECT FileMetaInfo + FROM ' . TABLE_PREFIX . 'ThemeFiles + WHERE FileId = ' . $file_id; + $meta_info = $this->Conn->GetOne($sql); + + if ( $meta_info ) { + $meta_info = unserialize($meta_info); + + return isset($meta_info['section_aware']); + } + + return false; + } + + /** * Returns environment variable values for given prefix (uses directly given params, when available) * * @param string $prefix_special