diff options
Diffstat (limited to 'phpBB/includes/functions_messenger.php')
| -rw-r--r-- | phpBB/includes/functions_messenger.php | 105 | 
1 files changed, 62 insertions, 43 deletions
diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index a646f35fdd..0222a57bcc 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -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";  	/** @@ -55,10 +56,10 @@ class messenger  		$this->vars = $this->msg = $this->replyto = $this->from = '';  		$this->mail_priority = MAIL_NORMAL_PRIORITY;  	} -	 +  	/**  	* Set addresses for to/im as available -	*  +	*  	* @param array $user User row  	*/  	function set_addresses($user) @@ -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($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, 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; +			$template_paths = array( +				$template_path, +			); +		} +		else +		{ +			$template_path = (!empty($user->lang_path)) ? $user->lang_path : $phpbb_root_path . 'language/'; +			$template_path .= $template_lang . '/email'; -			$fallback_template_path = false; +			$template_paths = array( +				$template_path, +			); -			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(), ''); +		$this->set_template_paths($template_lang . '_email', $template_paths); -			$tpl->set_filenames(array( -				'body'		=> $template_file . '.txt', -			)); -		} +		$this->template->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->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); +	}  }  /**  | 
