3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
5 * This file is a part of Fusionforge.
7 * Fusionforge 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 * Fusionforge 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/>.
21 require_once 'common/include/Codendi_Request.class.php';
26 class HTTPRequest extends Codendi_Request {
31 function HTTPRequest() {
32 parent::Codendi_Request($_REQUEST);
36 * Get the value of $variable in $this->params (server side values).
38 * @param string $variable Name of the parameter to get.
39 * @return mixed If the variable exist, the value is returned (string)
40 * otherwise return false;
42 function getFromServer($variable) {
43 return $this->_get($variable, $_SERVER);
47 * Check if current request is send via 'post' method.
49 * This method is useful to test if the current request comes from a form.
54 if($_SERVER['REQUEST_METHOD'] == 'POST') {
62 * Return true if browser used to submit the request is netscape 4.
66 function browserIsNetscape4() {
67 return browser_is_netscape4();
71 * Singleton method for the class.
73 * @return mixed HTTPRequest Object.
75 static function &instance() {
76 static $_httprequest_instance;
77 if (!$_httprequest_instance) {
78 $_httprequest_instance = new HTTPRequest();
80 return $_httprequest_instance;
84 * Validate file upload.
86 * @param Valid_File Validator for files.
89 function validFile(&$validator) {
90 if(is_a($validator, 'Valid_File')) {
91 $this->_validated_input[$validator->getKey()] = true;
92 return $validator->validate($_FILES, $validator->getKey());
99 * Remove slashes in $value. If $value is an array, remove slashes for each
103 * @param mixed $value
106 function _stripslashes($value) {
107 if (is_string($value)) {
108 $value = stripslashes($value);
109 } elseif (is_array($value)) {
110 foreach($value as $key => $val) {
111 $value[$key] = $this->_stripslashes($val);
118 * Get the value of $variable in $array. If magic_quotes are enabled, the
122 * @param string $variable Name of the parameter to get.
123 * @param array $array Name of the parameter to get.
126 function _get($variable, $array) {
127 if ($this->_exist($variable, $array)) {
128 return (get_magic_quotes_gpc()?$this->_stripslashes($array[$variable]):$array[$variable]);