2 /***************************************************************************
3 * Copyright (C) 2003-2004 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 // {{{ function escape_html ()
25 * default smarty plugin, used to auto-escape dangerous html.
30 * & not followed by some entity --> &
32 function escape_html($string)
34 if(is_string($string)) {
35 $transtbl = Array('<' => '<', '>' => '>', '"' => '"');
36 return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};)/", "&" , strtr($string, $transtbl));
43 // {{{ function at_to_globals()
49 function _to_globals($s) {
53 return var_export($globals->$t[0],true
);
55 return var_export($globals->$t[0]->$t[1],true
);
60 * compilation plugin used to import $globals confing through #globals.foo.bar# directives
63 function at_to_globals($tpl_source, &$smarty)
65 return preg_replace('/#globals\.([a-zA-Z0-9_.]+?)#/e', '_to_globals(\'\\1\')', $tpl_source);
69 // {{{ function trimwhitespace
71 function trimwhitespace($source, &$smarty)
73 // Pull out the script blocks
74 preg_match_all("!<script[^>]+>.*?</script>!is", $source, $match);
75 $_script_blocks = $match[0];
76 $source = preg_replace("!<script[^>]+>.*?</script>!is", '@@@SMARTY:TRIM:SCRIPT@@@', $source);
78 // Pull out the pre blocks
79 preg_match_all("!<pre>.*?</pre>!is", $source, $match);
80 $_pre_blocks = $match[0];
81 $source = preg_replace("!<pre>.*?</pre>!is", '@@@SMARTY:TRIM:PRE@@@', $source);
83 // Pull out the textarea blocks
84 preg_match_all("!<textarea[^>]+>.*?</textarea>!is", $source, $match);
85 $_textarea_blocks = $match[0];
86 $source = preg_replace("!<textarea[^>]+>.*?</textarea>!is", '@@@SMARTY:TRIM:TEXTAREA@@@', $source);
88 // remove all leading spaces, tabs and carriage returns NOT
89 // preceeded by a php close tag.
90 $source = preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source);
92 // replace script blocks
93 foreach($_script_blocks as $curr_block) {
94 $source = preg_replace("!@@@SMARTY:TRIM:SCRIPT@@@!", $curr_block, $source, 1);
97 foreach($_pre_blocks as $curr_block) {
98 $source = preg_replace("!@@@SMARTY:TRIM:PRE@@@!",$curr_block,$source,1);
100 // replace textarea blocks
101 foreach($_textarea_blocks as $curr_block) {
102 $source = preg_replace("!@@@SMARTY:TRIM:TEXTAREA@@@!",$curr_block,$source,1);
109 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: