f1481ab5058bab6d9b90be1270df10aa8270c586
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 $tags = array('script', 'pre', 'textarea');
75 foreach ($tags as $tag) {
76 preg_match_all("!<{$tag}[^>]+>.*?</{$tag}>!is", $source, $
{$tag});
77 $source = preg_replace("!<{$tag}[^>]+>.*?</{$tag}>!is", "&&&{$tag}&&&", $source);
80 // remove all leading spaces, tabs and carriage returns NOT
81 // preceeded by a php close tag.
82 $source = preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source);
84 foreach ($tags as $tag) {
85 $source = preg_replace("!&&&{$tag}&&&!e", 'array_shift(${$tag}[0])', $source);
92 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: