| [ Index ] |
krapohl.info |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Smarty plugin 4 * ------------------------------------------------------------- 5 * File: outputfilter.trimwhitespace.php 6 * Type: outputfilter 7 * Name: trimwhitespace 8 * Version: 1.2 9 * Date: April 30, 2002 10 * Purpose: trim leading white space and blank lines from 11 * template source after it gets interpreted, cleaning 12 * up code and saving bandwidth. Does not affect 13 * <PRE></PRE> and <SCRIPT></SCRIPT> blocks. 14 * Install: Drop into the plugin directory, call 15 * $smarty->load_filter('output','trimwhitespace'); 16 * from application. 17 * Author: Monte Ohrt <monte@ispi.net> 18 * ------------------------------------------------------------- 19 */ 20 function smarty_outputfilter_trimwhitespace($source, &$smarty) 21 { 22 // Pull out the script blocks 23 preg_match_all("!<script[^>]+>.*?</script>!is", $source, $match); 24 $_script_blocks = $match[0]; 25 $source = preg_replace("!<script[^>]+>.*?</script>!is", 26 '@@@SMARTY:TRIM:SCRIPT@@@', $source); 27 28 // Pull out the pre blocks 29 preg_match_all("!<pre>.*?</pre>!is", $source, $match); 30 $_pre_blocks = $match[0]; 31 $source = preg_replace("!<pre>.*?</pre>!is", 32 '@@@SMARTY:TRIM:PRE@@@', $source); 33 34 // Pull out the textarea blocks 35 preg_match_all("!<textarea[^>]+>.*?</textarea>!is", $source, $match); 36 $_textarea_blocks = $match[0]; 37 $source = preg_replace("!<textarea[^>]+>.*?</textarea>!is", 38 '@@@SMARTY:TRIM:TEXTAREA@@@', $source); 39 40 // remove all leading spaces, tabs and carriage returns NOT 41 // preceeded by a php close tag. 42 $source = preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source); 43 44 // replace script blocks 45 foreach($_script_blocks as $curr_block) { 46 $source = preg_replace("!@@@SMARTY:TRIM:SCRIPT@@@!",$curr_block,$source,1); 47 } 48 // replace pre blocks 49 foreach($_pre_blocks as $curr_block) { 50 $source = preg_replace("!@@@SMARTY:TRIM:PRE@@@!",$curr_block,$source,1); 51 } 52 // replace textarea blocks 53 foreach($_textarea_blocks as $curr_block) { 54 $source = preg_replace("!@@@SMARTY:TRIM:TEXTAREA@@@!",$curr_block,$source,1); 55 } 56 57 return $source; 58 } 59 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Feb 16 22:40:07 2005 | Cross-referenced by PHPXref 0.6 |