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;
135 $url = str_replace(
' ',
'%20',
$url);
137 if ($this->isValidMultiByteUrl(
$url)) {
140 $protocol_less_site_url = rtrim($protocol_less_site_url,
'/');
141 $protocol_less_site_url = str_replace(
'/',
'\/', $protocol_less_site_url);
147 if (preg_match(
'#^([a-z]+)\\:#',
$url, $matches)) {
150 if ($matches[1] !==
'http' && $matches[1] !==
'https') {
155 if (preg_match(
'#^(\\#|\\?|//)#',
$url)) {
160 if (preg_match(
'#^[^/]*\\.php(\\?.*)?$#',
$url)) {
166 if (preg_match(
'#^[^/?]*\\.#',
$url)) {
168 return "http://{$url}";
190 public function isUrlIdentical(
string $url1,
string $url2, array $ignore_params): bool {
191 $url1 = $this->normalizeUrl($url1);
192 $url2 = $this->normalizeUrl($url2);
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]);
256 $diff_count = count($this->arrayDiffAssocRecursive($url1_params, $url2_params));
257 $diff_count += count($this->arrayDiffAssocRecursive($url2_params, $url1_params));
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);
Create, sanitize and compare urls.
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().
static isValidMultiByteUrl(string $url)
Use a "fixed" filter_var() with FILTER_VALIDATE_URL that handles multi-byte chars.
arrayDiffAssocRecursive()
Computes the difference of arrays with additional index check.
addActionTokensToUrl(string $url, bool $html_encode=false)
Adds action tokens to URL.
isUrlIdentical(string $url1, string $url2, array $ignore_params)
Test if two URLs are functionally identical.
normalizeUrl(string $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.