From e620e94f52d8b0579af2cbd459e74b8aa27b2f0f Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Sun, 15 Oct 2017 18:06:37 +0200 Subject: [PATCH] Added generic templates for comment notification emails Closes #2444 --- ...ner.tpl => email_notification_comment.tpl} | 8 +++---- ...=> email_notification_commentResponse.tpl} | 4 ++-- ...ail_notification_commentResponseOwner.tpl} | 4 ++-- .../files/lib/data/comment/Comment.class.php | 21 +++++++++++++++++++ ...sponseOwnerUserNotificationEvent.class.php | 5 +++-- ...entResponseUserNotificationEvent.class.php | 5 +++-- ...fileCommentUserNotificationEvent.class.php | 5 +++-- 7 files changed, 38 insertions(+), 14 deletions(-) rename com.woltlab.wcf/templates/{email_notification_userProfileCommentResponseOwner.tpl => email_notification_comment.tpl} (83%) rename com.woltlab.wcf/templates/{email_notification_userProfileComment.tpl => email_notification_commentResponse.tpl} (91%) rename com.woltlab.wcf/templates/{email_notification_userProfileCommentResponse.tpl => email_notification_commentResponseOwner.tpl} (90%) diff --git a/com.woltlab.wcf/templates/email_notification_userProfileCommentResponseOwner.tpl b/com.woltlab.wcf/templates/email_notification_comment.tpl similarity index 83% rename from com.woltlab.wcf/templates/email_notification_userProfileCommentResponseOwner.tpl rename to com.woltlab.wcf/templates/email_notification_comment.tpl index 5874fefdfd..26400f1769 100644 --- a/com.woltlab.wcf/templates/email_notification_userProfileCommentResponseOwner.tpl +++ b/com.woltlab.wcf/templates/email_notification_comment.tpl @@ -1,12 +1,12 @@ {assign var='count' value=$event->getAuthors()|count}{assign var='guestTimesTriggered' value=$event->getNotification()->guestTimesTriggered}{assign var='authors' value=$event->getAuthors()|array_values} {if $mimeType === 'text/plain'} {capture assign='authorList'}{lang}wcf.user.notification.mail.authorList.plaintext{/lang}{/capture} -{lang}wcf.user.notification.commentResponseOwner.mail.plaintext{/lang}{if $count == 1 && !$guestTimesTriggered} +{lang}{@$languageVariablePrefix}.mail.plaintext{/lang}{if $count == 1 && !$guestTimesTriggered} -{$event->getUserNotificationObject()->message}{/if} {* this line ends with a space *} +{@$event->getUserNotificationObject()->getMailText($mimeType)}{/if} {* this line ends with a space *} {else} {capture assign='authorList'}{lang}wcf.user.notification.mail.authorList.html{/lang}{/capture} - {lang}wcf.user.notification.commentResponseOwner.mail.html{/lang} + {lang}{@$languageVariablePrefix}.mail.html{/lang} {assign var='user' value=$event->getAuthor()} {assign var='comment' value=$event->getUserNotificationObject()} @@ -29,7 +29,7 @@
- {$comment->message} + {@$comment->getMailText($mimeType)}
diff --git a/com.woltlab.wcf/templates/email_notification_userProfileComment.tpl b/com.woltlab.wcf/templates/email_notification_commentResponse.tpl similarity index 91% rename from com.woltlab.wcf/templates/email_notification_userProfileComment.tpl rename to com.woltlab.wcf/templates/email_notification_commentResponse.tpl index 07866879a9..282daf06b2 100644 --- a/com.woltlab.wcf/templates/email_notification_userProfileComment.tpl +++ b/com.woltlab.wcf/templates/email_notification_commentResponse.tpl @@ -1,12 +1,12 @@ {assign var='count' value=$event->getAuthors()|count}{assign var='guestTimesTriggered' value=$event->getNotification()->guestTimesTriggered}{assign var='authors' value=$event->getAuthors()|array_values} {if $mimeType === 'text/plain'} {capture assign='authorList'}{lang}wcf.user.notification.mail.authorList.plaintext{/lang}{/capture} -{lang}wcf.user.notification.comment.mail.plaintext{/lang}{if $count == 1 && !$guestTimesTriggered} +{lang}{@$languageVariablePrefix}.mail.plaintext{/lang}{if $count == 1 && !$guestTimesTriggered} {$event->getUserNotificationObject()->message}{/if} {* this line ends with a space *} {else} {capture assign='authorList'}{lang}wcf.user.notification.mail.authorList.html{/lang}{/capture} - {lang}wcf.user.notification.comment.mail.html{/lang} + {lang}{@$languageVariablePrefix}.mail.html{/lang} {assign var='user' value=$event->getAuthor()} {assign var='comment' value=$event->getUserNotificationObject()} diff --git a/com.woltlab.wcf/templates/email_notification_userProfileCommentResponse.tpl b/com.woltlab.wcf/templates/email_notification_commentResponseOwner.tpl similarity index 90% rename from com.woltlab.wcf/templates/email_notification_userProfileCommentResponse.tpl rename to com.woltlab.wcf/templates/email_notification_commentResponseOwner.tpl index 4cd7492862..282daf06b2 100644 --- a/com.woltlab.wcf/templates/email_notification_userProfileCommentResponse.tpl +++ b/com.woltlab.wcf/templates/email_notification_commentResponseOwner.tpl @@ -1,12 +1,12 @@ {assign var='count' value=$event->getAuthors()|count}{assign var='guestTimesTriggered' value=$event->getNotification()->guestTimesTriggered}{assign var='authors' value=$event->getAuthors()|array_values} {if $mimeType === 'text/plain'} {capture assign='authorList'}{lang}wcf.user.notification.mail.authorList.plaintext{/lang}{/capture} -{lang}wcf.user.notification.commentResponse.mail.plaintext{/lang}{if $count == 1 && !$guestTimesTriggered} +{lang}{@$languageVariablePrefix}.mail.plaintext{/lang}{if $count == 1 && !$guestTimesTriggered} {$event->getUserNotificationObject()->message}{/if} {* this line ends with a space *} {else} {capture assign='authorList'}{lang}wcf.user.notification.mail.authorList.html{/lang}{/capture} - {lang}wcf.user.notification.commentResponse.mail.html{/lang} + {lang}{@$languageVariablePrefix}.mail.html{/lang} {assign var='user' value=$event->getAuthor()} {assign var='comment' value=$event->getUserNotificationObject()} diff --git a/wcfsetup/install/files/lib/data/comment/Comment.class.php b/wcfsetup/install/files/lib/data/comment/Comment.class.php index 1ac5d10db0..142d5ec1fe 100644 --- a/wcfsetup/install/files/lib/data/comment/Comment.class.php +++ b/wcfsetup/install/files/lib/data/comment/Comment.class.php @@ -92,6 +92,27 @@ class Comment extends DatabaseObject implements IMessage { return $processor->getHtml(); } + /** + * Returns a version of this message optimized for use in emails. + * + * @param string $mimeType Either 'text/plain' or 'text/html' + * @return string + */ + public function getMailText($mimeType = 'text/plain') { + switch ($mimeType) { + case 'text/plain': + $processor = new HtmlOutputProcessor(); + $processor->setOutputType('text/plain'); + $processor->process($this->message, 'com.woltlab.wcf.comment', $this->commentID); + + return $processor->getHtml(); + case 'text/html': + return $this->getSimplifiedFormattedMessage(); + } + + throw new \LogicException('Unreachable'); + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseOwnerUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseOwnerUserNotificationEvent.class.php index dba558437c..2ae96e53d6 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseOwnerUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseOwnerUserNotificationEvent.class.php @@ -103,7 +103,7 @@ class UserProfileCommentResponseOwnerUserNotificationEvent extends AbstractShare $messageID = 'commentID.'@'.Email::getHost().'>'; return [ - 'template' => 'email_notification_userProfileCommentResponseOwner', + 'template' => 'email_notification_commentResponseOwner', 'application' => 'wcf', 'in-reply-to' => [$messageID], 'references' => [$messageID], @@ -111,7 +111,8 @@ class UserProfileCommentResponseOwnerUserNotificationEvent extends AbstractShare 'commentAuthor' => $commentAuthor, 'commentID' => $this->getUserNotificationObject()->commentID, 'owner' => $owner, - 'responseID' => $this->getUserNotificationObject()->responseID + 'responseID' => $this->getUserNotificationObject()->responseID, + 'languageVariablePrefix' => 'wcf.user.notification.commentResponseOwner' ] ]; } diff --git a/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseUserNotificationEvent.class.php index 032c6c33da..e1242eec4d 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseUserNotificationEvent.class.php @@ -89,14 +89,15 @@ class UserProfileCommentResponseUserNotificationEvent extends AbstractSharedUser $messageID = 'commentID.'@'.Email::getHost().'>'; return [ - 'template' => 'email_notification_userProfileCommentResponse', + 'template' => 'email_notification_commentResponse', 'application' => 'wcf', 'in-reply-to' => [$messageID], 'references' => [$messageID], 'variables' => [ 'commentID' => $this->getUserNotificationObject()->commentID, 'owner' => $owner, - 'responseID' => $this->getUserNotificationObject()->responseID + 'responseID' => $this->getUserNotificationObject()->responseID, + 'languageVariablePrefix' => 'wcf.user.notification.commentResponse' ] ]; } diff --git a/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentUserNotificationEvent.class.php index 9daa83f63b..944514246f 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentUserNotificationEvent.class.php @@ -80,11 +80,12 @@ class UserProfileCommentUserNotificationEvent extends AbstractSharedUserNotifica public function getEmailMessage($notificationType = 'instant') { return [ 'message-id' => 'com.woltlab.wcf.user.profileComment.notification/'.$this->getUserNotificationObject()->commentID, - 'template' => 'email_notification_userProfileComment', + 'template' => 'email_notification_comment', 'application' => 'wcf', 'variables' => [ 'commentID' => $this->getUserNotificationObject()->commentID, - 'owner' => new User($this->getUserNotificationObject()->objectID) + 'owner' => new User($this->getUserNotificationObject()->objectID), + 'languageVariablePrefix' => 'wcf.user.notification.comment' ] ]; } -- 2.20.1