mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
update with textarea support
This commit is contained in:
@@ -5,8 +5,8 @@
|
|||||||
* File: outputfilter.trimwhitespace.php
|
* File: outputfilter.trimwhitespace.php
|
||||||
* Type: outputfilter
|
* Type: outputfilter
|
||||||
* Name: trimwhitespace
|
* Name: trimwhitespace
|
||||||
* Version: 1.2
|
* Version: 1.3
|
||||||
* Date: April 30, 2002
|
* Date: Jan 25, 2003
|
||||||
* Purpose: trim leading white space and blank lines from
|
* Purpose: trim leading white space and blank lines from
|
||||||
* template source after it gets interpreted, cleaning
|
* template source after it gets interpreted, cleaning
|
||||||
* up code and saving bandwidth. Does not affect
|
* up code and saving bandwidth. Does not affect
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
* $smarty->load_filter('output','trimwhitespace');
|
* $smarty->load_filter('output','trimwhitespace');
|
||||||
* from application.
|
* from application.
|
||||||
* Author: Monte Ohrt <monte@ispi.net>
|
* Author: Monte Ohrt <monte@ispi.net>
|
||||||
|
* Contribs: Lars Noschinski <lars@usenet.noschinski.de>
|
||||||
* -------------------------------------------------------------
|
* -------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
function smarty_outputfilter_trimwhitespace($source, &$smarty)
|
function smarty_outputfilter_trimwhitespace($source, &$smarty)
|
||||||
@@ -31,9 +32,15 @@
|
|||||||
$source = preg_replace("!<pre>.*?</pre>!is",
|
$source = preg_replace("!<pre>.*?</pre>!is",
|
||||||
'@@@SMARTY:TRIM:PRE@@@', $source);
|
'@@@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);
|
||||||
|
|
||||||
// remove all leading spaces, tabs and carriage returns NOT
|
// remove all leading spaces, tabs and carriage returns NOT
|
||||||
// preceeded by a php close tag.
|
// 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
|
// replace script blocks
|
||||||
foreach($_script_blocks as $curr_block) {
|
foreach($_script_blocks as $curr_block) {
|
||||||
@@ -42,6 +49,10 @@
|
|||||||
// replace pre blocks
|
// replace pre blocks
|
||||||
foreach($_pre_blocks as $curr_block) {
|
foreach($_pre_blocks as $curr_block) {
|
||||||
$source = preg_replace("!@@@SMARTY:TRIM:PRE@@@!",$curr_block,$source,1);
|
$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;
|
return $source;
|
||||||
|
@@ -5,8 +5,8 @@
|
|||||||
* File: outputfilter.trimwhitespace.php
|
* File: outputfilter.trimwhitespace.php
|
||||||
* Type: outputfilter
|
* Type: outputfilter
|
||||||
* Name: trimwhitespace
|
* Name: trimwhitespace
|
||||||
* Version: 1.2
|
* Version: 1.3
|
||||||
* Date: April 30, 2002
|
* Date: Jan 25, 2003
|
||||||
* Purpose: trim leading white space and blank lines from
|
* Purpose: trim leading white space and blank lines from
|
||||||
* template source after it gets interpreted, cleaning
|
* template source after it gets interpreted, cleaning
|
||||||
* up code and saving bandwidth. Does not affect
|
* up code and saving bandwidth. Does not affect
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
* $smarty->load_filter('output','trimwhitespace');
|
* $smarty->load_filter('output','trimwhitespace');
|
||||||
* from application.
|
* from application.
|
||||||
* Author: Monte Ohrt <monte@ispi.net>
|
* Author: Monte Ohrt <monte@ispi.net>
|
||||||
|
* Contribs: Lars Noschinski <lars@usenet.noschinski.de>
|
||||||
* -------------------------------------------------------------
|
* -------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
function smarty_outputfilter_trimwhitespace($source, &$smarty)
|
function smarty_outputfilter_trimwhitespace($source, &$smarty)
|
||||||
@@ -31,9 +32,15 @@
|
|||||||
$source = preg_replace("!<pre>.*?</pre>!is",
|
$source = preg_replace("!<pre>.*?</pre>!is",
|
||||||
'@@@SMARTY:TRIM:PRE@@@', $source);
|
'@@@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);
|
||||||
|
|
||||||
// remove all leading spaces, tabs and carriage returns NOT
|
// remove all leading spaces, tabs and carriage returns NOT
|
||||||
// preceeded by a php close tag.
|
// 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
|
// replace script blocks
|
||||||
foreach($_script_blocks as $curr_block) {
|
foreach($_script_blocks as $curr_block) {
|
||||||
@@ -42,6 +49,10 @@
|
|||||||
// replace pre blocks
|
// replace pre blocks
|
||||||
foreach($_pre_blocks as $curr_block) {
|
foreach($_pre_blocks as $curr_block) {
|
||||||
$source = preg_replace("!@@@SMARTY:TRIM:PRE@@@!",$curr_block,$source,1);
|
$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;
|
return $source;
|
||||||
|
Reference in New Issue
Block a user