Added generic templates for comment notification emails
authorMarcel Werk <burntime@woltlab.com>
Sun, 15 Oct 2017 16:06:37 +0000 (18:06 +0200)
committerMarcel Werk <burntime@woltlab.com>
Sun, 15 Oct 2017 16:32:38 +0000 (18:32 +0200)
Closes #2444

com.woltlab.wcf/templates/email_notification_comment.tpl [new file with mode: 0644]
com.woltlab.wcf/templates/email_notification_commentResponse.tpl [new file with mode: 0644]
com.woltlab.wcf/templates/email_notification_commentResponseOwner.tpl [new file with mode: 0644]
com.woltlab.wcf/templates/email_notification_userProfileComment.tpl [deleted file]
com.woltlab.wcf/templates/email_notification_userProfileCommentResponse.tpl [deleted file]
com.woltlab.wcf/templates/email_notification_userProfileCommentResponseOwner.tpl [deleted file]
wcfsetup/install/files/lib/data/comment/Comment.class.php
wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseOwnerUserNotificationEvent.class.php
wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentResponseUserNotificationEvent.class.php
wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentUserNotificationEvent.class.php

diff --git a/com.woltlab.wcf/templates/email_notification_comment.tpl b/com.woltlab.wcf/templates/email_notification_comment.tpl
new file mode 100644 (file)
index 0000000..26400f1
--- /dev/null
@@ -0,0 +1,39 @@
+{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}{@$languageVariablePrefix}.mail.plaintext{/lang}{if $count == 1 && !$guestTimesTriggered}
+
+{@$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}{@$languageVariablePrefix}.mail.html{/lang}
+       {assign var='user' value=$event->getAuthor()}
+       {assign var='comment' value=$event->getUserNotificationObject()}
+       
+       {if $notificationType == 'instant'}{assign var='avatarSize' value=48}
+       {else}{assign var='avatarSize' value=32}{/if}
+       {capture assign='commentContent'}
+       <table cellpadding="0" cellspacing="0" border="0">
+               <tr>
+                       <td><a href="{link controller='User' object=$user isEmail=true}{/link}" title="{$comment->username}">{@$user->getAvatar()->getImageTag($avatarSize)}</a></td>
+                       <td class="boxContent">
+                               <div class="containerHeadline">
+                                       <h3>
+                                               {if $comment->userID}
+                                                       <a href="{link controller='User' object=$user isEmail=true}{/link}">{$comment->username}</a>
+                                               {else}
+                                                       {$comment->username}
+                                               {/if}
+                                               &#xb7;
+                                               <small>{$comment->time|plainTime}</small>
+                                       </h3>
+                               </div>
+                               <div>
+                                       {@$comment->getMailText($mimeType)}
+                               </div>
+                       </td>
+               </tr>
+       </table>
+       {/capture}
+       {include file='email_paddingHelper' block=true class='box'|concat:$avatarSize content=$commentContent sandbox=true}
+{/if}
diff --git a/com.woltlab.wcf/templates/email_notification_commentResponse.tpl b/com.woltlab.wcf/templates/email_notification_commentResponse.tpl
new file mode 100644 (file)
index 0000000..282daf0
--- /dev/null
@@ -0,0 +1,39 @@
+{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}{@$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}{@$languageVariablePrefix}.mail.html{/lang}
+       {assign var='user' value=$event->getAuthor()}
+       {assign var='comment' value=$event->getUserNotificationObject()}
+       
+       {if $notificationType == 'instant'}{assign var='avatarSize' value=48}
+       {else}{assign var='avatarSize' value=32}{/if}
+       {capture assign='commentContent'}
+       <table cellpadding="0" cellspacing="0" border="0">
+               <tr>
+                       <td><a href="{link controller='User' object=$user isEmail=true}{/link}" title="{$comment->username}">{@$user->getAvatar()->getImageTag($avatarSize)}</a></td>
+                       <td class="boxContent">
+                               <div class="containerHeadline">
+                                       <h3>
+                                               {if $comment->userID}
+                                                       <a href="{link controller='User' object=$user isEmail=true}{/link}">{$comment->username}</a>
+                                               {else}
+                                                       {$comment->username}
+                                               {/if}
+                                               &#xb7;
+                                               <small>{$comment->time|plainTime}</small>
+                                       </h3>
+                               </div>
+                               <div>
+                                       {$comment->message}
+                               </div>
+                       </td>
+               </tr>
+       </table>
+       {/capture}
+       {include file='email_paddingHelper' block=true class='box'|concat:$avatarSize content=$commentContent sandbox=true}
+{/if}
diff --git a/com.woltlab.wcf/templates/email_notification_commentResponseOwner.tpl b/com.woltlab.wcf/templates/email_notification_commentResponseOwner.tpl
new file mode 100644 (file)
index 0000000..282daf0
--- /dev/null
@@ -0,0 +1,39 @@
+{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}{@$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}{@$languageVariablePrefix}.mail.html{/lang}
+       {assign var='user' value=$event->getAuthor()}
+       {assign var='comment' value=$event->getUserNotificationObject()}
+       
+       {if $notificationType == 'instant'}{assign var='avatarSize' value=48}
+       {else}{assign var='avatarSize' value=32}{/if}
+       {capture assign='commentContent'}
+       <table cellpadding="0" cellspacing="0" border="0">
+               <tr>
+                       <td><a href="{link controller='User' object=$user isEmail=true}{/link}" title="{$comment->username}">{@$user->getAvatar()->getImageTag($avatarSize)}</a></td>
+                       <td class="boxContent">
+                               <div class="containerHeadline">
+                                       <h3>
+                                               {if $comment->userID}
+                                                       <a href="{link controller='User' object=$user isEmail=true}{/link}">{$comment->username}</a>
+                                               {else}
+                                                       {$comment->username}
+                                               {/if}
+                                               &#xb7;
+                                               <small>{$comment->time|plainTime}</small>
+                                       </h3>
+                               </div>
+                               <div>
+                                       {$comment->message}
+                               </div>
+                       </td>
+               </tr>
+       </table>
+       {/capture}
+       {include file='email_paddingHelper' block=true class='box'|concat:$avatarSize content=$commentContent sandbox=true}
+{/if}
diff --git a/com.woltlab.wcf/templates/email_notification_userProfileComment.tpl b/com.woltlab.wcf/templates/email_notification_userProfileComment.tpl
deleted file mode 100644 (file)
index 0786687..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-{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}
-
-{$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}
-       {assign var='user' value=$event->getAuthor()}
-       {assign var='comment' value=$event->getUserNotificationObject()}
-       
-       {if $notificationType == 'instant'}{assign var='avatarSize' value=48}
-       {else}{assign var='avatarSize' value=32}{/if}
-       {capture assign='commentContent'}
-       <table cellpadding="0" cellspacing="0" border="0">
-               <tr>
-                       <td><a href="{link controller='User' object=$user isEmail=true}{/link}" title="{$comment->username}">{@$user->getAvatar()->getImageTag($avatarSize)}</a></td>
-                       <td class="boxContent">
-                               <div class="containerHeadline">
-                                       <h3>
-                                               {if $comment->userID}
-                                                       <a href="{link controller='User' object=$user isEmail=true}{/link}">{$comment->username}</a>
-                                               {else}
-                                                       {$comment->username}
-                                               {/if}
-                                               &#xb7;
-                                               <small>{$comment->time|plainTime}</small>
-                                       </h3>
-                               </div>
-                               <div>
-                                       {$comment->message}
-                               </div>
-                       </td>
-               </tr>
-       </table>
-       {/capture}
-       {include file='email_paddingHelper' block=true class='box'|concat:$avatarSize content=$commentContent sandbox=true}
-{/if}
diff --git a/com.woltlab.wcf/templates/email_notification_userProfileCommentResponse.tpl b/com.woltlab.wcf/templates/email_notification_userProfileCommentResponse.tpl
deleted file mode 100644 (file)
index 4cd7492..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-{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}
-
-{$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}
-       {assign var='user' value=$event->getAuthor()}
-       {assign var='comment' value=$event->getUserNotificationObject()}
-       
-       {if $notificationType == 'instant'}{assign var='avatarSize' value=48}
-       {else}{assign var='avatarSize' value=32}{/if}
-       {capture assign='commentContent'}
-       <table cellpadding="0" cellspacing="0" border="0">
-               <tr>
-                       <td><a href="{link controller='User' object=$user isEmail=true}{/link}" title="{$comment->username}">{@$user->getAvatar()->getImageTag($avatarSize)}</a></td>
-                       <td class="boxContent">
-                               <div class="containerHeadline">
-                                       <h3>
-                                               {if $comment->userID}
-                                                       <a href="{link controller='User' object=$user isEmail=true}{/link}">{$comment->username}</a>
-                                               {else}
-                                                       {$comment->username}
-                                               {/if}
-                                               &#xb7;
-                                               <small>{$comment->time|plainTime}</small>
-                                       </h3>
-                               </div>
-                               <div>
-                                       {$comment->message}
-                               </div>
-                       </td>
-               </tr>
-       </table>
-       {/capture}
-       {include file='email_paddingHelper' block=true class='box'|concat:$avatarSize content=$commentContent sandbox=true}
-{/if}
diff --git a/com.woltlab.wcf/templates/email_notification_userProfileCommentResponseOwner.tpl b/com.woltlab.wcf/templates/email_notification_userProfileCommentResponseOwner.tpl
deleted file mode 100644 (file)
index 5874fef..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-{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}
-
-{$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.commentResponseOwner.mail.html{/lang}
-       {assign var='user' value=$event->getAuthor()}
-       {assign var='comment' value=$event->getUserNotificationObject()}
-       
-       {if $notificationType == 'instant'}{assign var='avatarSize' value=48}
-       {else}{assign var='avatarSize' value=32}{/if}
-       {capture assign='commentContent'}
-       <table cellpadding="0" cellspacing="0" border="0">
-               <tr>
-                       <td><a href="{link controller='User' object=$user isEmail=true}{/link}" title="{$comment->username}">{@$user->getAvatar()->getImageTag($avatarSize)}</a></td>
-                       <td class="boxContent">
-                               <div class="containerHeadline">
-                                       <h3>
-                                               {if $comment->userID}
-                                                       <a href="{link controller='User' object=$user isEmail=true}{/link}">{$comment->username}</a>
-                                               {else}
-                                                       {$comment->username}
-                                               {/if}
-                                               &#xb7;
-                                               <small>{$comment->time|plainTime}</small>
-                                       </h3>
-                               </div>
-                               <div>
-                                       {$comment->message}
-                               </div>
-                       </td>
-               </tr>
-       </table>
-       {/capture}
-       {include file='email_paddingHelper' block=true class='box'|concat:$avatarSize content=$commentContent sandbox=true}
-{/if}
index 1ac5d10db0d8f3f8d5583906354b88e1843188f7..142d5ec1fe61e9c422517285981953c2f6cc4edd 100644 (file)
@@ -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
         */
index dba558437cc81e18b0827b7d36ce51e771783649..2ae96e53d611fc26d2ea8436cba95e8d1e0c3beb 100644 (file)
@@ -103,7 +103,7 @@ class UserProfileCommentResponseOwnerUserNotificationEvent extends AbstractShare
                $messageID = '<com.woltlab.wcf.user.profileComment.notification/'.$comment->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'
                        ]
                ];
        }
index 032c6c33daf19329de56e5e0d8245059060769c1..e1242eec4d2ca59525946fe76a997ac4232a3508 100644 (file)
@@ -89,14 +89,15 @@ class UserProfileCommentResponseUserNotificationEvent extends AbstractSharedUser
                $messageID = '<com.woltlab.wcf.user.profileComment.notification/'.$comment->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'
                        ]
                ];
        }
index 9daa83f63b680a032ebb8ba9572d0d5de59d9e21..944514246f44938773be546a8b7db1446a136c9c 100644 (file)
@@ -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'
                        ]
                ];
        }