Add basic template parser and test
[hoplite.git] / base / filter.php
1 <?php
2 // Hoplite
3 // Copyright (c) 2011 Blue Static
4 //
5 // This program is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General License as published by the Free
7 // Software Foundation, either version 3 of the License, or any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General License for
12 // more details.
13 //
14 // You should have received a copy of the GNU General License along with
15 // this program. If not, see <http://www.gnu.org/licenses/>.
16
17 namespace hoplite\base\filter;
18
19 function TrimmedString($str)
20 {
21 return trim($str);
22 }
23
24 function String($str)
25 {
26 $find = array(
27 '<',
28 '>',
29 '"'
30 );
31 $replace = array(
32 '&lt;',
33 '&gt;',
34 '&quot;'
35 );
36 return str_replace($find, $replace, $str);
37 }
38
39 function Int($int)
40 {
41 return intval($int);
42 }
43
44 function Float($float)
45 {
46 return floatval($float);
47 }
48
49 function Bool($bool)
50 {
51 $str = strtolower(TrimmedString($bool));
52 if ($str == 'yes' || $str == 'true')
53 return TRUE;
54 else if ($str == 'no' || $str == 'false')
55 return FALSE;
56 return (bool)$bool;
57 }