PluginProbe
ShiftController Employee Shift Scheduling / 4.9.24
ShiftController Employee Shift Scheduling v4.9.24
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.24, at hc3/request.php

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