Cleanup URL and retrieve the final url to be called.

@param string $url

@return string
176118
private function cleanupUrl($url)
    {
        // rewrite part of urls to something more readable
        foreach ($this->config['rewrite_url'] as $find => $action) {
            if (false !== strpos($url, $find) && \is_array($action)) {
                $url = strtr($url, $action);
            }
        }

        // convert fragment to actual query parameters
        if ($fragmentPos = strpos($url, '#!')) {
            $fragment = parse_url($url, PHP_URL_FRAGMENT);
            // strip '!'
            $fragment = substr($fragment, 1);
            $query = ['_escaped_fragment_' => $fragment];

            // url without fragment
            $url = substr($url, 0, $fragmentPos);
            $url .= parse_url($url, PHP_URL_QUERY) ? '&' : '?';
            // needed for some sites
            $url .= str_replace('%2F', '/', http_build_query($query));
        }

        // remove fragment
        if ($pos = strpos($url, '#')) {
            $url = substr($url, 0, $pos);
        }

        return $url;
    }
67891
protected function removeQueryFromUrl(string $url): string
    {
        $queryPathPosition = \mb_strpos($url, '?');

        if ($queryPathPosition !== false) {
            return \mb_substr($url, 0, $queryPathPosition);
        }

        return $url;
    }
422970
private function getHostFromUrl($url)
    {
        if (strpos($url, '//')) {
            $url = substr($url, strpos($url, '//') + 2);
        }
        if (($p = strpos($url, '/')) !== false) {
            $url = substr($url, 0, $p);
        }
        return $url;
    }
967625
public static function segmentizeUrl($url)
        {
            $url = self::normalizeUrl($url);
            $segments = explode('/', $url);

            $result = array();

            foreach ($segments as $segment) {
                if (strlen($segment)) $result[] = $segment;
            }

            return $result;
        }
177486
protected function parseUrl($url) : string
    {
        // Ignore if its a valid url already, or an anchor link
        if (is_string($url) &&
            (filter_var($url, FILTER_VALIDATE_URL) !== false || Str::startsWith($url, '#'))) {
            return $url;
        }


        return $this->url->url($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);
    }
242659
private function cleanURL(string $url = '')
    {
        $url = str_replace(' ', '-', $url); 				// Replaces all spaces with hyphens
        $url = preg_replace('/[^A-Za-z0-9\/\-]+/', '-', $url);	// Replaces special characters with hyphens

        // remove "/" prefix on generated URL
        if (substr($url, 0, 1) == '/') {
            return preg_replace('/\//', '', $url, 1);
        }

        return $url;
    }
442424
protected function strip_base_url($url) {
        if (substr($url, 0, strlen($this->baseUrl)) == $this->baseUrl) {
            return substr($url, strlen($this->baseUrl));
        }
        return null;
    }
304716
public function url($url)
    {
        if (\is_string($url)) {
            if ('/' == $url[0]) {
                return $this->getPathToRoot().ltrim($url, '/');
            } elseif (\is_string($url)) {
                return $url;
            }
        } elseif ($url instanceof ClassDefinition) {
            return $this->url(Documentation::classUrl($url));
        } elseif ($url instanceof CompilerFile) {
            return $this->url(Documentation::classUrl($url->getClassDefinition()));
        }

        return '';
    }
760777
protected function splitUrl($url)
    {
        $path = parse_url(trim($url, '/'), PHP_URL_PATH);
        return $path ? explode('/', $path) : array();
    }
1041424
public function convenienceDELETE($url) {
        try {
            $url = $this->url . $url;
            return  new Context\Context($this->restRequest($url, 'DELETE')->getResponseBody());
        } catch (Exception $e) {
            var_dump($e);
        }
    }
241440
public function absolutizeUrl($url)
    {
        if (!$this->_baseUrl || preg_match('#^https?://#i', $url) || strpos($url, 'javascript:') === 0) {
            return $url;
        }

        if ($url === '') {
            return $this->_baseUrl;
        } elseif ($url[0] === '/') {
            return substr($this->_baseUrl, 0, strpos($this->_baseUrl, '/', 10)) . $url;
        } elseif ($url[0] === '#') {
            if (($pos = strrpos($this->_sourceUrl, '#')) === false) {
                return $this->_sourceUrl . $url;
            } else {
                return substr($this->_sourceUrl, 0, $pos) . $url;
            }
        } else {
            return substr($this->_baseUrl, 0, strrpos($this->_baseUrl, '/', 10) + 1) . $url;
        }
    }
347777
public static function getDomainFromURL($url)
	{
		$url = str_replace(self::getProtocolFromURL($url) . '://', '', $url);
		
		return explode('/', $url)[0];
	}
298226
public function checkLink($url)
    {
        $url = trim($url);
        if (substr($url, 0, 7 ) == "http://") return $url;

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

        return "http://".$url;
    }
354227
public function normalizeUrl($url)
    {
        $url = trim($url, '/') .'/';

        // if the page is the index page then hide it from the menu
        if (strpos(strtolower($url), '/index.md/')) {
            $url = substr($url, 0, strpos($url, "index.md/"));
        }

        return $url;
    }
1227713
public function purgeUrl ($url = null)
    {
        $apiKey = $this->settings->apiKey;

        Craft::trace(
            Craft::t(
                'imgix',
                'Purging asset: {url}', [ 'url' => $url ]
            ),
            'imgix');

        try {
            $client = Craft::createGuzzleClient([ 'timeout' => 30, 'connect_timeout' => 30 ]);

            $response = $client->post(self::IMGIX_PURGE_ENDPOINT, [
                'auth'        => [
                    $apiKey, ''
                ],
                'form_params' => [
                    'url' => $url,
                ]
            ]);

            Craft::trace(
                Craft::t(
                    'imgix',
                    'Purged asset: {url} - Status code {statusCode}', [
                        'url'        => $url,
                        'statusCode' => $response->getStatusCode()
                    ]
                ),
                'imgix');

            return $response->getStatusCode() >= 200 && $response->getStatusCode() < 400;
        }
        catch (RequestException $e) {
            Craft::error(
                Craft::t(
                    'imgix',
                    'Failed to purge {url}: {statusCode} {error}', [
                        'url'        => $url,
                        'error'      => $e->getMessage(),
                        'statusCode' => $e->getResponse()->getStatusCode() ]
                ),
                'imgix'
            );

            return false;
        }
    }
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;
    }