Example #1
0
 function parse(&$uri)
 {
     $vars = array();
     // Get the application
     $app =& JFactory::getApplication();
     if ($app->getCfg('force_ssl') == 2 && strtolower($uri->getScheme()) != 'https') {
         //forward to https
         $uri->setScheme('https');
         $app->redirect($uri->toString());
     }
     // Get the path
     $path = $uri->getPath();
     //Remove the suffix
     if ($this->_mode == JROUTER_MODE_SEF) {
         if ($app->getCfg('sef_suffix') && !(substr($path, -9) == 'index.php' || substr($path, -1) == '/')) {
             if ($suffix = pathinfo($path, PATHINFO_EXTENSION)) {
                 $path = str_replace('.' . $suffix, '', $path);
                 $vars['format'] = $suffix;
             }
         }
     }
     //Remove basepath
     $path = substr_replace($path, '', 0, strlen(JURI::base(true)));
     //Remove prefix
     $path = str_replace('index.php', '', $path);
     //Set the route
     $uri->setPath(trim($path, '/'));
     $vars += parent::parse($uri);
     return $vars;
 }
Example #2
0
 /**
  * Tests the parse method
  *
  * @param   array    $uri       An associative array with variables
  * @param   integer  $mode      JROUTER_MODE_RAW or JROUTER_MODE_SEF
  * @param   array    $vars      An associative array with global variables
  * @param   array    $expected  Expected value
  *
  * @return  void
  *
  * @dataProvider  casesParse
  * @since         3.4
  */
 public function testParse($url, $mode, $vars, $expected)
 {
     $this->object->setMode($mode);
     $this->object->setVars($vars);
     $uri = new JUri($url);
     $this->assertEquals($this->object->parse($uri), $expected);
 }
Example #3
0
 /**
  * @param   array  $preset   Initial router variables
  * @param   array  $rules    Callback to execute
  * @param   string $stage    Stage to process
  * @param   string $expected Expected return value
  *
  * @dataProvider  casesParseRulesForPrecedence
  * @since         3.4
  */
 public function testFirstParseRuleTakesPrecedence($preset, $rules, $stage, $expected)
 {
     $this->object->setVars($preset, false);
     foreach ($rules as $rule) {
         $this->object->attachParseRule($rule, $stage);
     }
     $uri = $this->getMock('JUri');
     $this->assertEquals($expected, $this->object->parse($uri));
 }
Example #4
0
 /**
  * Tests the parse methods redirect
  *
  * @return  void
  *
  * @since   3.4
  */
 public function testParseRedirect()
 {
     $uri = new JUri('http://www.example.com/index.php');
     $app = $this->object->getApp();
     $app->expects($this->any())->method('get')->will($this->returnValue(2));
     $app->expects($this->once())->method('redirect');
     $this->object->setApp($app);
     $this->object->parse($uri);
 }
Example #5
0
 /**
  * Tests the parse() method
  *
  * @dataProvider casesParse
  * @return  void
  * @testdox JRouter::parse() parses a JUri object into an array of parameters
  * @since   4.0
  */
 public function testParse($rules, $stages, $setVars, $url, $expected, $expectedVars)
 {
     foreach ($rules as $i => $rule) {
         $this->object->attachParseRule($rule, $stages[$i]);
     }
     $uri = new JUri($url);
     $result = $this->object->parse($uri, $setVars);
     $this->assertEquals($expected, $result);
     $this->assertEquals($expectedVars, $this->object->getVars());
 }
Example #6
0
	/**
	 * Parse the URI
	 *
	 * @param	object	The URI
	 *
	 * @return	array
	 */
	public function parse(&$uri)
	{
		$vars = array();

		// Get the application
		$app = JFactory::getApplication();

		if ($app->getCfg('force_ssl') == 2 && strtolower($uri->getScheme()) != 'https') {
			//forward to https
			$uri->setScheme('https');
			$app->redirect((string)$uri);
		}

		// Get the path
		$path = $uri->getPath();

		// Remove the base URI path.
		$path = substr_replace($path, '', 0, strlen(JURI::base(true)));

		// Check to see if a request to a specific entry point has been made.
		if (preg_match("#.*\.php#u", $path, $matches)) {

			// Get the current entry point path relative to the site path.
			$scriptPath = realpath($_SERVER['SCRIPT_FILENAME'] ? $_SERVER['SCRIPT_FILENAME'] : str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']));
			$relativeScriptPath = str_replace('\\', '/', str_replace(JPATH_SITE, '', $scriptPath));

			// If a php file has been found in the request path, check to see if it is a valid file.
			// Also verify that it represents the same file from the server variable for entry script.
			if (file_exists(JPATH_SITE.$matches[0]) && ($matches[0] == $relativeScriptPath)) {

				// Remove the entry point segments from the request path for proper routing.
				$path = str_replace($matches[0], '', $path);
			}
		}

		//Remove the suffix
		if ($this->_mode == JROUTER_MODE_SEF) {
			if ($app->getCfg('sef_suffix') && !(substr($path, -9) == 'index.php' || substr($path, -1) == '/')) {
				if ($suffix = pathinfo($path, PATHINFO_EXTENSION)) {
					$path = str_replace('.'.$suffix, '', $path);
					$vars['format'] = $suffix;
				}
			}
		}

		//Set the route
		$uri->setPath(trim($path , '/'));

		$vars += parent::parse($uri);

		return $vars;
	}
Example #7
0
 function parse(&$uri)
 {
     $vars = array();
     // Get the path
     $path = $uri->getPath();
     //Remove basepath
     $path = substr_replace($path, '', 0, strlen(JURI::base(true)));
     //Remove prefix
     $path = str_replace('index.php', '', $path);
     //Set the route
     $uri->setPath(trim($path, '/'));
     $vars += parent::parse($uri);
     return $vars;
 }
Example #8
0
 /**
  * Parse the URI
  *
  * @param	object	The URI
  *
  * @return	array
  */
 public function parse(&$uri)
 {
     $vars = array();
     // Get the application
     $app = JApplication::getInstance('site');
     if ($app->getCfg('force_ssl') == 2 && strtolower($uri->getScheme()) != 'https') {
         //forward to https
         $uri->setScheme('https');
         $app->redirect((string) $uri);
     }
     // Get the path
     $path = $uri->getPath();
     // Remove the base URI path.
     $path = substr_replace($path, '', 0, strlen(JURI::base(true)));
     // Check to see if a request to a specific entry point has been made.
     if (preg_match("#.*?\\.php#u", $path, $matches)) {
         // Get the current entry point path relative to the site path.
         $scriptPath = realpath($_SERVER['SCRIPT_FILENAME'] ? $_SERVER['SCRIPT_FILENAME'] : str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']));
         $relativeScriptPath = str_replace('\\', '/', str_replace(JPATH_SITE, '', $scriptPath));
         // If a php file has been found in the request path, check to see if it is a valid file.
         // Also verify that it represents the same file from the server variable for entry script.
         if (file_exists(JPATH_SITE . $matches[0]) && $matches[0] == $relativeScriptPath) {
             // Remove the entry point segments from the request path for proper routing.
             $path = str_replace($matches[0], '', $path);
         }
     }
     // Identify format
     if ($this->_mode == JROUTER_MODE_SEF) {
         if ($app->getCfg('sef_suffix') && !(substr($path, -9) == 'index.php' || substr($path, -1) == '/')) {
             if ($suffix = pathinfo($path, PATHINFO_EXTENSION)) {
                 $vars['format'] = $suffix;
             }
         }
     }
     //Remove prefix
     $path = str_replace('index.php', '', $path);
     //Set the route
     $uri->setPath(trim($path, '/'));
     $vars += parent::parse($uri);
     if (empty($vars['option']) && isset($_POST['option'])) {
         $vars['option'] = JRequest::getCmd('option', '', 'post');
     }
     if (empty($vars['option'])) {
         JError::raiseError(404, JText::_('JGLOBAL_RESOURCE_NOT_FOUND'));
     }
     /* START: HUBzero Extensions Follow to force registration and email confirmation */
     $juser = JFactory::getUser();
     if (!$juser->get('guest')) {
         $session = JFactory::getSession();
         $registration_incomplete = $session->get('registration.incomplete');
         if ($registration_incomplete) {
             if ($vars['option'] == 'com_users') {
                 if ($vars['view'] == 'logout' || $vars['task'] == 'logout') {
                     return $vars;
                 }
             }
             if ($vars['option'] == 'com_members' && (isset($vars['controller']) && $vars['controller'] == 'register' || isset($vars['view']) && $vars['view'] == 'register')) {
                 $session->set('linkaccount', false);
                 return $vars;
             }
             if ($uri->getPath() != 'legal/terms') {
                 $originalVars = $vars;
                 $vars = array();
                 if ($juser->get('tmp_user')) {
                     $vars['option'] = 'com_members';
                     $vars['controller'] = 'register';
                     $vars['task'] = 'create';
                     $vars['act'] = '';
                 } else {
                     if (substr($juser->get('email'), -8) == '@invalid') {
                         // First, allow ticket creation
                         if ($originalVars['option'] == 'com_support' && $originalVars['controller'] == 'tickets' && $originalVars['task'] == 'save') {
                             // Do nothing...allow it to pass through
                             $vars = $originalVars;
                         } elseif ($session->get('linkaccount', true)) {
                             $vars['option'] = 'com_users';
                             $vars['view'] = 'link';
                         } else {
                             $vars['option'] = 'com_members';
                             $vars['controller'] = 'register';
                             $vars['task'] = 'update';
                             $vars['act'] = '';
                         }
                     } else {
                         $o = JRequest::getVar('option', '');
                         $t = JRequest::getVar('task', '');
                         $nh = JRequest::getInt('no_html', 0);
                         //are we trying to use the tag autocompletor when forcing registration update?
                         if ($o == 'com_tags' && $t == 'autocomplete' && $nh) {
                             $vars['option'] = 'com_tags';
                         } else {
                             $vars['option'] = 'com_members';
                             $vars['id'] = $juser->get("id");
                             $vars['active'] = 'profile';
                         }
                     }
                 }
                 $this->setVars($vars);
                 JRequest::set($vars, 'get', true);
                 // overwrite existing
                 return $vars;
             }
         }
         $xprofile = \Hubzero\User\Profile::getInstance($juser->get('id'));
         if (is_object($xprofile) && $xprofile->get('emailConfirmed') != 1 && $xprofile->get('emailConfirmed') != 3) {
             if ($vars['option'] == 'com_users') {
                 if (isset($vars['view']) && $vars['view'] == 'logout' || isset($vars['task']) && $vars['task'] == 'logout') {
                     return $vars;
                 }
             } else {
                 if ($uri->getPath() == 'legal/terms') {
                     return $vars;
                 } else {
                     if ($vars['option'] == 'com_members' && (isset($vars['controller']) && $vars['controller'] == 'register' || isset($vars['view']) && $vars['view'] == 'register')) {
                         if (!empty($vars['task'])) {
                             if ($vars['task'] == 'unconfirmed' || $vars['task'] == 'change' || $vars['task'] == 'resend' || $vars['task'] == 'confirm') {
                                 return $vars;
                             }
                         }
                     } else {
                         if ($vars['option'] == 'com_members' && (isset($vars['task']) && $vars['task'] == 'download') && (isset($vars['active']) && strpos($vars['active'], 'Image:') !== false) && JFactory::getSession()->get('userchangedemail', 0) == 1) {
                             return $vars;
                         }
                     }
                 }
             }
             $vars = array();
             $vars['option'] = 'com_members';
             $vars['controller'] = 'register';
             $vars['task'] = 'unconfirmed';
             $this->setVars($vars);
             JRequest::set($vars, 'get', true);
             // overwrite existing
             return $vars;
         }
         if (!$juser->get('approved')) {
             if ($vars['option'] == 'com_users') {
                 if ($vars['view'] == 'logout' || $vars['task'] == 'logout') {
                     return $vars;
                 }
             } else {
                 if ($uri->getPath() == 'legal/terms') {
                     return $vars;
                 } else {
                     if ($vars['option'] == 'com_support' && $vars['controller'] == 'tickets' && $vars['task'] == 'save') {
                         return $vars;
                     } else {
                         if ($vars['option'] == 'com_support' && $vars['controller'] == 'tickets' && $vars['task'] == 'new') {
                             return $vars;
                         }
                     }
                 }
             }
             $vars = array();
             $vars['option'] = 'com_users';
             $vars['view'] = 'unapproved';
             $this->setVars($vars);
             JRequest::set($vars, 'get', true);
             // overwrite existing
             return $vars;
         }
         $badpassword = $session->get('badpassword', false);
         $expiredpassword = $session->get('expiredpassword', false);
         if ($badpassword || $expiredpassword) {
             if ($vars['option'] == 'com_members' && isset($vars['task']) && $vars['task'] == 'changepassword') {
                 return $vars;
             }
             if ($vars['option'] == 'com_users' && ($vars['view'] == 'logout' || $vars['task'] == 'logout' || JRequest::getWord('task') == 'logout')) {
                 return $vars;
             }
             if ($vars['option'] == 'com_support' && $vars['task'] == 'save') {
                 return $vars;
             }
             if ($uri->getPath() == 'legal/terms') {
                 return $vars;
             }
             // @FIXME: should double check shadowFlag here in case password gets chanegd
             // out of band.
             // @FIXME: should we clear POST and GET data
             $vars = array();
             $vars['option'] = 'com_members';
             $vars['task'] = 'changepassword';
             if ($badpassword) {
                 $vars['message'] = "Your password does not meet current site requirements. Please change your password now.";
             }
             if ($expiredpassword) {
                 $vars['message'] = "Your password has expired. Please change your password now.";
             }
             $this->setVars($vars);
             JRequest::set($vars, 'get', true);
             // overwrite existing
         }
     }
     // Call system plugins for parsing routes
     if ($responses = JDispatcher::getInstance()->trigger('onParseRoute', array($vars))) {
         // We're assuming here that if a plugin returns vars, we'll take them wholesale.
         // This also means that plugins need to be ordered in terms of priority, as we'll
         // return the first response that isn't empty.
         foreach ($responses as $response) {
             if (is_array($response) && !empty($response)) {
                 $this->setVars($response);
                 JRequest::set($response, 'get', true);
                 return $response;
             }
         }
     }
     /* END: HUBzero Extensions Follow to force registration and email confirmation */
     return $vars;
 }
Example #9
0
 function parse(&$uri)
 {
     $vars = parent::parse($uri);
     return $vars;
 }
Example #10
0
 /**
  * Function to convert a route to an internal URI
  *
  * @param   JUri  &$uri  The uri.
  *
  * @return  array
  *
  * @since   1.5
  */
 public function parse(&$uri)
 {
     $vars = array();
     if ($this->app->get('force_ssl') == 2 && strtolower($uri->getScheme()) != 'https') {
         // Forward to https
         $uri->setScheme('https');
         $this->app->redirect((string) $uri, 301);
     }
     // Get the path
     // Decode URL to convert percent-encoding to unicode so that strings match when routing.
     $path = urldecode($uri->getPath());
     // Remove the base URI path.
     $path = substr_replace($path, '', 0, strlen(JUri::base(true)));
     // Check to see if a request to a specific entry point has been made.
     if (preg_match("#.*?\\.php#u", $path, $matches)) {
         // Get the current entry point path relative to the site path.
         $scriptPath = realpath($_SERVER['SCRIPT_FILENAME'] ? $_SERVER['SCRIPT_FILENAME'] : str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']));
         $relativeScriptPath = str_replace('\\', '/', str_replace(JPATH_SITE, '', $scriptPath));
         // If a php file has been found in the request path, check to see if it is a valid file.
         // Also verify that it represents the same file from the server variable for entry script.
         if (file_exists(JPATH_SITE . $matches[0]) && $matches[0] == $relativeScriptPath) {
             // Remove the entry point segments from the request path for proper routing.
             $path = str_replace($matches[0], '', $path);
         }
     }
     // Identify format
     if ($this->_mode == JROUTER_MODE_SEF) {
         if ($this->app->get('sef_suffix') && !(substr($path, -9) == 'index.php' || substr($path, -1) == '/')) {
             if ($suffix = pathinfo($path, PATHINFO_EXTENSION)) {
                 $vars['format'] = $suffix;
             }
         }
     }
     // Set the route
     $uri->setPath(trim($path, '/'));
     // Set the parsepreprocess components methods
     $components = JComponentHelper::getComponents();
     foreach ($components as $component) {
         $componentRouter = $this->getComponentRouter($component->option);
         if (method_exists($componentRouter, 'parsepreprocess')) {
             $this->attachParseRule(array($componentRouter, 'parsepreprocess'), static::PROCESS_BEFORE);
         }
     }
     $vars += parent::parse($uri);
     return $vars;
 }
Example #11
0
 /**
  * Short description for 'parse'
  *
  * Long description (if any) ...
  *
  * @param      object &$uri Parameter description (if any) ...
  * @return     array Return description (if any) ...
  */
 function parse(&$uri)
 {
     $vars = array();
     // Get the application
     $app = JFactory::getApplication();
     if ($app->getCfg('force_ssl') == 2 && strtolower($uri->getScheme()) != 'https') {
         //forward to https
         $uri->setScheme('https');
         $app->redirect($uri->toString());
     }
     // Get the path
     $path = $uri->getPath();
     //Remove the suffix
     if ($this->_mode == JROUTER_MODE_SEF) {
         // Get the application
         $app = JFactory::getApplication();
         if ($app->getCfg('sef_suffix') && !(substr($path, -9) == 'index.php' || substr($path, -1) == '/')) {
             if ($suffix = pathinfo($path, PATHINFO_EXTENSION)) {
                 $path = str_replace('.' . $suffix, '', $path);
                 $vars['format'] = $suffix;
             }
         }
     }
     //Remove basepath
     $path = substr_replace($path, '', 0, strlen(JURI::base(true)));
     //Remove prefix
     $path = str_replace('index.php', '', $path);
     //Set the route
     $uri->setPath(trim($path, '/'));
     $vars += parent::parse($uri);
     /* HUBzero Extensions Follow to force registration and email confirmation */
     $juser = JFactory::getUser();
     if (!$juser->get('guest')) {
         $session = JFactory::getSession();
         $registration_incomplete = $session->get('registration.incomplete');
         if ($registration_incomplete) {
             if ($vars['option'] == 'com_user') {
                 if ($vars['view'] == 'logout' || $vars['task'] == 'logout') {
                     return $vars;
                 }
             }
             if ($vars['option'] == 'com_members' && (isset($vars['controller']) && $vars['controller'] == 'register' || isset($vars['view']) && $vars['view'] == 'register')) {
                 return $vars;
             }
             if ($uri->getPath() != 'legal/terms') {
                 $vars = array();
                 /*
                 					$vars['option'] = 'com_members';
                 					$vars['controller'] = 'register';
                 
                 					if ($juser->get('tmp_user'))
                 						$vars['task'] = 'create';
                 					else
                 						$vars['task'] = 'update';
                 
                 					$vars['act'] = '';
                 */
                 $vars['option'] = 'com_members';
                 $vars['id'] = $juser->get("id");
                 $vars['active'] = 'profile';
                 $this->setVars($vars);
                 JRequest::set($vars, 'get', true);
                 // overwrite existing
                 return $vars;
             }
         }
         $xprofile = \Hubzero\User\User::oneOrNew($juser->get('id'));
         if (is_object($xprofile) && $xprofile->get('activation') != 1 && $xprofile->get('activation') != 3) {
             if ($vars['option'] == 'com_user') {
                 if ($vars['view'] == 'logout' || $vars['task'] == 'logout') {
                     return $vars;
                 }
             } else {
                 if ($uri->getPath() == 'legal/terms') {
                     return $vars;
                 } else {
                     if ($vars['option'] == 'com_members' && (isset($vars['controller']) && $vars['controller'] == 'register' || isset($vars['view']) && $vars['view'] == 'register')) {
                         if (!empty($vars['task'])) {
                             if ($vars['task'] == 'unconfirmed' || $vars['task'] == 'change' || $vars['task'] == 'resend' || $vars['task'] == 'confirm') {
                                 return $vars;
                             }
                         }
                     }
                 }
             }
             $vars = array();
             $vars['option'] = 'com_members';
             $vars['controller'] = 'register';
             $vars['task'] = 'unconfirmed';
             $this->setVars($vars);
             JRequest::set($vars, 'get', true);
             // overwrite existing
             return $vars;
         }
     }
     return $vars;
 }