@@ -6,7 +6,6 @@ |
||
6 | 6 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
7 | 7 | use EventEspresso\core\exceptions\InvalidSessionDataException; |
8 | 8 | use EventEspresso\core\services\cache\CacheStorageInterface; |
9 | -use EventEspresso\core\services\loaders\LoaderFactory; |
|
10 | 9 | use EventEspresso\core\services\request\RequestInterface; |
11 | 10 | use EventEspresso\core\services\session\SessionStartHandler; |
12 | 11 |
@@ -25,1259 +25,1259 @@ discard block |
||
25 | 25 | class EE_Session implements SessionIdentifierInterface |
26 | 26 | { |
27 | 27 | |
28 | - const session_id_prefix = 'ee_ssn_'; |
|
29 | - |
|
30 | - const hash_check_prefix = 'ee_shc_'; |
|
31 | - |
|
32 | - const OPTION_NAME_SETTINGS = 'ee_session_settings'; |
|
33 | - |
|
34 | - const STATUS_CLOSED = 0; |
|
35 | - |
|
36 | - const STATUS_OPEN = 1; |
|
37 | - |
|
38 | - /** |
|
39 | - * instance of the EE_Session object |
|
40 | - * |
|
41 | - * @var EE_Session |
|
42 | - */ |
|
43 | - private static $_instance; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var CacheStorageInterface $cache_storage |
|
47 | - */ |
|
48 | - protected $cache_storage; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var EE_Encryption $encryption |
|
52 | - */ |
|
53 | - protected $encryption; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var SessionStartHandler $session_start_handler |
|
57 | - */ |
|
58 | - protected $session_start_handler; |
|
59 | - |
|
60 | - /** |
|
61 | - * the session id |
|
62 | - * |
|
63 | - * @var string |
|
64 | - */ |
|
65 | - private $_sid; |
|
66 | - |
|
67 | - /** |
|
68 | - * session id salt |
|
69 | - * |
|
70 | - * @var string |
|
71 | - */ |
|
72 | - private $_sid_salt; |
|
73 | - |
|
74 | - /** |
|
75 | - * session data |
|
76 | - * |
|
77 | - * @var array |
|
78 | - */ |
|
79 | - private $_session_data = array(); |
|
80 | - |
|
81 | - /** |
|
82 | - * how long an EE session lasts |
|
83 | - * default session lifespan of 1 hour (for not so instant IPNs) |
|
84 | - * |
|
85 | - * @var SessionLifespan $session_lifespan |
|
86 | - */ |
|
87 | - private $session_lifespan; |
|
88 | - |
|
89 | - /** |
|
90 | - * session expiration time as Unix timestamp in GMT |
|
91 | - * |
|
92 | - * @var int |
|
93 | - */ |
|
94 | - private $_expiration; |
|
95 | - |
|
96 | - /** |
|
97 | - * whether or not session has expired at some point |
|
98 | - * |
|
99 | - * @var boolean |
|
100 | - */ |
|
101 | - private $_expired = false; |
|
102 | - |
|
103 | - /** |
|
104 | - * current time as Unix timestamp in GMT |
|
105 | - * |
|
106 | - * @var int |
|
107 | - */ |
|
108 | - private $_time; |
|
109 | - |
|
110 | - /** |
|
111 | - * whether to encrypt session data |
|
112 | - * |
|
113 | - * @var bool |
|
114 | - */ |
|
115 | - private $_use_encryption; |
|
116 | - |
|
117 | - /** |
|
118 | - * well... according to the server... |
|
119 | - * |
|
120 | - * @var null |
|
121 | - */ |
|
122 | - private $_user_agent; |
|
123 | - |
|
124 | - /** |
|
125 | - * do you really trust the server ? |
|
126 | - * |
|
127 | - * @var null |
|
128 | - */ |
|
129 | - private $_ip_address; |
|
130 | - |
|
131 | - /** |
|
132 | - * current WP user_id |
|
133 | - * |
|
134 | - * @var null |
|
135 | - */ |
|
136 | - private $_wp_user_id; |
|
137 | - |
|
138 | - /** |
|
139 | - * array for defining default session vars |
|
140 | - * |
|
141 | - * @var array |
|
142 | - */ |
|
143 | - private $_default_session_vars = array( |
|
144 | - 'id' => null, |
|
145 | - 'user_id' => null, |
|
146 | - 'ip_address' => null, |
|
147 | - 'user_agent' => null, |
|
148 | - 'init_access' => null, |
|
149 | - 'last_access' => null, |
|
150 | - 'expiration' => null, |
|
151 | - 'pages_visited' => array(), |
|
152 | - ); |
|
153 | - |
|
154 | - /** |
|
155 | - * timestamp for when last garbage collection cycle was performed |
|
156 | - * |
|
157 | - * @var int $_last_gc |
|
158 | - */ |
|
159 | - private $_last_gc; |
|
160 | - |
|
161 | - /** |
|
162 | - * @var RequestInterface $request |
|
163 | - */ |
|
164 | - protected $request; |
|
165 | - |
|
166 | - /** |
|
167 | - * whether session is active or not |
|
168 | - * |
|
169 | - * @var int $status |
|
170 | - */ |
|
171 | - private $status = EE_Session::STATUS_CLOSED; |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * @singleton method used to instantiate class object |
|
176 | - * @param CacheStorageInterface $cache_storage |
|
177 | - * @param SessionLifespan|null $lifespan |
|
178 | - * @param RequestInterface $request |
|
179 | - * @param SessionStartHandler $session_start_handler |
|
180 | - * @param EE_Encryption $encryption |
|
181 | - * @return EE_Session |
|
182 | - * @throws InvalidArgumentException |
|
183 | - * @throws InvalidDataTypeException |
|
184 | - * @throws InvalidInterfaceException |
|
185 | - */ |
|
186 | - public static function instance( |
|
187 | - CacheStorageInterface $cache_storage = null, |
|
188 | - SessionLifespan $lifespan = null, |
|
189 | - RequestInterface $request = null, |
|
190 | - SessionStartHandler $session_start_handler = null, |
|
191 | - EE_Encryption $encryption = null |
|
192 | - ) { |
|
193 | - // check if class object is instantiated |
|
194 | - // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
|
195 | - // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
196 | - if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
197 | - self::$_instance = new self( |
|
198 | - $cache_storage, |
|
199 | - $lifespan, |
|
200 | - $request, |
|
201 | - $session_start_handler, |
|
202 | - $encryption |
|
203 | - ); |
|
204 | - } |
|
205 | - return self::$_instance; |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * protected constructor to prevent direct creation |
|
211 | - * |
|
212 | - * @param CacheStorageInterface $cache_storage |
|
213 | - * @param SessionLifespan $lifespan |
|
214 | - * @param RequestInterface $request |
|
215 | - * @param SessionStartHandler $session_start_handler |
|
216 | - * @param EE_Encryption $encryption |
|
217 | - * @throws InvalidArgumentException |
|
218 | - * @throws InvalidDataTypeException |
|
219 | - * @throws InvalidInterfaceException |
|
220 | - */ |
|
221 | - protected function __construct( |
|
222 | - CacheStorageInterface $cache_storage, |
|
223 | - SessionLifespan $lifespan, |
|
224 | - RequestInterface $request, |
|
225 | - SessionStartHandler $session_start_handler, |
|
226 | - EE_Encryption $encryption = null |
|
227 | - ) { |
|
228 | - // session loading is turned ON by default, |
|
229 | - // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook |
|
230 | - // (which currently fires on the init hook at priority 9), |
|
231 | - // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
232 | - if (! apply_filters('FHEE_load_EE_Session', true)) { |
|
233 | - return; |
|
234 | - } |
|
235 | - $this->session_start_handler = $session_start_handler; |
|
236 | - $this->session_lifespan = $lifespan; |
|
237 | - $this->request = $request; |
|
238 | - if (! defined('ESPRESSO_SESSION')) { |
|
239 | - define('ESPRESSO_SESSION', true); |
|
240 | - } |
|
241 | - // retrieve session options from db |
|
242 | - $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
243 | - if (! empty($session_settings)) { |
|
244 | - // cycle though existing session options |
|
245 | - foreach ($session_settings as $var_name => $session_setting) { |
|
246 | - // set values for class properties |
|
247 | - $var_name = '_' . $var_name; |
|
248 | - $this->{$var_name} = $session_setting; |
|
249 | - } |
|
250 | - } |
|
251 | - $this->cache_storage = $cache_storage; |
|
252 | - // are we using encryption? |
|
253 | - $this->_use_encryption = $encryption instanceof EE_Encryption |
|
254 | - && EE_Registry::instance()->CFG->admin->encode_session_data(); |
|
255 | - // encrypt data via: $this->encryption->encrypt(); |
|
256 | - $this->encryption = $encryption; |
|
257 | - // filter hook allows outside functions/classes/plugins to change default empty cart |
|
258 | - $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array()); |
|
259 | - array_merge($this->_default_session_vars, $extra_default_session_vars); |
|
260 | - // apply default session vars |
|
261 | - $this->_set_defaults(); |
|
262 | - add_action('AHEE__EE_System__initialize', array($this, 'open_session')); |
|
263 | - // check request for 'clear_session' param |
|
264 | - add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded')); |
|
265 | - // once everything is all said and done, |
|
266 | - add_action('shutdown', array($this, 'update'), 100); |
|
267 | - add_action('shutdown', array($this, 'garbageCollection'), 1000); |
|
268 | - $this->configure_garbage_collection_filters(); |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * @return bool |
|
274 | - * @throws InvalidArgumentException |
|
275 | - * @throws InvalidDataTypeException |
|
276 | - * @throws InvalidInterfaceException |
|
277 | - */ |
|
278 | - public static function isLoadedAndActive() |
|
279 | - { |
|
280 | - return did_action('AHEE__EE_System__core_loaded_and_ready') |
|
281 | - && EE_Session::instance() instanceof EE_Session |
|
282 | - && EE_Session::instance()->isActive(); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * @return bool |
|
288 | - */ |
|
289 | - public function isActive() |
|
290 | - { |
|
291 | - return $this->status === EE_Session::STATUS_OPEN; |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * @return void |
|
297 | - * @throws EE_Error |
|
298 | - * @throws InvalidArgumentException |
|
299 | - * @throws InvalidDataTypeException |
|
300 | - * @throws InvalidInterfaceException |
|
301 | - * @throws InvalidSessionDataException |
|
302 | - */ |
|
303 | - public function open_session() |
|
304 | - { |
|
305 | - // check for existing session and retrieve it from db |
|
306 | - if (! $this->_espresso_session()) { |
|
307 | - // or just start a new one |
|
308 | - $this->_create_espresso_session(); |
|
309 | - } |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * @return bool |
|
315 | - */ |
|
316 | - public function expired() |
|
317 | - { |
|
318 | - return $this->_expired; |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * @return void |
|
324 | - */ |
|
325 | - public function reset_expired() |
|
326 | - { |
|
327 | - $this->_expired = false; |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * @return int |
|
333 | - */ |
|
334 | - public function expiration() |
|
335 | - { |
|
336 | - return $this->_expiration; |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * @return int |
|
342 | - */ |
|
343 | - public function extension() |
|
344 | - { |
|
345 | - return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS); |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * @param int $time number of seconds to add to session expiration |
|
351 | - */ |
|
352 | - public function extend_expiration($time = 0) |
|
353 | - { |
|
354 | - $time = $time ? $time : $this->extension(); |
|
355 | - $this->_expiration += absint($time); |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * @return int |
|
361 | - */ |
|
362 | - public function lifespan() |
|
363 | - { |
|
364 | - return $this->session_lifespan->inSeconds(); |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * This just sets some defaults for the _session data property |
|
370 | - * |
|
371 | - * @access private |
|
372 | - * @return void |
|
373 | - */ |
|
374 | - private function _set_defaults() |
|
375 | - { |
|
376 | - // set some defaults |
|
377 | - foreach ($this->_default_session_vars as $key => $default_var) { |
|
378 | - if (is_array($default_var)) { |
|
379 | - $this->_session_data[ $key ] = array(); |
|
380 | - } else { |
|
381 | - $this->_session_data[ $key ] = ''; |
|
382 | - } |
|
383 | - } |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * @retrieve session data |
|
389 | - * @access public |
|
390 | - * @return string |
|
391 | - */ |
|
392 | - public function id() |
|
393 | - { |
|
394 | - return $this->_sid; |
|
395 | - } |
|
396 | - |
|
397 | - |
|
398 | - /** |
|
399 | - * @param \EE_Cart $cart |
|
400 | - * @return bool |
|
401 | - */ |
|
402 | - public function set_cart(EE_Cart $cart) |
|
403 | - { |
|
404 | - $this->_session_data['cart'] = $cart; |
|
405 | - return true; |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - /** |
|
410 | - * reset_cart |
|
411 | - */ |
|
412 | - public function reset_cart() |
|
413 | - { |
|
414 | - do_action('AHEE__EE_Session__reset_cart__before_reset', $this); |
|
415 | - $this->_session_data['cart'] = null; |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * @return \EE_Cart |
|
421 | - */ |
|
422 | - public function cart() |
|
423 | - { |
|
424 | - return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart |
|
425 | - ? $this->_session_data['cart'] |
|
426 | - : null; |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - /** |
|
431 | - * @param \EE_Checkout $checkout |
|
432 | - * @return bool |
|
433 | - */ |
|
434 | - public function set_checkout(EE_Checkout $checkout) |
|
435 | - { |
|
436 | - $this->_session_data['checkout'] = $checkout; |
|
437 | - return true; |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - /** |
|
442 | - * reset_checkout |
|
443 | - */ |
|
444 | - public function reset_checkout() |
|
445 | - { |
|
446 | - do_action('AHEE__EE_Session__reset_checkout__before_reset', $this); |
|
447 | - $this->_session_data['checkout'] = null; |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * @return \EE_Checkout |
|
453 | - */ |
|
454 | - public function checkout() |
|
455 | - { |
|
456 | - return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout |
|
457 | - ? $this->_session_data['checkout'] |
|
458 | - : null; |
|
459 | - } |
|
460 | - |
|
461 | - |
|
462 | - /** |
|
463 | - * @param \EE_Transaction $transaction |
|
464 | - * @return bool |
|
465 | - * @throws EE_Error |
|
466 | - */ |
|
467 | - public function set_transaction(EE_Transaction $transaction) |
|
468 | - { |
|
469 | - // first remove the session from the transaction before we save the transaction in the session |
|
470 | - $transaction->set_txn_session_data(null); |
|
471 | - $this->_session_data['transaction'] = $transaction; |
|
472 | - return true; |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - /** |
|
477 | - * reset_transaction |
|
478 | - */ |
|
479 | - public function reset_transaction() |
|
480 | - { |
|
481 | - do_action('AHEE__EE_Session__reset_transaction__before_reset', $this); |
|
482 | - $this->_session_data['transaction'] = null; |
|
483 | - } |
|
484 | - |
|
485 | - |
|
486 | - /** |
|
487 | - * @return \EE_Transaction |
|
488 | - */ |
|
489 | - public function transaction() |
|
490 | - { |
|
491 | - return isset($this->_session_data['transaction']) |
|
492 | - && $this->_session_data['transaction'] instanceof EE_Transaction |
|
493 | - ? $this->_session_data['transaction'] |
|
494 | - : null; |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - /** |
|
499 | - * retrieve session data |
|
500 | - * |
|
501 | - * @param null $key |
|
502 | - * @param bool $reset_cache |
|
503 | - * @return array |
|
504 | - */ |
|
505 | - public function get_session_data($key = null, $reset_cache = false) |
|
506 | - { |
|
507 | - if ($reset_cache) { |
|
508 | - $this->reset_cart(); |
|
509 | - $this->reset_checkout(); |
|
510 | - $this->reset_transaction(); |
|
511 | - } |
|
512 | - if (! empty($key)) { |
|
513 | - return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null; |
|
514 | - } |
|
515 | - return $this->_session_data; |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * Returns TRUE on success, FALSE on fail |
|
521 | - * |
|
522 | - * @param array $data |
|
523 | - * @return bool |
|
524 | - */ |
|
525 | - public function set_session_data($data) |
|
526 | - { |
|
527 | - // nothing ??? bad data ??? go home! |
|
528 | - if (empty($data) || ! is_array($data)) { |
|
529 | - EE_Error::add_error( |
|
530 | - esc_html__( |
|
531 | - 'No session data or invalid session data was provided.', |
|
532 | - 'event_espresso' |
|
533 | - ), |
|
534 | - __FILE__, |
|
535 | - __FUNCTION__, |
|
536 | - __LINE__ |
|
537 | - ); |
|
538 | - return false; |
|
539 | - } |
|
540 | - foreach ($data as $key => $value) { |
|
541 | - if (isset($this->_default_session_vars[ $key ])) { |
|
542 | - EE_Error::add_error( |
|
543 | - sprintf( |
|
544 | - esc_html__( |
|
545 | - 'Sorry! %s is a default session datum and can not be reset.', |
|
546 | - 'event_espresso' |
|
547 | - ), |
|
548 | - $key |
|
549 | - ), |
|
550 | - __FILE__, |
|
551 | - __FUNCTION__, |
|
552 | - __LINE__ |
|
553 | - ); |
|
554 | - return false; |
|
555 | - } |
|
556 | - $this->_session_data[ $key ] = $value; |
|
557 | - } |
|
558 | - return true; |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - /** |
|
563 | - * @initiate session |
|
564 | - * @access private |
|
565 | - * @return TRUE on success, FALSE on fail |
|
566 | - * @throws EE_Error |
|
567 | - * @throws InvalidArgumentException |
|
568 | - * @throws InvalidDataTypeException |
|
569 | - * @throws InvalidInterfaceException |
|
570 | - * @throws InvalidSessionDataException |
|
571 | - */ |
|
572 | - private function _espresso_session() |
|
573 | - { |
|
574 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
575 | - $this->session_start_handler->startSession(); |
|
576 | - $this->status = EE_Session::STATUS_OPEN; |
|
577 | - // get our modified session ID |
|
578 | - $this->_sid = $this->_generate_session_id(); |
|
579 | - // and the visitors IP |
|
580 | - $this->_ip_address = $this->request->ipAddress(); |
|
581 | - // set the "user agent" |
|
582 | - $this->_user_agent = $this->request->userAgent(); |
|
583 | - // now let's retrieve what's in the db |
|
584 | - $session_data = $this->_retrieve_session_data(); |
|
585 | - if (! empty($session_data)) { |
|
586 | - // get the current time in UTC |
|
587 | - $this->_time = $this->_time !== null ? $this->_time : time(); |
|
588 | - // and reset the session expiration |
|
589 | - $this->_expiration = isset($session_data['expiration']) |
|
590 | - ? $session_data['expiration'] |
|
591 | - : $this->_time + $this->session_lifespan->inSeconds(); |
|
592 | - } else { |
|
593 | - // set initial site access time and the session expiration |
|
594 | - $this->_set_init_access_and_expiration(); |
|
595 | - // set referer |
|
596 | - $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER']) |
|
597 | - ? esc_attr($_SERVER['HTTP_REFERER']) |
|
598 | - : ''; |
|
599 | - // no previous session = go back and create one (on top of the data above) |
|
600 | - return false; |
|
601 | - } |
|
602 | - // now the user agent |
|
603 | - if ($session_data['user_agent'] !== $this->_user_agent) { |
|
604 | - return false; |
|
605 | - } |
|
606 | - // wait a minute... how old are you? |
|
607 | - if ($this->_time > $this->_expiration) { |
|
608 | - // yer too old fer me! |
|
609 | - $this->_expired = true; |
|
610 | - // wipe out everything that isn't a default session datum |
|
611 | - $this->clear_session(__CLASS__, __FUNCTION__); |
|
612 | - } |
|
613 | - // make event espresso session data available to plugin |
|
614 | - $this->_session_data = array_merge($this->_session_data, $session_data); |
|
615 | - return true; |
|
616 | - } |
|
617 | - |
|
618 | - |
|
619 | - /** |
|
620 | - * _get_session_data |
|
621 | - * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup |
|
622 | - * databases |
|
623 | - * |
|
624 | - * @return array |
|
625 | - * @throws EE_Error |
|
626 | - * @throws InvalidArgumentException |
|
627 | - * @throws InvalidSessionDataException |
|
628 | - * @throws InvalidDataTypeException |
|
629 | - * @throws InvalidInterfaceException |
|
630 | - */ |
|
631 | - protected function _retrieve_session_data() |
|
632 | - { |
|
633 | - $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
634 | - try { |
|
635 | - // we're using WP's Transient API to store session data using the PHP session ID as the option name |
|
636 | - $session_data = $this->cache_storage->get($ssn_key, false); |
|
637 | - if (empty($session_data)) { |
|
638 | - return array(); |
|
639 | - } |
|
640 | - if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
641 | - $hash_check = $this->cache_storage->get( |
|
642 | - EE_Session::hash_check_prefix . $this->_sid, |
|
643 | - false |
|
644 | - ); |
|
645 | - if ($hash_check && $hash_check !== md5($session_data)) { |
|
646 | - EE_Error::add_error( |
|
647 | - sprintf( |
|
648 | - __( |
|
649 | - 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
|
650 | - 'event_espresso' |
|
651 | - ), |
|
652 | - EE_Session::session_id_prefix . $this->_sid |
|
653 | - ), |
|
654 | - __FILE__, |
|
655 | - __FUNCTION__, |
|
656 | - __LINE__ |
|
657 | - ); |
|
658 | - } |
|
659 | - } |
|
660 | - } catch (Exception $e) { |
|
661 | - // let's just eat that error for now and attempt to correct any corrupted data |
|
662 | - global $wpdb; |
|
663 | - $row = $wpdb->get_row( |
|
664 | - $wpdb->prepare( |
|
665 | - "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
|
666 | - '_transient_' . $ssn_key |
|
667 | - ) |
|
668 | - ); |
|
669 | - $session_data = is_object($row) ? $row->option_value : null; |
|
670 | - if ($session_data) { |
|
671 | - $session_data = preg_replace_callback( |
|
672 | - '!s:(d+):"(.*?)";!', |
|
673 | - function ($match) { |
|
674 | - return $match[1] === strlen($match[2]) |
|
675 | - ? $match[0] |
|
676 | - : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
677 | - }, |
|
678 | - $session_data |
|
679 | - ); |
|
680 | - } |
|
681 | - $session_data = maybe_unserialize($session_data); |
|
682 | - } |
|
683 | - // in case the data is encoded... try to decode it |
|
684 | - $session_data = $this->encryption instanceof EE_Encryption |
|
685 | - ? $this->encryption->base64_string_decode($session_data) |
|
686 | - : $session_data; |
|
687 | - if (! is_array($session_data)) { |
|
688 | - try { |
|
689 | - $session_data = maybe_unserialize($session_data); |
|
690 | - } catch (Exception $e) { |
|
691 | - $msg = esc_html__( |
|
692 | - 'An error occurred while attempting to unserialize the session data.', |
|
693 | - 'event_espresso' |
|
694 | - ); |
|
695 | - $msg .= WP_DEBUG |
|
696 | - ? '<br><pre>' |
|
697 | - . print_r($session_data, true) |
|
698 | - . '</pre><br>' |
|
699 | - . $this->find_serialize_error($session_data) |
|
700 | - : ''; |
|
701 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
702 | - throw new InvalidSessionDataException($msg, 0, $e); |
|
703 | - } |
|
704 | - } |
|
705 | - // just a check to make sure the session array is indeed an array |
|
706 | - if (! is_array($session_data)) { |
|
707 | - // no?!?! then something is wrong |
|
708 | - $msg = esc_html__( |
|
709 | - 'The session data is missing, invalid, or corrupted.', |
|
710 | - 'event_espresso' |
|
711 | - ); |
|
712 | - $msg .= WP_DEBUG |
|
713 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
714 | - : ''; |
|
715 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
716 | - throw new InvalidSessionDataException($msg); |
|
717 | - } |
|
718 | - if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
|
719 | - $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID( |
|
720 | - $session_data['transaction'] |
|
721 | - ); |
|
722 | - } |
|
723 | - return $session_data; |
|
724 | - } |
|
725 | - |
|
726 | - |
|
727 | - /** |
|
728 | - * _generate_session_id |
|
729 | - * Retrieves the PHP session id either directly from the PHP session, |
|
730 | - * or from the $_REQUEST array if it was passed in from an AJAX request. |
|
731 | - * The session id is then salted and hashed (mmm sounds tasty) |
|
732 | - * so that it can be safely used as a $_REQUEST param |
|
733 | - * |
|
734 | - * @return string |
|
735 | - */ |
|
736 | - protected function _generate_session_id() |
|
737 | - { |
|
738 | - // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length |
|
739 | - if (isset($_REQUEST['EESID'])) { |
|
740 | - $session_id = sanitize_text_field($_REQUEST['EESID']); |
|
741 | - } else { |
|
742 | - $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt()); |
|
743 | - } |
|
744 | - return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
|
745 | - } |
|
746 | - |
|
747 | - |
|
748 | - /** |
|
749 | - * _get_sid_salt |
|
750 | - * |
|
751 | - * @return string |
|
752 | - */ |
|
753 | - protected function _get_sid_salt() |
|
754 | - { |
|
755 | - // was session id salt already saved to db ? |
|
756 | - if (empty($this->_sid_salt)) { |
|
757 | - // no? then maybe use WP defined constant |
|
758 | - if (defined('AUTH_SALT')) { |
|
759 | - $this->_sid_salt = AUTH_SALT; |
|
760 | - } |
|
761 | - // if salt doesn't exist or is too short |
|
762 | - if (strlen($this->_sid_salt) < 32) { |
|
763 | - // create a new one |
|
764 | - $this->_sid_salt = wp_generate_password(64); |
|
765 | - } |
|
766 | - // and save it as a permanent session setting |
|
767 | - $this->updateSessionSettings(array('sid_salt' => $this->_sid_salt)); |
|
768 | - } |
|
769 | - return $this->_sid_salt; |
|
770 | - } |
|
771 | - |
|
772 | - |
|
773 | - /** |
|
774 | - * _set_init_access_and_expiration |
|
775 | - * |
|
776 | - * @return void |
|
777 | - */ |
|
778 | - protected function _set_init_access_and_expiration() |
|
779 | - { |
|
780 | - $this->_time = time(); |
|
781 | - $this->_expiration = $this->_time + $this->session_lifespan->inSeconds(); |
|
782 | - // set initial site access time |
|
783 | - $this->_session_data['init_access'] = $this->_time; |
|
784 | - // and the session expiration |
|
785 | - $this->_session_data['expiration'] = $this->_expiration; |
|
786 | - } |
|
787 | - |
|
788 | - |
|
789 | - /** |
|
790 | - * @update session data prior to saving to the db |
|
791 | - * @access public |
|
792 | - * @param bool $new_session |
|
793 | - * @return TRUE on success, FALSE on fail |
|
794 | - * @throws EE_Error |
|
795 | - * @throws InvalidArgumentException |
|
796 | - * @throws InvalidDataTypeException |
|
797 | - * @throws InvalidInterfaceException |
|
798 | - */ |
|
799 | - public function update($new_session = false) |
|
800 | - { |
|
801 | - $this->_session_data = $this->_session_data !== null |
|
802 | - && is_array($this->_session_data) |
|
803 | - && isset($this->_session_data['id']) |
|
804 | - ? $this->_session_data |
|
805 | - : array(); |
|
806 | - if (empty($this->_session_data)) { |
|
807 | - $this->_set_defaults(); |
|
808 | - } |
|
809 | - $session_data = array(); |
|
810 | - foreach ($this->_session_data as $key => $value) { |
|
811 | - switch ($key) { |
|
812 | - case 'id': |
|
813 | - // session ID |
|
814 | - $session_data['id'] = $this->_sid; |
|
815 | - break; |
|
816 | - case 'ip_address': |
|
817 | - // visitor ip address |
|
818 | - $session_data['ip_address'] = $this->request->ipAddress(); |
|
819 | - break; |
|
820 | - case 'user_agent': |
|
821 | - // visitor user_agent |
|
822 | - $session_data['user_agent'] = $this->_user_agent; |
|
823 | - break; |
|
824 | - case 'init_access': |
|
825 | - $session_data['init_access'] = absint($value); |
|
826 | - break; |
|
827 | - case 'last_access': |
|
828 | - // current access time |
|
829 | - $session_data['last_access'] = $this->_time; |
|
830 | - break; |
|
831 | - case 'expiration': |
|
832 | - // when the session expires |
|
833 | - $session_data['expiration'] = ! empty($this->_expiration) |
|
834 | - ? $this->_expiration |
|
835 | - : $session_data['init_access'] + $this->session_lifespan->inSeconds(); |
|
836 | - break; |
|
837 | - case 'user_id': |
|
838 | - // current user if logged in |
|
839 | - $session_data['user_id'] = $this->_wp_user_id(); |
|
840 | - break; |
|
841 | - case 'pages_visited': |
|
842 | - $page_visit = $this->_get_page_visit(); |
|
843 | - if ($page_visit) { |
|
844 | - // set pages visited where the first will be the http referrer |
|
845 | - $this->_session_data['pages_visited'][ $this->_time ] = $page_visit; |
|
846 | - // we'll only save the last 10 page visits. |
|
847 | - $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
|
848 | - } |
|
849 | - break; |
|
850 | - default: |
|
851 | - // carry any other data over |
|
852 | - $session_data[ $key ] = $this->_session_data[ $key ]; |
|
853 | - } |
|
854 | - } |
|
855 | - $this->_session_data = $session_data; |
|
856 | - // creating a new session does not require saving to the db just yet |
|
857 | - if (! $new_session) { |
|
858 | - // ready? let's save |
|
859 | - if ($this->_save_session_to_db()) { |
|
860 | - return true; |
|
861 | - } |
|
862 | - return false; |
|
863 | - } |
|
864 | - // meh, why not? |
|
865 | - return true; |
|
866 | - } |
|
867 | - |
|
868 | - |
|
869 | - /** |
|
870 | - * @create session data array |
|
871 | - * @access public |
|
872 | - * @return bool |
|
873 | - * @throws EE_Error |
|
874 | - * @throws InvalidArgumentException |
|
875 | - * @throws InvalidDataTypeException |
|
876 | - * @throws InvalidInterfaceException |
|
877 | - */ |
|
878 | - private function _create_espresso_session() |
|
879 | - { |
|
880 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, ''); |
|
881 | - // use the update function for now with $new_session arg set to TRUE |
|
882 | - return $this->update(true) ? true : false; |
|
883 | - } |
|
884 | - |
|
885 | - /** |
|
886 | - * Detects if there is anything worth saving in the session (eg the cart is a good one, notices are pretty good |
|
887 | - * too). This is used when determining if we want to save the session or not. |
|
888 | - * @since 4.9.67.p |
|
889 | - * @return bool |
|
890 | - */ |
|
891 | - private function sessionHasStuffWorthSaving() |
|
892 | - { |
|
893 | - return $this->cart() instanceof EE_Cart |
|
894 | - || ( |
|
895 | - isset($this->_session_data['ee_notices']) |
|
896 | - && ( |
|
897 | - ! empty($this->_session_data['ee_notices']['attention']) |
|
898 | - || !empty($this->_session_data['ee_notices']['errors']) |
|
899 | - || !empty($this->_session_data['ee_notices']['success']) |
|
900 | - ) |
|
901 | - ); |
|
902 | - } |
|
903 | - /** |
|
904 | - * _save_session_to_db |
|
905 | - * |
|
906 | - * @param bool $clear_session |
|
907 | - * @return string |
|
908 | - * @throws EE_Error |
|
909 | - * @throws InvalidArgumentException |
|
910 | - * @throws InvalidDataTypeException |
|
911 | - * @throws InvalidInterfaceException |
|
912 | - */ |
|
913 | - private function _save_session_to_db($clear_session = false) |
|
914 | - { |
|
915 | - // don't save sessions for crawlers |
|
916 | - // and unless we're deleting the session data, don't save anything if there isn't a cart |
|
917 | - if ($this->request->isBot() |
|
918 | - || ( |
|
919 | - ! $clear_session |
|
920 | - && ! $this->sessionHasStuffWorthSaving() |
|
921 | - && apply_filters('FHEE__EE_Session___save_session_to_db__abort_session_save', true) |
|
922 | - ) |
|
923 | - ) { |
|
924 | - return false; |
|
925 | - } |
|
926 | - $transaction = $this->transaction(); |
|
927 | - if ($transaction instanceof EE_Transaction) { |
|
928 | - if (! $transaction->ID()) { |
|
929 | - $transaction->save(); |
|
930 | - } |
|
931 | - $this->_session_data['transaction'] = $transaction->ID(); |
|
932 | - } |
|
933 | - // then serialize all of our session data |
|
934 | - $session_data = serialize($this->_session_data); |
|
935 | - // do we need to also encode it to avoid corrupted data when saved to the db? |
|
936 | - $session_data = $this->_use_encryption |
|
937 | - ? $this->encryption->base64_string_encode($session_data) |
|
938 | - : $session_data; |
|
939 | - // maybe save hash check |
|
940 | - if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
941 | - $this->cache_storage->add( |
|
942 | - EE_Session::hash_check_prefix . $this->_sid, |
|
943 | - md5($session_data), |
|
944 | - $this->session_lifespan->inSeconds() |
|
945 | - ); |
|
946 | - } |
|
947 | - // we're using the Transient API for storing session data, |
|
948 | - return $this->cache_storage->add( |
|
949 | - EE_Session::session_id_prefix . $this->_sid, |
|
950 | - $session_data, |
|
951 | - $this->session_lifespan->inSeconds() |
|
952 | - ); |
|
953 | - } |
|
954 | - |
|
955 | - |
|
956 | - /** |
|
957 | - * @get the full page request the visitor is accessing |
|
958 | - * @access public |
|
959 | - * @return string |
|
960 | - */ |
|
961 | - public function _get_page_visit() |
|
962 | - { |
|
963 | - $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
964 | - // check for request url |
|
965 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
966 | - $http_host = ''; |
|
967 | - $page_id = '?'; |
|
968 | - $e_reg = ''; |
|
969 | - $request_uri = esc_url($_SERVER['REQUEST_URI']); |
|
970 | - $ru_bits = explode('?', $request_uri); |
|
971 | - $request_uri = $ru_bits[0]; |
|
972 | - // check for and grab host as well |
|
973 | - if (isset($_SERVER['HTTP_HOST'])) { |
|
974 | - $http_host = esc_url($_SERVER['HTTP_HOST']); |
|
975 | - } |
|
976 | - // check for page_id in SERVER REQUEST |
|
977 | - if (isset($_REQUEST['page_id'])) { |
|
978 | - // rebuild $e_reg without any of the extra parameters |
|
979 | - $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&'; |
|
980 | - } |
|
981 | - // check for $e_reg in SERVER REQUEST |
|
982 | - if (isset($_REQUEST['ee'])) { |
|
983 | - // rebuild $e_reg without any of the extra parameters |
|
984 | - $e_reg = 'ee=' . esc_attr($_REQUEST['ee']); |
|
985 | - } |
|
986 | - $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?'); |
|
987 | - } |
|
988 | - return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
|
989 | - } |
|
990 | - |
|
991 | - |
|
992 | - /** |
|
993 | - * @the current wp user id |
|
994 | - * @access public |
|
995 | - * @return int |
|
996 | - */ |
|
997 | - public function _wp_user_id() |
|
998 | - { |
|
999 | - // if I need to explain the following lines of code, then you shouldn't be looking at this! |
|
1000 | - $this->_wp_user_id = get_current_user_id(); |
|
1001 | - return $this->_wp_user_id; |
|
1002 | - } |
|
1003 | - |
|
1004 | - |
|
1005 | - /** |
|
1006 | - * Clear EE_Session data |
|
1007 | - * |
|
1008 | - * @access public |
|
1009 | - * @param string $class |
|
1010 | - * @param string $function |
|
1011 | - * @return void |
|
1012 | - * @throws EE_Error |
|
1013 | - * @throws InvalidArgumentException |
|
1014 | - * @throws InvalidDataTypeException |
|
1015 | - * @throws InvalidInterfaceException |
|
1016 | - */ |
|
1017 | - public function clear_session($class = '', $function = '') |
|
1018 | - { |
|
28 | + const session_id_prefix = 'ee_ssn_'; |
|
29 | + |
|
30 | + const hash_check_prefix = 'ee_shc_'; |
|
31 | + |
|
32 | + const OPTION_NAME_SETTINGS = 'ee_session_settings'; |
|
33 | + |
|
34 | + const STATUS_CLOSED = 0; |
|
35 | + |
|
36 | + const STATUS_OPEN = 1; |
|
37 | + |
|
38 | + /** |
|
39 | + * instance of the EE_Session object |
|
40 | + * |
|
41 | + * @var EE_Session |
|
42 | + */ |
|
43 | + private static $_instance; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var CacheStorageInterface $cache_storage |
|
47 | + */ |
|
48 | + protected $cache_storage; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var EE_Encryption $encryption |
|
52 | + */ |
|
53 | + protected $encryption; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var SessionStartHandler $session_start_handler |
|
57 | + */ |
|
58 | + protected $session_start_handler; |
|
59 | + |
|
60 | + /** |
|
61 | + * the session id |
|
62 | + * |
|
63 | + * @var string |
|
64 | + */ |
|
65 | + private $_sid; |
|
66 | + |
|
67 | + /** |
|
68 | + * session id salt |
|
69 | + * |
|
70 | + * @var string |
|
71 | + */ |
|
72 | + private $_sid_salt; |
|
73 | + |
|
74 | + /** |
|
75 | + * session data |
|
76 | + * |
|
77 | + * @var array |
|
78 | + */ |
|
79 | + private $_session_data = array(); |
|
80 | + |
|
81 | + /** |
|
82 | + * how long an EE session lasts |
|
83 | + * default session lifespan of 1 hour (for not so instant IPNs) |
|
84 | + * |
|
85 | + * @var SessionLifespan $session_lifespan |
|
86 | + */ |
|
87 | + private $session_lifespan; |
|
88 | + |
|
89 | + /** |
|
90 | + * session expiration time as Unix timestamp in GMT |
|
91 | + * |
|
92 | + * @var int |
|
93 | + */ |
|
94 | + private $_expiration; |
|
95 | + |
|
96 | + /** |
|
97 | + * whether or not session has expired at some point |
|
98 | + * |
|
99 | + * @var boolean |
|
100 | + */ |
|
101 | + private $_expired = false; |
|
102 | + |
|
103 | + /** |
|
104 | + * current time as Unix timestamp in GMT |
|
105 | + * |
|
106 | + * @var int |
|
107 | + */ |
|
108 | + private $_time; |
|
109 | + |
|
110 | + /** |
|
111 | + * whether to encrypt session data |
|
112 | + * |
|
113 | + * @var bool |
|
114 | + */ |
|
115 | + private $_use_encryption; |
|
116 | + |
|
117 | + /** |
|
118 | + * well... according to the server... |
|
119 | + * |
|
120 | + * @var null |
|
121 | + */ |
|
122 | + private $_user_agent; |
|
123 | + |
|
124 | + /** |
|
125 | + * do you really trust the server ? |
|
126 | + * |
|
127 | + * @var null |
|
128 | + */ |
|
129 | + private $_ip_address; |
|
130 | + |
|
131 | + /** |
|
132 | + * current WP user_id |
|
133 | + * |
|
134 | + * @var null |
|
135 | + */ |
|
136 | + private $_wp_user_id; |
|
137 | + |
|
138 | + /** |
|
139 | + * array for defining default session vars |
|
140 | + * |
|
141 | + * @var array |
|
142 | + */ |
|
143 | + private $_default_session_vars = array( |
|
144 | + 'id' => null, |
|
145 | + 'user_id' => null, |
|
146 | + 'ip_address' => null, |
|
147 | + 'user_agent' => null, |
|
148 | + 'init_access' => null, |
|
149 | + 'last_access' => null, |
|
150 | + 'expiration' => null, |
|
151 | + 'pages_visited' => array(), |
|
152 | + ); |
|
153 | + |
|
154 | + /** |
|
155 | + * timestamp for when last garbage collection cycle was performed |
|
156 | + * |
|
157 | + * @var int $_last_gc |
|
158 | + */ |
|
159 | + private $_last_gc; |
|
160 | + |
|
161 | + /** |
|
162 | + * @var RequestInterface $request |
|
163 | + */ |
|
164 | + protected $request; |
|
165 | + |
|
166 | + /** |
|
167 | + * whether session is active or not |
|
168 | + * |
|
169 | + * @var int $status |
|
170 | + */ |
|
171 | + private $status = EE_Session::STATUS_CLOSED; |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * @singleton method used to instantiate class object |
|
176 | + * @param CacheStorageInterface $cache_storage |
|
177 | + * @param SessionLifespan|null $lifespan |
|
178 | + * @param RequestInterface $request |
|
179 | + * @param SessionStartHandler $session_start_handler |
|
180 | + * @param EE_Encryption $encryption |
|
181 | + * @return EE_Session |
|
182 | + * @throws InvalidArgumentException |
|
183 | + * @throws InvalidDataTypeException |
|
184 | + * @throws InvalidInterfaceException |
|
185 | + */ |
|
186 | + public static function instance( |
|
187 | + CacheStorageInterface $cache_storage = null, |
|
188 | + SessionLifespan $lifespan = null, |
|
189 | + RequestInterface $request = null, |
|
190 | + SessionStartHandler $session_start_handler = null, |
|
191 | + EE_Encryption $encryption = null |
|
192 | + ) { |
|
193 | + // check if class object is instantiated |
|
194 | + // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
|
195 | + // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
196 | + if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
197 | + self::$_instance = new self( |
|
198 | + $cache_storage, |
|
199 | + $lifespan, |
|
200 | + $request, |
|
201 | + $session_start_handler, |
|
202 | + $encryption |
|
203 | + ); |
|
204 | + } |
|
205 | + return self::$_instance; |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * protected constructor to prevent direct creation |
|
211 | + * |
|
212 | + * @param CacheStorageInterface $cache_storage |
|
213 | + * @param SessionLifespan $lifespan |
|
214 | + * @param RequestInterface $request |
|
215 | + * @param SessionStartHandler $session_start_handler |
|
216 | + * @param EE_Encryption $encryption |
|
217 | + * @throws InvalidArgumentException |
|
218 | + * @throws InvalidDataTypeException |
|
219 | + * @throws InvalidInterfaceException |
|
220 | + */ |
|
221 | + protected function __construct( |
|
222 | + CacheStorageInterface $cache_storage, |
|
223 | + SessionLifespan $lifespan, |
|
224 | + RequestInterface $request, |
|
225 | + SessionStartHandler $session_start_handler, |
|
226 | + EE_Encryption $encryption = null |
|
227 | + ) { |
|
228 | + // session loading is turned ON by default, |
|
229 | + // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook |
|
230 | + // (which currently fires on the init hook at priority 9), |
|
231 | + // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
232 | + if (! apply_filters('FHEE_load_EE_Session', true)) { |
|
233 | + return; |
|
234 | + } |
|
235 | + $this->session_start_handler = $session_start_handler; |
|
236 | + $this->session_lifespan = $lifespan; |
|
237 | + $this->request = $request; |
|
238 | + if (! defined('ESPRESSO_SESSION')) { |
|
239 | + define('ESPRESSO_SESSION', true); |
|
240 | + } |
|
241 | + // retrieve session options from db |
|
242 | + $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
243 | + if (! empty($session_settings)) { |
|
244 | + // cycle though existing session options |
|
245 | + foreach ($session_settings as $var_name => $session_setting) { |
|
246 | + // set values for class properties |
|
247 | + $var_name = '_' . $var_name; |
|
248 | + $this->{$var_name} = $session_setting; |
|
249 | + } |
|
250 | + } |
|
251 | + $this->cache_storage = $cache_storage; |
|
252 | + // are we using encryption? |
|
253 | + $this->_use_encryption = $encryption instanceof EE_Encryption |
|
254 | + && EE_Registry::instance()->CFG->admin->encode_session_data(); |
|
255 | + // encrypt data via: $this->encryption->encrypt(); |
|
256 | + $this->encryption = $encryption; |
|
257 | + // filter hook allows outside functions/classes/plugins to change default empty cart |
|
258 | + $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array()); |
|
259 | + array_merge($this->_default_session_vars, $extra_default_session_vars); |
|
260 | + // apply default session vars |
|
261 | + $this->_set_defaults(); |
|
262 | + add_action('AHEE__EE_System__initialize', array($this, 'open_session')); |
|
263 | + // check request for 'clear_session' param |
|
264 | + add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded')); |
|
265 | + // once everything is all said and done, |
|
266 | + add_action('shutdown', array($this, 'update'), 100); |
|
267 | + add_action('shutdown', array($this, 'garbageCollection'), 1000); |
|
268 | + $this->configure_garbage_collection_filters(); |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * @return bool |
|
274 | + * @throws InvalidArgumentException |
|
275 | + * @throws InvalidDataTypeException |
|
276 | + * @throws InvalidInterfaceException |
|
277 | + */ |
|
278 | + public static function isLoadedAndActive() |
|
279 | + { |
|
280 | + return did_action('AHEE__EE_System__core_loaded_and_ready') |
|
281 | + && EE_Session::instance() instanceof EE_Session |
|
282 | + && EE_Session::instance()->isActive(); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * @return bool |
|
288 | + */ |
|
289 | + public function isActive() |
|
290 | + { |
|
291 | + return $this->status === EE_Session::STATUS_OPEN; |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * @return void |
|
297 | + * @throws EE_Error |
|
298 | + * @throws InvalidArgumentException |
|
299 | + * @throws InvalidDataTypeException |
|
300 | + * @throws InvalidInterfaceException |
|
301 | + * @throws InvalidSessionDataException |
|
302 | + */ |
|
303 | + public function open_session() |
|
304 | + { |
|
305 | + // check for existing session and retrieve it from db |
|
306 | + if (! $this->_espresso_session()) { |
|
307 | + // or just start a new one |
|
308 | + $this->_create_espresso_session(); |
|
309 | + } |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * @return bool |
|
315 | + */ |
|
316 | + public function expired() |
|
317 | + { |
|
318 | + return $this->_expired; |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * @return void |
|
324 | + */ |
|
325 | + public function reset_expired() |
|
326 | + { |
|
327 | + $this->_expired = false; |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * @return int |
|
333 | + */ |
|
334 | + public function expiration() |
|
335 | + { |
|
336 | + return $this->_expiration; |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * @return int |
|
342 | + */ |
|
343 | + public function extension() |
|
344 | + { |
|
345 | + return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS); |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * @param int $time number of seconds to add to session expiration |
|
351 | + */ |
|
352 | + public function extend_expiration($time = 0) |
|
353 | + { |
|
354 | + $time = $time ? $time : $this->extension(); |
|
355 | + $this->_expiration += absint($time); |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * @return int |
|
361 | + */ |
|
362 | + public function lifespan() |
|
363 | + { |
|
364 | + return $this->session_lifespan->inSeconds(); |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * This just sets some defaults for the _session data property |
|
370 | + * |
|
371 | + * @access private |
|
372 | + * @return void |
|
373 | + */ |
|
374 | + private function _set_defaults() |
|
375 | + { |
|
376 | + // set some defaults |
|
377 | + foreach ($this->_default_session_vars as $key => $default_var) { |
|
378 | + if (is_array($default_var)) { |
|
379 | + $this->_session_data[ $key ] = array(); |
|
380 | + } else { |
|
381 | + $this->_session_data[ $key ] = ''; |
|
382 | + } |
|
383 | + } |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * @retrieve session data |
|
389 | + * @access public |
|
390 | + * @return string |
|
391 | + */ |
|
392 | + public function id() |
|
393 | + { |
|
394 | + return $this->_sid; |
|
395 | + } |
|
396 | + |
|
397 | + |
|
398 | + /** |
|
399 | + * @param \EE_Cart $cart |
|
400 | + * @return bool |
|
401 | + */ |
|
402 | + public function set_cart(EE_Cart $cart) |
|
403 | + { |
|
404 | + $this->_session_data['cart'] = $cart; |
|
405 | + return true; |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + /** |
|
410 | + * reset_cart |
|
411 | + */ |
|
412 | + public function reset_cart() |
|
413 | + { |
|
414 | + do_action('AHEE__EE_Session__reset_cart__before_reset', $this); |
|
415 | + $this->_session_data['cart'] = null; |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * @return \EE_Cart |
|
421 | + */ |
|
422 | + public function cart() |
|
423 | + { |
|
424 | + return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart |
|
425 | + ? $this->_session_data['cart'] |
|
426 | + : null; |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + /** |
|
431 | + * @param \EE_Checkout $checkout |
|
432 | + * @return bool |
|
433 | + */ |
|
434 | + public function set_checkout(EE_Checkout $checkout) |
|
435 | + { |
|
436 | + $this->_session_data['checkout'] = $checkout; |
|
437 | + return true; |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + /** |
|
442 | + * reset_checkout |
|
443 | + */ |
|
444 | + public function reset_checkout() |
|
445 | + { |
|
446 | + do_action('AHEE__EE_Session__reset_checkout__before_reset', $this); |
|
447 | + $this->_session_data['checkout'] = null; |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * @return \EE_Checkout |
|
453 | + */ |
|
454 | + public function checkout() |
|
455 | + { |
|
456 | + return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout |
|
457 | + ? $this->_session_data['checkout'] |
|
458 | + : null; |
|
459 | + } |
|
460 | + |
|
461 | + |
|
462 | + /** |
|
463 | + * @param \EE_Transaction $transaction |
|
464 | + * @return bool |
|
465 | + * @throws EE_Error |
|
466 | + */ |
|
467 | + public function set_transaction(EE_Transaction $transaction) |
|
468 | + { |
|
469 | + // first remove the session from the transaction before we save the transaction in the session |
|
470 | + $transaction->set_txn_session_data(null); |
|
471 | + $this->_session_data['transaction'] = $transaction; |
|
472 | + return true; |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + /** |
|
477 | + * reset_transaction |
|
478 | + */ |
|
479 | + public function reset_transaction() |
|
480 | + { |
|
481 | + do_action('AHEE__EE_Session__reset_transaction__before_reset', $this); |
|
482 | + $this->_session_data['transaction'] = null; |
|
483 | + } |
|
484 | + |
|
485 | + |
|
486 | + /** |
|
487 | + * @return \EE_Transaction |
|
488 | + */ |
|
489 | + public function transaction() |
|
490 | + { |
|
491 | + return isset($this->_session_data['transaction']) |
|
492 | + && $this->_session_data['transaction'] instanceof EE_Transaction |
|
493 | + ? $this->_session_data['transaction'] |
|
494 | + : null; |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + /** |
|
499 | + * retrieve session data |
|
500 | + * |
|
501 | + * @param null $key |
|
502 | + * @param bool $reset_cache |
|
503 | + * @return array |
|
504 | + */ |
|
505 | + public function get_session_data($key = null, $reset_cache = false) |
|
506 | + { |
|
507 | + if ($reset_cache) { |
|
508 | + $this->reset_cart(); |
|
509 | + $this->reset_checkout(); |
|
510 | + $this->reset_transaction(); |
|
511 | + } |
|
512 | + if (! empty($key)) { |
|
513 | + return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null; |
|
514 | + } |
|
515 | + return $this->_session_data; |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + /** |
|
520 | + * Returns TRUE on success, FALSE on fail |
|
521 | + * |
|
522 | + * @param array $data |
|
523 | + * @return bool |
|
524 | + */ |
|
525 | + public function set_session_data($data) |
|
526 | + { |
|
527 | + // nothing ??? bad data ??? go home! |
|
528 | + if (empty($data) || ! is_array($data)) { |
|
529 | + EE_Error::add_error( |
|
530 | + esc_html__( |
|
531 | + 'No session data or invalid session data was provided.', |
|
532 | + 'event_espresso' |
|
533 | + ), |
|
534 | + __FILE__, |
|
535 | + __FUNCTION__, |
|
536 | + __LINE__ |
|
537 | + ); |
|
538 | + return false; |
|
539 | + } |
|
540 | + foreach ($data as $key => $value) { |
|
541 | + if (isset($this->_default_session_vars[ $key ])) { |
|
542 | + EE_Error::add_error( |
|
543 | + sprintf( |
|
544 | + esc_html__( |
|
545 | + 'Sorry! %s is a default session datum and can not be reset.', |
|
546 | + 'event_espresso' |
|
547 | + ), |
|
548 | + $key |
|
549 | + ), |
|
550 | + __FILE__, |
|
551 | + __FUNCTION__, |
|
552 | + __LINE__ |
|
553 | + ); |
|
554 | + return false; |
|
555 | + } |
|
556 | + $this->_session_data[ $key ] = $value; |
|
557 | + } |
|
558 | + return true; |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + /** |
|
563 | + * @initiate session |
|
564 | + * @access private |
|
565 | + * @return TRUE on success, FALSE on fail |
|
566 | + * @throws EE_Error |
|
567 | + * @throws InvalidArgumentException |
|
568 | + * @throws InvalidDataTypeException |
|
569 | + * @throws InvalidInterfaceException |
|
570 | + * @throws InvalidSessionDataException |
|
571 | + */ |
|
572 | + private function _espresso_session() |
|
573 | + { |
|
574 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
575 | + $this->session_start_handler->startSession(); |
|
576 | + $this->status = EE_Session::STATUS_OPEN; |
|
577 | + // get our modified session ID |
|
578 | + $this->_sid = $this->_generate_session_id(); |
|
579 | + // and the visitors IP |
|
580 | + $this->_ip_address = $this->request->ipAddress(); |
|
581 | + // set the "user agent" |
|
582 | + $this->_user_agent = $this->request->userAgent(); |
|
583 | + // now let's retrieve what's in the db |
|
584 | + $session_data = $this->_retrieve_session_data(); |
|
585 | + if (! empty($session_data)) { |
|
586 | + // get the current time in UTC |
|
587 | + $this->_time = $this->_time !== null ? $this->_time : time(); |
|
588 | + // and reset the session expiration |
|
589 | + $this->_expiration = isset($session_data['expiration']) |
|
590 | + ? $session_data['expiration'] |
|
591 | + : $this->_time + $this->session_lifespan->inSeconds(); |
|
592 | + } else { |
|
593 | + // set initial site access time and the session expiration |
|
594 | + $this->_set_init_access_and_expiration(); |
|
595 | + // set referer |
|
596 | + $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER']) |
|
597 | + ? esc_attr($_SERVER['HTTP_REFERER']) |
|
598 | + : ''; |
|
599 | + // no previous session = go back and create one (on top of the data above) |
|
600 | + return false; |
|
601 | + } |
|
602 | + // now the user agent |
|
603 | + if ($session_data['user_agent'] !== $this->_user_agent) { |
|
604 | + return false; |
|
605 | + } |
|
606 | + // wait a minute... how old are you? |
|
607 | + if ($this->_time > $this->_expiration) { |
|
608 | + // yer too old fer me! |
|
609 | + $this->_expired = true; |
|
610 | + // wipe out everything that isn't a default session datum |
|
611 | + $this->clear_session(__CLASS__, __FUNCTION__); |
|
612 | + } |
|
613 | + // make event espresso session data available to plugin |
|
614 | + $this->_session_data = array_merge($this->_session_data, $session_data); |
|
615 | + return true; |
|
616 | + } |
|
617 | + |
|
618 | + |
|
619 | + /** |
|
620 | + * _get_session_data |
|
621 | + * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup |
|
622 | + * databases |
|
623 | + * |
|
624 | + * @return array |
|
625 | + * @throws EE_Error |
|
626 | + * @throws InvalidArgumentException |
|
627 | + * @throws InvalidSessionDataException |
|
628 | + * @throws InvalidDataTypeException |
|
629 | + * @throws InvalidInterfaceException |
|
630 | + */ |
|
631 | + protected function _retrieve_session_data() |
|
632 | + { |
|
633 | + $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
634 | + try { |
|
635 | + // we're using WP's Transient API to store session data using the PHP session ID as the option name |
|
636 | + $session_data = $this->cache_storage->get($ssn_key, false); |
|
637 | + if (empty($session_data)) { |
|
638 | + return array(); |
|
639 | + } |
|
640 | + if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
641 | + $hash_check = $this->cache_storage->get( |
|
642 | + EE_Session::hash_check_prefix . $this->_sid, |
|
643 | + false |
|
644 | + ); |
|
645 | + if ($hash_check && $hash_check !== md5($session_data)) { |
|
646 | + EE_Error::add_error( |
|
647 | + sprintf( |
|
648 | + __( |
|
649 | + 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
|
650 | + 'event_espresso' |
|
651 | + ), |
|
652 | + EE_Session::session_id_prefix . $this->_sid |
|
653 | + ), |
|
654 | + __FILE__, |
|
655 | + __FUNCTION__, |
|
656 | + __LINE__ |
|
657 | + ); |
|
658 | + } |
|
659 | + } |
|
660 | + } catch (Exception $e) { |
|
661 | + // let's just eat that error for now and attempt to correct any corrupted data |
|
662 | + global $wpdb; |
|
663 | + $row = $wpdb->get_row( |
|
664 | + $wpdb->prepare( |
|
665 | + "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
|
666 | + '_transient_' . $ssn_key |
|
667 | + ) |
|
668 | + ); |
|
669 | + $session_data = is_object($row) ? $row->option_value : null; |
|
670 | + if ($session_data) { |
|
671 | + $session_data = preg_replace_callback( |
|
672 | + '!s:(d+):"(.*?)";!', |
|
673 | + function ($match) { |
|
674 | + return $match[1] === strlen($match[2]) |
|
675 | + ? $match[0] |
|
676 | + : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
677 | + }, |
|
678 | + $session_data |
|
679 | + ); |
|
680 | + } |
|
681 | + $session_data = maybe_unserialize($session_data); |
|
682 | + } |
|
683 | + // in case the data is encoded... try to decode it |
|
684 | + $session_data = $this->encryption instanceof EE_Encryption |
|
685 | + ? $this->encryption->base64_string_decode($session_data) |
|
686 | + : $session_data; |
|
687 | + if (! is_array($session_data)) { |
|
688 | + try { |
|
689 | + $session_data = maybe_unserialize($session_data); |
|
690 | + } catch (Exception $e) { |
|
691 | + $msg = esc_html__( |
|
692 | + 'An error occurred while attempting to unserialize the session data.', |
|
693 | + 'event_espresso' |
|
694 | + ); |
|
695 | + $msg .= WP_DEBUG |
|
696 | + ? '<br><pre>' |
|
697 | + . print_r($session_data, true) |
|
698 | + . '</pre><br>' |
|
699 | + . $this->find_serialize_error($session_data) |
|
700 | + : ''; |
|
701 | + $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
702 | + throw new InvalidSessionDataException($msg, 0, $e); |
|
703 | + } |
|
704 | + } |
|
705 | + // just a check to make sure the session array is indeed an array |
|
706 | + if (! is_array($session_data)) { |
|
707 | + // no?!?! then something is wrong |
|
708 | + $msg = esc_html__( |
|
709 | + 'The session data is missing, invalid, or corrupted.', |
|
710 | + 'event_espresso' |
|
711 | + ); |
|
712 | + $msg .= WP_DEBUG |
|
713 | + ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
714 | + : ''; |
|
715 | + $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
716 | + throw new InvalidSessionDataException($msg); |
|
717 | + } |
|
718 | + if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
|
719 | + $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID( |
|
720 | + $session_data['transaction'] |
|
721 | + ); |
|
722 | + } |
|
723 | + return $session_data; |
|
724 | + } |
|
725 | + |
|
726 | + |
|
727 | + /** |
|
728 | + * _generate_session_id |
|
729 | + * Retrieves the PHP session id either directly from the PHP session, |
|
730 | + * or from the $_REQUEST array if it was passed in from an AJAX request. |
|
731 | + * The session id is then salted and hashed (mmm sounds tasty) |
|
732 | + * so that it can be safely used as a $_REQUEST param |
|
733 | + * |
|
734 | + * @return string |
|
735 | + */ |
|
736 | + protected function _generate_session_id() |
|
737 | + { |
|
738 | + // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length |
|
739 | + if (isset($_REQUEST['EESID'])) { |
|
740 | + $session_id = sanitize_text_field($_REQUEST['EESID']); |
|
741 | + } else { |
|
742 | + $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt()); |
|
743 | + } |
|
744 | + return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
|
745 | + } |
|
746 | + |
|
747 | + |
|
748 | + /** |
|
749 | + * _get_sid_salt |
|
750 | + * |
|
751 | + * @return string |
|
752 | + */ |
|
753 | + protected function _get_sid_salt() |
|
754 | + { |
|
755 | + // was session id salt already saved to db ? |
|
756 | + if (empty($this->_sid_salt)) { |
|
757 | + // no? then maybe use WP defined constant |
|
758 | + if (defined('AUTH_SALT')) { |
|
759 | + $this->_sid_salt = AUTH_SALT; |
|
760 | + } |
|
761 | + // if salt doesn't exist or is too short |
|
762 | + if (strlen($this->_sid_salt) < 32) { |
|
763 | + // create a new one |
|
764 | + $this->_sid_salt = wp_generate_password(64); |
|
765 | + } |
|
766 | + // and save it as a permanent session setting |
|
767 | + $this->updateSessionSettings(array('sid_salt' => $this->_sid_salt)); |
|
768 | + } |
|
769 | + return $this->_sid_salt; |
|
770 | + } |
|
771 | + |
|
772 | + |
|
773 | + /** |
|
774 | + * _set_init_access_and_expiration |
|
775 | + * |
|
776 | + * @return void |
|
777 | + */ |
|
778 | + protected function _set_init_access_and_expiration() |
|
779 | + { |
|
780 | + $this->_time = time(); |
|
781 | + $this->_expiration = $this->_time + $this->session_lifespan->inSeconds(); |
|
782 | + // set initial site access time |
|
783 | + $this->_session_data['init_access'] = $this->_time; |
|
784 | + // and the session expiration |
|
785 | + $this->_session_data['expiration'] = $this->_expiration; |
|
786 | + } |
|
787 | + |
|
788 | + |
|
789 | + /** |
|
790 | + * @update session data prior to saving to the db |
|
791 | + * @access public |
|
792 | + * @param bool $new_session |
|
793 | + * @return TRUE on success, FALSE on fail |
|
794 | + * @throws EE_Error |
|
795 | + * @throws InvalidArgumentException |
|
796 | + * @throws InvalidDataTypeException |
|
797 | + * @throws InvalidInterfaceException |
|
798 | + */ |
|
799 | + public function update($new_session = false) |
|
800 | + { |
|
801 | + $this->_session_data = $this->_session_data !== null |
|
802 | + && is_array($this->_session_data) |
|
803 | + && isset($this->_session_data['id']) |
|
804 | + ? $this->_session_data |
|
805 | + : array(); |
|
806 | + if (empty($this->_session_data)) { |
|
807 | + $this->_set_defaults(); |
|
808 | + } |
|
809 | + $session_data = array(); |
|
810 | + foreach ($this->_session_data as $key => $value) { |
|
811 | + switch ($key) { |
|
812 | + case 'id': |
|
813 | + // session ID |
|
814 | + $session_data['id'] = $this->_sid; |
|
815 | + break; |
|
816 | + case 'ip_address': |
|
817 | + // visitor ip address |
|
818 | + $session_data['ip_address'] = $this->request->ipAddress(); |
|
819 | + break; |
|
820 | + case 'user_agent': |
|
821 | + // visitor user_agent |
|
822 | + $session_data['user_agent'] = $this->_user_agent; |
|
823 | + break; |
|
824 | + case 'init_access': |
|
825 | + $session_data['init_access'] = absint($value); |
|
826 | + break; |
|
827 | + case 'last_access': |
|
828 | + // current access time |
|
829 | + $session_data['last_access'] = $this->_time; |
|
830 | + break; |
|
831 | + case 'expiration': |
|
832 | + // when the session expires |
|
833 | + $session_data['expiration'] = ! empty($this->_expiration) |
|
834 | + ? $this->_expiration |
|
835 | + : $session_data['init_access'] + $this->session_lifespan->inSeconds(); |
|
836 | + break; |
|
837 | + case 'user_id': |
|
838 | + // current user if logged in |
|
839 | + $session_data['user_id'] = $this->_wp_user_id(); |
|
840 | + break; |
|
841 | + case 'pages_visited': |
|
842 | + $page_visit = $this->_get_page_visit(); |
|
843 | + if ($page_visit) { |
|
844 | + // set pages visited where the first will be the http referrer |
|
845 | + $this->_session_data['pages_visited'][ $this->_time ] = $page_visit; |
|
846 | + // we'll only save the last 10 page visits. |
|
847 | + $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
|
848 | + } |
|
849 | + break; |
|
850 | + default: |
|
851 | + // carry any other data over |
|
852 | + $session_data[ $key ] = $this->_session_data[ $key ]; |
|
853 | + } |
|
854 | + } |
|
855 | + $this->_session_data = $session_data; |
|
856 | + // creating a new session does not require saving to the db just yet |
|
857 | + if (! $new_session) { |
|
858 | + // ready? let's save |
|
859 | + if ($this->_save_session_to_db()) { |
|
860 | + return true; |
|
861 | + } |
|
862 | + return false; |
|
863 | + } |
|
864 | + // meh, why not? |
|
865 | + return true; |
|
866 | + } |
|
867 | + |
|
868 | + |
|
869 | + /** |
|
870 | + * @create session data array |
|
871 | + * @access public |
|
872 | + * @return bool |
|
873 | + * @throws EE_Error |
|
874 | + * @throws InvalidArgumentException |
|
875 | + * @throws InvalidDataTypeException |
|
876 | + * @throws InvalidInterfaceException |
|
877 | + */ |
|
878 | + private function _create_espresso_session() |
|
879 | + { |
|
880 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, ''); |
|
881 | + // use the update function for now with $new_session arg set to TRUE |
|
882 | + return $this->update(true) ? true : false; |
|
883 | + } |
|
884 | + |
|
885 | + /** |
|
886 | + * Detects if there is anything worth saving in the session (eg the cart is a good one, notices are pretty good |
|
887 | + * too). This is used when determining if we want to save the session or not. |
|
888 | + * @since 4.9.67.p |
|
889 | + * @return bool |
|
890 | + */ |
|
891 | + private function sessionHasStuffWorthSaving() |
|
892 | + { |
|
893 | + return $this->cart() instanceof EE_Cart |
|
894 | + || ( |
|
895 | + isset($this->_session_data['ee_notices']) |
|
896 | + && ( |
|
897 | + ! empty($this->_session_data['ee_notices']['attention']) |
|
898 | + || !empty($this->_session_data['ee_notices']['errors']) |
|
899 | + || !empty($this->_session_data['ee_notices']['success']) |
|
900 | + ) |
|
901 | + ); |
|
902 | + } |
|
903 | + /** |
|
904 | + * _save_session_to_db |
|
905 | + * |
|
906 | + * @param bool $clear_session |
|
907 | + * @return string |
|
908 | + * @throws EE_Error |
|
909 | + * @throws InvalidArgumentException |
|
910 | + * @throws InvalidDataTypeException |
|
911 | + * @throws InvalidInterfaceException |
|
912 | + */ |
|
913 | + private function _save_session_to_db($clear_session = false) |
|
914 | + { |
|
915 | + // don't save sessions for crawlers |
|
916 | + // and unless we're deleting the session data, don't save anything if there isn't a cart |
|
917 | + if ($this->request->isBot() |
|
918 | + || ( |
|
919 | + ! $clear_session |
|
920 | + && ! $this->sessionHasStuffWorthSaving() |
|
921 | + && apply_filters('FHEE__EE_Session___save_session_to_db__abort_session_save', true) |
|
922 | + ) |
|
923 | + ) { |
|
924 | + return false; |
|
925 | + } |
|
926 | + $transaction = $this->transaction(); |
|
927 | + if ($transaction instanceof EE_Transaction) { |
|
928 | + if (! $transaction->ID()) { |
|
929 | + $transaction->save(); |
|
930 | + } |
|
931 | + $this->_session_data['transaction'] = $transaction->ID(); |
|
932 | + } |
|
933 | + // then serialize all of our session data |
|
934 | + $session_data = serialize($this->_session_data); |
|
935 | + // do we need to also encode it to avoid corrupted data when saved to the db? |
|
936 | + $session_data = $this->_use_encryption |
|
937 | + ? $this->encryption->base64_string_encode($session_data) |
|
938 | + : $session_data; |
|
939 | + // maybe save hash check |
|
940 | + if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
941 | + $this->cache_storage->add( |
|
942 | + EE_Session::hash_check_prefix . $this->_sid, |
|
943 | + md5($session_data), |
|
944 | + $this->session_lifespan->inSeconds() |
|
945 | + ); |
|
946 | + } |
|
947 | + // we're using the Transient API for storing session data, |
|
948 | + return $this->cache_storage->add( |
|
949 | + EE_Session::session_id_prefix . $this->_sid, |
|
950 | + $session_data, |
|
951 | + $this->session_lifespan->inSeconds() |
|
952 | + ); |
|
953 | + } |
|
954 | + |
|
955 | + |
|
956 | + /** |
|
957 | + * @get the full page request the visitor is accessing |
|
958 | + * @access public |
|
959 | + * @return string |
|
960 | + */ |
|
961 | + public function _get_page_visit() |
|
962 | + { |
|
963 | + $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
964 | + // check for request url |
|
965 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
966 | + $http_host = ''; |
|
967 | + $page_id = '?'; |
|
968 | + $e_reg = ''; |
|
969 | + $request_uri = esc_url($_SERVER['REQUEST_URI']); |
|
970 | + $ru_bits = explode('?', $request_uri); |
|
971 | + $request_uri = $ru_bits[0]; |
|
972 | + // check for and grab host as well |
|
973 | + if (isset($_SERVER['HTTP_HOST'])) { |
|
974 | + $http_host = esc_url($_SERVER['HTTP_HOST']); |
|
975 | + } |
|
976 | + // check for page_id in SERVER REQUEST |
|
977 | + if (isset($_REQUEST['page_id'])) { |
|
978 | + // rebuild $e_reg without any of the extra parameters |
|
979 | + $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&'; |
|
980 | + } |
|
981 | + // check for $e_reg in SERVER REQUEST |
|
982 | + if (isset($_REQUEST['ee'])) { |
|
983 | + // rebuild $e_reg without any of the extra parameters |
|
984 | + $e_reg = 'ee=' . esc_attr($_REQUEST['ee']); |
|
985 | + } |
|
986 | + $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?'); |
|
987 | + } |
|
988 | + return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
|
989 | + } |
|
990 | + |
|
991 | + |
|
992 | + /** |
|
993 | + * @the current wp user id |
|
994 | + * @access public |
|
995 | + * @return int |
|
996 | + */ |
|
997 | + public function _wp_user_id() |
|
998 | + { |
|
999 | + // if I need to explain the following lines of code, then you shouldn't be looking at this! |
|
1000 | + $this->_wp_user_id = get_current_user_id(); |
|
1001 | + return $this->_wp_user_id; |
|
1002 | + } |
|
1003 | + |
|
1004 | + |
|
1005 | + /** |
|
1006 | + * Clear EE_Session data |
|
1007 | + * |
|
1008 | + * @access public |
|
1009 | + * @param string $class |
|
1010 | + * @param string $function |
|
1011 | + * @return void |
|
1012 | + * @throws EE_Error |
|
1013 | + * @throws InvalidArgumentException |
|
1014 | + * @throws InvalidDataTypeException |
|
1015 | + * @throws InvalidInterfaceException |
|
1016 | + */ |
|
1017 | + public function clear_session($class = '', $function = '') |
|
1018 | + { |
|
1019 | 1019 | // echo ' |
1020 | 1020 | // <h3 style="color:#999;line-height:.9em;"> |
1021 | 1021 | // <span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/> |
1022 | 1022 | // <span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span> <b style="font-size:10px;"> ' . __LINE__ . ' </b> |
1023 | 1023 | // </h3>'; |
1024 | - do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()'); |
|
1025 | - $this->reset_cart(); |
|
1026 | - $this->reset_checkout(); |
|
1027 | - $this->reset_transaction(); |
|
1028 | - // wipe out everything that isn't a default session datum |
|
1029 | - $this->reset_data(array_keys($this->_session_data)); |
|
1030 | - // reset initial site access time and the session expiration |
|
1031 | - $this->_set_init_access_and_expiration(); |
|
1032 | - $this->_save_session_to_db(true); |
|
1033 | - } |
|
1034 | - |
|
1035 | - |
|
1036 | - /** |
|
1037 | - * resets all non-default session vars. Returns TRUE on success, FALSE on fail |
|
1038 | - * |
|
1039 | - * @param array|mixed $data_to_reset |
|
1040 | - * @param bool $show_all_notices |
|
1041 | - * @return bool |
|
1042 | - */ |
|
1043 | - public function reset_data($data_to_reset = array(), $show_all_notices = false) |
|
1044 | - { |
|
1045 | - // if $data_to_reset is not in an array, then put it in one |
|
1046 | - if (! is_array($data_to_reset)) { |
|
1047 | - $data_to_reset = array($data_to_reset); |
|
1048 | - } |
|
1049 | - // nothing ??? go home! |
|
1050 | - if (empty($data_to_reset)) { |
|
1051 | - EE_Error::add_error( |
|
1052 | - __( |
|
1053 | - 'No session data could be reset, because no session var name was provided.', |
|
1054 | - 'event_espresso' |
|
1055 | - ), |
|
1056 | - __FILE__, |
|
1057 | - __FUNCTION__, |
|
1058 | - __LINE__ |
|
1059 | - ); |
|
1060 | - return false; |
|
1061 | - } |
|
1062 | - $return_value = true; |
|
1063 | - // since $data_to_reset is an array, cycle through the values |
|
1064 | - foreach ($data_to_reset as $reset) { |
|
1065 | - // first check to make sure it is a valid session var |
|
1066 | - if (isset($this->_session_data[ $reset ])) { |
|
1067 | - // then check to make sure it is not a default var |
|
1068 | - if (! array_key_exists($reset, $this->_default_session_vars)) { |
|
1069 | - // remove session var |
|
1070 | - unset($this->_session_data[ $reset ]); |
|
1071 | - if ($show_all_notices) { |
|
1072 | - EE_Error::add_success( |
|
1073 | - sprintf( |
|
1074 | - __('The session variable %s was removed.', 'event_espresso'), |
|
1075 | - $reset |
|
1076 | - ), |
|
1077 | - __FILE__, |
|
1078 | - __FUNCTION__, |
|
1079 | - __LINE__ |
|
1080 | - ); |
|
1081 | - } |
|
1082 | - } else { |
|
1083 | - // yeeeeeeeeerrrrrrrrrrr OUT !!!! |
|
1084 | - if ($show_all_notices) { |
|
1085 | - EE_Error::add_error( |
|
1086 | - sprintf( |
|
1087 | - __( |
|
1088 | - 'Sorry! %s is a default session datum and can not be reset.', |
|
1089 | - 'event_espresso' |
|
1090 | - ), |
|
1091 | - $reset |
|
1092 | - ), |
|
1093 | - __FILE__, |
|
1094 | - __FUNCTION__, |
|
1095 | - __LINE__ |
|
1096 | - ); |
|
1097 | - } |
|
1098 | - $return_value = false; |
|
1099 | - } |
|
1100 | - } elseif ($show_all_notices) { |
|
1101 | - // oops! that session var does not exist! |
|
1102 | - EE_Error::add_error( |
|
1103 | - sprintf( |
|
1104 | - __( |
|
1105 | - 'The session item provided, %s, is invalid or does not exist.', |
|
1106 | - 'event_espresso' |
|
1107 | - ), |
|
1108 | - $reset |
|
1109 | - ), |
|
1110 | - __FILE__, |
|
1111 | - __FUNCTION__, |
|
1112 | - __LINE__ |
|
1113 | - ); |
|
1114 | - $return_value = false; |
|
1115 | - } |
|
1116 | - } // end of foreach |
|
1117 | - return $return_value; |
|
1118 | - } |
|
1119 | - |
|
1120 | - |
|
1121 | - /** |
|
1122 | - * wp_loaded |
|
1123 | - * |
|
1124 | - * @access public |
|
1125 | - * @throws EE_Error |
|
1126 | - * @throws InvalidDataTypeException |
|
1127 | - * @throws InvalidInterfaceException |
|
1128 | - * @throws InvalidArgumentException |
|
1129 | - */ |
|
1130 | - public function wp_loaded() |
|
1131 | - { |
|
1132 | - if ($this->request->requestParamIsSet('clear_session')) { |
|
1133 | - $this->clear_session(__CLASS__, __FUNCTION__); |
|
1134 | - } |
|
1135 | - } |
|
1136 | - |
|
1137 | - |
|
1138 | - /** |
|
1139 | - * Used to reset the entire object (for tests). |
|
1140 | - * |
|
1141 | - * @since 4.3.0 |
|
1142 | - * @throws EE_Error |
|
1143 | - * @throws InvalidDataTypeException |
|
1144 | - * @throws InvalidInterfaceException |
|
1145 | - * @throws InvalidArgumentException |
|
1146 | - */ |
|
1147 | - public function reset_instance() |
|
1148 | - { |
|
1149 | - $this->clear_session(); |
|
1150 | - self::$_instance = null; |
|
1151 | - } |
|
1152 | - |
|
1153 | - |
|
1154 | - public function configure_garbage_collection_filters() |
|
1155 | - { |
|
1156 | - // run old filter we had for controlling session cleanup |
|
1157 | - $expired_session_transient_delete_query_limit = absint( |
|
1158 | - apply_filters( |
|
1159 | - 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
1160 | - 50 |
|
1161 | - ) |
|
1162 | - ); |
|
1163 | - // is there a value? or one that is different than the default 50 records? |
|
1164 | - if ($expired_session_transient_delete_query_limit === 0) { |
|
1165 | - // hook into TransientCacheStorage in case Session cleanup was turned off |
|
1166 | - add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero'); |
|
1167 | - } elseif ($expired_session_transient_delete_query_limit !== 50) { |
|
1168 | - // or use that for the new transient cleanup query limit |
|
1169 | - add_filter( |
|
1170 | - 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
|
1171 | - function () use ($expired_session_transient_delete_query_limit) { |
|
1172 | - return $expired_session_transient_delete_query_limit; |
|
1173 | - } |
|
1174 | - ); |
|
1175 | - } |
|
1176 | - } |
|
1177 | - |
|
1178 | - |
|
1179 | - /** |
|
1180 | - * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996 |
|
1181 | - * @param $data1 |
|
1182 | - * @return string |
|
1183 | - */ |
|
1184 | - private function find_serialize_error($data1) |
|
1185 | - { |
|
1186 | - $error = '<pre>'; |
|
1187 | - $data2 = preg_replace_callback( |
|
1188 | - '!s:(\d+):"(.*?)";!', |
|
1189 | - function ($match) { |
|
1190 | - return ($match[1] === strlen($match[2])) |
|
1191 | - ? $match[0] |
|
1192 | - : 's:' |
|
1193 | - . strlen($match[2]) |
|
1194 | - . ':"' |
|
1195 | - . $match[2] |
|
1196 | - . '";'; |
|
1197 | - }, |
|
1198 | - $data1 |
|
1199 | - ); |
|
1200 | - $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
1201 | - $error .= $data1 . PHP_EOL; |
|
1202 | - $error .= $data2 . PHP_EOL; |
|
1203 | - for ($i = 0; $i < $max; $i++) { |
|
1204 | - if (@$data1[ $i ] !== @$data2[ $i ]) { |
|
1205 | - $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
1206 | - $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL; |
|
1207 | - $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
1208 | - $start = ($i - 20); |
|
1209 | - $start = ($start < 0) ? 0 : $start; |
|
1210 | - $length = 40; |
|
1211 | - $point = $max - $i; |
|
1212 | - if ($point < 20) { |
|
1213 | - $rlength = 1; |
|
1214 | - $rpoint = -$point; |
|
1215 | - } else { |
|
1216 | - $rpoint = $length - 20; |
|
1217 | - $rlength = 1; |
|
1218 | - } |
|
1219 | - $error .= "\t-> Section Data1 = "; |
|
1220 | - $error .= substr_replace( |
|
1221 | - substr($data1, $start, $length), |
|
1222 | - "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
1223 | - $rpoint, |
|
1224 | - $rlength |
|
1225 | - ); |
|
1226 | - $error .= PHP_EOL; |
|
1227 | - $error .= "\t-> Section Data2 = "; |
|
1228 | - $error .= substr_replace( |
|
1229 | - substr($data2, $start, $length), |
|
1230 | - "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
1231 | - $rpoint, |
|
1232 | - $rlength |
|
1233 | - ); |
|
1234 | - $error .= PHP_EOL; |
|
1235 | - } |
|
1236 | - } |
|
1237 | - $error .= '</pre>'; |
|
1238 | - return $error; |
|
1239 | - } |
|
1240 | - |
|
1241 | - |
|
1242 | - /** |
|
1243 | - * Saves an array of settings used for configuring aspects of session behaviour |
|
1244 | - * |
|
1245 | - * @param array $updated_settings |
|
1246 | - */ |
|
1247 | - private function updateSessionSettings(array $updated_settings = array()) |
|
1248 | - { |
|
1249 | - // add existing settings, but only if not included in incoming $updated_settings array |
|
1250 | - $updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
1251 | - update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings); |
|
1252 | - } |
|
1253 | - |
|
1254 | - |
|
1255 | - /** |
|
1256 | - * garbage_collection |
|
1257 | - */ |
|
1258 | - public function garbageCollection() |
|
1259 | - { |
|
1260 | - // only perform during regular requests if last garbage collection was over an hour ago |
|
1261 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
1262 | - $this->_last_gc = time(); |
|
1263 | - $this->updateSessionSettings(array('last_gc' => $this->_last_gc)); |
|
1264 | - /** @type WPDB $wpdb */ |
|
1265 | - global $wpdb; |
|
1266 | - // filter the query limit. Set to 0 to turn off garbage collection |
|
1267 | - $expired_session_transient_delete_query_limit = absint( |
|
1268 | - apply_filters( |
|
1269 | - 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
1270 | - 50 |
|
1271 | - ) |
|
1272 | - ); |
|
1273 | - // non-zero LIMIT means take out the trash |
|
1274 | - if ($expired_session_transient_delete_query_limit) { |
|
1275 | - $session_key = str_replace('_', '\_', EE_Session::session_id_prefix); |
|
1276 | - $hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix); |
|
1277 | - // since transient expiration timestamps are set in the future, we can compare against NOW |
|
1278 | - // but we only want to pick up any trash that's been around for more than a day |
|
1279 | - $expiration = time() - DAY_IN_SECONDS; |
|
1280 | - $SQL = " |
|
1024 | + do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()'); |
|
1025 | + $this->reset_cart(); |
|
1026 | + $this->reset_checkout(); |
|
1027 | + $this->reset_transaction(); |
|
1028 | + // wipe out everything that isn't a default session datum |
|
1029 | + $this->reset_data(array_keys($this->_session_data)); |
|
1030 | + // reset initial site access time and the session expiration |
|
1031 | + $this->_set_init_access_and_expiration(); |
|
1032 | + $this->_save_session_to_db(true); |
|
1033 | + } |
|
1034 | + |
|
1035 | + |
|
1036 | + /** |
|
1037 | + * resets all non-default session vars. Returns TRUE on success, FALSE on fail |
|
1038 | + * |
|
1039 | + * @param array|mixed $data_to_reset |
|
1040 | + * @param bool $show_all_notices |
|
1041 | + * @return bool |
|
1042 | + */ |
|
1043 | + public function reset_data($data_to_reset = array(), $show_all_notices = false) |
|
1044 | + { |
|
1045 | + // if $data_to_reset is not in an array, then put it in one |
|
1046 | + if (! is_array($data_to_reset)) { |
|
1047 | + $data_to_reset = array($data_to_reset); |
|
1048 | + } |
|
1049 | + // nothing ??? go home! |
|
1050 | + if (empty($data_to_reset)) { |
|
1051 | + EE_Error::add_error( |
|
1052 | + __( |
|
1053 | + 'No session data could be reset, because no session var name was provided.', |
|
1054 | + 'event_espresso' |
|
1055 | + ), |
|
1056 | + __FILE__, |
|
1057 | + __FUNCTION__, |
|
1058 | + __LINE__ |
|
1059 | + ); |
|
1060 | + return false; |
|
1061 | + } |
|
1062 | + $return_value = true; |
|
1063 | + // since $data_to_reset is an array, cycle through the values |
|
1064 | + foreach ($data_to_reset as $reset) { |
|
1065 | + // first check to make sure it is a valid session var |
|
1066 | + if (isset($this->_session_data[ $reset ])) { |
|
1067 | + // then check to make sure it is not a default var |
|
1068 | + if (! array_key_exists($reset, $this->_default_session_vars)) { |
|
1069 | + // remove session var |
|
1070 | + unset($this->_session_data[ $reset ]); |
|
1071 | + if ($show_all_notices) { |
|
1072 | + EE_Error::add_success( |
|
1073 | + sprintf( |
|
1074 | + __('The session variable %s was removed.', 'event_espresso'), |
|
1075 | + $reset |
|
1076 | + ), |
|
1077 | + __FILE__, |
|
1078 | + __FUNCTION__, |
|
1079 | + __LINE__ |
|
1080 | + ); |
|
1081 | + } |
|
1082 | + } else { |
|
1083 | + // yeeeeeeeeerrrrrrrrrrr OUT !!!! |
|
1084 | + if ($show_all_notices) { |
|
1085 | + EE_Error::add_error( |
|
1086 | + sprintf( |
|
1087 | + __( |
|
1088 | + 'Sorry! %s is a default session datum and can not be reset.', |
|
1089 | + 'event_espresso' |
|
1090 | + ), |
|
1091 | + $reset |
|
1092 | + ), |
|
1093 | + __FILE__, |
|
1094 | + __FUNCTION__, |
|
1095 | + __LINE__ |
|
1096 | + ); |
|
1097 | + } |
|
1098 | + $return_value = false; |
|
1099 | + } |
|
1100 | + } elseif ($show_all_notices) { |
|
1101 | + // oops! that session var does not exist! |
|
1102 | + EE_Error::add_error( |
|
1103 | + sprintf( |
|
1104 | + __( |
|
1105 | + 'The session item provided, %s, is invalid or does not exist.', |
|
1106 | + 'event_espresso' |
|
1107 | + ), |
|
1108 | + $reset |
|
1109 | + ), |
|
1110 | + __FILE__, |
|
1111 | + __FUNCTION__, |
|
1112 | + __LINE__ |
|
1113 | + ); |
|
1114 | + $return_value = false; |
|
1115 | + } |
|
1116 | + } // end of foreach |
|
1117 | + return $return_value; |
|
1118 | + } |
|
1119 | + |
|
1120 | + |
|
1121 | + /** |
|
1122 | + * wp_loaded |
|
1123 | + * |
|
1124 | + * @access public |
|
1125 | + * @throws EE_Error |
|
1126 | + * @throws InvalidDataTypeException |
|
1127 | + * @throws InvalidInterfaceException |
|
1128 | + * @throws InvalidArgumentException |
|
1129 | + */ |
|
1130 | + public function wp_loaded() |
|
1131 | + { |
|
1132 | + if ($this->request->requestParamIsSet('clear_session')) { |
|
1133 | + $this->clear_session(__CLASS__, __FUNCTION__); |
|
1134 | + } |
|
1135 | + } |
|
1136 | + |
|
1137 | + |
|
1138 | + /** |
|
1139 | + * Used to reset the entire object (for tests). |
|
1140 | + * |
|
1141 | + * @since 4.3.0 |
|
1142 | + * @throws EE_Error |
|
1143 | + * @throws InvalidDataTypeException |
|
1144 | + * @throws InvalidInterfaceException |
|
1145 | + * @throws InvalidArgumentException |
|
1146 | + */ |
|
1147 | + public function reset_instance() |
|
1148 | + { |
|
1149 | + $this->clear_session(); |
|
1150 | + self::$_instance = null; |
|
1151 | + } |
|
1152 | + |
|
1153 | + |
|
1154 | + public function configure_garbage_collection_filters() |
|
1155 | + { |
|
1156 | + // run old filter we had for controlling session cleanup |
|
1157 | + $expired_session_transient_delete_query_limit = absint( |
|
1158 | + apply_filters( |
|
1159 | + 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
1160 | + 50 |
|
1161 | + ) |
|
1162 | + ); |
|
1163 | + // is there a value? or one that is different than the default 50 records? |
|
1164 | + if ($expired_session_transient_delete_query_limit === 0) { |
|
1165 | + // hook into TransientCacheStorage in case Session cleanup was turned off |
|
1166 | + add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero'); |
|
1167 | + } elseif ($expired_session_transient_delete_query_limit !== 50) { |
|
1168 | + // or use that for the new transient cleanup query limit |
|
1169 | + add_filter( |
|
1170 | + 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
|
1171 | + function () use ($expired_session_transient_delete_query_limit) { |
|
1172 | + return $expired_session_transient_delete_query_limit; |
|
1173 | + } |
|
1174 | + ); |
|
1175 | + } |
|
1176 | + } |
|
1177 | + |
|
1178 | + |
|
1179 | + /** |
|
1180 | + * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996 |
|
1181 | + * @param $data1 |
|
1182 | + * @return string |
|
1183 | + */ |
|
1184 | + private function find_serialize_error($data1) |
|
1185 | + { |
|
1186 | + $error = '<pre>'; |
|
1187 | + $data2 = preg_replace_callback( |
|
1188 | + '!s:(\d+):"(.*?)";!', |
|
1189 | + function ($match) { |
|
1190 | + return ($match[1] === strlen($match[2])) |
|
1191 | + ? $match[0] |
|
1192 | + : 's:' |
|
1193 | + . strlen($match[2]) |
|
1194 | + . ':"' |
|
1195 | + . $match[2] |
|
1196 | + . '";'; |
|
1197 | + }, |
|
1198 | + $data1 |
|
1199 | + ); |
|
1200 | + $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
1201 | + $error .= $data1 . PHP_EOL; |
|
1202 | + $error .= $data2 . PHP_EOL; |
|
1203 | + for ($i = 0; $i < $max; $i++) { |
|
1204 | + if (@$data1[ $i ] !== @$data2[ $i ]) { |
|
1205 | + $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
1206 | + $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL; |
|
1207 | + $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
1208 | + $start = ($i - 20); |
|
1209 | + $start = ($start < 0) ? 0 : $start; |
|
1210 | + $length = 40; |
|
1211 | + $point = $max - $i; |
|
1212 | + if ($point < 20) { |
|
1213 | + $rlength = 1; |
|
1214 | + $rpoint = -$point; |
|
1215 | + } else { |
|
1216 | + $rpoint = $length - 20; |
|
1217 | + $rlength = 1; |
|
1218 | + } |
|
1219 | + $error .= "\t-> Section Data1 = "; |
|
1220 | + $error .= substr_replace( |
|
1221 | + substr($data1, $start, $length), |
|
1222 | + "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
1223 | + $rpoint, |
|
1224 | + $rlength |
|
1225 | + ); |
|
1226 | + $error .= PHP_EOL; |
|
1227 | + $error .= "\t-> Section Data2 = "; |
|
1228 | + $error .= substr_replace( |
|
1229 | + substr($data2, $start, $length), |
|
1230 | + "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
1231 | + $rpoint, |
|
1232 | + $rlength |
|
1233 | + ); |
|
1234 | + $error .= PHP_EOL; |
|
1235 | + } |
|
1236 | + } |
|
1237 | + $error .= '</pre>'; |
|
1238 | + return $error; |
|
1239 | + } |
|
1240 | + |
|
1241 | + |
|
1242 | + /** |
|
1243 | + * Saves an array of settings used for configuring aspects of session behaviour |
|
1244 | + * |
|
1245 | + * @param array $updated_settings |
|
1246 | + */ |
|
1247 | + private function updateSessionSettings(array $updated_settings = array()) |
|
1248 | + { |
|
1249 | + // add existing settings, but only if not included in incoming $updated_settings array |
|
1250 | + $updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
1251 | + update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings); |
|
1252 | + } |
|
1253 | + |
|
1254 | + |
|
1255 | + /** |
|
1256 | + * garbage_collection |
|
1257 | + */ |
|
1258 | + public function garbageCollection() |
|
1259 | + { |
|
1260 | + // only perform during regular requests if last garbage collection was over an hour ago |
|
1261 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
1262 | + $this->_last_gc = time(); |
|
1263 | + $this->updateSessionSettings(array('last_gc' => $this->_last_gc)); |
|
1264 | + /** @type WPDB $wpdb */ |
|
1265 | + global $wpdb; |
|
1266 | + // filter the query limit. Set to 0 to turn off garbage collection |
|
1267 | + $expired_session_transient_delete_query_limit = absint( |
|
1268 | + apply_filters( |
|
1269 | + 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
1270 | + 50 |
|
1271 | + ) |
|
1272 | + ); |
|
1273 | + // non-zero LIMIT means take out the trash |
|
1274 | + if ($expired_session_transient_delete_query_limit) { |
|
1275 | + $session_key = str_replace('_', '\_', EE_Session::session_id_prefix); |
|
1276 | + $hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix); |
|
1277 | + // since transient expiration timestamps are set in the future, we can compare against NOW |
|
1278 | + // but we only want to pick up any trash that's been around for more than a day |
|
1279 | + $expiration = time() - DAY_IN_SECONDS; |
|
1280 | + $SQL = " |
|
1281 | 1281 | SELECT option_name |
1282 | 1282 | FROM {$wpdb->options} |
1283 | 1283 | WHERE |
@@ -1286,17 +1286,17 @@ discard block |
||
1286 | 1286 | AND option_value < {$expiration} |
1287 | 1287 | LIMIT {$expired_session_transient_delete_query_limit} |
1288 | 1288 | "; |
1289 | - // produces something like: |
|
1290 | - // SELECT option_name FROM wp_options |
|
1291 | - // WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%' |
|
1292 | - // OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' ) |
|
1293 | - // AND option_value < 1508368198 LIMIT 50 |
|
1294 | - $expired_sessions = $wpdb->get_col($SQL); |
|
1295 | - // valid results? |
|
1296 | - if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
1297 | - $this->cache_storage->deleteMany($expired_sessions, true); |
|
1298 | - } |
|
1299 | - } |
|
1300 | - } |
|
1301 | - } |
|
1289 | + // produces something like: |
|
1290 | + // SELECT option_name FROM wp_options |
|
1291 | + // WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%' |
|
1292 | + // OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' ) |
|
1293 | + // AND option_value < 1508368198 LIMIT 50 |
|
1294 | + $expired_sessions = $wpdb->get_col($SQL); |
|
1295 | + // valid results? |
|
1296 | + if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
1297 | + $this->cache_storage->deleteMany($expired_sessions, true); |
|
1298 | + } |
|
1299 | + } |
|
1300 | + } |
|
1301 | + } |
|
1302 | 1302 | } |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | // check if class object is instantiated |
194 | 194 | // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
195 | 195 | // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
196 | - if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
196 | + if ( ! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
197 | 197 | self::$_instance = new self( |
198 | 198 | $cache_storage, |
199 | 199 | $lifespan, |
@@ -229,22 +229,22 @@ discard block |
||
229 | 229 | // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook |
230 | 230 | // (which currently fires on the init hook at priority 9), |
231 | 231 | // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
232 | - if (! apply_filters('FHEE_load_EE_Session', true)) { |
|
232 | + if ( ! apply_filters('FHEE_load_EE_Session', true)) { |
|
233 | 233 | return; |
234 | 234 | } |
235 | 235 | $this->session_start_handler = $session_start_handler; |
236 | 236 | $this->session_lifespan = $lifespan; |
237 | 237 | $this->request = $request; |
238 | - if (! defined('ESPRESSO_SESSION')) { |
|
238 | + if ( ! defined('ESPRESSO_SESSION')) { |
|
239 | 239 | define('ESPRESSO_SESSION', true); |
240 | 240 | } |
241 | 241 | // retrieve session options from db |
242 | 242 | $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
243 | - if (! empty($session_settings)) { |
|
243 | + if ( ! empty($session_settings)) { |
|
244 | 244 | // cycle though existing session options |
245 | 245 | foreach ($session_settings as $var_name => $session_setting) { |
246 | 246 | // set values for class properties |
247 | - $var_name = '_' . $var_name; |
|
247 | + $var_name = '_'.$var_name; |
|
248 | 248 | $this->{$var_name} = $session_setting; |
249 | 249 | } |
250 | 250 | } |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | public function open_session() |
304 | 304 | { |
305 | 305 | // check for existing session and retrieve it from db |
306 | - if (! $this->_espresso_session()) { |
|
306 | + if ( ! $this->_espresso_session()) { |
|
307 | 307 | // or just start a new one |
308 | 308 | $this->_create_espresso_session(); |
309 | 309 | } |
@@ -376,9 +376,9 @@ discard block |
||
376 | 376 | // set some defaults |
377 | 377 | foreach ($this->_default_session_vars as $key => $default_var) { |
378 | 378 | if (is_array($default_var)) { |
379 | - $this->_session_data[ $key ] = array(); |
|
379 | + $this->_session_data[$key] = array(); |
|
380 | 380 | } else { |
381 | - $this->_session_data[ $key ] = ''; |
|
381 | + $this->_session_data[$key] = ''; |
|
382 | 382 | } |
383 | 383 | } |
384 | 384 | } |
@@ -509,8 +509,8 @@ discard block |
||
509 | 509 | $this->reset_checkout(); |
510 | 510 | $this->reset_transaction(); |
511 | 511 | } |
512 | - if (! empty($key)) { |
|
513 | - return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null; |
|
512 | + if ( ! empty($key)) { |
|
513 | + return isset($this->_session_data[$key]) ? $this->_session_data[$key] : null; |
|
514 | 514 | } |
515 | 515 | return $this->_session_data; |
516 | 516 | } |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | return false; |
539 | 539 | } |
540 | 540 | foreach ($data as $key => $value) { |
541 | - if (isset($this->_default_session_vars[ $key ])) { |
|
541 | + if (isset($this->_default_session_vars[$key])) { |
|
542 | 542 | EE_Error::add_error( |
543 | 543 | sprintf( |
544 | 544 | esc_html__( |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | ); |
554 | 554 | return false; |
555 | 555 | } |
556 | - $this->_session_data[ $key ] = $value; |
|
556 | + $this->_session_data[$key] = $value; |
|
557 | 557 | } |
558 | 558 | return true; |
559 | 559 | } |
@@ -582,7 +582,7 @@ discard block |
||
582 | 582 | $this->_user_agent = $this->request->userAgent(); |
583 | 583 | // now let's retrieve what's in the db |
584 | 584 | $session_data = $this->_retrieve_session_data(); |
585 | - if (! empty($session_data)) { |
|
585 | + if ( ! empty($session_data)) { |
|
586 | 586 | // get the current time in UTC |
587 | 587 | $this->_time = $this->_time !== null ? $this->_time : time(); |
588 | 588 | // and reset the session expiration |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | // set initial site access time and the session expiration |
594 | 594 | $this->_set_init_access_and_expiration(); |
595 | 595 | // set referer |
596 | - $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER']) |
|
596 | + $this->_session_data['pages_visited'][$this->_session_data['init_access']] = isset($_SERVER['HTTP_REFERER']) |
|
597 | 597 | ? esc_attr($_SERVER['HTTP_REFERER']) |
598 | 598 | : ''; |
599 | 599 | // no previous session = go back and create one (on top of the data above) |
@@ -630,7 +630,7 @@ discard block |
||
630 | 630 | */ |
631 | 631 | protected function _retrieve_session_data() |
632 | 632 | { |
633 | - $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
633 | + $ssn_key = EE_Session::session_id_prefix.$this->_sid; |
|
634 | 634 | try { |
635 | 635 | // we're using WP's Transient API to store session data using the PHP session ID as the option name |
636 | 636 | $session_data = $this->cache_storage->get($ssn_key, false); |
@@ -639,7 +639,7 @@ discard block |
||
639 | 639 | } |
640 | 640 | if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
641 | 641 | $hash_check = $this->cache_storage->get( |
642 | - EE_Session::hash_check_prefix . $this->_sid, |
|
642 | + EE_Session::hash_check_prefix.$this->_sid, |
|
643 | 643 | false |
644 | 644 | ); |
645 | 645 | if ($hash_check && $hash_check !== md5($session_data)) { |
@@ -649,7 +649,7 @@ discard block |
||
649 | 649 | 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
650 | 650 | 'event_espresso' |
651 | 651 | ), |
652 | - EE_Session::session_id_prefix . $this->_sid |
|
652 | + EE_Session::session_id_prefix.$this->_sid |
|
653 | 653 | ), |
654 | 654 | __FILE__, |
655 | 655 | __FUNCTION__, |
@@ -663,17 +663,17 @@ discard block |
||
663 | 663 | $row = $wpdb->get_row( |
664 | 664 | $wpdb->prepare( |
665 | 665 | "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
666 | - '_transient_' . $ssn_key |
|
666 | + '_transient_'.$ssn_key |
|
667 | 667 | ) |
668 | 668 | ); |
669 | 669 | $session_data = is_object($row) ? $row->option_value : null; |
670 | 670 | if ($session_data) { |
671 | 671 | $session_data = preg_replace_callback( |
672 | 672 | '!s:(d+):"(.*?)";!', |
673 | - function ($match) { |
|
673 | + function($match) { |
|
674 | 674 | return $match[1] === strlen($match[2]) |
675 | 675 | ? $match[0] |
676 | - : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
676 | + : 's:'.strlen($match[2]).':"'.$match[2].'";'; |
|
677 | 677 | }, |
678 | 678 | $session_data |
679 | 679 | ); |
@@ -684,7 +684,7 @@ discard block |
||
684 | 684 | $session_data = $this->encryption instanceof EE_Encryption |
685 | 685 | ? $this->encryption->base64_string_decode($session_data) |
686 | 686 | : $session_data; |
687 | - if (! is_array($session_data)) { |
|
687 | + if ( ! is_array($session_data)) { |
|
688 | 688 | try { |
689 | 689 | $session_data = maybe_unserialize($session_data); |
690 | 690 | } catch (Exception $e) { |
@@ -698,21 +698,21 @@ discard block |
||
698 | 698 | . '</pre><br>' |
699 | 699 | . $this->find_serialize_error($session_data) |
700 | 700 | : ''; |
701 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
701 | + $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid); |
|
702 | 702 | throw new InvalidSessionDataException($msg, 0, $e); |
703 | 703 | } |
704 | 704 | } |
705 | 705 | // just a check to make sure the session array is indeed an array |
706 | - if (! is_array($session_data)) { |
|
706 | + if ( ! is_array($session_data)) { |
|
707 | 707 | // no?!?! then something is wrong |
708 | 708 | $msg = esc_html__( |
709 | 709 | 'The session data is missing, invalid, or corrupted.', |
710 | 710 | 'event_espresso' |
711 | 711 | ); |
712 | 712 | $msg .= WP_DEBUG |
713 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
713 | + ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data) |
|
714 | 714 | : ''; |
715 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
715 | + $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid); |
|
716 | 716 | throw new InvalidSessionDataException($msg); |
717 | 717 | } |
718 | 718 | if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
@@ -739,7 +739,7 @@ discard block |
||
739 | 739 | if (isset($_REQUEST['EESID'])) { |
740 | 740 | $session_id = sanitize_text_field($_REQUEST['EESID']); |
741 | 741 | } else { |
742 | - $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt()); |
|
742 | + $session_id = md5(session_id().get_current_blog_id().$this->_get_sid_salt()); |
|
743 | 743 | } |
744 | 744 | return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
745 | 745 | } |
@@ -842,19 +842,19 @@ discard block |
||
842 | 842 | $page_visit = $this->_get_page_visit(); |
843 | 843 | if ($page_visit) { |
844 | 844 | // set pages visited where the first will be the http referrer |
845 | - $this->_session_data['pages_visited'][ $this->_time ] = $page_visit; |
|
845 | + $this->_session_data['pages_visited'][$this->_time] = $page_visit; |
|
846 | 846 | // we'll only save the last 10 page visits. |
847 | 847 | $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
848 | 848 | } |
849 | 849 | break; |
850 | 850 | default: |
851 | 851 | // carry any other data over |
852 | - $session_data[ $key ] = $this->_session_data[ $key ]; |
|
852 | + $session_data[$key] = $this->_session_data[$key]; |
|
853 | 853 | } |
854 | 854 | } |
855 | 855 | $this->_session_data = $session_data; |
856 | 856 | // creating a new session does not require saving to the db just yet |
857 | - if (! $new_session) { |
|
857 | + if ( ! $new_session) { |
|
858 | 858 | // ready? let's save |
859 | 859 | if ($this->_save_session_to_db()) { |
860 | 860 | return true; |
@@ -895,8 +895,8 @@ discard block |
||
895 | 895 | isset($this->_session_data['ee_notices']) |
896 | 896 | && ( |
897 | 897 | ! empty($this->_session_data['ee_notices']['attention']) |
898 | - || !empty($this->_session_data['ee_notices']['errors']) |
|
899 | - || !empty($this->_session_data['ee_notices']['success']) |
|
898 | + || ! empty($this->_session_data['ee_notices']['errors']) |
|
899 | + || ! empty($this->_session_data['ee_notices']['success']) |
|
900 | 900 | ) |
901 | 901 | ); |
902 | 902 | } |
@@ -925,7 +925,7 @@ discard block |
||
925 | 925 | } |
926 | 926 | $transaction = $this->transaction(); |
927 | 927 | if ($transaction instanceof EE_Transaction) { |
928 | - if (! $transaction->ID()) { |
|
928 | + if ( ! $transaction->ID()) { |
|
929 | 929 | $transaction->save(); |
930 | 930 | } |
931 | 931 | $this->_session_data['transaction'] = $transaction->ID(); |
@@ -939,14 +939,14 @@ discard block |
||
939 | 939 | // maybe save hash check |
940 | 940 | if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
941 | 941 | $this->cache_storage->add( |
942 | - EE_Session::hash_check_prefix . $this->_sid, |
|
942 | + EE_Session::hash_check_prefix.$this->_sid, |
|
943 | 943 | md5($session_data), |
944 | 944 | $this->session_lifespan->inSeconds() |
945 | 945 | ); |
946 | 946 | } |
947 | 947 | // we're using the Transient API for storing session data, |
948 | 948 | return $this->cache_storage->add( |
949 | - EE_Session::session_id_prefix . $this->_sid, |
|
949 | + EE_Session::session_id_prefix.$this->_sid, |
|
950 | 950 | $session_data, |
951 | 951 | $this->session_lifespan->inSeconds() |
952 | 952 | ); |
@@ -960,7 +960,7 @@ discard block |
||
960 | 960 | */ |
961 | 961 | public function _get_page_visit() |
962 | 962 | { |
963 | - $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
963 | + $page_visit = home_url('/').'wp-admin/admin-ajax.php'; |
|
964 | 964 | // check for request url |
965 | 965 | if (isset($_SERVER['REQUEST_URI'])) { |
966 | 966 | $http_host = ''; |
@@ -976,14 +976,14 @@ discard block |
||
976 | 976 | // check for page_id in SERVER REQUEST |
977 | 977 | if (isset($_REQUEST['page_id'])) { |
978 | 978 | // rebuild $e_reg without any of the extra parameters |
979 | - $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&'; |
|
979 | + $page_id = '?page_id='.esc_attr($_REQUEST['page_id']).'&'; |
|
980 | 980 | } |
981 | 981 | // check for $e_reg in SERVER REQUEST |
982 | 982 | if (isset($_REQUEST['ee'])) { |
983 | 983 | // rebuild $e_reg without any of the extra parameters |
984 | - $e_reg = 'ee=' . esc_attr($_REQUEST['ee']); |
|
984 | + $e_reg = 'ee='.esc_attr($_REQUEST['ee']); |
|
985 | 985 | } |
986 | - $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?'); |
|
986 | + $page_visit = rtrim($http_host.$request_uri.$page_id.$e_reg, '?'); |
|
987 | 987 | } |
988 | 988 | return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
989 | 989 | } |
@@ -1021,7 +1021,7 @@ discard block |
||
1021 | 1021 | // <span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/> |
1022 | 1022 | // <span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span> <b style="font-size:10px;"> ' . __LINE__ . ' </b> |
1023 | 1023 | // </h3>'; |
1024 | - do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()'); |
|
1024 | + do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()'); |
|
1025 | 1025 | $this->reset_cart(); |
1026 | 1026 | $this->reset_checkout(); |
1027 | 1027 | $this->reset_transaction(); |
@@ -1043,7 +1043,7 @@ discard block |
||
1043 | 1043 | public function reset_data($data_to_reset = array(), $show_all_notices = false) |
1044 | 1044 | { |
1045 | 1045 | // if $data_to_reset is not in an array, then put it in one |
1046 | - if (! is_array($data_to_reset)) { |
|
1046 | + if ( ! is_array($data_to_reset)) { |
|
1047 | 1047 | $data_to_reset = array($data_to_reset); |
1048 | 1048 | } |
1049 | 1049 | // nothing ??? go home! |
@@ -1063,11 +1063,11 @@ discard block |
||
1063 | 1063 | // since $data_to_reset is an array, cycle through the values |
1064 | 1064 | foreach ($data_to_reset as $reset) { |
1065 | 1065 | // first check to make sure it is a valid session var |
1066 | - if (isset($this->_session_data[ $reset ])) { |
|
1066 | + if (isset($this->_session_data[$reset])) { |
|
1067 | 1067 | // then check to make sure it is not a default var |
1068 | - if (! array_key_exists($reset, $this->_default_session_vars)) { |
|
1068 | + if ( ! array_key_exists($reset, $this->_default_session_vars)) { |
|
1069 | 1069 | // remove session var |
1070 | - unset($this->_session_data[ $reset ]); |
|
1070 | + unset($this->_session_data[$reset]); |
|
1071 | 1071 | if ($show_all_notices) { |
1072 | 1072 | EE_Error::add_success( |
1073 | 1073 | sprintf( |
@@ -1168,7 +1168,7 @@ discard block |
||
1168 | 1168 | // or use that for the new transient cleanup query limit |
1169 | 1169 | add_filter( |
1170 | 1170 | 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
1171 | - function () use ($expired_session_transient_delete_query_limit) { |
|
1171 | + function() use ($expired_session_transient_delete_query_limit) { |
|
1172 | 1172 | return $expired_session_transient_delete_query_limit; |
1173 | 1173 | } |
1174 | 1174 | ); |
@@ -1186,7 +1186,7 @@ discard block |
||
1186 | 1186 | $error = '<pre>'; |
1187 | 1187 | $data2 = preg_replace_callback( |
1188 | 1188 | '!s:(\d+):"(.*?)";!', |
1189 | - function ($match) { |
|
1189 | + function($match) { |
|
1190 | 1190 | return ($match[1] === strlen($match[2])) |
1191 | 1191 | ? $match[0] |
1192 | 1192 | : 's:' |
@@ -1198,13 +1198,13 @@ discard block |
||
1198 | 1198 | $data1 |
1199 | 1199 | ); |
1200 | 1200 | $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
1201 | - $error .= $data1 . PHP_EOL; |
|
1202 | - $error .= $data2 . PHP_EOL; |
|
1201 | + $error .= $data1.PHP_EOL; |
|
1202 | + $error .= $data2.PHP_EOL; |
|
1203 | 1203 | for ($i = 0; $i < $max; $i++) { |
1204 | - if (@$data1[ $i ] !== @$data2[ $i ]) { |
|
1205 | - $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
1206 | - $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL; |
|
1207 | - $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
1204 | + if (@$data1[$i] !== @$data2[$i]) { |
|
1205 | + $error .= 'Difference '.@$data1[$i].' != '.@$data2[$i].PHP_EOL; |
|
1206 | + $error .= "\t-> ORD number ".ord(@$data1[$i]).' != '.ord(@$data2[$i]).PHP_EOL; |
|
1207 | + $error .= "\t-> Line Number = $i".PHP_EOL; |
|
1208 | 1208 | $start = ($i - 20); |
1209 | 1209 | $start = ($start < 0) ? 0 : $start; |
1210 | 1210 | $length = 40; |
@@ -1219,7 +1219,7 @@ discard block |
||
1219 | 1219 | $error .= "\t-> Section Data1 = "; |
1220 | 1220 | $error .= substr_replace( |
1221 | 1221 | substr($data1, $start, $length), |
1222 | - "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
1222 | + "<b style=\"color:green\">{$data1[$i]}</b>", |
|
1223 | 1223 | $rpoint, |
1224 | 1224 | $rlength |
1225 | 1225 | ); |
@@ -1227,7 +1227,7 @@ discard block |
||
1227 | 1227 | $error .= "\t-> Section Data2 = "; |
1228 | 1228 | $error .= substr_replace( |
1229 | 1229 | substr($data2, $start, $length), |
1230 | - "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
1230 | + "<b style=\"color:red\">{$data2[$i]}</b>", |
|
1231 | 1231 | $rpoint, |
1232 | 1232 | $rlength |
1233 | 1233 | ); |
@@ -1258,7 +1258,7 @@ discard block |
||
1258 | 1258 | public function garbageCollection() |
1259 | 1259 | { |
1260 | 1260 | // only perform during regular requests if last garbage collection was over an hour ago |
1261 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
1261 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
1262 | 1262 | $this->_last_gc = time(); |
1263 | 1263 | $this->updateSessionSettings(array('last_gc' => $this->_last_gc)); |
1264 | 1264 | /** @type WPDB $wpdb */ |
@@ -1293,7 +1293,7 @@ discard block |
||
1293 | 1293 | // AND option_value < 1508368198 LIMIT 50 |
1294 | 1294 | $expired_sessions = $wpdb->get_col($SQL); |
1295 | 1295 | // valid results? |
1296 | - if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
1296 | + if ( ! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
1297 | 1297 | $this->cache_storage->deleteMany($expired_sessions, true); |
1298 | 1298 | } |
1299 | 1299 | } |
@@ -27,234 +27,234 @@ |
||
27 | 27 | */ |
28 | 28 | class SessionStartHandler |
29 | 29 | { |
30 | - const OPTION_NAME_SESSION_SAVE_HANDLER_STATUS = 'ee_session_save_handler_status'; |
|
31 | - const REQUEST_PARAM_RETRY_SESSION = 'ee_retry_session'; |
|
32 | - const SESSION_SAVE_HANDLER_STATUS_FAILED = 'session_save_handler_failed'; |
|
33 | - const SESSION_SAVE_HANDLER_STATUS_SUCCESS = 'session_save_handler_success'; |
|
34 | - const SESSION_SAVE_HANDLER_STATUS_UNKNOWN = 'session_save_handler_untested'; |
|
30 | + const OPTION_NAME_SESSION_SAVE_HANDLER_STATUS = 'ee_session_save_handler_status'; |
|
31 | + const REQUEST_PARAM_RETRY_SESSION = 'ee_retry_session'; |
|
32 | + const SESSION_SAVE_HANDLER_STATUS_FAILED = 'session_save_handler_failed'; |
|
33 | + const SESSION_SAVE_HANDLER_STATUS_SUCCESS = 'session_save_handler_success'; |
|
34 | + const SESSION_SAVE_HANDLER_STATUS_UNKNOWN = 'session_save_handler_untested'; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var RequestInterface $request |
|
38 | - */ |
|
39 | - protected $request; |
|
36 | + /** |
|
37 | + * @var RequestInterface $request |
|
38 | + */ |
|
39 | + protected $request; |
|
40 | 40 | |
41 | - /** |
|
42 | - * StartSession constructor. |
|
43 | - * |
|
44 | - * @param RequestInterface $request |
|
45 | - */ |
|
46 | - public function __construct(RequestInterface $request) |
|
47 | - { |
|
48 | - $this->request = $request; |
|
49 | - } |
|
41 | + /** |
|
42 | + * StartSession constructor. |
|
43 | + * |
|
44 | + * @param RequestInterface $request |
|
45 | + */ |
|
46 | + public function __construct(RequestInterface $request) |
|
47 | + { |
|
48 | + $this->request = $request; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Check if a custom session save handler is in play |
|
53 | - * and attempt to start the PHP session |
|
54 | - * |
|
55 | - * @since $VID:$ |
|
56 | - */ |
|
57 | - public function startSession() |
|
58 | - { |
|
59 | - // check that session has started |
|
60 | - if (session_id() === '') { |
|
61 | - // starts a new session if one doesn't already exist, or re-initiates an existing one |
|
62 | - if ($this->hasKnownCustomSessionSaveHandler()) { |
|
63 | - $this->checkCustomSessionSaveHandler(); |
|
64 | - } else { |
|
65 | - session_start(); |
|
66 | - } |
|
67 | - } |
|
68 | - } |
|
51 | + /** |
|
52 | + * Check if a custom session save handler is in play |
|
53 | + * and attempt to start the PHP session |
|
54 | + * |
|
55 | + * @since $VID:$ |
|
56 | + */ |
|
57 | + public function startSession() |
|
58 | + { |
|
59 | + // check that session has started |
|
60 | + if (session_id() === '') { |
|
61 | + // starts a new session if one doesn't already exist, or re-initiates an existing one |
|
62 | + if ($this->hasKnownCustomSessionSaveHandler()) { |
|
63 | + $this->checkCustomSessionSaveHandler(); |
|
64 | + } else { |
|
65 | + session_start(); |
|
66 | + } |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Returns `true` if the 'session.save_handler' ini setting matches a known custom handler |
|
72 | - * |
|
73 | - * @since $VID:$ |
|
74 | - * @return bool |
|
75 | - */ |
|
76 | - private function hasKnownCustomSessionSaveHandler() |
|
77 | - { |
|
78 | - return in_array( |
|
79 | - ini_get('session.save_handler'), |
|
80 | - array( |
|
81 | - 'user', |
|
82 | - ), |
|
83 | - true |
|
84 | - ); |
|
85 | - } |
|
70 | + /** |
|
71 | + * Returns `true` if the 'session.save_handler' ini setting matches a known custom handler |
|
72 | + * |
|
73 | + * @since $VID:$ |
|
74 | + * @return bool |
|
75 | + */ |
|
76 | + private function hasKnownCustomSessionSaveHandler() |
|
77 | + { |
|
78 | + return in_array( |
|
79 | + ini_get('session.save_handler'), |
|
80 | + array( |
|
81 | + 'user', |
|
82 | + ), |
|
83 | + true |
|
84 | + ); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Attempt to start the PHP session when a custom Session Save Handler is known to be set. |
|
89 | - * |
|
90 | - * @since $VID:$ |
|
91 | - */ |
|
92 | - private function checkCustomSessionSaveHandler() |
|
93 | - { |
|
94 | - // If we've already successfully tested the session save handler |
|
95 | - // on a previous request then just start the session |
|
96 | - if ($this->sessionSaveHandlerIsValid()) { |
|
97 | - session_start(); |
|
98 | - return; |
|
99 | - } |
|
100 | - // If not, then attempt to deal with any errors, |
|
101 | - // otherwise, try to hobble along without the session |
|
102 | - if (! $this->handleSessionSaveHandlerErrors()) { |
|
103 | - return; |
|
104 | - } |
|
105 | - // there is no record of a fatal error while trying to start the session |
|
106 | - // so let's see if there's a custom session save handler. Proceed with caution |
|
107 | - $this->initializeSessionSaveHandlerStatus(); |
|
108 | - // hold your breath, the custom session save handler might cause a fatal here... |
|
109 | - session_start(); |
|
110 | - // phew! we made it! the custom session handler is a-ok |
|
111 | - $this->setSessionSaveHandlerStatusToValid(); |
|
112 | - } |
|
87 | + /** |
|
88 | + * Attempt to start the PHP session when a custom Session Save Handler is known to be set. |
|
89 | + * |
|
90 | + * @since $VID:$ |
|
91 | + */ |
|
92 | + private function checkCustomSessionSaveHandler() |
|
93 | + { |
|
94 | + // If we've already successfully tested the session save handler |
|
95 | + // on a previous request then just start the session |
|
96 | + if ($this->sessionSaveHandlerIsValid()) { |
|
97 | + session_start(); |
|
98 | + return; |
|
99 | + } |
|
100 | + // If not, then attempt to deal with any errors, |
|
101 | + // otherwise, try to hobble along without the session |
|
102 | + if (! $this->handleSessionSaveHandlerErrors()) { |
|
103 | + return; |
|
104 | + } |
|
105 | + // there is no record of a fatal error while trying to start the session |
|
106 | + // so let's see if there's a custom session save handler. Proceed with caution |
|
107 | + $this->initializeSessionSaveHandlerStatus(); |
|
108 | + // hold your breath, the custom session save handler might cause a fatal here... |
|
109 | + session_start(); |
|
110 | + // phew! we made it! the custom session handler is a-ok |
|
111 | + $this->setSessionSaveHandlerStatusToValid(); |
|
112 | + } |
|
113 | 113 | |
114 | 114 | |
115 | - /** |
|
116 | - * retrieves the value for the 'ee_session_save_handler_status' WP option. |
|
117 | - * default value = 'session_save_handler_untested' |
|
118 | - * |
|
119 | - * @since $VID:$ |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - private function getSessionSaveHandlerStatus() |
|
123 | - { |
|
124 | - return get_option( |
|
125 | - SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS, |
|
126 | - SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN |
|
127 | - ); |
|
128 | - } |
|
115 | + /** |
|
116 | + * retrieves the value for the 'ee_session_save_handler_status' WP option. |
|
117 | + * default value = 'session_save_handler_untested' |
|
118 | + * |
|
119 | + * @since $VID:$ |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + private function getSessionSaveHandlerStatus() |
|
123 | + { |
|
124 | + return get_option( |
|
125 | + SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS, |
|
126 | + SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN |
|
127 | + ); |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_failed' |
|
132 | - * which can then be upgraded is everything works correctly |
|
133 | - * |
|
134 | - * @since $VID:$ |
|
135 | - * @return bool |
|
136 | - */ |
|
137 | - private function initializeSessionSaveHandlerStatus() |
|
138 | - { |
|
139 | - return update_option( |
|
140 | - SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS, |
|
141 | - SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED |
|
142 | - ); |
|
143 | - } |
|
130 | + /** |
|
131 | + * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_failed' |
|
132 | + * which can then be upgraded is everything works correctly |
|
133 | + * |
|
134 | + * @since $VID:$ |
|
135 | + * @return bool |
|
136 | + */ |
|
137 | + private function initializeSessionSaveHandlerStatus() |
|
138 | + { |
|
139 | + return update_option( |
|
140 | + SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS, |
|
141 | + SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED |
|
142 | + ); |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_success' |
|
147 | - * |
|
148 | - * @since $VID:$ |
|
149 | - * @return bool |
|
150 | - */ |
|
151 | - private function setSessionSaveHandlerStatusToValid() |
|
152 | - { |
|
153 | - return update_option( |
|
154 | - SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS, |
|
155 | - SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS |
|
156 | - ); |
|
157 | - } |
|
145 | + /** |
|
146 | + * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_success' |
|
147 | + * |
|
148 | + * @since $VID:$ |
|
149 | + * @return bool |
|
150 | + */ |
|
151 | + private function setSessionSaveHandlerStatusToValid() |
|
152 | + { |
|
153 | + return update_option( |
|
154 | + SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS, |
|
155 | + SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS |
|
156 | + ); |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_untested' |
|
161 | - * |
|
162 | - * @since $VID:$ |
|
163 | - * @return bool |
|
164 | - */ |
|
165 | - private function resetSessionSaveHandlerStatus() |
|
166 | - { |
|
167 | - return update_option( |
|
168 | - SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS, |
|
169 | - SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN |
|
170 | - ); |
|
171 | - } |
|
159 | + /** |
|
160 | + * Sets the 'ee_session_save_handler_status' WP option value to 'session_save_handler_untested' |
|
161 | + * |
|
162 | + * @since $VID:$ |
|
163 | + * @return bool |
|
164 | + */ |
|
165 | + private function resetSessionSaveHandlerStatus() |
|
166 | + { |
|
167 | + return update_option( |
|
168 | + SessionStartHandler::OPTION_NAME_SESSION_SAVE_HANDLER_STATUS, |
|
169 | + SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_UNKNOWN |
|
170 | + ); |
|
171 | + } |
|
172 | 172 | |
173 | - /** |
|
174 | - * Returns `true` if the 'ee_session_save_handler_status' WP option value |
|
175 | - * is equal to 'session_save_handler_success' |
|
176 | - * |
|
177 | - * @since $VID:$ |
|
178 | - * @return bool |
|
179 | - */ |
|
180 | - private function sessionSaveHandlerIsValid() |
|
181 | - { |
|
182 | - return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS; |
|
183 | - } |
|
173 | + /** |
|
174 | + * Returns `true` if the 'ee_session_save_handler_status' WP option value |
|
175 | + * is equal to 'session_save_handler_success' |
|
176 | + * |
|
177 | + * @since $VID:$ |
|
178 | + * @return bool |
|
179 | + */ |
|
180 | + private function sessionSaveHandlerIsValid() |
|
181 | + { |
|
182 | + return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_SUCCESS; |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * Returns `true` if the 'ee_session_save_handler_status' WP option value |
|
187 | - * is equal to 'session_save_handler_failed' |
|
188 | - * |
|
189 | - * @since $VID:$ |
|
190 | - * @return bool |
|
191 | - */ |
|
192 | - private function sessionSaveHandlerFailed() |
|
193 | - { |
|
194 | - return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED; |
|
195 | - } |
|
185 | + /** |
|
186 | + * Returns `true` if the 'ee_session_save_handler_status' WP option value |
|
187 | + * is equal to 'session_save_handler_failed' |
|
188 | + * |
|
189 | + * @since $VID:$ |
|
190 | + * @return bool |
|
191 | + */ |
|
192 | + private function sessionSaveHandlerFailed() |
|
193 | + { |
|
194 | + return $this->getSessionSaveHandlerStatus() === SessionStartHandler::SESSION_SAVE_HANDLER_STATUS_FAILED; |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * Returns `true` if no errors were detected with the session save handler, |
|
199 | - * otherwise attempts to work notify the appropriate authorities |
|
200 | - * with a suggestion for how to fix the issue, and returns `false`. |
|
201 | - * |
|
202 | - * |
|
203 | - * @since $VID:$ |
|
204 | - * @return bool |
|
205 | - */ |
|
206 | - private function handleSessionSaveHandlerErrors() |
|
207 | - { |
|
208 | - // Check if we had a fatal error last time while trying to start the session |
|
209 | - if ($this->sessionSaveHandlerFailed()) { |
|
210 | - // apparently, last time we tried using the custom session save handler there was a fatal |
|
211 | - if ($this->request->requestParamIsSet(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION)) { |
|
212 | - $this->resetSessionSaveHandlerStatus(); |
|
213 | - // remove "ee_retry_session", otherwise if the problem still isn't fixed, |
|
214 | - // we'll just keep getting the fatal error over and over. |
|
215 | - // Better to remove it and redirect, and try on the next request |
|
216 | - EEH_URL::safeRedirectAndExit( |
|
217 | - remove_query_arg( |
|
218 | - array(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION), |
|
219 | - EEH_URL::current_url() |
|
220 | - ) |
|
221 | - ); |
|
222 | - } |
|
223 | - // so the session is broken, don't try it again, |
|
224 | - // just show a message to users that can fix it |
|
225 | - $this->displaySessionSaveHandlerErrorNotice(); |
|
226 | - return false; |
|
227 | - } |
|
228 | - return true; |
|
229 | - } |
|
197 | + /** |
|
198 | + * Returns `true` if no errors were detected with the session save handler, |
|
199 | + * otherwise attempts to work notify the appropriate authorities |
|
200 | + * with a suggestion for how to fix the issue, and returns `false`. |
|
201 | + * |
|
202 | + * |
|
203 | + * @since $VID:$ |
|
204 | + * @return bool |
|
205 | + */ |
|
206 | + private function handleSessionSaveHandlerErrors() |
|
207 | + { |
|
208 | + // Check if we had a fatal error last time while trying to start the session |
|
209 | + if ($this->sessionSaveHandlerFailed()) { |
|
210 | + // apparently, last time we tried using the custom session save handler there was a fatal |
|
211 | + if ($this->request->requestParamIsSet(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION)) { |
|
212 | + $this->resetSessionSaveHandlerStatus(); |
|
213 | + // remove "ee_retry_session", otherwise if the problem still isn't fixed, |
|
214 | + // we'll just keep getting the fatal error over and over. |
|
215 | + // Better to remove it and redirect, and try on the next request |
|
216 | + EEH_URL::safeRedirectAndExit( |
|
217 | + remove_query_arg( |
|
218 | + array(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION), |
|
219 | + EEH_URL::current_url() |
|
220 | + ) |
|
221 | + ); |
|
222 | + } |
|
223 | + // so the session is broken, don't try it again, |
|
224 | + // just show a message to users that can fix it |
|
225 | + $this->displaySessionSaveHandlerErrorNotice(); |
|
226 | + return false; |
|
227 | + } |
|
228 | + return true; |
|
229 | + } |
|
230 | 230 | |
231 | - /** |
|
232 | - * Generates an EE_Error notice regarding the current session woes |
|
233 | - * but only if the current user is an admin with permission to 'install_plugins'. |
|
234 | - * |
|
235 | - * @since $VID:$ |
|
236 | - */ |
|
237 | - private function displaySessionSaveHandlerErrorNotice() |
|
238 | - { |
|
239 | - if (current_user_can('install_plugins')) { |
|
240 | - $retry_session_url = add_query_arg( |
|
241 | - array(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION => true), |
|
242 | - EEH_URL::current_url() |
|
243 | - ); |
|
244 | - EE_Error::add_error( |
|
245 | - sprintf( |
|
246 | - esc_html__( |
|
247 | - 'It appears there was a fatal error while starting the session, so Event Espresso is not able to process registrations normally. Some hosting companies, like Pantheon, require an extra plugin for Event Espresso to work. Please install the %1$sWordPress Native PHP Sessions plugin%2$s, then %3$sclick here to check if the problem is resolved.%2$s', |
|
248 | - 'event_espresso' |
|
249 | - ), |
|
250 | - '<a href="https://wordpress.org/plugins/wp-native-php-sessions/">', |
|
251 | - '</a>', |
|
252 | - '<a href="' . $retry_session_url . '">' |
|
253 | - ), |
|
254 | - __FILE__, |
|
255 | - __FUNCTION__, |
|
256 | - __LINE__ |
|
257 | - ); |
|
258 | - } |
|
259 | - } |
|
231 | + /** |
|
232 | + * Generates an EE_Error notice regarding the current session woes |
|
233 | + * but only if the current user is an admin with permission to 'install_plugins'. |
|
234 | + * |
|
235 | + * @since $VID:$ |
|
236 | + */ |
|
237 | + private function displaySessionSaveHandlerErrorNotice() |
|
238 | + { |
|
239 | + if (current_user_can('install_plugins')) { |
|
240 | + $retry_session_url = add_query_arg( |
|
241 | + array(SessionStartHandler::REQUEST_PARAM_RETRY_SESSION => true), |
|
242 | + EEH_URL::current_url() |
|
243 | + ); |
|
244 | + EE_Error::add_error( |
|
245 | + sprintf( |
|
246 | + esc_html__( |
|
247 | + 'It appears there was a fatal error while starting the session, so Event Espresso is not able to process registrations normally. Some hosting companies, like Pantheon, require an extra plugin for Event Espresso to work. Please install the %1$sWordPress Native PHP Sessions plugin%2$s, then %3$sclick here to check if the problem is resolved.%2$s', |
|
248 | + 'event_espresso' |
|
249 | + ), |
|
250 | + '<a href="https://wordpress.org/plugins/wp-native-php-sessions/">', |
|
251 | + '</a>', |
|
252 | + '<a href="' . $retry_session_url . '">' |
|
253 | + ), |
|
254 | + __FILE__, |
|
255 | + __FUNCTION__, |
|
256 | + __LINE__ |
|
257 | + ); |
|
258 | + } |
|
259 | + } |
|
260 | 260 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | } |
100 | 100 | // If not, then attempt to deal with any errors, |
101 | 101 | // otherwise, try to hobble along without the session |
102 | - if (! $this->handleSessionSaveHandlerErrors()) { |
|
102 | + if ( ! $this->handleSessionSaveHandlerErrors()) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | // there is no record of a fatal error while trying to start the session |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | ), |
250 | 250 | '<a href="https://wordpress.org/plugins/wp-native-php-sessions/">', |
251 | 251 | '</a>', |
252 | - '<a href="' . $retry_session_url . '">' |
|
252 | + '<a href="'.$retry_session_url.'">' |
|
253 | 253 | ), |
254 | 254 | __FILE__, |
255 | 255 | __FUNCTION__, |
@@ -13,124 +13,124 @@ |
||
13 | 13 | interface RequestTypeContextCheckerInterface |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * true if the current request involves some form of activation |
|
18 | - * |
|
19 | - * @return bool |
|
20 | - */ |
|
21 | - public function isActivation(); |
|
16 | + /** |
|
17 | + * true if the current request involves some form of activation |
|
18 | + * |
|
19 | + * @return bool |
|
20 | + */ |
|
21 | + public function isActivation(); |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * @param $is_activation |
|
26 | - * @return bool |
|
27 | - */ |
|
28 | - public function setIsActivation($is_activation); |
|
24 | + /** |
|
25 | + * @param $is_activation |
|
26 | + * @return bool |
|
27 | + */ |
|
28 | + public function setIsActivation($is_activation); |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * true if the current request is for the admin and is not being made via AJAX |
|
33 | - * |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public function isAdmin(); |
|
31 | + /** |
|
32 | + * true if the current request is for the admin and is not being made via AJAX |
|
33 | + * |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public function isAdmin(); |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * true if the current request is for the admin AND is being made via AJAX |
|
41 | - * and the ajax request contains the request parameter "ee_admin_ajax" |
|
42 | - * |
|
43 | - * @return bool |
|
44 | - */ |
|
45 | - public function isAdminAjax(); |
|
39 | + /** |
|
40 | + * true if the current request is for the admin AND is being made via AJAX |
|
41 | + * and the ajax request contains the request parameter "ee_admin_ajax" |
|
42 | + * |
|
43 | + * @return bool |
|
44 | + */ |
|
45 | + public function isAdminAjax(); |
|
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * true if the current request is being made via AJAX... any AJAX |
|
50 | - * |
|
51 | - * @return bool |
|
52 | - */ |
|
53 | - public function isAjax(); |
|
48 | + /** |
|
49 | + * true if the current request is being made via AJAX... any AJAX |
|
50 | + * |
|
51 | + * @return bool |
|
52 | + */ |
|
53 | + public function isAjax(); |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * true if the current request is for the EE REST API |
|
58 | - * |
|
59 | - * @return bool |
|
60 | - */ |
|
61 | - public function isApi(); |
|
56 | + /** |
|
57 | + * true if the current request is for the EE REST API |
|
58 | + * |
|
59 | + * @return bool |
|
60 | + */ |
|
61 | + public function isApi(); |
|
62 | 62 | |
63 | 63 | |
64 | - /** |
|
65 | - * true if the current request is from the command line |
|
66 | - * |
|
67 | - * @return bool |
|
68 | - */ |
|
69 | - public function isCli(); |
|
64 | + /** |
|
65 | + * true if the current request is from the command line |
|
66 | + * |
|
67 | + * @return bool |
|
68 | + */ |
|
69 | + public function isCli(); |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * true if the current request is for a WP_Cron |
|
74 | - * |
|
75 | - * @return bool |
|
76 | - */ |
|
77 | - public function isCron(); |
|
72 | + /** |
|
73 | + * true if the current request is for a WP_Cron |
|
74 | + * |
|
75 | + * @return bool |
|
76 | + */ |
|
77 | + public function isCron(); |
|
78 | 78 | |
79 | 79 | |
80 | - /** |
|
81 | - * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX |
|
82 | - * |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - public function isEeAjax(); |
|
80 | + /** |
|
81 | + * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX |
|
82 | + * |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + public function isEeAjax(); |
|
86 | 86 | |
87 | 87 | |
88 | - /** |
|
89 | - * true if the current request is for a feed (ie: RSS) |
|
90 | - * |
|
91 | - * @return bool |
|
92 | - */ |
|
93 | - public function isFeed(); |
|
88 | + /** |
|
89 | + * true if the current request is for a feed (ie: RSS) |
|
90 | + * |
|
91 | + * @return bool |
|
92 | + */ |
|
93 | + public function isFeed(); |
|
94 | 94 | |
95 | 95 | |
96 | - /** |
|
97 | - * true if the current request is for the frontend and is not being made via AJAX |
|
98 | - * |
|
99 | - * @return bool |
|
100 | - */ |
|
101 | - public function isFrontend(); |
|
96 | + /** |
|
97 | + * true if the current request is for the frontend and is not being made via AJAX |
|
98 | + * |
|
99 | + * @return bool |
|
100 | + */ |
|
101 | + public function isFrontend(); |
|
102 | 102 | |
103 | 103 | |
104 | - /** |
|
105 | - * @return bool |
|
106 | - */ |
|
107 | - public function isFrontAjax(); |
|
104 | + /** |
|
105 | + * @return bool |
|
106 | + */ |
|
107 | + public function isFrontAjax(); |
|
108 | 108 | |
109 | 109 | |
110 | - /** |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - public function isIframe(); |
|
110 | + /** |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + public function isIframe(); |
|
114 | 114 | |
115 | 115 | |
116 | - /** |
|
117 | - * true if the current request is being made via AJAX but is NOT for EE related logic |
|
118 | - * |
|
119 | - * @return bool |
|
120 | - */ |
|
121 | - public function isOtherAjax(); |
|
116 | + /** |
|
117 | + * true if the current request is being made via AJAX but is NOT for EE related logic |
|
118 | + * |
|
119 | + * @return bool |
|
120 | + */ |
|
121 | + public function isOtherAjax(); |
|
122 | 122 | |
123 | 123 | |
124 | - /** |
|
125 | - * true if the current request is a loopback sent from WP core to test for errors |
|
126 | - * |
|
127 | - * @return bool |
|
128 | - */ |
|
129 | - public function isWordPressScrape(); |
|
124 | + /** |
|
125 | + * true if the current request is a loopback sent from WP core to test for errors |
|
126 | + * |
|
127 | + * @return bool |
|
128 | + */ |
|
129 | + public function isWordPressScrape(); |
|
130 | 130 | |
131 | 131 | |
132 | - /** |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - public function slug(); |
|
132 | + /** |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + public function slug(); |
|
136 | 136 | } |
@@ -16,195 +16,195 @@ |
||
16 | 16 | class RequestTypeContextChecker extends ContextChecker implements RequestTypeContextCheckerInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var RequestTypeContext $request_type |
|
21 | - */ |
|
22 | - private $request_type; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * RequestTypeContextChecker constructor. |
|
27 | - * |
|
28 | - * @param RequestTypeContext $request_type |
|
29 | - */ |
|
30 | - public function __construct(RequestTypeContext $request_type) |
|
31 | - { |
|
32 | - $this->request_type = $request_type; |
|
33 | - parent::__construct( |
|
34 | - 'RequestTypeContextChecker', |
|
35 | - $this->request_type->validRequestTypes() |
|
36 | - ); |
|
37 | - } |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * true if the current request involves some form of activation |
|
42 | - * |
|
43 | - * @return bool |
|
44 | - */ |
|
45 | - public function isActivation() |
|
46 | - { |
|
47 | - return $this->request_type->isActivation(); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * @param $is_activation |
|
53 | - * @return bool |
|
54 | - */ |
|
55 | - public function setIsActivation($is_activation) |
|
56 | - { |
|
57 | - return $this->request_type->setIsActivation($is_activation); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * true if the current request is for the admin and is not being made via AJAX |
|
63 | - * |
|
64 | - * @return bool |
|
65 | - */ |
|
66 | - public function isAdmin() |
|
67 | - { |
|
68 | - return $this->request_type->slug() === RequestTypeContext::ADMIN; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * true if the current request is for the admin AND is being made via AJAX |
|
74 | - * |
|
75 | - * @return bool |
|
76 | - */ |
|
77 | - public function isAdminAjax() |
|
78 | - { |
|
79 | - return $this->request_type->slug() === RequestTypeContext::AJAX_ADMIN; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * true if the current request is being made via AJAX... any AJAX |
|
85 | - * |
|
86 | - * @return bool |
|
87 | - */ |
|
88 | - public function isAjax() |
|
89 | - { |
|
90 | - return $this->isEeAjax() || $this->isOtherAjax(); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX |
|
96 | - * |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public function isEeAjax() |
|
100 | - { |
|
101 | - return $this->isAdminAjax() || $this->isFrontAjax(); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * true if the current request is being made via AJAX but is NOT for EE related logic |
|
107 | - * |
|
108 | - * @return bool |
|
109 | - */ |
|
110 | - public function isOtherAjax() |
|
111 | - { |
|
112 | - return $this->request_type->slug() === RequestTypeContext::AJAX_OTHER; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * true if the current request is for the EE REST API |
|
117 | - * |
|
118 | - * @return bool |
|
119 | - */ |
|
120 | - public function isApi() |
|
121 | - { |
|
122 | - return $this->request_type->slug() === RequestTypeContext::API; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * true if the current request is from the command line |
|
128 | - * |
|
129 | - * @return bool |
|
130 | - */ |
|
131 | - public function isCli() |
|
132 | - { |
|
133 | - return $this->request_type->slug() === RequestTypeContext::CLI; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * true if the current request is for a WP_Cron |
|
139 | - * |
|
140 | - * @return bool |
|
141 | - */ |
|
142 | - public function isCron() |
|
143 | - { |
|
144 | - return $this->request_type->slug() === RequestTypeContext::CRON; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * true if the current request is for a feed (ie: RSS) |
|
150 | - * |
|
151 | - * @return bool |
|
152 | - */ |
|
153 | - public function isFeed() |
|
154 | - { |
|
155 | - return $this->request_type->slug() === RequestTypeContext::FEED; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * true if the current request is for the frontend and is not being made via AJAX |
|
161 | - * |
|
162 | - * @return bool |
|
163 | - */ |
|
164 | - public function isFrontend() |
|
165 | - { |
|
166 | - return $this->request_type->slug() === RequestTypeContext::FRONTEND; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * true if the current request is for the frontend AND is being made via AJAX |
|
172 | - * |
|
173 | - * @return bool |
|
174 | - */ |
|
175 | - public function isFrontAjax() |
|
176 | - { |
|
177 | - return $this->request_type->slug() === RequestTypeContext::AJAX_FRONT; |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * true if the current request is for content that is to be displayed within an iframe |
|
183 | - * |
|
184 | - * @return bool |
|
185 | - */ |
|
186 | - public function isIframe() |
|
187 | - { |
|
188 | - return $this->request_type->slug() === RequestTypeContext::IFRAME; |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * true if the current request is a loopback sent from WP core to test for errors |
|
194 | - * |
|
195 | - * @return bool |
|
196 | - */ |
|
197 | - public function isWordPressScrape() |
|
198 | - { |
|
199 | - return $this->request_type->slug() === RequestTypeContext::WP_SCRAPE; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * @return string |
|
205 | - */ |
|
206 | - public function slug() |
|
207 | - { |
|
208 | - return $this->request_type->slug(); |
|
209 | - } |
|
19 | + /** |
|
20 | + * @var RequestTypeContext $request_type |
|
21 | + */ |
|
22 | + private $request_type; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * RequestTypeContextChecker constructor. |
|
27 | + * |
|
28 | + * @param RequestTypeContext $request_type |
|
29 | + */ |
|
30 | + public function __construct(RequestTypeContext $request_type) |
|
31 | + { |
|
32 | + $this->request_type = $request_type; |
|
33 | + parent::__construct( |
|
34 | + 'RequestTypeContextChecker', |
|
35 | + $this->request_type->validRequestTypes() |
|
36 | + ); |
|
37 | + } |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * true if the current request involves some form of activation |
|
42 | + * |
|
43 | + * @return bool |
|
44 | + */ |
|
45 | + public function isActivation() |
|
46 | + { |
|
47 | + return $this->request_type->isActivation(); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * @param $is_activation |
|
53 | + * @return bool |
|
54 | + */ |
|
55 | + public function setIsActivation($is_activation) |
|
56 | + { |
|
57 | + return $this->request_type->setIsActivation($is_activation); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * true if the current request is for the admin and is not being made via AJAX |
|
63 | + * |
|
64 | + * @return bool |
|
65 | + */ |
|
66 | + public function isAdmin() |
|
67 | + { |
|
68 | + return $this->request_type->slug() === RequestTypeContext::ADMIN; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * true if the current request is for the admin AND is being made via AJAX |
|
74 | + * |
|
75 | + * @return bool |
|
76 | + */ |
|
77 | + public function isAdminAjax() |
|
78 | + { |
|
79 | + return $this->request_type->slug() === RequestTypeContext::AJAX_ADMIN; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * true if the current request is being made via AJAX... any AJAX |
|
85 | + * |
|
86 | + * @return bool |
|
87 | + */ |
|
88 | + public function isAjax() |
|
89 | + { |
|
90 | + return $this->isEeAjax() || $this->isOtherAjax(); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX |
|
96 | + * |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public function isEeAjax() |
|
100 | + { |
|
101 | + return $this->isAdminAjax() || $this->isFrontAjax(); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * true if the current request is being made via AJAX but is NOT for EE related logic |
|
107 | + * |
|
108 | + * @return bool |
|
109 | + */ |
|
110 | + public function isOtherAjax() |
|
111 | + { |
|
112 | + return $this->request_type->slug() === RequestTypeContext::AJAX_OTHER; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * true if the current request is for the EE REST API |
|
117 | + * |
|
118 | + * @return bool |
|
119 | + */ |
|
120 | + public function isApi() |
|
121 | + { |
|
122 | + return $this->request_type->slug() === RequestTypeContext::API; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * true if the current request is from the command line |
|
128 | + * |
|
129 | + * @return bool |
|
130 | + */ |
|
131 | + public function isCli() |
|
132 | + { |
|
133 | + return $this->request_type->slug() === RequestTypeContext::CLI; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * true if the current request is for a WP_Cron |
|
139 | + * |
|
140 | + * @return bool |
|
141 | + */ |
|
142 | + public function isCron() |
|
143 | + { |
|
144 | + return $this->request_type->slug() === RequestTypeContext::CRON; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * true if the current request is for a feed (ie: RSS) |
|
150 | + * |
|
151 | + * @return bool |
|
152 | + */ |
|
153 | + public function isFeed() |
|
154 | + { |
|
155 | + return $this->request_type->slug() === RequestTypeContext::FEED; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * true if the current request is for the frontend and is not being made via AJAX |
|
161 | + * |
|
162 | + * @return bool |
|
163 | + */ |
|
164 | + public function isFrontend() |
|
165 | + { |
|
166 | + return $this->request_type->slug() === RequestTypeContext::FRONTEND; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * true if the current request is for the frontend AND is being made via AJAX |
|
172 | + * |
|
173 | + * @return bool |
|
174 | + */ |
|
175 | + public function isFrontAjax() |
|
176 | + { |
|
177 | + return $this->request_type->slug() === RequestTypeContext::AJAX_FRONT; |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * true if the current request is for content that is to be displayed within an iframe |
|
183 | + * |
|
184 | + * @return bool |
|
185 | + */ |
|
186 | + public function isIframe() |
|
187 | + { |
|
188 | + return $this->request_type->slug() === RequestTypeContext::IFRAME; |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * true if the current request is a loopback sent from WP core to test for errors |
|
194 | + * |
|
195 | + * @return bool |
|
196 | + */ |
|
197 | + public function isWordPressScrape() |
|
198 | + { |
|
199 | + return $this->request_type->slug() === RequestTypeContext::WP_SCRAPE; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * @return string |
|
205 | + */ |
|
206 | + public function slug() |
|
207 | + { |
|
208 | + return $this->request_type->slug(); |
|
209 | + } |
|
210 | 210 | } |
@@ -19,137 +19,137 @@ |
||
19 | 19 | class RequestTypeContextDetector |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var RequestTypeContextFactory $factory |
|
24 | - */ |
|
25 | - private $factory; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var RequestInterface $request |
|
29 | - */ |
|
30 | - private $request; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * RequestTypeContextDetector constructor. |
|
35 | - * |
|
36 | - * @param RequestInterface $request |
|
37 | - * @param RequestTypeContextFactory $factory |
|
38 | - */ |
|
39 | - public function __construct(RequestInterface $request, RequestTypeContextFactory $factory) |
|
40 | - { |
|
41 | - $this->request = $request; |
|
42 | - $this->factory = $factory; |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * @return RequestTypeContext |
|
48 | - * @throws InvalidArgumentException |
|
49 | - */ |
|
50 | - public function detectRequestTypeContext() |
|
51 | - { |
|
52 | - // Detect error scrapes |
|
53 | - if ($this->request->getRequestParam('wp_scrape_key') !== null |
|
54 | - && $this->request->getRequestParam('wp_scrape_nonce') !== null |
|
55 | - ) { |
|
56 | - return $this->factory->create(RequestTypeContext::WP_SCRAPE); |
|
57 | - } |
|
58 | - // Detect EE REST API |
|
59 | - if ($this->isEspressoRestApiRequest()) { |
|
60 | - return $this->factory->create(RequestTypeContext::API); |
|
61 | - } |
|
62 | - // Detect AJAX |
|
63 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
64 | - if (filter_var($this->request->getRequestParam('ee_front_ajax'), FILTER_VALIDATE_BOOLEAN)) { |
|
65 | - return $this->factory->create(RequestTypeContext::AJAX_FRONT); |
|
66 | - } |
|
67 | - if (filter_var($this->request->getRequestParam('ee_admin_ajax'), FILTER_VALIDATE_BOOLEAN)) { |
|
68 | - return $this->factory->create(RequestTypeContext::AJAX_ADMIN); |
|
69 | - } |
|
70 | - return $this->factory->create(RequestTypeContext::AJAX_OTHER); |
|
71 | - } |
|
72 | - // Detect WP_Cron |
|
73 | - if ($this->isCronRequest()) { |
|
74 | - return $this->factory->create(RequestTypeContext::CRON); |
|
75 | - } |
|
76 | - // Detect command line requests |
|
77 | - if (defined('WP_CLI') && WP_CLI) { |
|
78 | - return $this->factory->create(RequestTypeContext::CLI); |
|
79 | - } |
|
80 | - // detect WordPress admin (ie: "Dashboard") |
|
81 | - if (is_admin()) { |
|
82 | - return $this->factory->create(RequestTypeContext::ADMIN); |
|
83 | - } |
|
84 | - // Detect iFrames |
|
85 | - if ($this->isIframeRoute()) { |
|
86 | - return $this->factory->create(RequestTypeContext::IFRAME); |
|
87 | - } |
|
88 | - // Detect Feeds |
|
89 | - if ($this->isFeedRequest()) { |
|
90 | - return $this->factory->create(RequestTypeContext::FEED); |
|
91 | - } |
|
92 | - // and by process of elimination... |
|
93 | - return $this->factory->create(RequestTypeContext::FRONTEND); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @return bool |
|
99 | - */ |
|
100 | - private function isEspressoRestApiRequest() |
|
101 | - { |
|
102 | - $ee_rest_url_prefix = RecommendedVersions::compareWordPressVersion('4.4.0') |
|
103 | - ? trim(rest_get_url_prefix(), '/') |
|
104 | - : 'wp-json'; |
|
105 | - $ee_rest_url_prefix .= '/' . Domain::API_NAMESPACE; |
|
106 | - return $this->uriPathMatches($ee_rest_url_prefix); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - private function isCronRequest() |
|
114 | - { |
|
115 | - return $this->uriPathMatches('wp-cron.php'); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - private function isFeedRequest() |
|
123 | - { |
|
124 | - return $this->uriPathMatches('feed'); |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @param string $component |
|
130 | - * @return bool |
|
131 | - */ |
|
132 | - private function uriPathMatches($component) |
|
133 | - { |
|
134 | - $request_uri = $this->request->requestUri(); |
|
135 | - $parts = explode('?', $request_uri); |
|
136 | - $path = trim(reset($parts), '/'); |
|
137 | - return strpos($path, $component) === 0; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @return bool |
|
143 | - */ |
|
144 | - private function isIframeRoute() |
|
145 | - { |
|
146 | - $is_iframe_route = apply_filters( |
|
147 | - 'FHEE__EventEspresso_core_domain_services_contexts_RequestTypeContextDetector__isIframeRoute', |
|
148 | - $this->request->getRequestParam('event_list', '') === 'iframe' |
|
149 | - || $this->request->getRequestParam('ticket_selector', '') === 'iframe' |
|
150 | - || $this->request->getRequestParam('calendar', '') === 'iframe', |
|
151 | - $this |
|
152 | - ); |
|
153 | - return filter_var($is_iframe_route, FILTER_VALIDATE_BOOLEAN); |
|
154 | - } |
|
22 | + /** |
|
23 | + * @var RequestTypeContextFactory $factory |
|
24 | + */ |
|
25 | + private $factory; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var RequestInterface $request |
|
29 | + */ |
|
30 | + private $request; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * RequestTypeContextDetector constructor. |
|
35 | + * |
|
36 | + * @param RequestInterface $request |
|
37 | + * @param RequestTypeContextFactory $factory |
|
38 | + */ |
|
39 | + public function __construct(RequestInterface $request, RequestTypeContextFactory $factory) |
|
40 | + { |
|
41 | + $this->request = $request; |
|
42 | + $this->factory = $factory; |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * @return RequestTypeContext |
|
48 | + * @throws InvalidArgumentException |
|
49 | + */ |
|
50 | + public function detectRequestTypeContext() |
|
51 | + { |
|
52 | + // Detect error scrapes |
|
53 | + if ($this->request->getRequestParam('wp_scrape_key') !== null |
|
54 | + && $this->request->getRequestParam('wp_scrape_nonce') !== null |
|
55 | + ) { |
|
56 | + return $this->factory->create(RequestTypeContext::WP_SCRAPE); |
|
57 | + } |
|
58 | + // Detect EE REST API |
|
59 | + if ($this->isEspressoRestApiRequest()) { |
|
60 | + return $this->factory->create(RequestTypeContext::API); |
|
61 | + } |
|
62 | + // Detect AJAX |
|
63 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
64 | + if (filter_var($this->request->getRequestParam('ee_front_ajax'), FILTER_VALIDATE_BOOLEAN)) { |
|
65 | + return $this->factory->create(RequestTypeContext::AJAX_FRONT); |
|
66 | + } |
|
67 | + if (filter_var($this->request->getRequestParam('ee_admin_ajax'), FILTER_VALIDATE_BOOLEAN)) { |
|
68 | + return $this->factory->create(RequestTypeContext::AJAX_ADMIN); |
|
69 | + } |
|
70 | + return $this->factory->create(RequestTypeContext::AJAX_OTHER); |
|
71 | + } |
|
72 | + // Detect WP_Cron |
|
73 | + if ($this->isCronRequest()) { |
|
74 | + return $this->factory->create(RequestTypeContext::CRON); |
|
75 | + } |
|
76 | + // Detect command line requests |
|
77 | + if (defined('WP_CLI') && WP_CLI) { |
|
78 | + return $this->factory->create(RequestTypeContext::CLI); |
|
79 | + } |
|
80 | + // detect WordPress admin (ie: "Dashboard") |
|
81 | + if (is_admin()) { |
|
82 | + return $this->factory->create(RequestTypeContext::ADMIN); |
|
83 | + } |
|
84 | + // Detect iFrames |
|
85 | + if ($this->isIframeRoute()) { |
|
86 | + return $this->factory->create(RequestTypeContext::IFRAME); |
|
87 | + } |
|
88 | + // Detect Feeds |
|
89 | + if ($this->isFeedRequest()) { |
|
90 | + return $this->factory->create(RequestTypeContext::FEED); |
|
91 | + } |
|
92 | + // and by process of elimination... |
|
93 | + return $this->factory->create(RequestTypeContext::FRONTEND); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @return bool |
|
99 | + */ |
|
100 | + private function isEspressoRestApiRequest() |
|
101 | + { |
|
102 | + $ee_rest_url_prefix = RecommendedVersions::compareWordPressVersion('4.4.0') |
|
103 | + ? trim(rest_get_url_prefix(), '/') |
|
104 | + : 'wp-json'; |
|
105 | + $ee_rest_url_prefix .= '/' . Domain::API_NAMESPACE; |
|
106 | + return $this->uriPathMatches($ee_rest_url_prefix); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + private function isCronRequest() |
|
114 | + { |
|
115 | + return $this->uriPathMatches('wp-cron.php'); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + private function isFeedRequest() |
|
123 | + { |
|
124 | + return $this->uriPathMatches('feed'); |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @param string $component |
|
130 | + * @return bool |
|
131 | + */ |
|
132 | + private function uriPathMatches($component) |
|
133 | + { |
|
134 | + $request_uri = $this->request->requestUri(); |
|
135 | + $parts = explode('?', $request_uri); |
|
136 | + $path = trim(reset($parts), '/'); |
|
137 | + return strpos($path, $component) === 0; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @return bool |
|
143 | + */ |
|
144 | + private function isIframeRoute() |
|
145 | + { |
|
146 | + $is_iframe_route = apply_filters( |
|
147 | + 'FHEE__EventEspresso_core_domain_services_contexts_RequestTypeContextDetector__isIframeRoute', |
|
148 | + $this->request->getRequestParam('event_list', '') === 'iframe' |
|
149 | + || $this->request->getRequestParam('ticket_selector', '') === 'iframe' |
|
150 | + || $this->request->getRequestParam('calendar', '') === 'iframe', |
|
151 | + $this |
|
152 | + ); |
|
153 | + return filter_var($is_iframe_route, FILTER_VALIDATE_BOOLEAN); |
|
154 | + } |
|
155 | 155 | } |
@@ -16,143 +16,143 @@ |
||
16 | 16 | class RequestTypeContext extends Context |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * indicates that the current request involves some form of activation |
|
21 | - */ |
|
22 | - const ACTIVATION = 'activation-request'; |
|
23 | - |
|
24 | - /** |
|
25 | - * indicates that the current request is for the admin but is not being made via AJAX |
|
26 | - */ |
|
27 | - const ADMIN = 'non-ajax-admin-request'; |
|
28 | - |
|
29 | - /** |
|
30 | - * indicates that the current request is for the admin AND is being made via AJAX |
|
31 | - */ |
|
32 | - const AJAX_ADMIN = 'admin-ajax-request'; |
|
33 | - |
|
34 | - /** |
|
35 | - * indicates that the current request is for the frontend AND is being made via AJAX |
|
36 | - */ |
|
37 | - const AJAX_FRONT = 'frontend-ajax-request'; |
|
38 | - |
|
39 | - /** |
|
40 | - * indicates that the current request is being made via AJAX, but is NOT for EE |
|
41 | - */ |
|
42 | - const AJAX_OTHER = 'other-ajax-request'; |
|
43 | - |
|
44 | - /** |
|
45 | - * indicates that the current request is for the EE REST API |
|
46 | - */ |
|
47 | - const API = 'rest-api'; |
|
48 | - |
|
49 | - /** |
|
50 | - * indicates that the current request is from the command line |
|
51 | - */ |
|
52 | - const CLI = 'command-line'; |
|
53 | - |
|
54 | - /** |
|
55 | - * indicates that the current request is for a WP_Cron |
|
56 | - */ |
|
57 | - const CRON = 'wp-cron'; |
|
58 | - |
|
59 | - /** |
|
60 | - * indicates that the current request is for a feed (ie: RSS) |
|
61 | - */ |
|
62 | - const FEED = 'feed-request'; |
|
63 | - |
|
64 | - /** |
|
65 | - * indicates that the current request is for the frontend but is not being made via AJAX |
|
66 | - */ |
|
67 | - const FRONTEND = 'non-ajax-frontend-request'; |
|
68 | - |
|
69 | - /** |
|
70 | - * indicates that the current request is for content that is to be displayed within an iframe |
|
71 | - */ |
|
72 | - const IFRAME = 'iframe-request'; |
|
73 | - |
|
74 | - /** |
|
75 | - * indicates that the current request is a loopback sent from WP core to test for errors |
|
76 | - */ |
|
77 | - const WP_SCRAPE = 'wordpress-scrape'; |
|
78 | - |
|
79 | - /** |
|
80 | - * @var boolean $is_activation |
|
81 | - */ |
|
82 | - private $is_activation = false; |
|
83 | - |
|
84 | - /** |
|
85 | - * @var array $valid_request_types |
|
86 | - */ |
|
87 | - private $valid_request_types = array(); |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * RequestTypeContext constructor. |
|
92 | - * |
|
93 | - * @param string $slug |
|
94 | - * @param string $description |
|
95 | - * @throws InvalidArgumentException |
|
96 | - */ |
|
97 | - public function __construct($slug, $description) |
|
98 | - { |
|
99 | - parent::__construct($slug, $description); |
|
100 | - if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
101 | - throw new InvalidArgumentException( |
|
102 | - sprintf( |
|
103 | - esc_html__( |
|
104 | - 'The RequestTypeContext slug must be one of the following values: %1$s %2$s', |
|
105 | - 'event_espresso' |
|
106 | - ), |
|
107 | - var_export($this->validRequestTypes(), true) |
|
108 | - ) |
|
109 | - ); |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @return array |
|
116 | - */ |
|
117 | - public function validRequestTypes() |
|
118 | - { |
|
119 | - if (empty($this->valid_request_types)) { |
|
120 | - $this->valid_request_types = apply_filters( |
|
121 | - 'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes', |
|
122 | - array( |
|
123 | - RequestTypeContext::ACTIVATION, |
|
124 | - RequestTypeContext::ADMIN, |
|
125 | - RequestTypeContext::AJAX_ADMIN, |
|
126 | - RequestTypeContext::AJAX_FRONT, |
|
127 | - RequestTypeContext::AJAX_OTHER, |
|
128 | - RequestTypeContext::API, |
|
129 | - RequestTypeContext::CLI, |
|
130 | - RequestTypeContext::CRON, |
|
131 | - RequestTypeContext::FEED, |
|
132 | - RequestTypeContext::FRONTEND, |
|
133 | - RequestTypeContext::IFRAME, |
|
134 | - RequestTypeContext::WP_SCRAPE, |
|
135 | - ) |
|
136 | - ); |
|
137 | - } |
|
138 | - return $this->valid_request_types; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @return bool |
|
144 | - */ |
|
145 | - public function isActivation() |
|
146 | - { |
|
147 | - return $this->is_activation; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @param bool $is_activation |
|
153 | - */ |
|
154 | - public function setIsActivation($is_activation) |
|
155 | - { |
|
156 | - $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN); |
|
157 | - } |
|
19 | + /** |
|
20 | + * indicates that the current request involves some form of activation |
|
21 | + */ |
|
22 | + const ACTIVATION = 'activation-request'; |
|
23 | + |
|
24 | + /** |
|
25 | + * indicates that the current request is for the admin but is not being made via AJAX |
|
26 | + */ |
|
27 | + const ADMIN = 'non-ajax-admin-request'; |
|
28 | + |
|
29 | + /** |
|
30 | + * indicates that the current request is for the admin AND is being made via AJAX |
|
31 | + */ |
|
32 | + const AJAX_ADMIN = 'admin-ajax-request'; |
|
33 | + |
|
34 | + /** |
|
35 | + * indicates that the current request is for the frontend AND is being made via AJAX |
|
36 | + */ |
|
37 | + const AJAX_FRONT = 'frontend-ajax-request'; |
|
38 | + |
|
39 | + /** |
|
40 | + * indicates that the current request is being made via AJAX, but is NOT for EE |
|
41 | + */ |
|
42 | + const AJAX_OTHER = 'other-ajax-request'; |
|
43 | + |
|
44 | + /** |
|
45 | + * indicates that the current request is for the EE REST API |
|
46 | + */ |
|
47 | + const API = 'rest-api'; |
|
48 | + |
|
49 | + /** |
|
50 | + * indicates that the current request is from the command line |
|
51 | + */ |
|
52 | + const CLI = 'command-line'; |
|
53 | + |
|
54 | + /** |
|
55 | + * indicates that the current request is for a WP_Cron |
|
56 | + */ |
|
57 | + const CRON = 'wp-cron'; |
|
58 | + |
|
59 | + /** |
|
60 | + * indicates that the current request is for a feed (ie: RSS) |
|
61 | + */ |
|
62 | + const FEED = 'feed-request'; |
|
63 | + |
|
64 | + /** |
|
65 | + * indicates that the current request is for the frontend but is not being made via AJAX |
|
66 | + */ |
|
67 | + const FRONTEND = 'non-ajax-frontend-request'; |
|
68 | + |
|
69 | + /** |
|
70 | + * indicates that the current request is for content that is to be displayed within an iframe |
|
71 | + */ |
|
72 | + const IFRAME = 'iframe-request'; |
|
73 | + |
|
74 | + /** |
|
75 | + * indicates that the current request is a loopback sent from WP core to test for errors |
|
76 | + */ |
|
77 | + const WP_SCRAPE = 'wordpress-scrape'; |
|
78 | + |
|
79 | + /** |
|
80 | + * @var boolean $is_activation |
|
81 | + */ |
|
82 | + private $is_activation = false; |
|
83 | + |
|
84 | + /** |
|
85 | + * @var array $valid_request_types |
|
86 | + */ |
|
87 | + private $valid_request_types = array(); |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * RequestTypeContext constructor. |
|
92 | + * |
|
93 | + * @param string $slug |
|
94 | + * @param string $description |
|
95 | + * @throws InvalidArgumentException |
|
96 | + */ |
|
97 | + public function __construct($slug, $description) |
|
98 | + { |
|
99 | + parent::__construct($slug, $description); |
|
100 | + if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
101 | + throw new InvalidArgumentException( |
|
102 | + sprintf( |
|
103 | + esc_html__( |
|
104 | + 'The RequestTypeContext slug must be one of the following values: %1$s %2$s', |
|
105 | + 'event_espresso' |
|
106 | + ), |
|
107 | + var_export($this->validRequestTypes(), true) |
|
108 | + ) |
|
109 | + ); |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @return array |
|
116 | + */ |
|
117 | + public function validRequestTypes() |
|
118 | + { |
|
119 | + if (empty($this->valid_request_types)) { |
|
120 | + $this->valid_request_types = apply_filters( |
|
121 | + 'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes', |
|
122 | + array( |
|
123 | + RequestTypeContext::ACTIVATION, |
|
124 | + RequestTypeContext::ADMIN, |
|
125 | + RequestTypeContext::AJAX_ADMIN, |
|
126 | + RequestTypeContext::AJAX_FRONT, |
|
127 | + RequestTypeContext::AJAX_OTHER, |
|
128 | + RequestTypeContext::API, |
|
129 | + RequestTypeContext::CLI, |
|
130 | + RequestTypeContext::CRON, |
|
131 | + RequestTypeContext::FEED, |
|
132 | + RequestTypeContext::FRONTEND, |
|
133 | + RequestTypeContext::IFRAME, |
|
134 | + RequestTypeContext::WP_SCRAPE, |
|
135 | + ) |
|
136 | + ); |
|
137 | + } |
|
138 | + return $this->valid_request_types; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @return bool |
|
144 | + */ |
|
145 | + public function isActivation() |
|
146 | + { |
|
147 | + return $this->is_activation; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @param bool $is_activation |
|
153 | + */ |
|
154 | + public function setIsActivation($is_activation) |
|
155 | + { |
|
156 | + $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN); |
|
157 | + } |
|
158 | 158 | } |
@@ -17,586 +17,586 @@ |
||
17 | 17 | class Request implements InterminableInterface, RequestInterface, ReservedInstanceInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * $_GET parameters |
|
22 | - * |
|
23 | - * @var array $get |
|
24 | - */ |
|
25 | - private $get; |
|
26 | - |
|
27 | - /** |
|
28 | - * $_POST parameters |
|
29 | - * |
|
30 | - * @var array $post |
|
31 | - */ |
|
32 | - private $post; |
|
33 | - |
|
34 | - /** |
|
35 | - * $_COOKIE parameters |
|
36 | - * |
|
37 | - * @var array $cookie |
|
38 | - */ |
|
39 | - private $cookie; |
|
40 | - |
|
41 | - /** |
|
42 | - * $_SERVER parameters |
|
43 | - * |
|
44 | - * @var array $server |
|
45 | - */ |
|
46 | - private $server; |
|
47 | - |
|
48 | - /** |
|
49 | - * $_REQUEST parameters |
|
50 | - * |
|
51 | - * @var array $request |
|
52 | - */ |
|
53 | - private $request; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var RequestTypeContextCheckerInterface |
|
57 | - */ |
|
58 | - private $request_type; |
|
59 | - |
|
60 | - /** |
|
61 | - * IP address for request |
|
62 | - * |
|
63 | - * @var string $ip_address |
|
64 | - */ |
|
65 | - private $ip_address; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var string $user_agent |
|
69 | - */ |
|
70 | - private $user_agent; |
|
71 | - |
|
72 | - /** |
|
73 | - * true if current user appears to be some kind of bot |
|
74 | - * |
|
75 | - * @var bool $is_bot |
|
76 | - */ |
|
77 | - private $is_bot; |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * @param array $get |
|
82 | - * @param array $post |
|
83 | - * @param array $cookie |
|
84 | - * @param array $server |
|
85 | - */ |
|
86 | - public function __construct(array $get, array $post, array $cookie, array $server) |
|
87 | - { |
|
88 | - // grab request vars |
|
89 | - $this->get = $get; |
|
90 | - $this->post = $post; |
|
91 | - $this->cookie = $cookie; |
|
92 | - $this->server = $server; |
|
93 | - $this->request = array_merge($this->get, $this->post); |
|
94 | - $this->ip_address = $this->visitorIp(); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * @param RequestTypeContextCheckerInterface $type |
|
100 | - */ |
|
101 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
102 | - { |
|
103 | - $this->request_type = $type; |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @return array |
|
109 | - */ |
|
110 | - public function getParams() |
|
111 | - { |
|
112 | - return $this->get; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @return array |
|
118 | - */ |
|
119 | - public function postParams() |
|
120 | - { |
|
121 | - return $this->post; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @return array |
|
127 | - */ |
|
128 | - public function cookieParams() |
|
129 | - { |
|
130 | - return $this->cookie; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @return array |
|
136 | - */ |
|
137 | - public function serverParams() |
|
138 | - { |
|
139 | - return $this->server; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * returns contents of $_REQUEST |
|
145 | - * |
|
146 | - * @return array |
|
147 | - */ |
|
148 | - public function requestParams() |
|
149 | - { |
|
150 | - return $this->request; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @param $key |
|
156 | - * @param $value |
|
157 | - * @param bool $override_ee |
|
158 | - * @return void |
|
159 | - */ |
|
160 | - public function setRequestParam($key, $value, $override_ee = false) |
|
161 | - { |
|
162 | - // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
163 | - if ($key !== 'ee' |
|
164 | - || ($key === 'ee' && empty($this->request['ee'])) |
|
165 | - || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee) |
|
166 | - ) { |
|
167 | - $this->request[ $key ] = $value; |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * returns the value for a request param if the given key exists |
|
174 | - * |
|
175 | - * @param $key |
|
176 | - * @param null $default |
|
177 | - * @return mixed |
|
178 | - */ |
|
179 | - public function getRequestParam($key, $default = null) |
|
180 | - { |
|
181 | - return $this->requestParameterDrillDown($key, $default, 'get'); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * check if param exists |
|
187 | - * |
|
188 | - * @param $key |
|
189 | - * @return bool |
|
190 | - */ |
|
191 | - public function requestParamIsSet($key) |
|
192 | - { |
|
193 | - return $this->requestParameterDrillDown($key); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
199 | - * and return the value for the first match found |
|
200 | - * wildcards can be either of the following: |
|
201 | - * ? to represent a single character of any type |
|
202 | - * * to represent one or more characters of any type |
|
203 | - * |
|
204 | - * @param string $pattern |
|
205 | - * @param null|mixed $default |
|
206 | - * @return false|int |
|
207 | - */ |
|
208 | - public function getMatch($pattern, $default = null) |
|
209 | - { |
|
210 | - return $this->requestParameterDrillDown($pattern, $default, 'match'); |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
216 | - * wildcards can be either of the following: |
|
217 | - * ? to represent a single character of any type |
|
218 | - * * to represent one or more characters of any type |
|
219 | - * returns true if a match is found or false if not |
|
220 | - * |
|
221 | - * @param string $pattern |
|
222 | - * @return false|int |
|
223 | - */ |
|
224 | - public function matches($pattern) |
|
225 | - { |
|
226 | - return $this->requestParameterDrillDown($pattern, null, 'match') !== null; |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
232 | - * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
233 | - * and used to search through the current request's parameter keys |
|
234 | - * @param array $request_params The array of request parameters to search through |
|
235 | - * @param mixed $default [optional] The value to be returned if no match is found. |
|
236 | - * Default is null |
|
237 | - * @param string $return [optional] Controls what kind of value is returned. |
|
238 | - * Options are: |
|
239 | - * 'bool' will return true or false if match is found or not |
|
240 | - * 'key' will return the first key found that matches the supplied pattern |
|
241 | - * 'value' will return the value for the first request parameter |
|
242 | - * whose key matches the supplied pattern |
|
243 | - * Default is 'value' |
|
244 | - * @return boolean|string |
|
245 | - */ |
|
246 | - private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
247 | - { |
|
248 | - $return = in_array($return, array('bool', 'key', 'value'), true) |
|
249 | - ? $return |
|
250 | - : 'is_set'; |
|
251 | - // replace wildcard chars with regex chars |
|
252 | - $pattern = str_replace( |
|
253 | - array("\*", "\?"), |
|
254 | - array('.*', '.'), |
|
255 | - preg_quote($pattern, '/') |
|
256 | - ); |
|
257 | - foreach ($request_params as $key => $request_param) { |
|
258 | - if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
259 | - // return value for request param |
|
260 | - if ($return === 'value') { |
|
261 | - return $request_params[ $key ]; |
|
262 | - } |
|
263 | - // or actual key or true just to indicate it was found |
|
264 | - return $return === 'key' ? $key : true; |
|
265 | - } |
|
266 | - } |
|
267 | - // match not found so return default value or false |
|
268 | - return $return === 'value' ? $default : false; |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * the supplied key can be a simple string to represent a "top-level" request parameter |
|
274 | - * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
275 | - * by using square brackets to surround keys for deeper array elements. |
|
276 | - * For example : |
|
277 | - * if the supplied $key was: "first[second][third]" |
|
278 | - * then this will attempt to drill down into the request parameter array to find a value. |
|
279 | - * Given the following request parameters: |
|
280 | - * array( |
|
281 | - * 'first' => array( |
|
282 | - * 'second' => array( |
|
283 | - * 'third' => 'has a value' |
|
284 | - * ) |
|
285 | - * ) |
|
286 | - * ) |
|
287 | - * would return true if default parameters were set |
|
288 | - * |
|
289 | - * @param string $callback |
|
290 | - * @param $key |
|
291 | - * @param null $default |
|
292 | - * @param array $request_params |
|
293 | - * @return bool|mixed|null |
|
294 | - */ |
|
295 | - private function requestParameterDrillDown( |
|
296 | - $key, |
|
297 | - $default = null, |
|
298 | - $callback = 'is_set', |
|
299 | - array $request_params = array() |
|
300 | - ) { |
|
301 | - $callback = in_array($callback, array('is_set', 'get', 'match'), true) |
|
302 | - ? $callback |
|
303 | - : 'is_set'; |
|
304 | - $request_params = ! empty($request_params) |
|
305 | - ? $request_params |
|
306 | - : $this->request; |
|
307 | - // does incoming key represent an array like 'first[second][third]' ? |
|
308 | - if (strpos($key, '[') !== false) { |
|
309 | - // turn it into an actual array |
|
310 | - $key = str_replace(']', '', $key); |
|
311 | - $keys = explode('[', $key); |
|
312 | - $key = array_shift($keys); |
|
313 | - if ($callback === 'match') { |
|
314 | - $real_key = $this->match($key, $request_params, $default, 'key'); |
|
315 | - $key = $real_key ? $real_key : $key; |
|
316 | - } |
|
317 | - // check if top level key exists |
|
318 | - if (isset($request_params[ $key ])) { |
|
319 | - // build a new key to pass along like: 'second[third]' |
|
320 | - // or just 'second' depending on depth of keys |
|
321 | - $key_string = array_shift($keys); |
|
322 | - if (! empty($keys)) { |
|
323 | - $key_string .= '[' . implode('][', $keys) . ']'; |
|
324 | - } |
|
325 | - return $this->requestParameterDrillDown( |
|
326 | - $key_string, |
|
327 | - $default, |
|
328 | - $callback, |
|
329 | - $request_params[ $key ] |
|
330 | - ); |
|
331 | - } |
|
332 | - } |
|
333 | - if ($callback === 'is_set') { |
|
334 | - return isset($request_params[ $key ]); |
|
335 | - } |
|
336 | - if ($callback === 'match') { |
|
337 | - return $this->match($key, $request_params, $default); |
|
338 | - } |
|
339 | - return isset($request_params[ $key ]) |
|
340 | - ? $request_params[ $key ] |
|
341 | - : $default; |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * remove param |
|
347 | - * |
|
348 | - * @param $key |
|
349 | - * @param bool $unset_from_global_too |
|
350 | - */ |
|
351 | - public function unSetRequestParam($key, $unset_from_global_too = false) |
|
352 | - { |
|
353 | - unset($this->request[ $key ]); |
|
354 | - if ($unset_from_global_too) { |
|
355 | - unset($_REQUEST[ $key ]); |
|
356 | - } |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * @return string |
|
362 | - */ |
|
363 | - public function ipAddress() |
|
364 | - { |
|
365 | - return $this->ip_address; |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * attempt to get IP address of current visitor from server |
|
371 | - * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
372 | - * |
|
373 | - * @access public |
|
374 | - * @return string |
|
375 | - */ |
|
376 | - private function visitorIp() |
|
377 | - { |
|
378 | - $visitor_ip = '0.0.0.0'; |
|
379 | - $server_keys = array( |
|
380 | - 'HTTP_CLIENT_IP', |
|
381 | - 'HTTP_X_FORWARDED_FOR', |
|
382 | - 'HTTP_X_FORWARDED', |
|
383 | - 'HTTP_X_CLUSTER_CLIENT_IP', |
|
384 | - 'HTTP_FORWARDED_FOR', |
|
385 | - 'HTTP_FORWARDED', |
|
386 | - 'REMOTE_ADDR', |
|
387 | - ); |
|
388 | - foreach ($server_keys as $key) { |
|
389 | - if (isset($this->server[ $key ])) { |
|
390 | - foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
391 | - if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
392 | - $visitor_ip = $ip; |
|
393 | - } |
|
394 | - } |
|
395 | - } |
|
396 | - } |
|
397 | - return $visitor_ip; |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - /** |
|
402 | - * @return string |
|
403 | - */ |
|
404 | - public function requestUri() |
|
405 | - { |
|
406 | - $request_uri = filter_input( |
|
407 | - INPUT_SERVER, |
|
408 | - 'REQUEST_URI', |
|
409 | - FILTER_SANITIZE_URL, |
|
410 | - FILTER_NULL_ON_FAILURE |
|
411 | - ); |
|
412 | - if (empty($request_uri)) { |
|
413 | - // fallback sanitization if the above fails |
|
414 | - $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']); |
|
415 | - } |
|
416 | - return $request_uri; |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - /** |
|
421 | - * @return string |
|
422 | - */ |
|
423 | - public function userAgent() |
|
424 | - { |
|
425 | - return $this->user_agent; |
|
426 | - } |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * @param string $user_agent |
|
431 | - */ |
|
432 | - public function setUserAgent($user_agent = '') |
|
433 | - { |
|
434 | - if ($user_agent === '' || ! is_string($user_agent)) { |
|
435 | - $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : ''; |
|
436 | - } |
|
437 | - $this->user_agent = $user_agent; |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - /** |
|
442 | - * @return bool |
|
443 | - */ |
|
444 | - public function isBot() |
|
445 | - { |
|
446 | - return $this->is_bot; |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * @param bool $is_bot |
|
452 | - */ |
|
453 | - public function setIsBot($is_bot) |
|
454 | - { |
|
455 | - $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * @return bool |
|
461 | - */ |
|
462 | - public function isActivation() |
|
463 | - { |
|
464 | - return $this->request_type->isActivation(); |
|
465 | - } |
|
466 | - |
|
467 | - |
|
468 | - /** |
|
469 | - * @param $is_activation |
|
470 | - * @return bool |
|
471 | - */ |
|
472 | - public function setIsActivation($is_activation) |
|
473 | - { |
|
474 | - return $this->request_type->setIsActivation($is_activation); |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - /** |
|
479 | - * @return bool |
|
480 | - */ |
|
481 | - public function isAdmin() |
|
482 | - { |
|
483 | - return $this->request_type->isAdmin(); |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - /** |
|
488 | - * @return bool |
|
489 | - */ |
|
490 | - public function isAdminAjax() |
|
491 | - { |
|
492 | - return $this->request_type->isAdminAjax(); |
|
493 | - } |
|
494 | - |
|
495 | - |
|
496 | - /** |
|
497 | - * @return bool |
|
498 | - */ |
|
499 | - public function isAjax() |
|
500 | - { |
|
501 | - return $this->request_type->isAjax(); |
|
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - /** |
|
506 | - * @return bool |
|
507 | - */ |
|
508 | - public function isEeAjax() |
|
509 | - { |
|
510 | - return $this->request_type->isEeAjax(); |
|
511 | - } |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * @return bool |
|
516 | - */ |
|
517 | - public function isOtherAjax() |
|
518 | - { |
|
519 | - return $this->request_type->isOtherAjax(); |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - /** |
|
524 | - * @return bool |
|
525 | - */ |
|
526 | - public function isApi() |
|
527 | - { |
|
528 | - return $this->request_type->isApi(); |
|
529 | - } |
|
530 | - |
|
531 | - |
|
532 | - /** |
|
533 | - * @return bool |
|
534 | - */ |
|
535 | - public function isCli() |
|
536 | - { |
|
537 | - return $this->request_type->isCli(); |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - /** |
|
542 | - * @return bool |
|
543 | - */ |
|
544 | - public function isCron() |
|
545 | - { |
|
546 | - return $this->request_type->isCron(); |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * @return bool |
|
552 | - */ |
|
553 | - public function isFeed() |
|
554 | - { |
|
555 | - return $this->request_type->isFeed(); |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * @return bool |
|
561 | - */ |
|
562 | - public function isFrontend() |
|
563 | - { |
|
564 | - return $this->request_type->isFrontend(); |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - /** |
|
569 | - * @return bool |
|
570 | - */ |
|
571 | - public function isFrontAjax() |
|
572 | - { |
|
573 | - return $this->request_type->isFrontAjax(); |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * @return bool |
|
579 | - */ |
|
580 | - public function isIframe() |
|
581 | - { |
|
582 | - return $this->request_type->isIframe(); |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - /** |
|
587 | - * @return bool |
|
588 | - */ |
|
589 | - public function isWordPressScrape() |
|
590 | - { |
|
591 | - return $this->request_type->isWordPressScrape(); |
|
592 | - } |
|
593 | - |
|
594 | - |
|
595 | - /** |
|
596 | - * @return string |
|
597 | - */ |
|
598 | - public function slug() |
|
599 | - { |
|
600 | - return $this->request_type->slug(); |
|
601 | - } |
|
20 | + /** |
|
21 | + * $_GET parameters |
|
22 | + * |
|
23 | + * @var array $get |
|
24 | + */ |
|
25 | + private $get; |
|
26 | + |
|
27 | + /** |
|
28 | + * $_POST parameters |
|
29 | + * |
|
30 | + * @var array $post |
|
31 | + */ |
|
32 | + private $post; |
|
33 | + |
|
34 | + /** |
|
35 | + * $_COOKIE parameters |
|
36 | + * |
|
37 | + * @var array $cookie |
|
38 | + */ |
|
39 | + private $cookie; |
|
40 | + |
|
41 | + /** |
|
42 | + * $_SERVER parameters |
|
43 | + * |
|
44 | + * @var array $server |
|
45 | + */ |
|
46 | + private $server; |
|
47 | + |
|
48 | + /** |
|
49 | + * $_REQUEST parameters |
|
50 | + * |
|
51 | + * @var array $request |
|
52 | + */ |
|
53 | + private $request; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var RequestTypeContextCheckerInterface |
|
57 | + */ |
|
58 | + private $request_type; |
|
59 | + |
|
60 | + /** |
|
61 | + * IP address for request |
|
62 | + * |
|
63 | + * @var string $ip_address |
|
64 | + */ |
|
65 | + private $ip_address; |
|
66 | + |
|
67 | + /** |
|
68 | + * @var string $user_agent |
|
69 | + */ |
|
70 | + private $user_agent; |
|
71 | + |
|
72 | + /** |
|
73 | + * true if current user appears to be some kind of bot |
|
74 | + * |
|
75 | + * @var bool $is_bot |
|
76 | + */ |
|
77 | + private $is_bot; |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * @param array $get |
|
82 | + * @param array $post |
|
83 | + * @param array $cookie |
|
84 | + * @param array $server |
|
85 | + */ |
|
86 | + public function __construct(array $get, array $post, array $cookie, array $server) |
|
87 | + { |
|
88 | + // grab request vars |
|
89 | + $this->get = $get; |
|
90 | + $this->post = $post; |
|
91 | + $this->cookie = $cookie; |
|
92 | + $this->server = $server; |
|
93 | + $this->request = array_merge($this->get, $this->post); |
|
94 | + $this->ip_address = $this->visitorIp(); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * @param RequestTypeContextCheckerInterface $type |
|
100 | + */ |
|
101 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
102 | + { |
|
103 | + $this->request_type = $type; |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @return array |
|
109 | + */ |
|
110 | + public function getParams() |
|
111 | + { |
|
112 | + return $this->get; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @return array |
|
118 | + */ |
|
119 | + public function postParams() |
|
120 | + { |
|
121 | + return $this->post; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @return array |
|
127 | + */ |
|
128 | + public function cookieParams() |
|
129 | + { |
|
130 | + return $this->cookie; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @return array |
|
136 | + */ |
|
137 | + public function serverParams() |
|
138 | + { |
|
139 | + return $this->server; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * returns contents of $_REQUEST |
|
145 | + * |
|
146 | + * @return array |
|
147 | + */ |
|
148 | + public function requestParams() |
|
149 | + { |
|
150 | + return $this->request; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @param $key |
|
156 | + * @param $value |
|
157 | + * @param bool $override_ee |
|
158 | + * @return void |
|
159 | + */ |
|
160 | + public function setRequestParam($key, $value, $override_ee = false) |
|
161 | + { |
|
162 | + // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
163 | + if ($key !== 'ee' |
|
164 | + || ($key === 'ee' && empty($this->request['ee'])) |
|
165 | + || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee) |
|
166 | + ) { |
|
167 | + $this->request[ $key ] = $value; |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * returns the value for a request param if the given key exists |
|
174 | + * |
|
175 | + * @param $key |
|
176 | + * @param null $default |
|
177 | + * @return mixed |
|
178 | + */ |
|
179 | + public function getRequestParam($key, $default = null) |
|
180 | + { |
|
181 | + return $this->requestParameterDrillDown($key, $default, 'get'); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * check if param exists |
|
187 | + * |
|
188 | + * @param $key |
|
189 | + * @return bool |
|
190 | + */ |
|
191 | + public function requestParamIsSet($key) |
|
192 | + { |
|
193 | + return $this->requestParameterDrillDown($key); |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
199 | + * and return the value for the first match found |
|
200 | + * wildcards can be either of the following: |
|
201 | + * ? to represent a single character of any type |
|
202 | + * * to represent one or more characters of any type |
|
203 | + * |
|
204 | + * @param string $pattern |
|
205 | + * @param null|mixed $default |
|
206 | + * @return false|int |
|
207 | + */ |
|
208 | + public function getMatch($pattern, $default = null) |
|
209 | + { |
|
210 | + return $this->requestParameterDrillDown($pattern, $default, 'match'); |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
216 | + * wildcards can be either of the following: |
|
217 | + * ? to represent a single character of any type |
|
218 | + * * to represent one or more characters of any type |
|
219 | + * returns true if a match is found or false if not |
|
220 | + * |
|
221 | + * @param string $pattern |
|
222 | + * @return false|int |
|
223 | + */ |
|
224 | + public function matches($pattern) |
|
225 | + { |
|
226 | + return $this->requestParameterDrillDown($pattern, null, 'match') !== null; |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
232 | + * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
233 | + * and used to search through the current request's parameter keys |
|
234 | + * @param array $request_params The array of request parameters to search through |
|
235 | + * @param mixed $default [optional] The value to be returned if no match is found. |
|
236 | + * Default is null |
|
237 | + * @param string $return [optional] Controls what kind of value is returned. |
|
238 | + * Options are: |
|
239 | + * 'bool' will return true or false if match is found or not |
|
240 | + * 'key' will return the first key found that matches the supplied pattern |
|
241 | + * 'value' will return the value for the first request parameter |
|
242 | + * whose key matches the supplied pattern |
|
243 | + * Default is 'value' |
|
244 | + * @return boolean|string |
|
245 | + */ |
|
246 | + private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
247 | + { |
|
248 | + $return = in_array($return, array('bool', 'key', 'value'), true) |
|
249 | + ? $return |
|
250 | + : 'is_set'; |
|
251 | + // replace wildcard chars with regex chars |
|
252 | + $pattern = str_replace( |
|
253 | + array("\*", "\?"), |
|
254 | + array('.*', '.'), |
|
255 | + preg_quote($pattern, '/') |
|
256 | + ); |
|
257 | + foreach ($request_params as $key => $request_param) { |
|
258 | + if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
259 | + // return value for request param |
|
260 | + if ($return === 'value') { |
|
261 | + return $request_params[ $key ]; |
|
262 | + } |
|
263 | + // or actual key or true just to indicate it was found |
|
264 | + return $return === 'key' ? $key : true; |
|
265 | + } |
|
266 | + } |
|
267 | + // match not found so return default value or false |
|
268 | + return $return === 'value' ? $default : false; |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * the supplied key can be a simple string to represent a "top-level" request parameter |
|
274 | + * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
275 | + * by using square brackets to surround keys for deeper array elements. |
|
276 | + * For example : |
|
277 | + * if the supplied $key was: "first[second][third]" |
|
278 | + * then this will attempt to drill down into the request parameter array to find a value. |
|
279 | + * Given the following request parameters: |
|
280 | + * array( |
|
281 | + * 'first' => array( |
|
282 | + * 'second' => array( |
|
283 | + * 'third' => 'has a value' |
|
284 | + * ) |
|
285 | + * ) |
|
286 | + * ) |
|
287 | + * would return true if default parameters were set |
|
288 | + * |
|
289 | + * @param string $callback |
|
290 | + * @param $key |
|
291 | + * @param null $default |
|
292 | + * @param array $request_params |
|
293 | + * @return bool|mixed|null |
|
294 | + */ |
|
295 | + private function requestParameterDrillDown( |
|
296 | + $key, |
|
297 | + $default = null, |
|
298 | + $callback = 'is_set', |
|
299 | + array $request_params = array() |
|
300 | + ) { |
|
301 | + $callback = in_array($callback, array('is_set', 'get', 'match'), true) |
|
302 | + ? $callback |
|
303 | + : 'is_set'; |
|
304 | + $request_params = ! empty($request_params) |
|
305 | + ? $request_params |
|
306 | + : $this->request; |
|
307 | + // does incoming key represent an array like 'first[second][third]' ? |
|
308 | + if (strpos($key, '[') !== false) { |
|
309 | + // turn it into an actual array |
|
310 | + $key = str_replace(']', '', $key); |
|
311 | + $keys = explode('[', $key); |
|
312 | + $key = array_shift($keys); |
|
313 | + if ($callback === 'match') { |
|
314 | + $real_key = $this->match($key, $request_params, $default, 'key'); |
|
315 | + $key = $real_key ? $real_key : $key; |
|
316 | + } |
|
317 | + // check if top level key exists |
|
318 | + if (isset($request_params[ $key ])) { |
|
319 | + // build a new key to pass along like: 'second[third]' |
|
320 | + // or just 'second' depending on depth of keys |
|
321 | + $key_string = array_shift($keys); |
|
322 | + if (! empty($keys)) { |
|
323 | + $key_string .= '[' . implode('][', $keys) . ']'; |
|
324 | + } |
|
325 | + return $this->requestParameterDrillDown( |
|
326 | + $key_string, |
|
327 | + $default, |
|
328 | + $callback, |
|
329 | + $request_params[ $key ] |
|
330 | + ); |
|
331 | + } |
|
332 | + } |
|
333 | + if ($callback === 'is_set') { |
|
334 | + return isset($request_params[ $key ]); |
|
335 | + } |
|
336 | + if ($callback === 'match') { |
|
337 | + return $this->match($key, $request_params, $default); |
|
338 | + } |
|
339 | + return isset($request_params[ $key ]) |
|
340 | + ? $request_params[ $key ] |
|
341 | + : $default; |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * remove param |
|
347 | + * |
|
348 | + * @param $key |
|
349 | + * @param bool $unset_from_global_too |
|
350 | + */ |
|
351 | + public function unSetRequestParam($key, $unset_from_global_too = false) |
|
352 | + { |
|
353 | + unset($this->request[ $key ]); |
|
354 | + if ($unset_from_global_too) { |
|
355 | + unset($_REQUEST[ $key ]); |
|
356 | + } |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * @return string |
|
362 | + */ |
|
363 | + public function ipAddress() |
|
364 | + { |
|
365 | + return $this->ip_address; |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * attempt to get IP address of current visitor from server |
|
371 | + * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
372 | + * |
|
373 | + * @access public |
|
374 | + * @return string |
|
375 | + */ |
|
376 | + private function visitorIp() |
|
377 | + { |
|
378 | + $visitor_ip = '0.0.0.0'; |
|
379 | + $server_keys = array( |
|
380 | + 'HTTP_CLIENT_IP', |
|
381 | + 'HTTP_X_FORWARDED_FOR', |
|
382 | + 'HTTP_X_FORWARDED', |
|
383 | + 'HTTP_X_CLUSTER_CLIENT_IP', |
|
384 | + 'HTTP_FORWARDED_FOR', |
|
385 | + 'HTTP_FORWARDED', |
|
386 | + 'REMOTE_ADDR', |
|
387 | + ); |
|
388 | + foreach ($server_keys as $key) { |
|
389 | + if (isset($this->server[ $key ])) { |
|
390 | + foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
391 | + if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
392 | + $visitor_ip = $ip; |
|
393 | + } |
|
394 | + } |
|
395 | + } |
|
396 | + } |
|
397 | + return $visitor_ip; |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + /** |
|
402 | + * @return string |
|
403 | + */ |
|
404 | + public function requestUri() |
|
405 | + { |
|
406 | + $request_uri = filter_input( |
|
407 | + INPUT_SERVER, |
|
408 | + 'REQUEST_URI', |
|
409 | + FILTER_SANITIZE_URL, |
|
410 | + FILTER_NULL_ON_FAILURE |
|
411 | + ); |
|
412 | + if (empty($request_uri)) { |
|
413 | + // fallback sanitization if the above fails |
|
414 | + $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']); |
|
415 | + } |
|
416 | + return $request_uri; |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + /** |
|
421 | + * @return string |
|
422 | + */ |
|
423 | + public function userAgent() |
|
424 | + { |
|
425 | + return $this->user_agent; |
|
426 | + } |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * @param string $user_agent |
|
431 | + */ |
|
432 | + public function setUserAgent($user_agent = '') |
|
433 | + { |
|
434 | + if ($user_agent === '' || ! is_string($user_agent)) { |
|
435 | + $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : ''; |
|
436 | + } |
|
437 | + $this->user_agent = $user_agent; |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + /** |
|
442 | + * @return bool |
|
443 | + */ |
|
444 | + public function isBot() |
|
445 | + { |
|
446 | + return $this->is_bot; |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * @param bool $is_bot |
|
452 | + */ |
|
453 | + public function setIsBot($is_bot) |
|
454 | + { |
|
455 | + $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * @return bool |
|
461 | + */ |
|
462 | + public function isActivation() |
|
463 | + { |
|
464 | + return $this->request_type->isActivation(); |
|
465 | + } |
|
466 | + |
|
467 | + |
|
468 | + /** |
|
469 | + * @param $is_activation |
|
470 | + * @return bool |
|
471 | + */ |
|
472 | + public function setIsActivation($is_activation) |
|
473 | + { |
|
474 | + return $this->request_type->setIsActivation($is_activation); |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + /** |
|
479 | + * @return bool |
|
480 | + */ |
|
481 | + public function isAdmin() |
|
482 | + { |
|
483 | + return $this->request_type->isAdmin(); |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + /** |
|
488 | + * @return bool |
|
489 | + */ |
|
490 | + public function isAdminAjax() |
|
491 | + { |
|
492 | + return $this->request_type->isAdminAjax(); |
|
493 | + } |
|
494 | + |
|
495 | + |
|
496 | + /** |
|
497 | + * @return bool |
|
498 | + */ |
|
499 | + public function isAjax() |
|
500 | + { |
|
501 | + return $this->request_type->isAjax(); |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + /** |
|
506 | + * @return bool |
|
507 | + */ |
|
508 | + public function isEeAjax() |
|
509 | + { |
|
510 | + return $this->request_type->isEeAjax(); |
|
511 | + } |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * @return bool |
|
516 | + */ |
|
517 | + public function isOtherAjax() |
|
518 | + { |
|
519 | + return $this->request_type->isOtherAjax(); |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + /** |
|
524 | + * @return bool |
|
525 | + */ |
|
526 | + public function isApi() |
|
527 | + { |
|
528 | + return $this->request_type->isApi(); |
|
529 | + } |
|
530 | + |
|
531 | + |
|
532 | + /** |
|
533 | + * @return bool |
|
534 | + */ |
|
535 | + public function isCli() |
|
536 | + { |
|
537 | + return $this->request_type->isCli(); |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + /** |
|
542 | + * @return bool |
|
543 | + */ |
|
544 | + public function isCron() |
|
545 | + { |
|
546 | + return $this->request_type->isCron(); |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * @return bool |
|
552 | + */ |
|
553 | + public function isFeed() |
|
554 | + { |
|
555 | + return $this->request_type->isFeed(); |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * @return bool |
|
561 | + */ |
|
562 | + public function isFrontend() |
|
563 | + { |
|
564 | + return $this->request_type->isFrontend(); |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + /** |
|
569 | + * @return bool |
|
570 | + */ |
|
571 | + public function isFrontAjax() |
|
572 | + { |
|
573 | + return $this->request_type->isFrontAjax(); |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * @return bool |
|
579 | + */ |
|
580 | + public function isIframe() |
|
581 | + { |
|
582 | + return $this->request_type->isIframe(); |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + /** |
|
587 | + * @return bool |
|
588 | + */ |
|
589 | + public function isWordPressScrape() |
|
590 | + { |
|
591 | + return $this->request_type->isWordPressScrape(); |
|
592 | + } |
|
593 | + |
|
594 | + |
|
595 | + /** |
|
596 | + * @return string |
|
597 | + */ |
|
598 | + public function slug() |
|
599 | + { |
|
600 | + return $this->request_type->slug(); |
|
601 | + } |
|
602 | 602 | } |
@@ -17,23 +17,23 @@ |
||
17 | 17 | class DetectFileEditorRequest extends Middleware |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * converts a Request to a Response |
|
22 | - * |
|
23 | - * @param RequestInterface $request |
|
24 | - * @param ResponseInterface $response |
|
25 | - * @return ResponseInterface |
|
26 | - */ |
|
27 | - public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
28 | - { |
|
29 | - $this->request = $request; |
|
30 | - $this->response = $response; |
|
31 | - // can't store user data during WP error scrapes if no user exists |
|
32 | - // so don't load the session since it's not going to work anyways |
|
33 | - if ($this->request->isWordPressScrape()) { |
|
34 | - add_filter('FHEE_load_EE_Session', '__return_false', 999); |
|
35 | - } |
|
36 | - $this->response = $this->processRequestStack($this->request, $this->response); |
|
37 | - return $this->response; |
|
38 | - } |
|
20 | + /** |
|
21 | + * converts a Request to a Response |
|
22 | + * |
|
23 | + * @param RequestInterface $request |
|
24 | + * @param ResponseInterface $response |
|
25 | + * @return ResponseInterface |
|
26 | + */ |
|
27 | + public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
28 | + { |
|
29 | + $this->request = $request; |
|
30 | + $this->response = $response; |
|
31 | + // can't store user data during WP error scrapes if no user exists |
|
32 | + // so don't load the session since it's not going to work anyways |
|
33 | + if ($this->request->isWordPressScrape()) { |
|
34 | + add_filter('FHEE_load_EE_Session', '__return_false', 999); |
|
35 | + } |
|
36 | + $this->response = $this->processRequestStack($this->request, $this->response); |
|
37 | + return $this->response; |
|
38 | + } |
|
39 | 39 | } |
@@ -17,332 +17,332 @@ |
||
17 | 17 | class EED_Recaptcha_Invisible extends EED_Module |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var EE_Registration_Config $config |
|
22 | - */ |
|
23 | - private static $config; |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * @return EED_Module|EED_Recaptcha |
|
28 | - */ |
|
29 | - public static function instance() |
|
30 | - { |
|
31 | - return parent::get_instance(__CLASS__); |
|
32 | - } |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @return void |
|
37 | - * @throws InvalidInterfaceException |
|
38 | - * @throws InvalidDataTypeException |
|
39 | - * @throws InvalidArgumentException |
|
40 | - */ |
|
41 | - public static function set_hooks() |
|
42 | - { |
|
43 | - EED_Recaptcha_Invisible::setProperties(); |
|
44 | - if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) { |
|
45 | - if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
46 | - // ticket selection |
|
47 | - add_filter( |
|
48 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
49 | - array('EED_Recaptcha_Invisible', 'ticketSelectorForm'), |
|
50 | - 10, |
|
51 | - 3 |
|
52 | - ); |
|
53 | - add_action( |
|
54 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
55 | - array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
56 | - ); |
|
57 | - } |
|
58 | - if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
59 | - // checkout |
|
60 | - add_action( |
|
61 | - 'AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', |
|
62 | - array('EED_Recaptcha_Invisible', 'spcoRegStepForm') |
|
63 | - ); |
|
64 | - add_filter( |
|
65 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
66 | - array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
67 | - 10, |
|
68 | - 2 |
|
69 | - ); |
|
70 | - } |
|
71 | - add_action('loop_end', array('EED_Recaptcha_Invisible', 'localizeScriptVars')); |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @return void |
|
78 | - * @throws InvalidInterfaceException |
|
79 | - * @throws InvalidDataTypeException |
|
80 | - * @throws InvalidArgumentException |
|
81 | - */ |
|
82 | - public static function set_hooks_admin() |
|
83 | - { |
|
84 | - EED_Recaptcha_Invisible::setProperties(); |
|
85 | - if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
86 | - add_action( |
|
87 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
88 | - array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
89 | - ); |
|
90 | - } |
|
91 | - if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
92 | - add_filter( |
|
93 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
94 | - array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
95 | - 10, |
|
96 | - 2 |
|
97 | - ); |
|
98 | - } |
|
99 | - // admin settings |
|
100 | - add_action( |
|
101 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
102 | - array('EED_Recaptcha_Invisible', 'adminSettings') |
|
103 | - ); |
|
104 | - add_filter( |
|
105 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
106 | - array('EED_Recaptcha_Invisible', 'updateAdminSettings') |
|
107 | - ); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @return void |
|
113 | - * @throws InvalidInterfaceException |
|
114 | - * @throws InvalidDataTypeException |
|
115 | - * @throws InvalidArgumentException |
|
116 | - */ |
|
117 | - public static function setProperties() |
|
118 | - { |
|
119 | - |
|
120 | - EED_Recaptcha_Invisible::$config = EE_Registry::instance()->CFG->registration; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @return boolean |
|
126 | - */ |
|
127 | - public static function useInvisibleRecaptcha() |
|
128 | - { |
|
129 | - return EED_Recaptcha_Invisible::$config->use_captcha |
|
130 | - && EED_Recaptcha_Invisible::$config->recaptcha_theme === 'invisible'; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @param string $form |
|
136 | - * @return boolean |
|
137 | - */ |
|
138 | - public static function protectForm($form) |
|
139 | - { |
|
140 | - return is_array(EED_Recaptcha_Invisible::$config->recaptcha_protected_forms) |
|
141 | - && in_array($form, EED_Recaptcha_Invisible::$config->recaptcha_protected_forms, true); |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @return void |
|
147 | - * @throws InvalidInterfaceException |
|
148 | - * @throws InvalidDataTypeException |
|
149 | - * @throws InvalidArgumentException |
|
150 | - */ |
|
151 | - public static function localizeScriptVars() |
|
152 | - { |
|
153 | - /** @var \EventEspresso\core\services\request\Request $request */ |
|
154 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
155 | - // Invisible Recaptcha is ONLY ever required for the frontend and admin |
|
156 | - // so we don't need to load any JS assets for other types of requests (like AJAX or API). |
|
157 | - if (! ($request->isAdmin() || $request->isFrontend())) { |
|
158 | - return; |
|
159 | - } |
|
160 | - wp_localize_script( |
|
161 | - EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
162 | - 'eeRecaptcha', |
|
163 | - RecaptchaFactory::create()->getLocalizedVars() |
|
164 | - ); |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public static function assetsUrl() |
|
172 | - { |
|
173 | - return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * @param \WP $WP |
|
179 | - */ |
|
180 | - public function run($WP) |
|
181 | - { |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * @param EE_Request $request |
|
187 | - * @return bool |
|
188 | - * @throws InvalidArgumentException |
|
189 | - * @throws InvalidDataTypeException |
|
190 | - * @throws InvalidInterfaceException |
|
191 | - * @throws RuntimeException |
|
192 | - */ |
|
193 | - public static function verifyToken(EE_Request $request) |
|
194 | - { |
|
195 | - return RecaptchaFactory::create()->verifyToken($request); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * @param EE_Form_Section_Proper $reg_form |
|
201 | - * @return void |
|
202 | - * @throws EE_Error |
|
203 | - * @throws InvalidArgumentException |
|
204 | - * @throws InvalidDataTypeException |
|
205 | - * @throws InvalidInterfaceException |
|
206 | - * @throws DomainException |
|
207 | - */ |
|
208 | - public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
209 | - { |
|
210 | - // do nothing if form isn't for a reg step or test has already been passed |
|
211 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
212 | - return; |
|
213 | - } |
|
214 | - $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
|
215 | - if ($default_hidden_inputs instanceof EE_Form_Section_Proper) { |
|
216 | - $invisible_recaptcha = RecaptchaFactory::create(); |
|
217 | - $invisible_recaptcha->addToFormSection($default_hidden_inputs); |
|
218 | - } |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * @param EE_Form_Section_Proper $reg_form |
|
224 | - * @return bool |
|
225 | - * @throws InvalidDataTypeException |
|
226 | - * @throws InvalidInterfaceException |
|
227 | - * @throws EE_Error |
|
228 | - * @throws InvalidArgumentException |
|
229 | - */ |
|
230 | - public static function processSpcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
231 | - { |
|
232 | - return strpos($reg_form->name(), 'reg-step-form') !== false |
|
233 | - && ! RecaptchaFactory::create()->recaptchaPassed(); |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * @param array|null $req_data |
|
239 | - * @param EE_Form_Section_Proper $reg_form |
|
240 | - * @return array |
|
241 | - * @throws EE_Error |
|
242 | - * @throws InvalidArgumentException |
|
243 | - * @throws InvalidDataTypeException |
|
244 | - * @throws InvalidInterfaceException |
|
245 | - * @throws RuntimeException |
|
246 | - */ |
|
247 | - public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
|
248 | - { |
|
249 | - // do nothing if form isn't for a reg step or test has already been passed |
|
250 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
251 | - return $req_data; |
|
252 | - } |
|
253 | - /** @var EE_Request $request */ |
|
254 | - $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
255 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
256 | - if ($request->isAjax()) { |
|
257 | - $json_response = new EE_SPCO_JSON_Response(); |
|
258 | - $json_response->echoAndExit(); |
|
259 | - } |
|
260 | - EEH_URL::safeRedirectAndExit( |
|
261 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
262 | - ); |
|
263 | - } |
|
264 | - return $req_data; |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * @param string $html |
|
270 | - * @param EE_Event $event |
|
271 | - * @param bool $iframe |
|
272 | - * @return string |
|
273 | - * @throws EE_Error |
|
274 | - * @throws InvalidArgumentException |
|
275 | - * @throws InvalidDataTypeException |
|
276 | - * @throws InvalidInterfaceException |
|
277 | - * @throws ReflectionException |
|
278 | - * @throws DomainException |
|
279 | - */ |
|
280 | - public static function ticketSelectorForm($html = '', EE_Event $event, $iframe = false) |
|
281 | - { |
|
282 | - $recaptcha = RecaptchaFactory::create(); |
|
283 | - // do nothing if test has already been passed |
|
284 | - if ($recaptcha->recaptchaPassed()) { |
|
285 | - return $html; |
|
286 | - } |
|
287 | - $html .= $recaptcha->getInputHtml( |
|
288 | - array( |
|
289 | - 'recaptcha_id' => $event->ID(), |
|
290 | - 'iframe' => $iframe, |
|
291 | - 'localized_vars' => $recaptcha->getLocalizedVars(), |
|
292 | - ) |
|
293 | - ); |
|
294 | - return $html; |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * @return void |
|
300 | - * @throws InvalidArgumentException |
|
301 | - * @throws InvalidInterfaceException |
|
302 | - * @throws InvalidDataTypeException |
|
303 | - * @throws RuntimeException |
|
304 | - */ |
|
305 | - public static function processTicketSelectorForm() |
|
306 | - { |
|
307 | - // do nothing if test has already been passed |
|
308 | - if (RecaptchaFactory::create()->recaptchaPassed()) { |
|
309 | - return; |
|
310 | - } |
|
311 | - /** @var EE_Request $request */ |
|
312 | - $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
313 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
314 | - $event_id = $request->get('tkt-slctr-event-id'); |
|
315 | - $return_url = $request->is_set("tkt-slctr-return-url-{$event_id}") |
|
316 | - ? $request->get("tkt-slctr-return-url-{$event_id}") |
|
317 | - : get_permalink($event_id); |
|
318 | - EEH_URL::safeRedirectAndExit($return_url); |
|
319 | - } |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * @throws EE_Error |
|
325 | - * @throws InvalidArgumentException |
|
326 | - * @throws InvalidDataTypeException |
|
327 | - * @throws InvalidInterfaceException |
|
328 | - */ |
|
329 | - public static function adminSettings() |
|
330 | - { |
|
331 | - RecaptchaFactory::getAdminModule()->adminSettings(); |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * @param EE_Registration_Config $EE_Registration_Config |
|
337 | - * @return EE_Registration_Config |
|
338 | - * @throws EE_Error |
|
339 | - * @throws InvalidArgumentException |
|
340 | - * @throws InvalidDataTypeException |
|
341 | - * @throws InvalidInterfaceException |
|
342 | - * @throws ReflectionException |
|
343 | - */ |
|
344 | - public static function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
345 | - { |
|
346 | - return RecaptchaFactory::getAdminModule()->updateAdminSettings($EE_Registration_Config); |
|
347 | - } |
|
20 | + /** |
|
21 | + * @var EE_Registration_Config $config |
|
22 | + */ |
|
23 | + private static $config; |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * @return EED_Module|EED_Recaptcha |
|
28 | + */ |
|
29 | + public static function instance() |
|
30 | + { |
|
31 | + return parent::get_instance(__CLASS__); |
|
32 | + } |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @return void |
|
37 | + * @throws InvalidInterfaceException |
|
38 | + * @throws InvalidDataTypeException |
|
39 | + * @throws InvalidArgumentException |
|
40 | + */ |
|
41 | + public static function set_hooks() |
|
42 | + { |
|
43 | + EED_Recaptcha_Invisible::setProperties(); |
|
44 | + if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) { |
|
45 | + if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
46 | + // ticket selection |
|
47 | + add_filter( |
|
48 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
49 | + array('EED_Recaptcha_Invisible', 'ticketSelectorForm'), |
|
50 | + 10, |
|
51 | + 3 |
|
52 | + ); |
|
53 | + add_action( |
|
54 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
55 | + array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
56 | + ); |
|
57 | + } |
|
58 | + if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
59 | + // checkout |
|
60 | + add_action( |
|
61 | + 'AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', |
|
62 | + array('EED_Recaptcha_Invisible', 'spcoRegStepForm') |
|
63 | + ); |
|
64 | + add_filter( |
|
65 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
66 | + array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
67 | + 10, |
|
68 | + 2 |
|
69 | + ); |
|
70 | + } |
|
71 | + add_action('loop_end', array('EED_Recaptcha_Invisible', 'localizeScriptVars')); |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @return void |
|
78 | + * @throws InvalidInterfaceException |
|
79 | + * @throws InvalidDataTypeException |
|
80 | + * @throws InvalidArgumentException |
|
81 | + */ |
|
82 | + public static function set_hooks_admin() |
|
83 | + { |
|
84 | + EED_Recaptcha_Invisible::setProperties(); |
|
85 | + if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
86 | + add_action( |
|
87 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
88 | + array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
89 | + ); |
|
90 | + } |
|
91 | + if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
92 | + add_filter( |
|
93 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
94 | + array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
95 | + 10, |
|
96 | + 2 |
|
97 | + ); |
|
98 | + } |
|
99 | + // admin settings |
|
100 | + add_action( |
|
101 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
102 | + array('EED_Recaptcha_Invisible', 'adminSettings') |
|
103 | + ); |
|
104 | + add_filter( |
|
105 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
106 | + array('EED_Recaptcha_Invisible', 'updateAdminSettings') |
|
107 | + ); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @return void |
|
113 | + * @throws InvalidInterfaceException |
|
114 | + * @throws InvalidDataTypeException |
|
115 | + * @throws InvalidArgumentException |
|
116 | + */ |
|
117 | + public static function setProperties() |
|
118 | + { |
|
119 | + |
|
120 | + EED_Recaptcha_Invisible::$config = EE_Registry::instance()->CFG->registration; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @return boolean |
|
126 | + */ |
|
127 | + public static function useInvisibleRecaptcha() |
|
128 | + { |
|
129 | + return EED_Recaptcha_Invisible::$config->use_captcha |
|
130 | + && EED_Recaptcha_Invisible::$config->recaptcha_theme === 'invisible'; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @param string $form |
|
136 | + * @return boolean |
|
137 | + */ |
|
138 | + public static function protectForm($form) |
|
139 | + { |
|
140 | + return is_array(EED_Recaptcha_Invisible::$config->recaptcha_protected_forms) |
|
141 | + && in_array($form, EED_Recaptcha_Invisible::$config->recaptcha_protected_forms, true); |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @return void |
|
147 | + * @throws InvalidInterfaceException |
|
148 | + * @throws InvalidDataTypeException |
|
149 | + * @throws InvalidArgumentException |
|
150 | + */ |
|
151 | + public static function localizeScriptVars() |
|
152 | + { |
|
153 | + /** @var \EventEspresso\core\services\request\Request $request */ |
|
154 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
155 | + // Invisible Recaptcha is ONLY ever required for the frontend and admin |
|
156 | + // so we don't need to load any JS assets for other types of requests (like AJAX or API). |
|
157 | + if (! ($request->isAdmin() || $request->isFrontend())) { |
|
158 | + return; |
|
159 | + } |
|
160 | + wp_localize_script( |
|
161 | + EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
162 | + 'eeRecaptcha', |
|
163 | + RecaptchaFactory::create()->getLocalizedVars() |
|
164 | + ); |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public static function assetsUrl() |
|
172 | + { |
|
173 | + return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * @param \WP $WP |
|
179 | + */ |
|
180 | + public function run($WP) |
|
181 | + { |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * @param EE_Request $request |
|
187 | + * @return bool |
|
188 | + * @throws InvalidArgumentException |
|
189 | + * @throws InvalidDataTypeException |
|
190 | + * @throws InvalidInterfaceException |
|
191 | + * @throws RuntimeException |
|
192 | + */ |
|
193 | + public static function verifyToken(EE_Request $request) |
|
194 | + { |
|
195 | + return RecaptchaFactory::create()->verifyToken($request); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * @param EE_Form_Section_Proper $reg_form |
|
201 | + * @return void |
|
202 | + * @throws EE_Error |
|
203 | + * @throws InvalidArgumentException |
|
204 | + * @throws InvalidDataTypeException |
|
205 | + * @throws InvalidInterfaceException |
|
206 | + * @throws DomainException |
|
207 | + */ |
|
208 | + public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
209 | + { |
|
210 | + // do nothing if form isn't for a reg step or test has already been passed |
|
211 | + if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
212 | + return; |
|
213 | + } |
|
214 | + $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
|
215 | + if ($default_hidden_inputs instanceof EE_Form_Section_Proper) { |
|
216 | + $invisible_recaptcha = RecaptchaFactory::create(); |
|
217 | + $invisible_recaptcha->addToFormSection($default_hidden_inputs); |
|
218 | + } |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * @param EE_Form_Section_Proper $reg_form |
|
224 | + * @return bool |
|
225 | + * @throws InvalidDataTypeException |
|
226 | + * @throws InvalidInterfaceException |
|
227 | + * @throws EE_Error |
|
228 | + * @throws InvalidArgumentException |
|
229 | + */ |
|
230 | + public static function processSpcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
231 | + { |
|
232 | + return strpos($reg_form->name(), 'reg-step-form') !== false |
|
233 | + && ! RecaptchaFactory::create()->recaptchaPassed(); |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * @param array|null $req_data |
|
239 | + * @param EE_Form_Section_Proper $reg_form |
|
240 | + * @return array |
|
241 | + * @throws EE_Error |
|
242 | + * @throws InvalidArgumentException |
|
243 | + * @throws InvalidDataTypeException |
|
244 | + * @throws InvalidInterfaceException |
|
245 | + * @throws RuntimeException |
|
246 | + */ |
|
247 | + public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
|
248 | + { |
|
249 | + // do nothing if form isn't for a reg step or test has already been passed |
|
250 | + if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
251 | + return $req_data; |
|
252 | + } |
|
253 | + /** @var EE_Request $request */ |
|
254 | + $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
255 | + if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
256 | + if ($request->isAjax()) { |
|
257 | + $json_response = new EE_SPCO_JSON_Response(); |
|
258 | + $json_response->echoAndExit(); |
|
259 | + } |
|
260 | + EEH_URL::safeRedirectAndExit( |
|
261 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
262 | + ); |
|
263 | + } |
|
264 | + return $req_data; |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * @param string $html |
|
270 | + * @param EE_Event $event |
|
271 | + * @param bool $iframe |
|
272 | + * @return string |
|
273 | + * @throws EE_Error |
|
274 | + * @throws InvalidArgumentException |
|
275 | + * @throws InvalidDataTypeException |
|
276 | + * @throws InvalidInterfaceException |
|
277 | + * @throws ReflectionException |
|
278 | + * @throws DomainException |
|
279 | + */ |
|
280 | + public static function ticketSelectorForm($html = '', EE_Event $event, $iframe = false) |
|
281 | + { |
|
282 | + $recaptcha = RecaptchaFactory::create(); |
|
283 | + // do nothing if test has already been passed |
|
284 | + if ($recaptcha->recaptchaPassed()) { |
|
285 | + return $html; |
|
286 | + } |
|
287 | + $html .= $recaptcha->getInputHtml( |
|
288 | + array( |
|
289 | + 'recaptcha_id' => $event->ID(), |
|
290 | + 'iframe' => $iframe, |
|
291 | + 'localized_vars' => $recaptcha->getLocalizedVars(), |
|
292 | + ) |
|
293 | + ); |
|
294 | + return $html; |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * @return void |
|
300 | + * @throws InvalidArgumentException |
|
301 | + * @throws InvalidInterfaceException |
|
302 | + * @throws InvalidDataTypeException |
|
303 | + * @throws RuntimeException |
|
304 | + */ |
|
305 | + public static function processTicketSelectorForm() |
|
306 | + { |
|
307 | + // do nothing if test has already been passed |
|
308 | + if (RecaptchaFactory::create()->recaptchaPassed()) { |
|
309 | + return; |
|
310 | + } |
|
311 | + /** @var EE_Request $request */ |
|
312 | + $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
|
313 | + if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
314 | + $event_id = $request->get('tkt-slctr-event-id'); |
|
315 | + $return_url = $request->is_set("tkt-slctr-return-url-{$event_id}") |
|
316 | + ? $request->get("tkt-slctr-return-url-{$event_id}") |
|
317 | + : get_permalink($event_id); |
|
318 | + EEH_URL::safeRedirectAndExit($return_url); |
|
319 | + } |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * @throws EE_Error |
|
325 | + * @throws InvalidArgumentException |
|
326 | + * @throws InvalidDataTypeException |
|
327 | + * @throws InvalidInterfaceException |
|
328 | + */ |
|
329 | + public static function adminSettings() |
|
330 | + { |
|
331 | + RecaptchaFactory::getAdminModule()->adminSettings(); |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * @param EE_Registration_Config $EE_Registration_Config |
|
337 | + * @return EE_Registration_Config |
|
338 | + * @throws EE_Error |
|
339 | + * @throws InvalidArgumentException |
|
340 | + * @throws InvalidDataTypeException |
|
341 | + * @throws InvalidInterfaceException |
|
342 | + * @throws ReflectionException |
|
343 | + */ |
|
344 | + public static function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
345 | + { |
|
346 | + return RecaptchaFactory::getAdminModule()->updateAdminSettings($EE_Registration_Config); |
|
347 | + } |
|
348 | 348 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
155 | 155 | // Invisible Recaptcha is ONLY ever required for the frontend and admin |
156 | 156 | // so we don't need to load any JS assets for other types of requests (like AJAX or API). |
157 | - if (! ($request->isAdmin() || $request->isFrontend())) { |
|
157 | + if ( ! ($request->isAdmin() || $request->isFrontend())) { |
|
158 | 158 | return; |
159 | 159 | } |
160 | 160 | wp_localize_script( |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | */ |
171 | 171 | public static function assetsUrl() |
172 | 172 | { |
173 | - return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
173 | + return plugin_dir_url(__FILE__).'assets'.DS; |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
209 | 209 | { |
210 | 210 | // do nothing if form isn't for a reg step or test has already been passed |
211 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
211 | + if ( ! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
212 | 212 | return; |
213 | 213 | } |
214 | 214 | $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
@@ -247,12 +247,12 @@ discard block |
||
247 | 247 | public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
248 | 248 | { |
249 | 249 | // do nothing if form isn't for a reg step or test has already been passed |
250 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
250 | + if ( ! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
251 | 251 | return $req_data; |
252 | 252 | } |
253 | 253 | /** @var EE_Request $request */ |
254 | 254 | $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
255 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
255 | + if ( ! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
256 | 256 | if ($request->isAjax()) { |
257 | 257 | $json_response = new EE_SPCO_JSON_Response(); |
258 | 258 | $json_response->echoAndExit(); |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | } |
311 | 311 | /** @var EE_Request $request */ |
312 | 312 | $request = LoaderFactory::getLoader()->getShared('EE_Request'); |
313 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
313 | + if ( ! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
314 | 314 | $event_id = $request->get('tkt-slctr-event-id'); |
315 | 315 | $return_url = $request->is_set("tkt-slctr-return-url-{$event_id}") |
316 | 316 | ? $request->get("tkt-slctr-return-url-{$event_id}") |