Index: kernel/utility/event.php =================================================================== --- kernel/utility/event.php (revision 15331) +++ kernel/utility/event.php (working copy) @@ -264,11 +264,17 @@ * Allows to merge passed redirect params hash with existing ones * * @param Array $params + * @param bool $append * @access public */ - function setRedirectParams($params) + public function setRedirectParams($params, $append = true) { - $this->redirect_params = array_merge_recursive2($this->redirect_params, $params); + if ( $append ) { + // append new parameters to parameters set before + $params = array_merge_recursive2($this->redirect_params, $params); + } + + $this->redirect_params = $params; } /** Index: units/helpers/mod_rewrite_helper.php =================================================================== --- units/helpers/mod_rewrite_helper.php (revision 15331) +++ units/helpers/mod_rewrite_helper.php (working copy) @@ -89,20 +89,8 @@ $url = $this->HTTPQuery->Get('_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; - $this->Application->Redirect('external:' . $target_url, Array ('response_code' => 301)); - } - - break; - } - } + $this->_redirectToDefaultUrlEnding($url); + $url = $this->_removeUrlEnding($url); } $restored = false; @@ -141,6 +129,68 @@ $this->HTTPQuery->finalizeParsing($passed); } + /** + * 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)); + } + function _getCachedUrl($url) { if (!$url) { @@ -224,11 +274,36 @@ $this->Conn->doInsert($fields_hash, TABLE_PREFIX . 'CachedUrls'); } - function parseRewriteURL($url) + function parseRewriteURL($string, $pass_name = 'pass') { - $vars = Array ('pass' => Array ('m')); - $url_parts = $url ? explode('/', trim(mb_strtolower($url, 'UTF-8'), '/')) : Array (); + // 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_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 ) { Index: units/helpers/user_helper.php =================================================================== --- units/helpers/user_helper.php (revision 15331) +++ units/helpers/user_helper.php (working copy) @@ -319,10 +319,40 @@ } } + // 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) + { + $mod_rewrite_helper =& $this->Application->recallObject('ModRewriteHelper'); + /* @var $mod_rewrite_helper kModRewriteHelper */ + + $url = $this->Application->HREF($this->event->redirect, '', $this->event->redirect_params, $this->event->redirect_script); + $vars = $mod_rewrite_helper->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 *