PluginProbe
ShiftController Employee Shift Scheduling / 4.9.59
ShiftController Employee Shift Scheduling v4.9.59
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / hc3 / request.php

request.php in ShiftController Employee Shift Scheduling 4.9.59, at hc3/request.php

232 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (! defined('ABSPATH')) exit; // Exit if accessed directly
2 interface HC3_Request_
3 {
4 public function initParam( $k, $v );
5 public function setParam( $k, $v );
6 public function getSlug();
7 public function getParams( $withoutDefault = FALSE );
8
9 public function getMethod();
10 public function getIpAddress();
11 public function getUserAgent();
12 public function getCookie( $index );
13 public function getReferrer();
14
15 public function isPrintView();
16 public function isAjax();
17 }
18
19 class HC3_Request implements HC3_Request_
20 {
21 protected $url = null;
22 protected $initParams = array();
23 protected $setParams = array();
24 public $realSlug = '';
25 public $post, $uri;
26
27 public function __construct(
28 HC3_Uri $uri,
29 HC3_Post $post,
30
31 HC3_UriAction $uriAction
32 )
33 {
34 if( ! defined('WPINC') ){
35 $this->_sanitizeGet();
36 $this->_sanitizeCookie();
37 }
38
39 $method = $this->getMethod();
40 if( $method != 'get' ){
41 $this->uri = $uriAction;
42 if( $referrer = $this->getReferrer() ){
43 $uri->fromUrl( $referrer );
44 // echo "URI FROM URL '$referrer'<br>";
45 // exit;
46 }
47 }
48 else {
49 $this->uri = $uri;
50 }
51
52 $this->post = $post;
53 }
54
55 public function getReferrer()
56 {
57 $return = NULL;
58 if( isset($_SERVER['HTTP_REFERER']) && strlen($_SERVER['HTTP_REFERER']) ){
59 $return = $_SERVER['HTTP_REFERER'];
60 }
61 return $return;
62 }
63
64 public function isAjax()
65 {
66 $return = FALSE;
67 if( isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') ){
68 $return = TRUE;
69 }
70 return $return;
71 }
72
73 public function initParam( $k, $v )
74 {
75 $this->initParams[ $k ] = $v;
76 return $this;
77 }
78
79 public function setParam( $k, $v )
80 {
81 $this->setParams[ $k ] = $v;
82 return $this;
83 }
84
85 public function getSlug()
86 {
87 $hca = $this->post->get('hca');
88 if( $hca ){
89 $slug = $hca;
90 }
91 else {
92 $slug = $this->uri->getSlug();
93 }
94
95 if( null === $slug ){
96 $slug = '';
97 }
98
99 return $slug;
100 }
101
102 public function setRealSlug( $slug )
103 {
104 $this->realSlug = $slug;
105 return $this;
106 }
107
108 public function getRealSlug()
109 {
110 return $this->realSlug;
111 }
112
113 public function getParams( $withoutDefault = FALSE )
114 {
115 $return = $this->uri->getParams();
116
117 if( ! $withoutDefault ){
118 $return = array_merge( $this->initParams, $return );
119 }
120
121 $return = array_merge( $return, $this->setParams );
122 return $return;
123 }
124
125 public function isPrintView()
126 {
127 $return = FALSE;
128 $params = $this->getParams();
129 if( array_key_exists('print', $params) && ($params['print']) ){
130 $return = TRUE;
131 }
132 return $return;
133 }
134
135 public function getMethod()
136 {
137 $return = isset($_SERVER['REQUEST_METHOD']) ? strtolower($_SERVER['REQUEST_METHOD']) : 'get';
138 return $return;
139 }
140
141 public function getIpAddress()
142 {
143 $return = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0';
144 return $return;
145 }
146
147 public function getUserAgent()
148 {
149 $return = ( ! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT'];
150 return $return;
151 }
152
153 public function getCookie( $index )
154 {
155 return $this->_fetch_from_array( $_COOKIE, $index );
156 }
157
158 protected function _fetch_from_array($array, $index = '')
159 {
160 if ( ! isset($array[$index])){
161 return FALSE;
162 }
163 return $array[$index];
164 }
165
166 protected function _sanitizeGet()
167 {
168 if (is_array($_GET) AND count($_GET) > 0){
169 foreach ($_GET as $key => $val){
170 $_GET[$this->_cleanInputKeys($key)] = $this->_cleanInputData($val);
171 }
172 }
173 }
174
175 protected function _sanitizeCookie()
176 {
177 if (is_array($_COOKIE) AND count($_COOKIE) > 0){
178 unset($_COOKIE['$Version']);
179 unset($_COOKIE['$Path']);
180 unset($_COOKIE['$Domain']);
181
182 foreach ($_COOKIE as $key => $val){
183 $_COOKIE[$this->_cleanInputKeys($key)] = $this->_cleanInputData($val);
184 }
185 }
186 }
187
188 protected function _cleanInputKeys( $str )
189 {
190 if ( ! preg_match("/^[a-z0-9:_\/\-\~]+$/i", $str)){
191 exit('Disallowed Key Characters on: ' . '"' . $str . '"' . '<br>');
192 }
193 return $str;
194 }
195
196 protected function _cleanInputData( $str )
197 {
198 if( is_array($str) ){
199 $new_array = array();
200 foreach ($str as $key => $val){
201 $new_array[$this->_cleanInputKeys($key)] = $this->_cleanInputData($val);
202 }
203 return $new_array;
204 }
205
206 /* We strip slashes if magic quotes is on to keep things consistent
207 NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and
208 it will probably not exist in future versions at all.
209 */
210 $need_strip = FALSE;
211 if( version_compare(PHP_VERSION, '5.4', '<') && get_magic_quotes_gpc() ){
212 $need_strip = TRUE;
213 }
214 elseif( defined('WPINC') ){
215 $need_strip = TRUE;
216 }
217
218 if( $need_strip ){
219 $str = stripslashes($str);
220 }
221
222 // Remove control characters
223 $str = HC3_Functions::removeInvisibleCharacters($str);
224
225 // Standardize newlines
226 if (strpos($str, "\r") !== FALSE){
227 $str = str_replace(array("\r\n", "\r", "\r\n\n"), PHP_EOL, $str);
228 }
229
230 return $str;
231 }
232 }