Add EmailTemplateEngine
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 30 May 2016 14:04:59 +0000 (16:04 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 30 May 2016 16:41:09 +0000 (18:41 +0200)
wcfsetup/install/files/lib/system/WCF.class.php
wcfsetup/install/files/lib/system/template/EmailTemplateEngine.class.php [new file with mode: 0644]

index 40f64c8d171fe21152a8f3228262beb45b4bd606..9918db238753001b0ef0c9563aad3e2fc7abbfb8 100644 (file)
@@ -31,6 +31,7 @@ use wcf\system\request\RouteHandler;
 use wcf\system\session\SessionFactory;
 use wcf\system\session\SessionHandler;
 use wcf\system\style\StyleHandler;
+use wcf\system\template\EmailTemplateEngine;
 use wcf\system\template\TemplateEngine;
 use wcf\system\user\storage\UserStorageHandler;
 use wcf\util\FileUtil;
@@ -550,10 +551,12 @@ class WCF {
                                // add template path and abbreviation
                                $this->getTPL()->addApplication($abbreviation, $packageDir . 'templates/');
                        }
+                       EmailTemplateEngine::getInstance()->addApplication($abbreviation, $packageDir . 'templates/');
                        
                        // init application and assign it as template variable
                        self::$applicationObjects[$application->packageID] = call_user_func([$className, 'getInstance']);
                        $this->getTPL()->assign('__'.$abbreviation, self::$applicationObjects[$application->packageID]);
+                       EmailTemplateEngine::getInstance()->assign('__'.$abbreviation, self::$applicationObjects[$application->packageID]);
                }
                else {
                        unset(self::$autoloadDirectories[$abbreviation]);
@@ -626,6 +629,10 @@ class WCF {
                        '__wcf' => $this,
                        '__wcfVersion' => LAST_UPDATE_TIME // @deprecated since 2.1, use LAST_UPDATE_TIME directly
                ]);
+               EmailTemplateEngine::getInstance()->registerPrefilter(['event', 'hascontent', 'lang']);
+               EmailTemplateEngine::getInstance()->assign([
+                       '__wcf' => $this
+               ]);
        }
        
        /**
diff --git a/wcfsetup/install/files/lib/system/template/EmailTemplateEngine.class.php b/wcfsetup/install/files/lib/system/template/EmailTemplateEngine.class.php
new file mode 100644 (file)
index 0000000..7941e18
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+namespace wcf\system\template;
+use wcf\system\WCF;
+
+/**
+ * Loads and displays templates in emails.
+ * 
+ * @author     Tim Duesterhus
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.template
+ * @category   Community Framework
+ */
+class EmailTemplateEngine extends TemplateEngine {
+       /**
+        * @inheritDoc
+        */
+       protected $environment = 'email';
+       
+       /**
+        * @inheritDoc
+        */
+       protected function init() {
+               parent::init();
+               
+               $sql = "SELECT  templateGroupID
+                       FROM    wcf".WCF_N."_template_group
+                       WHERE   templateGroupFolderName = ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(['_wcf_email/']);
+               
+               parent::setTemplateGroupID($statement->fetchSingleColumn());
+       }
+       
+       /**
+        * This method always throws, because changing the template
+        * group is not supported.
+        * 
+        * @throws \BadMethodCallException
+        */
+       public function setTemplateGroupID($templateGroupID) {
+               throw new \BadMethodCallException("You may not change the template group of the email template engine");
+       }
+}