diff --git a/change_log.txt b/change_log.txt index 5a7b52fb..574c0266 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,3 +1,9 @@ +06/07/2010 +- create exception on recursive {extends} calls +- fixed reported line number at "unexpected closing tag " exception +- bugfix on escape:'mail' modifier +- drop exception if 'item' variable is equal 'from' variable in {foreach} tag + 01/07/2010 - removed call_user_func_array calls for optimization of compiled code when using registered modifiers and plugins diff --git a/libs/plugins/modifier.escape.php b/libs/plugins/modifier.escape.php index c35e67ae..46368867 100644 --- a/libs/plugins/modifier.escape.php +++ b/libs/plugins/modifier.escape.php @@ -1,39 +1,43 @@ -* Name: escape
-* Purpose: escape string for output -* -* @link http://smarty.php.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online manual) -* @author Monte Ohrt -* @param string $string input string -* @param string $esc_type escape type -* @param string $char_set character set -* @return string escaped input string -*/ + * Smarty escape modifier plugin + * + * Type: modifier
+ * Name: escape
+ * Purpose: escape string for output + * + * @link http://smarty.php.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online manual) + * @author Monte Ohrt + * @param string $string input string + * @param string $esc_type escape type + * @param string $char_set character set + * @return string escaped input string + */ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = SMARTY_RESOURCE_CHAR_SET) { - if (!function_exists('mb_str_replace') && function_exists('mb_strlen')) { + if (!function_exists('mb_str_replace')) { // simulate the missing PHP mb_str_replace function - function mb_str_replace($needle, $replacement, $haystack) + function mb_str_replace($needles, $replacements, $haystack) { - $needle_len = mb_strlen($needle); - $replacement_len = mb_strlen($replacement); - $pos = mb_strpos($haystack, $needle, 0); - while ($pos !== false) { - $haystack = mb_substr($haystack, 0, $pos) . $replacement - . mb_substr($haystack, $pos + $needle_len); - $pos = mb_strpos($haystack, $needle, $pos + $replacement_len); + $rep = (array)$replacements; + foreach ((array)$needles as $key => $needle) { + $replacement = $rep[$key]; + $needle_len = mb_strlen($needle); + $replacement_len = mb_strlen($replacement); + $pos = mb_strpos($haystack, $needle, 0); + while ($pos !== false) { + $haystack = mb_substr($haystack, 0, $pos) . $replacement + . mb_substr($haystack, $pos + $needle_len); + $pos = mb_strpos($haystack, $needle, $pos + $replacement_len); + } } return $haystack; } @@ -83,7 +87,7 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = SMARTY_ case 'mail': // safe way to display e-mail address on a web page - if (function_exists('mb_str_replace')) { + if (function_exists('mb_substr')) { return mb_str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string); } else { return str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string); @@ -108,4 +112,4 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = SMARTY_ } } -?> +?> \ No newline at end of file diff --git a/libs/plugins/modifier.replace.php b/libs/plugins/modifier.replace.php index 5f70979f..80f67e29 100644 --- a/libs/plugins/modifier.replace.php +++ b/libs/plugins/modifier.replace.php @@ -1,39 +1,43 @@ -* Name: replace
-* Purpose: simple search/replace -* -* @link http://smarty.php.net/manual/en/language.modifier.replace.php replace (Smarty online manual) -* @author Monte Ohrt -* @author Uwe Tews -* @param string $ -* @param string $ -* @param string $ -* @return string -*/ + * Smarty replace modifier plugin + * + * Type: modifier
+ * Name: replace
+ * Purpose: simple search/replace + * + * @link http://smarty.php.net/manual/en/language.modifier.replace.php replace (Smarty online manual) + * @author Monte Ohrt + * @author Uwe Tews + * @param string $ + * @param string $ + * @param string $ + * @return string + */ function smarty_modifier_replace($string, $search, $replace) { - if (!function_exists("mb_str_replace")) { + if (!function_exists('mb_str_replace')) { // simulate the missing PHP mb_str_replace function - function mb_str_replace($needle, $replacement, $haystack) + function mb_str_replace($needles, $replacements, $haystack) { - $needle_len = mb_strlen($needle); - $replacement_len = mb_strlen($replacement); - $pos = mb_strpos($haystack, $needle, 0); - while ($pos !== false) { - $haystack = mb_substr($haystack, 0, $pos) . $replacement - . mb_substr($haystack, $pos + $needle_len); - $pos = mb_strpos($haystack, $needle, $pos + $replacement_len); + $rep = (array)$replacements; + foreach ((array)$needles as $key => $needle) { + $replacement = $rep[$key]; + $needle_len = mb_strlen($needle); + $replacement_len = mb_strlen($replacement); + $pos = mb_strpos($haystack, $needle, 0); + while ($pos !== false) { + $haystack = mb_substr($haystack, 0, $pos) . $replacement + . mb_substr($haystack, $pos + $needle_len); + $pos = mb_strpos($haystack, $needle, $pos + $replacement_len); + } } return $haystack; } @@ -45,4 +49,4 @@ function smarty_modifier_replace($string, $search, $replace) } } -?> +?> \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_compile_extends.php b/libs/sysplugins/smarty_internal_compile_extends.php index 3f5997a4..fca17422 100644 --- a/libs/sysplugins/smarty_internal_compile_extends.php +++ b/libs/sysplugins/smarty_internal_compile_extends.php @@ -35,7 +35,11 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase { // create template object $_template = new $compiler->smarty->template_class($include_file, $this->smarty, $compiler->template); // save file dependency - $compiler->template->properties['file_dependency'][sha1($_template->getTemplateFilepath())] = array($_template->getTemplateFilepath(), $_template->getTemplateTimestamp()); + $template_sha1 = sha1($_template->getTemplateFilepath()); + if (isset($compiler->template->properties['file_dependency'][$template_sha1])) { + $this->compiler->trigger_template_error("illegal recursive call of \"{$include_file}\"",$compiler->lex->line-1); + } + $compiler->template->properties['file_dependency'][$template_sha1] = array($_template->getTemplateFilepath(), $_template->getTemplateTimestamp()); $_content = $compiler->template->template_source; if (preg_match_all("!({$this->_ldl}block\s(.+?){$this->_rdl})!", $_content, $s) != preg_match_all("!({$this->_ldl}/block(.*?){$this->_rdl})!", $_content, $c)) { @@ -71,8 +75,8 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase { if (0 == preg_match("!(.?)(name=)(.*?)(?=(\s|{$this->_rdl}))!", $block_tag, $_match)) { $this->compiler->trigger_template_error("\"" . $block_tag . "\" missing name attribute"); } else { - $_name = trim($_match[3], '\'"'); - // replace {$smarty.block.child} + $_name = trim($_match[3], '\'"'); + // replace {$smarty.block.child} if (strpos($block_content, $this->smarty->left_delimiter . '$smarty.block.child' . $this->smarty->right_delimiter) !== false) { if (isset($this->smarty->block_data[$_name])) { $block_content = str_replace($this->smarty->left_delimiter . '$smarty.block.child' . $this->smarty->right_delimiter, diff --git a/libs/sysplugins/smarty_internal_compile_foreach.php b/libs/sysplugins/smarty_internal_compile_foreach.php index 69a2a621..54440319 100644 --- a/libs/sysplugins/smarty_internal_compile_foreach.php +++ b/libs/sysplugins/smarty_internal_compile_foreach.php @@ -31,6 +31,10 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase { $from = $_attr['from']; $item = $_attr['item']; + if (substr_compare("\$_smarty_tpl->getVariable($item)", $from,0, strlen("\$_smarty_tpl->getVariable($item)")) == 0) { + $this->compiler->trigger_template_error("item parameter {$item} may not be the same parameter at 'from'"); + } + if (isset($_attr['key'])) { $key = $_attr['key']; } else { diff --git a/libs/sysplugins/smarty_internal_compilebase.php b/libs/sysplugins/smarty_internal_compilebase.php index 7a398f53..9485eacd 100644 --- a/libs/sysplugins/smarty_internal_compilebase.php +++ b/libs/sysplugins/smarty_internal_compilebase.php @@ -95,9 +95,9 @@ abstract class Smarty_Internal_CompileBase return; } // wrong nesting of tags - $this->compiler->trigger_template_error("unexpected closing tag"); + $this->compiler->trigger_template_error("unexpected closing tag",$this->compiler->lex->taglineno); return; } } -?> +?> \ No newline at end of file