From 156214016abd723dc6cd9096d76e300efdb715c7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 30 May 2016 16:04:59 +0200 Subject: [PATCH] Add EmailTemplateEngine --- .../install/files/lib/system/WCF.class.php | 7 +++ .../template/EmailTemplateEngine.class.php | 45 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/template/EmailTemplateEngine.class.php diff --git a/wcfsetup/install/files/lib/system/WCF.class.php b/wcfsetup/install/files/lib/system/WCF.class.php index 40f64c8d17..9918db2387 100644 --- a/wcfsetup/install/files/lib/system/WCF.class.php +++ b/wcfsetup/install/files/lib/system/WCF.class.php @@ -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 index 0000000000..7941e1869a --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/EmailTemplateEngine.class.php @@ -0,0 +1,45 @@ + + * @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"); + } +} -- 2.20.1