From 1e11860447b1658d55268669b5e76161ad047744 Mon Sep 17 00:00:00 2001 From: mohrt Date: Sat, 25 Jan 2003 17:31:55 +0000 Subject: [PATCH] update with textarea support --- libs/plugins/outputfilter.trimwhitespace.php | 17 ++++++++++++++--- plugins/outputfilter.trimwhitespace.php | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/libs/plugins/outputfilter.trimwhitespace.php b/libs/plugins/outputfilter.trimwhitespace.php index 49f4072e..262567a2 100644 --- a/libs/plugins/outputfilter.trimwhitespace.php +++ b/libs/plugins/outputfilter.trimwhitespace.php @@ -5,8 +5,8 @@ * File: outputfilter.trimwhitespace.php * Type: outputfilter * Name: trimwhitespace - * Version: 1.2 - * Date: April 30, 2002 + * Version: 1.3 + * Date: Jan 25, 2003 * Purpose: trim leading white space and blank lines from * template source after it gets interpreted, cleaning * up code and saving bandwidth. Does not affect @@ -15,6 +15,7 @@ * $smarty->load_filter('output','trimwhitespace'); * from application. * Author: Monte Ohrt + * Contribs: Lars Noschinski * ------------------------------------------------------------- */ function smarty_outputfilter_trimwhitespace($source, &$smarty) @@ -31,9 +32,15 @@ $source = preg_replace("!
.*?
!is", '@@@SMARTY:TRIM:PRE@@@', $source); + // Pull out the textarea blocks + preg_match_all("!]+>.*?!is", $source, $match); + $_textarea_blocks = $match[0]; + $source = preg_replace("!]+>.*?!is", + '@@@SMARTY:TRIM:TEXTAREA@@@', $source); + // remove all leading spaces, tabs and carriage returns NOT // preceeded by a php close tag. - $source = preg_replace('/((?)\n)[\s]+/m', '\1', $source); + $source = trim(preg_replace('/((?)\n)[\s]+/m', '\1', $source)); // replace script blocks foreach($_script_blocks as $curr_block) { @@ -42,6 +49,10 @@ // 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); } return $source; diff --git a/plugins/outputfilter.trimwhitespace.php b/plugins/outputfilter.trimwhitespace.php index 49f4072e..262567a2 100644 --- a/plugins/outputfilter.trimwhitespace.php +++ b/plugins/outputfilter.trimwhitespace.php @@ -5,8 +5,8 @@ * File: outputfilter.trimwhitespace.php * Type: outputfilter * Name: trimwhitespace - * Version: 1.2 - * Date: April 30, 2002 + * Version: 1.3 + * Date: Jan 25, 2003 * Purpose: trim leading white space and blank lines from * template source after it gets interpreted, cleaning * up code and saving bandwidth. Does not affect @@ -15,6 +15,7 @@ * $smarty->load_filter('output','trimwhitespace'); * from application. * Author: Monte Ohrt + * Contribs: Lars Noschinski * ------------------------------------------------------------- */ function smarty_outputfilter_trimwhitespace($source, &$smarty) @@ -31,9 +32,15 @@ $source = preg_replace("!
.*?
!is", '@@@SMARTY:TRIM:PRE@@@', $source); + // Pull out the textarea blocks + preg_match_all("!]+>.*?!is", $source, $match); + $_textarea_blocks = $match[0]; + $source = preg_replace("!]+>.*?!is", + '@@@SMARTY:TRIM:TEXTAREA@@@', $source); + // remove all leading spaces, tabs and carriage returns NOT // preceeded by a php close tag. - $source = preg_replace('/((?)\n)[\s]+/m', '\1', $source); + $source = trim(preg_replace('/((?)\n)[\s]+/m', '\1', $source)); // replace script blocks foreach($_script_blocks as $curr_block) { @@ -42,6 +49,10 @@ // 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); } return $source;