Util_Request.php
2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
namespace W3TC;
/**
* W3 Request object
*/
/**
* class Request
*/
class Util_Request {
/**
* Returns request value
*
* @param string $key
* @param mixed $default
* @return mixed
*/
static function get( $key, $default = null ) {
$request = Util_Request::get_request();
if ( isset( $request[$key] ) ) {
$value = $request[$key];
if ( defined( 'TEMPLATEPATH' ) || get_magic_quotes_gpc() ) {
$value = Util_Environment::stripslashes( $value );
}
return $value;
}
return $default;
}
/**
* Returns string value
*
* @param string $key
* @param string $default
* @param boolean $trim
* @return string
*/
static function get_string( $key, $default = '', $trim = true ) {
$value = (string) Util_Request::get( $key, $default );
return ( $trim ) ? trim( $value ) : $value;
}
/**
* Returns integer value
*
* @param string $key
* @param integer $default
* @return integer
*/
static function get_integer( $key, $default = 0 ) {
return (integer) Util_Request::get( $key, $default );
}
/**
* Returns double value
*
* @param string $key
* @param double|float $default
* @return double
*/
static function get_double( $key, $default = 0. ) {
return (double) Util_Request::get( $key, $default );
}
/**
* Returns boolean value
*
* @param string $key
* @param boolean $default
* @return boolean
*/
static function get_boolean( $key, $default = false ) {
return Util_Environment::to_boolean( Util_Request::get( $key, $default ) );
}
/**
* Returns array value
*
* @param string $key
* @param array $default
* @return array
*/
static function get_array( $key, $default = array() ) {
$value = Util_Request::get( $key );
if ( is_array( $value ) ) {
return $value;
} elseif ( $value != '' ) {
return preg_split( "/[\r\n,;]+/", trim( $value ) );
}
return $default;
}
/**
* Returns array value
*
* @param string $prefix
* @param array $default
* @return array
*/
static function get_as_array( $prefix, $default = array() ) {
$request = Util_Request::get_request();
$array = array();
foreach ( $request as $key => $value ) {
if ( strpos( $key, $prefix ) === 0 || strpos( $key, str_replace( '.', '_', $prefix ) ) === 0 ) {
$array[substr( $key, strlen( $prefix ) )] = $value;
}
}
return $array;
}
/**
* Returns request array
*
* @return array
*/
static function get_request() {
if ( !isset( $_GET ) ) {
$_GET = array();
}
if ( !isset( $_POST ) ) {
$_POST = array();
}
return array_merge( $_GET, $_POST );
}
}