aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/template.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes/template.php')
-rw-r--r--phpBB/includes/template.php74
1 files changed, 59 insertions, 15 deletions
diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php
index 0098c484bd..80434aca4c 100644
--- a/phpBB/includes/template.php
+++ b/phpBB/includes/template.php
@@ -39,6 +39,8 @@ class template
var $files_inherit = array();
var $files_template = array();
var $inherit_root = '';
+ var $orig_tpl_storedb;
+ var $orig_tpl_inherits_id;
// this will hash handle names to the compiled/uncompiled code for that handle.
var $compiled_code = array();
@@ -55,7 +57,20 @@ class template
{
$this->root = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template';
$this->cachepath = $phpbb_root_path . 'cache/tpl_' . str_replace('_', '-', $user->theme['template_path']) . '_';
-
+
+ if ($this->orig_tpl_storedb === null)
+ {
+ $this->orig_tpl_storedb = $user->theme['template_storedb'];
+ }
+
+ if ($this->orig_tpl_inherits_id === null)
+ {
+ $this->orig_tpl_inherits_id = $user->theme['template_inherits_id'];
+ }
+
+ $user->theme['template_storedb'] = $this->orig_tpl_storedb;
+ $user->theme['template_inherits_id'] = $this->orig_tpl_inherits_id;
+
if ($user->theme['template_inherits_id'])
{
$this->inherit_root = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template';
@@ -77,10 +92,20 @@ class template
*/
function set_custom_template($template_path, $template_name)
{
- global $phpbb_root_path;
+ global $phpbb_root_path, $user;
+
+ // 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->cachepath = $phpbb_root_path . 'cache/ctpl_' . str_replace('_', '-', $template_name) . '_';
+ $user->theme['template_storedb'] = false;
+ $user->theme['template_inherits_id'] = false;
+
+ $this->_rootref = &$this->_tpldata['.'][0];
return true;
}
@@ -105,13 +130,13 @@ class template
$this->filename[$handle] = $filename;
$this->files[$handle] = $this->root . '/' . $filename;
-
+
if ($this->inherit_root)
{
$this->files_inherit[$handle] = $this->inherit_root . '/' . $filename;
}
}
-
+
return true;
}
@@ -209,7 +234,7 @@ class template
return true;
}
-
+
/**
* Load a compiled template if possible, if not, recompile it
* @access private
@@ -220,7 +245,7 @@ class template
$filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . '.' . $phpEx;
$this->files_template[$handle] = $user->theme['template_id'];
-
+
$recompile = false;
if (!file_exists($filename) || @filesize($filename) === 0)
{
@@ -236,7 +261,7 @@ class template
}
$recompile = (@filemtime($filename) < filemtime($this->files[$handle])) ? true : false;
}
-
+
// Recompile page if the original template is newer, otherwise load the compiled version
if (!$recompile)
{
@@ -249,14 +274,14 @@ class template
{
include($phpbb_root_path . 'includes/functions_template.' . $phpEx);
}
-
+
// 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]))
{
$this->files[$handle] = $this->files_inherit[$handle];
$this->files_template[$handle] = $user->theme['template_inherits_id'];
}
-
+
$compile = new template_compile($this);
// If we don't have a file assigned to this handle, die.
@@ -282,7 +307,7 @@ class template
$ids[] = $user->theme['template_inherits_id'];
}
$ids[] = $user->theme['template_id'];
-
+
foreach ($ids as $id)
{
$sql = 'SELECT *
@@ -290,7 +315,7 @@ class template
WHERE template_id = ' . $id . "
AND (template_filename = '" . $db->sql_escape($this->filename[$handle]) . "'
OR template_included " . $db->sql_like_expression($db->any_char . $this->filename[$handle] . ':' . $db->any_char) . ')';
-
+
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
@@ -298,7 +323,7 @@ class template
}
$db->sql_freeresult($result);
}
-
+
if (sizeof($rows))
{
foreach ($rows as $row)
@@ -326,7 +351,7 @@ class template
{
$this->files_template[$row['template_filename']] = $user->theme['template_id'];
}
-
+
if ($force_reload || $row['template_mtime'] < filemtime($file))
{
if ($row['template_filename'] == $this->filename[$handle])
@@ -468,7 +493,7 @@ class template
{
unset($this->_tpldata[$blockname][($s_row_count - 1)]['S_LAST_ROW']);
}
-
+
// Add a new iteration to this block with the variable assignments we were given.
$this->_tpldata[$blockname][] = $vararray;
}
@@ -511,7 +536,7 @@ class template
// Nested blocks are not supported
return false;
}
-
+
// Change key to zero (change first position) if false and to last position if true
if ($key === false || $key === true)
{
@@ -614,6 +639,25 @@ class template
eval(' ?>' . $this->compiled_code[$handle] . '<?php ');
}
}
+
+ /**
+ * Include a php-file
+ * @access private
+ */
+ function _php_include($filename)
+ {
+ global $phpbb_root_path;
+
+ $file = $phpbb_root_path . $filename;
+
+ if (!file_exists($file))
+ {
+ // trigger_error cannot be used here, as the output already started
+ echo 'template->_php_include(): File ' . htmlspecialchars($file) . ' does not exist or is empty';
+ return;
+ }
+ include($file);
+ }
}
?> \ No newline at end of file