From 0a7db81426e966f9c44fcc85338615e1bb3c6f34 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 12 Nov 2013 22:25:23 +0100 Subject: [ticket/11997] Fix redirects from inside controllers The redirect url currently uses the web root path. However as we prepend the full board url later, we need to remove the relative web root path and prepend the normal root path again. Otherwise redirects from inside routes will not work as intended. PHPBB3-11997 --- phpBB/phpbb/path_helper.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/path_helper.php b/phpBB/phpbb/path_helper.php index 8cd8808261..71252ac05b 100644 --- a/phpBB/phpbb/path_helper.php +++ b/phpBB/phpbb/path_helper.php @@ -101,6 +101,27 @@ class path_helper return $path; } + /** + * Strips away the web root path and prepends the normal root path + * + * This replaces get_web_root_path() . some_url with + * $phpbb_root_path . some_url + * + * @param string $path The path to be updated + * @return string + */ + public function remove_web_root_path($path) + { + if (strpos($path, $this->get_web_root_path()) === 0) + { + $path = substr($path, strlen($this->get_web_root_path())); + + return $this->phpbb_root_path . $path; + } + + return $path; + } + /** * Get a relative root path from the current URL * -- cgit v1.2.1 From 8bbede425193caa57be81638b8377c2c9a21e022 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 7 Dec 2013 13:23:57 +0100 Subject: [ticket/11997] Add method for controller redirect URLs to path helper This method will allow us to get proper redirect URLs for controllers. PHPBB3-11997 --- phpBB/phpbb/path_helper.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/path_helper.php b/phpBB/phpbb/path_helper.php index 71252ac05b..f6587fa101 100644 --- a/phpBB/phpbb/path_helper.php +++ b/phpBB/phpbb/path_helper.php @@ -183,4 +183,28 @@ class path_helper */ return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $corrections - 1); } + + /** + * Get the redirect URL for controllers + * + * @param string $url URL to the controller + * + * @param string Redirect URL for controller + */ + public function get_controller_redirect_url($url) + { + // Remove predecing dots + $url = ltrim($this->remove_web_root_path($url), '.'); + + // Get position of URL delimiter + $delimiter_position = strpos($url, '/'); + + // Add URL delimiter in front of path if it doesn't exist + if ($delimiter_position === false || $delimiter_position > 1) + { + $url = '/' . $url; + } + + return generate_board_url() . $url; + } } -- cgit v1.2.1 From d9358c26da6737044a3c10893e7b954176b205d2 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 21 Dec 2013 20:08:00 +0100 Subject: [ticket/11997] Add clean_url() method to path_helper This method will get rid of unnecessary . and .. in URLs. PHPBB3-11997 --- phpBB/phpbb/path_helper.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/path_helper.php b/phpBB/phpbb/path_helper.php index f6587fa101..cd4c20bb7d 100644 --- a/phpBB/phpbb/path_helper.php +++ b/phpBB/phpbb/path_helper.php @@ -207,4 +207,27 @@ class path_helper return generate_board_url() . $url; } + + /** + * Eliminates useless . and .. components from specified URL + * + * @param string $url URL to clean + * + * @return string Cleaned URL + */ + public function clean_url($url) + { + $delimiter_position = strpos($url, '://'); + // URL should contain :// but it shouldn't start with it. + // Do not clean URLs that do not fit these constraints. + if (empty($delimiter_position)) + { + return $url; + } + $scheme = substr($url, 0, $delimiter_position) . '://'; + // Add length of URL delimiter to position + $path = substr($url, $delimiter_position + 3); + + return $scheme . $this->filesystem->clean_path($path); + } } -- cgit v1.2.1 From ce2c5213d7aad2c24ee83147b167236ce754c671 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 27 Dec 2013 18:41:44 +0100 Subject: [ticket/11997] Remove obsolete function get_controller_redirect_url() PHPBB3-11997 --- phpBB/phpbb/path_helper.php | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'phpBB/phpbb') diff --git a/phpBB/phpbb/path_helper.php b/phpBB/phpbb/path_helper.php index cd4c20bb7d..a8e12c4063 100644 --- a/phpBB/phpbb/path_helper.php +++ b/phpBB/phpbb/path_helper.php @@ -184,30 +184,6 @@ class path_helper return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $corrections - 1); } - /** - * Get the redirect URL for controllers - * - * @param string $url URL to the controller - * - * @param string Redirect URL for controller - */ - public function get_controller_redirect_url($url) - { - // Remove predecing dots - $url = ltrim($this->remove_web_root_path($url), '.'); - - // Get position of URL delimiter - $delimiter_position = strpos($url, '/'); - - // Add URL delimiter in front of path if it doesn't exist - if ($delimiter_position === false || $delimiter_position > 1) - { - $url = '/' . $url; - } - - return generate_board_url() . $url; - } - /** * Eliminates useless . and .. components from specified URL * -- cgit v1.2.1