[ticket/11508] Move the stripping param code to separate function as well.

PHPBB3-11508
This commit is contained in:
Cesar G 2013-11-11 15:45:02 -08:00
parent ef4202d859
commit e1c6b40ee8

View file

@ -2368,28 +2368,13 @@ function build_url($strip_vars = false)
// Append SID // Append SID
$redirect = append_sid($page, false, false); $redirect = append_sid($page, false, false);
$basic_parts = phpbb_get_url_parts($redirect, '&');
$params = $basic_parts['params'];
// Strip vars...
if ($strip_vars !== false) if ($strip_vars !== false)
{ {
if (!is_array($strip_vars)) $redirect = phpbb_strip_url_params($redirect, $strip_vars, '&');
{
$strip_vars = array($strip_vars);
} }
// Strip the vars off return $redirect;
foreach ($strip_vars as $strip)
{
if (isset($params[$strip]))
{
unset($params[$strip]);
}
}
}
return $basic_parts['base'] . (($params) ? '?' . phpbb_glue_url_params($params) : '');
} }
/** /**
@ -2449,15 +2434,48 @@ function phpbb_glue_url_params($params) {
return implode('&', $_params); return implode('&', $_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 &
* @return string Returns the new URL.
*/
function phpbb_strip_url_params($url, $strip, $separator = '&') {
$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. * Append parameters to an already built URL.
* *
* @param string $url URL to append parameters to * @param string $url URL to append parameters to
* @param array $new_params Parameters to add in the form of array(name => value) * @param array $new_params Parameters to add in the form of array(name => value)
* @param string $separator Parameter separator. Defaults to &
* @return string Returns the new URL. * @return string Returns the new URL.
*/ */
function phpbb_append_url_params($url, $new_params) { function phpbb_append_url_params($url, $new_params, $separator = '&') {
$url_parts = phpbb_get_url_parts($url); $url_parts = phpbb_get_url_parts($url, $separator);
$params = array_merge($url_parts['params'], $new_params); $params = array_merge($url_parts['params'], $new_params);
// Move the sid to the end if it's set // Move the sid to the end if it's set