diff options
Diffstat (limited to 'phpBB')
| -rw-r--r-- | phpBB/config/services.yml | 1 | ||||
| -rw-r--r-- | phpBB/includes/functions.php | 10 | ||||
| -rw-r--r-- | phpBB/phpbb/controller/helper.php | 44 | 
3 files changed, 37 insertions, 18 deletions
diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 33f249aa13..95a1210045 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -100,6 +100,7 @@ services:              - @controller.provider              - @ext.manager              - @symfony_request +            - @filesystem              - %core.root_path%              - %core.php_ext% diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 1de70d4210..7dfaea6f48 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1989,6 +1989,9 @@ function tracking_unserialize($string, $max_depth = 3)  * @param mixed $params String or array of additional url parameters  * @param bool $is_amp Is url using & (true) or & (false)  * @param string $session_id Possibility to use a custom session id instead of the global one +* @param bool $is_route Is url generated by a route. +* +* @return string The corrected url.  *  * Examples:  * <code> @@ -1999,7 +2002,7 @@ function tracking_unserialize($string, $max_depth = 3)  * </code>  *  */ -function append_sid($url, $params = false, $is_amp = true, $session_id = false) +function append_sid($url, $params = false, $is_amp = true, $session_id = false, $is_route = false)  {  	global $_SID, $_EXTRA_URL, $phpbb_hook, $phpbb_path_helper;  	global $phpbb_dispatcher; @@ -2011,7 +2014,7 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false)  	}  	// Update the root path with the correct relative web path -	if ($phpbb_path_helper instanceof \phpbb\path_helper) +	if (!$is_route && $phpbb_path_helper instanceof \phpbb\path_helper)  	{  		$url = $phpbb_path_helper->update_web_root_path($url);  	} @@ -2037,9 +2040,10 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false)  	*											the global one (false)  	* @var	bool|string	append_sid_overwrite	Overwrite function (string  	*											URL) or not (false) +	* @var	bool	is_route					Is url generated by a route.  	* @since 3.1.0-a1  	*/ -	$vars = array('url', 'params', 'is_amp', 'session_id', 'append_sid_overwrite'); +	$vars = array('url', 'params', 'is_amp', 'session_id', 'append_sid_overwrite', 'is_route');  	extract($phpbb_dispatcher->trigger_event('core.append_sid', compact($vars)));  	if ($append_sid_overwrite) diff --git a/phpBB/phpbb/controller/helper.php b/phpBB/phpbb/controller/helper.php index dd89d0504a..e5e54fac00 100644 --- a/phpBB/phpbb/controller/helper.php +++ b/phpBB/phpbb/controller/helper.php @@ -44,6 +44,11 @@ class helper  	protected $symfony_request;  	/** +	* @var \phpbb\filesystem The filesystem object +	*/ +	protected $filesystem; + +	/**  	* phpBB root path  	* @var string  	*/ @@ -64,15 +69,17 @@ class helper  	* @param \phpbb\controller\provider $provider Path provider  	* @param \phpbb\extension\manager $manager Extension manager object  	* @param \phpbb\symfony_request $symfony_request Symfony Request object +	* @param \phpbb\filesystem $filesystem The filesystem object  	* @param string $phpbb_root_path phpBB root path  	* @param string $php_ext PHP file extension  	*/ -	public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\controller\provider $provider, \phpbb\extension\manager $manager, \phpbb\symfony_request $symfony_request, $phpbb_root_path, $php_ext) +	public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\controller\provider $provider, \phpbb\extension\manager $manager, \phpbb\symfony_request $symfony_request, \phpbb\filesystem $filesystem, $phpbb_root_path, $php_ext)  	{  		$this->template = $template;  		$this->user = $user;  		$this->config = $config;  		$this->symfony_request = $symfony_request; +		$this->filesystem = $filesystem;  		$this->phpbb_root_path = $phpbb_root_path;  		$this->php_ext = $php_ext;  		$provider->find_routing_files($manager->get_finder()); @@ -119,27 +126,34 @@ class helper  			$anchor = '#' . $params['#'];  			unset($params['#']);  		} -		$url_generator = new UrlGenerator($this->route_collection, new RequestContext()); -		$route_url = $url_generator->generate($route, $params); -		if (strpos($route_url, '/') === 0) -		{ -			$route_url = substr($route_url, 1); -		} +		$context = new RequestContext(); +		$context->fromRequest($this->symfony_request); + +		$script_name = $this->symfony_request->getScriptName(); +		$page_name = substr($script_name, -1, 1) == '/' ? '' : utf8_basename($script_name); + +		$base_url = $context->getBaseUrl(); + +		// If enable_mod_rewrite is false we need to replace the current front-end by app.php, otherwise we need to remove it. +		$base_url = str_replace('/' . $page_name, empty($this->config['enable_mod_rewrite']) ? '/app.' . $this->php_ext : '', $base_url); + +		// We need to update the base url to move to the directory of the app.php file. +		$base_url = str_replace('/app.' . $this->php_ext, '/' . $this->phpbb_root_path . 'app.' . $this->php_ext, $base_url); + +		$base_url = $this->filesystem->clean_path($base_url); + +		$context->setBaseUrl($base_url); + +		$url_generator = new UrlGenerator($this->route_collection, $context); +		$route_url = $url_generator->generate($route, $params);  		if ($is_amp)  		{  			$route_url = str_replace(array('&', '&'), array('&', '&'), $route_url);  		} -		// If enable_mod_rewrite is false, we need to include app.php -		$route_prefix = $this->phpbb_root_path; -		if (empty($this->config['enable_mod_rewrite'])) -		{ -			$route_prefix .= 'app.' . $this->php_ext . '/'; -		} - -		return append_sid($route_prefix . $route_url . $anchor, false, $is_amp, $session_id); +		return append_sid($route_url . $anchor, false, $is_amp, $session_id, true);  	}  	/**  | 
