From: Alexander Ebert Date: Fri, 17 Jun 2016 12:15:06 +0000 (+0200) Subject: Properly reading quote authors for embedded objects X-Git-Tag: 3.0.0_Beta_1~1401 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=1be4bffd15bda3f747192e2c90847824eeee69d2;p=GitHub%2FWoltLab%2FWCF.git Properly reading quote authors for embedded objects --- diff --git a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php index ee1e170046..e88dc7e633 100644 --- a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php @@ -50,7 +50,12 @@ class HtmlInputNodeProcessor extends HtmlNodeProcessor implements IHtmlInputNode } public function addEmbeddedContent($type, array $data) { - $this->embeddedContent[$type] = $data; + if (isset($this->embeddedContent[$type])) { + $this->embeddedContent[$type] = array_merge($this->embeddedContent[$type], $data); + } + else { + $this->embeddedContent[$type] = $data; + } } protected function parseEmbeddedContent() { diff --git a/wcfsetup/install/files/lib/system/html/node/IHtmlNodeProcessor.class.php b/wcfsetup/install/files/lib/system/html/node/IHtmlNodeProcessor.class.php index 401aeeffde..0d428a0a35 100644 --- a/wcfsetup/install/files/lib/system/html/node/IHtmlNodeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/node/IHtmlNodeProcessor.class.php @@ -5,6 +5,9 @@ namespace wcf\system\html\node; * @since 3.0 */ interface IHtmlNodeProcessor { + /** + * @return \DOMDocument + */ public function getDocument(); public function getHtml(); diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeBlockquote.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeBlockquote.class.php index 7aed0e40dc..83a7744f03 100644 --- a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeBlockquote.class.php +++ b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeBlockquote.class.php @@ -3,6 +3,7 @@ namespace wcf\system\html\output\node; use wcf\system\application\ApplicationHandler; use wcf\system\html\node\AbstractHtmlNode; use wcf\system\html\node\HtmlNodeProcessor; +use wcf\system\message\embedded\object\MessageEmbeddedObjectManager; use wcf\system\request\RouteHandler; use wcf\system\WCF; use wcf\util\StringUtil; @@ -22,8 +23,8 @@ class HtmlOutputNodeBlockquote extends AbstractHtmlNode { foreach ($elements as $element) { $nodeIdentifier = StringUtil::getRandomID(); $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, [ - 'title' => ($element->hasAttribute('data-quote-title')) ? $element->getAttribute('data-quote-title') : '', - 'url' => ($element->hasAttribute('data-quote-url')) ? $element->getAttribute('data-quote-url') : '' + 'author' => ($element->hasAttribute('data-author')) ? $element->getAttribute('data-author') : '', + 'url' => ($element->hasAttribute('data-url')) ? $element->getAttribute('data-url') : '' ]); $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier); @@ -37,11 +38,8 @@ class HtmlOutputNodeBlockquote extends AbstractHtmlNode { } $quoteAuthorObject = null; - /* - * TODO: how should the author object be resolved? - * - if ($quoteAuthor && !$externalQuoteLink) { - $quoteAuthorLC = mb_strtolower(StringUtil::decodeHTML($quoteAuthor)); + if ($data['author'] && !$externalQuoteLink) { + $quoteAuthorLC = mb_strtolower(StringUtil::decodeHTML($data['author'])); foreach (MessageEmbeddedObjectManager::getInstance()->getObjects('com.woltlab.wcf.quote') as $user) { if (mb_strtolower($user->username) == $quoteAuthorLC) { $quoteAuthorObject = $user; @@ -49,11 +47,10 @@ class HtmlOutputNodeBlockquote extends AbstractHtmlNode { } } } - */ WCF::getTPL()->assign([ 'quoteLink' => $data['url'], - 'quoteAuthor' => $data['title'], + 'quoteAuthor' => $data['author'], 'quoteAuthorObject' => $quoteAuthorObject, 'isExternalQuoteLink' => $externalQuoteLink ]); diff --git a/wcfsetup/install/files/lib/system/message/embedded/object/QuoteMessageEmbeddedObjectHandler.class.php b/wcfsetup/install/files/lib/system/message/embedded/object/QuoteMessageEmbeddedObjectHandler.class.php index 4bd48d5447..856ff0cf6f 100644 --- a/wcfsetup/install/files/lib/system/message/embedded/object/QuoteMessageEmbeddedObjectHandler.class.php +++ b/wcfsetup/install/files/lib/system/message/embedded/object/QuoteMessageEmbeddedObjectHandler.class.php @@ -2,6 +2,8 @@ namespace wcf\system\message\embedded\object; use wcf\data\user\UserList; use wcf\system\cache\runtime\UserProfileRuntimeCache; +use wcf\system\html\input\HtmlInputProcessor; +use wcf\util\StringUtil; /** * IMessageEmbeddedObjectHandler implementation for quotes. @@ -15,8 +17,17 @@ class QuoteMessageEmbeddedObjectHandler extends AbstractMessageEmbeddedObjectHan /** * @inheritDoc */ - public function parseMessage($message) { - $usernames = self::getFirstParameters($message, 'quote'); + public function parse(HtmlInputProcessor $htmlInputProcessor, array $embeddedData) { + $usernames = []; + + /** @var \DOMElement $element */ + foreach ($htmlInputProcessor->getHtmlInputNodeProcessor()->getDocument()->getElementsByTagName('blockquote') as $element) { + $username = StringUtil::trim($element->getAttribute('data-author')); + if (!empty($username) && !in_array($username, $usernames)) { + $usernames[] = $username; + } + } + if (!empty($usernames)) { $userList = new UserList(); $userList->getConditionBuilder()->add("user_table.username IN (?)", [$usernames]); @@ -24,7 +35,7 @@ class QuoteMessageEmbeddedObjectHandler extends AbstractMessageEmbeddedObjectHan return $userList->getObjectIDs(); } - return false; + return []; } /**