+++ /dev/null
-<?php\r
-/**\r
- * Smarty plugin\r
- * @package Smarty\r
- * @subpackage plugins\r
- */\r
-\r
-/**\r
- * Smarty trimwhitespace outputfilter plugin\r
- *\r
- * File: outputfilter.trimwhitespace.php<br>\r
- * Type: outputfilter<br>\r
- * Name: trimwhitespace<br>\r
- * Date: Jan 25, 2003<br>\r
- * Purpose: trim leading white space and blank lines from\r
- * template source after it gets interpreted, cleaning\r
- * up code and saving bandwidth. Does not affect\r
- * <<PRE>></PRE> and <SCRIPT></SCRIPT> blocks.<br>\r
- * Install: Drop into the plugin directory, call \r
- * <code>$smarty->load_filter('output','trimwhitespace');</code>\r
- * from application.\r
- * @author Monte Ohrt <monte@ispi.net>\r
- * @author Contributions from Lars Noschinski <lars@usenet.noschinski.de>\r
- * @version 1.3\r
- * @param string\r
- * @param Smarty\r
- */\r
- function smarty_outputfilter_trimwhitespace($source, &$smarty)\r
- {\r
- // Pull out the script blocks\r
- preg_match_all("!<script[^>]+>.*?</script>!is", $source, $match);\r
- $_script_blocks = $match[0];\r
- $source = preg_replace("!<script[^>]+>.*?</script>!is",\r
- '@@@SMARTY:TRIM:SCRIPT@@@', $source);\r
-\r
- // Pull out the pre blocks\r
- preg_match_all("!<pre>.*?</pre>!is", $source, $match);\r
- $_pre_blocks = $match[0];\r
- $source = preg_replace("!<pre>.*?</pre>!is",\r
- '@@@SMARTY:TRIM:PRE@@@', $source);\r
-\r
- // Pull out the textarea blocks\r
- preg_match_all("!<textarea[^>]+>.*?</textarea>!is", $source, $match);\r
- $_textarea_blocks = $match[0];\r
- $source = preg_replace("!<textarea[^>]+>.*?</textarea>!is",\r
- '@@@SMARTY:TRIM:TEXTAREA@@@', $source);\r
-\r
- // remove all leading spaces, tabs and carriage returns NOT\r
- // preceeded by a php close tag.\r
- $source = trim(preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source));\r
-\r
- // replace script blocks\r
- smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:SCRIPT@@@",$_script_blocks, $source);\r
-\r
- // replace pre blocks\r
- smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:PRE@@@",$_pre_blocks, $source);\r
-\r
- // replace textarea blocks\r
- smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:TEXTAREA@@@",$_textarea_blocks, $source);\r
-\r
- return $source; \r
- }\r
-\r
-function smarty_outputfilter_trimwhitespace_replace($search_str, $replace, &$subject) {\r
- $_len = strlen($search_str);\r
- $_pos = 0;\r
- for ($_i=0, $_count=count($replace); $_i<$_count; $_i++)\r
- if (($_pos=strpos($subject, $search_str, $_pos))!==false)\r
- $subject = substr_replace($subject, $replace[$_i], $_pos, $_len);\r
- else\r
- break;\r
- \r
-}\r
-\r
-?>\r