Fix signature preview
authorMatthias Schmidt <gravatronics@live.com>
Tue, 16 Aug 2016 18:16:59 +0000 (20:16 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 16 Aug 2016 18:17:05 +0000 (20:17 +0200)
wcfsetup/install/files/lib/data/bbcode/MessagePreviewAction.class.php
wcfsetup/install/files/lib/data/user/UserProfileAction.class.php

index 9b39b683ea99b815da64f1f19aa18d8df461cdbe..96bd6d2684de28682c20362a853c1c68396af385 100644 (file)
@@ -21,7 +21,7 @@ class MessagePreviewAction extends BBCodeAction {
         * @inheritDoc
         */
        protected $allowGuestAccess = ['getMessagePreview'];
-               
+       
        /**
         * Validates parameters for message preview.
         */
index 7a9d81f32d447766d1e1ac3adf0434dd5748ea94..876ddc89c4ad10abc3fdac58a9ef8bff0a053ea8 100644 (file)
@@ -1,16 +1,19 @@
 <?php
 namespace wcf\data\user;
 use wcf\data\object\type\ObjectTypeCache;
-use wcf\system\bbcode\BBCodeParser;
-use wcf\system\bbcode\MessageParser;
+use wcf\system\bbcode\BBCodeHandler;
 use wcf\system\cache\runtime\UserProfileRuntimeCache;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\PermissionDeniedException;
 use wcf\system\exception\UserInputException;
+use wcf\system\html\input\HtmlInputProcessor;
+use wcf\system\html\output\HtmlOutputProcessor;
+use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
 use wcf\system\option\user\UserOptionHandler;
 use wcf\system\user\group\assignment\UserGroupAssignmentHandler;
 use wcf\system\user\storage\UserStorageHandler;
 use wcf\system\WCF;
+use wcf\util\ArrayUtil;
 use wcf\util\MessageUtil;
 use wcf\util\StringUtil;
 
@@ -30,7 +33,7 @@ class UserProfileAction extends UserAction {
        
        /**
         * user profile object
-        * @var \wcf\data\user\UserProfile
+        * @var UserProfile
         */
        public $userProfile = null;
        
@@ -39,19 +42,6 @@ class UserProfileAction extends UserAction {
         */
        public function validateGetMessagePreview() {
                $this->readString('message', true, 'data');
-               
-               if (!isset($this->parameters['options'])) {
-                       throw new UserInputException('options');
-               }
-               
-               if (isset($this->parameters['options']['enableBBCodes']) && WCF::getSession()->getPermission('user.signature.canUseBBCodes')) {
-                       $disallowedBBCodes = BBCodeParser::getInstance()->validateBBCodes($this->parameters['data']['message'], explode(',', WCF::getSession()->getPermission('user.signature.allowedBBCodes')));
-                       if (!empty($disallowedBBCodes)) {
-                               throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.disallowedBBCodes', [
-                                       'disallowedBBCodes' => $disallowedBBCodes
-                               ]));
-                       }
-               }
        }
        
        /**
@@ -60,22 +50,25 @@ class UserProfileAction extends UserAction {
         * @return      array
         */
        public function getMessagePreview() {
-               // get options
-               $enableBBCodes = isset($this->parameters['options']['enableBBCodes']) ? 1 : 0;
-               $enableHtml = isset($this->parameters['options']['enableHtml']) ? 1 : 0;
-               $enableSmilies = isset($this->parameters['options']['enableSmilies']) ? 1 : 0;
+               $htmlInputProcessor = new HtmlInputProcessor();
+               $htmlInputProcessor->process($this->parameters['data']['message'], 'com.woltlab.wcf.user.signature', WCF::getUser()->userID);
+               
+               BBCodeHandler::getInstance()->setDisallowedBBCodes(ArrayUtil::trim(explode(',', WCF::getSession()->getPermission('user.signature.disallowedBBCodes'))));
+               $disallowedBBCodes = $htmlInputProcessor->validate();
+               if (!empty($disallowedBBCodes)) {
+                       throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.disallowedBBCodes', [
+                               'disallowedBBCodes' => $disallowedBBCodes
+                       ]));
+               }
                
-               // validate permissions for options
-               if ($enableBBCodes && !WCF::getSession()->getPermission('user.signature.canUseBBCodes')) $enableBBCodes = 0;
-               if ($enableHtml && !WCF::getSession()->getPermission('user.signature.canUseHtml')) $enableHtml = 0;
-               if ($enableSmilies && !WCF::getSession()->getPermission('user.signature.canUseSmilies')) $enableSmilies = 0;
+               MessageEmbeddedObjectManager::getInstance()->registerTemporaryMessage($htmlInputProcessor);
                
-               // parse message
-               $message = StringUtil::trim($this->parameters['data']['message']);
-               $preview = MessageParser::getInstance()->parse($message, $enableSmilies, $enableHtml, $enableBBCodes, false);
+               $htmlOutputProcessor = new HtmlOutputProcessor();
+               $htmlOutputProcessor->process($htmlInputProcessor->getHtml(), 'com.woltlab.wcf.user.signature', WCF::getUser()->userID);
                
                return [
-                       'message' => $preview
+                       'message' => $htmlOutputProcessor->getHtml(),
+                       'raw' => $htmlInputProcessor->getHtml()
                ];
        }