Completed
Branch BUG-10626-dst-unit-test (cc62a6)
by
unknown
37:15 queued 23:58
created
core/EE_Session.core.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 	  * set session data
434 434
 	  * @access 	public
435 435
 	  * @param 	array $data
436
-	  * @return 	TRUE on success, FALSE on fail
436
+	  * @return 	boolean on success, FALSE on fail
437 437
 	  */
438 438
 	public function set_session_data( $data ) {
439 439
 
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 	 /**
462 462
 	  * @initiate session
463 463
 	  * @access   private
464
-	  * @return TRUE on success, FALSE on fail
464
+	  * @return boolean on success, FALSE on fail
465 465
 	  * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
466 466
 	  * @throws \EE_Error
467 467
 	  */
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
       * @update session data  prior to saving to the db
682 682
       * @access public
683 683
       * @param bool $new_session
684
-      * @return TRUE on success, FALSE on fail
684
+      * @return boolean on success, FALSE on fail
685 685
       * @throws \EE_Error
686 686
       */
687 687
 	public function update( $new_session = FALSE ) {
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
 	  * _save_session_to_db
788 788
 	  *
789 789
 	  * @access public
790
-	  * @return string
790
+	  * @return boolean
791 791
 	  * @throws \EE_Error
792 792
 	  */
793 793
 	private function _save_session_to_db() {
@@ -959,7 +959,7 @@  discard block
 block discarded – undo
959 959
 	  * @access public
960 960
 	  * @param array $data_to_reset
961 961
 	  * @param bool  $show_all_notices
962
-	  * @return TRUE on success, FALSE on fail
962
+	  * @return boolean on success, FALSE on fail
963 963
 	  */
964 964
 	public function reset_data( $data_to_reset = array(), $show_all_notices = FALSE ) {
965 965
 		// if $data_to_reset is not in an array, then put it in one
Please login to merge, or discard this patch.
Indentation   +293 added lines, -293 removed lines patch added patch discarded remove patch
@@ -22,19 +22,19 @@  discard block
 block discarded – undo
22 22
 	  */
23 23
 	 private static $_instance;
24 24
 
25
-     /**
26
-      * @var CacheStorageInterface $cache_storage
27
-      */
28
-     protected $cache_storage;
29
-
30
-     /**
31
-      * EE_Encryption object
32
-      *
33
-      * @var EE_Encryption
34
-      */
35
-     protected $encryption;
36
-
37
-     /**
25
+	 /**
26
+	  * @var CacheStorageInterface $cache_storage
27
+	  */
28
+	 protected $cache_storage;
29
+
30
+	 /**
31
+	  * EE_Encryption object
32
+	  *
33
+	  * @var EE_Encryption
34
+	  */
35
+	 protected $encryption;
36
+
37
+	 /**
38 38
 	  * the session id
39 39
 	  * @var string
40 40
 	  */
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
 	  */
66 66
 	 private $_expiration;
67 67
 
68
-    /**
69
-     * whether or not session has expired at some point
70
-     *
71
-     * @var boolean
72
-     */
73
-    private $_expired = false;
68
+	/**
69
+	 * whether or not session has expired at some point
70
+	 *
71
+	 * @var boolean
72
+	 */
73
+	private $_expired = false;
74 74
 
75 75
 	 /**
76 76
 	  * current time as Unix timestamp in GMT
@@ -107,30 +107,30 @@  discard block
 block discarded – undo
107 107
 	  * @var array
108 108
 	  */
109 109
 	 private $_default_session_vars = array (
110
-        'id'            => null,
111
-        'user_id'       => null,
112
-        'ip_address'    => null,
113
-        'user_agent'    => null,
114
-        'init_access'   => null,
115
-        'last_access'   => null,
116
-        'expiration'    => null,
117
-        'pages_visited' => array(),
110
+		'id'            => null,
111
+		'user_id'       => null,
112
+		'ip_address'    => null,
113
+		'user_agent'    => null,
114
+		'init_access'   => null,
115
+		'last_access'   => null,
116
+		'expiration'    => null,
117
+		'pages_visited' => array(),
118 118
 	);
119 119
 
120 120
 
121 121
 
122 122
 	 /**
123 123
 	  * @singleton method used to instantiate class object
124
-      * @param CacheStorageInterface $cache_storage
125
-      * @param \EE_Encryption        $encryption
124
+	  * @param CacheStorageInterface $cache_storage
125
+	  * @param \EE_Encryption        $encryption
126 126
 	  * @return EE_Session
127 127
 	  * @throws InvalidSessionDataException
128 128
 	  * @throws \EE_Error
129 129
 	  */
130 130
 	public static function instance(
131
-        CacheStorageInterface $cache_storage = null,
132
-        EE_Encryption $encryption = null
133
-    ) {
131
+		CacheStorageInterface $cache_storage = null,
132
+		EE_Encryption $encryption = null
133
+	) {
134 134
 		// check if class object is instantiated
135 135
 		// session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
136 136
 		// add_filter( 'FHEE_load_EE_Session', '__return_false' );
@@ -143,10 +143,10 @@  discard block
 block discarded – undo
143 143
 
144 144
 
145 145
 	 /**
146
-      * protected constructor to prevent direct creation
147
-      *
148
-      * @param CacheStorageInterface $cache_storage
149
-      * @param \EE_Encryption $encryption
146
+	  * protected constructor to prevent direct creation
147
+	  *
148
+	  * @param CacheStorageInterface $cache_storage
149
+	  * @param \EE_Encryption $encryption
150 150
 	  * @throws \EE_Error
151 151
 	  * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
152 152
 	  */
@@ -181,59 +181,59 @@  discard block
 block discarded – undo
181 181
 				$this->{$var_name} = $session_setting;
182 182
 			}
183 183
 		}
184
-         $this->cache_storage = $cache_storage;
185
-         // are we using encryption?
186
-         $this->_use_encryption = $encryption instanceof EE_Encryption && EE_Registry::instance()->CFG->admin->encode_session_data();
187
-         // \EEH_Debug_Tools::printr($this->_use_encryption, '$this->_use_encryption', __FILE__, __LINE__);
188
-        // encrypt data via: $this->encryption->encrypt();
189
-        $this->encryption = $encryption;
184
+		 $this->cache_storage = $cache_storage;
185
+		 // are we using encryption?
186
+		 $this->_use_encryption = $encryption instanceof EE_Encryption && EE_Registry::instance()->CFG->admin->encode_session_data();
187
+		 // \EEH_Debug_Tools::printr($this->_use_encryption, '$this->_use_encryption', __FILE__, __LINE__);
188
+		// encrypt data via: $this->encryption->encrypt();
189
+		$this->encryption = $encryption;
190 190
 		// filter hook allows outside functions/classes/plugins to change default empty cart
191 191
 		$extra_default_session_vars = apply_filters( 'FHEE__EE_Session__construct__extra_default_session_vars', array() );
192 192
 		array_merge( $this->_default_session_vars, $extra_default_session_vars );
193 193
 		// apply default session vars
194 194
 		$this->_set_defaults();
195
-         add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
196
-         // check request for 'clear_session' param
195
+		 add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
196
+		 // check request for 'clear_session' param
197 197
 		add_action( 'AHEE__EE_Request_Handler__construct__complete', array( $this, 'wp_loaded' ));
198 198
 		// once everything is all said and done,
199 199
 		add_action( 'shutdown', array( $this, 'update' ), 100 );
200
-         $this->configure_garbage_collection_filters();
200
+		 $this->configure_garbage_collection_filters();
201 201
 	}
202 202
 
203 203
 
204 204
 
205
-     /**
206
-      * @return void
207
-      * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
208
-      * @throws \EE_Error
209
-      */
205
+	 /**
206
+	  * @return void
207
+	  * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
208
+	  * @throws \EE_Error
209
+	  */
210 210
 	 public function open_session() {
211
-         // check for existing session and retrieve it from db
212
-         if ( ! $this->_espresso_session()) {
213
-             // or just start a new one
214
-             $this->_create_espresso_session();
215
-         }
216
-     }
211
+		 // check for existing session and retrieve it from db
212
+		 if ( ! $this->_espresso_session()) {
213
+			 // or just start a new one
214
+			 $this->_create_espresso_session();
215
+		 }
216
+	 }
217 217
 
218 218
 
219 219
 
220
-    /**
221
-     * @return bool
222
-     */
223
-    public function expired()
224
-    {
225
-        return $this->_expired;
226
-    }
220
+	/**
221
+	 * @return bool
222
+	 */
223
+	public function expired()
224
+	{
225
+		return $this->_expired;
226
+	}
227 227
 
228 228
 
229 229
 
230
-    /**
231
-     * @return void
232
-     */
233
-    public function reset_expired()
234
-    {
235
-        $this->_expired = false;
236
-    }
230
+	/**
231
+	 * @return void
232
+	 */
233
+	public function reset_expired()
234
+	{
235
+		$this->_expired = false;
236
+	}
237 237
 
238 238
 
239 239
 	 /**
@@ -245,24 +245,24 @@  discard block
 block discarded – undo
245 245
 
246 246
 
247 247
 
248
-    /**
249
-     * @return int
250
-     */
251
-    public function extension()
252
-    {
253
-        return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', (10 * MINUTE_IN_SECONDS));
254
-    }
248
+	/**
249
+	 * @return int
250
+	 */
251
+	public function extension()
252
+	{
253
+		return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', (10 * MINUTE_IN_SECONDS));
254
+	}
255 255
 
256 256
 
257 257
 
258
-    /**
259
-     * @param int $time number of seconds to add to session expiration
260
-     */
261
-    public function extend_expiration($time = 0)
262
-    {
263
-        $time = $time ? $time : $this->extension();
264
-        $this->_expiration += absint($time);
265
-    }
258
+	/**
259
+	 * @param int $time number of seconds to add to session expiration
260
+	 */
261
+	public function extend_expiration($time = 0)
262
+	{
263
+		$time = $time ? $time : $this->extension();
264
+		$this->_expiration += absint($time);
265
+	}
266 266
 
267 267
 
268 268
 
@@ -306,15 +306,15 @@  discard block
 block discarded – undo
306 306
 
307 307
 
308 308
 
309
-    /**
310
-     * @param \EE_Cart $cart
311
-     * @return bool
312
-     */
313
-    public function set_cart(EE_Cart $cart)
314
-    {
315
-        $this->_session_data['cart'] = $cart;
316
-        return true;
317
-    }
309
+	/**
310
+	 * @param \EE_Cart $cart
311
+	 * @return bool
312
+	 */
313
+	public function set_cart(EE_Cart $cart)
314
+	{
315
+		$this->_session_data['cart'] = $cart;
316
+		return true;
317
+	}
318 318
 
319 319
 
320 320
 
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	  * reset_cart
323 323
 	  */
324 324
 	 public function reset_cart() {
325
-        do_action('AHEE__EE_Session__reset_cart__before_reset', $this);
325
+		do_action('AHEE__EE_Session__reset_cart__before_reset', $this);
326 326
 		 $this->_session_data['cart'] = NULL;
327 327
 	 }
328 328
 
@@ -332,9 +332,9 @@  discard block
 block discarded – undo
332 332
 	  * @return \EE_Cart
333 333
 	  */
334 334
 	 public function cart() {
335
-        return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart
336
-            ? $this->_session_data['cart']
337
-            : null;
335
+		return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart
336
+			? $this->_session_data['cart']
337
+			: null;
338 338
 	 }
339 339
 
340 340
 
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
 	  * reset_checkout
355 355
 	  */
356 356
 	 public function reset_checkout() {
357
-        do_action('AHEE__EE_Session__reset_checkout__before_reset', $this);
357
+		do_action('AHEE__EE_Session__reset_checkout__before_reset', $this);
358 358
 		 $this->_session_data['checkout'] = NULL;
359 359
 	 }
360 360
 
@@ -364,9 +364,9 @@  discard block
 block discarded – undo
364 364
 	  * @return \EE_Checkout
365 365
 	  */
366 366
 	 public function checkout() {
367
-        return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout
368
-            ? $this->_session_data['checkout']
369
-            : null;
367
+		return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout
368
+			? $this->_session_data['checkout']
369
+			: null;
370 370
 	 }
371 371
 
372 372
 
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
 	  * reset_transaction
390 390
 	  */
391 391
 	 public function reset_transaction() {
392
-        do_action('AHEE__EE_Session__reset_transaction__before_reset', $this);
392
+		do_action('AHEE__EE_Session__reset_transaction__before_reset', $this);
393 393
 		 $this->_session_data['transaction'] = NULL;
394 394
 	 }
395 395
 
@@ -399,10 +399,10 @@  discard block
 block discarded – undo
399 399
 	  * @return \EE_Transaction
400 400
 	  */
401 401
 	 public function transaction() {
402
-        return isset($this->_session_data['transaction'])
403
-               && $this->_session_data['transaction'] instanceof EE_Transaction
404
-           ? $this->_session_data['transaction']
405
-           : null;
402
+		return isset($this->_session_data['transaction'])
403
+			   && $this->_session_data['transaction'] instanceof EE_Transaction
404
+		   ? $this->_session_data['transaction']
405
+		   : null;
406 406
 	 }
407 407
 
408 408
 
@@ -479,16 +479,16 @@  discard block
 block discarded – undo
479 479
 		// set the "user agent"
480 480
 		$this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr( $_SERVER['HTTP_USER_AGENT'] ) : FALSE;
481 481
 		// now let's retrieve what's in the db
482
-        $session_data = $this->_retrieve_session_data();
483
-        if (! empty($session_data)) {
484
-            // get the current time in UTC
482
+		$session_data = $this->_retrieve_session_data();
483
+		if (! empty($session_data)) {
484
+			// get the current time in UTC
485 485
 			$this->_time = isset( $this->_time ) ? $this->_time : time();
486 486
 			// and reset the session expiration
487 487
 			$this->_expiration = isset( $session_data['expiration'] )
488 488
 				? $session_data['expiration']
489 489
 				: $this->_time + $this->_lifespan;
490 490
 		} else {
491
-            // set initial site access time and the session expiration
491
+			// set initial site access time and the session expiration
492 492
 			$this->_set_init_access_and_expiration();
493 493
 			// set referer
494 494
 			$this->_session_data[ 'pages_visited' ][ $this->_session_data['init_access'] ] = isset( $_SERVER['HTTP_REFERER'] )
@@ -497,14 +497,14 @@  discard block
 block discarded – undo
497 497
 			// no previous session = go back and create one (on top of the data above)
498 498
 			return FALSE;
499 499
 		}
500
-        // now the user agent
500
+		// now the user agent
501 501
 		if ( $session_data['user_agent'] !== $this->_user_agent ) {
502 502
 			return FALSE;
503 503
 		}
504 504
 		// wait a minute... how old are you?
505 505
 		if ( $this->_time > $this->_expiration ) {
506 506
 			// yer too old fer me!
507
-            $this->_expired = true;
507
+			$this->_expired = true;
508 508
 			// wipe out everything that isn't a default session datum
509 509
 			$this->clear_session( __CLASS__, __FUNCTION__ );
510 510
 		}
@@ -516,101 +516,101 @@  discard block
 block discarded – undo
516 516
 
517 517
 
518 518
 
519
-     /**
520
-      * _get_session_data
521
-      * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup databases
522
-      *
523
-      * @return array
524
-      * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
525
-      */
526
-     protected function _retrieve_session_data()
527
-     {
528
-         $ssn_key = EE_Session::session_id_prefix . $this->_sid;
529
-         try {
530
-             // we're using WP's Transient API to store session data using the PHP session ID as the option name
531
-             $session_data = $this->cache_storage->get($ssn_key, false);
532
-	         if (empty($session_data)) {
533
-		         return array();
534
-             }
535
-             if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
536
-                 $hash_check = $this->cache_storage->get(
537
-                     EE_Session::hash_check_prefix . $this->_sid,
538
-                     false
539
-                 );
540
-                 if ($hash_check && $hash_check !== md5($session_data)) {
541
-	                 EE_Error::add_error(
542
-                         sprintf(
543
-                             __(
544
-                                 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
545
-                                 'event_espresso'
546
-                             ),
547
-                             EE_Session::session_id_prefix . $this->_sid
548
-                         ),
549
-                         __FILE__, __FUNCTION__, __LINE__
550
-                     );
551
-                 }
552
-             }
553
-         } catch (Exception $e) {
554
-             // let's just eat that error for now and attempt to correct any corrupted data
555
-             global $wpdb;
556
-             $row = $wpdb->get_row(
557
-                 $wpdb->prepare(
558
-                     "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
559
-                     '_transient_' . $ssn_key
560
-                 )
561
-             );
562
-             $session_data = is_object($row) ? $row->option_value : null;
563
-             if ($session_data) {
564
-                 $session_data = preg_replace_callback(
565
-                     '!s:(d+):"(.*?)";!',
566
-                     function ($match) {
567
-                         return $match[1] === strlen($match[2])
568
-                             ? $match[0]
569
-                             : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
570
-                     },
571
-                     $session_data
572
-                 );
573
-             }
574
-	         $session_data = maybe_unserialize($session_data);
575
-         }
576
-	     // in case the data is encoded... try to decode it
577
-         $session_data = $this->encryption instanceof EE_Encryption
578
-             ? $this->encryption->base64_string_decode($session_data)
579
-             : $session_data;
580
-
581
-         if ( ! is_array($session_data)) {
582
-             try {
583
-	             $session_data = maybe_unserialize($session_data);
584
-             } catch (Exception $e) {
585
-                 $msg = esc_html__(
586
-                     'An error occurred while attempting to unserialize the session data.',
587
-                     'event_espresso'
588
-                 );
589
-                 $msg .= WP_DEBUG
590
-                     ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
591
-                     : '';
592
-                 throw new InvalidSessionDataException($msg, 0, $e);
593
-             }
594
-         }
595
-         // just a check to make sure the session array is indeed an array
596
-         if ( ! is_array($session_data)) {
597
-             // no?!?! then something is wrong
598
-             $msg = esc_html__(
599
-                 'The session data is missing, invalid, or corrupted.',
600
-                 'event_espresso'
601
-             );
602
-             $msg .= WP_DEBUG
603
-                 ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
604
-                 : '';
605
-	         throw new InvalidSessionDataException($msg);
606
-         }
607
-	     if ( isset($session_data['transaction'] ) && absint($session_data['transaction'] ) !== 0 ) {
608
-             $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
609
-                 $session_data['transaction']
610
-	         );
611
-	     }
612
-         return $session_data;
613
-     }
519
+	 /**
520
+	  * _get_session_data
521
+	  * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup databases
522
+	  *
523
+	  * @return array
524
+	  * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
525
+	  */
526
+	 protected function _retrieve_session_data()
527
+	 {
528
+		 $ssn_key = EE_Session::session_id_prefix . $this->_sid;
529
+		 try {
530
+			 // we're using WP's Transient API to store session data using the PHP session ID as the option name
531
+			 $session_data = $this->cache_storage->get($ssn_key, false);
532
+			 if (empty($session_data)) {
533
+				 return array();
534
+			 }
535
+			 if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
536
+				 $hash_check = $this->cache_storage->get(
537
+					 EE_Session::hash_check_prefix . $this->_sid,
538
+					 false
539
+				 );
540
+				 if ($hash_check && $hash_check !== md5($session_data)) {
541
+					 EE_Error::add_error(
542
+						 sprintf(
543
+							 __(
544
+								 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
545
+								 'event_espresso'
546
+							 ),
547
+							 EE_Session::session_id_prefix . $this->_sid
548
+						 ),
549
+						 __FILE__, __FUNCTION__, __LINE__
550
+					 );
551
+				 }
552
+			 }
553
+		 } catch (Exception $e) {
554
+			 // let's just eat that error for now and attempt to correct any corrupted data
555
+			 global $wpdb;
556
+			 $row = $wpdb->get_row(
557
+				 $wpdb->prepare(
558
+					 "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
559
+					 '_transient_' . $ssn_key
560
+				 )
561
+			 );
562
+			 $session_data = is_object($row) ? $row->option_value : null;
563
+			 if ($session_data) {
564
+				 $session_data = preg_replace_callback(
565
+					 '!s:(d+):"(.*?)";!',
566
+					 function ($match) {
567
+						 return $match[1] === strlen($match[2])
568
+							 ? $match[0]
569
+							 : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
570
+					 },
571
+					 $session_data
572
+				 );
573
+			 }
574
+			 $session_data = maybe_unserialize($session_data);
575
+		 }
576
+		 // in case the data is encoded... try to decode it
577
+		 $session_data = $this->encryption instanceof EE_Encryption
578
+			 ? $this->encryption->base64_string_decode($session_data)
579
+			 : $session_data;
580
+
581
+		 if ( ! is_array($session_data)) {
582
+			 try {
583
+				 $session_data = maybe_unserialize($session_data);
584
+			 } catch (Exception $e) {
585
+				 $msg = esc_html__(
586
+					 'An error occurred while attempting to unserialize the session data.',
587
+					 'event_espresso'
588
+				 );
589
+				 $msg .= WP_DEBUG
590
+					 ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
591
+					 : '';
592
+				 throw new InvalidSessionDataException($msg, 0, $e);
593
+			 }
594
+		 }
595
+		 // just a check to make sure the session array is indeed an array
596
+		 if ( ! is_array($session_data)) {
597
+			 // no?!?! then something is wrong
598
+			 $msg = esc_html__(
599
+				 'The session data is missing, invalid, or corrupted.',
600
+				 'event_espresso'
601
+			 );
602
+			 $msg .= WP_DEBUG
603
+				 ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
604
+				 : '';
605
+			 throw new InvalidSessionDataException($msg);
606
+		 }
607
+		 if ( isset($session_data['transaction'] ) && absint($session_data['transaction'] ) !== 0 ) {
608
+			 $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
609
+				 $session_data['transaction']
610
+			 );
611
+		 }
612
+		 return $session_data;
613
+	 }
614 614
 
615 615
 
616 616
 
@@ -677,13 +677,13 @@  discard block
 block discarded – undo
677 677
 
678 678
 
679 679
 
680
-     /**
681
-      * @update session data  prior to saving to the db
682
-      * @access public
683
-      * @param bool $new_session
684
-      * @return TRUE on success, FALSE on fail
685
-      * @throws \EE_Error
686
-      */
680
+	 /**
681
+	  * @update session data  prior to saving to the db
682
+	  * @access public
683
+	  * @param bool $new_session
684
+	  * @return TRUE on success, FALSE on fail
685
+	  * @throws \EE_Error
686
+	  */
687 687
 	public function update( $new_session = FALSE ) {
688 688
 		$this->_session_data = isset( $this->_session_data )
689 689
 			&& is_array( $this->_session_data )
@@ -769,12 +769,12 @@  discard block
 block discarded – undo
769 769
 
770 770
 
771 771
 
772
-     /**
773
-      * @create session data array
774
-      * @access public
775
-      * @return bool
776
-      * @throws \EE_Error
777
-      */
772
+	 /**
773
+	  * @create session data array
774
+	  * @access public
775
+	  * @return bool
776
+	  * @throws \EE_Error
777
+	  */
778 778
 	private function _create_espresso_session( ) {
779 779
 		do_action( 'AHEE_log', __CLASS__, __FUNCTION__, '' );
780 780
 		// use the update function for now with $new_session arg set to TRUE
@@ -794,19 +794,19 @@  discard block
 block discarded – undo
794 794
 		if (
795 795
 			// if the current request is NOT one of the following
796 796
 			! (
797
-                // an an AJAX request from the frontend
798
-                EE_Registry::instance()->REQ->front_ajax
799
-                || (
800
-                    // OR an admin request that is NOT AJAX
797
+				// an an AJAX request from the frontend
798
+				EE_Registry::instance()->REQ->front_ajax
799
+				|| (
800
+					// OR an admin request that is NOT AJAX
801 801
 					! ( defined( 'DOING_AJAX' ) && DOING_AJAX )
802
-                    && is_admin()
802
+					&& is_admin()
803 803
 				)
804
-                || (
805
-                    // OR an espresso page
806
-                    EE_Registry::instance()->REQ instanceof EE_Request_Handler
807
-                    && EE_Registry::instance()->REQ->is_espresso_page()
808
-                )
809
-            )
804
+				|| (
805
+					// OR an espresso page
806
+					EE_Registry::instance()->REQ instanceof EE_Request_Handler
807
+					&& EE_Registry::instance()->REQ->is_espresso_page()
808
+				)
809
+			)
810 810
 		) {
811 811
 			return false;
812 812
 		}
@@ -817,27 +817,27 @@  discard block
 block discarded – undo
817 817
 			}
818 818
 			$this->_session_data['transaction'] = $transaction->ID();
819 819
 		}
820
-        // then serialize all of our session data
820
+		// then serialize all of our session data
821 821
 		$session_data = serialize($this->_session_data);
822 822
 		// do we need to also encode it to avoid corrupted data when saved to the db?
823 823
 		$session_data = $this->_use_encryption
824
-            ? $this->encryption->base64_string_encode( $session_data )
825
-            : $session_data;
824
+			? $this->encryption->base64_string_encode( $session_data )
825
+			: $session_data;
826 826
 		// maybe save hash check
827 827
 		if ( apply_filters( 'FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG ) ) {
828
-            $this->cache_storage->add(
829
-                EE_Session::hash_check_prefix . $this->_sid,
830
-                md5($session_data),
831
-                $this->_lifespan
832
-            );
833
-        }
834
-        // we're using the Transient API for storing session data,
835
-        return $this->cache_storage->add(
836
-            EE_Session::session_id_prefix . $this->_sid,
837
-            $session_data,
838
-            $this->_lifespan
839
-        );
840
-    }
828
+			$this->cache_storage->add(
829
+				EE_Session::hash_check_prefix . $this->_sid,
830
+				md5($session_data),
831
+				$this->_lifespan
832
+			);
833
+		}
834
+		// we're using the Transient API for storing session data,
835
+		return $this->cache_storage->add(
836
+			EE_Session::session_id_prefix . $this->_sid,
837
+			$session_data,
838
+			$this->_lifespan
839
+		);
840
+	}
841 841
 
842 842
 
843 843
 
@@ -930,18 +930,18 @@  discard block
 block discarded – undo
930 930
 
931 931
 
932 932
 
933
-     /**
934
-      * Clear EE_Session data
935
-      *
936
-      * @access public
937
-      * @param string $class
938
-      * @param string $function
939
-      * @return void
940
-      * @throws \EE_Error
941
-      */
933
+	 /**
934
+	  * Clear EE_Session data
935
+	  *
936
+	  * @access public
937
+	  * @param string $class
938
+	  * @param string $function
939
+	  * @return void
940
+	  * @throws \EE_Error
941
+	  */
942 942
 	public function clear_session( $class = '', $function = '' ) {
943 943
 		//echo '<h3 style="color:#999;line-height:.9em;"><span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/><span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b></h3>';
944
-        do_action( 'AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' .  $function . '()' );
944
+		do_action( 'AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' .  $function . '()' );
945 945
 		$this->reset_cart();
946 946
 		$this->reset_checkout();
947 947
 		$this->reset_transaction();
@@ -1008,12 +1008,12 @@  discard block
 block discarded – undo
1008 1008
 
1009 1009
 
1010 1010
 
1011
-     /**
1012
-      *   wp_loaded
1013
-      *
1014
-      * @access public
1015
-      * @throws \EE_Error
1016
-      */
1011
+	 /**
1012
+	  *   wp_loaded
1013
+	  *
1014
+	  * @access public
1015
+	  * @throws \EE_Error
1016
+	  */
1017 1017
 	public function wp_loaded() {
1018 1018
 		if ( isset(  EE_Registry::instance()->REQ ) && EE_Registry::instance()->REQ->is_set( 'clear_session' )) {
1019 1019
 			$this->clear_session( __CLASS__, __FUNCTION__ );
@@ -1022,12 +1022,12 @@  discard block
 block discarded – undo
1022 1022
 
1023 1023
 
1024 1024
 
1025
-     /**
1026
-      * Used to reset the entire object (for tests).
1027
-      *
1028
-      * @since 4.3.0
1029
-      * @throws \EE_Error
1030
-      */
1025
+	 /**
1026
+	  * Used to reset the entire object (for tests).
1027
+	  *
1028
+	  * @since 4.3.0
1029
+	  * @throws \EE_Error
1030
+	  */
1031 1031
 	public function reset_instance() {
1032 1032
 		$this->clear_session();
1033 1033
 		self::$_instance = NULL;
@@ -1035,29 +1035,29 @@  discard block
 block discarded – undo
1035 1035
 
1036 1036
 
1037 1037
 
1038
-     public function configure_garbage_collection_filters()
1039
-     {
1040
-         // run old filter we had for controlling session cleanup
1041
-         $expired_session_transient_delete_query_limit = absint(
1042
-             apply_filters(
1043
-                 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1044
-                 50
1045
-             )
1046
-         );
1047
-         // is there a value? or one that is different than the default 50 records?
1048
-         if ($expired_session_transient_delete_query_limit === 0) {
1049
-             // hook into TransientCacheStorage in case Session cleanup was turned off
1050
-             add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero');
1051
-         } else if ($expired_session_transient_delete_query_limit !== 50) {
1052
-             // or use that for the new transient cleanup query limit
1053
-             add_filter(
1054
-                 'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1055
-                 function () use ($expired_session_transient_delete_query_limit) {
1056
-                     return $expired_session_transient_delete_query_limit;
1057
-                 }
1058
-             );
1059
-         }
1060
-     }
1038
+	 public function configure_garbage_collection_filters()
1039
+	 {
1040
+		 // run old filter we had for controlling session cleanup
1041
+		 $expired_session_transient_delete_query_limit = absint(
1042
+			 apply_filters(
1043
+				 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1044
+				 50
1045
+			 )
1046
+		 );
1047
+		 // is there a value? or one that is different than the default 50 records?
1048
+		 if ($expired_session_transient_delete_query_limit === 0) {
1049
+			 // hook into TransientCacheStorage in case Session cleanup was turned off
1050
+			 add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero');
1051
+		 } else if ($expired_session_transient_delete_query_limit !== 50) {
1052
+			 // or use that for the new transient cleanup query limit
1053
+			 add_filter(
1054
+				 'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1055
+				 function () use ($expired_session_transient_delete_query_limit) {
1056
+					 return $expired_session_transient_delete_query_limit;
1057
+				 }
1058
+			 );
1059
+		 }
1060
+	 }
1061 1061
 
1062 1062
 
1063 1063
 
Please login to merge, or discard this patch.
Spacing   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\exceptions\InvalidSessionDataException;
3 3
 use EventEspresso\core\services\cache\CacheStorageInterface;
4 4
 
5
-if (!defined( 'EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');}
5
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); }
6 6
 /**
7 7
  *
8 8
  * EE_Session class
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 	  * array for defining default session vars
109 109
 	  * @var array
110 110
 	  */
111
-	 private $_default_session_vars = array (
111
+	 private $_default_session_vars = array(
112 112
         'id'            => null,
113 113
         'user_id'       => null,
114 114
         'ip_address'    => null,
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
 		// check if class object is instantiated
137 137
 		// session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
138 138
 		// add_filter( 'FHEE_load_EE_Session', '__return_false' );
139
-		if ( ! self::$_instance instanceof EE_Session && apply_filters( 'FHEE_load_EE_Session', true ) ) {
140
-			self::$_instance = new self($cache_storage, $encryption );
139
+		if ( ! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
140
+			self::$_instance = new self($cache_storage, $encryption);
141 141
 		}
142 142
 		return self::$_instance;
143 143
 	}
@@ -152,15 +152,15 @@  discard block
 block discarded – undo
152 152
 	  * @throws \EE_Error
153 153
 	  * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
154 154
 	  */
155
-	 protected function __construct(CacheStorageInterface $cache_storage, EE_Encryption $encryption = null ) {
155
+	 protected function __construct(CacheStorageInterface $cache_storage, EE_Encryption $encryption = null) {
156 156
 
157 157
 		// session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
158
-		if ( ! apply_filters( 'FHEE_load_EE_Session', true ) ) {
158
+		if ( ! apply_filters('FHEE_load_EE_Session', true)) {
159 159
 			return;
160 160
 		}
161
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
162
-		if ( ! defined( 'ESPRESSO_SESSION' ) ) {
163
-			define( 'ESPRESSO_SESSION', true );
161
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
162
+		if ( ! defined('ESPRESSO_SESSION')) {
163
+			define('ESPRESSO_SESSION', true);
164 164
 		}
165 165
 		// default session lifespan in seconds
166 166
 		$this->_lifespan = apply_filters(
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
 		 * 		}
175 175
 		 */
176 176
 		// retrieve session options from db
177
-		$session_settings = (array) get_option( 'ee_session_settings', array() );
178
-		if ( ! empty( $session_settings )) {
177
+		$session_settings = (array) get_option('ee_session_settings', array());
178
+		if ( ! empty($session_settings)) {
179 179
 			// cycle though existing session options
180
-			foreach ( $session_settings as $var_name => $session_setting ) {
180
+			foreach ($session_settings as $var_name => $session_setting) {
181 181
 				// set values for class properties
182
-				$var_name = '_' . $var_name;
182
+				$var_name = '_'.$var_name;
183 183
 				$this->{$var_name} = $session_setting;
184 184
 			}
185 185
 		}
@@ -190,15 +190,15 @@  discard block
 block discarded – undo
190 190
         // encrypt data via: $this->encryption->encrypt();
191 191
         $this->encryption = $encryption;
192 192
 		// filter hook allows outside functions/classes/plugins to change default empty cart
193
-		$extra_default_session_vars = apply_filters( 'FHEE__EE_Session__construct__extra_default_session_vars', array() );
194
-		array_merge( $this->_default_session_vars, $extra_default_session_vars );
193
+		$extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array());
194
+		array_merge($this->_default_session_vars, $extra_default_session_vars);
195 195
 		// apply default session vars
196 196
 		$this->_set_defaults();
197 197
          add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
198 198
          // check request for 'clear_session' param
199
-		add_action( 'AHEE__EE_Request_Handler__construct__complete', array( $this, 'wp_loaded' ));
199
+		add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded'));
200 200
 		// once everything is all said and done,
201
-		add_action( 'shutdown', array( $this, 'update' ), 100 );
201
+		add_action('shutdown', array($this, 'update'), 100);
202 202
          $this->configure_garbage_collection_filters();
203 203
 	}
204 204
 
@@ -286,11 +286,11 @@  discard block
 block discarded – undo
286 286
 	 */
287 287
 	private function _set_defaults() {
288 288
 		// set some defaults
289
-		foreach ( $this->_default_session_vars as $key => $default_var ) {
290
-			if ( is_array( $default_var )) {
291
-				$this->_session_data[ $key ] = array();
289
+		foreach ($this->_default_session_vars as $key => $default_var) {
290
+			if (is_array($default_var)) {
291
+				$this->_session_data[$key] = array();
292 292
 			} else {
293
-				$this->_session_data[ $key ] = '';
293
+				$this->_session_data[$key] = '';
294 294
 			}
295 295
 		}
296 296
 	}
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 	  * @param \EE_Checkout $checkout
346 346
 	  * @return bool
347 347
 	  */
348
-	 public function set_checkout( EE_Checkout $checkout ) {
348
+	 public function set_checkout(EE_Checkout $checkout) {
349 349
 		 $this->_session_data['checkout'] = $checkout;
350 350
 		 return TRUE;
351 351
 	 }
@@ -378,9 +378,9 @@  discard block
 block discarded – undo
378 378
 	  * @return bool
379 379
 	  * @throws \EE_Error
380 380
 	  */
381
-	 public function set_transaction( EE_Transaction $transaction ) {
381
+	 public function set_transaction(EE_Transaction $transaction) {
382 382
 		 // first remove the session from the transaction before we save the transaction in the session
383
-		 $transaction->set_txn_session_data( NULL );
383
+		 $transaction->set_txn_session_data(NULL);
384 384
 		 $this->_session_data['transaction'] = $transaction;
385 385
 		 return TRUE;
386 386
 	 }
@@ -416,15 +416,15 @@  discard block
 block discarded – undo
416 416
 	  * @param bool $reset_cache
417 417
 	  * @return    array
418 418
 	  */
419
-	public function get_session_data( $key = NULL, $reset_cache = FALSE ) {
420
-		if ( $reset_cache ) {
419
+	public function get_session_data($key = NULL, $reset_cache = FALSE) {
420
+		if ($reset_cache) {
421 421
 			$this->reset_cart();
422 422
 			$this->reset_checkout();
423 423
 			$this->reset_transaction();
424 424
 		}
425
-		 if ( ! empty( $key ))  {
426
-			return  isset( $this->_session_data[ $key ] ) ? $this->_session_data[ $key ] : NULL;
427
-		}  else  {
425
+		 if ( ! empty($key)) {
426
+			return  isset($this->_session_data[$key]) ? $this->_session_data[$key] : NULL;
427
+		} else {
428 428
 			return $this->_session_data;
429 429
 		}
430 430
 	}
@@ -437,20 +437,20 @@  discard block
 block discarded – undo
437 437
 	  * @param 	array $data
438 438
 	  * @return 	TRUE on success, FALSE on fail
439 439
 	  */
440
-	public function set_session_data( $data ) {
440
+	public function set_session_data($data) {
441 441
 
442 442
 		// nothing ??? bad data ??? go home!
443
-		if ( empty( $data ) || ! is_array( $data )) {
444
-			EE_Error::add_error( __( 'No session data or invalid session data was provided.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
443
+		if (empty($data) || ! is_array($data)) {
444
+			EE_Error::add_error(__('No session data or invalid session data was provided.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
445 445
 			return FALSE;
446 446
 		}
447 447
 
448
-		foreach ( $data as $key =>$value ) {
449
-			if ( isset( $this->_default_session_vars[ $key ] )) {
450
-				EE_Error::add_error( sprintf( __( 'Sorry! %s is a default session datum and can not be reset.', 'event_espresso' ), $key ), __FILE__, __FUNCTION__, __LINE__ );
448
+		foreach ($data as $key =>$value) {
449
+			if (isset($this->_default_session_vars[$key])) {
450
+				EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', 'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__);
451 451
 				return FALSE;
452 452
 			} else {
453
-				$this->_session_data[ $key ] = $value;
453
+				$this->_session_data[$key] = $value;
454 454
 			}
455 455
 		}
456 456
 
@@ -468,9 +468,9 @@  discard block
 block discarded – undo
468 468
 	  * @throws \EE_Error
469 469
 	  */
470 470
 	private function _espresso_session() {
471
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
471
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
472 472
 		// check that session has started
473
-		if ( session_id() === '' ) {
473
+		if (session_id() === '') {
474 474
 			//starts a new session if one doesn't already exist, or re-initiates an existing one
475 475
 			session_start();
476 476
 		}
@@ -479,39 +479,39 @@  discard block
 block discarded – undo
479 479
 		// and the visitors IP
480 480
 		$this->_ip_address = $this->_visitor_ip();
481 481
 		// set the "user agent"
482
-		$this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr( $_SERVER['HTTP_USER_AGENT'] ) : FALSE;
482
+		$this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr($_SERVER['HTTP_USER_AGENT']) : FALSE;
483 483
 		// now let's retrieve what's in the db
484 484
         $session_data = $this->_retrieve_session_data();
485
-        if (! empty($session_data)) {
485
+        if ( ! empty($session_data)) {
486 486
             // get the current time in UTC
487
-			$this->_time = isset( $this->_time ) ? $this->_time : time();
487
+			$this->_time = isset($this->_time) ? $this->_time : time();
488 488
 			// and reset the session expiration
489
-			$this->_expiration = isset( $session_data['expiration'] )
489
+			$this->_expiration = isset($session_data['expiration'])
490 490
 				? $session_data['expiration']
491 491
 				: $this->_time + $this->_lifespan;
492 492
 		} else {
493 493
             // set initial site access time and the session expiration
494 494
 			$this->_set_init_access_and_expiration();
495 495
 			// set referer
496
-			$this->_session_data[ 'pages_visited' ][ $this->_session_data['init_access'] ] = isset( $_SERVER['HTTP_REFERER'] )
497
-				? esc_attr( $_SERVER['HTTP_REFERER'] )
496
+			$this->_session_data['pages_visited'][$this->_session_data['init_access']] = isset($_SERVER['HTTP_REFERER'])
497
+				? esc_attr($_SERVER['HTTP_REFERER'])
498 498
 				: '';
499 499
 			// no previous session = go back and create one (on top of the data above)
500 500
 			return FALSE;
501 501
 		}
502 502
         // now the user agent
503
-		if ( $session_data['user_agent'] !== $this->_user_agent ) {
503
+		if ($session_data['user_agent'] !== $this->_user_agent) {
504 504
 			return FALSE;
505 505
 		}
506 506
 		// wait a minute... how old are you?
507
-		if ( $this->_time > $this->_expiration ) {
507
+		if ($this->_time > $this->_expiration) {
508 508
 			// yer too old fer me!
509 509
             $this->_expired = true;
510 510
 			// wipe out everything that isn't a default session datum
511
-			$this->clear_session( __CLASS__, __FUNCTION__ );
511
+			$this->clear_session(__CLASS__, __FUNCTION__);
512 512
 		}
513 513
 		// make event espresso session data available to plugin
514
-		$this->_session_data = array_merge( $this->_session_data, $session_data );
514
+		$this->_session_data = array_merge($this->_session_data, $session_data);
515 515
 		return TRUE;
516 516
 
517 517
 	}
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
       */
528 528
      protected function _retrieve_session_data()
529 529
      {
530
-         $ssn_key = EE_Session::session_id_prefix . $this->_sid;
530
+         $ssn_key = EE_Session::session_id_prefix.$this->_sid;
531 531
          try {
532 532
              // we're using WP's Transient API to store session data using the PHP session ID as the option name
533 533
              $session_data = $this->cache_storage->get($ssn_key, false);
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
              }
537 537
              if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
538 538
                  $hash_check = $this->cache_storage->get(
539
-                     EE_Session::hash_check_prefix . $this->_sid,
539
+                     EE_Session::hash_check_prefix.$this->_sid,
540 540
                      false
541 541
                  );
542 542
                  if ($hash_check && $hash_check !== md5($session_data)) {
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
                                  'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
547 547
                                  'event_espresso'
548 548
                              ),
549
-                             EE_Session::session_id_prefix . $this->_sid
549
+                             EE_Session::session_id_prefix.$this->_sid
550 550
                          ),
551 551
                          __FILE__, __FUNCTION__, __LINE__
552 552
                      );
@@ -558,17 +558,17 @@  discard block
 block discarded – undo
558 558
              $row = $wpdb->get_row(
559 559
                  $wpdb->prepare(
560 560
                      "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
561
-                     '_transient_' . $ssn_key
561
+                     '_transient_'.$ssn_key
562 562
                  )
563 563
              );
564 564
              $session_data = is_object($row) ? $row->option_value : null;
565 565
              if ($session_data) {
566 566
                  $session_data = preg_replace_callback(
567 567
                      '!s:(d+):"(.*?)";!',
568
-                     function ($match) {
568
+                     function($match) {
569 569
                          return $match[1] === strlen($match[2])
570 570
                              ? $match[0]
571
-                             : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
571
+                             : 's:'.strlen($match[2]).':"'.$match[2].'";';
572 572
                      },
573 573
                      $session_data
574 574
                  );
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
                      'event_espresso'
590 590
                  );
591 591
                  $msg .= WP_DEBUG
592
-                     ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
592
+                     ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data)
593 593
                      : '';
594 594
                  throw new InvalidSessionDataException($msg, 0, $e);
595 595
              }
@@ -602,11 +602,11 @@  discard block
 block discarded – undo
602 602
                  'event_espresso'
603 603
              );
604 604
              $msg .= WP_DEBUG
605
-                 ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
605
+                 ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data)
606 606
                  : '';
607 607
 	         throw new InvalidSessionDataException($msg);
608 608
          }
609
-	     if ( isset($session_data['transaction'] ) && absint($session_data['transaction'] ) !== 0 ) {
609
+	     if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
610 610
              $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
611 611
                  $session_data['transaction']
612 612
 	         );
@@ -627,12 +627,12 @@  discard block
 block discarded – undo
627 627
 	  */
628 628
 	protected function _generate_session_id() {
629 629
 		// check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length
630
-		if ( isset( $_REQUEST[ 'EESID' ] ) ) {
631
-			$session_id = sanitize_text_field( $_REQUEST[ 'EESID' ] );
630
+		if (isset($_REQUEST['EESID'])) {
631
+			$session_id = sanitize_text_field($_REQUEST['EESID']);
632 632
 		} else {
633
-			$session_id = md5( session_id() . get_current_blog_id() . $this->_get_sid_salt() );
633
+			$session_id = md5(session_id().get_current_blog_id().$this->_get_sid_salt());
634 634
 		}
635
-		return apply_filters( 'FHEE__EE_Session___generate_session_id__session_id', $session_id );
635
+		return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
636 636
 	}
637 637
 
638 638
 
@@ -644,20 +644,20 @@  discard block
 block discarded – undo
644 644
 	  */
645 645
 	protected function _get_sid_salt() {
646 646
 		// was session id salt already saved to db ?
647
-		if ( empty( $this->_sid_salt ) ) {
647
+		if (empty($this->_sid_salt)) {
648 648
 			// no?  then maybe use WP defined constant
649
-			if ( defined( 'AUTH_SALT' ) ) {
649
+			if (defined('AUTH_SALT')) {
650 650
 				$this->_sid_salt = AUTH_SALT;
651 651
 			}
652 652
 			// if salt doesn't exist or is too short
653
-			if ( strlen( $this->_sid_salt ) < 32 ) {
653
+			if (strlen($this->_sid_salt) < 32) {
654 654
 				// create a new one
655
-				$this->_sid_salt = wp_generate_password( 64 );
655
+				$this->_sid_salt = wp_generate_password(64);
656 656
 			}
657 657
 			// and save it as a permanent session setting
658
-			$session_settings = get_option( 'ee_session_settings' );
659
-			$session_settings[ 'sid_salt' ] = $this->_sid_salt;
660
-			update_option( 'ee_session_settings', $session_settings );
658
+			$session_settings = get_option('ee_session_settings');
659
+			$session_settings['sid_salt'] = $this->_sid_salt;
660
+			update_option('ee_session_settings', $session_settings);
661 661
 		}
662 662
 		return $this->_sid_salt;
663 663
 	}
@@ -686,19 +686,19 @@  discard block
 block discarded – undo
686 686
       * @return TRUE on success, FALSE on fail
687 687
       * @throws \EE_Error
688 688
       */
689
-	public function update( $new_session = FALSE ) {
690
-		$this->_session_data = isset( $this->_session_data )
691
-			&& is_array( $this->_session_data )
692
-			&& isset( $this->_session_data['id'])
689
+	public function update($new_session = FALSE) {
690
+		$this->_session_data = isset($this->_session_data)
691
+			&& is_array($this->_session_data)
692
+			&& isset($this->_session_data['id'])
693 693
 			? $this->_session_data
694 694
 			: array();
695
-		if ( empty( $this->_session_data )) {
695
+		if (empty($this->_session_data)) {
696 696
 			$this->_set_defaults();
697 697
 		}
698 698
 		$session_data = array();
699
-		foreach ( $this->_session_data as $key => $value ) {
699
+		foreach ($this->_session_data as $key => $value) {
700 700
 
701
-			switch( $key ) {
701
+			switch ($key) {
702 702
 
703 703
 				case 'id' :
704 704
 					// session ID
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
 				break;
717 717
 
718 718
 				case 'init_access' :
719
-					$session_data['init_access'] = absint( $value );
719
+					$session_data['init_access'] = absint($value);
720 720
 				break;
721 721
 
722 722
 				case 'last_access' :
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
 
727 727
 				case 'expiration' :
728 728
 					// when the session expires
729
-					$session_data['expiration'] = ! empty( $this->_expiration )
729
+					$session_data['expiration'] = ! empty($this->_expiration)
730 730
 						? $this->_expiration
731 731
 						: $session_data['init_access'] + $this->_lifespan;
732 732
 				break;
@@ -738,11 +738,11 @@  discard block
 block discarded – undo
738 738
 
739 739
 				case 'pages_visited' :
740 740
 					$page_visit = $this->_get_page_visit();
741
-					if ( $page_visit ) {
741
+					if ($page_visit) {
742 742
 						// set pages visited where the first will be the http referrer
743
-						$this->_session_data[ 'pages_visited' ][ $this->_time ] = $page_visit;
743
+						$this->_session_data['pages_visited'][$this->_time] = $page_visit;
744 744
 						// we'll only save the last 10 page visits.
745
-						$session_data[ 'pages_visited' ] = array_slice( $this->_session_data['pages_visited'], -10 );
745
+						$session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
746 746
 					}
747 747
 				break;
748 748
 
@@ -756,9 +756,9 @@  discard block
 block discarded – undo
756 756
 
757 757
 		$this->_session_data = $session_data;
758 758
 		// creating a new session does not require saving to the db just yet
759
-		if ( ! $new_session ) {
759
+		if ( ! $new_session) {
760 760
 			// ready? let's save
761
-			if ( $this->_save_session_to_db() ) {
761
+			if ($this->_save_session_to_db()) {
762 762
 				return TRUE;
763 763
 			} else {
764 764
 				return FALSE;
@@ -778,9 +778,9 @@  discard block
 block discarded – undo
778 778
       * @throws \EE_Error
779 779
       */
780 780
 	private function _create_espresso_session( ) {
781
-		do_action( 'AHEE_log', __CLASS__, __FUNCTION__, '' );
781
+		do_action('AHEE_log', __CLASS__, __FUNCTION__, '');
782 782
 		// use the update function for now with $new_session arg set to TRUE
783
-		return  $this->update( TRUE ) ? TRUE : FALSE;
783
+		return  $this->update(TRUE) ? TRUE : FALSE;
784 784
 	}
785 785
 
786 786
 
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
                 EE_Registry::instance()->REQ->front_ajax
801 801
                 || (
802 802
                     // OR an admin request that is NOT AJAX
803
-					! ( defined( 'DOING_AJAX' ) && DOING_AJAX )
803
+					! (defined('DOING_AJAX') && DOING_AJAX)
804 804
                     && is_admin()
805 805
 				)
806 806
                 || (
@@ -813,8 +813,8 @@  discard block
 block discarded – undo
813 813
 			return false;
814 814
 		}
815 815
 		$transaction = $this->transaction();
816
-		if ( $transaction instanceof EE_Transaction ) {
817
-			if ( ! $transaction->ID() ) {
816
+		if ($transaction instanceof EE_Transaction) {
817
+			if ( ! $transaction->ID()) {
818 818
 				$transaction->save();
819 819
 			}
820 820
 			$this->_session_data['transaction'] = $transaction->ID();
@@ -823,19 +823,19 @@  discard block
 block discarded – undo
823 823
 		$session_data = serialize($this->_session_data);
824 824
 		// do we need to also encode it to avoid corrupted data when saved to the db?
825 825
 		$session_data = $this->_use_encryption
826
-            ? $this->encryption->base64_string_encode( $session_data )
826
+            ? $this->encryption->base64_string_encode($session_data)
827 827
             : $session_data;
828 828
 		// maybe save hash check
829
-		if ( apply_filters( 'FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG ) ) {
829
+		if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
830 830
             $this->cache_storage->add(
831
-                EE_Session::hash_check_prefix . $this->_sid,
831
+                EE_Session::hash_check_prefix.$this->_sid,
832 832
                 md5($session_data),
833 833
                 $this->_lifespan
834 834
             );
835 835
         }
836 836
         // we're using the Transient API for storing session data,
837 837
         return $this->cache_storage->add(
838
-            EE_Session::session_id_prefix . $this->_sid,
838
+            EE_Session::session_id_prefix.$this->_sid,
839 839
             $session_data,
840 840
             $this->_lifespan
841 841
         );
@@ -864,10 +864,10 @@  discard block
 block discarded – undo
864 864
 			'HTTP_FORWARDED',
865 865
 			'REMOTE_ADDR'
866 866
 		);
867
-		foreach ( $server_keys as $key ){
868
-			if ( isset( $_SERVER[ $key ] )) {
869
-				foreach ( array_map( 'trim', explode( ',', $_SERVER[ $key ] )) as $ip ) {
870
-					if ( $ip === '127.0.0.1' || filter_var( $ip, FILTER_VALIDATE_IP ) !== FALSE ) {
867
+		foreach ($server_keys as $key) {
868
+			if (isset($_SERVER[$key])) {
869
+				foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
870
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== FALSE) {
871 871
 						$visitor_ip = $ip;
872 872
 					}
873 873
 				}
@@ -886,32 +886,32 @@  discard block
 block discarded – undo
886 886
 	 *			@return string
887 887
 	 */
888 888
 	public function _get_page_visit() {
889
-		$page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
889
+		$page_visit = home_url('/').'wp-admin/admin-ajax.php';
890 890
 		// check for request url
891
-		if ( isset( $_SERVER['REQUEST_URI'] )) {
891
+		if (isset($_SERVER['REQUEST_URI'])) {
892 892
 			$http_host = '';
893 893
 			$page_id = '?';
894 894
 			$e_reg = '';
895
-			$request_uri = esc_url( $_SERVER['REQUEST_URI'] );
896
-			$ru_bits = explode( '?', $request_uri );
895
+			$request_uri = esc_url($_SERVER['REQUEST_URI']);
896
+			$ru_bits = explode('?', $request_uri);
897 897
 			$request_uri = $ru_bits[0];
898 898
 			// check for and grab host as well
899
-			if ( isset( $_SERVER['HTTP_HOST'] )) {
900
-				$http_host = esc_url( $_SERVER['HTTP_HOST'] );
899
+			if (isset($_SERVER['HTTP_HOST'])) {
900
+				$http_host = esc_url($_SERVER['HTTP_HOST']);
901 901
 			}
902 902
 			// check for page_id in SERVER REQUEST
903
-			if ( isset( $_REQUEST['page_id'] )) {
903
+			if (isset($_REQUEST['page_id'])) {
904 904
 				// rebuild $e_reg without any of the extra parameters
905
-				$page_id = '?page_id=' . esc_attr( $_REQUEST['page_id'] ) . '&amp;';
905
+				$page_id = '?page_id='.esc_attr($_REQUEST['page_id']).'&amp;';
906 906
 			}
907 907
 			// check for $e_reg in SERVER REQUEST
908
-			if ( isset( $_REQUEST['ee'] )) {
908
+			if (isset($_REQUEST['ee'])) {
909 909
 				// rebuild $e_reg without any of the extra parameters
910
-				$e_reg = 'ee=' . esc_attr( $_REQUEST['ee'] );
910
+				$e_reg = 'ee='.esc_attr($_REQUEST['ee']);
911 911
 			}
912
-			$page_visit = rtrim( $http_host . $request_uri . $page_id . $e_reg, '?' );
912
+			$page_visit = rtrim($http_host.$request_uri.$page_id.$e_reg, '?');
913 913
 		}
914
-		return $page_visit !== home_url( '/wp-admin/admin-ajax.php' ) ? $page_visit : '';
914
+		return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
915 915
 
916 916
 	}
917 917
 
@@ -941,14 +941,14 @@  discard block
 block discarded – undo
941 941
       * @return void
942 942
       * @throws \EE_Error
943 943
       */
944
-	public function clear_session( $class = '', $function = '' ) {
944
+	public function clear_session($class = '', $function = '') {
945 945
 		//echo '<h3 style="color:#999;line-height:.9em;"><span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/><span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b></h3>';
946
-        do_action( 'AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' .  $function . '()' );
946
+        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()');
947 947
 		$this->reset_cart();
948 948
 		$this->reset_checkout();
949 949
 		$this->reset_transaction();
950 950
 		// wipe out everything that isn't a default session datum
951
-		$this->reset_data( array_keys( $this->_session_data ));
951
+		$this->reset_data(array_keys($this->_session_data));
952 952
 		// reset initial site access time and the session expiration
953 953
 		$this->_set_init_access_and_expiration();
954 954
 		$this->_save_session_to_db();
@@ -963,42 +963,42 @@  discard block
 block discarded – undo
963 963
 	  * @param bool  $show_all_notices
964 964
 	  * @return TRUE on success, FALSE on fail
965 965
 	  */
966
-	public function reset_data( $data_to_reset = array(), $show_all_notices = FALSE ) {
966
+	public function reset_data($data_to_reset = array(), $show_all_notices = FALSE) {
967 967
 		// if $data_to_reset is not in an array, then put it in one
968
-		if ( ! is_array( $data_to_reset ) ) {
969
-			$data_to_reset = array ( $data_to_reset );
968
+		if ( ! is_array($data_to_reset)) {
969
+			$data_to_reset = array($data_to_reset);
970 970
 		}
971 971
 		// nothing ??? go home!
972
-		if ( empty( $data_to_reset )) {
973
-			EE_Error::add_error( __( 'No session data could be reset, because no session var name was provided.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
972
+		if (empty($data_to_reset)) {
973
+			EE_Error::add_error(__('No session data could be reset, because no session var name was provided.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
974 974
 			return FALSE;
975 975
 		}
976 976
 		$return_value = TRUE;
977 977
 		// since $data_to_reset is an array, cycle through the values
978
-		foreach ( $data_to_reset as $reset ) {
978
+		foreach ($data_to_reset as $reset) {
979 979
 
980 980
 			// first check to make sure it is a valid session var
981
-			if ( isset( $this->_session_data[ $reset ] )) {
981
+			if (isset($this->_session_data[$reset])) {
982 982
 				// then check to make sure it is not a default var
983
-				if ( ! array_key_exists( $reset, $this->_default_session_vars )) {
983
+				if ( ! array_key_exists($reset, $this->_default_session_vars)) {
984 984
 					// remove session var
985
-					unset( $this->_session_data[ $reset ] );
986
-					if ( $show_all_notices ) {
987
-						EE_Error::add_success( sprintf( __( 'The session variable %s was removed.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ );
985
+					unset($this->_session_data[$reset]);
986
+					if ($show_all_notices) {
987
+						EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
988 988
 					}
989
-					$return_value = !isset($return_value) ? TRUE : $return_value;
989
+					$return_value = ! isset($return_value) ? TRUE : $return_value;
990 990
 
991 991
 				} else {
992 992
 					// yeeeeeeeeerrrrrrrrrrr OUT !!!!
993
-					if ( $show_all_notices ) {
994
-						EE_Error::add_error( sprintf( __( 'Sorry! %s is a default session datum and can not be reset.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ );
993
+					if ($show_all_notices) {
994
+						EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
995 995
 					}
996 996
 					$return_value = FALSE;
997 997
 				}
998 998
 
999
-			} else if ( $show_all_notices ) {
999
+			} else if ($show_all_notices) {
1000 1000
 				// oops! that session var does not exist!
1001
-				EE_Error::add_error( sprintf( __( 'The session item provided, %s, is invalid or does not exist.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ );
1001
+				EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
1002 1002
 				$return_value = FALSE;
1003 1003
 			}
1004 1004
 
@@ -1017,8 +1017,8 @@  discard block
 block discarded – undo
1017 1017
       * @throws \EE_Error
1018 1018
       */
1019 1019
 	public function wp_loaded() {
1020
-		if ( isset(  EE_Registry::instance()->REQ ) && EE_Registry::instance()->REQ->is_set( 'clear_session' )) {
1021
-			$this->clear_session( __CLASS__, __FUNCTION__ );
1020
+		if (isset(EE_Registry::instance()->REQ) && EE_Registry::instance()->REQ->is_set('clear_session')) {
1021
+			$this->clear_session(__CLASS__, __FUNCTION__);
1022 1022
 		}
1023 1023
 	}
1024 1024
 
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
              // or use that for the new transient cleanup query limit
1055 1055
              add_filter(
1056 1056
                  'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1057
-                 function () use ($expired_session_transient_delete_query_limit) {
1057
+                 function() use ($expired_session_transient_delete_query_limit) {
1058 1058
                      return $expired_session_transient_delete_query_limit;
1059 1059
                  }
1060 1060
              );
@@ -1068,34 +1068,34 @@  discard block
 block discarded – undo
1068 1068
 	  * @param $data1
1069 1069
 	  * @return string
1070 1070
 	  */
1071
-	 private function find_serialize_error( $data1 ) {
1071
+	 private function find_serialize_error($data1) {
1072 1072
 		$error = '<pre>';
1073 1073
 		 $data2 = preg_replace_callback(
1074 1074
 			 '!s:(\d+):"(.*?)";!',
1075
-			 function ( $match ) {
1076
-				 return ( $match[1] === strlen( $match[2] ) )
1075
+			 function($match) {
1076
+				 return ($match[1] === strlen($match[2]))
1077 1077
 					 ? $match[0]
1078 1078
 					 : 's:'
1079
-					   . strlen( $match[2] )
1079
+					   . strlen($match[2])
1080 1080
 					   . ':"'
1081 1081
 					   . $match[2]
1082 1082
 					   . '";';
1083 1083
 			 },
1084 1084
 			 $data1
1085 1085
 		 );
1086
-		$max = ( strlen( $data1 ) > strlen( $data2 ) ) ? strlen( $data1 ) : strlen( $data2 );
1087
-		$error .= $data1 . PHP_EOL;
1088
-		$error .= $data2 . PHP_EOL;
1089
-		for ( $i = 0; $i < $max; $i++ ) {
1090
-			if ( @$data1[ $i ] !== @$data2[ $i ] ) {
1091
-				$error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1092
-				$error .= "\t-> ORD number " . ord( @$data1[ $i ] ) . ' != ' . ord( @$data2[ $i ] ) . PHP_EOL;
1093
-				$error .= "\t-> Line Number = $i" . PHP_EOL;
1094
-				$start = ( $i - 20 );
1095
-				$start = ( $start < 0 ) ? 0 : $start;
1086
+		$max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1087
+		$error .= $data1.PHP_EOL;
1088
+		$error .= $data2.PHP_EOL;
1089
+		for ($i = 0; $i < $max; $i++) {
1090
+			if (@$data1[$i] !== @$data2[$i]) {
1091
+				$error .= 'Difference '.@$data1[$i].' != '.@$data2[$i].PHP_EOL;
1092
+				$error .= "\t-> ORD number ".ord(@$data1[$i]).' != '.ord(@$data2[$i]).PHP_EOL;
1093
+				$error .= "\t-> Line Number = $i".PHP_EOL;
1094
+				$start = ($i - 20);
1095
+				$start = ($start < 0) ? 0 : $start;
1096 1096
 				$length = 40;
1097 1097
 				$point = $max - $i;
1098
-				if ( $point < 20 ) {
1098
+				if ($point < 20) {
1099 1099
 					$rlength = 1;
1100 1100
 					$rpoint = -$point;
1101 1101
 				} else {
@@ -1104,16 +1104,16 @@  discard block
 block discarded – undo
1104 1104
 				}
1105 1105
 				$error .= "\t-> Section Data1  = ";
1106 1106
 				$error .= substr_replace(
1107
-					substr( $data1, $start, $length ),
1108
-					"<b style=\"color:green\">{$data1[ $i ]}</b>",
1107
+					substr($data1, $start, $length),
1108
+					"<b style=\"color:green\">{$data1[$i]}</b>",
1109 1109
 					$rpoint,
1110 1110
 					$rlength
1111 1111
 				);
1112 1112
 				$error .= PHP_EOL;
1113 1113
 				$error .= "\t-> Section Data2  = ";
1114 1114
 				$error .= substr_replace(
1115
-					substr( $data2, $start, $length ),
1116
-					"<b style=\"color:red\">{$data2[ $i ]}</b>",
1115
+					substr($data2, $start, $length),
1116
+					"<b style=\"color:red\">{$data2[$i]}</b>",
1117 1117
 					$rpoint,
1118 1118
 					$rlength
1119 1119
 				);
Please login to merge, or discard this patch.
core/admin/EE_Admin.core.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,9 @@
 block discarded – undo
1 1
 <?php
2 2
 use EventEspresso\core\interfaces\InterminableInterface;
3 3
 
4
-if ( ! defined( 'EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
4
+if ( ! defined( 'EVENT_ESPRESSO_VERSION')) {
5
+	exit('No direct script access allowed');
6
+}
5 7
 /**
6 8
  * Event Espresso
7 9
  *
Please login to merge, or discard this patch.
Spacing   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 use EventEspresso\core\interfaces\InterminableInterface;
3 3
 
4
-if ( ! defined( 'EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
5 5
 /**
6 6
  * Event Espresso
7 7
  *
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 */
44 44
 	public static function instance() {
45 45
 		// check if class object is instantiated
46
-		if (  ! self::$_instance instanceof EE_Admin ) {
46
+		if ( ! self::$_instance instanceof EE_Admin) {
47 47
 			self::$_instance = new self();
48 48
 		}
49 49
 		return self::$_instance;
@@ -70,25 +70,25 @@  discard block
 block discarded – undo
70 70
 		// define global EE_Admin constants
71 71
 		$this->_define_all_constants();
72 72
 		// set autoloaders for our admin page classes based on included path information
73
-		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder( EE_ADMIN );
73
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN);
74 74
 		// admin hooks
75
-		add_filter( 'plugin_action_links', array( $this, 'filter_plugin_actions' ), 10, 2 );
75
+		add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2);
76 76
 		// load EE_Request_Handler early
77
-		add_action( 'AHEE__EE_System__core_loaded_and_ready', array( $this, 'get_request' ));
78
-		add_action( 'AHEE__EE_System__initialize_last', array( $this, 'init' ));
79
-		add_action( 'AHEE__EE_Admin_Page__route_admin_request', array( $this, 'route_admin_request' ), 100, 2 );
80
-		add_action( 'wp_loaded', array( $this, 'wp_loaded' ), 100 );
81
-		add_action( 'admin_init', array( $this, 'admin_init' ), 100 );
82
-		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ), 20 );
83
-		add_action( 'admin_notices', array( $this, 'display_admin_notices' ), 10 );
84
-		add_action( 'network_admin_notices', array( $this, 'display_admin_notices' ), 10 );
85
-		add_filter( 'pre_update_option', array( $this, 'check_for_invalid_datetime_formats' ), 100, 2 );
86
-		add_filter('admin_footer_text', array( $this, 'espresso_admin_footer' ));
77
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request'));
78
+		add_action('AHEE__EE_System__initialize_last', array($this, 'init'));
79
+		add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2);
80
+		add_action('wp_loaded', array($this, 'wp_loaded'), 100);
81
+		add_action('admin_init', array($this, 'admin_init'), 100);
82
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20);
83
+		add_action('admin_notices', array($this, 'display_admin_notices'), 10);
84
+		add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
85
+		add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
86
+		add_filter('admin_footer_text', array($this, 'espresso_admin_footer'));
87 87
 
88 88
 		//reset Environment config (we only do this on admin page loads);
89 89
 		EE_Registry::instance()->CFG->environment->recheck_values();
90 90
 
91
-		do_action( 'AHEE__EE_Admin__loaded' );
91
+		do_action('AHEE__EE_Admin__loaded');
92 92
 	}
93 93
 
94 94
 
@@ -103,12 +103,12 @@  discard block
 block discarded – undo
103 103
 	 * @return void
104 104
 	 */
105 105
 	private function _define_all_constants() {
106
-		if ( ! defined( 'EE_ADMIN_URL' ) ) {
107
-			define( 'EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/' );
108
-			define( 'EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/' );
109
-			define( 'EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS );
110
-			define( 'WP_ADMIN_PATH', ABSPATH . 'wp-admin/' );
111
-			define( 'WP_AJAX_URL', admin_url( 'admin-ajax.php' ) );
106
+		if ( ! defined('EE_ADMIN_URL')) {
107
+			define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/');
108
+			define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/');
109
+			define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates'.DS);
110
+			define('WP_ADMIN_PATH', ABSPATH.'wp-admin/');
111
+			define('WP_AJAX_URL', admin_url('admin-ajax.php'));
112 112
 		}
113 113
 	}
114 114
 
@@ -122,23 +122,23 @@  discard block
 block discarded – undo
122 122
 	 * @param 	string 	$plugin
123 123
 	 * @return 	array
124 124
 	 */
125
-	public function filter_plugin_actions( $links, $plugin ) {
125
+	public function filter_plugin_actions($links, $plugin) {
126 126
 		// set $main_file in stone
127 127
 		static $main_file;
128 128
 		// if $main_file is not set yet
129
-		if ( ! $main_file ) {
130
-			$main_file = plugin_basename( EVENT_ESPRESSO_MAIN_FILE );
129
+		if ( ! $main_file) {
130
+			$main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
131 131
 		}
132
-		 if ( $plugin === $main_file ) {
132
+		 if ($plugin === $main_file) {
133 133
 		 	// compare current plugin to this one
134
-			if ( EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance ) {
135
-				$maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings" title="Event Espresso is in maintenance mode.  Click this link to learn why.">' . __('Maintenance Mode Active', 'event_espresso' ) . '</a>';
136
-				array_unshift( $links, $maintenance_link );
134
+			if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
135
+				$maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings" title="Event Espresso is in maintenance mode.  Click this link to learn why.">'.__('Maintenance Mode Active', 'event_espresso').'</a>';
136
+				array_unshift($links, $maintenance_link);
137 137
 			} else {
138
-				$org_settings_link = '<a href="admin.php?page=espresso_general_settings">' . __( 'Settings', 'event_espresso' ) . '</a>';
139
-				$events_link = '<a href="admin.php?page=espresso_events">' . __( 'Events', 'event_espresso' ) . '</a>';
138
+				$org_settings_link = '<a href="admin.php?page=espresso_general_settings">'.__('Settings', 'event_espresso').'</a>';
139
+				$events_link = '<a href="admin.php?page=espresso_events">'.__('Events', 'event_espresso').'</a>';
140 140
 				// add before other links
141
-				array_unshift( $links, $org_settings_link, $events_link );
141
+				array_unshift($links, $org_settings_link, $events_link);
142 142
 			}
143 143
 		}
144 144
 		return $links;
@@ -153,8 +153,8 @@  discard block
 block discarded – undo
153 153
 	 *	@return void
154 154
 	 */
155 155
 	public function get_request() {
156
-		EE_Registry::instance()->load_core( 'Request_Handler' );
157
-		EE_Registry::instance()->load_core( 'CPT_Strategy' );
156
+		EE_Registry::instance()->load_core('Request_Handler');
157
+		EE_Registry::instance()->load_core('CPT_Strategy');
158 158
 	}
159 159
 
160 160
 
@@ -166,11 +166,11 @@  discard block
 block discarded – undo
166 166
 	 * @param array $admin_page_folder_names
167 167
 	 * @return array
168 168
 	 */
169
-	public function hide_admin_pages_except_maintenance_mode( $admin_page_folder_names = array() ){
169
+	public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) {
170 170
 		return array(
171
-			'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
172
-			'about' => EE_ADMIN_PAGES . 'about' . DS,
173
-			'support' => EE_ADMIN_PAGES . 'support' . DS
171
+			'maintenance' => EE_ADMIN_PAGES.'maintenance'.DS,
172
+			'about' => EE_ADMIN_PAGES.'about'.DS,
173
+			'support' => EE_ADMIN_PAGES.'support'.DS
174 174
 		);
175 175
 	}
176 176
 
@@ -184,31 +184,31 @@  discard block
 block discarded – undo
184 184
 	*/
185 185
 	public function init() {
186 186
 		//only enable most of the EE_Admin IF we're not in full maintenance mode
187
-		if ( EE_Maintenance_Mode::instance()->models_can_query() ){
187
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
188 188
 			//ok so we want to enable the entire admin
189
-			add_action( 'wp_ajax_dismiss_ee_nag_notice', array( $this, 'dismiss_ee_nag_notice_callback' ));
190
-			add_action( 'admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 );
191
-			add_action( 'network_admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 );
189
+			add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback'));
190
+			add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9);
191
+			add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9);
192 192
 			//at a glance dashboard widget
193
-			add_filter( 'dashboard_glance_items', array( $this, 'dashboard_glance_items' ), 10 );
193
+			add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
194 194
 			//filter for get_edit_post_link used on comments for custom post types
195
-			add_filter( 'get_edit_post_link', array( $this, 'modify_edit_post_link' ), 10, 2 );
195
+			add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
196 196
 		}
197 197
 		// run the admin page factory but ONLY if we are doing an ee admin ajax request
198
-		if ( !defined('DOING_AJAX') || EE_ADMIN_AJAX ) {
198
+		if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
199 199
 			try {
200 200
 				//this loads the controller for the admin pages which will setup routing etc
201
-				EE_Registry::instance()->load_core( 'Admin_Page_Loader' );
202
-			} catch ( EE_Error $e ) {
201
+				EE_Registry::instance()->load_core('Admin_Page_Loader');
202
+			} catch (EE_Error $e) {
203 203
 				$e->get_error();
204 204
 			}
205 205
 		}
206
-		add_filter( 'content_save_pre', array( $this, 'its_eSpresso' ), 10, 1 );
206
+		add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
207 207
 		//make sure our CPTs and custom taxonomy metaboxes get shown for first time users
208
-		add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes' ), 10 );
209
-		add_action('admin_head', array( $this, 'register_custom_nav_menu_boxes' ), 10 );
208
+		add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
209
+		add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
210 210
 		//exclude EE critical pages from all nav menus and wp_list_pages
211
-		add_filter('nav_menu_meta_box_object', array( $this, 'remove_pages_from_nav_menu'), 10 );
211
+		add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
212 212
 	}
213 213
 
214 214
 
@@ -221,9 +221,9 @@  discard block
 block discarded – undo
221 221
 	 * @param  object $post_type WP post type object
222 222
 	 * @return object            WP post type object
223 223
 	 */
224
-	public function remove_pages_from_nav_menu( $post_type ) {
224
+	public function remove_pages_from_nav_menu($post_type) {
225 225
 		//if this isn't the "pages" post type let's get out
226
-		if ( $post_type->name !== 'page' ) {
226
+		if ($post_type->name !== 'page') {
227 227
 			return $post_type;
228 228
 		}
229 229
 		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
@@ -243,28 +243,28 @@  discard block
 block discarded – undo
243 243
 	 */
244 244
 	public function enable_hidden_ee_nav_menu_metaboxes() {
245 245
 		global $wp_meta_boxes, $pagenow;
246
-		if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php' ) {
246
+		if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
247 247
 			return;
248 248
 		}
249 249
 		$user = wp_get_current_user();
250 250
 		//has this been done yet?
251
-		if ( get_user_option( 'ee_nav_menu_initialized', $user->ID ) ) {
251
+		if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
252 252
 			return;
253 253
 		}
254 254
 
255
-		$hidden_meta_boxes = get_user_option( 'metaboxhidden_nav-menus', $user->ID );
256
-		$initial_meta_boxes = apply_filters( 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', array( 'nav-menu-theme-locations', 'add-page', 'add-custom-links', 'add-category', 'add-espresso_events', 'add-espresso_venues', 'add-espresso_event_categories', 'add-espresso_venue_categories', 'add-post-type-post', 'add-post-type-page' ) );
255
+		$hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID);
256
+		$initial_meta_boxes = apply_filters('FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', array('nav-menu-theme-locations', 'add-page', 'add-custom-links', 'add-category', 'add-espresso_events', 'add-espresso_venues', 'add-espresso_event_categories', 'add-espresso_venue_categories', 'add-post-type-post', 'add-post-type-page'));
257 257
 
258
-		if ( is_array( $hidden_meta_boxes ) ) {
259
-			foreach ( $hidden_meta_boxes as $key => $meta_box_id ) {
260
-				if ( in_array( $meta_box_id, $initial_meta_boxes ) ) {
261
-					unset( $hidden_meta_boxes[ $key ] );
258
+		if (is_array($hidden_meta_boxes)) {
259
+			foreach ($hidden_meta_boxes as $key => $meta_box_id) {
260
+				if (in_array($meta_box_id, $initial_meta_boxes)) {
261
+					unset($hidden_meta_boxes[$key]);
262 262
 				}
263 263
 			}
264 264
 		}
265 265
 
266
-		update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true );
267
-		update_user_option( $user->ID, 'ee_nav_menu_initialized', 1, true );
266
+		update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
267
+		update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
268 268
 	}
269 269
 
270 270
 
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 	 * @return void
284 284
 	 */
285 285
 	public function register_custom_nav_menu_boxes() {
286
-		add_meta_box( 'add-extra-nav-menu-pages', __('Event Espresso Pages', 'event_espresso'), array( $this, 'ee_cpt_archive_pages' ), 'nav-menus', 'side', 'core' );
286
+		add_meta_box('add-extra-nav-menu-pages', __('Event Espresso Pages', 'event_espresso'), array($this, 'ee_cpt_archive_pages'), 'nav-menus', 'side', 'core');
287 287
 	}
288 288
 
289 289
 
@@ -299,16 +299,16 @@  discard block
 block discarded – undo
299 299
 	 *
300 300
 	 * @return string  the (maybe) modified link
301 301
 	 */
302
-	public function modify_edit_post_link( $link, $id ) {
303
-		if ( ! $post = get_post( $id ) ){
302
+	public function modify_edit_post_link($link, $id) {
303
+		if ( ! $post = get_post($id)) {
304 304
 			return $link;
305 305
 		}
306
-		if ( $post->post_type === 'espresso_attendees' ) {
306
+		if ($post->post_type === 'espresso_attendees') {
307 307
 			$query_args = array(
308 308
 				'action' => 'edit_attendee',
309 309
 				'post' => $id
310 310
 			);
311
-			return EEH_URL::add_query_args_and_nonce( $query_args, admin_url('admin.php?page=espresso_registrations') );
311
+			return EEH_URL::add_query_args_and_nonce($query_args, admin_url('admin.php?page=espresso_registrations'));
312 312
 		}
313 313
 		return $link;
314 314
 	}
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 		global $nav_menu_selected_id;
321 321
 
322 322
 		$db_fields = false;
323
-		$walker = new Walker_Nav_Menu_Checklist( $db_fields );
323
+		$walker = new Walker_Nav_Menu_Checklist($db_fields);
324 324
 		$current_tab = 'event-archives';
325 325
 
326 326
 		/*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) {
@@ -339,9 +339,9 @@  discard block
 block discarded – undo
339 339
 		?>
340 340
 		<div id="posttype-extra-nav-menu-pages" class="posttypediv">
341 341
 			<ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs">
342
-				<li <?php echo ( 'event-archives' === $current_tab ? ' class="tabs"' : '' ); ?>>
343
-					<a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" href="<?php if ( $nav_menu_selected_id ) {echo esc_url(add_query_arg('extra-nav-menu-pages-tab', 'event-archives', remove_query_arg($removed_args)));} ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
344
-						<?php _e( 'Event Archive Pages', 'event_espresso' ); ?>
342
+				<li <?php echo ('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>>
343
+					<a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" href="<?php if ($nav_menu_selected_id) {echo esc_url(add_query_arg('extra-nav-menu-pages-tab', 'event-archives', remove_query_arg($removed_args))); } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
344
+						<?php _e('Event Archive Pages', 'event_espresso'); ?>
345 345
 					</a>
346 346
 				</li>
347 347
 			<?php /* // temporarily removing but leaving skeleton in place in case we ever decide to add more tabs.
@@ -359,13 +359,13 @@  discard block
 block discarded – undo
359 359
  			<?php */ ?>
360 360
 
361 361
 			<div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php
362
-			echo ( 'event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
362
+			echo ('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
363 363
 			?>">
364 364
 				<ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear">
365 365
 					<?php
366 366
 					$pages = $this->_get_extra_nav_menu_pages_items();
367 367
 					$args['walker'] = $walker;
368
-					echo walk_nav_menu_tree( array_map( array( $this, '_setup_extra_nav_menu_pages_items' ), $pages), 0, (object) $args );
368
+					echo walk_nav_menu_tree(array_map(array($this, '_setup_extra_nav_menu_pages_items'), $pages), 0, (object) $args);
369 369
 					?>
370 370
 				</ul>
371 371
 			</div><!-- /.tabs-panel -->
@@ -373,18 +373,18 @@  discard block
 block discarded – undo
373 373
 			<p class="button-controls">
374 374
 				<span class="list-controls">
375 375
 					<a href="<?php
376
-						echo esc_url( add_query_arg(
376
+						echo esc_url(add_query_arg(
377 377
 							array(
378 378
 								'extra-nav-menu-pages-tab' => 'event-archives',
379 379
 								'selectall' => 1,
380 380
 							),
381
-							remove_query_arg( $removed_args )
381
+							remove_query_arg($removed_args)
382 382
 						));
383 383
 					?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a>
384 384
 				</span>
385 385
 
386 386
 				<span class="add-to-menu">
387
-					<input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( __( 'Add to Menu' ) ); ?>" name="add-post-type-menu-item" id="<?php esc_attr_e( 'submit-posttype-extra-nav-menu-pages' ); ?>" />
387
+					<input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e(__('Add to Menu')); ?>" name="add-post-type-menu-item" id="<?php esc_attr_e('submit-posttype-extra-nav-menu-pages'); ?>" />
388 388
 					<span class="spinner"></span>
389 389
 				</span>
390 390
 			</p>
@@ -405,10 +405,10 @@  discard block
 block discarded – undo
405 405
 	private function _get_extra_nav_menu_pages_items() {
406 406
 		$menuitems[] = array(
407 407
 			'title' => __('Event List', 'event_espresso'),
408
-			'url' => get_post_type_archive_link( 'espresso_events' ),
408
+			'url' => get_post_type_archive_link('espresso_events'),
409 409
 			'description' => __('Archive page for all events.', 'event_espresso')
410 410
 		);
411
-		return apply_filters( 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems );
411
+		return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
412 412
 	}
413 413
 
414 414
 
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
 	 * @param $menu_item_values
421 421
 	 * @return stdClass
422 422
 	 */
423
-	private function _setup_extra_nav_menu_pages_items( $menu_item_values ) {
423
+	private function _setup_extra_nav_menu_pages_items($menu_item_values) {
424 424
 		$menu_item = new stdClass();
425 425
 		$keys = array(
426 426
 			'ID' => 0,
@@ -440,8 +440,8 @@  discard block
 block discarded – undo
440 440
 			'xfn' => ''
441 441
 		);
442 442
 
443
-		foreach ( $keys as $key => $value) {
444
-			$menu_item->{$key} = isset( $menu_item_values[ $key]) ? $menu_item_values[ $key] : $value;
443
+		foreach ($keys as $key => $value) {
444
+			$menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value;
445 445
 		}
446 446
 		return $menu_item;
447 447
 	}
@@ -480,9 +480,9 @@  discard block
 block discarded – undo
480 480
 		 * - check if doing post processing of one of EE CPTs
481 481
 		 * - instantiate the corresponding EE CPT model for the post_type being processed.
482 482
 		 */
483
-		if ( isset( $_POST['action'], $_POST['post_type'] ) && $_POST['action'] === 'editpost' ) {
484
-			EE_Registry::instance()->load_core( 'Register_CPTs' );
485
-			EE_Register_CPTs::instantiate_cpt_models( $_POST['post_type'] );
483
+		if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
484
+			EE_Registry::instance()->load_core('Register_CPTs');
485
+			EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']);
486 486
 		}
487 487
 
488 488
 
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
          * tab in the EE General Settings Admin page.
493 493
          * This is for user-proofing.
494 494
 		 */
495
-        add_filter( 'wp_dropdown_pages', array( $this, 'modify_dropdown_pages' ) );
495
+        add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
496 496
 
497 497
 	}
498 498
 
@@ -503,25 +503,25 @@  discard block
 block discarded – undo
503 503
 	 * @param string $output  Current output.
504 504
 	 * @return string
505 505
 	 */
506
-	public function modify_dropdown_pages( $output ) {
506
+	public function modify_dropdown_pages($output) {
507 507
 		//get critical pages
508 508
 		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
509 509
 
510 510
 		//split current output by line break for easier parsing.
511
-		$split_output = explode( "\n", $output );
511
+		$split_output = explode("\n", $output);
512 512
 
513 513
 		//loop through to remove any critical pages from the array.
514
-		foreach ( $critical_pages as $page_id ) {
515
-			$needle = 'value="' . $page_id . '"';
516
-			foreach( $split_output as $key => $haystack ) {
517
-				if( strpos( $haystack, $needle ) !== false ) {
518
-					unset( $split_output[$key] );
514
+		foreach ($critical_pages as $page_id) {
515
+			$needle = 'value="'.$page_id.'"';
516
+			foreach ($split_output as $key => $haystack) {
517
+				if (strpos($haystack, $needle) !== false) {
518
+					unset($split_output[$key]);
519 519
 				}
520 520
 			}
521 521
 		}
522 522
 
523 523
 		//replace output with the new contents
524
-		return implode( "\n", $split_output );
524
+		return implode("\n", $split_output);
525 525
 	}
526 526
 
527 527
 
@@ -535,17 +535,17 @@  discard block
 block discarded – undo
535 535
 	public function enqueue_admin_scripts() {
536 536
 		// this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
537 537
 		// Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script calls.
538
-		wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE);
538
+		wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE);
539 539
 		// register cookie script for future dependencies
540
-		wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', array('jquery'), '2.1', TRUE );
540
+		wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js', array('jquery'), '2.1', TRUE);
541 541
 		//joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again vai: add_filter('FHEE_load_joyride', '__return_true' );
542
-		if ( apply_filters( 'FHEE_load_joyride', FALSE ) ) {
542
+		if (apply_filters('FHEE_load_joyride', FALSE)) {
543 543
 			//joyride style
544
-			wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
545
-			wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', array('joyride-css'), EVENT_ESPRESSO_VERSION );
546
-			wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', array(), '2.1', TRUE );
544
+			wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1');
545
+			wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', array('joyride-css'), EVENT_ESPRESSO_VERSION);
546
+			wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', array(), '2.1', TRUE);
547 547
 			//joyride JS
548
-			wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', array('jquery-cookie', 'joyride-modernizr'), '2.1', TRUE );
548
+			wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', array('jquery-cookie', 'joyride-modernizr'), '2.1', TRUE);
549 549
 			// wanna go for a joyride?
550 550
 			wp_enqueue_style('ee-joyride-css');
551 551
 			wp_enqueue_script('jquery-joyride');
@@ -575,11 +575,11 @@  discard block
 block discarded – undo
575 575
 	public function get_persistent_admin_notices() {
576 576
 		// http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30
577 577
 		$args = array(
578
-			'page' => EE_Registry::instance()->REQ->is_set( 'page' ) ? EE_Registry::instance()->REQ->get( 'page' ) : '',
579
-			'action' => EE_Registry::instance()->REQ->is_set( 'action' ) ? EE_Registry::instance()->REQ->get( 'action' ) : '',
578
+			'page' => EE_Registry::instance()->REQ->is_set('page') ? EE_Registry::instance()->REQ->get('page') : '',
579
+			'action' => EE_Registry::instance()->REQ->is_set('action') ? EE_Registry::instance()->REQ->get('action') : '',
580 580
 		);
581
-		$return_url = EE_Admin_Page::add_query_args_and_nonce( $args, EE_ADMIN_URL );
582
-		echo EE_Error::get_persistent_admin_notices( $return_url );
581
+		$return_url = EE_Admin_Page::add_query_args_and_nonce($args, EE_ADMIN_URL);
582
+		echo EE_Error::get_persistent_admin_notices($return_url);
583 583
 	}
584 584
 
585 585
 
@@ -604,24 +604,24 @@  discard block
 block discarded – undo
604 604
 	public function dashboard_glance_items($elements) {
605 605
         $elements = is_array($elements) ? $elements : array($elements);
606 606
 		$events = EEM_Event::instance()->count();
607
-		$items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_events'), admin_url('admin.php') );
608
-		$items['events']['text'] = sprintf( _n( '%s Event', '%s Events', $events ), number_format_i18n( $events ) );
607
+		$items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_events'), admin_url('admin.php'));
608
+		$items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events));
609 609
 		$items['events']['title'] = __('Click to view all Events', 'event_espresso');
610 610
 		$registrations = EEM_Registration::instance()->count(
611 611
 			array(
612 612
 				array(
613
-					'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete )
613
+					'STS_ID' => array('!=', EEM_Registration::status_id_incomplete)
614 614
 				)
615 615
 			)
616 616
 		);
617
-		$items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_registrations' ), admin_url('admin.php') );
618
-		$items['registrations']['text'] = sprintf( _n( '%s Registration', '%s Registrations', $registrations ), number_format_i18n($registrations) );
617
+		$items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_registrations'), admin_url('admin.php'));
618
+		$items['registrations']['text'] = sprintf(_n('%s Registration', '%s Registrations', $registrations), number_format_i18n($registrations));
619 619
 		$items['registrations']['title'] = __('Click to view all registrations', 'event_espresso');
620 620
 
621
-		$items = (array) apply_filters( 'FHEE__EE_Admin__dashboard_glance_items__items', $items );
621
+		$items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
622 622
 
623
-		foreach ( $items as $type => $item_properties ) {
624
-			$elements[] = sprintf( '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', $item_properties['url'], $item_properties['title'], $item_properties['text'] );
623
+		foreach ($items as $type => $item_properties) {
624
+			$elements[] = sprintf('<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>', $item_properties['url'], $item_properties['title'], $item_properties['text']);
625 625
 		}
626 626
 		return $elements;
627 627
 	}
@@ -638,31 +638,31 @@  discard block
 block discarded – undo
638 638
 	 * @throws EE_Error
639 639
 	 * @return    string
640 640
 	 */
641
-	public function check_for_invalid_datetime_formats( $value, $option ) {
641
+	public function check_for_invalid_datetime_formats($value, $option) {
642 642
 		// check for date_format or time_format
643
-		switch ( $option ) {
643
+		switch ($option) {
644 644
 			case 'date_format' :
645
-				$date_time_format = $value . ' ' . get_option('time_format');
645
+				$date_time_format = $value.' '.get_option('time_format');
646 646
 				break;
647 647
 			case 'time_format' :
648
-				$date_time_format = get_option('date_format') . ' ' . $value;
648
+				$date_time_format = get_option('date_format').' '.$value;
649 649
 				break;
650 650
 			default :
651 651
 				$date_time_format = FALSE;
652 652
 		}
653 653
 		// do we have a date_time format to check ?
654
-		if ( $date_time_format ) {
655
-			$error_msg = EEH_DTT_Helper::validate_format_string( $date_time_format );
654
+		if ($date_time_format) {
655
+			$error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
656 656
 
657
-			if ( is_array( $error_msg ) ) {
658
-				$msg = '<p>' . sprintf( __( 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', 'event_espresso' ), date( $date_time_format ) , $date_time_format  ) . '</p><p><ul>';
657
+			if (is_array($error_msg)) {
658
+				$msg = '<p>'.sprintf(__('The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', 'event_espresso'), date($date_time_format), $date_time_format).'</p><p><ul>';
659 659
 
660 660
 
661
-				foreach ( $error_msg as $error ) {
662
-					$msg .= '<li>' . $error . '</li>';
661
+				foreach ($error_msg as $error) {
662
+					$msg .= '<li>'.$error.'</li>';
663 663
 				}
664 664
 
665
-				$msg .= '</ul></p><p>' . sprintf( __( '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', 'event_espresso' ), '<span style="color:#D54E21;">', '</span>' ) . '</p>';
665
+				$msg .= '</ul></p><p>'.sprintf(__('%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', 'event_espresso'), '<span style="color:#D54E21;">', '</span>').'</p>';
666 666
 
667 667
 				// trigger WP settings error
668 668
 				add_settings_error(
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
 				);
673 673
 
674 674
 				// set format to something valid
675
-				switch ( $option ) {
675
+				switch ($option) {
676 676
 					case 'date_format' :
677 677
 						$value = 'F j, Y';
678 678
 						break;
@@ -694,8 +694,8 @@  discard block
 block discarded – undo
694 694
 	 * @param $content
695 695
 	 * @return    string
696 696
 	 */
697
-	public function its_eSpresso( $content ) {
698
-		return str_replace( '[EXPRESSO_', '[ESPRESSO_', $content );
697
+	public function its_eSpresso($content) {
698
+		return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
699 699
 	}
700 700
 
701 701
 
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
 	 *  @return 	string
708 708
 	 */
709 709
 	public function espresso_admin_footer() {
710
-		return \EEH_Template::powered_by_event_espresso( 'aln-cntr', '', array( 'utm_content' => 'admin_footer' ));
710
+		return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
711 711
 	}
712 712
 
713 713
 
@@ -726,12 +726,12 @@  discard block
 block discarded – undo
726 726
 	 * @param array $config
727 727
 	 * @return void
728 728
 	 */
729
-	public static function register_ee_admin_page( $page_basename, $page_path, $config = array() ) {
730
-		EE_Error::doing_it_wrong( __METHOD__, sprintf( __('Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.', 'event_espresso'), $page_basename), '4.3' );
731
-		if ( class_exists( 'EE_Register_Admin_Page' ) ) {
729
+	public static function register_ee_admin_page($page_basename, $page_path, $config = array()) {
730
+		EE_Error::doing_it_wrong(__METHOD__, sprintf(__('Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.', 'event_espresso'), $page_basename), '4.3');
731
+		if (class_exists('EE_Register_Admin_Page')) {
732 732
 			$config['page_path'] = $page_path;
733 733
 		}
734
-		EE_Register_Admin_Page::register( $page_basename, $config );
734
+		EE_Register_Admin_Page::register($page_basename, $config);
735 735
 
736 736
 	}
737 737
 
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
 	 * @param  \WP_Post $post
745 745
 	 * @return void
746 746
 	 */
747
-	public static function parse_post_content_on_save( $post_ID, $post ) {
747
+	public static function parse_post_content_on_save($post_ID, $post) {
748 748
 		EE_Error::doing_it_wrong(
749 749
 			__METHOD__,
750 750
 			__('Usage is deprecated', 'event_espresso'),
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
 	 * @param  $value
763 763
 	 * @return void
764 764
 	 */
765
-	public function reset_page_for_posts_on_change( $option, $old_value, $value ) {
765
+	public function reset_page_for_posts_on_change($option, $old_value, $value) {
766 766
 		EE_Error::doing_it_wrong(
767 767
 			__METHOD__,
768 768
 			__('Usage is deprecated', 'event_espresso'),
Please login to merge, or discard this patch.
core/interfaces/InterminableInterface.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\interfaces;
3 3
 
4
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
-	exit( 'No direct script access allowed' );
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
Please login to merge, or discard this patch.
core/request_stack/EE_Request.core.php 1 patch
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\interfaces\InterminableInterface;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -18,231 +18,231 @@  discard block
 block discarded – undo
18 18
 class EE_Request implements InterminableInterface
19 19
 {
20 20
 
21
-    /**
22
-     * @access private
23
-     * @var    array $_get $_GET parameters
24
-     */
25
-    private $_get = array();
26
-
27
-    /**
28
-     * @access private
29
-     * @var    array $_post $_POST parameters
30
-     */
31
-    private $_post = array();
32
-
33
-    /**
34
-     * @access private
35
-     * @var    array $_cookie $_COOKIE parameters
36
-     */
37
-    private $_cookie = array();
38
-
39
-    /**
40
-     * @access private
41
-     * @var    array $_params $_REQUEST parameters
42
-     */
43
-    private $_params = array();
44
-
45
-    /**
46
-     * whether current request is via AJAX
47
-     *
48
-     * @var    boolean
49
-     * @access public
50
-     */
51
-    public $ajax = false;
52
-
53
-    /**
54
-     * whether current request is via AJAX from the frontend of the site
55
-     *
56
-     * @var    boolean
57
-     * @access public
58
-     */
59
-    public $front_ajax = false;
60
-
61
-    /**
62
-     * IP address for request
63
-     *
64
-     * @var string $_ip_address
65
-     */
66
-    private $_ip_address = '';
67
-
68
-
69
-
70
-    /**
71
-     * class constructor
72
-     *
73
-     * @access    public
74
-     * @param array $get
75
-     * @param array $post
76
-     * @param array $cookie
77
-     */
78
-    public function __construct($get, $post, $cookie)
79
-    {
80
-        // grab request vars
81
-        $this->_get = (array)$get;
82
-        $this->_post = (array)$post;
83
-        $this->_cookie = (array)$cookie;
84
-        $this->_params = array_merge($this->_get, $this->_post);
85
-        // AJAX ???
86
-        $this->ajax = defined('DOING_AJAX') ? true : false;
87
-        $this->front_ajax = $this->is_set('ee_front_ajax') && (int)$this->get('ee_front_ajax') === 1;
88
-        // grab user IP
89
-        $this->_ip_address = $this->_visitor_ip();
90
-    }
91
-
92
-
93
-
94
-    /**
95
-     * @return array
96
-     */
97
-    public function get_params()
98
-    {
99
-        return $this->_get;
100
-    }
101
-
102
-
103
-
104
-    /**
105
-     * @return array
106
-     */
107
-    public function post_params()
108
-    {
109
-        return $this->_post;
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * @return array
116
-     */
117
-    public function cookie_params()
118
-    {
119
-        return $this->_cookie;
120
-    }
121
-
122
-
123
-
124
-    /**
125
-     * returns contents of $_REQUEST
126
-     *
127
-     * @return array
128
-     */
129
-    public function params()
130
-    {
131
-        return $this->_params;
132
-    }
133
-
134
-
135
-
136
-    /**
137
-     *    setter
138
-     *
139
-     * @access    public
140
-     * @param      $key
141
-     * @param      $value
142
-     * @param bool $override_ee
143
-     * @return    void
144
-     */
145
-    public function set($key, $value, $override_ee = false)
146
-    {
147
-        // don't allow "ee" to be overwritten unless explicitly instructed to do so
148
-        if (
149
-            $key !== 'ee'
150
-            || ($key === 'ee' && empty($this->_params['ee']))
151
-            || ($key === 'ee' && ! empty($this->_params['ee']) && $override_ee)
152
-        ) {
153
-            $this->_params[$key] = $value;
154
-        }
155
-    }
156
-
157
-
158
-
159
-    /**
160
-     *    getter
161
-     *
162
-     * @access    public
163
-     * @param      $key
164
-     * @param null $default
165
-     * @return    mixed
166
-     */
167
-    public function get($key, $default = null)
168
-    {
169
-        return isset($this->_params[$key]) ? $this->_params[$key] : $default;
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     *    check if param exists
176
-     *
177
-     * @access    public
178
-     * @param $key
179
-     * @return    boolean
180
-     */
181
-    public function is_set($key)
182
-    {
183
-        return isset($this->_params[$key]) ? true : false;
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     *    remove param
190
-     *
191
-     * @access    public
192
-     * @param      $key
193
-     * @param bool $unset_from_global_too
194
-     */
195
-    public function un_set($key, $unset_from_global_too = false)
196
-    {
197
-        unset($this->_params[$key]);
198
-        if ($unset_from_global_too) {
199
-            unset($_REQUEST[$key]);
200
-        }
201
-    }
202
-
203
-
204
-
205
-    /**
206
-     * @return string
207
-     */
208
-    public function ip_address()
209
-    {
210
-        return $this->_ip_address;
211
-    }
212
-
213
-
214
-
215
-    /**
216
-     * _visitor_ip
217
-     *    attempt to get IP address of current visitor from server
218
-     * plz see: http://stackoverflow.com/a/2031935/1475279
219
-     *
220
-     * @access public
221
-     * @return string
222
-     */
223
-    private function _visitor_ip()
224
-    {
225
-        $visitor_ip = '0.0.0.0';
226
-        $server_keys = array(
227
-            'HTTP_CLIENT_IP',
228
-            'HTTP_X_FORWARDED_FOR',
229
-            'HTTP_X_FORWARDED',
230
-            'HTTP_X_CLUSTER_CLIENT_IP',
231
-            'HTTP_FORWARDED_FOR',
232
-            'HTTP_FORWARDED',
233
-            'REMOTE_ADDR',
234
-        );
235
-        foreach ($server_keys as $key) {
236
-            if (isset($_SERVER[$key])) {
237
-                foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
238
-                    if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
239
-                        $visitor_ip = $ip;
240
-                    }
241
-                }
242
-            }
243
-        }
244
-        return $visitor_ip;
245
-    }
21
+	/**
22
+	 * @access private
23
+	 * @var    array $_get $_GET parameters
24
+	 */
25
+	private $_get = array();
26
+
27
+	/**
28
+	 * @access private
29
+	 * @var    array $_post $_POST parameters
30
+	 */
31
+	private $_post = array();
32
+
33
+	/**
34
+	 * @access private
35
+	 * @var    array $_cookie $_COOKIE parameters
36
+	 */
37
+	private $_cookie = array();
38
+
39
+	/**
40
+	 * @access private
41
+	 * @var    array $_params $_REQUEST parameters
42
+	 */
43
+	private $_params = array();
44
+
45
+	/**
46
+	 * whether current request is via AJAX
47
+	 *
48
+	 * @var    boolean
49
+	 * @access public
50
+	 */
51
+	public $ajax = false;
52
+
53
+	/**
54
+	 * whether current request is via AJAX from the frontend of the site
55
+	 *
56
+	 * @var    boolean
57
+	 * @access public
58
+	 */
59
+	public $front_ajax = false;
60
+
61
+	/**
62
+	 * IP address for request
63
+	 *
64
+	 * @var string $_ip_address
65
+	 */
66
+	private $_ip_address = '';
67
+
68
+
69
+
70
+	/**
71
+	 * class constructor
72
+	 *
73
+	 * @access    public
74
+	 * @param array $get
75
+	 * @param array $post
76
+	 * @param array $cookie
77
+	 */
78
+	public function __construct($get, $post, $cookie)
79
+	{
80
+		// grab request vars
81
+		$this->_get = (array)$get;
82
+		$this->_post = (array)$post;
83
+		$this->_cookie = (array)$cookie;
84
+		$this->_params = array_merge($this->_get, $this->_post);
85
+		// AJAX ???
86
+		$this->ajax = defined('DOING_AJAX') ? true : false;
87
+		$this->front_ajax = $this->is_set('ee_front_ajax') && (int)$this->get('ee_front_ajax') === 1;
88
+		// grab user IP
89
+		$this->_ip_address = $this->_visitor_ip();
90
+	}
91
+
92
+
93
+
94
+	/**
95
+	 * @return array
96
+	 */
97
+	public function get_params()
98
+	{
99
+		return $this->_get;
100
+	}
101
+
102
+
103
+
104
+	/**
105
+	 * @return array
106
+	 */
107
+	public function post_params()
108
+	{
109
+		return $this->_post;
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * @return array
116
+	 */
117
+	public function cookie_params()
118
+	{
119
+		return $this->_cookie;
120
+	}
121
+
122
+
123
+
124
+	/**
125
+	 * returns contents of $_REQUEST
126
+	 *
127
+	 * @return array
128
+	 */
129
+	public function params()
130
+	{
131
+		return $this->_params;
132
+	}
133
+
134
+
135
+
136
+	/**
137
+	 *    setter
138
+	 *
139
+	 * @access    public
140
+	 * @param      $key
141
+	 * @param      $value
142
+	 * @param bool $override_ee
143
+	 * @return    void
144
+	 */
145
+	public function set($key, $value, $override_ee = false)
146
+	{
147
+		// don't allow "ee" to be overwritten unless explicitly instructed to do so
148
+		if (
149
+			$key !== 'ee'
150
+			|| ($key === 'ee' && empty($this->_params['ee']))
151
+			|| ($key === 'ee' && ! empty($this->_params['ee']) && $override_ee)
152
+		) {
153
+			$this->_params[$key] = $value;
154
+		}
155
+	}
156
+
157
+
158
+
159
+	/**
160
+	 *    getter
161
+	 *
162
+	 * @access    public
163
+	 * @param      $key
164
+	 * @param null $default
165
+	 * @return    mixed
166
+	 */
167
+	public function get($key, $default = null)
168
+	{
169
+		return isset($this->_params[$key]) ? $this->_params[$key] : $default;
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 *    check if param exists
176
+	 *
177
+	 * @access    public
178
+	 * @param $key
179
+	 * @return    boolean
180
+	 */
181
+	public function is_set($key)
182
+	{
183
+		return isset($this->_params[$key]) ? true : false;
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 *    remove param
190
+	 *
191
+	 * @access    public
192
+	 * @param      $key
193
+	 * @param bool $unset_from_global_too
194
+	 */
195
+	public function un_set($key, $unset_from_global_too = false)
196
+	{
197
+		unset($this->_params[$key]);
198
+		if ($unset_from_global_too) {
199
+			unset($_REQUEST[$key]);
200
+		}
201
+	}
202
+
203
+
204
+
205
+	/**
206
+	 * @return string
207
+	 */
208
+	public function ip_address()
209
+	{
210
+		return $this->_ip_address;
211
+	}
212
+
213
+
214
+
215
+	/**
216
+	 * _visitor_ip
217
+	 *    attempt to get IP address of current visitor from server
218
+	 * plz see: http://stackoverflow.com/a/2031935/1475279
219
+	 *
220
+	 * @access public
221
+	 * @return string
222
+	 */
223
+	private function _visitor_ip()
224
+	{
225
+		$visitor_ip = '0.0.0.0';
226
+		$server_keys = array(
227
+			'HTTP_CLIENT_IP',
228
+			'HTTP_X_FORWARDED_FOR',
229
+			'HTTP_X_FORWARDED',
230
+			'HTTP_X_CLUSTER_CLIENT_IP',
231
+			'HTTP_FORWARDED_FOR',
232
+			'HTTP_FORWARDED',
233
+			'REMOTE_ADDR',
234
+		);
235
+		foreach ($server_keys as $key) {
236
+			if (isset($_SERVER[$key])) {
237
+				foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
238
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
239
+						$visitor_ip = $ip;
240
+					}
241
+				}
242
+			}
243
+		}
244
+		return $visitor_ip;
245
+	}
246 246
 
247 247
 
248 248
 
Please login to merge, or discard this patch.
core/EE_Psr4AutoloaderInit.core.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 use EventEspresso\core\Psr4Autoloader;
3 3
 
4
-if ( ! defined( 'EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
5 5
 
6 6
 /**
7 7
  * Class EE_Psr4AutoloaderInit
@@ -37,15 +37,15 @@  discard block
 block discarded – undo
37 37
 	 */
38 38
 	public static function initialize_psr4_loader() {
39 39
 		static $initialized = false;
40
-		if ( ! $initialized ) {
40
+		if ( ! $initialized) {
41 41
 			// instantiate PSR4 autoloader
42
-			espresso_load_required( 'Psr4Autoloader', EE_CORE . 'Psr4Autoloader.php' );
42
+			espresso_load_required('Psr4Autoloader', EE_CORE.'Psr4Autoloader.php');
43 43
 			EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader();
44 44
 			// register the autoloader
45 45
 			EE_Psr4AutoloaderInit::$psr4_loader->register();
46 46
 			// register the base directories for the namespace prefix
47
-			EE_Psr4AutoloaderInit::$psr4_loader->addNamespace( 'EventEspresso', EE_PLUGIN_DIR_PATH );
48
-			EE_Psr4AutoloaderInit::$psr4_loader->addNamespace( 'EventEspressoBatchRequest', EE_LIBRARIES . 'batch' );
47
+			EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH);
48
+			EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES.'batch');
49 49
 			$initialized = true;
50 50
 		}
51 51
 	}
Please login to merge, or discard this patch.
core/services/cache/TransientCacheStorage.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -234,7 +234,7 @@
 block discarded – undo
234 234
     /**
235 235
      * delete multiple transients and remove tracking
236 236
      *
237
-     * @param array $transient_keys [required] array of full or partial transient keys to be deleted
237
+     * @param string[] $transient_keys [required] array of full or partial transient keys to be deleted
238 238
      */
239 239
     public function deleteMany(array $transient_keys)
240 240
     {
Please login to merge, or discard this patch.
Unused Use Statements   -4 removed lines patch added patch discarded remove patch
@@ -1,10 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\services\cache;
3 3
 
4
-use EE_Error;
5
-use WP_Error;
6
-use wpdb;
7
-
8 4
 defined('EVENT_ESPRESSO_VERSION') || exit;
9 5
 
10 6
 
Please login to merge, or discard this patch.
Indentation   +355 added lines, -355 removed lines patch added patch discarded remove patch
@@ -23,361 +23,361 @@
 block discarded – undo
23 23
 class TransientCacheStorage implements CacheStorageInterface
24 24
 {
25 25
 
26
-    /**
27
-     * wp-option option_name for tracking transients
28
-     *
29
-     * @type string
30
-     */
31
-    const TRANSIENT_SCHEDULE_OPTIONS_KEY = 'ee_transient_schedule';
32
-
33
-    /**
34
-     * @var int $current_time
35
-     */
36
-    private $current_time = 0;
37
-
38
-    /**
39
-     * how often to perform transient cleanup
40
-     *
41
-     * @var string $transient_cleanup_frequency
42
-     */
43
-    private $transient_cleanup_frequency = 'hour';
44
-
45
-    /**
46
-     * options for how often to perform transient cleanup
47
-     *
48
-     * @var array $transient_cleanup_frequency_options
49
-     */
50
-    private $transient_cleanup_frequency_options = array();
51
-
52
-    /**
53
-     * @var array $transients
54
-     */
55
-    private $transients = array();
56
-
57
-
58
-
59
-    /**
60
-     * TransientCacheStorage constructor.
61
-     */
62
-    public function __construct()
63
-    {
64
-        $this->transient_cleanup_frequency = $this->setTransientCleanupFrequency();
65
-        // round current time down to closest 5 minutes to simplify scheduling
66
-        $this->current_time = $this->roundTimestamp(time(), '5-minutes', false);
67
-        $this->transients = (array)get_option(TransientCacheStorage::TRANSIENT_SCHEDULE_OPTIONS_KEY, array());
68
-        if ( ! (defined('DOING_AJAX') && DOING_AJAX) && $this->transient_cleanup_frequency !== 'off') {
69
-            add_action('shutdown', array($this, 'checkTransientCleanupSchedule'), 999);
70
-        }
71
-    }
72
-
73
-
74
-
75
-    /**
76
-     * Sets how often transient cleanup occurs
77
-     *
78
-     * @return int
79
-     */
80
-    private function setTransientCleanupFrequency()
81
-    {
82
-        // sets how often transients are cleaned up
83
-        $this->transient_cleanup_frequency_options = apply_filters(
84
-            'FHEE__TransientCacheStorage__transient_cleanup_schedule_options',
85
-            array(
86
-                'off',
87
-                '15-minutes',
88
-                'hour',
89
-                '12-hours',
90
-                'day',
91
-            )
92
-        );
93
-        $transient_cleanup_frequency = apply_filters(
94
-            'FHEE__TransientCacheStorage__transient_cleanup_schedule',
95
-            'hour'
96
-        );
97
-        return in_array(
98
-            $transient_cleanup_frequency,
99
-            $this->transient_cleanup_frequency_options,
100
-            true
101
-        )
102
-            ? $transient_cleanup_frequency
103
-            : 'hour';
104
-    }
105
-
106
-
107
-
108
-    /**
109
-     * we need to be able to round timestamps off to match the set transient cleanup frequency
110
-     * so if a transient is set to expire at 1:17 pm for example, and our cleanup schedule is every hour,
111
-     * then that timestamp needs to be rounded up to 2:00 pm so that it is removed
112
-     * during the next scheduled cleanup after its expiration.
113
-     * We also round off the current time timestamp to the closest 5 minutes
114
-     * just to make the timestamps a little easier to round which helps with debugging.
115
-     *
116
-     * @param int    $timestamp [required]
117
-     * @param string $cleanup_frequency
118
-     * @param bool   $round_up
119
-     * @return false|int
120
-     */
121
-    private function roundTimestamp($timestamp, $cleanup_frequency = 'hour', $round_up = true)
122
-    {
123
-        $cleanup_frequency = $cleanup_frequency ? $cleanup_frequency : $this->transient_cleanup_frequency;
124
-        // in order to round the time to the closest xx minutes (or hours),
125
-        // we take the minutes (or hours) portion of the timestamp and divide it by xx,
126
-        // round down to a whole number, then multiply by xx to bring us almost back up to where we were
127
-        // why round down ? so the minutes (or hours) don't go over 60 (or 24)
128
-        // and bump the hour, which could bump the day, which could bump the month, etc,
129
-        // which would be bad because we don't always want to round up,
130
-        // but when we do we can easily achieve that by simply adding the desired offset,
131
-        $minutes = '00';
132
-        $hours = 'H';
133
-        switch ($cleanup_frequency) {
134
-            case '5-minutes' :
135
-                $minutes = floor((int)date('i', $timestamp) / 5) * 5;
136
-                $minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT);
137
-                $offset = MINUTE_IN_SECONDS * 5;
138
-                break;
139
-            case '15-minutes' :
140
-                $minutes = floor((int)date('i', $timestamp) / 15) * 15;
141
-                $minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT);
142
-                $offset = MINUTE_IN_SECONDS * 15;
143
-                break;
144
-            case '12-hours' :
145
-                $hours = floor((int)date('H', $timestamp) / 12) * 12;
146
-                $hours = str_pad($hours, 2, '0', STR_PAD_LEFT);
147
-                $offset = HOUR_IN_SECONDS * 12;
148
-                break;
149
-            case 'day' :
150
-                $hours = '03'; // run cleanup at 3:00 am (or first site hit after that)
151
-                $offset = DAY_IN_SECONDS;
152
-                break;
153
-            case 'hour' :
154
-            default :
155
-                $offset = HOUR_IN_SECONDS;
156
-                break;
157
-        }
158
-        $rounded_timestamp = strtotime(date("Y-m-d {$hours}:{$minutes}:00", $timestamp));
159
-        $rounded_timestamp += $round_up ? $offset : 0;
160
-        return apply_filters(
161
-            'FHEE__TransientCacheStorage__roundTimestamp__timestamp',
162
-            $rounded_timestamp,
163
-            $timestamp,
164
-            $cleanup_frequency,
165
-            $round_up
166
-        );
167
-    }
168
-
169
-
170
-
171
-    /**
172
-     * Saves supplied data to a transient
173
-     * if an expiration is set, then it automatically schedules the transient for cleanup
174
-     *
175
-     * @param string $transient_key [required]
176
-     * @param string $data          [required]
177
-     * @param int    $expiration    number of seconds until the cache expires
178
-     * @return bool
179
-     */
180
-    public function add($transient_key, $data, $expiration = 0)
181
-    {
182
-        $expiration = (int)abs($expiration);
183
-        $saved = set_transient($transient_key, $data, $expiration);
184
-        if ($saved && $expiration) {
185
-            $this->scheduleTransientCleanup($transient_key, $expiration);
186
-        }
187
-        return $saved;
188
-    }
189
-
190
-
191
-
192
-    /**
193
-     * retrieves transient data
194
-     * automatically triggers early cache refresh for standard cache items
195
-     * in order to avoid cache stampedes on busy sites.
196
-     * For non-standard cache items like PHP Session data where early refreshing is not wanted,
197
-     * the $standard_cache parameter should be set to false when retrieving data
198
-     *
199
-     * @param string $transient_key [required]
200
-     * @param bool   $standard_cache
201
-     * @return mixed|null
202
-     */
203
-    public function get($transient_key, $standard_cache = true)
204
-    {
205
-        // to avoid cache stampedes (AKA:dogpiles) for standard cache items,
206
-        // check if known cache expires within the next minute,
207
-        // and if so, remove it from our tracking and and return nothing.
208
-        // this should trigger the cache content to be regenerated during this request,
209
-        // while allowing any following requests to still access the existing cache
210
-        // until it gets replaced with the refreshed content
211
-        if (
212
-            $standard_cache
213
-            && isset($this->transients[$transient_key])
214
-            && $this->transients[$transient_key] - time() <= MINUTE_IN_SECONDS
215
-        ) {
216
-            unset($this->transients[$transient_key]);
217
-            $this->updateTransients();
218
-            return null;
219
-        }
220
-        $content = get_transient($transient_key);
221
-        return $content !== false ? $content : null;
222
-    }
223
-
224
-
225
-
226
-    /**
227
-     * delete a single transient and remove tracking
228
-     *
229
-     * @param string $transient_key [required] full or partial transient key to be deleted
230
-     */
231
-    public function delete($transient_key)
232
-    {
233
-        $this->deleteMany(array($transient_key));
234
-    }
235
-
236
-
237
-
238
-    /**
239
-     * delete multiple transients and remove tracking
240
-     *
241
-     * @param array $transient_keys [required] array of full or partial transient keys to be deleted
242
-     */
243
-    public function deleteMany(array $transient_keys)
244
-    {
245
-        $full_transient_keys = array();
246
-        foreach ($this->transients as $transient_key => $expiration) {
247
-            foreach ($transient_keys as $transient_key_to_delete) {
248
-                if (strpos($transient_key, $transient_key_to_delete) !== false) {
249
-                    $full_transient_keys[] = $transient_key;
250
-                }
251
-            }
252
-        }
253
-        if ($this->deleteTransientKeys($full_transient_keys)) {
254
-            $this->updateTransients();
255
-        }
256
-    }
257
-
258
-
259
-
260
-    /**
261
-     * sorts transients numerically by timestamp
262
-     * then saves the transient schedule to a WP option
263
-     */
264
-    private function updateTransients()
265
-    {
266
-        asort($this->transients, SORT_NUMERIC);
267
-        update_option(
268
-            TransientCacheStorage::TRANSIENT_SCHEDULE_OPTIONS_KEY,
269
-            $this->transients
270
-        );
271
-    }
272
-
273
-
274
-
275
-    /**
276
-     * schedules a transient for cleanup by adding it to the transient tracking
277
-     *
278
-     * @param string $transient_key [required]
279
-     * @param int    $expiration    [required]
280
-     */
281
-    private function scheduleTransientCleanup($transient_key, $expiration)
282
-    {
283
-        // make sure a valid future timestamp is set
284
-        $expiration += $expiration < time() ? time() : 0;
285
-        // and round to the closest 15 minutes
286
-        $expiration = $this->roundTimestamp($expiration);
287
-        // save transients to clear using their ID as the key to avoid duplicates
288
-        $this->transients[$transient_key] = $expiration;
289
-        $this->updateTransients();
290
-    }
291
-
292
-
293
-
294
-    /**
295
-     * Since our tracked transients are sorted by their timestamps
296
-     * we can grab the first transient and see when it is scheduled for cleanup.
297
-     * If that timestamp is less than or equal to the current time,
298
-     * then cleanup is triggered
299
-     */
300
-    public function checkTransientCleanupSchedule()
301
-    {
302
-        if (empty($this->transients)) {
303
-            return;
304
-        }
305
-        // when do we run the next cleanup job?
306
-        reset($this->transients);
307
-        $next_scheduled_cleanup = current($this->transients);
308
-        // if the next cleanup job is scheduled for the current hour
309
-        if ($next_scheduled_cleanup <= $this->current_time) {
310
-            if ($this->cleanupExpiredTransients()) {
311
-                $this->updateTransients();
312
-            }
313
-        }
314
-    }
315
-
316
-
317
-
318
-    /**
319
-     * loops through the array of tracked transients,
320
-     * compiles a list of those that have expired, and sends that list off for deletion.
321
-     * Also removes any bad records from the transients array
322
-     *
323
-     * @return bool
324
-     */
325
-    private function cleanupExpiredTransients()
326
-    {
327
-        $update = false;
328
-        // filter the query limit. Set to 0 to turn off garbage collection
329
-        $limit = (int)abs(
330
-            apply_filters(
331
-                'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
332
-                50
333
-            )
334
-        );
335
-        // non-zero LIMIT means take out the trash
336
-        if ($limit) {
337
-            $transient_keys = array();
338
-            foreach ($this->transients as $transient_key => $expiration) {
339
-                if ($expiration > $this->current_time) {
340
-                    continue;
341
-                }
342
-                if ( ! $expiration || ! $transient_key) {
343
-                    unset($this->transients[$transient_key]);
344
-                    $update = true;
345
-                    continue;
346
-                }
347
-                $transient_keys[] = $transient_key;
348
-            }
349
-            // delete expired keys, but maintain value of $update if nothing is deleted
350
-            $update = $this->deleteTransientKeys($transient_keys, $limit) ? true : $update;
351
-            do_action( 'FHEE__TransientCacheStorage__clearExpiredTransients__end', $this);
352
-        }
353
-        return $update;
354
-    }
355
-
356
-
357
-
358
-    /**
359
-     * calls delete_transient() on each transient key provided, up to the specified limit
360
-     *
361
-     * @param array $transient_keys [required]
362
-     * @param int   $limit
363
-     * @return bool
364
-     */
365
-    private function deleteTransientKeys(array $transient_keys, $limit = 50)
366
-    {
367
-        if (empty($transient_keys)) {
368
-            return false;
369
-        }
370
-        $counter = 0;
371
-        foreach ($transient_keys as $transient_key) {
372
-            if($counter === $limit){
373
-                break;
374
-            }
375
-            delete_transient($transient_key);
376
-            unset($this->transients[$transient_key]);
377
-            $counter++;
378
-        }
379
-        return $counter > 0;
380
-    }
26
+	/**
27
+	 * wp-option option_name for tracking transients
28
+	 *
29
+	 * @type string
30
+	 */
31
+	const TRANSIENT_SCHEDULE_OPTIONS_KEY = 'ee_transient_schedule';
32
+
33
+	/**
34
+	 * @var int $current_time
35
+	 */
36
+	private $current_time = 0;
37
+
38
+	/**
39
+	 * how often to perform transient cleanup
40
+	 *
41
+	 * @var string $transient_cleanup_frequency
42
+	 */
43
+	private $transient_cleanup_frequency = 'hour';
44
+
45
+	/**
46
+	 * options for how often to perform transient cleanup
47
+	 *
48
+	 * @var array $transient_cleanup_frequency_options
49
+	 */
50
+	private $transient_cleanup_frequency_options = array();
51
+
52
+	/**
53
+	 * @var array $transients
54
+	 */
55
+	private $transients = array();
56
+
57
+
58
+
59
+	/**
60
+	 * TransientCacheStorage constructor.
61
+	 */
62
+	public function __construct()
63
+	{
64
+		$this->transient_cleanup_frequency = $this->setTransientCleanupFrequency();
65
+		// round current time down to closest 5 minutes to simplify scheduling
66
+		$this->current_time = $this->roundTimestamp(time(), '5-minutes', false);
67
+		$this->transients = (array)get_option(TransientCacheStorage::TRANSIENT_SCHEDULE_OPTIONS_KEY, array());
68
+		if ( ! (defined('DOING_AJAX') && DOING_AJAX) && $this->transient_cleanup_frequency !== 'off') {
69
+			add_action('shutdown', array($this, 'checkTransientCleanupSchedule'), 999);
70
+		}
71
+	}
72
+
73
+
74
+
75
+	/**
76
+	 * Sets how often transient cleanup occurs
77
+	 *
78
+	 * @return int
79
+	 */
80
+	private function setTransientCleanupFrequency()
81
+	{
82
+		// sets how often transients are cleaned up
83
+		$this->transient_cleanup_frequency_options = apply_filters(
84
+			'FHEE__TransientCacheStorage__transient_cleanup_schedule_options',
85
+			array(
86
+				'off',
87
+				'15-minutes',
88
+				'hour',
89
+				'12-hours',
90
+				'day',
91
+			)
92
+		);
93
+		$transient_cleanup_frequency = apply_filters(
94
+			'FHEE__TransientCacheStorage__transient_cleanup_schedule',
95
+			'hour'
96
+		);
97
+		return in_array(
98
+			$transient_cleanup_frequency,
99
+			$this->transient_cleanup_frequency_options,
100
+			true
101
+		)
102
+			? $transient_cleanup_frequency
103
+			: 'hour';
104
+	}
105
+
106
+
107
+
108
+	/**
109
+	 * we need to be able to round timestamps off to match the set transient cleanup frequency
110
+	 * so if a transient is set to expire at 1:17 pm for example, and our cleanup schedule is every hour,
111
+	 * then that timestamp needs to be rounded up to 2:00 pm so that it is removed
112
+	 * during the next scheduled cleanup after its expiration.
113
+	 * We also round off the current time timestamp to the closest 5 minutes
114
+	 * just to make the timestamps a little easier to round which helps with debugging.
115
+	 *
116
+	 * @param int    $timestamp [required]
117
+	 * @param string $cleanup_frequency
118
+	 * @param bool   $round_up
119
+	 * @return false|int
120
+	 */
121
+	private function roundTimestamp($timestamp, $cleanup_frequency = 'hour', $round_up = true)
122
+	{
123
+		$cleanup_frequency = $cleanup_frequency ? $cleanup_frequency : $this->transient_cleanup_frequency;
124
+		// in order to round the time to the closest xx minutes (or hours),
125
+		// we take the minutes (or hours) portion of the timestamp and divide it by xx,
126
+		// round down to a whole number, then multiply by xx to bring us almost back up to where we were
127
+		// why round down ? so the minutes (or hours) don't go over 60 (or 24)
128
+		// and bump the hour, which could bump the day, which could bump the month, etc,
129
+		// which would be bad because we don't always want to round up,
130
+		// but when we do we can easily achieve that by simply adding the desired offset,
131
+		$minutes = '00';
132
+		$hours = 'H';
133
+		switch ($cleanup_frequency) {
134
+			case '5-minutes' :
135
+				$minutes = floor((int)date('i', $timestamp) / 5) * 5;
136
+				$minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT);
137
+				$offset = MINUTE_IN_SECONDS * 5;
138
+				break;
139
+			case '15-minutes' :
140
+				$minutes = floor((int)date('i', $timestamp) / 15) * 15;
141
+				$minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT);
142
+				$offset = MINUTE_IN_SECONDS * 15;
143
+				break;
144
+			case '12-hours' :
145
+				$hours = floor((int)date('H', $timestamp) / 12) * 12;
146
+				$hours = str_pad($hours, 2, '0', STR_PAD_LEFT);
147
+				$offset = HOUR_IN_SECONDS * 12;
148
+				break;
149
+			case 'day' :
150
+				$hours = '03'; // run cleanup at 3:00 am (or first site hit after that)
151
+				$offset = DAY_IN_SECONDS;
152
+				break;
153
+			case 'hour' :
154
+			default :
155
+				$offset = HOUR_IN_SECONDS;
156
+				break;
157
+		}
158
+		$rounded_timestamp = strtotime(date("Y-m-d {$hours}:{$minutes}:00", $timestamp));
159
+		$rounded_timestamp += $round_up ? $offset : 0;
160
+		return apply_filters(
161
+			'FHEE__TransientCacheStorage__roundTimestamp__timestamp',
162
+			$rounded_timestamp,
163
+			$timestamp,
164
+			$cleanup_frequency,
165
+			$round_up
166
+		);
167
+	}
168
+
169
+
170
+
171
+	/**
172
+	 * Saves supplied data to a transient
173
+	 * if an expiration is set, then it automatically schedules the transient for cleanup
174
+	 *
175
+	 * @param string $transient_key [required]
176
+	 * @param string $data          [required]
177
+	 * @param int    $expiration    number of seconds until the cache expires
178
+	 * @return bool
179
+	 */
180
+	public function add($transient_key, $data, $expiration = 0)
181
+	{
182
+		$expiration = (int)abs($expiration);
183
+		$saved = set_transient($transient_key, $data, $expiration);
184
+		if ($saved && $expiration) {
185
+			$this->scheduleTransientCleanup($transient_key, $expiration);
186
+		}
187
+		return $saved;
188
+	}
189
+
190
+
191
+
192
+	/**
193
+	 * retrieves transient data
194
+	 * automatically triggers early cache refresh for standard cache items
195
+	 * in order to avoid cache stampedes on busy sites.
196
+	 * For non-standard cache items like PHP Session data where early refreshing is not wanted,
197
+	 * the $standard_cache parameter should be set to false when retrieving data
198
+	 *
199
+	 * @param string $transient_key [required]
200
+	 * @param bool   $standard_cache
201
+	 * @return mixed|null
202
+	 */
203
+	public function get($transient_key, $standard_cache = true)
204
+	{
205
+		// to avoid cache stampedes (AKA:dogpiles) for standard cache items,
206
+		// check if known cache expires within the next minute,
207
+		// and if so, remove it from our tracking and and return nothing.
208
+		// this should trigger the cache content to be regenerated during this request,
209
+		// while allowing any following requests to still access the existing cache
210
+		// until it gets replaced with the refreshed content
211
+		if (
212
+			$standard_cache
213
+			&& isset($this->transients[$transient_key])
214
+			&& $this->transients[$transient_key] - time() <= MINUTE_IN_SECONDS
215
+		) {
216
+			unset($this->transients[$transient_key]);
217
+			$this->updateTransients();
218
+			return null;
219
+		}
220
+		$content = get_transient($transient_key);
221
+		return $content !== false ? $content : null;
222
+	}
223
+
224
+
225
+
226
+	/**
227
+	 * delete a single transient and remove tracking
228
+	 *
229
+	 * @param string $transient_key [required] full or partial transient key to be deleted
230
+	 */
231
+	public function delete($transient_key)
232
+	{
233
+		$this->deleteMany(array($transient_key));
234
+	}
235
+
236
+
237
+
238
+	/**
239
+	 * delete multiple transients and remove tracking
240
+	 *
241
+	 * @param array $transient_keys [required] array of full or partial transient keys to be deleted
242
+	 */
243
+	public function deleteMany(array $transient_keys)
244
+	{
245
+		$full_transient_keys = array();
246
+		foreach ($this->transients as $transient_key => $expiration) {
247
+			foreach ($transient_keys as $transient_key_to_delete) {
248
+				if (strpos($transient_key, $transient_key_to_delete) !== false) {
249
+					$full_transient_keys[] = $transient_key;
250
+				}
251
+			}
252
+		}
253
+		if ($this->deleteTransientKeys($full_transient_keys)) {
254
+			$this->updateTransients();
255
+		}
256
+	}
257
+
258
+
259
+
260
+	/**
261
+	 * sorts transients numerically by timestamp
262
+	 * then saves the transient schedule to a WP option
263
+	 */
264
+	private function updateTransients()
265
+	{
266
+		asort($this->transients, SORT_NUMERIC);
267
+		update_option(
268
+			TransientCacheStorage::TRANSIENT_SCHEDULE_OPTIONS_KEY,
269
+			$this->transients
270
+		);
271
+	}
272
+
273
+
274
+
275
+	/**
276
+	 * schedules a transient for cleanup by adding it to the transient tracking
277
+	 *
278
+	 * @param string $transient_key [required]
279
+	 * @param int    $expiration    [required]
280
+	 */
281
+	private function scheduleTransientCleanup($transient_key, $expiration)
282
+	{
283
+		// make sure a valid future timestamp is set
284
+		$expiration += $expiration < time() ? time() : 0;
285
+		// and round to the closest 15 minutes
286
+		$expiration = $this->roundTimestamp($expiration);
287
+		// save transients to clear using their ID as the key to avoid duplicates
288
+		$this->transients[$transient_key] = $expiration;
289
+		$this->updateTransients();
290
+	}
291
+
292
+
293
+
294
+	/**
295
+	 * Since our tracked transients are sorted by their timestamps
296
+	 * we can grab the first transient and see when it is scheduled for cleanup.
297
+	 * If that timestamp is less than or equal to the current time,
298
+	 * then cleanup is triggered
299
+	 */
300
+	public function checkTransientCleanupSchedule()
301
+	{
302
+		if (empty($this->transients)) {
303
+			return;
304
+		}
305
+		// when do we run the next cleanup job?
306
+		reset($this->transients);
307
+		$next_scheduled_cleanup = current($this->transients);
308
+		// if the next cleanup job is scheduled for the current hour
309
+		if ($next_scheduled_cleanup <= $this->current_time) {
310
+			if ($this->cleanupExpiredTransients()) {
311
+				$this->updateTransients();
312
+			}
313
+		}
314
+	}
315
+
316
+
317
+
318
+	/**
319
+	 * loops through the array of tracked transients,
320
+	 * compiles a list of those that have expired, and sends that list off for deletion.
321
+	 * Also removes any bad records from the transients array
322
+	 *
323
+	 * @return bool
324
+	 */
325
+	private function cleanupExpiredTransients()
326
+	{
327
+		$update = false;
328
+		// filter the query limit. Set to 0 to turn off garbage collection
329
+		$limit = (int)abs(
330
+			apply_filters(
331
+				'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
332
+				50
333
+			)
334
+		);
335
+		// non-zero LIMIT means take out the trash
336
+		if ($limit) {
337
+			$transient_keys = array();
338
+			foreach ($this->transients as $transient_key => $expiration) {
339
+				if ($expiration > $this->current_time) {
340
+					continue;
341
+				}
342
+				if ( ! $expiration || ! $transient_key) {
343
+					unset($this->transients[$transient_key]);
344
+					$update = true;
345
+					continue;
346
+				}
347
+				$transient_keys[] = $transient_key;
348
+			}
349
+			// delete expired keys, but maintain value of $update if nothing is deleted
350
+			$update = $this->deleteTransientKeys($transient_keys, $limit) ? true : $update;
351
+			do_action( 'FHEE__TransientCacheStorage__clearExpiredTransients__end', $this);
352
+		}
353
+		return $update;
354
+	}
355
+
356
+
357
+
358
+	/**
359
+	 * calls delete_transient() on each transient key provided, up to the specified limit
360
+	 *
361
+	 * @param array $transient_keys [required]
362
+	 * @param int   $limit
363
+	 * @return bool
364
+	 */
365
+	private function deleteTransientKeys(array $transient_keys, $limit = 50)
366
+	{
367
+		if (empty($transient_keys)) {
368
+			return false;
369
+		}
370
+		$counter = 0;
371
+		foreach ($transient_keys as $transient_key) {
372
+			if($counter === $limit){
373
+				break;
374
+			}
375
+			delete_transient($transient_key);
376
+			unset($this->transients[$transient_key]);
377
+			$counter++;
378
+		}
379
+		return $counter > 0;
380
+	}
381 381
 
382 382
 
383 383
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
         $this->transient_cleanup_frequency = $this->setTransientCleanupFrequency();
65 65
         // round current time down to closest 5 minutes to simplify scheduling
66 66
         $this->current_time = $this->roundTimestamp(time(), '5-minutes', false);
67
-        $this->transients = (array)get_option(TransientCacheStorage::TRANSIENT_SCHEDULE_OPTIONS_KEY, array());
67
+        $this->transients = (array) get_option(TransientCacheStorage::TRANSIENT_SCHEDULE_OPTIONS_KEY, array());
68 68
         if ( ! (defined('DOING_AJAX') && DOING_AJAX) && $this->transient_cleanup_frequency !== 'off') {
69 69
             add_action('shutdown', array($this, 'checkTransientCleanupSchedule'), 999);
70 70
         }
@@ -132,17 +132,17 @@  discard block
 block discarded – undo
132 132
         $hours = 'H';
133 133
         switch ($cleanup_frequency) {
134 134
             case '5-minutes' :
135
-                $minutes = floor((int)date('i', $timestamp) / 5) * 5;
135
+                $minutes = floor((int) date('i', $timestamp) / 5) * 5;
136 136
                 $minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT);
137 137
                 $offset = MINUTE_IN_SECONDS * 5;
138 138
                 break;
139 139
             case '15-minutes' :
140
-                $minutes = floor((int)date('i', $timestamp) / 15) * 15;
140
+                $minutes = floor((int) date('i', $timestamp) / 15) * 15;
141 141
                 $minutes = str_pad($minutes, 2, '0', STR_PAD_LEFT);
142 142
                 $offset = MINUTE_IN_SECONDS * 15;
143 143
                 break;
144 144
             case '12-hours' :
145
-                $hours = floor((int)date('H', $timestamp) / 12) * 12;
145
+                $hours = floor((int) date('H', $timestamp) / 12) * 12;
146 146
                 $hours = str_pad($hours, 2, '0', STR_PAD_LEFT);
147 147
                 $offset = HOUR_IN_SECONDS * 12;
148 148
                 break;
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
      */
180 180
     public function add($transient_key, $data, $expiration = 0)
181 181
     {
182
-        $expiration = (int)abs($expiration);
182
+        $expiration = (int) abs($expiration);
183 183
         $saved = set_transient($transient_key, $data, $expiration);
184 184
         if ($saved && $expiration) {
185 185
             $this->scheduleTransientCleanup($transient_key, $expiration);
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
     {
327 327
         $update = false;
328 328
         // filter the query limit. Set to 0 to turn off garbage collection
329
-        $limit = (int)abs(
329
+        $limit = (int) abs(
330 330
             apply_filters(
331 331
                 'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
332 332
                 50
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
             }
349 349
             // delete expired keys, but maintain value of $update if nothing is deleted
350 350
             $update = $this->deleteTransientKeys($transient_keys, $limit) ? true : $update;
351
-            do_action( 'FHEE__TransientCacheStorage__clearExpiredTransients__end', $this);
351
+            do_action('FHEE__TransientCacheStorage__clearExpiredTransients__end', $this);
352 352
         }
353 353
         return $update;
354 354
     }
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
         }
370 370
         $counter = 0;
371 371
         foreach ($transient_keys as $transient_key) {
372
-            if($counter === $limit){
372
+            if ($counter === $limit) {
373 373
                 break;
374 374
             }
375 375
             delete_transient($transient_key);
Please login to merge, or discard this patch.
core/services/container/CoffeeShop.php 1 patch
Indentation   +497 added lines, -497 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 use OutOfBoundsException;
14 14
 
15 15
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
16
-    exit('No direct script access allowed');
16
+	exit('No direct script access allowed');
17 17
 }
18 18
 
19 19
 
@@ -32,502 +32,502 @@  discard block
 block discarded – undo
32 32
 {
33 33
 
34 34
 
35
-    /**
36
-     * This was the best coffee related name I could think of to represent class name "aliases"
37
-     * So classes can be found via an alias identifier,
38
-     * that is revealed when it is run through... the filters... eh? get it?
39
-     *
40
-     * @var array $filters
41
-     */
42
-    private $filters = array();
43
-
44
-    /**
45
-     * These are the classes that will actually build the objects (to order of course)
46
-     *
47
-     * @var array $coffee_makers
48
-     */
49
-    private $coffee_makers = array();
50
-
51
-    /**
52
-     * where the instantiated "singleton" objects are stored
53
-     *
54
-     * @var CollectionInterface $carafe
55
-     */
56
-    private $carafe;
57
-
58
-    /**
59
-     * collection of Recipes that instruct us how to brew objects
60
-     *
61
-     * @var CollectionInterface $recipes
62
-     */
63
-    private $recipes;
64
-
65
-    /**
66
-     * collection of closures for brewing objects
67
-     *
68
-     * @var CollectionInterface $reservoir
69
-     */
70
-    private $reservoir;
71
-
72
-
73
-
74
-    /**
75
-     * CoffeeShop constructor
76
-     */
77
-    public function __construct()
78
-    {
79
-        // array for storing class aliases
80
-        $this->filters = array();
81
-        // create collection for storing shared services
82
-        $this->carafe = new LooseCollection( '' );
83
-        // create collection for storing recipes that tell how to build services and entities
84
-        $this->recipes = new Collection('EventEspresso\core\services\container\RecipeInterface');
85
-        // create collection for storing closures for constructing new entities
86
-        $this->reservoir = new Collection('Closure');
87
-        // create collection for storing the generators that build our services and entity closures
88
-        $this->coffee_makers = new Collection('EventEspresso\core\services\container\CoffeeMakerInterface');
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * Returns true if the container can return an entry for the given identifier.
95
-     * Returns false otherwise.
96
-     * `has($identifier)` returning true does not mean that `get($identifier)` will not throw an exception.
97
-     * It does however mean that `get($identifier)` will not throw a `ServiceNotFoundException`.
98
-     *
99
-     * @param string $identifier  Identifier of the entry to look for.
100
-     *                            Typically a Fully Qualified Class Name
101
-     * @return boolean
102
-     */
103
-    public function has($identifier)
104
-    {
105
-        $identifier = $this->filterIdentifier($identifier);
106
-        return $this->carafe->has($identifier);
107
-    }
108
-
109
-
110
-
111
-    /**
112
-     * finds a previously brewed (SHARED) service and returns it
113
-     *
114
-     * @param  string $identifier Identifier for the entity class to be constructed.
115
-     *                            Typically a Fully Qualified Class Name
116
-     * @return mixed
117
-     * @throws ServiceNotFoundException No service was found for this identifier.
118
-     */
119
-    public function get($identifier)
120
-    {
121
-        $identifier = $this->filterIdentifier($identifier);
122
-        if ($this->carafe->has($identifier)) {
123
-            return $this->carafe->get($identifier);
124
-        }
125
-        throw new ServiceNotFoundException($identifier);
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * returns an instance of the requested entity type using the supplied arguments.
132
-     * If a shared service is requested and an instance is already in the carafe, then it will be returned.
133
-     * If it is not already in the carafe, then the service will be constructed, added to the carafe, and returned
134
-     * If the request is for a new entity and a closure exists in the reservoir for creating it,
135
-     * then a new entity will be instantiated from the closure and returned.
136
-     * If a closure does not exist, then one will be built and added to the reservoir
137
-     * before instantiating the requested entity.
138
-     *
139
-     * @param  string $identifier Identifier for the entity class to be constructed.
140
-     *                            Typically a Fully Qualified Class Name
141
-     * @param array   $arguments  an array of arguments to be passed to the entity constructor
142
-     * @param string  $type
143
-     * @return mixed
144
-     * @throws ServiceNotFoundException No service was found for this identifier.
145
-     */
146
-    public function brew($identifier, $arguments = array(), $type = '')
147
-    {
148
-        // resolve any class aliases that may exist
149
-        $identifier = $this->filterIdentifier($identifier);
150
-        try {
151
-            // is a shared service being requested?
152
-            if (empty($type) || $type === CoffeeMaker::BREW_SHARED) {
153
-                // if a shared service was requested and an instance is in the carafe, then return it
154
-                return $this->get($identifier);
155
-            }
156
-        } catch (ServiceNotFoundException $e) {
157
-            // if not then we'll just catch the ServiceNotFoundException but not do anything just yet,
158
-            // and instead, attempt to build whatever was requested
159
-        }
160
-        $brewed = false;
161
-        // if the reservoir doesn't have a closure already for the requested identifier,
162
-        // then neither a shared service nor a closure for making entities has been built yet
163
-        if ( ! $this->reservoir->has($identifier)) {
164
-            // so let's brew something up and add it to the proper collection
165
-            $brewed = $this->makeCoffee($identifier, $arguments, $type);
166
-        }
167
-        // was the brewed item a callable factory function ?
168
-        if (is_callable($brewed)) {
169
-            // then instantiate a new entity from the cached closure
170
-            $entity = $brewed($arguments);
171
-        } else if ($brewed) {
172
-            // requested object was a shared entity, so attempt to get it from the carafe again
173
-            // because if it wasn't there before, then it should have just been brewed and added,
174
-            // but if it still isn't there, then this time
175
-            // the thrown ServiceNotFoundException will not be caught
176
-            $entity = $this->get($identifier);
177
-        } else {
178
-            // if identifier is for a non-shared entity,
179
-            // then either a cached closure already existed, or was just brewed
180
-            $closure = $this->reservoir->get($identifier);
181
-            $entity = $closure($arguments);
182
-        }
183
-        return $entity;
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * @param CoffeeMakerInterface $coffee_maker
190
-     * @param string               $type
191
-     * @return bool
192
-     */
193
-    public function addCoffeeMaker(CoffeeMakerInterface $coffee_maker, $type)
194
-    {
195
-        $type = CoffeeMaker::validateType($type);
196
-        return $this->coffee_makers->add($coffee_maker, $type);
197
-    }
198
-
199
-
200
-
201
-    /**
202
-     * @param string   $identifier
203
-     * @param callable $closure
204
-     * @return callable|null
205
-     */
206
-    public function addClosure($identifier, $closure)
207
-    {
208
-        if ( ! is_callable($closure)) {
209
-            throw new InvalidDataTypeException('$closure', $closure, 'Closure');
210
-        }
211
-        $identifier = $this->processIdentifier($identifier);
212
-        if ($this->reservoir->add($closure, $identifier)) {
213
-            return $closure;
214
-        }
215
-        return null;
216
-    }
217
-
218
-
219
-
220
-    /**
221
-     * @param string   $identifier
222
-     * @return boolean
223
-     */
224
-    public function removeClosure($identifier)
225
-    {
226
-        $identifier = $this->processIdentifier($identifier);
227
-        if ($this->reservoir->has($identifier)) {
228
-            $this->reservoir->remove($this->reservoir->get($identifier));
229
-            if ( ! $this->reservoir->has($identifier)) {
230
-                return true;
231
-            }
232
-        }
233
-        return false;
234
-    }
235
-
236
-
237
-
238
-    /**
239
-     * @param  string $identifier Identifier for the entity class that the service applies to
240
-     *                            Typically a Fully Qualified Class Name
241
-     * @param mixed  $service
242
-     * @return bool
243
-     */
244
-    public function addService($identifier, $service)
245
-    {
246
-        $identifier = $this->processIdentifier($identifier);
247
-        $service = $this->validateService($identifier, $service);
248
-        return $this->carafe->add($service, $identifier);
249
-    }
250
-
251
-
252
-
253
-    /**
254
-     * @param string $identifier
255
-     * @return boolean
256
-     */
257
-    public function removeService($identifier)
258
-    {
259
-        $identifier = $this->processIdentifier($identifier);
260
-        if ($this->carafe->has($identifier)) {
261
-            $this->carafe->remove($this->carafe->get($identifier));
262
-            if ( ! $this->carafe->has($identifier)) {
263
-                return true;
264
-            }
265
-        }
266
-        return false;
267
-    }
268
-
269
-
270
-
271
-    /**
272
-     * Adds instructions on how to brew objects
273
-     *
274
-     * @param RecipeInterface $recipe
275
-     * @return mixed
276
-     */
277
-    public function addRecipe(RecipeInterface $recipe)
278
-    {
279
-        $this->addAliases($recipe->identifier(), $recipe->filters());
280
-        $identifier = $this->processIdentifier($recipe->identifier());
281
-        return $this->recipes->add($recipe, $identifier);
282
-    }
283
-
284
-
285
-
286
-    /**
287
-     * @param string $identifier The Recipe's identifier
288
-     * @return boolean
289
-     */
290
-    public function removeRecipe($identifier)
291
-    {
292
-        $identifier = $this->processIdentifier($identifier);
293
-        if ($this->recipes->has($identifier)) {
294
-            $this->recipes->remove(
295
-                $this->recipes->get($identifier)
296
-            );
297
-            if ( ! $this->recipes->has($identifier)) {
298
-                return true;
299
-            }
300
-        }
301
-        return false;
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * Get instructions on how to brew objects
308
-     *
309
-     * @param  string $identifier Identifier for the entity class that the recipe applies to
310
-     *                            Typically a Fully Qualified Class Name
311
-     * @param string $type
312
-     * @return RecipeInterface
313
-     */
314
-    public function getRecipe($identifier, $type = '')
315
-    {
316
-        $identifier = $this->processIdentifier($identifier);
317
-        if ($this->recipes->has($identifier)) {
318
-            return $this->recipes->get($identifier);
319
-        }
320
-        $default_recipes = $this->getDefaultRecipes();
321
-        $matches = array();
322
-        foreach ($default_recipes as $wildcard => $default_recipe) {
323
-            // is the wildcard recipe prefix in the identifier ?
324
-            if (strpos($identifier, $wildcard) !== false) {
325
-                // track matches and use the number of wildcard characters matched for the key
326
-                $matches[strlen($wildcard)] = $default_recipe;
327
-            }
328
-        }
329
-        if (count($matches) > 0) {
330
-            // sort our recipes by the number of wildcard characters matched
331
-            ksort($matches);
332
-            // then grab the last recipe form the list, since it had the most matching characters
333
-            $match = array_pop($matches);
334
-            // since we are using a default recipe, we need to set it's identifier and fqcn
335
-            return $this->copyDefaultRecipe($match, $identifier, $type);
336
-        }
337
-        if ($this->recipes->has(Recipe::DEFAULT_ID)) {
338
-            // since we are using a default recipe, we need to set it's identifier and fqcn
339
-            return $this->copyDefaultRecipe($this->recipes->get(Recipe::DEFAULT_ID), $identifier, $type);
340
-        }
341
-        throw new OutOfBoundsException(
342
-            sprintf(
343
-                __('Could not brew coffee because no recipes were found for class "%1$s".', 'event_espresso'),
344
-                $identifier
345
-            )
346
-        );
347
-    }
348
-
349
-
350
-
351
-    /**
352
-     * adds class name aliases to list of filters
353
-     *
354
-     * @param  string       $identifier Identifier for the entity class that the alias applies to
355
-     *                                  Typically a Fully Qualified Class Name
356
-     * @param  array|string $aliases
357
-     * @return void
358
-     * @throws InvalidIdentifierException
359
-     */
360
-    public function addAliases($identifier, $aliases)
361
-    {
362
-        if (empty($aliases)) {
363
-            return;
364
-        }
365
-        $identifier = $this->processIdentifier($identifier);
366
-        foreach ((array)$aliases as $alias) {
367
-            $this->filters[$this->processIdentifier($alias)] = $identifier;
368
-        }
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * Adds a service to one of the internal collections
375
-     *
376
-     * @param        $identifier
377
-     * @param array  $arguments
378
-     * @param string $type
379
-     * @return mixed
380
-     * @throws ServiceExistsException
381
-     */
382
-    private function makeCoffee($identifier, $arguments = array(), $type = '')
383
-    {
384
-        if ((empty($type) || $type === CoffeeMaker::BREW_SHARED) && $this->has($identifier)) {
385
-            throw new ServiceExistsException($identifier);
386
-        }
387
-        $identifier = $this->filterIdentifier($identifier);
388
-        $recipe = $this->getRecipe($identifier, $type);
389
-        $type = ! empty($type) ? $type : $recipe->type();
390
-        $coffee_maker = $this->getCoffeeMaker($type);
391
-        return $coffee_maker->brew($recipe, $arguments);
392
-    }
393
-
394
-
395
-
396
-    /**
397
-     * filters alias identifiers to find the real class name
398
-     *
399
-     * @param  string $identifier Identifier for the entity class that the filter applies to
400
-     *                            Typically a Fully Qualified Class Name
401
-     * @return string
402
-     * @throws InvalidIdentifierException
403
-     */
404
-    private function filterIdentifier($identifier)
405
-    {
406
-        $identifier = $this->processIdentifier($identifier);
407
-        return isset($this->filters[$identifier]) && ! empty($this->filters[$identifier])
408
-            ? $this->filters[$identifier]
409
-            : $identifier;
410
-    }
411
-
412
-
413
-
414
-    /**
415
-     * verifies and standardizes identifiers
416
-     *
417
-     * @param  string $identifier Identifier for the entity class
418
-     *                            Typically a Fully Qualified Class Name
419
-     * @return string
420
-     * @throws InvalidIdentifierException
421
-     */
422
-    private function processIdentifier($identifier)
423
-    {
424
-        if ( ! is_string($identifier)) {
425
-            throw new InvalidIdentifierException(
426
-                is_object($identifier) ? get_class($identifier) : gettype($identifier),
427
-                '\Fully\Qualified\ClassName'
428
-            );
429
-        }
430
-        return ltrim($identifier, '\\');
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     * @param string $type
437
-     * @return CoffeeMakerInterface
438
-     * @throws InvalidDataTypeException
439
-     * @throws InvalidClassException
440
-     */
441
-    private function getCoffeeMaker($type)
442
-    {
443
-        if ( ! $this->coffee_makers->has($type)) {
444
-            throw new OutOfBoundsException(
445
-                __('The requested coffee maker is either missing or invalid.', 'event_espresso')
446
-            );
447
-        }
448
-        return $this->coffee_makers->get($type);
449
-    }
450
-
451
-
452
-
453
-    /**
454
-     * Retrieves all recipes that use a wildcard "*" in their identifier
455
-     * This allows recipes to be set up for handling
456
-     * legacy classes that do not support PSR-4 autoloading.
457
-     * for example:
458
-     * using "EEM_*" for a recipe identifier would target all legacy models like EEM_Attendee
459
-     *
460
-     * @return array
461
-     */
462
-    private function getDefaultRecipes()
463
-    {
464
-        $default_recipes = array();
465
-        $this->recipes->rewind();
466
-        while ($this->recipes->valid()) {
467
-            $identifier = $this->recipes->getInfo();
468
-            // does this recipe use a wildcard ? (but is NOT the global default)
469
-            if ($identifier !== Recipe::DEFAULT_ID && strpos($identifier, '*') !== false) {
470
-                // strip the wildcard and use identifier as key
471
-                $default_recipes[str_replace('*', '', $identifier)] = $this->recipes->current();
472
-            }
473
-            $this->recipes->next();
474
-        }
475
-        return $default_recipes;
476
-    }
477
-
478
-
479
-
480
-    /**
481
-     * clones a default recipe and then copies details
482
-     * from the incoming request to it so that it can be used
483
-     *
484
-     * @param RecipeInterface $default_recipe
485
-     * @param string          $identifier
486
-     * @param string          $type
487
-     * @return RecipeInterface
488
-     */
489
-    private function copyDefaultRecipe(RecipeInterface $default_recipe, $identifier, $type = '')
490
-    {
491
-        $recipe = clone $default_recipe;
492
-        if ( ! empty($type)) {
493
-            $recipe->setType($type);
494
-        }
495
-        // is this the base default recipe ?
496
-        if ($default_recipe->identifier() === Recipe::DEFAULT_ID) {
497
-            $recipe->setIdentifier($identifier);
498
-            $recipe->setFqcn($identifier);
499
-            return $recipe;
500
-        }
501
-        $recipe->setIdentifier($identifier);
502
-        foreach ($default_recipe->paths() as $path) {
503
-            $path = str_replace('*', $identifier, $path);
504
-            if (is_readable($path)) {
505
-                $recipe->setPaths($path);
506
-            }
507
-        }
508
-        $recipe->setFqcn($identifier);
509
-        return $recipe;
510
-    }
511
-
512
-
513
-
514
-    /**
515
-     * @param  string $identifier Identifier for the entity class that the service applies to
516
-     *                            Typically a Fully Qualified Class Name
517
-     * @param mixed  $service
518
-     * @return object
519
-     * @throws InvalidServiceException
520
-     */
521
-    private function validateService($identifier, $service)
522
-    {
523
-        if ( ! is_object($service)) {
524
-            throw new InvalidServiceException(
525
-                $identifier,
526
-                $service
527
-            );
528
-        }
529
-        return $service;
530
-    }
35
+	/**
36
+	 * This was the best coffee related name I could think of to represent class name "aliases"
37
+	 * So classes can be found via an alias identifier,
38
+	 * that is revealed when it is run through... the filters... eh? get it?
39
+	 *
40
+	 * @var array $filters
41
+	 */
42
+	private $filters = array();
43
+
44
+	/**
45
+	 * These are the classes that will actually build the objects (to order of course)
46
+	 *
47
+	 * @var array $coffee_makers
48
+	 */
49
+	private $coffee_makers = array();
50
+
51
+	/**
52
+	 * where the instantiated "singleton" objects are stored
53
+	 *
54
+	 * @var CollectionInterface $carafe
55
+	 */
56
+	private $carafe;
57
+
58
+	/**
59
+	 * collection of Recipes that instruct us how to brew objects
60
+	 *
61
+	 * @var CollectionInterface $recipes
62
+	 */
63
+	private $recipes;
64
+
65
+	/**
66
+	 * collection of closures for brewing objects
67
+	 *
68
+	 * @var CollectionInterface $reservoir
69
+	 */
70
+	private $reservoir;
71
+
72
+
73
+
74
+	/**
75
+	 * CoffeeShop constructor
76
+	 */
77
+	public function __construct()
78
+	{
79
+		// array for storing class aliases
80
+		$this->filters = array();
81
+		// create collection for storing shared services
82
+		$this->carafe = new LooseCollection( '' );
83
+		// create collection for storing recipes that tell how to build services and entities
84
+		$this->recipes = new Collection('EventEspresso\core\services\container\RecipeInterface');
85
+		// create collection for storing closures for constructing new entities
86
+		$this->reservoir = new Collection('Closure');
87
+		// create collection for storing the generators that build our services and entity closures
88
+		$this->coffee_makers = new Collection('EventEspresso\core\services\container\CoffeeMakerInterface');
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * Returns true if the container can return an entry for the given identifier.
95
+	 * Returns false otherwise.
96
+	 * `has($identifier)` returning true does not mean that `get($identifier)` will not throw an exception.
97
+	 * It does however mean that `get($identifier)` will not throw a `ServiceNotFoundException`.
98
+	 *
99
+	 * @param string $identifier  Identifier of the entry to look for.
100
+	 *                            Typically a Fully Qualified Class Name
101
+	 * @return boolean
102
+	 */
103
+	public function has($identifier)
104
+	{
105
+		$identifier = $this->filterIdentifier($identifier);
106
+		return $this->carafe->has($identifier);
107
+	}
108
+
109
+
110
+
111
+	/**
112
+	 * finds a previously brewed (SHARED) service and returns it
113
+	 *
114
+	 * @param  string $identifier Identifier for the entity class to be constructed.
115
+	 *                            Typically a Fully Qualified Class Name
116
+	 * @return mixed
117
+	 * @throws ServiceNotFoundException No service was found for this identifier.
118
+	 */
119
+	public function get($identifier)
120
+	{
121
+		$identifier = $this->filterIdentifier($identifier);
122
+		if ($this->carafe->has($identifier)) {
123
+			return $this->carafe->get($identifier);
124
+		}
125
+		throw new ServiceNotFoundException($identifier);
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * returns an instance of the requested entity type using the supplied arguments.
132
+	 * If a shared service is requested and an instance is already in the carafe, then it will be returned.
133
+	 * If it is not already in the carafe, then the service will be constructed, added to the carafe, and returned
134
+	 * If the request is for a new entity and a closure exists in the reservoir for creating it,
135
+	 * then a new entity will be instantiated from the closure and returned.
136
+	 * If a closure does not exist, then one will be built and added to the reservoir
137
+	 * before instantiating the requested entity.
138
+	 *
139
+	 * @param  string $identifier Identifier for the entity class to be constructed.
140
+	 *                            Typically a Fully Qualified Class Name
141
+	 * @param array   $arguments  an array of arguments to be passed to the entity constructor
142
+	 * @param string  $type
143
+	 * @return mixed
144
+	 * @throws ServiceNotFoundException No service was found for this identifier.
145
+	 */
146
+	public function brew($identifier, $arguments = array(), $type = '')
147
+	{
148
+		// resolve any class aliases that may exist
149
+		$identifier = $this->filterIdentifier($identifier);
150
+		try {
151
+			// is a shared service being requested?
152
+			if (empty($type) || $type === CoffeeMaker::BREW_SHARED) {
153
+				// if a shared service was requested and an instance is in the carafe, then return it
154
+				return $this->get($identifier);
155
+			}
156
+		} catch (ServiceNotFoundException $e) {
157
+			// if not then we'll just catch the ServiceNotFoundException but not do anything just yet,
158
+			// and instead, attempt to build whatever was requested
159
+		}
160
+		$brewed = false;
161
+		// if the reservoir doesn't have a closure already for the requested identifier,
162
+		// then neither a shared service nor a closure for making entities has been built yet
163
+		if ( ! $this->reservoir->has($identifier)) {
164
+			// so let's brew something up and add it to the proper collection
165
+			$brewed = $this->makeCoffee($identifier, $arguments, $type);
166
+		}
167
+		// was the brewed item a callable factory function ?
168
+		if (is_callable($brewed)) {
169
+			// then instantiate a new entity from the cached closure
170
+			$entity = $brewed($arguments);
171
+		} else if ($brewed) {
172
+			// requested object was a shared entity, so attempt to get it from the carafe again
173
+			// because if it wasn't there before, then it should have just been brewed and added,
174
+			// but if it still isn't there, then this time
175
+			// the thrown ServiceNotFoundException will not be caught
176
+			$entity = $this->get($identifier);
177
+		} else {
178
+			// if identifier is for a non-shared entity,
179
+			// then either a cached closure already existed, or was just brewed
180
+			$closure = $this->reservoir->get($identifier);
181
+			$entity = $closure($arguments);
182
+		}
183
+		return $entity;
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * @param CoffeeMakerInterface $coffee_maker
190
+	 * @param string               $type
191
+	 * @return bool
192
+	 */
193
+	public function addCoffeeMaker(CoffeeMakerInterface $coffee_maker, $type)
194
+	{
195
+		$type = CoffeeMaker::validateType($type);
196
+		return $this->coffee_makers->add($coffee_maker, $type);
197
+	}
198
+
199
+
200
+
201
+	/**
202
+	 * @param string   $identifier
203
+	 * @param callable $closure
204
+	 * @return callable|null
205
+	 */
206
+	public function addClosure($identifier, $closure)
207
+	{
208
+		if ( ! is_callable($closure)) {
209
+			throw new InvalidDataTypeException('$closure', $closure, 'Closure');
210
+		}
211
+		$identifier = $this->processIdentifier($identifier);
212
+		if ($this->reservoir->add($closure, $identifier)) {
213
+			return $closure;
214
+		}
215
+		return null;
216
+	}
217
+
218
+
219
+
220
+	/**
221
+	 * @param string   $identifier
222
+	 * @return boolean
223
+	 */
224
+	public function removeClosure($identifier)
225
+	{
226
+		$identifier = $this->processIdentifier($identifier);
227
+		if ($this->reservoir->has($identifier)) {
228
+			$this->reservoir->remove($this->reservoir->get($identifier));
229
+			if ( ! $this->reservoir->has($identifier)) {
230
+				return true;
231
+			}
232
+		}
233
+		return false;
234
+	}
235
+
236
+
237
+
238
+	/**
239
+	 * @param  string $identifier Identifier for the entity class that the service applies to
240
+	 *                            Typically a Fully Qualified Class Name
241
+	 * @param mixed  $service
242
+	 * @return bool
243
+	 */
244
+	public function addService($identifier, $service)
245
+	{
246
+		$identifier = $this->processIdentifier($identifier);
247
+		$service = $this->validateService($identifier, $service);
248
+		return $this->carafe->add($service, $identifier);
249
+	}
250
+
251
+
252
+
253
+	/**
254
+	 * @param string $identifier
255
+	 * @return boolean
256
+	 */
257
+	public function removeService($identifier)
258
+	{
259
+		$identifier = $this->processIdentifier($identifier);
260
+		if ($this->carafe->has($identifier)) {
261
+			$this->carafe->remove($this->carafe->get($identifier));
262
+			if ( ! $this->carafe->has($identifier)) {
263
+				return true;
264
+			}
265
+		}
266
+		return false;
267
+	}
268
+
269
+
270
+
271
+	/**
272
+	 * Adds instructions on how to brew objects
273
+	 *
274
+	 * @param RecipeInterface $recipe
275
+	 * @return mixed
276
+	 */
277
+	public function addRecipe(RecipeInterface $recipe)
278
+	{
279
+		$this->addAliases($recipe->identifier(), $recipe->filters());
280
+		$identifier = $this->processIdentifier($recipe->identifier());
281
+		return $this->recipes->add($recipe, $identifier);
282
+	}
283
+
284
+
285
+
286
+	/**
287
+	 * @param string $identifier The Recipe's identifier
288
+	 * @return boolean
289
+	 */
290
+	public function removeRecipe($identifier)
291
+	{
292
+		$identifier = $this->processIdentifier($identifier);
293
+		if ($this->recipes->has($identifier)) {
294
+			$this->recipes->remove(
295
+				$this->recipes->get($identifier)
296
+			);
297
+			if ( ! $this->recipes->has($identifier)) {
298
+				return true;
299
+			}
300
+		}
301
+		return false;
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * Get instructions on how to brew objects
308
+	 *
309
+	 * @param  string $identifier Identifier for the entity class that the recipe applies to
310
+	 *                            Typically a Fully Qualified Class Name
311
+	 * @param string $type
312
+	 * @return RecipeInterface
313
+	 */
314
+	public function getRecipe($identifier, $type = '')
315
+	{
316
+		$identifier = $this->processIdentifier($identifier);
317
+		if ($this->recipes->has($identifier)) {
318
+			return $this->recipes->get($identifier);
319
+		}
320
+		$default_recipes = $this->getDefaultRecipes();
321
+		$matches = array();
322
+		foreach ($default_recipes as $wildcard => $default_recipe) {
323
+			// is the wildcard recipe prefix in the identifier ?
324
+			if (strpos($identifier, $wildcard) !== false) {
325
+				// track matches and use the number of wildcard characters matched for the key
326
+				$matches[strlen($wildcard)] = $default_recipe;
327
+			}
328
+		}
329
+		if (count($matches) > 0) {
330
+			// sort our recipes by the number of wildcard characters matched
331
+			ksort($matches);
332
+			// then grab the last recipe form the list, since it had the most matching characters
333
+			$match = array_pop($matches);
334
+			// since we are using a default recipe, we need to set it's identifier and fqcn
335
+			return $this->copyDefaultRecipe($match, $identifier, $type);
336
+		}
337
+		if ($this->recipes->has(Recipe::DEFAULT_ID)) {
338
+			// since we are using a default recipe, we need to set it's identifier and fqcn
339
+			return $this->copyDefaultRecipe($this->recipes->get(Recipe::DEFAULT_ID), $identifier, $type);
340
+		}
341
+		throw new OutOfBoundsException(
342
+			sprintf(
343
+				__('Could not brew coffee because no recipes were found for class "%1$s".', 'event_espresso'),
344
+				$identifier
345
+			)
346
+		);
347
+	}
348
+
349
+
350
+
351
+	/**
352
+	 * adds class name aliases to list of filters
353
+	 *
354
+	 * @param  string       $identifier Identifier for the entity class that the alias applies to
355
+	 *                                  Typically a Fully Qualified Class Name
356
+	 * @param  array|string $aliases
357
+	 * @return void
358
+	 * @throws InvalidIdentifierException
359
+	 */
360
+	public function addAliases($identifier, $aliases)
361
+	{
362
+		if (empty($aliases)) {
363
+			return;
364
+		}
365
+		$identifier = $this->processIdentifier($identifier);
366
+		foreach ((array)$aliases as $alias) {
367
+			$this->filters[$this->processIdentifier($alias)] = $identifier;
368
+		}
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * Adds a service to one of the internal collections
375
+	 *
376
+	 * @param        $identifier
377
+	 * @param array  $arguments
378
+	 * @param string $type
379
+	 * @return mixed
380
+	 * @throws ServiceExistsException
381
+	 */
382
+	private function makeCoffee($identifier, $arguments = array(), $type = '')
383
+	{
384
+		if ((empty($type) || $type === CoffeeMaker::BREW_SHARED) && $this->has($identifier)) {
385
+			throw new ServiceExistsException($identifier);
386
+		}
387
+		$identifier = $this->filterIdentifier($identifier);
388
+		$recipe = $this->getRecipe($identifier, $type);
389
+		$type = ! empty($type) ? $type : $recipe->type();
390
+		$coffee_maker = $this->getCoffeeMaker($type);
391
+		return $coffee_maker->brew($recipe, $arguments);
392
+	}
393
+
394
+
395
+
396
+	/**
397
+	 * filters alias identifiers to find the real class name
398
+	 *
399
+	 * @param  string $identifier Identifier for the entity class that the filter applies to
400
+	 *                            Typically a Fully Qualified Class Name
401
+	 * @return string
402
+	 * @throws InvalidIdentifierException
403
+	 */
404
+	private function filterIdentifier($identifier)
405
+	{
406
+		$identifier = $this->processIdentifier($identifier);
407
+		return isset($this->filters[$identifier]) && ! empty($this->filters[$identifier])
408
+			? $this->filters[$identifier]
409
+			: $identifier;
410
+	}
411
+
412
+
413
+
414
+	/**
415
+	 * verifies and standardizes identifiers
416
+	 *
417
+	 * @param  string $identifier Identifier for the entity class
418
+	 *                            Typically a Fully Qualified Class Name
419
+	 * @return string
420
+	 * @throws InvalidIdentifierException
421
+	 */
422
+	private function processIdentifier($identifier)
423
+	{
424
+		if ( ! is_string($identifier)) {
425
+			throw new InvalidIdentifierException(
426
+				is_object($identifier) ? get_class($identifier) : gettype($identifier),
427
+				'\Fully\Qualified\ClassName'
428
+			);
429
+		}
430
+		return ltrim($identifier, '\\');
431
+	}
432
+
433
+
434
+
435
+	/**
436
+	 * @param string $type
437
+	 * @return CoffeeMakerInterface
438
+	 * @throws InvalidDataTypeException
439
+	 * @throws InvalidClassException
440
+	 */
441
+	private function getCoffeeMaker($type)
442
+	{
443
+		if ( ! $this->coffee_makers->has($type)) {
444
+			throw new OutOfBoundsException(
445
+				__('The requested coffee maker is either missing or invalid.', 'event_espresso')
446
+			);
447
+		}
448
+		return $this->coffee_makers->get($type);
449
+	}
450
+
451
+
452
+
453
+	/**
454
+	 * Retrieves all recipes that use a wildcard "*" in their identifier
455
+	 * This allows recipes to be set up for handling
456
+	 * legacy classes that do not support PSR-4 autoloading.
457
+	 * for example:
458
+	 * using "EEM_*" for a recipe identifier would target all legacy models like EEM_Attendee
459
+	 *
460
+	 * @return array
461
+	 */
462
+	private function getDefaultRecipes()
463
+	{
464
+		$default_recipes = array();
465
+		$this->recipes->rewind();
466
+		while ($this->recipes->valid()) {
467
+			$identifier = $this->recipes->getInfo();
468
+			// does this recipe use a wildcard ? (but is NOT the global default)
469
+			if ($identifier !== Recipe::DEFAULT_ID && strpos($identifier, '*') !== false) {
470
+				// strip the wildcard and use identifier as key
471
+				$default_recipes[str_replace('*', '', $identifier)] = $this->recipes->current();
472
+			}
473
+			$this->recipes->next();
474
+		}
475
+		return $default_recipes;
476
+	}
477
+
478
+
479
+
480
+	/**
481
+	 * clones a default recipe and then copies details
482
+	 * from the incoming request to it so that it can be used
483
+	 *
484
+	 * @param RecipeInterface $default_recipe
485
+	 * @param string          $identifier
486
+	 * @param string          $type
487
+	 * @return RecipeInterface
488
+	 */
489
+	private function copyDefaultRecipe(RecipeInterface $default_recipe, $identifier, $type = '')
490
+	{
491
+		$recipe = clone $default_recipe;
492
+		if ( ! empty($type)) {
493
+			$recipe->setType($type);
494
+		}
495
+		// is this the base default recipe ?
496
+		if ($default_recipe->identifier() === Recipe::DEFAULT_ID) {
497
+			$recipe->setIdentifier($identifier);
498
+			$recipe->setFqcn($identifier);
499
+			return $recipe;
500
+		}
501
+		$recipe->setIdentifier($identifier);
502
+		foreach ($default_recipe->paths() as $path) {
503
+			$path = str_replace('*', $identifier, $path);
504
+			if (is_readable($path)) {
505
+				$recipe->setPaths($path);
506
+			}
507
+		}
508
+		$recipe->setFqcn($identifier);
509
+		return $recipe;
510
+	}
511
+
512
+
513
+
514
+	/**
515
+	 * @param  string $identifier Identifier for the entity class that the service applies to
516
+	 *                            Typically a Fully Qualified Class Name
517
+	 * @param mixed  $service
518
+	 * @return object
519
+	 * @throws InvalidServiceException
520
+	 */
521
+	private function validateService($identifier, $service)
522
+	{
523
+		if ( ! is_object($service)) {
524
+			throw new InvalidServiceException(
525
+				$identifier,
526
+				$service
527
+			);
528
+		}
529
+		return $service;
530
+	}
531 531
 
532 532
 }
533 533
 // End of file CoffeeShop.php
Please login to merge, or discard this patch.
modules/events_archive/EventsArchiveIframe.php 2 patches
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\libraries\iframe_display\Iframe;
5 5
 
6 6
 if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
7
-    exit( 'No direct script access allowed' );
7
+	exit( 'No direct script access allowed' );
8 8
 }
9 9
 
10 10
 
@@ -21,57 +21,57 @@  discard block
 block discarded – undo
21 21
 
22 22
 
23 23
 
24
-    /**
25
-     * EventsArchiveIframe constructor.
26
-     *
27
-     * @param \EED_Events_Archive $EED_Events_Archive
28
-     * @throws \DomainException
29
-     */
30
-    public function __construct( $EED_Events_Archive )
31
-    {
32
-        \EE_Registry::instance()->REQ->set_espresso_page( true );
33
-        add_filter('FHEE__EED_Events_Archive__event_list_iframe', '__return_true');
34
-        $EED_Events_Archive->event_list();
35
-        /** @var \EventEspresso\core\domain\entities\shortcodes\EspressoEvents $event_list */
36
-        $event_list = \EE_Registry::instance()->create('EventEspresso\core\domain\entities\shortcodes\EspressoEvents');
37
-        parent::__construct(
38
-            esc_html__( 'Event List', 'event_espresso' ),
39
-            $event_list->processShortcode()
40
-        );
41
-        $this->addStylesheets(
42
-            apply_filters(
43
-                'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
44
-                array(
45
-                    'espresso_default'           => is_readable( EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css' )
46
-                        ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION
47
-                        : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION,
48
-                ),
49
-                $this
50
-            )
51
-        );
52
-        $this->addScripts(
53
-            apply_filters(
54
-                'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
55
-                array(
56
-                    'gmap_api' => sprintf(
57
-                        'https://maps.googleapis.com/maps/api/js?key=%s',
58
-                        apply_filters(
59
-                            'FHEE__EEH_Maps__espresso_google_maps_js__api_key',
60
-                            \EE_Registry::instance()->CFG->map_settings->google_map_api_key
61
-                        )
62
-                    ),
63
-                    'ee_gmap'  => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0',
64
-                ),
65
-                $this
66
-            )
67
-        );
68
-        $this->addLocalizedVars(
69
-            array(
70
-                'ee_gmap' => \EEH_Maps::$gmap_vars,
71
-            ),
72
-            'ee_gmap_vars'
73
-        );
74
-    }
24
+	/**
25
+	 * EventsArchiveIframe constructor.
26
+	 *
27
+	 * @param \EED_Events_Archive $EED_Events_Archive
28
+	 * @throws \DomainException
29
+	 */
30
+	public function __construct( $EED_Events_Archive )
31
+	{
32
+		\EE_Registry::instance()->REQ->set_espresso_page( true );
33
+		add_filter('FHEE__EED_Events_Archive__event_list_iframe', '__return_true');
34
+		$EED_Events_Archive->event_list();
35
+		/** @var \EventEspresso\core\domain\entities\shortcodes\EspressoEvents $event_list */
36
+		$event_list = \EE_Registry::instance()->create('EventEspresso\core\domain\entities\shortcodes\EspressoEvents');
37
+		parent::__construct(
38
+			esc_html__( 'Event List', 'event_espresso' ),
39
+			$event_list->processShortcode()
40
+		);
41
+		$this->addStylesheets(
42
+			apply_filters(
43
+				'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
44
+				array(
45
+					'espresso_default'           => is_readable( EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css' )
46
+						? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION
47
+						: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION,
48
+				),
49
+				$this
50
+			)
51
+		);
52
+		$this->addScripts(
53
+			apply_filters(
54
+				'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
55
+				array(
56
+					'gmap_api' => sprintf(
57
+						'https://maps.googleapis.com/maps/api/js?key=%s',
58
+						apply_filters(
59
+							'FHEE__EEH_Maps__espresso_google_maps_js__api_key',
60
+							\EE_Registry::instance()->CFG->map_settings->google_map_api_key
61
+						)
62
+					),
63
+					'ee_gmap'  => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0',
64
+				),
65
+				$this
66
+			)
67
+		);
68
+		$this->addLocalizedVars(
69
+			array(
70
+				'ee_gmap' => \EEH_Maps::$gmap_vars,
71
+			),
72
+			'ee_gmap_vars'
73
+		);
74
+	}
75 75
 
76 76
 
77 77
 
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@  discard block
 block discarded – undo
3 3
 
4 4
 use EventEspresso\core\libraries\iframe_display\Iframe;
5 5
 
6
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
7
-    exit( 'No direct script access allowed' );
6
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7
+    exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -27,24 +27,24 @@  discard block
 block discarded – undo
27 27
      * @param \EED_Events_Archive $EED_Events_Archive
28 28
      * @throws \DomainException
29 29
      */
30
-    public function __construct( $EED_Events_Archive )
30
+    public function __construct($EED_Events_Archive)
31 31
     {
32
-        \EE_Registry::instance()->REQ->set_espresso_page( true );
32
+        \EE_Registry::instance()->REQ->set_espresso_page(true);
33 33
         add_filter('FHEE__EED_Events_Archive__event_list_iframe', '__return_true');
34 34
         $EED_Events_Archive->event_list();
35 35
         /** @var \EventEspresso\core\domain\entities\shortcodes\EspressoEvents $event_list */
36 36
         $event_list = \EE_Registry::instance()->create('EventEspresso\core\domain\entities\shortcodes\EspressoEvents');
37 37
         parent::__construct(
38
-            esc_html__( 'Event List', 'event_espresso' ),
38
+            esc_html__('Event List', 'event_espresso'),
39 39
             $event_list->processShortcode()
40 40
         );
41 41
         $this->addStylesheets(
42 42
             apply_filters(
43 43
                 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
44 44
                 array(
45
-                    'espresso_default'           => is_readable( EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css' )
46
-                        ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION
47
-                        : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION,
45
+                    'espresso_default'           => is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css')
46
+                        ? EVENT_ESPRESSO_UPLOAD_DIR.'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION
47
+                        : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION,
48 48
                 ),
49 49
                 $this
50 50
             )
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
                             \EE_Registry::instance()->CFG->map_settings->google_map_api_key
61 61
                         )
62 62
                     ),
63
-                    'ee_gmap'  => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0',
63
+                    'ee_gmap'  => EE_HELPERS_ASSETS.'ee_gmap.js?ver=1.0',
64 64
                 ),
65 65
                 $this
66 66
             )
Please login to merge, or discard this patch.
core/services/cache/PostRelatedCacheManager.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function clearPostRelatedCacheOnUpdate($post_ID, $id_prefix)
73 73
     {
74
-        $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array());
74
+        $post_related_cache = (array) get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array());
75 75
         // if post is not already being tracked
76 76
         if ( ! isset($post_related_cache[$post_ID])) {
77 77
             // add array to add cache ids to
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
      */
93 93
     public function clearPostRelatedCache($post_ID)
94 94
     {
95
-        $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array());
95
+        $post_related_cache = (array) get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array());
96 96
         // if post is not being tracked
97 97
         if ( ! isset($post_related_cache[$post_ID])) {
98 98
             return;
Please login to merge, or discard this patch.
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -18,92 +18,92 @@
 block discarded – undo
18 18
 class PostRelatedCacheManager extends BasicCacheManager
19 19
 {
20 20
 
21
-    /**
22
-     * @type string
23
-     */
24
-    const POST_CACHE_PREFIX = 'ee_cache_post_';
25
-
26
-    /**
27
-     * wp-option option_name for tracking post related cache
28
-     *
29
-     * @type string
30
-     */
31
-    const POST_CACHE_OPTIONS_KEY = 'ee_post_cache';
32
-
33
-
34
-
35
-    /**
36
-     * PostRelatedCacheManager constructor.
37
-     *
38
-     * @param CacheStorageInterface      $cache_storage
39
-     */
40
-    public function __construct(CacheStorageInterface $cache_storage)
41
-    {
42
-        parent::__construct($cache_storage);
43
-        add_action('save_post', array($this, 'clearPostRelatedCache'));
44
-    }
45
-
46
-
47
-
48
-    /**
49
-     * returns a string that will be prepended to all cache identifiers
50
-     *
51
-     * @return string
52
-     */
53
-    public function cachePrefix()
54
-    {
55
-        return PostRelatedCacheManager::POST_CACHE_PREFIX;
56
-    }
57
-
58
-
59
-
60
-    /**
61
-     * If you are caching content that pertains to a Post of any type,
62
-     * then it is recommended to pass the post id and cache id prefix to this method
63
-     * so that it can be added to the post related cache tracking.
64
-     * Then, whenever that post is updated, the cache will automatically be deleted,
65
-     * which helps to ensure that outdated cache content will not be served
66
-     *
67
-     * @param int    $post_ID    [required]
68
-     * @param string $id_prefix  [required] Appended to all cache IDs. Can be helpful in finding specific cache types.
69
-     *                           May also be helpful to include an additional specific identifier,
70
-     *                           such as a post ID as part of the $id_prefix so that individual caches
71
-     *                           can be found and/or cleared. ex: "venue-28", or "shortcode-156".
72
-     *                           BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id.
73
-     */
74
-    public function clearPostRelatedCacheOnUpdate($post_ID, $id_prefix)
75
-    {
76
-        $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array());
77
-        // if post is not already being tracked
78
-        if ( ! isset($post_related_cache[$post_ID])) {
79
-            // add array to add cache ids to
80
-            $post_related_cache[$post_ID] = array();
81
-        }
82
-        // add cache id to be tracked
83
-        $post_related_cache[$post_ID][] = $id_prefix;
84
-        update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache);
85
-    }
86
-
87
-
88
-
89
-    /**
90
-     * callback hooked into the WordPress "save_post" action
91
-     * deletes any cache content associated with the post
92
-     *
93
-     * @param int $post_ID [required]
94
-     */
95
-    public function clearPostRelatedCache($post_ID)
96
-    {
97
-        $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array());
98
-        // if post is not being tracked
99
-        if ( ! isset($post_related_cache[$post_ID])) {
100
-            return;
101
-        }
102
-        // get cache id prefixes for post, and delete their corresponding transients
103
-        $this->clear($post_related_cache[$post_ID]);
104
-        unset($post_related_cache[$post_ID]);
105
-        update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache);
106
-    }
21
+	/**
22
+	 * @type string
23
+	 */
24
+	const POST_CACHE_PREFIX = 'ee_cache_post_';
25
+
26
+	/**
27
+	 * wp-option option_name for tracking post related cache
28
+	 *
29
+	 * @type string
30
+	 */
31
+	const POST_CACHE_OPTIONS_KEY = 'ee_post_cache';
32
+
33
+
34
+
35
+	/**
36
+	 * PostRelatedCacheManager constructor.
37
+	 *
38
+	 * @param CacheStorageInterface      $cache_storage
39
+	 */
40
+	public function __construct(CacheStorageInterface $cache_storage)
41
+	{
42
+		parent::__construct($cache_storage);
43
+		add_action('save_post', array($this, 'clearPostRelatedCache'));
44
+	}
45
+
46
+
47
+
48
+	/**
49
+	 * returns a string that will be prepended to all cache identifiers
50
+	 *
51
+	 * @return string
52
+	 */
53
+	public function cachePrefix()
54
+	{
55
+		return PostRelatedCacheManager::POST_CACHE_PREFIX;
56
+	}
57
+
58
+
59
+
60
+	/**
61
+	 * If you are caching content that pertains to a Post of any type,
62
+	 * then it is recommended to pass the post id and cache id prefix to this method
63
+	 * so that it can be added to the post related cache tracking.
64
+	 * Then, whenever that post is updated, the cache will automatically be deleted,
65
+	 * which helps to ensure that outdated cache content will not be served
66
+	 *
67
+	 * @param int    $post_ID    [required]
68
+	 * @param string $id_prefix  [required] Appended to all cache IDs. Can be helpful in finding specific cache types.
69
+	 *                           May also be helpful to include an additional specific identifier,
70
+	 *                           such as a post ID as part of the $id_prefix so that individual caches
71
+	 *                           can be found and/or cleared. ex: "venue-28", or "shortcode-156".
72
+	 *                           BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id.
73
+	 */
74
+	public function clearPostRelatedCacheOnUpdate($post_ID, $id_prefix)
75
+	{
76
+		$post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array());
77
+		// if post is not already being tracked
78
+		if ( ! isset($post_related_cache[$post_ID])) {
79
+			// add array to add cache ids to
80
+			$post_related_cache[$post_ID] = array();
81
+		}
82
+		// add cache id to be tracked
83
+		$post_related_cache[$post_ID][] = $id_prefix;
84
+		update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache);
85
+	}
86
+
87
+
88
+
89
+	/**
90
+	 * callback hooked into the WordPress "save_post" action
91
+	 * deletes any cache content associated with the post
92
+	 *
93
+	 * @param int $post_ID [required]
94
+	 */
95
+	public function clearPostRelatedCache($post_ID)
96
+	{
97
+		$post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array());
98
+		// if post is not being tracked
99
+		if ( ! isset($post_related_cache[$post_ID])) {
100
+			return;
101
+		}
102
+		// get cache id prefixes for post, and delete their corresponding transients
103
+		$this->clear($post_related_cache[$post_ID]);
104
+		unset($post_related_cache[$post_ID]);
105
+		update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache);
106
+	}
107 107
 
108 108
 
109 109
 }
Please login to merge, or discard this patch.