Merge emailText{Html,Plain}.tpl into email.tpl
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 24 Jul 2015 15:18:21 +0000 (17:18 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 24 Jul 2015 15:18:21 +0000 (17:18 +0200)
com.woltlab.wcf/templates/email.tpl [new file with mode: 0644]
com.woltlab.wcf/templates/emailTextHtml.tpl [deleted file]
com.woltlab.wcf/templates/emailTextPlain.tpl [deleted file]
wcfsetup/install/files/lib/system/email/UserMailbox.class.php
wcfsetup/install/files/lib/system/email/mime/AbstractRecipientAwareTextMimePart.class.php [deleted file]
wcfsetup/install/files/lib/system/email/mime/HtmlTextMimePart.class.php
wcfsetup/install/files/lib/system/email/mime/PlainTextMimePart.class.php
wcfsetup/install/files/lib/system/email/mime/RecipientAwareTextMimePart.class.php [new file with mode: 0644]

diff --git a/com.woltlab.wcf/templates/email.tpl b/com.woltlab.wcf/templates/email.tpl
new file mode 100644 (file)
index 0000000..a9ab267
--- /dev/null
@@ -0,0 +1,39 @@
+{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'}
+<html>
+<body>
+<div style="text-align: center;">
+<a href="{link}{/link}">
+{if $__wcf->getStyleHandler()->getStyle()->getPageLogo()}<img src="{$__wcf->getStyleHandler()->getStyle()->getPageLogo()}" alt="">{/if}
+{event name='headerLogo'}
+</a>
+</div>
+<div class="content">{@$content}</div>
+{hascontent}
+<div class="signature" style="color: grey; font-size: 10px;">
+-- <br>
+{content}
+{@MAIL_SIGNATURE|language}
+{if $mailbox|is_a:'wcf\system\email\UserMailbox'}
+{if MAIL_SIGNATURE|language}<br><br>{/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}
+</div>
+{/hascontent}
+</body>
+</html>
+{/if}
diff --git a/com.woltlab.wcf/templates/emailTextHtml.tpl b/com.woltlab.wcf/templates/emailTextHtml.tpl
deleted file mode 100644 (file)
index 4cec0b4..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-<html>
-<body>
-<div style="text-align: center;">
-<a href="{link}{/link}">
-{if $__wcf->getStyleHandler()->getStyle()->getPageLogo()}<img src="{$__wcf->getStyleHandler()->getStyle()->getPageLogo()}" alt="">{/if}
-{event name='headerLogo'}
-</a>
-</div>
-<div class="content">{$content}</div>
-{hascontent}
-<div class="signature" style="color: grey; font-size: 10px;">
--- <br>
-{content}
-{@MAIL_SIGNATURE|language}
-{if $mailbox|is_a:'wcf\system\email\UserMailbox'}
-{if MAIL_SIGNATURE|language}<br><br>{/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}
-</div>
-{/hascontent}
-</body>
-</html>
diff --git a/com.woltlab.wcf/templates/emailTextPlain.tpl b/com.woltlab.wcf/templates/emailTextPlain.tpl
deleted file mode 100644 (file)
index ed60bea..0000000
+++ /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}
index 6e9a01c9b584d3881ef955db86982e36272a98af..880273c0f3c9cff7f5b03c897e2c2b17a3453b11 100644 (file)
@@ -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/AbstractRecipientAwareTextMimePart.class.php b/wcfsetup/install/files/lib/system/email/mime/AbstractRecipientAwareTextMimePart.class.php
deleted file mode 100644 (file)
index f2df88e..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-<?php
-namespace wcf\system\email\mime;
-use wcf\system\email\Mailbox;
-use wcf\system\email\UserMailbox;
-use wcf\system\WCF;
-
-/**
- * Abstract 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.
- * 
- * @author     Tim Duesterhus
- * @copyright  2001-2015 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    com.woltlab.wcf
- * @subpackage system.email.mime
- * @category   Community Framework
- */
-abstract class AbstractRecipientAwareTextMimePart extends TextMimePart implements IRecipientAwareMimePart {
-       /**
-        * template to use for this email
-        * @var string
-        */
-       protected $template = '';
-       
-       /**
-        * application of this template
-        * @var string
-        */
-       protected $application = 'wcf';
-       
-       /**
-        * the recipient of the email containing this mime part
-        * @var \wcf\system\email\Mailbox
-        */
-       protected $mailbox = null;
-       
-       /**
-        * @see \wcf\system\email\mime\IRecipientAwareMimePart::setRecipient()
-        */
-       public function setRecipient(Mailbox $mailbox = null) {
-               $this->mailbox = $mailbox;
-       }
-       
-       /**
-        * @see \wcf\system\email\mime\AbstractMimePart::getContent()
-        */
-       public function getContent() {
-               $language = WCF::getLanguage();
-               
-               try {
-                       if ($this->mailbox instanceof UserMailbox) {
-                               WCF::setLanguage($this->mailbox->getUser()->getLanguage()->languageID);
-                       }
-                       
-                       return WCF::getTPL()->fetch($this->template, $this->application, [
-                               'content' => $this->content,
-                               'mailbox' => $this->mailbox
-                       ], true);
-               }
-               finally {
-                       WCF::setLanguage($language->languageID);
-               }
-       }
-}
index 6b22c032c760befd8e1e8768f7af3552fa94b2ca..92dbe754e5d7046e10a6c0f28a63b1c15ac2c751 100644 (file)
@@ -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');
        }
 }
index 226947ed651048297cd80ec2888818c2c73107dc..4dc8d537a6ab8823447468df65cf76e81e0cabf8 100644 (file)
@@ -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/RecipientAwareTextMimePart.class.php b/wcfsetup/install/files/lib/system/email/mime/RecipientAwareTextMimePart.class.php
new file mode 100644 (file)
index 0000000..0c86cde
--- /dev/null
@@ -0,0 +1,81 @@
+<?php
+namespace wcf\system\email\mime;
+use wcf\system\email\Mailbox;
+use wcf\system\email\UserMailbox;
+use wcf\system\WCF;
+
+/**
+ * Default implementation of a recipient aware TextMimePart.
+ * 
+ * This implementation generates the final content by passing the content
+ * 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
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.email.mime
+ * @category   Community Framework
+ */
+class RecipientAwareTextMimePart extends TextMimePart implements IRecipientAwareMimePart {
+       /**
+        * template to use for this email
+        * @var string
+        */
+       protected $template = '';
+       
+       /**
+        * application of this template
+        * @var string
+        */
+       protected $application = 'wcf';
+       
+       /**
+        * the recipient of the email containing this mime part
+        * @var \wcf\system\email\Mailbox
+        */
+       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()
+        */
+       public function setRecipient(Mailbox $mailbox = null) {
+               $this->mailbox = $mailbox;
+       }
+       
+       /**
+        * @see \wcf\system\email\mime\AbstractMimePart::getContent()
+        */
+       public function getContent() {
+               $language = WCF::getLanguage();
+               
+               try {
+                       WCF::setLanguage($this->mailbox->getLanguage()->languageID);
+                       
+                       return WCF::getTPL()->fetch($this->template, $this->application, [
+                               'content' => $this->content,
+                               'mimeType' => $this->mimeType,
+                               'mailbox' => $this->mailbox
+                       ], true);
+               }
+               finally {
+                       WCF::setLanguage($language->languageID);
+               }
+       }
+}