Returns the actual url through which a script is served.

@param moodle_url|string $url full moodle url, or shortened path to script
@return moodle_url
481768
protected function js_fix_url($url) {
        global $CFG;

        if ($url instanceof moodle_url) {
            return $url;
        } else if (strpos($url, '/') === 0) {
            // Fix the admin links if needed.
            if ($CFG->admin !== 'admin') {
                if (strpos($url, "/admin/") === 0) {
                    $url = preg_replace("|^/admin/|", "/$CFG->admin/", $url);
                }
            }
            if (debugging()) {
                // Check file existence only when in debug mode.
                if (!file_exists($CFG->dirroot . strtok($url, '?'))) {
                    throw new coding_exception('Attempt to require a JavaScript file that does not exist.', $url);
                }
            }
            if (substr($url, -3) === '.js') {
                $jsrev = $this->get_jsrev();
                if (empty($CFG->slasharguments)) {
                    return new moodle_url('/lib/javascript.php', array('rev'=>$jsrev, 'jsfile'=>$url));
                } else {
                    $returnurl = new moodle_url('/lib/javascript.php');
                    $returnurl->set_slashargument('/'.$jsrev.$url);
                    return $returnurl;
                }
            } else {
                return new moodle_url($url);
            }
        } else {
            throw new coding_exception('Invalid JS url, it has to be shortened url starting with / or moodle_url instance.', $url);
        }
    }
352767
public function getUrlRacine()
    {
        $protocol = empty($_SERVER["HTTPS"])?"http":"https";
        if (isset($_SERVER["SERVER_NAME"])) {
            $dirname=dirname($_SERVER["PHP_SELF"]);
            if (basename($dirname)=="script") {
                $dirname = dirname($dirname);
            }
        } else {
            $dirname="";
        }
        $url =$protocol."://".$this->getNomServeur().
        $dirname;
        if ($dirname!="/") {
            $url.="/";
        }
        return $url;
    }
753219
public function getLogoFromUrl($url)
    {
        $pathInPiwik  = 'plugins/Morpheus/icons/dist/searchEngines/%s.png';
        $pathWithCode = sprintf($pathInPiwik, $this->getHostFromUrl($url));
        $absolutePath = PIWIK_INCLUDE_PATH . '/' . $pathWithCode;
        if (file_exists($absolutePath)) {
            return $pathWithCode;
        }
        return sprintf($pathInPiwik, 'xx');
    }
279701
private function getPath($url)
    {
        $url = trim($url);
        $parsed = $this->parseURL($url);
        if ($parsed !== false) {
            $this->url = $url;
            return $parsed['custom'];
        }
        return $url;
    }
865368
static public function getRootUrl($url=null)
	{
	    if (!$url || strpos($url, '://') === false) {
            $schema = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https://' : 'http://';
            $domain = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : getenv('HTTP_HOST');
            $domain = static::GetRootDomain($domain);
            $baseUrl = $domain ? $schema . $domain : '';
            $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : null;
	    } else {
	        $parts = parse_url($url);
	        $domain = static::GetRootDomain($parts['host']);
	        $baseUrl = $parts['scheme'] . '://' . $domain;
	        $port = isset($parts['port']) ? $parts['port'] : '';
	    }
	    if ($port && $port != 80 && $port != 443) {
	        $baseUrl .= ':'.$port;
	    }
	    
	    return $baseUrl;
	}
981034
protected function urlParts(string $url)
    {
        if (false === filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)) {
            return false;
        }
        return parse_url($url) ?: false;
    }
989552
protected function parseURL($url)
    {
        $parsed = parse_url($url);
        if ($parsed === false) {
            return false;
        } elseif (!isset($parsed['scheme']) || !$this->isValidScheme($parsed['scheme'])) {
            return false;
        } else {
            if (!isset($parsed['host']) || !$this->isValidHostName($parsed['host'])) {
                return false;
            } else {
                if (!isset($parsed['port'])) {
                    $parsed['port'] = getservbyname($parsed['scheme'], 'tcp');
                    if (!is_int($parsed['port'])) {
                        return false;
                    }
                }
            }
        }
        $parsed['custom'] = (isset($parsed['path']) ? $parsed['path'] : '/') . (isset($parsed['query']) ? '?' . $parsed['query'] : '');
        return $parsed;
    }
972355
protected function log_convert_url(moodle_url $fullurl) {
        static $baseurl;

        if (!isset($baseurl)) {
            $baseurl = new moodle_url('/mod/workshop/');
            $baseurl = $baseurl->out();
        }

        return substr($fullurl->out(), strlen($baseurl));
    }
1028745
protected function _getUrl($url, $rel = false)
    {
        if (!is_array($url)) {
            $url = ltrim($url, '/');
            $url = '/' . $url;
        }
        if ($rel !== false) {
            $url = Router::url($url);
        }
        return $url;
    }
81774
private function getUrl(string $url): string
    {
        $urlParts = parse_url($url);

        if ($urlParts === false) {
            throw new \ParseError("Could not parse URL: $url");
        }

        if ($this->baseUrl !== null && ! isset($urlParts['host'])) {
            $url = $this->baseUrl . '/' . ltrim($url, '/');
        }

        return $url;
    }
1189820
public function url($url)
    {
        if (is_string($url)) {
            $url = $this->localePrefix($url);
        }

        try {
            $url = Router::url($url, true);
        } catch (\Exception $ex) {
            $url = '';
        }

        return $url;
    }
596944
public function get_filename(moodle_url $url) {
        // Use the 'file' parameter if provided (for links created when
        // slasharguments was off). If not present, just use URL path.
        $path = $url->get_param('file');
        if (!$path) {
            $path = $url->get_path();
        }

        // Remove everything before last / if present. Does not use textlib as / is UTF8-safe.
        $slash = strrpos($path, '/');
        if ($slash !== false) {
            $path = substr($path, $slash + 1);
        }
        return $path;
    }
1031248
public function get_extension(moodle_url $url) {
        // Note: Does not use core_text (. is UTF8-safe).
        $filename = self::get_filename($url);
        $dot = strrpos($filename, '.');
        if ($dot === false) {
            return '';
        } else {
            return strtolower(substr($filename, $dot + 1));
        }
    }
1338982
public function getRoute($url)
    {
        $routes = $this->_route->getRoutes();
        $return = '';
        foreach ($routes as $route) {
            $routeURI = $this->_config->from('app')->get('basepath').$route['uri'];

            // POST requests
            if (isset($_POST)) {
                foreach ($_POST as $key => $value) {
                    $route['query'][] = [$key => $value];
                }
            }

            // GET requests
            $getexp = explode('?', $_SERVER['REQUEST_URI']);
            if (isset($getexp[1])) {
                if (implode('?', $getexp) == $routeURI.'?'.$getexp[1]) {
                    $route['querystring'] = $getexp[1];
                    $qexp = explode('&', $route['querystring']);
                    foreach ($qexp as $q) {
                        $i = explode('=', $q);
                        $route['query'][] = [$i[0] => $i[1]];
                    }
                }
            }

            // For handling routes with variables
            $expressionExp = explode('/', $route['uri']);
            $serveruri = '/'.substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], $expressionExp[1]));
            $serveruriexp = explode('/', $serveruri);

            for ($i = 0; $i < count($expressionExp); $i++) {
                $expressionExp[$i] = preg_replace_callback('/\{(.+)\}/', function ($m) use ($serveruriexp, $i, &$route) {
                    $route['query'][] = [$m[1] => $serveruriexp[$i]];

                    return strtolower($serveruriexp[$i]); // url hack to accept upper cases too
                }, $expressionExp[$i]);
            }

            $expression = implode('/', $expressionExp);
            $route['uri'] = $expression;

            if (isset($route['querystring'])) {
                $checkurl = $route['uri'].'?'.$route['querystring'];
            } else {
                $checkurl = $route['uri'];
            }

            if ((strtolower($checkurl) == $url) && ($_SERVER['REQUEST_METHOD'] == $route['method'])) {
                return $route;
            }
        }
    }
540478
protected function getUrlContents(string $url): string
    {
        $request = $this->getRequest($url);

        return $this->getParsedResponse($request);
    }
1312558
public function parseUrl($url) {
		$url = parse_url($url);
		$url['vars'] = array();
		if (!isset($url['fragment'])) {
			$url['fragment'] = null;
		}
		if (isset($url['query'])) {
			parse_str($url['query'], $url['vars']);
		}

		return $url;
	}
39570
private function getCurlHandle($url)
    {
        if ($curl = curl_init($url)) {
            curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

            if ($this->is_https && $this->verify_ssl_peer) {
                curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
                curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);

                if ($this->custom_ca_file) {
                    curl_setopt($curl, CURLOPT_CAINFO, $this->custom_ca_file);
                }
            } else {
                curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
                curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            }

            return $curl;
        } else {
            throw new \RuntimeException("Can't create curl handle");
        }
    }