mirror of
https://github.com/phpbb/phpbb.git
synced 2025-02-24 20:13:22 +01:00
[feature/template-engine] Get rid of orig_tpl_* in template engine.
The origins of orig_tpl_* are not pretty. Please see the following commits and associated tickets: r9823, r9839, r9847, r10150, r10460. In short, multiple hacks were required due to template engine reading inheritance/storedb flags from $user (global) even when the template that was being looked up or rendered was not the "active style of the current user". We no longer store templates in the database, removing half of the problem. This commit fixes the second half of the problem by deleting set_template_path function from template locator, and moving that logic back into the template class' set_template. set_template now calls set_custom_template, the latter only taking the template path and the fallback paths as parameters. With this change template locator no longer uses $user and does not use phpbb root path either. All logic involving setting the user's "active" template is now encapsulated in a single template class's function, set_template. Setting other templates is done via set_custom_template and the caller is responsible for determining and passing in fallback/inheritance path, if any. PHPBB3-9726
This commit is contained in:
parent
1a6250d8b6
commit
52f208900f
@ -58,56 +58,6 @@ class phpbb_template_locator
|
||||
*/
|
||||
private $files_inherit = array();
|
||||
|
||||
private $orig_tpl_inherits_id;
|
||||
|
||||
private $user;
|
||||
|
||||
public function __construct($phpbb_root_path, $user)
|
||||
{
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set template location.
|
||||
* @param string $style_name Name of style from which templates are to be taken
|
||||
*/
|
||||
public function set_template_path($style_name)
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
$this->root = $template_root;
|
||||
|
||||
if ($this->orig_tpl_inherits_id === null)
|
||||
{
|
||||
$this->orig_tpl_inherits_id = $this->user->theme['template_inherits_id'];
|
||||
}
|
||||
|
||||
$this->user->theme['template_inherits_id'] = $this->orig_tpl_inherits_id;
|
||||
|
||||
if ($this->user->theme['template_inherits_id'])
|
||||
{
|
||||
$this->inherit_root = $this->phpbb_root_path . $this->relative_template_root_for_style($this->user->theme['template_inherit_path']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set custom template location (able to use directory outside of phpBB).
|
||||
*
|
||||
@ -134,11 +84,6 @@ class phpbb_template_locator
|
||||
}
|
||||
|
||||
$this->inherit_root = $fallback_template_path;
|
||||
$this->orig_tpl_inherits_id = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->orig_tpl_inherits_id = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,8 +42,6 @@ class phpbb_template
|
||||
*/
|
||||
public $cachepath = '';
|
||||
|
||||
public $orig_tpl_inherits_id;
|
||||
|
||||
/**
|
||||
* @var string phpBB root path
|
||||
*/
|
||||
@ -81,7 +79,7 @@ class phpbb_template
|
||||
$this->phpEx = $phpEx;
|
||||
$this->config = $config;
|
||||
$this->user = $user;
|
||||
$this->locator = new phpbb_template_locator($phpbb_root_path, $user);
|
||||
$this->locator = new phpbb_template_locator();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,18 +87,28 @@ class phpbb_template
|
||||
*/
|
||||
public function set_template()
|
||||
{
|
||||
$template_path = $style_name = $this->user->theme['template_path'];
|
||||
$this->locator->set_template_path($style_name);
|
||||
$style_name = $this->user->theme['template_path'];
|
||||
|
||||
if (file_exists($this->phpbb_root_path . 'styles/' . $template_path . '/template'))
|
||||
$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))
|
||||
{
|
||||
$this->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $template_path) . '_';
|
||||
trigger_error('template locator: Template path could not be found: ' . $relative_template_root, E_USER_ERROR);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
trigger_error('Template path could not be found: styles/' . $template_path . '/template', E_USER_ERROR);
|
||||
$fallback_template_path = null;
|
||||
}
|
||||
|
||||
$this->locator->set_custom_template($template_root, $fallback_template_path);
|
||||
|
||||
$this->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $style_name) . '_';
|
||||
|
||||
$this->context = new phpbb_template_context();
|
||||
|
||||
return true;
|
||||
@ -126,6 +134,18 @@ class phpbb_template
|
||||
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. $filename_array
|
||||
* should be a hash of handle => filename pairs.
|
||||
@ -274,11 +294,6 @@ class phpbb_template
|
||||
$virtual_source_file = $this->locator->get_virtual_source_file_for_handle($handle);
|
||||
$source_file = null;
|
||||
|
||||
// reload this setting to have the values they had when this object was initialised
|
||||
// using set_template or set_custom_template, they might otherwise have been overwritten
|
||||
// by other template class instances in between.
|
||||
$this->user->theme['template_inherits_id'] = $this->orig_tpl_inherits_id;
|
||||
|
||||
$compiled_path = $this->cachepath . str_replace('/', '.', $virtual_source_file) . '.' . $this->phpEx;
|
||||
|
||||
$recompile = defined('DEBUG_EXTRA') ||
|
||||
|
Loading…
x
Reference in New Issue
Block a user