public static function encodeUrl($strUrl)
{
if ($strUrl == '') {
return '';
}
// Empty anchor (see #3555)
if ($strUrl == '#') {
return $strUrl;
}
// E-mail address
if (strncasecmp($strUrl, 'mailto:', 7) === 0) {
return static::encodeEmail($strUrl);
}
$arrUrl = parse_url($strUrl);
// Add the scheme to ensure that parse_url works correctly
if (!isset($arrUrl['scheme']) && strncmp($strUrl, '{{', 2) !== 0) {
$arrUrl = parse_url('http://' . $strUrl);
unset($arrUrl['scheme']);
}
// Scheme
if (isset($arrUrl['scheme'])) {
$arrUrl['scheme'] .= substr($strUrl, strlen($arrUrl['scheme']), 3) == '://' ? '://' : ':';
}
// User
if (isset($arrUrl['user'])) {
$arrUrl['user'] .= isset($arrUrl['pass']) ? ':' : '@';
}
// Password
if (isset($arrUrl['pass'])) {
$arrUrl['pass'] .= '@';
}
// Host
if (isset($arrUrl['host'])) {
$arrUrl['host'] = static::encode($arrUrl['host']);
}
// Port
if (isset($arrUrl['port'])) {
$arrUrl['port'] = ':' . $arrUrl['port'];
}
// Path does not have to be altered
// Query
if (isset($arrUrl['query'])) {
$arrUrl['query'] = '?' . $arrUrl['query'];
}
// Anchor
if (isset($arrUrl['fragment'])) {
$arrUrl['fragment'] = '#' . $arrUrl['fragment'];
}
return $arrUrl['scheme'] . $arrUrl['user'] . $arrUrl['pass'] . $arrUrl['host'] . $arrUrl['port'] . $arrUrl['path'] . $arrUrl['query'] . $arrUrl['fragment'];
}