Shorten code to render individual reactions (in language items)
authorMatthias Schmidt <gravatronics@live.com>
Thu, 21 May 2020 13:18:13 +0000 (15:18 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Thu, 21 May 2020 13:18:13 +0000 (15:18 +0200)
See #3320

wcfsetup/install/files/lib/data/article/LikeableArticleProvider.class.php
wcfsetup/install/files/lib/data/like/Like.class.php
wcfsetup/install/files/lib/system/comment/manager/ArticleCommentManager.class.php
wcfsetup/install/files/lib/system/comment/manager/PageCommentManager.class.php
wcfsetup/install/files/lib/system/comment/manager/UserProfileCommentManager.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 88e3bdfafb7b5b49ac631078ba737874edeb98e5..4eea05fccf490bc3a3dc2cc2d3e71fafa36f7cb8 100644 (file)
@@ -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);
                                
index 1adcfc2a9b64fc0fe1cbe7f3d49c6bf4fab22104..7f7038467525d811808d357ff130fe3e69dba9a5 100644 (file)
@@ -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 '<span title="' . StringUtil::encodeHTML($this) . '" class="jsTooltip">' . $this->getReactionType()->renderIcon() . '</span>';
+       }
+       
        /**
         * Returns the like with given type, object id and user id.
         * 
index c91c5888f552005c7f41751406cb4a67713ddb84..de8632b0f4a64f9b705b15e0ef76b985d9b5c7b2 100644 (file)
@@ -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);
                                                
index fdd42fc953f550aec94ecab137cd3d6c316f413e..1cfe306bc9c86b2f988bae325dc1904a506ad368 100644 (file)
@@ -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
                                                ]);
index 77ebdce387bbac4f577d868e93ee981a3168870f..29dc8a061aab21ce292c890142edd1378ec236a1 100644 (file)
@@ -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
                                                ]);
index 75b37346f48a5cefcbae96ae1ea862f185e381d1..7669b0986c84b924431dcd0f83b47f9787608bdb 100644 (file)
@@ -4018,14 +4018,14 @@ Dateianhänge:
                <item name="wcf.like.likes.noMoreEntries"><![CDATA[Keine weiteren Reaktionen]]></item>
                <item name="wcf.like.dislikes.more"><![CDATA[Weitere Dislikes]]></item>
                <item name="wcf.like.dislikes.noMoreEntries"><![CDATA[Keine weiteren Dislikes]]></item>
-               <item name="wcf.like.title.com.woltlab.wcf.user.profileComment"><![CDATA[Hat mit <span title="{$like->getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()}</span> auf den Kommentar {if $commentAuthor}<a href="{link controller='User' object=$commentAuthor}{/link}">von {$commentAuthor->username}</a>{else}eines Gasts{/if} an der <a href="{$comment->getLink()}">Pinnwand von {$user->username}</a> reagiert.]]></item>
-               <item name="wcf.like.title.com.woltlab.wcf.user.profileComment.response"><![CDATA[Hat mit <span title="{$like->getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()}</span> auf die Antwort {if $responseAuthor}<a href="{link controller='User' object=$responseAuthor}{/link}">von {$responseAuthor->username}</a>{else}eines Gasts{/if} zum Kommentar {if $commentAuthor}von <a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}eines Gasts{/if} an der <a href="{$response->getLink()}">Pinnwand von {$user->username}</a> reagiert.]]></item>
+               <item name="wcf.like.title.com.woltlab.wcf.user.profileComment"><![CDATA[Hat mit {@$reaction->render()} auf den Kommentar {if $commentAuthor}<a href="{link controller='User' object=$commentAuthor}{/link}">von {$commentAuthor->username}</a>{else}eines Gasts{/if} an der <a href="{$comment->getLink()}">Pinnwand von {$user->username}</a> reagiert.]]></item>
+               <item name="wcf.like.title.com.woltlab.wcf.user.profileComment.response"><![CDATA[Hat mit {@$reaction->render()} auf die Antwort {if $responseAuthor}<a href="{link controller='User' object=$responseAuthor}{/link}">von {$responseAuthor->username}</a>{else}eines Gasts{/if} zum Kommentar {if $commentAuthor}von <a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}eines Gasts{/if} an der <a href="{$response->getLink()}">Pinnwand von {$user->username}</a> reagiert.]]></item>
                <item name="wcf.like.objectType.com.woltlab.wcf.likeableArticle"><![CDATA[Artikel]]></item>
-               <item name="wcf.like.title.com.woltlab.wcf.likeableArticle"><![CDATA[Hat mit <span title="{$like->getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()}</span> auf den Artikel <a href="{$article->getLink()}">{$article->getTitle()}</a> reagiert.]]></item>
-               <item name="wcf.like.title.com.woltlab.wcf.articleComment"><![CDATA[Hat mit <span title="{$like->getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()}</span> auf den Kommentar {if $commentAuthor}von <a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}eines Gasts{/if} zum Artikel <a href="{$comment->getLink()}">{$articleContent->getTitle()}</a> reagiert.]]></item>
-               <item name="wcf.like.title.com.woltlab.wcf.articleComment.response"><![CDATA[Hat mit <span title="{$like->getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()}</span> auf die Antwort {if $responseAuthor}von <a href="{link controller='User' object=$responseAuthor}{/link}">{$responseAuthor->username}</a>{else}eines Gasts{/if} zum Kommentar {if $commentAuthor}von <a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}eines Gasts{/if} zum Artikel <a href="{$response->getLink()}">{$articleContent->getTitle()}</a> reagiert.]]></item>
-               <item name="wcf.like.title.com.woltlab.wcf.pageComment"><![CDATA[Hat mit <span title="{$like->getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()}</span> auf den Kommentar {if $commentAuthor}von <a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}eines Gasts{/if} zu der Seite <a href="{$comment->getLink()}">{$page->getTitle()}</a> reagiert.]]></item>
-               <item name="wcf.like.title.com.woltlab.wcf.pageComment.response"><![CDATA[Hat mit <span title="{$like->getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()}</span> auf die Antwort {if $responseAuthor}von <a href="{link controller='User' object=$responseAuthor}{/link}">{$responseAuthor->username}</a>{else}eines Gasts{/if} zum Kommentar {if $commentAuthor}von <a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}eines Gasts{/if} zu der Seite <a href="{$response->getLink()}">{$page->getTitle()}</a> reagiert.]]></item>
+               <item name="wcf.like.title.com.woltlab.wcf.likeableArticle"><![CDATA[Hat mit {@$reaction->render()} auf den Artikel <a href="{$article->getLink()}">{$article->getTitle()}</a> reagiert.]]></item>
+               <item name="wcf.like.title.com.woltlab.wcf.articleComment"><![CDATA[Hat mit {@$reaction->render()} auf den Kommentar {if $commentAuthor}von <a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}eines Gasts{/if} zum Artikel <a href="{$comment->getLink()}">{$articleContent->getTitle()}</a> reagiert.]]></item>
+               <item name="wcf.like.title.com.woltlab.wcf.articleComment.response"><![CDATA[Hat mit {@$reaction->render()} auf die Antwort {if $responseAuthor}von <a href="{link controller='User' object=$responseAuthor}{/link}">{$responseAuthor->username}</a>{else}eines Gasts{/if} zum Kommentar {if $commentAuthor}von <a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}eines Gasts{/if} zum Artikel <a href="{$response->getLink()}">{$articleContent->getTitle()}</a> reagiert.]]></item>
+               <item name="wcf.like.title.com.woltlab.wcf.pageComment"><![CDATA[Hat mit {@$reaction->render()} auf den Kommentar {if $commentAuthor}von <a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}eines Gasts{/if} zu der Seite <a href="{$comment->getLink()}">{$page->getTitle()}</a> reagiert.]]></item>
+               <item name="wcf.like.title.com.woltlab.wcf.pageComment.response"><![CDATA[Hat mit {@$reaction->render()} auf die Antwort {if $responseAuthor}von <a href="{link controller='User' object=$responseAuthor}{/link}">{$responseAuthor->username}</a>{else}eines Gasts{/if} zum Kommentar {if $commentAuthor}von <a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}eines Gasts{/if} zu der Seite <a href="{$response->getLink()}">{$page->getTitle()}</a> reagiert.]]></item>
                <item name="wcf.like.reaction.label"><![CDATA[{#$reactions} Reaktion{if $reactions != 1}en{/if}]]></item>
                <item name="wcf.like.reaction.more"><![CDATA[Weitere Reaktionen]]></item>
                <item name="wcf.like.reaction.noMoreEntries"><![CDATA[Keine weiteren Reaktionen]]></item>
index 57d11c26361b8dba0631e6092ecbf115c4371c2a..4b275e02a21bfd696710d50830bdd64f295211a1 100644 (file)
@@ -3963,14 +3963,14 @@ Attachments:
                <item name="wcf.like.likes.noMoreEntries"><![CDATA[There are no new likes at the moment.]]></item>
                <item name="wcf.like.dislikes.more"><![CDATA[More Dislikes]]></item>
                <item name="wcf.like.dislikes.noMoreEntries"><![CDATA[There are no new dislikes at the moment.]]></item>
-               <item name="wcf.like.title.com.woltlab.wcf.user.profileComment"><![CDATA[Reacted with <span title="{$like->getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()}</span> to the comment by {if $commentAuthor}<a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}a guest{/if} on <a href="{$comment->getLink()}">{$user->username}’s wall</a>.]]></item>
-               <item name="wcf.like.title.com.woltlab.wcf.user.profileComment.response"><![CDATA[Reacted with <span title="{$like->getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()}</span> to the response by {if $responseAuthor}<a href="{link controller='User' object=$responseAuthor}{/link}">{$responseAuthor->username}</a>{else}a guest{/if} on the comment by {if $commentAuthor}<a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}a guest{/if} on <a href="{$response->getLink()}">{$user->username}’s wall</a>.]]></item>
+               <item name="wcf.like.title.com.woltlab.wcf.user.profileComment"><![CDATA[Reacted with {@$reaction->render()} to the comment by {if $commentAuthor}<a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}a guest{/if} on <a href="{$comment->getLink()}">{$user->username}’s wall</a>.]]></item>
+               <item name="wcf.like.title.com.woltlab.wcf.user.profileComment.response"><![CDATA[Reacted with {@$reaction->render()} to the response by {if $responseAuthor}<a href="{link controller='User' object=$responseAuthor}{/link}">{$responseAuthor->username}</a>{else}a guest{/if} on the comment by {if $commentAuthor}<a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}a guest{/if} on <a href="{$response->getLink()}">{$user->username}’s wall</a>.]]></item>
                <item name="wcf.like.objectType.com.woltlab.wcf.likeableArticle"><![CDATA[Article]]></item>
-               <item name="wcf.like.title.com.woltlab.wcf.likeableArticle"><![CDATA[Reacted with <span title="{$like->getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()}</span> to the article <a href="{$article->getLink()}">{$article->getTitle()}</a>.]]></item>
-               <item name="wcf.like.title.com.woltlab.wcf.articleComment"><![CDATA[Reacted with <span title="{$like->getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()}</span> to the comment by {if $commentAuthor}<a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}a guest{/if} on the article <a href="{$comment->getLink()}">{$articleContent->getTitle()}</a>.]]></item>
-               <item name="wcf.like.title.com.woltlab.wcf.articleComment.response"><![CDATA[Reacted with <span title="{$like->getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()}</span> to the response by {if $responseAuthor}<a href="{link controller='User' object=$responseAuthor}{/link}">{$responseAuthor->username}</a>{else}a guest{/if} on the comment by {if $commentAuthor}<a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}a guest{/if} on the article <a href="{$response->getLink()}">{$articleContent->getTitle()}</a>.]]></item>
-               <item name="wcf.like.title.com.woltlab.wcf.pageComment"><![CDATA[Reacted with <span title="{$like->getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()}</span> to the comment by {if $commentAuthor}<a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}a guest{/if} on the page <a href="{$comment->getLink()}">{$page->getTitle()}</a>.]]></item>
-               <item name="wcf.like.title.com.woltlab.wcf.pageComment.response"><![CDATA[Reacted with <span title="{$like->getReactionType()->getTitle()}" class="jsTooltip">{@$like->getReactionType()->renderIcon()}</span> to the response by {if $responseAuthor}<a href="{link controller='User' object=$responseAuthor}{/link}">{$responseAuthor->username}</a>{else}a guest{/if} on the comment by {if $commentAuthor}<a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}a guest{/if} on the page <a href="{$response->getLink()}">{$page->getTitle()}</a>.]]></item>
+               <item name="wcf.like.title.com.woltlab.wcf.likeableArticle"><![CDATA[Reacted with {@$reaction->render()} to the article <a href="{$article->getLink()}">{$article->getTitle()}</a>.]]></item>
+               <item name="wcf.like.title.com.woltlab.wcf.articleComment"><![CDATA[Reacted with {@$reaction->render()} to the comment by {if $commentAuthor}<a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}a guest{/if} on the article <a href="{$comment->getLink()}">{$articleContent->getTitle()}</a>.]]></item>
+               <item name="wcf.like.title.com.woltlab.wcf.articleComment.response"><![CDATA[Reacted with {@$reaction->render()} to the response by {if $responseAuthor}<a href="{link controller='User' object=$responseAuthor}{/link}">{$responseAuthor->username}</a>{else}a guest{/if} on the comment by {if $commentAuthor}<a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}a guest{/if} on the article <a href="{$response->getLink()}">{$articleContent->getTitle()}</a>.]]></item>
+               <item name="wcf.like.title.com.woltlab.wcf.pageComment"><![CDATA[Reacted with {@$reaction->render()} to the comment by {if $commentAuthor}<a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}a guest{/if} on the page <a href="{$comment->getLink()}">{$page->getTitle()}</a>.]]></item>
+               <item name="wcf.like.title.com.woltlab.wcf.pageComment.response"><![CDATA[Reacted with {@$reaction->render()} to the response by {if $responseAuthor}<a href="{link controller='User' object=$responseAuthor}{/link}">{$responseAuthor->username}</a>{else}a guest{/if} on the comment by {if $commentAuthor}<a href="{link controller='User' object=$commentAuthor}{/link}">{$commentAuthor->username}</a>{else}a guest{/if} on the page <a href="{$response->getLink()}">{$page->getTitle()}</a>.]]></item>
                <item name="wcf.like.reaction.label"><![CDATA[{#$reactions} reaction{if $reactions != 1}s{/if}]]></item>
                <item name="wcf.like.reaction.more"><![CDATA[More Reactions]]></item>
                <item name="wcf.like.reaction.noMoreEntries"><![CDATA[There are no new reactions at the moment.]]></item>