Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
179afa7f | 3 | * Copyright (C) 2003-2008 Polytechnique.org * |
0337d704 | 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 | ||
0337d704 | 22 | class Env |
23 | { | |
6995a9b9 | 24 | public static function _get($key, $default) |
0337d704 | 25 | { |
26 | return isset($_REQUEST[$key]) ? $_REQUEST[$key] : $default; | |
27 | } | |
5e2307dc | 28 | |
6995a9b9 | 29 | public static function has($key) |
0337d704 | 30 | { |
31 | return isset($_REQUEST[$key]); | |
32 | } | |
5e2307dc | 33 | |
6995a9b9 | 34 | public static function kill($key) |
0337d704 | 35 | { |
36 | unset($_REQUEST[$key]); | |
37 | } | |
38 | ||
6995a9b9 | 39 | public static function v($key, $default = null) |
0337d704 | 40 | { |
41 | return Env::_get($key, $default); | |
42 | } | |
43 | ||
eaf30d86 PH |
44 | public static function s($key, $default = '') |
45 | { | |
46 | return (string)Env::_get($key, $default); | |
47 | } | |
7280eb45 | 48 | |
720e3261 FB |
49 | public static function t($key, $default = '') |
50 | { | |
51 | return trim(Env::s($key, $default)); | |
52 | } | |
53 | ||
54 | public static function blank($key, $strict = false) | |
55 | { | |
56 | if (!Env::has($key)) { | |
57 | return true; | |
58 | } | |
59 | $var = $strict ? Env::s($key) : Env::t($key); | |
60 | return empty($var); | |
61 | } | |
62 | ||
6995a9b9 | 63 | public static function b($key, $default = false) |
0337d704 | 64 | { |
65 | return (bool)Env::_get($key, $default); | |
66 | } | |
67 | ||
6995a9b9 | 68 | public static function i($key, $default = 0) |
0337d704 | 69 | { |
70 | $i = Env::_get($key, $default); | |
29e515ed | 71 | return is_numeric($i) ? intval($i) : $default; |
0337d704 | 72 | } |
7280eb45 | 73 | |
74 | public static function l(array $keys) | |
75 | { | |
76 | return array_map(array('Env', 'v'), $keys); | |
77 | } | |
0337d704 | 78 | } |
79 | ||
0337d704 | 80 | class Post |
81 | { | |
6995a9b9 | 82 | public static function _get($key, $default) |
0337d704 | 83 | { |
84 | return isset($_POST[$key]) ? $_POST[$key] : $default; | |
85 | } | |
5e2307dc | 86 | |
6995a9b9 | 87 | public static function has($key) |
0337d704 | 88 | { |
89 | return isset($_POST[$key]); | |
90 | } | |
5e2307dc | 91 | |
6995a9b9 | 92 | public static function kill($key) |
0337d704 | 93 | { |
94 | unset($_POST[$key]); | |
95 | } | |
96 | ||
6995a9b9 | 97 | public static function v($key, $default = null) |
0337d704 | 98 | { |
99 | return Post::_get($key, $default); | |
100 | } | |
101 | ||
6995a9b9 | 102 | public static function b($key, $default = false) |
0337d704 | 103 | { |
104 | return (bool)Post::_get($key, $default); | |
105 | } | |
106 | ||
eaf30d86 PH |
107 | public static function s($key, $default = '') |
108 | { | |
109 | return (string)Post::_get($key, $default); | |
110 | } | |
7280eb45 | 111 | |
720e3261 FB |
112 | public static function t($key, $default = '') |
113 | { | |
114 | return trim(Post::s($key, $default)); | |
115 | } | |
116 | ||
117 | public static function blank($key, $strict = false) | |
118 | { | |
119 | if (!Post::has($key)) { | |
120 | return true; | |
121 | } | |
122 | $var = $strict ? Post::s($key) : Post::t($key); | |
123 | return empty($var); | |
124 | } | |
125 | ||
6995a9b9 | 126 | public static function i($key, $default = 0) |
0337d704 | 127 | { |
128 | $i = Post::_get($key, $default); | |
29e515ed | 129 | return is_numeric($i) ? intval($i) : $default; |
0337d704 | 130 | } |
7280eb45 | 131 | |
132 | public static function l(array $keys) | |
133 | { | |
134 | return array_map(array('Post', 'v'), $keys); | |
135 | } | |
0337d704 | 136 | } |
137 | ||
0337d704 | 138 | class Get |
139 | { | |
6995a9b9 | 140 | public static function _get($key, $default) |
0337d704 | 141 | { |
142 | return isset($_GET[$key]) ? $_GET[$key] : $default; | |
143 | } | |
5e2307dc | 144 | |
6995a9b9 | 145 | public static function has($key) |
0337d704 | 146 | { |
147 | return isset($_GET[$key]); | |
148 | } | |
5e2307dc | 149 | |
6995a9b9 | 150 | public static function kill($key) |
0337d704 | 151 | { |
152 | unset($_GET[$key]); | |
153 | } | |
154 | ||
6995a9b9 | 155 | public static function v($key, $default = null) |
0337d704 | 156 | { |
157 | return Get::_get($key, $default); | |
158 | } | |
159 | ||
6995a9b9 | 160 | public static function b($key, $default = false) |
0337d704 | 161 | { |
162 | return (bool)Get::_get($key, $default); | |
163 | } | |
164 | ||
7280eb45 | 165 | public static function s($key, $default = '') |
166 | { | |
167 | return (string)Get::_get($key, $default); | |
168 | } | |
169 | ||
720e3261 FB |
170 | public static function t($key, $default = '') |
171 | { | |
172 | return trim(Get::s($key, $default)); | |
173 | } | |
174 | ||
175 | public static function blank($key, $strict = false) | |
176 | { | |
177 | if (!Get::has($key)) { | |
178 | return true; | |
179 | } | |
180 | $var = $strict ? Get::s($key) : Get::t($key); | |
181 | return empty($var); | |
182 | } | |
183 | ||
6995a9b9 | 184 | public static function i($key, $default = 0) |
0337d704 | 185 | { |
186 | $i = Get::_get($key, $default); | |
29e515ed | 187 | return is_numeric($i) ? intval($i) : $default; |
0337d704 | 188 | } |
7280eb45 | 189 | |
190 | public static function l(array $keys) | |
191 | { | |
192 | return array_map(array('Get', 'v'), $keys); | |
193 | } | |
0337d704 | 194 | } |
195 | ||
0337d704 | 196 | class Cookie |
197 | { | |
6995a9b9 | 198 | public static function _get($key, $default) |
0337d704 | 199 | { |
200 | return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default; | |
201 | } | |
5e2307dc | 202 | |
6995a9b9 | 203 | public static function has($key) |
0337d704 | 204 | { |
205 | return isset($_COOKIE[$key]); | |
206 | } | |
5e2307dc | 207 | |
6995a9b9 | 208 | public static function kill($key) |
0337d704 | 209 | { |
210 | unset($_COOKIE[$key]); | |
211 | } | |
212 | ||
6995a9b9 | 213 | public static function v($key, $default = null) |
0337d704 | 214 | { |
215 | return Cookie::_get($key, $default); | |
216 | } | |
217 | ||
eaf30d86 | 218 | public static function s($key, $default = '') |
7280eb45 | 219 | { |
eaf30d86 | 220 | return (string)Cookie::_get($key, $default); |
7280eb45 | 221 | } |
222 | ||
720e3261 FB |
223 | public static function t($key, $default = '') |
224 | { | |
225 | return trim(Cookie::s($key, $default)); | |
226 | } | |
227 | ||
228 | public static function blank($key, $strict = false) | |
229 | { | |
230 | if (!Cookie::has($key)) { | |
231 | return true; | |
232 | } | |
233 | $var = $strict ? Cookie::s($key) : Cookie::t($key); | |
234 | return empty($var); | |
235 | } | |
236 | ||
6995a9b9 | 237 | public static function b($key, $default = false) |
0337d704 | 238 | { |
239 | return (bool)Cookie::_get($key, $default); | |
240 | } | |
241 | ||
6995a9b9 | 242 | public static function i($key, $default = 0) |
0337d704 | 243 | { |
244 | $i = Cookie::_get($key, $default); | |
29e515ed | 245 | return is_numeric($i) ? intval($i) : $default; |
0337d704 | 246 | } |
7280eb45 | 247 | |
248 | public static function l(array $keys) | |
249 | { | |
250 | return array_map(array('Cookie', 'v'), $keys); | |
251 | } | |
0337d704 | 252 | } |
253 | ||
0337d704 | 254 | function fix_gpc_magic(&$item, $key) { |
255 | if (is_array($item)) { | |
256 | array_walk($item, 'fix_gpc_magic'); | |
257 | } else { | |
258 | $item = stripslashes($item); | |
259 | } | |
260 | } | |
261 | ||
5e2307dc | 262 | if (ini_get('magic_quotes_gpc') && empty($DONT_FIX_GPC)) { |
0337d704 | 263 | array_walk($_GET, 'fix_gpc_magic'); |
264 | array_walk($_POST, 'fix_gpc_magic'); | |
265 | array_walk($_COOKIE, 'fix_gpc_magic'); | |
266 | array_walk($_REQUEST, 'fix_gpc_magic'); | |
267 | } | |
268 | ||
a7de4ef7 | 269 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 270 | ?> |