aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authorCesar G <prototech91@gmail.com>2013-12-06 13:38:54 -0800
committerCesar G <prototech91@gmail.com>2014-04-22 15:21:02 -0700
commit3163388f63a6d0bac77ada86e2f1561f1d7f9714 (patch)
treecdd5acc22c8a83bf47b5048e678b2489dea9ce20 /phpBB
parente1c6b40ee82a79a58276d8e85de9c3593a6f3703 (diff)
downloadforums-3163388f63a6d0bac77ada86e2f1561f1d7f9714.tar
forums-3163388f63a6d0bac77ada86e2f1561f1d7f9714.tar.gz
forums-3163388f63a6d0bac77ada86e2f1561f1d7f9714.tar.bz2
forums-3163388f63a6d0bac77ada86e2f1561f1d7f9714.tar.xz
forums-3163388f63a6d0bac77ada86e2f1561f1d7f9714.zip
[ticket/11508] Move helper functions to path_helper class.
PHPBB3-11508
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/includes/functions.php123
-rw-r--r--phpBB/includes/functions_content.php6
-rw-r--r--phpBB/phpbb/path_helper.php115
3 files changed, 126 insertions, 118 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 71716ae6b3..9c77aa935c 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -2344,8 +2344,10 @@ function reapply_sid($url)
*/
function build_url($strip_vars = false)
{
- global $config, $user, $phpEx, $phpbb_root_path;
+ global $config, $user, $phpbb_container;
+ $path_helper = $phpbb_container->get('path_helper');
+ $php_ext = $path_helper->get_php_ext();
$page = $user->page['page'];
// We need to be cautious here.
@@ -2358,12 +2360,12 @@ function build_url($strip_vars = false)
if ($url_parts === false || empty($url_parts['scheme']) || empty($url_parts['host']))
{
// Remove 'app.php/' from the page, when rewrite is enabled
- if ($config['enable_mod_rewrite'] && strpos($page, 'app.' . $phpEx . '/') === 0)
+ if ($config['enable_mod_rewrite'] && strpos($page, 'app.' . $php_ext . '/') === 0)
{
- $page = substr($page, strlen('app.' . $phpEx . '/'));
+ $page = substr($page, strlen('app.' . $php_ext . '/'));
}
- $page = $phpbb_root_path . $page;
+ $page = $path_helper->get_phpbb_root_path() . $page;
}
// Append SID
@@ -2371,124 +2373,13 @@ function build_url($strip_vars = false)
if ($strip_vars !== false)
{
- $redirect = phpbb_strip_url_params($redirect, $strip_vars, '&');
+ $redirect = $path_helper->strip_url_params($redirect, $strip_vars, '&');
}
return $redirect;
}
/**
-* Get the base and parameters of a URL
-*
-* @param string $url URL to break apart
-* @param string $separator Parameter separator. Defaults to &amp;
-* @return array Returns the base and parameters in the form of array('base' => string, 'params' => array(name => value))
-*/
-function phpbb_get_url_parts($url, $separator = '&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)
- {
- $arguments = explode('=', $argument);
- $key = $arguments[0];
- unset($arguments[0]);
-
- if ($key === '')
- {
- continue;
- }
-
- $params[$key] = implode('=', $arguments);
- }
- }
- else
- {
- $base = $url;
- }
-
- return array(
- 'base' => $base,
- 'params' => $params,
- );
-}
-
-/**
-* Glue URL parameters together
-*
-* @param array $params URL parameters in the form of array(name => value)
-* @return string Returns the glued string.
-*/
-function phpbb_glue_url_params($params) {
- $_params = array();
-
- foreach ($params as $key => $value)
- {
- $_params[] = $key . '=' . $value;
- }
- return implode('&amp;', $_params);
-}
-
-/**
-* Strip parameters from an already built URL.
-*
-* @param string $url URL to strip parameters from
-* @param array|string $strip Parameters to strip.
-* @param string $separator Parameter separator. Defaults to &amp;
-* @return string Returns the new URL.
-*/
-function phpbb_strip_url_params($url, $strip, $separator = '&amp;') {
- $url_parts = phpbb_get_url_parts($url, $separator);
- $params = $url_parts['params'];
-
- if (!is_array($strip))
- {
- $strip = array($strip);
- }
-
- if (!empty($params))
- {
- // Strip the parameters off
- foreach ($strip as $param)
- {
- if (isset($params[$param]))
- {
- unset($params[$param]);
- }
- }
- }
-
- return $url_parts['base'] . (($params) ? '?' . phpbb_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 $separator Parameter separator. Defaults to &amp;
-* @return string Returns the new URL.
-*/
-function phpbb_append_url_params($url, $new_params, $separator = '&amp;') {
- $url_parts = phpbb_get_url_parts($url, $separator);
- $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'] . '?' . phpbb_glue_url_params($params);
-}
-
-/**
* Meta refresh assignment
* Adds META template variable with meta http tag.
*
diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php
index 387695a9e8..ff75a5b05d 100644
--- a/phpBB/includes/functions_content.php
+++ b/phpBB/includes/functions_content.php
@@ -110,7 +110,7 @@ function gen_sort_selects(&$limit_days, &$sort_by_text, &$sort_days, &$sort_key,
*/
function make_jumpbox($action, $forum_id = false, $select_all = false, $acl_list = false, $force_display = false)
{
- global $config, $auth, $template, $user, $db;
+ global $config, $auth, $template, $user, $db, $phpbb_container;
// We only return if the jumpbox is not forced to be displayed (in case it is needed for functionality)
if (!$config['load_jumpbox'] && $force_display === false)
@@ -195,7 +195,9 @@ function make_jumpbox($action, $forum_id = false, $select_all = false, $acl_list
}
$db->sql_freeresult($result);
unset($padding_store);
- $url_parts = phpbb_get_url_parts($action);
+
+ $path_helper = $phpbb_container->get('path_helper');
+ $url_parts = $path_helper->get_url_parts($action);
$template->assign_vars(array(
'S_DISPLAY_JUMPBOX' => $display_jumpbox,
diff --git a/phpBB/phpbb/path_helper.php b/phpBB/phpbb/path_helper.php
index fefef39c51..ff36ce5fc5 100644
--- a/phpBB/phpbb/path_helper.php
+++ b/phpBB/phpbb/path_helper.php
@@ -216,4 +216,119 @@ 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 string $separator Parameter separator. Defaults to &amp;
+ * @return array Returns the base and parameters in the form of array('base' => string, 'params' => array(name => value))
+ */
+ public function get_url_parts($url, $separator = '&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)
+ {
+ $arguments = explode('=', $argument);
+ $key = $arguments[0];
+ unset($arguments[0]);
+
+ if ($key === '')
+ {
+ continue;
+ }
+
+ $params[$key] = implode('=', $arguments);
+ }
+ }
+ 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 string $separator Parameter separator. Defaults to &amp;
+ * @return string Returns the new URL.
+ */
+ public function strip_url_params($url, $strip, $separator = '&amp;')
+ {
+ $url_parts = $this->get_url_parts($url, $separator);
+ $params = $url_parts['params'];
+
+ if (!is_array($strip))
+ {
+ $strip = array($strip);
+ }
+
+ if (!empty($params))
+ {
+ // Strip the parameters off
+ foreach ($strip as $param)
+ {
+ if (isset($params[$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 $separator Parameter separator. Defaults to &amp;
+ * @return string Returns the new URL.
+ */
+ public function append_url_params($url, $new_params, $separator = '&amp;')
+ {
+ $url_parts = $this->get_url_parts($url, $separator);
+ $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'] . '?' . $this->glue_url_params($params);
+ }
}