aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/path_helper.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/path_helper.php')
-rw-r--r--phpBB/phpbb/path_helper.php74
1 files changed, 59 insertions, 15 deletions
diff --git a/phpBB/phpbb/path_helper.php b/phpBB/phpbb/path_helper.php
index b2ed11a927..fefef39c51 100644
--- a/phpBB/phpbb/path_helper.php
+++ b/phpBB/phpbb/path_helper.php
@@ -10,14 +10,6 @@
namespace phpbb;
/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-/**
* A class with various functions that are related to paths, files and the filesystem
* @package phpBB3
*/
@@ -89,26 +81,45 @@ class path_helper
}
/**
- * Update a path to the correct relative root path
+ * Update a web path to the correct relative root path
*
* This replaces $phpbb_root_path . some_url with
- * get_web_root_path() . some_url OR if $phpbb_root_path
- * is not at the beginning of $path, just prepends the
- * web root path
+ * get_web_root_path() . some_url
*
* @param string $path The path to be updated
* @return string
*/
public function update_web_root_path($path)
{
- $web_root_path = $this->get_web_root_path($this->symfony_request);
-
if (strpos($path, $this->phpbb_root_path) === 0)
{
$path = substr($path, strlen($this->phpbb_root_path));
+
+ return $this->get_web_root_path() . $path;
}
- return $web_root_path . $path;
+ 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;
}
/**
@@ -138,6 +149,16 @@ class path_helper
$script_name = $this->symfony_request->getScriptName();
/*
+ * If the path info is empty but we're using app.php, then we
+ * might be using an empty route like app.php/ which is
+ * supported by symfony's routing
+ */
+ if ($path_info === '/' && preg_match('/app\.' . $this->php_ext . '\/$/', $request_uri))
+ {
+ return $this->web_root_path = $this->phpbb_root_path . '../';
+ }
+
+ /*
* If the path info is empty (single /), then we're not using
* a route like app.php/foo/bar
*/
@@ -172,4 +193,27 @@ class path_helper
*/
return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $corrections - 1);
}
+
+ /**
+ * 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);
+ }
}