diff options
author | David King <imkingdavid@gmail.com> | 2012-11-19 18:15:59 -0500 |
---|---|---|
committer | David King <imkingdavid@gmail.com> | 2013-07-06 23:20:21 -0400 |
commit | c20f92ba1eb089222bfbe7d7acd5992682a9c936 (patch) | |
tree | 866a38dd818256b06a0553d626f099dd0279df1e /phpBB | |
parent | 2d7a91ebd630d6b9316f05cd8c153cd9dde5c3c9 (diff) | |
download | forums-c20f92ba1eb089222bfbe7d7acd5992682a9c936.tar forums-c20f92ba1eb089222bfbe7d7acd5992682a9c936.tar.gz forums-c20f92ba1eb089222bfbe7d7acd5992682a9c936.tar.bz2 forums-c20f92ba1eb089222bfbe7d7acd5992682a9c936.tar.xz forums-c20f92ba1eb089222bfbe7d7acd5992682a9c936.zip |
[ticket/11215] Correct paths when path info is used for controller access
PHPBB3-11215
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/app.php | 1 | ||||
-rw-r--r-- | phpBB/common.php | 3 | ||||
-rw-r--r-- | phpBB/includes/functions.php | 62 |
3 files changed, 52 insertions, 14 deletions
diff --git a/phpBB/app.php b/phpBB/app.php index d93208d585..f1023ff1b5 100644 --- a/phpBB/app.php +++ b/phpBB/app.php @@ -24,7 +24,6 @@ $user->session_begin(); $auth->acl($user->data); $user->setup('app'); -$symfony_request = phpbb_create_symfony_request($request); $http_kernel = $phpbb_container->get('http_kernel'); $response = $http_kernel->handle($symfony_request); $response->send(); diff --git a/phpBB/common.php b/phpBB/common.php index f6f109c3de..236d456eec 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -109,6 +109,9 @@ $db = $phpbb_container->get('dbal.conn'); // make sure request_var uses this request instance request_var('', 0, false, false, $request); // "dependency injection" for a function +// Create a Symfony Request object from our phpbb_request object +$symfony_request = phpbb_create_symfony_request($request); + // Grab global variables, re-cache if necessary $config = $phpbb_container->get('config'); set_config(null, null, null, $config); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 6a1b3fd4f8..60181c488e 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2413,6 +2413,7 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) { global $_SID, $_EXTRA_URL, $phpbb_hook; global $phpbb_dispatcher; + global $request; if ($params === '' || (is_array($params) && empty($params))) { @@ -2420,6 +2421,12 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) $params = false; } + $corrected_root = phpbb_get_web_root_path(phpbb_create_symfony_request($request)); + if ($corrected_root) + { + $url = $corrected_root . substr($url, strlen($phpbb_root_path)); + } + $append_sid_overwrite = false; /** @@ -5209,7 +5216,11 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 // Determine board url - we may need it later $board_url = generate_board_url() . '/'; - $web_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? $board_url : $phpbb_root_path; + // This path is sent with the base template paths in the assign_vars() + // call below. We need to correct it in case we are accessing from a + // controller because the web paths will be incorrect otherwise. + $corrected_path = phpbb_get_web_root_path(phpbb_create_symfony_request($request)); + $web_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? $board_url : $corrected_path; // Send a proper content-language to the output $user_lang = $user->lang['USER_LANG']; @@ -5685,6 +5696,16 @@ function phpbb_convert_30_dbms_to_31($dbms) */ function phpbb_create_symfony_request(phpbb_request $request) { + // If we have already gotten it, don't go back through all the trouble of + // creating it again; instead, just return it. This allows multiple calls + // of this method so we don't have to globalize $symfony_request in other + // functions. + static $symfony_request; + if (null !== $symfony_request) + { + return $symfony_request; + } + // This function is meant to sanitize the global input arrays $sanitizer = function(&$value, $key) { $type_cast_helper = new phpbb_request_type_cast_helper(); @@ -5704,21 +5725,36 @@ function phpbb_create_symfony_request(phpbb_request $request) array_walk_recursive($get_parameters, $sanitizer); array_walk_recursive($post_parameters, $sanitizer); - // Until we fix the issue with relative paths, we have to fake path info - // to allow urls like app.php?controller=foo/bar - $controller = $request->variable('controller', ''); - $path_info = '/' . $controller; - $request_uri = $server_parameters['REQUEST_URI']; + $symfony_request = new Request($get_parameters, $post_parameters, array(), $cookie_parameters, $files_parameters, $server_parameters); + return $symfony_request; +} - // Remove the query string from REQUEST_URI - if ($pos = strpos($request_uri, '?')) +/** +* Get a relative root path from the current URL +* +* @param Request $symfony_request Symfony Request object +*/ +function phpbb_get_web_root_path(Request $symfony_request) +{ + static $path; + if (null !== $path) { - $request_uri = substr($request_uri, 0, $pos); + return $path; } - // Add the path info (i.e. controller route) to the REQUEST_URI - $server_parameters['REQUEST_URI'] = $request_uri . $path_info; - $server_parameters['SCRIPT_NAME'] = ''; + $path_info = $symfony_request->getPathInfo(); + if ($path_info == '/') + { + return ''; + } + + $corrections = substr_count($symfony_request->getPathInfo(), '/'); + + $path = ''; + for ($i = 0; $i < $corrections; $i++) + { + $path .= '../'; + } - return new Request($get_parameters, $post_parameters, array(), $cookie_parameters, $files_parameters, $server_parameters); + return $path; } |