diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html
index 356987cd33..6011933082 100644
--- a/phpBB/docs/CHANGELOG.html
+++ b/phpBB/docs/CHANGELOG.html
@@ -219,6 +219,7 @@
[Feature] Ability to empty a user's outbox from the user ACP quick tools.
[Feature] Ability to filter ACP / MCP logs
[Feature] Users can report PMs to moderators which are then visible in a new MCP module
+ [Feature] Parse email text files with the template engine.
1.ii. Changes since 3.0.4
diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php
index 4916ee41d7..2255b3dcb5 100644
--- a/phpBB/includes/functions_messenger.php
+++ b/phpBB/includes/functions_messenger.php
@@ -27,6 +27,8 @@ class messenger
var $mail_priority = MAIL_NORMAL_PRIORITY;
var $use_queue = true;
+
+ var $tpl_obj = NULL;
var $tpl_msg = array();
var $eol = "\n";
@@ -177,7 +179,7 @@ class messenger
if (!trim($template_file))
{
- trigger_error('No template file set', E_USER_ERROR);
+ trigger_error('No template file for emailing set.', E_USER_ERROR);
}
if (!trim($template_lang))
@@ -185,25 +187,25 @@ class messenger
$template_lang = basename($config['default_lang']);
}
- if (empty($this->tpl_msg[$template_lang . $template_file]))
+ // tpl_msg now holds a template object we can use to parse the template file
+ if (!isset($this->tpl_msg[$template_lang . $template_file]))
{
- $tpl_file = (!empty($user->lang_path)) ? $user->lang_path : $phpbb_root_path . 'language/';
- $tpl_file .= $template_lang . "/email/$template_file.txt";
+ $this->tpl_msg[$template_lang . $template_file] = new template();
+ $tpl = &$this->tpl_msg[$template_lang . $template_file];
- if (!file_exists($tpl_file))
- {
- trigger_error("Could not find email template file [ $tpl_file ]", E_USER_ERROR);
- }
+ $template_path = (!empty($user->lang_path)) ? $user->lang_path : $phpbb_root_path . 'language/';
+ $template_path .= $template_lang . '/email';
- if (($data = @file_get_contents($tpl_file)) === false)
- {
- trigger_error("Failed opening template file [ $tpl_file ]", E_USER_ERROR);
- }
+ $tpl->set_custom_template($template_path, $template_lang . '_email');
- $this->tpl_msg[$template_lang . $template_file] = $data;
+ $tpl->set_filenames(array(
+ 'body' => $template_file . '.txt',
+ ));
}
- $this->msg = $this->tpl_msg[$template_lang . $template_file];
+ $this->tpl_obj = &$this->tpl_msg[$template_lang . $template_file];
+ $this->vars = &$this->tpl_obj->_rootref;
+ $this->tpl_msg = '';
return true;
}
@@ -213,7 +215,22 @@ class messenger
*/
function assign_vars($vars)
{
- $this->vars = (empty($this->vars)) ? $vars : $this->vars + $vars;
+ if (!is_object($this->tpl_obj))
+ {
+ return;
+ }
+
+ $this->tpl_obj->assign_vars($vars);
+ }
+
+ function assign_block_vars($blockname, $vars)
+ {
+ if (!is_object($this->tpl_obj))
+ {
+ return;
+ }
+
+ $this->tpl_obj->assign_block_vars($blockname, $vars);
}
/**
@@ -224,15 +241,29 @@ class messenger
global $config, $user;
// We add some standard variables we always use, no need to specify them always
- $this->vars['U_BOARD'] = (!isset($this->vars['U_BOARD'])) ? generate_board_url() : $this->vars['U_BOARD'];
- $this->vars['EMAIL_SIG'] = (!isset($this->vars['EMAIL_SIG'])) ? str_replace('
', "\n", "-- \n" . htmlspecialchars_decode($config['board_email_sig'])) : $this->vars['EMAIL_SIG'];
- $this->vars['SITENAME'] = (!isset($this->vars['SITENAME'])) ? htmlspecialchars_decode($config['sitename']) : $this->vars['SITENAME'];
+ if (!isset($this->vars['U_BOARD']))
+ {
+ $this->assign_vars(array(
+ 'U_BOARD' => generate_board_url(),
+ ));
+ }
- // Escape all quotes, else the eval will fail.
- $this->msg = str_replace ("'", "\'", $this->msg);
- $this->msg = preg_replace('#\{([a-z0-9\-_]*?)\}#is', "' . ((isset(\$this->vars['\\1'])) ? \$this->vars['\\1'] : '') . '", $this->msg);
+ if (!isset($this->vars['EMAIL_SIG']))
+ {
+ $this->assign_vars(array(
+ 'EMAIL_SIG' => str_replace('
', "\n", "-- \n" . htmlspecialchars_decode($config['board_email_sig'])),
+ ));
+ }
- eval("\$this->msg = '$this->msg';");
+ if (!isset($this->vars['SITENAME']))
+ {
+ $this->assign_vars(array(
+ 'SITENAME' => htmlspecialchars_decode($config['sitename']),
+ ));
+ }
+
+ // Parse message through template
+ $this->msg = trim($this->tpl_obj->assign_display('body'));
// We now try and pull a subject from the email body ... if it exists,
// do this here because the subject may contain a variable