fix situation when no compiled tags are present

This commit is contained in:
mohrt
2007-02-23 15:41:56 +00:00
parent 7d334255b7
commit 6afa5118b4

View File

@@ -357,10 +357,12 @@ class Smarty_Compiler extends Smarty {
/* Interleave the compiled contents and text blocks to get the final result. */ /* Interleave the compiled contents and text blocks to get the final result. */
for ($i = 0, $for_max = count($compiled_tags); $i < $for_max; $i++) { for ($i = 0, $for_max = count($compiled_tags); $i < $for_max; $i++) {
if ($compiled_tags[$i] == '') { if ($compiled_tags[$i] == '') {
// tag result empty, remove first newline from following text block // tag result empty, remove first newline from following text block
$text_blocks[$i+1] = preg_replace('~^(\r\n|\r|\n)~', '', $text_blocks[$i+1]); $text_blocks[$i+1] = preg_replace('~^(\r\n|\r|\n)~', '', $text_blocks[$i+1]);
} }
// replace legit PHP tags with placeholder // replace legit PHP tags with placeholder
$text_blocks[$i] = str_replace('<?',$tmp_id,$text_blocks[$i]); $text_blocks[$i] = str_replace('<?',$tmp_id,$text_blocks[$i]);
$compiled_tags[$i] = str_replace('<?',$tmp_id,$compiled_tags[$i]); $compiled_tags[$i] = str_replace('<?',$tmp_id,$compiled_tags[$i]);
@@ -369,10 +371,13 @@ class Smarty_Compiler extends Smarty {
} }
$compiled_content .= $text_blocks[$i]; $compiled_content .= $text_blocks[$i];
// escape created php tags if(count($compiled_tags)>0)
$compiled_content = str_replace('<?',"<?php echo '<?' ?>\n",$compiled_content); {
// unescape legit tags // escape created php tags
$compiled_content = str_replace($tmp_id,'<?',$compiled_content); $compiled_content = str_replace('<?',"<?php echo '<?' ?>\n",$compiled_content);
// recover legit tags
$compiled_content = str_replace($tmp_id,'<?',$compiled_content);
}
// remove \n from the end of the file, if any // remove \n from the end of the file, if any
if (strlen($compiled_content) && (substr($compiled_content, -1) == "\n") ) { if (strlen($compiled_content) && (substr($compiled_content, -1) == "\n") ) {