diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2009-07-22 09:07:24 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2009-07-22 09:07:24 +0000 |
commit | cef8c2d87e2c1e55a7fd6d57e3f998e531fd0bf2 (patch) | |
tree | d99d2740f0d66701897af1b413734be85a46f852 /phpBB/includes/functions_messenger.php | |
parent | 16e393b61d53843dfec3b88257925a0848c027ed (diff) | |
download | forums-cef8c2d87e2c1e55a7fd6d57e3f998e531fd0bf2.tar forums-cef8c2d87e2c1e55a7fd6d57e3f998e531fd0bf2.tar.gz forums-cef8c2d87e2c1e55a7fd6d57e3f998e531fd0bf2.tar.bz2 forums-cef8c2d87e2c1e55a7fd6d57e3f998e531fd0bf2.tar.xz forums-cef8c2d87e2c1e55a7fd6d57e3f998e531fd0bf2.zip |
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
Diffstat (limited to 'phpBB/includes/functions_messenger.php')
-rw-r--r-- | phpBB/includes/functions_messenger.php | 75 |
1 files changed, 53 insertions, 22 deletions
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('<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'])), + )); + } + + if (!isset($this->vars['SITENAME'])) + { + $this->assign_vars(array( + 'SITENAME' => htmlspecialchars_decode($config['sitename']), + )); + } - eval("\$this->msg = '$this->msg';"); + // 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 |