X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fplatal%2Fsmarty.plugins.inc.php;h=e3109e9d288d7c584aa163b4cc53eacb81f95203;hb=d7a8b04cfd6812be3c0deb9418f373331f9805f7;hp=4c79fd1bdd74043e953534667b90919bdf1f7366;hpb=ff5e503480298fe9ff29d4002f393223d3e7b3ed;p=platal.git diff --git a/include/platal/smarty.plugins.inc.php b/include/platal/smarty.plugins.inc.php index 4c79fd1..e3109e9 100644 --- a/include/platal/smarty.plugins.inc.php +++ b/include/platal/smarty.plugins.inc.php @@ -1,6 +1,6 @@ '<', '>' => '>', '"' => '"', '\'' => '''); + $transtbl = Array('<' => '<', '>' => '>', '"' => '"', '\'' => '''); return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};)/", "&" , strtr($string, $transtbl)); } else { return $string; @@ -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;