|
From: Paul S. O. <ps...@us...> - 2002-06-22 11:48:14
|
Update of /cvsroot/phpbb/phpBB2/includes
In directory usw-pr-cvs1:/tmp/cvs-serv3141/includes
Modified Files:
template.php
Log Message:
Template caching ( file based )
Index: template.php
===================================================================
RCS file: /cvsroot/phpbb/phpBB2/includes/template.php,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** template.php 2 Apr 2002 21:13:47 -0000 1.10
--- template.php 22 Jun 2002 11:48:10 -0000 1.11
***************
*** 1,5 ****
<?php
/***************************************************************************
! * template.php
* -------------------
* begin : Saturday, Feb 13, 2001
--- 1,5 ----
<?php
/***************************************************************************
! * template.inc
* -------------------
* begin : Saturday, Feb 13, 2001
***************
*** 29,33 ****
class Template {
! var $classname = "Template";
// variable that holds all the data we'll be substituting into
--- 29,33 ----
class Template {
! var $classname = 'Template';
// variable that holds all the data we'll be substituting into
***************
*** 44,48 ****
// Root template directory.
! var $root = "";
// this will hash handle names to the compiled code for that handle.
--- 44,48 ----
// Root template directory.
! var $root = '';
// this will hash handle names to the compiled code for that handle.
***************
*** 56,62 ****
*
*/
! function Template($root = ".")
{
$this->set_rootdir($root);
}
--- 56,65 ----
*
*/
! function Template($root = '.')
{
+ global $board_config, $db;
+
$this->set_rootdir($root);
+ $this->db = $db;
}
***************
*** 81,84 ****
--- 84,88 ----
$this->root = $dir;
+ $this->cachedir = $dir . '/cache/';
return true;
}
***************
*** 90,101 ****
function set_filenames($filename_array)
{
! if (!is_array($filename_array))
{
return false;
}
! reset($filename_array);
! while(list($handle, $filename) = each($filename_array))
{
$this->files[$handle] = $this->make_filename($filename);
}
--- 94,107 ----
function set_filenames($filename_array)
{
! if ( !is_array($filename_array) )
{
return false;
}
! $template_names = '';
! @reset($filename_array);
! while ( list($handle, $filename) = @each($filename_array) )
{
+ $this->filename[$handle] = $filename;
$this->files[$handle] = $this->make_filename($filename);
}
***************
*** 112,129 ****
function pparse($handle)
{
! if (!$this->loadfile($handle))
{
! die("Template->pparse(): Couldn't load template file for handle $handle");
! }
! // actually compile the template now.
! if (!isset($this->compiled_code[$handle]) || empty($this->compiled_code[$handle]))
{
// Actually compile the code now.
$this->compiled_code[$handle] = $this->compile($this->uncompiled_code[$handle]);
- }
! // Run the compiled code.
! eval($this->compiled_code[$handle]);
return true;
}
--- 118,155 ----
function pparse($handle)
{
! $cache_file = $this->cachedir . $this->filename[$handle] . '.php';
!
! if( @filemtime($cache_file) == @filemtime($this->files[$handle]) )
{
! $_str = '';
! include($cache_file);
! if ( $_str != '' )
! {
! echo $_str;
! }
! }
! else
{
+ if ( !$this->loadfile($handle) )
+ {
+ die("Template->pparse(): Couldn't load template file for handle $handle");
+ }
+
+ //
// Actually compile the code now.
+ //
$this->compiled_code[$handle] = $this->compile($this->uncompiled_code[$handle]);
! $fp = fopen($cache_file, 'w+');
! fwrite ($fp, '<?php' . "\n" . $this->compiled_code[$handle] . "\n?" . '>');
! fclose($fp);
!
! touch($cache_file, filemtime($this->files[$handle]));
! @chmod($cache_file, 0777);
!
! eval($this->compiled_code[$handle]);
! }
!
return true;
}
***************
*** 139,153 ****
function assign_var_from_handle($varname, $handle)
{
! if (!$this->loadfile($handle))
{
! die("Template->assign_var_from_handle(): Couldn't load template file for handle $handle");
}
! // Compile it, with the "no echo statements" option on.
! $_str = "";
! $code = $this->compile($this->uncompiled_code[$handle], true, '_str');
- // evaluate the variable assignment.
- eval($code);
// assign the value of the generated variable to the given varname.
$this->assign_var($varname, $_str);
--- 165,198 ----
function assign_var_from_handle($varname, $handle)
{
! $cache_file = $this->cachedir . $this->filename[$handle] . '.php';
!
! if( @filemtime($cache_file) == @filemtime($this->files[$handle]) )
{
! $_str = '';
! include($cache_file);
}
+ else
+ {
+ if ( !$this->loadfile($handle) )
+ {
+ die("Template->pparse(): Couldn't load template file for handle $handle");
+ }
+
+ $code = $this->compile($this->uncompiled_code[$handle], true, '_str');
! $fp = fopen($cache_file, 'w+');
! fwrite ($fp, '<?php' . "\n" . $code . "\n?" . '>');
! fclose($fp);
!
! touch($cache_file, filemtime($this->files[$handle]));
! @chmod($cache_file, 0777);
!
! // Compile It, With The "no Echo Statements" Option On.
! $_str = '';
! // evaluate the variable assignment.
! eval($code);
!
! }
// assign the value of the generated variable to the given varname.
$this->assign_var($varname, $_str);
***************
*** 249,273 ****
function loadfile($handle)
{
! // If the file for this handle is already loaded and compiled, do nothing.
! if (isset($this->uncompiled_code[$handle]) && !empty($this->uncompiled_code[$handle]))
{
! return true;
! }
! // If we don't have a file assigned to this handle, die.
! if (!isset($this->files[$handle]))
! {
! die("Template->loadfile(): No file specified for handle $handle");
! }
! $filename = $this->files[$handle];
! $str = implode("", @file($filename));
! if (empty($str))
! {
! die("Template->loadfile(): File $filename for handle $handle is empty");
! }
! $this->uncompiled_code[$handle] = $str;
return true;
--- 294,327 ----
function loadfile($handle)
{
! switch ( $board_config['template_cache'] )
{
! case 1:
! break;
! case 2:
! break;
! default:
! // If the file for this handle is already loaded and compiled, do nothing.
! if ( !empty($this->uncompiled_code[$handle]) )
! {
! return true;
! }
! // If we don't have a file assigned to this handle, die.
! if (!isset($this->files[$handle]))
! {
! die("Template->loadfile(): No file specified for handle $handle");
! }
! $filename = $this->files[$handle];
! $str = implode('', @file($filename));
! if (empty($str))
! {
! die("Template->loadfile(): File $filename for handle $handle is empty");
! }
! $this->uncompiled_code[$handle] = $str;
! break;
! }
return true;
***************
*** 312,316 ****
$block_nesting_level = 0;
$block_names = array();
! $block_names[0] = ".";
// Second: prepend echo ', append ' . "\n"; to each line.
--- 366,370 ----
$block_nesting_level = 0;
$block_names = array();
! $block_names[0] = '.';
// Second: prepend echo ', append ' . "\n"; to each line.
***************
*** 413,418 ****
// Bring it back into a single string of lines of code.
$code = implode("\n", $code_lines);
! return $code ;
!
}
--- 467,471 ----
// Bring it back into a single string of lines of code.
$code = implode("\n", $code_lines);
! return $code;
}
***************
*** 455,459 ****
{
// Get an array of the blocks involved.
! $blocks = explode(".", $blockname);
$blockcount = sizeof($blocks) - 1;
$varref = '$this->_tpldata';
--- 508,512 ----
{
// Get an array of the blocks involved.
! $blocks = explode('.', $blockname);
$blockcount = sizeof($blocks) - 1;
$varref = '$this->_tpldata';
***************
*** 476,478 ****
}
! ?>
--- 529,531 ----
}
! ?>
\ No newline at end of file
|