aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/template.php
diff options
context:
space:
mode:
authorOleg Pudeyev <oleg@bsdpower.com>2011-04-24 21:18:18 -0400
committerOleg Pudeyev <oleg@bsdpower.com>2011-04-24 21:18:18 -0400
commita2c75f60537ccf6a424c7f066eafbffc13c0c38d (patch)
treeffb6dbac52bbb4fd3fc8eca94450ac4d9e7387ab /phpBB/includes/template.php
parent81962d1d8ff083dd366c77e7d3858fd2c9ed7d43 (diff)
downloadforums-a2c75f60537ccf6a424c7f066eafbffc13c0c38d.tar
forums-a2c75f60537ccf6a424c7f066eafbffc13c0c38d.tar.gz
forums-a2c75f60537ccf6a424c7f066eafbffc13c0c38d.tar.bz2
forums-a2c75f60537ccf6a424c7f066eafbffc13c0c38d.tar.xz
forums-a2c75f60537ccf6a424c7f066eafbffc13c0c38d.zip
[feature/template-engine] Deleted $template from phpbb_template_compile class.
phpbb_template_compile is now much simpler. It takes complete file paths as inputs, either source template path or source template path and output compiled template path. The number of methods also went down to two - compile template and returned compiled text or compile and write to file. phpbb_compile class is responsible for determining source and compiled paths. It already had all the data necessary for this, now the code is in the same place as the data it uses. PHPBB3-9726
Diffstat (limited to 'phpBB/includes/template.php')
-rw-r--r--phpBB/includes/template.php67
1 files changed, 49 insertions, 18 deletions
diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php
index 2b4c7a09f7..e1e96791c9 100644
--- a/phpBB/includes/template.php
+++ b/phpBB/includes/template.php
@@ -366,7 +366,7 @@ class phpbb_template
{
return $filename;
}
-
+
// Inheritance - we point to another template file for this one. Equality is also used for store_db
if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($this->files[$handle]))
{
@@ -374,20 +374,54 @@ class phpbb_template
$this->files_template[$handle] = $user->theme['template_inherits_id'];
}
+ $source_file = $this->_source_file_for_handle($handle);
+
+ $compile = new phpbb_template_compile($this);
+
+ if ($compile->compile_write($source_file, $this->_compiled_file_for_handle($handle)) === false)
+ {
+ return false;
+ }
+
+ return $filename;
+ }
+
+ /**
+ * Resolves template handle $handle to source file path.
+ * @access private
+ * @param string $handle Template handle (i.e. "friendly" template name)
+ * @return string Source file path
+ */
+ private function _source_file_for_handle($handle)
+ {
// If we don't have a file assigned to this handle, die.
if (!isset($this->files[$handle]))
{
- trigger_error("template->_tpl_load(): No file specified for handle $handle", E_USER_ERROR);
+ trigger_error("_source_file_for_handle(): No file specified for handle $handle", E_USER_ERROR);
}
- $compile = new phpbb_template_compile($this);
+ $source_file = $this->files[$handle];
- if ($compile->_tpl_load_file($handle) === false)
+ // Try and open template for reading
+ if (!file_exists($source_file))
{
- return false;
+ trigger_error("_source_file_for_handle(): File $source_file does not exist", E_USER_ERROR);
}
-
- return $filename;
+ return $source_file;
+ }
+
+ /**
+ * Determines compiled file path for handle $handle.
+ * @access private
+ * @param string $handle Template handle (i.e. "friendly" template name)
+ * @return string Compiled file path
+ */
+ private function _compiled_file_for_handle($handle)
+ {
+ global $phpEx;
+
+ $compiled_file = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . '.' . $phpEx;
+ return $compiled_file;
}
/**
@@ -401,13 +435,9 @@ class phpbb_template
{
$compile = new phpbb_template_compile($this);
- // If we don't have a file assigned to this handle, die.
- if (!isset($this->files[$handle]))
- {
- trigger_error("template->_tpl_eval(): No file specified for handle $handle", E_USER_ERROR);
- }
+ $source_file = $this->_source_file_for_handle($handle);
- if (($code = $compile->_tpl_gen_src($handle)) === false)
+ if (($code = $compile->compile_gen($source_file)) === false)
{
return false;
}
@@ -473,13 +503,13 @@ class phpbb_template
{
if ($row['template_filename'] == $this->filename[$handle])
{
- $compile->_tpl_load_file($handle, true);
+ $compile->compile_write($source_file, $this->_compiled_file_for_handle($handle));
}
else
{
$this->files[$row['template_filename']] = $file;
$this->filename[$row['template_filename']] = $row['template_filename'];
- $compile->_tpl_load_file($row['template_filename'], true);
+ $compile->compile_write($this->_source_file_for_handle($row['template_filename']), $this->_compiled_file_for_handle($row['template_filename']));
unset($this->compiled_code[$row['template_filename']]);
unset($this->files[$row['template_filename']]);
unset($this->filename[$row['template_filename']]);
@@ -515,14 +545,14 @@ class phpbb_template
$this->files_template[$row['template_filename']] = $user->theme['template_inherits_id'];
}
// Try to load from filesystem and instruct to insert into the styles table...
- $compile->_tpl_load_file($handle, true);
+ $compile->compile_write($source_file, $this->_compiled_file_for_handle($handle));
return false;
}
return false;
}
- $compile->_tpl_load_file($handle);
+ $compile->compile_write($source_file, $this->_compiled_file_for_handle($handle));
return false;
}
@@ -801,7 +831,8 @@ class phpbb_template
{
$compile = new phpbb_template_compile($this);
- if (($code = $compile->_tpl_gen_src($handle)) !== false)
+ $source_file = $this->_source_file_for_handle($handle);
+ if (($code = $compile->compile_gen($source_file)) !== false)
{
$code = ' ?> ' . $code . ' <?php ';
eval($code);