cvs: smarty / NEWS /libs/internals core.write_cache_file.php

"Messju Mohr" <[email protected]>
Newsgroups gmane.comp.php.cvs.smarty
Message-ID <cvsmessju1096740205@cvsserver>
messju		Sat Oct  2 14:03:25 2004 EDT

  Modified files:              
    /smarty	NEWS 
    /smarty/libs/internals	core.write_cache_file.php 
  Log:
  fixed nocache-handling with nested includes. there was a logical error
  in the replacement of internal nocache-tags to dynamic content that
  lead to false results with deeply nested includes or with
  nocache-blocks inside nocache-blocks.
  
  many thanks to Lars Jankowfsky for providing big help on reproducing
  and tracking down this bug!
  
  
  
http://cvs.php.net/diff.php/smarty/NEWS?r1=1.477&r2=1.478&ty=u
Index: smarty/NEWS
diff -u smarty/NEWS:1.477 smarty/NEWS:1.478
--- smarty/NEWS:1.477	Thu Sep 16 19:07:31 2004
+++ smarty/NEWS	Sat Oct  2 14:03:25 2004
@@ -1,3 +1,4 @@
+  - fixed nocache-handling with nested includes (Lars Jankowfsky, messju)
   - moved /libs/core to /libs/internals (boots)
   - fixed more parsing problems (messju)
 
http://cvs.php.net/diff.php/smarty/libs/internals/core.write_cache_file.php?r1=1.2&r2=1.3&ty=u
Index: smarty/libs/internals/core.write_cache_file.php
diff -u smarty/libs/internals/core.write_cache_file.php:1.2 smarty/libs/internals/core.write_cache_file.php:1.3
--- smarty/libs/internals/core.write_cache_file.php:1.2	Fri Sep 17 22:09:35 2004
+++ smarty/libs/internals/core.write_cache_file.php	Sat Oct  2 14:03:25 2004
@@ -31,12 +31,34 @@
         $smarty->_cache_info['expires'] = -1;
     }
 
-    // collapse {nocache...}-tags
-    $params['results'] = preg_replace('!((\{nocache\:([0-9a-f]{32})#(\d+)\})'
-                                      .'.*'
-                                      .'{/nocache\:\\3#\\4\})!Us'
-                                      ,'\\2'
-                                      ,$params['results']);
+    // collapse nocache.../nocache-tags
+    if (preg_match_all('!\{(/?)nocache\:[0-9a-f]{32}#\d+\}!', $params['results'], $match, PREG_PATTERN_ORDER)) {
+        // remove everything between every pair of outermost noache.../nocache-tags
+        // and replace it by a single nocache-tag
+        // this new nocache-tag will be replaced by dynamic contents in
+        // smarty_core_process_compiled_includes() on a cache-read
+        
+        $match_count = count($match[0]);
+        $results = preg_split('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!', $params['results'], -1, PREG_SPLIT_DELIM_CAPTURE);
+        
+        $level = 0;
+        $j = 0;
+        for ($i=0, $results_count = count($results); $i < $results_count && $j < $match_count; $i++) {
+            if ($results[$i] == $match[0][$j]) {
+                // nocache tag
+                if ($match[1][$j]) { // closing tag
+                    $level--;
+                    unset($results[$i]);
+                } else { // opening tag
+                    if ($level++ > 0) unset($results[$i]);
+                }
+                $j++;
+            } elseif ($level > 0) {
+                unset($results[$i]);
+            }
+        }
+        $params['results'] = implode('', $results);
+    }
     $smarty->_cache_info['cache_serials'] = $smarty->_cache_serials;
 
     // prepend the cache header info into cache file

-- 
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.