From 93dc0cb6402f5fe073b365312352aace2b1083dd Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Thu, 21 May 2020 15:57:00 +0200 Subject: [PATCH] Shorten code to render reaction inline lists (in language items) See #3320 --- .../system/reaction/ReactionHandler.class.php | 19 +++++++++++++++++++ wcfsetup/install/lang/de.xml | 13 +++++++------ wcfsetup/install/lang/en.xml | 13 +++++++------ 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php index ee8b4b57ba..799c3b694d 100644 --- a/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php +++ b/wcfsetup/install/files/lib/system/reaction/ReactionHandler.class.php @@ -789,4 +789,23 @@ class ReactionHandler extends SingletonFactory { return null; } + + /** + * Renders an inline list of reaction counts. + * + * @param int[] $reactionCounts format: `[reactionID => count]` + * @return string + * @since 5.3 + */ + public function renderInlineList(array $reactionCounts) { + $reactionsOuput = []; + foreach ($reactionCounts as $reactionTypeID => $count) { + $reactionsOuput[] = WCF::getLanguage()->getDynamicVariable('wcf.reactions.reactionTypeCount', [ + 'count' => $count, + 'reaction' => $this->getReactionTypeByID($reactionTypeID), + ]); + } + + return implode(',', $reactionsOuput); + } } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 7669b0986c..029f779a29 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -3253,8 +3253,8 @@ Benutzerkontos nun in vollem Umfang nutzen.]]> - getAnchorTag()} hat auf {if LANGUAGE_USE_INFORMAL_VARIANT}deinen{else}Ihren{/if} Artikel {$article->getTitle()} reagiert ({implode from=$reactions key=reactionID item=count}{@$__wcf->getReactionHandler()->getReactionTypeByID($reactionID)->renderIcon()}×{#$count}{/implode}).]]> - getAnchorTag()}{if $count == 2} und {else}, {/if}{@$authors[1]->getAnchorTag()}{if $count == 3} und {@$authors[2]->getAnchorTag()}{/if}{else}{@$authors[0]->getAnchorTag()} und {#$others} weitere{/if} haben auf {if LANGUAGE_USE_INFORMAL_VARIANT}deinen{else}Ihren{/if} Artikel {$article->getTitle()} reagiert ({implode from=$reactions key=reactionID item=count}{@$__wcf->getReactionHandler()->getReactionTypeByID($reactionID)->renderIcon()}×{#$count}{/implode}).]]> + getAnchorTag()} hat auf {if LANGUAGE_USE_INFORMAL_VARIANT}deinen{else}Ihren{/if} Artikel {$article->getTitle()} reagiert ({@$__wcf->getReactionHandler()->renderInlineList($reactions)}).]]> + getAnchorTag()}{if $count == 2} und {else}, {/if}{@$authors[1]->getAnchorTag()}{if $count == 3} und {@$authors[2]->getAnchorTag()}{/if}{else}{@$authors[0]->getAnchorTag()} und {#$others} weitere{/if} haben auf {if LANGUAGE_USE_INFORMAL_VARIANT}deinen{else}Ihren{/if} Artikel {$article->getTitle()} reagiert ({@$__wcf->getReactionHandler()->renderInlineList($reactions)}).]]> filesize|filesize}, {#$attachment->downloads} Mal heruntergeladen{if $attachment->downloads > 0}, zuletzt: {@$attachment->lastDownloadTime|time}{/if})]]> @@ -4361,6 +4361,7 @@ Dateianhänge: + renderIcon()}×{#$count}]]> @@ -5062,8 +5063,8 @@ Benachrichtigungen auf {PAGE_TITLE|lang {@$authorList} {if $count == 1 && $guestTimesTriggered < 2 && (!$event->getAuthor()->userID || $guestTimesTriggered == 0)}hat einen Kommentar{else}haben Kommentare{/if} an {if LANGUAGE_USE_INFORMAL_VARIANT}deiner{else}Ihrer{/if} Pinnwand verfasst:

]]> - getAnchorTag()} hat auf {if LANGUAGE_USE_INFORMAL_VARIANT}deinen{else}Ihren{/if} Kommentar an {if $owner === null}{if LANGUAGE_USE_INFORMAL_VARIANT}deiner{else}Ihrer{/if} Pinnwand{else}der Pinnwand von {$owner->username}{/if} reagiert ({implode from=$reactions key=reactionID item=count}{@$__wcf->getReactionHandler()->getReactionTypeByID($reactionID)->renderIcon()}×{#$count}{/implode}).]]> - getAnchorTag()}{if $count == 2} und {else}, {/if}{@$authors[1]->getAnchorTag()}{if $count == 3} und {@$authors[2]->getAnchorTag()}{/if}{else}{@$authors[0]->getAnchorTag()} und {#$others} weitere Benutzer{/if} haben auf {if LANGUAGE_USE_INFORMAL_VARIANT}deinen{else}Ihren{/if} Kommentar an {if $owner === null}{if LANGUAGE_USE_INFORMAL_VARIANT}deiner{else}Ihrer{/if} Pinnwand{else}der Pinnwand von {$owner->username}{/if} reagiert ({implode from=$reactions key=reactionID item=count}{@$__wcf->getReactionHandler()->getReactionTypeByID($reactionID)->renderIcon()}×{#$count}{/implode}).]]> + getAnchorTag()} hat auf {if LANGUAGE_USE_INFORMAL_VARIANT}deinen{else}Ihren{/if} Kommentar an {if $owner === null}{if LANGUAGE_USE_INFORMAL_VARIANT}deiner{else}Ihrer{/if} Pinnwand{else}der Pinnwand von {$owner->username}{/if} reagiert ({@$__wcf->getReactionHandler()->renderInlineList($reactions)}).]]> + getAnchorTag()}{if $count == 2} und {else}, {/if}{@$authors[1]->getAnchorTag()}{if $count == 3} und {@$authors[2]->getAnchorTag()}{/if}{else}{@$authors[0]->getAnchorTag()} und {#$others} weitere Benutzer{/if} haben auf {if LANGUAGE_USE_INFORMAL_VARIANT}deinen{else}Ihren{/if} Kommentar an {if $owner === null}{if LANGUAGE_USE_INFORMAL_VARIANT}deiner{else}Ihrer{/if} Pinnwand{else}der Pinnwand von {$owner->username}{/if} reagiert ({@$__wcf->getReactionHandler()->renderInlineList($reactions)}).]]> userID}Ein Gast{else}{@$author->getAnchorTag()}{/if} hat eine Antwort zu {if LANGUAGE_USE_INFORMAL_VARIANT}deinem{else}Ihrem{/if} Kommentar an {if $owner->userID == $__wcf->getUser()->userID}{if LANGUAGE_USE_INFORMAL_VARIANT}deiner{else}Ihrer{/if} Pinnwand{else}der Pinnwand von {$owner->username}{/if} verfasst.]]> @@ -5072,8 +5073,8 @@ Benachrichtigungen auf {PAGE_TITLE|lang {@$authorList} {if $count == 1 && $guestTimesTriggered < 2 && (!$event->getAuthor()->userID || $guestTimesTriggered == 0)}hat eine Antwort{else}haben Antworten{/if} zu {if LANGUAGE_USE_INFORMAL_VARIANT}deinem{else}Ihrem{/if} Kommentar an {if $mailbox->getUser()->userID == $notificationContent[variables][owner]->userID}{if LANGUAGE_USE_INFORMAL_VARIANT}deiner{else}Ihrer{/if} Pinnwand{else}der Pinnwand von {$notificationContent[variables][owner]->username}{/if} verfasst:

]]> - getAnchorTag()} hat auf {if LANGUAGE_USE_INFORMAL_VARIANT}deine{else}Ihre{/if} Antwort auf einen Kommentar an {if $owner === null}{if LANGUAGE_USE_INFORMAL_VARIANT}deiner{else}Ihrer{/if} Pinnwand{else}der Pinnwand von {$owner->username}{/if} reagiert ({implode from=$reactions key=reactionID item=count}{@$__wcf->getReactionHandler()->getReactionTypeByID($reactionID)->renderIcon()}×{#$count}{/implode}).]]> - getAnchorTag()}{if $count == 2} und {else}, {/if}{@$authors[1]->getAnchorTag()}{if $count == 3} und {@$authors[2]->getAnchorTag()}{/if}{else}{@$authors[0]->getAnchorTag()} und {#$others} weitere Benutzer{/if} haben auf {if LANGUAGE_USE_INFORMAL_VARIANT}deine{else}Ihre{/if} Antwort auf einen Kommentar an {if $owner === null}{if LANGUAGE_USE_INFORMAL_VARIANT}deiner{else}Ihrer{/if} Pinnwand{else}der Pinnwand von {$owner->username}{/if} reagiert ({implode from=$reactions key=reactionID item=count}{@$__wcf->getReactionHandler()->getReactionTypeByID($reactionID)->renderIcon()}×{#$count}{/implode}).]]> + getAnchorTag()} hat auf {if LANGUAGE_USE_INFORMAL_VARIANT}deine{else}Ihre{/if} Antwort auf einen Kommentar an {if $owner === null}{if LANGUAGE_USE_INFORMAL_VARIANT}deiner{else}Ihrer{/if} Pinnwand{else}der Pinnwand von {$owner->username}{/if} reagiert ({@$__wcf->getReactionHandler()->renderInlineList($reactions)}).]]> + getAnchorTag()}{if $count == 2} und {else}, {/if}{@$authors[1]->getAnchorTag()}{if $count == 3} und {@$authors[2]->getAnchorTag()}{/if}{else}{@$authors[0]->getAnchorTag()} und {#$others} weitere Benutzer{/if} haben auf {if LANGUAGE_USE_INFORMAL_VARIANT}deine{else}Ihre{/if} Antwort auf einen Kommentar an {if $owner === null}{if LANGUAGE_USE_INFORMAL_VARIANT}deiner{else}Ihrer{/if} Pinnwand{else}der Pinnwand von {$owner->username}{/if} reagiert ({@$__wcf->getReactionHandler()->renderInlineList($reactions)}).]]> userID}Ein Gast{else}{@$author->getAnchorTag()}{/if} hat eine Antwort zum Kommentar von {if $commentAuthor->userID}{$commentAuthor->username}{else}{$commentAuthor->username}{/if} an {if LANGUAGE_USE_INFORMAL_VARIANT}deiner{else}Ihrer{/if} Pinnwand verfasst.]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 4b275e02a2..235b475892 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -3176,8 +3176,8 @@ full extend.]]> - getAnchorTag()} reacted to your article {$article->getTitle()} ({implode from=$reactions key=reactionID item=count}{@$__wcf->getReactionHandler()->getReactionTypeByID($reactionID)->renderIcon()}×{#$count}{/implode}).]]> - getAnchorTag()}{if $count == 2} and {else}, {/if}{@$authors[1]->getAnchorTag()}{if $count == 3} and {@$authors[2]->getAnchorTag()}{/if}{else}{@$authors[0]->getAnchorTag()} and {#$others} other users{/if} reacted to article {$article->getTitle()} ({implode from=$reactions key=reactionID item=count}{@$__wcf->getReactionHandler()->getReactionTypeByID($reactionID)->renderIcon()}×{#$count}{/implode}).]]> + getAnchorTag()} reacted to your article {$article->getTitle()} ({@$__wcf->getReactionHandler()->renderInlineList($reactions)}).]]> + getAnchorTag()}{if $count == 2} and {else}, {/if}{@$authors[1]->getAnchorTag()}{if $count == 3} and {@$authors[2]->getAnchorTag()}{/if}{else}{@$authors[0]->getAnchorTag()} and {#$others} other users{/if} reacted to article {$article->getTitle()} ({@$__wcf->getReactionHandler()->renderInlineList($reactions)}).]]>
filesize|filesize}, downloaded {#$attachment->downloads} times{if $attachment->downloads > 0}, last: {@$attachment->lastDownloadTime|time}{/if})]]> @@ -4362,6 +4362,7 @@ Attachments: + renderIcon()}×{#$count}]]> @@ -5059,8 +5060,8 @@ your notifications on {PAGE_TITLE|langu {@$authorList} commented on your wall:

]]> - getAnchorTag()} reacted to your comment on {if $owner === null}your wall{else}{$owner->username}’s wall{/if} ({implode from=$reactions key=reactionID item=count}{@$__wcf->getReactionHandler()->getReactionTypeByID($reactionID)->renderIcon()}×{#$count}{/implode}).]]> - getAnchorTag()}{if $count == 2} and {else}, {/if}{@$authors[1]->getAnchorTag()}{if $count == 3} and {@$authors[2]->getAnchorTag()}{/if}{else}{@$authors[0]->getAnchorTag()} and {#$others} other users{/if} reacted to your comment on {if $owner === null}your wall{else}{$owner->username}’s wall{/if} ({implode from=$reactions key=reactionID item=count}{@$__wcf->getReactionHandler()->getReactionTypeByID($reactionID)->renderIcon()}×{#$count}{/implode}).]]> + getAnchorTag()} reacted to your comment on {if $owner === null}your wall{else}{$owner->username}’s wall{/if} ({@$__wcf->getReactionHandler()->renderInlineList($reactions)}).]]> + getAnchorTag()}{if $count == 2} and {else}, {/if}{@$authors[1]->getAnchorTag()}{if $count == 3} and {@$authors[2]->getAnchorTag()}{/if}{else}{@$authors[0]->getAnchorTag()} and {#$others} other users{/if} reacted to your comment on {if $owner === null}your wall{else}{$owner->username}’s wall{/if} ({@$__wcf->getReactionHandler()->renderInlineList($reactions)}).]]> userID}A guest{else}{@$author->getAnchorTag()}{/if} replied to your comment on {if $owner->userID == $__wcf->getUser()->userID}your{else}{$owner->username}’s{/if} wall.]]> @@ -5069,8 +5070,8 @@ your notifications on {PAGE_TITLE|langu {@$authorList} replied to your comment on {if $mailbox->getUser()->userID == $notificationContent[variables][owner]->userID}your{else}{$notificationContent[variables][owner]->username}’s{/if} wall:

]]> - getAnchorTag()} reacted to your reply to a comment on {if $owner === null}your wall{else}{$owner->username}’s wall{/if} ({implode from=$reactions key=reactionID item=count}{@$__wcf->getReactionHandler()->getReactionTypeByID($reactionID)->renderIcon()}×{#$count}{/implode}).]]> - getAnchorTag()}{if $count == 2} and {else}, {/if}{@$authors[1]->getAnchorTag()}{if $count == 3} and {@$authors[2]->getAnchorTag()}{/if}{else}{@$authors[0]->getAnchorTag()} and {#$others} other users{/if} reacted to your reply to a comment on {if $owner === null}your wall{else}{$owner->username}’s wall{/if} ({implode from=$reactions key=reactionID item=count}{@$__wcf->getReactionHandler()->getReactionTypeByID($reactionID)->renderIcon()}×{#$count}{/implode}).]]> + getAnchorTag()} reacted to your reply to a comment on {if $owner === null}your wall{else}{$owner->username}’s wall{/if} ({@$__wcf->getReactionHandler()->renderInlineList($reactions)}).]]> + getAnchorTag()}{if $count == 2} and {else}, {/if}{@$authors[1]->getAnchorTag()}{if $count == 3} and {@$authors[2]->getAnchorTag()}{/if}{else}{@$authors[0]->getAnchorTag()} and {#$others} other users{/if} reacted to your reply to a comment on {if $owner === null}your wall{else}{$owner->username}’s wall{/if} ({@$__wcf->getReactionHandler()->renderInlineList($reactions)}).]]> userID}A guest{else}{@$author->getAnchorTag()}{/if} replied to {$commentAuthor->username}’s comment on your wall.]]> -- 2.20.1