Unified comment and comment response processing
authorAlexander Ebert <ebert@woltlab.com>
Mon, 18 Dec 2017 10:20:53 +0000 (11:20 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 18 Dec 2017 10:20:53 +0000 (11:20 +0100)
wcfsetup/install/files/lib/data/comment/CommentAction.class.php

index 3d21cfe44b3dfb2d698c554dce18e215411f389d..43f8ee31e40d2107e5a78f8957f5f43e8c800d7f 100644 (file)
@@ -296,7 +296,7 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
                        $this->validateCaptcha();
                }
                
-               $this->validateMessage(true);
+               $this->validateMessage();
                $objectType = $this->validateObjectType();
                
                // validate object id and permissions
@@ -477,13 +477,16 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
                        ];
                }
                
+               /** @var HtmlInputProcessor $htmlInputProcessor */
+               $htmlInputProcessor = $this->parameters['htmlInputProcessor'];
+               
                // create response
                $this->createdResponse = CommentResponseEditor::create([
                        'commentID' => $this->comment->commentID,
                        'time' => TIME_NOW,
                        'userID' => WCF::getUser()->userID ?: null,
                        'username' => WCF::getUser()->userID ? WCF::getUser()->username : $this->parameters['data']['username'],
-                       'message' => $this->parameters['data']['message'],
+                       'message' => $htmlInputProcessor->getHtml(),
                        'enableHtml' => 1,
                        'isDisabled' => $this->commentProcessor->canAddWithoutApproval($this->parameters['data']['objectID']) ? 0 : 1
                ]);
@@ -1046,12 +1049,11 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
        }
        
        /**
-        * Validates message parameter.
+        * Validates message parameters.
         * 
-        * @param       bool  $isComment
         * @throws      UserInputException
         */
-       protected function validateMessage($isComment = false) {
+       protected function validateMessage() {
                $this->readString('message', false, 'data');
                $this->parameters['data']['message'] = MessageUtil::stripCrap($this->parameters['data']['message']);
                
@@ -1061,25 +1063,20 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
                
                CommentHandler::enforceCensorship($this->parameters['data']['message']);
                
-               if ($isComment) {
-                       $this->setDisallowedBBCodes();
-                       $htmlInputProcessor = $this->getHtmlInputProcessor($this->parameters['data']['message'], ($this->comment !== null ? $this->comment->commentID : 0));
-                       
-                       // search for disallowed bbcodes
-                       $disallowedBBCodes = $htmlInputProcessor->validate();
-                       if (!empty($disallowedBBCodes)) {
-                               throw new UserInputException('text', WCF::getLanguage()->getDynamicVariable('wcf.message.error.disallowedBBCodes', ['disallowedBBCodes' => $disallowedBBCodes]));
-                       }
-                       
-                       if ($htmlInputProcessor->appearsToBeEmpty()) {
-                               throw new UserInputException('message');
-                       }
-                       
-                       $this->parameters['htmlInputProcessor'] = $htmlInputProcessor;
+               $this->setDisallowedBBCodes();
+               $htmlInputProcessor = $this->getHtmlInputProcessor($this->parameters['data']['message'], ($this->comment !== null ? $this->comment->commentID : 0));
+               
+               // search for disallowed bbcodes
+               $disallowedBBCodes = $htmlInputProcessor->validate();
+               if (!empty($disallowedBBCodes)) {
+                       throw new UserInputException('text', WCF::getLanguage()->getDynamicVariable('wcf.message.error.disallowedBBCodes', ['disallowedBBCodes' => $disallowedBBCodes]));
                }
-               else {
-                       unset($this->parameters['htmlInputProcessor']);
+               
+               if ($htmlInputProcessor->appearsToBeEmpty()) {
+                       throw new UserInputException('message');
                }
+               
+               $this->parameters['htmlInputProcessor'] = $htmlInputProcessor;
        }
        
        /**