Prepare url to place in <loc> tag

@param string $url original url

@return string
166196
public static function prepareUrl($url)
    {
        // $url = urlencode($url);

        $replacement = [
            '&' => '&amp;',
            "'" => '&apos;',
            '"' => '&quot;',
            '>' => '&gt;',
            '<' => '&lt;',
        ];

        $url = str_replace(array_keys($replacement), array_values($replacement), $url);

        return $url;
    }
290305
public function prepareURLForPersist($url)
    {
        if (substr($url, 0, 7 ) == "http://") return $url;

        if (substr($url, 0, 8 ) == "https://") return $url;

        $washedUrl  = "http://";
        $washedUrl .= $url;

        return $url;
    }
1066982
protected function expandUrl($url)
    {
        // skip if no short url
        if (!ParserUtil::isShortUrl($url)) {
            return $url;
        }

        $header_location = get_headers($url, 1)['Location'];

        return $header_location ?: $url;
    }
466730
public static function normalizeUrl($url)
    {
        foreach (self::$urlPrefixMap as $prefix => $id) {
            if (strtolower(substr($url, 0, strlen($prefix))) == $prefix) {
                return array(
                    'url'      => substr($url, strlen($prefix)),
                    'prefixId' => $id
                );
            }
        }

        return array('url' => $url, 'prefixId' => null);
    }
1039619
public function getPathFromUrl($url)
    {
        $basename = $this->storageUrl ? basename($this->storageUrl) : basename($this->storageDir);
        $basename && $url = preg_replace("/(.*$basename\/)/", '', $url);
        return $url;
    }
20084
public static function base($url) {
        if (preg_match('#^(/|(ht|f)tps?://).+#', $url)) {
            return $url;
        }
        $url = preg_replace('#/?index\.html?$#', '', $url);

        return WWWROOT_DIR . $url;
    }
283127
private function fixUriParts($url)
    {
        $position = Str::strpos($url, '?') ?: Str::strpos($url, '#');

        if ($position === false) {
            return $url;
        }

        return Str::substr($url, 0, $position) . '/' . Str::substr($url, $position);
    }
842499
protected function patchUrl($url)
    {
        if (substr($url, 0, 1) !== '/' && !preg_match('#^[a-zA-Z0-9]+://#', $url)) {
            $url = \JUri::base(true) . '/' . $url;
        }

        $patched = false;
        $base = \JUri::base(false, false);
        if (stripos($url, $base) === 0) {
            $patched = true;
            $url = substr($url, strlen($base));
        } else {
            $base = \JUri::base(true, false);
            if (stripos($url, $base) === 0) {
                $patched = true;
                $url = substr($url, strlen($base));
            }
        }

        if ($patched) {
            $url = self::$helper->getUrl($url);
        }

        return $url;
    }
1348129
private function parseUrl($url)
    {
        $parsed = parse_url($url);

        if ((count($parsed) === 1)
            && isset($parsed['path'])
            && (0 === strpos($parsed['path'], '?') || false !== strpos($parsed['path'], '&'))
        ) {
            $parsed = array(
                'query' => $parsed['path']
            );

            return $parsed;
        }

        return $parsed;
    }
1314137
private function applyBaseUrl(string $url): string
    {
        if ($this->baseUrl === null) {
            return $url;
        }

        if (substr($url, 0, 7) === "http://") {
            return $url;
        }

        if (substr($url, 0, 8) === "https://") {
            return $url;
        }

        $baseUrl = $this->baseUrl;

        if (substr($url, 0, 1) === "/") {
            $path = parse_url($baseUrl, \PHP_URL_PATH);
            if ($path !== null) {
                $baseUrl = substr($baseUrl, 0, strlen($path) * -1);
            }
        }

        return "{$baseUrl}/" . ltrim($url, "/");
    }
69551
protected function buildUrl($url)
    {
        if (strpos($url, '://') || 0 === strpos($url, '/')) {
            return $url;
        } elseif ($url === '') {
            return $url;
        } else {
            return Url::build($url);
        }
    }
1004014
protected function createUri($url)
	{
		if ($url instanceof Uri)
		{
			return $url;
		}

		// Create full URL if we are only appending variables to it
		if (substr($url, 0, 1) == '&')
		{
			$vars = array();

			if (strpos($url, '&amp;') !== false)
			{
				$url = str_replace('&amp;', '&', $url);
			}

			parse_str($url, $vars);

			$vars = array_merge($this->vars(), $vars);

			foreach ($vars as $key => $var)
			{
				if ($var == '')
				{
					unset($vars[$key]);
				}
			}

			$url = 'index.php?' . urldecode(http_build_query($vars, '', '&'));
		}

		return new Uri($url);
	}
1235569
public static function buildUrl($url) {
		if (!is_array($url)) {
			return $url;
		}

		foreach (self::$_urlNotations as $part => $rules) {
			if (array_key_exists($part, $url)) {
				$url[$part] = @$rules['before'] . $url[$part] . @$rules['after'];
			}
		}

		return array_reduce($url,  function($return, $item) {
			$return .= $item;

			return $return;
		});
	}
548823
public static function url($url){

		$url = static::_nullValue($url);
		if(!$url){

			return $url;
		}

		$query = parse_url($url, PHP_URL_QUERY);
		if(!$query){

			return $url;
		}

		parse_str($query, $query_parts);

		// First urldecode to be sure that we do not re-encode the query parts.
		$query_parts = array_map('static::_nested_urldecode', $query_parts);

		// http_build_query will take care of the urlencode.
		return strtok($url, '?') . '?' . http_build_query($query_parts);
	}
1066746
public static function urlToPath($url)
    {
        $path = str_replace('http://', '', $url);
        $path = str_replace('https://', '', $path);
        $path = str_replace($_SERVER['HTTP_HOST'], '', $path);

        if (substr($path, 0, 1) == '/') {
            $path = substr($path, 1);
        }

        return $_SERVER['DOCUMENT_ROOT'] . '/' . $path;
    }
991018
protected function fetchUrl(string $url): string
    {
        $curl = curl_init($url);
        curl_setopt_array($curl, [
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_TIMEOUT => $this->timeOut
        ]);
        $data = curl_exec($curl);
        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $error = curl_error($curl);
        curl_close($curl);

        if ($error) {
            throw new FetchFailedException(sprintf("A cURL error occurred for \"%s\": %s", $url, $error));
        }

        if ($statusCode !== 200) {
            throw new FetchFailedException(sprintf("URL \"%s\" responded with status code %d.", $url, $statusCode));
        }

        if (!$data) {
            throw new FetchFailedException(sprintf("URL \"%s\" returned no data.", $url));
        }

        return $data;
    }
502252
protected function parseUrl($url = "")
    {
        $parsed = ($url) ? parse_url($url) : parse_url($this->_env['REQUEST_URI']);
        
        if (preg_match('/[a-zA-Z0-9_]+\.php/i', $parsed['path'], $matches)) {
            $parsed['path'] = preg_replace("/$matches[0]/", '/', $parsed['path']);
        }
        
        return $parsed;
    }