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.php129
1 files changed, 108 insertions, 21 deletions
diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php
index 2e60beb658..d17ad55691 100644
--- a/phpBB/includes/template.php
+++ b/phpBB/includes/template.php
@@ -36,6 +36,9 @@ class template
var $cachepath = '';
var $files = array();
var $filename = array();
+ var $files_inherit = array();
+ var $files_template = array();
+ var $inherit_root = '';
// this will hash handle names to the compiled/uncompiled code for that handle.
var $compiled_code = array();
@@ -52,6 +55,11 @@ class template
{
$this->root = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template';
$this->cachepath = $phpbb_root_path . 'cache/tpl_' . $user->theme['template_path'] . '_';
+
+ if ($user->theme['template_inherits_id'])
+ {
+ $this->inherit_root = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template';
+ }
}
else
{
@@ -88,7 +96,6 @@ class template
{
return false;
}
-
foreach ($filename_array as $handle => $filename)
{
if (empty($filename))
@@ -98,8 +105,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;
}
@@ -197,7 +209,7 @@ class template
return true;
}
-
+
/**
* Load a compiled template if possible, if not, recompile it
* @access private
@@ -207,9 +219,24 @@ class template
global $user, $phpEx, $config;
$filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . '.' . $phpEx;
-
- $recompile = (($config['load_tplcompile'] && @filemtime($filename) < filemtime($this->files[$handle])) || !file_exists($filename) || @filesize($filename) === 0) ? true : false;
-
+ $this->files_template[$handle] = $user->theme['template_id'];
+
+ $recompile = false;
+ if (!file_exists($filename) || @filesize($filename) === 0)
+ {
+ $recompile = true;
+ }
+ else if ($config['load_tplcompile'])
+ {
+ // No way around it: we need to check inheritance here
+ if ($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'];
+ }
+ $recompile = (@filemtime($filename) < filemtime($this->files[$handle])) ? true : false;
+ }
+
// Recompile page if the original template is newer, otherwise load the compiled version
if (!$recompile)
{
@@ -222,7 +249,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.
@@ -240,28 +274,70 @@ class template
if (isset($user->theme['template_storedb']) && $user->theme['template_storedb'])
{
- $sql = 'SELECT *
+ $rows = array();
+ $ids = array();
+ // Inheritance
+ if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'])
+ {
+ $ids[] = $user->theme['template_inherits_id'];
+ }
+ $ids[] = $user->theme['template_id'];
+
+ foreach ($ids as $id)
+ {
+ $sql = 'SELECT *
FROM ' . STYLES_TEMPLATE_DATA_TABLE . '
- WHERE template_id = ' . $user->theme['template_id'] . "
+ 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);
- $row = $db->sql_fetchrow($result);
-
- if ($row)
+
+ $result = $db->sql_query($sql);
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $rows[$row['template_filename']] = $row;
+ }
+ $db->sql_freeresult($result);
+ }
+
+ if (sizeof($rows))
{
- do
+ foreach ($rows as $row)
{
- if ($row['template_mtime'] < filemtime($phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/' . $row['template_filename']))
+ $file = $this->root . '/' . $row['template_filename'];
+ $force_reload = false;
+ if ($row['template_id'] != $user->theme['template_id'])
+ {
+ // make sure that we are not overlooking a file not in the db yet
+ if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($file))
+ {
+ $file = $this->inherit_root . '/' . $row['template_filename'];
+ $this->files[$row['template_filename']] = $file;
+ $this->files_inherit[$row['template_filename']] = $file;
+ $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id'];
+ }
+ else if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'])
+ {
+ // Ok, we have a situation. There is a file in the subtemplate, but nothing in the DB. We have to fix that.
+ $force_reload = true;
+ $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id'];
+ }
+ }
+ else
+ {
+ $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])
{
- $compile->_tpl_load_file($handle);
+ $compile->_tpl_load_file($handle, true);
}
else
{
- $this->files[$row['template_filename']] = $this->root . '/' . $row['template_filename'];
- $compile->_tpl_load_file($row['template_filename']);
+ $this->files[$row['template_filename']] = $file;
+ $this->filename[$row['template_filename']] = $row['template_filename'];
+ $compile->_tpl_load_file($row['template_filename'], true);
unset($this->compiled_code[$row['template_filename']]);
unset($this->files[$row['template_filename']]);
unset($this->filename[$row['template_filename']]);
@@ -284,15 +360,22 @@ class template
}
}
}
- while ($row = $db->sql_fetchrow($result));
}
else
{
+ $file = $this->root . '/' . $row['template_filename'];
+
+ if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($file))
+ {
+ $file = $this->inherit_root . '/' . $row['template_filename'];
+ $this->files[$row['template_filename']] = $file;
+ $this->files_inherit[$row['template_filename']] = $file;
+ $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);
return false;
}
- $db->sql_freeresult($result);
return false;
}
@@ -512,8 +595,12 @@ class template
$handle = $filename;
$this->filename[$handle] = $filename;
$this->files[$handle] = $this->root . '/' . $filename;
+ if ($this->inherit_root)
+ {
+ $this->files_inherit[$handle] = $this->inherit_root . '/' . $filename;
+ }
- $filename = $this->_tpl_load($handle);
+ $filename = $this->_tpl_load($handle);
if ($include)
{