mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
split up _compile_template to _compile_file and _compile_source, fix eval function
VS: ----------------------------------------------------------------------
This commit is contained in:
@@ -1138,12 +1138,12 @@ reques * @var string
|
||||
/**
|
||||
* executes & returns or displays the template results
|
||||
*
|
||||
* @param string $tpl_file
|
||||
* @param string $file_path
|
||||
* @param string $cache_id
|
||||
* @param string $compile_id
|
||||
* @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();
|
||||
|
||||
@@ -1166,7 +1166,7 @@ reques * @var string
|
||||
require_once(SMARTY_DIR . 'core/core.get_microtime.php');
|
||||
$_debug_start_time = smarty_core_get_microtime($_params, $this);
|
||||
$this->_smarty_debug_info[] = array('type' => 'template',
|
||||
'filename' => $tpl_file,
|
||||
'filename' => $file_path,
|
||||
'depth' => 0);
|
||||
$_included_tpls_idx = count($this->_smarty_debug_info) - 1;
|
||||
}
|
||||
@@ -1183,7 +1183,7 @@ reques * @var string
|
||||
array_push($_cache_info, $this->_cache_info);
|
||||
$this->_cache_info = array();
|
||||
$_params = array(
|
||||
'tpl_file' => $tpl_file,
|
||||
'tpl_file' => $file_path,
|
||||
'cache_id' => $cache_id,
|
||||
'compile_id' => $compile_id,
|
||||
'results' => null
|
||||
@@ -1241,7 +1241,7 @@ reques * @var string
|
||||
return $_smarty_results;
|
||||
}
|
||||
} else {
|
||||
$this->_cache_info['template'][$tpl_file] = true;
|
||||
$this->_cache_info['template'][$file_path] = true;
|
||||
if ($this->cache_modified_check) {
|
||||
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
|
||||
// buffering - for speed
|
||||
if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) {
|
||||
if ($this->_is_compiled($tpl_file, $_smarty_compile_path)
|
||||
|| $this->_compile_template($tpl_file, $_smarty_compile_path))
|
||||
if ($this->_is_compiled($file_path, $_smarty_compile_path)
|
||||
|| $this->_compile_file($file_path, $_smarty_compile_path))
|
||||
{
|
||||
include($_smarty_compile_path);
|
||||
}
|
||||
} else {
|
||||
ob_start();
|
||||
if ($this->_is_compiled($tpl_file, $_smarty_compile_path)
|
||||
|| $this->_compile_template($tpl_file, $_smarty_compile_path))
|
||||
if ($this->_is_compiled($file_path, $_smarty_compile_path)
|
||||
|| $this->_compile_file($file_path, $_smarty_compile_path))
|
||||
{
|
||||
include($_smarty_compile_path);
|
||||
}
|
||||
@@ -1283,7 +1283,7 @@ reques * @var string
|
||||
}
|
||||
|
||||
if ($this->caching) {
|
||||
$_params = array('tpl_file' => $tpl_file,
|
||||
$_params = array('tpl_file' => $file_path,
|
||||
'cache_id' => $cache_id,
|
||||
'compile_id' => $compile_id,
|
||||
'results' => $_smarty_results);
|
||||
@@ -1460,15 +1460,14 @@ reques * @var string
|
||||
/**
|
||||
* compile the template
|
||||
*
|
||||
* @param string $tpl_file
|
||||
* @param string $file_path
|
||||
* @param string $compile_path
|
||||
* @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' => $tpl_file);
|
||||
$_params = array('file_path' => $file_path);
|
||||
require_once(SMARTY_DIR . 'core/core.fetch_file_info.php');
|
||||
if (!smarty_core_fetch_file_info($_params, $this)) {
|
||||
return false;
|
||||
@@ -1477,6 +1476,36 @@ reques * @var string
|
||||
$_file_source = $_params['file_source'];
|
||||
$_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)) {
|
||||
require_once(SMARTY_DIR . $this->compiler_file);
|
||||
} else {
|
||||
@@ -1512,25 +1541,9 @@ reques * @var string
|
||||
$smarty_compiler->_cache_serial = null;
|
||||
$smarty_compiler->_cache_include = substr($compile_path, 0, -4).'.inc';
|
||||
|
||||
if ($smarty_compiler->_compile_file($tpl_file, $_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);
|
||||
return $smarty_compiler->_compile_file($file_path, $file_source, $file_compiled);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the compile path for this template file
|
||||
|
@@ -221,7 +221,7 @@ class Smarty_Compiler extends Smarty {
|
||||
* @param string $file_compiled
|
||||
* @return true
|
||||
*/
|
||||
function _compile_file($tpl_file, $file_source, &$file_compiled)
|
||||
function _compile_file($file_path, $file_source, &$file_compiled)
|
||||
{
|
||||
|
||||
if ($this->security) {
|
||||
@@ -234,7 +234,7 @@ class Smarty_Compiler extends Smarty {
|
||||
|
||||
$this->_load_filters();
|
||||
|
||||
$this->_current_file = $tpl_file;
|
||||
$this->_current_file = $file_path;
|
||||
$this->_current_line_no = 1;
|
||||
$ldq = preg_quote($this->left_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
|
||||
$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. */
|
||||
$this->_plugins_code = '';
|
||||
|
@@ -37,7 +37,7 @@ function smarty_core_display_debug_console($params, &$this)
|
||||
$this->_compile_id = null;
|
||||
|
||||
$_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();
|
||||
include($_compile_path);
|
||||
|
@@ -36,7 +36,7 @@ function smarty_core_smarty_include($params, &$this)
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
@@ -19,27 +19,27 @@
|
||||
*/
|
||||
function smarty_function_eval($params, &$smarty)
|
||||
{
|
||||
extract($params);
|
||||
|
||||
if (!isset($var)) {
|
||||
if (!isset($params['var'])) {
|
||||
$smarty->trigger_error("eval: missing 'var' parameter");
|
||||
return;
|
||||
}
|
||||
if($var == '') {
|
||||
|
||||
if($params['var'] == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$smarty->_compile_template("evaluated template", $var, $source);
|
||||
$smarty->_compile_source('evaluated template', $params['var'], $_var_compiled);
|
||||
|
||||
ob_start();
|
||||
eval('?>' . $source);
|
||||
$contents = ob_get_contents();
|
||||
eval('?>' . $_var_compiled);
|
||||
$_contents = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
if (!empty($assign)) {
|
||||
$smarty->assign($assign, $contents);
|
||||
$smarty->assign($assign, $_contents);
|
||||
} else {
|
||||
return $contents;
|
||||
return $_contents;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user