本文整理汇总了PHP中JRouter::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP JRouter::parse方法的具体用法?PHP JRouter::parse怎么用?PHP JRouter::parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JRouter
的用法示例。
在下文中一共展示了JRouter::parse方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
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;
}
示例2: testParse
/**
* 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);
}
示例3: testFirstParseRuleTakesPrecedence
/**
* @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));
}
示例4: testParseRedirect
/**
* 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);
}
示例5: testParse
/**
* 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());
}
示例6: parse
/**
* 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;
}
示例7: parse
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;
}
示例8: parse
/**
* 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");
//.........这里部分代码省略.........
示例9: parse
function parse(&$uri)
{
$vars = parent::parse($uri);
return $vars;
}
示例10: parse
/**
* 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;
}
示例11: parse
/**
* 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
//.........这里部分代码省略.........