From dd56027476a5cd02698006b863ede1d70431aa1e Mon Sep 17 00:00:00 2001 From: andrei Date: Wed, 3 Apr 2002 16:31:59 +0000 Subject: [PATCH] - Added $smarty.template variable. - Fixed {include_php} tag when dynamic values were used for 'file' attribute. --- NEWS | 5 ++++- Smarty.class.php | 27 +++++++++++++++++++++++++++ Smarty_Compiler.class.php | 30 ++++++++++-------------------- libs/Smarty.class.php | 27 +++++++++++++++++++++++++++ libs/Smarty_Compiler.class.php | 30 ++++++++++-------------------- 5 files changed, 78 insertions(+), 41 deletions(-) diff --git a/NEWS b/NEWS index 7beca4e8..ccc8fba5 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ + - fixed a problem with using dynamic values for 'file' + attribute of {include_php} tag. (Andrei) + - added $smarty.template variable. (Andrei) - fixed several plugins that would not work if the plugin directory was not the default one. (Andrei) - implemented support for block functions. (Andrei) @@ -339,4 +342,4 @@ Version 1.0 ------------ - initial release -/* vim: set et tw=64: */ +/* vim: set et tw=64 ft=changelog: */ diff --git a/Smarty.class.php b/Smarty.class.php index 905f9070..407315f5 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -1008,6 +1008,33 @@ function _generate_debug_output() { } } +/*======================================================================*\ + Function: _smarty_include_php() + Purpose: called for included templates +\*======================================================================*/ + function _smarty_include_php($_smarty_include_php_file, $_smarty_assign) + { + $this->_get_php_resource($_smarty_include_php_file, $_smarty_resource_type, + $_smarty_php_resource); + + if (!empty($_smarty_assign)) { + ob_start(); + if ($_smarty_resource_type == 'file') { + include_once($_smarty_php_resource); + } else { + eval($_smarty_php_resource); + } + $this->assign($_smarty_assign, ob_get_contents()); + ob_end_clean(); + } else { + if ($_smarty_resource_type == 'file') { + include_once($_smarty_php_resource); + } else { + eval($_smarty_php_resource); + } + } + } + /*======================================================================*\ Function: _config_load Purpose: load configuration values diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index 0b55cf95..40178f7a 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -632,27 +632,10 @@ class Smarty_Compiler extends Smarty { if (empty($attrs['file'])) { $this->_syntax_error("missing 'file' attribute in include_php tag"); } + + $assign_var = $this->_dequote($attrs['assign']); - $this->_get_php_resource($this->_dequote($attrs['file']), - $resource_type, $php_resource); - - if (!empty($attrs['assign'])) { - $output = "assign(" . $attrs['assign'] . ", ob_get_contents()); ob_end_clean();\n?>"; - } else { - if ($resource_type == 'file') { - $output = ''; - } else { - $output = ''; - } - } - - return $output; + return "_smarty_include_php($attrs[file], '$assign_var'); ?>"; } @@ -1350,6 +1333,13 @@ class Smarty_Compiler extends Smarty { case 'capture': return null; + case 'template': + $compiled_ref = "'$this->_current_file'"; + if (count($indexes) > 1) { + $this->_syntax_error('$smarty' . implode('', $indexes) .' is an invalid reference'); + } + break; + default: $this->_syntax_error('$smarty.' . $ref . ' is an unknown reference'); break; diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 905f9070..407315f5 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -1008,6 +1008,33 @@ function _generate_debug_output() { } } +/*======================================================================*\ + Function: _smarty_include_php() + Purpose: called for included templates +\*======================================================================*/ + function _smarty_include_php($_smarty_include_php_file, $_smarty_assign) + { + $this->_get_php_resource($_smarty_include_php_file, $_smarty_resource_type, + $_smarty_php_resource); + + if (!empty($_smarty_assign)) { + ob_start(); + if ($_smarty_resource_type == 'file') { + include_once($_smarty_php_resource); + } else { + eval($_smarty_php_resource); + } + $this->assign($_smarty_assign, ob_get_contents()); + ob_end_clean(); + } else { + if ($_smarty_resource_type == 'file') { + include_once($_smarty_php_resource); + } else { + eval($_smarty_php_resource); + } + } + } + /*======================================================================*\ Function: _config_load Purpose: load configuration values diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index 0b55cf95..40178f7a 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -632,27 +632,10 @@ class Smarty_Compiler extends Smarty { if (empty($attrs['file'])) { $this->_syntax_error("missing 'file' attribute in include_php tag"); } + + $assign_var = $this->_dequote($attrs['assign']); - $this->_get_php_resource($this->_dequote($attrs['file']), - $resource_type, $php_resource); - - if (!empty($attrs['assign'])) { - $output = "assign(" . $attrs['assign'] . ", ob_get_contents()); ob_end_clean();\n?>"; - } else { - if ($resource_type == 'file') { - $output = ''; - } else { - $output = ''; - } - } - - return $output; + return "_smarty_include_php($attrs[file], '$assign_var'); ?>"; } @@ -1350,6 +1333,13 @@ class Smarty_Compiler extends Smarty { case 'capture': return null; + case 'template': + $compiled_ref = "'$this->_current_file'"; + if (count($indexes) > 1) { + $this->_syntax_error('$smarty' . implode('', $indexes) .' is an invalid reference'); + } + break; + default: $this->_syntax_error('$smarty.' . $ref . ' is an unknown reference'); break;