1: <?php
2: 3: 4: 5: 6:
7:
8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
28: function smarty_outputfilter_trimwhitespace($source, &$smarty)
29: {
30:
31: preg_match_all("!<script[^>]*?>.*?</script>!is", $source, $match);
32: $_script_blocks = $match[0];
33: $source = preg_replace("!<script[^>]*?>.*?</script>!is",
34: '@@@SMARTY:TRIM:SCRIPT@@@', $source);
35:
36:
37: preg_match_all("!<pre[^>]*?>.*?</pre>!is", $source, $match);
38: $_pre_blocks = $match[0];
39: $source = preg_replace("!<pre[^>]*?>.*?</pre>!is",
40: '@@@SMARTY:TRIM:PRE@@@', $source);
41:
42:
43: preg_match_all("!<textarea[^>]*?>.*?</textarea>!is", $source, $match);
44: $_textarea_blocks = $match[0];
45: $source = preg_replace("!<textarea[^>]*?>.*?</textarea>!is",
46: '@@@SMARTY:TRIM:TEXTAREA@@@', $source);
47:
48:
49:
50: $source = trim(preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source));
51:
52:
53: smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:TEXTAREA@@@",$_textarea_blocks, $source);
54:
55:
56: smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:PRE@@@",$_pre_blocks, $source);
57:
58:
59: smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:SCRIPT@@@",$_script_blocks, $source);
60:
61: return $source;
62: }
63:
64: function smarty_outputfilter_trimwhitespace_replace($search_str, $replace, &$subject) {
65: $_len = strlen($search_str);
66: $_pos = 0;
67: for ($_i=0, $_count=count($replace); $_i<$_count; $_i++)
68: if (($_pos=strpos($subject, $search_str, $_pos))!==false)
69: $subject = substr_replace($subject, $replace[$_i], $_pos, $_len);
70: else
71: break;
72:
73: }
74:
75: ?>
76: