0337d704 |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2004 Polytechnique.org * |
4 | * http://opensource.polytechnique.org/ * |
5 | * * |
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. * |
10 | * * |
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. * |
15 | * * |
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 * |
18 | * Foundation, Inc., * |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
20 | ***************************************************************************/ |
21 | |
22 | // {{{ function escape_html () |
23 | |
24 | /** |
25 | * default smarty plugin, used to auto-escape dangerous html. |
26 | * |
27 | * < --> < |
28 | * > --> > |
29 | * " --> " |
30 | * & not followed by some entity --> & |
31 | */ |
32 | function escape_html($string) |
33 | { |
34 | if(is_string($string)) { |
c1714ff5 |
35 | $transtbl = Array('<' => '<', '>' => '>', '"' => '"', '\'' => '''); |
0337d704 |
36 | return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};)/", "&" , strtr($string, $transtbl)); |
37 | } else { |
38 | return $string; |
39 | } |
40 | } |
41 | |
42 | // }}} |
43 | // {{{ function at_to_globals() |
44 | |
45 | /** |
46 | * helper |
47 | */ |
48 | |
49 | function _to_globals($s) { |
50 | global $globals; |
51 | $t = explode('.',$s); |
52 | if (count($t) == 1) { |
53 | return var_export($globals->$t[0],true); |
54 | } else { |
55 | return var_export($globals->$t[0]->$t[1],true); |
56 | } |
57 | } |
58 | |
59 | /** |
60 | * compilation plugin used to import $globals confing through #globals.foo.bar# directives |
61 | */ |
62 | |
63 | function at_to_globals($tpl_source, &$smarty) |
64 | { |
65 | return preg_replace('/#globals\.([a-zA-Z0-9_.]+?)#/e', '_to_globals(\'\\1\')', $tpl_source); |
66 | } |
67 | |
68 | // }}} |
69 | // {{{ function trimwhitespace |
70 | |
71 | function trimwhitespace($source, &$smarty) |
72 | { |
514d865a |
73 | $tags = array('script', 'pre', 'textarea'); |
0337d704 |
74 | |
514d865a |
75 | foreach ($tags as $tag) { |
76 | preg_match_all("!<{$tag}[^>]+>.*?</{$tag}>!is", $source, ${$tag}); |
77 | $source = preg_replace("!<{$tag}[^>]+>.*?</{$tag}>!is", "&&&{$tag}&&&", $source); |
78 | } |
0337d704 |
79 | |
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); |
83 | |
514d865a |
84 | foreach ($tags as $tag) { |
85 | $source = preg_replace("!&&&{$tag}&&&!e", 'array_shift(${$tag}[0])', $source); |
0337d704 |
86 | } |
87 | |
88 | return $source; |
89 | } |
90 | |
91 | // }}} |
92 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: |
93 | ?> |