From 2bce12e9e00437daa5e9c294ad72391770fc87f4 Mon Sep 17 00:00:00 2001 From: mohrt Date: Mon, 10 Feb 2003 20:59:08 +0000 Subject: [PATCH] add support for $foo->$bar syntax --- NEWS | 1 + Smarty_Compiler.class.php | 21 +++++++++++++++------ libs/Smarty_Compiler.class.php | 21 +++++++++++++++------ 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/NEWS b/NEWS index ac0b78d5..2951ed1b 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,4 @@ + - support embedded variables in objects (Monte) - fix bug with objects with no properties (M Mohr, Monte) - support full dollar var syntax in quoted text (Monte) - fixed bug in $smarty.const.FOO introduced in 2.4.1 (M diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index 6e0f53c1..aae73a17 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -1495,7 +1495,7 @@ class Smarty_Compiler extends Smarty { $indexes = $match[0]; $var_name = array_shift($indexes); - + /* Handle $smarty.* variable references as a special case. */ if ($var_name == 'smarty') { /* @@ -1513,8 +1513,7 @@ class Smarty_Compiler extends Smarty { $output = "\$this->_tpl_vars['$var_name']"; } - foreach ($indexes as $index) { - + foreach ($indexes as $index) { if ($index{0} == '[') { $index = substr($index, 1, -1); if (is_numeric($index)) { @@ -1538,9 +1537,19 @@ class Smarty_Compiler extends Smarty { } elseif($this->security && substr($index,2,1) == '_') { $this->_syntax_error('(secure) call to private object member is not allowed', E_USER_ERROR, __FILE__, __LINE__); } else { - // parse each parameter to the object - if(preg_match('!(?:' . $this->_obj_ext_regexp . ')+(?:(' . $this->_obj_params_regexp . '))?!', $index, $match)) { - $index = str_replace($match[1], $this->_parse_parenth_args($match[1]), $index); + if(preg_match('!((?:' . $this->_obj_ext_regexp . ')+)(' . $this->_obj_params_regexp . ')?!', $index, $match)) { + if(!empty($match[2])) { + // parse object parameters + $index = str_replace($match[2], $this->_parse_parenth_args($match[2]), $index); + } + if(preg_match_all('!' . $this->_dvar_regexp . '!', $match[1], $_dvar_match)) { + // parse embedded variables + $_match_replace = $match[1]; + foreach($_dvar_match[0] as $_curr_var) { + $_match_replace = str_replace($_curr_var, '{' . $this->_parse_var($_curr_var) . '}', $_match_replace); + } + $index = str_replace($match[1], $_match_replace, $index); + } } $output .= $index; } diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index 6e0f53c1..aae73a17 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -1495,7 +1495,7 @@ class Smarty_Compiler extends Smarty { $indexes = $match[0]; $var_name = array_shift($indexes); - + /* Handle $smarty.* variable references as a special case. */ if ($var_name == 'smarty') { /* @@ -1513,8 +1513,7 @@ class Smarty_Compiler extends Smarty { $output = "\$this->_tpl_vars['$var_name']"; } - foreach ($indexes as $index) { - + foreach ($indexes as $index) { if ($index{0} == '[') { $index = substr($index, 1, -1); if (is_numeric($index)) { @@ -1538,9 +1537,19 @@ class Smarty_Compiler extends Smarty { } elseif($this->security && substr($index,2,1) == '_') { $this->_syntax_error('(secure) call to private object member is not allowed', E_USER_ERROR, __FILE__, __LINE__); } else { - // parse each parameter to the object - if(preg_match('!(?:' . $this->_obj_ext_regexp . ')+(?:(' . $this->_obj_params_regexp . '))?!', $index, $match)) { - $index = str_replace($match[1], $this->_parse_parenth_args($match[1]), $index); + if(preg_match('!((?:' . $this->_obj_ext_regexp . ')+)(' . $this->_obj_params_regexp . ')?!', $index, $match)) { + if(!empty($match[2])) { + // parse object parameters + $index = str_replace($match[2], $this->_parse_parenth_args($match[2]), $index); + } + if(preg_match_all('!' . $this->_dvar_regexp . '!', $match[1], $_dvar_match)) { + // parse embedded variables + $_match_replace = $match[1]; + foreach($_dvar_match[0] as $_curr_var) { + $_match_replace = str_replace($_curr_var, '{' . $this->_parse_var($_curr_var) . '}', $_match_replace); + } + $index = str_replace($match[1], $_match_replace, $index); + } } $output .= $index; }