mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 05:18:52 +00:00
[feature/template-events] Convert a single style name to array of them.
This allows template code to know the entire style hierarchy for templates being rendered. PHPBB3-9550
This commit is contained in:
parent
0a29312d83
commit
44d6dc4c4c
13 changed files with 33 additions and 26 deletions
|
@ -52,7 +52,7 @@ $mode = request_var('mode', '');
|
||||||
|
|
||||||
// Set custom style for admin area
|
// Set custom style for admin area
|
||||||
$phpbb_style->set_ext_dir_prefix('adm/');
|
$phpbb_style->set_ext_dir_prefix('adm/');
|
||||||
$phpbb_style->set_custom_style('admin', $phpbb_admin_path . 'style', '');
|
$phpbb_style->set_custom_style('admin', $phpbb_admin_path . 'style', array(), '');
|
||||||
$template->assign_var('T_ASSETS_PATH', $phpbb_root_path . 'assets');
|
$template->assign_var('T_ASSETS_PATH', $phpbb_root_path . 'assets');
|
||||||
$template->assign_var('T_TEMPLATE_PATH', $phpbb_admin_path . 'style');
|
$template->assign_var('T_TEMPLATE_PATH', $phpbb_admin_path . 'style');
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ $user->setup();
|
||||||
$phpbb_admin_path = (defined('PHPBB_ADMIN_PATH')) ? PHPBB_ADMIN_PATH : './';
|
$phpbb_admin_path = (defined('PHPBB_ADMIN_PATH')) ? PHPBB_ADMIN_PATH : './';
|
||||||
|
|
||||||
// Set custom template for admin area
|
// Set custom template for admin area
|
||||||
$phpbb_style->set_custom_style('admin', $phpbb_admin_path . 'style', '');
|
$phpbb_style->set_custom_style('admin', $phpbb_admin_path . 'style', array(), '');
|
||||||
|
|
||||||
$template->set_filenames(array(
|
$template->set_filenames(array(
|
||||||
'body' => 'colour_swatch.html')
|
'body' => 'colour_swatch.html')
|
||||||
|
|
|
@ -231,7 +231,7 @@ class messenger
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$style->set_custom_style($template_lang . '_email', array($template_path, $fallback_template_path), '');
|
$style->set_custom_style($template_lang . '_email', array($template_path, $fallback_template_path), array(), '');
|
||||||
|
|
||||||
$tpl->set_filenames(array(
|
$tpl->set_filenames(array(
|
||||||
'body' => $template_file . '.txt',
|
'body' => $template_file . '.txt',
|
||||||
|
|
|
@ -110,18 +110,27 @@ class phpbb_style
|
||||||
*
|
*
|
||||||
* @param string $name Name of style, used for cache prefix. Examples: "admin", "prosilver"
|
* @param string $name Name of style, used for cache prefix. Examples: "admin", "prosilver"
|
||||||
* @param array or string $paths Array of style paths, relative to current root directory
|
* @param array or string $paths Array of style paths, relative to current root directory
|
||||||
|
* @param array $names Array of names of templates in inheritance tree order, used by extensions. If empty, $name will be used.
|
||||||
* @param string $template_path Path to templates, relative to style directory. False if path should be set to default (templates/).
|
* @param string $template_path Path to templates, relative to style directory. False if path should be set to default (templates/).
|
||||||
*/
|
*/
|
||||||
public function set_custom_style($name, $paths, $template_path = false)
|
public function set_custom_style($name, $paths, $names = array(), $template_path = false)
|
||||||
{
|
{
|
||||||
if (is_string($paths))
|
if (is_string($paths))
|
||||||
{
|
{
|
||||||
$paths = array($paths);
|
$paths = array($paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (empty($names))
|
||||||
|
{
|
||||||
|
$names = array($name);
|
||||||
|
}
|
||||||
|
$this->names = $names;
|
||||||
|
|
||||||
$this->provider->set_styles($paths);
|
$this->provider->set_styles($paths);
|
||||||
$this->locator->set_paths($this->provider);
|
$this->locator->set_paths($this->provider);
|
||||||
|
|
||||||
|
$this->template->style_names = $names;
|
||||||
|
|
||||||
if ($template_path !== false)
|
if ($template_path !== false)
|
||||||
{
|
{
|
||||||
$this->locator->set_template_path($template_path);
|
$this->locator->set_template_path($template_path);
|
||||||
|
|
|
@ -36,17 +36,17 @@ 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 $style_name Name of style to which the template being compiled belongs
|
* @param array $style_names Name of style to which the template being compiled belongs and parents in style tree order
|
||||||
* @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
|
||||||
* @param phpbb_user $user Current user
|
* @param phpbb_user $user Current user
|
||||||
*/
|
*/
|
||||||
public function __construct($allow_php, $style_name, $locator, $phpbb_root_path, $extension_manager = null, $user = null)
|
public function __construct($allow_php, $style_names, $locator, $phpbb_root_path, $extension_manager = null, $user = null)
|
||||||
{
|
{
|
||||||
$this->filter_params = array(
|
$this->filter_params = array(
|
||||||
'allow_php' => $allow_php,
|
'allow_php' => $allow_php,
|
||||||
'style_name' => $style_name,
|
'style_names' => $style_names,
|
||||||
'locator' => $locator,
|
'locator' => $locator,
|
||||||
'phpbb_root_path' => $phpbb_root_path,
|
'phpbb_root_path' => $phpbb_root_path,
|
||||||
'extension_manager' => $extension_manager,
|
'extension_manager' => $extension_manager,
|
||||||
|
|
|
@ -89,14 +89,13 @@ class phpbb_template_filter extends php_user_filter
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of the style that the template being compiled and/or rendered
|
* Name of the style that the template being compiled and/or rendered
|
||||||
* belongs to.
|
* belongs to, and its parents, in inheritance tree order.
|
||||||
*
|
*
|
||||||
* This is used by hooks implementation to invoke style-specific
|
* Used to invoke style-specific template events.
|
||||||
* template hooks.
|
|
||||||
*
|
*
|
||||||
* @var string
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $style_name;
|
private $style_names;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extension manager.
|
* Extension manager.
|
||||||
|
@ -169,7 +168,7 @@ class phpbb_template_filter extends php_user_filter
|
||||||
/**
|
/**
|
||||||
* Initializer, called on creation.
|
* Initializer, called on creation.
|
||||||
*
|
*
|
||||||
* Get the allow_php option, style_name, root directory and locator from params,
|
* Get the allow_php option, style_names, 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()
|
||||||
|
@ -179,7 +178,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->style_name = $this->params['style_name'];
|
$this->style_names = $this->params['style_names'];
|
||||||
$this->extension_manager = $this->params['extension_manager'];
|
$this->extension_manager = $this->params['extension_manager'];
|
||||||
if (isset($this->params['user']))
|
if (isset($this->params['user']))
|
||||||
{
|
{
|
||||||
|
|
|
@ -83,14 +83,13 @@ class phpbb_template
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Name of the style that the template being compiled and/or rendered
|
* Name of the style that the template being compiled and/or rendered
|
||||||
* belongs to.
|
* belongs to, and its parents, in inheritance tree order.
|
||||||
*
|
*
|
||||||
* This is used by hooks implementation to invoke style-specific
|
* Used to invoke style-specific template events.
|
||||||
* template hooks.
|
|
||||||
*
|
*
|
||||||
* @var string
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $style_name;
|
public $style_names;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
@ -302,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->style_name, $this->locator, $this->phpbb_root_path, $this->extension_manager, $this->user);
|
$compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->style_names, $this->locator, $this->phpbb_root_path, $this->extension_manager, $this->user);
|
||||||
|
|
||||||
if ($compile->compile_file_to_file($source_file, $output_file) !== false)
|
if ($compile->compile_file_to_file($source_file, $output_file) !== false)
|
||||||
{
|
{
|
||||||
|
|
|
@ -215,7 +215,7 @@ $phpbb_style_path_provider = new phpbb_style_path_provider();
|
||||||
$template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, new phpbb_template_context());
|
$template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, new phpbb_template_context());
|
||||||
$phpbb_style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider, $template);
|
$phpbb_style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider, $template);
|
||||||
$phpbb_style->set_ext_dir_prefix('adm/');
|
$phpbb_style->set_ext_dir_prefix('adm/');
|
||||||
$phpbb_style->set_custom_style('admin', '../adm/style', '');
|
$phpbb_style->set_custom_style('admin', '../adm/style', array(), '');
|
||||||
$template->assign_var('T_ASSETS_PATH', '../assets');
|
$template->assign_var('T_ASSETS_PATH', '../assets');
|
||||||
$template->assign_var('T_TEMPLATE_PATH', '../adm/style');
|
$template->assign_var('T_TEMPLATE_PATH', '../adm/style');
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ class install_update extends module
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set custom template again. ;)
|
// Set custom template again. ;)
|
||||||
$phpbb_style->set_custom_style('admin', '../adm/style', '');
|
$phpbb_style->set_custom_style('admin', '../adm/style', array(), '');
|
||||||
|
|
||||||
$template->assign_vars(array(
|
$template->assign_vars(array(
|
||||||
'S_USER_LANG' => $user->lang['USER_LANG'],
|
'S_USER_LANG' => $user->lang['USER_LANG'],
|
||||||
|
|
|
@ -48,7 +48,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case
|
||||||
|
|
||||||
$this->setup_engine(array('tpl_allow_php' => true));
|
$this->setup_engine(array('tpl_allow_php' => true));
|
||||||
|
|
||||||
$this->style->set_custom_style('tests', $cache_dir, '');
|
$this->style->set_custom_style('tests', $cache_dir, array(), '');
|
||||||
$cache_file = $this->template->cachepath . 'includephp_absolute.html.php';
|
$cache_file = $this->template->cachepath . 'includephp_absolute.html.php';
|
||||||
|
|
||||||
$this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php", $cache_file);
|
$this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php", $cache_file);
|
||||||
|
|
|
@ -77,6 +77,6 @@ class phpbb_template_template_events_test extends phpbb_template_template_test_c
|
||||||
$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context, $this->extension_manager);
|
$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context, $this->extension_manager);
|
||||||
$this->style_provider = new phpbb_style_path_provider();
|
$this->style_provider = new phpbb_style_path_provider();
|
||||||
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
|
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
|
||||||
$this->style->set_custom_style('tests', array($this->template_path), '');
|
$this->style->set_custom_style('silver', array($this->template_path), array(), '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
|
||||||
$this->style_provider = new phpbb_style_path_provider();
|
$this->style_provider = new phpbb_style_path_provider();
|
||||||
$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context());
|
$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context());
|
||||||
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
|
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
|
||||||
$this->style->set_custom_style('tests', $this->template_path, '');
|
$this->style->set_custom_style('tests', $this->template_path, array(), '');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
|
|
|
@ -24,6 +24,6 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
|
||||||
$this->style_provider = new phpbb_style_path_provider();
|
$this->style_provider = new phpbb_style_path_provider();
|
||||||
$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context());
|
$this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context());
|
||||||
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
|
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
|
||||||
$this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), '');
|
$this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), array(), '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue