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