diff --git a/phpBB/common.php b/phpBB/common.php
index a00e3e82a8..81fe275008 100644
--- a/phpBB/common.php
+++ b/phpBB/common.php
@@ -124,7 +124,7 @@ $phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_ro
// Initialize style
$phpbb_style_resource_locator = new phpbb_style_resource_locator();
$phpbb_style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider());
-$template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider);
+$template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator);
$phpbb_style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider, $template);
$phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager);
diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php
index 612ced8ad6..fde917e5b1 100644
--- a/phpBB/includes/bbcode.php
+++ b/phpBB/includes/bbcode.php
@@ -134,7 +134,7 @@ class bbcode
$style_resource_locator = new phpbb_style_resource_locator();
$style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider());
- $template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider);
+ $template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator);
$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider, $template);
$style->set_style();
$template->set_filenames(array('bbcode.html' => 'bbcode.html'));
diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php
index f608c95fe4..e9073553d0 100644
--- a/phpBB/includes/functions_messenger.php
+++ b/phpBB/includes/functions_messenger.php
@@ -210,8 +210,9 @@ class messenger
{
$style_resource_locator = new phpbb_style_resource_locator();
$style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider());
- $tpl = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider);
+ $tpl = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator);
$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $style_resource_locator, $style_path_provider, $tpl);
+
$this->tpl_msg[$template_lang . $template_file] = $tpl;
$fallback_template_path = false;
diff --git a/phpBB/includes/style/resource_locator.php b/phpBB/includes/style/resource_locator.php
index 3e6dd5d6aa..fafa11c352 100644
--- a/phpBB/includes/style/resource_locator.php
+++ b/phpBB/includes/style/resource_locator.php
@@ -30,7 +30,7 @@ if (!defined('IN_PHPBB'))
*
* @package phpBB3
*/
-class phpbb_style_resource_locator
+class phpbb_style_resource_locator implements phpbb_template_locator
{
/**
* Paths to style directories.
diff --git a/phpBB/includes/style/style.php b/phpBB/includes/style/style.php
index 5ac61c9f10..3f470015f6 100644
--- a/phpBB/includes/style/style.php
+++ b/phpBB/includes/style/style.php
@@ -22,28 +22,33 @@ if (!defined('IN_PHPBB'))
class phpbb_style
{
/**
- * @var phpbb_style_template Template class.
+ * Template class.
* Handles everything related to templates.
+ * @var phpbb_template
*/
private $template;
/**
- * @var string phpBB root path
+ * phpBB root path
+ * @var string
*/
private $phpbb_root_path;
/**
- * @var phpEx PHP file extension
+ * PHP file extension
+ * @var string
*/
private $phpEx;
/**
- * @var phpbb_config phpBB config instance
+ * phpBB config instance
+ * @var phpbb_config
*/
private $config;
/**
- * @var user current user
+ * Current user
+ * @var phpbb_user
*/
private $user;
@@ -66,9 +71,9 @@ class phpbb_style
* @param user $user current user
* @param phpbb_style_resource_locator $locator style resource locator
* @param phpbb_style_path_provider $provider style path provider
- * @param phpbb_style_template $template template
+ * @param phpbb_template $template template
*/
- public function __construct($phpbb_root_path, $phpEx, $config, $user, phpbb_style_resource_locator $locator, phpbb_style_path_provider_interface $provider, phpbb_style_template $template)
+ public function __construct($phpbb_root_path, $phpEx, $config, $user, phpbb_style_resource_locator $locator, phpbb_style_path_provider_interface $provider, phpbb_template $template)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->phpEx = $phpEx;
@@ -119,7 +124,7 @@ class phpbb_style
$this->template->cachepath = $this->phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $name) . '_';
- $this->template->context = new phpbb_style_template_context();
+ $this->template->context = new phpbb_template_context();
if ($template_path !== false)
{
diff --git a/phpBB/includes/style/template_compile.php b/phpBB/includes/template/compile.php
similarity index 96%
rename from phpBB/includes/style/template_compile.php
rename to phpBB/includes/template/compile.php
index fa0928f424..82b301c1a2 100644
--- a/phpBB/includes/style/template_compile.php
+++ b/phpBB/includes/template/compile.php
@@ -15,7 +15,7 @@ if (!defined('IN_PHPBB'))
exit;
}
-stream_filter_register('phpbb_template', 'phpbb_style_template_filter');
+stream_filter_register('phpbb_template', 'phpbb_template_filter');
/**
* Extension of template class - Functions needed for compiling templates only.
@@ -23,7 +23,7 @@ stream_filter_register('phpbb_template', 'phpbb_style_template_filter');
* @package phpBB3
* @uses template_filter As a PHP stream filter to perform compilation of templates
*/
-class phpbb_style_template_compile
+class phpbb_template_compile
{
/**
* Array of parameters to forward to template filter
diff --git a/phpBB/includes/style/template_context.php b/phpBB/includes/template/context.php
similarity index 99%
rename from phpBB/includes/style/template_context.php
rename to phpBB/includes/template/context.php
index b22f77da2e..ec09da1cf3 100644
--- a/phpBB/includes/style/template_context.php
+++ b/phpBB/includes/template/context.php
@@ -20,7 +20,7 @@ if (!defined('IN_PHPBB'))
*
* @package phpBB3
*/
-class phpbb_style_template_context
+class phpbb_template_context
{
/**
* variable that holds all the data we'll be substituting into
@@ -86,7 +86,7 @@ class phpbb_style_template_context
* Returns a reference to template data array.
*
* This function is public so that template renderer may invoke it.
- * Users should alter template variables via functions in phpbb_style_template.
+ * Users should alter template variables via functions in phpbb_template.
*
* Note: modifying returned array will affect data stored in the context.
*
diff --git a/phpBB/includes/style/template_filter.php b/phpBB/includes/template/filter.php
similarity index 99%
rename from phpBB/includes/style/template_filter.php
rename to phpBB/includes/template/filter.php
index 6ef9d80a3d..4a2593b757 100644
--- a/phpBB/includes/style/template_filter.php
+++ b/phpBB/includes/template/filter.php
@@ -35,7 +35,7 @@ if (!defined('IN_PHPBB'))
* @see template_compile
* @package phpBB3
*/
-class phpbb_style_template_filter extends php_user_filter
+class phpbb_template_filter extends php_user_filter
{
const REGEX_NS = '[a-z_][a-z_0-9]+';
diff --git a/phpBB/includes/template/locator.php b/phpBB/includes/template/locator.php
new file mode 100644
index 0000000000..01c79eec4e
--- /dev/null
+++ b/phpBB/includes/template/locator.php
@@ -0,0 +1,121 @@
+ filename pairs.
+ *
+ * @param array $filname_array Should be a hash of handle => filename pairs.
+ */
+ public function set_filenames(array $filename_array);
+
+ /**
+ * Determines the filename for a template handle.
+ *
+ * The filename comes from array used in a set_filenames call,
+ * which should have been performed prior to invoking this function.
+ * Return value is a file basename (without path).
+ *
+ * @param $handle string Template handle
+ * @return string Filename corresponding to the template handle
+ */
+ public function get_filename_for_handle($handle);
+
+ /**
+ * Determines the source file path for a template handle without
+ * regard for styles tree.
+ *
+ * This function returns the path in "primary" style directory
+ * corresponding to the given template handle. That path may or
+ * may not actually exist on the filesystem. Because this function
+ * does not perform stat calls to determine whether the path it
+ * returns actually exists, it is faster than get_source_file_for_handle.
+ *
+ * Use get_source_file_for_handle to obtain the actual path that is
+ * guaranteed to exist (which might come from the parent style
+ * directory if primary style has parent styles).
+ *
+ * This function will trigger an error if the handle was never
+ * associated with a template file via set_filenames.
+ *
+ * @param $handle string Template handle
+ * @return string Path to source file path in primary style directory
+ */
+ public function get_virtual_source_file_for_handle($handle);
+
+ /**
+ * Determines the source file path for a template handle, accounting
+ * for styles tree and verifying that the path exists.
+ *
+ * This function returns the actual path that may be compiled for
+ * the specified template handle. It will trigger an error if
+ * the template handle was never associated with a template path
+ * via set_filenames or if the template file does not exist on the
+ * filesystem.
+ *
+ * Use get_virtual_source_file_for_handle to just resolve a template
+ * handle to a path without any filesystem or styles tree checks.
+ *
+ * @param string $handle Template handle (i.e. "friendly" template name)
+ * @param bool $find_all If true, each root path will be checked and function
+ * will return array of files instead of string and will not
+ * trigger a error if template does not exist
+ * @return string Source file path
+ */
+ public function get_source_file_for_handle($handle, $find_all = false);
+
+ /**
+ * Locates source file path, accounting for styles tree and verifying that
+ * the path exists.
+ *
+ * Unlike previous functions, this function works without template handle
+ * and it can search for more than one file. If more than one file name is
+ * specified, it will return location of file that it finds first.
+ *
+ * @param array $files List of files to locate.
+ * @param bool $return_default Determines what to return if file does not
+ * exist. If true, function will return location where file is
+ * supposed to be. If false, function will return false.
+ * @param bool $return_full_path If true, function will return full path
+ * to file. If false, function will return file name. This
+ * parameter can be used to check which one of set of files
+ * is available.
+ * @return string or boolean Source file path if file exists or $return_default is
+ * true. False if file does not exist and $return_default is false
+ */
+ public function get_first_file_location($files, $return_default = false, $return_full_path = true);
+}
diff --git a/phpBB/includes/style/template_renderer.php b/phpBB/includes/template/renderer.php
similarity index 81%
rename from phpBB/includes/style/template_renderer.php
rename to phpBB/includes/template/renderer.php
index bd2a786e86..30e234a733 100644
--- a/phpBB/includes/style/template_renderer.php
+++ b/phpBB/includes/template/renderer.php
@@ -23,12 +23,12 @@ if (!defined('IN_PHPBB'))
*
* @package phpBB3
*/
-interface phpbb_style_template_renderer
+interface phpbb_template_renderer
{
/**
* Displays the template managed by this renderer.
*
- * @param phpbb_style_template_context $context Template context to use
+ * @param phpbb_template_context $context Template context to use
* @param array $lang Language entries to use
*/
public function render($context, $lang);
diff --git a/phpBB/includes/style/template_renderer_eval.php b/phpBB/includes/template/renderer_eval.php
similarity index 83%
rename from phpBB/includes/style/template_renderer_eval.php
rename to phpBB/includes/template/renderer_eval.php
index 3e08b06e69..f8e4cb7b10 100644
--- a/phpBB/includes/style/template_renderer_eval.php
+++ b/phpBB/includes/template/renderer_eval.php
@@ -21,7 +21,7 @@ if (!defined('IN_PHPBB'))
*
* @package phpBB3
*/
-class phpbb_style_template_renderer_eval implements phpbb_style_template_renderer
+class phpbb_template_renderer_eval implements phpbb_template_renderer
{
/**
* Template code to be eval'ed.
@@ -33,7 +33,7 @@ class phpbb_style_template_renderer_eval implements phpbb_style_template_rendere
* Template includes are delegated to template object $template.
*
* @param string $code php code of the template
- * @param phpbb_style_template $template template object
+ * @param phpbb_template $template template object
*/
public function __construct($code, $template)
{
@@ -45,7 +45,7 @@ class phpbb_style_template_renderer_eval implements phpbb_style_template_rendere
* Displays the template managed by this renderer by eval'ing php code
* of the template.
*
- * @param phpbb_style_template_context $context Template context to use
+ * @param phpbb_template_context $context Template context to use
* @param array $lang Language entries to use
*/
public function render($context, $lang)
diff --git a/phpBB/includes/style/template_renderer_include.php b/phpBB/includes/template/renderer_include.php
similarity index 87%
rename from phpBB/includes/style/template_renderer_include.php
rename to phpBB/includes/template/renderer_include.php
index 91c1a1bb65..f5c9026abf 100644
--- a/phpBB/includes/style/template_renderer_include.php
+++ b/phpBB/includes/template/renderer_include.php
@@ -22,7 +22,7 @@ if (!defined('IN_PHPBB'))
*
* @package phpBB3
*/
-class phpbb_style_template_renderer_include implements phpbb_style_template_renderer
+class phpbb_template_renderer_include implements phpbb_template_renderer
{
/**
* Template path to be included.
@@ -45,7 +45,7 @@ class phpbb_style_template_renderer_include implements phpbb_style_template_rend
* Displays the template managed by this renderer by including
* the php file containing the template.
*
- * @param phpbb_style_template_context $context Template context to use
+ * @param phpbb_template_context $context Template context to use
* @param array $lang Language entries to use
*/
public function render($context, $lang)
diff --git a/phpBB/includes/style/template.php b/phpBB/includes/template/template.php
similarity index 89%
rename from phpBB/includes/style/template.php
rename to phpBB/includes/template/template.php
index 9d476e74b9..e6512c8417 100644
--- a/phpBB/includes/style/template.php
+++ b/phpBB/includes/template/template.php
@@ -29,51 +29,51 @@ if (!defined('IN_PHPBB'))
* Base Template class.
* @package phpBB3
*/
-class phpbb_style_template
+class phpbb_template
{
/**
- * @var phpbb_style_template_context Template context.
+ * Template context.
* Stores template data used during template rendering.
+ * @var phpbb_template_context
*/
public $context;
/**
- * @var string Path of the cache directory for the template
+ * Path of the cache directory for the template
+ * @var string
*/
public $cachepath = '';
/**
- * @var string phpBB root path
+ * phpBB root path
+ * @var string
*/
private $phpbb_root_path;
/**
- * @var phpEx PHP file extension
+ * PHP file extension
+ * @var string
*/
private $phpEx;
/**
- * @var phpbb_config phpBB config instance
+ * phpBB config instance
+ * @var phpbb_config
*/
private $config;
/**
- * @var user current user
+ * Current user
+ * @var phpbb_user
*/
private $user;
/**
- * Style resource locator
- * @var phpbb_style_resource_locator
+ * Template locator
+ * @var phpbb_template_locator
*/
private $locator;
- /**
- * Template path provider
- * @var phpbb_style_path_provider
- */
- private $provider;
-
/**
* Location of templates directory within style directories
* @var string
@@ -85,10 +85,9 @@ class phpbb_style_template
*
* @param string $phpbb_root_path phpBB root path
* @param user $user current user
- * @param phpbb_style_resource_locator $locator style resource locator
- * @param phpbb_style_path_provider $provider style path provider
+ * @param phpbb_template_locator $locator template locator
*/
- public function __construct($phpbb_root_path, $phpEx, $config, $user, phpbb_style_resource_locator $locator, phpbb_style_path_provider_interface $provider)
+ public function __construct($phpbb_root_path, $phpEx, $config, $user, phpbb_template_locator $locator)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->phpEx = $phpEx;
@@ -96,7 +95,6 @@ class phpbb_style_template
$this->user = $user;
$this->locator = $locator;
$this->template_path = $this->locator->template_path;
- $this->provider = $provider;
}
/**
@@ -253,15 +251,15 @@ class phpbb_style_template
* configuration setting may be used to force templates to be always
* recompiled.
*
- * Returns an object implementing phpbb_style_template_renderer, or null
+ * Returns an object implementing phpbb_template_renderer, or null
* if template loading or compilation failed. Call render() on the
* renderer to display the template. This will result in template
* contents sent to the output stream (unless, of course, output
* buffering is in effect).
*
* @param string $handle Handle of the template to load
- * @return phpbb_style_template_renderer Template renderer object, or null on failure
- * @uses phpbb_style_template_compile is used to compile template source
+ * @return phpbb_template_renderer Template renderer object, or null on failure
+ * @uses phpbb_template_compile is used to compile template source
*/
private function _tpl_load($handle)
{
@@ -285,18 +283,18 @@ class phpbb_style_template
// Recompile page if the original template is newer, otherwise load the compiled version
if (!$recompile)
{
- return new phpbb_style_template_renderer_include($output_file, $this);
+ return new phpbb_template_renderer_include($output_file, $this);
}
- $compile = new phpbb_style_template_compile($this->config['tpl_allow_php'], $this->locator, $this->phpbb_root_path);
+ $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->locator, $this->phpbb_root_path);
if ($compile->compile_file_to_file($source_file, $output_file) !== false)
{
- $renderer = new phpbb_style_template_renderer_include($output_file, $this);
+ $renderer = new phpbb_template_renderer_include($output_file, $this);
}
else if (($code = $compile->compile_file($source_file)) !== false)
{
- $renderer = new phpbb_style_template_renderer_eval($code, $this);
+ $renderer = new phpbb_template_renderer_eval($code, $this);
}
else
{
@@ -358,7 +356,7 @@ class phpbb_style_template
$this->context->append_var($varname, $varval);
}
- // Docstring is copied from phpbb_style_template_context method with the same name.
+ // Docstring is copied from phpbb_template_context method with the same name.
/**
* Assign key variable pairs from an array to a specified block
* @param string $blockname Name of block to assign $vararray to
@@ -369,7 +367,7 @@ class phpbb_style_template
return $this->context->assign_block_vars($blockname, $vararray);
}
- // Docstring is copied from phpbb_style_template_context method with the same name.
+ // Docstring is copied from phpbb_template_context method with the same name.
/**
* Change already assigned key variable pair (one-dimensional - single loop entry)
*
diff --git a/phpBB/install/index.php b/phpBB/install/index.php
index bb10521bba..f992b67bb7 100644
--- a/phpBB/install/index.php
+++ b/phpBB/install/index.php
@@ -202,7 +202,7 @@ $config = new phpbb_config(array(
$phpbb_style_resource_locator = new phpbb_style_resource_locator();
$phpbb_style_path_provider = new phpbb_style_path_provider();
-$template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider);
+$template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator);
$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', '');
diff --git a/tests/template/renderer_eval_test.php b/tests/template/renderer_eval_test.php
index 9b4f74c824..7ebb8b9bda 100644
--- a/tests/template/renderer_eval_test.php
+++ b/tests/template/renderer_eval_test.php
@@ -13,8 +13,8 @@ class phpbb_template_renderer_eval_test extends phpbb_test_case
{
$compiled_code = '';
$valid_code = '';
- $context = new phpbb_style_template_context();
- $template = new phpbb_style_template_renderer_eval($compiled_code, NULL);
+ $context = new phpbb_template_context();
+ $template = new phpbb_template_renderer_eval($compiled_code, NULL);
ob_start();
try
{
diff --git a/tests/template/template_compile_test.php b/tests/template/template_compile_test.php
index e2264fb1b7..0cfcd6ceb5 100644
--- a/tests/template/template_compile_test.php
+++ b/tests/template/template_compile_test.php
@@ -16,7 +16,7 @@ class phpbb_template_template_compile_test extends phpbb_test_case
protected function setUp()
{
- $this->template_compile = new phpbb_style_template_compile(false, null, '');
+ $this->template_compile = new phpbb_template_compile(false, null, '');
$this->template_path = dirname(__FILE__) . '/templates';
}
diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php
index a87e531a07..d660aa3f56 100644
--- a/tests/template/template_test_case.php
+++ b/tests/template/template_test_case.php
@@ -66,7 +66,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
$this->template_path = dirname(__FILE__) . '/templates';
$this->style_resource_locator = new phpbb_style_resource_locator();
$this->style_provider = new phpbb_style_path_provider();
- $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider);
+ $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator);
$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, '');
}
diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php
index e76d9436cf..9522c97330 100644
--- a/tests/template/template_test_case_with_tree.php
+++ b/tests/template/template_test_case_with_tree.php
@@ -22,7 +22,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
$this->parent_template_path = dirname(__FILE__) . '/parent_templates';
$this->style_resource_locator = new phpbb_style_resource_locator();
$this->style_provider = new phpbb_style_path_provider();
- $this->template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider);
+ $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator);
$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), '');
}