aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Pudeyev <oleg@bsdpower.com>2012-11-08 12:21:06 -0500
committerOleg Pudeyev <oleg@bsdpower.com>2012-11-17 16:42:40 -0500
commit44d6dc4c4ccf969fd3d84f3b39bfd24ecd3a3f9d (patch)
tree5dd030f606400f049141dbc9b086e6288b6dd0b7
parent0a29312d830c65dc293822c291bf2efd6f93a29b (diff)
downloadforums-44d6dc4c4ccf969fd3d84f3b39bfd24ecd3a3f9d.tar
forums-44d6dc4c4ccf969fd3d84f3b39bfd24ecd3a3f9d.tar.gz
forums-44d6dc4c4ccf969fd3d84f3b39bfd24ecd3a3f9d.tar.bz2
forums-44d6dc4c4ccf969fd3d84f3b39bfd24ecd3a3f9d.tar.xz
forums-44d6dc4c4ccf969fd3d84f3b39bfd24ecd3a3f9d.zip
[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
-rw-r--r--phpBB/adm/index.php2
-rw-r--r--phpBB/adm/swatch.php2
-rw-r--r--phpBB/includes/functions_messenger.php2
-rw-r--r--phpBB/includes/style/style.php11
-rw-r--r--phpBB/includes/template/compile.php6
-rw-r--r--phpBB/includes/template/filter.php13
-rw-r--r--phpBB/includes/template/template.php11
-rw-r--r--phpBB/install/index.php2
-rw-r--r--phpBB/install/install_update.php2
-rw-r--r--tests/template/includephp_test.php2
-rw-r--r--tests/template/template_events_test.php2
-rw-r--r--tests/template/template_test_case.php2
-rw-r--r--tests/template/template_test_case_with_tree.php2
13 files changed, 33 insertions, 26 deletions
diff --git a/phpBB/adm/index.php b/phpBB/adm/index.php
index e20bbe4bec..0f84af6f9e 100644
--- a/phpBB/adm/index.php
+++ b/phpBB/adm/index.php
@@ -52,7 +52,7 @@ $mode = request_var('mode', '');
// Set custom style for admin area
$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_TEMPLATE_PATH', $phpbb_admin_path . 'style');
diff --git a/phpBB/adm/swatch.php b/phpBB/adm/swatch.php
index 86498a255f..c01651e0f0 100644
--- a/phpBB/adm/swatch.php
+++ b/phpBB/adm/swatch.php
@@ -24,7 +24,7 @@ $user->setup();
$phpbb_admin_path = (defined('PHPBB_ADMIN_PATH')) ? PHPBB_ADMIN_PATH : './';
// 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(
'body' => 'colour_swatch.html')
diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php
index 55884caedb..2043e2f7be 100644
--- a/phpBB/includes/functions_messenger.php
+++ b/phpBB/includes/functions_messenger.php
@@ -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(
'body' => $template_file . '.txt',
diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php
index effd496fb9..9ce96c5da5 100644
--- a/phpBB/includes/style/style.php
+++ b/phpBB/includes/style/style.php
@@ -110,18 +110,27 @@ class phpbb_style
*
* @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 $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/).
*/
- 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))
{
$paths = array($paths);
}
+ if (empty($names))
+ {
+ $names = array($name);
+ }
+ $this->names = $names;
+
$this->provider->set_styles($paths);
$this->locator->set_paths($this->provider);
+ $this->template->style_names = $names;
+
if ($template_path !== false)
{
$this->locator->set_template_path($template_path);
diff --git a/phpBB/includes/template/compile.php b/phpBB/includes/template/compile.php
index c2762bfd59..76ad2317c9 100644
--- a/phpBB/includes/template/compile.php
+++ b/phpBB/includes/template/compile.php
@@ -36,17 +36,17 @@ class phpbb_template_compile
* Constructor.
*
* @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 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, $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(
'allow_php' => $allow_php,
- 'style_name' => $style_name,
+ 'style_names' => $style_names,
'locator' => $locator,
'phpbb_root_path' => $phpbb_root_path,
'extension_manager' => $extension_manager,
diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php
index 5d9e00553f..a5a0865569 100644
--- a/phpBB/includes/template/filter.php
+++ b/phpBB/includes/template/filter.php
@@ -89,14 +89,13 @@ class phpbb_template_filter extends php_user_filter
/**
* 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
- * template hooks.
+ * Used to invoke style-specific template events.
*
- * @var string
+ * @var array
*/
- private $style_name;
+ private $style_names;
/**
* Extension manager.
@@ -169,7 +168,7 @@ class phpbb_template_filter extends php_user_filter
/**
* 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.
*/
public function onCreate()
@@ -179,7 +178,7 @@ class phpbb_template_filter extends php_user_filter
$this->allow_php = $this->params['allow_php'];
$this->locator = $this->params['locator'];
$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'];
if (isset($this->params['user']))
{
diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php
index 52c08326d5..4d257d2510 100644
--- a/phpBB/includes/template/template.php
+++ b/phpBB/includes/template/template.php
@@ -83,14 +83,13 @@ class phpbb_template
/**
* 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
- * template hooks.
+ * Used to invoke style-specific template events.
*
- * @var string
+ * @var array
*/
- private $style_name;
+ public $style_names;
/**
* Constructor.
@@ -302,7 +301,7 @@ class phpbb_template
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)
{
diff --git a/phpBB/install/index.php b/phpBB/install/index.php
index 09560946a6..2be5adaaac 100644
--- a/phpBB/install/index.php
+++ b/phpBB/install/index.php
@@ -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());
$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_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_TEMPLATE_PATH', '../adm/style');
diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php
index 8c044550f3..3964dbfe2b 100644
--- a/phpBB/install/install_update.php
+++ b/phpBB/install/install_update.php
@@ -131,7 +131,7 @@ class install_update extends module
}
// 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(
'S_USER_LANG' => $user->lang['USER_LANG'],
diff --git a/tests/template/includephp_test.php b/tests/template/includephp_test.php
index c93a53e2ad..f1012b6939 100644
--- a/tests/template/includephp_test.php
+++ b/tests/template/includephp_test.php
@@ -48,7 +48,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case
$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';
$this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php", $cache_file);
diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php
index 274af7d7cf..22aa2e88d5 100644
--- a/tests/template/template_events_test.php
+++ b/tests/template/template_events_test.php
@@ -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->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->set_custom_style('tests', array($this->template_path), '');
+ $this->style->set_custom_style('silver', array($this->template_path), array(), '');
}
}
diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php
index 2e6f703eb1..3c997cb00e 100644
--- a/tests/template/template_test_case.php
+++ b/tests/template/template_test_case.php
@@ -69,7 +69,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
$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->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()
diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php
index 6a226f317a..7585be5728 100644
--- a/tests/template/template_test_case_with_tree.php
+++ b/tests/template/template_test_case_with_tree.php
@@ -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->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->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(), '');
}
}