0337d704 |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2004 Polytechnique.org * |
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 | |
22 | // {{{ class Env |
23 | |
24 | class Env |
25 | { |
26 | // {{{ function _get |
27 | |
28 | function _get($key, $default) |
29 | { |
30 | return isset($_REQUEST[$key]) ? $_REQUEST[$key] : $default; |
31 | } |
32 | |
33 | // }}} |
34 | // {{{ function has |
35 | |
36 | function has($key) |
37 | { |
38 | return isset($_REQUEST[$key]); |
39 | } |
40 | |
41 | // }}} |
42 | // {{{ function kill |
43 | |
44 | function kill($key) |
45 | { |
46 | unset($_REQUEST[$key]); |
47 | } |
48 | |
49 | // }}} |
50 | // {{{ function get |
51 | |
52 | function get($key, $default='') |
53 | { |
54 | return (string)Env::_get($key, $default); |
55 | } |
56 | |
57 | // }}} |
58 | // {{{ function &getMixed |
59 | |
60 | function &getMixed($key, $default=null) |
61 | { |
62 | return Env::_get($key, $default); |
63 | } |
64 | |
65 | // }}} |
66 | // {{{ function getBool |
67 | |
68 | function getBool($key, $default=false) |
69 | { |
70 | return (bool)Env::_get($key, $default); |
71 | } |
72 | |
73 | // }}} |
74 | // {{{ function getInt |
75 | |
76 | function getInt($key, $default=0) |
77 | { |
78 | $i = Env::_get($key, $default); |
79 | return preg_match(',^[0-9]+$,', $i) ? intval($i) : $default; |
80 | } |
81 | |
82 | // }}} |
83 | } |
84 | |
85 | // }}} |
86 | // {{{ class Post |
87 | |
88 | class Post |
89 | { |
90 | // {{{ function _get |
91 | |
92 | function _get($key, $default) |
93 | { |
94 | return isset($_POST[$key]) ? $_POST[$key] : $default; |
95 | } |
96 | |
97 | // }}} |
98 | // {{{ function has |
99 | |
100 | function has($key) |
101 | { |
102 | return isset($_POST[$key]); |
103 | } |
104 | |
105 | // }}} |
106 | // {{{ function kill |
107 | |
108 | function kill($key) |
109 | { |
110 | unset($_POST[$key]); |
111 | } |
112 | |
113 | // }}} |
114 | // {{{ function get |
115 | |
116 | function get($key, $default='') |
117 | { |
118 | return (string)Post::_get($key, $default); |
119 | } |
120 | |
121 | // }}} |
122 | // {{{ function &getMixed |
123 | |
124 | function &getMixed($key, $default=null) |
125 | { |
126 | return Post::_get($key, $default); |
127 | } |
128 | |
129 | // }}} |
130 | // {{{ function getBool |
131 | |
132 | function getBool($key, $default=false) |
133 | { |
134 | return (bool)Post::_get($key, $default); |
135 | } |
136 | |
137 | // }}} |
138 | // {{{ function getInt |
139 | |
140 | function getInt($key, $default=0) |
141 | { |
142 | $i = Post::_get($key, $default); |
143 | return preg_match(',^[0-9]+$,', $i) ? intval($i) : $default; |
144 | } |
145 | |
146 | // }}} |
147 | } |
148 | |
149 | // }}} |
150 | // {{{ class Get |
151 | |
152 | class Get |
153 | { |
154 | // {{{ function _get |
155 | |
156 | function _get($key, $default) |
157 | { |
158 | return isset($_GET[$key]) ? $_GET[$key] : $default; |
159 | } |
160 | |
161 | // }}} |
162 | // {{{ function has |
163 | |
164 | function has($key) |
165 | { |
166 | return isset($_GET[$key]); |
167 | } |
168 | |
169 | // }}} |
170 | // {{{ function kill |
171 | |
172 | function kill($key) |
173 | { |
174 | unset($_GET[$key]); |
175 | } |
176 | |
177 | // }}} |
178 | // {{{ function get |
179 | |
180 | function get($key, $default='') |
181 | { |
182 | return (string)Get::_get($key, $default); |
183 | } |
184 | |
185 | // }}} |
186 | // {{{ function &getMixed |
187 | |
188 | function &getMixed($key, $default=null) |
189 | { |
190 | return Get::_get($key, $default); |
191 | } |
192 | |
193 | // }}} |
194 | // {{{ function getBool |
195 | |
196 | function getBool($key, $default=false) |
197 | { |
198 | return (bool)Get::_get($key, $default); |
199 | } |
200 | |
201 | // }}} |
202 | // {{{ function getInt |
203 | |
204 | function getInt($key, $default=0) |
205 | { |
206 | $i = Get::_get($key, $default); |
207 | return preg_match(',^[0-9]+$,', $i) ? intval($i) : $default; |
208 | } |
209 | |
210 | // }}} |
211 | } |
212 | |
213 | // }}} |
214 | // {{{ class Session |
215 | |
216 | class Session |
217 | { |
218 | // {{{ function _get |
219 | |
220 | function _get($key, $default) |
221 | { |
222 | return isset($_SESSION[$key]) ? $_SESSION[$key] : $default; |
223 | } |
224 | |
225 | // }}} |
226 | // {{{ function has |
227 | |
228 | function has($key) |
229 | { |
230 | return isset($_SESSION[$key]); |
231 | } |
232 | |
233 | // }}} |
234 | // {{{ function kill |
235 | |
236 | function kill($key) |
237 | { |
238 | unset($_SESSION[$key]); |
239 | } |
240 | |
241 | // }}} |
242 | // {{{ function get |
243 | |
244 | function get($key, $default='') |
245 | { |
246 | return (string)Session::_get($key, $default); |
247 | } |
248 | |
249 | // }}} |
250 | // {{{ function &getMixed |
251 | |
252 | function &getMixed($key, $default=null) |
253 | { |
254 | return Session::_get($key, $default); |
255 | } |
256 | |
257 | // }}} |
258 | // {{{ function getBool |
259 | |
260 | function getBool($key, $default=false) |
261 | { |
262 | return (bool)Session::_get($key, $default); |
263 | } |
264 | |
265 | // }}} |
266 | // {{{ function getInt |
267 | |
268 | function getInt($key, $default=0) |
269 | { |
270 | $i = Session::_get($key, $default); |
271 | return preg_match(',^[0-9]+$,', $i) ? intval($i) : $default; |
272 | } |
273 | |
274 | // }}} |
275 | } |
276 | |
277 | // }}} |
278 | // {{{ class Cookie |
279 | |
280 | class Cookie |
281 | { |
282 | // {{{ function _get |
283 | |
284 | function _get($key, $default) |
285 | { |
286 | return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default; |
287 | } |
288 | |
289 | // }}} |
290 | // {{{ function has |
291 | |
292 | function has($key) |
293 | { |
294 | return isset($_COOKIE[$key]); |
295 | } |
296 | |
297 | // }}} |
298 | // {{{ function kill |
299 | |
300 | function kill($key) |
301 | { |
302 | unset($_COOKIE[$key]); |
303 | } |
304 | |
305 | // }}} |
306 | // {{{ function get |
307 | |
308 | function get($key, $default='') |
309 | { |
310 | return (string)Cookie::_get($key, $default); |
311 | } |
312 | |
313 | // }}} |
314 | // {{{ function &getMixed |
315 | |
316 | function &getMixed($key, $default=null) |
317 | { |
318 | return Cookie::_get($key, $default); |
319 | } |
320 | |
321 | // }}} |
322 | // {{{ function getBool |
323 | |
324 | function getBool($key, $default=false) |
325 | { |
326 | return (bool)Cookie::_get($key, $default); |
327 | } |
328 | |
329 | // }}} |
330 | // {{{ function getInt |
331 | |
332 | function getInt($key, $default=0) |
333 | { |
334 | $i = Cookie::_get($key, $default); |
335 | return preg_match(',^[0-9]+$,', $i) ? intval($i) : $default; |
336 | } |
337 | |
338 | // }}} |
339 | } |
340 | |
341 | // }}} |
342 | |
343 | function fix_gpc_magic(&$item, $key) { |
344 | if (is_array($item)) { |
345 | array_walk($item, 'fix_gpc_magic'); |
346 | } else { |
347 | $item = stripslashes($item); |
348 | } |
349 | } |
350 | |
351 | function unfix_gpc_magic(&$item, $key) { |
352 | if (is_array($item)) { |
925d64c1 |
353 | array_walk($item, 'unfix_gpc_magic'); |
0337d704 |
354 | } else { |
355 | $item = addslashes($item); |
356 | } |
357 | } |
358 | |
359 | if (ini_get("magic_quotes_gpc")) { |
360 | array_walk($_GET, 'fix_gpc_magic'); |
361 | array_walk($_POST, 'fix_gpc_magic'); |
362 | array_walk($_COOKIE, 'fix_gpc_magic'); |
363 | array_walk($_REQUEST, 'fix_gpc_magic'); |
364 | } |
365 | |
366 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: |
367 | ?> |