From bad92278d2551f195afe20c9acf06e53ef4a809d Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Thu, 21 May 2020 15:18:13 +0200 Subject: [PATCH] Shorten code to render individual reactions (in language items) See #3320 --- .../article/LikeableArticleProvider.class.php | 4 +++- .../files/lib/data/like/Like.class.php | 21 +++++++++++++++++++ .../manager/ArticleCommentManager.class.php | 8 +++++-- .../manager/PageCommentManager.class.php | 6 +++++- .../UserProfileCommentManager.class.php | 6 +++++- wcfsetup/install/lang/de.xml | 14 ++++++------- wcfsetup/install/lang/en.xml | 14 ++++++------- 7 files changed, 54 insertions(+), 19 deletions(-) diff --git a/wcfsetup/install/files/lib/data/article/LikeableArticleProvider.class.php b/wcfsetup/install/files/lib/data/article/LikeableArticleProvider.class.php index 88e3bdfafb..4eea05fccf 100644 --- a/wcfsetup/install/files/lib/data/article/LikeableArticleProvider.class.php +++ b/wcfsetup/install/files/lib/data/article/LikeableArticleProvider.class.php @@ -71,7 +71,9 @@ class LikeableArticleProvider extends AbstractObjectTypeProvider implements ILik // short output $text = WCF::getLanguage()->getDynamicVariable('wcf.like.title.com.woltlab.wcf.likeableArticle', [ 'article' => $article, - 'like' => $like + 'reaction' => $like, + // @deprecated 5.3 Use `$reaction` instead + 'like' => $like, ]); $like->setTitle($text); diff --git a/wcfsetup/install/files/lib/data/like/Like.class.php b/wcfsetup/install/files/lib/data/like/Like.class.php index 1adcfc2a9b..7f70384675 100644 --- a/wcfsetup/install/files/lib/data/like/Like.class.php +++ b/wcfsetup/install/files/lib/data/like/Like.class.php @@ -4,6 +4,7 @@ use wcf\data\reaction\type\ReactionType; use wcf\data\reaction\type\ReactionTypeCache; use wcf\data\DatabaseObject; use wcf\system\WCF; +use wcf\util\StringUtil; /** * Represents a like of an object. @@ -35,6 +36,26 @@ class Like extends DatabaseObject { */ const DISLIKE = -1; + /** + * Returns the title of the associated reaction type. + * + * @return string + * @since 5.3 + */ + public function __toString() { + return $this->getReactionType()->getTitle(); + } + + /** + * Renders the like by showing the associated reaction type's icon. + * + * @return string + * @since 5.3 + */ + public function render() { + return '' . $this->getReactionType()->renderIcon() . ''; + } + /** * Returns the like with given type, object id and user id. * diff --git a/wcfsetup/install/files/lib/system/comment/manager/ArticleCommentManager.class.php b/wcfsetup/install/files/lib/system/comment/manager/ArticleCommentManager.class.php index c91c5888f5..de8632b0f4 100644 --- a/wcfsetup/install/files/lib/system/comment/manager/ArticleCommentManager.class.php +++ b/wcfsetup/install/files/lib/system/comment/manager/ArticleCommentManager.class.php @@ -169,7 +169,9 @@ class ArticleCommentManager extends AbstractCommentManager implements IViewableL 'commentAuthor' => $comment->userID ? $users[$comment->userID] : null, 'comment' => $comment, 'articleContent' => $articleContents[$comment->objectID], - 'like' => $like + 'reaction' => $like, + // @deprecated 5.3 Use `$reaction` instead + 'like' => $like, ]); $like->setTitle($text); @@ -192,8 +194,10 @@ class ArticleCommentManager extends AbstractCommentManager implements IViewableL 'responseAuthor' => $comment->userID ? $users[$response->userID] : null, 'commentAuthor' => $comment->userID ? $users[$comment->userID] : null, 'articleContent' => $articleContents[$comment->objectID], + 'reaction' => $like, + // @deprecated 5.3 Use `$reaction` instead 'like' => $like, - 'response' => $response + 'response' => $response, ]); $like->setTitle($text); diff --git a/wcfsetup/install/files/lib/system/comment/manager/PageCommentManager.class.php b/wcfsetup/install/files/lib/system/comment/manager/PageCommentManager.class.php index fdd42fc953..1cfe306bc9 100644 --- a/wcfsetup/install/files/lib/system/comment/manager/PageCommentManager.class.php +++ b/wcfsetup/install/files/lib/system/comment/manager/PageCommentManager.class.php @@ -163,7 +163,9 @@ class PageCommentManager extends AbstractCommentManager implements IViewableLike 'commentAuthor' => $comment->userID ? $users[$comment->userID] : null, 'comment' => $comment, 'page' => $pages[$comment->objectID], - 'like' => $like + 'reaction' => $like, + // @deprecated 5.3 Use `$reaction` instead + 'like' => $like, ]); $like->setTitle($text); @@ -186,6 +188,8 @@ class PageCommentManager extends AbstractCommentManager implements IViewableLike 'responseAuthor' => $comment->userID ? $users[$response->userID] : null, 'commentAuthor' => $comment->userID ? $users[$comment->userID] : null, 'page' => $pages[$comment->objectID], + 'reaction' => $like, + // @deprecated 5.3 Use `$reaction` instead 'like' => $like, 'response' => $response ]); diff --git a/wcfsetup/install/files/lib/system/comment/manager/UserProfileCommentManager.class.php b/wcfsetup/install/files/lib/system/comment/manager/UserProfileCommentManager.class.php index 77ebdce387..29dc8a061a 100644 --- a/wcfsetup/install/files/lib/system/comment/manager/UserProfileCommentManager.class.php +++ b/wcfsetup/install/files/lib/system/comment/manager/UserProfileCommentManager.class.php @@ -212,7 +212,9 @@ class UserProfileCommentManager extends AbstractCommentManager implements IViewa 'commentAuthor' => $comment->userID ? $users[$comment->userID] : null, 'comment' => $comment, 'user' => $users[$comment->objectID], - 'like' => $like + 'reaction' => $like, + // @deprecated 5.3 Use `$reaction` instead + 'like' => $like, ]); $like->setTitle($text); @@ -235,6 +237,8 @@ class UserProfileCommentManager extends AbstractCommentManager implements IViewa 'responseAuthor' => $response->userID ? $users[$response->userID] : null, 'commentAuthor' => $comment->userID ? $users[$comment->userID] : null, 'user' => $users[$comment->objectID], + 'reaction' => $like, + // @deprecated 5.3 Use `$reaction` instead 'like' => $like, 'response' => $response ]); diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 75b37346f4..7669b0986c 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -4018,14 +4018,14 @@ Dateianhänge: - getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()} auf den Kommentar {if $commentAuthor}von {$commentAuthor->username}{else}eines Gasts{/if} an der Pinnwand von {$user->username} reagiert.]]> - getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()} auf die Antwort {if $responseAuthor}von {$responseAuthor->username}{else}eines Gasts{/if} zum Kommentar {if $commentAuthor}von {$commentAuthor->username}{else}eines Gasts{/if} an der Pinnwand von {$user->username} reagiert.]]> + render()} auf den Kommentar {if $commentAuthor}von {$commentAuthor->username}{else}eines Gasts{/if} an der Pinnwand von {$user->username} reagiert.]]> + render()} auf die Antwort {if $responseAuthor}von {$responseAuthor->username}{else}eines Gasts{/if} zum Kommentar {if $commentAuthor}von {$commentAuthor->username}{else}eines Gasts{/if} an der Pinnwand von {$user->username} reagiert.]]> - getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()} auf den Artikel {$article->getTitle()} reagiert.]]> - getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()} auf den Kommentar {if $commentAuthor}von {$commentAuthor->username}{else}eines Gasts{/if} zum Artikel {$articleContent->getTitle()} reagiert.]]> - getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()} auf die Antwort {if $responseAuthor}von {$responseAuthor->username}{else}eines Gasts{/if} zum Kommentar {if $commentAuthor}von {$commentAuthor->username}{else}eines Gasts{/if} zum Artikel {$articleContent->getTitle()} reagiert.]]> - getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()} auf den Kommentar {if $commentAuthor}von {$commentAuthor->username}{else}eines Gasts{/if} zu der Seite {$page->getTitle()} reagiert.]]> - getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()} auf die Antwort {if $responseAuthor}von {$responseAuthor->username}{else}eines Gasts{/if} zum Kommentar {if $commentAuthor}von {$commentAuthor->username}{else}eines Gasts{/if} zu der Seite {$page->getTitle()} reagiert.]]> + render()} auf den Artikel {$article->getTitle()} reagiert.]]> + render()} auf den Kommentar {if $commentAuthor}von {$commentAuthor->username}{else}eines Gasts{/if} zum Artikel {$articleContent->getTitle()} reagiert.]]> + render()} auf die Antwort {if $responseAuthor}von {$responseAuthor->username}{else}eines Gasts{/if} zum Kommentar {if $commentAuthor}von {$commentAuthor->username}{else}eines Gasts{/if} zum Artikel {$articleContent->getTitle()} reagiert.]]> + render()} auf den Kommentar {if $commentAuthor}von {$commentAuthor->username}{else}eines Gasts{/if} zu der Seite {$page->getTitle()} reagiert.]]> + render()} auf die Antwort {if $responseAuthor}von {$responseAuthor->username}{else}eines Gasts{/if} zum Kommentar {if $commentAuthor}von {$commentAuthor->username}{else}eines Gasts{/if} zu der Seite {$page->getTitle()} reagiert.]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 57d11c2636..4b275e02a2 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -3963,14 +3963,14 @@ Attachments: - getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()} to the comment by {if $commentAuthor}{$commentAuthor->username}{else}a guest{/if} on {$user->username}’s wall.]]> - getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()} to the response by {if $responseAuthor}{$responseAuthor->username}{else}a guest{/if} on the comment by {if $commentAuthor}{$commentAuthor->username}{else}a guest{/if} on {$user->username}’s wall.]]> + render()} to the comment by {if $commentAuthor}{$commentAuthor->username}{else}a guest{/if} on {$user->username}’s wall.]]> + render()} to the response by {if $responseAuthor}{$responseAuthor->username}{else}a guest{/if} on the comment by {if $commentAuthor}{$commentAuthor->username}{else}a guest{/if} on {$user->username}’s wall.]]> - getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()} to the article {$article->getTitle()}.]]> - getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()} to the comment by {if $commentAuthor}{$commentAuthor->username}{else}a guest{/if} on the article {$articleContent->getTitle()}.]]> - getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()} to the response by {if $responseAuthor}{$responseAuthor->username}{else}a guest{/if} on the comment by {if $commentAuthor}{$commentAuthor->username}{else}a guest{/if} on the article {$articleContent->getTitle()}.]]> - getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()} to the comment by {if $commentAuthor}{$commentAuthor->username}{else}a guest{/if} on the page {$page->getTitle()}.]]> - getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()} to the response by {if $responseAuthor}{$responseAuthor->username}{else}a guest{/if} on the comment by {if $commentAuthor}{$commentAuthor->username}{else}a guest{/if} on the page {$page->getTitle()}.]]> + render()} to the article {$article->getTitle()}.]]> + render()} to the comment by {if $commentAuthor}{$commentAuthor->username}{else}a guest{/if} on the article {$articleContent->getTitle()}.]]> + render()} to the response by {if $responseAuthor}{$responseAuthor->username}{else}a guest{/if} on the comment by {if $commentAuthor}{$commentAuthor->username}{else}a guest{/if} on the article {$articleContent->getTitle()}.]]> + render()} to the comment by {if $commentAuthor}{$commentAuthor->username}{else}a guest{/if} on the page {$page->getTitle()}.]]> + render()} to the response by {if $responseAuthor}{$responseAuthor->username}{else}a guest{/if} on the comment by {if $commentAuthor}{$commentAuthor->username}{else}a guest{/if} on the page {$page->getTitle()}.]]> -- 2.20.1