mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-09 12:58:52 +00:00
[feature/template-events] Handle user access correctly.
Pass through $user from template to filter. Allow $user to be null for standalone usage of the template engine. PHPBB3-9550
This commit is contained in:
parent
45a1219886
commit
1b36fc3a60
2 changed files with 21 additions and 3 deletions
|
@ -40,8 +40,9 @@ class phpbb_template_compile
|
|||
* @param phpbb_style_resource_locator $locator Resource locator
|
||||
* @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_user $user Current user
|
||||
*/
|
||||
public function __construct($allow_php, $template_name, $locator, $phpbb_root_path, $extension_manager = null)
|
||||
public function __construct($allow_php, $template_name, $locator, $phpbb_root_path, $extension_manager = null, $user = null)
|
||||
{
|
||||
$this->filter_params = array(
|
||||
'allow_php' => $allow_php,
|
||||
|
@ -49,6 +50,7 @@ class phpbb_template_compile
|
|||
'locator' => $locator,
|
||||
'phpbb_root_path' => $phpbb_root_path,
|
||||
'extension_manager' => $extension_manager,
|
||||
'user' => $user,
|
||||
'template_compile' => $this,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -104,6 +104,12 @@ class phpbb_template_filter extends php_user_filter
|
|||
*/
|
||||
private $extension_manager;
|
||||
|
||||
/**
|
||||
* Current user
|
||||
* @var phpbb_user
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* Template compiler.
|
||||
*
|
||||
|
@ -174,6 +180,10 @@ class phpbb_template_filter extends php_user_filter
|
|||
$this->phpbb_root_path = $this->params['phpbb_root_path'];
|
||||
$this->template_name = $this->params['template_name'];
|
||||
$this->extension_manager = $this->params['extension_manager'];
|
||||
if (isset($this->params['user']))
|
||||
{
|
||||
$this->user = $this->params['user'];
|
||||
}
|
||||
$this->template_compile = $this->params['template_compile'];
|
||||
return true;
|
||||
}
|
||||
|
@ -878,8 +888,14 @@ class phpbb_template_filter extends php_user_filter
|
|||
if (!preg_match('/^\w+$/', $tag_args))
|
||||
{
|
||||
// The hook location is wrongly formatted,
|
||||
global $user;
|
||||
trigger_error($user->lang('ERR_TEMPLATE_EVENT_LOCATION', $tag_args), E_USER_ERROR);
|
||||
if ($this->user)
|
||||
{
|
||||
trigger_error($this->user->lang('ERR_TEMPLATE_EVENT_LOCATION', $tag_args), E_USER_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
trigger_error(sprintf('The specified template event location <em>[%s]</em> is wrongly formatted.', $tag_args), E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
$location = $tag_args;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue