1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-21 23:13:43 +02:00

[feature/template-events] Pass top-level template name to template filter.

This will be used to invoke template-specific hooks.

PHPBB3-9550
This commit is contained in:
Oleg Pudeyev 2012-03-16 00:22:42 -04:00
parent dd7c5183fb
commit a6c7fbc59d
3 changed files with 26 additions and 3 deletions

View File

@ -36,14 +36,16 @@ class phpbb_template_compile
* Constructor. * Constructor.
* *
* @param bool $allow_php Whether PHP code will be allowed in templates (inline PHP code, PHP tag and INCLUDEPHP tag) * @param bool $allow_php Whether PHP code will be allowed in templates (inline PHP code, PHP tag and INCLUDEPHP tag)
* @param string $template_name Name of top-level template being compiled
* @param phpbb_style_resource_locator $locator Resource locator * @param phpbb_style_resource_locator $locator Resource locator
* @param string $phpbb_root_path Path to phpBB root directory * @param string $phpbb_root_path Path to phpBB root directory
* @param phpbb_extension_manager $extension_manager Extension manager to use for finding template fragments in extensions; if null, template hooks will not be invoked * @param phpbb_extension_manager $extension_manager Extension manager to use for finding template fragments in extensions; if null, template hooks will not be invoked
*/ */
public function __construct($allow_php, $locator, $phpbb_root_path, $extension_manager = null) public function __construct($allow_php, $template_name, $locator, $phpbb_root_path, $extension_manager = null)
{ {
$this->filter_params = array( $this->filter_params = array(
'allow_php' => $allow_php, 'allow_php' => $allow_php,
'template_name' => $template_name,
'locator' => $locator, 'locator' => $locator,
'phpbb_root_path' => $phpbb_root_path, 'phpbb_root_path' => $phpbb_root_path,
'extension_manager' => $extension_manager, 'extension_manager' => $extension_manager,

View File

@ -87,6 +87,16 @@ class phpbb_template_filter extends php_user_filter
*/ */
private $phpbb_root_path; private $phpbb_root_path;
/**
* Name of the top-level template being compiled and/or rendered.
*
* This is used by hooks implementation to invoke template-specific
* template hooks.
*
* @var string
*/
private $template_name;
/** /**
* Extension manager. * Extension manager.
* *
@ -152,7 +162,7 @@ class phpbb_template_filter extends php_user_filter
/** /**
* Initializer, called on creation. * Initializer, called on creation.
* *
* Get the allow_php option, root directory and locator from params, * Get the allow_php option, template_name, root directory and locator from params,
* which are passed to stream_filter_append. * which are passed to stream_filter_append.
*/ */
public function onCreate() public function onCreate()
@ -162,6 +172,7 @@ class phpbb_template_filter extends php_user_filter
$this->allow_php = $this->params['allow_php']; $this->allow_php = $this->params['allow_php'];
$this->locator = $this->params['locator']; $this->locator = $this->params['locator'];
$this->phpbb_root_path = $this->params['phpbb_root_path']; $this->phpbb_root_path = $this->params['phpbb_root_path'];
$this->template_name = $this->params['template_name'];
$this->extension_manager = $this->params['extension_manager']; $this->extension_manager = $this->params['extension_manager'];
$this->template_compile = $this->params['template_compile']; $this->template_compile = $this->params['template_compile'];
return true; return true;

View File

@ -81,6 +81,16 @@ class phpbb_template
*/ */
private $extension_manager; private $extension_manager;
/**
* Name of the top-level template being compiled and/or rendered.
*
* This is used by hooks implementation to invoke template-specific
* template hooks.
*
* @var string
*/
private $template_name;
/** /**
* Constructor. * Constructor.
* *
@ -291,7 +301,7 @@ class phpbb_template
return new phpbb_template_renderer_include($output_file, $this); return new phpbb_template_renderer_include($output_file, $this);
} }
$compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->locator, $this->phpbb_root_path, $this->extension_manager); $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->template_name, $this->locator, $this->phpbb_root_path, $this->extension_manager);
if ($compile->compile_file_to_file($source_file, $output_file) !== false) if ($compile->compile_file_to_file($source_file, $output_file) !== false)
{ {