Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
2ab75571 | 3 | * Copyright (C) 2003-2010 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 | { |
f09d3319 FB |
200 | global $globals; |
201 | $key = $globals->cookie_ns . $key; | |
0337d704 | 202 | return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default; |
203 | } | |
5e2307dc | 204 | |
6995a9b9 | 205 | public static function has($key) |
0337d704 | 206 | { |
f09d3319 FB |
207 | global $globals; |
208 | $key = $globals->cookie_ns . $key; | |
0337d704 | 209 | return isset($_COOKIE[$key]); |
210 | } | |
5e2307dc | 211 | |
6995a9b9 | 212 | public static function kill($key) |
0337d704 | 213 | { |
f09d3319 FB |
214 | global $globals; |
215 | $key = $globals->cookie_ns . $key; | |
216 | setcookie($key, '', time() - 3600, $globals->cookie_path); | |
0337d704 | 217 | unset($_COOKIE[$key]); |
218 | } | |
219 | ||
ad27ee66 | 220 | public static function set($key, $value, $days, $secure = false) { |
f09d3319 FB |
221 | global $globals; |
222 | $key = $globals->cookie_ns . $key; | |
ad27ee66 FB |
223 | if (!$secure || @$_SERVER['HTTPS']) { |
224 | setcookie($key, $value, time() + 86400 * $days, $globals->cookie_path, '', | |
225 | $secure, $secure); | |
226 | $_COOKIE[$key] = $value; | |
227 | } | |
f09d3319 FB |
228 | } |
229 | ||
6995a9b9 | 230 | public static function v($key, $default = null) |
0337d704 | 231 | { |
232 | return Cookie::_get($key, $default); | |
233 | } | |
234 | ||
eaf30d86 | 235 | public static function s($key, $default = '') |
7280eb45 | 236 | { |
eaf30d86 | 237 | return (string)Cookie::_get($key, $default); |
7280eb45 | 238 | } |
239 | ||
720e3261 FB |
240 | public static function t($key, $default = '') |
241 | { | |
242 | return trim(Cookie::s($key, $default)); | |
243 | } | |
244 | ||
245 | public static function blank($key, $strict = false) | |
246 | { | |
247 | if (!Cookie::has($key)) { | |
248 | return true; | |
249 | } | |
250 | $var = $strict ? Cookie::s($key) : Cookie::t($key); | |
251 | return empty($var); | |
252 | } | |
253 | ||
6995a9b9 | 254 | public static function b($key, $default = false) |
0337d704 | 255 | { |
256 | return (bool)Cookie::_get($key, $default); | |
257 | } | |
258 | ||
6995a9b9 | 259 | public static function i($key, $default = 0) |
0337d704 | 260 | { |
261 | $i = Cookie::_get($key, $default); | |
29e515ed | 262 | return is_numeric($i) ? intval($i) : $default; |
0337d704 | 263 | } |
7280eb45 | 264 | |
265 | public static function l(array $keys) | |
266 | { | |
267 | return array_map(array('Cookie', 'v'), $keys); | |
268 | } | |
0337d704 | 269 | } |
270 | ||
0337d704 | 271 | function fix_gpc_magic(&$item, $key) { |
272 | if (is_array($item)) { | |
273 | array_walk($item, 'fix_gpc_magic'); | |
274 | } else { | |
275 | $item = stripslashes($item); | |
276 | } | |
277 | } | |
278 | ||
5e2307dc | 279 | if (ini_get('magic_quotes_gpc') && empty($DONT_FIX_GPC)) { |
0337d704 | 280 | array_walk($_GET, 'fix_gpc_magic'); |
281 | array_walk($_POST, 'fix_gpc_magic'); | |
282 | array_walk($_COOKIE, 'fix_gpc_magic'); | |
283 | array_walk($_REQUEST, 'fix_gpc_magic'); | |
284 | } | |
285 | ||
a7de4ef7 | 286 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 287 | ?> |