fix order of php tag comparisons

This commit is contained in:
mohrt
2003-01-30 16:48:55 +00:00
parent 71b0cc207b
commit 8266f8660e
4 changed files with 55 additions and 17 deletions

20
NEWS
View File

@@ -1,19 +1,21 @@
- fix known problems with php tag handling in templates - fix known problems with php tag handling in templates
(recursion, echoing <?xml tags) (Monte) (recursion, echoing <?xml tags) (Monte)
- add support for object registration (Monte) - add support for object registration (Monte)
- add debug template to secure dir, add template_dir - add debug template to secure_dir, add template_dir
to secure_dir by default (Ferdinand Beyer, Monte) to secure_dir by default (Ferdinand Beyer, Monte)
- added support for object method access (Monte) - added support for assigned object access (Monte)
- fixed bug with directories named '0' (Frank Bauer, Monte) - fixed bug with directories named '0' (Frank Bauer, Monte)
- add javascript parameter to escape modifier (Monte) - add javascript parameter to escape modifier (Monte)
- added correct line numbers to syntax error messages - added calling function line numbers to syntax error
in compiler (Monte) messages in compiler (Monte)
- added support for modifiers to function calls (Monte) - added support for modifiers to function calls (Monte)
- support return value for custom functions (Monte) - support return value for custom functions
- can access constants via $smarty.const.FOO (Monte) instead of echoing (but echo still works) (Monte)
- cleaned up regex code in compiler (Monte) - added direct access to constants
- can now pass modifiers to static content (Monte) via $smarty.const.FOO (Monte)
- fix up regex code in compiler, more flexible and - added support for passing modifiers
to static values (Monte)
- fix up regex code in compiler, more accurate and
maintainable (Monte) maintainable (Monte)
- added day_value_format to html_select_date (Marcus - added day_value_format to html_select_date (Marcus
Bointon, Monte) Bointon, Monte)

View File

@@ -247,6 +247,8 @@ class Smarty_Compiler extends Smarty {
/* match anything resembling php tags */ /* match anything resembling php tags */
if (preg_match_all('!(<\?(?:\w+|=)?|\?>|language\s*=\s*[\"\']?php[\"\']?)!is', $text_blocks[$curr_tb], $sp_match)) { if (preg_match_all('!(<\?(?:\w+|=)?|\?>|language\s*=\s*[\"\']?php[\"\']?)!is', $text_blocks[$curr_tb], $sp_match)) {
/* replace tags with placeholders to prevent recursive replacements */ /* 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++) { 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]); $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 { } else {
/* SMARTY_PHP_ALLOW, but echo non php starting tags */ /* SMARTY_PHP_ALLOW, but echo non php starting tags */
$sp_match[1][$curr_sp] = preg_replace('%(<\?(?!php|=|$))%i', '<?php echo \'\\1\'?>'."\n", $sp_match[1][$curr_sp]); $sp_match[1][$curr_sp] = preg_replace('%(<\?(?!php|=|$))%i', '<?php echo \'\\1\'?>'."\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; return true;
} }
/** /**
* Compile a template tag * 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: */ /* vim: set et: */
?> ?>

4
TODO
View File

@@ -1,15 +1,11 @@
* handle asp style tags in $php_handler * handle asp style tags in $php_handler
* correctly capture nested php tag syntax in templates:
<?php echo "<?php exit(); ?>"; ?>
* support implementations of prefiltes, mods, and others as class methods. * support implementations of prefiltes, mods, and others as class methods.
* ability to concatenate values/strings together * ability to concatenate values/strings together
* fix all E_NOTICE warnings * fix all E_NOTICE warnings
* make simple math easier * make simple math easier
* caching all but parts of the template * caching all but parts of the template
* change plugins so $smarty variable always comes first * change plugins so $smarty variable always comes first
* being able to load config files from PHP scripts
* get cache ttl with function call * get cache ttl with function call
* make Config_File booleanize configurable through Smarty
FIX: make inserts use normal functions before plugins FIX: make inserts use normal functions before plugins
UPD: change it so that if template comes from some resource, UPD: change it so that if template comes from some resource,
that resource stays as the default, no need to specify it that resource stays as the default, no need to specify it

View File

@@ -247,6 +247,8 @@ class Smarty_Compiler extends Smarty {
/* match anything resembling php tags */ /* match anything resembling php tags */
if (preg_match_all('!(<\?(?:\w+|=)?|\?>|language\s*=\s*[\"\']?php[\"\']?)!is', $text_blocks[$curr_tb], $sp_match)) { if (preg_match_all('!(<\?(?:\w+|=)?|\?>|language\s*=\s*[\"\']?php[\"\']?)!is', $text_blocks[$curr_tb], $sp_match)) {
/* replace tags with placeholders to prevent recursive replacements */ /* 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++) { 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]); $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 { } else {
/* SMARTY_PHP_ALLOW, but echo non php starting tags */ /* SMARTY_PHP_ALLOW, but echo non php starting tags */
$sp_match[1][$curr_sp] = preg_replace('%(<\?(?!php|=|$))%i', '<?php echo \'\\1\'?>'."\n", $sp_match[1][$curr_sp]); $sp_match[1][$curr_sp] = preg_replace('%(<\?(?!php|=|$))%i', '<?php echo \'\\1\'?>'."\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; return true;
} }
/** /**
* Compile a template tag * 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: */ /* vim: set et: */
?> ?>