Skip to content

Commit

Permalink
Fix bug #45805 - INCLUDEPHP not depending on phpbb_root_path
Browse files Browse the repository at this point in the history
Authorised by: acydburn

git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9633 89ea8834-ac86-4346-8a33-228a782c2dd0
  • Loading branch information
nickvergessen committed Jun 19, 2009
1 parent d85a5ad commit 7d605da
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
1 change: 1 addition & 0 deletions phpBB/docs/CHANGELOG.html
Expand Up @@ -132,6 +132,7 @@ <h1>Changelog</h1>
<li>[Change] Ability to define column split in FAQ/BBCode help (Bug #31405)</li>
<li>[Change] Changed behaviour of group_create() function to support specifying additional group columns</li>
<li>[Change] Hide avatar when avatar-type is not allowed (Bug #46785 - Patch by cYbercOsmOnauT and nickvergessen)</li>
<li>[Change] INCLUDEPHP not depending on phpbb_root_path (Bug #45805 - Patch by nickvergessen)</li>
<li>[Feature] Add confirmation for deactivating styles (Bug #14304 - Patch by leviatan21)</li>
<li>[Feature] Backported 3.2 captcha plugins.</li>
<li>[Feature] Introduced new ACM plugins:
Expand Down
2 changes: 1 addition & 1 deletion phpBB/includes/functions_template.php
Expand Up @@ -640,7 +640,7 @@ function compile_tag_include($tag_args)
*/
function compile_tag_include_php($tag_args)
{
return "include('" . $tag_args . "');";
return "\$this->_php_include('$tag_args');";
}

/**
Expand Down
47 changes: 33 additions & 14 deletions phpBB/includes/template.php
Expand Up @@ -55,7 +55,7 @@ function set_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 ($user->theme['template_inherits_id'])
{
$this->inherit_root = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template';
Expand Down Expand Up @@ -105,13 +105,13 @@ function set_filenames($filename_array)

$this->filename[$handle] = $filename;
$this->files[$handle] = $this->root . '/' . $filename;

if ($this->inherit_root)
{
$this->files_inherit[$handle] = $this->inherit_root . '/' . $filename;
}
}

return true;
}

Expand Down Expand Up @@ -209,7 +209,7 @@ function assign_display($handle, $template_var = '', $return_content = true, $in

return true;
}

/**
* Load a compiled template if possible, if not, recompile it
* @access private
Expand All @@ -220,7 +220,7 @@ function _tpl_load(&$handle)

$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)
{
Expand All @@ -236,7 +236,7 @@ function _tpl_load(&$handle)
}
$recompile = (@filemtime($filename) < filemtime($this->files[$handle])) ? true : false;
}

// Recompile page if the original template is newer, otherwise load the compiled version
if (!$recompile)
{
Expand All @@ -249,14 +249,14 @@ function _tpl_load(&$handle)
{
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.
Expand All @@ -282,23 +282,23 @@ function _tpl_load(&$handle)
$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 = ' . $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))
{
$rows[$row['template_filename']] = $row;
}
$db->sql_freeresult($result);
}

if (sizeof($rows))
{
foreach ($rows as $row)
Expand Down Expand Up @@ -326,7 +326,7 @@ function _tpl_load(&$handle)
{
$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])
Expand Down Expand Up @@ -468,7 +468,7 @@ function assign_block_vars($blockname, $vararray)
{
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;
}
Expand Down Expand Up @@ -511,7 +511,7 @@ function alter_block_array($blockname, $vararray, $key = false, $mode = 'insert'
// 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)
{
Expand Down Expand Up @@ -614,6 +614,25 @@ function _tpl_include($filename, $include = true)
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);
}
}

?>

0 comments on commit 7d605da

Please sign in to comment.