From 31a8e6cae82b6e392811722c73fba676bd0b37c3 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Fri, 30 Jun 2023 13:58:24 +0200 Subject: [PATCH] Move replacement of placerholders in mail texts into `UserMailBox` Also added support for an `{$email}` placeholder. --- com.woltlab.wcf/templates/email_mailWorker.tpl | 2 +- .../files/lib/system/email/UserMailbox.class.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/com.woltlab.wcf/templates/email_mailWorker.tpl b/com.woltlab.wcf/templates/email_mailWorker.tpl index 639f14628b..2e42bbfd8f 100644 --- a/com.woltlab.wcf/templates/email_mailWorker.tpl +++ b/com.woltlab.wcf/templates/email_mailWorker.tpl @@ -1,4 +1,4 @@ -{assign var='text' value="\x7B\$username\x7D"|str_replace:$mailbox->getUser()->username:$text}{if $mimeType === 'text/plain'} +{assign var='text' value=$mailbox->getPersonalizedText($text)}{if $mimeType === 'text/plain'} {include file='email_plaintext' content=$text} {else} {if $enableHTML} diff --git a/wcfsetup/install/files/lib/system/email/UserMailbox.class.php b/wcfsetup/install/files/lib/system/email/UserMailbox.class.php index 2c6cf8b432..c69ed4ad14 100644 --- a/wcfsetup/install/files/lib/system/email/UserMailbox.class.php +++ b/wcfsetup/install/files/lib/system/email/UserMailbox.class.php @@ -47,4 +47,15 @@ class UserMailbox extends Mailbox implements IUserMailbox return $user; } + + /** + * Takes the passed text and replaces the placeholders for username and email address with the user's values. + */ + public function getPersonalizedText(string $text): string + { + $text = \str_replace('{$username}', $this->getUser()->username, $text); + $text = \str_replace('{$email}', $this->getUser()->email, $text); + + return $text; + } } -- 2.20.1