From f3874b1435cf4e984a1f68a5d81ee788a6df963a Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 20 Jan 2019 16:20:47 +0100 Subject: [PATCH] Add support for HTML in category descriptions Close #2833 --- .../install/files/acp/templates/categoryAdd.tpl | 9 +++++++++ .../acp/form/AbstractCategoryAddForm.class.php | 17 ++++++++++++++++- .../acp/form/AbstractCategoryEditForm.class.php | 16 +++++++++++----- .../files/lib/data/category/Category.class.php | 1 + .../category/AbstractCategoryType.class.php | 8 ++++++++ .../lib/system/category/ICategoryType.class.php | 8 ++++++++ wcfsetup/install/lang/de.xml | 1 + wcfsetup/install/lang/en.xml | 1 + wcfsetup/setup/db/install.sql | 1 + 9 files changed, 56 insertions(+), 6 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/categoryAdd.tpl b/wcfsetup/install/files/acp/templates/categoryAdd.tpl index 10ee9ee1ad..8297538c72 100644 --- a/wcfsetup/install/files/acp/templates/categoryAdd.tpl +++ b/wcfsetup/install/files/acp/templates/categoryAdd.tpl @@ -94,6 +94,15 @@ {hascontent}{content}{@$objectType->getProcessor()->getLanguageVariable('description.description', true)}{/content}{/hascontent} + + {if $objectType->getProcessor()->supportsHtmlDescription()} +
+
+
+ +
+
+ {/if} {/if} diff --git a/wcfsetup/install/files/lib/acp/form/AbstractCategoryAddForm.class.php b/wcfsetup/install/files/lib/acp/form/AbstractCategoryAddForm.class.php index e8ab220458..a27de4c5e9 100644 --- a/wcfsetup/install/files/lib/acp/form/AbstractCategoryAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/AbstractCategoryAddForm.class.php @@ -8,6 +8,7 @@ use wcf\form\AbstractForm; use wcf\system\acl\ACLHandler; use wcf\system\category\CategoryHandler; use wcf\system\category\CategoryPermissionHandler; +use wcf\system\category\ICategoryType; use wcf\system\exception\PermissionDeniedException; use wcf\system\exception\SystemException; use wcf\system\exception\UserInputException; @@ -48,6 +49,12 @@ abstract class AbstractCategoryAddForm extends AbstractForm { */ public $categoryNodeTree = null; + /** + * is `1` if HTML is used in the description + * @var integer + */ + public $descriptionUseHtml = 0; + /** * indicates if the category is disabled * @var integer @@ -145,6 +152,7 @@ abstract class AbstractCategoryAddForm extends AbstractForm { 'addController' => $this->addController, 'additionalData' => $this->additionalData, 'categoryNodeList' => $this->categoryNodeTree->getIterator(), + 'descriptionUseHtml' => $this->descriptionUseHtml, 'editController' => $this->editController, 'isDisabled' => $this->isDisabled, 'listController' => $this->listController, @@ -221,6 +229,9 @@ abstract class AbstractCategoryAddForm extends AbstractForm { if (isset($_POST['isDisabled'])) { $this->isDisabled = 1; } + if (isset($_POST['descriptionUseHtml'])) { + $this->descriptionUseHtml = 1; + } if (isset($_POST['parentCategoryID'])) { $this->parentCategoryID = intval($_POST['parentCategoryID']); } @@ -235,10 +246,14 @@ abstract class AbstractCategoryAddForm extends AbstractForm { public function save() { parent::save(); + /** @var ICategoryType $categoryType */ + $categoryType = $this->objectType->getProcessor(); + $this->objectAction = new CategoryAction([], 'create', [ 'data' => array_merge($this->additionalFields, [ 'additionalData' => serialize($this->additionalData), - 'description' => ($this->objectType->getProcessor()->hasDescription() && I18nHandler::getInstance()->isPlainValue('description')) ? I18nHandler::getInstance()->getValue('description') : '', + 'description' => ($categoryType->hasDescription() && I18nHandler::getInstance()->isPlainValue('description')) ? I18nHandler::getInstance()->getValue('description') : '', + 'descriptionUseHtml' => $categoryType->supportsHtmlDescription() ? $this->descriptionUseHtml : 0, 'isDisabled' => $this->isDisabled, 'objectTypeID' => $this->objectType->objectTypeID, 'parentCategoryID' => $this->parentCategoryID, diff --git a/wcfsetup/install/files/lib/acp/form/AbstractCategoryEditForm.class.php b/wcfsetup/install/files/lib/acp/form/AbstractCategoryEditForm.class.php index 0d8c471336..5954a8b066 100644 --- a/wcfsetup/install/files/lib/acp/form/AbstractCategoryEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/AbstractCategoryEditForm.class.php @@ -7,6 +7,7 @@ use wcf\form\AbstractForm; use wcf\system\acl\ACLHandler; use wcf\system\category\CategoryHandler; use wcf\system\category\CategoryPermissionHandler; +use wcf\system\category\ICategoryType; use wcf\system\exception\IllegalLinkException; use wcf\system\exception\PermissionDeniedException; use wcf\system\exception\UserInputException; @@ -99,6 +100,7 @@ class AbstractCategoryEditForm extends AbstractCategoryAddForm { I18nHandler::getInstance()->setOptions('title', $this->packageID, $this->category->title, $this->objectType->getProcessor()->getI18nLangVarPrefix().'.title.category\d+'); $this->additionalData = $this->category->additionalData; + $this->descriptionUseHtml = $this->category->descriptionUseHtml; $this->isDisabled = $this->category->isDisabled; $this->parentCategoryID = $this->category->parentCategoryID; $this->showOrder = $this->category->showOrder; @@ -111,27 +113,30 @@ class AbstractCategoryEditForm extends AbstractCategoryAddForm { public function save() { AbstractForm::save(); + /** @var ICategoryType $categoryType */ + $categoryType = $this->objectType->getProcessor(); + // handle description $description = ''; - if ($this->objectType->getProcessor()->hasDescription()) { - $description = $this->objectType->getProcessor()->getI18nLangVarPrefix().'.description.category'.$this->category->categoryID; + if ($categoryType->hasDescription()) { + $description = $categoryType->getI18nLangVarPrefix().'.description.category'.$this->category->categoryID; if (I18nHandler::getInstance()->isPlainValue('description')) { I18nHandler::getInstance()->remove($description); $description = I18nHandler::getInstance()->getValue('description'); } else { - I18nHandler::getInstance()->save('description', $description, $this->objectType->getProcessor()->getDescriptionLangVarCategory(), $this->packageID); + I18nHandler::getInstance()->save('description', $description, $categoryType->getDescriptionLangVarCategory(), $this->packageID); } } // handle title - $title = $this->objectType->getProcessor()->getI18nLangVarPrefix().'.title.category'.$this->category->categoryID; + $title = $categoryType->getI18nLangVarPrefix().'.title.category'.$this->category->categoryID; if (I18nHandler::getInstance()->isPlainValue('title')) { I18nHandler::getInstance()->remove($title); $title = I18nHandler::getInstance()->getValue('title'); } else { - I18nHandler::getInstance()->save('title', $title, $this->objectType->getProcessor()->getTitleLangVarCategory(), $this->packageID); + I18nHandler::getInstance()->save('title', $title, $categoryType->getTitleLangVarCategory(), $this->packageID); } // update category @@ -139,6 +144,7 @@ class AbstractCategoryEditForm extends AbstractCategoryAddForm { 'data' => array_merge($this->additionalFields, [ 'additionalData' => serialize($this->additionalData), 'description' => $description, + 'descriptionUseHtml' => $categoryType->supportsHtmlDescription() ? $this->descriptionUseHtml : 0, 'isDisabled' => $this->isDisabled, 'parentCategoryID' => $this->parentCategoryID, 'showOrder' => $this->showOrder, diff --git a/wcfsetup/install/files/lib/data/category/Category.class.php b/wcfsetup/install/files/lib/data/category/Category.class.php index b8c535e858..a86322172a 100644 --- a/wcfsetup/install/files/lib/data/category/Category.class.php +++ b/wcfsetup/install/files/lib/data/category/Category.class.php @@ -24,6 +24,7 @@ use wcf\system\WCF; * @property-read integer $parentCategoryID id of the category's parent category or `0` if it has no parent category * @property-read string $title title of the category or name of language item which contains the title * @property-read string $description description of the category or name of language item which contains the description + * @property-read integer $descriptionUseHtml is `1` if html is enabled in the description, otherwise `0` * @property-read integer $showOrder position of the category in relation to its siblings * @property-read integer $time timestamp at which the comment has been created * @property-read integer $isDisabled is `1` if the category is disabled and thus neither accessible nor selectable, otherwise `0` diff --git a/wcfsetup/install/files/lib/system/category/AbstractCategoryType.class.php b/wcfsetup/install/files/lib/system/category/AbstractCategoryType.class.php index 3c2faf6564..dc7d5879d4 100644 --- a/wcfsetup/install/files/lib/system/category/AbstractCategoryType.class.php +++ b/wcfsetup/install/files/lib/system/category/AbstractCategoryType.class.php @@ -184,4 +184,12 @@ abstract class AbstractCategoryType extends SingletonFactory implements ICategor public function hasDescription() { return $this->hasDescription; } + + /** + * @inheritDoc + * @since 5.2 + */ + public function supportsHtmlDescription() { + return false; + } } diff --git a/wcfsetup/install/files/lib/system/category/ICategoryType.class.php b/wcfsetup/install/files/lib/system/category/ICategoryType.class.php index f7c6a24853..184f70f0e5 100644 --- a/wcfsetup/install/files/lib/system/category/ICategoryType.class.php +++ b/wcfsetup/install/files/lib/system/category/ICategoryType.class.php @@ -141,4 +141,12 @@ interface ICategoryType { * @return boolean */ public function hasDescription(); + + /** + * Returns `true` if the descriptions of categories of this type support HTML. + * + * @return boolean + * @since 5.2 + */ + public function supportsHtmlDescription(); } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index a608755c49..4a28b32a4b 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -3175,6 +3175,7 @@ Erlaubte Dateiendungen: {', '|implode:$attachmentHandler->getFormattedAllowedExt + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 99702f7fe3..3f9c2b3503 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -3099,6 +3099,7 @@ Allowed extensions: {', '|implode:$attachmentHandler->getFormattedAllowedExtensi + diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 7cb83622b5..7c8909e89d 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -350,6 +350,7 @@ CREATE TABLE wcf1_category ( parentCategoryID INT(10) NOT NULL DEFAULT 0, title VARCHAR(255) NOT NULL, description TEXT, + descriptionUseHtml TINYINT(1) NOT NULL DEFAULT 0, showOrder INT(10) NOT NULL DEFAULT 0, time INT(10) NOT NULL DEFAULT 0, isDisabled TINYINT(1) NOT NULL DEFAULT 0, -- 2.20.1