Checks if a given string is a valid frame URL to be loaded in the
backend.

@param string $url potential URL to check
@return string either $url if $url is considered to be harmless, or an
empty string otherwise
484133
public static function sanitizeLocalUrl($url = '') {
		$sanitizedUrl = '';
		$decodedUrl = rawurldecode($url);

		if (!empty($url) && self::removeXSS($decodedUrl) === $decodedUrl) {
			$testAbsoluteUrl = self::resolveBackPath($decodedUrl);
			$testRelativeUrl = self::resolveBackPath(
				self::dirname(self::getIndpEnv('SCRIPT_NAME')) . '/' . $decodedUrl
			);

				// Pass if URL is on the current host:
			if (self::isValidUrl($decodedUrl)) {
				if (self::isOnCurrentHost($decodedUrl) && strpos($decodedUrl, self::getIndpEnv('TYPO3_SITE_URL')) === 0) {
					$sanitizedUrl = $url;
				}
				// Pass if URL is an absolute file path:
			} elseif (self::isAbsPath($decodedUrl) && self::isAllowedAbsPath($decodedUrl)) {
				$sanitizedUrl = $url;
				// Pass if URL is absolute and below TYPO3 base directory:
			} elseif (strpos($testAbsoluteUrl, self::getIndpEnv('TYPO3_SITE_PATH')) === 0 && substr($decodedUrl, 0, 1) === '/') {
				$sanitizedUrl = $url;
				// Pass if URL is relative and below TYPO3 base directory:
			} elseif (strpos($testRelativeUrl, self::getIndpEnv('TYPO3_SITE_PATH')) === 0 && substr($decodedUrl, 0, 1) !== '/') {
				$sanitizedUrl = $url;
			}
		}

		if (!empty($url) && empty($sanitizedUrl)) {
			self::sysLog('The URL "' . $url . '" is not considered to be local and was denied.', 'Core', self::SYSLOG_SEVERITY_NOTICE);
		}

		return $sanitizedUrl;
	}
1099712
public function urlQuerystring($url)
    {
        $querystring = $this->querystring();
        if (isset($this->timestamp) && !Utils::contains($querystring, $this->timestamp)) {
            $querystring = empty($querystring) ? ('?' . $this->timestamp) : ($querystring . '&' . $this->timestamp);
        }

        return ltrim($url . $querystring . $this->urlHash(), '/');
    }
1207184
protected function check_domain_availability($url) {
        $curl = new \curl();
        $curl->head($url);
        $info = $curl->get_info();
        return !empty($info['http_code']) && $info['http_code'] == 200;
    }
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;
	}
712364
private static function cleanUrl($url)
    {
        $result = '';
        $inner = false;

        for ($i = 0; $i < strlen($url); $i++) {
            if (!$inner) {
                if ($url[$i] != '{') {
                    $result .= $url[$i];
                } else {
                    $result .= '{';
                    $inner = true;
                }
            } else {
                if ($url[$i] == '}') {
                    $result .= '}';
                    $inner = false;
                }
            }
        }

        return $result;
    }
631399
public static function parse($url)
    {
        if (!strlen($url)) {
            return null;
        }
        $_urls = array_merge( @parse_url($url), array('params'=>array()) );
        if (isset($_urls['query'])) {
            parse_str($_urls['query'], $_urls['params']);
        }
        return $_urls;  
    }
674214
public static function is($url, $regexp = false) {
        $r = self::getRouter();
        if ($regexp) {
            return preg_match('`^' . $url . '$`', $r->requestURL);
        }

        return $url == $r->requestURL;
    }
864063
public function check(string $url): LinkState
    {
        $response = null;

        try {
            $requests = $this->createRequestSet($url);

            foreach ($requests as $request) {
                $response = $this->getHttpResponse($request);

                if ($response->getStatusCode() === self::HTTP_STATUS_CODE_OK) {
                    return new LinkState(LinkState::TYPE_HTTP, $response->getStatusCode());
                }
            }
        } catch (\InvalidArgumentException $invalidArgumentException) {
            if (substr_count($invalidArgumentException->getMessage(), 'Unable to parse URI')) {
                return new LinkState(LinkState::TYPE_CURL, Configuration::CURL_MALFORMED_URL_CODE);
            }
        } catch (HttpConnectException $connectException) {
            $curlExceptionFactory = new CurlExceptionFactory();

            if ($curlExceptionFactory::isCurlException($connectException)) {
                $curlException = $curlExceptionFactory::fromConnectException($connectException);
                return new LinkState(LinkState::TYPE_CURL, $curlException->getCurlCode());
            }
        } catch (GuzzleException $guzzleException) {
            // Cannot happen
            return new LinkState(LinkState::TYPE_CURL, 0);
        }

        return new LinkState(LinkState::TYPE_HTTP, $response->getStatusCode());
    }
520311
public function getDesiredUrl(?string $url = null)
  {
    if (isset($_GET['url'])) {
      $url = $_GET['url'] . (count($_GET) > 0 ? '?' : '');
      unset($_GET['url']);

      foreach ($_GET as $key => $value) {
        $url .= (ends_with($url, '?') ? '' : '&') . $key . '=' . $value;
      }
    }

    if ($url != null) return $url;
    return false;
  }
1091628
public function prepUrl($url)
	{
        if (empty($url)) {
            return '';
        }

        return parse_url($url, PHP_URL_SCHEME) === null ? 'http://' . $url : $url;
	}
898229
public static function validate_url(String $url)
    {
        // https://mathiasbynens.be/demo/url-regex
        // @diegoperini (502 chars)
        $regex = '_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.1';
        $regex .= '68(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d';
        $regex .= '|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?';
        $regex .= ':[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iuS';

        if (preg_match($regex, $url))
            return true;

        return false;
    }
1253537
static public function clean_url($url=NULL) {
		//make sure we've still got something valid to work with.
		if(strlen($url)) {
			//if there's an "APPURL" constant, drop that from the url.
			if(defined('APPURL') && strlen(constant('APPURL'))) {
				$dropThis = preg_replace('/^\//', '', constant('APPURL'));
				$dropThis = preg_replace('/\//', '\\/', $dropThis);
				$url = preg_replace('/^'. $dropThis .'/', '', $url);
			}
			
			//check the string to make sure it doesn't begin with a "/"
			if($url[0] == '/') {
				$url = substr($url, 1, strlen($url));
			}
	
			//check the last char for a "/"...
			if($url[strlen($url) -1] == '/') {
				//last char is a '/'... kill it.
				$url = substr($url, 0, strlen($url) -1);
			}
	
			//if we've been sent a query, kill it off the string...
			if(preg_match('/\?/', $url)) {
				$url = preg_split('/\?/', $url);
				$url = $url[0];
			}
	
			if(preg_match("/\./", $url)) {
				//disregard file extensions, but keep everything else...
				//	i.e. "index.php/yermom.html" becomes "index/yermom"
				$tArr = explode('/', $url);
				$tUrl = null;
				foreach($tArr as $tUrlPart) {
					$temp = explode(".", $tUrlPart);
					if(strlen($temp[0])) {
						$tUrlPart = $temp[0];
					}
					$tUrl = ToolBox::create_list($tUrl, $tUrlPart, '/');
				}
				$url = $tUrl;
			}
		}
		else {
			$url = null;
		}

		return($url);
	}
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;
	}
873752
public static function validateURL($url = null)
    {
        $url = trim($url);

        if (is_null($url) || $url == '') {
            return $url;
        }

        if (!preg_match('#^http[s]?:\/\/#i', $url)) {
            $url = 'http://' . $url;
        }

        include TOOLKIT . '/util.validators.php';

        if (!preg_match($validators['URI'], $url)) {
            $url = '';
        }

        return $url;
    }
596524
private static function domain(string $url): ?string
    {
        $domain = parse_url($url, PHP_URL_HOST);

        if (null !== $domain) {
            return implode('.', array_slice(explode('.', $domain), -2));
        }

        return null;
    }
107962
public static function getUrlStatusCode($url)
    {
        //Instantiate the EpiCurl class to be used
        //with checking URL HTTP status code.
        $epi_curl_checker = EpiCurl::getInstance();

        // Add the given URL to the url checker.
        $url_check = $epi_curl_checker->addURL($url);

        //Return the HTTP status code.
        return $url_check->code;
    }
347777
public static function getDomainFromURL($url)
	{
		$url = str_replace(self::getProtocolFromURL($url) . '://', '', $url);
		
		return explode('/', $url)[0];
	}