From: x2000habouzit Date: Mon, 31 Oct 2005 13:53:57 +0000 (+0000) Subject: just be more clever X-Git-Tag: xorg/0.9.9~62 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=514d865a4ae1639db71926a56545e95abc253fe4;p=platal.git just be more clever git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@149 839d8a87-29fc-0310-9880-83ba4fa771e5 --- diff --git a/include/platal/smarty.plugins.inc.php b/include/platal/smarty.plugins.inc.php index b49132e..f1481ab 100644 --- a/include/platal/smarty.plugins.inc.php +++ b/include/platal/smarty.plugins.inc.php @@ -70,36 +70,19 @@ function at_to_globals($tpl_source, &$smarty) function trimwhitespace($source, &$smarty) { - // Pull out the script blocks - preg_match_all("!]+>.*?!is", $source, $match); - $_script_blocks = $match[0]; - $source = preg_replace("!]+>.*?!is", '@@@SMARTY:TRIM:SCRIPT@@@', $source); + $tags = array('script', 'pre', 'textarea'); - // Pull out the pre blocks - preg_match_all("!
.*?
!is", $source, $match); - $_pre_blocks = $match[0]; - $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); + foreach ($tags as $tag) { + preg_match_all("!<{$tag}[^>]+>.*?!is", $source, ${$tag}); + $source = preg_replace("!<{$tag}[^>]+>.*?!is", "&&&{$tag}&&&", $source); + } // remove all leading spaces, tabs and carriage returns NOT // preceeded by a php close tag. $source = preg_replace('/((?)\n)[\s]+/m', '\1', $source); - // replace script blocks - foreach($_script_blocks as $curr_block) { - $source = preg_replace("!@@@SMARTY:TRIM:SCRIPT@@@!", $curr_block, $source, 1); - } - // 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); + foreach ($tags as $tag) { + $source = preg_replace("!&&&{$tag}&&&!e", 'array_shift(${$tag}[0])', $source); } return $source;