cvs: smarty /libs Smarty_Compiler.class.php
"Messju Mohr" <[email protected]>
| Newsgroups | gmane.comp.php.cvs.smarty |
|---|---|
| Message-ID | <cvsmessju1073565987@cvsserver> |
messju Thu Jan 8 07:46:27 2004 EDT
Modified files:
/smarty/libs Smarty_Compiler.class.php
Log:
fixed handling of comments inside {php} and {literal}
Index: smarty/libs/Smarty_Compiler.class.php
diff -u smarty/libs/Smarty_Compiler.class.php:1.304 smarty/libs/Smarty_Compiler.class.php:1.305
--- smarty/libs/Smarty_Compiler.class.php:1.304 Sat Dec 27 04:25:25 2003
+++ smarty/libs/Smarty_Compiler.class.php Thu Jan 8 07:46:27 2004
@@ -39,7 +39,7 @@
* @package Smarty
*/
-/* $Id: Smarty_Compiler.class.php,v 1.304 2003/12/27 09:25:25 messju Exp $ */
+/* $Id: Smarty_Compiler.class.php,v 1.305 2004/01/08 12:46:27 messju Exp $ */
/**
* Template compiling class
@@ -51,8 +51,7 @@
/**#@+
* @access private
*/
- var $_literal_blocks = array(); // keeps literal template blocks
- var $_php_blocks = array(); // keeps php code blocks
+ var $_folded_blocks = array(); // keeps folded template blocks
var $_current_file = null; // the current template being compiled
var $_current_line_no = 1; // line number for error messages
var $_capture_stack = array(); // keeps track of nested capture buffers
@@ -254,22 +253,20 @@
}
}
- /* Annihilate the comments. */
- $source_content = preg_replace("!({$ldq})\*(.*?)\*({$rdq})!se",
- "'\\1*'.str_repeat(\"\n\", substr_count('\\2', \"\n\")) .'*\\3'",
- $source_content);
-
- /* Pull out the literal blocks. */
- preg_match_all("!{$ldq}\s*literal\s*{$rdq}(.*?){$ldq}\s*/literal\s*{$rdq}!s", $source_content, $_match);
- $this->_literal_blocks = $_match[1];
- $source_content = preg_replace("!{$ldq}\s*literal\s*{$rdq}(.*?){$ldq}\s*/literal\s*{$rdq}!s",
- $this->_quote_replace($this->left_delimiter.'literal'.$this->right_delimiter), $source_content);
-
- /* Pull out the php code blocks. */
- preg_match_all("!{$ldq}php{$rdq}(.*?){$ldq}/php{$rdq}!s", $source_content, $_match);
- $this->_php_blocks = $_match[1];
- $source_content = preg_replace("!{$ldq}php{$rdq}(.*?){$ldq}/php{$rdq}!s",
- $this->_quote_replace($this->left_delimiter.'php'.$this->right_delimiter), $source_content);
+ /* fetch all special blocks */
+ $search = "!{$ldq}\*(.*?)\*{$rdq}|{$ldq}\s*literal\s*{$rdq}(.*?){$ldq}\s*/literal\s*{$rdq}|{$ldq}\s*php\s*{$rdq}(.*?){$ldq}\s*/php\s*{$rdq}!s";
+
+ preg_match_all($search, $source_content, $match, PREG_SET_ORDER);
+ $this->_folded_blocks = $match;
+ reset($this->_folded_blocks);
+
+ /* replace special blocks by "{php}" */
+ $source_content = preg_replace($search.'e', "'"
+ . $this->_quote_replace($this->left_delimiter) . 'php'
+ . "' . str_repeat(\"\n\", substr_count('\\0', \"\n\")) .'"
+ . $this->_quote_replace($this->right_delimiter)
+ . "'"
+ , $source_content);
/* Gather all template tags. */
preg_match_all("!{$ldq}\s*(.*?)\s*{$rdq}!s", $source_content, $_match);
@@ -531,19 +528,27 @@
}
return '';
- case 'literal':
- list (,$literal_block) = each($this->_literal_blocks);
- $this->_current_line_no += substr_count($literal_block, "\n");
- return "<?php echo '".str_replace("'", "\'", str_replace("\\", "\\\\", $literal_block))."'; ?>" . $this->_additional_newline;
-
case 'php':
- if ($this->security && !$this->security_settings['PHP_TAGS']) {
- $this->_syntax_error("(secure mode) php tags not permitted", E_USER_WARNING, __FILE__, __LINE__);
- return;
- }
- list (,$php_block) = each($this->_php_blocks);
- $this->_current_line_no += substr_count($php_block, "\n");
- return '<?php '.$php_block.' ?>';
+ /* handle folded tags replaced by {php} */
+ list(, $block) = each($this->_folded_blocks);
+ $this->_current_line_no += substr_count($block[0], "\n");
+ /* the number of matched elements in the regexp in _compile_file()
+ determins the type of folded tag that was found */
+ switch (count($block)) {
+ case 2: /* comment */
+ return '';
+
+ case 3: /* literal */
+ return "<?php echo '" . strtr($block[2], array("'"=>"\'", "\\"=>"\\\\")) . "'; ?>" . $this->_additional_newline;
+
+ case 4: /* php */
+ if ($this->security && !$this->security_settings['PHP_TAGS']) {
+ $this->_syntax_error("(secure mode) php tags not permitted", E_USER_WARNING, __FILE__, __LINE__);
+ return;
+ }
+ return '<?php ' . $block[4] .' ?>';
+ }
+ break;
case 'insert':
return $this->_compile_insert_tag($tag_args);
--
Smarty CVS Mailing List (http://cvs.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php