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;
    }
 
    public function addActionTokensToUrl(
string $url, 
bool $html_encode = 
false): 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;
    }
    
    public function normalizeUrl(
string $url): string {
 
    
        if ($this->isValidMultiByteUrl(
$url)) {
 
            
            $protocol_less_site_url = rtrim($protocol_less_site_url, '/');
            $protocol_less_site_url = str_replace('/', '\/', $protocol_less_site_url);
    
        }
    
        $matches = [];
        if (preg_match(
'#^([a-z]+)\\:#', 
$url, $matches)) {
 
            
            
            if ($matches[1] !== 'http' && $matches[1] !== 'https') {
            }
        }
    
        if (preg_match(
'#^(\\#|\\?|//)#', 
$url)) {
 
            
        }
    
        if (preg_match(
'#^[^/]*\\.php(\\?.*)?$#', 
$url)) {
 
            
            
        }
    
        if (preg_match(
'#^[^/?]*\\.#', 
$url)) {
 
            
            return "http://{$url}";
        }
    
        
        
        
    }
    
    public function isUrlIdentical(string $url1, string $url2, array $ignore_params): bool {
        $url1 = $this->normalizeUrl($url1);
        $url2 = $this->normalizeUrl($url2);
    
        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]);
        }
    
        
        
        
        
        
        $diff_count = count($this->arrayDiffAssocRecursive($url1_params, $url2_params));
        $diff_count += count($this->arrayDiffAssocRecursive($url2_params, $url1_params));
        if ($diff_count > 0) {
            return false;
        }
    
        return true;
    }
    
    public static function isValidMultiByteUrl(
string $url): bool {
 
        
        if (filter_var(
$url, FILTER_VALIDATE_URL) !== false) {
 
            return true;
        }
    
        
        if (strlen(
$url) === $l) {
 
            return false;
        }
    
        
        $s = '';
        for ($i = 0; $i < $l; ++$i) {
            $s .= (strlen($ch) > 1) ? 'X' : $ch;
        }
    
        
        return (bool) filter_var($s, FILTER_VALIDATE_URL);
    }
    
    protected function arrayDiffAssocRecursive(): array {
        $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)) {
                }
            }
        }
        
        return $diff;
    }
}
addQueryElementsToUrl(string $url, array $elements)
Sets elements in a URL's query string.
buildUrl(array $parts, bool $html_encode=true)
Builds a URL from the a parts array like one returned by parse_url().
elgg_get_site_url()
Get the URL for the current (or specified) site, ending with "/".
foreach($plugin_guids as $guid) if(empty($deactivated_plugins)) $url
if($item instanceof \ElggEntity) elseif($item instanceof \ElggRiverItem) elseif($item instanceof \ElggRelationship) elseif(is_callable([ $item, 'getType']))
_elgg_services()
Get the global service provider.
$args
Some servers don't allow PHP to check the rewrite, so try via AJAX.
elgg_substr()
Wrapper function for mb_substr().
elgg_parse_str($str)
Elgg UTF-8 string functions.
elgg_strlen()
Wrapper function for mb_strlen().
if($container instanceof ElggGroup && $container->guid !=elgg_get_page_owner_guid()) $key
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.