mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-30 21:40:43 +02:00
[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
This commit is contained in:
@@ -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'];
|
||||
$template_name = $this->user->theme['template_path'];
|
||||
$fallback_name = ($this->user->theme['template_inherits_id']) ? $this->user->theme['template_inherit_path'] : false;
|
||||
|
||||
$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);
|
||||
}
|
||||
return $this->set_custom_template(false, $template_name, false, $fallback_name);
|
||||
}
|
||||
|
||||
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($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,30 +122,24 @@ 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();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
Reference in New Issue
Block a user