From: Tim Düsterhus Date: Mon, 30 May 2016 14:04:59 +0000 (+0200) Subject: Add EmailTemplateEngine X-Git-Tag: 3.0.0_Beta_1~1568^2~3 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=156214016abd723dc6cd9096d76e300efdb715c7;p=GitHub%2FWoltLab%2FWCF.git Add EmailTemplateEngine --- 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"); + } +}