aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/path_helper.php
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2014-05-02 16:40:01 +0200
committerNils Adermann <naderman@naderman.de>2014-05-02 16:40:01 +0200
commite65c51e3cd6f8ecd0a811b2671a94fef3fcf9d83 (patch)
tree43e2c07a830283973bf4246ca8ae43232fb29f5d /phpBB/phpbb/path_helper.php
parenta9ae1f83c7caa461ca2a13b9ef41f1b3140b7d22 (diff)
parente9b00071dd1e7ae40a04e26d3f337d70bafbcf93 (diff)
downloadforums-e65c51e3cd6f8ecd0a811b2671a94fef3fcf9d83.tar
forums-e65c51e3cd6f8ecd0a811b2671a94fef3fcf9d83.tar.gz
forums-e65c51e3cd6f8ecd0a811b2671a94fef3fcf9d83.tar.bz2
forums-e65c51e3cd6f8ecd0a811b2671a94fef3fcf9d83.tar.xz
forums-e65c51e3cd6f8ecd0a811b2671a94fef3fcf9d83.zip
Merge remote-tracking branch 'github-prototech/ticket/11508' into develop-ascraeus
* github-prototech/ticket/11508: [ticket/11508] Fix build_url test. [ticket/11508] Add functional test for jumpbox. [ticket/11508] Use $phpbb_path_helper. [ticket/11508] Allow equal sign in parameter value. [ticket/11508] Remove unnecessary implode. [ticket/11508] Remove unnecessary isset check. [ticket/11508] Fix build_url test. [ticket/11508] Curly brace should be on its own line... [ticket/11508] The question mark is expected even if there are no parameters. [ticket/11508] Add tests. [ticket/11508] Do not add the '?' unless there are parameters. [ticket/11508] Change separator parameter to a simple true|false $is_amp. [ticket/11508] Move helper functions to path_helper class. [ticket/11508] Move the stripping param code to separate function as well. [ticket/11508] Build the jumpbox hidden fields using the _form action_ [ticket/11508] Split parts of build_url() into reusable functions.
Diffstat (limited to 'phpBB/phpbb/path_helper.php')
-rw-r--r--phpBB/phpbb/path_helper.php116
1 files changed, 116 insertions, 0 deletions
diff --git a/phpBB/phpbb/path_helper.php b/phpBB/phpbb/path_helper.php
index fefef39c51..f92c2b72b2 100644
--- a/phpBB/phpbb/path_helper.php
+++ b/phpBB/phpbb/path_helper.php
@@ -216,4 +216,120 @@ class path_helper
return $scheme . $this->filesystem->clean_path($path);
}
+
+ /**
+ * Glue URL parameters together
+ *
+ * @param array $params URL parameters in the form of array(name => value)
+ * @return string Returns the glued string, e.g. name1=value1&amp;name2=value2
+ */
+ public function glue_url_params($params)
+ {
+ $_params = array();
+
+ foreach ($params as $key => $value)
+ {
+ $_params[] = $key . '=' . $value;
+ }
+ return implode('&amp;', $_params);
+ }
+
+ /**
+ * Get the base and parameters of a URL
+ *
+ * @param string $url URL to break apart
+ * @param bool $is_amp Is the parameter separator &amp;. Defaults to true.
+ * @return array Returns the base and parameters in the form of array('base' => string, 'params' => array(name => value))
+ */
+ public function get_url_parts($url, $is_amp = true)
+ {
+ $separator = ($is_amp) ? '&amp;' : '&';
+ $params = array();
+
+ if (strpos($url, '?') !== false)
+ {
+ $base = substr($url, 0, strpos($url, '?'));
+ $args = substr($url, strlen($base) + 1);
+ $args = ($args) ? explode($separator, $args) : array();
+
+ foreach ($args as $argument)
+ {
+ if (empty($argument))
+ {
+ continue;
+ }
+ list($key, $value) = explode('=', $argument, 2);
+
+ if ($key === '')
+ {
+ continue;
+ }
+
+ $params[$key] = $value;
+ }
+ }
+ else
+ {
+ $base = $url;
+ }
+
+ return array(
+ 'base' => $base,
+ 'params' => $params,
+ );
+ }
+
+ /**
+ * Strip parameters from an already built URL.
+ *
+ * @param string $url URL to strip parameters from
+ * @param array|string $strip Parameters to strip.
+ * @param bool $is_amp Is the parameter separator &amp;. Defaults to true.
+ * @return string Returns the new URL.
+ */
+ public function strip_url_params($url, $strip, $is_amp = true)
+ {
+ $url_parts = $this->get_url_parts($url, $is_amp);
+ $params = $url_parts['params'];
+
+ if (!is_array($strip))
+ {
+ $strip = array($strip);
+ }
+
+ if (!empty($params))
+ {
+ // Strip the parameters off
+ foreach ($strip as $param)
+ {
+ unset($params[$param]);
+ }
+ }
+
+ return $url_parts['base'] . (($params) ? '?' . $this->glue_url_params($params) : '');
+ }
+
+ /**
+ * Append parameters to an already built URL.
+ *
+ * @param string $url URL to append parameters to
+ * @param array $new_params Parameters to add in the form of array(name => value)
+ * @param string $is_amp Is the parameter separator &amp;. Defaults to true.
+ * @return string Returns the new URL.
+ */
+ public function append_url_params($url, $new_params, $is_amp = true)
+ {
+ $url_parts = $this->get_url_parts($url, $is_amp);
+ $params = array_merge($url_parts['params'], $new_params);
+
+ // Move the sid to the end if it's set
+ if (isset($params['sid']))
+ {
+ $sid = $params['sid'];
+ unset($params['sid']);
+ $params['sid'] = $sid;
+ }
+
+ return $url_parts['base'] . (($params) ? '?' . $this->glue_url_params($params) : '');
+ }
}