aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/request/request.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes/request/request.php')
-rw-r--r--phpBB/includes/request/request.php71
1 files changed, 68 insertions, 3 deletions
diff --git a/phpBB/includes/request/request.php b/phpBB/includes/request/request.php
index 7d284a9bf7..8659ee8998 100644
--- a/phpBB/includes/request/request.php
+++ b/phpBB/includes/request/request.php
@@ -32,7 +32,8 @@ class phpbb_request implements phpbb_request_interface
phpbb_request_interface::POST => '_POST',
phpbb_request_interface::GET => '_GET',
phpbb_request_interface::REQUEST => '_REQUEST',
- phpbb_request_interface::COOKIE => '_COOKIE'
+ phpbb_request_interface::COOKIE => '_COOKIE',
+ phpbb_request_interface::SERVER => '_SERVER',
);
/**
@@ -193,11 +194,12 @@ class phpbb_request implements phpbb_request_interface
* Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks
* @param phpbb_request_interface::POST|GET|REQUEST|COOKIE $super_global
* Specifies which super global should be used
+ * @param bool $html_encode When true, html encoding will be applied
*
* @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the
* the same as that of $default. If the variable is not set $default is returned.
*/
- public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST)
+ public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST, $html_encode = true)
{
$path = false;
@@ -236,12 +238,55 @@ class phpbb_request implements phpbb_request_interface
}
}
- $this->type_cast_helper->recursive_set_var($var, $default, $multibyte);
+ $this->type_cast_helper->recursive_set_var($var, $default, $multibyte, $html_encode);
return $var;
}
/**
+ * Shortcut method to retrieve SERVER variables.
+ *
+ * Also fall back to getenv(), some CGI setups may need it (probably not, but
+ * whatever).
+ *
+ * @param string|array $var_name See phpbb_request_interface::variable
+ * @param mixed $Default See phpbb_request_interface::variable
+ * @param bool $html_encode See phpbb_request_interface::variable
+ *
+ * @return mixed The server variable value.
+ */
+ public function server($var_name, $default = '', $html_encode = false)
+ {
+ $multibyte = true;
+
+ if ($this->is_set($var_name, phpbb_request_interface::SERVER))
+ {
+ return $this->variable($var_name, $default, $multibyte, phpbb_request_interface::SERVER, $html_encode);
+ }
+ else
+ {
+ $var = getenv($var_name);
+ $this->type_cast_helper->recursive_set_var($var, $default, $multibyte, $html_encode);
+ return $var;
+ }
+ }
+
+ /**
+ * Shortcut method to retrieve the value of client HTTP headers.
+ *
+ * @param string|array $header_name The name of the header to retrieve.
+ * @param mixed $default See phpbb_request_interface::variable
+ * @param bool $html_encode See phpbb_request_interface::variable
+ *
+ * @return mixed The header value.
+ */
+ public function header($header_name, $default = '', $html_encode = true)
+ {
+ $var_name = 'HTTP_' . str_replace('-', '_', strtoupper($header_name));
+ return $this->server($var_name, $default, $html_encode);
+ }
+
+ /**
* Checks whether a certain variable was sent via POST.
* To make sure that a request was sent using POST you should call this function
* on at least one variable.
@@ -272,6 +317,26 @@ class phpbb_request implements phpbb_request_interface
}
/**
+ * Checks whether the current request is an AJAX request (XMLHttpRequest)
+ *
+ * @return bool True if the current request is an ajax request
+ */
+ public function is_ajax()
+ {
+ return $this->header('X-Requested-With') == 'XMLHttpRequest';
+ }
+
+ /**
+ * Checks if the current request is happening over HTTPS.
+ *
+ * @return bool True if the request is secure.
+ */
+ public function is_secure()
+ {
+ return $this->server('HTTPS') == 'on';
+ }
+
+ /**
* Returns all variable names for a given super global
*
* @param phpbb_request_interface::POST|GET|REQUEST|COOKIE $super_global