From 8266f8660ea8ceb8c6eff7ae5a252184ce6a5ade Mon Sep 17 00:00:00 2001 From: mohrt Date: Thu, 30 Jan 2003 16:48:55 +0000 Subject: [PATCH] fix order of php tag comparisons --- NEWS | 20 +++++++++++--------- Smarty_Compiler.class.php | 24 ++++++++++++++++++++++-- TODO | 4 ---- libs/Smarty_Compiler.class.php | 24 ++++++++++++++++++++++-- 4 files changed, 55 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index 8bf9e4f6..eb228d4c 100644 --- a/NEWS +++ b/NEWS @@ -1,19 +1,21 @@ - fix known problems with php tag handling in templates (recursion, echoing |language\s*=\s*[\"\']?php[\"\']?)!is', $text_blocks[$curr_tb], $sp_match)) { /* replace tags with placeholders to prevent recursive replacements */ + $sp_match[1] = array_unique($sp_match[1]); + usort($sp_match[1], '_smarty_sort_length'); for ($curr_sp = 0, $for_max2 = count($sp_match[1]); $curr_sp < $for_max2; $curr_sp++) { $text_blocks[$curr_tb] = str_replace($sp_match[1][$curr_sp],'%%%SMARTYSP'.$curr_sp.'%%%',$text_blocks[$curr_tb]); } @@ -264,7 +266,7 @@ class Smarty_Compiler extends Smarty { } else { /* SMARTY_PHP_ALLOW, but echo non php starting tags */ $sp_match[1][$curr_sp] = preg_replace('%(<\?(?!php|=|$))%i', ''."\n", $sp_match[1][$curr_sp]); - $text_blocks[$curr_tb] = str_replace('%%%SMARTYSP'.$curr_sp.'%%%',$sp_match[1][$curr_sp],$text_blocks[$curr_tb]); + $text_blocks[$curr_tb] = str_replace('%%%SMARTYSP'.$curr_sp.'%%%', $sp_match[1][$curr_sp], $text_blocks[$curr_tb]); } } } @@ -343,7 +345,6 @@ class Smarty_Compiler extends Smarty { return true; } - /** * Compile a template tag * @@ -1818,6 +1819,25 @@ class Smarty_Compiler extends Smarty { } } +/** + * compare to values by their string length + * + * @access private + * @param $a + * @param $b + */ +function _smarty_sort_length($a, $b) +{ + if($a == $b) + return 0; + + if(strlen($a) == strlen($b)) + return ($a > $b) ? -1 : 1; + + return (strlen($a) > strlen($b)) ? -1 : 1; +} + + /* vim: set et: */ ?> diff --git a/TODO b/TODO index b97590ef..4699b021 100644 --- a/TODO +++ b/TODO @@ -1,15 +1,11 @@ * handle asp style tags in $php_handler -* correctly capture nested php tag syntax in templates: - "; ?> * support implementations of prefiltes, mods, and others as class methods. * ability to concatenate values/strings together * fix all E_NOTICE warnings * make simple math easier * caching all but parts of the template * change plugins so $smarty variable always comes first -* being able to load config files from PHP scripts * get cache ttl with function call -* make Config_File booleanize configurable through Smarty FIX: make inserts use normal functions before plugins UPD: change it so that if template comes from some resource, that resource stays as the default, no need to specify it diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index b14e317f..bddd22a8 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -247,6 +247,8 @@ class Smarty_Compiler extends Smarty { /* match anything resembling php tags */ if (preg_match_all('!(<\?(?:\w+|=)?|\?>|language\s*=\s*[\"\']?php[\"\']?)!is', $text_blocks[$curr_tb], $sp_match)) { /* replace tags with placeholders to prevent recursive replacements */ + $sp_match[1] = array_unique($sp_match[1]); + usort($sp_match[1], '_smarty_sort_length'); for ($curr_sp = 0, $for_max2 = count($sp_match[1]); $curr_sp < $for_max2; $curr_sp++) { $text_blocks[$curr_tb] = str_replace($sp_match[1][$curr_sp],'%%%SMARTYSP'.$curr_sp.'%%%',$text_blocks[$curr_tb]); } @@ -264,7 +266,7 @@ class Smarty_Compiler extends Smarty { } else { /* SMARTY_PHP_ALLOW, but echo non php starting tags */ $sp_match[1][$curr_sp] = preg_replace('%(<\?(?!php|=|$))%i', ''."\n", $sp_match[1][$curr_sp]); - $text_blocks[$curr_tb] = str_replace('%%%SMARTYSP'.$curr_sp.'%%%',$sp_match[1][$curr_sp],$text_blocks[$curr_tb]); + $text_blocks[$curr_tb] = str_replace('%%%SMARTYSP'.$curr_sp.'%%%', $sp_match[1][$curr_sp], $text_blocks[$curr_tb]); } } } @@ -343,7 +345,6 @@ class Smarty_Compiler extends Smarty { return true; } - /** * Compile a template tag * @@ -1818,6 +1819,25 @@ class Smarty_Compiler extends Smarty { } } +/** + * compare to values by their string length + * + * @access private + * @param $a + * @param $b + */ +function _smarty_sort_length($a, $b) +{ + if($a == $b) + return 0; + + if(strlen($a) == strlen($b)) + return ($a > $b) ? -1 : 1; + + return (strlen($a) > strlen($b)) ? -1 : 1; +} + + /* vim: set et: */ ?>