diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 1cbbfd23..533488cd 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -1492,15 +1492,16 @@ class Smarty $_resource_timestamp = $_params['resource_timestamp']; 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 ($this->_cache_include_info) { 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); } + + $_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; } else { $this->trigger_error($smarty_compiler->_error_msg); @@ -1526,6 +1527,7 @@ class Smarty require_once($this->compiler_file); } + $smarty_compiler = new $this->compiler_class; $smarty_compiler->template_dir = $this->template_dir; @@ -1771,8 +1773,6 @@ class Smarty return (is_array($function)) ? method_exists($function[0], $function[1]) : function_exists($function); } - /**#@-*/ - /** @@ -1788,6 +1788,31 @@ class Smarty 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: */ diff --git a/libs/core/core.smarty_include.php b/libs/core/core.smarty_include.php index a7a24946..d3c86430 100644 --- a/libs/core/core.smarty_include.php +++ b/libs/core/core.smarty_include.php @@ -14,47 +14,47 @@ // $_smarty_include_tpl_file, $_smarty_include_vars -function smarty_core_smarty_include($params, &$this) +function smarty_core_smarty_include($params, &$smarty) { - if ($this->debugging) { - $_params = array(); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php'); - $debug_start_time = smarty_core_get_microtime($_params, $this); - $this->_smarty_debug_info[] = array('type' => 'template', + if ($smarty->debugging) { + $_params = array(); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php'); + $debug_start_time = smarty_core_get_microtime($_params, $smarty); + $smarty->_smarty_debug_info[] = array('type' => 'template', 'filename' => $params['smarty_include_tpl_file'], - 'depth' => ++$this->_inclusion_depth); - $included_tpls_idx = count($this->_smarty_debug_info) - 1; + 'depth' => ++$smarty->_inclusion_depth); + $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 // 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) - || $this->_compile_resource($params['smarty_include_tpl_file'], $_smarty_compile_path)) + if ($smarty->_is_compiled($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 - 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 - $_params = array(); - 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; + $_params = array(); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php'); + $smarty->_smarty_debug_info[$included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $smarty) - $debug_start_time; } - if ($this->caching) { - $this->_cache_info['template'][$params['smarty_include_tpl_file']] = true; + if ($smarty->caching) { + $smarty->_cache_info['template'][$params['smarty_include_tpl_file']] = true; } } diff --git a/libs/core/core.smarty_include_php.php b/libs/core/core.smarty_include_php.php index 71210091..c7c2dbdd 100644 --- a/libs/core/core.smarty_include_php.php +++ b/libs/core/core.smarty_include_php.php @@ -16,40 +16,32 @@ * {include file="blah" var=$var} */ -// $file, $assign, $once, $_smarty_include_vars - -function smarty_core_smarty_include_php($params, &$this) +// $file, $assign, $once, $_smarty_include_vars + +function smarty_core_smarty_include_php($params, &$smarty) { - $_params = array('resource_name' => $params['smarty_file']); - require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_php_resource.php'); - smarty_core_get_php_resource($_params, $this); - $_smarty_resource_type = $_params['resource_type']; - $_smarty_php_resource = $_params['php_resource']; + $_params = array('resource_name' => $params['smarty_file']); + require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_php_resource.php'); + smarty_core_get_php_resource($_params, $smarty); + $_smarty_resource_type = $_params['resource_type']; + $_smarty_php_resource = $_params['php_resource']; extract($params['smarty_include_vars'], EXTR_PREFIX_SAME, 'include_php_'); if (!empty($params['smarty_assign'])) { ob_start(); if ($_smarty_resource_type == 'file') { - if($params['smarty_once']) { - include_once($_smarty_php_resource); - } else { - include($_smarty_php_resource); - } + $smarty->smarty_include($_smarty_php_resource, $params['smarty_once']); } 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(); } else { if ($_smarty_resource_type == 'file') { - if($params['smarty_once']) { - include_once($_smarty_php_resource); - } else { - include($_smarty_php_resource); - } + $smarty->smarty_include($_smarty_php_resource, $params['smarty_once']); } else { - eval($_smarty_php_resource); + $smarty->smarty_eval($_smarty_php_resource); } } } diff --git a/libs/plugins/function.eval.php b/libs/plugins/function.eval.php index c72ceeff..fd65e2e2 100644 --- a/libs/plugins/function.eval.php +++ b/libs/plugins/function.eval.php @@ -32,8 +32,7 @@ function smarty_function_eval($params, &$smarty) $smarty->_compile_source('evaluated template', $params['var'], $_var_compiled); ob_start(); - $this =& $smarty; /* this should be done nicer, maybe */ - eval('?>' . $_var_compiled); + $smarty->smarty_eval('?>' . $_var_compiled); $_contents = ob_get_contents(); ob_end_clean();