aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/template/template.php
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2011-08-30 01:32:11 -0400
committerNils Adermann <naderman@naderman.de>2011-09-29 16:15:53 +0200
commitea46feb11542a9cf54ce083ee0ad03f4c5e02a1e (patch)
tree0990527e0c05bd9da495a063350ec199eb2ed227 /phpBB/includes/template/template.php
parent6ea6d50ccb9607429486a01d3144c7d32322e1b5 (diff)
downloadforums-ea46feb11542a9cf54ce083ee0ad03f4c5e02a1e.tar
forums-ea46feb11542a9cf54ce083ee0ad03f4c5e02a1e.tar.gz
forums-ea46feb11542a9cf54ce083ee0ad03f4c5e02a1e.tar.bz2
forums-ea46feb11542a9cf54ce083ee0ad03f4c5e02a1e.tar.xz
forums-ea46feb11542a9cf54ce083ee0ad03f4c5e02a1e.zip
[feature/extension-manager] Add support for templates in extensions.
This commit adds a template path provider to separate the process of locating (cached) paths in extensions from the template engine. The locator is supplied with a list of paths from the path provider. Admin templates can now be created in ext/<ext>/adm/style/ and regular templates go into ext/<ext>/styles/<style>/template/. Extension templates override regular templates. So if an extension supplies a file with a name used in phpBB, the extension's file will be used. A side-effect of this commit: Locator and Provider are now able to deal with arbitrary levels of template inheritance. So we can expose this through phpbb_template if we choose to, and allow styles to inherit from inherited styles. PHPBB3-10323
Diffstat (limited to 'phpBB/includes/template/template.php')
-rw-r--r--phpBB/includes/template/template.php67
1 files changed, 33 insertions, 34 deletions
diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php
index ec5fbe2829..53db171a5d 100644
--- a/phpBB/includes/template/template.php
+++ b/phpBB/includes/template/template.php
@@ -63,24 +63,33 @@ class phpbb_template
private $user;
/**
- * @var locator template locator
+ * Template locator
+ * @var phpbb_template_locator
*/
private $locator;
/**
+ * Template path provider
+ * @var phpbb_template_path_provider
+ */
+ private $provider;
+
+ /**
* Constructor.
*
* @param string $phpbb_root_path phpBB root path
* @param user $user current user
* @param phpbb_template_locator $locator template locator
+ * @param phpbb_template_path_provider $provider template path provider
*/
- public function __construct($phpbb_root_path, $phpEx, $config, $user, phpbb_template_locator $locator)
+ public function __construct($phpbb_root_path, $phpEx, $config, $user, phpbb_template_locator $locator, phpbb_template_path_provider $provider)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->phpEx = $phpEx;
$this->config = $config;
$this->user = $user;
$this->locator = $locator;
+ $this->provider = $provider;
}
/**
@@ -88,25 +97,21 @@ class phpbb_template
*/
public function set_template()
{
- $style_name = $this->user->theme['template_path'];
-
- $relative_template_root = $this->relative_template_root_for_style($style_name);
- $template_root = $this->phpbb_root_path . $relative_template_root;
- if (!file_exists($template_root))
- {
- trigger_error('template locator: Template path could not be found: ' . $relative_template_root, E_USER_ERROR);
- }
+ $template_name = $this->user->theme['template_path'];
+ $fallback_name = ($this->user->theme['template_inherits_id']) ? $this->user->theme['template_inherit_path'] : false;
- if ($this->user->theme['template_inherits_id'])
- {
- $fallback_template_path = $this->phpbb_root_path . $this->relative_template_root_for_style($this->user->theme['template_inherit_path']);
- }
- else
- {
- $fallback_template_path = null;
- }
+ return $this->set_custom_template(false, $template_name, false, $fallback_name);
+ }
- return $this->set_custom_template($template_root, $style_name, $fallback_template_path);
+ /**
+ * Defines a prefix to use for template paths in extensions
+ *
+ * @param string $ext_dir_prefix The prefix including trailing slash
+ * @return null
+ */
+ public function set_ext_dir_prefix($ext_dir_prefix)
+ {
+ $this->provider->set_ext_dir_prefix($ext_dir_prefix);
}
/**
@@ -117,12 +122,18 @@ class phpbb_template
* @param string $template_path Path to template directory
* @param string $template_name Name of template
* @param string $fallback_template_path Path to fallback template
+ * @param string $fallback_template_name Name of fallback template
*/
- public function set_custom_template($template_path, $style_name, $fallback_template_path = false)
+ public function set_custom_template($template_path, $template_name, $fallback_template_path = false, $fallback_template_name = false)
{
- $this->locator->set_custom_template($template_path, $fallback_template_path);
+ $this->provider->set_templates(array(
+ $template_name => $template_path,
+ $fallback_template_name => $fallback_template_path,
+ ));
+ $this->locator->set_paths($this->provider);
+ $this->locator->set_main_template($this->provider->get_main_template_path());
- $this->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $style_name) . '_';
+ $this->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $template_name) . '_';
$this->context = new phpbb_template_context();
@@ -130,18 +141,6 @@ class phpbb_template
}
/**
- * Converts a style name to relative (to board root) path to
- * the style's template files.
- *
- * @param $style_name string Style name
- * @return string Path to style template files
- */
- private function relative_template_root_for_style($style_name)
- {
- return 'styles/' . $style_name . '/template';
- }
-
- /**
* Sets the template filenames for handles.
*
* @param array $filname_array Should be a hash of handle => filename pairs.