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

@@ -43,16 +43,16 @@
// set SMARTY_DIR to absolute path to Smarty library files.
// if not defined, include_path will be used.
if(!defined("SMARTY_DIR")) {
define("SMARTY_DIR","");
if (!defined('SMARTY_DIR')) {
define('SMARTY_DIR', '');
}
require_once SMARTY_DIR.'Smarty.addons.php';
define("SMARTY_PHP_PASSTHRU",0);
define("SMARTY_PHP_QUOTE",1);
define("SMARTY_PHP_REMOVE",2);
define("SMARTY_PHP_ALLOW",3);
define('SMARTY_PHP_PASSTHRU', 0);
define('SMARTY_PHP_QUOTE', 1);
define('SMARTY_PHP_REMOVE', 2);
define('SMARTY_PHP_ALLOW', 3);
class Smarty
{
@@ -69,10 +69,10 @@ class Smarty
var $debugging = false; // enable debugging console true/false
var $debug_tpl = 'file:debug.tpl'; // path to debug console template
var $debugging_ctrl = 'NONE'; // Possible values:
// NONE - no debug control allowed
// URL - enable debugging when keyword
// SMARTY_DEBUG is found in $QUERY_STRING
var $debugging_ctrl = 'NONE'; // Possible values:
// NONE - no debug control allowed
// URL - enable debugging when keyword
// SMARTY_DEBUG is found in $QUERY_STRING
var $global_assign = array( 'HTTP_SERVER_VARS' => array( 'SCRIPT_NAME' )
); // variables from the GLOBALS array
@@ -141,8 +141,8 @@ class Smarty
'fetch' => 'smarty_func_fetch',
'counter' => 'smarty_func_counter',
'assign' => 'smarty_func_assign',
'popup_init' => 'smarty_func_overlib_init',
'popup' => 'smarty_func_overlib',
'popup_init' => 'smarty_func_overlib_init',
'popup' => 'smarty_func_overlib',
'assign_debug_info' => 'smarty_func_assign_debug_info'
);
@@ -198,7 +198,7 @@ class Smarty
var $_compile_id = null; // for different compiled templates
var $_smarty_debug_id = 'SMARTY_DEBUG'; // text in URL to enable debug mode
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
/*======================================================================*\
@@ -496,53 +496,51 @@ class Smarty
global $HTTP_SERVER_VARS, $QUERY_STRING, $HTTP_COOKIE_VARS;
if ($this->debugging_ctrl == 'URL'
&& (!empty($QUERY_STRING)
&& strstr($QUERY_STRING,$this->_smarty_debug_id))) {
$this->debugging = true;
}
&& (!empty($QUERY_STRING) && strstr($QUERY_STRING,$this->_smarty_debug_id))) {
$this->debugging = true;
}
if($this->debugging)
{
// capture time for debugging info
$debug_start_time = $this->_get_microtime();
$this->_smarty_debug_info[] = array('type' => 'template',
'filename' => $tpl_file,
'depth' => 0);
$included_tpls_idx = count($this->_smarty_debug_info) - 1;
}
if($this->debugging) {
// capture time for debugging info
$debug_start_time = $this->_get_microtime();
$this->_smarty_debug_info[] = array('type' => 'template',
'filename' => $tpl_file,
'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;
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) &&
($this->cache_lifetime == 0 ||
(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;
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();
}
return;
} else {
return $results;
}
}
echo $this->_generate_debug_output();
}
return;
} else {
return $results;
}
}
}
}
@@ -570,33 +568,33 @@ class Smarty
$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
if ($display && !$this->caching) {
echo $info_header;
if($this->_process_template($tpl_file, $compile_path))
{
if ($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n";
}
include($compile_path);
if ($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n";
}
}
if ($this->_process_template($tpl_file, $compile_path))
{
if ($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n";
}
include($compile_path);
if ($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n";
}
}
} else {
ob_start();
echo $info_header;
if($this->_process_template($tpl_file, $compile_path))
{
if ($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n";
}
include($compile_path);
if ($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n";
}
}
if ($this->_process_template($tpl_file, $compile_path))
{
if ($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n";
}
include($compile_path);
if ($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n";
}
}
$results = ob_get_contents();
ob_end_clean();
}
@@ -609,12 +607,12 @@ class Smarty
if ($display) {
if (isset($results)) { 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);
{
// 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();
}
echo $this->_generate_debug_output();
}
return;
} else {
if (isset($results)) { return $results; }
@@ -653,7 +651,7 @@ class Smarty
}
$smarty['request'] = array_merge($smarty['request'], $smarty['session']);
$smarty['now'] = time();
$smarty['now'] = time();
$this->assign('smarty', $smarty);
}
@@ -665,24 +663,24 @@ class Smarty
\*======================================================================*/
function _generate_debug_output() {
// we must force compile the debug template in case the environment
// changed between separate applications.
// we must force compile the debug template in case the environment
// changed between separate applications.
ob_start();
$force_compile_orig = $this->force_compile;
$this->force_compile = true;
$force_compile_orig = $this->force_compile;
$this->force_compile = true;
$compile_path = $this->_get_compile_path($tpl_file);
if($this->_process_template($this->debug_tpl, $compile_path))
{
if ($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$this->debug_tpl." -->\n";
}
include($compile_path);
if ($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$this->debug_tpl." -->\n";
}
}
if ($this->_process_template($this->debug_tpl, $compile_path))
{
if ($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$this->debug_tpl." -->\n";
}
include($compile_path);
if ($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$this->debug_tpl." -->\n";
}
}
$results = ob_get_contents();
$this->force_compile = $force_compile_orig;
$this->force_compile = $force_compile_orig;
ob_end_clean();
return $results;
}
@@ -700,9 +698,10 @@ function _generate_debug_output() {
return true;
} else {
// get template source and timestamp
if(!$this->_fetch_template_info($tpl_file, $template_source, $template_timestamp)) {
return false;
}
if (!$this->_fetch_template_info($tpl_file, $template_source,
$template_timestamp)) {
return false;
}
if ($template_timestamp <= $this->_fetch_compiled_template_timestamp($compile_path)) {
// template not expired, no recompile
return true;
@@ -715,9 +714,10 @@ function _generate_debug_output() {
}
} else {
// compiled template does not exist, or forced compile
if(!$this->_fetch_template_info($tpl_file, $template_source, $template_timestamp)) {
return false;
}
if (!$this->_fetch_template_info($tpl_file, $template_source,
$template_timestamp)) {
return false;
}
$this->_compile_template($tpl_file, $template_source, $template_compiled);
$this->_write_compiled_template($compile_path, $template_compiled);
return true;
@@ -730,7 +730,8 @@ function _generate_debug_output() {
\*======================================================================*/
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);
}
@@ -768,7 +769,7 @@ function _generate_debug_output() {
/*======================================================================*\
Function: _fetch_template_info()
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)
{
@@ -791,9 +792,9 @@ function _generate_debug_output() {
$resource_name = $this->template_dir.'/'.$resource_name;
}
if (file_exists($resource_name) && is_readable($resource_name)) {
if($get_source) {
$template_source = $this->_read_file($resource_name);
}
if($get_source) {
$template_source = $this->_read_file($resource_name);
}
$template_timestamp = filemtime($resource_name);
} else {
$this->_trigger_error_msg("unable to read template resource: \"$tpl_path\"");
@@ -880,13 +881,13 @@ function _generate_debug_output() {
\*======================================================================*/
function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars)
{
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
$this->_smarty_debug_info[] = array('type' => 'template',
'filename' => $_smarty_include_tpl_file,
'depth' => ++$this->_inclusion_depth);
$included_tpls_idx = count($this->_smarty_debug_info) - 1;
}
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
$this->_smarty_debug_info[] = array('type' => 'template',
'filename' => $_smarty_include_tpl_file,
'depth' => ++$this->_inclusion_depth);
$included_tpls_idx = count($this->_smarty_debug_info) - 1;
}
$this->_tpl_vars = array_merge($this->_tpl_vars, $_smarty_include_vars);
extract($this->_tpl_vars);
@@ -908,14 +909,14 @@ function _generate_debug_output() {
array_shift($this->_config);
$this->_inclusion_depth--;
if ($this->debugging) {
// capture time for debugging info
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
}
if ($this->debugging) {
// capture time for debugging info
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
}
if ($this->caching) {
$this->_cache_info[] = array('template',$_smarty_include_tpl_file);
}
$this->_cache_info[] = array('template', $_smarty_include_tpl_file);
}
}
@@ -925,14 +926,13 @@ function _generate_debug_output() {
\*======================================================================*/
function _config_load($file, $section, $scope)
{
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
}
if ($this->caching) {
$this->_cache_info[] = array('config',$file);
}
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
}
if ($this->caching) {
$this->_cache_info[] = array('config', $file);
}
$this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file));
if ($scope == 'parent') {
@@ -951,13 +951,13 @@ function _generate_debug_output() {
for ($i = 1; $i < count($this->_config); $i++)
$this->_config[$i] = array_merge($this->_config[$i], $this->_conf_obj->get($file, $section));
}
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
$this->_smarty_debug_info[] = array('type' => 'config',
'filename' => $file.' ['.$section.'] '.$scope,
'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time);
}
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
$this->_smarty_debug_info[] = array('type' => 'config',
'filename' => $file.' ['.$section.'] '.$scope,
'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time);
}
}
@@ -967,9 +967,9 @@ function _generate_debug_output() {
\*======================================================================*/
function _process_cached_inserts($results)
{
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
}
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
}
preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'!Uis',
$results, $match);
@@ -986,15 +986,14 @@ function _generate_debug_output() {
$replace = $function_name($args, $this);
$results = str_replace($cached_inserts[$i], $replace, $results);
if ($this->debugging) {
$this->_smarty_debug_info[] = array('type' => 'insert',
'filename' => 'insert_'.$name,
'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time);
}
if ($this->debugging) {
$this->_smarty_debug_info[] = array('type' => 'insert',
'filename' => 'insert_'.$name,
'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time);
}
}
return $results;
}
@@ -1005,9 +1004,9 @@ function _generate_debug_output() {
\*======================================================================*/
function _run_insert_handler($args)
{
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
}
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
}
if ($this->caching) {
$arg_string = serialize($args);
@@ -1016,12 +1015,12 @@ function _run_insert_handler($args)
$function_name = 'insert_'.$args['name'];
$content = $function_name($args, $this);
if ($this->debugging) {
$this->_smarty_debug_info[] = array('type' => 'insert',
'filename' => 'insert_'.$args['name'],
'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time);
}
return $content;
$this->_smarty_debug_info[] = array('type' => 'insert',
'filename' => 'insert_'.$args['name'],
'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time);
}
return $content;
}
}
@@ -1205,57 +1204,59 @@ function _run_mod_handler()
/*======================================================================*\
Function: _write_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)
{
// put the templates involved with this cache in the first line
$cache_info = "SMARTY_CACHE_INFO_HEADER".serialize($this->_cache_info)."\n";
// put the templates involved with this cache in the first line
$cache_info = 'SMARTY_CACHE_INFO_HEADER'.serialize($this->_cache_info)."\n";
$this->_write_file($cache_file, $cache_info.$results, true);
return true;
return true;
}
/*======================================================================*\
Function: _read_cache_file
Purpose: See if any of the templates for this cache file
have changed or not since the cache was created.
Remove the cache info from the cache results.
have changed or not since the cache was created.
Remove the cache info from the cache 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);
// get the templates involved with this cache from the first line
$contents = explode("\n", $results, 2);
if(substr($contents[0],0,24) == 'SMARTY_CACHE_INFO_HEADER') {
$cache_info = unserialize(substr($contents[0],24));
$results = $contents[1];
if (substr($contents[0], 0, 24) == 'SMARTY_CACHE_INFO_HEADER') {
$cache_info = unserialize(substr($contents[0], 24));
$results = $contents[1];
if($this->compile_check) {
$cache_filemtime = filemtime($cache_file);
if ($this->compile_check) {
$cache_filemtime = filemtime($cache_file);
foreach($cache_info as $curr_cache_info) {
switch ($curr_cache_info[0]) {
case 'template':
$this->_fetch_template_info($curr_cache_info[1], $template_source, $template_timestamp, false);
if( $cache_filemtime < $template_timestamp) {
// template file has changed, regenerate cache
return false;
}
break;
case 'config':
if( $cache_filemtime < filemtime($this->config_dir.'/'.$curr_cache_info[1])) {
// config file file has changed, regenerate cache
return false;
}
break;
}
}
}
}
return true;
foreach ($cache_info as $curr_cache_info) {
switch ($curr_cache_info[0]) {
case 'template':
$this->_fetch_template_info($curr_cache_info[1], $template_source, $template_timestamp, false);
if($cache_filemtime < $template_timestamp) {
// template file has changed, regenerate cache
return false;
}
break;
case 'config':
if ($cache_filemtime < filemtime($this->config_dir.'/'.$curr_cache_info[1])) {
// config file file has changed, regenerate cache
return false;
}
break;
}
}
}
}
return true;
}
@@ -1279,16 +1280,16 @@ function _run_mod_handler()
}
/*======================================================================*\
Function: _get_microtime
Purpose: Get seconds and microseconds
Function: _get_microtime
Purpose: Get seconds and microseconds
\*======================================================================*/
function _get_microtime()
{
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = (double)($mtime[1]) + (double)($mtime[0]);
return ($mtime);
}
function _get_microtime()
{
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = (double)($mtime[1]) + (double)($mtime[0]);
return ($mtime);
}
}

View File

@@ -43,16 +43,16 @@
// set SMARTY_DIR to absolute path to Smarty library files.
// if not defined, include_path will be used.
if(!defined("SMARTY_DIR")) {
define("SMARTY_DIR","");
if (!defined('SMARTY_DIR')) {
define('SMARTY_DIR', '');
}
require_once SMARTY_DIR.'Smarty.addons.php';
define("SMARTY_PHP_PASSTHRU",0);
define("SMARTY_PHP_QUOTE",1);
define("SMARTY_PHP_REMOVE",2);
define("SMARTY_PHP_ALLOW",3);
define('SMARTY_PHP_PASSTHRU', 0);
define('SMARTY_PHP_QUOTE', 1);
define('SMARTY_PHP_REMOVE', 2);
define('SMARTY_PHP_ALLOW', 3);
class Smarty
{
@@ -69,10 +69,10 @@ class Smarty
var $debugging = false; // enable debugging console true/false
var $debug_tpl = 'file:debug.tpl'; // path to debug console template
var $debugging_ctrl = 'NONE'; // Possible values:
// NONE - no debug control allowed
// URL - enable debugging when keyword
// SMARTY_DEBUG is found in $QUERY_STRING
var $debugging_ctrl = 'NONE'; // Possible values:
// NONE - no debug control allowed
// URL - enable debugging when keyword
// SMARTY_DEBUG is found in $QUERY_STRING
var $global_assign = array( 'HTTP_SERVER_VARS' => array( 'SCRIPT_NAME' )
); // variables from the GLOBALS array
@@ -141,8 +141,8 @@ class Smarty
'fetch' => 'smarty_func_fetch',
'counter' => 'smarty_func_counter',
'assign' => 'smarty_func_assign',
'popup_init' => 'smarty_func_overlib_init',
'popup' => 'smarty_func_overlib',
'popup_init' => 'smarty_func_overlib_init',
'popup' => 'smarty_func_overlib',
'assign_debug_info' => 'smarty_func_assign_debug_info'
);
@@ -198,7 +198,7 @@ class Smarty
var $_compile_id = null; // for different compiled templates
var $_smarty_debug_id = 'SMARTY_DEBUG'; // text in URL to enable debug mode
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
/*======================================================================*\
@@ -496,53 +496,51 @@ class Smarty
global $HTTP_SERVER_VARS, $QUERY_STRING, $HTTP_COOKIE_VARS;
if ($this->debugging_ctrl == 'URL'
&& (!empty($QUERY_STRING)
&& strstr($QUERY_STRING,$this->_smarty_debug_id))) {
$this->debugging = true;
}
&& (!empty($QUERY_STRING) && strstr($QUERY_STRING,$this->_smarty_debug_id))) {
$this->debugging = true;
}
if($this->debugging)
{
// capture time for debugging info
$debug_start_time = $this->_get_microtime();
$this->_smarty_debug_info[] = array('type' => 'template',
'filename' => $tpl_file,
'depth' => 0);
$included_tpls_idx = count($this->_smarty_debug_info) - 1;
}
if($this->debugging) {
// capture time for debugging info
$debug_start_time = $this->_get_microtime();
$this->_smarty_debug_info[] = array('type' => 'template',
'filename' => $tpl_file,
'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;
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) &&
($this->cache_lifetime == 0 ||
(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;
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();
}
return;
} else {
return $results;
}
}
echo $this->_generate_debug_output();
}
return;
} else {
return $results;
}
}
}
}
@@ -570,33 +568,33 @@ class Smarty
$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
if ($display && !$this->caching) {
echo $info_header;
if($this->_process_template($tpl_file, $compile_path))
{
if ($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n";
}
include($compile_path);
if ($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n";
}
}
if ($this->_process_template($tpl_file, $compile_path))
{
if ($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n";
}
include($compile_path);
if ($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n";
}
}
} else {
ob_start();
echo $info_header;
if($this->_process_template($tpl_file, $compile_path))
{
if ($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n";
}
include($compile_path);
if ($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n";
}
}
if ($this->_process_template($tpl_file, $compile_path))
{
if ($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n";
}
include($compile_path);
if ($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n";
}
}
$results = ob_get_contents();
ob_end_clean();
}
@@ -609,12 +607,12 @@ class Smarty
if ($display) {
if (isset($results)) { 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);
{
// 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();
}
echo $this->_generate_debug_output();
}
return;
} else {
if (isset($results)) { return $results; }
@@ -653,7 +651,7 @@ class Smarty
}
$smarty['request'] = array_merge($smarty['request'], $smarty['session']);
$smarty['now'] = time();
$smarty['now'] = time();
$this->assign('smarty', $smarty);
}
@@ -665,24 +663,24 @@ class Smarty
\*======================================================================*/
function _generate_debug_output() {
// we must force compile the debug template in case the environment
// changed between separate applications.
// we must force compile the debug template in case the environment
// changed between separate applications.
ob_start();
$force_compile_orig = $this->force_compile;
$this->force_compile = true;
$force_compile_orig = $this->force_compile;
$this->force_compile = true;
$compile_path = $this->_get_compile_path($tpl_file);
if($this->_process_template($this->debug_tpl, $compile_path))
{
if ($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$this->debug_tpl." -->\n";
}
include($compile_path);
if ($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$this->debug_tpl." -->\n";
}
}
if ($this->_process_template($this->debug_tpl, $compile_path))
{
if ($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$this->debug_tpl." -->\n";
}
include($compile_path);
if ($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$this->debug_tpl." -->\n";
}
}
$results = ob_get_contents();
$this->force_compile = $force_compile_orig;
$this->force_compile = $force_compile_orig;
ob_end_clean();
return $results;
}
@@ -700,9 +698,10 @@ function _generate_debug_output() {
return true;
} else {
// get template source and timestamp
if(!$this->_fetch_template_info($tpl_file, $template_source, $template_timestamp)) {
return false;
}
if (!$this->_fetch_template_info($tpl_file, $template_source,
$template_timestamp)) {
return false;
}
if ($template_timestamp <= $this->_fetch_compiled_template_timestamp($compile_path)) {
// template not expired, no recompile
return true;
@@ -715,9 +714,10 @@ function _generate_debug_output() {
}
} else {
// compiled template does not exist, or forced compile
if(!$this->_fetch_template_info($tpl_file, $template_source, $template_timestamp)) {
return false;
}
if (!$this->_fetch_template_info($tpl_file, $template_source,
$template_timestamp)) {
return false;
}
$this->_compile_template($tpl_file, $template_source, $template_compiled);
$this->_write_compiled_template($compile_path, $template_compiled);
return true;
@@ -730,7 +730,8 @@ function _generate_debug_output() {
\*======================================================================*/
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);
}
@@ -768,7 +769,7 @@ function _generate_debug_output() {
/*======================================================================*\
Function: _fetch_template_info()
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)
{
@@ -791,9 +792,9 @@ function _generate_debug_output() {
$resource_name = $this->template_dir.'/'.$resource_name;
}
if (file_exists($resource_name) && is_readable($resource_name)) {
if($get_source) {
$template_source = $this->_read_file($resource_name);
}
if($get_source) {
$template_source = $this->_read_file($resource_name);
}
$template_timestamp = filemtime($resource_name);
} else {
$this->_trigger_error_msg("unable to read template resource: \"$tpl_path\"");
@@ -880,13 +881,13 @@ function _generate_debug_output() {
\*======================================================================*/
function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars)
{
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
$this->_smarty_debug_info[] = array('type' => 'template',
'filename' => $_smarty_include_tpl_file,
'depth' => ++$this->_inclusion_depth);
$included_tpls_idx = count($this->_smarty_debug_info) - 1;
}
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
$this->_smarty_debug_info[] = array('type' => 'template',
'filename' => $_smarty_include_tpl_file,
'depth' => ++$this->_inclusion_depth);
$included_tpls_idx = count($this->_smarty_debug_info) - 1;
}
$this->_tpl_vars = array_merge($this->_tpl_vars, $_smarty_include_vars);
extract($this->_tpl_vars);
@@ -908,14 +909,14 @@ function _generate_debug_output() {
array_shift($this->_config);
$this->_inclusion_depth--;
if ($this->debugging) {
// capture time for debugging info
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
}
if ($this->debugging) {
// capture time for debugging info
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = $this->_get_microtime() - $debug_start_time;
}
if ($this->caching) {
$this->_cache_info[] = array('template',$_smarty_include_tpl_file);
}
$this->_cache_info[] = array('template', $_smarty_include_tpl_file);
}
}
@@ -925,14 +926,13 @@ function _generate_debug_output() {
\*======================================================================*/
function _config_load($file, $section, $scope)
{
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
}
if ($this->caching) {
$this->_cache_info[] = array('config',$file);
}
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
}
if ($this->caching) {
$this->_cache_info[] = array('config', $file);
}
$this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file));
if ($scope == 'parent') {
@@ -951,13 +951,13 @@ function _generate_debug_output() {
for ($i = 1; $i < count($this->_config); $i++)
$this->_config[$i] = array_merge($this->_config[$i], $this->_conf_obj->get($file, $section));
}
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
$this->_smarty_debug_info[] = array('type' => 'config',
'filename' => $file.' ['.$section.'] '.$scope,
'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time);
}
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
$this->_smarty_debug_info[] = array('type' => 'config',
'filename' => $file.' ['.$section.'] '.$scope,
'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time);
}
}
@@ -967,9 +967,9 @@ function _generate_debug_output() {
\*======================================================================*/
function _process_cached_inserts($results)
{
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
}
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
}
preg_match_all('!'.$this->_smarty_md5.'{insert_cache (.*)}'.$this->_smarty_md5.'!Uis',
$results, $match);
@@ -986,15 +986,14 @@ function _generate_debug_output() {
$replace = $function_name($args, $this);
$results = str_replace($cached_inserts[$i], $replace, $results);
if ($this->debugging) {
$this->_smarty_debug_info[] = array('type' => 'insert',
'filename' => 'insert_'.$name,
'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time);
}
if ($this->debugging) {
$this->_smarty_debug_info[] = array('type' => 'insert',
'filename' => 'insert_'.$name,
'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time);
}
}
return $results;
}
@@ -1005,9 +1004,9 @@ function _generate_debug_output() {
\*======================================================================*/
function _run_insert_handler($args)
{
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
}
if($this->debugging) {
$debug_start_time = $this->_get_microtime();
}
if ($this->caching) {
$arg_string = serialize($args);
@@ -1016,12 +1015,12 @@ function _run_insert_handler($args)
$function_name = 'insert_'.$args['name'];
$content = $function_name($args, $this);
if ($this->debugging) {
$this->_smarty_debug_info[] = array('type' => 'insert',
'filename' => 'insert_'.$args['name'],
'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time);
}
return $content;
$this->_smarty_debug_info[] = array('type' => 'insert',
'filename' => 'insert_'.$args['name'],
'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time);
}
return $content;
}
}
@@ -1205,57 +1204,59 @@ function _run_mod_handler()
/*======================================================================*\
Function: _write_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)
{
// put the templates involved with this cache in the first line
$cache_info = "SMARTY_CACHE_INFO_HEADER".serialize($this->_cache_info)."\n";
// put the templates involved with this cache in the first line
$cache_info = 'SMARTY_CACHE_INFO_HEADER'.serialize($this->_cache_info)."\n";
$this->_write_file($cache_file, $cache_info.$results, true);
return true;
return true;
}
/*======================================================================*\
Function: _read_cache_file
Purpose: See if any of the templates for this cache file
have changed or not since the cache was created.
Remove the cache info from the cache results.
have changed or not since the cache was created.
Remove the cache info from the cache 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);
// get the templates involved with this cache from the first line
$contents = explode("\n", $results, 2);
if(substr($contents[0],0,24) == 'SMARTY_CACHE_INFO_HEADER') {
$cache_info = unserialize(substr($contents[0],24));
$results = $contents[1];
if (substr($contents[0], 0, 24) == 'SMARTY_CACHE_INFO_HEADER') {
$cache_info = unserialize(substr($contents[0], 24));
$results = $contents[1];
if($this->compile_check) {
$cache_filemtime = filemtime($cache_file);
if ($this->compile_check) {
$cache_filemtime = filemtime($cache_file);
foreach($cache_info as $curr_cache_info) {
switch ($curr_cache_info[0]) {
case 'template':
$this->_fetch_template_info($curr_cache_info[1], $template_source, $template_timestamp, false);
if( $cache_filemtime < $template_timestamp) {
// template file has changed, regenerate cache
return false;
}
break;
case 'config':
if( $cache_filemtime < filemtime($this->config_dir.'/'.$curr_cache_info[1])) {
// config file file has changed, regenerate cache
return false;
}
break;
}
}
}
}
return true;
foreach ($cache_info as $curr_cache_info) {
switch ($curr_cache_info[0]) {
case 'template':
$this->_fetch_template_info($curr_cache_info[1], $template_source, $template_timestamp, false);
if($cache_filemtime < $template_timestamp) {
// template file has changed, regenerate cache
return false;
}
break;
case 'config':
if ($cache_filemtime < filemtime($this->config_dir.'/'.$curr_cache_info[1])) {
// config file file has changed, regenerate cache
return false;
}
break;
}
}
}
}
return true;
}
@@ -1279,16 +1280,16 @@ function _run_mod_handler()
}
/*======================================================================*\
Function: _get_microtime
Purpose: Get seconds and microseconds
Function: _get_microtime
Purpose: Get seconds and microseconds
\*======================================================================*/
function _get_microtime()
{
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = (double)($mtime[1]) + (double)($mtime[0]);
return ($mtime);
}
function _get_microtime()
{
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = (double)($mtime[1]) + (double)($mtime[0]);
return ($mtime);
}
}