| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2007 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 | public static function _get($key, $default) |
| 25 | { |
| 26 | return isset($_REQUEST[$key]) ? $_REQUEST[$key] : $default; |
| 27 | } |
| 28 | |
| 29 | public static function has($key) |
| 30 | { |
| 31 | return isset($_REQUEST[$key]); |
| 32 | } |
| 33 | |
| 34 | public static function kill($key) |
| 35 | { |
| 36 | unset($_REQUEST[$key]); |
| 37 | } |
| 38 | |
| 39 | public static function v($key, $default = null) |
| 40 | { |
| 41 | return Env::_get($key, $default); |
| 42 | } |
| 43 | |
| 44 | public static function s($key, $default = '') |
| 45 | { |
| 46 | return (string)Env::_get($key, $default); |
| 47 | } |
| 48 | |
| 49 | public static function b($key, $default = false) |
| 50 | { |
| 51 | return (bool)Env::_get($key, $default); |
| 52 | } |
| 53 | |
| 54 | public static function i($key, $default = 0) |
| 55 | { |
| 56 | $i = Env::_get($key, $default); |
| 57 | return is_numeric($i) ? intval($i) : $default; |
| 58 | } |
| 59 | |
| 60 | public static function l(array $keys) |
| 61 | { |
| 62 | return array_map(array('Env', 'v'), $keys); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | class Post |
| 67 | { |
| 68 | public static function _get($key, $default) |
| 69 | { |
| 70 | return isset($_POST[$key]) ? $_POST[$key] : $default; |
| 71 | } |
| 72 | |
| 73 | public static function has($key) |
| 74 | { |
| 75 | return isset($_POST[$key]); |
| 76 | } |
| 77 | |
| 78 | public static function kill($key) |
| 79 | { |
| 80 | unset($_POST[$key]); |
| 81 | } |
| 82 | |
| 83 | public static function v($key, $default = null) |
| 84 | { |
| 85 | return Post::_get($key, $default); |
| 86 | } |
| 87 | |
| 88 | public static function b($key, $default = false) |
| 89 | { |
| 90 | return (bool)Post::_get($key, $default); |
| 91 | } |
| 92 | |
| 93 | public static function s($key, $default = '') |
| 94 | { |
| 95 | return (string)Post::_get($key, $default); |
| 96 | } |
| 97 | |
| 98 | public static function i($key, $default = 0) |
| 99 | { |
| 100 | $i = Post::_get($key, $default); |
| 101 | return is_numeric($i) ? intval($i) : $default; |
| 102 | } |
| 103 | |
| 104 | public static function l(array $keys) |
| 105 | { |
| 106 | return array_map(array('Post', 'v'), $keys); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | class Get |
| 111 | { |
| 112 | public static function _get($key, $default) |
| 113 | { |
| 114 | return isset($_GET[$key]) ? $_GET[$key] : $default; |
| 115 | } |
| 116 | |
| 117 | public static function has($key) |
| 118 | { |
| 119 | return isset($_GET[$key]); |
| 120 | } |
| 121 | |
| 122 | public static function kill($key) |
| 123 | { |
| 124 | unset($_GET[$key]); |
| 125 | } |
| 126 | |
| 127 | public static function v($key, $default = null) |
| 128 | { |
| 129 | return Get::_get($key, $default); |
| 130 | } |
| 131 | |
| 132 | public static function b($key, $default = false) |
| 133 | { |
| 134 | return (bool)Get::_get($key, $default); |
| 135 | } |
| 136 | |
| 137 | public static function s($key, $default = '') |
| 138 | { |
| 139 | return (string)Get::_get($key, $default); |
| 140 | } |
| 141 | |
| 142 | public static function i($key, $default = 0) |
| 143 | { |
| 144 | $i = Get::_get($key, $default); |
| 145 | return is_numeric($i) ? intval($i) : $default; |
| 146 | } |
| 147 | |
| 148 | public static function l(array $keys) |
| 149 | { |
| 150 | return array_map(array('Get', 'v'), $keys); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | class Cookie |
| 155 | { |
| 156 | public static function _get($key, $default) |
| 157 | { |
| 158 | return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default; |
| 159 | } |
| 160 | |
| 161 | public static function has($key) |
| 162 | { |
| 163 | return isset($_COOKIE[$key]); |
| 164 | } |
| 165 | |
| 166 | public static function kill($key) |
| 167 | { |
| 168 | unset($_COOKIE[$key]); |
| 169 | } |
| 170 | |
| 171 | public static function v($key, $default = null) |
| 172 | { |
| 173 | return Cookie::_get($key, $default); |
| 174 | } |
| 175 | |
| 176 | public static function s($key, $default = '') |
| 177 | { |
| 178 | return (string)Cookie::_get($key, $default); |
| 179 | } |
| 180 | |
| 181 | public static function b($key, $default = false) |
| 182 | { |
| 183 | return (bool)Cookie::_get($key, $default); |
| 184 | } |
| 185 | |
| 186 | public static function i($key, $default = 0) |
| 187 | { |
| 188 | $i = Cookie::_get($key, $default); |
| 189 | return is_numeric($i) ? intval($i) : $default; |
| 190 | } |
| 191 | |
| 192 | public static function l(array $keys) |
| 193 | { |
| 194 | return array_map(array('Cookie', 'v'), $keys); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | function 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 | |
| 206 | if (ini_get('magic_quotes_gpc') && empty($DONT_FIX_GPC)) { |
| 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 | |
| 213 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 214 | ?> |