Move some templates in the core.
[platal.git] / classes / env.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
179afa7f 3 * Copyright (C) 2003-2008 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($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
6995a9b9 49 public static function b($key, $default = false)
0337d704 50 {
51 return (bool)Env::_get($key, $default);
52 }
53
6995a9b9 54 public static function i($key, $default = 0)
0337d704 55 {
56 $i = Env::_get($key, $default);
29e515ed 57 return is_numeric($i) ? intval($i) : $default;
0337d704 58 }
7280eb45 59
60 public static function l(array $keys)
61 {
62 return array_map(array('Env', 'v'), $keys);
63 }
0337d704 64}
65
0337d704 66class Post
67{
6995a9b9 68 public static function _get($key, $default)
0337d704 69 {
70 return isset($_POST[$key]) ? $_POST[$key] : $default;
71 }
5e2307dc 72
6995a9b9 73 public static function has($key)
0337d704 74 {
75 return isset($_POST[$key]);
76 }
5e2307dc 77
6995a9b9 78 public static function kill($key)
0337d704 79 {
80 unset($_POST[$key]);
81 }
82
6995a9b9 83 public static function v($key, $default = null)
0337d704 84 {
85 return Post::_get($key, $default);
86 }
87
6995a9b9 88 public static function b($key, $default = false)
0337d704 89 {
90 return (bool)Post::_get($key, $default);
91 }
92
eaf30d86
PH
93 public static function s($key, $default = '')
94 {
95 return (string)Post::_get($key, $default);
96 }
7280eb45 97
6995a9b9 98 public static function i($key, $default = 0)
0337d704 99 {
100 $i = Post::_get($key, $default);
29e515ed 101 return is_numeric($i) ? intval($i) : $default;
0337d704 102 }
7280eb45 103
104 public static function l(array $keys)
105 {
106 return array_map(array('Post', 'v'), $keys);
107 }
0337d704 108}
109
0337d704 110class Get
111{
6995a9b9 112 public static function _get($key, $default)
0337d704 113 {
114 return isset($_GET[$key]) ? $_GET[$key] : $default;
115 }
5e2307dc 116
6995a9b9 117 public static function has($key)
0337d704 118 {
119 return isset($_GET[$key]);
120 }
5e2307dc 121
6995a9b9 122 public static function kill($key)
0337d704 123 {
124 unset($_GET[$key]);
125 }
126
6995a9b9 127 public static function v($key, $default = null)
0337d704 128 {
129 return Get::_get($key, $default);
130 }
131
6995a9b9 132 public static function b($key, $default = false)
0337d704 133 {
134 return (bool)Get::_get($key, $default);
135 }
136
7280eb45 137 public static function s($key, $default = '')
138 {
139 return (string)Get::_get($key, $default);
140 }
141
6995a9b9 142 public static function i($key, $default = 0)
0337d704 143 {
144 $i = Get::_get($key, $default);
29e515ed 145 return is_numeric($i) ? intval($i) : $default;
0337d704 146 }
7280eb45 147
148 public static function l(array $keys)
149 {
150 return array_map(array('Get', 'v'), $keys);
151 }
0337d704 152}
153
0337d704 154class Cookie
155{
6995a9b9 156 public static function _get($key, $default)
0337d704 157 {
158 return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default;
159 }
5e2307dc 160
6995a9b9 161 public static function has($key)
0337d704 162 {
163 return isset($_COOKIE[$key]);
164 }
5e2307dc 165
6995a9b9 166 public static function kill($key)
0337d704 167 {
168 unset($_COOKIE[$key]);
169 }
170
6995a9b9 171 public static function v($key, $default = null)
0337d704 172 {
173 return Cookie::_get($key, $default);
174 }
175
eaf30d86 176 public static function s($key, $default = '')
7280eb45 177 {
eaf30d86 178 return (string)Cookie::_get($key, $default);
7280eb45 179 }
180
6995a9b9 181 public static function b($key, $default = false)
0337d704 182 {
183 return (bool)Cookie::_get($key, $default);
184 }
185
6995a9b9 186 public static function i($key, $default = 0)
0337d704 187 {
188 $i = Cookie::_get($key, $default);
29e515ed 189 return is_numeric($i) ? intval($i) : $default;
0337d704 190 }
7280eb45 191
192 public static function l(array $keys)
193 {
194 return array_map(array('Cookie', 'v'), $keys);
195 }
0337d704 196}
197
0337d704 198function fix_gpc_magic(&$item, $key) {
199 if (is_array($item)) {
200 array_walk($item, 'fix_gpc_magic');
201 } else {
202 $item = stripslashes($item);
203 }
204}
205
5e2307dc 206if (ini_get('magic_quotes_gpc') && empty($DONT_FIX_GPC)) {
0337d704 207 array_walk($_GET, 'fix_gpc_magic');
208 array_walk($_POST, 'fix_gpc_magic');
209 array_walk($_COOKIE, 'fix_gpc_magic');
210 array_walk($_REQUEST, 'fix_gpc_magic');
211}
212
a7de4ef7 213// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0337d704 214?>