split up _compile_template to _compile_file and _compile_source, fix eval function

VS: ----------------------------------------------------------------------
This commit is contained in:
mohrt
2003-06-19 14:04:49 +00:00
parent 96e1934b03
commit f869abbf9f
5 changed files with 63 additions and 50 deletions

View File

@@ -1138,12 +1138,12 @@ reques * @var string
/** /**
* executes & returns or displays the template results * executes & returns or displays the template results
* *
* @param string $tpl_file * @param string $file_path
* @param string $cache_id * @param string $cache_id
* @param string $compile_id * @param string $compile_id
* @param boolean $display * @param boolean $display
*/ */
function fetch($tpl_file, $cache_id = null, $compile_id = null, $display = false) function fetch($file_path, $cache_id = null, $compile_id = null, $display = false)
{ {
static $_cache_info = array(); static $_cache_info = array();
@@ -1166,7 +1166,7 @@ reques * @var string
require_once(SMARTY_DIR . 'core/core.get_microtime.php'); require_once(SMARTY_DIR . 'core/core.get_microtime.php');
$_debug_start_time = smarty_core_get_microtime($_params, $this); $_debug_start_time = smarty_core_get_microtime($_params, $this);
$this->_smarty_debug_info[] = array('type' => 'template', $this->_smarty_debug_info[] = array('type' => 'template',
'filename' => $tpl_file, 'filename' => $file_path,
'depth' => 0); 'depth' => 0);
$_included_tpls_idx = count($this->_smarty_debug_info) - 1; $_included_tpls_idx = count($this->_smarty_debug_info) - 1;
} }
@@ -1183,7 +1183,7 @@ reques * @var string
array_push($_cache_info, $this->_cache_info); array_push($_cache_info, $this->_cache_info);
$this->_cache_info = array(); $this->_cache_info = array();
$_params = array( $_params = array(
'tpl_file' => $tpl_file, 'tpl_file' => $file_path,
'cache_id' => $cache_id, 'cache_id' => $cache_id,
'compile_id' => $compile_id, 'compile_id' => $compile_id,
'results' => null 'results' => null
@@ -1241,7 +1241,7 @@ reques * @var string
return $_smarty_results; return $_smarty_results;
} }
} else { } else {
$this->_cache_info['template'][$tpl_file] = true; $this->_cache_info['template'][$file_path] = true;
if ($this->cache_modified_check) { if ($this->cache_modified_check) {
header("Last-Modified: ".gmdate('D, d M Y H:i:s', time()).' GMT'); header("Last-Modified: ".gmdate('D, d M Y H:i:s', time()).' GMT');
} }
@@ -1257,20 +1257,20 @@ reques * @var string
} }
} }
$_smarty_compile_path = $this->_get_compile_path($tpl_file); $_smarty_compile_path = $this->_get_compile_path($file_path);
// 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 && count($this->_plugins['outputfilter']) == 0) { if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) {
if ($this->_is_compiled($tpl_file, $_smarty_compile_path) if ($this->_is_compiled($file_path, $_smarty_compile_path)
|| $this->_compile_template($tpl_file, $_smarty_compile_path)) || $this->_compile_file($file_path, $_smarty_compile_path))
{ {
include($_smarty_compile_path); include($_smarty_compile_path);
} }
} else { } else {
ob_start(); ob_start();
if ($this->_is_compiled($tpl_file, $_smarty_compile_path) if ($this->_is_compiled($file_path, $_smarty_compile_path)
|| $this->_compile_template($tpl_file, $_smarty_compile_path)) || $this->_compile_file($file_path, $_smarty_compile_path))
{ {
include($_smarty_compile_path); include($_smarty_compile_path);
} }
@@ -1283,7 +1283,7 @@ reques * @var string
} }
if ($this->caching) { if ($this->caching) {
$_params = array('tpl_file' => $tpl_file, $_params = array('tpl_file' => $file_path,
'cache_id' => $cache_id, 'cache_id' => $cache_id,
'compile_id' => $compile_id, 'compile_id' => $compile_id,
'results' => $_smarty_results); 'results' => $_smarty_results);
@@ -1460,15 +1460,14 @@ reques * @var string
/** /**
* compile the template * compile the template
* *
* @param string $tpl_file * @param string $file_path
* @param string $compile_path * @param string $compile_path
* @return boolean * @return boolean
*/ */
function _compile_template($tpl_file, $compile_path) function _compile_file($file_path, $compile_path)
{ {
// compiled template does not exist, or forced compile $_params = array('file_path' => $file_path);
$_params = array('file_path' => $tpl_file);
require_once(SMARTY_DIR . 'core/core.fetch_file_info.php'); require_once(SMARTY_DIR . 'core/core.fetch_file_info.php');
if (!smarty_core_fetch_file_info($_params, $this)) { if (!smarty_core_fetch_file_info($_params, $this)) {
return false; return false;
@@ -1477,6 +1476,36 @@ reques * @var string
$_file_source = $_params['file_source']; $_file_source = $_params['file_source'];
$_file_timestamp = $_params['file_timestamp']; $_file_timestamp = $_params['file_timestamp'];
if ($this->_compile_source($file_path, $_file_source, $_file_compiled)) {
$_params = array('compile_path' => $compile_path, 'file_compiled' => $_file_compiled, 'file_timestamp' => $_file_timestamp);
require_once(SMARTY_DIR . 'core/core.write_compiled_template.php');
smarty_core_write_compiled_template($_params, $this);
// if a _cache_serial was set, we also have to write an include-file:
if ($this->_cache_serial = $smarty_compiler->_cache_serial) {
$_params['plugins_code'] = $smarty_compiler->_plugins_code;
$_params['include_file_path'] = $smarty_compiler->_cache_include;
require_once(SMARTY_DIR . 'core/core.write_compiled_include.php');
smarty_core_write_compiled_include($_params, $this);
}
return true;
} else {
$this->trigger_error($smarty_compiler->_error_msg);
return false;
}
}
/**
* compile the given source
*
* @param string $file_path
* @param string $file_source
* @param string $file_compiled
* @return boolean
*/
function _compile_source($file_path, &$file_source, &$file_compiled)
{
if (file_exists(SMARTY_DIR . $this->compiler_file)) { if (file_exists(SMARTY_DIR . $this->compiler_file)) {
require_once(SMARTY_DIR . $this->compiler_file); require_once(SMARTY_DIR . $this->compiler_file);
} else { } else {
@@ -1512,23 +1541,7 @@ reques * @var string
$smarty_compiler->_cache_serial = null; $smarty_compiler->_cache_serial = null;
$smarty_compiler->_cache_include = substr($compile_path, 0, -4).'.inc'; $smarty_compiler->_cache_include = substr($compile_path, 0, -4).'.inc';
if ($smarty_compiler->_compile_file($tpl_file, $_file_source, $_file_compiled)) { return $smarty_compiler->_compile_file($file_path, $file_source, $file_compiled);
$_params = array('compile_path' => $compile_path, 'file_compiled' => $_file_compiled, 'file_timestamp' => $_file_timestamp);
require_once(SMARTY_DIR . 'core/core.write_compiled_template.php');
smarty_core_write_compiled_template($_params, $this);
// if a _cache_serial was set, we also have to write an include-file:
if ($this->_cache_serial = $smarty_compiler->_cache_serial) {
$_params['plugins_code'] = $smarty_compiler->_plugins_code;
$_params['include_file_path'] = $smarty_compiler->_cache_include;
require_once(SMARTY_DIR . 'core/core.write_compiled_include.php');
smarty_core_write_compiled_include($_params, $this);
}
return true;
} else {
$this->trigger_error($smarty_compiler->_error_msg);
return false;
}
} }

View File

@@ -221,7 +221,7 @@ class Smarty_Compiler extends Smarty {
* @param string $file_compiled * @param string $file_compiled
* @return true * @return true
*/ */
function _compile_file($tpl_file, $file_source, &$file_compiled) function _compile_file($file_path, $file_source, &$file_compiled)
{ {
if ($this->security) { if ($this->security) {
@@ -234,7 +234,7 @@ class Smarty_Compiler extends Smarty {
$this->_load_filters(); $this->_load_filters();
$this->_current_file = $tpl_file; $this->_current_file = $file_path;
$this->_current_line_no = 1; $this->_current_line_no = 1;
$ldq = preg_quote($this->left_delimiter, '!'); $ldq = preg_quote($this->left_delimiter, '!');
$rdq = preg_quote($this->right_delimiter, '!'); $rdq = preg_quote($this->right_delimiter, '!');
@@ -354,7 +354,7 @@ class Smarty_Compiler extends Smarty {
// put header at the top of the compiled template // put header at the top of the compiled template
$template_header = "<?php /* Smarty version ".$this->_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n"; $template_header = "<?php /* Smarty version ".$this->_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n";
$template_header .= " compiled from ".$tpl_file." */ ?>\n"; $template_header .= " compiled from ".$file_path." */ ?>\n";
/* Emit code to load needed plugins. */ /* Emit code to load needed plugins. */
$this->_plugins_code = ''; $this->_plugins_code = '';

View File

@@ -37,7 +37,7 @@ function smarty_core_display_debug_console($params, &$this)
$this->_compile_id = null; $this->_compile_id = null;
$_compile_path = $this->_get_compile_path($this->debug_tpl); $_compile_path = $this->_get_compile_path($this->debug_tpl);
if ($this->_compile_template($this->debug_tpl, $_compile_path)) if ($this->_compile_file($this->debug_tpl, $_compile_path))
{ {
ob_start(); ob_start();
include($_compile_path); include($_compile_path);

View File

@@ -36,7 +36,7 @@ function smarty_core_smarty_include($params, &$this)
if ($this->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path) if ($this->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path)
|| $this->_compile_template($params['smarty_include_tpl_file'], $_smarty_compile_path)) || $this->_compile_file($params['smarty_include_tpl_file'], $_smarty_compile_path))
{ {
include($_smarty_compile_path); include($_smarty_compile_path);
} }

View File

@@ -19,27 +19,27 @@
*/ */
function smarty_function_eval($params, &$smarty) function smarty_function_eval($params, &$smarty)
{ {
extract($params);
if (!isset($var)) { if (!isset($params['var'])) {
$smarty->trigger_error("eval: missing 'var' parameter"); $smarty->trigger_error("eval: missing 'var' parameter");
return; return;
} }
if($var == '') {
if($params['var'] == '') {
return; return;
} }
$smarty->_compile_template("evaluated template", $var, $source); $smarty->_compile_source('evaluated template', $params['var'], $_var_compiled);
ob_start(); ob_start();
eval('?>' . $source); eval('?>' . $_var_compiled);
$contents = ob_get_contents(); $_contents = ob_get_contents();
ob_end_clean(); ob_end_clean();
if (!empty($assign)) { if (!empty($assign)) {
$smarty->assign($assign, $contents); $smarty->assign($assign, $_contents);
} else { } else {
return $contents; return $_contents;
} }
} }