Exemple #1
0
    /**
     * Handles pre-parsing of URLs.
     */
    protected function parseURLs()
    {
        static $urlPattern = null;
        static $callback = null;
        if ($urlPattern === null) {
            $urlPattern = new Regex('
			(?<!\\B|"|\'|=|/|,|\\?|\\.)
			(?:						# hostname
				(?:ftp|https?)://' . static::$illegalChars . '(?:\\.' . static::$illegalChars . ')*
				|
				www\\.(?:' . static::$illegalChars . '\\.)+
				(?:[a-z]{2,63}(?=\\b))			# tld
			)
			
			(?::\\d+)?					# port
			
			(?:
				/
				[^!.,?;"\'<>()\\[\\]{}\\s]*
				(?:
					[!.,?;(){}]+ [^!.,?;"\'<>()\\[\\]{}\\s]+
				)*
			)?', Regex::IGNORE_WHITESPACE | Regex::CASE_INSENSITIVE);
        }
        if ($callback === null) {
            $callback = new Callback(function ($matches) {
                if ((PreParser::getInstance()->allowedBBCodes === null || BBCode::isAllowedBBCode('media', PreParser::getInstance()->allowedBBCodes)) && BBCodeMediaProvider::isMediaURL($matches[0])) {
                    return '[media]' . $matches[0] . '[/media]';
                }
                if (PreParser::getInstance()->allowedBBCodes === null || BBCode::isAllowedBBCode('url', PreParser::getInstance()->allowedBBCodes)) {
                    return '[url]' . $matches[0] . '[/url]';
                }
                return $matches[0];
            });
        }
        $this->text = $urlPattern->replace($this->text, $callback);
    }