From 86ebc5207d16166daa7914b0f1f6dddba52ec0ec Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 24 Jul 2015 17:18:21 +0200 Subject: [PATCH] Merge emailText{Html,Plain}.tpl into email.tpl --- .../{emailTextHtml.tpl => email.tpl} | 19 +++++++++++- com.woltlab.wcf/templates/emailTextPlain.tpl | 13 --------- .../lib/system/email/UserMailbox.class.php | 2 +- .../email/mime/HtmlTextMimePart.class.php | 13 ++------- .../email/mime/PlainTextMimePart.class.php | 13 ++------- ...p => RecipientAwareTextMimePart.class.php} | 29 ++++++++++++++----- 6 files changed, 46 insertions(+), 43 deletions(-) rename com.woltlab.wcf/templates/{emailTextHtml.tpl => email.tpl} (56%) delete mode 100644 com.woltlab.wcf/templates/emailTextPlain.tpl rename wcfsetup/install/files/lib/system/email/mime/{AbstractRecipientAwareTextMimePart.class.php => RecipientAwareTextMimePart.class.php} (57%) diff --git a/com.woltlab.wcf/templates/emailTextHtml.tpl b/com.woltlab.wcf/templates/email.tpl similarity index 56% rename from com.woltlab.wcf/templates/emailTextHtml.tpl rename to com.woltlab.wcf/templates/email.tpl index 4cec0b422c..a9ab2676e0 100644 --- a/com.woltlab.wcf/templates/emailTextHtml.tpl +++ b/com.woltlab.wcf/templates/email.tpl @@ -1,3 +1,19 @@ +{if $mimeType === 'text/plain'} +{@$content} +{hascontent} + +-- {* The Space is important, do not remove *} +{content} +{@MAIL_SIGNATURE|language} +{if $mailbox|is_a:'wcf\system\email\UserMailbox'}{if MAIL_SIGNATURE|language}{* add newlines *} + + +{/if}This email was sent to you, because you registered on +the {$mailbox->getUser()->registrationDate|plainTime} at {@PAGE_TITLE|language}.{/if} {* TODO: language item *} +{/content} +{/hascontent} + +{elseif $mimeType === 'text/html'}
@@ -6,7 +22,7 @@ {event name='headerLogo'}
-
{$content}
+
{@$content}
{hascontent}
--
@@ -20,3 +36,4 @@ This email was sent to you, because you registered on the {$mailbox->getUser()-> {/hascontent} +{/if} diff --git a/com.woltlab.wcf/templates/emailTextPlain.tpl b/com.woltlab.wcf/templates/emailTextPlain.tpl deleted file mode 100644 index ed60beab94..0000000000 --- a/com.woltlab.wcf/templates/emailTextPlain.tpl +++ /dev/null @@ -1,13 +0,0 @@ -{$content} -{hascontent} - --- {* The Space is important, do not remove *} -{content} -{@MAIL_SIGNATURE|language} -{if $mailbox|is_a:'wcf\system\email\UserMailbox'}{if MAIL_SIGNATURE|language}{* add newlines *} - - -{/if}This email was sent to you, because you registered on -the {$mailbox->getUser()->registrationDate|plainTime} at {@PAGE_TITLE|language}.{/if} {* TODO: language item *} -{/content} -{/hascontent} diff --git a/wcfsetup/install/files/lib/system/email/UserMailbox.class.php b/wcfsetup/install/files/lib/system/email/UserMailbox.class.php index 6e9a01c9b5..880273c0f3 100644 --- a/wcfsetup/install/files/lib/system/email/UserMailbox.class.php +++ b/wcfsetup/install/files/lib/system/email/UserMailbox.class.php @@ -25,7 +25,7 @@ class UserMailbox extends Mailbox { * @param \wcf\data\user\User $user User object belonging to this Mailbox */ public function __construct(User $user) { - parent::__construct($user->email, $user->username); + parent::__construct($user->email, $user->username, $user->getLanguage()); $this->user = $user; } diff --git a/wcfsetup/install/files/lib/system/email/mime/HtmlTextMimePart.class.php b/wcfsetup/install/files/lib/system/email/mime/HtmlTextMimePart.class.php index 6b22c032c7..92dbe754e5 100644 --- a/wcfsetup/install/files/lib/system/email/mime/HtmlTextMimePart.class.php +++ b/wcfsetup/install/files/lib/system/email/mime/HtmlTextMimePart.class.php @@ -4,8 +4,7 @@ use wcf\system\email\UserMailbox; use wcf\system\WCF; /** - * HtmlTextMimePart is a text/html implementation of an - * AbstractRecipientAwareTextMimePart. + * HtmlTextMimePart is a text/html implementation of a RecipientAwareTextMimePart. * * @author Tim Duesterhus * @copyright 2001-2015 WoltLab GmbH @@ -14,19 +13,13 @@ use wcf\system\WCF; * @subpackage system.email.mime * @category Community Framework */ -class HtmlTextMimePart extends AbstractRecipientAwareTextMimePart { - /** - * template to use for this email - * @var string - */ - protected $template = 'emailTextHtml'; - +class HtmlTextMimePart extends RecipientAwareTextMimePart { /** * Creates a new HtmlTextMimePart. * * @param string $content Content of this text part. */ public function __construct($content) { - parent::__construct($content, 'text/html'); + parent::__construct($content, 'text/html', 'email'); } } diff --git a/wcfsetup/install/files/lib/system/email/mime/PlainTextMimePart.class.php b/wcfsetup/install/files/lib/system/email/mime/PlainTextMimePart.class.php index 226947ed65..4dc8d537a6 100644 --- a/wcfsetup/install/files/lib/system/email/mime/PlainTextMimePart.class.php +++ b/wcfsetup/install/files/lib/system/email/mime/PlainTextMimePart.class.php @@ -4,8 +4,7 @@ use wcf\system\email\UserMailbox; use wcf\system\WCF; /** - * PlainTextMimePart is a text/plain implementation of an - * AbstractRecipientAwareTextMimePart. + * PlainTextMimePart is a text/plain implementation of a RecipientAwareTextMimePart. * * @author Tim Duesterhus * @copyright 2001-2015 WoltLab GmbH @@ -14,19 +13,13 @@ use wcf\system\WCF; * @subpackage system.email.mime * @category Community Framework */ -class PlainTextMimePart extends AbstractRecipientAwareTextMimePart { - /** - * template to use for this email - * @var string - */ - protected $template = 'emailTextPlain'; - +class PlainTextMimePart extends RecipientAwareTextMimePart { /** * Creates a new PlainTextMimePart. * * @param string $content Content of this text part. */ public function __construct($content) { - parent::__construct($content, 'text/plain'); + parent::__construct($content, 'text/plain', 'email'); } } diff --git a/wcfsetup/install/files/lib/system/email/mime/AbstractRecipientAwareTextMimePart.class.php b/wcfsetup/install/files/lib/system/email/mime/RecipientAwareTextMimePart.class.php similarity index 57% rename from wcfsetup/install/files/lib/system/email/mime/AbstractRecipientAwareTextMimePart.class.php rename to wcfsetup/install/files/lib/system/email/mime/RecipientAwareTextMimePart.class.php index f2df88e504..0c86cde499 100644 --- a/wcfsetup/install/files/lib/system/email/mime/AbstractRecipientAwareTextMimePart.class.php +++ b/wcfsetup/install/files/lib/system/email/mime/RecipientAwareTextMimePart.class.php @@ -5,12 +5,11 @@ use wcf\system\email\UserMailbox; use wcf\system\WCF; /** - * Abstract implementation of a recipient aware TextMimePart. + * Default implementation of a recipient aware TextMimePart. * * This implementation generates the final content by passing the content - * to a specified template. If the recipient is a UserMailbox the language - * will be changed to the user's interface language, before evaluating the - * template. + * to a specified template. The language will be changed to the Mailbox' language, + * before evaluating the template. * * @author Tim Duesterhus * @copyright 2001-2015 WoltLab GmbH @@ -19,7 +18,7 @@ use wcf\system\WCF; * @subpackage system.email.mime * @category Community Framework */ -abstract class AbstractRecipientAwareTextMimePart extends TextMimePart implements IRecipientAwareMimePart { +class RecipientAwareTextMimePart extends TextMimePart implements IRecipientAwareMimePart { /** * template to use for this email * @var string @@ -38,6 +37,21 @@ abstract class AbstractRecipientAwareTextMimePart extends TextMimePart implement */ protected $mailbox = null; + /** + * Creates a new AbstractRecipientAwareTextMimePart. + * + * @param string $content Content of this text part (this is passed to the template). + * @param string $mimeType Mime type to provide in the email. You *must* not provide a charset. UTF-8 will be used automatically. + * @param string $template Template to evaluate + * @param string $application Application of the template to evaluate (default: wcf) + */ + public function __construct($content, $mimeType, $template, $application = 'wcf') { + parent::__construct($content, $mimeType); + + $this->template = $template; + $this->application = $application; + } + /** * @see \wcf\system\email\mime\IRecipientAwareMimePart::setRecipient() */ @@ -52,12 +66,11 @@ abstract class AbstractRecipientAwareTextMimePart extends TextMimePart implement $language = WCF::getLanguage(); try { - if ($this->mailbox instanceof UserMailbox) { - WCF::setLanguage($this->mailbox->getUser()->getLanguage()->languageID); - } + WCF::setLanguage($this->mailbox->getLanguage()->languageID); return WCF::getTPL()->fetch($this->template, $this->application, [ 'content' => $this->content, + 'mimeType' => $this->mimeType, 'mailbox' => $this->mailbox ], true); } -- 2.20.1