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