mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-15 12:05: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 $mail_priority = MAIL_NORMAL_PRIORITY;
|
||||||
var $use_queue = true;
|
var $use_queue = true;
|
||||||
|
|
||||||
var $tpl_obj = NULL;
|
/** @var phpbb_template */
|
||||||
var $tpl_msg = array();
|
protected $template;
|
||||||
|
|
||||||
var $eol = "\n";
|
var $eol = "\n";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -210,6 +211,8 @@ class messenger
|
|||||||
{
|
{
|
||||||
global $config, $phpbb_root_path, $phpEx, $user, $phpbb_extension_manager;
|
global $config, $phpbb_root_path, $phpEx, $user, $phpbb_extension_manager;
|
||||||
|
|
||||||
|
$this->setup_template();
|
||||||
|
|
||||||
if (!trim($template_file))
|
if (!trim($template_file))
|
||||||
{
|
{
|
||||||
trigger_error('No template file for emailing set.', E_USER_ERROR);
|
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
|
// fall back to board default language if the user's language is
|
||||||
// missing $template_file. If this does not exist either,
|
// 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']);
|
$template_lang = basename($config['default_lang']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// tpl_msg now holds a template object we can use to parse the template file
|
if ($template_path)
|
||||||
if (!isset($this->tpl_msg[$template_lang . $template_file]))
|
|
||||||
{
|
{
|
||||||
$style_resource_locator = new phpbb_style_resource_locator();
|
$template_paths = array(
|
||||||
$style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider(), $phpbb_root_path);
|
$template_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);
|
}
|
||||||
|
|
||||||
$this->tpl_msg[$template_lang . $template_file] = $tpl;
|
|
||||||
|
|
||||||
$fallback_template_path = false;
|
|
||||||
|
|
||||||
if (!$template_path)
|
if (!$template_path)
|
||||||
{
|
{
|
||||||
$template_path = (!empty($user->lang_path)) ? $user->lang_path : $phpbb_root_path . 'language/';
|
$template_path = (!empty($user->lang_path)) ? $user->lang_path : $phpbb_root_path . 'language/';
|
||||||
$template_path .= $template_lang . '/email';
|
$template_path .= $template_lang . '/email';
|
||||||
|
|
||||||
|
$template_paths = array(
|
||||||
|
$template_path,
|
||||||
|
);
|
||||||
|
|
||||||
// we can only specify default language fallback when the path is not a custom one for which we
|
// 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
|
// do not know the default language alternative
|
||||||
if ($template_lang !== basename($config['default_lang']))
|
if ($template_lang !== basename($config['default_lang']))
|
||||||
{
|
{
|
||||||
$fallback_template_path = (!empty($user->lang_path)) ? $user->lang_path : $phpbb_root_path . 'language/';
|
$fallback_template_path = (!empty($user->lang_path)) ? $user->lang_path : $phpbb_root_path . 'language/';
|
||||||
$fallback_template_path .= basename($config['default_lang']) . '/email';
|
$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(), '');
|
$this->set_template_paths($template_lang . '_email', $template_paths);
|
||||||
|
|
||||||
$tpl->set_filenames(array(
|
$this->template->set_filenames(array(
|
||||||
'body' => $template_file . '.txt',
|
'body' => $template_file . '.txt',
|
||||||
));
|
));
|
||||||
}
|
|
||||||
|
|
||||||
$this->tpl_obj = &$this->tpl_msg[$template_lang . $template_file];
|
$this->vars = $this->template->get_template_vars();
|
||||||
$this->vars = &$this->tpl_obj->_rootref;
|
|
||||||
$this->tpl_msg = '';
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -268,22 +268,16 @@ class messenger
|
|||||||
*/
|
*/
|
||||||
function assign_vars($vars)
|
function assign_vars($vars)
|
||||||
{
|
{
|
||||||
if (!is_object($this->tpl_obj))
|
$this->setup_template();
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->tpl_obj->assign_vars($vars);
|
$this->template->assign_vars($vars);
|
||||||
}
|
}
|
||||||
|
|
||||||
function assign_block_vars($blockname, $vars)
|
function assign_block_vars($blockname, $vars)
|
||||||
{
|
{
|
||||||
if (!is_object($this->tpl_obj))
|
$this->setup_template();
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$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
|
// 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
|
// 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);
|
$this->msg = str_replace("\r\n", "\n", $this->msg);
|
||||||
@ -643,6 +637,31 @@ class messenger
|
|||||||
unset($addresses);
|
unset($addresses);
|
||||||
return true;
|
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