diff options
author | Igor Wiedler <igor@wiedler.ch> | 2012-02-17 13:48:48 +0100 |
---|---|---|
committer | Igor Wiedler <igor@wiedler.ch> | 2012-02-17 13:48:48 +0100 |
commit | d70c3f1eb8c0ddc68d8eda1bd8708c4957c21182 (patch) | |
tree | c0081f9deac588982d2e00cf935daabb03af6605 /phpBB/includes/template | |
parent | 7295e5824aed6f5ec32cfab0ad17cfa2c24855ac (diff) | |
parent | 9611b5ff83582d7bda22ab991e8d69786dab5b93 (diff) | |
download | forums-d70c3f1eb8c0ddc68d8eda1bd8708c4957c21182.tar forums-d70c3f1eb8c0ddc68d8eda1bd8708c4957c21182.tar.gz forums-d70c3f1eb8c0ddc68d8eda1bd8708c4957c21182.tar.bz2 forums-d70c3f1eb8c0ddc68d8eda1bd8708c4957c21182.tar.xz forums-d70c3f1eb8c0ddc68d8eda1bd8708c4957c21182.zip |
Merge branch 'develop' into ticket/10380
* develop: (325 commits)
[ticket/10641] Update MCP template with new plurality forms
[ticket/10637] Leftovers from implementation of extensions in convertor
[ticket/10637] Leftovers from implementation of extensions in develop tools
[ticket/10637] Leftovers from implementation of extensions in mcp_post
[ticket/10637] Leftovers from implementation of extensions in mcp_main
[ticket/10637] Leftovers from implementation of extensions
[ticket/10606] Also correctly use $s_search_hidden_fields in view(forum|topic).
[ticket/10606] Fix incorrect hidden fields array name in page_header().
[ticket/10633] Stop leaking filename of attachments when thumbnail is requested
[ticket/10636] Resolve variable name ($sql_ary) conflict in cache_moderators().
[ticket/10634] Specify module type when viewing profile
[ticket/10634] Changing p_master::is_full_class
[ticket/10569] Invalid string comparison in prosilver
[ticket/10495] Update request/type_cast_helper for PHP 5.4 magic_quotes_gpc drop
[ticket/10512] Call startup.php from tests/bootstrap.php
[ticket/10535] Delete no longer needed email confirm language entries.
[ticket/9914] Add backup warning to updater.
[ticket/10616] Add template inheritance to exported template
[ticket/10616] Ignore template inheritance that points to self
[ticket/10616] Add template inheritance to default styles
...
Diffstat (limited to 'phpBB/includes/template')
-rw-r--r-- | phpBB/includes/template/compile.php | 2 | ||||
-rw-r--r-- | phpBB/includes/template/context.php | 2 | ||||
-rw-r--r-- | phpBB/includes/template/extension_path_provider.php | 130 | ||||
-rw-r--r-- | phpBB/includes/template/filter.php | 26 | ||||
-rw-r--r-- | phpBB/includes/template/locator.php | 99 | ||||
-rw-r--r-- | phpBB/includes/template/path_provider.php | 102 | ||||
-rw-r--r-- | phpBB/includes/template/path_provider_interface.php | 54 | ||||
-rw-r--r-- | phpBB/includes/template/renderer.php | 2 | ||||
-rw-r--r-- | phpBB/includes/template/renderer_eval.php | 2 | ||||
-rw-r--r-- | phpBB/includes/template/renderer_include.php | 2 | ||||
-rw-r--r-- | phpBB/includes/template/template.php | 100 |
11 files changed, 409 insertions, 112 deletions
diff --git a/phpBB/includes/template/compile.php b/phpBB/includes/template/compile.php index 8d8560ded5..b0009421c5 100644 --- a/phpBB/includes/template/compile.php +++ b/phpBB/includes/template/compile.php @@ -3,7 +3,7 @@ * * @package phpBB3 * @copyright (c) 2005 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/phpBB/includes/template/context.php b/phpBB/includes/template/context.php index f85f86a0ec..65a3531bc5 100644 --- a/phpBB/includes/template/context.php +++ b/phpBB/includes/template/context.php @@ -3,7 +3,7 @@ * * @package phpBB3 * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/phpBB/includes/template/extension_path_provider.php b/phpBB/includes/template/extension_path_provider.php new file mode 100644 index 0000000000..2897f60ac1 --- /dev/null +++ b/phpBB/includes/template/extension_path_provider.php @@ -0,0 +1,130 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Provides a template locator with core template paths and extension template paths +* +* Finds installed template paths and makes them available to the locator. +* +* @package phpBB3 +*/ +class phpbb_template_extension_path_provider extends phpbb_extension_provider implements phpbb_template_path_provider_interface +{ + /** + * Optional prefix for template paths searched within extensions. + * + * Empty by default. Relative to the extension directory. As an example, it + * could be adm/ for admin templates. + * + * @var string + */ + protected $ext_dir_prefix = ''; + + /** + * A provider of paths to be searched for templates + * @var phpbb_template_path_provider + */ + protected $base_path_provider; + + /** + * Constructor stores extension manager + * + * @param phpbb_extension_manager $extension_manager phpBB extension manager + * @param phpbb_template_path_provider $base_path_provider A simple path provider + * to provide paths to be located in extensions + */ + public function __construct(phpbb_extension_manager $extension_manager, phpbb_template_path_provider $base_path_provider) + { + parent::__construct($extension_manager); + $this->base_path_provider = $base_path_provider; + } + + /** + * Sets a prefix for template paths searched within extensions. + * + * The prefix is inserted between the extension's path e.g. ext/foo/ and + * the looked up template path, e.g. styles/bar/template/some.html. So it + * should not have a leading slash, but should have a trailing slash. + * + * @param string $ext_dir_prefix The prefix including trailing slash + * @return null + */ + public function set_ext_dir_prefix($ext_dir_prefix) + { + $this->ext_dir_prefix = $ext_dir_prefix; + } + + /** + * Finds template paths using the extension manager + * + * Locates a path (e.g. styles/prosilver/template/) in all active extensions. + * Then appends the core template paths based in the current working + * directory. + * + * @return array List of template paths + */ + public function find() + { + $directories = array(); + + $finder = $this->extension_manager->get_finder(); + foreach ($this->base_path_provider as $path) + { + if ($path && !phpbb_is_absolute($path)) + { + $directories = array_merge($directories, $finder + ->directory('/' . $this->ext_dir_prefix . $path) + ->get_directories() + ); + } + } + + foreach ($this->base_path_provider as $path) + { + $directories[] = $path; + } + + return $directories; + } + + /** + * Overwrites the current template names and paths + * + * @param array $templates An associative map from template names to paths. + * The first element is the main template. + * If the path is false, it will be generated from + * the supplied name. + * @param string $style_root_path The root directory for styles identified + * by name only. + * @return null + */ + public function set_templates(array $templates, $style_root_path) + { + $this->base_path_provider->set_templates($templates, $style_root_path); + $this->items = null; + } + + /** + * Retrieves the path to the main template passed into set_templates() + * + * @return string Main template path + */ + public function get_main_template_path() + { + return $this->base_path_provider->get_main_template_path(); + } +} diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index f24c3f4d09..f55c8d7e9c 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -3,7 +3,7 @@ * * @package phpBB3 * @copyright (c) 2011 phpBB Group, sections (c) 2001 ispi of Lincoln Inc -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ @@ -40,6 +40,7 @@ class phpbb_template_filter extends php_user_filter const REGEX_NS = '[a-z_][a-z_0-9]+'; const REGEX_VAR = '[A-Z_][A-Z_0-9]+'; + const REGEX_VAR_SUFFIX = '[A-Z_0-9]+'; const REGEX_TAG = '<!-- ([A-Z][A-Z_0-9]+)(?: (.*?) ?)?-->'; @@ -374,7 +375,7 @@ class phpbb_template_filter extends php_user_filter // transform vars prefixed by L_ into their language variable pendant if nothing is set within the tpldata array if (strpos($text_blocks, '{L_') !== false) { - $text_blocks = preg_replace('#\{L_(' . self::REGEX_VAR . ')\}#', "<?php echo ((isset(\$_rootref['L_\\1'])) ? \$_rootref['L_\\1'] : ((isset(\$_lang['\\1'])) ? \$_lang['\\1'] : '{ \\1 }')); /**/?>", $text_blocks, -1, $replacements); + $text_blocks = preg_replace('#\{L_(' . self::REGEX_VAR_SUFFIX . ')\}#', "<?php echo ((isset(\$_rootref['L_\\1'])) ? \$_rootref['L_\\1'] : ((isset(\$_lang['\\1'])) ? \$_lang['\\1'] : '{ \\1 }')); /**/?>", $text_blocks, -1, $replacements); return (bool) $replacements; } @@ -382,7 +383,7 @@ class phpbb_template_filter extends php_user_filter // If a template variable already exist, it will be used in favor of it... if (strpos($text_blocks, '{LA_') !== false) { - $text_blocks = preg_replace('#\{LA_(' . self::REGEX_VAR . '+)\}#', "<?php echo ((isset(\$_rootref['LA_\\1'])) ? \$_rootref['LA_\\1'] : ((isset(\$_rootref['L_\\1'])) ? addslashes(\$_rootref['L_\\1']) : ((isset(\$_lang['\\1'])) ? addslashes(\$_lang['\\1']) : '{ \\1 }'))); /**/?>", $text_blocks, -1, $replacements); + $text_blocks = preg_replace('#\{LA_(' . self::REGEX_VAR_SUFFIX . '+)\}#', "<?php echo ((isset(\$_rootref['LA_\\1'])) ? \$_rootref['LA_\\1'] : ((isset(\$_rootref['L_\\1'])) ? addslashes(\$_rootref['L_\\1']) : ((isset(\$_lang['\\1'])) ? addslashes(\$_lang['\\1']) : '{ \\1 }'))); /**/?>", $text_blocks, -1, $replacements); return (bool) $replacements; } @@ -872,6 +873,15 @@ class phpbb_template_filter extends php_user_filter // Strip the trailing period. $namespace = substr($namespace, 0, -1); + if (($pos = strrpos($namespace, '.')) !== false) + { + $local_namespace = substr($namespace, $pos + 1); + } + else + { + $local_namespace = $namespace; + } + $expr = true; // S_ROW_COUNT is deceptive, it returns the current row number now the number of rows @@ -880,23 +890,23 @@ class phpbb_template_filter extends php_user_filter { case 'S_ROW_NUM': case 'S_ROW_COUNT': - $varref = "\$_${namespace}_i"; + $varref = "\$_${local_namespace}_i"; break; case 'S_NUM_ROWS': - $varref = "\$_${namespace}_count"; + $varref = "\$_${local_namespace}_count"; break; case 'S_FIRST_ROW': - $varref = "(\$_${namespace}_i == 0)"; + $varref = "(\$_${local_namespace}_i == 0)"; break; case 'S_LAST_ROW': - $varref = "(\$_${namespace}_i == \$_${namespace}_count - 1)"; + $varref = "(\$_${local_namespace}_i == \$_${local_namespace}_count - 1)"; break; case 'S_BLOCK_NAME': - $varref = "'$namespace'"; + $varref = "'$local_namespace'"; break; default: diff --git a/phpBB/includes/template/locator.php b/phpBB/includes/template/locator.php index 35e33bb9e6..d4502d7984 100644 --- a/phpBB/includes/template/locator.php +++ b/phpBB/includes/template/locator.php @@ -3,7 +3,7 @@ * * @package phpBB3 * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ @@ -28,62 +28,70 @@ if (!defined('IN_PHPBB')) class phpbb_template_locator { /** - * @var string Path to directory that templates are stored in. + * Paths to directories that templates are stored in. + * @var array */ - private $root = ''; + private $roots = array(); /** - * @var string Path to parent/fallback template directory. + * Index of the main template in the roots array + * @var int */ - private $inherit_root = ''; + private $main_root_id = 0; /** - * @var array Map from handles to source template file paths. + * Map from root index to handles to source template file paths. * Normally it only contains paths for handles that are used * (or are likely to be used) by the page being rendered and not * all templates that exist on the filesystem. + * @var array */ private $files = array(); /** - * @var array Map from handles to source template file names. + * Map from handles to source template file names. * Covers the same data as $files property but maps to basenames * instead of paths. + * @var array */ private $filenames = array(); /** - * @var array Map from handles to parent/fallback source template - * file paths. Covers the same data as $files. + * Set main template location (must have been added through set_paths first). + * + * @param string $template_path Path to template directory + * @return null */ - private $files_inherit = array(); + public function set_main_template($template) + { + $this->main_root_id = array_search($template, $this->roots, true); + } /** - * Set custom template location (able to use directory outside of phpBB). + * Sets the list of template paths * - * Note: Templates are still compiled to phpBB's cache directory. + * These paths will be searched for template files in the provided order. + * Paths may be outside of phpBB, but templates loaded from these paths + * will still be cached. * - * @param string $template_path Path to template directory - * @param string|bool $fallback_template_path Path to fallback template, or false to disable fallback + * @param array $template_paths An array of paths to template directories + * @return null */ - public function set_custom_template($template_path, $fallback_template_path = false) + public function set_paths($template_paths) { - // Make sure $template_path has no ending slash - if (substr($template_path, -1) == '/') - { - $template_path = substr($template_path, 0, -1); - } - - $this->root = $template_path; + $this->roots = array(); + $this->files = array(); + $this->filenames = array(); + $this->main_root_id = 0; - if ($fallback_template_path !== false) + foreach ($template_paths as $path) { - if (substr($fallback_template_path, -1) == '/') + // Make sure $path has no ending slash + if (substr($path, -1) === '/') { - $fallback_template_path = substr($fallback_template_path, 0, -1); + $path = substr($path, 0, -1); } - - $this->inherit_root = $fallback_template_path; + $this->roots[] = $path; } } @@ -103,11 +111,10 @@ class phpbb_template_locator } $this->filename[$handle] = $filename; - $this->files[$handle] = $this->root . '/' . $filename; - if ($this->inherit_root) + foreach ($this->roots as $root_index => $root) { - $this->files_inherit[$handle] = $this->inherit_root . '/' . $filename; + $this->files[$root_index][$handle] = $root . '/' . $filename; } } } @@ -154,12 +161,12 @@ class phpbb_template_locator public function get_virtual_source_file_for_handle($handle) { // If we don't have a file assigned to this handle, die. - if (!isset($this->files[$handle])) + if (!isset($this->files[$this->main_root_id][$handle])) { trigger_error("template locator: No file specified for handle $handle", E_USER_ERROR); } - $source_file = $this->files[$handle]; + $source_file = $this->files[$this->main_root_id][$handle]; return $source_file; } @@ -182,30 +189,26 @@ class phpbb_template_locator public function get_source_file_for_handle($handle) { // If we don't have a file assigned to this handle, die. - if (!isset($this->files[$handle])) + if (!isset($this->files[$this->main_root_id][$handle])) { trigger_error("template locator: No file specified for handle $handle", E_USER_ERROR); } - $source_file = $this->files[$handle]; + // locate a source file that exists + $source_file = $this->files[0][$handle]; + $tried = $source_file; + for ($i = 1, $n = count($this->roots); $i < $n && !file_exists($source_file); $i++) + { + $source_file = $this->files[$i][$handle]; + $tried .= ', ' . $source_file; + } - // Try and open template for reading + // search failed if (!file_exists($source_file)) { - if (isset($this->files_inherit[$handle]) && $this->files_inherit[$handle]) - { - $parent_source_file = $this->files_inherit[$handle]; - if (!file_exists($parent_source_file)) - { - trigger_error("template locator: Neither $source_file nor $parent_source_file exist", E_USER_ERROR); - } - $source_file = $parent_source_file; - } - else - { - trigger_error("template locator: File $source_file does not exist", E_USER_ERROR); - } + trigger_error("template locator: File for handle $handle does not exist. Could not find: $tried", E_USER_ERROR); } + return $source_file; } } diff --git a/phpBB/includes/template/path_provider.php b/phpBB/includes/template/path_provider.php new file mode 100644 index 0000000000..b0b545973d --- /dev/null +++ b/phpBB/includes/template/path_provider.php @@ -0,0 +1,102 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Provides a template locator with paths +* +* Finds installed template paths and makes them available to the locator. +* +* @package phpBB3 +*/ +class phpbb_template_path_provider implements IteratorAggregate, phpbb_template_path_provider_interface +{ + protected $main_template_name = ''; + protected $paths = array(); + + /** + * Ignores the extension dir prefix + * + * @param string $ext_dir_prefix The prefix including trailing slash + * @return null + */ + public function set_ext_dir_prefix($ext_dir_prefix) + { + } + + /** + * Overwrites the current template names and paths + * + * The first element of the passed templates map, is considered the main + * template and can be retrieved through get_main_template_path(). + * + * @param array $templates An associative map from template names to paths. + * The first element is the main template. + * If the path is false, it will be generated from + * the supplied name. + * @param string $style_root_path The root directory for styles identified + * by name only. + * @return null + */ + public function set_templates(array $templates, $style_root_path) + { + $this->paths = array(); + + foreach ($templates as $name => $path) + { + if (!$path) + { + $path = $style_root_path . $this->template_root_for_style($name); + } + + $this->paths[] = $path; + } + + $this->main_template_path = $this->paths[0]; + } + + /** + * Retrieves the path to the main template passed into set_templates() + * + * @return string Main template path + */ + public function get_main_template_path() + { + return $this->main_template_path; + } + + /** + * Converts a style name to relative (to board root or extension) path to + * the style's template files. + * + * @param $style_name string Style name + * @return string Path to style template files + */ + private function template_root_for_style($style_name) + { + return 'styles/' . $style_name . '/template'; + } + + /** + * Retrieve an iterator over all template paths + * + * @return ArrayIterator An iterator for the array of template paths + */ + public function getIterator() + { + return new ArrayIterator($this->paths); + } +} diff --git a/phpBB/includes/template/path_provider_interface.php b/phpBB/includes/template/path_provider_interface.php new file mode 100644 index 0000000000..8b3a406d2a --- /dev/null +++ b/phpBB/includes/template/path_provider_interface.php @@ -0,0 +1,54 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Provides a template locator with paths +* +* Finds installed template paths and makes them available to the locator. +* +* @package phpBB3 +*/ +interface phpbb_template_path_provider_interface extends Traversable +{ + /** + * 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); + + /** + * Overwrites the current template names and paths + * + * @param array $templates An associative map from template names to paths. + * The first element is the main template. + * If the path is false, it will be generated from + * the supplied name. + * @param string $style_root_path The root directory for styles identified + * by name only. + * @return null + */ + public function set_templates(array $templates, $style_root_path); + + /** + * Retrieves the path to the main template passed into set_templates() + * + * @return string Main template path + */ + public function get_main_template_path(); +} diff --git a/phpBB/includes/template/renderer.php b/phpBB/includes/template/renderer.php index 59c85df443..30e234a733 100644 --- a/phpBB/includes/template/renderer.php +++ b/phpBB/includes/template/renderer.php @@ -3,7 +3,7 @@ * * @package phpBB3 * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/phpBB/includes/template/renderer_eval.php b/phpBB/includes/template/renderer_eval.php index 2c05a1c1df..f8e4cb7b10 100644 --- a/phpBB/includes/template/renderer_eval.php +++ b/phpBB/includes/template/renderer_eval.php @@ -3,7 +3,7 @@ * * @package phpBB3 * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/phpBB/includes/template/renderer_include.php b/phpBB/includes/template/renderer_include.php index 40e7a3376c..f5c9026abf 100644 --- a/phpBB/includes/template/renderer_include.php +++ b/phpBB/includes/template/renderer_include.php @@ -3,7 +3,7 @@ * * @package phpBB3 * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 0495ade9c5..989322320b 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -3,7 +3,7 @@ * * @package phpBB3 * @copyright (c) 2005 phpBB Group, sections (c) 2001 ispi of Lincoln Inc -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ @@ -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_interface $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); - } - - 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,22 @@ 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); + $templates = array($template_name => $template_path); + + if ($fallback_template_path !== false) + { + $templates[$fallback_template_name] = $fallback_template_path; + } + + $this->provider->set_templates($templates, $this->phpbb_root_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 +145,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. @@ -307,36 +310,31 @@ class phpbb_template */ private function _tpl_load($handle) { - $virtual_source_file = $this->locator->get_virtual_source_file_for_handle($handle); - $source_file = null; - - $compiled_path = $this->cachepath . str_replace('/', '.', $virtual_source_file) . '.' . $this->phpEx; + $output_file = $this->_compiled_file_for_handle($handle); $recompile = defined('DEBUG_EXTRA') || - !file_exists($compiled_path) || - @filesize($compiled_path) === 0 || - ($this->config['load_tplcompile'] && @filemtime($compiled_path) < @filemtime($source_file)); + !file_exists($output_file) || + @filesize($output_file) === 0; - if (!$recompile && $this->config['load_tplcompile']) + if ($recompile || $this->config['load_tplcompile']) { + // Set only if a recompile or an mtime check are required. $source_file = $this->locator->get_source_file_for_handle($handle); - $recompile = (@filemtime($compiled_path) < @filemtime($source_file)) ? true : false; + + if (!$recompile && @filemtime($output_file) < @filemtime($source_file)) + { + $recompile = true; + } } // Recompile page if the original template is newer, otherwise load the compiled version if (!$recompile) { - return new phpbb_template_renderer_include($compiled_path, $this); - } - - if ($source_file === null) - { - $source_file = $this->locator->get_source_file_for_handle($handle); + return new phpbb_template_renderer_include($output_file, $this); } $compile = new phpbb_template_compile($this->config['tpl_allow_php']); - $output_file = $this->_compiled_file_for_handle($handle); if ($compile->compile_file_to_file($source_file, $output_file) !== false) { $renderer = new phpbb_template_renderer_include($output_file, $this); |