From b5be45d7065519481510fe6cc7f09bef28bf2373 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joshua=20R=C3=BCsweg?= Date: Fri, 3 Aug 2018 17:51:23 +0200 Subject: [PATCH] Add support for html in trophy descriptions See #2635 --- com.woltlab.wcf/templates/boxUserTrophyList.tpl | 2 +- .../templates/groupedUserTrophyList.tpl | 2 +- com.woltlab.wcf/templates/trophy.tpl | 4 ++-- com.woltlab.wcf/templates/trophyList.tpl | 2 +- .../install/files/acp/templates/trophyAdd.tpl | 7 +++++++ .../files/acp/templates/userTrophyAdd.tpl | 9 +++++++++ .../files/lib/acp/form/TrophyAddForm.class.php | 16 +++++++++++++--- .../files/lib/acp/form/TrophyEditForm.class.php | 4 +++- .../lib/acp/form/UserTrophyAddForm.class.php | 15 ++++++++++++--- .../lib/acp/form/UserTrophyEditForm.class.php | 4 +++- .../files/lib/data/trophy/Trophy.class.php | 6 ++++++ .../lib/data/user/trophy/UserTrophy.class.php | 6 ++++++ wcfsetup/install/lang/de.xml | 1 + wcfsetup/install/lang/en.xml | 1 + wcfsetup/setup/db/install.sql | 2 ++ 15 files changed, 68 insertions(+), 13 deletions(-) diff --git a/com.woltlab.wcf/templates/boxUserTrophyList.tpl b/com.woltlab.wcf/templates/boxUserTrophyList.tpl index ddd992ca71..061b4b924b 100644 --- a/com.woltlab.wcf/templates/boxUserTrophyList.tpl +++ b/com.woltlab.wcf/templates/boxUserTrophyList.tpl @@ -24,7 +24,7 @@

{$boxUserTrophy->getTrophy()->getTitle()}

- {if !$boxUserTrophy->getDescription()|empty}

{$boxUserTrophy->getDescription()}

{/if}

{@$boxUserTrophy->getUserProfile()->getAnchorTag()} {@$boxUserTrophy->time|time}

+ {if !$boxUserTrophy->getDescription()|empty}

{@$boxUserTrophy->getDescription()}

{/if}

{@$boxUserTrophy->getUserProfile()->getAnchorTag()} {@$boxUserTrophy->time|time}

{/foreach} diff --git a/com.woltlab.wcf/templates/groupedUserTrophyList.tpl b/com.woltlab.wcf/templates/groupedUserTrophyList.tpl index a04ba57404..68c6497908 100644 --- a/com.woltlab.wcf/templates/groupedUserTrophyList.tpl +++ b/com.woltlab.wcf/templates/groupedUserTrophyList.tpl @@ -7,7 +7,7 @@

{$userTrophy->getTrophy()->getTitle()}

- {if !$userTrophy->getDescription()|empty}{$userTrophy->getDescription()} {/if}{@$userTrophy->time|time} + {if !$userTrophy->getDescription()|empty}{@$userTrophy->getDescription()} {/if}{@$userTrophy->time|time}
diff --git a/com.woltlab.wcf/templates/trophy.tpl b/com.woltlab.wcf/templates/trophy.tpl index d95b415eae..95a9fcc563 100644 --- a/com.woltlab.wcf/templates/trophy.tpl +++ b/com.woltlab.wcf/templates/trophy.tpl @@ -18,7 +18,7 @@

{$trophy->getTitle()}

diff --git a/wcfsetup/install/files/lib/acp/form/TrophyAddForm.class.php b/wcfsetup/install/files/lib/acp/form/TrophyAddForm.class.php index aa8fa17af4..3fd9ff7753 100644 --- a/wcfsetup/install/files/lib/acp/form/TrophyAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/TrophyAddForm.class.php @@ -112,12 +112,19 @@ class TrophyAddForm extends AbstractAcpForm { * @var int */ public $isDisabled = 0; + /** * `1` if the trophy has conditions to reward automatically trophies. * @var int */ public $awardAutomatically = 0; + /** + * `1` if the trophy contains html in the description + * @var int + */ + public $trophyUseHtml = 0; + /** * list of grouped user group assignment condition object types * @var ObjectType[][] @@ -170,6 +177,7 @@ class TrophyAddForm extends AbstractAcpForm { if (isset($_POST['iconColor'])) $this->iconColor = $_POST['iconColor']; if (isset($_POST['badgeColor'])) $this->badgeColor = $_POST['badgeColor']; if (isset($_POST['awardAutomatically'])) $this->awardAutomatically = 1; + if (isset($_POST['trophyUseHtml'])) $this->trophyUseHtml = 1; // read file upload $fileExtension = WCF::getSession()->getVar('trophyImage-'.$this->tmpHash); @@ -279,7 +287,8 @@ class TrophyAddForm extends AbstractAcpForm { 'categoryID' => $this->categoryID, 'type' => $this->type, 'isDisabled' => $this->isDisabled, - 'awardAutomatically' => $this->awardAutomatically + 'awardAutomatically' => $this->awardAutomatically, + 'trophyUseHtml' => $this->trophyUseHtml ]), 'tmpHash' => $this->tmpHash ]); @@ -311,7 +320,7 @@ class TrophyAddForm extends AbstractAcpForm { public function reset() { parent::reset(); - $this->isDisabled = $this->awardAutomatically = $this->categoryID = 0; + $this->isDisabled = $this->awardAutomatically = $this->categoryID = $this->trophyUseHtml = 0; $this->type = Trophy::TYPE_BADGE; $this->iconName = $this->uploadedImageURL = ''; $this->iconColor = 'rgba(255, 255, 255, 1)'; @@ -344,7 +353,8 @@ class TrophyAddForm extends AbstractAcpForm { 'awardAutomatically' => $this->awardAutomatically, 'availableTypes' => $this->availableTypes, 'tmpHash' => $this->tmpHash, - 'uploadedImageURL' => $this->uploadedImageURL + 'uploadedImageURL' => $this->uploadedImageURL, + 'trophyUseHtml' => $this->trophyUseHtml ]); } } diff --git a/wcfsetup/install/files/lib/acp/form/TrophyEditForm.class.php b/wcfsetup/install/files/lib/acp/form/TrophyEditForm.class.php index cc75811e21..e562bf69ac 100644 --- a/wcfsetup/install/files/lib/acp/form/TrophyEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/TrophyEditForm.class.php @@ -74,6 +74,7 @@ class TrophyEditForm extends TrophyAddForm { $this->iconColor = $this->trophy->iconColor; $this->badgeColor = $this->trophy->badgeColor; $this->awardAutomatically = $this->trophy->awardAutomatically; + $this->trophyUseHtml = $this->trophy->trophyUseHtml; // reset badge values for non badge trophies if ($this->trophy->type != Trophy::TYPE_BADGE) { @@ -164,7 +165,8 @@ class TrophyEditForm extends TrophyAddForm { 'categoryID' => $this->categoryID, 'type' => $this->type, 'isDisabled' => $this->isDisabled, - 'awardAutomatically' => $this->awardAutomatically + 'awardAutomatically' => $this->awardAutomatically, + 'trophyUseHtml' => $this->trophyUseHtml ])]); $this->objectAction->executeAction(); diff --git a/wcfsetup/install/files/lib/acp/form/UserTrophyAddForm.class.php b/wcfsetup/install/files/lib/acp/form/UserTrophyAddForm.class.php index 85c405779b..84e76a7613 100644 --- a/wcfsetup/install/files/lib/acp/form/UserTrophyAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserTrophyAddForm.class.php @@ -62,6 +62,12 @@ class UserTrophyAddForm extends AbstractAcpForm { */ public $description; + /** + * `1` if the trophy contains html in the description + * @var int + */ + public $trophyUseHtml = 0; + /** * @var integer */ @@ -94,6 +100,7 @@ class UserTrophyAddForm extends AbstractAcpForm { if (isset($_POST['user'])) $this->user = StringUtil::trim($_POST['user']); if (isset($_POST['trophyID'])) $this->trophyID = intval($_POST['trophyID']); if (isset($_POST['useCustomDescription'])) $this->useCustomDescription = 1; + if (isset($_POST['trophyUseHtml'])) $this->trophyUseHtml = 1; $this->trophy = new Trophy($this->trophyID); } @@ -168,7 +175,8 @@ class UserTrophyAddForm extends AbstractAcpForm { 'userID' => $user, 'description' => $this->useCustomDescription ? $this->description : '', 'time' => TIME_NOW, - 'useCustomDescription' => $this->useCustomDescription + 'useCustomDescription' => $this->useCustomDescription, + 'trophyUseHtml' => $this->trophyUseHtml ]) ]))->executeAction(); @@ -186,7 +194,7 @@ class UserTrophyAddForm extends AbstractAcpForm { $this->user = $this->userIDs = []; $this->trophyID = ''; - $this->useCustomDescription = 0; + $this->useCustomDescription = $this->trophyUseHtml = 0; } /** @@ -200,7 +208,8 @@ class UserTrophyAddForm extends AbstractAcpForm { 'user' => $this->user, 'trophyCategories' => TrophyCategoryCache::getInstance()->getCategories(), 'useCustomDescription' => $this->useCustomDescription, - 'hasSuitableTrophy' => $this->hasSuitableTrophy() + 'hasSuitableTrophy' => $this->hasSuitableTrophy(), + 'trophyUseHtml' => $this->trophyUseHtml ]); } diff --git a/wcfsetup/install/files/lib/acp/form/UserTrophyEditForm.class.php b/wcfsetup/install/files/lib/acp/form/UserTrophyEditForm.class.php index f9b9557c17..71217f8293 100644 --- a/wcfsetup/install/files/lib/acp/form/UserTrophyEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserTrophyEditForm.class.php @@ -70,6 +70,7 @@ class UserTrophyEditForm extends UserTrophyAddForm { $this->readDataI18n($this->userTrophy); $this->useCustomDescription = $this->userTrophy->useCustomDescription; + $this->trophyUseHtml = $this->userTrophy->trophyUseHtml; } parent::readData(); @@ -86,7 +87,8 @@ class UserTrophyEditForm extends UserTrophyAddForm { $this->objectAction = new UserTrophyAction([$this->userTrophy], 'update', [ 'data' => array_merge($this->additionalFields, [ 'useCustomDescription' => $this->useCustomDescription, - 'description' => $this->description + 'description' => $this->description, + 'trophyUseHtml' => $this->trophyUseHtml ]) ]); $this->objectAction->executeAction(); diff --git a/wcfsetup/install/files/lib/data/trophy/Trophy.class.php b/wcfsetup/install/files/lib/data/trophy/Trophy.class.php index 0a2e7ef622..3287b3f53f 100644 --- a/wcfsetup/install/files/lib/data/trophy/Trophy.class.php +++ b/wcfsetup/install/files/lib/data/trophy/Trophy.class.php @@ -10,6 +10,7 @@ use wcf\system\event\EventHandler; use wcf\system\request\IRouteController; use wcf\system\request\LinkHandler; use wcf\system\WCF; +use wcf\util\StringUtil; /** * Represents a user trophy. @@ -31,6 +32,7 @@ use wcf\system\WCF; * @property-read string $badgeColor the icon badge color * @property-read integer $isDisabled `1` if the trophy is disabled * @property-read integer $awardAutomatically `1` if the trophy is awarded automatically + * @property-read integer $trophyUseHtml `1`, if the trophy use a html description */ class Trophy extends DatabaseObject implements ITitledLinkObject, IRouteController { /** @@ -143,6 +145,10 @@ class Trophy extends DatabaseObject implements ITitledLinkObject, IRouteControll * @return string */ public function getDescription() { + if (!$this->trophyUseHtml) { + return nl2br(StringUtil::encodeHTML(WCF::getLanguage()->get($this->description)), false); + } + return WCF::getLanguage()->get($this->description); } diff --git a/wcfsetup/install/files/lib/data/user/trophy/UserTrophy.class.php b/wcfsetup/install/files/lib/data/user/trophy/UserTrophy.class.php index 0682dcb92d..3229670c45 100644 --- a/wcfsetup/install/files/lib/data/user/trophy/UserTrophy.class.php +++ b/wcfsetup/install/files/lib/data/user/trophy/UserTrophy.class.php @@ -8,6 +8,7 @@ use wcf\data\DatabaseObject; use wcf\system\cache\runtime\UserProfileRuntimeCache; use wcf\system\event\EventHandler; use wcf\system\WCF; +use wcf\util\StringUtil; /** * Represents a user trophy. @@ -24,6 +25,7 @@ use wcf\system\WCF; * @property-read integer $time the time when the trophy was rewarded * @property-read string $description the custom trophy description * @property-read string $useCustomDescription `1`, if the trophy use a custom description + * @property-read integer $trophyUseHtml `1`, if the trophy use a html description */ class UserTrophy extends DatabaseObject { /** @@ -65,6 +67,10 @@ class UserTrophy extends DatabaseObject { return $this->getTrophy()->getDescription(); } + if (!$this->trophyUseHtml) { + return nl2br(StringUtil::encodeHTML(strtr(WCF::getLanguage()->get($this->description), $this->getReplacements())), false); + } + return strtr(WCF::getLanguage()->get($this->description), $this->getReplacements()); } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 03b8d841ad..c6b4f07ea6 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -3854,6 +3854,7 @@ Die E-Mail-Adresse des neuen Benutzers lautet: {@$user->email} {$userTrophy->getTrophy()->getTitle()} von {$userTrophy->getUserProfile()->username} wirklich löschen?]]> Kategorie hinzufügen.]]> Trophäe hinzufügen, welche nicht automatisch durch das System vergeben wird.]]> + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 4d900e4151..06ecb2e3ca 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -3847,6 +3847,7 @@ Open the link below to access the user profile: {$userTrophy->getTrophy()->getTitle()} from {$userTrophy->getUserProfile()->username}?]]> add a category before creating trophies.]]> add a trophy that is not automatically awarded before you award trophies.]]> + diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 1e9cbaf46a..44ed4edd89 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -1382,6 +1382,7 @@ CREATE TABLE wcf1_trophy( badgeColor VARCHAR(255), isDisabled TINYINT(1) NOT NULL DEFAULT 0, awardAutomatically TINYINT(1) NOT NULL DEFAULT 0, + trophyUseHtml TINYINT(1) NOT NULL DEFAULT 0, KEY(categoryID) ); @@ -1594,6 +1595,7 @@ CREATE TABLE wcf1_user_trophy( time INT(10) NOT NULL DEFAULT 0, description MEDIUMTEXT, useCustomDescription TINYINT(1) NOT NULL DEFAULT 0, + trophyUseHtml TINYINT(1) NOT NULL DEFAULT 0, KEY(trophyID, time) ); -- 2.20.1