Message options now have WYSIWYG support / fixed signature
authorAlexander Ebert <ebert@woltlab.com>
Thu, 21 Jul 2016 10:54:56 +0000 (12:54 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 21 Jul 2016 10:55:02 +0000 (12:55 +0200)
com.woltlab.wcf/objectType.xml
com.woltlab.wcf/userOption.xml
wcfsetup/install/files/acp/templates/messageOptionType.tpl
wcfsetup/install/files/acp/templates/userAdd.tpl
wcfsetup/install/files/lib/acp/form/UserAddForm.class.php
wcfsetup/install/files/lib/acp/form/UserEditForm.class.php
wcfsetup/install/files/lib/form/SignatureEditForm.class.php
wcfsetup/install/files/lib/system/option/MessageOptionType.class.php
wcfsetup/install/files/lib/system/user/signature/SignatureCache.class.php

index 6c726a2bd12c27ba25bdb582bd83d4c5a656eb49..fc34092717c6cbd082ea3c9411fc18b100c3a04d 100644 (file)
                        <name>com.woltlab.wcf.box.content</name>
                        <definitionname>com.woltlab.wcf.message</definitionname>
                </type>
+               <type>
+                       <name>com.woltlab.wcf.user.aboutMe</name>
+                       <definitionname>com.woltlab.wcf.message</definitionname>
+               </type>
+               <type>
+                       <name>com.woltlab.wcf.user.signature</name>
+                       <definitionname>com.woltlab.wcf.message</definitionname>
+               </type>
                
                <type>
                        <name>com.woltlab.wcf.bbcode.smiley</name>
index 546cb6789bb7e2e6781e9dd3d394faaed1cfb9ef..a56cc8b44293cfb7d041db8e2ee670f7f044c13a 100644 (file)
@@ -61,6 +61,7 @@
                                <outputclass>wcf\system\option\user\MessageUserOptionOutput</outputclass>
                                <visible>15</visible>
                                <editable>3</editable>
+                               <messageObjectType>com.woltlab.wcf.user.aboutMe</messageObjectType>
                        </option>
                        <option name="birthday">
                                <categoryname>profile.personal</categoryname>
index 310cd47267b2652a529a79b087cc1b3db22974f8..4c314f0ca722e66742617bf8c4701d175e4273e0 100644 (file)
@@ -1 +1,2 @@
 <textarea id="{$option->optionName}" name="values[{$option->optionName}]" cols="40" rows="10">{$value}</textarea>
+{include file='wysiwyg' wysiwygSelector=$option->optionName}
index 0814e53b2d198f31160f12b0bca0334e09302384..a062e4511f2ce08effdfc117b659340c949872e0 100644 (file)
                                                <dt><label for="signature">{lang}wcf.user.signature{/lang}</label></dt>
                                                <dd>
                                                        <textarea name="signature" id="signature" cols="40" rows="10">{$signature}</textarea>
+                                                       {include file='wysiwyg' wysiwygSelector='signature'}
                                                </dd>
                                        </dl>
                                        
index ca6d4e8a5c04fce9aa04921e7643debdb4078288..fa39aadf685e7d60c84f8f980423f4a45e07c38b 100644 (file)
@@ -3,8 +3,10 @@ namespace wcf\acp\form;
 use wcf\data\user\group\UserGroup;
 use wcf\data\user\UserAction;
 use wcf\form\AbstractForm;
+use wcf\system\bbcode\BBCodeHandler;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\UserInputException;
+use wcf\system\html\input\HtmlInputProcessor;
 use wcf\system\language\LanguageFactory;
 use wcf\system\WCF;
 use wcf\util\ArrayUtil;
@@ -66,6 +68,11 @@ class UserAddForm extends UserOptionListForm {
         */
        public $groupIDs = [];
        
+       /**
+        * @var HtmlInputProcessor
+        */
+       public $htmlInputProcessor;
+       
        /**
         * language id
         * @var integer
@@ -220,6 +227,17 @@ class UserAddForm extends UserOptionListForm {
                        $this->errorType[$e->getField()] = $e->getType();
                }
                
+               // validate signature
+               $this->htmlInputProcessor = new HtmlInputProcessor();
+               $this->htmlInputProcessor->process($this->signature, 'com.woltlab.wcf.user.signature', 0);
+               
+               BBCodeHandler::getInstance()->setDisallowedBBCodes(explode(',', WCF::getSession()->getPermission('user.signature.disallowedBBCodes')));
+               $disallowedBBCodes = $this->htmlInputProcessor->validate();
+               if (!empty($disallowedBBCodes)) {
+                       WCF::getTPL()->assign('disallowedBBCodes', $disallowedBBCodes);
+                       throw new UserInputException('signature', 'disallowedBBCodes');
+               }
+               
                // validate dynamic options
                parent::validate();
        }
@@ -239,7 +257,7 @@ class UserAddForm extends UserOptionListForm {
                                'email' => $this->email,
                                'password' => $this->password,
                                'userTitle' => $this->userTitle,
-                               'signature' => $this->signature
+                               'signature' => $this->htmlInputProcessor->getHtml()
                        ]),
                        'groups' => $this->groupIDs,
                        'languageIDs' => $this->visibleLanguages,
index 046bde5b5c63de4e6ef88c0d5c25168e4e123de1..22257b698964e11dea3b85d959849f14f87341f4 100755 (executable)
@@ -194,9 +194,6 @@ class UserEditForm extends UserAddForm {
                $this->userTitle = $this->user->userTitle;
                
                $this->signature = $this->user->signature;
-               $this->signatureEnableBBCodes = $this->user->signatureEnableBBCodes;
-               $this->signatureEnableSmilies = $this->user->signatureEnableSmilies;
-               $this->signatureEnableHtml = $this->user->signatureEnableHtml;
                $this->disableSignature = $this->user->disableSignature;
                $this->disableSignatureReason = $this->user->disableSignatureReason;
                $this->disableSignatureExpires = $this->user->disableSignatureExpires;
@@ -291,10 +288,7 @@ class UserEditForm extends UserAddForm {
                                'password' => $this->password,
                                'languageID' => $this->languageID,
                                'userTitle' => $this->userTitle,
-                               'signature' => $this->signature,
-                               'signatureEnableBBCodes' => $this->signatureEnableBBCodes,
-                               'signatureEnableSmilies' => $this->signatureEnableSmilies,
-                               'signatureEnableHtml' => $this->signatureEnableHtml
+                               'signature' => $this->htmlInputProcessor->getHtml()
                        ]),
                        'groups' => $this->groupIDs,
                        'languageIDs' => $this->visibleLanguages,
index b4ec37f299ed05a2f7d14393ab0c4b70510735f5..ad7e051aa48aa05ce6cbf318cbd5fee79f14ea3f 100644 (file)
@@ -26,6 +26,11 @@ class SignatureEditForm extends MessageForm {
         */
        public $loginRequired = true;
        
+       /**
+        * @inheritDoc
+        */
+       public $messageObjectType = 'com.woltlab.wcf.user.signature';
+       
        /**
         * @inheritDoc
         */
index f9eebbe5121fc3b03caf3630f7eaf9f8cca1a4b3..cf2ab8e66e34773bd54c2d66131f2f8ce9f841ad 100644 (file)
@@ -22,29 +22,39 @@ class MessageOptionType extends TextareaOptionType {
         */
        protected $htmlInputProcessor;
        
+       /**
+        * object type for definition 'com.woltlab.wcf.message'
+        * @var string
+        */
+       protected $messageObjectType = '';
+       
        /**
         * @inheritDoc
         */
-       /*public function getData(Option $option, $newValue) {
-               if ($option->disallowedbbcodepermission) {
-                       BBCodeHandler::getInstance()->setDisallowedBBCodes(explode(',', ArrayUtil::trim(WCF::getSession()->getPermission($option->disallowedbbcodepermission))));
+       public function getData(Option $option, $newValue) {
+               if (!$this->messageObjectType) $this->messageObjectType = $option->messageObjectType;
+               if (empty($this->messageObjectType)) {
+                       throw new \RuntimeException("Message object type '".$option->optionName."' requires an object type for definition 'com.woltlab.wcf.message'.");
                }
                
+               $permission = ($option->disallowedbbcodepermission) ?: 'user.message.disallowedBBCodes';
+               BBCodeHandler::getInstance()->setDisallowedBBCodes(explode(',', ArrayUtil::trim(WCF::getSession()->getPermission($permission))));
+               
                $this->htmlInputProcessor = new HtmlInputProcessor();
-               $this->htmlInputProcessor->process($newValue, 'com.woltlab.wcf.invalid', 0);
+               
+               // the object id is fixed because options are not tied to a specific object
+               // especially when used in the user option context, such as "about me"
+               $this->htmlInputProcessor->process($newValue, $this->messageObjectType, 0);
                
                return parent::getData($option, $this->htmlInputProcessor->getHtml());
-       }*/
+       }
        
        /**
         * @inheritDoc
         */
        public function getFormElement(Option $option, $value) {
-               $disallowedBBCodes = [];
-               if ($option->disallowedbbcodepermission) {
-                       $disallowedBBCodes = explode(',', WCF::getSession()->getPermission($option->disallowedbbcodepermission));
-               }
-               BBCodeHandler::getInstance()->setDisallowedBBCodes($disallowedBBCodes);
+               $permission = ($option->disallowedbbcodepermission) ?: 'user.message.disallowedBBCodes';
+               BBCodeHandler::getInstance()->setDisallowedBBCodes(explode(',', ArrayUtil::trim(WCF::getSession()->getPermission($permission))));
                
                WCF::getTPL()->assign([
                        'defaultSmilies' => SmileyCache::getInstance()->getCategorySmilies(),
@@ -58,16 +68,13 @@ class MessageOptionType extends TextareaOptionType {
        /**
         * @inheritDoc
         */
-       /*public function validate(Option $option, $newValue) {
+       public function validate(Option $option, $newValue) {
                parent::validate($option, $newValue);
                
-               if ($option->disallowedbbcodepermission) {
-                       $disallowedBBCodes = $this->htmlInputProcessor->validate();
-                       
-                       if (!empty($disallowedBBCodes)) {
-                               WCF::getTPL()->assign('disallowedBBCodes', $disallowedBBCodes);
-                               throw new UserInputException($option->optionName, 'disallowedBBCodes');
-                       }
+               $disallowedBBCodes = $this->htmlInputProcessor->validate();
+               if (!empty($disallowedBBCodes)) {
+                       WCF::getTPL()->assign('disallowedBBCodes', $disallowedBBCodes);
+                       throw new UserInputException($option->optionName, 'disallowedBBCodes');
                }
-       }*/
+       }
 }
index 1e1dc6e7fd79504055a268fcc13f33db2cca3051..4f13d0ceb2a14cfdbd9beb684fc24ddb2ebc815e 100644 (file)
@@ -36,7 +36,7 @@ class SignatureCache extends SingletonFactory {
                                $this->htmlOutputProcessor = new HtmlOutputProcessor();
                        }
                        
-                       $this->htmlOutputProcessor->process($user->signature, 'com.woltlab.wcf.userSignature', $user->userID);
+                       $this->htmlOutputProcessor->process($user->signature, 'com.woltlab.wcf.user.signature', $user->userID);
                        $this->signatures[$user->userID] = $this->htmlOutputProcessor->getHtml();
                }