From: Matthias Schmidt Date: Thu, 21 May 2020 13:18:13 +0000 (+0200) Subject: Shorten code to render individual reactions (in language items) X-Git-Tag: 5.3.0_Alpha_1~287 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=bad92278d2551f195afe20c9acf06e53ef4a809d;p=GitHub%2FWoltLab%2FWCF.git Shorten code to render individual reactions (in language items) See #3320 --- 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()}.]]>