Support disallowed bbcodes in wysiwyg form builder field
authorMatthias Schmidt <gravatronics@live.com>
Sat, 17 Aug 2019 16:00:54 +0000 (18:00 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 17 Aug 2019 16:00:54 +0000 (18:00 +0200)
Close #3022

com.woltlab.wcf/objectType.xml
wcfsetup/install/files/lib/system/form/builder/field/wysiwyg/WysiwygFormField.class.php
wcfsetup/install/files/lib/system/package/plugin/ObjectTypePackageInstallationPlugin.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index d0da57fbcd3ea727d3328a09108c9d8f4d189c36..fa07ea4b5bf6be45c9169276a050c00c9b755185 100644 (file)
                <type>
                        <name>com.woltlab.wcf.user.signature</name>
                        <definitionname>com.woltlab.wcf.message</definitionname>
+                       <disallowedBBCodesPermission>user.signature.disallowedBBCodes</disallowedBBCodesPermission>
                </type>
                <type>
                        <name>com.woltlab.wcf.user.signature</name>
                <type>
                        <name>com.woltlab.wcf.comment</name>
                        <definitionname>com.woltlab.wcf.message</definitionname>
+                       <disallowedBBCodesPermission>user.comment.disallowedBBCodes</disallowedBBCodesPermission>
                </type>
                <type>
                        <name>com.woltlab.wcf.comment.response</name>
                        <definitionname>com.woltlab.wcf.message</definitionname>
+                       <disallowedBBCodesPermission>user.comment.disallowedBBCodes</disallowedBBCodesPermission>
                </type>
                <type>
                        <name>com.woltlab.wcf.paidSubscription</name>
index 040cc89159eb2ac2a2aeb8c10da223d6d540c7aa..cb7b0efe5c9553719f58bad2bea752a870be02bf 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\system\form\builder\field\wysiwyg;
 use wcf\data\IMessageQuoteAction;
 use wcf\data\object\type\ObjectTypeCache;
+use wcf\system\bbcode\BBCodeHandler;
 use wcf\system\form\builder\data\processor\CustomFormDataProcessor;
 use wcf\system\form\builder\field\AbstractFormField;
 use wcf\system\form\builder\field\IMaximumLengthFormField;
@@ -15,6 +16,7 @@ use wcf\system\form\builder\TObjectTypeFormNode;
 use wcf\system\html\input\HtmlInputProcessor;
 use wcf\system\message\censorship\Censorship;
 use wcf\system\message\quote\MessageQuoteManager;
+use wcf\system\WCF;
 use wcf\util\StringUtil;
 
 /**
@@ -115,6 +117,17 @@ class WysiwygFormField extends AbstractFormField implements IMaximumLengthFormFi
                        MessageQuoteManager::getInstance()->assignVariables();
                }
                
+               /** @noinspection PhpUndefinedFieldInspection */
+               $disallowedBBCodesPermission = $this->getObjectType()->disallowedBBCodesPermission;
+               if ($disallowedBBCodesPermission === null) {
+                       $disallowedBBCodesPermission = 'user.message.disallowedBBCodes';
+               }
+               
+               BBCodeHandler::getInstance()->setDisallowedBBCodes(explode(
+                       ',',
+                       WCF::getSession()->getPermission($disallowedBBCodesPermission)
+               ));
+               
                return parent::getHtml();
        }
        
@@ -345,6 +358,17 @@ class WysiwygFormField extends AbstractFormField implements IMaximumLengthFormFi
         * @inheritDoc
         */
        public function validate() {
+               /** @noinspection PhpUndefinedFieldInspection */
+               $disallowedBBCodesPermission = $this->getObjectType()->disallowedBBCodesPermission;
+               if ($disallowedBBCodesPermission === null) {
+                       $disallowedBBCodesPermission = 'user.message.disallowedBBCodes';
+               }
+               
+               BBCodeHandler::getInstance()->setDisallowedBBCodes(explode(
+                       ',',
+                       WCF::getSession()->getPermission($disallowedBBCodesPermission)
+               ));
+               
                $this->htmlInputProcessor = new HtmlInputProcessor();
                $this->htmlInputProcessor->process($this->getValue(), $this->getObjectType()->objectType);
                
@@ -352,18 +376,28 @@ class WysiwygFormField extends AbstractFormField implements IMaximumLengthFormFi
                        $this->addValidationError(new FormFieldValidationError('empty'));
                }
                else {
-                       $message = $this->htmlInputProcessor->getTextContent();
-                       $this->validateMinimumLength($message);
-                       $this->validateMaximumLength($message);
-                       
-                       if (empty($this->getValidationErrors()) && ENABLE_CENSORSHIP) {
-                               $result = Censorship::getInstance()->test($message);
-                               if ($result) {
-                                       $this->addValidationError(new FormFieldValidationError(
-                                               'censoredWords',
-                                               'wcf.message.error.censoredWordsFound',
-                                               ['censoredWords' => $result]
-                                       ));
+                       $disallowedBBCodes = $this->htmlInputProcessor->validate();
+                       if (!empty($disallowedBBCodes)) {
+                               $this->addValidationError(new FormFieldValidationError(
+                                       'disallowedBBCodes',
+                                       'wcf.message.error.disallowedBBCodes',
+                                       ['disallowedBBCodes' => $disallowedBBCodes]
+                               ));
+                       }
+                       else {
+                               $message = $this->htmlInputProcessor->getTextContent();
+                               $this->validateMinimumLength($message);
+                               $this->validateMaximumLength($message);
+                               
+                               if (empty($this->getValidationErrors()) && ENABLE_CENSORSHIP) {
+                                       $result = Censorship::getInstance()->test($message);
+                                       if ($result) {
+                                               $this->addValidationError(new FormFieldValidationError(
+                                                       'censoredWords',
+                                                       'wcf.message.error.censoredWordsFound',
+                                                       ['censoredWords' => $result]
+                                               ));
+                                       }
                                }
                        }
                }
index de3e9dcfaef8a872c5491a792ffc446a83f27d26..5a5f34360011154ba3fe379cbb9b44015a05a663 100644 (file)
@@ -6,6 +6,7 @@ use wcf\data\object\type\ObjectTypeEditor;
 use wcf\data\DatabaseObjectList;
 use wcf\data\page\PageNode;
 use wcf\data\page\PageNodeTree;
+use wcf\data\user\group\option\UserGroupOption;
 use wcf\system\application\ApplicationHandler;
 use wcf\system\condition\AbstractIntegerCondition;
 use wcf\system\condition\UserGroupCondition;
@@ -480,11 +481,39 @@ class ObjectTypePackageInstallationPlugin extends AbstractXMLPackageInstallation
                // com.woltlab.wcf.message
                $this->getObjectTypeDefinitionDataContainer($form, 'com.woltlab.wcf.message')
                        ->appendChildren([
-                               BooleanFormField::create('enableToc')
+                               // TODO: maximum of one item (see https://github.com/WoltLab/WCF/issues/3040)
+                               UserGroupOptionFormField::create('messageObjectDisallowedBBCodesPermission')
+                                       ->objectProperty('disallowedBBCodesPermission')
+                                       ->label('wcf.acp.pip.objectType.com.woltlab.wcf.message.disallowedBBCodesPermission')
+                                       ->description('wcf.acp.pip.objectType.com.woltlab.wcf.message.disallowedBBCodesPermission.description')
+                                       ->addValidator(new FormFieldValidator('optionType', function(UserGroupOptionFormField $formField) {
+                                               $value = $formField->getValue();
+                                               if (empty($value)) return;
+                                               
+                                               $sql = "SELECT  optionType
+                                                       FROM    wcf" . WCF_N . "_user_group_option
+                                                       WHERE   optionName = ?";
+                                               $statement = WCF::getDB()->prepareStatement($sql);
+                                               $statement->execute([reset($value)]);
+                                               if ($statement->fetchSingleColumn() !== 'BBCodeSelect') {
+                                                       $formField->addValidationError(
+                                                               new FormFieldValidationError(
+                                                                       'optionType',
+                                                                       'wcf.acp.pip.objectType.com.woltlab.wcf.message.disallowedBBCodesPermission.error.optionType'
+                                                               )
+                                                       );
+                                               }
+                                       })),
+                               
+                               BooleanFormField::create('messageObjectTypeEnableToc')
+                                       ->objectProperty('enableToc')
                                        ->label('wcf.acp.pip.objectType.com.woltlab.wcf.message.enableToc')
                                        ->description('wcf.acp.pip.objectType.com.woltlab.wcf.message.enableToc.description')
                        ]);
-               $this->definitionElementChildren['com.woltlab.wcf.message'] = ['enableToc' => 0];
+               $this->definitionElementChildren['com.woltlab.wcf.message'] = [
+                       'disallowedBBCodesPermission' => '',
+                       'enableToc' => 0
+               ];
                
                // com.woltlab.wcf.notification.objectType
                $this->getObjectTypeDefinitionDataContainer($form, 'com.woltlab.wcf.notification.objectType')
index 5b51d7143ba7ef2ce29f964caa9761e1199e56f8..4ddd527816fb321a6a5ab6a275cdba77228aa586 100644 (file)
@@ -2398,6 +2398,9 @@ Die Datenbestände werden sorgfältig gepflegt, aber es ist nicht ausgeschlossen
                <item name="wcf.acp.pip.objectType.com.woltlab.wcf.content.userContentProvider.requiredObjectType"><![CDATA[Benötigte Objekt-Typen]]></item>
                <item name="wcf.acp.pip.objectType.com.woltlab.wcf.content.userContentProvider.requiredObjectType.description"><![CDATA[Die durch die angegebenen Objekttypen repräsentierten Benutzerinhalte werden bei der Entfernung der Benutzerinhalte durch <strong>diesen</strong> Anbieter ebenfalls entfernt. Muss dabei eine bestimmte Reihenfolge beachtet werden, müssen nice-Werte angegeben werden.]]></item>
                <item name="wcf.acp.pip.objectType.com.woltlab.wcf.message.data.title"><![CDATA[Daten des Nachrichtentyps]]></item>
+               <item name="wcf.acp.pip.objectType.com.woltlab.wcf.message.disallowedBBCodesPermission"><![CDATA[Berechtigung für nicht erlaubte BBCodes]]></item>
+               <item name="wcf.acp.pip.objectType.com.woltlab.wcf.message.disallowedBBCodesPermission.description"><![CDATA[Wird mit der Form Builder-API eine Nachricht dieses Typs erstellt, wird die angegebene Benutzergruppenberechtigung dafür verwendet, für nicht erlaubten BBCodes zu bestimmen. Wird keine Berechtigung angegeben, wird die allgemeine Berechtigung für nicht erlaubte BBCodes für Nachrichten verwendet.]]></item>
+               <item name="wcf.acp.pip.objectType.com.woltlab.wcf.message.disallowedBBCodesPermission.error.optionType"><![CDATA[Die angegebene Benutzergruppenberechtigung muss vom Typ BBCodeSelect sein.]]></item>
                <item name="wcf.acp.pip.objectType.com.woltlab.wcf.message.enableToc"><![CDATA[Inhaltsverzeichnis erstellen]]></item>
                <item name="wcf.acp.pip.objectType.com.woltlab.wcf.message.enableToc.description"><![CDATA[Wenn ausgewählt wird ein Inhaltsverzeichnis für jede Nachricht dieses Types erstellt.]]></item>
                <item name="wcf.acp.pip.objectType.com.woltlab.wcf.notification.objectType.category"><![CDATA[Kategorie]]></item>
index e0bd56b447c0379df0fd20427aa38bd86da80ef9..0b5988b9698bda94194a81d7af2c20b2339b42f5 100644 (file)
@@ -2461,6 +2461,9 @@ If you have <strong>already bought the licenses for the listed apps</strong>, th
                <item name="wcf.acp.pip.objectType.integerCondition.propertyName.description"><![CDATA[Name of the object property and column of <kbd>{$tableName}</kbd> database table used for this condition.]]></item>
                <item name="wcf.acp.pip.objectType.integerCondition.propertyName"><![CDATA[Object Property Name]]></item>
                <item name="wcf.acp.pip.objectType.com.woltlab.wcf.message.data.title"><![CDATA[Message Type Data]]></item>
+               <item name="wcf.acp.pip.objectType.com.woltlab.wcf.message.disallowedBBCodesPermission"><![CDATA[Permission for Disallowed BBCodes]]></item>
+               <item name="wcf.acp.pip.objectType.com.woltlab.wcf.message.disallowedBBCodesPermission.description"><![CDATA[If the form builder API is used to create a message of this type, the given user group permission will be used to determine the disallowed BBCodes. If no permission is given, the general permission for disallowed BBCodes for messages is used.]]></item>
+               <item name="wcf.acp.pip.objectType.com.woltlab.wcf.message.disallowedBBCodesPermission.error.optionType"><![CDATA[The entered user group permission’s type has to be BBCodeSelect.]]></item>
                <item name="wcf.acp.pip.objectType.com.woltlab.wcf.message.enableToc"><![CDATA[Generate Table of Contents]]></item>
                <item name="wcf.acp.pip.objectType.com.woltlab.wcf.message.enableToc.description"><![CDATA[If selected, a table of contents is created for each message of this type.]]></item>
                <item name="wcf.acp.pip.templateListener.niceValue"><![CDATA[Nice Value]]></item>