@author Vova Feldman (@svovaf)
@since  2.0.0

@param string $url

@return bool
196343
static function is_localhost_by_address( $url ) {
            if ( false !== strpos( $url, '127.0.0.1' ) ||
                 false !== strpos( $url, 'localhost' )
            ) {
                return true;
            }

            if ( ! fs_starts_with( $url, 'http' ) ) {
                $url = 'http://' . $url;
            }

            $url_parts = parse_url( $url );

            $subdomain = $url_parts['host'];

            return (
                // Starts with.
                fs_starts_with( $subdomain, 'local.' ) ||
                fs_starts_with( $subdomain, 'dev.' ) ||
                fs_starts_with( $subdomain, 'test.' ) ||
                fs_starts_with( $subdomain, 'stage.' ) ||
                fs_starts_with( $subdomain, 'staging.' ) ||

                // Ends with.
                fs_ends_with( $subdomain, '.dev' ) ||
                fs_ends_with( $subdomain, '.test' ) ||
                fs_ends_with( $subdomain, '.staging' ) ||
                fs_ends_with( $subdomain, '.local' ) ||
                fs_ends_with( $subdomain, '.example' ) ||
                fs_ends_with( $subdomain, '.invalid' ) ||
                // GoDaddy test/dev.
                fs_ends_with( $subdomain, '.myftpupload.com' ) ||
                // ngrok tunneling.
                fs_ends_with( $subdomain, '.ngrok.io' ) ||
                // wpsandbox.
                fs_ends_with( $subdomain, '.wpsandbox.pro' ) ||
                // SiteGround staging.
                fs_starts_with( $subdomain, 'staging' ) ||
                // WPEngine staging.
                fs_ends_with( $subdomain, '.staging.wpengine.com' ) ||
                // Pantheon
                ( fs_ends_with($subdomain, 'pantheonsite.io') &&
                  (fs_starts_with($subdomain, 'test-') || fs_starts_with($subdomain, 'dev-'))) ||
                // Cloudways
                fs_ends_with( $subdomain, '.cloudwaysapps.com' ) ||
                // Kinsta
                (fs_ends_with($subdomain, '.kinsta.com') && fs_starts_with($subdomain, 'staging-'))
            );
        }
173844
public function contains($url)
	{
		$url = trim($url, '/');

		foreach ($this->entries as $entry) {
			if ($entry['loc'] == $url) {
				return TRUE;
			}
		}

		return FALSE;
	}
1088690
public function isWebpage($url) {
		$url = filter_var($url, FILTER_VALIDATE_URL);
		if (!strlen($url)) {
			return false;
		}
		
		$c = curl_init(); 
		curl_setopt($c, CURLOPT_URL, $url); 
		curl_setopt($c, CURLOPT_HEADER, 1); // get the header 
		curl_setopt($c, CURLOPT_NOBODY, 1); // and *only* get the header 
		curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); // get the response as a string from curl_exec(), rather than echoing it 
		curl_setopt($c, CURLOPT_FRESH_CONNECT, 1); // don't use a cached version of the url 
		$result = curl_exec($c);
		
		if (!$result) { 
			return false; 
		} 
		
		if (stripos($result, 'Content-type: text/html')) {
//			$svc = new RestfulService($url);
//			$response = $svc->request('', 'GET');
			return true;
		}
		
		return false;
	}
77573
public static function isValidUrl($url) {
		require_once(PATH_typo3 . 'contrib/idna/idna_convert.class.php');
		$IDN = new idna_convert(array('idn_version' => 2008));

		return (filter_var($IDN->encode($url), FILTER_VALIDATE_URL) !== FALSE);
	}
557053
public static function isUrlArchive($url)
    {
        if (0 === strpos($url, 'http')) {
            foreach (self::$extensions as $extension) {
                if (substr($url, -\strlen($extension)) === $extension) {
                    return true;
                }
            }
        }

        return false;
    }
1205974
public function checkWhitelist(string $url): bool
	{
		$pluginSettings = EmbeddedAssets::$plugin->getSettings();
		$whitelist = array_merge($pluginSettings->whitelist, $pluginSettings->extraWhitelist);

		foreach ($whitelist as $whitelistUrl)
		{
			if ($whitelistUrl)
			{
				$pattern = explode('*', $whitelistUrl);
				$pattern = array_map('preg_quote', $pattern);
				$pattern = implode('[a-z][a-z0-9]*', $pattern);
				$pattern = "%^(https?:)?//([a-z0-9\-]+\\.)?$pattern([:/].*)?$%";

				if (preg_match($pattern, $url))
				{
					return true;
				}
			}
		}

		return false;
	}
924283
public function isCurrentProtocol($url)
    {
        // Missing protocol, cannot proceed, assuming true.
        if (!$url || (strpos($url, "http") !== 0)) {
            return true;
        }

        return (strpos($url, "https:") === 0) == $this->isSsl();
    }
1085159
public function verify($url)
    {
        $url = parse_url($url);
        if ($url === false) {
            throw new \Exception('Bad url to match (not an url ?)');
        }

        $path = isset($url['path']) ? $url['path'] : '';

        if ((bool) preg_match($this->pattern, $path, $matches)) {
            array_shift($matches);

            foreach ($matches as $position => $value) {
                $this->parameterCollection->getByPosition($position)
                    ->setValue($value);
            }

            return true;
        }

        return false;
    }
449028
public function setURL($url = '')
    {
        try {
            if (mb_strlen($url) > 0) {
                if (substr($url, 0, 8) == 'https://') {
                    $this->isSSL = TRUE;
                    $this->debug->debug(__FUNCTION__, 'Set SSL: ' . $this->isSSL);
                } elseif (substr($url, 0, 7) == 'http://') {
                    $this->isSSL = TRUE;
                    $this->debug->debug(__FUNCTION__, 'Set SSL: ' . $this->isSSL);
                }
            }
            $this->url = $url;
        }
        catch (Exception $e) {
            $this->url = NULL;
            $message   = "Error: " . __CLASS__ . ": Invalid protocol specified. URL must start with http:// or https:// - " . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
            $this->debug->error(__FUNCTION__, $message);

            return $message;
        }
        $this->debug->debug(__FUNCTION__, 'Endpoint URL to Request: ', $this->url);

        return $this;
    }
1024168
private function checkNumberRedirects($url)
    {
        ++self::$nbRedirect;

        // keep initial url in case of endless redirect
        if ('' === self::$initialUrl) {
            self::$initialUrl = $url;
        }

        if (self::$nbRedirect > $this->config['max_redirect']) {
            $this->logger->warning('Endless redirect: ' . self::$nbRedirect . ' on "{url}"', ['url' => $url]);

            return false;
        }

        return true;
    }
816078
public static function active( $url )
	{
		$url = parse_url( $url, PHP_URL_PATH );

		if ( empty( $url ) )
		{
			return false;
		}

		if ( $url[0] !== '/' )
		{
			$url = static::to( $url );
		}

		// when we are on "/" only "/" counts as active.
	 	if ( $url === '/' )
		{
			return static::current() == $url;
		}

		// for everything else we cut the url and compare
		$cut = substr( static::current(), 0, strlen( $url ) );

		return $cut == $url;
	}
616157
public function match($url = null)
    {
        $match = parent::match($url);
        $regex = $this->getRegex($this->getMatchUrl());

        if ($regex !== ' ') {
            if (preg_match("@" . ltrim($regex) . "@si", $this->getRequestedUrl(), $matches) || true === $match) {
                unset($matches[0]);
                ParameterBag::setParameters($matches);
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }

    }
1272775
protected function isUARouted(string $url)
    {
        $exploded = explode('/', $url);
        $uaRoute = $exploded[0];

        $routingData = $this->getParameter('field_cito.routing.user_agent_routing');
        foreach ($routingData as $route => $browsers) {
            if ($route === $uaRoute) {
                return true;
            }
        }
        return false;
    }
328119
public function isAccessible($url)
    {
        $context = $this->getContext($url);

        return is_resource(@fopen($url, 'r', null, $context));
    }
1320996
private static function httpGet($url)
    {
        $oCurl = curl_init();
        curl_setopt($oCurl, CURLOPT_URL, $url);
        curl_setopt($oCurl, CURLOPT_TIMEOUT, 10);
        curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
        $sContent = curl_exec($oCurl);
        $aStatus = curl_getinfo($oCurl);
        curl_close($oCurl);
        if (intval($aStatus["http_code"]) == 200) {
            return $sContent;
        } else {
            return false;
        }
    }
260675
public function curl($url)
    {
        $ip = '127.0.0.1';
        $port = '9051';
        $auth = 'PASSWORD';
        $command = 'signal NEWNYM';

        $fp = fsockopen($ip, $port, $error_number, $err_string, 2);
        if (!$fp) {
            echo "ERROR: $error_number : $err_string";

            return false;
        } else {
            fwrite($fp, "AUTHENTICATE \"".$auth."\"\n");
            fread($fp, 512);
            fwrite($fp, $command."\n");
            fread($fp, 512);
        }

        fclose($fp);

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:9050');
        curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_VERBOSE, 0);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_USERAGENT, $this->getUserAgent());  // $this->getUserAgent(true) for random);
        curl_setopt($ch, CURLOPT_ENCODING , 'gzip');
        $response = curl_exec($ch);

        return [$response, $ch];
    }
1355678
protected function checkUrl($url)
    {
        if ($this->fullName) {
            $pos = strpos($this->fullName, '<');

            if (false !== $pos) {
                $str = substr($this->fullName, 0, $pos);
            } else {
                $str = $this->fullName;
            }

            if ($str && 0 !== stripos(str_replace('|', '/', $url), $str)) {
                return false;
            }
        }

        return true;
    }