Properly reading quote authors for embedded objects
authorAlexander Ebert <ebert@woltlab.com>
Fri, 17 Jun 2016 12:15:06 +0000 (14:15 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 17 Jun 2016 22:37:57 +0000 (00:37 +0200)
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php
wcfsetup/install/files/lib/system/html/node/IHtmlNodeProcessor.class.php
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeBlockquote.class.php
wcfsetup/install/files/lib/system/message/embedded/object/QuoteMessageEmbeddedObjectHandler.class.php

index ee1e17004612b1b826516303a611eae6b1fd1439..e88dc7e6336069ac514895c850c877bde9eb4a3d 100644 (file)
@@ -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() {
index 401aeeffdefefcb7962ce5286f7fb8925c1fbad8..0d428a0a350588d34ec062c933d980ca58b0a285 100644 (file)
@@ -5,6 +5,9 @@ namespace wcf\system\html\node;
  * @since 3.0
  */
 interface IHtmlNodeProcessor {
+       /**
+        * @return      \DOMDocument
+        */
        public function getDocument();
        
        public function getHtml();
index 7aed0e40dc1a94547b3f797fa12d6f0c29c86401..83a7744f039ffc3197179dfd0cf5a8d7cc41f9d2 100644 (file)
@@ -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
                ]);
index 4bd48d544777d5aa17cbb0b8b5b32bbcb193fd36..856ff0cf6fd31fcd46b9a2fc9e492bc5d8d3a0a5 100644 (file)
@@ -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 [];
        }
        
        /**