pending commit, finished during MQ/S download ...
[platal.git] / include / platal / env.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
50a40a33 3 * Copyright (C) 2003-2006 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
22// {{{ class Env
23
24class 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
88class 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
152class 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// }}}
0337d704 214// {{{ class Cookie
215
216class Cookie
217{
218 // {{{ function _get
219
220 function _get($key, $default)
221 {
222 return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default;
223 }
224
225 // }}}
226 // {{{ function has
227
228 function has($key)
229 {
230 return isset($_COOKIE[$key]);
231 }
232
233 // }}}
234 // {{{ function kill
235
236 function kill($key)
237 {
238 unset($_COOKIE[$key]);
239 }
240
241 // }}}
242 // {{{ function get
243
244 function get($key, $default='')
245 {
246 return (string)Cookie::_get($key, $default);
247 }
248
249 // }}}
250 // {{{ function &getMixed
251
252 function &getMixed($key, $default=null)
253 {
254 return Cookie::_get($key, $default);
255 }
256
257 // }}}
258 // {{{ function getBool
259
260 function getBool($key, $default=false)
261 {
262 return (bool)Cookie::_get($key, $default);
263 }
264
265 // }}}
266 // {{{ function getInt
267
268 function getInt($key, $default=0)
269 {
270 $i = Cookie::_get($key, $default);
271 return preg_match(',^[0-9]+$,', $i) ? intval($i) : $default;
272 }
273
274 // }}}
275}
276
277// }}}
278
279function fix_gpc_magic(&$item, $key) {
280 if (is_array($item)) {
281 array_walk($item, 'fix_gpc_magic');
282 } else {
283 $item = stripslashes($item);
284 }
285}
286
287function unfix_gpc_magic(&$item, $key) {
288 if (is_array($item)) {
925d64c1 289 array_walk($item, 'unfix_gpc_magic');
0337d704 290 } else {
291 $item = addslashes($item);
292 }
293}
294
295if (ini_get("magic_quotes_gpc")) {
296 array_walk($_GET, 'fix_gpc_magic');
297 array_walk($_POST, 'fix_gpc_magic');
298 array_walk($_COOKIE, 'fix_gpc_magic');
299 array_walk($_REQUEST, 'fix_gpc_magic');
300}
301
302// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
303?>