From: Alexander Ebert Date: Wed, 20 Jul 2016 14:01:50 +0000 (+0200) Subject: Updated API for mentioned users/quotes X-Git-Tag: 3.0.0_Beta_1~1028 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=657e0c2307397c61805517d8340bb11d48cebf37;p=GitHub%2FWoltLab%2FWCF.git Updated API for mentioned users/quotes --- diff --git a/wcfsetup/install/files/lib/util/MessageUtil.class.php b/wcfsetup/install/files/lib/util/MessageUtil.class.php index 7f1f234670..dd0b3f8724 100644 --- a/wcfsetup/install/files/lib/util/MessageUtil.class.php +++ b/wcfsetup/install/files/lib/util/MessageUtil.class.php @@ -1,6 +1,7 @@ $tag) { - if (!$inQuote) { - $newText .= $substrings[$i]; - } - - if ($tag == '[quote') { - $inQuote++; - } - else { - $inQuote--; - } + public static function getMentionedUsers(HtmlInputProcessor $htmlInputProcessor) { + $usernames = []; + + $elements = $htmlInputProcessor->getHtmlInputNodeProcessor()->getDocument()->getElementsByTagName('woltlab-mention'); + /** @var \DOMElement $element */ + foreach ($elements as $element) { + if (DOMUtil::hasParent($element, 'blockquote')) { + // ignore mentions within quotes + continue; } - if (!$inQuote) $newText .= $substrings[count($substrings) - 1]; - } - - // check for mentions - if (preg_match_all("~\[url='[^']+'\]@(.+?)\[/url\]~", $newText, $matches)) { - return $matches[1]; + $usernames[] = $element->getAttribute('data-username'); } - return []; + return $usernames; } /** * Returns the quoted users in the given text. - * - * @param string $text - * @return string[] + * + * @param HtmlInputProcessor $htmlInputProcessor html input processor instance + * @return string[] quoted usernames */ - public static function getQuotedUsers($text) { + public static function getQuotedUsers(HtmlInputProcessor $htmlInputProcessor) { $usernames = []; - if (preg_match_all("~(?:\[(quote)=(?:')?(.+?)(?:')?(?:,[^\]]*)?\]|\[/quote\])~i", $text, $matches)) { - $level = 0; - - foreach ($matches[1] as $i => $tag) { - if ($tag == 'quote') { - if (!$level) { - $usernames[] = $matches[2][$i]; - } - $level++; - } - else { - $level--; - } - } + + $elements = $htmlInputProcessor->getHtmlInputNodeProcessor()->getDocument()->getElementsByTagName('blockquote'); + /** @var \DOMElement $element */ + foreach ($elements as $element) { + $username = $element->getAttribute('data-author'); + if (!empty($username)) $usernames[] = $username; } return $usernames;