- 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
This commit is contained in:
Uwe.Tews
2010-07-06 20:00:41 +00:00
parent cbe2f3356f
commit c83ef6792c
6 changed files with 85 additions and 63 deletions

View File

@@ -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 01/07/2010
- removed call_user_func_array calls for optimization of compiled code when using registered modifiers and plugins - removed call_user_func_array calls for optimization of compiled code when using registered modifiers and plugins

View File

@@ -1,39 +1,43 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifier * @subpackage PluginsModifier
*/ */
/** /**
* Smarty escape modifier plugin * Smarty escape modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: escape<br> * Name: escape<br>
* Purpose: escape string for output * Purpose: escape string for output
* *
* @link http://smarty.php.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online manual) * @link http://smarty.php.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @param string $string input string * @param string $string input string
* @param string $esc_type escape type * @param string $esc_type escape type
* @param string $char_set character set * @param string $char_set character set
* @return string escaped input string * @return string escaped input string
*/ */
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = SMARTY_RESOURCE_CHAR_SET) 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 // 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); $rep = (array)$replacements;
$replacement_len = mb_strlen($replacement); foreach ((array)$needles as $key => $needle) {
$pos = mb_strpos($haystack, $needle, 0); $replacement = $rep[$key];
while ($pos !== false) { $needle_len = mb_strlen($needle);
$haystack = mb_substr($haystack, 0, $pos) . $replacement $replacement_len = mb_strlen($replacement);
. mb_substr($haystack, $pos + $needle_len); $pos = mb_strpos($haystack, $needle, 0);
$pos = mb_strpos($haystack, $needle, $pos + $replacement_len); 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; return $haystack;
} }
@@ -83,7 +87,7 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = SMARTY_
case 'mail': case 'mail':
// safe way to display e-mail address on a web page // 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); return mb_str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
} else { } else {
return str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string); return str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
@@ -108,4 +112,4 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = SMARTY_
} }
} }
?> ?>

View File

@@ -1,39 +1,43 @@
<?php <?php
/** /**
* Smarty plugin * Smarty plugin
* *
* @package Smarty * @package Smarty
* @subpackage PluginsModifier * @subpackage PluginsModifier
*/ */
/** /**
* Smarty replace modifier plugin * Smarty replace modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: replace<br> * Name: replace<br>
* Purpose: simple search/replace * Purpose: simple search/replace
* *
* @link http://smarty.php.net/manual/en/language.modifier.replace.php replace (Smarty online manual) * @link http://smarty.php.net/manual/en/language.modifier.replace.php replace (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author Uwe Tews * @author Uwe Tews
* @param string $ * @param string $
* @param string $ * @param string $
* @param string $ * @param string $
* @return string * @return string
*/ */
function smarty_modifier_replace($string, $search, $replace) 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 // 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); $rep = (array)$replacements;
$replacement_len = mb_strlen($replacement); foreach ((array)$needles as $key => $needle) {
$pos = mb_strpos($haystack, $needle, 0); $replacement = $rep[$key];
while ($pos !== false) { $needle_len = mb_strlen($needle);
$haystack = mb_substr($haystack, 0, $pos) . $replacement $replacement_len = mb_strlen($replacement);
. mb_substr($haystack, $pos + $needle_len); $pos = mb_strpos($haystack, $needle, 0);
$pos = mb_strpos($haystack, $needle, $pos + $replacement_len); 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; return $haystack;
} }
@@ -45,4 +49,4 @@ function smarty_modifier_replace($string, $search, $replace)
} }
} }
?> ?>

View File

@@ -35,7 +35,11 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
// create template object // create template object
$_template = new $compiler->smarty->template_class($include_file, $this->smarty, $compiler->template); $_template = new $compiler->smarty->template_class($include_file, $this->smarty, $compiler->template);
// save file dependency // 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; $_content = $compiler->template->template_source;
if (preg_match_all("!({$this->_ldl}block\s(.+?){$this->_rdl})!", $_content, $s) != if (preg_match_all("!({$this->_ldl}block\s(.+?){$this->_rdl})!", $_content, $s) !=
preg_match_all("!({$this->_ldl}/block(.*?){$this->_rdl})!", $_content, $c)) { 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)) { if (0 == preg_match("!(.?)(name=)(.*?)(?=(\s|{$this->_rdl}))!", $block_tag, $_match)) {
$this->compiler->trigger_template_error("\"" . $block_tag . "\" missing name attribute"); $this->compiler->trigger_template_error("\"" . $block_tag . "\" missing name attribute");
} else { } else {
$_name = trim($_match[3], '\'"'); $_name = trim($_match[3], '\'"');
// replace {$smarty.block.child} // replace {$smarty.block.child}
if (strpos($block_content, $this->smarty->left_delimiter . '$smarty.block.child' . $this->smarty->right_delimiter) !== false) { if (strpos($block_content, $this->smarty->left_delimiter . '$smarty.block.child' . $this->smarty->right_delimiter) !== false) {
if (isset($this->smarty->block_data[$_name])) { if (isset($this->smarty->block_data[$_name])) {
$block_content = str_replace($this->smarty->left_delimiter . '$smarty.block.child' . $this->smarty->right_delimiter, $block_content = str_replace($this->smarty->left_delimiter . '$smarty.block.child' . $this->smarty->right_delimiter,

View File

@@ -31,6 +31,10 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase {
$from = $_attr['from']; $from = $_attr['from'];
$item = $_attr['item']; $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'])) { if (isset($_attr['key'])) {
$key = $_attr['key']; $key = $_attr['key'];
} else { } else {

View File

@@ -95,9 +95,9 @@ abstract class Smarty_Internal_CompileBase
return; return;
} }
// wrong nesting of tags // 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; return;
} }
} }
?> ?>