Index: branches/5.1.x/core/units/helpers/mod_rewrite_helper.php =================================================================== diff -u -N -r14241 -r14342 --- branches/5.1.x/core/units/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 14241) +++ branches/5.1.x/core/units/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 14342) @@ -1,6 +1,6 @@ Array ('m')); $url_parts = $url ? explode('/', trim(mb_strtolower($url, 'UTF-8'), '/')) : Array (); - if (($this->HTTPQuery->Get('rewrite') == 'on') || !$url_parts) { + $this->_partsToParse = $url_parts; + + if ( ($this->HTTPQuery->Get('rewrite') == 'on') || !$url_parts ) { $this->_setDefaultValues($vars); } - if (!$url_parts) { + if ( !$url_parts ) { $this->InitAll(); $vars['t'] = $this->HTTPQuery->getDefaultTemplate(''); @@ -256,21 +258,15 @@ return $vars; } - if ($this->_parsePhisycalTemplate($url_parts, $vars)) { - $this->_partsFound[] = 'parsePhisycalTemplate'; - } + $this->_parsePhisycalTemplate($url_parts, $vars); - if (($this->_modulePrefix === false) && in_array('parseCategory', $this->_partsFound)) { - // no item found, but category found -> module index page - /*foreach ($this->Application->RewriteListeners as $prefix => $listener) { - // no idea what module we are talking about, so pass info form all modules - $vars['pass'][] = $prefix; - }*/ + if ( ($this->_modulePrefix === false) && $vars['m_cat_id'] && !$this->_partsToParse ) { + // no category item found, but category found and all url matched -> module index page return $vars; } - if (!$this->_partsFound) { + if ( $this->_partsToParse ) { $not_found = $this->Application->ConfigValue('ErrorTemplate'); $vars['t'] = $not_found ? $not_found : 'error_notfound'; @@ -302,13 +298,8 @@ function processRewriteListeners(&$url_parts, &$vars) { $this->initRewriteListeners(); - $page_number = $this->_parsePage($url_parts, $vars); - if ($page_number) { - $this->_partsFound[] = 'parsePage'; - } - foreach ($this->Application->RewriteListeners as $prefix => $listeners) { // set default page // $vars[$prefix . '_Page'] = 1; // will override page in session in case, when none is given in url @@ -370,6 +361,12 @@ if ($template_found) { $vars['t'] = $template_path; + $template_parts = explode('/', $template_path); + + while ( $template_parts ) { + $this->partParsed( array_pop($template_parts), 'rtl' ); + } + // 1. will damage actual category during category item review add process // 2. will use "use_section" parameter of "m_Link" tag to gain same effect // $themes_helper =& $this->Application->recallObject('ThemesHelper'); @@ -404,9 +401,7 @@ return false; } - if ($this->_parseCategory($url_parts, $params)) { - $this->_partsFound[] = 'parseCategory'; - } + $this->_parseCategory($url_parts, $params); return true; } @@ -561,6 +556,7 @@ if ($language_info['SortKey'] == 2) { // language was found by pack name array_shift($url_parts); + $this->partParsed($url_part); } elseif ($this->primaryLanguageId) { // use domain-based primary language instead of site-wide primary language @@ -609,6 +605,7 @@ if ($theme_info['SortKey'] == 2) { // theme was found by name array_shift($url_parts); + $this->partParsed($url_part); } elseif ($this->primaryThemeId) { // use domain-based primary theme instead of site-wide primary theme @@ -638,11 +635,16 @@ $sql = 'SELECT CategoryId, NamedParentPath FROM ' . TABLE_PREFIX . 'Category WHERE FriendlyURL = ' . $this->Conn->qstr(implode('/', $url_parts)); - $friendly = $this->Conn->GetRow($sql); + if ($friendly) { $vars['m_cat_id'] = $friendly['CategoryId']; $vars['t'] = preg_replace('/^Content\//i', '', $friendly['NamedParentPath']); + + while ($url_parts) { + $this->partParsed( array_shift($url_parts) ); + } + return true; } @@ -670,6 +672,7 @@ } array_pop($url_parts); + $this->partParsed($page_number, 'rtl'); return $page_number; } @@ -721,6 +724,8 @@ if ($category_info !== false) { $last_category_info = $category_info; + $this->partParsed($url_part); + $url_part = array_shift($url_parts); $res = true; } @@ -776,9 +781,9 @@ if (!$parsed) { $this->_modulePrefix = $this->_parseCategoryItemUrl($url_parts, $params); + if ($this->_modulePrefix !== false) { $params['pass'][] = $this->_modulePrefix; - $this->_partsFound[] = 'parseCategoryItemUrl'; } $parsed = true; @@ -879,6 +884,7 @@ if (preg_match('/^bb_([\d]+)/', $item_filename, $regs)) { // process topics separatly, because they don't use item filenames array_pop($url_parts); + $this->partParsed($item_filename, 'rtl'); return $this->_parseTopicUrl($regs[1], $vars); } @@ -906,6 +912,8 @@ array_pop($url_parts); if ($item_id) { + $this->partParsed($item_filename, 'rtl'); + if ($item_template) { // when template is found in category -> set it $vars['t'] = $item_template; @@ -1142,4 +1150,36 @@ } } } + + /** + * Marks url part as parsed + * + * @param string $url_part + * @param string $parse_direction + */ + function partParsed($url_part, $parse_direction = 'ltr') + { + if ( !$this->_partsToParse ) { + return ; + } + + if ( $parse_direction == 'ltr' ) { + $expected_url_part = reset($this->_partsToParse); + + if ( $url_part == $expected_url_part ) { + array_shift($this->_partsToParse); + } + } + else { + $expected_url_part = end($this->_partsToParse); + + if ( $url_part == $expected_url_part ) { + array_pop($this->_partsToParse); + } + } + + if ( $url_part != $expected_url_part ) { + trigger_error('partParsed: expected URL part "' . $expected_url_part . '", received URL part "' . $url_part . '"', E_USER_NOTICE); + } + } }