mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
removed $this from smarty_include and smarty_include_php
added cleaner handling of $this to {eval}
This commit is contained in:
@@ -1492,15 +1492,16 @@ class Smarty
|
|||||||
$_resource_timestamp = $_params['resource_timestamp'];
|
$_resource_timestamp = $_params['resource_timestamp'];
|
||||||
|
|
||||||
if ($this->_compile_source($resource_name, $_source_content, $_compiled_content)) {
|
if ($this->_compile_source($resource_name, $_source_content, $_compiled_content)) {
|
||||||
$_params = array('compile_path'=>$compile_path, 'compiled_content' => $_compiled_content, 'resource_timestamp' => $_resource_timestamp);
|
|
||||||
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_compiled_resource.php');
|
|
||||||
smarty_core_write_compiled_resource($_params, $this);
|
|
||||||
|
|
||||||
// if a _cache_serial was set, we also have to write an include-file:
|
// if a _cache_serial was set, we also have to write an include-file:
|
||||||
if ($this->_cache_include_info) {
|
if ($this->_cache_include_info) {
|
||||||
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_compiled_include.php');
|
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_compiled_include.php');
|
||||||
smarty_core_write_compiled_include(array_merge($this->_cache_include_info, array('compiled_content'=>$_compiled_content)), $this);
|
smarty_core_write_compiled_include(array_merge($this->_cache_include_info, array('compiled_content'=>$_compiled_content)), $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$_params = array('compile_path'=>$compile_path, 'compiled_content' => $_compiled_content, 'resource_timestamp' => $_resource_timestamp);
|
||||||
|
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_compiled_resource.php');
|
||||||
|
smarty_core_write_compiled_resource($_params, $this);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
$this->trigger_error($smarty_compiler->_error_msg);
|
$this->trigger_error($smarty_compiler->_error_msg);
|
||||||
@@ -1526,6 +1527,7 @@ class Smarty
|
|||||||
require_once($this->compiler_file);
|
require_once($this->compiler_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$smarty_compiler = new $this->compiler_class;
|
$smarty_compiler = new $this->compiler_class;
|
||||||
|
|
||||||
$smarty_compiler->template_dir = $this->template_dir;
|
$smarty_compiler->template_dir = $this->template_dir;
|
||||||
@@ -1771,8 +1773,6 @@ class Smarty
|
|||||||
return (is_array($function)) ?
|
return (is_array($function)) ?
|
||||||
method_exists($function[0], $function[1]) : function_exists($function);
|
method_exists($function[0], $function[1]) : function_exists($function);
|
||||||
}
|
}
|
||||||
/**#@-*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1788,6 +1788,31 @@ class Smarty
|
|||||||
return $_ret;
|
return $_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wrapper for include() retaining $this
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function smarty_include($filename, $once=false)
|
||||||
|
{
|
||||||
|
if ($once) {
|
||||||
|
return include_once($filename);
|
||||||
|
} else {
|
||||||
|
return include($filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wrapper for eval() retaining $this
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function smarty_eval($code)
|
||||||
|
{
|
||||||
|
return eval($code);
|
||||||
|
}
|
||||||
|
/**#@-*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set expandtab: */
|
/* vim: set expandtab: */
|
||||||
|
@@ -14,47 +14,47 @@
|
|||||||
|
|
||||||
// $_smarty_include_tpl_file, $_smarty_include_vars
|
// $_smarty_include_tpl_file, $_smarty_include_vars
|
||||||
|
|
||||||
function smarty_core_smarty_include($params, &$this)
|
function smarty_core_smarty_include($params, &$smarty)
|
||||||
{
|
{
|
||||||
if ($this->debugging) {
|
if ($smarty->debugging) {
|
||||||
$_params = array();
|
$_params = array();
|
||||||
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php');
|
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php');
|
||||||
$debug_start_time = smarty_core_get_microtime($_params, $this);
|
$debug_start_time = smarty_core_get_microtime($_params, $smarty);
|
||||||
$this->_smarty_debug_info[] = array('type' => 'template',
|
$smarty->_smarty_debug_info[] = array('type' => 'template',
|
||||||
'filename' => $params['smarty_include_tpl_file'],
|
'filename' => $params['smarty_include_tpl_file'],
|
||||||
'depth' => ++$this->_inclusion_depth);
|
'depth' => ++$smarty->_inclusion_depth);
|
||||||
$included_tpls_idx = count($this->_smarty_debug_info) - 1;
|
$included_tpls_idx = count($smarty->_smarty_debug_info) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_tpl_vars = array_merge($this->_tpl_vars, $params['smarty_include_vars']);
|
$smarty->_tpl_vars = array_merge($smarty->_tpl_vars, $params['smarty_include_vars']);
|
||||||
|
|
||||||
// config vars are treated as local, so push a copy of the
|
// config vars are treated as local, so push a copy of the
|
||||||
// current ones onto the front of the stack
|
// current ones onto the front of the stack
|
||||||
array_unshift($this->_config, $this->_config[0]);
|
array_unshift($smarty->_config, $smarty->_config[0]);
|
||||||
|
|
||||||
$_smarty_compile_path = $this->_get_compile_path($params['smarty_include_tpl_file']);
|
$_smarty_compile_path = $smarty->_get_compile_path($params['smarty_include_tpl_file']);
|
||||||
|
|
||||||
|
|
||||||
if ($this->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path)
|
if ($smarty->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path)
|
||||||
|| $this->_compile_resource($params['smarty_include_tpl_file'], $_smarty_compile_path))
|
|| $smarty->_compile_resource($params['smarty_include_tpl_file'], $_smarty_compile_path))
|
||||||
{
|
{
|
||||||
include($_smarty_compile_path);
|
$smarty->smarty_include($_smarty_compile_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pop the local vars off the front of the stack
|
// pop the local vars off the front of the stack
|
||||||
array_shift($this->_config);
|
array_shift($smarty->_config);
|
||||||
|
|
||||||
$this->_inclusion_depth--;
|
$smarty->_inclusion_depth--;
|
||||||
|
|
||||||
if ($this->debugging) {
|
if ($smarty->debugging) {
|
||||||
// capture time for debugging info
|
// capture time for debugging info
|
||||||
$_params = array();
|
$_params = array();
|
||||||
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php');
|
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php');
|
||||||
$this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $debug_start_time;
|
$smarty->_smarty_debug_info[$included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $smarty) - $debug_start_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->caching) {
|
if ($smarty->caching) {
|
||||||
$this->_cache_info['template'][$params['smarty_include_tpl_file']] = true;
|
$smarty->_cache_info['template'][$params['smarty_include_tpl_file']] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,40 +16,32 @@
|
|||||||
* {include file="blah" var=$var}
|
* {include file="blah" var=$var}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// $file, $assign, $once, $_smarty_include_vars
|
// $file, $assign, $once, $_smarty_include_vars
|
||||||
|
|
||||||
function smarty_core_smarty_include_php($params, &$this)
|
function smarty_core_smarty_include_php($params, &$smarty)
|
||||||
{
|
{
|
||||||
$_params = array('resource_name' => $params['smarty_file']);
|
$_params = array('resource_name' => $params['smarty_file']);
|
||||||
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_php_resource.php');
|
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_php_resource.php');
|
||||||
smarty_core_get_php_resource($_params, $this);
|
smarty_core_get_php_resource($_params, $smarty);
|
||||||
$_smarty_resource_type = $_params['resource_type'];
|
$_smarty_resource_type = $_params['resource_type'];
|
||||||
$_smarty_php_resource = $_params['php_resource'];
|
$_smarty_php_resource = $_params['php_resource'];
|
||||||
|
|
||||||
extract($params['smarty_include_vars'], EXTR_PREFIX_SAME, 'include_php_');
|
extract($params['smarty_include_vars'], EXTR_PREFIX_SAME, 'include_php_');
|
||||||
|
|
||||||
if (!empty($params['smarty_assign'])) {
|
if (!empty($params['smarty_assign'])) {
|
||||||
ob_start();
|
ob_start();
|
||||||
if ($_smarty_resource_type == 'file') {
|
if ($_smarty_resource_type == 'file') {
|
||||||
if($params['smarty_once']) {
|
$smarty->smarty_include($_smarty_php_resource, $params['smarty_once']);
|
||||||
include_once($_smarty_php_resource);
|
|
||||||
} else {
|
|
||||||
include($_smarty_php_resource);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
eval($_smarty_php_resource);
|
$smarty->smarty_eval($_smarty_php_resource);
|
||||||
}
|
}
|
||||||
$this->assign($params['smarty_assign'], ob_get_contents());
|
$smarty->assign($params['smarty_assign'], ob_get_contents());
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
} else {
|
} else {
|
||||||
if ($_smarty_resource_type == 'file') {
|
if ($_smarty_resource_type == 'file') {
|
||||||
if($params['smarty_once']) {
|
$smarty->smarty_include($_smarty_php_resource, $params['smarty_once']);
|
||||||
include_once($_smarty_php_resource);
|
|
||||||
} else {
|
|
||||||
include($_smarty_php_resource);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
eval($_smarty_php_resource);
|
$smarty->smarty_eval($_smarty_php_resource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,8 +32,7 @@ function smarty_function_eval($params, &$smarty)
|
|||||||
$smarty->_compile_source('evaluated template', $params['var'], $_var_compiled);
|
$smarty->_compile_source('evaluated template', $params['var'], $_var_compiled);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$this =& $smarty; /* this should be done nicer, maybe */
|
$smarty->smarty_eval('?>' . $_var_compiled);
|
||||||
eval('?>' . $_var_compiled);
|
|
||||||
$_contents = ob_get_contents();
|
$_contents = ob_get_contents();
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user