Index: branches/5.0.x/core/units/helpers/mod_rewrite_helper.php =================================================================== diff -u -r12511 -r12634 --- branches/5.0.x/core/units/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 12511) +++ branches/5.0.x/core/units/helpers/mod_rewrite_helper.php (.../mod_rewrite_helper.php) (revision 12634) @@ -1,6 +1,6 @@ Array ('m')); - $url_parts = $url ? explode('/', trim($url, '/')) : Array (); + $url_parts = $url ? explode('/', trim(mb_strtolower($url), '/')) : Array (); if (($this->HTTPQuery->Get('rewrite') == 'on') || !$url_parts) { $this->_setDefaultValues($vars); @@ -175,7 +175,7 @@ $themes_helper =& $this->Application->recallObject('ThemesHelper'); /* @var $themes_helper kThemesHelper */ - $vars['m_cat_id'] = $themes_helper->getPageByTemplate($vars['t']); + $vars['m_cat_id'] = $themes_helper->getPageByTemplate($vars['t'], $vars['m_theme']); header('HTTP/1.0 404 Not Found'); } @@ -234,7 +234,7 @@ $sql = 'SELECT FileId FROM ' . TABLE_PREFIX . 'ThemeFiles - WHERE (FilePath = ' . $this->Conn->qstr($t_parts['path']) . ') AND (FileName = ' . $this->Conn->qstr($t_parts['file'] . '.tpl') . ')'; + WHERE (ThemeId = ' . $vars['m_theme'] . ') AND (FilePath = ' . $this->Conn->qstr($t_parts['path']) . ') AND (FileName = ' . $this->Conn->qstr($t_parts['file'] . '.tpl') . ')'; $template_found = $this->Conn->GetOne($sql); if (!$template_found) { @@ -244,6 +244,12 @@ if ($template_found) { $vars['t'] = $template_path; + + $themes_helper =& $this->Application->recallObject('ThemesHelper'); + /* @var $themes_helper kThemesHelper */ + + $vars['m_cat_id'] = $themes_helper->getPageByTemplate($template_path, $vars['m_theme']); + return true; } @@ -404,21 +410,28 @@ return false; } - $url_part = array_shift($url_parts); + $url_part = reset($url_parts); - $sql = 'SELECT LanguageId + $sql = 'SELECT LanguageId, IF(LOWER(PackName) = ' . $this->Conn->qstr($url_part) . ', 2, PrimaryLang) AS SortKey FROM ' . TABLE_PREFIX . 'Language - WHERE LOWER(PackName) = ' . $this->Conn->qstr($url_part) . ' AND Enabled = 1'; - $language_id = $this->Conn->GetOne($sql); - + WHERE Enabled = 1 + ORDER BY SortKey DESC'; + $language_info = $this->Conn->GetRow($sql); $this->Application->Phrases = new PhrasesCache(); - if ($language_id) { - $vars['m_lang'] = $language_id; + + if ($language_info && $language_info['LanguageId'] && $language_info['SortKey']) { + // primary language will be selected in case, when $url_part doesn't match to other's language pack name + // don't use next enabled language, when primary language is disabled + $vars['m_lang'] = $language_info['LanguageId']; + + if ($language_info['SortKey'] == 2) { + // language was found by pack name + array_shift($url_parts); + } + return true; } - array_unshift($url_parts, $url_part); - return false; } @@ -435,18 +448,28 @@ return false; } - $url_part = array_shift($url_parts); + $url_part = reset($url_parts); - $sql = 'SELECT ThemeId + $sql = 'SELECT ThemeId, IF(LOWER(Name) = ' . $this->Conn->qstr($url_part) . ', 2, PrimaryTheme) AS SortKey FROM ' . TABLE_PREFIX . 'Theme - WHERE LOWER(Name) = ' . $this->Conn->qstr($url_part) . ' AND Enabled = 1'; - $theme_id = $this->Conn->GetOne($sql); - if ($theme_id) { - $vars['m_theme'] = $theme_id; + WHERE Enabled = 1 + ORDER BY SortKey DESC'; + $theme_info = $this->Conn->GetRow($sql); + + if ($theme_info && $theme_info['ThemeId'] && $theme_info['SortKey']) { + // primary theme will be selected in case, when $url_part doesn't match to other's theme name + // don't use next enabled theme, when primary theme is disabled + $vars['m_theme'] = $theme_info['ThemeId']; + + if ($theme_info['SortKey'] == 2) { + // theme was found by name + array_shift($url_parts); + } + return true; } - array_unshift($url_parts, $url_part); + $vars['m_theme'] = 0; // required, because used later for category/template detection return false; } @@ -563,7 +586,7 @@ $sql = 'SELECT CategoryId, IsIndex, NamedParentPath FROM ' . TABLE_PREFIX . 'Category - WHERE Status IN (1,4) AND (LOWER(NamedParentPath) = ' . $this->Conn->qstr($category_path) . ')'; + WHERE Status IN (1,4) AND (LOWER(NamedParentPath) = ' . $this->Conn->qstr($category_path) . ') AND (ThemeId = ' . $vars['m_theme'] . ' OR ThemeId = 0)'; $category_info = $this->Conn->GetRow($sql); if ($category_info !== false) { @@ -578,7 +601,7 @@ if ($last_category_info['IsIndex'] == 2) { $sql = 'SELECT CategoryId, NamedParentPath FROM ' . TABLE_PREFIX . 'Category - WHERE ParentId = ' . $last_category_info['CategoryId'] . ' AND IsIndex = 1'; + WHERE (ParentId = ' . $last_category_info['CategoryId'] . ') AND (IsIndex = 1) AND (ThemeId = ' . $vars['m_theme'] . ' OR ThemeId = 0)'; $category_info = $this->Conn->GetRow($sql); if ($category_info) {