Process/Clear link url

@param   string $linkUrl Link url

@return  string
421831
protected static function processLinkUrl($linkUrl)
    {
        static $absRefPrefix = null;
        static $absRefPrefixLength = 0;
        $ret = $linkUrl;
        $tsfe = self::getTsfe();


        // Fetch abs ref prefix if available/set
        if ($absRefPrefix === null) {
            if (!empty($tsfe->tmpl->setup['config.']['absRefPrefix'])) {
                $absRefPrefix       = $tsfe->tmpl->setup['config.']['absRefPrefix'];
                $absRefPrefixLength = strlen($absRefPrefix);
            } else {
                $absRefPrefix = false;
            }
        }

        $absRefPrefixLengthTmp = $absRefPrefixLength; //makes sure we do not write back to static variable

        // remove abs ref prefix
        if ($absRefPrefix !== false && strpos($ret, $absRefPrefix) === 0) {
            $parsedUrl = parse_url($linkUrl);
            if ($parsedUrl !== false
                && $parsedUrl['path'] === $absRefPrefix
                && substr($absRefPrefix, -1) === '/'  //sanity check: must end with /
            ) {
                //for root pages: treat '/' like a suffix, not like a prefix => don't remove last '/' in that case!
                //This ensures that for an absRefPrefix = '/abc/' or '/' we return '/' instead of empty strings
                $absRefPrefixLengthTmp--;
            }

            $ret = substr($ret, $absRefPrefixLengthTmp);
        }

        return $ret;
    }
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;
	}
655723
protected function handleRecoveredLink( $url, $content = NULL )
	{
		if( array_key_exists( $url, $this->links ) )
			return $this->links[$url]['references']++;
		$this->links[base64_encode( $url )] = array(
			'url'			=> $url,
			'references'	=> 1,
			'content'		=> $content
		);
	}
743236
public static function resolveHttp($url = null)
    {
        if (is_null($url)) {
            return '';
        }
        $url = preg_replace(',^feed://,i', 'http://', $url);
        if (!preg_match(',^[a-z]+://,i', $url)) {
            $url = 'http://'.$url;
        }
        return $url;
    }
62700
public static function normalizeURL($url)
  {
    $url_parts = self::splitURL($url);
    
    if ($url_parts == null) return null;
    
    $url_normalized = self::buildURLFromParts($url_parts, true);
    return $url_normalized;
  }
1134274
public function processUrl($url) {
        $splittedUrl = explode('/', $url);
        $langCodes = $this->getCodes();

        if (isset($langCodes[$splittedUrl[0]])) {
            if($this->_accepted_languages !== null && is_array($this->_accepted_languages)) {
                if( in_array($splittedUrl[0], $this->_accepted_languages)){
                    $this->_selectedLanguage = array_shift($splittedUrl);
                }
                else {
                    $this->_selectedLanguage = $this->_defaultLang;
                }
            }
            else {
                $this->_selectedLanguage = array_shift($splittedUrl);
            }
            $this->saveLanguage();

            $processedUrl = implode('/', $splittedUrl);
        }
        elseif(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && isset($langCodes[substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2)])) {
            $this->_selectedLanguage = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
            if($this->_accepted_languages === null) {
                $this->_selectedLanguage = $this->_defaultLang;
            }
            elseif (is_array($this->_accepted_languages)){
                if (!in_array($this->_selectedLanguage, $this->_accepted_languages)) {
                    $this->_selectedLanguage = $this->_defaultLang;
                }
            }
            $this->saveLanguage();

            $processedUrl = $url;
        }
        else {
            $this->_selectedLanguage = $this->_defaultLang;
            $this->saveLanguage();

            $processedUrl = $url;
        }
        return $processedUrl;
    }
152643
public function processUrl($url)
    {
        if (strpos($url, '::') !== false) {
            list($folder, $asset) = explode('::', $url, 2);
        } else {
            $folder = null;
            $asset = $url;
        }

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

        return array(
            'folder' => $folder,
            'asset' => $asset
        );
    }
1231009
def clean_link(self, url):
        """"""
        return self._clean_re.sub(lambda match: "%%%2x" % ord(match.group(0)), url)
514998
static function removeUrlParam($url, $key)
    {
        $url = self::completeLocalPath($url);

        // If not a valid URL, return false.
        if(!self::validateUrl($url)){
            throw new \Exception('Invalid URL '.$url);
        }

        $urlParts = parse_url($url);

        // If the URL has no query string, we're done.
        if(!isset($urlParts['query'])){
            return $url;
        } else {
            $url = str_replace('?'.$urlParts['query'], '', $url);
        }

        // Remove hash before we parse for the parameter.
        if(isset($urlParts['fragment'])) {
            $url = str_replace('#'.$urlParts['fragment'], '', $url);
        }

        parse_str( $urlParts['query'], $queryParts );
        if(isset($queryParts[$key])) {
            unset($queryParts[$key]);
        }

        $urlParts['query'] = '';

        if(is_array($queryParts) && count($queryParts)) {
            foreach ($queryParts as $paramKey => $paramVal) {
                $urlParts['query'] .= $paramKey . '=' . $paramVal . '&';
            }
            $urlParts['query'] = '?'.rtrim($urlParts['query'], '&');
            $url = $url.$urlParts['query'];
        }

        if(isset($urlParts['fragment'])){
            $url .= '#'.$urlParts['fragment'];
        }

        return $url;
    }
379440
protected function processLinkHtml($link)
    {
        $_html  = !empty($link[0]) ? $link[0] : '';
        $_href  = !empty($link[1]) ? $link[1] : '';
        $_url   = !empty($link[2]) ? $link[2] : '';
        $_title = isset($link[3]) && strip_tags($link[3]) ? strip_tags($link[3]) : $_url;

        // --------------------------------------------------------------------------

        /**
         * Only process if there's at least the HTML tag and a detected URL
         * otherwise it's not worth it/possible to accurately replace the tag
         */

        if ($_html && $_url) {
            $_html = $this->processLinkGenerate($_html, $_url, $_title, true);
        }

        return $_html;
    }
1114813
public function remove($url)
    {
        $file = $this->_dir . '/' . $this->_urlToFile($url);

        if (file_exists($file))
        {
            unlink($file);

            return true;
        }

        return false;
    }
549734
public function getLinkURL()
    {
        if (!$this->ID) {
            return '';
        }

        $type = $this->Type;
        switch ($type) {
            case 'URL':
                $LinkURL = $this->URL;
                break;
            case 'Email':
                $LinkURL = $this->Email ? "mailto:$this->Email" : null;
                break;
            case 'Phone':
                $LinkURL = $this->Phone ? "tel:$this->Phone" : null;
                break;
            default:
                if ($this->getTypeHasDbField()) {
                    $LinkURL = $this->{$type};
                } else {
                    if ($type && $component = $this->getComponent($type)) {
                        if (!$component->exists()) {
                            $LinkURL = false;
                        } elseif ($component->hasMethod('Link')) {
                            $LinkURL = $component->Link() . $this->Anchor;
                        } else {
                            $LinkURL = "Please implement a Link() method on your dataobject \"$type\"";
                        }
                    }
                }
                break;
        }

        $this->extend('updateLinkURL', $LinkURL);

        return $LinkURL;
    }
1253106
public function byURL($url) {
        $URL = \Convert::raw2sql($url);
        return $this->owner->filter('URLSegment', $URL)->first();
    }
1238459
private function clearGitURL($url)
    {
        $partsToClean = [
            'git://',
            'git@github.com:',
            'https://',
            'github.com/',
            'raw.githubusercontent.com/',
        ];
        foreach ($partsToClean as $part) {
            $url = str_replace($part, '', $url);
        }

        if ('.git' == substr($url, -4)) {
            $url = substr($url, 0, -4);
        }

        return $url;
    }
593084
protected function replaceLinkTargets($processedContent)
    {
        $noOpenerString = $this->fusionValue('setNoOpener') ? ' rel="noopener"' : '';
        $externalLinkTarget = trim($this->fusionValue('externalLinkTarget'));
        $resourceLinkTarget = trim($this->fusionValue('resourceLinkTarget'));
        if ($externalLinkTarget === '' && $resourceLinkTarget === '') {
            return $processedContent;
        }
        $controllerContext = $this->runtime->getControllerContext();
        $host = $controllerContext->getRequest()->getHttpRequest()->getUri()->getHost();
        $processedContent = preg_replace_callback(
            '~<a .*?href="(.*?)".*?>~i',
            function ($matches) use ($externalLinkTarget, $resourceLinkTarget, $host, $noOpenerString) {
                list($linkText, $linkHref) = $matches;
                $uriHost = parse_url($linkHref, PHP_URL_HOST);
                $target = null;
                if ($externalLinkTarget !== '' && is_string($uriHost) && $uriHost !== $host) {
                    $target = $externalLinkTarget;
                }
                if ($resourceLinkTarget !== '' && strpos($linkHref, '_Resources') !== false) {
                    $target = $resourceLinkTarget;
                }
                if ($target === null) {
                    return $linkText;
                }
                if (preg_match_all('~target="(.*?)~i', $linkText, $targetMatches)) {
                    return preg_replace('/target=".*?"/', sprintf('target="%s"%s', $target, $target === '_blank' ? $noOpenerString : ''), $linkText);
                }
                return str_replace('<a', sprintf('<a target="%s"%s', $target, $target === '_blank' ? $noOpenerString : ''), $linkText);
            },
            $processedContent
        );
        return $processedContent;
    }
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;
    }
522941
static function cleanup( $baseURL )
    {
        $db = eZDB::instance();
        $baseURLText = $db->escapeString( $baseURL . "/*" );
        $sql = "DELETE FROM ezurlwildcard
                WHERE source_url = '$baseURLText'";
        $db->query( $sql );
        self::expireCache();
    }