/** * @see \wcf\system\bbcode\IBBCode::getParsedTag() */ public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser) { $content = StringUtil::trim($content); if ($parser->getOutputType() == 'text/html') { foreach (BBCodeMediaProvider::getCache() as $provider) { if ($provider->matches($content)) { return $provider->getOutput($content); } } } if ($parser->getOutputType() == 'text/simplified-html') { foreach (BBCodeMediaProvider::getCache() as $provider) { if ($provider->matches($content)) { return StringUtil::getAnchorTag($content); } } } return StringUtil::encodeHTML($content); }
/** * 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); }