【php开源代码栏目提醒】:网学会员php开源代码为您提供template_db_cache.php参考,解决您在template_db_cache.php学习中工作中的难题,参考学习。
<?php
/***************************************************************************
* template.inc
* -------------------
* begin : Saturday, Feb 13, 2001
* copyright : (C) 2001 The phpBB Group
* email : support@phpbb.com
*
* $Id: template.php,v 1.7 2002/01/28 19:12:37 psotfx Exp $
*
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
/**
* Template class. By Nathan Codding of the phpBB group.
* The interface was originally inspired by
PHPLib templates,
* and the template file formats are quite similar.
*
*/
class Template {
var $classname = "Template";
// variable that holds all the data we'll be substituting into
// the compiled templates.
// ...
// This will end up being a multi-dimensional array like this:
// $this->_tpldata[block.][iteration#][child.][iteration#][child2.][iteration#][variablename] == value
// if it's a root-level variable, it'll be like this:
// $this->_tpldata[.][0][varname] == value
var $_tpldata = array();
// Hash of filenames for each template handle.
var $files = array();
// Root template directory.
var $root = "";
// this will hash handle names to the compiled code for that handle.
var $compiled_code = array();
// This will hold the uncompiled code for that handle.
var $uncompiled_code = array();
/**
* Constructor. Simply sets the root dir.
*
*/
function Template($root = '.')
{
global $db;
$this->set_rootdir($root);
$this->db = &$db;
$this->pparse_order = array();
}
/**
* Destroys this template object. Should be called when you're done with it, in order
* to clear out the template data so you can load/parse a new template set.
*/
function destroy()
{
$this->_tpldata = array();
}
/**
* Sets the template root directory for this Template object.
*/
function set_rootdir($dir)
{
if (!is_dir($dir))
{
return false;
}
$this->root = $dir;
return true;
}
/**
* Sets the template filenames for handles. $filename_array
* should be a hash of handle => filename pairs.
*/
function set_filenames($filename_array)
{
global $table_prefix;
if ( !is_array($filename_array) )
{
return false;
}
$template_names = '';
@reset($filename_array);
while ( list($handle, $filename) = @each($filename_array) )
{
$this->files[$handle] = $this->make_filename($filename);
$template_names .= ( $template_names != '' ) ? ", '" . addslashes($this->files[$handle]) . "'" : "'" . addslashes($this->files[$handle]) . "'";
}
$sql = "SELECT *
FROM " . $table_prefix . "template_cache
WHERE template_name IN ($template_names)";
if ( $result = $this->db->sql_query($sql) )
{
while( $row = $this->db->sql_fetchrow($result) )
{
if( $row['template_cached'] == filemtime($row['template_name']) )
{
$this->compiled_code[$row['template_handle']] = $row['template_compile'];
$this->echo_compiled[$row['template_handle']] = $row['template_echo'];
}
}
}
$this->db->sql_freeresult();
return true;
}
/**
* Load the file for the handle, compile the file,
* and run the compiled code. This will print out
* the results of executing the template.
*/
function pparse($handle)
{
global $table_prefix;
if( empty($this->compiled_code[$handle]) )
{
if ( !$this->loadfile($handle) )
{
die("Template->pparse(): Couldn't load template file for handle $handle");
}
//
// Actually compile the code now.
//
$this->echo_compiled[$handle] = 1;
$this->compiled_code[$handle] = $this->compile($this->uncompiled_code[$handle]);
$
sql = "REPLACE INTO " . $table_prefix . "template_cache (template_name, template_handle, template_cached, template_compile) VALUES ('" . addslashes($this->files[$handle]) . "', '" . addslashes($handle) . "', " . filemtime($this->files[$handle]) . ", '" . addslashes($this->compiled_code[$handle]) . "')";
if ( !($result = $this->db->sql_query($sql)) )
{
die("Couldn't insert template into cache!");
}
}
$_str = "";
eval($this->compiled_code[$handle]);
if( $_str != "" )
{
echo