Index: kernel/application.php =================================================================== --- kernel/application.php (revision 15359) +++ kernel/application.php (working copy) @@ -1758,6 +1758,19 @@ } /** + * Parses rewrite url and returns parsed variables + * + * @param string $url + * @param string $pass_name + * @return Array + * @access public + */ + public function parseRewriteUrl($url, $pass_name = 'passed') + { + return $this->UrlManager->rewrite->parse($url, $pass_name); + } + + /** * Returns base part of all urls, build on website * * @param string $prefix Index: kernel/managers/rewrite_url_processor.php =================================================================== --- kernel/managers/rewrite_url_processor.php (revision 15359) +++ kernel/managers/rewrite_url_processor.php (working copy) @@ -121,22 +121,8 @@ $url = $this->Application->GetVar('_mod_rw_url_'); if ( $url ) { - foreach ($this->_urlEndings as $url_ending) { - if ( substr($url, strlen($url) - strlen($url_ending)) == $url_ending ) { - $url = substr($url, 0, strlen($url) - strlen($url_ending)); - $default_ending = $this->Application->ConfigValue('ModRewriteUrlEnding'); - - // user manually typed url with different url ending -> redirect to same url with default url ending - if ( ($url_ending != $default_ending) && $this->Application->ConfigValue('ForceModRewriteUrlEnding') ) { - $target_url = $this->Application->BaseURL() . $url . $default_ending; - - trigger_error('Mod-rewrite url "' . $_SERVER['REQUEST_URI'] . '" without "' . $default_ending . '" line ending used', E_USER_NOTICE); - $this->Application->Redirect('external:' . $target_url, Array ('response_code' => 301)); - } - - break; - } - } + $this->_redirectToDefaultUrlEnding($url); + $url = $this->_removeUrlEnding($url); } $cached = $this->_getCachedUrl($url); @@ -177,6 +163,68 @@ } /** + * Detects url ending of given url + * + * @param string $url + * @return string + * @access protected + */ + protected function _findUrlEnding($url) + { + if ( !$url ) { + return ''; + } + + foreach ($this->_urlEndings as $url_ending) { + if ( mb_substr($url, mb_strlen($url) - mb_strlen($url_ending)) == $url_ending ) { + return $url_ending; + } + } + + return ''; + } + + /** + * Removes url ending from url + * + * @param string $url + * @return string + * @access protected + */ + protected function _removeUrlEnding($url) + { + $url_ending = $this->_findUrlEnding($url); + + if ( !$url_ending ) { + return $url; + } + + return mb_substr($url, 0, mb_strlen($url) - mb_strlen($url_ending)); + } + + /** + * Redirects user to page with default url ending, where needed + * + * @param string $url + * @return void + * @access protected + */ + protected function _redirectToDefaultUrlEnding($url) + { + $default_ending = $this->Application->ConfigValue('ModRewriteUrlEnding'); + + if ( $this->_findUrlEnding($url) == $default_ending || !$this->Application->ConfigValue('ForceModRewriteUrlEnding') ) { + return; + } + + // user manually typed url with different url ending -> redirect to same url with default url ending + $target_url = $this->Application->BaseURL() . $this->_removeUrlEnding($url) . $default_ending; + + trigger_error('Mod-rewrite url "' . $_SERVER['REQUEST_URI'] . '" without "' . $default_ending . '" line ending used', E_USER_NOTICE); + $this->Application->Redirect('external:' . $target_url, Array ('response_code' => 301)); + } + + /** * Returns url parsing result from cache or false, when not yet parsed * * @param $url @@ -314,9 +362,34 @@ */ public function parse($string, $pass_name = 'pass') { + // external url (could be back this website as well) + if ( preg_match('/external:(.*)/', $string, $regs) ) { + $string = $regs[1]; + } + $vars = Array ($pass_name => Array ('m')); - $url_parts = $string ? explode('/', trim(mb_strtolower($string, 'UTF-8'), '/')) : Array (); + $url_components = parse_url($string); + if ( isset($url_components['query']) ) { + parse_str($url_components['query'], $vars); + } + + if ( isset($url_components['path']) ) { + if ( BASE_PATH ) { + $string = preg_replace('/^' . preg_quote(BASE_PATH, '/') . '/', '', $url_components['path'], 1); + } + else { + $string = $url_components['path']; + } + + $string = $this->_removeUrlEnding(trim($string, '/')); + } + else { + $string = ''; + } + + $url_parts = $string ? explode('/', mb_strtolower($string, 'UTF-8')) : Array (); + $this->_partsToParse = $url_parts; if ( ($this->HTTPQuery->Get('rewrite') == 'on') || !$url_parts ) { @@ -450,7 +523,7 @@ * @return string * @access protected * - * @todo Should find a way, how to determine what rewrite listerner page is it + * @todo Should find a way, how to determine what rewrite listener page is it */ protected function _parsePage(&$url_parts, &$vars) { @@ -808,7 +881,7 @@ { return count($this->_partsToParse) > 0; } - + /** * Builds url * Index: kernel/utility/event.php =================================================================== --- kernel/utility/event.php (revision 15359) +++ kernel/utility/event.php (working copy) @@ -370,12 +370,17 @@ * Allows to merge passed redirect params hash with existing ones * * @param Array $params + * @param bool $append * @access public */ - public function setRedirectParams($params) + public function setRedirectParams($params, $append = true) { - // append new parameters to parameters set before - $this->redirectParams = kUtil::array_merge_recursive($this->redirectParams, $params); + if ( $append ) { + // append new parameters to parameters set before + $params = kUtil::array_merge_recursive($this->redirectParams, $params); + } + + $this->redirectParams = $params; } /** Index: units/helpers/user_helper.php =================================================================== --- units/helpers/user_helper.php (revision 15359) +++ units/helpers/user_helper.php (working copy) @@ -397,11 +397,38 @@ } } + // set language for Admin Console & Front-End with disabled Mod-Rewrite $this->event->SetRedirectParam('m_lang', $language_id); // data $this->Application->Session->SetField('Language', $language_id); // interface + + // set language for Front-End with enabled Mod-Rewrite + if ( MOD_REWRITE ) { + $this->_injectLanguageIntoUrl($language_id); + } } /** + * Inject language into whatever page user wants to go after login + * + * @param int $language_id + * @return void + * @access protected + */ + protected function _injectLanguageIntoUrl($language_id) + { + $url = $this->Application->HREF($this->event->redirect, '', $this->event->getRedirectParams(), $this->event->redirectScript); + $vars = $this->Application->parseRewriteUrl($url, 'pass'); + + $vars['pass'] = implode(',', $vars['pass']); + $vars['m_lang'] = $language_id; + $template = $vars['t']; + unset($vars['is_virtual'], $vars['t']); + + $this->event->redirect = $template; + $this->event->setRedirectParams($vars, false); + } + + /** * Checks that user is allowed to use super admin mode * * @return bool