use wcf\system\request\LinkHandler;
use wcf\system\Callback;
use wcf\system\Regex;
+use wcf\util\StringStack;
use wcf\util\StringUtil;
/**
$userRegex = new Regex("(?<=^|\s)@([^',\s][^,\s]{2,}|'(?:''|[^'])*')");
}
- $userRegex->match($eventObj->text, true);
+ // cache quotes
+ // @see wcf\system\bbcode\BBCodeParser::buildTagArray()
+ $pattern = '~\[(?:/(?:quote)|(?:quote)
+ (?:=
+ (?:\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|[^,\]]*)
+ (?:,(?:\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|[^,\]]*))*
+ )?)\]~ix';
+ preg_match_all($pattern, $eventObj->text, $quoteMatches);
+ $textArray = preg_split($pattern, $eventObj->text);
+ $text = $textArray[0];
+
+ $openQuotes = 0;
+ $quote = '';
+ foreach ($quoteMatches[0] as $i => $quoteTag) {
+ if (mb_substr($quoteTag, 1, 1) == '/') {
+ $openQuotes--;
+
+ $quote .= $quoteTag;
+ if ($openQuotes) {
+ $quote .= $textArray[$i + 1];
+ }
+ else {
+ $text .= StringStack::pushToStringStack($quote, 'preParserUserMentions', '@@@').$textArray[$i + 1];
+ $quote = '';
+ }
+ }
+ else {
+ $openQuotes++;
+ $quote .= $quoteTag.$textArray[$i + 1];
+ }
+ }
+
+ $userRegex->match($text, true);
$matches = $userRegex->getMatches();
if (!empty($matches[1])) {
$users[StringUtil::toLowerCase($user->username)] = $user;
}
- $eventObj->text = $userRegex->replace($eventObj->text, new Callback(function ($matches) use ($users) {
+ $text = $userRegex->replace($text, new Callback(function ($matches) use ($users) {
$username = PreParserAtUserListener::getUsername($matches[1]);
if (isset($users[$username])) {
}));
}
}
+
+ // reinsert cached quotes
+ $eventObj->text = StringStack::reinsertStrings($text, 'preParserUserMentions');
}
/**