3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
5 * This file is a part of Codendi.
7 * Codendi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Codendi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Codendi. If not, see <http://www.gnu.org/licenses/>.
22 require_once 'common/include/Codendi_Request.class.php';
28 class HTTPRequest extends Codendi_Request {
33 function HTTPRequest() {
34 parent::Codendi_Request($_REQUEST);
39 * Get the value of $variable in $this->params (server side values).
41 * @param string $variable Name of the parameter to get.
42 * @return mixed If the variable exist, the value is returned (string)
43 * otherwise return false;
45 function getFromServer($variable) {
46 return $this->_get($variable, $_SERVER);
50 * Check if current request is send via 'post' method.
52 * This method is useful to test if the current request comes from a form.
57 if($_SERVER['REQUEST_METHOD'] == 'POST') {
65 * Return true if browser used to submit the request is netscape 4.
69 function browserIsNetscape4() {
70 return browser_is_netscape4();
74 * Singleton method for the class.
76 * @return mixed HTTPRequest Object.
78 static function &instance() {
79 static $_httprequest_instance;
80 if (!$_httprequest_instance) {
81 $_httprequest_instance = new HTTPRequest();
83 return $_httprequest_instance;
87 * Validate file upload.
89 * @param Valid_File Validator for files.
92 function validFile(&$validator) {
93 if(is_a($validator, 'Valid_File')) {
94 $this->_validated_input[$validator->getKey()] = true;
95 return $validator->validate($_FILES, $validator->getKey());
102 * Remove slashes in $value. If $value is an array, remove slashes for each
106 * @param mixed $value
109 function _stripslashes($value) {
110 if (is_string($value)) {
111 $value = stripslashes($value);
112 } elseif (is_array($value)) {
113 foreach($value as $key => $val) {
114 $value[$key] = $this->_stripslashes($val);
121 * Get the value of $variable in $array. If magic_quotes are enabled, the
125 * @param string $variable Name of the parameter to get.
126 * @param array $array Name of the parameter to get.
129 function _get($variable, $array) {
130 if ($this->_exist($variable, $array)) {
131 return (get_magic_quotes_gpc()?$this->_stripslashes($array[$variable]):$array[$variable]);