PluginProbe
ShiftController Employee Shift Scheduling / 4.9.66
ShiftController Employee Shift Scheduling v4.9.66
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.66, at hc3/request.php

238 lines 5.1 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 setSlug( $slug )
86 {
87 $this->uri->setSlug( $slug );
88 return $this;
89 }
90
91 public function getSlug()
92 {
93 $hca = $this->post->get('hca');
94 if( $hca ){
95 $slug = $hca;
96 }
97 else {
98 $slug = $this->uri->getSlug();
99 }
100
101 if( null === $slug ){
102 $slug = '';
103 }
104
105 return $slug;
106 }
107
108 public function setRealSlug( $slug )
109 {
110 $this->realSlug = $slug;
111 return $this;
112 }
113
114 public function getRealSlug()
115 {
116 return $this->realSlug;
117 }
118
119 public function getParams( $withoutDefault = FALSE )
120 {
121 $return = $this->uri->getParams();
122
123 if( ! $withoutDefault ){
124 $return = array_merge( $this->initParams, $return );
125 }
126
127 $return = array_merge( $return, $this->setParams );
128 return $return;
129 }
130
131 public function isPrintView()
132 {
133 $return = FALSE;
134 $params = $this->getParams();
135 if( array_key_exists('print', $params) && ($params['print']) ){
136 $return = TRUE;
137 }
138 return $return;
139 }
140
141 public function getMethod()
142 {
143 $return = isset($_SERVER['REQUEST_METHOD']) ? strtolower($_SERVER['REQUEST_METHOD']) : 'get';
144 return $return;
145 }
146
147 public function getIpAddress()
148 {
149 $return = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0';
150 return $return;
151 }
152
153 public function getUserAgent()
154 {
155 $return = ( ! isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT'];
156 return $return;
157 }
158
159 public function getCookie( $index )
160 {
161 return $this->_fetch_from_array( $_COOKIE, $index );
162 }
163
164 protected function _fetch_from_array($array, $index = '')
165 {
166 if ( ! isset($array[$index])){
167 return FALSE;
168 }
169 return $array[$index];
170 }
171
172 protected function _sanitizeGet()
173 {
174 if (is_array($_GET) AND count($_GET) > 0){
175 foreach ($_GET as $key => $val){
176 $_GET[$this->_cleanInputKeys($key)] = $this->_cleanInputData($val);
177 }
178 }
179 }
180
181 protected function _sanitizeCookie()
182 {
183 if (is_array($_COOKIE) AND count($_COOKIE) > 0){
184 unset($_COOKIE['$Version']);
185 unset($_COOKIE['$Path']);
186 unset($_COOKIE['$Domain']);
187
188 foreach ($_COOKIE as $key => $val){
189 $_COOKIE[$this->_cleanInputKeys($key)] = $this->_cleanInputData($val);
190 }
191 }
192 }
193
194 protected function _cleanInputKeys( $str )
195 {
196 if ( ! preg_match("/^[a-z0-9:_\/\-\~]+$/i", $str)){
197 exit('Disallowed Key Characters on: ' . '"' . $str . '"' . '<br>');
198 }
199 return $str;
200 }
201
202 protected function _cleanInputData( $str )
203 {
204 if( is_array($str) ){
205 $new_array = array();
206 foreach ($str as $key => $val){
207 $new_array[$this->_cleanInputKeys($key)] = $this->_cleanInputData($val);
208 }
209 return $new_array;
210 }
211
212 /* We strip slashes if magic quotes is on to keep things consistent
213 NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and
214 it will probably not exist in future versions at all.
215 */
216 $need_strip = FALSE;
217 if( version_compare(PHP_VERSION, '5.4', '<') && get_magic_quotes_gpc() ){
218 $need_strip = TRUE;
219 }
220 elseif( defined('WPINC') ){
221 $need_strip = TRUE;
222 }
223
224 if( $need_strip ){
225 $str = stripslashes($str);
226 }
227
228 // Remove control characters
229 $str = HC3_Functions::removeInvisibleCharacters($str);
230
231 // Standardize newlines
232 if (strpos($str, "\r") !== FALSE){
233 $str = str_replace(array("\r\n", "\r", "\r\n\n"), PHP_EOL, $str);
234 }
235
236 return $str;
237 }
238 }