mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-14 19:45:21 +02:00
[feature/twig] Clean up the messenger a little bit
This should fix at least one bug, noticed we were using: $this->vars = &$this->tpl_obj->_rootref; Which hasn't been valid for a long+ time PHPBB3-11598
This commit is contained in:
parent
8f303b376b
commit
16ebf14653
@ -27,8 +27,9 @@ class messenger
|
||||
var $mail_priority = MAIL_NORMAL_PRIORITY;
|
||||
var $use_queue = true;
|
||||
|
||||
var $tpl_obj = NULL;
|
||||
var $tpl_msg = array();
|
||||
/** @var phpbb_template */
|
||||
protected $template;
|
||||
|
||||
var $eol = "\n";
|
||||
|
||||
/**
|
||||
@ -210,6 +211,8 @@ class messenger
|
||||
{
|
||||
global $config, $phpbb_root_path, $phpEx, $user, $phpbb_extension_manager;
|
||||
|
||||
$this->setup_template();
|
||||
|
||||
if (!trim($template_file))
|
||||
{
|
||||
trigger_error('No template file for emailing set.', E_USER_ERROR);
|
||||
@ -219,46 +222,43 @@ class messenger
|
||||
{
|
||||
// fall back to board default language if the user's language is
|
||||
// missing $template_file. If this does not exist either,
|
||||
// $tpl->set_filenames will do a trigger_error
|
||||
// $this->template->set_filenames will do a trigger_error
|
||||
$template_lang = basename($config['default_lang']);
|
||||
}
|
||||
|
||||
// tpl_msg now holds a template object we can use to parse the template file
|
||||
if (!isset($this->tpl_msg[$template_lang . $template_file]))
|
||||
if ($template_path)
|
||||
{
|
||||
$style_resource_locator = new phpbb_style_resource_locator();
|
||||
$style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider(), $phpbb_root_path);
|
||||
$tpl = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context(), $phpbb_extension_manager);
|
||||
$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider, $tpl);
|
||||
$template_paths = array(
|
||||
$template_path,
|
||||
);
|
||||
}
|
||||
if (!$template_path)
|
||||
{
|
||||
$template_path = (!empty($user->lang_path)) ? $user->lang_path : $phpbb_root_path . 'language/';
|
||||
$template_path .= $template_lang . '/email';
|
||||
|
||||
$this->tpl_msg[$template_lang . $template_file] = $tpl;
|
||||
$template_paths = array(
|
||||
$template_path,
|
||||
);
|
||||
|
||||
$fallback_template_path = false;
|
||||
|
||||
if (!$template_path)
|
||||
// we can only specify default language fallback when the path is not a custom one for which we
|
||||
// do not know the default language alternative
|
||||
if ($template_lang !== basename($config['default_lang']))
|
||||
{
|
||||
$template_path = (!empty($user->lang_path)) ? $user->lang_path : $phpbb_root_path . 'language/';
|
||||
$template_path .= $template_lang . '/email';
|
||||
$fallback_template_path = (!empty($user->lang_path)) ? $user->lang_path : $phpbb_root_path . 'language/';
|
||||
$fallback_template_path .= basename($config['default_lang']) . '/email';
|
||||
|
||||
// we can only specify default language fallback when the path is not a custom one for which we
|
||||
// do not know the default language alternative
|
||||
if ($template_lang !== basename($config['default_lang']))
|
||||
{
|
||||
$fallback_template_path = (!empty($user->lang_path)) ? $user->lang_path : $phpbb_root_path . 'language/';
|
||||
$fallback_template_path .= basename($config['default_lang']) . '/email';
|
||||
}
|
||||
$template_paths[] = $fallback_template_path;
|
||||
}
|
||||
|
||||
$style->set_custom_style($template_lang . '_email', array($template_path, $fallback_template_path), array(), '');
|
||||
|
||||
$tpl->set_filenames(array(
|
||||
'body' => $template_file . '.txt',
|
||||
));
|
||||
}
|
||||
|
||||
$this->tpl_obj = &$this->tpl_msg[$template_lang . $template_file];
|
||||
$this->vars = &$this->tpl_obj->_rootref;
|
||||
$this->tpl_msg = '';
|
||||
$this->set_template_paths($template_lang . '_email', $template_paths);
|
||||
|
||||
$this->template->set_filenames(array(
|
||||
'body' => $template_file . '.txt',
|
||||
));
|
||||
|
||||
$this->vars = $this->template->get_template_vars();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -268,22 +268,16 @@ class messenger
|
||||
*/
|
||||
function assign_vars($vars)
|
||||
{
|
||||
if (!is_object($this->tpl_obj))
|
||||
{
|
||||
return;
|
||||
}
|
||||
$this->setup_template();
|
||||
|
||||
$this->tpl_obj->assign_vars($vars);
|
||||
$this->template->assign_vars($vars);
|
||||
}
|
||||
|
||||
function assign_block_vars($blockname, $vars)
|
||||
{
|
||||
if (!is_object($this->tpl_obj))
|
||||
{
|
||||
return;
|
||||
}
|
||||
$this->setup_template();
|
||||
|
||||
$this->tpl_obj->assign_block_vars($blockname, $vars);
|
||||
$this->template->assign_block_vars($blockname, $vars);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -316,7 +310,7 @@ class messenger
|
||||
}
|
||||
|
||||
// Parse message through template
|
||||
$this->msg = trim($this->tpl_obj->assign_display('body'));
|
||||
$this->msg = trim($this->template->assign_display('body'));
|
||||
|
||||
// Because we use \n for newlines in the body message we need to fix line encoding errors for those admins who uploaded email template files in the wrong encoding
|
||||
$this->msg = str_replace("\r\n", "\n", $this->msg);
|
||||
@ -643,6 +637,31 @@ class messenger
|
||||
unset($addresses);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup template engine
|
||||
*/
|
||||
protected function setup_template()
|
||||
{
|
||||
global $config, $phpbb_root_path, $phpEx, $user, $phpbb_extension_manager;
|
||||
|
||||
if ($this->template instanceof phpbb_template)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context(), $phpbb_extension_manager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set template paths to load
|
||||
*/
|
||||
protected function set_template_paths($path_name, $paths)
|
||||
{
|
||||
$this->setup_template();
|
||||
|
||||
$this->template->set_style_names(array($path_name), $paths);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user