Index: branches/5.2.x/core/units/helpers/mod_rewrite_helper.php
===================================================================
diff -u -r14473 -r14585
--- branches/5.2.x/core/units/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 14473)
+++ branches/5.2.x/core/units/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 14585)
@@ -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';
@@ -306,13 +302,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
@@ -374,6 +365,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');
@@ -408,9 +405,7 @@
return false;
}
- if ($this->_parseCategory($url_parts, $params)) {
- $this->_partsFound[] = 'parseCategory';
- }
+ $this->_parseCategory($url_parts, $params);
return true;
}
@@ -523,9 +518,9 @@
$template = 'index';
}
- // remove template from url if it is category index cached template
- if (($template == $category_template) || (mb_strtolower($template) == '__default__')) {
- // given template is also default template for this category or '__default__' given
+ // remove template from url if it is category index cached template OR site homepage
+ if (($template == $category_template) || (mb_strtolower($template) == '__default__') || ($template == 'index')) {
+ // given template is also default template for this category OR '__default__' given OR site homepage
$params['pass_template'] = false;
}
@@ -565,6 +560,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
@@ -613,6 +609,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
@@ -642,11 +639,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;
}
@@ -674,6 +676,7 @@
}
array_pop($url_parts);
+ $this->partParsed($page_number, 'rtl');
return $page_number;
}
@@ -725,6 +728,8 @@
if ($category_info !== false) {
$last_category_info = $category_info;
+ $this->partParsed($url_part);
+
$url_part = array_shift($url_parts);
$res = true;
}
@@ -780,9 +785,9 @@
if (!$parsed) {
$this->_modulePrefix = $this->_parseCategoryItemUrl($url_parts, $params);
+
if ($this->_modulePrefix !== false) {
$params['pass'][] = $this->_modulePrefix;
- $this->_partsFound[] = 'parseCategoryItemUrl';
}
$parsed = true;
@@ -925,6 +930,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);
}
@@ -952,6 +958,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;
@@ -1188,4 +1196,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);
+ }
+ }
}