Converts shorthand URLs to absolute URLs, unless the given URL is absolute, protocol-relative, or starts with a protocol/fragment/queryelgg_normalize_url(''); // 'http://my.site.com/' elgg_normalize_url('dashboard'); // 'http://my.site.com/dashboard' elgg_normalize_url('http://google.com/'); // no change elgg_normalize_url('//google.com/'); // no change
<?php
class Urls {
$url_array = parse_url($url);
if (isset($url_array['query'])) {
} else {
}
foreach ($elements as $k => $v) {
if ($v === null) {
} else {
}
}
if (
$query || empty($url_array[
'path'])) {
$url_array[
'query'] = http_build_query(
$query);
} else {
unset($url_array['query']);
}
$string = $this->
buildUrl($url_array,
false);
if (!isset($url_array['scheme']) && (str_starts_with($url, '//'))) {
$string = "//{$string}";
}
return $string;
}
$components = parse_url($url);
if (isset($components['query'])) {
} else {
}
}
$components[
'query'] = http_build_query(
$query);
return $this->
buildUrl($components, $html_encode);
}
public function buildUrl(array $parts,
bool $html_encode =
true): string {
$scheme = isset($parts['scheme']) ? "{$parts['scheme']}://" : '';
$host = isset($parts['host']) ? "{$parts['host']}" : '';
$port = isset($parts['port']) ? ":{$parts['port']}" : '';
$path = isset($parts[
'path']) ?
"{$parts['path']}" :
'';
$query = isset($parts[
'query']) ?
"?{$parts['query']}" :
'';
$fragment = isset($parts['fragment']) ? "#{$parts['fragment']}" : '';
$string = $scheme . $host . $port .
$path .
$query . $fragment;
return $html_encode ? htmlspecialchars($string, ENT_QUOTES, 'UTF-8', false) : $string;
}
$protocol_less_site_url =
rtrim($protocol_less_site_url,
'/');
$protocol_less_site_url =
str_replace(
'/',
'\/', $protocol_less_site_url);
return preg_replace(
"/^https?{$protocol_less_site_url}\/?/i",
elgg_get_site_url(), $url);
}
$matches = [];
if (
preg_match(
'#^([a-z]+)\\:#', $url, $matches)) {
if ($matches[1] !== 'http' && $matches[1] !== 'https') {
}
}
}
if (
preg_match(
'#^[^/]*\\.php(\\?.*)?$#', $url)) {
}
return "http://{$url}";
}
}
public function isUrlIdentical(
string $url1,
string $url2, array $ignore_params): bool {
if ($url1 === $url2) {
return true;
}
$url1_info = parse_url($url1);
$url2_info = parse_url($url2);
if (isset($url1_info['path'])) {
$url1_info[
'path'] =
trim($url1_info[
'path'],
'/');
}
if (isset($url2_info['path'])) {
$url2_info[
'path'] =
trim($url2_info[
'path'],
'/');
}
$parts = ['scheme', 'host', 'path'];
foreach ($parts as $part) {
if (isset($url1_info[$part], $url2_info[$part]) && $url1_info[$part] !== $url2_info[$part]) {
return false;
}
elseif (isset($url1_info[$part]) && !isset($url2_info[$part])) {
return false;
}
elseif (!isset($url1_info[$part]) && isset($url2_info[$part])) {
return false;
}
}
if (isset($url1_info['query'], $url2_info['query']) && $url1_info['query'] === $url2_info['query']) {
return true;
}
$url1_params = [];
$url2_params = [];
if (isset($url1_info['query'])) {
$url1_info['query'] = html_entity_decode($url1_info['query']);
}
}
if (isset($url2_info['query'])) {
$url2_info['query'] = html_entity_decode($url2_info['query']);
}
}
foreach ($ignore_params as $param) {
unset($url1_params[$param]);
unset($url2_params[$param]);
}
if ($diff_count > 0) {
return false;
}
return true;
}
if (filter_var($url, FILTER_VALIDATE_URL) !== false) {
return true;
}
return false;
}
$s = '';
for ($i = 0; $i < $l; ++$i) {
$s .= (
strlen($ch) > 1) ?
'X' : $ch;
}
return (bool) filter_var($s, FILTER_VALIDATE_URL);
}
$diff = [];
foreach (array_shift(
$args) as
$key => $val) {
if (is_array($val)) {
$j++;
} else {
}
$j++;
}
}
if (is_array($val)) {
$tmp = call_user_func_array([$this, 'arrayDiffAssocRecursive'], $tmp);
if (!empty($tmp)) {
}
}
elseif ($j == $count && $count) {
}
}
return $diff;
}
}