Index: branches/RC/core/units/general/helpers/mod_rewrite_helper.php =================================================================== diff -u -N -r11504 -r11520 --- branches/RC/core/units/general/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 11504) +++ branches/RC/core/units/general/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 11520) @@ -70,36 +70,66 @@ function ProcessCategory(&$url_parts, &$vars) { - if (!isset($url_parts[0])) return false; + if (!isset($url_parts[0])) { + return false; + } + $res = false; $url_part = array_shift($url_parts); $category_id = 0; - $last_category_id = 0; - $category_path = ''; + $last_category_info = false; + $category_path = $url_part == 'content' ? '' : 'content'; + do { - $category_path = trim($category_path.'/'.$url_part, '/'); + $category_path = trim($category_path . '/' . $url_part, '/'); // bb__ -> forums/bb__2 OR forums/bb_2_6 if( !preg_match('/^bb_([\d]+)*_[\d]+/', $url_part) && preg_match('/(.*)_([\d]+)$/', $category_path, $rets) ) { $category_path = $rets[1]; $vars['m_cat_page'] = $rets[2]; } - $sql = 'SELECT CategoryId - FROM '.TABLE_PREFIX.'Category - WHERE Status = 1 AND NamedParentPath = '.$this->Conn->qstr($category_path); - $category_id = $this->Conn->GetOne($sql); - if ($category_id !== false) { - $last_category_id = $category_id; + $sql = 'SELECT CategoryId, IsIndex, NamedParentPath + FROM ' . TABLE_PREFIX . 'Category + WHERE Status IN (1,4) AND (LOWER(NamedParentPath) = ' . $this->Conn->qstr($category_path) . ')'; + $category_info = $this->Conn->GetRow($sql); + + if ($category_info !== false) { + $last_category_info = $category_info; $url_part = array_shift($url_parts); $res = true; } - } while ($category_id !== false && $url_part); - $vars['m_cat_id'] = $last_category_id; + } while ($category_info !== false && $url_part); + if ($last_category_info) { + // IsIndex = 2 is a Container-only page, meaning it should go to index-page child + if ($last_category_info['IsIndex'] == 2) { + $sql = 'SELECT CategoryId, NamedParentPath + FROM ' . TABLE_PREFIX . 'Category + WHERE ParentId = ' . $last_category_info['CategoryId'] . ' AND IsIndex = 1'; + $category_info = $this->Conn->GetRow($sql); + + if ($category_info) { + // when index sub-page is found use it, otherwise use container page + $last_category_info = $category_info; + } + } + + // 1. Set virtual page as template, this will be replaced to physical template later in kApplication::Run. + // 2. Don't set CachedTemplate field as template here, because we will loose original page associated with it's cms blocks! + $vars['t'] = strtolower( preg_replace('/^Content\//i', '', $last_category_info['NamedParentPath']) ); + + $vars['m_cat_id'] = $last_category_info['CategoryId']; + $vars['is_virtual'] = true; // for template from POST + } + else { + $vars['m_cat_id'] = 0; + } + if ($url_part) { array_unshift($url_parts, $url_part); } + return $res; } @@ -151,31 +181,14 @@ $this->ProcessPage($url_parts, $vars); } - // try to find CMS index page of the category - if ($this->Application->isModuleEnabled('In-CMS')) { - $sql = 'SELECT p.Path, ci.CategoryId FROM '.TABLE_PREFIX.'Pages AS p - LEFT JOIN '.TABLE_PREFIX.'CategoryItems AS ci - ON ci.ItemResourceId = p.ResourceId - WHERE - p.IsIndex = 1 - AND - p.Status = 1 - AND - CategoryId = '.$vars['m_cat_id'].' - AND - ci.PrimaryCat = 1'; - $template_found = $this->Conn->GetRow($sql); - if ($template_found !== false) { - $vars['t'] = $template_found['Path']; - return true; - } - } + /*$sql = 'SELECT CachedTemplate + FROM ' . TABLE_PREFIX . 'Category + WHERE CategoryId = ' . $vars['m_cat_id']; + $vars['t'] = $this->Conn->GetOne($sql);*/ - $sql = 'SELECT CachedTemplate - FROM '.TABLE_PREFIX.'Category - WHERE CategoryId = '.$vars['m_cat_id']; - $vars['t'] = $this->Conn->GetOne($sql); - if (!$vars['t']) $vars['t'] = 'index'; + if (!$vars['t']) { + $vars['t'] = 'index'; + } return true; } @@ -338,7 +351,7 @@ * @param array $url_parts * @return boolean */ - function ProcessVirtualTemplate(&$url_parts, &$vars) + function ProcessFriendlyUrl(&$url_parts, &$vars) { if (!isset($url_parts[0])) return false; @@ -349,38 +362,10 @@ $friendly = $this->Conn->GetRow($sql); if ($friendly) { $vars['m_cat_id'] = $friendly['CategoryId']; - $vars['t'] = preg_replace('/^content\//i', '', $friendly['NamedParentPath']); + $vars['t'] = preg_replace('/^Content\//i', '', $friendly['NamedParentPath']); return true; } - $template_path = 'content/' . implode('/', $url_parts); - - $sql = 'SELECT CategoryId, IsIndex, NamedParentPath FROM '.TABLE_PREFIX.'Category - WHERE - LOWER(NamedParentPath) = '.$this->Conn->qstr($template_path).' - AND - Status IN (1,4) '; - $template_found = $this->Conn->GetRow($sql); - - if ($template_found) { - // IsIndex = 2 is a Container-only page, meaning it should go to index-page child - if ($template_found['IsIndex'] == 2) { - $sql = 'SELECT CategoryId, NamedParentPath - FROM ' . TABLE_PREFIX . 'Category - WHERE ParentId = '.$template_found['CategoryId'].' AND IsIndex = 1'; - $template_found = $this->Conn->GetRow($sql); - $vars['t'] = preg_replace('/^content\//i', '', $template_found['NamedParentPath']); - } - else { - $vars['t'] = implode('/', $url_parts); - } - - $vars['m_cat_id'] = $template_found['CategoryId']; - $vars['is_virtual'] = true; // for template from POST - - return true; - } - return false; } @@ -467,7 +452,7 @@ // bug #1: cancells all other processing in case, when cms page is found // bug #2: doesn't match template partially, e.g. "test/case/other" will not match to page "test/case" with "other" left for future processing - if ( $this->ProcessVirtualTemplate($url_parts, $vars) ) { + if ( $this->ProcessFriendlyUrl($url_parts, $vars) ) { return $vars; } @@ -536,15 +521,15 @@ return $vars; } - if ( $this->Application->isModuleEnabled('In-Edit') && $this->Application->GetVar('admin') == 1) { + /*if ( $this->Application->isModuleEnabled('In-Edit') && $this->Application->GetVar('admin') == 1) { $adm_ses =& $this->Application->recallObject('Session.admin'); $user = $adm_ses->RecallVar('user_id'); $perm_helper =& $this->Application->recallObject('PermissionsHelper'); if ($perm_helper->CheckUserPermission($user, 'PAGE.ADD', 0)) { $vars['t'] = implode('/', $url_parts); return $vars; } - } + }*/ $not_found = $this->Application->ConfigValue('ErrorTemplate'); $vars['t'] = $not_found ? $not_found : 'error_notfound';