diff options
author | Pico88 <luki_9@wp.pl> | 2014-04-21 19:53:46 +0200 |
---|---|---|
committer | Tristan Darricau <github@nicofuma.fr> | 2014-06-29 20:54:38 +0200 |
commit | f383d4221ce085dc36ef4c04a0a2c7c3f381b108 (patch) | |
tree | 06dfe75ca688aff35693b29c574a7365890fee4f | |
parent | 404c2f11448f53e55eca4cfdf082671230711241 (diff) | |
download | forums-f383d4221ce085dc36ef4c04a0a2c7c3f381b108.tar forums-f383d4221ce085dc36ef4c04a0a2c7c3f381b108.tar.gz forums-f383d4221ce085dc36ef4c04a0a2c7c3f381b108.tar.bz2 forums-f383d4221ce085dc36ef4c04a0a2c7c3f381b108.tar.xz forums-f383d4221ce085dc36ef4c04a0a2c7c3f381b108.zip |
[ticket/12099] Add request argument to path_helper service
PHPBB3-12099
-rw-r--r-- | phpBB/config/services.yml | 2 | ||||
-rw-r--r-- | phpBB/phpbb/path_helper.php | 54 | ||||
-rw-r--r-- | tests/avatar/manager_test.php | 2 | ||||
-rw-r--r-- | tests/controller/helper_route_test.php | 2 | ||||
-rw-r--r-- | tests/extension/metadata_manager_test.php | 2 | ||||
-rw-r--r-- | tests/path_helper/path_helper_test.php | 4 | ||||
-rw-r--r-- | tests/security/redirect_test.php | 2 | ||||
-rw-r--r-- | tests/template/template_events_test.php | 2 | ||||
-rw-r--r-- | tests/template/template_test_case.php | 2 | ||||
-rw-r--r-- | tests/template/template_test_case_with_tree.php | 2 | ||||
-rw-r--r-- | tests/test_framework/phpbb_session_test_case.php | 2 |
11 files changed, 74 insertions, 2 deletions
diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 72eeae9b15..a7addf510b 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -299,6 +299,8 @@ services: arguments: - @symfony_request - @filesystem + - @request + - @config - %core.root_path% - %core.php_ext% - %core.adm_relative_path% diff --git a/phpBB/phpbb/path_helper.php b/phpBB/phpbb/path_helper.php index b592cc4460..b157c5930a 100644 --- a/phpBB/phpbb/path_helper.php +++ b/phpBB/phpbb/path_helper.php @@ -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, '/'); /* diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index 246397ad6c..96d3ba1474 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -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 ); diff --git a/tests/controller/helper_route_test.php b/tests/controller/helper_route_test.php index 621efaa830..a9e8e46a42 100644 --- a/tests/controller/helper_route_test.php +++ b/tests/controller/helper_route_test.php @@ -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 ); diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 3678ac0a3f..b7f309b2a9 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -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 ), diff --git a/tests/path_helper/path_helper_test.php b/tests/path_helper/path_helper_test.php index 9866cb6efe..e7e2ae697f 100644 --- a/tests/path_helper/path_helper_test.php +++ b/tests/path_helper/path_helper_test.php @@ -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' ); diff --git a/tests/security/redirect_test.php b/tests/security/redirect_test.php index fb1011cde0..24c42ca8c2 100644 --- a/tests/security/redirect_test.php +++ b/tests/security/redirect_test.php @@ -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' ); diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index ce3c90b78a..2c29d42173 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -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 ); diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 00b823b2c4..d393027566 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -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 ); diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php index 4f778a9c1c..c1b22e94e0 100644 --- a/tests/template/template_test_case_with_tree.php +++ b/tests/template/template_test_case_with_tree.php @@ -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 ); diff --git a/tests/test_framework/phpbb_session_test_case.php b/tests/test_framework/phpbb_session_test_case.php index 8a5d582573..144e05b5fa 100644 --- a/tests/test_framework/phpbb_session_test_case.php +++ b/tests/test_framework/phpbb_session_test_case.php @@ -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 ); |