Line 36 | Line 36 |
---|
var $cachepath = ''; var $files = array(); var $filename = array();
|
var $cachepath = ''; var $files = array(); var $filename = array();
|
| 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();
| // this will hash handle names to the compiled/uncompiled code for that handle. var $compiled_code = array();
|
Line 51 | Line 56 |
---|
if (file_exists($phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template')) { $this->root = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template';
|
if (file_exists($phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template')) { $this->root = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template';
|
$this->cachepath = $phpbb_root_path . 'cache/tpl_' . $user->theme['template_path'] . '_';
| $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'; }
|
} else {
| } else {
|
Line 67 | Line 90 |
---|
* Set custom template location (able to use directory outside of phpBB) * @access public */
|
* Set custom template location (able to use directory outside of phpBB) * @access public */
|
function set_custom_template($template_path, $template_name)
| function set_custom_template($template_path, $template_name, $fallback_template_path = false)
|
{
|
{
|
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->root = $template_path;
|
$this->cachepath = $phpbb_root_path . 'cache/ctpl_' . $template_name . '_';
| $this->cachepath = $phpbb_root_path . 'cache/ctpl_' . str_replace('_', '-', $template_name) . '_';
if ($fallback_template_path !== false) { if (substr($fallback_template_path, -1) == '/') { $fallback_template_path = substr($fallback_template_path, 0, -1); }
$this->inherit_root = $fallback_template_path; $this->orig_tpl_inherits_id = true; } else { $this->orig_tpl_inherits_id = false; }
// the database does not store the path or name of a custom template // so there is no way we can properly store custom templates there $this->orig_tpl_storedb = false;
$this->_rootref = &$this->_tpldata['.'][0];
|
return true; }
| return true; }
|
Line 88 | Line 138 |
---|
{ return false; }
|
{ return false; }
|
| |
foreach ($filename_array as $handle => $filename) { if (empty($filename))
| foreach ($filename_array as $handle => $filename) { if (empty($filename))
|
Line 98 | Line 147 |
---|
$this->filename[$handle] = $filename; $this->files[$handle] = $this->root . '/' . $filename;
|
$this->filename[$handle] = $filename; $this->files[$handle] = $this->root . '/' . $filename;
|
| if ($this->inherit_root) { $this->files_inherit[$handle] = $this->inherit_root . '/' . $filename; }
|
}
return true;
| }
return true;
|
Line 110 | Line 164 |
---|
function destroy() { $this->_tpldata = array('.' => array(0 => array()));
|
function destroy() { $this->_tpldata = array('.' => array(0 => array()));
|
| $this->_rootref = &$this->_tpldata['.'][0];
|
}
/**
| }
/**
|
Line 150 | Line 205 |
---|
{ global $user, $phpbb_hook;
|
{ global $user, $phpbb_hook;
|
if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, __FUNCTION__), $handle, $include_once))
| if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, __FUNCTION__), $handle, $include_once, $this))
|
{ if ($phpbb_hook->hook_return(array(__CLASS__, __FUNCTION__))) {
| { if ($phpbb_hook->hook_return(array(__CLASS__, __FUNCTION__))) {
|
Line 205 | Line 260 |
---|
function _tpl_load(&$handle) { global $user, $phpEx, $config;
|
function _tpl_load(&$handle) { global $user, $phpEx, $config;
|
| if (!isset($this->filename[$handle])) { trigger_error("template->_tpl_load(): No file specified for handle $handle", E_USER_ERROR); }
// reload these settings to have the values they had when this object was initialised // using set_template or set_custom_template, they might otherwise have been overwritten // by other template class instances in between. $user->theme['template_storedb'] = $this->orig_tpl_storedb; $user->theme['template_inherits_id'] = $this->orig_tpl_inherits_id;
|
$filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . '.' . $phpEx;
|
$filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . '.' . $phpEx;
|
| $this->files_template[$handle] = (isset($user->theme['template_id'])) ? $user->theme['template_id'] : 0;
|
|
|
$recompile = (($config['load_tplcompile'] && @filemtime($filename) < filemtime($this->files[$handle])) || !file_exists($filename) || @filesize($filename) === 0) ? true : false;
| $recompile = false; if (!file_exists($filename) || @filesize($filename) === 0 || defined('DEBUG_EXTRA')) { $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)
| // Recompile page if the original template is newer, otherwise load the compiled version if (!$recompile)
|
Line 221 | Line 302 |
---|
if (!class_exists('template_compile')) { include($phpbb_root_path . 'includes/functions_template.' . $phpEx);
|
if (!class_exists('template_compile')) { 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);
| }
$compile = new template_compile($this);
|
Line 239 | Line 327 |
---|
}
if (isset($user->theme['template_storedb']) && $user->theme['template_storedb'])
|
}
if (isset($user->theme['template_storedb']) && $user->theme['template_storedb'])
|
| { $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 . '
|
{ $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) . ')';
|
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);
|
$result = $db->sql_query($sql);
|
$row = $db->sql_fetchrow($result);
| while ($row = $db->sql_fetchrow($result)) { $rows[$row['template_filename']] = $row; } $db->sql_freeresult($result); }
|
|
|
if ($row)
| 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]) {
|
{ if ($row['template_filename'] == $this->filename[$handle]) {
|
$compile->_tpl_load_file($handle);
| $compile->_tpl_load_file($handle, true);
|
} else {
|
} 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']]);
| unset($this->compiled_code[$row['template_filename']]); unset($this->files[$row['template_filename']]); unset($this->filename[$row['template_filename']]);
|
Line 284 | Line 414 |
---|
} } }
|
} } }
|
while ($row = $db->sql_fetchrow($result));
| |
} else {
|
} 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; }
|
// 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; }
| return false; }
|
Line 512 | Line 649 |
---|
$handle = $filename; $this->filename[$handle] = $filename; $this->files[$handle] = $this->root . '/' . $filename;
|
$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);
|
Line 526 | Line 667 |
---|
} eval(' ?>' . $this->compiled_code[$handle] . '<?php '); }
|
} 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);
|
} }
| } }
|