2006 => 2007 Happy New Year\!
[platal.git] / classes / env.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
5ddeb07c 3 * Copyright (C) 2003-2007 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
6995a9b9 44 public static function b($key, $default = false)
0337d704 45 {
46 return (bool)Env::_get($key, $default);
47 }
48
6995a9b9 49 public static function i($key, $default = 0)
0337d704 50 {
51 $i = Env::_get($key, $default);
29e515ed 52 return is_numeric($i) ? intval($i) : $default;
0337d704 53 }
0337d704 54}
55
0337d704 56class Post
57{
6995a9b9 58 public static function _get($key, $default)
0337d704 59 {
60 return isset($_POST[$key]) ? $_POST[$key] : $default;
61 }
5e2307dc 62
6995a9b9 63 public static function has($key)
0337d704 64 {
65 return isset($_POST[$key]);
66 }
5e2307dc 67
6995a9b9 68 public static function kill($key)
0337d704 69 {
70 unset($_POST[$key]);
71 }
72
6995a9b9 73 public static function v($key, $default = null)
0337d704 74 {
75 return Post::_get($key, $default);
76 }
77
6995a9b9 78 public static function b($key, $default = false)
0337d704 79 {
80 return (bool)Post::_get($key, $default);
81 }
82
6995a9b9 83 public static function i($key, $default = 0)
0337d704 84 {
85 $i = Post::_get($key, $default);
29e515ed 86 return is_numeric($i) ? intval($i) : $default;
0337d704 87 }
0337d704 88}
89
0337d704 90class Get
91{
6995a9b9 92 public static function _get($key, $default)
0337d704 93 {
94 return isset($_GET[$key]) ? $_GET[$key] : $default;
95 }
5e2307dc 96
6995a9b9 97 public static function has($key)
0337d704 98 {
99 return isset($_GET[$key]);
100 }
5e2307dc 101
6995a9b9 102 public static function kill($key)
0337d704 103 {
104 unset($_GET[$key]);
105 }
106
6995a9b9 107 public static function v($key, $default = null)
0337d704 108 {
109 return Get::_get($key, $default);
110 }
111
6995a9b9 112 public static function b($key, $default = false)
0337d704 113 {
114 return (bool)Get::_get($key, $default);
115 }
116
6995a9b9 117 public static function i($key, $default = 0)
0337d704 118 {
119 $i = Get::_get($key, $default);
29e515ed 120 return is_numeric($i) ? intval($i) : $default;
0337d704 121 }
0337d704 122}
123
0337d704 124class Cookie
125{
6995a9b9 126 public static function _get($key, $default)
0337d704 127 {
128 return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default;
129 }
5e2307dc 130
6995a9b9 131 public static function has($key)
0337d704 132 {
133 return isset($_COOKIE[$key]);
134 }
5e2307dc 135
6995a9b9 136 public static function kill($key)
0337d704 137 {
138 unset($_COOKIE[$key]);
139 }
140
6995a9b9 141 public static function v($key, $default = null)
0337d704 142 {
143 return Cookie::_get($key, $default);
144 }
145
6995a9b9 146 public static function b($key, $default = false)
0337d704 147 {
148 return (bool)Cookie::_get($key, $default);
149 }
150
6995a9b9 151 public static function i($key, $default = 0)
0337d704 152 {
153 $i = Cookie::_get($key, $default);
29e515ed 154 return is_numeric($i) ? intval($i) : $default;
0337d704 155 }
0337d704 156}
157
0337d704 158function fix_gpc_magic(&$item, $key) {
159 if (is_array($item)) {
160 array_walk($item, 'fix_gpc_magic');
161 } else {
162 $item = stripslashes($item);
163 }
164}
ae0832b8 165function fix_encoding(&$item, $key) {
166 if (is_array($item)) {
167 array_walk($item, 'fix_encoding');
168 } elseif (preg_match('/[\x80-\x9f]/', $item)) {
169 $item = iconv('CP1252', 'ISO-8859-15//TRANSLIT', $item);
170 }
171}
0337d704 172
5e2307dc 173if (ini_get('magic_quotes_gpc') && empty($DONT_FIX_GPC)) {
0337d704 174 array_walk($_GET, 'fix_gpc_magic');
175 array_walk($_POST, 'fix_gpc_magic');
176 array_walk($_COOKIE, 'fix_gpc_magic');
177 array_walk($_REQUEST, 'fix_gpc_magic');
178}
ae0832b8 179array_walk($_POST, 'fix_encoding');
0337d704 180
181// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
182?>