23 $url_array = parse_url($url);
25 if (isset($url_array[
'query'])) {
31 foreach ($elements as $k => $v) {
42 if (
$query || empty($url_array[
'path'])) {
43 $url_array[
'query'] = http_build_query(
$query);
45 unset($url_array[
'query']);
48 $string = $this->
buildUrl($url_array,
false);
51 if (!isset($url_array[
'scheme']) && (str_starts_with($url,
'//'))) {
52 $string =
"//{$string}";
71 $components = parse_url($url);
73 if (isset($components[
'query'])) {
79 if (isset(
$query[
'__elgg_ts'],
$query[
'__elgg_token'])) {
87 $components[
'query'] = http_build_query(
$query);
90 return $this->
buildUrl($components, $html_encode);
106 public function buildUrl(array $parts,
bool $html_encode =
true): string {
108 $scheme = isset($parts[
'scheme']) ?
"{$parts['scheme']}://" :
'';
109 $host = isset($parts[
'host']) ?
"{$parts['host']}" :
'';
110 $port = isset($parts[
'port']) ?
":{$parts['port']}" :
'';
111 $path = isset($parts[
'path']) ?
"{$parts['path']}" :
'';
112 $query = isset($parts[
'query']) ?
"?{$parts['query']}" :
'';
113 $fragment = isset($parts[
'fragment']) ?
"#{$parts['fragment']}" :
'';
115 $string = $scheme . $host . $port .
$path .
$query . $fragment;
117 return $html_encode ? htmlspecialchars($string, ENT_QUOTES,
'UTF-8',
false) : $string;
140 $protocol_less_site_url =
rtrim($protocol_less_site_url,
'/');
141 $protocol_less_site_url =
str_replace(
'/',
'\/', $protocol_less_site_url);
143 return preg_replace(
"/^https?{$protocol_less_site_url}\/?/i",
elgg_get_site_url(), $url);
147 if (
preg_match(
'#^([a-z]+)\\:#', $url, $matches)) {
150 if ($matches[1] !==
'http' && $matches[1] !==
'https') {
160 if (
preg_match(
'#^[^/]*\\.php(\\?.*)?$#', $url)) {
168 return "http://{$url}";
190 public function isUrlIdentical(
string $url1,
string $url2, array $ignore_params): bool {
194 if ($url1 === $url2) {
198 $url1_info = parse_url($url1);
199 $url2_info = parse_url($url2);
201 if (isset($url1_info[
'path'])) {
202 $url1_info[
'path'] =
trim($url1_info[
'path'],
'/');
205 if (isset($url2_info[
'path'])) {
206 $url2_info[
'path'] =
trim($url2_info[
'path'],
'/');
210 $parts = [
'scheme',
'host',
'path'];
212 foreach ($parts as $part) {
213 if (isset($url1_info[$part], $url2_info[$part]) && $url1_info[$part] !== $url2_info[$part]) {
215 }
elseif (isset($url1_info[$part]) && !isset($url2_info[$part])) {
217 }
elseif (!isset($url1_info[$part]) && isset($url2_info[$part])) {
223 if (isset($url1_info[
'query'], $url2_info[
'query']) && $url1_info[
'query'] === $url2_info[
'query']) {
231 if (isset($url1_info[
'query'])) {
232 $url1_info[
'query'] = html_entity_decode($url1_info[
'query']);
238 if (isset($url2_info[
'query'])) {
239 $url2_info[
'query'] = html_entity_decode($url2_info[
'query']);
246 foreach ($ignore_params as $param) {
247 unset($url1_params[$param]);
248 unset($url2_params[$param]);
258 if ($diff_count > 0) {
278 if (filter_var($url, FILTER_VALIDATE_URL) !==
false) {
284 if (
strlen($url) === $l) {
290 for ($i = 0; $i < $l; ++$i) {
292 $s .= (
strlen($ch) > 1) ?
'X' : $ch;
296 return (
bool) filter_var($s, FILTER_VALIDATE_URL);
308 $args = func_get_args();
311 foreach (array_shift(
$args) as
$key => $val) {
313 if (is_array($val)) {
324 if (is_array($val)) {
325 $tmp = call_user_func_array([$this,
'arrayDiffAssocRecursive'], $tmp);
331 }
elseif ($j == $count && $count) {
elgg_parse_str($str)
Elgg UTF-8 string functions.
buildUrl(array $parts, bool $html_encode=true)
Builds a URL from the a parts array like one returned by parse_url().
$args
Some servers don't allow PHP to check the rewrite, so try via AJAX.
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
elgg_strlen()
Wrapper function for mb_strlen().
isUrlIdentical(string $url1, string $url2, array $ignore_params)
Test if two URLs are functionally identical.
static isValidMultiByteUrl(string $url)
Use a "fixed" filter_var() with FILTER_VALIDATE_URL that handles multi-byte chars.
addActionTokensToUrl(string $url, bool $html_encode=false)
Adds action tokens to URL.
elgg_get_site_url()
Get the URL for the current (or specified) site, ending with "/".
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
elgg_substr()
Wrapper function for mb_substr().
normalizeUrl(string $url)
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
_elgg_services()
Get the global service provider.
arrayDiffAssocRecursive()
Computes the difference of arrays with additional index check.
addQueryElementsToUrl(string $url, array $elements)
Sets elements in a URL's query string.
Create, sanitize and compare urls.