1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-06-25 04:24:31 +02:00

Parse email text files with the template engine.

Did not check if this influences styles template cache list/purge/etc.

git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9823 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen
2009-07-22 09:07:24 +00:00
parent 16e393b61d
commit cef8c2d87e
2 changed files with 54 additions and 22 deletions

View File

@ -219,6 +219,7 @@
<li>[Feature] Ability to empty a user's outbox from the user ACP quick tools.</li>
<li>[Feature] Ability to filter ACP / MCP logs</li>
<li>[Feature] Users can report PMs to moderators which are then visible in a new MCP module</li>
<li>[Feature] Parse email text files with the template engine.</li>
</ul>
<a name="v304"></a><h3>1.ii. Changes since 3.0.4</h3>

View File

@ -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('<br />', "\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('<br />', "\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