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 / uri.php

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

329 lines 7.2 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_IUri
3 {
4 public function setAssetsPath( $path );
5 public function assetsPath( $src );
6 public function getSlug();
7 public function getParams();
8 public function makeUrl( $slug = NULL, $proto = NULL );
9 public function baseUrl();
10 public function fromUrl( $url );
11 public function isFullUrl( $url );
12 public function currentUrl();
13 }
14
15 if( ! defined('HC3_URI_NO_PORT') ) define( 'HC3_URI_NO_PORT', true );
16
17 class HC3_Uri implements HC3_IUri
18 {
19 protected $_hca = 'hca';
20 protected $_hcj = 'hcj';
21 // protected $_hcr = 'hcr';
22 protected $_hcr = '';
23 protected $_hcrValue = NULL;
24
25 protected $_separatorToParams = ':';
26 // protected $_separatorToParams = '*';
27 protected $_suffixForMulti = '_';
28 protected $_separatorForMulti = '|';
29
30 protected $baseUrl = NULL;
31 protected $baseParams = array();
32 protected $slug = NULL;
33 protected $rawParams = array();
34 protected $params = array();
35
36 protected $assetsPath = NULL;
37
38 public function __construct()
39 {
40 $this->fromUrl( $this->currentUrl() );
41 if( strlen($this->_hcr) ){
42 $this->_hcrValue = mt_rand(1000, 9999);
43 }
44 }
45
46 public function setAssetsPath( $path )
47 {
48 $this->assetsPath = $path;
49 return $this;
50 }
51
52 public function assetsPath( $src )
53 {
54 $return = $this->assetsPath ? $this->assetsPath : $this->baseUrl();
55 return $return;
56 }
57
58 public function getSlug()
59 {
60 return $this->slug;
61 }
62
63 public function getParams()
64 {
65 return $this->params;
66 }
67
68 public function makeUrl( $slug = NULL, $proto = NULL )
69 {
70 $params = array();
71 if( is_array($slug) ){
72 list( $slug, $params ) = $slug;
73 }
74
75 if( $this->isFullUrl($slug) ){
76 return $slug;
77 }
78
79 if( $slug == '-referrer-' ){
80 if( isset($_SERVER['HTTP_REFERER']) && strlen($_SERVER['HTTP_REFERER']) ){
81 $this->fromUrl( $_SERVER['HTTP_REFERER'] );
82 $slug = $this->getSlug();
83 // $return = $_SERVER['HTTP_REFERER'];
84 // return $return;
85 }
86 }
87
88 $href_params = $this->baseParams;
89
90 $hca_param = NULL;
91 if( $slug ){
92 $hca_param = $slug;
93
94 // pesist params within the same slug
95 if( $slug == $this->slug && ($params !== NULL) ){
96 $params = array_merge( $this->params, $params );
97 }
98 }
99
100 // pesist params within the same slug
101 if( (NULL == $slug) && (! $this->slug) ){
102 $params = array_merge( $this->params, $params );
103 }
104
105 if( $params ){
106 $params_string = $this->_buildHcaParams( $params );
107 if( strlen($params_string) ){
108 $hca_param .= $this->_separatorToParams . $params_string;
109 }
110 }
111
112 if( $hca_param ){
113 // add random to avoid unnecessary caching
114 $href_params[$this->_hca] = $hca_param;
115 if( $this->_hcrValue ){
116 $href_params[$this->_hcr] = $this->_hcrValue;
117 }
118 }
119
120 $return = $this->baseUrl;
121 if( $href_params ){
122 $href_params = http_build_query($href_params);
123 $href_params = urldecode( $href_params );
124
125 $glue = (strpos($return, '?') === FALSE) ? '?' : '&';
126 $return .= $glue . $href_params;
127 }
128
129 if( NULL !== $proto ){
130 // echo "PROTO = '$proto'<br>";
131 $starts = array( 'https://', 'http://', '//' );
132 foreach( $starts as $prefix ){
133 if( substr($return, 0, strlen($prefix)) == $prefix ){
134 $return = $proto . substr($return, strlen($prefix));
135 break;
136 }
137 }
138 }
139
140 return $return;
141 }
142
143 public function baseUrl()
144 {
145 $return = $this->baseUrl;
146 return $return;
147 }
148
149 public function fromUrl( $url )
150 {
151 $purl = parse_url( $url );
152
153 $baseUrl = $purl['scheme'] . '://'. $purl['host'];
154 if( isset($purl['port']) && (80 != $purl['port']) ){
155 if( FALSE === strpos($purl['host'], ':') ){
156 $baseUrl .= ':' . $purl['port'];
157 }
158 }
159 $baseUrl .= $purl['path'];
160
161 $this->baseUrl = $baseUrl;
162 $this->baseParams = array();
163 // $this->slug = NULL;
164
165 if( isset($purl['query']) && $purl['query']){
166 parse_str( $purl['query'], $base_params );
167
168 /* grab our hca */
169 if( isset($base_params[$this->_hca]) ){
170 // $this->slug = NULL;
171 $hca = $base_params[$this->_hca];
172
173 // trim slashes
174 $hca = trim($hca, '/');
175
176 $slug = $hca;
177 $params = array();
178
179 if( strpos($slug, $this->_separatorToParams) !== FALSE ){
180 list( $slug, $params ) = explode($this->_separatorToParams, $slug, 2);
181 $params = explode('/', $params);
182 }
183
184 $this->slug = $slug;
185 $this->rawParams = $params;
186 $this->params = $this->_parseHcaParams( $params );
187 }
188
189 /* base params */
190 unset( $base_params[$this->_hca] );
191 $this->baseParams = $base_params;
192 }
193 else {
194 $this->slug = NULL;
195 }
196
197 unset( $this->baseParams[$this->_hcj] );
198
199 return $this;
200 }
201
202 public function isFullUrl( $url )
203 {
204 $ret = false;
205
206 if( is_array($url) ){
207 $url = array_shift($url);
208 }
209
210 if( null === $url ){
211 $url = '';
212 }
213
214 $prfx = array( 'http://', 'https://', '//', 'webcal://' );
215 reset( $prfx );
216 foreach( $prfx as $prf ){
217 if( substr($url, 0, strlen($prf)) == $prf ){
218 $ret = true;
219 return $ret;
220 }
221 }
222
223 if( strpos($url, '.php') !== false ){
224 $ret = true;
225 return $ret;
226 }
227
228 return $ret;
229 }
230
231 public function currentUrl()
232 {
233 $noPort = defined( 'HC3_URI_NO_PORT' ) && HC3_URI_NO_PORT ? true : false;
234
235 $return = 'http';
236 if( isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on') ){
237 $return .= 's';
238 }
239
240 $return .= "://";
241
242 $host = '';
243 if( isset($_SERVER['HTTP_HOST']) && $_SERVER['SERVER_PORT'] != '80'){
244 if( FALSE === strpos($_SERVER['HTTP_HOST'], ':') ){
245 $host .= $_SERVER['HTTP_HOST'] . ':' . $_SERVER['SERVER_PORT'];
246 }
247 else {
248 $host .= $_SERVER['HTTP_HOST'];
249 }
250 }
251 else {
252 $host = $_SERVER['HTTP_HOST'];
253 }
254
255 if( $noPort ){
256 $pos = strpos( $host, ':' );
257 if( false !== $pos ){
258 $host = substr( $host, 0, $pos );
259 }
260 }
261
262 $return .= $host;
263
264 if ( ! empty($_SERVER['REQUEST_URI']) ){
265 $return .= $_SERVER['REQUEST_URI'];
266 }
267 else {
268 $return .= $_SERVER['SCRIPT_NAME'];
269 }
270
271 $return = urldecode( $return );
272 return $return;
273 }
274
275 protected function _buildHcaParams( $params )
276 {
277 $return = array();
278
279 foreach( $params as $k => $v ){
280 if( is_array($v) ){
281 if( ! $v ){
282 continue;
283 }
284 $k = $k . $this->_suffixForMulti;
285 $v = HC3_Functions::glueArray( $v );
286 // $v = join($this->_separatorForMulti, $v);
287 }
288 else {
289 if( $v === NULL ){
290 continue;
291 }
292 }
293 $return[] = $k . '/' . $v;
294 }
295
296 $return = join('/', $return);
297 return $return;
298 }
299
300 protected function _parseHcaParams( $rawParams )
301 {
302 $return = array();
303 for( $ii = 0; $ii < count($rawParams); $ii = $ii + 2 ){
304 if( ! isset($rawParams[$ii + 1]) ){
305 break;
306 }
307
308 $key = $rawParams[$ii];
309 $value = $rawParams[$ii + 1];
310
311 $needArray = (substr($key, -strlen($this->_suffixForMulti)) == $this->_suffixForMulti) ? TRUE : FALSE;
312 if( $needArray ){
313 $key = substr($key, 0, -strlen($this->_suffixForMulti));
314 $value = HC3_Functions::unglueArray( $value );
315 // $value = explode($this->_separatorForMulti, $value);
316 }
317
318 if( array_key_exists($key, $return) && $needArray ){
319 $return[$key] = array_merge( $return[$key], $value );
320 }
321 else {
322 $return[$key] = $value;
323 }
324 }
325
326 return $return;
327 }
328 }
329