3 # Copyright (C) 2005 Jason Woofenden
5 # This file is part of wfpl.
7 # wfpl is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU Lesser General Public License as published by the Free
9 # Software Foundation; either version 2.1 of the License, or (at your option)
12 # wfpl is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with wfpl; if not, write to the Free Software Foundation, Inc., 51
19 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 # This file contains basic encodings. These are used by the encoder. You can
23 # specify any template tag to be encoded with this syntax: ~variable.encoding~
25 # this example: <p>~foo.html~</p>
26 # will encode foo (using enc_html()) before displaying it, so that characters
27 # such as < will display properly.
30 # encode for putting within double-quotes in SQL
31 function enc_sql($str) {
32 $str = str_replace("\\", "\\\\", $str);
33 $str = str_replace('"', "\\\"", $str);
37 # Encode for output in html. does nothing with whitespace
39 # Example: <p>~foo.html~</p>
40 function enc_html($str) {
41 $str = str_replace('&', '&', $str);
42 $str = str_replace('<', '<', $str);
43 $str = str_replace('>', '>', $str);
50 # Example: <input name="foo" value="~foo.attr~">
51 function enc_attr($str) {
52 $str = str_replace('&', '&', $str);
53 $str = str_replace('"', '"', $str);
59 # Example: <a href="http://example.com?foo=~foo.url_val.attr~">http://example.com?foo=~foo.url_val~</a>
60 function enc_url_val($str) {
61 return rawurlencode($str);
64 # This is a hack to work around html's stupid syntax for checkboxes.
66 # Place the template marker just before a " somewhere.
68 # Example: <input type="checkbox" name="foo~foo.checked~">
69 function enc_checked($str) {
71 return '" checked="checked';
77 # add a tab at the begining of each non-empty line
78 function enc_tab($str) {
79 $lines = explode("\n", $str);
81 foreach($lines as $line) {
88 # remove the extra newline added above
89 return substr($out, 0, -1);