Cleaning up code, formatting mostly.

This commit is contained in:
andrey
2001-10-26 14:12:23 +00:00
parent 0554b2b0af
commit e5f8cb1e5a
2 changed files with 570 additions and 568 deletions

View File

@@ -7,7 +7,7 @@
* *
* Version: 1.4.5 * Version: 1.4.5
* Copyright: 2001 ispi of Lincoln, Inc. * Copyright: 2001 ispi of Lincoln, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
@@ -43,37 +43,37 @@
// set SMARTY_DIR to absolute path to Smarty library files. // set SMARTY_DIR to absolute path to Smarty library files.
// if not defined, include_path will be used. // if not defined, include_path will be used.
if(!defined("SMARTY_DIR")) { if (!defined('SMARTY_DIR')) {
define("SMARTY_DIR",""); define('SMARTY_DIR', '');
} }
require_once SMARTY_DIR.'Smarty.addons.php'; require_once SMARTY_DIR.'Smarty.addons.php';
define("SMARTY_PHP_PASSTHRU",0); define('SMARTY_PHP_PASSTHRU', 0);
define("SMARTY_PHP_QUOTE",1); define('SMARTY_PHP_QUOTE', 1);
define("SMARTY_PHP_REMOVE",2); define('SMARTY_PHP_REMOVE', 2);
define("SMARTY_PHP_ALLOW",3); define('SMARTY_PHP_ALLOW', 3);
class Smarty class Smarty
{ {
/**************************************************************************/ /**************************************************************************/
/* BEGIN SMARTY CONFIGURATION SECTION */ /* BEGIN SMARTY CONFIGURATION SECTION */
/* Set the following config variables to your liking. */ /* Set the following config variables to your liking. */
/**************************************************************************/ /**************************************************************************/
// public vars // public vars
var $template_dir = './templates'; // name of directory for templates var $template_dir = './templates'; // name of directory for templates
var $compile_dir = './templates_c'; // name of directory for compiled templates var $compile_dir = './templates_c'; // name of directory for compiled templates
var $config_dir = './configs'; // directory where config files are located var $config_dir = './configs'; // directory where config files are located
var $debugging = false; // enable debugging console true/false var $debugging = false; // enable debugging console true/false
var $debug_tpl = 'file:debug.tpl'; // path to debug console template var $debug_tpl = 'file:debug.tpl'; // path to debug console template
var $debugging_ctrl = 'NONE'; // Possible values: var $debugging_ctrl = 'NONE'; // Possible values:
// NONE - no debug control allowed // NONE - no debug control allowed
// URL - enable debugging when keyword // URL - enable debugging when keyword
// SMARTY_DEBUG is found in $QUERY_STRING // SMARTY_DEBUG is found in $QUERY_STRING
var $global_assign = array( 'HTTP_SERVER_VARS' => array( 'SCRIPT_NAME' ) var $global_assign = array( 'HTTP_SERVER_VARS' => array( 'SCRIPT_NAME' )
); // variables from the GLOBALS array ); // variables from the GLOBALS array
// that are implicitly assigned // that are implicitly assigned
@@ -112,8 +112,8 @@ class Smarty
// SMARTY_PHP_REMOVE -> remove php tags // SMARTY_PHP_REMOVE -> remove php tags
// SMARTY_PHP_ALLOW -> execute php tags // SMARTY_PHP_ALLOW -> execute php tags
// default: SMARTY_PHP_PASSTHRU // default: SMARTY_PHP_PASSTHRU
var $security = false; // enable template security (default false) var $security = false; // enable template security (default false)
var $secure_dir = array('./templates'); // array of directories considered secure var $secure_dir = array('./templates'); // array of directories considered secure
var $secure_ext = array('.tpl'); // array of file extentions considered secure var $secure_ext = array('.tpl'); // array of file extentions considered secure
@@ -130,7 +130,7 @@ class Smarty
var $left_delimiter = '{'; // template tag delimiters. var $left_delimiter = '{'; // template tag delimiters.
var $right_delimiter = '}'; var $right_delimiter = '}';
var $compiler_funcs = array( var $compiler_funcs = array(
); );
@@ -141,11 +141,11 @@ class Smarty
'fetch' => 'smarty_func_fetch', 'fetch' => 'smarty_func_fetch',
'counter' => 'smarty_func_counter', 'counter' => 'smarty_func_counter',
'assign' => 'smarty_func_assign', 'assign' => 'smarty_func_assign',
'popup_init' => 'smarty_func_overlib_init', 'popup_init' => 'smarty_func_overlib_init',
'popup' => 'smarty_func_overlib', 'popup' => 'smarty_func_overlib',
'assign_debug_info' => 'smarty_func_assign_debug_info' 'assign_debug_info' => 'smarty_func_assign_debug_info'
); );
var $custom_mods = array( 'lower' => 'strtolower', var $custom_mods = array( 'lower' => 'strtolower',
'upper' => 'strtoupper', 'upper' => 'strtoupper',
'capitalize' => 'ucwords', 'capitalize' => 'ucwords',
@@ -163,7 +163,7 @@ class Smarty
'count_sentences' => 'smarty_mod_count_sentences', 'count_sentences' => 'smarty_mod_count_sentences',
'count_paragraphs' => 'smarty_mod_count_paragraphs' 'count_paragraphs' => 'smarty_mod_count_paragraphs'
); );
var $show_info_header = false; // display HTML info header at top of page output var $show_info_header = false; // display HTML info header at top of page output
var $show_info_include = false; // display HTML comments at top & bottom of var $show_info_include = false; // display HTML comments at top & bottom of
// each included template // each included template
@@ -181,32 +181,32 @@ class Smarty
// in php.ini // in php.ini
/**************************************************************************/ /**************************************************************************/
/* END SMARTY CONFIGURATION SECTION */ /* END SMARTY CONFIGURATION SECTION */
/* There should be no need to touch anything below this line. */ /* There should be no need to touch anything below this line. */
/**************************************************************************/ /**************************************************************************/
// internal vars // internal vars
var $_error_msg = false; // error messages. true/false var $_error_msg = false; // error messages. true/false
var $_tpl_vars = array(); // where assigned template vars are kept var $_tpl_vars = array(); // where assigned template vars are kept
var $_sections = array(); // keeps track of sections var $_sections = array(); // keeps track of sections
var $_conf_obj = null; // configuration object var $_conf_obj = null; // configuration object
var $_config = array(); // loaded configuration settings var $_config = array(); // loaded configuration settings
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty' var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
var $_version = '1.4.5'; // Smarty version number var $_version = '1.4.5'; // Smarty version number
var $_extract = false; // flag for custom functions var $_extract = false; // flag for custom functions
var $_inclusion_depth = 0; // current template inclusion depth var $_inclusion_depth = 0; // current template inclusion depth
var $_compile_id = null; // for different compiled templates var $_compile_id = null; // for different compiled templates
var $_smarty_debug_id = 'SMARTY_DEBUG'; // text in URL to enable debug mode var $_smarty_debug_id = 'SMARTY_DEBUG'; // text in URL to enable debug mode
var $_smarty_debug_info = array(); // debugging information for debug console var $_smarty_debug_info = array(); // debugging information for debug console
var $_cache_info = array(); // info that makes up a cache file var $_cache_info = array(); // info that makes up a cache file
/*======================================================================*\ /*======================================================================*\
Function: Smarty Function: Smarty
Purpose: Constructor Purpose: Constructor
\*======================================================================*/ \*======================================================================*/
function Smarty() function Smarty()
{ {
foreach ($this->global_assign as $key => $var_name) { foreach ($this->global_assign as $key => $var_name) {
if (is_array($var_name)) { if (is_array($var_name)) {
foreach ($var_name as $var) { foreach ($var_name as $var) {
@@ -245,7 +245,7 @@ class Smarty
$this->_extract = true; $this->_extract = true;
} }
/*======================================================================*\ /*======================================================================*\
Function: append Function: append
Purpose: appens values to template variables Purpose: appens values to template variables
@@ -284,7 +284,7 @@ class Smarty
unset($this->_tpl_vars[$tpl_var]); unset($this->_tpl_vars[$tpl_var]);
} }
/*======================================================================*\ /*======================================================================*\
Function: register_function Function: register_function
Purpose: Registers custom function to be used in templates Purpose: Registers custom function to be used in templates
@@ -320,7 +320,7 @@ class Smarty
{ {
unset($this->compiler_funcs[$function]); unset($this->compiler_funcs[$function]);
} }
/*======================================================================*\ /*======================================================================*\
Function: register_modifier Function: register_modifier
Purpose: Registers modifier to be used in templates Purpose: Registers modifier to be used in templates
@@ -381,7 +381,7 @@ class Smarty
} }
$this->prefilter_funcs = $tmp_array; $this->prefilter_funcs = $tmp_array;
} }
/*======================================================================*\ /*======================================================================*\
Function: register_postfilter Function: register_postfilter
Purpose: Registers a postfilter function to apply Purpose: Registers a postfilter function to apply
@@ -406,7 +406,7 @@ class Smarty
} }
$this->postfilter_funcs = $tmp_array; $this->postfilter_funcs = $tmp_array;
} }
/*======================================================================*\ /*======================================================================*\
Function: clear_cache() Function: clear_cache()
Purpose: clear cached content for the given template and cache id Purpose: clear cached content for the given template and cache id
@@ -415,8 +415,8 @@ class Smarty
{ {
return $this->_rm_auto($this->cache_dir, $tpl_file, $compile_id . $cache_id); return $this->_rm_auto($this->cache_dir, $tpl_file, $compile_id . $cache_id);
} }
/*======================================================================*\ /*======================================================================*\
Function: clear_all_cache() Function: clear_all_cache()
Purpose: clear the entire contents of cache (all templates) Purpose: clear the entire contents of cache (all templates)
@@ -436,7 +436,7 @@ class Smarty
if (!$this->caching) if (!$this->caching)
return false; return false;
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id); $cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
if (file_exists($cache_file) && if (file_exists($cache_file) &&
($this->cache_lifetime == 0 || ($this->cache_lifetime == 0 ||
@@ -444,10 +444,10 @@ class Smarty
return true; return true;
else else
return false; return false;
} }
/*======================================================================*\ /*======================================================================*\
Function: clear_all_assign() Function: clear_all_assign()
Purpose: clear all the assigned template variables. Purpose: clear all the assigned template variables.
@@ -486,7 +486,7 @@ class Smarty
{ {
$this->fetch($tpl_file, $cache_id, $compile_id, true); $this->fetch($tpl_file, $cache_id, $compile_id, true);
} }
/*======================================================================*\ /*======================================================================*\
Function: fetch() Function: fetch()
Purpose: executes & returns or displays the template results Purpose: executes & returns or displays the template results
@@ -496,53 +496,51 @@ class Smarty
global $HTTP_SERVER_VARS, $QUERY_STRING, $HTTP_COOKIE_VARS; global $HTTP_SERVER_VARS, $QUERY_STRING, $HTTP_COOKIE_VARS;
if ($this->debugging_ctrl == 'URL' if ($this->debugging_ctrl == 'URL'
&& (!empty($QUERY_STRING) && (!empty($QUERY_STRING) && strstr($QUERY_STRING,$this->_smarty_debug_id))) {
&& strstr($QUERY_STRING,$this->_smarty_debug_id))) { $this->debugging = true;
$this->debugging = true; }
}
if($this->debugging) {
if($this->debugging) // capture time for debugging info
{ $debug_start_time = $this->_get_microtime();
// capture time for debugging info $this->_smarty_debug_info[] = array('type' => 'template',
$debug_start_time = $this->_get_microtime(); 'filename' => $tpl_file,
$this->_smarty_debug_info[] = array('type' => 'template', 'depth' => 0);
'filename' => $tpl_file, $included_tpls_idx = count($this->_smarty_debug_info) - 1;
'depth' => 0); }
$included_tpls_idx = count($this->_smarty_debug_info) - 1;
} $this->_compile_id = $compile_id;
$this->_compile_id = $compile_id;
$this->_inclusion_depth = 0; $this->_inclusion_depth = 0;
if ($this->caching) { if ($this->caching) {
$this->_cache_info[] = array('template',$tpl_file); $this->_cache_info[] = array('template', $tpl_file);
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id); $cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
if (file_exists($cache_file) && if (file_exists($cache_file) &&
($this->cache_lifetime == 0 || ($this->cache_lifetime == 0 ||
(time() - filemtime($cache_file) <= $this->cache_lifetime))) { (time() - filemtime($cache_file) <= $this->cache_lifetime))) {
if($this->_read_cache_file($cache_file,$results)) {
if ($this->insert_tag_check) {
$results = $this->_process_cached_inserts($results);
}
if ($display) {
echo $results;
if ($this->debugging)
{
// capture time for debugging info
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
echo $this->_generate_debug_output(); if($this->_read_cache_file($cache_file,$results)) {
} if ($this->insert_tag_check) {
return; $results = $this->_process_cached_inserts($results);
} else { }
return $results; if ($display) {
} echo $results;
} if ($this->debugging)
{
// capture time for debugging info
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
echo $this->_generate_debug_output();
}
return;
} else {
return $results;
}
}
} }
} }
@@ -565,38 +563,38 @@ class Smarty
if ($this->show_info_header) { if ($this->show_info_header) {
$info_header = '<!-- Smarty '.$this->_version.' '.strftime("%Y-%m-%d %H:%M:%S %Z").' -->'."\n\n"; $info_header = '<!-- Smarty '.$this->_version.' '.strftime("%Y-%m-%d %H:%M:%S %Z").' -->'."\n\n";
} else { } else {
$info_header = ''; $info_header = '';
} }
$compile_path = $this->_get_compile_path($tpl_file); $compile_path = $this->_get_compile_path($tpl_file);
// if we just need to display the results, don't perform output // if we just need to display the results, don't perform output
// buffering - for speed // buffering - for speed
if ($display && !$this->caching) { if ($display && !$this->caching) {
echo $info_header; echo $info_header;
if($this->_process_template($tpl_file, $compile_path)) if ($this->_process_template($tpl_file, $compile_path))
{ {
if ($this->show_info_include) { if ($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n"; echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n";
} }
include($compile_path); include($compile_path);
if ($this->show_info_include) { if ($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n"; echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n";
} }
} }
} else { } else {
ob_start(); ob_start();
echo $info_header; echo $info_header;
if($this->_process_template($tpl_file, $compile_path)) if ($this->_process_template($tpl_file, $compile_path))
{ {
if ($this->show_info_include) { if ($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n"; echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n";
} }
include($compile_path); include($compile_path);
if ($this->show_info_include) { if ($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n"; echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n";
} }
} }
$results = ob_get_contents(); $results = ob_get_contents();
ob_end_clean(); ob_end_clean();
} }
@@ -605,29 +603,29 @@ class Smarty
$this->_write_cache_file($cache_file, $results); $this->_write_cache_file($cache_file, $results);
$results = $this->_process_cached_inserts($results); $results = $this->_process_cached_inserts($results);
} }
if ($display) { if ($display) {
if (isset($results)) { echo $results; } if (isset($results)) { echo $results; }
if ($this->debugging) if ($this->debugging)
{ {
// capture time for debugging info // capture time for debugging info
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = ($this->_get_microtime() - $debug_start_time); $this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = ($this->_get_microtime() - $debug_start_time);
echo $this->_generate_debug_output(); echo $this->_generate_debug_output();
} }
return; return;
} else { } else {
if (isset($results)) { return $results; } if (isset($results)) { return $results; }
} }
} }
/*======================================================================*\ /*======================================================================*\
Function: _assign_smarty_interface Function: _assign_smarty_interface
Purpose: assign $smarty interface variable Purpose: assign $smarty interface variable
\*======================================================================*/ \*======================================================================*/
function _assign_smarty_interface() function _assign_smarty_interface()
{ {
$egpcs = array('e' => 'env', $egpcs = array('e' => 'env',
'g' => 'get', 'g' => 'get',
'p' => 'post', 'p' => 'post',
@@ -653,8 +651,8 @@ class Smarty
} }
$smarty['request'] = array_merge($smarty['request'], $smarty['session']); $smarty['request'] = array_merge($smarty['request'], $smarty['session']);
$smarty['now'] = time(); $smarty['now'] = time();
$this->assign('smarty', $smarty); $this->assign('smarty', $smarty);
} }
@@ -665,31 +663,31 @@ class Smarty
\*======================================================================*/ \*======================================================================*/
function _generate_debug_output() { function _generate_debug_output() {
// we must force compile the debug template in case the environment // we must force compile the debug template in case the environment
// changed between separate applications. // changed between separate applications.
ob_start(); ob_start();
$force_compile_orig = $this->force_compile; $force_compile_orig = $this->force_compile;
$this->force_compile = true; $this->force_compile = true;
$compile_path = $this->_get_compile_path($tpl_file); $compile_path = $this->_get_compile_path($tpl_file);
if($this->_process_template($this->debug_tpl, $compile_path)) if ($this->_process_template($this->debug_tpl, $compile_path))
{ {
if ($this->show_info_include) { if ($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$this->debug_tpl." -->\n"; echo "\n<!-- SMARTY_BEGIN: ".$this->debug_tpl." -->\n";
} }
include($compile_path); include($compile_path);
if ($this->show_info_include) { if ($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$this->debug_tpl." -->\n"; echo "\n<!-- SMARTY_END: ".$this->debug_tpl." -->\n";
} }
} }
$results = ob_get_contents(); $results = ob_get_contents();
$this->force_compile = $force_compile_orig; $this->force_compile = $force_compile_orig;
ob_end_clean(); ob_end_clean();
return $results; return $results;
} }
/*======================================================================*\ /*======================================================================*\
Function: _process_template() Function: _process_template()
Purpose: Purpose:
\*======================================================================*/ \*======================================================================*/
function _process_template($tpl_file, $compile_path) function _process_template($tpl_file, $compile_path)
{ {
@@ -698,11 +696,12 @@ function _generate_debug_output() {
if (!$this->compile_check) { if (!$this->compile_check) {
// no need to check if the template needs recompiled // no need to check if the template needs recompiled
return true; return true;
} else { } else {
// get template source and timestamp // get template source and timestamp
if(!$this->_fetch_template_info($tpl_file, $template_source, $template_timestamp)) { if (!$this->_fetch_template_info($tpl_file, $template_source,
return false; $template_timestamp)) {
} return false;
}
if ($template_timestamp <= $this->_fetch_compiled_template_timestamp($compile_path)) { if ($template_timestamp <= $this->_fetch_compiled_template_timestamp($compile_path)) {
// template not expired, no recompile // template not expired, no recompile
return true; return true;
@@ -715,9 +714,10 @@ function _generate_debug_output() {
} }
} else { } else {
// compiled template does not exist, or forced compile // compiled template does not exist, or forced compile
if(!$this->_fetch_template_info($tpl_file, $template_source, $template_timestamp)) { if (!$this->_fetch_template_info($tpl_file, $template_source,
return false; $template_timestamp)) {
} return false;
}
$this->_compile_template($tpl_file, $template_source, $template_compiled); $this->_compile_template($tpl_file, $template_source, $template_compiled);
$this->_write_compiled_template($compile_path, $template_compiled); $this->_write_compiled_template($compile_path, $template_compiled);
return true; return true;
@@ -730,77 +730,78 @@ function _generate_debug_output() {
\*======================================================================*/ \*======================================================================*/
function _get_compile_path($tpl_file) function _get_compile_path($tpl_file)
{ {
return $this->_get_auto_filename($this->compile_dir, $tpl_file, $this->_compile_id); return $this->_get_auto_filename($this->compile_dir, $tpl_file,
} $this->_compile_id);
}
/*======================================================================*\ /*======================================================================*\
Function: _compiled_template_exists Function: _compiled_template_exists
Purpose: Purpose:
\*======================================================================*/ \*======================================================================*/
function _compiled_template_exists($include_path) function _compiled_template_exists($include_path)
{ {
// everything is in $compile_dir // everything is in $compile_dir
return file_exists($include_path); return file_exists($include_path);
} }
/*======================================================================*\ /*======================================================================*\
Function: _fetch_compiled_template_timestamp Function: _fetch_compiled_template_timestamp
Purpose: Purpose:
\*======================================================================*/ \*======================================================================*/
function _fetch_compiled_template_timestamp($include_path) function _fetch_compiled_template_timestamp($include_path)
{ {
// everything is in $compile_dir // everything is in $compile_dir
return filemtime($include_path); return filemtime($include_path);
} }
/*======================================================================*\ /*======================================================================*\
Function: _write_compiled_template Function: _write_compiled_template
Purpose: Purpose:
\*======================================================================*/ \*======================================================================*/
function _write_compiled_template($compile_path, $template_compiled) function _write_compiled_template($compile_path, $template_compiled)
{ {
// we save everything into $compile_dir // we save everything into $compile_dir
$this->_write_file($compile_path, $template_compiled, true); $this->_write_file($compile_path, $template_compiled, true);
return true; return true;
} }
/*======================================================================*\ /*======================================================================*\
Function: _fetch_template_info() Function: _fetch_template_info()
Purpose: fetch the template info. Gets timestamp, and source Purpose: fetch the template info. Gets timestamp, and source
if get_source is true if get_source is true
\*======================================================================*/ \*======================================================================*/
function _fetch_template_info($tpl_path, &$template_source, &$template_timestamp, $get_source=true) function _fetch_template_info($tpl_path, &$template_source, &$template_timestamp, $get_source=true)
{ {
// split tpl_path by the first colon // split tpl_path by the first colon
$tpl_path_parts = explode(':', $tpl_path, 2); $tpl_path_parts = explode(':', $tpl_path, 2);
if (count($tpl_path_parts) == 1) { if (count($tpl_path_parts) == 1) {
// no resource type, treat as type "file" // no resource type, treat as type "file"
$resource_type = 'file'; $resource_type = 'file';
$resource_name = $tpl_path_parts[0]; $resource_name = $tpl_path_parts[0];
} else { } else {
$resource_type = $tpl_path_parts[0]; $resource_type = $tpl_path_parts[0];
$resource_name = $tpl_path_parts[1]; $resource_name = $tpl_path_parts[1];
} }
switch ($resource_type) { switch ($resource_type) {
case 'file': case 'file':
if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/",$resource_name)) { if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/",$resource_name)) {
// relative pathname to $template_dir // relative pathname to $template_dir
$resource_name = $this->template_dir.'/'.$resource_name; $resource_name = $this->template_dir.'/'.$resource_name;
} }
if (file_exists($resource_name) && is_readable($resource_name)) { if (file_exists($resource_name) && is_readable($resource_name)) {
if($get_source) { if($get_source) {
$template_source = $this->_read_file($resource_name); $template_source = $this->_read_file($resource_name);
} }
$template_timestamp = filemtime($resource_name); $template_timestamp = filemtime($resource_name);
} else { } else {
$this->_trigger_error_msg("unable to read template resource: \"$tpl_path\""); $this->_trigger_error_msg("unable to read template resource: \"$tpl_path\"");
return false; return false;
} }
// if security is on, make sure template comes from a $secure_dir // if security is on, make sure template comes from a $secure_dir
if ($this->security && !$this->security_settings['INCLUDE_ANY']) { if ($this->security && !$this->security_settings['INCLUDE_ANY']) {
$resource_is_secure = false; $resource_is_secure = false;
foreach ($this->secure_dir as $curr_dir) { foreach ($this->secure_dir as $curr_dir) {
@@ -812,7 +813,7 @@ function _generate_debug_output() {
if (!$resource_is_secure) { if (!$resource_is_secure) {
$this->_trigger_error_msg("(secure mode) including \"$resource_name\" is not allowed"); $this->_trigger_error_msg("(secure mode) including \"$resource_name\" is not allowed");
return false; return false;
} }
} }
break; break;
default: default:
@@ -836,7 +837,7 @@ function _generate_debug_output() {
return true; return true;
} }
/*======================================================================*\ /*======================================================================*\
Function: _compile_template() Function: _compile_template()
Purpose: called to compile the templates Purpose: called to compile the templates
@@ -880,13 +881,13 @@ function _generate_debug_output() {
\*======================================================================*/ \*======================================================================*/
function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars) function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars)
{ {
if($this->debugging) { if($this->debugging) {
$debug_start_time = $this->_get_microtime(); $debug_start_time = $this->_get_microtime();
$this->_smarty_debug_info[] = array('type' => 'template', $this->_smarty_debug_info[] = array('type' => 'template',
'filename' => $_smarty_include_tpl_file, 'filename' => $_smarty_include_tpl_file,
'depth' => ++$this->_inclusion_depth); 'depth' => ++$this->_inclusion_depth);
$included_tpls_idx = count($this->_smarty_debug_info) - 1; $included_tpls_idx = count($this->_smarty_debug_info) - 1;
} }
$this->_tpl_vars = array_merge($this->_tpl_vars, $_smarty_include_vars); $this->_tpl_vars = array_merge($this->_tpl_vars, $_smarty_include_vars);
extract($this->_tpl_vars); extract($this->_tpl_vars);
@@ -907,33 +908,32 @@ function _generate_debug_output() {
array_shift($this->_config); array_shift($this->_config);
$this->_inclusion_depth--; $this->_inclusion_depth--;
if ($this->debugging) { if ($this->debugging) {
// capture time for debugging info // capture time for debugging info
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time; $this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
} }
if ($this->caching) { if ($this->caching) {
$this->_cache_info[] = array('template',$_smarty_include_tpl_file); $this->_cache_info[] = array('template', $_smarty_include_tpl_file);
} }
} }
/*======================================================================*\ /*======================================================================*\
Function: _config_load Function: _config_load
Purpose: load configuration values Purpose: load configuration values
\*======================================================================*/ \*======================================================================*/
function _config_load($file, $section, $scope) function _config_load($file, $section, $scope)
{ {
if($this->debugging) { if($this->debugging) {
$debug_start_time = $this->_get_microtime(); $debug_start_time = $this->_get_microtime();
} }
if ($this->caching) { if ($this->caching) {
$this->_cache_info[] = array('config',$file); $this->_cache_info[] = array('config', $file);
} }
$this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file)); $this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file));
if ($scope == 'parent') { if ($scope == 'parent') {
if (count($this->_config) > 0) if (count($this->_config) > 0)
@@ -951,13 +951,13 @@ function _generate_debug_output() {
for ($i = 1; $i < count($this->_config); $i++) for ($i = 1; $i < count($this->_config); $i++)
$this->_config[$i] = array_merge($this->_config[$i], $this->_conf_obj->get($file, $section)); $this->_config[$i] = array_merge($this->_config[$i], $this->_conf_obj->get($file, $section));
} }
if($this->debugging) { if($this->debugging) {
$debug_start_time = $this->_get_microtime(); $debug_start_time = $this->_get_microtime();
$this->_smarty_debug_info[] = array('type' => 'config', $this->_smarty_debug_info[] = array('type' => 'config',
'filename' => $file.' ['.$section.'] '.$scope, 'filename' => $file.' ['.$section.'] '.$scope,
'depth' => $this->_inclusion_depth, 'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time); 'exec_time' => $this->_get_microtime() - $debug_start_time);
} }
} }
@@ -967,10 +967,10 @@ function _generate_debug_output() {
\*======================================================================*/ \*======================================================================*/
function _process_cached_inserts($results) function _process_cached_inserts($results)
{ {
if($this->debugging) { if($this->debugging) {
$debug_start_time = $this->_get_microtime(); $debug_start_time = $this->_get_microtime();
} }
preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'!Uis', preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'!Uis',
$results, $match); $results, $match);
list($cached_inserts, $insert_args) = $match; list($cached_inserts, $insert_args) = $match;
@@ -986,17 +986,16 @@ function _generate_debug_output() {
$replace = $function_name($args, $this); $replace = $function_name($args, $this);
$results = str_replace($cached_inserts[$i], $replace, $results); $results = str_replace($cached_inserts[$i], $replace, $results);
if ($this->debugging) { if ($this->debugging) {
$this->_smarty_debug_info[] = array('type' => 'insert', $this->_smarty_debug_info[] = array('type' => 'insert',
'filename' => 'insert_'.$name, 'filename' => 'insert_'.$name,
'depth' => $this->_inclusion_depth, 'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time); 'exec_time' => $this->_get_microtime() - $debug_start_time);
} }
} }
return $results; return $results;
} }
/*======================================================================*\ /*======================================================================*\
@@ -1005,9 +1004,9 @@ function _generate_debug_output() {
\*======================================================================*/ \*======================================================================*/
function _run_insert_handler($args) function _run_insert_handler($args)
{ {
if($this->debugging) { if($this->debugging) {
$debug_start_time = $this->_get_microtime(); $debug_start_time = $this->_get_microtime();
} }
if ($this->caching) { if ($this->caching) {
$arg_string = serialize($args); $arg_string = serialize($args);
@@ -1016,12 +1015,12 @@ function _run_insert_handler($args)
$function_name = 'insert_'.$args['name']; $function_name = 'insert_'.$args['name'];
$content = $function_name($args, $this); $content = $function_name($args, $this);
if ($this->debugging) { if ($this->debugging) {
$this->_smarty_debug_info[] = array('type' => 'insert', $this->_smarty_debug_info[] = array('type' => 'insert',
'filename' => 'insert_'.$args['name'], 'filename' => 'insert_'.$args['name'],
'depth' => $this->_inclusion_depth, 'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time); 'exec_time' => $this->_get_microtime() - $debug_start_time);
} }
return $content; return $content;
} }
} }
@@ -1047,7 +1046,7 @@ function _run_mod_handler()
} }
} }
/*======================================================================*\ /*======================================================================*\
Function: _dequote Function: _dequote
Purpose: Remove starting and ending quotes from the string Purpose: Remove starting and ending quotes from the string
@@ -1061,7 +1060,7 @@ function _run_mod_handler()
return $string; return $string;
} }
/*======================================================================*\ /*======================================================================*\
Function: _read_file() Function: _read_file()
Purpose: read in a file Purpose: read in a file
@@ -1087,23 +1086,23 @@ function _run_mod_handler()
{ {
if ($create_dirs) if ($create_dirs)
$this->_create_dir_structure(dirname($filename)); $this->_create_dir_structure(dirname($filename));
if (!($fd = fopen($filename, 'w'))) { if (!($fd = fopen($filename, 'w'))) {
$this->_trigger_error_msg("problem writing '$filename.'"); $this->_trigger_error_msg("problem writing '$filename.'");
return false; return false;
} }
// flock doesn't seem to work on several windows platforms (98, NT4, NT5, ?), // flock doesn't seem to work on several windows platforms (98, NT4, NT5, ?),
// so we'll not use it at all in windows. // so we'll not use it at all in windows.
if ( strtoupper(substr(PHP_OS,0,3)) == 'WIN' || (flock($fd, LOCK_EX)) ) { if ( strtoupper(substr(PHP_OS,0,3)) == 'WIN' || (flock($fd, LOCK_EX)) ) {
fwrite( $fd, $contents ); fwrite( $fd, $contents );
fclose($fd); fclose($fd);
chmod($filename,0644); chmod($filename,0644);
} }
return true; return true;
} }
/*======================================================================*\ /*======================================================================*\
Function: _get_auto_base Function: _get_auto_base
@@ -1120,7 +1119,7 @@ function _run_mod_handler()
/*======================================================================*\ /*======================================================================*\
Function: _get_auto_filename Function: _get_auto_filename
Purpose: get a concrete filename for automagically created content Purpose: get a concrete filename for automagically created content
\*======================================================================*/ \*======================================================================*/
function _get_auto_filename($auto_base, $auto_source, $auto_id = null) function _get_auto_filename($auto_base, $auto_source, $auto_id = null)
{ {
@@ -1132,7 +1131,7 @@ function _run_mod_handler()
/*======================================================================*\ /*======================================================================*\
Function: _rm_auto Function: _rm_auto
Purpose: delete an automagically created file by name and id Purpose: delete an automagically created file by name and id
\*======================================================================*/ \*======================================================================*/
function _rm_auto($auto_base, $auto_source = null, $auto_id = null) function _rm_auto($auto_base, $auto_source = null, $auto_id = null)
{ {
@@ -1161,18 +1160,18 @@ function _run_mod_handler()
\*======================================================================*/ \*======================================================================*/
function _rmdir($dirname, $level = 1) function _rmdir($dirname, $level = 1)
{ {
$handle = opendir($dirname); $handle = opendir($dirname);
while ($entry = readdir($handle)) { while ($entry = readdir($handle)) {
if ($entry != '.' && $entry != '..') { if ($entry != '.' && $entry != '..') {
if (is_dir($dirname . '/' . $entry)) { if (is_dir($dirname . '/' . $entry)) {
$this->_rmdir($dirname . '/' . $entry, $level + 1); $this->_rmdir($dirname . '/' . $entry, $level + 1);
} }
else { else {
unlink($dirname . '/' . $entry); unlink($dirname . '/' . $entry);
} }
} }
} }
closedir($handle); closedir($handle);
@@ -1195,70 +1194,72 @@ function _run_mod_handler()
$new_dir .= $dir_part; $new_dir .= $dir_part;
if (!file_exists($new_dir) && !mkdir($new_dir, 0701)) { if (!file_exists($new_dir) && !mkdir($new_dir, 0701)) {
$this->_trigger_error_msg("problem creating directory \"$dir\""); $this->_trigger_error_msg("problem creating directory \"$dir\"");
return false; return false;
} }
$new_dir .= '/'; $new_dir .= '/';
} }
} }
} }
/*======================================================================*\ /*======================================================================*\
Function: _write_cache_file Function: _write_cache_file
Purpose: Prepend the cache information to the cache file Purpose: Prepend the cache information to the cache file
and write it to disk and write it to disk
\*======================================================================*/ \*======================================================================*/
function _write_cache_file($cache_file,$results) function _write_cache_file($cache_file,$results)
{ {
// put the templates involved with this cache in the first line // put the templates involved with this cache in the first line
$cache_info = "SMARTY_CACHE_INFO_HEADER".serialize($this->_cache_info)."\n"; $cache_info = 'SMARTY_CACHE_INFO_HEADER'.serialize($this->_cache_info)."\n";
$this->_write_file($cache_file, $cache_info.$results, true); $this->_write_file($cache_file, $cache_info.$results, true);
return true; return true;
} }
/*======================================================================*\ /*======================================================================*\
Function: _read_cache_file Function: _read_cache_file
Purpose: See if any of the templates for this cache file Purpose: See if any of the templates for this cache file
have changed or not since the cache was created. have changed or not since the cache was created.
Remove the cache info from the cache results. Remove the cache info from the cache results.
\*======================================================================*/ \*======================================================================*/
function _read_cache_file($cache_file,&$results) function _read_cache_file($cache_file,&$results)
{ {
$results = $this->_read_file($cache_file); $results = $this->_read_file($cache_file);
// get the templates involved with this cache from the first line
$contents = split("\n",$results,2);
if(substr($contents[0],0,24) == 'SMARTY_CACHE_INFO_HEADER') {
$cache_info = unserialize(substr($contents[0],24));
$results = $contents[1];
if($this->compile_check) { // get the templates involved with this cache from the first line
$cache_filemtime = filemtime($cache_file); $contents = explode("\n", $results, 2);
foreach($cache_info as $curr_cache_info) { if (substr($contents[0], 0, 24) == 'SMARTY_CACHE_INFO_HEADER') {
switch ($curr_cache_info[0]) { $cache_info = unserialize(substr($contents[0], 24));
case 'template': $results = $contents[1];
$this->_fetch_template_info($curr_cache_info[1], $template_source, $template_timestamp, false);
if( $cache_filemtime < $template_timestamp) { if ($this->compile_check) {
// template file has changed, regenerate cache $cache_filemtime = filemtime($cache_file);
return false;
} foreach ($cache_info as $curr_cache_info) {
break; switch ($curr_cache_info[0]) {
case 'config': case 'template':
if( $cache_filemtime < filemtime($this->config_dir.'/'.$curr_cache_info[1])) { $this->_fetch_template_info($curr_cache_info[1], $template_source, $template_timestamp, false);
// config file file has changed, regenerate cache if($cache_filemtime < $template_timestamp) {
return false; // template file has changed, regenerate cache
} return false;
break; }
} break;
}
} case 'config':
} if ($cache_filemtime < filemtime($this->config_dir.'/'.$curr_cache_info[1])) {
return true; // config file file has changed, regenerate cache
return false;
}
break;
}
}
}
}
return true;
} }
/*======================================================================*\ /*======================================================================*\
Function: quote_replace Function: quote_replace
Purpose: Quote subpattern references Purpose: Quote subpattern references
@@ -1279,16 +1280,16 @@ function _run_mod_handler()
} }
/*======================================================================*\ /*======================================================================*\
Function: _get_microtime Function: _get_microtime
Purpose: Get seconds and microseconds Purpose: Get seconds and microseconds
\*======================================================================*/ \*======================================================================*/
function _get_microtime() function _get_microtime()
{ {
$mtime = microtime(); $mtime = microtime();
$mtime = explode(" ", $mtime); $mtime = explode(" ", $mtime);
$mtime = (double)($mtime[1]) + (double)($mtime[0]); $mtime = (double)($mtime[1]) + (double)($mtime[0]);
return ($mtime); return ($mtime);
} }
} }

View File

@@ -7,7 +7,7 @@
* *
* Version: 1.4.5 * Version: 1.4.5
* Copyright: 2001 ispi of Lincoln, Inc. * Copyright: 2001 ispi of Lincoln, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
@@ -43,37 +43,37 @@
// set SMARTY_DIR to absolute path to Smarty library files. // set SMARTY_DIR to absolute path to Smarty library files.
// if not defined, include_path will be used. // if not defined, include_path will be used.
if(!defined("SMARTY_DIR")) { if (!defined('SMARTY_DIR')) {
define("SMARTY_DIR",""); define('SMARTY_DIR', '');
} }
require_once SMARTY_DIR.'Smarty.addons.php'; require_once SMARTY_DIR.'Smarty.addons.php';
define("SMARTY_PHP_PASSTHRU",0); define('SMARTY_PHP_PASSTHRU', 0);
define("SMARTY_PHP_QUOTE",1); define('SMARTY_PHP_QUOTE', 1);
define("SMARTY_PHP_REMOVE",2); define('SMARTY_PHP_REMOVE', 2);
define("SMARTY_PHP_ALLOW",3); define('SMARTY_PHP_ALLOW', 3);
class Smarty class Smarty
{ {
/**************************************************************************/ /**************************************************************************/
/* BEGIN SMARTY CONFIGURATION SECTION */ /* BEGIN SMARTY CONFIGURATION SECTION */
/* Set the following config variables to your liking. */ /* Set the following config variables to your liking. */
/**************************************************************************/ /**************************************************************************/
// public vars // public vars
var $template_dir = './templates'; // name of directory for templates var $template_dir = './templates'; // name of directory for templates
var $compile_dir = './templates_c'; // name of directory for compiled templates var $compile_dir = './templates_c'; // name of directory for compiled templates
var $config_dir = './configs'; // directory where config files are located var $config_dir = './configs'; // directory where config files are located
var $debugging = false; // enable debugging console true/false var $debugging = false; // enable debugging console true/false
var $debug_tpl = 'file:debug.tpl'; // path to debug console template var $debug_tpl = 'file:debug.tpl'; // path to debug console template
var $debugging_ctrl = 'NONE'; // Possible values: var $debugging_ctrl = 'NONE'; // Possible values:
// NONE - no debug control allowed // NONE - no debug control allowed
// URL - enable debugging when keyword // URL - enable debugging when keyword
// SMARTY_DEBUG is found in $QUERY_STRING // SMARTY_DEBUG is found in $QUERY_STRING
var $global_assign = array( 'HTTP_SERVER_VARS' => array( 'SCRIPT_NAME' ) var $global_assign = array( 'HTTP_SERVER_VARS' => array( 'SCRIPT_NAME' )
); // variables from the GLOBALS array ); // variables from the GLOBALS array
// that are implicitly assigned // that are implicitly assigned
@@ -112,8 +112,8 @@ class Smarty
// SMARTY_PHP_REMOVE -> remove php tags // SMARTY_PHP_REMOVE -> remove php tags
// SMARTY_PHP_ALLOW -> execute php tags // SMARTY_PHP_ALLOW -> execute php tags
// default: SMARTY_PHP_PASSTHRU // default: SMARTY_PHP_PASSTHRU
var $security = false; // enable template security (default false) var $security = false; // enable template security (default false)
var $secure_dir = array('./templates'); // array of directories considered secure var $secure_dir = array('./templates'); // array of directories considered secure
var $secure_ext = array('.tpl'); // array of file extentions considered secure var $secure_ext = array('.tpl'); // array of file extentions considered secure
@@ -130,7 +130,7 @@ class Smarty
var $left_delimiter = '{'; // template tag delimiters. var $left_delimiter = '{'; // template tag delimiters.
var $right_delimiter = '}'; var $right_delimiter = '}';
var $compiler_funcs = array( var $compiler_funcs = array(
); );
@@ -141,11 +141,11 @@ class Smarty
'fetch' => 'smarty_func_fetch', 'fetch' => 'smarty_func_fetch',
'counter' => 'smarty_func_counter', 'counter' => 'smarty_func_counter',
'assign' => 'smarty_func_assign', 'assign' => 'smarty_func_assign',
'popup_init' => 'smarty_func_overlib_init', 'popup_init' => 'smarty_func_overlib_init',
'popup' => 'smarty_func_overlib', 'popup' => 'smarty_func_overlib',
'assign_debug_info' => 'smarty_func_assign_debug_info' 'assign_debug_info' => 'smarty_func_assign_debug_info'
); );
var $custom_mods = array( 'lower' => 'strtolower', var $custom_mods = array( 'lower' => 'strtolower',
'upper' => 'strtoupper', 'upper' => 'strtoupper',
'capitalize' => 'ucwords', 'capitalize' => 'ucwords',
@@ -163,7 +163,7 @@ class Smarty
'count_sentences' => 'smarty_mod_count_sentences', 'count_sentences' => 'smarty_mod_count_sentences',
'count_paragraphs' => 'smarty_mod_count_paragraphs' 'count_paragraphs' => 'smarty_mod_count_paragraphs'
); );
var $show_info_header = false; // display HTML info header at top of page output var $show_info_header = false; // display HTML info header at top of page output
var $show_info_include = false; // display HTML comments at top & bottom of var $show_info_include = false; // display HTML comments at top & bottom of
// each included template // each included template
@@ -181,32 +181,32 @@ class Smarty
// in php.ini // in php.ini
/**************************************************************************/ /**************************************************************************/
/* END SMARTY CONFIGURATION SECTION */ /* END SMARTY CONFIGURATION SECTION */
/* There should be no need to touch anything below this line. */ /* There should be no need to touch anything below this line. */
/**************************************************************************/ /**************************************************************************/
// internal vars // internal vars
var $_error_msg = false; // error messages. true/false var $_error_msg = false; // error messages. true/false
var $_tpl_vars = array(); // where assigned template vars are kept var $_tpl_vars = array(); // where assigned template vars are kept
var $_sections = array(); // keeps track of sections var $_sections = array(); // keeps track of sections
var $_conf_obj = null; // configuration object var $_conf_obj = null; // configuration object
var $_config = array(); // loaded configuration settings var $_config = array(); // loaded configuration settings
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty' var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
var $_version = '1.4.5'; // Smarty version number var $_version = '1.4.5'; // Smarty version number
var $_extract = false; // flag for custom functions var $_extract = false; // flag for custom functions
var $_inclusion_depth = 0; // current template inclusion depth var $_inclusion_depth = 0; // current template inclusion depth
var $_compile_id = null; // for different compiled templates var $_compile_id = null; // for different compiled templates
var $_smarty_debug_id = 'SMARTY_DEBUG'; // text in URL to enable debug mode var $_smarty_debug_id = 'SMARTY_DEBUG'; // text in URL to enable debug mode
var $_smarty_debug_info = array(); // debugging information for debug console var $_smarty_debug_info = array(); // debugging information for debug console
var $_cache_info = array(); // info that makes up a cache file var $_cache_info = array(); // info that makes up a cache file
/*======================================================================*\ /*======================================================================*\
Function: Smarty Function: Smarty
Purpose: Constructor Purpose: Constructor
\*======================================================================*/ \*======================================================================*/
function Smarty() function Smarty()
{ {
foreach ($this->global_assign as $key => $var_name) { foreach ($this->global_assign as $key => $var_name) {
if (is_array($var_name)) { if (is_array($var_name)) {
foreach ($var_name as $var) { foreach ($var_name as $var) {
@@ -245,7 +245,7 @@ class Smarty
$this->_extract = true; $this->_extract = true;
} }
/*======================================================================*\ /*======================================================================*\
Function: append Function: append
Purpose: appens values to template variables Purpose: appens values to template variables
@@ -284,7 +284,7 @@ class Smarty
unset($this->_tpl_vars[$tpl_var]); unset($this->_tpl_vars[$tpl_var]);
} }
/*======================================================================*\ /*======================================================================*\
Function: register_function Function: register_function
Purpose: Registers custom function to be used in templates Purpose: Registers custom function to be used in templates
@@ -320,7 +320,7 @@ class Smarty
{ {
unset($this->compiler_funcs[$function]); unset($this->compiler_funcs[$function]);
} }
/*======================================================================*\ /*======================================================================*\
Function: register_modifier Function: register_modifier
Purpose: Registers modifier to be used in templates Purpose: Registers modifier to be used in templates
@@ -381,7 +381,7 @@ class Smarty
} }
$this->prefilter_funcs = $tmp_array; $this->prefilter_funcs = $tmp_array;
} }
/*======================================================================*\ /*======================================================================*\
Function: register_postfilter Function: register_postfilter
Purpose: Registers a postfilter function to apply Purpose: Registers a postfilter function to apply
@@ -406,7 +406,7 @@ class Smarty
} }
$this->postfilter_funcs = $tmp_array; $this->postfilter_funcs = $tmp_array;
} }
/*======================================================================*\ /*======================================================================*\
Function: clear_cache() Function: clear_cache()
Purpose: clear cached content for the given template and cache id Purpose: clear cached content for the given template and cache id
@@ -415,8 +415,8 @@ class Smarty
{ {
return $this->_rm_auto($this->cache_dir, $tpl_file, $compile_id . $cache_id); return $this->_rm_auto($this->cache_dir, $tpl_file, $compile_id . $cache_id);
} }
/*======================================================================*\ /*======================================================================*\
Function: clear_all_cache() Function: clear_all_cache()
Purpose: clear the entire contents of cache (all templates) Purpose: clear the entire contents of cache (all templates)
@@ -436,7 +436,7 @@ class Smarty
if (!$this->caching) if (!$this->caching)
return false; return false;
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id); $cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
if (file_exists($cache_file) && if (file_exists($cache_file) &&
($this->cache_lifetime == 0 || ($this->cache_lifetime == 0 ||
@@ -444,10 +444,10 @@ class Smarty
return true; return true;
else else
return false; return false;
} }
/*======================================================================*\ /*======================================================================*\
Function: clear_all_assign() Function: clear_all_assign()
Purpose: clear all the assigned template variables. Purpose: clear all the assigned template variables.
@@ -486,7 +486,7 @@ class Smarty
{ {
$this->fetch($tpl_file, $cache_id, $compile_id, true); $this->fetch($tpl_file, $cache_id, $compile_id, true);
} }
/*======================================================================*\ /*======================================================================*\
Function: fetch() Function: fetch()
Purpose: executes & returns or displays the template results Purpose: executes & returns or displays the template results
@@ -496,53 +496,51 @@ class Smarty
global $HTTP_SERVER_VARS, $QUERY_STRING, $HTTP_COOKIE_VARS; global $HTTP_SERVER_VARS, $QUERY_STRING, $HTTP_COOKIE_VARS;
if ($this->debugging_ctrl == 'URL' if ($this->debugging_ctrl == 'URL'
&& (!empty($QUERY_STRING) && (!empty($QUERY_STRING) && strstr($QUERY_STRING,$this->_smarty_debug_id))) {
&& strstr($QUERY_STRING,$this->_smarty_debug_id))) { $this->debugging = true;
$this->debugging = true; }
}
if($this->debugging) {
if($this->debugging) // capture time for debugging info
{ $debug_start_time = $this->_get_microtime();
// capture time for debugging info $this->_smarty_debug_info[] = array('type' => 'template',
$debug_start_time = $this->_get_microtime(); 'filename' => $tpl_file,
$this->_smarty_debug_info[] = array('type' => 'template', 'depth' => 0);
'filename' => $tpl_file, $included_tpls_idx = count($this->_smarty_debug_info) - 1;
'depth' => 0); }
$included_tpls_idx = count($this->_smarty_debug_info) - 1;
} $this->_compile_id = $compile_id;
$this->_compile_id = $compile_id;
$this->_inclusion_depth = 0; $this->_inclusion_depth = 0;
if ($this->caching) { if ($this->caching) {
$this->_cache_info[] = array('template',$tpl_file); $this->_cache_info[] = array('template', $tpl_file);
$cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id); $cache_file = $this->_get_auto_filename($this->cache_dir, $tpl_file, $compile_id . $cache_id);
if (file_exists($cache_file) && if (file_exists($cache_file) &&
($this->cache_lifetime == 0 || ($this->cache_lifetime == 0 ||
(time() - filemtime($cache_file) <= $this->cache_lifetime))) { (time() - filemtime($cache_file) <= $this->cache_lifetime))) {
if($this->_read_cache_file($cache_file,$results)) {
if ($this->insert_tag_check) {
$results = $this->_process_cached_inserts($results);
}
if ($display) {
echo $results;
if ($this->debugging)
{
// capture time for debugging info
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
echo $this->_generate_debug_output(); if($this->_read_cache_file($cache_file,$results)) {
} if ($this->insert_tag_check) {
return; $results = $this->_process_cached_inserts($results);
} else { }
return $results; if ($display) {
} echo $results;
} if ($this->debugging)
{
// capture time for debugging info
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
echo $this->_generate_debug_output();
}
return;
} else {
return $results;
}
}
} }
} }
@@ -565,38 +563,38 @@ class Smarty
if ($this->show_info_header) { if ($this->show_info_header) {
$info_header = '<!-- Smarty '.$this->_version.' '.strftime("%Y-%m-%d %H:%M:%S %Z").' -->'."\n\n"; $info_header = '<!-- Smarty '.$this->_version.' '.strftime("%Y-%m-%d %H:%M:%S %Z").' -->'."\n\n";
} else { } else {
$info_header = ''; $info_header = '';
} }
$compile_path = $this->_get_compile_path($tpl_file); $compile_path = $this->_get_compile_path($tpl_file);
// if we just need to display the results, don't perform output // if we just need to display the results, don't perform output
// buffering - for speed // buffering - for speed
if ($display && !$this->caching) { if ($display && !$this->caching) {
echo $info_header; echo $info_header;
if($this->_process_template($tpl_file, $compile_path)) if ($this->_process_template($tpl_file, $compile_path))
{ {
if ($this->show_info_include) { if ($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n"; echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n";
} }
include($compile_path); include($compile_path);
if ($this->show_info_include) { if ($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n"; echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n";
} }
} }
} else { } else {
ob_start(); ob_start();
echo $info_header; echo $info_header;
if($this->_process_template($tpl_file, $compile_path)) if ($this->_process_template($tpl_file, $compile_path))
{ {
if ($this->show_info_include) { if ($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n"; echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n";
} }
include($compile_path); include($compile_path);
if ($this->show_info_include) { if ($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n"; echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n";
} }
} }
$results = ob_get_contents(); $results = ob_get_contents();
ob_end_clean(); ob_end_clean();
} }
@@ -605,29 +603,29 @@ class Smarty
$this->_write_cache_file($cache_file, $results); $this->_write_cache_file($cache_file, $results);
$results = $this->_process_cached_inserts($results); $results = $this->_process_cached_inserts($results);
} }
if ($display) { if ($display) {
if (isset($results)) { echo $results; } if (isset($results)) { echo $results; }
if ($this->debugging) if ($this->debugging)
{ {
// capture time for debugging info // capture time for debugging info
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = ($this->_get_microtime() - $debug_start_time); $this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = ($this->_get_microtime() - $debug_start_time);
echo $this->_generate_debug_output(); echo $this->_generate_debug_output();
} }
return; return;
} else { } else {
if (isset($results)) { return $results; } if (isset($results)) { return $results; }
} }
} }
/*======================================================================*\ /*======================================================================*\
Function: _assign_smarty_interface Function: _assign_smarty_interface
Purpose: assign $smarty interface variable Purpose: assign $smarty interface variable
\*======================================================================*/ \*======================================================================*/
function _assign_smarty_interface() function _assign_smarty_interface()
{ {
$egpcs = array('e' => 'env', $egpcs = array('e' => 'env',
'g' => 'get', 'g' => 'get',
'p' => 'post', 'p' => 'post',
@@ -653,8 +651,8 @@ class Smarty
} }
$smarty['request'] = array_merge($smarty['request'], $smarty['session']); $smarty['request'] = array_merge($smarty['request'], $smarty['session']);
$smarty['now'] = time(); $smarty['now'] = time();
$this->assign('smarty', $smarty); $this->assign('smarty', $smarty);
} }
@@ -665,31 +663,31 @@ class Smarty
\*======================================================================*/ \*======================================================================*/
function _generate_debug_output() { function _generate_debug_output() {
// we must force compile the debug template in case the environment // we must force compile the debug template in case the environment
// changed between separate applications. // changed between separate applications.
ob_start(); ob_start();
$force_compile_orig = $this->force_compile; $force_compile_orig = $this->force_compile;
$this->force_compile = true; $this->force_compile = true;
$compile_path = $this->_get_compile_path($tpl_file); $compile_path = $this->_get_compile_path($tpl_file);
if($this->_process_template($this->debug_tpl, $compile_path)) if ($this->_process_template($this->debug_tpl, $compile_path))
{ {
if ($this->show_info_include) { if ($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$this->debug_tpl." -->\n"; echo "\n<!-- SMARTY_BEGIN: ".$this->debug_tpl." -->\n";
} }
include($compile_path); include($compile_path);
if ($this->show_info_include) { if ($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$this->debug_tpl." -->\n"; echo "\n<!-- SMARTY_END: ".$this->debug_tpl." -->\n";
} }
} }
$results = ob_get_contents(); $results = ob_get_contents();
$this->force_compile = $force_compile_orig; $this->force_compile = $force_compile_orig;
ob_end_clean(); ob_end_clean();
return $results; return $results;
} }
/*======================================================================*\ /*======================================================================*\
Function: _process_template() Function: _process_template()
Purpose: Purpose:
\*======================================================================*/ \*======================================================================*/
function _process_template($tpl_file, $compile_path) function _process_template($tpl_file, $compile_path)
{ {
@@ -698,11 +696,12 @@ function _generate_debug_output() {
if (!$this->compile_check) { if (!$this->compile_check) {
// no need to check if the template needs recompiled // no need to check if the template needs recompiled
return true; return true;
} else { } else {
// get template source and timestamp // get template source and timestamp
if(!$this->_fetch_template_info($tpl_file, $template_source, $template_timestamp)) { if (!$this->_fetch_template_info($tpl_file, $template_source,
return false; $template_timestamp)) {
} return false;
}
if ($template_timestamp <= $this->_fetch_compiled_template_timestamp($compile_path)) { if ($template_timestamp <= $this->_fetch_compiled_template_timestamp($compile_path)) {
// template not expired, no recompile // template not expired, no recompile
return true; return true;
@@ -715,9 +714,10 @@ function _generate_debug_output() {
} }
} else { } else {
// compiled template does not exist, or forced compile // compiled template does not exist, or forced compile
if(!$this->_fetch_template_info($tpl_file, $template_source, $template_timestamp)) { if (!$this->_fetch_template_info($tpl_file, $template_source,
return false; $template_timestamp)) {
} return false;
}
$this->_compile_template($tpl_file, $template_source, $template_compiled); $this->_compile_template($tpl_file, $template_source, $template_compiled);
$this->_write_compiled_template($compile_path, $template_compiled); $this->_write_compiled_template($compile_path, $template_compiled);
return true; return true;
@@ -730,77 +730,78 @@ function _generate_debug_output() {
\*======================================================================*/ \*======================================================================*/
function _get_compile_path($tpl_file) function _get_compile_path($tpl_file)
{ {
return $this->_get_auto_filename($this->compile_dir, $tpl_file, $this->_compile_id); return $this->_get_auto_filename($this->compile_dir, $tpl_file,
} $this->_compile_id);
}
/*======================================================================*\ /*======================================================================*\
Function: _compiled_template_exists Function: _compiled_template_exists
Purpose: Purpose:
\*======================================================================*/ \*======================================================================*/
function _compiled_template_exists($include_path) function _compiled_template_exists($include_path)
{ {
// everything is in $compile_dir // everything is in $compile_dir
return file_exists($include_path); return file_exists($include_path);
} }
/*======================================================================*\ /*======================================================================*\
Function: _fetch_compiled_template_timestamp Function: _fetch_compiled_template_timestamp
Purpose: Purpose:
\*======================================================================*/ \*======================================================================*/
function _fetch_compiled_template_timestamp($include_path) function _fetch_compiled_template_timestamp($include_path)
{ {
// everything is in $compile_dir // everything is in $compile_dir
return filemtime($include_path); return filemtime($include_path);
} }
/*======================================================================*\ /*======================================================================*\
Function: _write_compiled_template Function: _write_compiled_template
Purpose: Purpose:
\*======================================================================*/ \*======================================================================*/
function _write_compiled_template($compile_path, $template_compiled) function _write_compiled_template($compile_path, $template_compiled)
{ {
// we save everything into $compile_dir // we save everything into $compile_dir
$this->_write_file($compile_path, $template_compiled, true); $this->_write_file($compile_path, $template_compiled, true);
return true; return true;
} }
/*======================================================================*\ /*======================================================================*\
Function: _fetch_template_info() Function: _fetch_template_info()
Purpose: fetch the template info. Gets timestamp, and source Purpose: fetch the template info. Gets timestamp, and source
if get_source is true if get_source is true
\*======================================================================*/ \*======================================================================*/
function _fetch_template_info($tpl_path, &$template_source, &$template_timestamp, $get_source=true) function _fetch_template_info($tpl_path, &$template_source, &$template_timestamp, $get_source=true)
{ {
// split tpl_path by the first colon // split tpl_path by the first colon
$tpl_path_parts = explode(':', $tpl_path, 2); $tpl_path_parts = explode(':', $tpl_path, 2);
if (count($tpl_path_parts) == 1) { if (count($tpl_path_parts) == 1) {
// no resource type, treat as type "file" // no resource type, treat as type "file"
$resource_type = 'file'; $resource_type = 'file';
$resource_name = $tpl_path_parts[0]; $resource_name = $tpl_path_parts[0];
} else { } else {
$resource_type = $tpl_path_parts[0]; $resource_type = $tpl_path_parts[0];
$resource_name = $tpl_path_parts[1]; $resource_name = $tpl_path_parts[1];
} }
switch ($resource_type) { switch ($resource_type) {
case 'file': case 'file':
if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/",$resource_name)) { if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/",$resource_name)) {
// relative pathname to $template_dir // relative pathname to $template_dir
$resource_name = $this->template_dir.'/'.$resource_name; $resource_name = $this->template_dir.'/'.$resource_name;
} }
if (file_exists($resource_name) && is_readable($resource_name)) { if (file_exists($resource_name) && is_readable($resource_name)) {
if($get_source) { if($get_source) {
$template_source = $this->_read_file($resource_name); $template_source = $this->_read_file($resource_name);
} }
$template_timestamp = filemtime($resource_name); $template_timestamp = filemtime($resource_name);
} else { } else {
$this->_trigger_error_msg("unable to read template resource: \"$tpl_path\""); $this->_trigger_error_msg("unable to read template resource: \"$tpl_path\"");
return false; return false;
} }
// if security is on, make sure template comes from a $secure_dir // if security is on, make sure template comes from a $secure_dir
if ($this->security && !$this->security_settings['INCLUDE_ANY']) { if ($this->security && !$this->security_settings['INCLUDE_ANY']) {
$resource_is_secure = false; $resource_is_secure = false;
foreach ($this->secure_dir as $curr_dir) { foreach ($this->secure_dir as $curr_dir) {
@@ -812,7 +813,7 @@ function _generate_debug_output() {
if (!$resource_is_secure) { if (!$resource_is_secure) {
$this->_trigger_error_msg("(secure mode) including \"$resource_name\" is not allowed"); $this->_trigger_error_msg("(secure mode) including \"$resource_name\" is not allowed");
return false; return false;
} }
} }
break; break;
default: default:
@@ -836,7 +837,7 @@ function _generate_debug_output() {
return true; return true;
} }
/*======================================================================*\ /*======================================================================*\
Function: _compile_template() Function: _compile_template()
Purpose: called to compile the templates Purpose: called to compile the templates
@@ -880,13 +881,13 @@ function _generate_debug_output() {
\*======================================================================*/ \*======================================================================*/
function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars) function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars)
{ {
if($this->debugging) { if($this->debugging) {
$debug_start_time = $this->_get_microtime(); $debug_start_time = $this->_get_microtime();
$this->_smarty_debug_info[] = array('type' => 'template', $this->_smarty_debug_info[] = array('type' => 'template',
'filename' => $_smarty_include_tpl_file, 'filename' => $_smarty_include_tpl_file,
'depth' => ++$this->_inclusion_depth); 'depth' => ++$this->_inclusion_depth);
$included_tpls_idx = count($this->_smarty_debug_info) - 1; $included_tpls_idx = count($this->_smarty_debug_info) - 1;
} }
$this->_tpl_vars = array_merge($this->_tpl_vars, $_smarty_include_vars); $this->_tpl_vars = array_merge($this->_tpl_vars, $_smarty_include_vars);
extract($this->_tpl_vars); extract($this->_tpl_vars);
@@ -907,33 +908,32 @@ function _generate_debug_output() {
array_shift($this->_config); array_shift($this->_config);
$this->_inclusion_depth--; $this->_inclusion_depth--;
if ($this->debugging) { if ($this->debugging) {
// capture time for debugging info // capture time for debugging info
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time; $this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
} }
if ($this->caching) { if ($this->caching) {
$this->_cache_info[] = array('template',$_smarty_include_tpl_file); $this->_cache_info[] = array('template', $_smarty_include_tpl_file);
} }
} }
/*======================================================================*\ /*======================================================================*\
Function: _config_load Function: _config_load
Purpose: load configuration values Purpose: load configuration values
\*======================================================================*/ \*======================================================================*/
function _config_load($file, $section, $scope) function _config_load($file, $section, $scope)
{ {
if($this->debugging) { if($this->debugging) {
$debug_start_time = $this->_get_microtime(); $debug_start_time = $this->_get_microtime();
} }
if ($this->caching) { if ($this->caching) {
$this->_cache_info[] = array('config',$file); $this->_cache_info[] = array('config', $file);
} }
$this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file)); $this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file));
if ($scope == 'parent') { if ($scope == 'parent') {
if (count($this->_config) > 0) if (count($this->_config) > 0)
@@ -951,13 +951,13 @@ function _generate_debug_output() {
for ($i = 1; $i < count($this->_config); $i++) for ($i = 1; $i < count($this->_config); $i++)
$this->_config[$i] = array_merge($this->_config[$i], $this->_conf_obj->get($file, $section)); $this->_config[$i] = array_merge($this->_config[$i], $this->_conf_obj->get($file, $section));
} }
if($this->debugging) { if($this->debugging) {
$debug_start_time = $this->_get_microtime(); $debug_start_time = $this->_get_microtime();
$this->_smarty_debug_info[] = array('type' => 'config', $this->_smarty_debug_info[] = array('type' => 'config',
'filename' => $file.' ['.$section.'] '.$scope, 'filename' => $file.' ['.$section.'] '.$scope,
'depth' => $this->_inclusion_depth, 'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time); 'exec_time' => $this->_get_microtime() - $debug_start_time);
} }
} }
@@ -967,10 +967,10 @@ function _generate_debug_output() {
\*======================================================================*/ \*======================================================================*/
function _process_cached_inserts($results) function _process_cached_inserts($results)
{ {
if($this->debugging) { if($this->debugging) {
$debug_start_time = $this->_get_microtime(); $debug_start_time = $this->_get_microtime();
} }
preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'!Uis', preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'!Uis',
$results, $match); $results, $match);
list($cached_inserts, $insert_args) = $match; list($cached_inserts, $insert_args) = $match;
@@ -986,17 +986,16 @@ function _generate_debug_output() {
$replace = $function_name($args, $this); $replace = $function_name($args, $this);
$results = str_replace($cached_inserts[$i], $replace, $results); $results = str_replace($cached_inserts[$i], $replace, $results);
if ($this->debugging) { if ($this->debugging) {
$this->_smarty_debug_info[] = array('type' => 'insert', $this->_smarty_debug_info[] = array('type' => 'insert',
'filename' => 'insert_'.$name, 'filename' => 'insert_'.$name,
'depth' => $this->_inclusion_depth, 'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time); 'exec_time' => $this->_get_microtime() - $debug_start_time);
} }
} }
return $results; return $results;
} }
/*======================================================================*\ /*======================================================================*\
@@ -1005,9 +1004,9 @@ function _generate_debug_output() {
\*======================================================================*/ \*======================================================================*/
function _run_insert_handler($args) function _run_insert_handler($args)
{ {
if($this->debugging) { if($this->debugging) {
$debug_start_time = $this->_get_microtime(); $debug_start_time = $this->_get_microtime();
} }
if ($this->caching) { if ($this->caching) {
$arg_string = serialize($args); $arg_string = serialize($args);
@@ -1016,12 +1015,12 @@ function _run_insert_handler($args)
$function_name = 'insert_'.$args['name']; $function_name = 'insert_'.$args['name'];
$content = $function_name($args, $this); $content = $function_name($args, $this);
if ($this->debugging) { if ($this->debugging) {
$this->_smarty_debug_info[] = array('type' => 'insert', $this->_smarty_debug_info[] = array('type' => 'insert',
'filename' => 'insert_'.$args['name'], 'filename' => 'insert_'.$args['name'],
'depth' => $this->_inclusion_depth, 'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time); 'exec_time' => $this->_get_microtime() - $debug_start_time);
} }
return $content; return $content;
} }
} }
@@ -1047,7 +1046,7 @@ function _run_mod_handler()
} }
} }
/*======================================================================*\ /*======================================================================*\
Function: _dequote Function: _dequote
Purpose: Remove starting and ending quotes from the string Purpose: Remove starting and ending quotes from the string
@@ -1061,7 +1060,7 @@ function _run_mod_handler()
return $string; return $string;
} }
/*======================================================================*\ /*======================================================================*\
Function: _read_file() Function: _read_file()
Purpose: read in a file Purpose: read in a file
@@ -1087,23 +1086,23 @@ function _run_mod_handler()
{ {
if ($create_dirs) if ($create_dirs)
$this->_create_dir_structure(dirname($filename)); $this->_create_dir_structure(dirname($filename));
if (!($fd = fopen($filename, 'w'))) { if (!($fd = fopen($filename, 'w'))) {
$this->_trigger_error_msg("problem writing '$filename.'"); $this->_trigger_error_msg("problem writing '$filename.'");
return false; return false;
} }
// flock doesn't seem to work on several windows platforms (98, NT4, NT5, ?), // flock doesn't seem to work on several windows platforms (98, NT4, NT5, ?),
// so we'll not use it at all in windows. // so we'll not use it at all in windows.
if ( strtoupper(substr(PHP_OS,0,3)) == 'WIN' || (flock($fd, LOCK_EX)) ) { if ( strtoupper(substr(PHP_OS,0,3)) == 'WIN' || (flock($fd, LOCK_EX)) ) {
fwrite( $fd, $contents ); fwrite( $fd, $contents );
fclose($fd); fclose($fd);
chmod($filename,0644); chmod($filename,0644);
} }
return true; return true;
} }
/*======================================================================*\ /*======================================================================*\
Function: _get_auto_base Function: _get_auto_base
@@ -1120,7 +1119,7 @@ function _run_mod_handler()
/*======================================================================*\ /*======================================================================*\
Function: _get_auto_filename Function: _get_auto_filename
Purpose: get a concrete filename for automagically created content Purpose: get a concrete filename for automagically created content
\*======================================================================*/ \*======================================================================*/
function _get_auto_filename($auto_base, $auto_source, $auto_id = null) function _get_auto_filename($auto_base, $auto_source, $auto_id = null)
{ {
@@ -1132,7 +1131,7 @@ function _run_mod_handler()
/*======================================================================*\ /*======================================================================*\
Function: _rm_auto Function: _rm_auto
Purpose: delete an automagically created file by name and id Purpose: delete an automagically created file by name and id
\*======================================================================*/ \*======================================================================*/
function _rm_auto($auto_base, $auto_source = null, $auto_id = null) function _rm_auto($auto_base, $auto_source = null, $auto_id = null)
{ {
@@ -1161,18 +1160,18 @@ function _run_mod_handler()
\*======================================================================*/ \*======================================================================*/
function _rmdir($dirname, $level = 1) function _rmdir($dirname, $level = 1)
{ {
$handle = opendir($dirname); $handle = opendir($dirname);
while ($entry = readdir($handle)) { while ($entry = readdir($handle)) {
if ($entry != '.' && $entry != '..') { if ($entry != '.' && $entry != '..') {
if (is_dir($dirname . '/' . $entry)) { if (is_dir($dirname . '/' . $entry)) {
$this->_rmdir($dirname . '/' . $entry, $level + 1); $this->_rmdir($dirname . '/' . $entry, $level + 1);
} }
else { else {
unlink($dirname . '/' . $entry); unlink($dirname . '/' . $entry);
} }
} }
} }
closedir($handle); closedir($handle);
@@ -1195,70 +1194,72 @@ function _run_mod_handler()
$new_dir .= $dir_part; $new_dir .= $dir_part;
if (!file_exists($new_dir) && !mkdir($new_dir, 0701)) { if (!file_exists($new_dir) && !mkdir($new_dir, 0701)) {
$this->_trigger_error_msg("problem creating directory \"$dir\""); $this->_trigger_error_msg("problem creating directory \"$dir\"");
return false; return false;
} }
$new_dir .= '/'; $new_dir .= '/';
} }
} }
} }
/*======================================================================*\ /*======================================================================*\
Function: _write_cache_file Function: _write_cache_file
Purpose: Prepend the cache information to the cache file Purpose: Prepend the cache information to the cache file
and write it to disk and write it to disk
\*======================================================================*/ \*======================================================================*/
function _write_cache_file($cache_file,$results) function _write_cache_file($cache_file,$results)
{ {
// put the templates involved with this cache in the first line // put the templates involved with this cache in the first line
$cache_info = "SMARTY_CACHE_INFO_HEADER".serialize($this->_cache_info)."\n"; $cache_info = 'SMARTY_CACHE_INFO_HEADER'.serialize($this->_cache_info)."\n";
$this->_write_file($cache_file, $cache_info.$results, true); $this->_write_file($cache_file, $cache_info.$results, true);
return true; return true;
} }
/*======================================================================*\ /*======================================================================*\
Function: _read_cache_file Function: _read_cache_file
Purpose: See if any of the templates for this cache file Purpose: See if any of the templates for this cache file
have changed or not since the cache was created. have changed or not since the cache was created.
Remove the cache info from the cache results. Remove the cache info from the cache results.
\*======================================================================*/ \*======================================================================*/
function _read_cache_file($cache_file,&$results) function _read_cache_file($cache_file,&$results)
{ {
$results = $this->_read_file($cache_file); $results = $this->_read_file($cache_file);
// get the templates involved with this cache from the first line
$contents = split("\n",$results,2);
if(substr($contents[0],0,24) == 'SMARTY_CACHE_INFO_HEADER') {
$cache_info = unserialize(substr($contents[0],24));
$results = $contents[1];
if($this->compile_check) { // get the templates involved with this cache from the first line
$cache_filemtime = filemtime($cache_file); $contents = explode("\n", $results, 2);
foreach($cache_info as $curr_cache_info) { if (substr($contents[0], 0, 24) == 'SMARTY_CACHE_INFO_HEADER') {
switch ($curr_cache_info[0]) { $cache_info = unserialize(substr($contents[0], 24));
case 'template': $results = $contents[1];
$this->_fetch_template_info($curr_cache_info[1], $template_source, $template_timestamp, false);
if( $cache_filemtime < $template_timestamp) { if ($this->compile_check) {
// template file has changed, regenerate cache $cache_filemtime = filemtime($cache_file);
return false;
} foreach ($cache_info as $curr_cache_info) {
break; switch ($curr_cache_info[0]) {
case 'config': case 'template':
if( $cache_filemtime < filemtime($this->config_dir.'/'.$curr_cache_info[1])) { $this->_fetch_template_info($curr_cache_info[1], $template_source, $template_timestamp, false);
// config file file has changed, regenerate cache if($cache_filemtime < $template_timestamp) {
return false; // template file has changed, regenerate cache
} return false;
break; }
} break;
}
} case 'config':
} if ($cache_filemtime < filemtime($this->config_dir.'/'.$curr_cache_info[1])) {
return true; // config file file has changed, regenerate cache
return false;
}
break;
}
}
}
}
return true;
} }
/*======================================================================*\ /*======================================================================*\
Function: quote_replace Function: quote_replace
Purpose: Quote subpattern references Purpose: Quote subpattern references
@@ -1279,16 +1280,16 @@ function _run_mod_handler()
} }
/*======================================================================*\ /*======================================================================*\
Function: _get_microtime Function: _get_microtime
Purpose: Get seconds and microseconds Purpose: Get seconds and microseconds
\*======================================================================*/ \*======================================================================*/
function _get_microtime() function _get_microtime()
{ {
$mtime = microtime(); $mtime = microtime();
$mtime = explode(" ", $mtime); $mtime = explode(" ", $mtime);
$mtime = (double)($mtime[1]) + (double)($mtime[0]); $mtime = (double)($mtime[1]) + (double)($mtime[0]);
return ($mtime); return ($mtime);
} }
} }