예제 #1
0
 /**
  * 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;
 }
예제 #2
0
 /**
  * Tests the parse methods redirect
  *
  * @return  void
  * @testdox External URLs trigger a redirect
  * @since   3.4
  */
 public function testParseRedirect()
 {
     $uri = new JUri('http://www.example.com/index.php');
     $app = $this->getMockCmsApp();
     $app->expects($this->any())->method('get')->will($this->returnValue(2));
     $app->expects($this->once())->method('redirect');
     $object = new JRouterSite(array(), $app, TestMockMenu::create($this));
     $object->parse($uri);
 }