| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2011 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 t($key, $default = '') |
| 50 | { |
| 51 | return trim(Env::s($key, $default)); |
| 52 | } |
| 53 | |
| 54 | public static function blank($key, $strict = false) |
| 55 | { |
| 56 | if (!Env::has($key)) { |
| 57 | return true; |
| 58 | } |
| 59 | $var = $strict ? Env::s($key) : Env::t($key); |
| 60 | return empty($var); |
| 61 | } |
| 62 | |
| 63 | public static function b($key, $default = false) |
| 64 | { |
| 65 | return (bool)Env::_get($key, $default); |
| 66 | } |
| 67 | |
| 68 | public static function i($key, $default = 0) |
| 69 | { |
| 70 | $i = to_integer(Env::_get($key, $default)); |
| 71 | return $i === false ? $default : $i; |
| 72 | } |
| 73 | |
| 74 | public static function l(array $keys) |
| 75 | { |
| 76 | return array_map(array('Env', 'v'), $keys); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | class Post |
| 81 | { |
| 82 | public static function _get($key, $default) |
| 83 | { |
| 84 | return isset($_POST[$key]) ? $_POST[$key] : $default; |
| 85 | } |
| 86 | |
| 87 | public static function has($key) |
| 88 | { |
| 89 | return isset($_POST[$key]); |
| 90 | } |
| 91 | |
| 92 | public static function kill($key) |
| 93 | { |
| 94 | unset($_POST[$key]); |
| 95 | } |
| 96 | |
| 97 | public static function v($key, $default = null) |
| 98 | { |
| 99 | return Post::_get($key, $default); |
| 100 | } |
| 101 | |
| 102 | public static function b($key, $default = false) |
| 103 | { |
| 104 | return (bool)Post::_get($key, $default); |
| 105 | } |
| 106 | |
| 107 | public static function s($key, $default = '') |
| 108 | { |
| 109 | return (string)Post::_get($key, $default); |
| 110 | } |
| 111 | |
| 112 | public static function t($key, $default = '') |
| 113 | { |
| 114 | return trim(Post::s($key, $default)); |
| 115 | } |
| 116 | |
| 117 | public static function blank($key, $strict = false) |
| 118 | { |
| 119 | if (!Post::has($key)) { |
| 120 | return true; |
| 121 | } |
| 122 | $var = $strict ? Post::s($key) : Post::t($key); |
| 123 | return empty($var); |
| 124 | } |
| 125 | |
| 126 | public static function i($key, $default = 0) |
| 127 | { |
| 128 | $i = to_integer(Post::_get($key, $default)); |
| 129 | return $i === false ? $default : $i; |
| 130 | } |
| 131 | |
| 132 | public static function l(array $keys) |
| 133 | { |
| 134 | return array_map(array('Post', 'v'), $keys); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | class Get |
| 139 | { |
| 140 | public static function _get($key, $default) |
| 141 | { |
| 142 | return isset($_GET[$key]) ? $_GET[$key] : $default; |
| 143 | } |
| 144 | |
| 145 | public static function has($key) |
| 146 | { |
| 147 | return isset($_GET[$key]); |
| 148 | } |
| 149 | |
| 150 | public static function kill($key) |
| 151 | { |
| 152 | unset($_GET[$key]); |
| 153 | } |
| 154 | |
| 155 | public static function v($key, $default = null) |
| 156 | { |
| 157 | return Get::_get($key, $default); |
| 158 | } |
| 159 | |
| 160 | public static function b($key, $default = false) |
| 161 | { |
| 162 | return (bool)Get::_get($key, $default); |
| 163 | } |
| 164 | |
| 165 | public static function s($key, $default = '') |
| 166 | { |
| 167 | return (string)Get::_get($key, $default); |
| 168 | } |
| 169 | |
| 170 | public static function t($key, $default = '') |
| 171 | { |
| 172 | return trim(Get::s($key, $default)); |
| 173 | } |
| 174 | |
| 175 | public static function blank($key, $strict = false) |
| 176 | { |
| 177 | if (!Get::has($key)) { |
| 178 | return true; |
| 179 | } |
| 180 | $var = $strict ? Get::s($key) : Get::t($key); |
| 181 | return empty($var); |
| 182 | } |
| 183 | |
| 184 | public static function i($key, $default = 0) |
| 185 | { |
| 186 | $i = to_integer(Get::_get($key, $default)); |
| 187 | return $i === false ? $default : $i; |
| 188 | } |
| 189 | |
| 190 | public static function l(array $keys) |
| 191 | { |
| 192 | return array_map(array('Get', 'v'), $keys); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | class Cookie |
| 197 | { |
| 198 | public static function _get($key, $default) |
| 199 | { |
| 200 | global $globals; |
| 201 | $key = $globals->cookie_ns . $key; |
| 202 | return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default; |
| 203 | } |
| 204 | |
| 205 | public static function has($key) |
| 206 | { |
| 207 | global $globals; |
| 208 | $key = $globals->cookie_ns . $key; |
| 209 | return isset($_COOKIE[$key]); |
| 210 | } |
| 211 | |
| 212 | public static function kill($key) |
| 213 | { |
| 214 | global $globals; |
| 215 | $key = $globals->cookie_ns . $key; |
| 216 | setcookie($key, '', time() - 3600, $globals->cookie_path); |
| 217 | unset($_COOKIE[$key]); |
| 218 | } |
| 219 | |
| 220 | public static function set($key, $value, $days, $secure = false) { |
| 221 | global $globals; |
| 222 | $key = $globals->cookie_ns . $key; |
| 223 | if (!$secure || @$_SERVER['HTTPS']) { |
| 224 | setcookie($key, $value, time() + 86400 * $days, $globals->cookie_path, '', |
| 225 | $secure, $secure); |
| 226 | $_COOKIE[$key] = $value; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | public static function v($key, $default = null) |
| 231 | { |
| 232 | return Cookie::_get($key, $default); |
| 233 | } |
| 234 | |
| 235 | public static function s($key, $default = '') |
| 236 | { |
| 237 | return (string)Cookie::_get($key, $default); |
| 238 | } |
| 239 | |
| 240 | public static function t($key, $default = '') |
| 241 | { |
| 242 | return trim(Cookie::s($key, $default)); |
| 243 | } |
| 244 | |
| 245 | public static function blank($key, $strict = false) |
| 246 | { |
| 247 | if (!Cookie::has($key)) { |
| 248 | return true; |
| 249 | } |
| 250 | $var = $strict ? Cookie::s($key) : Cookie::t($key); |
| 251 | return empty($var); |
| 252 | } |
| 253 | |
| 254 | public static function b($key, $default = false) |
| 255 | { |
| 256 | return (bool)Cookie::_get($key, $default); |
| 257 | } |
| 258 | |
| 259 | public static function i($key, $default = 0) |
| 260 | { |
| 261 | $i = to_integer(Cookie::_get($key, $default)); |
| 262 | return $i === false ? $default : $i; |
| 263 | } |
| 264 | |
| 265 | public static function l(array $keys) |
| 266 | { |
| 267 | return array_map(array('Cookie', 'v'), $keys); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | function fix_gpc_magic(&$item, $key) { |
| 272 | if (is_array($item)) { |
| 273 | array_walk($item, 'fix_gpc_magic'); |
| 274 | } else { |
| 275 | $item = stripslashes($item); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | if (ini_get('magic_quotes_gpc') && empty($DONT_FIX_GPC)) { |
| 280 | array_walk($_GET, 'fix_gpc_magic'); |
| 281 | array_walk($_POST, 'fix_gpc_magic'); |
| 282 | array_walk($_COOKIE, 'fix_gpc_magic'); |
| 283 | array_walk($_REQUEST, 'fix_gpc_magic'); |
| 284 | } |
| 285 | |
| 286 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 287 | ?> |