cvs: smarty / NEWS /libs Smarty_Compiler.class.php

"Messju Mohr" <[email protected]>
Newsgroups gmane.comp.php.cvs.smarty
Message-ID <cvsmessju1107122080@cvsserver>
messju		Sun Jan 30 16:54:40 2005 EDT

  Modified files:              
    /smarty	NEWS 
    /smarty/libs	Smarty_Compiler.class.php 
  Log:
  fixed handling of hashed opening php-tags inside strip-blocks
  (reported by titi_rafa)
  
  
  
http://cvs.php.net/diff.php/smarty/NEWS?r1=1.485&r2=1.486&ty=u
Index: smarty/NEWS
diff -u smarty/NEWS:1.485 smarty/NEWS:1.486
--- smarty/NEWS:1.485	Fri Jan 28 12:20:13 2005
+++ smarty/NEWS	Sun Jan 30 16:54:39 2005
@@ -1,3 +1,4 @@
+  - fix handling of hashed opening php-tags inside strip-blocks (messju)
   - change escape:url use rawurlencode() instead of urlencode() (messju)
   - make $smarty.const.FOO compile to "FOO", and not to "constant('foo')".
     this is less code and a little faster execution. note that undefined
http://cvs.php.net/diff.php/smarty/libs/Smarty_Compiler.class.php?r1=1.358&r2=1.359&ty=u
Index: smarty/libs/Smarty_Compiler.class.php
diff -u smarty/libs/Smarty_Compiler.class.php:1.358 smarty/libs/Smarty_Compiler.class.php:1.359
--- smarty/libs/Smarty_Compiler.class.php:1.358	Fri Jan 21 12:46:14 2005
+++ smarty/libs/Smarty_Compiler.class.php	Sun Jan 30 16:54:39 2005
@@ -26,7 +26,7 @@
  * @package Smarty
  */
 
-/* $Id: Smarty_Compiler.class.php,v 1.358 2005/01/21 17:46:14 mohrt Exp $ */
+/* $Id: Smarty_Compiler.class.php,v 1.359 2005/01/30 21:54:39 messju Exp $ */
 
 /**
  * Template compiling class
@@ -318,6 +318,32 @@
             return;
         }
 
+        /* Reformat $text_blocks between 'strip' and '/strip' tags,
+           removing spaces, tabs and newlines. */
+        $strip = false;
+        for ($i = 0, $for_max = count($compiled_tags); $i < $for_max; $i++) {
+            if ($compiled_tags[$i] == '{strip}') {
+                $compiled_tags[$i] = '';
+                $strip = true;
+            }
+            if ($strip) {
+                /* strip all $text_blocks before the next '/strip' */
+                for ($j = $i + 1; $j < $for_max; $j++) {
+                    /* remove leading and trailing whitespaces of each line */
+                    $text_blocks[$j] = preg_replace('!\s+$|^\s+!m', '', $text_blocks[$j]);
+                    /* remove carriage return and newline between each line */
+                    $text_blocks[$j] = preg_replace('![\r\n]+!m', '', $text_blocks[$j]);                
+                    $text_blocks[$j] = "<?php echo '" . strtr($text_blocks[$j], array("'"=>"\'", "\\"=>"\\\\")) . "'; ?>";
+                    if ($compiled_tags[$j] == '{/strip}') {
+                        $compiled_tags[$j] = "\n"; /* slurped by php, but necessary
+                                    if a newline is following the closing strip-tag */
+                        $strip = false;
+                        $i = $j;
+                        break;
+                    }
+                }
+            }
+        }
         $compiled_content = '';
 
         /* Interleave the compiled contents and text blocks to get the final result. */
@@ -330,17 +356,6 @@
         }
         $compiled_content .= $text_blocks[$i];
 
-        /* Reformat data between 'strip' and '/strip' tags, removing spaces, tabs and newlines. */
-        if (preg_match_all("~{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}~s", $compiled_content, $_match)) {
-            $strip_tags = $_match[0];
-            $strip_tags_modified = preg_replace("~{$ldq}/?strip{$rdq}|[\t ]+$|^[\t ]+~m", '', $strip_tags);
-            $strip_tags_modified = preg_replace('~[\r\n]+~m', '', $strip_tags_modified);
-            for ($i = 0, $for_max = count($strip_tags); $i < $for_max; $i++)
-                $compiled_content = preg_replace("~{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}~s",
-                                                  $this->_quote_replace($strip_tags_modified[$i]),
-                                                  $compiled_content, 1);
-        }
-
         // remove \n from the end of the file, if any
         if (($_len=strlen($compiled_content)) && ($compiled_content{$_len - 1} == "\n" )) {
             $compiled_content = substr($compiled_content, 0, -1);

-- 
Smarty CVS Mailing List (http://cvs.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.