Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
e92ecb8c | 3 | * Copyright (C) 2003-2011 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 | { |
e24eb48b FB |
70 | $i = to_integer(Env::_get($key, $default)); |
71 | return $i === false ? $default : $i; | |
0337d704 | 72 | } |
7280eb45 | 73 | |
74 | public static function l(array $keys) | |
75 | { | |
76 | return array_map(array('Env', 'v'), $keys); | |
77 | } | |
31dc3dd3 RB |
78 | |
79 | public static function set($key, $value) | |
80 | { | |
81 | $_REQUEST[$key] =& $value; | |
82 | } | |
83 | ||
84 | public static function bootstrap($key, $value) | |
85 | { | |
86 | if (!Env::has($key)) { | |
87 | Env::set($key, $value); | |
88 | } | |
89 | } | |
0337d704 | 90 | } |
91 | ||
0337d704 | 92 | class Post |
93 | { | |
6995a9b9 | 94 | public static function _get($key, $default) |
0337d704 | 95 | { |
96 | return isset($_POST[$key]) ? $_POST[$key] : $default; | |
97 | } | |
5e2307dc | 98 | |
6995a9b9 | 99 | public static function has($key) |
0337d704 | 100 | { |
101 | return isset($_POST[$key]); | |
102 | } | |
5e2307dc | 103 | |
6995a9b9 | 104 | public static function kill($key) |
0337d704 | 105 | { |
106 | unset($_POST[$key]); | |
107 | } | |
108 | ||
6995a9b9 | 109 | public static function v($key, $default = null) |
0337d704 | 110 | { |
111 | return Post::_get($key, $default); | |
112 | } | |
113 | ||
6995a9b9 | 114 | public static function b($key, $default = false) |
0337d704 | 115 | { |
116 | return (bool)Post::_get($key, $default); | |
117 | } | |
118 | ||
eaf30d86 PH |
119 | public static function s($key, $default = '') |
120 | { | |
121 | return (string)Post::_get($key, $default); | |
122 | } | |
7280eb45 | 123 | |
720e3261 FB |
124 | public static function t($key, $default = '') |
125 | { | |
126 | return trim(Post::s($key, $default)); | |
127 | } | |
128 | ||
129 | public static function blank($key, $strict = false) | |
130 | { | |
131 | if (!Post::has($key)) { | |
132 | return true; | |
133 | } | |
134 | $var = $strict ? Post::s($key) : Post::t($key); | |
135 | return empty($var); | |
136 | } | |
137 | ||
6995a9b9 | 138 | public static function i($key, $default = 0) |
0337d704 | 139 | { |
e24eb48b FB |
140 | $i = to_integer(Post::_get($key, $default)); |
141 | return $i === false ? $default : $i; | |
0337d704 | 142 | } |
7280eb45 | 143 | |
144 | public static function l(array $keys) | |
145 | { | |
146 | return array_map(array('Post', 'v'), $keys); | |
147 | } | |
31dc3dd3 RB |
148 | |
149 | public static function set($key, $value) | |
150 | { | |
151 | $_POST[$key] =& $value; | |
152 | } | |
153 | ||
154 | public static function bootstrap($key, $value) | |
155 | { | |
156 | if (!Post::has($key)) { | |
157 | Post::set($key, $value); | |
158 | } | |
159 | } | |
0337d704 | 160 | } |
161 | ||
0337d704 | 162 | class Get |
163 | { | |
6995a9b9 | 164 | public static function _get($key, $default) |
0337d704 | 165 | { |
166 | return isset($_GET[$key]) ? $_GET[$key] : $default; | |
167 | } | |
5e2307dc | 168 | |
6995a9b9 | 169 | public static function has($key) |
0337d704 | 170 | { |
171 | return isset($_GET[$key]); | |
172 | } | |
5e2307dc | 173 | |
6995a9b9 | 174 | public static function kill($key) |
0337d704 | 175 | { |
176 | unset($_GET[$key]); | |
177 | } | |
178 | ||
6995a9b9 | 179 | public static function v($key, $default = null) |
0337d704 | 180 | { |
181 | return Get::_get($key, $default); | |
182 | } | |
183 | ||
6995a9b9 | 184 | public static function b($key, $default = false) |
0337d704 | 185 | { |
186 | return (bool)Get::_get($key, $default); | |
187 | } | |
188 | ||
7280eb45 | 189 | public static function s($key, $default = '') |
190 | { | |
191 | return (string)Get::_get($key, $default); | |
192 | } | |
193 | ||
720e3261 FB |
194 | public static function t($key, $default = '') |
195 | { | |
196 | return trim(Get::s($key, $default)); | |
197 | } | |
198 | ||
199 | public static function blank($key, $strict = false) | |
200 | { | |
201 | if (!Get::has($key)) { | |
202 | return true; | |
203 | } | |
204 | $var = $strict ? Get::s($key) : Get::t($key); | |
205 | return empty($var); | |
206 | } | |
207 | ||
6995a9b9 | 208 | public static function i($key, $default = 0) |
0337d704 | 209 | { |
e24eb48b FB |
210 | $i = to_integer(Get::_get($key, $default)); |
211 | return $i === false ? $default : $i; | |
0337d704 | 212 | } |
7280eb45 | 213 | |
214 | public static function l(array $keys) | |
215 | { | |
216 | return array_map(array('Get', 'v'), $keys); | |
217 | } | |
31dc3dd3 RB |
218 | |
219 | public static function set($key, $value) | |
220 | { | |
221 | $_GET[$key] =& $value; | |
222 | } | |
223 | ||
224 | public static function bootstrap($key, $value) | |
225 | { | |
226 | if (!Get::has($key)) { | |
227 | Get::set($key, $value); | |
228 | } | |
229 | } | |
0337d704 | 230 | } |
231 | ||
0337d704 | 232 | class Cookie |
233 | { | |
6995a9b9 | 234 | public static function _get($key, $default) |
0337d704 | 235 | { |
f09d3319 FB |
236 | global $globals; |
237 | $key = $globals->cookie_ns . $key; | |
0337d704 | 238 | return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default; |
239 | } | |
5e2307dc | 240 | |
6995a9b9 | 241 | public static function has($key) |
0337d704 | 242 | { |
f09d3319 FB |
243 | global $globals; |
244 | $key = $globals->cookie_ns . $key; | |
0337d704 | 245 | return isset($_COOKIE[$key]); |
246 | } | |
5e2307dc | 247 | |
6995a9b9 | 248 | public static function kill($key) |
0337d704 | 249 | { |
f09d3319 FB |
250 | global $globals; |
251 | $key = $globals->cookie_ns . $key; | |
252 | setcookie($key, '', time() - 3600, $globals->cookie_path); | |
0337d704 | 253 | unset($_COOKIE[$key]); |
254 | } | |
255 | ||
ad27ee66 | 256 | public static function set($key, $value, $days, $secure = false) { |
f09d3319 FB |
257 | global $globals; |
258 | $key = $globals->cookie_ns . $key; | |
ad27ee66 FB |
259 | if (!$secure || @$_SERVER['HTTPS']) { |
260 | setcookie($key, $value, time() + 86400 * $days, $globals->cookie_path, '', | |
261 | $secure, $secure); | |
262 | $_COOKIE[$key] = $value; | |
263 | } | |
f09d3319 FB |
264 | } |
265 | ||
6995a9b9 | 266 | public static function v($key, $default = null) |
0337d704 | 267 | { |
268 | return Cookie::_get($key, $default); | |
269 | } | |
270 | ||
eaf30d86 | 271 | public static function s($key, $default = '') |
7280eb45 | 272 | { |
eaf30d86 | 273 | return (string)Cookie::_get($key, $default); |
7280eb45 | 274 | } |
275 | ||
720e3261 FB |
276 | public static function t($key, $default = '') |
277 | { | |
278 | return trim(Cookie::s($key, $default)); | |
279 | } | |
280 | ||
281 | public static function blank($key, $strict = false) | |
282 | { | |
283 | if (!Cookie::has($key)) { | |
284 | return true; | |
285 | } | |
286 | $var = $strict ? Cookie::s($key) : Cookie::t($key); | |
287 | return empty($var); | |
288 | } | |
289 | ||
6995a9b9 | 290 | public static function b($key, $default = false) |
0337d704 | 291 | { |
292 | return (bool)Cookie::_get($key, $default); | |
293 | } | |
294 | ||
6995a9b9 | 295 | public static function i($key, $default = 0) |
0337d704 | 296 | { |
e24eb48b FB |
297 | $i = to_integer(Cookie::_get($key, $default)); |
298 | return $i === false ? $default : $i; | |
0337d704 | 299 | } |
7280eb45 | 300 | |
301 | public static function l(array $keys) | |
302 | { | |
303 | return array_map(array('Cookie', 'v'), $keys); | |
304 | } | |
0337d704 | 305 | } |
306 | ||
0337d704 | 307 | function fix_gpc_magic(&$item, $key) { |
308 | if (is_array($item)) { | |
309 | array_walk($item, 'fix_gpc_magic'); | |
310 | } else { | |
311 | $item = stripslashes($item); | |
312 | } | |
313 | } | |
314 | ||
5e2307dc | 315 | if (ini_get('magic_quotes_gpc') && empty($DONT_FIX_GPC)) { |
0337d704 | 316 | array_walk($_GET, 'fix_gpc_magic'); |
317 | array_walk($_POST, 'fix_gpc_magic'); | |
318 | array_walk($_COOKIE, 'fix_gpc_magic'); | |
319 | array_walk($_REQUEST, 'fix_gpc_magic'); | |
320 | } | |
321 | ||
a7de4ef7 | 322 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 323 | ?> |