Fixes in carnet rss
[platal.git] / classes / env.php
... / ...
CommitLineData
1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2006 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
22class 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 b($key, $default = false)
45 {
46 return (bool)Env::_get($key, $default);
47 }
48
49 public static function i($key, $default = 0)
50 {
51 $i = Env::_get($key, $default);
52 return is_numeric($i) ? intval($i) : $default;
53 }
54}
55
56class Post
57{
58 public static function _get($key, $default)
59 {
60 return isset($_POST[$key]) ? $_POST[$key] : $default;
61 }
62
63 public static function has($key)
64 {
65 return isset($_POST[$key]);
66 }
67
68 public static function kill($key)
69 {
70 unset($_POST[$key]);
71 }
72
73 public static function v($key, $default = null)
74 {
75 return Post::_get($key, $default);
76 }
77
78 public static function b($key, $default = false)
79 {
80 return (bool)Post::_get($key, $default);
81 }
82
83 public static function i($key, $default = 0)
84 {
85 $i = Post::_get($key, $default);
86 return is_numeric($i) ? intval($i) : $default;
87 }
88}
89
90class Get
91{
92 public static function _get($key, $default)
93 {
94 return isset($_GET[$key]) ? $_GET[$key] : $default;
95 }
96
97 public static function has($key)
98 {
99 return isset($_GET[$key]);
100 }
101
102 public static function kill($key)
103 {
104 unset($_GET[$key]);
105 }
106
107 public static function v($key, $default = null)
108 {
109 return Get::_get($key, $default);
110 }
111
112 public static function b($key, $default = false)
113 {
114 return (bool)Get::_get($key, $default);
115 }
116
117 public static function i($key, $default = 0)
118 {
119 $i = Get::_get($key, $default);
120 return is_numeric($i) ? intval($i) : $default;
121 }
122}
123
124class Cookie
125{
126 public static function _get($key, $default)
127 {
128 return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default;
129 }
130
131 public static function has($key)
132 {
133 return isset($_COOKIE[$key]);
134 }
135
136 public static function kill($key)
137 {
138 unset($_COOKIE[$key]);
139 }
140
141 public static function v($key, $default = null)
142 {
143 return Cookie::_get($key, $default);
144 }
145
146 public static function b($key, $default = false)
147 {
148 return (bool)Cookie::_get($key, $default);
149 }
150
151 public static function i($key, $default = 0)
152 {
153 $i = Cookie::_get($key, $default);
154 return is_numeric($i) ? intval($i) : $default;
155 }
156}
157
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}
165
166if (ini_get('magic_quotes_gpc') && empty($DONT_FIX_GPC)) {
167 array_walk($_GET, 'fix_gpc_magic');
168 array_walk($_POST, 'fix_gpc_magic');
169 array_walk($_COOKIE, 'fix_gpc_magic');
170 array_walk($_REQUEST, 'fix_gpc_magic');
171}
172
173// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
174?>