1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-15 05:14:28 +02:00

[ticket/12099] Add request argument to path_helper service

PHPBB3-12099
This commit is contained in:
Pico88 2014-04-21 19:53:46 +02:00 committed by Tristan Darricau
parent 404c2f1144
commit f383d4221c
11 changed files with 74 additions and 2 deletions

View File

@ -299,6 +299,8 @@ services:
arguments:
- @symfony_request
- @filesystem
- @request
- @config
- %core.root_path%
- %core.php_ext%
- %core.adm_relative_path%

View File

@ -24,6 +24,12 @@ class path_helper
/** @var \phpbb\filesystem */
protected $filesystem;
/** @var \phpbb\request\request */
protected $request;
/** @var \phpbb\config\config */
protected $config;
/** @var string */
protected $phpbb_root_path;
@ -41,13 +47,17 @@ class path_helper
*
* @param \phpbb\symfony_request $symfony_request
* @param \phpbb\filesystem $filesystem
* @param \phpbb\request\request $request
* @param \phpbb\config\config $config
* @param string $phpbb_root_path Relative path to phpBB root
* @param string $php_ext PHP extension (php)
*/
public function __construct(\phpbb\symfony_request $symfony_request, \phpbb\filesystem $filesystem, $phpbb_root_path, $php_ext, $adm_relative_path = null)
public function __construct(\phpbb\symfony_request $symfony_request, \phpbb\filesystem $filesystem, \phpbb\request\request $request, \phpbb\config\config $config, $phpbb_root_path, $php_ext, $adm_relative_path = null)
{
$this->symfony_request = $symfony_request;
$this->filesystem = $filesystem;
$this->request = $request;
$this->config = $config;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->adm_relative_path = $adm_relative_path;
@ -170,7 +180,47 @@ class path_helper
return $this->web_root_path = $this->phpbb_root_path;
}
// How many corrections might we need?
/*
* Check AJAX request
*/
if ($this->request->is_ajax())
{
// Check referer
$referer = strtolower($this->request->header('Referer'));
// Count chars
$chars = strlen($this->config['server_name'] . $this->config['script_path']) - 1;
/*
* Return string without server name and script path
* e.g. 'http://localhost/phpBB/app.php', where server name is 'localhost'
* and script path is '/phpBB', will be cut to '/app.php'
*/
$ref = substr(strstr($referer, strtolower($this->config['server_name'] . $this->config['script_path'])), $chars);
// How many slashes does the referer used?
$count_slashes = substr_count($ref, '/');
/*
* If the shorten referer has only 1 slash,
* return default path
*/
if ($count_slashes == 1)
{
return $this->web_root_path = $this->phpbb_root_path;
}
/*
* Otherwise we are on routed page so we must correct the relative path
* for web URLs. We must append ../ to the end of the root path
* as many times as / exists in shorten referer less one time
*/
else
{
return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $count_slashes - 1);
}
}
// How many corrections might we need?
$corrections = substr_count($path_info, '/');
/*

View File

@ -38,6 +38,8 @@ class phpbb_avatar_manager_test extends \phpbb_test_case
new phpbb_mock_request()
),
new \phpbb\filesystem(),
$this->getMock('\phpbb\request\request'),
$config,
$phpbb_root_path,
$phpEx
);

View File

@ -26,6 +26,8 @@ class phpbb_controller_helper_route_test extends phpbb_test_case
new phpbb_mock_request()
),
new \phpbb\filesystem(),
$this->getMock('\phpbb\request\request'),
new \phpbb\config\config(array()),
$phpbb_root_path,
$phpEx
);

View File

@ -50,6 +50,8 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
new phpbb_mock_request()
),
new \phpbb\filesystem(),
$this->getMock('\phpbb\request\request'),
new \phpbb\config\config(array()),
$this->phpbb_root_path,
$this->phpEx
),

View File

@ -29,6 +29,8 @@ class phpbb_path_helper_test extends phpbb_test_case
new phpbb_mock_request()
),
new \phpbb\filesystem(),
$this->getMock('\phpbb\request\request'),
new \phpbb\config\config(array()),
$this->phpbb_root_path,
'php'
);
@ -158,6 +160,8 @@ class phpbb_path_helper_test extends phpbb_test_case
$path_helper = new \phpbb\path_helper(
$symfony_request,
new \phpbb\filesystem(),
$this->getMock('\phpbb\request\request'),
new \phpbb\config\config(array()),
$this->phpbb_root_path,
'php'
);

View File

@ -63,6 +63,8 @@ class phpbb_security_redirect_test extends phpbb_security_test_base
new phpbb_mock_request()
),
new \phpbb\filesystem(),
$this->getMock('\phpbb\request\request'),
new \phpbb\config\config(array()),
$this->phpbb_root_path,
'php'
);

View File

@ -143,6 +143,8 @@ Zeta test event in all',
new phpbb_mock_request()
),
new \phpbb\filesystem(),
$this->getMock('\phpbb\request\request'),
new \phpbb\config\config(array()),
$phpbb_root_path,
$phpEx
);

View File

@ -72,6 +72,8 @@ class phpbb_template_template_test_case extends phpbb_test_case
new phpbb_mock_request()
),
new \phpbb\filesystem(),
$this->getMock('\phpbb\request\request'),
new \phpbb\config\config(array()),
$phpbb_root_path,
$phpEx
);

View File

@ -27,6 +27,8 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
new phpbb_mock_request()
),
new \phpbb\filesystem(),
$this->getMock('\phpbb\request\request'),
new \phpbb\config\config(array()),
$phpbb_root_path,
$phpEx
);

View File

@ -32,6 +32,8 @@ abstract class phpbb_session_test_case extends phpbb_database_test_case
$phpbb_path_helper = new \phpbb\path_helper(
$symfony_request,
$phpbb_filesystem,
$this->getMock('\phpbb\request\request'),
new \phpbb\config\config(array()),
$phpbb_root_path,
$phpEx
);