/** * Proxy the router parse function to fix a bug in the core * * @param object $url The URI to parse * @return array */ public function parse($uri) { $nooku = KFactory::get('admin::com.nooku.model.nooku'); $app = KFactory::get('lib.joomla.application'); // Perform the actual parse $result = parent::parse($uri); $this->setVars($result); // Redirect if the language has changed $old = $nooku->getLanguage(); $new = KInput::get('lang', array('post', 'get'), 'lang'); if (isset($new) && strtolower($new) != strtolower($old)) { //Set the language $nooku->setLanguage($new); if (KInput::getMethod() == 'POST') { $uri->setVar('lang', $new); $route = JRoute::_($uri->toString(), false); /* * Dirty hack. Joomla URI class transforms cid[] into cid[0] * * TODO : either fix in KUri or in the koowa javascript uri parser */ $route = str_replace('cid[0]', 'cid[]', $route); $app->redirect($route); } } return $result; }
/** * Proxy the router parse function to fix a bug in the core * * @param object $url The URI to parse * @return array */ public function parse($uri) { $nooku = KFactory::get('admin::com.nooku.model.nooku'); $app = KFactory::get('lib.joomla.application'); // Fool the parent in thinking we are coming in through index $path = $uri->getPath(); $path = str_replace('index2.php', 'index.php', $path); $uri->setPath($path); // Perform the actual parse $result = parent::parse($uri); $result = $this->_parseSegments($result); $this->setVars($result); //Get the active languages $languages = $nooku->getLanguages(); if (count($languages) > 1) { // Redirect if the language has changed if (KInput::getMethod() == 'POST') { $old = $nooku->getLanguage(); $new = KInput::get('lang', array('post', 'get'), 'lang'); if (isset($new) && strtolower($new) != strtolower($old)) { //Set the language $nooku->setLanguage($new); //Force a reload on the menu $menu = $app->getMenu(); $menu->load(); $result = $this->_translateSegments($result); $this->setVars($result); $app->redirect(JRoute::_('&lang=' . $new, false)); } } //Set the language $nooku->setLanguage($result['lang']); //Set language in case no language information cannot be found if (empty($result['lang']) && !is_null($result['lang'])) { $result['lang'] = $nooku->getLanguage(); $uri->setQuery($result); $this->setVars($result); /* * Redirect if language information is empty * * This fix was added to deal with forms that don't use JRoute in the action. * for example mod_search. */ if (JRequest::getMethod() != 'POST') { $app->redirect(JRoute::_('index.php' . $uri->toString(array('query')), false)); } } //Error : language cannot be found if (is_null($result['lang']) || !isset($languages[$result['lang']])) { throw new KProxyJoomlaException(JText::_("Language Not Found")); } } return $result; }
public function onApplicationAfterRoute(ArrayObject $args) { if (KInput::getMethod() != 'POST') { return; } $nooku = KFactory::get('admin::com.nooku.model.nooku'); $old = $nooku->getLanguage(); $new = KInput::get('lang', array('post', 'get'), 'lang'); //Set the language if (!empty($new) && $new != $old) { $nooku->setLanguage($new); } }