remove fail() that is not used
[platal.git] / include / platal / smarty.plugins.inc.php
index 4c79fd1..e3109e9 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2004 Polytechnique.org                              *
+ *  Copyright (C) 2003-2006 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -32,7 +32,7 @@
 function escape_html($string)
 {
     if(is_string($string)) {
-       $transtbl = Array('<' => '&lt;', '>' => '&gt;', '"' => '&quot;', '\'' => '&apos;');
+       $transtbl = Array('<' => '&lt;', '>' => '&gt;', '"' => '&quot;', '\'' => '&#39;');
        return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};)/", "&amp;" , strtr($string, $transtbl));
     } else {
        return $string;
@@ -70,36 +70,19 @@ function at_to_globals($tpl_source, &$smarty)
 
 function trimwhitespace($source, &$smarty)
 {
-    // Pull out the script blocks
-    preg_match_all("!<script[^>]+>.*?</script>!is", $source, $match);
-    $_script_blocks = $match[0];
-    $source = preg_replace("!<script[^>]+>.*?</script>!is", '@@@SMARTY:TRIM:SCRIPT@@@', $source);
+    $tags = array('script', 'pre', 'textarea');
 
-    // Pull out the pre blocks
-    preg_match_all("!<pre>.*?</pre>!is", $source, $match);
-    $_pre_blocks = $match[0];
-    $source = preg_replace("!<pre>.*?</pre>!is", '@@@SMARTY:TRIM:PRE@@@', $source);
-
-    // Pull out the textarea blocks
-    preg_match_all("!<textarea[^>]+>.*?</textarea>!is", $source, $match);
-    $_textarea_blocks = $match[0];
-    $source = preg_replace("!<textarea[^>]+>.*?</textarea>!is", '@@@SMARTY:TRIM:TEXTAREA@@@', $source);
+    foreach ($tags as $tag) {
+        preg_match_all("!<{$tag}[^>]+>.*?</{$tag}>!is", $source, ${$tag});
+        $source = preg_replace("!<{$tag}[^>]+>.*?</{$tag}>!is", "&&&{$tag}&&&", $source);
+    }
 
     // remove all leading spaces, tabs and carriage returns NOT
     // preceeded by a php close tag.
     $source = preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source);
 
-    // replace script blocks
-    foreach($_script_blocks as $curr_block) {
-        $source = preg_replace("!@@@SMARTY:TRIM:SCRIPT@@@!", $curr_block, $source, 1);
-    }
-    // replace pre blocks
-    foreach($_pre_blocks as $curr_block) {
-        $source = preg_replace("!@@@SMARTY:TRIM:PRE@@@!",$curr_block,$source,1);
-    }
-    // replace textarea blocks
-    foreach($_textarea_blocks as $curr_block) {
-        $source = preg_replace("!@@@SMARTY:TRIM:TEXTAREA@@@!",$curr_block,$source,1);
+    foreach ($tags as $tag) {
+        $source = preg_replace("!&&&{$tag}&&&!e",  'array_shift(${$tag}[0])', $source);
     }
 
     return $source;