Completed
Branch FET/11450/reserved-instance-in... (0b2d22)
by
unknown
32:10 queued 12:45
created
modules/ticket_selector/ProcessTicketSelector.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -473,7 +473,7 @@
 block discarded – undo
473 473
      *
474 474
      * @param EE_Ticket $ticket
475 475
      * @param int        $qty
476
-     * @return TRUE on success, FALSE on fail
476
+     * @return boolean on success, FALSE on fail
477 477
      * @throws InvalidArgumentException
478 478
      * @throws InvalidInterfaceException
479 479
      * @throws InvalidDataTypeException
Please login to merge, or discard this patch.
Indentation   +520 added lines, -520 removed lines patch added patch discarded remove patch
@@ -34,526 +34,526 @@
 block discarded – undo
34 34
 class ProcessTicketSelector
35 35
 {
36 36
 
37
-    /**
38
-     * @var EE_Cart $cart
39
-     */
40
-    private $cart;
41
-
42
-    /**
43
-     * @var EE_Core_Config $core_config
44
-     */
45
-    private $core_config;
46
-
47
-    /**
48
-     * @var Request $request
49
-     */
50
-    private $request;
51
-
52
-    /**
53
-     * @var EE_Session $session
54
-     */
55
-    private $session;
56
-
57
-    /**
58
-     * @var EEM_Ticket $ticket_model
59
-     */
60
-    private $ticket_model;
61
-
62
-    /**
63
-     * @var TicketDatetimeAvailabilityTracker $tracker
64
-     */
65
-    private $tracker;
66
-
67
-
68
-    /**
69
-     * ProcessTicketSelector constructor.
70
-     * NOTE: PLZ use the Loader to instantiate this class if need be
71
-     * so that all dependencies get injected correctly (which will happen automatically)
72
-     * Null values for parameters are only for backwards compatibility but will be removed later on.
73
-     *
74
-     * @param EE_Core_Config                    $core_config
75
-     * @param Request                           $request
76
-     * @param EE_Session                        $session
77
-     * @param EEM_Ticket                        $ticket_model
78
-     * @param TicketDatetimeAvailabilityTracker $tracker
79
-     * @throws InvalidArgumentException
80
-     * @throws InvalidDataTypeException
81
-     * @throws InvalidInterfaceException
82
-     */
83
-    public function __construct(
84
-        EE_Core_Config $core_config = null,
85
-        Request $request = null,
86
-        EE_Session $session = null,
87
-        EEM_Ticket $ticket_model = null,
88
-        TicketDatetimeAvailabilityTracker $tracker = null
89
-    ) {
90
-        /** @var LoaderInterface $loader */
91
-        $loader             = LoaderFactory::getLoader();
92
-        $this->core_config  = $core_config instanceof EE_Core_Config
93
-            ? $core_config
94
-            : $loader->getShared('EE_Core_Config');
95
-        $this->request      = $request instanceof Request
96
-            ? $request
97
-            : $loader->getShared('EventEspresso\core\services\request\Request');
98
-        $this->session      = $session instanceof EE_Session
99
-            ? $session
100
-            : $loader->getShared('EE_Session');
101
-        $this->ticket_model = $ticket_model instanceof EEM_Ticket
102
-            ? $ticket_model
103
-            : $loader->getShared('EEM_Ticket');
104
-        $this->tracker      = $tracker instanceof TicketDatetimeAvailabilityTracker
105
-            ? $tracker
106
-            : $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker');
107
-    }
108
-
109
-
110
-    /**
111
-     * cancelTicketSelections
112
-     *
113
-     * @return bool
114
-     * @throws EE_Error
115
-     * @throws InvalidArgumentException
116
-     * @throws InvalidInterfaceException
117
-     * @throws InvalidDataTypeException
118
-     */
119
-    public function cancelTicketSelections()
120
-    {
121
-        // check nonce
122
-        if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
123
-            return false;
124
-        }
125
-        $this->session->clear_session(__CLASS__, __FUNCTION__);
126
-        if ($this->request->requestParamIsSet('event_id')) {
127
-            EEH_URL::safeRedirectAndExit(
128
-                EEH_Event_View::event_link_url(
129
-                    $this->request->getRequestParam('event_id')
130
-                )
131
-            );
132
-        }
133
-        EEH_URL::safeRedirectAndExit(
134
-            site_url('/' . $this->core_config->event_cpt_slug . '/')
135
-        );
136
-        return true;
137
-    }
138
-
139
-
140
-    /**
141
-     * processTicketSelectorNonce
142
-     *
143
-     * @param  string $nonce_name
144
-     * @param string  $id
145
-     * @return bool
146
-     */
147
-    private function processTicketSelectorNonce($nonce_name, $id = '')
148
-    {
149
-        $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce";
150
-        if (
151
-            ! $this->request->isAdmin()
152
-            && (
153
-                ! $this->request->is_set($nonce_name_with_id)
154
-                || ! wp_verify_nonce(
155
-                    $this->request->get($nonce_name_with_id),
156
-                    $nonce_name
157
-                )
158
-            )
159
-        ) {
160
-            EE_Error::add_error(
161
-                sprintf(
162
-                    esc_html__(
163
-                        'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.',
164
-                        'event_espresso'
165
-                    ),
166
-                    '<br/>'
167
-                ),
168
-                __FILE__,
169
-                __FUNCTION__,
170
-                __LINE__
171
-            );
172
-            return false;
173
-        }
174
-        return true;
175
-    }
176
-
177
-
178
-    /**
179
-     * process_ticket_selections
180
-     *
181
-     * @return array|bool
182
-     * @throws EE_Error
183
-     * @throws InvalidArgumentException
184
-     * @throws InvalidDataTypeException
185
-     * @throws InvalidInterfaceException
186
-     */
187
-    public function processTicketSelections()
188
-    {
189
-        do_action('EED_Ticket_Selector__process_ticket_selections__before');
190
-        if($this->request->isBot()) {
191
-            EEH_URL::safeRedirectAndExit(
192
-                apply_filters(
193
-                    'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url',
194
-                    site_url()
195
-                )
196
-            );
197
-        }
198
-        // do we have an event id?
199
-        $id = $this->getEventId();
200
-        // we should really only have 1 registration in the works now
201
-        // (ie, no MER) so unless otherwise requested, clear the session
202
-        if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) {
203
-            $this->session->clear_session(__CLASS__, __FUNCTION__);
204
-        }
205
-        // validate/sanitize/filter data
206
-        $valid = apply_filters(
207
-            'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data',
208
-            $this->validatePostData($id)
209
-        );
210
-        //check total tickets ordered vs max number of attendees that can register
211
-        if ($valid['total_tickets'] > $valid['max_atndz']) {
212
-            $this->maxAttendeesViolation($valid);
213
-        } else {
214
-            // all data appears to be valid
215
-            if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) {
216
-                return true;
217
-            }
218
-        }
219
-        // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT
220
-        // at this point, just return if registration is being made from admin
221
-        if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
222
-            return false;
223
-        }
224
-        if ($valid['return_url']) {
225
-            EEH_URL::safeRedirectAndExit($valid['return_url']);
226
-        }
227
-        if ($id) {
228
-            EEH_URL::safeRedirectAndExit(get_permalink($id));
229
-        }
230
-        echo EE_Error::get_notices();
231
-        return false;
232
-    }
233
-
234
-
235
-    /**
236
-     * @return int
237
-     */
238
-    private function getEventId()
239
-    {
240
-        // do we have an event id?
241
-        if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
242
-            // $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
243
-            EE_Error::add_error(
244
-                sprintf(
245
-                    esc_html__(
246
-                        'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.',
247
-                        'event_espresso'
248
-                    ),
249
-                    '<br/>'
250
-                ),
251
-                __FILE__,
252
-                __FUNCTION__,
253
-                __LINE__
254
-            );
255
-        }
256
-        //if event id is valid
257
-        return absint($this->request->getRequestParam('tkt-slctr-event-id'));
258
-    }
259
-
260
-
261
-    /**
262
-     * validate_post_data
263
-     *
264
-     * @param int $id
265
-     * @return array|FALSE
266
-     */
267
-    private function validatePostData($id = 0)
268
-    {
269
-        if (! $id) {
270
-            EE_Error::add_error(
271
-                esc_html__('The event id provided was not valid.', 'event_espresso'),
272
-                __FILE__,
273
-                __FUNCTION__,
274
-                __LINE__
275
-            );
276
-            return false;
277
-        }
278
-        // start with an empty array()
279
-        $valid_data = array();
280
-        // grab valid id
281
-        $valid_data['id'] = $id;
282
-        // array of other form names
283
-        $inputs_to_clean = array(
284
-            'event_id'   => 'tkt-slctr-event-id',
285
-            'max_atndz'  => 'tkt-slctr-max-atndz-',
286
-            'rows'       => 'tkt-slctr-rows-',
287
-            'qty'        => 'tkt-slctr-qty-',
288
-            'ticket_id'  => 'tkt-slctr-ticket-id-',
289
-            'return_url' => 'tkt-slctr-return-url-',
290
-        );
291
-        // let's track the total number of tickets ordered.'
292
-        $valid_data['total_tickets'] = 0;
293
-        // cycle through $inputs_to_clean array
294
-        foreach ($inputs_to_clean as $what => $input_to_clean) {
295
-            // check for POST data
296
-            if ($this->request->requestParamIsSet($input_to_clean . $id)) {
297
-                // grab value
298
-                $input_value = $this->request->getRequestParam($input_to_clean . $id);
299
-                switch ($what) {
300
-                    // integers
301
-                    case 'event_id':
302
-                        $valid_data[ $what ] = absint($input_value);
303
-                        // get event via the event id we put in the form
304
-                        break;
305
-                    case 'rows':
306
-                    case 'max_atndz':
307
-                        $valid_data[ $what ] = absint($input_value);
308
-                        break;
309
-                    // arrays of integers
310
-                    case 'qty':
311
-                        /** @var array $row_qty */
312
-                        $row_qty = $input_value;
313
-                        // if qty is coming from a radio button input, then we need to assemble an array of rows
314
-                        if (! is_array($row_qty)) {
315
-                            /** @var string $row_qty */
316
-                            // get number of rows
317
-                            $rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id)
318
-                                ? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id))
319
-                                : 1;
320
-                            // explode integers by the dash
321
-                            $row_qty = explode('-', $row_qty);
322
-                            $row     = isset($row_qty[0]) ? absint($row_qty[0]) : 1;
323
-                            $qty     = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
324
-                            $row_qty = array($row => $qty);
325
-                            for ($x = 1; $x <= $rows; $x++) {
326
-                                if (! isset($row_qty[ $x ])) {
327
-                                    $row_qty[ $x ] = 0;
328
-                                }
329
-                            }
330
-                        }
331
-                        ksort($row_qty);
332
-                        // cycle thru values
333
-                        foreach ($row_qty as $qty) {
334
-                            $qty = absint($qty);
335
-                            // sanitize as integers
336
-                            $valid_data[ $what ][]       = $qty;
337
-                            $valid_data['total_tickets'] += $qty;
338
-                        }
339
-                        break;
340
-                    // array of integers
341
-                    case 'ticket_id':
342
-                        // cycle thru values
343
-                        foreach ((array) $input_value as $key => $value) {
344
-                            // allow only integers
345
-                            $valid_data[ $what ][ $key ] = absint($value);
346
-                        }
347
-                        break;
348
-                    case 'return_url' :
349
-                        // grab and sanitize return-url
350
-                        $input_value = esc_url_raw($input_value);
351
-                        // was the request coming from an iframe ? if so, then:
352
-                        if (strpos($input_value, 'event_list=iframe')) {
353
-                            // get anchor fragment
354
-                            $input_value = explode('#', $input_value);
355
-                            $input_value = end($input_value);
356
-                            // use event list url instead, but append anchor
357
-                            $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value;
358
-                        }
359
-                        $valid_data[ $what ] = $input_value;
360
-                        break;
361
-                }    // end switch $what
362
-            }
363
-        }    // end foreach $inputs_to_clean
364
-        return $valid_data;
365
-    }
366
-
367
-
368
-    /**
369
-     * @param array $valid
370
-     */
371
-    private function maxAttendeesViolation(array $valid)
372
-    {
373
-        // ordering too many tickets !!!
374
-        $total_tickets_string = esc_html(
375
-            _n(
376
-                'You have attempted to purchase %s ticket.',
377
-                'You have attempted to purchase %s tickets.',
378
-                $valid['total_tickets'],
379
-                'event_espresso'
380
-            )
381
-        );
382
-        $limit_error_1        = sprintf($total_tickets_string, $valid['total_tickets']);
383
-        // dev only message
384
-        $max_attendees_string = esc_html(
385
-            _n(
386
-                'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
387
-                'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
388
-                $valid['max_atndz'],
389
-                'event_espresso'
390
-            )
391
-        );
392
-        $limit_error_2    = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
393
-        EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
394
-    }
395
-
396
-
397
-    /**
398
-     * @param array $valid
399
-     * @return int|TRUE
400
-     * @throws EE_Error
401
-     * @throws InvalidArgumentException
402
-     * @throws InvalidDataTypeException
403
-     * @throws InvalidInterfaceException
404
-     */
405
-    private function addTicketsToCart(array $valid)
406
-    {
407
-        $tickets_added = 0;
408
-        $tickets_selected = false;
409
-        if($valid['total_tickets'] > 0){
410
-            // load cart using factory because we don't want to do so until actually needed
411
-            $this->cart = CartFactory::getCart();
412
-            // cycle thru the number of data rows sent from the event listing
413
-            for ($x = 0; $x < $valid['rows']; $x++) {
414
-                // does this row actually contain a ticket quantity?
415
-                if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) {
416
-                    // YES we have a ticket quantity
417
-                    $tickets_selected = true;
418
-                    $valid_ticket     = false;
419
-                    // \EEH_Debug_Tools::printr(
420
-                    //     $valid['ticket_id'][ $x ],
421
-                    //     '$valid[\'ticket_id\'][ $x ]',
422
-                    //     __FILE__, __LINE__
423
-                    // );
424
-                    if (isset($valid['ticket_id'][ $x ])) {
425
-                        // get ticket via the ticket id we put in the form
426
-                        $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]);
427
-                        if ($ticket instanceof EE_Ticket) {
428
-                            $valid_ticket  = true;
429
-                            $tickets_added += $this->addTicketToCart(
430
-                                $ticket,
431
-                                $valid['qty'][ $x ]
432
-                            );
433
-                        }
434
-                    }
435
-                    if ($valid_ticket !== true) {
436
-                        // nothing added to cart retrieved
437
-                        EE_Error::add_error(
438
-                            sprintf(
439
-                                esc_html__(
440
-                                    'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.',
441
-                                    'event_espresso'
442
-                                ),
443
-                                '<br/>'
444
-                            ),
445
-                            __FILE__, __FUNCTION__, __LINE__
446
-                        );
447
-                    }
448
-                    if (EE_Error::has_error()) {
449
-                        break;
450
-                    }
451
-                }
452
-            }
453
-        }
454
-        do_action(
455
-            'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
456
-            $this->cart,
457
-            $this
458
-        );
459
-        if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
460
-            // no ticket quantities were selected
461
-            EE_Error::add_error(
462
-                esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'),
463
-                __FILE__, __FUNCTION__, __LINE__
464
-            );
465
-        }
466
-        return $tickets_added;
467
-    }
468
-
469
-
470
-
471
-    /**
472
-     * adds a ticket to the cart
473
-     *
474
-     * @param EE_Ticket $ticket
475
-     * @param int        $qty
476
-     * @return TRUE on success, FALSE on fail
477
-     * @throws InvalidArgumentException
478
-     * @throws InvalidInterfaceException
479
-     * @throws InvalidDataTypeException
480
-     * @throws EE_Error
481
-     */
482
-    private function addTicketToCart(EE_Ticket $ticket, $qty = 1)
483
-    {
484
-        // get the number of spaces left for this datetime ticket
485
-        $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket);
486
-        // compare available spaces against the number of tickets being purchased
487
-        if ($available_spaces >= $qty) {
488
-            // allow addons to prevent a ticket from being added to cart
489
-            if (
490
-                ! apply_filters(
491
-                    'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart',
492
-                    true,
493
-                    $ticket,
494
-                    $qty,
495
-                    $available_spaces
496
-                )
497
-            ) {
498
-                return false;
499
-            }
500
-            $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket));
501
-            // add event to cart
502
-            if ($this->cart->add_ticket_to_cart($ticket, $qty)) {
503
-                $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty);
504
-                return true;
505
-            }
506
-            return false;
507
-        }
508
-        $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count());
509
-        return false;
510
-    }
511
-
512
-
513
-    /**
514
-     * @param $tickets_added
515
-     * @return bool
516
-     * @throws InvalidInterfaceException
517
-     * @throws InvalidDataTypeException
518
-     * @throws EE_Error
519
-     * @throws InvalidArgumentException
520
-     */
521
-    private function processSuccessfulCart($tickets_added)
522
-    {
523
-        // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
524
-        if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
525
-            // make sure cart is loaded
526
-            if(! $this->cart  instanceof EE_Cart){
527
-                $this->cart = CartFactory::getCart();
528
-            }
529
-            do_action(
530
-                'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout',
531
-                $this->cart,
532
-                $this
533
-            );
534
-            $this->cart->recalculate_all_cart_totals();
535
-            $this->cart->save_cart(false);
536
-            // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<  OR HERE TO KILL REDIRECT AFTER CART UPDATE
537
-            // just return TRUE for registrations being made from admin
538
-            if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
539
-                return true;
540
-            }
541
-            EEH_URL::safeRedirectAndExit(
542
-                apply_filters(
543
-                    'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url',
544
-                    $this->core_config->reg_page_url()
545
-                )
546
-            );
547
-        }
548
-        if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
549
-            // nothing added to cart
550
-            EE_Error::add_attention(
551
-                esc_html__('No tickets were added for the event', 'event_espresso'),
552
-                __FILE__, __FUNCTION__, __LINE__
553
-            );
554
-        }
555
-        return false;
556
-    }
37
+	/**
38
+	 * @var EE_Cart $cart
39
+	 */
40
+	private $cart;
41
+
42
+	/**
43
+	 * @var EE_Core_Config $core_config
44
+	 */
45
+	private $core_config;
46
+
47
+	/**
48
+	 * @var Request $request
49
+	 */
50
+	private $request;
51
+
52
+	/**
53
+	 * @var EE_Session $session
54
+	 */
55
+	private $session;
56
+
57
+	/**
58
+	 * @var EEM_Ticket $ticket_model
59
+	 */
60
+	private $ticket_model;
61
+
62
+	/**
63
+	 * @var TicketDatetimeAvailabilityTracker $tracker
64
+	 */
65
+	private $tracker;
66
+
67
+
68
+	/**
69
+	 * ProcessTicketSelector constructor.
70
+	 * NOTE: PLZ use the Loader to instantiate this class if need be
71
+	 * so that all dependencies get injected correctly (which will happen automatically)
72
+	 * Null values for parameters are only for backwards compatibility but will be removed later on.
73
+	 *
74
+	 * @param EE_Core_Config                    $core_config
75
+	 * @param Request                           $request
76
+	 * @param EE_Session                        $session
77
+	 * @param EEM_Ticket                        $ticket_model
78
+	 * @param TicketDatetimeAvailabilityTracker $tracker
79
+	 * @throws InvalidArgumentException
80
+	 * @throws InvalidDataTypeException
81
+	 * @throws InvalidInterfaceException
82
+	 */
83
+	public function __construct(
84
+		EE_Core_Config $core_config = null,
85
+		Request $request = null,
86
+		EE_Session $session = null,
87
+		EEM_Ticket $ticket_model = null,
88
+		TicketDatetimeAvailabilityTracker $tracker = null
89
+	) {
90
+		/** @var LoaderInterface $loader */
91
+		$loader             = LoaderFactory::getLoader();
92
+		$this->core_config  = $core_config instanceof EE_Core_Config
93
+			? $core_config
94
+			: $loader->getShared('EE_Core_Config');
95
+		$this->request      = $request instanceof Request
96
+			? $request
97
+			: $loader->getShared('EventEspresso\core\services\request\Request');
98
+		$this->session      = $session instanceof EE_Session
99
+			? $session
100
+			: $loader->getShared('EE_Session');
101
+		$this->ticket_model = $ticket_model instanceof EEM_Ticket
102
+			? $ticket_model
103
+			: $loader->getShared('EEM_Ticket');
104
+		$this->tracker      = $tracker instanceof TicketDatetimeAvailabilityTracker
105
+			? $tracker
106
+			: $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker');
107
+	}
108
+
109
+
110
+	/**
111
+	 * cancelTicketSelections
112
+	 *
113
+	 * @return bool
114
+	 * @throws EE_Error
115
+	 * @throws InvalidArgumentException
116
+	 * @throws InvalidInterfaceException
117
+	 * @throws InvalidDataTypeException
118
+	 */
119
+	public function cancelTicketSelections()
120
+	{
121
+		// check nonce
122
+		if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
123
+			return false;
124
+		}
125
+		$this->session->clear_session(__CLASS__, __FUNCTION__);
126
+		if ($this->request->requestParamIsSet('event_id')) {
127
+			EEH_URL::safeRedirectAndExit(
128
+				EEH_Event_View::event_link_url(
129
+					$this->request->getRequestParam('event_id')
130
+				)
131
+			);
132
+		}
133
+		EEH_URL::safeRedirectAndExit(
134
+			site_url('/' . $this->core_config->event_cpt_slug . '/')
135
+		);
136
+		return true;
137
+	}
138
+
139
+
140
+	/**
141
+	 * processTicketSelectorNonce
142
+	 *
143
+	 * @param  string $nonce_name
144
+	 * @param string  $id
145
+	 * @return bool
146
+	 */
147
+	private function processTicketSelectorNonce($nonce_name, $id = '')
148
+	{
149
+		$nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce";
150
+		if (
151
+			! $this->request->isAdmin()
152
+			&& (
153
+				! $this->request->is_set($nonce_name_with_id)
154
+				|| ! wp_verify_nonce(
155
+					$this->request->get($nonce_name_with_id),
156
+					$nonce_name
157
+				)
158
+			)
159
+		) {
160
+			EE_Error::add_error(
161
+				sprintf(
162
+					esc_html__(
163
+						'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.',
164
+						'event_espresso'
165
+					),
166
+					'<br/>'
167
+				),
168
+				__FILE__,
169
+				__FUNCTION__,
170
+				__LINE__
171
+			);
172
+			return false;
173
+		}
174
+		return true;
175
+	}
176
+
177
+
178
+	/**
179
+	 * process_ticket_selections
180
+	 *
181
+	 * @return array|bool
182
+	 * @throws EE_Error
183
+	 * @throws InvalidArgumentException
184
+	 * @throws InvalidDataTypeException
185
+	 * @throws InvalidInterfaceException
186
+	 */
187
+	public function processTicketSelections()
188
+	{
189
+		do_action('EED_Ticket_Selector__process_ticket_selections__before');
190
+		if($this->request->isBot()) {
191
+			EEH_URL::safeRedirectAndExit(
192
+				apply_filters(
193
+					'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url',
194
+					site_url()
195
+				)
196
+			);
197
+		}
198
+		// do we have an event id?
199
+		$id = $this->getEventId();
200
+		// we should really only have 1 registration in the works now
201
+		// (ie, no MER) so unless otherwise requested, clear the session
202
+		if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) {
203
+			$this->session->clear_session(__CLASS__, __FUNCTION__);
204
+		}
205
+		// validate/sanitize/filter data
206
+		$valid = apply_filters(
207
+			'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data',
208
+			$this->validatePostData($id)
209
+		);
210
+		//check total tickets ordered vs max number of attendees that can register
211
+		if ($valid['total_tickets'] > $valid['max_atndz']) {
212
+			$this->maxAttendeesViolation($valid);
213
+		} else {
214
+			// all data appears to be valid
215
+			if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) {
216
+				return true;
217
+			}
218
+		}
219
+		// die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT
220
+		// at this point, just return if registration is being made from admin
221
+		if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
222
+			return false;
223
+		}
224
+		if ($valid['return_url']) {
225
+			EEH_URL::safeRedirectAndExit($valid['return_url']);
226
+		}
227
+		if ($id) {
228
+			EEH_URL::safeRedirectAndExit(get_permalink($id));
229
+		}
230
+		echo EE_Error::get_notices();
231
+		return false;
232
+	}
233
+
234
+
235
+	/**
236
+	 * @return int
237
+	 */
238
+	private function getEventId()
239
+	{
240
+		// do we have an event id?
241
+		if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
242
+			// $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
243
+			EE_Error::add_error(
244
+				sprintf(
245
+					esc_html__(
246
+						'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.',
247
+						'event_espresso'
248
+					),
249
+					'<br/>'
250
+				),
251
+				__FILE__,
252
+				__FUNCTION__,
253
+				__LINE__
254
+			);
255
+		}
256
+		//if event id is valid
257
+		return absint($this->request->getRequestParam('tkt-slctr-event-id'));
258
+	}
259
+
260
+
261
+	/**
262
+	 * validate_post_data
263
+	 *
264
+	 * @param int $id
265
+	 * @return array|FALSE
266
+	 */
267
+	private function validatePostData($id = 0)
268
+	{
269
+		if (! $id) {
270
+			EE_Error::add_error(
271
+				esc_html__('The event id provided was not valid.', 'event_espresso'),
272
+				__FILE__,
273
+				__FUNCTION__,
274
+				__LINE__
275
+			);
276
+			return false;
277
+		}
278
+		// start with an empty array()
279
+		$valid_data = array();
280
+		// grab valid id
281
+		$valid_data['id'] = $id;
282
+		// array of other form names
283
+		$inputs_to_clean = array(
284
+			'event_id'   => 'tkt-slctr-event-id',
285
+			'max_atndz'  => 'tkt-slctr-max-atndz-',
286
+			'rows'       => 'tkt-slctr-rows-',
287
+			'qty'        => 'tkt-slctr-qty-',
288
+			'ticket_id'  => 'tkt-slctr-ticket-id-',
289
+			'return_url' => 'tkt-slctr-return-url-',
290
+		);
291
+		// let's track the total number of tickets ordered.'
292
+		$valid_data['total_tickets'] = 0;
293
+		// cycle through $inputs_to_clean array
294
+		foreach ($inputs_to_clean as $what => $input_to_clean) {
295
+			// check for POST data
296
+			if ($this->request->requestParamIsSet($input_to_clean . $id)) {
297
+				// grab value
298
+				$input_value = $this->request->getRequestParam($input_to_clean . $id);
299
+				switch ($what) {
300
+					// integers
301
+					case 'event_id':
302
+						$valid_data[ $what ] = absint($input_value);
303
+						// get event via the event id we put in the form
304
+						break;
305
+					case 'rows':
306
+					case 'max_atndz':
307
+						$valid_data[ $what ] = absint($input_value);
308
+						break;
309
+					// arrays of integers
310
+					case 'qty':
311
+						/** @var array $row_qty */
312
+						$row_qty = $input_value;
313
+						// if qty is coming from a radio button input, then we need to assemble an array of rows
314
+						if (! is_array($row_qty)) {
315
+							/** @var string $row_qty */
316
+							// get number of rows
317
+							$rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id)
318
+								? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id))
319
+								: 1;
320
+							// explode integers by the dash
321
+							$row_qty = explode('-', $row_qty);
322
+							$row     = isset($row_qty[0]) ? absint($row_qty[0]) : 1;
323
+							$qty     = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
324
+							$row_qty = array($row => $qty);
325
+							for ($x = 1; $x <= $rows; $x++) {
326
+								if (! isset($row_qty[ $x ])) {
327
+									$row_qty[ $x ] = 0;
328
+								}
329
+							}
330
+						}
331
+						ksort($row_qty);
332
+						// cycle thru values
333
+						foreach ($row_qty as $qty) {
334
+							$qty = absint($qty);
335
+							// sanitize as integers
336
+							$valid_data[ $what ][]       = $qty;
337
+							$valid_data['total_tickets'] += $qty;
338
+						}
339
+						break;
340
+					// array of integers
341
+					case 'ticket_id':
342
+						// cycle thru values
343
+						foreach ((array) $input_value as $key => $value) {
344
+							// allow only integers
345
+							$valid_data[ $what ][ $key ] = absint($value);
346
+						}
347
+						break;
348
+					case 'return_url' :
349
+						// grab and sanitize return-url
350
+						$input_value = esc_url_raw($input_value);
351
+						// was the request coming from an iframe ? if so, then:
352
+						if (strpos($input_value, 'event_list=iframe')) {
353
+							// get anchor fragment
354
+							$input_value = explode('#', $input_value);
355
+							$input_value = end($input_value);
356
+							// use event list url instead, but append anchor
357
+							$input_value = EEH_Event_View::event_archive_url() . '#' . $input_value;
358
+						}
359
+						$valid_data[ $what ] = $input_value;
360
+						break;
361
+				}    // end switch $what
362
+			}
363
+		}    // end foreach $inputs_to_clean
364
+		return $valid_data;
365
+	}
366
+
367
+
368
+	/**
369
+	 * @param array $valid
370
+	 */
371
+	private function maxAttendeesViolation(array $valid)
372
+	{
373
+		// ordering too many tickets !!!
374
+		$total_tickets_string = esc_html(
375
+			_n(
376
+				'You have attempted to purchase %s ticket.',
377
+				'You have attempted to purchase %s tickets.',
378
+				$valid['total_tickets'],
379
+				'event_espresso'
380
+			)
381
+		);
382
+		$limit_error_1        = sprintf($total_tickets_string, $valid['total_tickets']);
383
+		// dev only message
384
+		$max_attendees_string = esc_html(
385
+			_n(
386
+				'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
387
+				'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
388
+				$valid['max_atndz'],
389
+				'event_espresso'
390
+			)
391
+		);
392
+		$limit_error_2    = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
393
+		EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
394
+	}
395
+
396
+
397
+	/**
398
+	 * @param array $valid
399
+	 * @return int|TRUE
400
+	 * @throws EE_Error
401
+	 * @throws InvalidArgumentException
402
+	 * @throws InvalidDataTypeException
403
+	 * @throws InvalidInterfaceException
404
+	 */
405
+	private function addTicketsToCart(array $valid)
406
+	{
407
+		$tickets_added = 0;
408
+		$tickets_selected = false;
409
+		if($valid['total_tickets'] > 0){
410
+			// load cart using factory because we don't want to do so until actually needed
411
+			$this->cart = CartFactory::getCart();
412
+			// cycle thru the number of data rows sent from the event listing
413
+			for ($x = 0; $x < $valid['rows']; $x++) {
414
+				// does this row actually contain a ticket quantity?
415
+				if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) {
416
+					// YES we have a ticket quantity
417
+					$tickets_selected = true;
418
+					$valid_ticket     = false;
419
+					// \EEH_Debug_Tools::printr(
420
+					//     $valid['ticket_id'][ $x ],
421
+					//     '$valid[\'ticket_id\'][ $x ]',
422
+					//     __FILE__, __LINE__
423
+					// );
424
+					if (isset($valid['ticket_id'][ $x ])) {
425
+						// get ticket via the ticket id we put in the form
426
+						$ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]);
427
+						if ($ticket instanceof EE_Ticket) {
428
+							$valid_ticket  = true;
429
+							$tickets_added += $this->addTicketToCart(
430
+								$ticket,
431
+								$valid['qty'][ $x ]
432
+							);
433
+						}
434
+					}
435
+					if ($valid_ticket !== true) {
436
+						// nothing added to cart retrieved
437
+						EE_Error::add_error(
438
+							sprintf(
439
+								esc_html__(
440
+									'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.',
441
+									'event_espresso'
442
+								),
443
+								'<br/>'
444
+							),
445
+							__FILE__, __FUNCTION__, __LINE__
446
+						);
447
+					}
448
+					if (EE_Error::has_error()) {
449
+						break;
450
+					}
451
+				}
452
+			}
453
+		}
454
+		do_action(
455
+			'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
456
+			$this->cart,
457
+			$this
458
+		);
459
+		if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
460
+			// no ticket quantities were selected
461
+			EE_Error::add_error(
462
+				esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'),
463
+				__FILE__, __FUNCTION__, __LINE__
464
+			);
465
+		}
466
+		return $tickets_added;
467
+	}
468
+
469
+
470
+
471
+	/**
472
+	 * adds a ticket to the cart
473
+	 *
474
+	 * @param EE_Ticket $ticket
475
+	 * @param int        $qty
476
+	 * @return TRUE on success, FALSE on fail
477
+	 * @throws InvalidArgumentException
478
+	 * @throws InvalidInterfaceException
479
+	 * @throws InvalidDataTypeException
480
+	 * @throws EE_Error
481
+	 */
482
+	private function addTicketToCart(EE_Ticket $ticket, $qty = 1)
483
+	{
484
+		// get the number of spaces left for this datetime ticket
485
+		$available_spaces = $this->tracker->ticketDatetimeAvailability($ticket);
486
+		// compare available spaces against the number of tickets being purchased
487
+		if ($available_spaces >= $qty) {
488
+			// allow addons to prevent a ticket from being added to cart
489
+			if (
490
+				! apply_filters(
491
+					'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart',
492
+					true,
493
+					$ticket,
494
+					$qty,
495
+					$available_spaces
496
+				)
497
+			) {
498
+				return false;
499
+			}
500
+			$qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket));
501
+			// add event to cart
502
+			if ($this->cart->add_ticket_to_cart($ticket, $qty)) {
503
+				$this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty);
504
+				return true;
505
+			}
506
+			return false;
507
+		}
508
+		$this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count());
509
+		return false;
510
+	}
511
+
512
+
513
+	/**
514
+	 * @param $tickets_added
515
+	 * @return bool
516
+	 * @throws InvalidInterfaceException
517
+	 * @throws InvalidDataTypeException
518
+	 * @throws EE_Error
519
+	 * @throws InvalidArgumentException
520
+	 */
521
+	private function processSuccessfulCart($tickets_added)
522
+	{
523
+		// exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
524
+		if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
525
+			// make sure cart is loaded
526
+			if(! $this->cart  instanceof EE_Cart){
527
+				$this->cart = CartFactory::getCart();
528
+			}
529
+			do_action(
530
+				'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout',
531
+				$this->cart,
532
+				$this
533
+			);
534
+			$this->cart->recalculate_all_cart_totals();
535
+			$this->cart->save_cart(false);
536
+			// exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<  OR HERE TO KILL REDIRECT AFTER CART UPDATE
537
+			// just return TRUE for registrations being made from admin
538
+			if ($this->request->isAdmin() || $this->request->isFrontAjax()) {
539
+				return true;
540
+			}
541
+			EEH_URL::safeRedirectAndExit(
542
+				apply_filters(
543
+					'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url',
544
+					$this->core_config->reg_page_url()
545
+				)
546
+			);
547
+		}
548
+		if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
549
+			// nothing added to cart
550
+			EE_Error::add_attention(
551
+				esc_html__('No tickets were added for the event', 'event_espresso'),
552
+				__FILE__, __FUNCTION__, __LINE__
553
+			);
554
+		}
555
+		return false;
556
+	}
557 557
 }
558 558
 // End of file ProcessTicketSelector.php
559 559
 // Location: /ProcessTicketSelector.php
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
     public function cancelTicketSelections()
120 120
     {
121 121
         // check nonce
122
-        if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
122
+        if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) {
123 123
             return false;
124 124
         }
125 125
         $this->session->clear_session(__CLASS__, __FUNCTION__);
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
             );
132 132
         }
133 133
         EEH_URL::safeRedirectAndExit(
134
-            site_url('/' . $this->core_config->event_cpt_slug . '/')
134
+            site_url('/'.$this->core_config->event_cpt_slug.'/')
135 135
         );
136 136
         return true;
137 137
     }
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
     public function processTicketSelections()
188 188
     {
189 189
         do_action('EED_Ticket_Selector__process_ticket_selections__before');
190
-        if($this->request->isBot()) {
190
+        if ($this->request->isBot()) {
191 191
             EEH_URL::safeRedirectAndExit(
192 192
                 apply_filters(
193 193
                     'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url',
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
     private function getEventId()
239 239
     {
240 240
         // do we have an event id?
241
-        if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
241
+        if ( ! $this->request->requestParamIsSet('tkt-slctr-event-id')) {
242 242
             // $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
243 243
             EE_Error::add_error(
244 244
                 sprintf(
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
      */
267 267
     private function validatePostData($id = 0)
268 268
     {
269
-        if (! $id) {
269
+        if ( ! $id) {
270 270
             EE_Error::add_error(
271 271
                 esc_html__('The event id provided was not valid.', 'event_espresso'),
272 272
                 __FILE__,
@@ -293,29 +293,29 @@  discard block
 block discarded – undo
293 293
         // cycle through $inputs_to_clean array
294 294
         foreach ($inputs_to_clean as $what => $input_to_clean) {
295 295
             // check for POST data
296
-            if ($this->request->requestParamIsSet($input_to_clean . $id)) {
296
+            if ($this->request->requestParamIsSet($input_to_clean.$id)) {
297 297
                 // grab value
298
-                $input_value = $this->request->getRequestParam($input_to_clean . $id);
298
+                $input_value = $this->request->getRequestParam($input_to_clean.$id);
299 299
                 switch ($what) {
300 300
                     // integers
301 301
                     case 'event_id':
302
-                        $valid_data[ $what ] = absint($input_value);
302
+                        $valid_data[$what] = absint($input_value);
303 303
                         // get event via the event id we put in the form
304 304
                         break;
305 305
                     case 'rows':
306 306
                     case 'max_atndz':
307
-                        $valid_data[ $what ] = absint($input_value);
307
+                        $valid_data[$what] = absint($input_value);
308 308
                         break;
309 309
                     // arrays of integers
310 310
                     case 'qty':
311 311
                         /** @var array $row_qty */
312 312
                         $row_qty = $input_value;
313 313
                         // if qty is coming from a radio button input, then we need to assemble an array of rows
314
-                        if (! is_array($row_qty)) {
314
+                        if ( ! is_array($row_qty)) {
315 315
                             /** @var string $row_qty */
316 316
                             // get number of rows
317
-                            $rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id)
318
-                                ? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id))
317
+                            $rows = $this->request->requestParamIsSet('tkt-slctr-rows-'.$id)
318
+                                ? absint($this->request->getRequestParam('tkt-slctr-rows-'.$id))
319 319
                                 : 1;
320 320
                             // explode integers by the dash
321 321
                             $row_qty = explode('-', $row_qty);
@@ -323,8 +323,8 @@  discard block
 block discarded – undo
323 323
                             $qty     = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
324 324
                             $row_qty = array($row => $qty);
325 325
                             for ($x = 1; $x <= $rows; $x++) {
326
-                                if (! isset($row_qty[ $x ])) {
327
-                                    $row_qty[ $x ] = 0;
326
+                                if ( ! isset($row_qty[$x])) {
327
+                                    $row_qty[$x] = 0;
328 328
                                 }
329 329
                             }
330 330
                         }
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
                         foreach ($row_qty as $qty) {
334 334
                             $qty = absint($qty);
335 335
                             // sanitize as integers
336
-                            $valid_data[ $what ][]       = $qty;
336
+                            $valid_data[$what][] = $qty;
337 337
                             $valid_data['total_tickets'] += $qty;
338 338
                         }
339 339
                         break;
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
                         // cycle thru values
343 343
                         foreach ((array) $input_value as $key => $value) {
344 344
                             // allow only integers
345
-                            $valid_data[ $what ][ $key ] = absint($value);
345
+                            $valid_data[$what][$key] = absint($value);
346 346
                         }
347 347
                         break;
348 348
                     case 'return_url' :
@@ -354,9 +354,9 @@  discard block
 block discarded – undo
354 354
                             $input_value = explode('#', $input_value);
355 355
                             $input_value = end($input_value);
356 356
                             // use event list url instead, but append anchor
357
-                            $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value;
357
+                            $input_value = EEH_Event_View::event_archive_url().'#'.$input_value;
358 358
                         }
359
-                        $valid_data[ $what ] = $input_value;
359
+                        $valid_data[$what] = $input_value;
360 360
                         break;
361 361
                 }    // end switch $what
362 362
             }
@@ -389,8 +389,8 @@  discard block
 block discarded – undo
389 389
                 'event_espresso'
390 390
             )
391 391
         );
392
-        $limit_error_2    = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
393
-        EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
392
+        $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']);
393
+        EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__);
394 394
     }
395 395
 
396 396
 
@@ -406,13 +406,13 @@  discard block
 block discarded – undo
406 406
     {
407 407
         $tickets_added = 0;
408 408
         $tickets_selected = false;
409
-        if($valid['total_tickets'] > 0){
409
+        if ($valid['total_tickets'] > 0) {
410 410
             // load cart using factory because we don't want to do so until actually needed
411 411
             $this->cart = CartFactory::getCart();
412 412
             // cycle thru the number of data rows sent from the event listing
413 413
             for ($x = 0; $x < $valid['rows']; $x++) {
414 414
                 // does this row actually contain a ticket quantity?
415
-                if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) {
415
+                if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) {
416 416
                     // YES we have a ticket quantity
417 417
                     $tickets_selected = true;
418 418
                     $valid_ticket     = false;
@@ -421,14 +421,14 @@  discard block
 block discarded – undo
421 421
                     //     '$valid[\'ticket_id\'][ $x ]',
422 422
                     //     __FILE__, __LINE__
423 423
                     // );
424
-                    if (isset($valid['ticket_id'][ $x ])) {
424
+                    if (isset($valid['ticket_id'][$x])) {
425 425
                         // get ticket via the ticket id we put in the form
426
-                        $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]);
426
+                        $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][$x]);
427 427
                         if ($ticket instanceof EE_Ticket) {
428
-                            $valid_ticket  = true;
428
+                            $valid_ticket = true;
429 429
                             $tickets_added += $this->addTicketToCart(
430 430
                                 $ticket,
431
-                                $valid['qty'][ $x ]
431
+                                $valid['qty'][$x]
432 432
                             );
433 433
                         }
434 434
                     }
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
             $this->cart,
457 457
             $this
458 458
         );
459
-        if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
459
+        if ( ! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) {
460 460
             // no ticket quantities were selected
461 461
             EE_Error::add_error(
462 462
                 esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'),
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
         // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
524 524
         if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
525 525
             // make sure cart is loaded
526
-            if(! $this->cart  instanceof EE_Cart){
526
+            if ( ! $this->cart  instanceof EE_Cart) {
527 527
                 $this->cart = CartFactory::getCart();
528 528
             }
529 529
             do_action(
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
                 )
546 546
             );
547 547
         }
548
-        if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
548
+        if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
549 549
             // nothing added to cart
550 550
             EE_Error::add_attention(
551 551
                 esc_html__('No tickets were added for the event', 'event_espresso'),
Please login to merge, or discard this patch.
widgets/upcoming_events/EEW_Upcoming_Events.widget.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -210,14 +210,14 @@  discard block
 block discarded – undo
210 210
 		        <?php _e('Show on all Pages:', 'event_espresso'); ?>
211 211
 			</label>
212 212
 	 	    <?php
213
-	 	    echo EEH_Form_Fields::select(
214
-	 	        __('Show on all Pages:', 'event_espresso'),
215
-	 	        $instance['show_everywhere'],
216
-	 	        $yes_no_values,
217
-	 	        $this->get_field_name('show_everywhere'),
218
-	 	        $this->get_field_id('show_everywhere')
219
-	 	    );
220
-	 	    ?>
213
+	 		echo EEH_Form_Fields::select(
214
+	 			__('Show on all Pages:', 'event_espresso'),
215
+	 			$instance['show_everywhere'],
216
+	 			$yes_no_values,
217
+	 			$this->get_field_name('show_everywhere'),
218
+	 			$this->get_field_id('show_everywhere')
219
+	 		);
220
+	 		?>
221 221
 	 	</p>
222 222
 		<p>
223 223
 			<label for="<?php echo $this->get_field_id('date_limit'); ?>">
@@ -300,14 +300,14 @@  discard block
 block discarded – undo
300 300
 				extract($args);
301 301
 
302 302
 				// add function to make the title a link
303
-	            add_filter('widget_title', array($this, 'make_the_title_a_link'), 15);
303
+				add_filter('widget_title', array($this, 'make_the_title_a_link'), 15);
304 304
 
305 305
 				$title = isset( $instance['title'] ) && ! empty( $instance['title'] ) ? $instance['title'] : '';
306 306
 				// filter the title
307 307
 				$title = apply_filters('widget_title', $title);
308 308
 
309 309
 				// remove the function from the filter, so it does not affect other widgets
310
-	            remove_filter('widget_title', array($this, 'make_the_title_a_link'), 15);
310
+				remove_filter('widget_title', array($this, 'make_the_title_a_link'), 15);
311 311
 
312 312
 				// Before widget (defined by themes).
313 313
 				echo $before_widget;
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 	 * @return string
420 420
 	 */
421 421
 	public function make_the_title_a_link($title) {
422
-	    return '<a href="' . EEH_Event_View::event_archive_url() . '">' . $title . '</a>';
422
+		return '<a href="' . EEH_Event_View::event_archive_url() . '">' . $title . '</a>';
423 423
 	}
424 424
 
425 425
 }
Please login to merge, or discard this patch.
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -31,8 +31,8 @@  discard block
 block discarded – undo
31 31
 	 */
32 32
 	public function __construct() {
33 33
 		parent::__construct(
34
-			__( 'Event Espresso Upcoming Events', 'event_espresso' ),
35
-			 array( 'description' => __( 'A widget to display your upcoming events.', 'event_espresso' ))
34
+			__('Event Espresso Upcoming Events', 'event_espresso'),
35
+			 array('description' => __('A widget to display your upcoming events.', 'event_espresso'))
36 36
 		);
37 37
 	}
38 38
 
@@ -45,9 +45,9 @@  discard block
 block discarded – undo
45 45
 	 * @param array $instance Previously saved values from database.
46 46
 	 * @return string|void
47 47
 	 */
48
-	public function form( $instance ) {
48
+	public function form($instance) {
49 49
 
50
-		EE_Registry::instance()->load_class( 'Question_Option', array(), FALSE, FALSE, TRUE );
50
+		EE_Registry::instance()->load_class('Question_Option', array(), FALSE, FALSE, TRUE);
51 51
 		// Set up some default widget settings.
52 52
 		$defaults = array(
53 53
 			'title' => __('Upcoming Events', 'event_espresso'),
@@ -63,16 +63,16 @@  discard block
 block discarded – undo
63 63
 			'image_size' => 'medium'
64 64
 		);
65 65
 
66
-		$instance = wp_parse_args( (array) $instance, $defaults );
66
+		$instance = wp_parse_args((array) $instance, $defaults);
67 67
 		// don't add HTML labels for EE_Form_Fields generated inputs
68
-		add_filter( 'FHEE__EEH_Form_Fields__label_html', '__return_empty_string' );
68
+		add_filter('FHEE__EEH_Form_Fields__label_html', '__return_empty_string');
69 69
 		$yes_no_values = array(
70
-			EE_Question_Option::new_instance( array( 'QSO_value' => FALSE, 'QSO_desc' => __('No', 'event_espresso'))),
71
-			EE_Question_Option::new_instance( array( 'QSO_value' => TRUE, 'QSO_desc' => __('Yes', 'event_espresso')))
70
+			EE_Question_Option::new_instance(array('QSO_value' => FALSE, 'QSO_desc' => __('No', 'event_espresso'))),
71
+			EE_Question_Option::new_instance(array('QSO_value' => TRUE, 'QSO_desc' => __('Yes', 'event_espresso')))
72 72
 		);
73 73
 		$sort_values = array(
74
-			EE_Question_Option::new_instance( array( 'QSO_value' => 'ASC', 'QSO_desc' => __('ASC', 'event_espresso'))),
75
-			EE_Question_Option::new_instance( array( 'QSO_value' => 'DESC', 'QSO_desc' => __('DESC', 'event_espresso')))
74
+			EE_Question_Option::new_instance(array('QSO_value' => 'ASC', 'QSO_desc' => __('ASC', 'event_espresso'))),
75
+			EE_Question_Option::new_instance(array('QSO_value' => 'DESC', 'QSO_desc' => __('DESC', 'event_espresso')))
76 76
 		);
77 77
 
78 78
 	?>
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 			<label for="<?php echo $this->get_field_id('title'); ?>">
84 84
 				<?php _e('Title:', 'event_espresso'); ?>
85 85
 			</label>
86
-			<input id="<?php echo $this->get_field_id('title'); ?>" class="widefat" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" type="text" />
86
+			<input id="<?php echo $this->get_field_id('title'); ?>" class="widefat" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($instance['title']); ?>" type="text" />
87 87
 		</p>
88 88
 		<p>
89 89
 			<label for="<?php echo $this->get_field_id('category_name'); ?>">
@@ -92,16 +92,16 @@  discard block
 block discarded – undo
92 92
 			<?php
93 93
 			$event_categories = array();
94 94
 			/** @type EEM_Term $EEM_Term */
95
-			$EEM_Term = EE_Registry::instance()->load_model( 'Term' );
96
-			$categories = $EEM_Term->get_all_ee_categories( TRUE );
97
-			if ( $categories ) {
98
-				foreach ( $categories as $category ) {
99
-					if ( $category instanceof EE_Term ) {
100
-						$event_categories[] = EE_Question_Option::new_instance( array( 'QSO_value' => $category->get( 'slug' ), 'QSO_desc' => $category->get( 'name' )));
95
+			$EEM_Term = EE_Registry::instance()->load_model('Term');
96
+			$categories = $EEM_Term->get_all_ee_categories(TRUE);
97
+			if ($categories) {
98
+				foreach ($categories as $category) {
99
+					if ($category instanceof EE_Term) {
100
+						$event_categories[] = EE_Question_Option::new_instance(array('QSO_value' => $category->get('slug'), 'QSO_desc' => $category->get('name')));
101 101
 					}
102 102
 				}
103 103
 			}
104
-			array_unshift( $event_categories, EE_Question_Option::new_instance( array( 'QSO_value' => '', 'QSO_desc' => __(' - display all - ', 'event_espresso'))));
104
+			array_unshift($event_categories, EE_Question_Option::new_instance(array('QSO_value' => '', 'QSO_desc' => __(' - display all - ', 'event_espresso'))));
105 105
 			echo EEH_Form_Fields::select(
106 106
 				 __('Event Category:', 'event_espresso'),
107 107
 				$instance['category_name'],
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 				 __('Show Expired Events:', 'event_espresso'),
127 127
 				$instance['show_expired'],
128 128
 				array(
129
-					EE_Question_Option::new_instance( array( 'QSO_value' => 0, 'QSO_desc' => __('No', 'event_espresso'))), 
130
-					EE_Question_Option::new_instance( array( 'QSO_value' => 1, 'QSO_desc' => __('Yes', 'event_espresso'))), 
131
-					EE_Question_Option::new_instance( array( 'QSO_value' => 2, 'QSO_desc' => __('Show Only Expired', 'event_espresso'))), 
129
+					EE_Question_Option::new_instance(array('QSO_value' => 0, 'QSO_desc' => __('No', 'event_espresso'))), 
130
+					EE_Question_Option::new_instance(array('QSO_value' => 1, 'QSO_desc' => __('Yes', 'event_espresso'))), 
131
+					EE_Question_Option::new_instance(array('QSO_value' => 2, 'QSO_desc' => __('Show Only Expired', 'event_espresso'))), 
132 132
 				),
133 133
 				$this->get_field_name('show_expired'),
134 134
 				$this->get_field_id('show_expired')
@@ -156,16 +156,16 @@  discard block
 block discarded – undo
156 156
 			<?php
157 157
 			$image_sizes = array();
158 158
 			$sizes = get_intermediate_image_sizes();
159
-			if ( $sizes ) {
159
+			if ($sizes) {
160 160
 				// loop thru images and create option objects out of them
161
-				foreach ( $sizes as $image_size ) {
162
-					$image_size = trim( $image_size );
161
+				foreach ($sizes as $image_size) {
162
+					$image_size = trim($image_size);
163 163
 					// no big images plz
164
-					if ( ! in_array( $image_size, array( 'large', 'post-thumbnail' ))) {
165
-						$image_sizes[] = EE_Question_Option::new_instance( array( 'QSO_value' => $image_size, 'QSO_desc' => $image_size ));
164
+					if ( ! in_array($image_size, array('large', 'post-thumbnail'))) {
165
+						$image_sizes[] = EE_Question_Option::new_instance(array('QSO_value' => $image_size, 'QSO_desc' => $image_size));
166 166
 					}
167 167
 				}
168
-				$image_sizes[] = EE_Question_Option::new_instance( array( 'QSO_value' => 'none', 'QSO_desc' =>  __('don\'t show images', 'event_espresso') ));
168
+				$image_sizes[] = EE_Question_Option::new_instance(array('QSO_value' => 'none', 'QSO_desc' =>  __('don\'t show images', 'event_espresso')));
169 169
 			}
170 170
 			echo EEH_Form_Fields::select(
171 171
 				 __('Image Size:', 'event_espresso'),
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 			<label for="<?php echo $this->get_field_id('date_limit'); ?>">
224 224
 				<?php _e('Number of Dates to Display:', 'event_espresso'); ?>
225 225
 			</label>
226
-			<input id="<?php echo $this->get_field_id('date_limit'); ?>" name="<?php echo $this->get_field_name('date_limit'); ?>" value="<?php echo esc_attr( $instance['date_limit'] ); ?>" size="3" type="text" />
226
+			<input id="<?php echo $this->get_field_id('date_limit'); ?>" name="<?php echo $this->get_field_name('date_limit'); ?>" value="<?php echo esc_attr($instance['date_limit']); ?>" size="3" type="text" />
227 227
 		</p>
228 228
 		<p>
229 229
 			<label for="<?php echo $this->get_field_id('date_range'); ?>">
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
 	 *
256 256
 	 * @return array Updated safe values to be saved.
257 257
 	 */
258
-	public function update( $new_instance, $old_instance ) {
258
+	public function update($new_instance, $old_instance) {
259 259
 		$instance = $old_instance;
260
-		$instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : '';
260
+		$instance['title'] = ! empty($new_instance['title']) ? strip_tags($new_instance['title']) : '';
261 261
 		$instance['category_name'] = $new_instance['category_name'];
262 262
 		$instance['show_expired'] = $new_instance['show_expired'];
263 263
 		$instance['limit'] = $new_instance['limit'];
@@ -281,18 +281,18 @@  discard block
 block discarded – undo
281 281
 	 * @param array $args     Widget arguments.
282 282
 	 * @param array $instance Saved values from database.
283 283
 	 */
284
-	public function widget( $args, $instance ) {
284
+	public function widget($args, $instance) {
285 285
 
286 286
 		global $post;
287 287
 		// make sure there is some kinda post object
288
-		if ( $post instanceof WP_Post ) {
288
+		if ($post instanceof WP_Post) {
289 289
 			$before_widget = '';
290 290
 			$before_title = '';
291 291
 			$after_title = '';
292 292
 			$after_widget = '';
293 293
 			// but NOT an events archives page, cuz that would be like two event lists on the same page
294
-			$show_everywhere = isset( $instance['show_everywhere'] ) ? (bool) absint( $instance['show_everywhere'] ) : TRUE;
295
-			if ( $show_everywhere || ! ( $post->post_type == 'espresso_events' && is_archive() )) {
294
+			$show_everywhere = isset($instance['show_everywhere']) ? (bool) absint($instance['show_everywhere']) : TRUE;
295
+			if ($show_everywhere || ! ($post->post_type == 'espresso_events' && is_archive())) {
296 296
 				// let's use some of the event helper functions'
297 297
 				// make separate vars out of attributes
298 298
 
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 				// add function to make the title a link
303 303
 	            add_filter('widget_title', array($this, 'make_the_title_a_link'), 15);
304 304
 
305
-				$title = isset( $instance['title'] ) && ! empty( $instance['title'] ) ? $instance['title'] : '';
305
+				$title = isset($instance['title']) && ! empty($instance['title']) ? $instance['title'] : '';
306 306
 				// filter the title
307 307
 				$title = apply_filters('widget_title', $title);
308 308
 
@@ -312,90 +312,90 @@  discard block
 block discarded – undo
312 312
 				// Before widget (defined by themes).
313 313
 				echo $before_widget;
314 314
 				// Display the widget title if one was input (before and after defined by themes).
315
-				if ( ! empty( $title )) {
316
-					echo $before_title . $title . $after_title;
315
+				if ( ! empty($title)) {
316
+					echo $before_title.$title.$after_title;
317 317
 				}
318 318
 				// grab widget settings
319
-				$category = isset( $instance['category_name'] ) && ! empty( $instance['category_name'] ) ? $instance['category_name'] : FALSE;
320
-				$show_expired = isset( $instance['show_expired'] ) ? absint( $instance['show_expired'] ) : 0;
321
-				$image_size = isset( $instance['image_size'] ) && ! empty( $instance['image_size'] ) ? $instance['image_size'] : 'medium';
322
-				$show_desc = isset( $instance['show_desc'] ) ? (bool) absint( $instance['show_desc'] ) : TRUE;
323
-				$show_dates = isset( $instance['show_dates'] ) ? (bool) absint( $instance['show_dates'] ) : TRUE;
324
-				$date_limit = isset( $instance['date_limit'] ) && ! empty( $instance['date_limit'] ) ? $instance['date_limit'] : NULL;
325
-				$date_range = isset( $instance['date_range'] ) && ! empty( $instance['date_range'] ) ? $instance['date_range'] : FALSE;
319
+				$category = isset($instance['category_name']) && ! empty($instance['category_name']) ? $instance['category_name'] : FALSE;
320
+				$show_expired = isset($instance['show_expired']) ? absint($instance['show_expired']) : 0;
321
+				$image_size = isset($instance['image_size']) && ! empty($instance['image_size']) ? $instance['image_size'] : 'medium';
322
+				$show_desc = isset($instance['show_desc']) ? (bool) absint($instance['show_desc']) : TRUE;
323
+				$show_dates = isset($instance['show_dates']) ? (bool) absint($instance['show_dates']) : TRUE;
324
+				$date_limit = isset($instance['date_limit']) && ! empty($instance['date_limit']) ? $instance['date_limit'] : NULL;
325
+				$date_range = isset($instance['date_range']) && ! empty($instance['date_range']) ? $instance['date_range'] : FALSE;
326 326
 				// start to build our where clause
327 327
 				$where = array(
328 328
 //					'Datetime.DTT_is_primary' => 1,
329
-					'status' => array( 'IN', array( 'publish', 'sold_out' ) )
329
+					'status' => array('IN', array('publish', 'sold_out'))
330 330
 				);
331 331
 				// add category
332
-				if ( $category ) {
332
+				if ($category) {
333 333
 					$where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
334 334
 					$where['Term_Taxonomy.Term.slug'] = $category;
335 335
 				}
336 336
 				// if NOT expired then we want events that start today or in the future
337 337
 				// if NOT show expired then we want events that start today or in the future 
338
-				if ( $show_expired == 0 ) { 
339
-				 	$where['Datetime.DTT_EVT_end'] = array( '>=', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) ); 
338
+				if ($show_expired == 0) { 
339
+				 	$where['Datetime.DTT_EVT_end'] = array('>=', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')); 
340 340
 				} 
341 341
 				// if show ONLY expired we want events that ended prior to today 
342
-				if ( $show_expired == 2 ) { 
343
-					$where['Datetime.DTT_EVT_end'] = array( '<=', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_start' ) ); 
342
+				if ($show_expired == 2) { 
343
+					$where['Datetime.DTT_EVT_end'] = array('<=', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')); 
344 344
 				}
345 345
 				// allow $where to be filtered
346
-				$where = apply_filters( 'FHEE__EEW_Upcoming_Events__widget__where', $where, $category, $show_expired );
346
+				$where = apply_filters('FHEE__EEW_Upcoming_Events__widget__where', $where, $category, $show_expired);
347 347
 				// run the query
348
-				$events = EE_Registry::instance()->load_model( 'Event' )->get_all( array(
348
+				$events = EE_Registry::instance()->load_model('Event')->get_all(array(
349 349
 					$where,
350 350
 					'limit' => isset($instance['limit']) && $instance['limit'] > 0 
351
-								? '0,' . $instance['limit'] 
351
+								? '0,'.$instance['limit'] 
352 352
 								: '0,10',
353 353
 					'order_by' => 'Datetime.DTT_EVT_start',
354 354
 					'order' => isset($instance['sort']) ? $instance['sort'] : 'ASC',
355 355
 					'group_by' => 'EVT_ID'
356 356
 				));
357 357
 
358
-				if ( ! empty( $events )) {
358
+				if ( ! empty($events)) {
359 359
 					echo '<ul class="ee-upcoming-events-widget-ul">';
360
-					foreach ( $events as $event ) {
361
-						if ( $event instanceof EE_Event && ( !is_single() || $post->ID != $event->ID() ) ) {
360
+					foreach ($events as $event) {
361
+						if ($event instanceof EE_Event && ( ! is_single() || $post->ID != $event->ID())) {
362 362
 							//printr( $event, '$event  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
363
-							echo '<li id="ee-upcoming-events-widget-li-' . $event->ID() . '" class="ee-upcoming-events-widget-li">';
363
+							echo '<li id="ee-upcoming-events-widget-li-'.$event->ID().'" class="ee-upcoming-events-widget-li">';
364 364
 							// how big is the event name ?
365
-							$name_length = strlen( $event->name() );
366
-							switch( $name_length ) {
365
+							$name_length = strlen($event->name());
366
+							switch ($name_length) {
367 367
 								case $name_length > 70 :
368
-									$len_class =  ' three-line';
368
+									$len_class = ' three-line';
369 369
 									break;
370 370
 								case $name_length > 35 :
371
-									$len_class =  ' two-line';
371
+									$len_class = ' two-line';
372 372
 									break;
373 373
 								default :
374
-									$len_class =  ' one-line';
374
+									$len_class = ' one-line';
375 375
 							}
376
-							$event_url = apply_filters( 'FHEE_EEW_Upcoming_Events__widget__event_url', $event->get_permalink(), $event );
377
-							echo '<h5 class="ee-upcoming-events-widget-title-h5"><a class="ee-widget-event-name-a' . $len_class . '" href="' . $event_url . '">' . $event->name() . '</a></h5>';
378
-							if ( post_password_required( $event->ID() ) ) {
379
-								$pswd_form = apply_filters( 'FHEE_EEW_Upcoming_Events__widget__password_form', get_the_password_form( $event->ID() ), $event );
376
+							$event_url = apply_filters('FHEE_EEW_Upcoming_Events__widget__event_url', $event->get_permalink(), $event);
377
+							echo '<h5 class="ee-upcoming-events-widget-title-h5"><a class="ee-widget-event-name-a'.$len_class.'" href="'.$event_url.'">'.$event->name().'</a></h5>';
378
+							if (post_password_required($event->ID())) {
379
+								$pswd_form = apply_filters('FHEE_EEW_Upcoming_Events__widget__password_form', get_the_password_form($event->ID()), $event);
380 380
 								echo $pswd_form;
381 381
 							} else {
382
-								if ( has_post_thumbnail( $event->ID() ) && $image_size != 'none' ) {
383
-									echo '<div class="ee-upcoming-events-widget-img-dv"><a class="ee-upcoming-events-widget-img" href="' . $event_url . '">' . get_the_post_thumbnail( $event->ID(), $image_size ) . '</a></div>';
382
+								if (has_post_thumbnail($event->ID()) && $image_size != 'none') {
383
+									echo '<div class="ee-upcoming-events-widget-img-dv"><a class="ee-upcoming-events-widget-img" href="'.$event_url.'">'.get_the_post_thumbnail($event->ID(), $image_size).'</a></div>';
384 384
 								}
385
-								$desc = $event->short_description( 25 );
386
-								if ( $show_dates ) {
387
-									$date_format = apply_filters( 'FHEE__espresso_event_date_range__date_format', get_option( 'date_format' ));
388
-									$time_format = apply_filters( 'FHEE__espresso_event_date_range__time_format', get_option( 'time_format' ));
389
-									$single_date_format = apply_filters( 'FHEE__espresso_event_date_range__single_date_format', get_option( 'date_format' ));
390
-									$single_time_format = apply_filters( 'FHEE__espresso_event_date_range__single_time_format', get_option( 'time_format' ));
391
-									if ( $date_range == TRUE ) {
392
-										echo espresso_event_date_range( $date_format, $time_format, $single_date_format, $single_time_format, $event->ID() );
393
-									}else{
394
-										echo espresso_list_of_event_dates( $event->ID(), $date_format, $time_format, FALSE, NULL, TRUE, TRUE, $date_limit );
385
+								$desc = $event->short_description(25);
386
+								if ($show_dates) {
387
+									$date_format = apply_filters('FHEE__espresso_event_date_range__date_format', get_option('date_format'));
388
+									$time_format = apply_filters('FHEE__espresso_event_date_range__time_format', get_option('time_format'));
389
+									$single_date_format = apply_filters('FHEE__espresso_event_date_range__single_date_format', get_option('date_format'));
390
+									$single_time_format = apply_filters('FHEE__espresso_event_date_range__single_time_format', get_option('time_format'));
391
+									if ($date_range == TRUE) {
392
+										echo espresso_event_date_range($date_format, $time_format, $single_date_format, $single_time_format, $event->ID());
393
+									} else {
394
+										echo espresso_list_of_event_dates($event->ID(), $date_format, $time_format, FALSE, NULL, TRUE, TRUE, $date_limit);
395 395
 									}
396 396
 								}
397
-								if ( $show_desc && $desc ) {
398
-									echo '<p style="margin-top: .5em">' . $desc . '</p>';
397
+								if ($show_desc && $desc) {
398
+									echo '<p style="margin-top: .5em">'.$desc.'</p>';
399 399
 								}
400 400
 							}
401 401
 							echo '</li>';
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 	 * @return string
420 420
 	 */
421 421
 	public function make_the_title_a_link($title) {
422
-	    return '<a href="' . EEH_Event_View::event_archive_url() . '">' . $title . '</a>';
422
+	    return '<a href="'.EEH_Event_View::event_archive_url().'">'.$title.'</a>';
423 423
 	}
424 424
 
425 425
 }
Please login to merge, or discard this patch.
core/EE_Config.core.php 1 patch
Indentation   +3092 added lines, -3092 removed lines patch added patch discarded remove patch
@@ -17,2474 +17,2474 @@  discard block
 block discarded – undo
17 17
 final class EE_Config implements ResettableInterface
18 18
 {
19 19
 
20
-    const OPTION_NAME        = 'ee_config';
20
+	const OPTION_NAME        = 'ee_config';
21
+
22
+	const LOG_NAME           = 'ee_config_log';
23
+
24
+	const LOG_LENGTH         = 100;
25
+
26
+	const ADDON_OPTION_NAMES = 'ee_config_option_names';
27
+
28
+
29
+	/**
30
+	 *    instance of the EE_Config object
31
+	 *
32
+	 * @var    EE_Config $_instance
33
+	 * @access    private
34
+	 */
35
+	private static $_instance;
36
+
37
+	/**
38
+	 * @var boolean $_logging_enabled
39
+	 */
40
+	private static $_logging_enabled = false;
41
+
42
+	/**
43
+	 * @var LegacyShortcodesManager $legacy_shortcodes_manager
44
+	 */
45
+	private $legacy_shortcodes_manager;
46
+
47
+	/**
48
+	 * An StdClass whose property names are addon slugs,
49
+	 * and values are their config classes
50
+	 *
51
+	 * @var StdClass
52
+	 */
53
+	public $addons;
54
+
55
+	/**
56
+	 * @var EE_Admin_Config
57
+	 */
58
+	public $admin;
59
+
60
+	/**
61
+	 * @var EE_Core_Config
62
+	 */
63
+	public $core;
64
+
65
+	/**
66
+	 * @var EE_Currency_Config
67
+	 */
68
+	public $currency;
69
+
70
+	/**
71
+	 * @var EE_Organization_Config
72
+	 */
73
+	public $organization;
74
+
75
+	/**
76
+	 * @var EE_Registration_Config
77
+	 */
78
+	public $registration;
79
+
80
+	/**
81
+	 * @var EE_Template_Config
82
+	 */
83
+	public $template_settings;
84
+
85
+	/**
86
+	 * Holds EE environment values.
87
+	 *
88
+	 * @var EE_Environment_Config
89
+	 */
90
+	public $environment;
91
+
92
+	/**
93
+	 * settings pertaining to Google maps
94
+	 *
95
+	 * @var EE_Map_Config
96
+	 */
97
+	public $map_settings;
98
+
99
+	/**
100
+	 * settings pertaining to Taxes
101
+	 *
102
+	 * @var EE_Tax_Config
103
+	 */
104
+	public $tax_settings;
105
+
106
+
107
+	/**
108
+	 * Settings pertaining to global messages settings.
109
+	 *
110
+	 * @var EE_Messages_Config
111
+	 */
112
+	public $messages;
113
+
114
+	/**
115
+	 * @deprecated
116
+	 * @var EE_Gateway_Config
117
+	 */
118
+	public $gateway;
119
+
120
+	/**
121
+	 * @var    array $_addon_option_names
122
+	 * @access    private
123
+	 */
124
+	private $_addon_option_names = array();
125
+
126
+	/**
127
+	 * @var    array $_module_route_map
128
+	 * @access    private
129
+	 */
130
+	private static $_module_route_map = array();
131
+
132
+	/**
133
+	 * @var    array $_module_forward_map
134
+	 * @access    private
135
+	 */
136
+	private static $_module_forward_map = array();
137
+
138
+	/**
139
+	 * @var    array $_module_view_map
140
+	 * @access    private
141
+	 */
142
+	private static $_module_view_map = array();
143
+
144
+
145
+
146
+	/**
147
+	 * @singleton method used to instantiate class object
148
+	 * @access    public
149
+	 * @return EE_Config instance
150
+	 */
151
+	public static function instance()
152
+	{
153
+		// check if class object is instantiated, and instantiated properly
154
+		if (! self::$_instance instanceof EE_Config) {
155
+			self::$_instance = new self();
156
+		}
157
+		return self::$_instance;
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 * Resets the config
164
+	 *
165
+	 * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
166
+	 *                               (default) leaves the database alone, and merely resets the EE_Config object to
167
+	 *                               reflect its state in the database
168
+	 * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
169
+	 *                               $_instance as NULL. Useful in case you want to forget about the old instance on
170
+	 *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
171
+	 *                               site was put into maintenance mode)
172
+	 * @return EE_Config
173
+	 */
174
+	public static function reset($hard_reset = false, $reinstantiate = true)
175
+	{
176
+		if (self::$_instance instanceof EE_Config) {
177
+			if ($hard_reset) {
178
+				self::$_instance->legacy_shortcodes_manager = null;
179
+				self::$_instance->_addon_option_names = array();
180
+				self::$_instance->_initialize_config();
181
+				self::$_instance->update_espresso_config();
182
+			}
183
+			self::$_instance->update_addon_option_names();
184
+		}
185
+		self::$_instance = null;
186
+		//we don't need to reset the static properties imo because those should
187
+		//only change when a module is added or removed. Currently we don't
188
+		//support removing a module during a request when it previously existed
189
+		if ($reinstantiate) {
190
+			return self::instance();
191
+		} else {
192
+			return null;
193
+		}
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 *    class constructor
200
+	 *
201
+	 * @access    private
202
+	 */
203
+	private function __construct()
204
+	{
205
+		do_action('AHEE__EE_Config__construct__begin', $this);
206
+		EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
207
+		// setup empty config classes
208
+		$this->_initialize_config();
209
+		// load existing EE site settings
210
+		$this->_load_core_config();
211
+		// confirm everything loaded correctly and set filtered defaults if not
212
+		$this->_verify_config();
213
+		//  register shortcodes and modules
214
+		add_action(
215
+			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
216
+			array($this, 'register_shortcodes_and_modules'),
217
+			999
218
+		);
219
+		//  initialize shortcodes and modules
220
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
221
+		// register widgets
222
+		add_action('widgets_init', array($this, 'widgets_init'), 10);
223
+		// shutdown
224
+		add_action('shutdown', array($this, 'shutdown'), 10);
225
+		// construct__end hook
226
+		do_action('AHEE__EE_Config__construct__end', $this);
227
+		// hardcoded hack
228
+		$this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
229
+	}
230
+
231
+
232
+
233
+	/**
234
+	 * @return boolean
235
+	 */
236
+	public static function logging_enabled()
237
+	{
238
+		return self::$_logging_enabled;
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * use to get the current theme if needed from static context
245
+	 *
246
+	 * @return string current theme set.
247
+	 */
248
+	public static function get_current_theme()
249
+	{
250
+		return isset(self::$_instance->template_settings->current_espresso_theme)
251
+			? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
252
+	}
253
+
254
+
255
+
256
+	/**
257
+	 *        _initialize_config
258
+	 *
259
+	 * @access private
260
+	 * @return void
261
+	 */
262
+	private function _initialize_config()
263
+	{
264
+		EE_Config::trim_log();
265
+		//set defaults
266
+		$this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
267
+		$this->addons = new stdClass();
268
+		// set _module_route_map
269
+		EE_Config::$_module_route_map = array();
270
+		// set _module_forward_map
271
+		EE_Config::$_module_forward_map = array();
272
+		// set _module_view_map
273
+		EE_Config::$_module_view_map = array();
274
+	}
275
+
276
+
277
+
278
+	/**
279
+	 *        load core plugin configuration
280
+	 *
281
+	 * @access private
282
+	 * @return void
283
+	 */
284
+	private function _load_core_config()
285
+	{
286
+		// load_core_config__start hook
287
+		do_action('AHEE__EE_Config___load_core_config__start', $this);
288
+		$espresso_config = $this->get_espresso_config();
289
+		foreach ($espresso_config as $config => $settings) {
290
+			// load_core_config__start hook
291
+			$settings = apply_filters(
292
+				'FHEE__EE_Config___load_core_config__config_settings',
293
+				$settings,
294
+				$config,
295
+				$this
296
+			);
297
+			if (is_object($settings) && property_exists($this, $config)) {
298
+				$this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
299
+				//call configs populate method to ensure any defaults are set for empty values.
300
+				if (method_exists($settings, 'populate')) {
301
+					$this->{$config}->populate();
302
+				}
303
+				if (method_exists($settings, 'do_hooks')) {
304
+					$this->{$config}->do_hooks();
305
+				}
306
+			}
307
+		}
308
+		if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
309
+			$this->update_espresso_config();
310
+		}
311
+		// load_core_config__end hook
312
+		do_action('AHEE__EE_Config___load_core_config__end', $this);
313
+	}
314
+
315
+
316
+
317
+	/**
318
+	 *    _verify_config
319
+	 *
320
+	 * @access    protected
321
+	 * @return    void
322
+	 */
323
+	protected function _verify_config()
324
+	{
325
+		$this->core = $this->core instanceof EE_Core_Config
326
+			? $this->core
327
+			: new EE_Core_Config();
328
+		$this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
329
+		$this->organization = $this->organization instanceof EE_Organization_Config
330
+			? $this->organization
331
+			: new EE_Organization_Config();
332
+		$this->organization = apply_filters(
333
+			'FHEE__EE_Config___initialize_config__organization',
334
+			$this->organization
335
+		);
336
+		$this->currency = $this->currency instanceof EE_Currency_Config
337
+			? $this->currency
338
+			: new EE_Currency_Config();
339
+		$this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
340
+		$this->registration = $this->registration instanceof EE_Registration_Config
341
+			? $this->registration
342
+			: new EE_Registration_Config();
343
+		$this->registration = apply_filters(
344
+			'FHEE__EE_Config___initialize_config__registration',
345
+			$this->registration
346
+		);
347
+		$this->admin = $this->admin instanceof EE_Admin_Config
348
+			? $this->admin
349
+			: new EE_Admin_Config();
350
+		$this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
351
+		$this->template_settings = $this->template_settings instanceof EE_Template_Config
352
+			? $this->template_settings
353
+			: new EE_Template_Config();
354
+		$this->template_settings = apply_filters(
355
+			'FHEE__EE_Config___initialize_config__template_settings',
356
+			$this->template_settings
357
+		);
358
+		$this->map_settings = $this->map_settings instanceof EE_Map_Config
359
+			? $this->map_settings
360
+			: new EE_Map_Config();
361
+		$this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings',
362
+			$this->map_settings);
363
+		$this->environment = $this->environment instanceof EE_Environment_Config
364
+			? $this->environment
365
+			: new EE_Environment_Config();
366
+		$this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment',
367
+			$this->environment);
368
+		$this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
369
+			? $this->tax_settings
370
+			: new EE_Tax_Config();
371
+		$this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings',
372
+			$this->tax_settings);
373
+		$this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
374
+		$this->messages = $this->messages instanceof EE_Messages_Config
375
+			? $this->messages
376
+			: new EE_Messages_Config();
377
+		$this->gateway = $this->gateway instanceof EE_Gateway_Config
378
+			? $this->gateway
379
+			: new EE_Gateway_Config();
380
+		$this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
381
+		$this->legacy_shortcodes_manager = null;
382
+	}
383
+
384
+
385
+	/**
386
+	 *    get_espresso_config
387
+	 *
388
+	 * @access    public
389
+	 * @return    array of espresso config stuff
390
+	 */
391
+	public function get_espresso_config()
392
+	{
393
+		// grab espresso configuration
394
+		return apply_filters(
395
+			'FHEE__EE_Config__get_espresso_config__CFG',
396
+			get_option(EE_Config::OPTION_NAME, array())
397
+		);
398
+	}
399
+
400
+
401
+
402
+	/**
403
+	 *    double_check_config_comparison
404
+	 *
405
+	 * @access    public
406
+	 * @param string $option
407
+	 * @param        $old_value
408
+	 * @param        $value
409
+	 */
410
+	public function double_check_config_comparison($option = '', $old_value, $value)
411
+	{
412
+		// make sure we're checking the ee config
413
+		if ($option === EE_Config::OPTION_NAME) {
414
+			// run a loose comparison of the old value against the new value for type and properties,
415
+			// but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
416
+			if ($value != $old_value) {
417
+				// if they are NOT the same, then remove the hook,
418
+				// which means the subsequent update results will be based solely on the update query results
419
+				// the reason we do this is because, as stated above,
420
+				// WP update_option performs an exact instance comparison (===) on any update values passed to it
421
+				// this happens PRIOR to serialization and any subsequent update.
422
+				// If values are found to match their previous old value,
423
+				// then WP bails before performing any update.
424
+				// Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
425
+				// it just pulled from the db, with the one being passed to it (which will not match).
426
+				// HOWEVER, once the object is serialized and passed off to MySQL to update,
427
+				// MySQL MAY ALSO NOT perform the update because
428
+				// the string it sees in the db looks the same as the new one it has been passed!!!
429
+				// This results in the query returning an "affected rows" value of ZERO,
430
+				// which gets returned immediately by WP update_option and looks like an error.
431
+				remove_action('update_option', array($this, 'check_config_updated'));
432
+			}
433
+		}
434
+	}
435
+
436
+
437
+
438
+	/**
439
+	 *    update_espresso_config
440
+	 *
441
+	 * @access   public
442
+	 */
443
+	protected function _reset_espresso_addon_config()
444
+	{
445
+		$this->_addon_option_names = array();
446
+		foreach ($this->addons as $addon_name => $addon_config_obj) {
447
+			$addon_config_obj = maybe_unserialize($addon_config_obj);
448
+			if ($addon_config_obj instanceof EE_Config_Base) {
449
+				$this->update_config('addons', $addon_name, $addon_config_obj, false);
450
+			}
451
+			$this->addons->{$addon_name} = null;
452
+		}
453
+	}
454
+
455
+
456
+
457
+	/**
458
+	 *    update_espresso_config
459
+	 *
460
+	 * @access   public
461
+	 * @param   bool $add_success
462
+	 * @param   bool $add_error
463
+	 * @return   bool
464
+	 */
465
+	public function update_espresso_config($add_success = false, $add_error = true)
466
+	{
467
+		// don't allow config updates during WP heartbeats
468
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
469
+			return false;
470
+		}
471
+		// commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
472
+		//$clone = clone( self::$_instance );
473
+		//self::$_instance = NULL;
474
+		do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
475
+		$this->_reset_espresso_addon_config();
476
+		// hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
477
+		// but BEFORE the actual update occurs
478
+		add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
479
+		// don't want to persist legacy_shortcodes_manager, but don't want to lose it either
480
+		$legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
481
+		$this->legacy_shortcodes_manager = null;
482
+		// now update "ee_config"
483
+		$saved = update_option(EE_Config::OPTION_NAME, $this);
484
+		$this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
485
+		EE_Config::log(EE_Config::OPTION_NAME);
486
+		// if not saved... check if the hook we just added still exists;
487
+		// if it does, it means one of two things:
488
+		// 		that update_option bailed at the ( $value === $old_value ) conditional,
489
+		//		 or...
490
+		// 		the db update query returned 0 rows affected
491
+		// 		(probably because the data  value was the same from it's perspective)
492
+		// so the existence of the hook means that a negative result from update_option is NOT an error,
493
+		// but just means no update occurred, so don't display an error to the user.
494
+		// BUT... if update_option returns FALSE, AND the hook is missing,
495
+		// then it means that something truly went wrong
496
+		$saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
497
+		// remove our action since we don't want it in the system anymore
498
+		remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
499
+		do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
500
+		//self::$_instance = $clone;
501
+		//unset( $clone );
502
+		// if config remains the same or was updated successfully
503
+		if ($saved) {
504
+			if ($add_success) {
505
+				EE_Error::add_success(
506
+					__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
507
+					__FILE__,
508
+					__FUNCTION__,
509
+					__LINE__
510
+				);
511
+			}
512
+			return true;
513
+		} else {
514
+			if ($add_error) {
515
+				EE_Error::add_error(
516
+					__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
517
+					__FILE__,
518
+					__FUNCTION__,
519
+					__LINE__
520
+				);
521
+			}
522
+			return false;
523
+		}
524
+	}
525
+
526
+
527
+
528
+	/**
529
+	 *    _verify_config_params
530
+	 *
531
+	 * @access    private
532
+	 * @param    string         $section
533
+	 * @param    string         $name
534
+	 * @param    string         $config_class
535
+	 * @param    EE_Config_Base $config_obj
536
+	 * @param    array          $tests_to_run
537
+	 * @param    bool           $display_errors
538
+	 * @return    bool    TRUE on success, FALSE on fail
539
+	 */
540
+	private function _verify_config_params(
541
+		$section = '',
542
+		$name = '',
543
+		$config_class = '',
544
+		$config_obj = null,
545
+		$tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
546
+		$display_errors = true
547
+	) {
548
+		try {
549
+			foreach ($tests_to_run as $test) {
550
+				switch ($test) {
551
+					// TEST #1 : check that section was set
552
+					case 1 :
553
+						if (empty($section)) {
554
+							if ($display_errors) {
555
+								throw new EE_Error(
556
+									sprintf(
557
+										__(
558
+											'No configuration section has been provided while attempting to save "%s".',
559
+											'event_espresso'
560
+										),
561
+										$config_class
562
+									)
563
+								);
564
+							}
565
+							return false;
566
+						}
567
+						break;
568
+					// TEST #2 : check that settings section exists
569
+					case 2 :
570
+						if (! isset($this->{$section})) {
571
+							if ($display_errors) {
572
+								throw new EE_Error(
573
+									sprintf(
574
+										__('The "%s" configuration section does not exist.', 'event_espresso'),
575
+										$section
576
+									)
577
+								);
578
+							}
579
+							return false;
580
+						}
581
+						break;
582
+					// TEST #3 : check that section is the proper format
583
+					case 3 :
584
+						if (
585
+						! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
586
+						) {
587
+							if ($display_errors) {
588
+								throw new EE_Error(
589
+									sprintf(
590
+										__(
591
+											'The "%s" configuration settings have not been formatted correctly.',
592
+											'event_espresso'
593
+										),
594
+										$section
595
+									)
596
+								);
597
+							}
598
+							return false;
599
+						}
600
+						break;
601
+					// TEST #4 : check that config section name has been set
602
+					case 4 :
603
+						if (empty($name)) {
604
+							if ($display_errors) {
605
+								throw new EE_Error(
606
+									__(
607
+										'No name has been provided for the specific configuration section.',
608
+										'event_espresso'
609
+									)
610
+								);
611
+							}
612
+							return false;
613
+						}
614
+						break;
615
+					// TEST #5 : check that a config class name has been set
616
+					case 5 :
617
+						if (empty($config_class)) {
618
+							if ($display_errors) {
619
+								throw new EE_Error(
620
+									__(
621
+										'No class name has been provided for the specific configuration section.',
622
+										'event_espresso'
623
+									)
624
+								);
625
+							}
626
+							return false;
627
+						}
628
+						break;
629
+					// TEST #6 : verify config class is accessible
630
+					case 6 :
631
+						if (! class_exists($config_class)) {
632
+							if ($display_errors) {
633
+								throw new EE_Error(
634
+									sprintf(
635
+										__(
636
+											'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
637
+											'event_espresso'
638
+										),
639
+										$config_class
640
+									)
641
+								);
642
+							}
643
+							return false;
644
+						}
645
+						break;
646
+					// TEST #7 : check that config has even been set
647
+					case 7 :
648
+						if (! isset($this->{$section}->{$name})) {
649
+							if ($display_errors) {
650
+								throw new EE_Error(
651
+									sprintf(
652
+										__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
653
+										$section,
654
+										$name
655
+									)
656
+								);
657
+							}
658
+							return false;
659
+						} else {
660
+							// and make sure it's not serialized
661
+							$this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
662
+						}
663
+						break;
664
+					// TEST #8 : check that config is the requested type
665
+					case 8 :
666
+						if (! $this->{$section}->{$name} instanceof $config_class) {
667
+							if ($display_errors) {
668
+								throw new EE_Error(
669
+									sprintf(
670
+										__(
671
+											'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
672
+											'event_espresso'
673
+										),
674
+										$section,
675
+										$name,
676
+										$config_class
677
+									)
678
+								);
679
+							}
680
+							return false;
681
+						}
682
+						break;
683
+					// TEST #9 : verify config object
684
+					case 9 :
685
+						if (! $config_obj instanceof EE_Config_Base) {
686
+							if ($display_errors) {
687
+								throw new EE_Error(
688
+									sprintf(
689
+										__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
690
+										print_r($config_obj, true)
691
+									)
692
+								);
693
+							}
694
+							return false;
695
+						}
696
+						break;
697
+				}
698
+			}
699
+		} catch (EE_Error $e) {
700
+			$e->get_error();
701
+		}
702
+		// you have successfully run the gauntlet
703
+		return true;
704
+	}
705
+
706
+
707
+
708
+	/**
709
+	 *    _generate_config_option_name
710
+	 *
711
+	 * @access        protected
712
+	 * @param        string $section
713
+	 * @param        string $name
714
+	 * @return        string
715
+	 */
716
+	private function _generate_config_option_name($section = '', $name = '')
717
+	{
718
+		return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
719
+	}
720
+
721
+
722
+
723
+	/**
724
+	 *    _set_config_class
725
+	 * ensures that a config class is set, either from a passed config class or one generated from the config name
726
+	 *
727
+	 * @access    private
728
+	 * @param    string $config_class
729
+	 * @param    string $name
730
+	 * @return    string
731
+	 */
732
+	private function _set_config_class($config_class = '', $name = '')
733
+	{
734
+		return ! empty($config_class)
735
+			? $config_class
736
+			: str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
737
+	}
738
+
739
+
740
+
741
+	/**
742
+	 *    set_config
743
+	 *
744
+	 * @access    protected
745
+	 * @param    string         $section
746
+	 * @param    string         $name
747
+	 * @param    string         $config_class
748
+	 * @param    EE_Config_Base $config_obj
749
+	 * @return    EE_Config_Base
750
+	 */
751
+	public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
752
+	{
753
+		// ensure config class is set to something
754
+		$config_class = $this->_set_config_class($config_class, $name);
755
+		// run tests 1-4, 6, and 7 to verify all config params are set and valid
756
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
757
+			return null;
758
+		}
759
+		$config_option_name = $this->_generate_config_option_name($section, $name);
760
+		// if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
761
+		if (! isset($this->_addon_option_names[$config_option_name])) {
762
+			$this->_addon_option_names[$config_option_name] = $config_class;
763
+			$this->update_addon_option_names();
764
+		}
765
+		// verify the incoming config object but suppress errors
766
+		if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
767
+			$config_obj = new $config_class();
768
+		}
769
+		if (get_option($config_option_name)) {
770
+			EE_Config::log($config_option_name);
771
+			update_option($config_option_name, $config_obj);
772
+			$this->{$section}->{$name} = $config_obj;
773
+			return $this->{$section}->{$name};
774
+		} else {
775
+			// create a wp-option for this config
776
+			if (add_option($config_option_name, $config_obj, '', 'no')) {
777
+				$this->{$section}->{$name} = maybe_unserialize($config_obj);
778
+				return $this->{$section}->{$name};
779
+			} else {
780
+				EE_Error::add_error(
781
+					sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
782
+					__FILE__,
783
+					__FUNCTION__,
784
+					__LINE__
785
+				);
786
+				return null;
787
+			}
788
+		}
789
+	}
790
+
791
+
792
+
793
+	/**
794
+	 *    update_config
795
+	 * Important: the config object must ALREADY be set, otherwise this will produce an error.
796
+	 *
797
+	 * @access    public
798
+	 * @param    string                $section
799
+	 * @param    string                $name
800
+	 * @param    EE_Config_Base|string $config_obj
801
+	 * @param    bool                  $throw_errors
802
+	 * @return    bool
803
+	 */
804
+	public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
805
+	{
806
+		// don't allow config updates during WP heartbeats
807
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
808
+			return false;
809
+		}
810
+		$config_obj = maybe_unserialize($config_obj);
811
+		// get class name of the incoming object
812
+		$config_class = get_class($config_obj);
813
+		// run tests 1-5 and 9 to verify config
814
+		if (! $this->_verify_config_params(
815
+			$section,
816
+			$name,
817
+			$config_class,
818
+			$config_obj,
819
+			array(1, 2, 3, 4, 7, 9)
820
+		)
821
+		) {
822
+			return false;
823
+		}
824
+		$config_option_name = $this->_generate_config_option_name($section, $name);
825
+		// check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
826
+		if (! isset($this->_addon_option_names[$config_option_name])) {
827
+			// save new config to db
828
+			if ($this->set_config($section, $name, $config_class, $config_obj)) {
829
+				return true;
830
+			}
831
+		} else {
832
+			// first check if the record already exists
833
+			$existing_config = get_option($config_option_name);
834
+			$config_obj = serialize($config_obj);
835
+			// just return if db record is already up to date (NOT type safe comparison)
836
+			if ($existing_config == $config_obj) {
837
+				$this->{$section}->{$name} = $config_obj;
838
+				return true;
839
+			} else if (update_option($config_option_name, $config_obj)) {
840
+				EE_Config::log($config_option_name);
841
+				// update wp-option for this config class
842
+				$this->{$section}->{$name} = $config_obj;
843
+				return true;
844
+			} elseif ($throw_errors) {
845
+				EE_Error::add_error(
846
+					sprintf(
847
+						__(
848
+							'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
849
+							'event_espresso'
850
+						),
851
+						$config_class,
852
+						'EE_Config->' . $section . '->' . $name
853
+					),
854
+					__FILE__,
855
+					__FUNCTION__,
856
+					__LINE__
857
+				);
858
+			}
859
+		}
860
+		return false;
861
+	}
862
+
863
+
864
+
865
+	/**
866
+	 *    get_config
867
+	 *
868
+	 * @access    public
869
+	 * @param    string $section
870
+	 * @param    string $name
871
+	 * @param    string $config_class
872
+	 * @return    mixed EE_Config_Base | NULL
873
+	 */
874
+	public function get_config($section = '', $name = '', $config_class = '')
875
+	{
876
+		// ensure config class is set to something
877
+		$config_class = $this->_set_config_class($config_class, $name);
878
+		// run tests 1-4, 6 and 7 to verify that all params have been set
879
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
880
+			return null;
881
+		}
882
+		// now test if the requested config object exists, but suppress errors
883
+		if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
884
+			// config already exists, so pass it back
885
+			return $this->{$section}->{$name};
886
+		}
887
+		// load config option from db if it exists
888
+		$config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
889
+		// verify the newly retrieved config object, but suppress errors
890
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
891
+			// config is good, so set it and pass it back
892
+			$this->{$section}->{$name} = $config_obj;
893
+			return $this->{$section}->{$name};
894
+		}
895
+		// oops! $config_obj is not already set and does not exist in the db, so create a new one
896
+		$config_obj = $this->set_config($section, $name, $config_class);
897
+		// verify the newly created config object
898
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
899
+			return $this->{$section}->{$name};
900
+		} else {
901
+			EE_Error::add_error(
902
+				sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
903
+				__FILE__,
904
+				__FUNCTION__,
905
+				__LINE__
906
+			);
907
+		}
908
+		return null;
909
+	}
910
+
911
+
912
+
913
+	/**
914
+	 *    get_config_option
915
+	 *
916
+	 * @access    public
917
+	 * @param    string $config_option_name
918
+	 * @return    mixed EE_Config_Base | FALSE
919
+	 */
920
+	public function get_config_option($config_option_name = '')
921
+	{
922
+		// retrieve the wp-option for this config class.
923
+		$config_option = maybe_unserialize(get_option($config_option_name, array()));
924
+		if (empty($config_option)) {
925
+			EE_Config::log($config_option_name . '-NOT-FOUND');
926
+		}
927
+		return $config_option;
928
+	}
929
+
930
+
931
+
932
+	/**
933
+	 * log
934
+	 *
935
+	 * @param string $config_option_name
936
+	 */
937
+	public static function log($config_option_name = '')
938
+	{
939
+		if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
940
+			$config_log = get_option(EE_Config::LOG_NAME, array());
941
+			//copy incoming $_REQUEST and sanitize it so we can save it
942
+			$_request = $_REQUEST;
943
+			array_walk_recursive($_request, 'sanitize_text_field');
944
+			$config_log[(string)microtime(true)] = array(
945
+				'config_name' => $config_option_name,
946
+				'request'     => $_request,
947
+			);
948
+			update_option(EE_Config::LOG_NAME, $config_log);
949
+		}
950
+	}
951
+
952
+
953
+
954
+	/**
955
+	 * trim_log
956
+	 * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
957
+	 */
958
+	public static function trim_log()
959
+	{
960
+		if (! EE_Config::logging_enabled()) {
961
+			return;
962
+		}
963
+		$config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
964
+		$log_length = count($config_log);
965
+		if ($log_length > EE_Config::LOG_LENGTH) {
966
+			ksort($config_log);
967
+			$config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
968
+			update_option(EE_Config::LOG_NAME, $config_log);
969
+		}
970
+	}
971
+
972
+
973
+
974
+	/**
975
+	 *    get_page_for_posts
976
+	 *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
977
+	 *    wp-option "page_for_posts", or "posts" if no page is selected
978
+	 *
979
+	 * @access    public
980
+	 * @return    string
981
+	 */
982
+	public static function get_page_for_posts()
983
+	{
984
+		$page_for_posts = get_option('page_for_posts');
985
+		if (! $page_for_posts) {
986
+			return 'posts';
987
+		}
988
+		/** @type WPDB $wpdb */
989
+		global $wpdb;
990
+		$SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
991
+		return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
992
+	}
993
+
994
+
995
+
996
+	/**
997
+	 *    register_shortcodes_and_modules.
998
+	 *    At this point, it's too early to tell if we're maintenance mode or not.
999
+	 *    In fact, this is where we give modules a chance to let core know they exist
1000
+	 *    so they can help trigger maintenance mode if it's needed
1001
+	 *
1002
+	 * @access    public
1003
+	 * @return    void
1004
+	 */
1005
+	public function register_shortcodes_and_modules()
1006
+	{
1007
+		// allow modules to set hooks for the rest of the system
1008
+		EE_Registry::instance()->modules = $this->_register_modules();
1009
+	}
1010
+
1011
+
1012
+
1013
+	/**
1014
+	 *    initialize_shortcodes_and_modules
1015
+	 *    meaning they can start adding their hooks to get stuff done
1016
+	 *
1017
+	 * @access    public
1018
+	 * @return    void
1019
+	 */
1020
+	public function initialize_shortcodes_and_modules()
1021
+	{
1022
+		// allow modules to set hooks for the rest of the system
1023
+		$this->_initialize_modules();
1024
+	}
1025
+
1026
+
1027
+
1028
+	/**
1029
+	 *    widgets_init
1030
+	 *
1031
+	 * @access private
1032
+	 * @return void
1033
+	 */
1034
+	public function widgets_init()
1035
+	{
1036
+		//only init widgets on admin pages when not in complete maintenance, and
1037
+		//on frontend when not in any maintenance mode
1038
+		if (
1039
+			! EE_Maintenance_Mode::instance()->level()
1040
+			|| (
1041
+				is_admin()
1042
+				&& EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1043
+			)
1044
+		) {
1045
+			// grab list of installed widgets
1046
+			$widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1047
+			// filter list of modules to register
1048
+			$widgets_to_register = apply_filters(
1049
+				'FHEE__EE_Config__register_widgets__widgets_to_register',
1050
+				$widgets_to_register
1051
+			);
1052
+			if (! empty($widgets_to_register)) {
1053
+				// cycle thru widget folders
1054
+				foreach ($widgets_to_register as $widget_path) {
1055
+					// add to list of installed widget modules
1056
+					EE_Config::register_ee_widget($widget_path);
1057
+				}
1058
+			}
1059
+			// filter list of installed modules
1060
+			EE_Registry::instance()->widgets = apply_filters(
1061
+				'FHEE__EE_Config__register_widgets__installed_widgets',
1062
+				EE_Registry::instance()->widgets
1063
+			);
1064
+		}
1065
+	}
1066
+
1067
+
1068
+
1069
+	/**
1070
+	 *    register_ee_widget - makes core aware of this widget
1071
+	 *
1072
+	 * @access    public
1073
+	 * @param    string $widget_path - full path up to and including widget folder
1074
+	 * @return    void
1075
+	 */
1076
+	public static function register_ee_widget($widget_path = null)
1077
+	{
1078
+		do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1079
+		$widget_ext = '.widget.php';
1080
+		// make all separators match
1081
+		$widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS);
1082
+		// does the file path INCLUDE the actual file name as part of the path ?
1083
+		if (strpos($widget_path, $widget_ext) !== false) {
1084
+			// grab and shortcode file name from directory name and break apart at dots
1085
+			$file_name = explode('.', basename($widget_path));
1086
+			// take first segment from file name pieces and remove class prefix if it exists
1087
+			$widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1088
+			// sanitize shortcode directory name
1089
+			$widget = sanitize_key($widget);
1090
+			// now we need to rebuild the shortcode path
1091
+			$widget_path = explode(DS, $widget_path);
1092
+			// remove last segment
1093
+			array_pop($widget_path);
1094
+			// glue it back together
1095
+			$widget_path = implode(DS, $widget_path);
1096
+		} else {
1097
+			// grab and sanitize widget directory name
1098
+			$widget = sanitize_key(basename($widget_path));
1099
+		}
1100
+		// create classname from widget directory name
1101
+		$widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1102
+		// add class prefix
1103
+		$widget_class = 'EEW_' . $widget;
1104
+		// does the widget exist ?
1105
+		if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1106
+			$msg = sprintf(
1107
+				__(
1108
+					'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1109
+					'event_espresso'
1110
+				),
1111
+				$widget_class,
1112
+				$widget_path . DS . $widget_class . $widget_ext
1113
+			);
1114
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1115
+			return;
1116
+		}
1117
+		// load the widget class file
1118
+		require_once($widget_path . DS . $widget_class . $widget_ext);
1119
+		// verify that class exists
1120
+		if (! class_exists($widget_class)) {
1121
+			$msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1122
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1123
+			return;
1124
+		}
1125
+		register_widget($widget_class);
1126
+		// add to array of registered widgets
1127
+		EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1128
+	}
1129
+
1130
+
1131
+
1132
+	/**
1133
+	 *        _register_modules
1134
+	 *
1135
+	 * @access private
1136
+	 * @return array
1137
+	 */
1138
+	private function _register_modules()
1139
+	{
1140
+		// grab list of installed modules
1141
+		$modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1142
+		// filter list of modules to register
1143
+		$modules_to_register = apply_filters(
1144
+			'FHEE__EE_Config__register_modules__modules_to_register',
1145
+			$modules_to_register
1146
+		);
1147
+		if (! empty($modules_to_register)) {
1148
+			// loop through folders
1149
+			foreach ($modules_to_register as $module_path) {
1150
+				/**TEMPORARILY EXCLUDE gateways from modules for time being**/
1151
+				if (
1152
+					$module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1153
+					&& $module_path !== EE_MODULES . 'gateways'
1154
+				) {
1155
+					// add to list of installed modules
1156
+					EE_Config::register_module($module_path);
1157
+				}
1158
+			}
1159
+		}
1160
+		// filter list of installed modules
1161
+		return apply_filters(
1162
+			'FHEE__EE_Config___register_modules__installed_modules',
1163
+			EE_Registry::instance()->modules
1164
+		);
1165
+	}
1166
+
1167
+
1168
+
1169
+	/**
1170
+	 *    register_module - makes core aware of this module
1171
+	 *
1172
+	 * @access    public
1173
+	 * @param    string $module_path - full path up to and including module folder
1174
+	 * @return    bool
1175
+	 */
1176
+	public static function register_module($module_path = null)
1177
+	{
1178
+		do_action('AHEE__EE_Config__register_module__begin', $module_path);
1179
+		$module_ext = '.module.php';
1180
+		// make all separators match
1181
+		$module_path = str_replace(array('\\', '/'), DS, $module_path);
1182
+		// does the file path INCLUDE the actual file name as part of the path ?
1183
+		if (strpos($module_path, $module_ext) !== false) {
1184
+			// grab and shortcode file name from directory name and break apart at dots
1185
+			$module_file = explode('.', basename($module_path));
1186
+			// now we need to rebuild the shortcode path
1187
+			$module_path = explode(DS, $module_path);
1188
+			// remove last segment
1189
+			array_pop($module_path);
1190
+			// glue it back together
1191
+			$module_path = implode(DS, $module_path) . DS;
1192
+			// take first segment from file name pieces and sanitize it
1193
+			$module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1194
+			// ensure class prefix is added
1195
+			$module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1196
+		} else {
1197
+			// we need to generate the filename based off of the folder name
1198
+			// grab and sanitize module name
1199
+			$module = strtolower(basename($module_path));
1200
+			$module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1201
+			// like trailingslashit()
1202
+			$module_path = rtrim($module_path, DS) . DS;
1203
+			// create classname from module directory name
1204
+			$module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1205
+			// add class prefix
1206
+			$module_class = 'EED_' . $module;
1207
+		}
1208
+		// does the module exist ?
1209
+		if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1210
+			$msg = sprintf(
1211
+				__(
1212
+					'The requested %s module file could not be found or is not readable due to file permissions.',
1213
+					'event_espresso'
1214
+				),
1215
+				$module
1216
+			);
1217
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1218
+			return false;
1219
+		}
1220
+		// load the module class file
1221
+		require_once($module_path . $module_class . $module_ext);
1222
+		// verify that class exists
1223
+		if (! class_exists($module_class)) {
1224
+			$msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1225
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1226
+			return false;
1227
+		}
1228
+		// add to array of registered modules
1229
+		EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1230
+		do_action(
1231
+			'AHEE__EE_Config__register_module__complete',
1232
+			$module_class,
1233
+			EE_Registry::instance()->modules->{$module_class}
1234
+		);
1235
+		return true;
1236
+	}
1237
+
1238
+
1239
+
1240
+	/**
1241
+	 *    _initialize_modules
1242
+	 *    allow modules to set hooks for the rest of the system
1243
+	 *
1244
+	 * @access private
1245
+	 * @return void
1246
+	 */
1247
+	private function _initialize_modules()
1248
+	{
1249
+		// cycle thru shortcode folders
1250
+		foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1251
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1252
+			// which set hooks ?
1253
+			if (is_admin()) {
1254
+				// fire immediately
1255
+				call_user_func(array($module_class, 'set_hooks_admin'));
1256
+			} else {
1257
+				// delay until other systems are online
1258
+				add_action(
1259
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1260
+					array($module_class, 'set_hooks')
1261
+				);
1262
+			}
1263
+		}
1264
+	}
1265
+
1266
+
1267
+
1268
+	/**
1269
+	 *    register_route - adds module method routes to route_map
1270
+	 *
1271
+	 * @access    public
1272
+	 * @param    string $route       - "pretty" public alias for module method
1273
+	 * @param    string $module      - module name (classname without EED_ prefix)
1274
+	 * @param    string $method_name - the actual module method to be routed to
1275
+	 * @param    string $key         - url param key indicating a route is being called
1276
+	 * @return    bool
1277
+	 */
1278
+	public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1279
+	{
1280
+		do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1281
+		$module = str_replace('EED_', '', $module);
1282
+		$module_class = 'EED_' . $module;
1283
+		if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1284
+			$msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1285
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1286
+			return false;
1287
+		}
1288
+		if (empty($route)) {
1289
+			$msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1290
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1291
+			return false;
1292
+		}
1293
+		if (! method_exists('EED_' . $module, $method_name)) {
1294
+			$msg = sprintf(
1295
+				__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1296
+				$route
1297
+			);
1298
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1299
+			return false;
1300
+		}
1301
+		EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name);
1302
+		return true;
1303
+	}
1304
+
1305
+
1306
+
1307
+	/**
1308
+	 *    get_route - get module method route
1309
+	 *
1310
+	 * @access    public
1311
+	 * @param    string $route - "pretty" public alias for module method
1312
+	 * @param    string $key   - url param key indicating a route is being called
1313
+	 * @return    string
1314
+	 */
1315
+	public static function get_route($route = null, $key = 'ee')
1316
+	{
1317
+		do_action('AHEE__EE_Config__get_route__begin', $route);
1318
+		$route = (string)apply_filters('FHEE__EE_Config__get_route', $route);
1319
+		if (isset(EE_Config::$_module_route_map[$key][$route])) {
1320
+			return EE_Config::$_module_route_map[$key][$route];
1321
+		}
1322
+		return null;
1323
+	}
1324
+
1325
+
1326
+
1327
+	/**
1328
+	 *    get_routes - get ALL module method routes
1329
+	 *
1330
+	 * @access    public
1331
+	 * @return    array
1332
+	 */
1333
+	public static function get_routes()
1334
+	{
1335
+		return EE_Config::$_module_route_map;
1336
+	}
1337
+
1338
+
1339
+
1340
+	/**
1341
+	 *    register_forward - allows modules to forward request to another module for further processing
1342
+	 *
1343
+	 * @access    public
1344
+	 * @param    string       $route   - "pretty" public alias for module method
1345
+	 * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1346
+	 *                                 class, allows different forwards to be served based on status
1347
+	 * @param    array|string $forward - function name or array( class, method )
1348
+	 * @param    string       $key     - url param key indicating a route is being called
1349
+	 * @return    bool
1350
+	 */
1351
+	public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1352
+	{
1353
+		do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1354
+		if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1355
+			$msg = sprintf(
1356
+				__('The module route %s for this forward has not been registered.', 'event_espresso'),
1357
+				$route
1358
+			);
1359
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1360
+			return false;
1361
+		}
1362
+		if (empty($forward)) {
1363
+			$msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1364
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1365
+			return false;
1366
+		}
1367
+		if (is_array($forward)) {
1368
+			if (! isset($forward[1])) {
1369
+				$msg = sprintf(
1370
+					__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1371
+					$route
1372
+				);
1373
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1374
+				return false;
1375
+			}
1376
+			if (! method_exists($forward[0], $forward[1])) {
1377
+				$msg = sprintf(
1378
+					__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1379
+					$forward[1],
1380
+					$route
1381
+				);
1382
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1383
+				return false;
1384
+			}
1385
+		} else if (! function_exists($forward)) {
1386
+			$msg = sprintf(
1387
+				__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1388
+				$forward,
1389
+				$route
1390
+			);
1391
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1392
+			return false;
1393
+		}
1394
+		EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward;
1395
+		return true;
1396
+	}
1397
+
1398
+
1399
+
1400
+	/**
1401
+	 *    get_forward - get forwarding route
1402
+	 *
1403
+	 * @access    public
1404
+	 * @param    string  $route  - "pretty" public alias for module method
1405
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1406
+	 *                           allows different forwards to be served based on status
1407
+	 * @param    string  $key    - url param key indicating a route is being called
1408
+	 * @return    string
1409
+	 */
1410
+	public static function get_forward($route = null, $status = 0, $key = 'ee')
1411
+	{
1412
+		do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1413
+		if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) {
1414
+			return apply_filters(
1415
+				'FHEE__EE_Config__get_forward',
1416
+				EE_Config::$_module_forward_map[$key][$route][$status],
1417
+				$route,
1418
+				$status
1419
+			);
1420
+		}
1421
+		return null;
1422
+	}
1423
+
1424
+
1425
+
1426
+	/**
1427
+	 *    register_forward - allows modules to specify different view templates for different method routes and status
1428
+	 *    results
1429
+	 *
1430
+	 * @access    public
1431
+	 * @param    string  $route  - "pretty" public alias for module method
1432
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1433
+	 *                           allows different views to be served based on status
1434
+	 * @param    string  $view
1435
+	 * @param    string  $key    - url param key indicating a route is being called
1436
+	 * @return    bool
1437
+	 */
1438
+	public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1439
+	{
1440
+		do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1441
+		if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1442
+			$msg = sprintf(
1443
+				__('The module route %s for this view has not been registered.', 'event_espresso'),
1444
+				$route
1445
+			);
1446
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1447
+			return false;
1448
+		}
1449
+		if (! is_readable($view)) {
1450
+			$msg = sprintf(
1451
+				__(
1452
+					'The %s view file could not be found or is not readable due to file permissions.',
1453
+					'event_espresso'
1454
+				),
1455
+				$view
1456
+			);
1457
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1458
+			return false;
1459
+		}
1460
+		EE_Config::$_module_view_map[$key][$route][absint($status)] = $view;
1461
+		return true;
1462
+	}
1463
+
1464
+
1465
+
1466
+	/**
1467
+	 *    get_view - get view for route and status
1468
+	 *
1469
+	 * @access    public
1470
+	 * @param    string  $route  - "pretty" public alias for module method
1471
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1472
+	 *                           allows different views to be served based on status
1473
+	 * @param    string  $key    - url param key indicating a route is being called
1474
+	 * @return    string
1475
+	 */
1476
+	public static function get_view($route = null, $status = 0, $key = 'ee')
1477
+	{
1478
+		do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1479
+		if (isset(EE_Config::$_module_view_map[$key][$route][$status])) {
1480
+			return apply_filters(
1481
+				'FHEE__EE_Config__get_view',
1482
+				EE_Config::$_module_view_map[$key][$route][$status],
1483
+				$route,
1484
+				$status
1485
+			);
1486
+		}
1487
+		return null;
1488
+	}
1489
+
1490
+
1491
+
1492
+	public function update_addon_option_names()
1493
+	{
1494
+		update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1495
+	}
1496
+
1497
+
1498
+
1499
+	public function shutdown()
1500
+	{
1501
+		$this->update_addon_option_names();
1502
+	}
1503
+
1504
+
1505
+
1506
+	/**
1507
+	 * @return LegacyShortcodesManager
1508
+	 */
1509
+	public static function getLegacyShortcodesManager()
1510
+	{
1511
+
1512
+		if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1513
+			EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1514
+				EE_Registry::instance()
1515
+			);
1516
+		}
1517
+		return EE_Config::instance()->legacy_shortcodes_manager;
1518
+	}
1519
+
1520
+
1521
+
1522
+	/**
1523
+	 * register_shortcode - makes core aware of this shortcode
1524
+	 *
1525
+	 * @deprecated 4.9.26
1526
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
1527
+	 * @return    bool
1528
+	 */
1529
+	public static function register_shortcode($shortcode_path = null)
1530
+	{
1531
+		EE_Error::doing_it_wrong(
1532
+			__METHOD__,
1533
+			__(
1534
+				'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1535
+				'event_espresso'
1536
+			),
1537
+			'4.9.26'
1538
+		);
1539
+		return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1540
+	}
21 1541
 
22
-    const LOG_NAME           = 'ee_config_log';
23 1542
 
24
-    const LOG_LENGTH         = 100;
25 1543
 
26
-    const ADDON_OPTION_NAMES = 'ee_config_option_names';
27
-
28
-
29
-    /**
30
-     *    instance of the EE_Config object
31
-     *
32
-     * @var    EE_Config $_instance
33
-     * @access    private
34
-     */
35
-    private static $_instance;
36
-
37
-    /**
38
-     * @var boolean $_logging_enabled
39
-     */
40
-    private static $_logging_enabled = false;
41
-
42
-    /**
43
-     * @var LegacyShortcodesManager $legacy_shortcodes_manager
44
-     */
45
-    private $legacy_shortcodes_manager;
46
-
47
-    /**
48
-     * An StdClass whose property names are addon slugs,
49
-     * and values are their config classes
50
-     *
51
-     * @var StdClass
52
-     */
53
-    public $addons;
54
-
55
-    /**
56
-     * @var EE_Admin_Config
57
-     */
58
-    public $admin;
59
-
60
-    /**
61
-     * @var EE_Core_Config
62
-     */
63
-    public $core;
64
-
65
-    /**
66
-     * @var EE_Currency_Config
67
-     */
68
-    public $currency;
69
-
70
-    /**
71
-     * @var EE_Organization_Config
72
-     */
73
-    public $organization;
74
-
75
-    /**
76
-     * @var EE_Registration_Config
77
-     */
78
-    public $registration;
79
-
80
-    /**
81
-     * @var EE_Template_Config
82
-     */
83
-    public $template_settings;
84
-
85
-    /**
86
-     * Holds EE environment values.
87
-     *
88
-     * @var EE_Environment_Config
89
-     */
90
-    public $environment;
91
-
92
-    /**
93
-     * settings pertaining to Google maps
94
-     *
95
-     * @var EE_Map_Config
96
-     */
97
-    public $map_settings;
98
-
99
-    /**
100
-     * settings pertaining to Taxes
101
-     *
102
-     * @var EE_Tax_Config
103
-     */
104
-    public $tax_settings;
105
-
106
-
107
-    /**
108
-     * Settings pertaining to global messages settings.
109
-     *
110
-     * @var EE_Messages_Config
111
-     */
112
-    public $messages;
113
-
114
-    /**
115
-     * @deprecated
116
-     * @var EE_Gateway_Config
117
-     */
118
-    public $gateway;
119
-
120
-    /**
121
-     * @var    array $_addon_option_names
122
-     * @access    private
123
-     */
124
-    private $_addon_option_names = array();
125
-
126
-    /**
127
-     * @var    array $_module_route_map
128
-     * @access    private
129
-     */
130
-    private static $_module_route_map = array();
131
-
132
-    /**
133
-     * @var    array $_module_forward_map
134
-     * @access    private
135
-     */
136
-    private static $_module_forward_map = array();
137
-
138
-    /**
139
-     * @var    array $_module_view_map
140
-     * @access    private
141
-     */
142
-    private static $_module_view_map = array();
143
-
144
-
145
-
146
-    /**
147
-     * @singleton method used to instantiate class object
148
-     * @access    public
149
-     * @return EE_Config instance
150
-     */
151
-    public static function instance()
152
-    {
153
-        // check if class object is instantiated, and instantiated properly
154
-        if (! self::$_instance instanceof EE_Config) {
155
-            self::$_instance = new self();
156
-        }
157
-        return self::$_instance;
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     * Resets the config
164
-     *
165
-     * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
166
-     *                               (default) leaves the database alone, and merely resets the EE_Config object to
167
-     *                               reflect its state in the database
168
-     * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
169
-     *                               $_instance as NULL. Useful in case you want to forget about the old instance on
170
-     *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
171
-     *                               site was put into maintenance mode)
172
-     * @return EE_Config
173
-     */
174
-    public static function reset($hard_reset = false, $reinstantiate = true)
175
-    {
176
-        if (self::$_instance instanceof EE_Config) {
177
-            if ($hard_reset) {
178
-                self::$_instance->legacy_shortcodes_manager = null;
179
-                self::$_instance->_addon_option_names = array();
180
-                self::$_instance->_initialize_config();
181
-                self::$_instance->update_espresso_config();
182
-            }
183
-            self::$_instance->update_addon_option_names();
184
-        }
185
-        self::$_instance = null;
186
-        //we don't need to reset the static properties imo because those should
187
-        //only change when a module is added or removed. Currently we don't
188
-        //support removing a module during a request when it previously existed
189
-        if ($reinstantiate) {
190
-            return self::instance();
191
-        } else {
192
-            return null;
193
-        }
194
-    }
195
-
196
-
197
-
198
-    /**
199
-     *    class constructor
200
-     *
201
-     * @access    private
202
-     */
203
-    private function __construct()
204
-    {
205
-        do_action('AHEE__EE_Config__construct__begin', $this);
206
-        EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
207
-        // setup empty config classes
208
-        $this->_initialize_config();
209
-        // load existing EE site settings
210
-        $this->_load_core_config();
211
-        // confirm everything loaded correctly and set filtered defaults if not
212
-        $this->_verify_config();
213
-        //  register shortcodes and modules
214
-        add_action(
215
-            'AHEE__EE_System__register_shortcodes_modules_and_widgets',
216
-            array($this, 'register_shortcodes_and_modules'),
217
-            999
218
-        );
219
-        //  initialize shortcodes and modules
220
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
221
-        // register widgets
222
-        add_action('widgets_init', array($this, 'widgets_init'), 10);
223
-        // shutdown
224
-        add_action('shutdown', array($this, 'shutdown'), 10);
225
-        // construct__end hook
226
-        do_action('AHEE__EE_Config__construct__end', $this);
227
-        // hardcoded hack
228
-        $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
229
-    }
230
-
231
-
232
-
233
-    /**
234
-     * @return boolean
235
-     */
236
-    public static function logging_enabled()
237
-    {
238
-        return self::$_logging_enabled;
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * use to get the current theme if needed from static context
245
-     *
246
-     * @return string current theme set.
247
-     */
248
-    public static function get_current_theme()
249
-    {
250
-        return isset(self::$_instance->template_settings->current_espresso_theme)
251
-            ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
252
-    }
253
-
254
-
255
-
256
-    /**
257
-     *        _initialize_config
258
-     *
259
-     * @access private
260
-     * @return void
261
-     */
262
-    private function _initialize_config()
263
-    {
264
-        EE_Config::trim_log();
265
-        //set defaults
266
-        $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
267
-        $this->addons = new stdClass();
268
-        // set _module_route_map
269
-        EE_Config::$_module_route_map = array();
270
-        // set _module_forward_map
271
-        EE_Config::$_module_forward_map = array();
272
-        // set _module_view_map
273
-        EE_Config::$_module_view_map = array();
274
-    }
275
-
276
-
277
-
278
-    /**
279
-     *        load core plugin configuration
280
-     *
281
-     * @access private
282
-     * @return void
283
-     */
284
-    private function _load_core_config()
285
-    {
286
-        // load_core_config__start hook
287
-        do_action('AHEE__EE_Config___load_core_config__start', $this);
288
-        $espresso_config = $this->get_espresso_config();
289
-        foreach ($espresso_config as $config => $settings) {
290
-            // load_core_config__start hook
291
-            $settings = apply_filters(
292
-                'FHEE__EE_Config___load_core_config__config_settings',
293
-                $settings,
294
-                $config,
295
-                $this
296
-            );
297
-            if (is_object($settings) && property_exists($this, $config)) {
298
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
299
-                //call configs populate method to ensure any defaults are set for empty values.
300
-                if (method_exists($settings, 'populate')) {
301
-                    $this->{$config}->populate();
302
-                }
303
-                if (method_exists($settings, 'do_hooks')) {
304
-                    $this->{$config}->do_hooks();
305
-                }
306
-            }
307
-        }
308
-        if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
309
-            $this->update_espresso_config();
310
-        }
311
-        // load_core_config__end hook
312
-        do_action('AHEE__EE_Config___load_core_config__end', $this);
313
-    }
314
-
315
-
316
-
317
-    /**
318
-     *    _verify_config
319
-     *
320
-     * @access    protected
321
-     * @return    void
322
-     */
323
-    protected function _verify_config()
324
-    {
325
-        $this->core = $this->core instanceof EE_Core_Config
326
-            ? $this->core
327
-            : new EE_Core_Config();
328
-        $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
329
-        $this->organization = $this->organization instanceof EE_Organization_Config
330
-            ? $this->organization
331
-            : new EE_Organization_Config();
332
-        $this->organization = apply_filters(
333
-            'FHEE__EE_Config___initialize_config__organization',
334
-            $this->organization
335
-        );
336
-        $this->currency = $this->currency instanceof EE_Currency_Config
337
-            ? $this->currency
338
-            : new EE_Currency_Config();
339
-        $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
340
-        $this->registration = $this->registration instanceof EE_Registration_Config
341
-            ? $this->registration
342
-            : new EE_Registration_Config();
343
-        $this->registration = apply_filters(
344
-            'FHEE__EE_Config___initialize_config__registration',
345
-            $this->registration
346
-        );
347
-        $this->admin = $this->admin instanceof EE_Admin_Config
348
-            ? $this->admin
349
-            : new EE_Admin_Config();
350
-        $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
351
-        $this->template_settings = $this->template_settings instanceof EE_Template_Config
352
-            ? $this->template_settings
353
-            : new EE_Template_Config();
354
-        $this->template_settings = apply_filters(
355
-            'FHEE__EE_Config___initialize_config__template_settings',
356
-            $this->template_settings
357
-        );
358
-        $this->map_settings = $this->map_settings instanceof EE_Map_Config
359
-            ? $this->map_settings
360
-            : new EE_Map_Config();
361
-        $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings',
362
-            $this->map_settings);
363
-        $this->environment = $this->environment instanceof EE_Environment_Config
364
-            ? $this->environment
365
-            : new EE_Environment_Config();
366
-        $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment',
367
-            $this->environment);
368
-        $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
369
-            ? $this->tax_settings
370
-            : new EE_Tax_Config();
371
-        $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings',
372
-            $this->tax_settings);
373
-        $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
374
-        $this->messages = $this->messages instanceof EE_Messages_Config
375
-            ? $this->messages
376
-            : new EE_Messages_Config();
377
-        $this->gateway = $this->gateway instanceof EE_Gateway_Config
378
-            ? $this->gateway
379
-            : new EE_Gateway_Config();
380
-        $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
381
-        $this->legacy_shortcodes_manager = null;
382
-    }
383
-
384
-
385
-    /**
386
-     *    get_espresso_config
387
-     *
388
-     * @access    public
389
-     * @return    array of espresso config stuff
390
-     */
391
-    public function get_espresso_config()
392
-    {
393
-        // grab espresso configuration
394
-        return apply_filters(
395
-            'FHEE__EE_Config__get_espresso_config__CFG',
396
-            get_option(EE_Config::OPTION_NAME, array())
397
-        );
398
-    }
399
-
400
-
401
-
402
-    /**
403
-     *    double_check_config_comparison
404
-     *
405
-     * @access    public
406
-     * @param string $option
407
-     * @param        $old_value
408
-     * @param        $value
409
-     */
410
-    public function double_check_config_comparison($option = '', $old_value, $value)
411
-    {
412
-        // make sure we're checking the ee config
413
-        if ($option === EE_Config::OPTION_NAME) {
414
-            // run a loose comparison of the old value against the new value for type and properties,
415
-            // but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
416
-            if ($value != $old_value) {
417
-                // if they are NOT the same, then remove the hook,
418
-                // which means the subsequent update results will be based solely on the update query results
419
-                // the reason we do this is because, as stated above,
420
-                // WP update_option performs an exact instance comparison (===) on any update values passed to it
421
-                // this happens PRIOR to serialization and any subsequent update.
422
-                // If values are found to match their previous old value,
423
-                // then WP bails before performing any update.
424
-                // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
425
-                // it just pulled from the db, with the one being passed to it (which will not match).
426
-                // HOWEVER, once the object is serialized and passed off to MySQL to update,
427
-                // MySQL MAY ALSO NOT perform the update because
428
-                // the string it sees in the db looks the same as the new one it has been passed!!!
429
-                // This results in the query returning an "affected rows" value of ZERO,
430
-                // which gets returned immediately by WP update_option and looks like an error.
431
-                remove_action('update_option', array($this, 'check_config_updated'));
432
-            }
433
-        }
434
-    }
435
-
436
-
437
-
438
-    /**
439
-     *    update_espresso_config
440
-     *
441
-     * @access   public
442
-     */
443
-    protected function _reset_espresso_addon_config()
444
-    {
445
-        $this->_addon_option_names = array();
446
-        foreach ($this->addons as $addon_name => $addon_config_obj) {
447
-            $addon_config_obj = maybe_unserialize($addon_config_obj);
448
-            if ($addon_config_obj instanceof EE_Config_Base) {
449
-                $this->update_config('addons', $addon_name, $addon_config_obj, false);
450
-            }
451
-            $this->addons->{$addon_name} = null;
452
-        }
453
-    }
454
-
455
-
456
-
457
-    /**
458
-     *    update_espresso_config
459
-     *
460
-     * @access   public
461
-     * @param   bool $add_success
462
-     * @param   bool $add_error
463
-     * @return   bool
464
-     */
465
-    public function update_espresso_config($add_success = false, $add_error = true)
466
-    {
467
-        // don't allow config updates during WP heartbeats
468
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
469
-            return false;
470
-        }
471
-        // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
472
-        //$clone = clone( self::$_instance );
473
-        //self::$_instance = NULL;
474
-        do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
475
-        $this->_reset_espresso_addon_config();
476
-        // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
477
-        // but BEFORE the actual update occurs
478
-        add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
479
-        // don't want to persist legacy_shortcodes_manager, but don't want to lose it either
480
-        $legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
481
-        $this->legacy_shortcodes_manager = null;
482
-        // now update "ee_config"
483
-        $saved = update_option(EE_Config::OPTION_NAME, $this);
484
-        $this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
485
-        EE_Config::log(EE_Config::OPTION_NAME);
486
-        // if not saved... check if the hook we just added still exists;
487
-        // if it does, it means one of two things:
488
-        // 		that update_option bailed at the ( $value === $old_value ) conditional,
489
-        //		 or...
490
-        // 		the db update query returned 0 rows affected
491
-        // 		(probably because the data  value was the same from it's perspective)
492
-        // so the existence of the hook means that a negative result from update_option is NOT an error,
493
-        // but just means no update occurred, so don't display an error to the user.
494
-        // BUT... if update_option returns FALSE, AND the hook is missing,
495
-        // then it means that something truly went wrong
496
-        $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
497
-        // remove our action since we don't want it in the system anymore
498
-        remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
499
-        do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
500
-        //self::$_instance = $clone;
501
-        //unset( $clone );
502
-        // if config remains the same or was updated successfully
503
-        if ($saved) {
504
-            if ($add_success) {
505
-                EE_Error::add_success(
506
-                    __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
507
-                    __FILE__,
508
-                    __FUNCTION__,
509
-                    __LINE__
510
-                );
511
-            }
512
-            return true;
513
-        } else {
514
-            if ($add_error) {
515
-                EE_Error::add_error(
516
-                    __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
517
-                    __FILE__,
518
-                    __FUNCTION__,
519
-                    __LINE__
520
-                );
521
-            }
522
-            return false;
523
-        }
524
-    }
525
-
526
-
527
-
528
-    /**
529
-     *    _verify_config_params
530
-     *
531
-     * @access    private
532
-     * @param    string         $section
533
-     * @param    string         $name
534
-     * @param    string         $config_class
535
-     * @param    EE_Config_Base $config_obj
536
-     * @param    array          $tests_to_run
537
-     * @param    bool           $display_errors
538
-     * @return    bool    TRUE on success, FALSE on fail
539
-     */
540
-    private function _verify_config_params(
541
-        $section = '',
542
-        $name = '',
543
-        $config_class = '',
544
-        $config_obj = null,
545
-        $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
546
-        $display_errors = true
547
-    ) {
548
-        try {
549
-            foreach ($tests_to_run as $test) {
550
-                switch ($test) {
551
-                    // TEST #1 : check that section was set
552
-                    case 1 :
553
-                        if (empty($section)) {
554
-                            if ($display_errors) {
555
-                                throw new EE_Error(
556
-                                    sprintf(
557
-                                        __(
558
-                                            'No configuration section has been provided while attempting to save "%s".',
559
-                                            'event_espresso'
560
-                                        ),
561
-                                        $config_class
562
-                                    )
563
-                                );
564
-                            }
565
-                            return false;
566
-                        }
567
-                        break;
568
-                    // TEST #2 : check that settings section exists
569
-                    case 2 :
570
-                        if (! isset($this->{$section})) {
571
-                            if ($display_errors) {
572
-                                throw new EE_Error(
573
-                                    sprintf(
574
-                                        __('The "%s" configuration section does not exist.', 'event_espresso'),
575
-                                        $section
576
-                                    )
577
-                                );
578
-                            }
579
-                            return false;
580
-                        }
581
-                        break;
582
-                    // TEST #3 : check that section is the proper format
583
-                    case 3 :
584
-                        if (
585
-                        ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
586
-                        ) {
587
-                            if ($display_errors) {
588
-                                throw new EE_Error(
589
-                                    sprintf(
590
-                                        __(
591
-                                            'The "%s" configuration settings have not been formatted correctly.',
592
-                                            'event_espresso'
593
-                                        ),
594
-                                        $section
595
-                                    )
596
-                                );
597
-                            }
598
-                            return false;
599
-                        }
600
-                        break;
601
-                    // TEST #4 : check that config section name has been set
602
-                    case 4 :
603
-                        if (empty($name)) {
604
-                            if ($display_errors) {
605
-                                throw new EE_Error(
606
-                                    __(
607
-                                        'No name has been provided for the specific configuration section.',
608
-                                        'event_espresso'
609
-                                    )
610
-                                );
611
-                            }
612
-                            return false;
613
-                        }
614
-                        break;
615
-                    // TEST #5 : check that a config class name has been set
616
-                    case 5 :
617
-                        if (empty($config_class)) {
618
-                            if ($display_errors) {
619
-                                throw new EE_Error(
620
-                                    __(
621
-                                        'No class name has been provided for the specific configuration section.',
622
-                                        'event_espresso'
623
-                                    )
624
-                                );
625
-                            }
626
-                            return false;
627
-                        }
628
-                        break;
629
-                    // TEST #6 : verify config class is accessible
630
-                    case 6 :
631
-                        if (! class_exists($config_class)) {
632
-                            if ($display_errors) {
633
-                                throw new EE_Error(
634
-                                    sprintf(
635
-                                        __(
636
-                                            'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
637
-                                            'event_espresso'
638
-                                        ),
639
-                                        $config_class
640
-                                    )
641
-                                );
642
-                            }
643
-                            return false;
644
-                        }
645
-                        break;
646
-                    // TEST #7 : check that config has even been set
647
-                    case 7 :
648
-                        if (! isset($this->{$section}->{$name})) {
649
-                            if ($display_errors) {
650
-                                throw new EE_Error(
651
-                                    sprintf(
652
-                                        __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
653
-                                        $section,
654
-                                        $name
655
-                                    )
656
-                                );
657
-                            }
658
-                            return false;
659
-                        } else {
660
-                            // and make sure it's not serialized
661
-                            $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
662
-                        }
663
-                        break;
664
-                    // TEST #8 : check that config is the requested type
665
-                    case 8 :
666
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
667
-                            if ($display_errors) {
668
-                                throw new EE_Error(
669
-                                    sprintf(
670
-                                        __(
671
-                                            'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
672
-                                            'event_espresso'
673
-                                        ),
674
-                                        $section,
675
-                                        $name,
676
-                                        $config_class
677
-                                    )
678
-                                );
679
-                            }
680
-                            return false;
681
-                        }
682
-                        break;
683
-                    // TEST #9 : verify config object
684
-                    case 9 :
685
-                        if (! $config_obj instanceof EE_Config_Base) {
686
-                            if ($display_errors) {
687
-                                throw new EE_Error(
688
-                                    sprintf(
689
-                                        __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
690
-                                        print_r($config_obj, true)
691
-                                    )
692
-                                );
693
-                            }
694
-                            return false;
695
-                        }
696
-                        break;
697
-                }
698
-            }
699
-        } catch (EE_Error $e) {
700
-            $e->get_error();
701
-        }
702
-        // you have successfully run the gauntlet
703
-        return true;
704
-    }
705
-
706
-
707
-
708
-    /**
709
-     *    _generate_config_option_name
710
-     *
711
-     * @access        protected
712
-     * @param        string $section
713
-     * @param        string $name
714
-     * @return        string
715
-     */
716
-    private function _generate_config_option_name($section = '', $name = '')
717
-    {
718
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
719
-    }
720
-
721
-
722
-
723
-    /**
724
-     *    _set_config_class
725
-     * ensures that a config class is set, either from a passed config class or one generated from the config name
726
-     *
727
-     * @access    private
728
-     * @param    string $config_class
729
-     * @param    string $name
730
-     * @return    string
731
-     */
732
-    private function _set_config_class($config_class = '', $name = '')
733
-    {
734
-        return ! empty($config_class)
735
-            ? $config_class
736
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
737
-    }
738
-
739
-
740
-
741
-    /**
742
-     *    set_config
743
-     *
744
-     * @access    protected
745
-     * @param    string         $section
746
-     * @param    string         $name
747
-     * @param    string         $config_class
748
-     * @param    EE_Config_Base $config_obj
749
-     * @return    EE_Config_Base
750
-     */
751
-    public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
752
-    {
753
-        // ensure config class is set to something
754
-        $config_class = $this->_set_config_class($config_class, $name);
755
-        // run tests 1-4, 6, and 7 to verify all config params are set and valid
756
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
757
-            return null;
758
-        }
759
-        $config_option_name = $this->_generate_config_option_name($section, $name);
760
-        // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
761
-        if (! isset($this->_addon_option_names[$config_option_name])) {
762
-            $this->_addon_option_names[$config_option_name] = $config_class;
763
-            $this->update_addon_option_names();
764
-        }
765
-        // verify the incoming config object but suppress errors
766
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
767
-            $config_obj = new $config_class();
768
-        }
769
-        if (get_option($config_option_name)) {
770
-            EE_Config::log($config_option_name);
771
-            update_option($config_option_name, $config_obj);
772
-            $this->{$section}->{$name} = $config_obj;
773
-            return $this->{$section}->{$name};
774
-        } else {
775
-            // create a wp-option for this config
776
-            if (add_option($config_option_name, $config_obj, '', 'no')) {
777
-                $this->{$section}->{$name} = maybe_unserialize($config_obj);
778
-                return $this->{$section}->{$name};
779
-            } else {
780
-                EE_Error::add_error(
781
-                    sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
782
-                    __FILE__,
783
-                    __FUNCTION__,
784
-                    __LINE__
785
-                );
786
-                return null;
787
-            }
788
-        }
789
-    }
790
-
791
-
792
-
793
-    /**
794
-     *    update_config
795
-     * Important: the config object must ALREADY be set, otherwise this will produce an error.
796
-     *
797
-     * @access    public
798
-     * @param    string                $section
799
-     * @param    string                $name
800
-     * @param    EE_Config_Base|string $config_obj
801
-     * @param    bool                  $throw_errors
802
-     * @return    bool
803
-     */
804
-    public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
805
-    {
806
-        // don't allow config updates during WP heartbeats
807
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
808
-            return false;
809
-        }
810
-        $config_obj = maybe_unserialize($config_obj);
811
-        // get class name of the incoming object
812
-        $config_class = get_class($config_obj);
813
-        // run tests 1-5 and 9 to verify config
814
-        if (! $this->_verify_config_params(
815
-            $section,
816
-            $name,
817
-            $config_class,
818
-            $config_obj,
819
-            array(1, 2, 3, 4, 7, 9)
820
-        )
821
-        ) {
822
-            return false;
823
-        }
824
-        $config_option_name = $this->_generate_config_option_name($section, $name);
825
-        // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
826
-        if (! isset($this->_addon_option_names[$config_option_name])) {
827
-            // save new config to db
828
-            if ($this->set_config($section, $name, $config_class, $config_obj)) {
829
-                return true;
830
-            }
831
-        } else {
832
-            // first check if the record already exists
833
-            $existing_config = get_option($config_option_name);
834
-            $config_obj = serialize($config_obj);
835
-            // just return if db record is already up to date (NOT type safe comparison)
836
-            if ($existing_config == $config_obj) {
837
-                $this->{$section}->{$name} = $config_obj;
838
-                return true;
839
-            } else if (update_option($config_option_name, $config_obj)) {
840
-                EE_Config::log($config_option_name);
841
-                // update wp-option for this config class
842
-                $this->{$section}->{$name} = $config_obj;
843
-                return true;
844
-            } elseif ($throw_errors) {
845
-                EE_Error::add_error(
846
-                    sprintf(
847
-                        __(
848
-                            'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
849
-                            'event_espresso'
850
-                        ),
851
-                        $config_class,
852
-                        'EE_Config->' . $section . '->' . $name
853
-                    ),
854
-                    __FILE__,
855
-                    __FUNCTION__,
856
-                    __LINE__
857
-                );
858
-            }
859
-        }
860
-        return false;
861
-    }
862
-
863
-
864
-
865
-    /**
866
-     *    get_config
867
-     *
868
-     * @access    public
869
-     * @param    string $section
870
-     * @param    string $name
871
-     * @param    string $config_class
872
-     * @return    mixed EE_Config_Base | NULL
873
-     */
874
-    public function get_config($section = '', $name = '', $config_class = '')
875
-    {
876
-        // ensure config class is set to something
877
-        $config_class = $this->_set_config_class($config_class, $name);
878
-        // run tests 1-4, 6 and 7 to verify that all params have been set
879
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
880
-            return null;
881
-        }
882
-        // now test if the requested config object exists, but suppress errors
883
-        if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
884
-            // config already exists, so pass it back
885
-            return $this->{$section}->{$name};
886
-        }
887
-        // load config option from db if it exists
888
-        $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
889
-        // verify the newly retrieved config object, but suppress errors
890
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
891
-            // config is good, so set it and pass it back
892
-            $this->{$section}->{$name} = $config_obj;
893
-            return $this->{$section}->{$name};
894
-        }
895
-        // oops! $config_obj is not already set and does not exist in the db, so create a new one
896
-        $config_obj = $this->set_config($section, $name, $config_class);
897
-        // verify the newly created config object
898
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
899
-            return $this->{$section}->{$name};
900
-        } else {
901
-            EE_Error::add_error(
902
-                sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
903
-                __FILE__,
904
-                __FUNCTION__,
905
-                __LINE__
906
-            );
907
-        }
908
-        return null;
909
-    }
910
-
911
-
912
-
913
-    /**
914
-     *    get_config_option
915
-     *
916
-     * @access    public
917
-     * @param    string $config_option_name
918
-     * @return    mixed EE_Config_Base | FALSE
919
-     */
920
-    public function get_config_option($config_option_name = '')
921
-    {
922
-        // retrieve the wp-option for this config class.
923
-        $config_option = maybe_unserialize(get_option($config_option_name, array()));
924
-        if (empty($config_option)) {
925
-            EE_Config::log($config_option_name . '-NOT-FOUND');
926
-        }
927
-        return $config_option;
928
-    }
929
-
930
-
931
-
932
-    /**
933
-     * log
934
-     *
935
-     * @param string $config_option_name
936
-     */
937
-    public static function log($config_option_name = '')
938
-    {
939
-        if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
940
-            $config_log = get_option(EE_Config::LOG_NAME, array());
941
-            //copy incoming $_REQUEST and sanitize it so we can save it
942
-            $_request = $_REQUEST;
943
-            array_walk_recursive($_request, 'sanitize_text_field');
944
-            $config_log[(string)microtime(true)] = array(
945
-                'config_name' => $config_option_name,
946
-                'request'     => $_request,
947
-            );
948
-            update_option(EE_Config::LOG_NAME, $config_log);
949
-        }
950
-    }
951
-
952
-
953
-
954
-    /**
955
-     * trim_log
956
-     * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
957
-     */
958
-    public static function trim_log()
959
-    {
960
-        if (! EE_Config::logging_enabled()) {
961
-            return;
962
-        }
963
-        $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
964
-        $log_length = count($config_log);
965
-        if ($log_length > EE_Config::LOG_LENGTH) {
966
-            ksort($config_log);
967
-            $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
968
-            update_option(EE_Config::LOG_NAME, $config_log);
969
-        }
970
-    }
971
-
972
-
973
-
974
-    /**
975
-     *    get_page_for_posts
976
-     *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
977
-     *    wp-option "page_for_posts", or "posts" if no page is selected
978
-     *
979
-     * @access    public
980
-     * @return    string
981
-     */
982
-    public static function get_page_for_posts()
983
-    {
984
-        $page_for_posts = get_option('page_for_posts');
985
-        if (! $page_for_posts) {
986
-            return 'posts';
987
-        }
988
-        /** @type WPDB $wpdb */
989
-        global $wpdb;
990
-        $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
991
-        return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
992
-    }
993
-
994
-
995
-
996
-    /**
997
-     *    register_shortcodes_and_modules.
998
-     *    At this point, it's too early to tell if we're maintenance mode or not.
999
-     *    In fact, this is where we give modules a chance to let core know they exist
1000
-     *    so they can help trigger maintenance mode if it's needed
1001
-     *
1002
-     * @access    public
1003
-     * @return    void
1004
-     */
1005
-    public function register_shortcodes_and_modules()
1006
-    {
1007
-        // allow modules to set hooks for the rest of the system
1008
-        EE_Registry::instance()->modules = $this->_register_modules();
1009
-    }
1010
-
1011
-
1012
-
1013
-    /**
1014
-     *    initialize_shortcodes_and_modules
1015
-     *    meaning they can start adding their hooks to get stuff done
1016
-     *
1017
-     * @access    public
1018
-     * @return    void
1019
-     */
1020
-    public function initialize_shortcodes_and_modules()
1021
-    {
1022
-        // allow modules to set hooks for the rest of the system
1023
-        $this->_initialize_modules();
1024
-    }
1025
-
1026
-
1027
-
1028
-    /**
1029
-     *    widgets_init
1030
-     *
1031
-     * @access private
1032
-     * @return void
1033
-     */
1034
-    public function widgets_init()
1035
-    {
1036
-        //only init widgets on admin pages when not in complete maintenance, and
1037
-        //on frontend when not in any maintenance mode
1038
-        if (
1039
-            ! EE_Maintenance_Mode::instance()->level()
1040
-            || (
1041
-                is_admin()
1042
-                && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1043
-            )
1044
-        ) {
1045
-            // grab list of installed widgets
1046
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1047
-            // filter list of modules to register
1048
-            $widgets_to_register = apply_filters(
1049
-                'FHEE__EE_Config__register_widgets__widgets_to_register',
1050
-                $widgets_to_register
1051
-            );
1052
-            if (! empty($widgets_to_register)) {
1053
-                // cycle thru widget folders
1054
-                foreach ($widgets_to_register as $widget_path) {
1055
-                    // add to list of installed widget modules
1056
-                    EE_Config::register_ee_widget($widget_path);
1057
-                }
1058
-            }
1059
-            // filter list of installed modules
1060
-            EE_Registry::instance()->widgets = apply_filters(
1061
-                'FHEE__EE_Config__register_widgets__installed_widgets',
1062
-                EE_Registry::instance()->widgets
1063
-            );
1064
-        }
1065
-    }
1066
-
1067
-
1068
-
1069
-    /**
1070
-     *    register_ee_widget - makes core aware of this widget
1071
-     *
1072
-     * @access    public
1073
-     * @param    string $widget_path - full path up to and including widget folder
1074
-     * @return    void
1075
-     */
1076
-    public static function register_ee_widget($widget_path = null)
1077
-    {
1078
-        do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1079
-        $widget_ext = '.widget.php';
1080
-        // make all separators match
1081
-        $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS);
1082
-        // does the file path INCLUDE the actual file name as part of the path ?
1083
-        if (strpos($widget_path, $widget_ext) !== false) {
1084
-            // grab and shortcode file name from directory name and break apart at dots
1085
-            $file_name = explode('.', basename($widget_path));
1086
-            // take first segment from file name pieces and remove class prefix if it exists
1087
-            $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1088
-            // sanitize shortcode directory name
1089
-            $widget = sanitize_key($widget);
1090
-            // now we need to rebuild the shortcode path
1091
-            $widget_path = explode(DS, $widget_path);
1092
-            // remove last segment
1093
-            array_pop($widget_path);
1094
-            // glue it back together
1095
-            $widget_path = implode(DS, $widget_path);
1096
-        } else {
1097
-            // grab and sanitize widget directory name
1098
-            $widget = sanitize_key(basename($widget_path));
1099
-        }
1100
-        // create classname from widget directory name
1101
-        $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1102
-        // add class prefix
1103
-        $widget_class = 'EEW_' . $widget;
1104
-        // does the widget exist ?
1105
-        if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1106
-            $msg = sprintf(
1107
-                __(
1108
-                    'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1109
-                    'event_espresso'
1110
-                ),
1111
-                $widget_class,
1112
-                $widget_path . DS . $widget_class . $widget_ext
1113
-            );
1114
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1115
-            return;
1116
-        }
1117
-        // load the widget class file
1118
-        require_once($widget_path . DS . $widget_class . $widget_ext);
1119
-        // verify that class exists
1120
-        if (! class_exists($widget_class)) {
1121
-            $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1122
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1123
-            return;
1124
-        }
1125
-        register_widget($widget_class);
1126
-        // add to array of registered widgets
1127
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1128
-    }
1129
-
1130
-
1131
-
1132
-    /**
1133
-     *        _register_modules
1134
-     *
1135
-     * @access private
1136
-     * @return array
1137
-     */
1138
-    private function _register_modules()
1139
-    {
1140
-        // grab list of installed modules
1141
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1142
-        // filter list of modules to register
1143
-        $modules_to_register = apply_filters(
1144
-            'FHEE__EE_Config__register_modules__modules_to_register',
1145
-            $modules_to_register
1146
-        );
1147
-        if (! empty($modules_to_register)) {
1148
-            // loop through folders
1149
-            foreach ($modules_to_register as $module_path) {
1150
-                /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1151
-                if (
1152
-                    $module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1153
-                    && $module_path !== EE_MODULES . 'gateways'
1154
-                ) {
1155
-                    // add to list of installed modules
1156
-                    EE_Config::register_module($module_path);
1157
-                }
1158
-            }
1159
-        }
1160
-        // filter list of installed modules
1161
-        return apply_filters(
1162
-            'FHEE__EE_Config___register_modules__installed_modules',
1163
-            EE_Registry::instance()->modules
1164
-        );
1165
-    }
1166
-
1167
-
1168
-
1169
-    /**
1170
-     *    register_module - makes core aware of this module
1171
-     *
1172
-     * @access    public
1173
-     * @param    string $module_path - full path up to and including module folder
1174
-     * @return    bool
1175
-     */
1176
-    public static function register_module($module_path = null)
1177
-    {
1178
-        do_action('AHEE__EE_Config__register_module__begin', $module_path);
1179
-        $module_ext = '.module.php';
1180
-        // make all separators match
1181
-        $module_path = str_replace(array('\\', '/'), DS, $module_path);
1182
-        // does the file path INCLUDE the actual file name as part of the path ?
1183
-        if (strpos($module_path, $module_ext) !== false) {
1184
-            // grab and shortcode file name from directory name and break apart at dots
1185
-            $module_file = explode('.', basename($module_path));
1186
-            // now we need to rebuild the shortcode path
1187
-            $module_path = explode(DS, $module_path);
1188
-            // remove last segment
1189
-            array_pop($module_path);
1190
-            // glue it back together
1191
-            $module_path = implode(DS, $module_path) . DS;
1192
-            // take first segment from file name pieces and sanitize it
1193
-            $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1194
-            // ensure class prefix is added
1195
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1196
-        } else {
1197
-            // we need to generate the filename based off of the folder name
1198
-            // grab and sanitize module name
1199
-            $module = strtolower(basename($module_path));
1200
-            $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1201
-            // like trailingslashit()
1202
-            $module_path = rtrim($module_path, DS) . DS;
1203
-            // create classname from module directory name
1204
-            $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1205
-            // add class prefix
1206
-            $module_class = 'EED_' . $module;
1207
-        }
1208
-        // does the module exist ?
1209
-        if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1210
-            $msg = sprintf(
1211
-                __(
1212
-                    'The requested %s module file could not be found or is not readable due to file permissions.',
1213
-                    'event_espresso'
1214
-                ),
1215
-                $module
1216
-            );
1217
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1218
-            return false;
1219
-        }
1220
-        // load the module class file
1221
-        require_once($module_path . $module_class . $module_ext);
1222
-        // verify that class exists
1223
-        if (! class_exists($module_class)) {
1224
-            $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1225
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1226
-            return false;
1227
-        }
1228
-        // add to array of registered modules
1229
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1230
-        do_action(
1231
-            'AHEE__EE_Config__register_module__complete',
1232
-            $module_class,
1233
-            EE_Registry::instance()->modules->{$module_class}
1234
-        );
1235
-        return true;
1236
-    }
1237
-
1238
-
1239
-
1240
-    /**
1241
-     *    _initialize_modules
1242
-     *    allow modules to set hooks for the rest of the system
1243
-     *
1244
-     * @access private
1245
-     * @return void
1246
-     */
1247
-    private function _initialize_modules()
1248
-    {
1249
-        // cycle thru shortcode folders
1250
-        foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1251
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1252
-            // which set hooks ?
1253
-            if (is_admin()) {
1254
-                // fire immediately
1255
-                call_user_func(array($module_class, 'set_hooks_admin'));
1256
-            } else {
1257
-                // delay until other systems are online
1258
-                add_action(
1259
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1260
-                    array($module_class, 'set_hooks')
1261
-                );
1262
-            }
1263
-        }
1264
-    }
1265
-
1266
-
1267
-
1268
-    /**
1269
-     *    register_route - adds module method routes to route_map
1270
-     *
1271
-     * @access    public
1272
-     * @param    string $route       - "pretty" public alias for module method
1273
-     * @param    string $module      - module name (classname without EED_ prefix)
1274
-     * @param    string $method_name - the actual module method to be routed to
1275
-     * @param    string $key         - url param key indicating a route is being called
1276
-     * @return    bool
1277
-     */
1278
-    public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1279
-    {
1280
-        do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1281
-        $module = str_replace('EED_', '', $module);
1282
-        $module_class = 'EED_' . $module;
1283
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1284
-            $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1285
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1286
-            return false;
1287
-        }
1288
-        if (empty($route)) {
1289
-            $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1290
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1291
-            return false;
1292
-        }
1293
-        if (! method_exists('EED_' . $module, $method_name)) {
1294
-            $msg = sprintf(
1295
-                __('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1296
-                $route
1297
-            );
1298
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1299
-            return false;
1300
-        }
1301
-        EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name);
1302
-        return true;
1303
-    }
1304
-
1305
-
1306
-
1307
-    /**
1308
-     *    get_route - get module method route
1309
-     *
1310
-     * @access    public
1311
-     * @param    string $route - "pretty" public alias for module method
1312
-     * @param    string $key   - url param key indicating a route is being called
1313
-     * @return    string
1314
-     */
1315
-    public static function get_route($route = null, $key = 'ee')
1316
-    {
1317
-        do_action('AHEE__EE_Config__get_route__begin', $route);
1318
-        $route = (string)apply_filters('FHEE__EE_Config__get_route', $route);
1319
-        if (isset(EE_Config::$_module_route_map[$key][$route])) {
1320
-            return EE_Config::$_module_route_map[$key][$route];
1321
-        }
1322
-        return null;
1323
-    }
1324
-
1325
-
1326
-
1327
-    /**
1328
-     *    get_routes - get ALL module method routes
1329
-     *
1330
-     * @access    public
1331
-     * @return    array
1332
-     */
1333
-    public static function get_routes()
1334
-    {
1335
-        return EE_Config::$_module_route_map;
1336
-    }
1337
-
1338
-
1339
-
1340
-    /**
1341
-     *    register_forward - allows modules to forward request to another module for further processing
1342
-     *
1343
-     * @access    public
1344
-     * @param    string       $route   - "pretty" public alias for module method
1345
-     * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1346
-     *                                 class, allows different forwards to be served based on status
1347
-     * @param    array|string $forward - function name or array( class, method )
1348
-     * @param    string       $key     - url param key indicating a route is being called
1349
-     * @return    bool
1350
-     */
1351
-    public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1352
-    {
1353
-        do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1354
-        if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1355
-            $msg = sprintf(
1356
-                __('The module route %s for this forward has not been registered.', 'event_espresso'),
1357
-                $route
1358
-            );
1359
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1360
-            return false;
1361
-        }
1362
-        if (empty($forward)) {
1363
-            $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1364
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1365
-            return false;
1366
-        }
1367
-        if (is_array($forward)) {
1368
-            if (! isset($forward[1])) {
1369
-                $msg = sprintf(
1370
-                    __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1371
-                    $route
1372
-                );
1373
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1374
-                return false;
1375
-            }
1376
-            if (! method_exists($forward[0], $forward[1])) {
1377
-                $msg = sprintf(
1378
-                    __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1379
-                    $forward[1],
1380
-                    $route
1381
-                );
1382
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1383
-                return false;
1384
-            }
1385
-        } else if (! function_exists($forward)) {
1386
-            $msg = sprintf(
1387
-                __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1388
-                $forward,
1389
-                $route
1390
-            );
1391
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1392
-            return false;
1393
-        }
1394
-        EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward;
1395
-        return true;
1396
-    }
1397
-
1398
-
1399
-
1400
-    /**
1401
-     *    get_forward - get forwarding route
1402
-     *
1403
-     * @access    public
1404
-     * @param    string  $route  - "pretty" public alias for module method
1405
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1406
-     *                           allows different forwards to be served based on status
1407
-     * @param    string  $key    - url param key indicating a route is being called
1408
-     * @return    string
1409
-     */
1410
-    public static function get_forward($route = null, $status = 0, $key = 'ee')
1411
-    {
1412
-        do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1413
-        if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) {
1414
-            return apply_filters(
1415
-                'FHEE__EE_Config__get_forward',
1416
-                EE_Config::$_module_forward_map[$key][$route][$status],
1417
-                $route,
1418
-                $status
1419
-            );
1420
-        }
1421
-        return null;
1422
-    }
1423
-
1424
-
1425
-
1426
-    /**
1427
-     *    register_forward - allows modules to specify different view templates for different method routes and status
1428
-     *    results
1429
-     *
1430
-     * @access    public
1431
-     * @param    string  $route  - "pretty" public alias for module method
1432
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1433
-     *                           allows different views to be served based on status
1434
-     * @param    string  $view
1435
-     * @param    string  $key    - url param key indicating a route is being called
1436
-     * @return    bool
1437
-     */
1438
-    public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1439
-    {
1440
-        do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1441
-        if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1442
-            $msg = sprintf(
1443
-                __('The module route %s for this view has not been registered.', 'event_espresso'),
1444
-                $route
1445
-            );
1446
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1447
-            return false;
1448
-        }
1449
-        if (! is_readable($view)) {
1450
-            $msg = sprintf(
1451
-                __(
1452
-                    'The %s view file could not be found or is not readable due to file permissions.',
1453
-                    'event_espresso'
1454
-                ),
1455
-                $view
1456
-            );
1457
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1458
-            return false;
1459
-        }
1460
-        EE_Config::$_module_view_map[$key][$route][absint($status)] = $view;
1461
-        return true;
1462
-    }
1463
-
1464
-
1465
-
1466
-    /**
1467
-     *    get_view - get view for route and status
1468
-     *
1469
-     * @access    public
1470
-     * @param    string  $route  - "pretty" public alias for module method
1471
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1472
-     *                           allows different views to be served based on status
1473
-     * @param    string  $key    - url param key indicating a route is being called
1474
-     * @return    string
1475
-     */
1476
-    public static function get_view($route = null, $status = 0, $key = 'ee')
1477
-    {
1478
-        do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1479
-        if (isset(EE_Config::$_module_view_map[$key][$route][$status])) {
1480
-            return apply_filters(
1481
-                'FHEE__EE_Config__get_view',
1482
-                EE_Config::$_module_view_map[$key][$route][$status],
1483
-                $route,
1484
-                $status
1485
-            );
1486
-        }
1487
-        return null;
1488
-    }
1489
-
1490
-
1491
-
1492
-    public function update_addon_option_names()
1493
-    {
1494
-        update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1495
-    }
1496
-
1497
-
1498
-
1499
-    public function shutdown()
1500
-    {
1501
-        $this->update_addon_option_names();
1502
-    }
1503
-
1504
-
1505
-
1506
-    /**
1507
-     * @return LegacyShortcodesManager
1508
-     */
1509
-    public static function getLegacyShortcodesManager()
1510
-    {
1511
-
1512
-        if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1513
-            EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1514
-                EE_Registry::instance()
1515
-            );
1516
-        }
1517
-        return EE_Config::instance()->legacy_shortcodes_manager;
1518
-    }
1519
-
1520
-
1521
-
1522
-    /**
1523
-     * register_shortcode - makes core aware of this shortcode
1524
-     *
1525
-     * @deprecated 4.9.26
1526
-     * @param    string $shortcode_path - full path up to and including shortcode folder
1527
-     * @return    bool
1528
-     */
1529
-    public static function register_shortcode($shortcode_path = null)
1530
-    {
1531
-        EE_Error::doing_it_wrong(
1532
-            __METHOD__,
1533
-            __(
1534
-                'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1535
-                'event_espresso'
1536
-            ),
1537
-            '4.9.26'
1538
-        );
1539
-        return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1540
-    }
1541
-
1542
-
1543
-
1544
-}
1545
-
1546
-
1547
-
1548
-/**
1549
- * Base class used for config classes. These classes should generally not have
1550
- * magic functions in use, except we'll allow them to magically set and get stuff...
1551
- * basically, they should just be well-defined stdClasses
1552
- */
1553
-class EE_Config_Base
1554
-{
1555
-
1556
-    /**
1557
-     * Utility function for escaping the value of a property and returning.
1558
-     *
1559
-     * @param string $property property name (checks to see if exists).
1560
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1561
-     * @throws \EE_Error
1562
-     */
1563
-    public function get_pretty($property)
1564
-    {
1565
-        if (! property_exists($this, $property)) {
1566
-            throw new EE_Error(
1567
-                sprintf(
1568
-                    __(
1569
-                        '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1570
-                        'event_espresso'
1571
-                    ),
1572
-                    get_class($this),
1573
-                    $property
1574
-                )
1575
-            );
1576
-        }
1577
-        //just handling escaping of strings for now.
1578
-        if (is_string($this->{$property})) {
1579
-            return stripslashes($this->{$property});
1580
-        }
1581
-        return $this->{$property};
1582
-    }
1583
-
1584
-
1585
-
1586
-    public function populate()
1587
-    {
1588
-        //grab defaults via a new instance of this class.
1589
-        $class_name = get_class($this);
1590
-        $defaults = new $class_name;
1591
-        //loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1592
-        //default from our $defaults object.
1593
-        foreach (get_object_vars($defaults) as $property => $value) {
1594
-            if ($this->{$property} === null) {
1595
-                $this->{$property} = $value;
1596
-            }
1597
-        }
1598
-        //cleanup
1599
-        unset($defaults);
1600
-    }
1601
-
1602
-
1603
-
1604
-    /**
1605
-     *        __isset
1606
-     *
1607
-     * @param $a
1608
-     * @return bool
1609
-     */
1610
-    public function __isset($a)
1611
-    {
1612
-        return false;
1613
-    }
1614
-
1615
-
1616
-
1617
-    /**
1618
-     *        __unset
1619
-     *
1620
-     * @param $a
1621
-     * @return bool
1622
-     */
1623
-    public function __unset($a)
1624
-    {
1625
-        return false;
1626
-    }
1627
-
1628
-
1629
-
1630
-    /**
1631
-     *        __clone
1632
-     */
1633
-    public function __clone()
1634
-    {
1635
-    }
1636
-
1637
-
1638
-
1639
-    /**
1640
-     *        __wakeup
1641
-     */
1642
-    public function __wakeup()
1643
-    {
1644
-    }
1645
-
1646
-
1647
-
1648
-    /**
1649
-     *        __destruct
1650
-     */
1651
-    public function __destruct()
1652
-    {
1653
-    }
1654
-}
1655
-
1656
-
1657
-
1658
-/**
1659
- * Class for defining what's in the EE_Config relating to registration settings
1660
- */
1661
-class EE_Core_Config extends EE_Config_Base
1662
-{
1663
-
1664
-    public $current_blog_id;
1665
-
1666
-    public $ee_ueip_optin;
1667
-
1668
-    public $ee_ueip_has_notified;
1669
-
1670
-    /**
1671
-     * Not to be confused with the 4 critical page variables (See
1672
-     * get_critical_pages_array()), this is just an array of wp posts that have EE
1673
-     * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1674
-     * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1675
-     *
1676
-     * @var array
1677
-     */
1678
-    public $post_shortcodes;
1679
-
1680
-    public $module_route_map;
1681
-
1682
-    public $module_forward_map;
1683
-
1684
-    public $module_view_map;
1685
-
1686
-    /**
1687
-     * The next 4 vars are the IDs of critical EE pages.
1688
-     *
1689
-     * @var int
1690
-     */
1691
-    public $reg_page_id;
1692
-
1693
-    public $txn_page_id;
1694
-
1695
-    public $thank_you_page_id;
1696
-
1697
-    public $cancel_page_id;
1698
-
1699
-    /**
1700
-     * The next 4 vars are the URLs of critical EE pages.
1701
-     *
1702
-     * @var int
1703
-     */
1704
-    public $reg_page_url;
1705
-
1706
-    public $txn_page_url;
1707
-
1708
-    public $thank_you_page_url;
1709
-
1710
-    public $cancel_page_url;
1711
-
1712
-    /**
1713
-     * The next vars relate to the custom slugs for EE CPT routes
1714
-     */
1715
-    public $event_cpt_slug;
1716
-
1717
-
1718
-    /**
1719
-     * This caches the _ee_ueip_option in case this config is reset in the same
1720
-     * request across blog switches in a multisite context.
1721
-     * Avoids extra queries to the db for this option.
1722
-     *
1723
-     * @var bool
1724
-     */
1725
-    public static $ee_ueip_option;
1726
-
1727
-
1728
-
1729
-    /**
1730
-     *    class constructor
1731
-     *
1732
-     * @access    public
1733
-     */
1734
-    public function __construct()
1735
-    {
1736
-        // set default organization settings
1737
-        $this->current_blog_id = get_current_blog_id();
1738
-        $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1739
-        $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1740
-        $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1741
-        $this->post_shortcodes = array();
1742
-        $this->module_route_map = array();
1743
-        $this->module_forward_map = array();
1744
-        $this->module_view_map = array();
1745
-        // critical EE page IDs
1746
-        $this->reg_page_id = 0;
1747
-        $this->txn_page_id = 0;
1748
-        $this->thank_you_page_id = 0;
1749
-        $this->cancel_page_id = 0;
1750
-        // critical EE page URLs
1751
-        $this->reg_page_url = '';
1752
-        $this->txn_page_url = '';
1753
-        $this->thank_you_page_url = '';
1754
-        $this->cancel_page_url = '';
1755
-        //cpt slugs
1756
-        $this->event_cpt_slug = __('events', 'event_espresso');
1757
-        //ueip constant check
1758
-        if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1759
-            $this->ee_ueip_optin = false;
1760
-            $this->ee_ueip_has_notified = true;
1761
-        }
1762
-    }
1763
-
1764
-
1765
-
1766
-    /**
1767
-     * @return array
1768
-     */
1769
-    public function get_critical_pages_array()
1770
-    {
1771
-        return array(
1772
-            $this->reg_page_id,
1773
-            $this->txn_page_id,
1774
-            $this->thank_you_page_id,
1775
-            $this->cancel_page_id,
1776
-        );
1777
-    }
1778
-
1779
-
1780
-
1781
-    /**
1782
-     * @return array
1783
-     */
1784
-    public function get_critical_pages_shortcodes_array()
1785
-    {
1786
-        return array(
1787
-            $this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1788
-            $this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1789
-            $this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1790
-            $this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1791
-        );
1792
-    }
1793
-
1794
-
1795
-
1796
-    /**
1797
-     *  gets/returns URL for EE reg_page
1798
-     *
1799
-     * @access    public
1800
-     * @return    string
1801
-     */
1802
-    public function reg_page_url()
1803
-    {
1804
-        if (! $this->reg_page_url) {
1805
-            $this->reg_page_url = add_query_arg(
1806
-                                      array('uts' => time()),
1807
-                                      get_permalink($this->reg_page_id)
1808
-                                  ) . '#checkout';
1809
-        }
1810
-        return $this->reg_page_url;
1811
-    }
1812
-
1813
-
1814
-
1815
-    /**
1816
-     *  gets/returns URL for EE txn_page
1817
-     *
1818
-     * @param array $query_args like what gets passed to
1819
-     *                          add_query_arg() as the first argument
1820
-     * @access    public
1821
-     * @return    string
1822
-     */
1823
-    public function txn_page_url($query_args = array())
1824
-    {
1825
-        if (! $this->txn_page_url) {
1826
-            $this->txn_page_url = get_permalink($this->txn_page_id);
1827
-        }
1828
-        if ($query_args) {
1829
-            return add_query_arg($query_args, $this->txn_page_url);
1830
-        } else {
1831
-            return $this->txn_page_url;
1832
-        }
1833
-    }
1834
-
1835
-
1836
-
1837
-    /**
1838
-     *  gets/returns URL for EE thank_you_page
1839
-     *
1840
-     * @param array $query_args like what gets passed to
1841
-     *                          add_query_arg() as the first argument
1842
-     * @access    public
1843
-     * @return    string
1844
-     */
1845
-    public function thank_you_page_url($query_args = array())
1846
-    {
1847
-        if (! $this->thank_you_page_url) {
1848
-            $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1849
-        }
1850
-        if ($query_args) {
1851
-            return add_query_arg($query_args, $this->thank_you_page_url);
1852
-        } else {
1853
-            return $this->thank_you_page_url;
1854
-        }
1855
-    }
1856
-
1857
-
1858
-
1859
-    /**
1860
-     *  gets/returns URL for EE cancel_page
1861
-     *
1862
-     * @access    public
1863
-     * @return    string
1864
-     */
1865
-    public function cancel_page_url()
1866
-    {
1867
-        if (! $this->cancel_page_url) {
1868
-            $this->cancel_page_url = get_permalink($this->cancel_page_id);
1869
-        }
1870
-        return $this->cancel_page_url;
1871
-    }
1872
-
1873
-
1874
-
1875
-    /**
1876
-     * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1877
-     *
1878
-     * @since 4.7.5
1879
-     */
1880
-    protected function _reset_urls()
1881
-    {
1882
-        $this->reg_page_url = '';
1883
-        $this->txn_page_url = '';
1884
-        $this->cancel_page_url = '';
1885
-        $this->thank_you_page_url = '';
1886
-    }
1887
-
1888
-
1889
-
1890
-    /**
1891
-     * Used to return what the optin value is set for the EE User Experience Program.
1892
-     * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1893
-     * on the main site only.
1894
-     *
1895
-     * @return mixed|void
1896
-     */
1897
-    protected function _get_main_ee_ueip_optin()
1898
-    {
1899
-        //if this is the main site then we can just bypass our direct query.
1900
-        if (is_main_site()) {
1901
-            return get_option('ee_ueip_optin', false);
1902
-        }
1903
-        //is this already cached for this request?  If so use it.
1904
-        if ( ! empty(EE_Core_Config::$ee_ueip_option)) {
1905
-            return EE_Core_Config::$ee_ueip_option;
1906
-        }
1907
-        global $wpdb;
1908
-        $current_network_main_site = is_multisite() ? get_current_site() : null;
1909
-        $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1910
-        $option = 'ee_ueip_optin';
1911
-        //set correct table for query
1912
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1913
-        //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1914
-        //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1915
-        //re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1916
-        //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1917
-        //for the purpose of caching.
1918
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1919
-        if (false !== $pre) {
1920
-            EE_Core_Config::$ee_ueip_option = $pre;
1921
-            return EE_Core_Config::$ee_ueip_option;
1922
-        }
1923
-        $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1924
-            $option));
1925
-        if (is_object($row)) {
1926
-            $value = $row->option_value;
1927
-        } else { //option does not exist so use default.
1928
-            return apply_filters('default_option_' . $option, false, $option);
1929
-        }
1930
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1931
-        return EE_Core_Config::$ee_ueip_option;
1932
-    }
1933
-
1934
-    /**
1935
-     * Utility function for escaping the value of a property and returning.
1936
-     *
1937
-     * @param string $property property name (checks to see if exists).
1938
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1939
-     * @throws \EE_Error
1940
-     */
1941
-    public function get_pretty($property)
1942
-    {
1943
-        if ($property === 'ee_ueip_optin') {
1944
-            return $this->ee_ueip_optin ? 'yes' : 'no';
1945
-        }
1946
-        return parent::get_pretty($property);
1947
-    }
1948
-
1949
-
1950
-    /**
1951
-     * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1952
-     * on the object.
1953
-     *
1954
-     * @return array
1955
-     */
1956
-    public function __sleep()
1957
-    {
1958
-        //reset all url properties
1959
-        $this->_reset_urls();
1960
-        //return what to save to db
1961
-        return array_keys(get_object_vars($this));
1962
-    }
1963
-
1964
-}
1965
-
1966
-
1967
-
1968
-/**
1969
- * Config class for storing info on the Organization
1970
- */
1971
-class EE_Organization_Config extends EE_Config_Base
1972
-{
1973
-
1974
-    /**
1975
-     * @var string $name
1976
-     * eg EE4.1
1977
-     */
1978
-    public $name;
1979
-
1980
-    /**
1981
-     * @var string $address_1
1982
-     * eg 123 Onna Road
1983
-     */
1984
-    public $address_1;
1985
-
1986
-    /**
1987
-     * @var string $address_2
1988
-     * eg PO Box 123
1989
-     */
1990
-    public $address_2;
1991
-
1992
-    /**
1993
-     * @var string $city
1994
-     * eg Inna City
1995
-     */
1996
-    public $city;
1997
-
1998
-    /**
1999
-     * @var int $STA_ID
2000
-     * eg 4
2001
-     */
2002
-    public $STA_ID;
2003
-
2004
-    /**
2005
-     * @var string $CNT_ISO
2006
-     * eg US
2007
-     */
2008
-    public $CNT_ISO;
2009
-
2010
-    /**
2011
-     * @var string $zip
2012
-     * eg 12345  or V1A 2B3
2013
-     */
2014
-    public $zip;
2015
-
2016
-    /**
2017
-     * @var string $email
2018
-     * eg [email protected]
2019
-     */
2020
-    public $email;
2021
-
2022
-
2023
-    /**
2024
-     * @var string $phone
2025
-     * eg. 111-111-1111
2026
-     */
2027
-    public $phone;
2028
-
2029
-
2030
-    /**
2031
-     * @var string $vat
2032
-     * VAT/Tax Number
2033
-     */
2034
-    public $vat;
2035
-
2036
-    /**
2037
-     * @var string $logo_url
2038
-     * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
2039
-     */
2040
-    public $logo_url;
2041
-
2042
-
2043
-    /**
2044
-     * The below are all various properties for holding links to organization social network profiles
2045
-     *
2046
-     * @var string
2047
-     */
2048
-    /**
2049
-     * facebook (facebook.com/profile.name)
2050
-     *
2051
-     * @var string
2052
-     */
2053
-    public $facebook;
2054
-
2055
-
2056
-    /**
2057
-     * twitter (twitter.com/twitter_handle)
2058
-     *
2059
-     * @var string
2060
-     */
2061
-    public $twitter;
2062
-
2063
-
2064
-    /**
2065
-     * linkedin (linkedin.com/in/profile_name)
2066
-     *
2067
-     * @var string
2068
-     */
2069
-    public $linkedin;
2070
-
2071
-
2072
-    /**
2073
-     * pinterest (www.pinterest.com/profile_name)
2074
-     *
2075
-     * @var string
2076
-     */
2077
-    public $pinterest;
2078
-
2079
-
2080
-    /**
2081
-     * google+ (google.com/+profileName)
2082
-     *
2083
-     * @var string
2084
-     */
2085
-    public $google;
2086
-
2087
-
2088
-    /**
2089
-     * instagram (instagram.com/handle)
2090
-     *
2091
-     * @var string
2092
-     */
2093
-    public $instagram;
2094
-
2095
-
2096
-
2097
-    /**
2098
-     *    class constructor
2099
-     *
2100
-     * @access    public
2101
-     */
2102
-    public function __construct()
2103
-    {
2104
-        // set default organization settings
2105
-        //decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2106
-        $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2107
-        $this->address_1 = '123 Onna Road';
2108
-        $this->address_2 = 'PO Box 123';
2109
-        $this->city = 'Inna City';
2110
-        $this->STA_ID = 4;
2111
-        $this->CNT_ISO = 'US';
2112
-        $this->zip = '12345';
2113
-        $this->email = get_bloginfo('admin_email');
2114
-        $this->phone = '';
2115
-        $this->vat = '123456789';
2116
-        $this->logo_url = '';
2117
-        $this->facebook = '';
2118
-        $this->twitter = '';
2119
-        $this->linkedin = '';
2120
-        $this->pinterest = '';
2121
-        $this->google = '';
2122
-        $this->instagram = '';
2123
-    }
2124
-
2125
-}
2126
-
2127
-
2128
-
2129
-/**
2130
- * Class for defining what's in the EE_Config relating to currency
2131
- */
2132
-class EE_Currency_Config extends EE_Config_Base
2133
-{
2134
-
2135
-    /**
2136
-     * @var string $code
2137
-     * eg 'US'
2138
-     */
2139
-    public $code;
2140
-
2141
-    /**
2142
-     * @var string $name
2143
-     * eg 'Dollar'
2144
-     */
2145
-    public $name;
2146
-
2147
-    /**
2148
-     * plural name
2149
-     *
2150
-     * @var string $plural
2151
-     * eg 'Dollars'
2152
-     */
2153
-    public $plural;
2154
-
2155
-    /**
2156
-     * currency sign
2157
-     *
2158
-     * @var string $sign
2159
-     * eg '$'
2160
-     */
2161
-    public $sign;
2162
-
2163
-    /**
2164
-     * Whether the currency sign should come before the number or not
2165
-     *
2166
-     * @var boolean $sign_b4
2167
-     */
2168
-    public $sign_b4;
2169
-
2170
-    /**
2171
-     * How many digits should come after the decimal place
2172
-     *
2173
-     * @var int $dec_plc
2174
-     */
2175
-    public $dec_plc;
2176
-
2177
-    /**
2178
-     * Symbol to use for decimal mark
2179
-     *
2180
-     * @var string $dec_mrk
2181
-     * eg '.'
2182
-     */
2183
-    public $dec_mrk;
2184
-
2185
-    /**
2186
-     * Symbol to use for thousands
2187
-     *
2188
-     * @var string $thsnds
2189
-     * eg ','
2190
-     */
2191
-    public $thsnds;
2192
-
2193
-
2194
-
2195
-    /**
2196
-     *    class constructor
2197
-     *
2198
-     * @access    public
2199
-     * @param string $CNT_ISO
2200
-     * @throws \EE_Error
2201
-     */
2202
-    public function __construct($CNT_ISO = '')
2203
-    {
2204
-        /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2205
-        $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2206
-        // get country code from organization settings or use default
2207
-        $ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2208
-                   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2209
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
2210
-            : '';
2211
-        // but override if requested
2212
-        $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2213
-        // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2214
-        if (
2215
-            ! empty($CNT_ISO)
2216
-            && EE_Maintenance_Mode::instance()->models_can_query()
2217
-            && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2218
-        ) {
2219
-            // retrieve the country settings from the db, just in case they have been customized
2220
-            $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2221
-            if ($country instanceof EE_Country) {
2222
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2223
-                $this->name = $country->currency_name_single();    // Dollar
2224
-                $this->plural = $country->currency_name_plural();    // Dollars
2225
-                $this->sign = $country->currency_sign();            // currency sign: $
2226
-                $this->sign_b4 = $country->currency_sign_before();        // currency sign before or after: $TRUE  or  FALSE$
2227
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2228
-                $this->dec_mrk = $country->currency_decimal_mark();    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2229
-                $this->thsnds = $country->currency_thousands_separator();    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2230
-            }
2231
-        }
2232
-        // fallback to hardcoded defaults, in case the above failed
2233
-        if (empty($this->code)) {
2234
-            // set default currency settings
2235
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2236
-            $this->name = __('Dollar', 'event_espresso');    // Dollar
2237
-            $this->plural = __('Dollars', 'event_espresso');    // Dollars
2238
-            $this->sign = '$';    // currency sign: $
2239
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2240
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2241
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2242
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2243
-        }
2244
-    }
2245
-}
2246
-
2247
-
2248
-
2249
-/**
2250
- * Class for defining what's in the EE_Config relating to registration settings
2251
- */
2252
-class EE_Registration_Config extends EE_Config_Base
2253
-{
2254
-
2255
-    /**
2256
-     * Default registration status
2257
-     *
2258
-     * @var string $default_STS_ID
2259
-     * eg 'RPP'
2260
-     */
2261
-    public $default_STS_ID;
2262
-
2263
-
2264
-    /**
2265
-     * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2266
-     * registrations)
2267
-     * @var int
2268
-     */
2269
-    public $default_maximum_number_of_tickets;
2270
-
2271
-
2272
-    /**
2273
-     * level of validation to apply to email addresses
2274
-     *
2275
-     * @var string $email_validation_level
2276
-     * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2277
-     */
2278
-    public $email_validation_level;
2279
-
2280
-    /**
2281
-     *    whether or not to show alternate payment options during the reg process if payment status is pending
2282
-     *
2283
-     * @var boolean $show_pending_payment_options
2284
-     */
2285
-    public $show_pending_payment_options;
2286
-
2287
-    /**
2288
-     * Whether to skip the registration confirmation page
2289
-     *
2290
-     * @var boolean $skip_reg_confirmation
2291
-     */
2292
-    public $skip_reg_confirmation;
2293
-
2294
-    /**
2295
-     * an array of SPCO reg steps where:
2296
-     *        the keys denotes the reg step order
2297
-     *        each element consists of an array with the following elements:
2298
-     *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2299
-     *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2300
-     *            "slug" => the URL param used to trigger the reg step
2301
-     *
2302
-     * @var array $reg_steps
2303
-     */
2304
-    public $reg_steps;
2305
-
2306
-    /**
2307
-     * Whether registration confirmation should be the last page of SPCO
2308
-     *
2309
-     * @var boolean $reg_confirmation_last
2310
-     */
2311
-    public $reg_confirmation_last;
2312
-
2313
-    /**
2314
-     * Whether or not to enable the EE Bot Trap
2315
-     *
2316
-     * @var boolean $use_bot_trap
2317
-     */
2318
-    public $use_bot_trap;
2319
-
2320
-    /**
2321
-     * Whether or not to encrypt some data sent by the EE Bot Trap
2322
-     *
2323
-     * @var boolean $use_encryption
2324
-     */
2325
-    public $use_encryption;
2326
-
2327
-    /**
2328
-     * Whether or not to use ReCaptcha
2329
-     *
2330
-     * @var boolean $use_captcha
2331
-     */
2332
-    public $use_captcha;
2333
-
2334
-    /**
2335
-     * ReCaptcha Theme
2336
-     *
2337
-     * @var string $recaptcha_theme
2338
-     *    options: 'dark', 'light', 'invisible'
2339
-     */
2340
-    public $recaptcha_theme;
1544
+}
2341 1545
 
2342
-    /**
2343
-     * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2344
-     *
2345
-     * @var string $recaptcha_badge
2346
-     *    options: 'bottomright', 'bottomleft', 'inline'
2347
-     */
2348
-    public $recaptcha_badge;
2349 1546
 
2350
-    /**
2351
-     * ReCaptcha Type
2352
-     *
2353
-     * @var string $recaptcha_type
2354
-     *    options: 'audio', 'image'
2355
-     */
2356
-    public $recaptcha_type;
2357 1547
 
2358
-    /**
2359
-     * ReCaptcha language
2360
-     *
2361
-     * @var string $recaptcha_language
2362
-     * eg 'en'
2363
-     */
2364
-    public $recaptcha_language;
1548
+/**
1549
+ * Base class used for config classes. These classes should generally not have
1550
+ * magic functions in use, except we'll allow them to magically set and get stuff...
1551
+ * basically, they should just be well-defined stdClasses
1552
+ */
1553
+class EE_Config_Base
1554
+{
2365 1555
 
2366
-    /**
2367
-     * ReCaptcha public key
2368
-     *
2369
-     * @var string $recaptcha_publickey
2370
-     */
2371
-    public $recaptcha_publickey;
1556
+	/**
1557
+	 * Utility function for escaping the value of a property and returning.
1558
+	 *
1559
+	 * @param string $property property name (checks to see if exists).
1560
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1561
+	 * @throws \EE_Error
1562
+	 */
1563
+	public function get_pretty($property)
1564
+	{
1565
+		if (! property_exists($this, $property)) {
1566
+			throw new EE_Error(
1567
+				sprintf(
1568
+					__(
1569
+						'%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1570
+						'event_espresso'
1571
+					),
1572
+					get_class($this),
1573
+					$property
1574
+				)
1575
+			);
1576
+		}
1577
+		//just handling escaping of strings for now.
1578
+		if (is_string($this->{$property})) {
1579
+			return stripslashes($this->{$property});
1580
+		}
1581
+		return $this->{$property};
1582
+	}
1583
+
1584
+
1585
+
1586
+	public function populate()
1587
+	{
1588
+		//grab defaults via a new instance of this class.
1589
+		$class_name = get_class($this);
1590
+		$defaults = new $class_name;
1591
+		//loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1592
+		//default from our $defaults object.
1593
+		foreach (get_object_vars($defaults) as $property => $value) {
1594
+			if ($this->{$property} === null) {
1595
+				$this->{$property} = $value;
1596
+			}
1597
+		}
1598
+		//cleanup
1599
+		unset($defaults);
1600
+	}
1601
+
1602
+
1603
+
1604
+	/**
1605
+	 *        __isset
1606
+	 *
1607
+	 * @param $a
1608
+	 * @return bool
1609
+	 */
1610
+	public function __isset($a)
1611
+	{
1612
+		return false;
1613
+	}
1614
+
1615
+
1616
+
1617
+	/**
1618
+	 *        __unset
1619
+	 *
1620
+	 * @param $a
1621
+	 * @return bool
1622
+	 */
1623
+	public function __unset($a)
1624
+	{
1625
+		return false;
1626
+	}
1627
+
1628
+
1629
+
1630
+	/**
1631
+	 *        __clone
1632
+	 */
1633
+	public function __clone()
1634
+	{
1635
+	}
1636
+
1637
+
1638
+
1639
+	/**
1640
+	 *        __wakeup
1641
+	 */
1642
+	public function __wakeup()
1643
+	{
1644
+	}
1645
+
1646
+
1647
+
1648
+	/**
1649
+	 *        __destruct
1650
+	 */
1651
+	public function __destruct()
1652
+	{
1653
+	}
1654
+}
2372 1655
 
2373
-    /**
2374
-     * ReCaptcha private key
2375
-     *
2376
-     * @var string $recaptcha_privatekey
2377
-     */
2378
-    public $recaptcha_privatekey;
2379 1656
 
2380
-    /**
2381
-     * array of form names protected by ReCaptcha
2382
-     *
2383
-     * @var array $recaptcha_protected_forms
2384
-     */
2385
-    public $recaptcha_protected_forms;
2386 1657
 
2387
-    /**
2388
-     * ReCaptcha width
2389
-     *
2390
-     * @var int $recaptcha_width
2391
-     * @deprecated
2392
-     */
2393
-    public $recaptcha_width;
1658
+/**
1659
+ * Class for defining what's in the EE_Config relating to registration settings
1660
+ */
1661
+class EE_Core_Config extends EE_Config_Base
1662
+{
2394 1663
 
2395
-    /**
2396
-     * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2397
-     *
2398
-     * @var boolean $track_invalid_checkout_access
2399
-     */
2400
-    protected $track_invalid_checkout_access = true;
1664
+	public $current_blog_id;
1665
+
1666
+	public $ee_ueip_optin;
1667
+
1668
+	public $ee_ueip_has_notified;
1669
+
1670
+	/**
1671
+	 * Not to be confused with the 4 critical page variables (See
1672
+	 * get_critical_pages_array()), this is just an array of wp posts that have EE
1673
+	 * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1674
+	 * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1675
+	 *
1676
+	 * @var array
1677
+	 */
1678
+	public $post_shortcodes;
1679
+
1680
+	public $module_route_map;
1681
+
1682
+	public $module_forward_map;
1683
+
1684
+	public $module_view_map;
1685
+
1686
+	/**
1687
+	 * The next 4 vars are the IDs of critical EE pages.
1688
+	 *
1689
+	 * @var int
1690
+	 */
1691
+	public $reg_page_id;
1692
+
1693
+	public $txn_page_id;
1694
+
1695
+	public $thank_you_page_id;
1696
+
1697
+	public $cancel_page_id;
1698
+
1699
+	/**
1700
+	 * The next 4 vars are the URLs of critical EE pages.
1701
+	 *
1702
+	 * @var int
1703
+	 */
1704
+	public $reg_page_url;
1705
+
1706
+	public $txn_page_url;
1707
+
1708
+	public $thank_you_page_url;
1709
+
1710
+	public $cancel_page_url;
1711
+
1712
+	/**
1713
+	 * The next vars relate to the custom slugs for EE CPT routes
1714
+	 */
1715
+	public $event_cpt_slug;
1716
+
1717
+
1718
+	/**
1719
+	 * This caches the _ee_ueip_option in case this config is reset in the same
1720
+	 * request across blog switches in a multisite context.
1721
+	 * Avoids extra queries to the db for this option.
1722
+	 *
1723
+	 * @var bool
1724
+	 */
1725
+	public static $ee_ueip_option;
1726
+
1727
+
1728
+
1729
+	/**
1730
+	 *    class constructor
1731
+	 *
1732
+	 * @access    public
1733
+	 */
1734
+	public function __construct()
1735
+	{
1736
+		// set default organization settings
1737
+		$this->current_blog_id = get_current_blog_id();
1738
+		$this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1739
+		$this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1740
+		$this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1741
+		$this->post_shortcodes = array();
1742
+		$this->module_route_map = array();
1743
+		$this->module_forward_map = array();
1744
+		$this->module_view_map = array();
1745
+		// critical EE page IDs
1746
+		$this->reg_page_id = 0;
1747
+		$this->txn_page_id = 0;
1748
+		$this->thank_you_page_id = 0;
1749
+		$this->cancel_page_id = 0;
1750
+		// critical EE page URLs
1751
+		$this->reg_page_url = '';
1752
+		$this->txn_page_url = '';
1753
+		$this->thank_you_page_url = '';
1754
+		$this->cancel_page_url = '';
1755
+		//cpt slugs
1756
+		$this->event_cpt_slug = __('events', 'event_espresso');
1757
+		//ueip constant check
1758
+		if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1759
+			$this->ee_ueip_optin = false;
1760
+			$this->ee_ueip_has_notified = true;
1761
+		}
1762
+	}
1763
+
1764
+
1765
+
1766
+	/**
1767
+	 * @return array
1768
+	 */
1769
+	public function get_critical_pages_array()
1770
+	{
1771
+		return array(
1772
+			$this->reg_page_id,
1773
+			$this->txn_page_id,
1774
+			$this->thank_you_page_id,
1775
+			$this->cancel_page_id,
1776
+		);
1777
+	}
1778
+
1779
+
1780
+
1781
+	/**
1782
+	 * @return array
1783
+	 */
1784
+	public function get_critical_pages_shortcodes_array()
1785
+	{
1786
+		return array(
1787
+			$this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1788
+			$this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1789
+			$this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1790
+			$this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1791
+		);
1792
+	}
1793
+
1794
+
1795
+
1796
+	/**
1797
+	 *  gets/returns URL for EE reg_page
1798
+	 *
1799
+	 * @access    public
1800
+	 * @return    string
1801
+	 */
1802
+	public function reg_page_url()
1803
+	{
1804
+		if (! $this->reg_page_url) {
1805
+			$this->reg_page_url = add_query_arg(
1806
+									  array('uts' => time()),
1807
+									  get_permalink($this->reg_page_id)
1808
+								  ) . '#checkout';
1809
+		}
1810
+		return $this->reg_page_url;
1811
+	}
1812
+
1813
+
1814
+
1815
+	/**
1816
+	 *  gets/returns URL for EE txn_page
1817
+	 *
1818
+	 * @param array $query_args like what gets passed to
1819
+	 *                          add_query_arg() as the first argument
1820
+	 * @access    public
1821
+	 * @return    string
1822
+	 */
1823
+	public function txn_page_url($query_args = array())
1824
+	{
1825
+		if (! $this->txn_page_url) {
1826
+			$this->txn_page_url = get_permalink($this->txn_page_id);
1827
+		}
1828
+		if ($query_args) {
1829
+			return add_query_arg($query_args, $this->txn_page_url);
1830
+		} else {
1831
+			return $this->txn_page_url;
1832
+		}
1833
+	}
1834
+
1835
+
1836
+
1837
+	/**
1838
+	 *  gets/returns URL for EE thank_you_page
1839
+	 *
1840
+	 * @param array $query_args like what gets passed to
1841
+	 *                          add_query_arg() as the first argument
1842
+	 * @access    public
1843
+	 * @return    string
1844
+	 */
1845
+	public function thank_you_page_url($query_args = array())
1846
+	{
1847
+		if (! $this->thank_you_page_url) {
1848
+			$this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1849
+		}
1850
+		if ($query_args) {
1851
+			return add_query_arg($query_args, $this->thank_you_page_url);
1852
+		} else {
1853
+			return $this->thank_you_page_url;
1854
+		}
1855
+	}
1856
+
1857
+
1858
+
1859
+	/**
1860
+	 *  gets/returns URL for EE cancel_page
1861
+	 *
1862
+	 * @access    public
1863
+	 * @return    string
1864
+	 */
1865
+	public function cancel_page_url()
1866
+	{
1867
+		if (! $this->cancel_page_url) {
1868
+			$this->cancel_page_url = get_permalink($this->cancel_page_id);
1869
+		}
1870
+		return $this->cancel_page_url;
1871
+	}
1872
+
1873
+
1874
+
1875
+	/**
1876
+	 * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1877
+	 *
1878
+	 * @since 4.7.5
1879
+	 */
1880
+	protected function _reset_urls()
1881
+	{
1882
+		$this->reg_page_url = '';
1883
+		$this->txn_page_url = '';
1884
+		$this->cancel_page_url = '';
1885
+		$this->thank_you_page_url = '';
1886
+	}
1887
+
1888
+
1889
+
1890
+	/**
1891
+	 * Used to return what the optin value is set for the EE User Experience Program.
1892
+	 * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1893
+	 * on the main site only.
1894
+	 *
1895
+	 * @return mixed|void
1896
+	 */
1897
+	protected function _get_main_ee_ueip_optin()
1898
+	{
1899
+		//if this is the main site then we can just bypass our direct query.
1900
+		if (is_main_site()) {
1901
+			return get_option('ee_ueip_optin', false);
1902
+		}
1903
+		//is this already cached for this request?  If so use it.
1904
+		if ( ! empty(EE_Core_Config::$ee_ueip_option)) {
1905
+			return EE_Core_Config::$ee_ueip_option;
1906
+		}
1907
+		global $wpdb;
1908
+		$current_network_main_site = is_multisite() ? get_current_site() : null;
1909
+		$current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1910
+		$option = 'ee_ueip_optin';
1911
+		//set correct table for query
1912
+		$table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1913
+		//rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1914
+		//get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1915
+		//re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1916
+		//this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1917
+		//for the purpose of caching.
1918
+		$pre = apply_filters('pre_option_' . $option, false, $option);
1919
+		if (false !== $pre) {
1920
+			EE_Core_Config::$ee_ueip_option = $pre;
1921
+			return EE_Core_Config::$ee_ueip_option;
1922
+		}
1923
+		$row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1924
+			$option));
1925
+		if (is_object($row)) {
1926
+			$value = $row->option_value;
1927
+		} else { //option does not exist so use default.
1928
+			return apply_filters('default_option_' . $option, false, $option);
1929
+		}
1930
+		EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1931
+		return EE_Core_Config::$ee_ueip_option;
1932
+	}
1933
+
1934
+	/**
1935
+	 * Utility function for escaping the value of a property and returning.
1936
+	 *
1937
+	 * @param string $property property name (checks to see if exists).
1938
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1939
+	 * @throws \EE_Error
1940
+	 */
1941
+	public function get_pretty($property)
1942
+	{
1943
+		if ($property === 'ee_ueip_optin') {
1944
+			return $this->ee_ueip_optin ? 'yes' : 'no';
1945
+		}
1946
+		return parent::get_pretty($property);
1947
+	}
1948
+
1949
+
1950
+	/**
1951
+	 * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1952
+	 * on the object.
1953
+	 *
1954
+	 * @return array
1955
+	 */
1956
+	public function __sleep()
1957
+	{
1958
+		//reset all url properties
1959
+		$this->_reset_urls();
1960
+		//return what to save to db
1961
+		return array_keys(get_object_vars($this));
1962
+	}
2401 1963
 
1964
+}
2402 1965
 
2403 1966
 
2404
-    /**
2405
-     *    class constructor
2406
-     *
2407
-     * @access    public
2408
-     */
2409
-    public function __construct()
2410
-    {
2411
-        // set default registration settings
2412
-        $this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2413
-        $this->email_validation_level = 'wp_default';
2414
-        $this->show_pending_payment_options = true;
2415
-        $this->skip_reg_confirmation = false;
2416
-        $this->reg_steps = array();
2417
-        $this->reg_confirmation_last = false;
2418
-        $this->use_bot_trap = true;
2419
-        $this->use_encryption = true;
2420
-        $this->use_captcha = false;
2421
-        $this->recaptcha_theme = 'light';
2422
-        $this->recaptcha_badge = 'bottomleft';
2423
-        $this->recaptcha_type = 'image';
2424
-        $this->recaptcha_language = 'en';
2425
-        $this->recaptcha_publickey = null;
2426
-        $this->recaptcha_privatekey = null;
2427
-        $this->recaptcha_protected_forms = array();
2428
-        $this->recaptcha_width = 500;
2429
-        $this->default_maximum_number_of_tickets = 10;
2430
-    }
2431
-
2432
-
2433
-
2434
-    /**
2435
-     * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2436
-     *
2437
-     * @since 4.8.8.rc.019
2438
-     */
2439
-    public function do_hooks()
2440
-    {
2441
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2442
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2443
-    }
2444 1967
 
1968
+/**
1969
+ * Config class for storing info on the Organization
1970
+ */
1971
+class EE_Organization_Config extends EE_Config_Base
1972
+{
2445 1973
 
1974
+	/**
1975
+	 * @var string $name
1976
+	 * eg EE4.1
1977
+	 */
1978
+	public $name;
1979
+
1980
+	/**
1981
+	 * @var string $address_1
1982
+	 * eg 123 Onna Road
1983
+	 */
1984
+	public $address_1;
1985
+
1986
+	/**
1987
+	 * @var string $address_2
1988
+	 * eg PO Box 123
1989
+	 */
1990
+	public $address_2;
1991
+
1992
+	/**
1993
+	 * @var string $city
1994
+	 * eg Inna City
1995
+	 */
1996
+	public $city;
1997
+
1998
+	/**
1999
+	 * @var int $STA_ID
2000
+	 * eg 4
2001
+	 */
2002
+	public $STA_ID;
2003
+
2004
+	/**
2005
+	 * @var string $CNT_ISO
2006
+	 * eg US
2007
+	 */
2008
+	public $CNT_ISO;
2009
+
2010
+	/**
2011
+	 * @var string $zip
2012
+	 * eg 12345  or V1A 2B3
2013
+	 */
2014
+	public $zip;
2015
+
2016
+	/**
2017
+	 * @var string $email
2018
+	 * eg [email protected]
2019
+	 */
2020
+	public $email;
2021
+
2022
+
2023
+	/**
2024
+	 * @var string $phone
2025
+	 * eg. 111-111-1111
2026
+	 */
2027
+	public $phone;
2028
+
2029
+
2030
+	/**
2031
+	 * @var string $vat
2032
+	 * VAT/Tax Number
2033
+	 */
2034
+	public $vat;
2035
+
2036
+	/**
2037
+	 * @var string $logo_url
2038
+	 * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
2039
+	 */
2040
+	public $logo_url;
2041
+
2042
+
2043
+	/**
2044
+	 * The below are all various properties for holding links to organization social network profiles
2045
+	 *
2046
+	 * @var string
2047
+	 */
2048
+	/**
2049
+	 * facebook (facebook.com/profile.name)
2050
+	 *
2051
+	 * @var string
2052
+	 */
2053
+	public $facebook;
2054
+
2055
+
2056
+	/**
2057
+	 * twitter (twitter.com/twitter_handle)
2058
+	 *
2059
+	 * @var string
2060
+	 */
2061
+	public $twitter;
2062
+
2063
+
2064
+	/**
2065
+	 * linkedin (linkedin.com/in/profile_name)
2066
+	 *
2067
+	 * @var string
2068
+	 */
2069
+	public $linkedin;
2070
+
2071
+
2072
+	/**
2073
+	 * pinterest (www.pinterest.com/profile_name)
2074
+	 *
2075
+	 * @var string
2076
+	 */
2077
+	public $pinterest;
2078
+
2079
+
2080
+	/**
2081
+	 * google+ (google.com/+profileName)
2082
+	 *
2083
+	 * @var string
2084
+	 */
2085
+	public $google;
2086
+
2087
+
2088
+	/**
2089
+	 * instagram (instagram.com/handle)
2090
+	 *
2091
+	 * @var string
2092
+	 */
2093
+	public $instagram;
2094
+
2095
+
2096
+
2097
+	/**
2098
+	 *    class constructor
2099
+	 *
2100
+	 * @access    public
2101
+	 */
2102
+	public function __construct()
2103
+	{
2104
+		// set default organization settings
2105
+		//decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2106
+		$this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2107
+		$this->address_1 = '123 Onna Road';
2108
+		$this->address_2 = 'PO Box 123';
2109
+		$this->city = 'Inna City';
2110
+		$this->STA_ID = 4;
2111
+		$this->CNT_ISO = 'US';
2112
+		$this->zip = '12345';
2113
+		$this->email = get_bloginfo('admin_email');
2114
+		$this->phone = '';
2115
+		$this->vat = '123456789';
2116
+		$this->logo_url = '';
2117
+		$this->facebook = '';
2118
+		$this->twitter = '';
2119
+		$this->linkedin = '';
2120
+		$this->pinterest = '';
2121
+		$this->google = '';
2122
+		$this->instagram = '';
2123
+	}
2446 2124
 
2447
-    /**
2448
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status
2449
-     * field matches the config setting for default_STS_ID.
2450
-     */
2451
-    public function set_default_reg_status_on_EEM_Event()
2452
-    {
2453
-        EEM_Event::set_default_reg_status($this->default_STS_ID);
2454
-    }
2125
+}
2455 2126
 
2456 2127
 
2457
-    /**
2458
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2459
-     * for Events matches the config setting for default_maximum_number_of_tickets
2460
-     */
2461
-    public function set_default_max_ticket_on_EEM_Event()
2462
-    {
2463
-        EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2464
-    }
2465 2128
 
2129
+/**
2130
+ * Class for defining what's in the EE_Config relating to currency
2131
+ */
2132
+class EE_Currency_Config extends EE_Config_Base
2133
+{
2466 2134
 
2135
+	/**
2136
+	 * @var string $code
2137
+	 * eg 'US'
2138
+	 */
2139
+	public $code;
2140
+
2141
+	/**
2142
+	 * @var string $name
2143
+	 * eg 'Dollar'
2144
+	 */
2145
+	public $name;
2146
+
2147
+	/**
2148
+	 * plural name
2149
+	 *
2150
+	 * @var string $plural
2151
+	 * eg 'Dollars'
2152
+	 */
2153
+	public $plural;
2154
+
2155
+	/**
2156
+	 * currency sign
2157
+	 *
2158
+	 * @var string $sign
2159
+	 * eg '$'
2160
+	 */
2161
+	public $sign;
2162
+
2163
+	/**
2164
+	 * Whether the currency sign should come before the number or not
2165
+	 *
2166
+	 * @var boolean $sign_b4
2167
+	 */
2168
+	public $sign_b4;
2169
+
2170
+	/**
2171
+	 * How many digits should come after the decimal place
2172
+	 *
2173
+	 * @var int $dec_plc
2174
+	 */
2175
+	public $dec_plc;
2176
+
2177
+	/**
2178
+	 * Symbol to use for decimal mark
2179
+	 *
2180
+	 * @var string $dec_mrk
2181
+	 * eg '.'
2182
+	 */
2183
+	public $dec_mrk;
2184
+
2185
+	/**
2186
+	 * Symbol to use for thousands
2187
+	 *
2188
+	 * @var string $thsnds
2189
+	 * eg ','
2190
+	 */
2191
+	public $thsnds;
2192
+
2193
+
2194
+
2195
+	/**
2196
+	 *    class constructor
2197
+	 *
2198
+	 * @access    public
2199
+	 * @param string $CNT_ISO
2200
+	 * @throws \EE_Error
2201
+	 */
2202
+	public function __construct($CNT_ISO = '')
2203
+	{
2204
+		/** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2205
+		$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2206
+		// get country code from organization settings or use default
2207
+		$ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2208
+				   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2209
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
2210
+			: '';
2211
+		// but override if requested
2212
+		$CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2213
+		// so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2214
+		if (
2215
+			! empty($CNT_ISO)
2216
+			&& EE_Maintenance_Mode::instance()->models_can_query()
2217
+			&& $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2218
+		) {
2219
+			// retrieve the country settings from the db, just in case they have been customized
2220
+			$country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2221
+			if ($country instanceof EE_Country) {
2222
+				$this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2223
+				$this->name = $country->currency_name_single();    // Dollar
2224
+				$this->plural = $country->currency_name_plural();    // Dollars
2225
+				$this->sign = $country->currency_sign();            // currency sign: $
2226
+				$this->sign_b4 = $country->currency_sign_before();        // currency sign before or after: $TRUE  or  FALSE$
2227
+				$this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2228
+				$this->dec_mrk = $country->currency_decimal_mark();    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2229
+				$this->thsnds = $country->currency_thousands_separator();    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2230
+			}
2231
+		}
2232
+		// fallback to hardcoded defaults, in case the above failed
2233
+		if (empty($this->code)) {
2234
+			// set default currency settings
2235
+			$this->code = 'USD';    // currency code: USD, CAD, EUR
2236
+			$this->name = __('Dollar', 'event_espresso');    // Dollar
2237
+			$this->plural = __('Dollars', 'event_espresso');    // Dollars
2238
+			$this->sign = '$';    // currency sign: $
2239
+			$this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2240
+			$this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2241
+			$this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2242
+			$this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2243
+		}
2244
+	}
2245
+}
2467 2246
 
2468
-    /**
2469
-     * @return boolean
2470
-     */
2471
-    public function track_invalid_checkout_access()
2472
-    {
2473
-        return $this->track_invalid_checkout_access;
2474
-    }
2475 2247
 
2476 2248
 
2249
+/**
2250
+ * Class for defining what's in the EE_Config relating to registration settings
2251
+ */
2252
+class EE_Registration_Config extends EE_Config_Base
2253
+{
2477 2254
 
2478
-    /**
2479
-     * @param boolean $track_invalid_checkout_access
2480
-     */
2481
-    public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2482
-    {
2483
-        $this->track_invalid_checkout_access = filter_var(
2484
-            $track_invalid_checkout_access,
2485
-            FILTER_VALIDATE_BOOLEAN
2486
-        );
2487
-    }
2255
+	/**
2256
+	 * Default registration status
2257
+	 *
2258
+	 * @var string $default_STS_ID
2259
+	 * eg 'RPP'
2260
+	 */
2261
+	public $default_STS_ID;
2262
+
2263
+
2264
+	/**
2265
+	 * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2266
+	 * registrations)
2267
+	 * @var int
2268
+	 */
2269
+	public $default_maximum_number_of_tickets;
2270
+
2271
+
2272
+	/**
2273
+	 * level of validation to apply to email addresses
2274
+	 *
2275
+	 * @var string $email_validation_level
2276
+	 * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2277
+	 */
2278
+	public $email_validation_level;
2279
+
2280
+	/**
2281
+	 *    whether or not to show alternate payment options during the reg process if payment status is pending
2282
+	 *
2283
+	 * @var boolean $show_pending_payment_options
2284
+	 */
2285
+	public $show_pending_payment_options;
2286
+
2287
+	/**
2288
+	 * Whether to skip the registration confirmation page
2289
+	 *
2290
+	 * @var boolean $skip_reg_confirmation
2291
+	 */
2292
+	public $skip_reg_confirmation;
2293
+
2294
+	/**
2295
+	 * an array of SPCO reg steps where:
2296
+	 *        the keys denotes the reg step order
2297
+	 *        each element consists of an array with the following elements:
2298
+	 *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2299
+	 *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2300
+	 *            "slug" => the URL param used to trigger the reg step
2301
+	 *
2302
+	 * @var array $reg_steps
2303
+	 */
2304
+	public $reg_steps;
2305
+
2306
+	/**
2307
+	 * Whether registration confirmation should be the last page of SPCO
2308
+	 *
2309
+	 * @var boolean $reg_confirmation_last
2310
+	 */
2311
+	public $reg_confirmation_last;
2312
+
2313
+	/**
2314
+	 * Whether or not to enable the EE Bot Trap
2315
+	 *
2316
+	 * @var boolean $use_bot_trap
2317
+	 */
2318
+	public $use_bot_trap;
2319
+
2320
+	/**
2321
+	 * Whether or not to encrypt some data sent by the EE Bot Trap
2322
+	 *
2323
+	 * @var boolean $use_encryption
2324
+	 */
2325
+	public $use_encryption;
2326
+
2327
+	/**
2328
+	 * Whether or not to use ReCaptcha
2329
+	 *
2330
+	 * @var boolean $use_captcha
2331
+	 */
2332
+	public $use_captcha;
2333
+
2334
+	/**
2335
+	 * ReCaptcha Theme
2336
+	 *
2337
+	 * @var string $recaptcha_theme
2338
+	 *    options: 'dark', 'light', 'invisible'
2339
+	 */
2340
+	public $recaptcha_theme;
2341
+
2342
+	/**
2343
+	 * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2344
+	 *
2345
+	 * @var string $recaptcha_badge
2346
+	 *    options: 'bottomright', 'bottomleft', 'inline'
2347
+	 */
2348
+	public $recaptcha_badge;
2349
+
2350
+	/**
2351
+	 * ReCaptcha Type
2352
+	 *
2353
+	 * @var string $recaptcha_type
2354
+	 *    options: 'audio', 'image'
2355
+	 */
2356
+	public $recaptcha_type;
2357
+
2358
+	/**
2359
+	 * ReCaptcha language
2360
+	 *
2361
+	 * @var string $recaptcha_language
2362
+	 * eg 'en'
2363
+	 */
2364
+	public $recaptcha_language;
2365
+
2366
+	/**
2367
+	 * ReCaptcha public key
2368
+	 *
2369
+	 * @var string $recaptcha_publickey
2370
+	 */
2371
+	public $recaptcha_publickey;
2372
+
2373
+	/**
2374
+	 * ReCaptcha private key
2375
+	 *
2376
+	 * @var string $recaptcha_privatekey
2377
+	 */
2378
+	public $recaptcha_privatekey;
2379
+
2380
+	/**
2381
+	 * array of form names protected by ReCaptcha
2382
+	 *
2383
+	 * @var array $recaptcha_protected_forms
2384
+	 */
2385
+	public $recaptcha_protected_forms;
2386
+
2387
+	/**
2388
+	 * ReCaptcha width
2389
+	 *
2390
+	 * @var int $recaptcha_width
2391
+	 * @deprecated
2392
+	 */
2393
+	public $recaptcha_width;
2394
+
2395
+	/**
2396
+	 * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2397
+	 *
2398
+	 * @var boolean $track_invalid_checkout_access
2399
+	 */
2400
+	protected $track_invalid_checkout_access = true;
2401
+
2402
+
2403
+
2404
+	/**
2405
+	 *    class constructor
2406
+	 *
2407
+	 * @access    public
2408
+	 */
2409
+	public function __construct()
2410
+	{
2411
+		// set default registration settings
2412
+		$this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2413
+		$this->email_validation_level = 'wp_default';
2414
+		$this->show_pending_payment_options = true;
2415
+		$this->skip_reg_confirmation = false;
2416
+		$this->reg_steps = array();
2417
+		$this->reg_confirmation_last = false;
2418
+		$this->use_bot_trap = true;
2419
+		$this->use_encryption = true;
2420
+		$this->use_captcha = false;
2421
+		$this->recaptcha_theme = 'light';
2422
+		$this->recaptcha_badge = 'bottomleft';
2423
+		$this->recaptcha_type = 'image';
2424
+		$this->recaptcha_language = 'en';
2425
+		$this->recaptcha_publickey = null;
2426
+		$this->recaptcha_privatekey = null;
2427
+		$this->recaptcha_protected_forms = array();
2428
+		$this->recaptcha_width = 500;
2429
+		$this->default_maximum_number_of_tickets = 10;
2430
+	}
2431
+
2432
+
2433
+
2434
+	/**
2435
+	 * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2436
+	 *
2437
+	 * @since 4.8.8.rc.019
2438
+	 */
2439
+	public function do_hooks()
2440
+	{
2441
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2442
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2443
+	}
2444
+
2445
+
2446
+
2447
+	/**
2448
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status
2449
+	 * field matches the config setting for default_STS_ID.
2450
+	 */
2451
+	public function set_default_reg_status_on_EEM_Event()
2452
+	{
2453
+		EEM_Event::set_default_reg_status($this->default_STS_ID);
2454
+	}
2455
+
2456
+
2457
+	/**
2458
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2459
+	 * for Events matches the config setting for default_maximum_number_of_tickets
2460
+	 */
2461
+	public function set_default_max_ticket_on_EEM_Event()
2462
+	{
2463
+		EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2464
+	}
2465
+
2466
+
2467
+
2468
+	/**
2469
+	 * @return boolean
2470
+	 */
2471
+	public function track_invalid_checkout_access()
2472
+	{
2473
+		return $this->track_invalid_checkout_access;
2474
+	}
2475
+
2476
+
2477
+
2478
+	/**
2479
+	 * @param boolean $track_invalid_checkout_access
2480
+	 */
2481
+	public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2482
+	{
2483
+		$this->track_invalid_checkout_access = filter_var(
2484
+			$track_invalid_checkout_access,
2485
+			FILTER_VALIDATE_BOOLEAN
2486
+		);
2487
+	}
2488 2488
 
2489 2489
 
2490 2490
 
@@ -2498,160 +2498,160 @@  discard block
 block discarded – undo
2498 2498
 class EE_Admin_Config extends EE_Config_Base
2499 2499
 {
2500 2500
 
2501
-    /**
2502
-     * @var boolean $use_personnel_manager
2503
-     */
2504
-    public $use_personnel_manager;
2505
-
2506
-    /**
2507
-     * @var boolean $use_dashboard_widget
2508
-     */
2509
-    public $use_dashboard_widget;
2510
-
2511
-    /**
2512
-     * @var int $events_in_dashboard
2513
-     */
2514
-    public $events_in_dashboard;
2515
-
2516
-    /**
2517
-     * @var boolean $use_event_timezones
2518
-     */
2519
-    public $use_event_timezones;
2520
-
2521
-    /**
2522
-     * @var boolean $use_full_logging
2523
-     */
2524
-    public $use_full_logging;
2525
-
2526
-    /**
2527
-     * @var string $log_file_name
2528
-     */
2529
-    public $log_file_name;
2530
-
2531
-    /**
2532
-     * @var string $debug_file_name
2533
-     */
2534
-    public $debug_file_name;
2535
-
2536
-    /**
2537
-     * @var boolean $use_remote_logging
2538
-     */
2539
-    public $use_remote_logging;
2540
-
2541
-    /**
2542
-     * @var string $remote_logging_url
2543
-     */
2544
-    public $remote_logging_url;
2545
-
2546
-    /**
2547
-     * @var boolean $show_reg_footer
2548
-     */
2549
-    public $show_reg_footer;
2550
-
2551
-    /**
2552
-     * @var string $affiliate_id
2553
-     */
2554
-    public $affiliate_id;
2555
-
2556
-    /**
2557
-     * help tours on or off (global setting)
2558
-     *
2559
-     * @var boolean
2560
-     */
2561
-    public $help_tour_activation;
2562
-
2563
-    /**
2564
-     * adds extra layer of encoding to session data to prevent serialization errors
2565
-     * but is incompatible with some server configuration errors
2566
-     * if you get "500 internal server errors" during registration, try turning this on
2567
-     * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2568
-     *
2569
-     * @var boolean $encode_session_data
2570
-     */
2571
-    private $encode_session_data = false;
2572
-
2573
-
2574
-
2575
-    /**
2576
-     *    class constructor
2577
-     *
2578
-     * @access    public
2579
-     */
2580
-    public function __construct()
2581
-    {
2582
-        // set default general admin settings
2583
-        $this->use_personnel_manager = true;
2584
-        $this->use_dashboard_widget = true;
2585
-        $this->events_in_dashboard = 30;
2586
-        $this->use_event_timezones = false;
2587
-        $this->use_full_logging = false;
2588
-        $this->use_remote_logging = false;
2589
-        $this->remote_logging_url = null;
2590
-        $this->show_reg_footer = true;
2591
-        $this->affiliate_id = 'default';
2592
-        $this->help_tour_activation = true;
2593
-        $this->encode_session_data = false;
2594
-    }
2595
-
2596
-
2597
-
2598
-    /**
2599
-     * @param bool $reset
2600
-     * @return string
2601
-     */
2602
-    public function log_file_name($reset = false)
2603
-    {
2604
-        if (empty($this->log_file_name) || $reset) {
2605
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2606
-            EE_Config::instance()->update_espresso_config(false, false);
2607
-        }
2608
-        return $this->log_file_name;
2609
-    }
2610
-
2611
-
2612
-
2613
-    /**
2614
-     * @param bool $reset
2615
-     * @return string
2616
-     */
2617
-    public function debug_file_name($reset = false)
2618
-    {
2619
-        if (empty($this->debug_file_name) || $reset) {
2620
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2621
-            EE_Config::instance()->update_espresso_config(false, false);
2622
-        }
2623
-        return $this->debug_file_name;
2624
-    }
2625
-
2626
-
2627
-
2628
-    /**
2629
-     * @return string
2630
-     */
2631
-    public function affiliate_id()
2632
-    {
2633
-        return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2634
-    }
2635
-
2636
-
2637
-
2638
-    /**
2639
-     * @return boolean
2640
-     */
2641
-    public function encode_session_data()
2642
-    {
2643
-        return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2644
-    }
2645
-
2646
-
2647
-
2648
-    /**
2649
-     * @param boolean $encode_session_data
2650
-     */
2651
-    public function set_encode_session_data($encode_session_data)
2652
-    {
2653
-        $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2654
-    }
2501
+	/**
2502
+	 * @var boolean $use_personnel_manager
2503
+	 */
2504
+	public $use_personnel_manager;
2505
+
2506
+	/**
2507
+	 * @var boolean $use_dashboard_widget
2508
+	 */
2509
+	public $use_dashboard_widget;
2510
+
2511
+	/**
2512
+	 * @var int $events_in_dashboard
2513
+	 */
2514
+	public $events_in_dashboard;
2515
+
2516
+	/**
2517
+	 * @var boolean $use_event_timezones
2518
+	 */
2519
+	public $use_event_timezones;
2520
+
2521
+	/**
2522
+	 * @var boolean $use_full_logging
2523
+	 */
2524
+	public $use_full_logging;
2525
+
2526
+	/**
2527
+	 * @var string $log_file_name
2528
+	 */
2529
+	public $log_file_name;
2530
+
2531
+	/**
2532
+	 * @var string $debug_file_name
2533
+	 */
2534
+	public $debug_file_name;
2535
+
2536
+	/**
2537
+	 * @var boolean $use_remote_logging
2538
+	 */
2539
+	public $use_remote_logging;
2540
+
2541
+	/**
2542
+	 * @var string $remote_logging_url
2543
+	 */
2544
+	public $remote_logging_url;
2545
+
2546
+	/**
2547
+	 * @var boolean $show_reg_footer
2548
+	 */
2549
+	public $show_reg_footer;
2550
+
2551
+	/**
2552
+	 * @var string $affiliate_id
2553
+	 */
2554
+	public $affiliate_id;
2555
+
2556
+	/**
2557
+	 * help tours on or off (global setting)
2558
+	 *
2559
+	 * @var boolean
2560
+	 */
2561
+	public $help_tour_activation;
2562
+
2563
+	/**
2564
+	 * adds extra layer of encoding to session data to prevent serialization errors
2565
+	 * but is incompatible with some server configuration errors
2566
+	 * if you get "500 internal server errors" during registration, try turning this on
2567
+	 * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2568
+	 *
2569
+	 * @var boolean $encode_session_data
2570
+	 */
2571
+	private $encode_session_data = false;
2572
+
2573
+
2574
+
2575
+	/**
2576
+	 *    class constructor
2577
+	 *
2578
+	 * @access    public
2579
+	 */
2580
+	public function __construct()
2581
+	{
2582
+		// set default general admin settings
2583
+		$this->use_personnel_manager = true;
2584
+		$this->use_dashboard_widget = true;
2585
+		$this->events_in_dashboard = 30;
2586
+		$this->use_event_timezones = false;
2587
+		$this->use_full_logging = false;
2588
+		$this->use_remote_logging = false;
2589
+		$this->remote_logging_url = null;
2590
+		$this->show_reg_footer = true;
2591
+		$this->affiliate_id = 'default';
2592
+		$this->help_tour_activation = true;
2593
+		$this->encode_session_data = false;
2594
+	}
2595
+
2596
+
2597
+
2598
+	/**
2599
+	 * @param bool $reset
2600
+	 * @return string
2601
+	 */
2602
+	public function log_file_name($reset = false)
2603
+	{
2604
+		if (empty($this->log_file_name) || $reset) {
2605
+			$this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2606
+			EE_Config::instance()->update_espresso_config(false, false);
2607
+		}
2608
+		return $this->log_file_name;
2609
+	}
2610
+
2611
+
2612
+
2613
+	/**
2614
+	 * @param bool $reset
2615
+	 * @return string
2616
+	 */
2617
+	public function debug_file_name($reset = false)
2618
+	{
2619
+		if (empty($this->debug_file_name) || $reset) {
2620
+			$this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2621
+			EE_Config::instance()->update_espresso_config(false, false);
2622
+		}
2623
+		return $this->debug_file_name;
2624
+	}
2625
+
2626
+
2627
+
2628
+	/**
2629
+	 * @return string
2630
+	 */
2631
+	public function affiliate_id()
2632
+	{
2633
+		return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2634
+	}
2635
+
2636
+
2637
+
2638
+	/**
2639
+	 * @return boolean
2640
+	 */
2641
+	public function encode_session_data()
2642
+	{
2643
+		return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2644
+	}
2645
+
2646
+
2647
+
2648
+	/**
2649
+	 * @param boolean $encode_session_data
2650
+	 */
2651
+	public function set_encode_session_data($encode_session_data)
2652
+	{
2653
+		$this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2654
+	}
2655 2655
 
2656 2656
 
2657 2657
 
@@ -2665,71 +2665,71 @@  discard block
 block discarded – undo
2665 2665
 class EE_Template_Config extends EE_Config_Base
2666 2666
 {
2667 2667
 
2668
-    /**
2669
-     * @var boolean $enable_default_style
2670
-     */
2671
-    public $enable_default_style;
2672
-
2673
-    /**
2674
-     * @var string $custom_style_sheet
2675
-     */
2676
-    public $custom_style_sheet;
2677
-
2678
-    /**
2679
-     * @var boolean $display_address_in_regform
2680
-     */
2681
-    public $display_address_in_regform;
2682
-
2683
-    /**
2684
-     * @var int $display_description_on_multi_reg_page
2685
-     */
2686
-    public $display_description_on_multi_reg_page;
2687
-
2688
-    /**
2689
-     * @var boolean $use_custom_templates
2690
-     */
2691
-    public $use_custom_templates;
2692
-
2693
-    /**
2694
-     * @var string $current_espresso_theme
2695
-     */
2696
-    public $current_espresso_theme;
2697
-
2698
-    /**
2699
-     * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2700
-     */
2701
-    public $EED_Ticket_Selector;
2702
-
2703
-    /**
2704
-     * @var EE_Event_Single_Config $EED_Event_Single
2705
-     */
2706
-    public $EED_Event_Single;
2707
-
2708
-    /**
2709
-     * @var EE_Events_Archive_Config $EED_Events_Archive
2710
-     */
2711
-    public $EED_Events_Archive;
2712
-
2713
-
2714
-
2715
-    /**
2716
-     *    class constructor
2717
-     *
2718
-     * @access    public
2719
-     */
2720
-    public function __construct()
2721
-    {
2722
-        // set default template settings
2723
-        $this->enable_default_style = true;
2724
-        $this->custom_style_sheet = null;
2725
-        $this->display_address_in_regform = true;
2726
-        $this->display_description_on_multi_reg_page = false;
2727
-        $this->use_custom_templates = false;
2728
-        $this->current_espresso_theme = 'Espresso_Arabica_2014';
2729
-        $this->EED_Event_Single = null;
2730
-        $this->EED_Events_Archive = null;
2731
-        $this->EED_Ticket_Selector = null;
2732
-    }
2668
+	/**
2669
+	 * @var boolean $enable_default_style
2670
+	 */
2671
+	public $enable_default_style;
2672
+
2673
+	/**
2674
+	 * @var string $custom_style_sheet
2675
+	 */
2676
+	public $custom_style_sheet;
2677
+
2678
+	/**
2679
+	 * @var boolean $display_address_in_regform
2680
+	 */
2681
+	public $display_address_in_regform;
2682
+
2683
+	/**
2684
+	 * @var int $display_description_on_multi_reg_page
2685
+	 */
2686
+	public $display_description_on_multi_reg_page;
2687
+
2688
+	/**
2689
+	 * @var boolean $use_custom_templates
2690
+	 */
2691
+	public $use_custom_templates;
2692
+
2693
+	/**
2694
+	 * @var string $current_espresso_theme
2695
+	 */
2696
+	public $current_espresso_theme;
2697
+
2698
+	/**
2699
+	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2700
+	 */
2701
+	public $EED_Ticket_Selector;
2702
+
2703
+	/**
2704
+	 * @var EE_Event_Single_Config $EED_Event_Single
2705
+	 */
2706
+	public $EED_Event_Single;
2707
+
2708
+	/**
2709
+	 * @var EE_Events_Archive_Config $EED_Events_Archive
2710
+	 */
2711
+	public $EED_Events_Archive;
2712
+
2713
+
2714
+
2715
+	/**
2716
+	 *    class constructor
2717
+	 *
2718
+	 * @access    public
2719
+	 */
2720
+	public function __construct()
2721
+	{
2722
+		// set default template settings
2723
+		$this->enable_default_style = true;
2724
+		$this->custom_style_sheet = null;
2725
+		$this->display_address_in_regform = true;
2726
+		$this->display_description_on_multi_reg_page = false;
2727
+		$this->use_custom_templates = false;
2728
+		$this->current_espresso_theme = 'Espresso_Arabica_2014';
2729
+		$this->EED_Event_Single = null;
2730
+		$this->EED_Events_Archive = null;
2731
+		$this->EED_Ticket_Selector = null;
2732
+	}
2733 2733
 
2734 2734
 }
2735 2735
 
@@ -2741,115 +2741,115 @@  discard block
 block discarded – undo
2741 2741
 class EE_Map_Config extends EE_Config_Base
2742 2742
 {
2743 2743
 
2744
-    /**
2745
-     * @var boolean $use_google_maps
2746
-     */
2747
-    public $use_google_maps;
2748
-
2749
-    /**
2750
-     * @var string $api_key
2751
-     */
2752
-    public $google_map_api_key;
2753
-
2754
-    /**
2755
-     * @var int $event_details_map_width
2756
-     */
2757
-    public $event_details_map_width;
2758
-
2759
-    /**
2760
-     * @var int $event_details_map_height
2761
-     */
2762
-    public $event_details_map_height;
2763
-
2764
-    /**
2765
-     * @var int $event_details_map_zoom
2766
-     */
2767
-    public $event_details_map_zoom;
2768
-
2769
-    /**
2770
-     * @var boolean $event_details_display_nav
2771
-     */
2772
-    public $event_details_display_nav;
2773
-
2774
-    /**
2775
-     * @var boolean $event_details_nav_size
2776
-     */
2777
-    public $event_details_nav_size;
2778
-
2779
-    /**
2780
-     * @var string $event_details_control_type
2781
-     */
2782
-    public $event_details_control_type;
2783
-
2784
-    /**
2785
-     * @var string $event_details_map_align
2786
-     */
2787
-    public $event_details_map_align;
2788
-
2789
-    /**
2790
-     * @var int $event_list_map_width
2791
-     */
2792
-    public $event_list_map_width;
2793
-
2794
-    /**
2795
-     * @var int $event_list_map_height
2796
-     */
2797
-    public $event_list_map_height;
2798
-
2799
-    /**
2800
-     * @var int $event_list_map_zoom
2801
-     */
2802
-    public $event_list_map_zoom;
2803
-
2804
-    /**
2805
-     * @var boolean $event_list_display_nav
2806
-     */
2807
-    public $event_list_display_nav;
2808
-
2809
-    /**
2810
-     * @var boolean $event_list_nav_size
2811
-     */
2812
-    public $event_list_nav_size;
2813
-
2814
-    /**
2815
-     * @var string $event_list_control_type
2816
-     */
2817
-    public $event_list_control_type;
2818
-
2819
-    /**
2820
-     * @var string $event_list_map_align
2821
-     */
2822
-    public $event_list_map_align;
2823
-
2824
-
2825
-
2826
-    /**
2827
-     *    class constructor
2828
-     *
2829
-     * @access    public
2830
-     */
2831
-    public function __construct()
2832
-    {
2833
-        // set default map settings
2834
-        $this->use_google_maps = true;
2835
-        $this->google_map_api_key = '';
2836
-        // for event details pages (reg page)
2837
-        $this->event_details_map_width = 585;            // ee_map_width_single
2838
-        $this->event_details_map_height = 362;            // ee_map_height_single
2839
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2840
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2841
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2842
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2843
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2844
-        // for event list pages
2845
-        $this->event_list_map_width = 300;            // ee_map_width
2846
-        $this->event_list_map_height = 185;        // ee_map_height
2847
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2848
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2849
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2850
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2851
-        $this->event_list_map_align = 'center';            // ee_map_align
2852
-    }
2744
+	/**
2745
+	 * @var boolean $use_google_maps
2746
+	 */
2747
+	public $use_google_maps;
2748
+
2749
+	/**
2750
+	 * @var string $api_key
2751
+	 */
2752
+	public $google_map_api_key;
2753
+
2754
+	/**
2755
+	 * @var int $event_details_map_width
2756
+	 */
2757
+	public $event_details_map_width;
2758
+
2759
+	/**
2760
+	 * @var int $event_details_map_height
2761
+	 */
2762
+	public $event_details_map_height;
2763
+
2764
+	/**
2765
+	 * @var int $event_details_map_zoom
2766
+	 */
2767
+	public $event_details_map_zoom;
2768
+
2769
+	/**
2770
+	 * @var boolean $event_details_display_nav
2771
+	 */
2772
+	public $event_details_display_nav;
2773
+
2774
+	/**
2775
+	 * @var boolean $event_details_nav_size
2776
+	 */
2777
+	public $event_details_nav_size;
2778
+
2779
+	/**
2780
+	 * @var string $event_details_control_type
2781
+	 */
2782
+	public $event_details_control_type;
2783
+
2784
+	/**
2785
+	 * @var string $event_details_map_align
2786
+	 */
2787
+	public $event_details_map_align;
2788
+
2789
+	/**
2790
+	 * @var int $event_list_map_width
2791
+	 */
2792
+	public $event_list_map_width;
2793
+
2794
+	/**
2795
+	 * @var int $event_list_map_height
2796
+	 */
2797
+	public $event_list_map_height;
2798
+
2799
+	/**
2800
+	 * @var int $event_list_map_zoom
2801
+	 */
2802
+	public $event_list_map_zoom;
2803
+
2804
+	/**
2805
+	 * @var boolean $event_list_display_nav
2806
+	 */
2807
+	public $event_list_display_nav;
2808
+
2809
+	/**
2810
+	 * @var boolean $event_list_nav_size
2811
+	 */
2812
+	public $event_list_nav_size;
2813
+
2814
+	/**
2815
+	 * @var string $event_list_control_type
2816
+	 */
2817
+	public $event_list_control_type;
2818
+
2819
+	/**
2820
+	 * @var string $event_list_map_align
2821
+	 */
2822
+	public $event_list_map_align;
2823
+
2824
+
2825
+
2826
+	/**
2827
+	 *    class constructor
2828
+	 *
2829
+	 * @access    public
2830
+	 */
2831
+	public function __construct()
2832
+	{
2833
+		// set default map settings
2834
+		$this->use_google_maps = true;
2835
+		$this->google_map_api_key = '';
2836
+		// for event details pages (reg page)
2837
+		$this->event_details_map_width = 585;            // ee_map_width_single
2838
+		$this->event_details_map_height = 362;            // ee_map_height_single
2839
+		$this->event_details_map_zoom = 14;            // ee_map_zoom_single
2840
+		$this->event_details_display_nav = true;            // ee_map_nav_display_single
2841
+		$this->event_details_nav_size = false;            // ee_map_nav_size_single
2842
+		$this->event_details_control_type = 'default';        // ee_map_type_control_single
2843
+		$this->event_details_map_align = 'center';            // ee_map_align_single
2844
+		// for event list pages
2845
+		$this->event_list_map_width = 300;            // ee_map_width
2846
+		$this->event_list_map_height = 185;        // ee_map_height
2847
+		$this->event_list_map_zoom = 12;            // ee_map_zoom
2848
+		$this->event_list_display_nav = false;        // ee_map_nav_display
2849
+		$this->event_list_nav_size = true;            // ee_map_nav_size
2850
+		$this->event_list_control_type = 'dropdown';        // ee_map_type_control
2851
+		$this->event_list_map_align = 'center';            // ee_map_align
2852
+	}
2853 2853
 
2854 2854
 }
2855 2855
 
@@ -2861,47 +2861,47 @@  discard block
 block discarded – undo
2861 2861
 class EE_Events_Archive_Config extends EE_Config_Base
2862 2862
 {
2863 2863
 
2864
-    public $display_status_banner;
2864
+	public $display_status_banner;
2865 2865
 
2866
-    public $display_description;
2866
+	public $display_description;
2867 2867
 
2868
-    public $display_ticket_selector;
2868
+	public $display_ticket_selector;
2869 2869
 
2870
-    public $display_datetimes;
2870
+	public $display_datetimes;
2871 2871
 
2872
-    public $display_venue;
2872
+	public $display_venue;
2873 2873
 
2874
-    public $display_expired_events;
2874
+	public $display_expired_events;
2875 2875
 
2876
-    public $use_sortable_display_order;
2876
+	public $use_sortable_display_order;
2877 2877
 
2878
-    public $display_order_tickets;
2878
+	public $display_order_tickets;
2879 2879
 
2880
-    public $display_order_datetimes;
2880
+	public $display_order_datetimes;
2881 2881
 
2882
-    public $display_order_event;
2882
+	public $display_order_event;
2883 2883
 
2884
-    public $display_order_venue;
2884
+	public $display_order_venue;
2885 2885
 
2886 2886
 
2887 2887
 
2888
-    /**
2889
-     *    class constructor
2890
-     */
2891
-    public function __construct()
2892
-    {
2893
-        $this->display_status_banner = 0;
2894
-        $this->display_description = 1;
2895
-        $this->display_ticket_selector = 0;
2896
-        $this->display_datetimes = 1;
2897
-        $this->display_venue = 0;
2898
-        $this->display_expired_events = 0;
2899
-        $this->use_sortable_display_order = false;
2900
-        $this->display_order_tickets = 100;
2901
-        $this->display_order_datetimes = 110;
2902
-        $this->display_order_event = 120;
2903
-        $this->display_order_venue = 130;
2904
-    }
2888
+	/**
2889
+	 *    class constructor
2890
+	 */
2891
+	public function __construct()
2892
+	{
2893
+		$this->display_status_banner = 0;
2894
+		$this->display_description = 1;
2895
+		$this->display_ticket_selector = 0;
2896
+		$this->display_datetimes = 1;
2897
+		$this->display_venue = 0;
2898
+		$this->display_expired_events = 0;
2899
+		$this->use_sortable_display_order = false;
2900
+		$this->display_order_tickets = 100;
2901
+		$this->display_order_datetimes = 110;
2902
+		$this->display_order_event = 120;
2903
+		$this->display_order_venue = 130;
2904
+	}
2905 2905
 }
2906 2906
 
2907 2907
 
@@ -2912,35 +2912,35 @@  discard block
 block discarded – undo
2912 2912
 class EE_Event_Single_Config extends EE_Config_Base
2913 2913
 {
2914 2914
 
2915
-    public $display_status_banner_single;
2915
+	public $display_status_banner_single;
2916 2916
 
2917
-    public $display_venue;
2917
+	public $display_venue;
2918 2918
 
2919
-    public $use_sortable_display_order;
2919
+	public $use_sortable_display_order;
2920 2920
 
2921
-    public $display_order_tickets;
2921
+	public $display_order_tickets;
2922 2922
 
2923
-    public $display_order_datetimes;
2923
+	public $display_order_datetimes;
2924 2924
 
2925
-    public $display_order_event;
2925
+	public $display_order_event;
2926 2926
 
2927
-    public $display_order_venue;
2927
+	public $display_order_venue;
2928 2928
 
2929 2929
 
2930 2930
 
2931
-    /**
2932
-     *    class constructor
2933
-     */
2934
-    public function __construct()
2935
-    {
2936
-        $this->display_status_banner_single = 0;
2937
-        $this->display_venue = 1;
2938
-        $this->use_sortable_display_order = false;
2939
-        $this->display_order_tickets = 100;
2940
-        $this->display_order_datetimes = 110;
2941
-        $this->display_order_event = 120;
2942
-        $this->display_order_venue = 130;
2943
-    }
2931
+	/**
2932
+	 *    class constructor
2933
+	 */
2934
+	public function __construct()
2935
+	{
2936
+		$this->display_status_banner_single = 0;
2937
+		$this->display_venue = 1;
2938
+		$this->use_sortable_display_order = false;
2939
+		$this->display_order_tickets = 100;
2940
+		$this->display_order_datetimes = 110;
2941
+		$this->display_order_event = 120;
2942
+		$this->display_order_venue = 130;
2943
+	}
2944 2944
 }
2945 2945
 
2946 2946
 
@@ -2951,152 +2951,152 @@  discard block
 block discarded – undo
2951 2951
 class EE_Ticket_Selector_Config extends EE_Config_Base
2952 2952
 {
2953 2953
 
2954
-    /**
2955
-     * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2956
-     */
2957
-    const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2958
-
2959
-    /**
2960
-     * constant to indicate that a datetime selector should only be shown for ticket selectors
2961
-     * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2962
-     */
2963
-    const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2964
-
2965
-    /**
2966
-     * @var boolean $show_ticket_sale_columns
2967
-     */
2968
-    public $show_ticket_sale_columns;
2969
-
2970
-    /**
2971
-     * @var boolean $show_ticket_details
2972
-     */
2973
-    public $show_ticket_details;
2974
-
2975
-    /**
2976
-     * @var boolean $show_expired_tickets
2977
-     */
2978
-    public $show_expired_tickets;
2979
-
2980
-    /**
2981
-     * whether or not to display a dropdown box populated with event datetimes
2982
-     * that toggles which tickets are displayed for a ticket selector.
2983
-     * uses one of the *_DATETIME_SELECTOR constants defined above
2984
-     *
2985
-     * @var string $show_datetime_selector
2986
-     */
2987
-    private $show_datetime_selector = 'no_datetime_selector';
2988
-
2989
-    /**
2990
-     * the number of datetimes an event has to have before conditionally displaying a datetime selector
2991
-     *
2992
-     * @var int $datetime_selector_threshold
2993
-     */
2994
-    private $datetime_selector_threshold = 3;
2995
-
2996
-
2997
-
2998
-    /**
2999
-     *    class constructor
3000
-     */
3001
-    public function __construct()
3002
-    {
3003
-        $this->show_ticket_sale_columns = true;
3004
-        $this->show_ticket_details = true;
3005
-        $this->show_expired_tickets = true;
3006
-        $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3007
-        $this->datetime_selector_threshold = 3;
3008
-    }
3009
-
3010
-
3011
-
3012
-    /**
3013
-     * returns true if a datetime selector should be displayed
3014
-     *
3015
-     * @param array $datetimes
3016
-     * @return bool
3017
-     */
3018
-    public function showDatetimeSelector(array $datetimes)
3019
-    {
3020
-        // if the settings are NOT: don't show OR below threshold, THEN active = true
3021
-        return ! (
3022
-            $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3023
-            || (
3024
-                $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3025
-                && count($datetimes) < $this->getDatetimeSelectorThreshold()
3026
-            )
3027
-        );
3028
-    }
3029
-
3030
-
3031
-
3032
-    /**
3033
-     * @return string
3034
-     */
3035
-    public function getShowDatetimeSelector()
3036
-    {
3037
-        return $this->show_datetime_selector;
3038
-    }
3039
-
3040
-
3041
-
3042
-    /**
3043
-     * @param bool $keys_only
3044
-     * @return array
3045
-     */
3046
-    public function getShowDatetimeSelectorOptions($keys_only = true)
3047
-    {
3048
-        return $keys_only
3049
-            ? array(
3050
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3051
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3052
-            )
3053
-            : array(
3054
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3055
-                    'Do not show date & time filter', 'event_espresso'
3056
-                ),
3057
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3058
-                    'Maybe show date & time filter', 'event_espresso'
3059
-                ),
3060
-            );
3061
-    }
3062
-
3063
-
3064
-
3065
-    /**
3066
-     * @param string $show_datetime_selector
3067
-     */
3068
-    public function setShowDatetimeSelector($show_datetime_selector)
3069
-    {
3070
-        $this->show_datetime_selector = in_array(
3071
-            $show_datetime_selector,
3072
-            $this->getShowDatetimeSelectorOptions(),
3073
-            true
3074
-        )
3075
-            ? $show_datetime_selector
3076
-            : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3077
-    }
3078
-
3079
-
3080
-
3081
-    /**
3082
-     * @return int
3083
-     */
3084
-    public function getDatetimeSelectorThreshold()
3085
-    {
3086
-        return $this->datetime_selector_threshold;
3087
-    }
3088
-
3089
-
3090
-
3091
-
3092
-    /**
3093
-     * @param int $datetime_selector_threshold
3094
-     */
3095
-    public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3096
-    {
3097
-        $datetime_selector_threshold = absint($datetime_selector_threshold);
3098
-        $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3099
-    }
2954
+	/**
2955
+	 * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2956
+	 */
2957
+	const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2958
+
2959
+	/**
2960
+	 * constant to indicate that a datetime selector should only be shown for ticket selectors
2961
+	 * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2962
+	 */
2963
+	const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2964
+
2965
+	/**
2966
+	 * @var boolean $show_ticket_sale_columns
2967
+	 */
2968
+	public $show_ticket_sale_columns;
2969
+
2970
+	/**
2971
+	 * @var boolean $show_ticket_details
2972
+	 */
2973
+	public $show_ticket_details;
2974
+
2975
+	/**
2976
+	 * @var boolean $show_expired_tickets
2977
+	 */
2978
+	public $show_expired_tickets;
2979
+
2980
+	/**
2981
+	 * whether or not to display a dropdown box populated with event datetimes
2982
+	 * that toggles which tickets are displayed for a ticket selector.
2983
+	 * uses one of the *_DATETIME_SELECTOR constants defined above
2984
+	 *
2985
+	 * @var string $show_datetime_selector
2986
+	 */
2987
+	private $show_datetime_selector = 'no_datetime_selector';
2988
+
2989
+	/**
2990
+	 * the number of datetimes an event has to have before conditionally displaying a datetime selector
2991
+	 *
2992
+	 * @var int $datetime_selector_threshold
2993
+	 */
2994
+	private $datetime_selector_threshold = 3;
2995
+
2996
+
2997
+
2998
+	/**
2999
+	 *    class constructor
3000
+	 */
3001
+	public function __construct()
3002
+	{
3003
+		$this->show_ticket_sale_columns = true;
3004
+		$this->show_ticket_details = true;
3005
+		$this->show_expired_tickets = true;
3006
+		$this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3007
+		$this->datetime_selector_threshold = 3;
3008
+	}
3009
+
3010
+
3011
+
3012
+	/**
3013
+	 * returns true if a datetime selector should be displayed
3014
+	 *
3015
+	 * @param array $datetimes
3016
+	 * @return bool
3017
+	 */
3018
+	public function showDatetimeSelector(array $datetimes)
3019
+	{
3020
+		// if the settings are NOT: don't show OR below threshold, THEN active = true
3021
+		return ! (
3022
+			$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3023
+			|| (
3024
+				$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3025
+				&& count($datetimes) < $this->getDatetimeSelectorThreshold()
3026
+			)
3027
+		);
3028
+	}
3029
+
3030
+
3031
+
3032
+	/**
3033
+	 * @return string
3034
+	 */
3035
+	public function getShowDatetimeSelector()
3036
+	{
3037
+		return $this->show_datetime_selector;
3038
+	}
3039
+
3040
+
3041
+
3042
+	/**
3043
+	 * @param bool $keys_only
3044
+	 * @return array
3045
+	 */
3046
+	public function getShowDatetimeSelectorOptions($keys_only = true)
3047
+	{
3048
+		return $keys_only
3049
+			? array(
3050
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3051
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3052
+			)
3053
+			: array(
3054
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3055
+					'Do not show date & time filter', 'event_espresso'
3056
+				),
3057
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3058
+					'Maybe show date & time filter', 'event_espresso'
3059
+				),
3060
+			);
3061
+	}
3062
+
3063
+
3064
+
3065
+	/**
3066
+	 * @param string $show_datetime_selector
3067
+	 */
3068
+	public function setShowDatetimeSelector($show_datetime_selector)
3069
+	{
3070
+		$this->show_datetime_selector = in_array(
3071
+			$show_datetime_selector,
3072
+			$this->getShowDatetimeSelectorOptions(),
3073
+			true
3074
+		)
3075
+			? $show_datetime_selector
3076
+			: \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3077
+	}
3078
+
3079
+
3080
+
3081
+	/**
3082
+	 * @return int
3083
+	 */
3084
+	public function getDatetimeSelectorThreshold()
3085
+	{
3086
+		return $this->datetime_selector_threshold;
3087
+	}
3088
+
3089
+
3090
+
3091
+
3092
+	/**
3093
+	 * @param int $datetime_selector_threshold
3094
+	 */
3095
+	public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3096
+	{
3097
+		$datetime_selector_threshold = absint($datetime_selector_threshold);
3098
+		$this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3099
+	}
3100 3100
 
3101 3101
 
3102 3102
 
@@ -3114,85 +3114,85 @@  discard block
 block discarded – undo
3114 3114
 class EE_Environment_Config extends EE_Config_Base
3115 3115
 {
3116 3116
 
3117
-    /**
3118
-     * Hold any php environment variables that we want to track.
3119
-     *
3120
-     * @var stdClass;
3121
-     */
3122
-    public $php;
3123
-
3124
-
3125
-
3126
-    /**
3127
-     *    constructor
3128
-     */
3129
-    public function __construct()
3130
-    {
3131
-        $this->php = new stdClass();
3132
-        $this->_set_php_values();
3133
-    }
3134
-
3135
-
3136
-
3137
-    /**
3138
-     * This sets the php environment variables.
3139
-     *
3140
-     * @since 4.4.0
3141
-     * @return void
3142
-     */
3143
-    protected function _set_php_values()
3144
-    {
3145
-        $this->php->max_input_vars = ini_get('max_input_vars');
3146
-        $this->php->version = phpversion();
3147
-    }
3148
-
3149
-
3150
-
3151
-    /**
3152
-     * helper method for determining whether input_count is
3153
-     * reaching the potential maximum the server can handle
3154
-     * according to max_input_vars
3155
-     *
3156
-     * @param int   $input_count the count of input vars.
3157
-     * @return array {
3158
-     *                           An array that represents whether available space and if no available space the error
3159
-     *                           message.
3160
-     * @type bool   $has_space   whether more inputs can be added.
3161
-     * @type string $msg         Any message to be displayed.
3162
-     *                           }
3163
-     */
3164
-    public function max_input_vars_limit_check($input_count = 0)
3165
-    {
3166
-        if (! empty($this->php->max_input_vars)
3167
-            && ($input_count >= $this->php->max_input_vars)
3168
-            && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9)
3169
-        ) {
3170
-            return sprintf(
3171
-                __(
3172
-                    'The maximum number of inputs on this page has been exceeded.  You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.',
3173
-                    'event_espresso'
3174
-                ),
3175
-                '<br>',
3176
-                $input_count,
3177
-                $this->php->max_input_vars
3178
-            );
3179
-        } else {
3180
-            return '';
3181
-        }
3182
-    }
3183
-
3184
-
3185
-
3186
-    /**
3187
-     * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3188
-     *
3189
-     * @since 4.4.1
3190
-     * @return void
3191
-     */
3192
-    public function recheck_values()
3193
-    {
3194
-        $this->_set_php_values();
3195
-    }
3117
+	/**
3118
+	 * Hold any php environment variables that we want to track.
3119
+	 *
3120
+	 * @var stdClass;
3121
+	 */
3122
+	public $php;
3123
+
3124
+
3125
+
3126
+	/**
3127
+	 *    constructor
3128
+	 */
3129
+	public function __construct()
3130
+	{
3131
+		$this->php = new stdClass();
3132
+		$this->_set_php_values();
3133
+	}
3134
+
3135
+
3136
+
3137
+	/**
3138
+	 * This sets the php environment variables.
3139
+	 *
3140
+	 * @since 4.4.0
3141
+	 * @return void
3142
+	 */
3143
+	protected function _set_php_values()
3144
+	{
3145
+		$this->php->max_input_vars = ini_get('max_input_vars');
3146
+		$this->php->version = phpversion();
3147
+	}
3148
+
3149
+
3150
+
3151
+	/**
3152
+	 * helper method for determining whether input_count is
3153
+	 * reaching the potential maximum the server can handle
3154
+	 * according to max_input_vars
3155
+	 *
3156
+	 * @param int   $input_count the count of input vars.
3157
+	 * @return array {
3158
+	 *                           An array that represents whether available space and if no available space the error
3159
+	 *                           message.
3160
+	 * @type bool   $has_space   whether more inputs can be added.
3161
+	 * @type string $msg         Any message to be displayed.
3162
+	 *                           }
3163
+	 */
3164
+	public function max_input_vars_limit_check($input_count = 0)
3165
+	{
3166
+		if (! empty($this->php->max_input_vars)
3167
+			&& ($input_count >= $this->php->max_input_vars)
3168
+			&& (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9)
3169
+		) {
3170
+			return sprintf(
3171
+				__(
3172
+					'The maximum number of inputs on this page has been exceeded.  You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.',
3173
+					'event_espresso'
3174
+				),
3175
+				'<br>',
3176
+				$input_count,
3177
+				$this->php->max_input_vars
3178
+			);
3179
+		} else {
3180
+			return '';
3181
+		}
3182
+	}
3183
+
3184
+
3185
+
3186
+	/**
3187
+	 * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3188
+	 *
3189
+	 * @since 4.4.1
3190
+	 * @return void
3191
+	 */
3192
+	public function recheck_values()
3193
+	{
3194
+		$this->_set_php_values();
3195
+	}
3196 3196
 
3197 3197
 
3198 3198
 
@@ -3210,22 +3210,22 @@  discard block
 block discarded – undo
3210 3210
 class EE_Tax_Config extends EE_Config_Base
3211 3211
 {
3212 3212
 
3213
-    /*
3213
+	/*
3214 3214
      * flag to indicate whether or not to display ticket prices with the taxes included
3215 3215
      *
3216 3216
      * @var boolean $prices_displayed_including_taxes
3217 3217
      */
3218
-    public $prices_displayed_including_taxes;
3218
+	public $prices_displayed_including_taxes;
3219 3219
 
3220 3220
 
3221 3221
 
3222
-    /**
3223
-     *    class constructor
3224
-     */
3225
-    public function __construct()
3226
-    {
3227
-        $this->prices_displayed_including_taxes = true;
3228
-    }
3222
+	/**
3223
+	 *    class constructor
3224
+	 */
3225
+	public function __construct()
3226
+	{
3227
+		$this->prices_displayed_including_taxes = true;
3228
+	}
3229 3229
 }
3230 3230
 
3231 3231
 
@@ -3240,17 +3240,17 @@  discard block
 block discarded – undo
3240 3240
 class EE_Messages_Config extends EE_Config_Base
3241 3241
 {
3242 3242
 
3243
-    /**
3244
-     * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3245
-     * A value of 0 represents never deleting.  Default is 0.
3246
-     *
3247
-     * @var integer
3248
-     */
3249
-    public $delete_threshold;
3250
-
3251
-    public function __construct() {
3252
-        $this->delete_threshold = 0;
3253
-    }
3243
+	/**
3244
+	 * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3245
+	 * A value of 0 represents never deleting.  Default is 0.
3246
+	 *
3247
+	 * @var integer
3248
+	 */
3249
+	public $delete_threshold;
3250
+
3251
+	public function __construct() {
3252
+		$this->delete_threshold = 0;
3253
+	}
3254 3254
 }
3255 3255
 
3256 3256
 
@@ -3262,34 +3262,34 @@  discard block
 block discarded – undo
3262 3262
 class EE_Gateway_Config extends EE_Config_Base
3263 3263
 {
3264 3264
 
3265
-    /**
3266
-     * Array with keys that are payment gateways slugs, and values are arrays
3267
-     * with any config info the gateway wants to store
3268
-     *
3269
-     * @var array
3270
-     */
3271
-    public $payment_settings;
3272
-
3273
-    /**
3274
-     * Where keys are gateway slugs, and values are booleans indicating whether or not
3275
-     * the gateway is stored in the uploads directory
3276
-     *
3277
-     * @var array
3278
-     */
3279
-    public $active_gateways;
3280
-
3281
-
3282
-
3283
-    /**
3284
-     *    class constructor
3285
-     *
3286
-     * @deprecated
3287
-     */
3288
-    public function __construct()
3289
-    {
3290
-        $this->payment_settings = array();
3291
-        $this->active_gateways = array('Invoice' => false);
3292
-    }
3265
+	/**
3266
+	 * Array with keys that are payment gateways slugs, and values are arrays
3267
+	 * with any config info the gateway wants to store
3268
+	 *
3269
+	 * @var array
3270
+	 */
3271
+	public $payment_settings;
3272
+
3273
+	/**
3274
+	 * Where keys are gateway slugs, and values are booleans indicating whether or not
3275
+	 * the gateway is stored in the uploads directory
3276
+	 *
3277
+	 * @var array
3278
+	 */
3279
+	public $active_gateways;
3280
+
3281
+
3282
+
3283
+	/**
3284
+	 *    class constructor
3285
+	 *
3286
+	 * @deprecated
3287
+	 */
3288
+	public function __construct()
3289
+	{
3290
+		$this->payment_settings = array();
3291
+		$this->active_gateways = array('Invoice' => false);
3292
+	}
3293 3293
 }
3294 3294
 
3295 3295
 // End of file EE_Config.core.php
Please login to merge, or discard this patch.
core/EE_System.core.php 1 patch
Indentation   +1265 added lines, -1265 removed lines patch added patch discarded remove patch
@@ -32,1271 +32,1271 @@
 block discarded – undo
32 32
 {
33 33
 
34 34
 
35
-    /**
36
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
37
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
38
-     */
39
-    const req_type_normal = 0;
40
-
41
-    /**
42
-     * Indicates this is a brand new installation of EE so we should install
43
-     * tables and default data etc
44
-     */
45
-    const req_type_new_activation = 1;
46
-
47
-    /**
48
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
49
-     * and we just exited maintenance mode). We MUST check the database is setup properly
50
-     * and that default data is setup too
51
-     */
52
-    const req_type_reactivation = 2;
53
-
54
-    /**
55
-     * indicates that EE has been upgraded since its previous request.
56
-     * We may have data migration scripts to call and will want to trigger maintenance mode
57
-     */
58
-    const req_type_upgrade = 3;
59
-
60
-    /**
61
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
62
-     */
63
-    const req_type_downgrade = 4;
64
-
65
-    /**
66
-     * @deprecated since version 4.6.0.dev.006
67
-     * Now whenever a new_activation is detected the request type is still just
68
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
69
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
70
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
71
-     * (Specifically, when the migration manager indicates migrations are finished
72
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
73
-     */
74
-    const req_type_activation_but_not_installed = 5;
75
-
76
-    /**
77
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
78
-     */
79
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
80
-
81
-
82
-    /**
83
-     * @var EE_System $_instance
84
-     */
85
-    private static $_instance;
86
-
87
-    /**
88
-     * @var EE_Registry $registry
89
-     */
90
-    private $registry;
91
-
92
-    /**
93
-     * @var LoaderInterface $loader
94
-     */
95
-    private $loader;
96
-
97
-    /**
98
-     * @var EE_Capabilities $capabilities
99
-     */
100
-    private $capabilities;
101
-
102
-    /**
103
-     * @var RequestInterface $request
104
-     */
105
-    private $request;
106
-
107
-    /**
108
-     * @var EE_Maintenance_Mode $maintenance_mode
109
-     */
110
-    private $maintenance_mode;
111
-
112
-    /**
113
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
114
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
115
-     *
116
-     * @var int $_req_type
117
-     */
118
-    private $_req_type;
119
-
120
-    /**
121
-     * Whether or not there was a non-micro version change in EE core version during this request
122
-     *
123
-     * @var boolean $_major_version_change
124
-     */
125
-    private $_major_version_change = false;
126
-
127
-    /**
128
-     * A Context DTO dedicated solely to identifying the current request type.
129
-     *
130
-     * @var RequestTypeContextCheckerInterface $request_type
131
-     */
132
-    private $request_type;
133
-
134
-
135
-
136
-    /**
137
-     * @singleton method used to instantiate class object
138
-     * @param EE_Registry|null         $registry
139
-     * @param LoaderInterface|null     $loader
140
-     * @param RequestInterface|null          $request
141
-     * @param EE_Maintenance_Mode|null $maintenance_mode
142
-     * @return EE_System
143
-     */
144
-    public static function instance(
145
-        EE_Registry $registry = null,
146
-        LoaderInterface $loader = null,
147
-        RequestInterface $request = null,
148
-        EE_Maintenance_Mode $maintenance_mode = null
149
-    ) {
150
-        // check if class object is instantiated
151
-        if (! self::$_instance instanceof EE_System) {
152
-            self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
153
-        }
154
-        return self::$_instance;
155
-    }
156
-
157
-
158
-
159
-    /**
160
-     * resets the instance and returns it
161
-     *
162
-     * @return EE_System
163
-     */
164
-    public static function reset()
165
-    {
166
-        self::$_instance->_req_type = null;
167
-        //make sure none of the old hooks are left hanging around
168
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
169
-        //we need to reset the migration manager in order for it to detect DMSs properly
170
-        EE_Data_Migration_Manager::reset();
171
-        self::instance()->detect_activations_or_upgrades();
172
-        self::instance()->perform_activations_upgrades_and_migrations();
173
-        return self::instance();
174
-    }
175
-
176
-
177
-
178
-    /**
179
-     * sets hooks for running rest of system
180
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
181
-     * starting EE Addons from any other point may lead to problems
182
-     *
183
-     * @param EE_Registry         $registry
184
-     * @param LoaderInterface     $loader
185
-     * @param RequestInterface          $request
186
-     * @param EE_Maintenance_Mode $maintenance_mode
187
-     */
188
-    private function __construct(
189
-        EE_Registry $registry,
190
-        LoaderInterface $loader,
191
-        RequestInterface $request,
192
-        EE_Maintenance_Mode $maintenance_mode
193
-    ) {
194
-        $this->registry         = $registry;
195
-        $this->loader           = $loader;
196
-        $this->request          = $request;
197
-        $this->maintenance_mode = $maintenance_mode;
198
-        do_action('AHEE__EE_System__construct__begin', $this);
199
-        add_action(
200
-            'AHEE__EE_Bootstrap__load_espresso_addons',
201
-            array($this, 'loadCapabilities'),
202
-            5
203
-        );
204
-        add_action(
205
-            'AHEE__EE_Bootstrap__load_espresso_addons',
206
-            array($this, 'loadCommandBus'),
207
-            7
208
-        );
209
-        add_action(
210
-            'AHEE__EE_Bootstrap__load_espresso_addons',
211
-            array($this, 'loadPluginApi'),
212
-            9
213
-        );
214
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
215
-        add_action(
216
-            'AHEE__EE_Bootstrap__load_espresso_addons',
217
-            array($this, 'load_espresso_addons')
218
-        );
219
-        // when an ee addon is activated, we want to call the core hook(s) again
220
-        // because the newly-activated addon didn't get a chance to run at all
221
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
222
-        // detect whether install or upgrade
223
-        add_action(
224
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
225
-            array($this, 'detect_activations_or_upgrades'),
226
-            3
227
-        );
228
-        // load EE_Config, EE_Textdomain, etc
229
-        add_action(
230
-            'AHEE__EE_Bootstrap__load_core_configuration',
231
-            array($this, 'load_core_configuration'),
232
-            5
233
-        );
234
-        // load EE_Config, EE_Textdomain, etc
235
-        add_action(
236
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
237
-            array($this, 'register_shortcodes_modules_and_widgets'),
238
-            7
239
-        );
240
-        // you wanna get going? I wanna get going... let's get going!
241
-        add_action(
242
-            'AHEE__EE_Bootstrap__brew_espresso',
243
-            array($this, 'brew_espresso'),
244
-            9
245
-        );
246
-        //other housekeeping
247
-        //exclude EE critical pages from wp_list_pages
248
-        add_filter(
249
-            'wp_list_pages_excludes',
250
-            array($this, 'remove_pages_from_wp_list_pages'),
251
-            10
252
-        );
253
-        // ALL EE Addons should use the following hook point to attach their initial setup too
254
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
255
-        do_action('AHEE__EE_System__construct__complete', $this);
256
-    }
257
-
258
-
259
-    /**
260
-     * load and setup EE_Capabilities
261
-     *
262
-     * @return void
263
-     * @throws EE_Error
264
-     */
265
-    public function loadCapabilities()
266
-    {
267
-        $this->capabilities = $this->loader->getShared('EE_Capabilities');
268
-        add_action(
269
-            'AHEE__EE_Capabilities__init_caps__before_initialization',
270
-            function ()
271
-            {
272
-                LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
273
-            }
274
-        );
275
-    }
276
-
277
-
278
-
279
-    /**
280
-     * create and cache the CommandBus, and also add middleware
281
-     * The CapChecker middleware requires the use of EE_Capabilities
282
-     * which is why we need to load the CommandBus after Caps are set up
283
-     *
284
-     * @return void
285
-     * @throws EE_Error
286
-     */
287
-    public function loadCommandBus()
288
-    {
289
-        $this->loader->getShared(
290
-            'CommandBusInterface',
291
-            array(
292
-                null,
293
-                apply_filters(
294
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
295
-                    array(
296
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
297
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
298
-                    )
299
-                ),
300
-            )
301
-        );
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * @return void
308
-     * @throws EE_Error
309
-     */
310
-    public function loadPluginApi()
311
-    {
312
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
313
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
314
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
315
-        $this->loader->getShared('EE_Request_Handler');
316
-    }
317
-
318
-
319
-    /**
320
-     * @param string $addon_name
321
-     * @param string $version_constant
322
-     * @param string $min_version_required
323
-     * @param string $load_callback
324
-     * @param string $plugin_file_constant
325
-     * @return void
326
-     */
327
-    private function deactivateIncompatibleAddon(
328
-        $addon_name,
329
-        $version_constant,
330
-        $min_version_required,
331
-        $load_callback,
332
-        $plugin_file_constant
333
-    ) {
334
-        if (! defined($version_constant)) {
335
-            return;
336
-        }
337
-        $addon_version = constant($version_constant);
338
-        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
339
-            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
340
-            if (! function_exists('deactivate_plugins')) {
341
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
342
-            }
343
-            deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
344
-            unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
345
-            EE_Error::add_error(
346
-                sprintf(
347
-                    esc_html__(
348
-                        'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
349
-                        'event_espresso'
350
-                    ),
351
-                    $addon_name,
352
-                    $min_version_required
353
-                ),
354
-                __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
355
-            );
356
-            EE_Error::get_notices(false, true);
357
-        }
358
-    }
359
-
360
-
361
-    /**
362
-     * load_espresso_addons
363
-     * allow addons to load first so that they can set hooks for running DMS's, etc
364
-     * this is hooked into both:
365
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
366
-     *        which runs during the WP 'plugins_loaded' action at priority 5
367
-     *    and the WP 'activate_plugin' hook point
368
-     *
369
-     * @access public
370
-     * @return void
371
-     */
372
-    public function load_espresso_addons()
373
-    {
374
-        $this->deactivateIncompatibleAddon(
375
-            'Wait Lists',
376
-            'EE_WAIT_LISTS_VERSION',
377
-            '1.0.0.beta.074',
378
-            'load_espresso_wait_lists',
379
-            'EE_WAIT_LISTS_PLUGIN_FILE'
380
-        );
381
-        $this->deactivateIncompatibleAddon(
382
-            'Automated Upcoming Event Notifications',
383
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
384
-            '1.0.0.beta.091',
385
-            'load_espresso_automated_upcoming_event_notification',
386
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
387
-        );
388
-        do_action('AHEE__EE_System__load_espresso_addons');
389
-        //if the WP API basic auth plugin isn't already loaded, load it now.
390
-        //We want it for mobile apps. Just include the entire plugin
391
-        //also, don't load the basic auth when a plugin is getting activated, because
392
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
393
-        //and causes a fatal error
394
-        if (
395
-            $this->request->getRequestParam('activate') !== 'true'
396
-            && ! function_exists('json_basic_auth_handler')
397
-            && ! function_exists('json_basic_auth_error')
398
-            && ! in_array(
399
-                $this->request->getRequestParam('action'),
400
-                array('activate', 'activate-selected'),
401
-                true
402
-            )
403
-        ) {
404
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
405
-        }
406
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
407
-    }
408
-
409
-
410
-
411
-    /**
412
-     * detect_activations_or_upgrades
413
-     * Checks for activation or upgrade of core first;
414
-     * then also checks if any registered addons have been activated or upgraded
415
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
416
-     * which runs during the WP 'plugins_loaded' action at priority 3
417
-     *
418
-     * @access public
419
-     * @return void
420
-     */
421
-    public function detect_activations_or_upgrades()
422
-    {
423
-        //first off: let's make sure to handle core
424
-        $this->detect_if_activation_or_upgrade();
425
-        foreach ($this->registry->addons as $addon) {
426
-            if ($addon instanceof EE_Addon) {
427
-                //detect teh request type for that addon
428
-                $addon->detect_activation_or_upgrade();
429
-            }
430
-        }
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     * detect_if_activation_or_upgrade
437
-     * Takes care of detecting whether this is a brand new install or code upgrade,
438
-     * and either setting up the DB or setting up maintenance mode etc.
439
-     *
440
-     * @access public
441
-     * @return void
442
-     */
443
-    public function detect_if_activation_or_upgrade()
444
-    {
445
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
446
-        // check if db has been updated, or if its a brand-new installation
447
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
448
-        $request_type       = $this->detect_req_type($espresso_db_update);
449
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
450
-        switch ($request_type) {
451
-            case EE_System::req_type_new_activation:
452
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
453
-                $this->_handle_core_version_change($espresso_db_update);
454
-                break;
455
-            case EE_System::req_type_reactivation:
456
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
457
-                $this->_handle_core_version_change($espresso_db_update);
458
-                break;
459
-            case EE_System::req_type_upgrade:
460
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
461
-                //migrations may be required now that we've upgraded
462
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
463
-                $this->_handle_core_version_change($espresso_db_update);
464
-                //				echo "done upgrade";die;
465
-                break;
466
-            case EE_System::req_type_downgrade:
467
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
468
-                //its possible migrations are no longer required
469
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
470
-                $this->_handle_core_version_change($espresso_db_update);
471
-                break;
472
-            case EE_System::req_type_normal:
473
-            default:
474
-                break;
475
-        }
476
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
477
-    }
478
-
479
-
480
-
481
-    /**
482
-     * Updates the list of installed versions and sets hooks for
483
-     * initializing the database later during the request
484
-     *
485
-     * @param array $espresso_db_update
486
-     */
487
-    private function _handle_core_version_change($espresso_db_update)
488
-    {
489
-        $this->update_list_of_installed_versions($espresso_db_update);
490
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
491
-        add_action(
492
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
493
-            array($this, 'initialize_db_if_no_migrations_required')
494
-        );
495
-    }
496
-
497
-
498
-
499
-    /**
500
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
501
-     * information about what versions of EE have been installed and activated,
502
-     * NOT necessarily the state of the database
503
-     *
504
-     * @param mixed $espresso_db_update           the value of the WordPress option.
505
-     *                                            If not supplied, fetches it from the options table
506
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
507
-     */
508
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
509
-    {
510
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
511
-        if (! $espresso_db_update) {
512
-            $espresso_db_update = get_option('espresso_db_update');
513
-        }
514
-        // check that option is an array
515
-        if (! is_array($espresso_db_update)) {
516
-            // if option is FALSE, then it never existed
517
-            if ($espresso_db_update === false) {
518
-                // make $espresso_db_update an array and save option with autoload OFF
519
-                $espresso_db_update = array();
520
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
521
-            } else {
522
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
523
-                $espresso_db_update = array($espresso_db_update => array());
524
-                update_option('espresso_db_update', $espresso_db_update);
525
-            }
526
-        } else {
527
-            $corrected_db_update = array();
528
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
529
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
530
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
531
-                    //the key is an int, and the value IS NOT an array
532
-                    //so it must be numerically-indexed, where values are versions installed...
533
-                    //fix it!
534
-                    $version_string                         = $should_be_array;
535
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
536
-                } else {
537
-                    //ok it checks out
538
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
539
-                }
540
-            }
541
-            $espresso_db_update = $corrected_db_update;
542
-            update_option('espresso_db_update', $espresso_db_update);
543
-        }
544
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
545
-        return $espresso_db_update;
546
-    }
547
-
548
-
549
-
550
-    /**
551
-     * Does the traditional work of setting up the plugin's database and adding default data.
552
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
553
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
554
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
555
-     * so that it will be done when migrations are finished
556
-     *
557
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
558
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
559
-     *                                       This is a resource-intensive job
560
-     *                                       so we prefer to only do it when necessary
561
-     * @return void
562
-     * @throws EE_Error
563
-     */
564
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
565
-    {
566
-        $request_type = $this->detect_req_type();
567
-        //only initialize system if we're not in maintenance mode.
568
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
569
-            update_option('ee_flush_rewrite_rules', true);
570
-            if ($verify_schema) {
571
-                EEH_Activation::initialize_db_and_folders();
572
-            }
573
-            EEH_Activation::initialize_db_content();
574
-            EEH_Activation::system_initialization();
575
-            if ($initialize_addons_too) {
576
-                $this->initialize_addons();
577
-            }
578
-        } else {
579
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
580
-        }
581
-        if ($request_type === EE_System::req_type_new_activation
582
-            || $request_type === EE_System::req_type_reactivation
583
-            || (
584
-                $request_type === EE_System::req_type_upgrade
585
-                && $this->is_major_version_change()
586
-            )
587
-        ) {
588
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
589
-        }
590
-    }
591
-
592
-
593
-
594
-    /**
595
-     * Initializes the db for all registered addons
596
-     *
597
-     * @throws EE_Error
598
-     */
599
-    public function initialize_addons()
600
-    {
601
-        //foreach registered addon, make sure its db is up-to-date too
602
-        foreach ($this->registry->addons as $addon) {
603
-            if ($addon instanceof EE_Addon) {
604
-                $addon->initialize_db_if_no_migrations_required();
605
-            }
606
-        }
607
-    }
608
-
609
-
610
-
611
-    /**
612
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
613
-     *
614
-     * @param    array  $version_history
615
-     * @param    string $current_version_to_add version to be added to the version history
616
-     * @return    boolean success as to whether or not this option was changed
617
-     */
618
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
619
-    {
620
-        if (! $version_history) {
621
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
622
-        }
623
-        if ($current_version_to_add === null) {
624
-            $current_version_to_add = espresso_version();
625
-        }
626
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
627
-        // re-save
628
-        return update_option('espresso_db_update', $version_history);
629
-    }
630
-
631
-
632
-
633
-    /**
634
-     * Detects if the current version indicated in the has existed in the list of
635
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
636
-     *
637
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
638
-     *                                  If not supplied, fetches it from the options table.
639
-     *                                  Also, caches its result so later parts of the code can also know whether
640
-     *                                  there's been an update or not. This way we can add the current version to
641
-     *                                  espresso_db_update, but still know if this is a new install or not
642
-     * @return int one of the constants on EE_System::req_type_
643
-     */
644
-    public function detect_req_type($espresso_db_update = null)
645
-    {
646
-        if ($this->_req_type === null) {
647
-            $espresso_db_update          = ! empty($espresso_db_update)
648
-                ? $espresso_db_update
649
-                : $this->fix_espresso_db_upgrade_option();
650
-            $this->_req_type             = EE_System::detect_req_type_given_activation_history(
651
-                $espresso_db_update,
652
-                'ee_espresso_activation', espresso_version()
653
-            );
654
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
655
-            $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
656
-        }
657
-        return $this->_req_type;
658
-    }
659
-
660
-
661
-
662
-    /**
663
-     * Returns whether or not there was a non-micro version change (ie, change in either
664
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
665
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
666
-     *
667
-     * @param $activation_history
668
-     * @return bool
669
-     */
670
-    private function _detect_major_version_change($activation_history)
671
-    {
672
-        $previous_version       = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
673
-        $previous_version_parts = explode('.', $previous_version);
674
-        $current_version_parts  = explode('.', espresso_version());
675
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
676
-               && ($previous_version_parts[0] !== $current_version_parts[0]
677
-                   || $previous_version_parts[1] !== $current_version_parts[1]
678
-               );
679
-    }
680
-
681
-
682
-
683
-    /**
684
-     * Returns true if either the major or minor version of EE changed during this request.
685
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
686
-     *
687
-     * @return bool
688
-     */
689
-    public function is_major_version_change()
690
-    {
691
-        return $this->_major_version_change;
692
-    }
693
-
694
-
695
-
696
-    /**
697
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
698
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
699
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
700
-     * just activated to (for core that will always be espresso_version())
701
-     *
702
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
703
-     *                                                 ee plugin. for core that's 'espresso_db_update'
704
-     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
705
-     *                                                 indicate that this plugin was just activated
706
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
707
-     *                                                 espresso_version())
708
-     * @return int one of the constants on EE_System::req_type_*
709
-     */
710
-    public static function detect_req_type_given_activation_history(
711
-        $activation_history_for_addon,
712
-        $activation_indicator_option_name,
713
-        $version_to_upgrade_to
714
-    ) {
715
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
716
-        if ($activation_history_for_addon) {
717
-            //it exists, so this isn't a completely new install
718
-            //check if this version already in that list of previously installed versions
719
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
720
-                //it a version we haven't seen before
721
-                if ($version_is_higher === 1) {
722
-                    $req_type = EE_System::req_type_upgrade;
723
-                } else {
724
-                    $req_type = EE_System::req_type_downgrade;
725
-                }
726
-                delete_option($activation_indicator_option_name);
727
-            } else {
728
-                // its not an update. maybe a reactivation?
729
-                if (get_option($activation_indicator_option_name, false)) {
730
-                    if ($version_is_higher === -1) {
731
-                        $req_type = EE_System::req_type_downgrade;
732
-                    } elseif ($version_is_higher === 0) {
733
-                        //we've seen this version before, but it's an activation. must be a reactivation
734
-                        $req_type = EE_System::req_type_reactivation;
735
-                    } else {//$version_is_higher === 1
736
-                        $req_type = EE_System::req_type_upgrade;
737
-                    }
738
-                    delete_option($activation_indicator_option_name);
739
-                } else {
740
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
741
-                    if ($version_is_higher === -1) {
742
-                        $req_type = EE_System::req_type_downgrade;
743
-                    } elseif ($version_is_higher === 0) {
744
-                        //we've seen this version before and it's not an activation. its normal request
745
-                        $req_type = EE_System::req_type_normal;
746
-                    } else {//$version_is_higher === 1
747
-                        $req_type = EE_System::req_type_upgrade;
748
-                    }
749
-                }
750
-            }
751
-        } else {
752
-            //brand new install
753
-            $req_type = EE_System::req_type_new_activation;
754
-            delete_option($activation_indicator_option_name);
755
-        }
756
-        return $req_type;
757
-    }
758
-
759
-
760
-
761
-    /**
762
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
763
-     * the $activation_history_for_addon
764
-     *
765
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
766
-     *                                             sometimes containing 'unknown-date'
767
-     * @param string $version_to_upgrade_to        (current version)
768
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
769
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
770
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
771
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
772
-     */
773
-    private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
774
-    {
775
-        //find the most recently-activated version
776
-        $most_recently_active_version =
777
-            EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
778
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
779
-    }
780
-
781
-
782
-
783
-    /**
784
-     * Gets the most recently active version listed in the activation history,
785
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
786
-     *
787
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
788
-     *                                   sometimes containing 'unknown-date'
789
-     * @return string
790
-     */
791
-    private static function _get_most_recently_active_version_from_activation_history($activation_history)
792
-    {
793
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
794
-        $most_recently_active_version            = '0.0.0.dev.000';
795
-        if (is_array($activation_history)) {
796
-            foreach ($activation_history as $version => $times_activated) {
797
-                //check there is a record of when this version was activated. Otherwise,
798
-                //mark it as unknown
799
-                if (! $times_activated) {
800
-                    $times_activated = array('unknown-date');
801
-                }
802
-                if (is_string($times_activated)) {
803
-                    $times_activated = array($times_activated);
804
-                }
805
-                foreach ($times_activated as $an_activation) {
806
-                    if ($an_activation !== 'unknown-date'
807
-                        && $an_activation
808
-                           > $most_recently_active_version_activation) {
809
-                        $most_recently_active_version            = $version;
810
-                        $most_recently_active_version_activation = $an_activation === 'unknown-date'
811
-                            ? '1970-01-01 00:00:00'
812
-                            : $an_activation;
813
-                    }
814
-                }
815
-            }
816
-        }
817
-        return $most_recently_active_version;
818
-    }
819
-
820
-
821
-
822
-    /**
823
-     * This redirects to the about EE page after activation
824
-     *
825
-     * @return void
826
-     */
827
-    public function redirect_to_about_ee()
828
-    {
829
-        $notices = EE_Error::get_notices(false);
830
-        //if current user is an admin and it's not an ajax or rest request
831
-        if (
832
-            ! isset($notices['errors'])
833
-            && $this->request->isAdmin()
834
-            && apply_filters(
835
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
836
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
837
-            )
838
-        ) {
839
-            $query_params = array('page' => 'espresso_about');
840
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
841
-                $query_params['new_activation'] = true;
842
-            }
843
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
844
-                $query_params['reactivation'] = true;
845
-            }
846
-            $url = add_query_arg($query_params, admin_url('admin.php'));
847
-            wp_safe_redirect($url);
848
-            exit();
849
-        }
850
-    }
851
-
852
-
853
-
854
-    /**
855
-     * load_core_configuration
856
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
857
-     * which runs during the WP 'plugins_loaded' action at priority 5
858
-     *
859
-     * @return void
860
-     * @throws ReflectionException
861
-     */
862
-    public function load_core_configuration()
863
-    {
864
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
865
-        $this->loader->getShared('EE_Load_Textdomain');
866
-        //load textdomain
867
-        EE_Load_Textdomain::load_textdomain();
868
-        // load and setup EE_Config and EE_Network_Config
869
-        $config = $this->loader->getShared('EE_Config');
870
-        $this->loader->getShared('EE_Network_Config');
871
-        // setup autoloaders
872
-        // enable logging?
873
-        if ($config->admin->use_full_logging) {
874
-            $this->loader->getShared('EE_Log');
875
-        }
876
-        // check for activation errors
877
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
878
-        if ($activation_errors) {
879
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
880
-            update_option('ee_plugin_activation_errors', false);
881
-        }
882
-        // get model names
883
-        $this->_parse_model_names();
884
-        //load caf stuff a chance to play during the activation process too.
885
-        $this->_maybe_brew_regular();
886
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
887
-    }
888
-
889
-
890
-
891
-    /**
892
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
893
-     *
894
-     * @return void
895
-     * @throws ReflectionException
896
-     */
897
-    private function _parse_model_names()
898
-    {
899
-        //get all the files in the EE_MODELS folder that end in .model.php
900
-        $models                 = glob(EE_MODELS . '*.model.php');
901
-        $model_names            = array();
902
-        $non_abstract_db_models = array();
903
-        foreach ($models as $model) {
904
-            // get model classname
905
-            $classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
906
-            $short_name      = str_replace('EEM_', '', $classname);
907
-            $reflectionClass = new ReflectionClass($classname);
908
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
909
-                $non_abstract_db_models[ $short_name ] = $classname;
910
-            }
911
-            $model_names[ $short_name ] = $classname;
912
-        }
913
-        $this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
914
-        $this->registry->non_abstract_db_models = apply_filters(
915
-            'FHEE__EE_System__parse_implemented_model_names',
916
-            $non_abstract_db_models
917
-        );
918
-    }
919
-
920
-
921
-    /**
922
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
923
-     * that need to be setup before our EE_System launches.
924
-     *
925
-     * @return void
926
-     * @throws DomainException
927
-     * @throws InvalidArgumentException
928
-     * @throws InvalidDataTypeException
929
-     * @throws InvalidInterfaceException
930
-     * @throws InvalidClassException
931
-     * @throws InvalidFilePathException
932
-     */
933
-    private function _maybe_brew_regular()
934
-    {
935
-        /** @var Domain $domain */
936
-        $domain = DomainFactory::getShared(
937
-            new FullyQualifiedName(
938
-                'EventEspresso\core\domain\Domain'
939
-            ),
940
-            array(
941
-                new FilePath(EVENT_ESPRESSO_MAIN_FILE),
942
-                Version::fromString(espresso_version())
943
-            )
944
-        );
945
-        if ($domain->isCaffeinated()) {
946
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
947
-        }
948
-    }
949
-
950
-
951
-
952
-    /**
953
-     * register_shortcodes_modules_and_widgets
954
-     * generate lists of shortcodes and modules, then verify paths and classes
955
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
956
-     * which runs during the WP 'plugins_loaded' action at priority 7
957
-     *
958
-     * @access public
959
-     * @return void
960
-     * @throws Exception
961
-     */
962
-    public function register_shortcodes_modules_and_widgets()
963
-    {
964
-        if ($this->request->isFrontend() || $this->request->isIframe()) {
965
-            try {
966
-                // load, register, and add shortcodes the new way
967
-                $this->loader->getShared(
968
-                    'EventEspresso\core\services\shortcodes\ShortcodesManager',
969
-                    array(
970
-                        // and the old way, but we'll put it under control of the new system
971
-                        EE_Config::getLegacyShortcodesManager(),
972
-                    )
973
-                );
974
-            } catch (Exception $exception) {
975
-                new ExceptionStackTraceDisplay($exception);
976
-            }
977
-        }
978
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
979
-        // check for addons using old hook point
980
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
981
-            $this->_incompatible_addon_error();
982
-        }
983
-    }
984
-
985
-
986
-
987
-    /**
988
-     * _incompatible_addon_error
989
-     *
990
-     * @access public
991
-     * @return void
992
-     */
993
-    private function _incompatible_addon_error()
994
-    {
995
-        // get array of classes hooking into here
996
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
997
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
998
-        );
999
-        if (! empty($class_names)) {
1000
-            $msg = __(
1001
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
1002
-                'event_espresso'
1003
-            );
1004
-            $msg .= '<ul>';
1005
-            foreach ($class_names as $class_name) {
1006
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
1007
-                        array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
1008
-                        $class_name
1009
-                    ) . '</b></li>';
1010
-            }
1011
-            $msg .= '</ul>';
1012
-            $msg .= __(
1013
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1014
-                'event_espresso'
1015
-            );
1016
-            // save list of incompatible addons to wp-options for later use
1017
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
1018
-            if (is_admin()) {
1019
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1020
-            }
1021
-        }
1022
-    }
1023
-
1024
-
1025
-
1026
-    /**
1027
-     * brew_espresso
1028
-     * begins the process of setting hooks for initializing EE in the correct order
1029
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1030
-     * which runs during the WP 'plugins_loaded' action at priority 9
1031
-     *
1032
-     * @return void
1033
-     */
1034
-    public function brew_espresso()
1035
-    {
1036
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
1037
-        // load some final core systems
1038
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
1039
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1040
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
1041
-        add_action('init', array($this, 'load_controllers'), 7);
1042
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
1043
-        add_action('init', array($this, 'initialize'), 10);
1044
-        add_action('init', array($this, 'initialize_last'), 100);
1045
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1046
-            // pew pew pew
1047
-            $this->loader->getShared('EventEspresso\core\services\licensing\LicenseService');
1048
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1049
-        }
1050
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
1051
-    }
1052
-
1053
-
1054
-
1055
-    /**
1056
-     *    set_hooks_for_core
1057
-     *
1058
-     * @access public
1059
-     * @return    void
1060
-     * @throws EE_Error
1061
-     */
1062
-    public function set_hooks_for_core()
1063
-    {
1064
-        $this->_deactivate_incompatible_addons();
1065
-        do_action('AHEE__EE_System__set_hooks_for_core');
1066
-        $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1067
-        //caps need to be initialized on every request so that capability maps are set.
1068
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1069
-        $this->registry->CAP->init_caps();
1070
-    }
1071
-
1072
-
1073
-
1074
-    /**
1075
-     * Using the information gathered in EE_System::_incompatible_addon_error,
1076
-     * deactivates any addons considered incompatible with the current version of EE
1077
-     */
1078
-    private function _deactivate_incompatible_addons()
1079
-    {
1080
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
1081
-        if (! empty($incompatible_addons)) {
1082
-            $active_plugins = get_option('active_plugins', array());
1083
-            foreach ($active_plugins as $active_plugin) {
1084
-                foreach ($incompatible_addons as $incompatible_addon) {
1085
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
1086
-                        unset($_GET['activate']);
1087
-                        espresso_deactivate_plugin($active_plugin);
1088
-                    }
1089
-                }
1090
-            }
1091
-        }
1092
-    }
1093
-
1094
-
1095
-
1096
-    /**
1097
-     *    perform_activations_upgrades_and_migrations
1098
-     *
1099
-     * @access public
1100
-     * @return    void
1101
-     */
1102
-    public function perform_activations_upgrades_and_migrations()
1103
-    {
1104
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1105
-    }
1106
-
1107
-
1108
-
1109
-    /**
1110
-     *    load_CPTs_and_session
1111
-     *
1112
-     * @access public
1113
-     * @return    void
1114
-     */
1115
-    public function load_CPTs_and_session()
1116
-    {
1117
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
1118
-        // register Custom Post Types
1119
-        $this->loader->getShared('EE_Register_CPTs');
1120
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1121
-    }
1122
-
1123
-
1124
-
1125
-    /**
1126
-     * load_controllers
1127
-     * this is the best place to load any additional controllers that needs access to EE core.
1128
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1129
-     * time
1130
-     *
1131
-     * @access public
1132
-     * @return void
1133
-     */
1134
-    public function load_controllers()
1135
-    {
1136
-        do_action('AHEE__EE_System__load_controllers__start');
1137
-        // let's get it started
1138
-        if (
1139
-            ! $this->maintenance_mode->level()
1140
-            && ($this->request->isFrontend() || $this->request->isFrontAjax())
1141
-        ) {
1142
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1143
-            $this->loader->getShared('EE_Front_Controller');
1144
-        } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1145
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1146
-            $this->loader->getShared('EE_Admin');
1147
-        }
1148
-        do_action('AHEE__EE_System__load_controllers__complete');
1149
-    }
1150
-
1151
-
1152
-
1153
-    /**
1154
-     * core_loaded_and_ready
1155
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1156
-     *
1157
-     * @access public
1158
-     * @return void
1159
-     */
1160
-    public function core_loaded_and_ready()
1161
-    {
1162
-        if (
1163
-            $this->request->isAdmin()
1164
-            || $this->request->isEeAjax()
1165
-            || $this->request->isFrontend()
1166
-        ) {
1167
-            $this->loader->getShared('EE_Session');
1168
-        }
1169
-        do_action('AHEE__EE_System__core_loaded_and_ready');
1170
-        // load_espresso_template_tags
1171
-        if (
1172
-            is_readable(EE_PUBLIC . 'template_tags.php')
1173
-            && ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isFeed())
1174
-        ) {
1175
-            require_once EE_PUBLIC . 'template_tags.php';
1176
-        }
1177
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1178
-        if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1179
-            $this->loader->getShared('EventEspresso\core\services\assets\Registry');
1180
-        }
1181
-    }
1182
-
1183
-
1184
-
1185
-    /**
1186
-     * initialize
1187
-     * this is the best place to begin initializing client code
1188
-     *
1189
-     * @access public
1190
-     * @return void
1191
-     */
1192
-    public function initialize()
1193
-    {
1194
-        do_action('AHEE__EE_System__initialize');
1195
-    }
1196
-
1197
-
1198
-
1199
-    /**
1200
-     * initialize_last
1201
-     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1202
-     * initialize has done so
1203
-     *
1204
-     * @access public
1205
-     * @return void
1206
-     */
1207
-    public function initialize_last()
1208
-    {
1209
-        do_action('AHEE__EE_System__initialize_last');
1210
-        add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1211
-    }
1212
-
1213
-
1214
-
1215
-    /**
1216
-     * @return void
1217
-     * @throws EE_Error
1218
-     */
1219
-    public function addEspressoToolbar()
1220
-    {
1221
-        $this->loader->getShared(
1222
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
1223
-            array($this->registry->CAP)
1224
-        );
1225
-    }
1226
-
1227
-
1228
-
1229
-    /**
1230
-     * do_not_cache
1231
-     * sets no cache headers and defines no cache constants for WP plugins
1232
-     *
1233
-     * @access public
1234
-     * @return void
1235
-     */
1236
-    public static function do_not_cache()
1237
-    {
1238
-        // set no cache constants
1239
-        if (! defined('DONOTCACHEPAGE')) {
1240
-            define('DONOTCACHEPAGE', true);
1241
-        }
1242
-        if (! defined('DONOTCACHCEOBJECT')) {
1243
-            define('DONOTCACHCEOBJECT', true);
1244
-        }
1245
-        if (! defined('DONOTCACHEDB')) {
1246
-            define('DONOTCACHEDB', true);
1247
-        }
1248
-        // add no cache headers
1249
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1250
-        // plus a little extra for nginx and Google Chrome
1251
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1252
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1253
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1254
-    }
1255
-
1256
-
1257
-
1258
-    /**
1259
-     *    extra_nocache_headers
1260
-     *
1261
-     * @access    public
1262
-     * @param $headers
1263
-     * @return    array
1264
-     */
1265
-    public static function extra_nocache_headers($headers)
1266
-    {
1267
-        // for NGINX
1268
-        $headers['X-Accel-Expires'] = 0;
1269
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1270
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1271
-        return $headers;
1272
-    }
1273
-
1274
-
1275
-
1276
-    /**
1277
-     *    nocache_headers
1278
-     *
1279
-     * @access    public
1280
-     * @return    void
1281
-     */
1282
-    public static function nocache_headers()
1283
-    {
1284
-        nocache_headers();
1285
-    }
1286
-
1287
-
1288
-
1289
-    /**
1290
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1291
-     * never returned with the function.
1292
-     *
1293
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1294
-     * @return array
1295
-     */
1296
-    public function remove_pages_from_wp_list_pages($exclude_array)
1297
-    {
1298
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1299
-    }
35
+	/**
36
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
37
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
38
+	 */
39
+	const req_type_normal = 0;
40
+
41
+	/**
42
+	 * Indicates this is a brand new installation of EE so we should install
43
+	 * tables and default data etc
44
+	 */
45
+	const req_type_new_activation = 1;
46
+
47
+	/**
48
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
49
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
50
+	 * and that default data is setup too
51
+	 */
52
+	const req_type_reactivation = 2;
53
+
54
+	/**
55
+	 * indicates that EE has been upgraded since its previous request.
56
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
57
+	 */
58
+	const req_type_upgrade = 3;
59
+
60
+	/**
61
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
62
+	 */
63
+	const req_type_downgrade = 4;
64
+
65
+	/**
66
+	 * @deprecated since version 4.6.0.dev.006
67
+	 * Now whenever a new_activation is detected the request type is still just
68
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
69
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
70
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
71
+	 * (Specifically, when the migration manager indicates migrations are finished
72
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
73
+	 */
74
+	const req_type_activation_but_not_installed = 5;
75
+
76
+	/**
77
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
78
+	 */
79
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
80
+
81
+
82
+	/**
83
+	 * @var EE_System $_instance
84
+	 */
85
+	private static $_instance;
86
+
87
+	/**
88
+	 * @var EE_Registry $registry
89
+	 */
90
+	private $registry;
91
+
92
+	/**
93
+	 * @var LoaderInterface $loader
94
+	 */
95
+	private $loader;
96
+
97
+	/**
98
+	 * @var EE_Capabilities $capabilities
99
+	 */
100
+	private $capabilities;
101
+
102
+	/**
103
+	 * @var RequestInterface $request
104
+	 */
105
+	private $request;
106
+
107
+	/**
108
+	 * @var EE_Maintenance_Mode $maintenance_mode
109
+	 */
110
+	private $maintenance_mode;
111
+
112
+	/**
113
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
114
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
115
+	 *
116
+	 * @var int $_req_type
117
+	 */
118
+	private $_req_type;
119
+
120
+	/**
121
+	 * Whether or not there was a non-micro version change in EE core version during this request
122
+	 *
123
+	 * @var boolean $_major_version_change
124
+	 */
125
+	private $_major_version_change = false;
126
+
127
+	/**
128
+	 * A Context DTO dedicated solely to identifying the current request type.
129
+	 *
130
+	 * @var RequestTypeContextCheckerInterface $request_type
131
+	 */
132
+	private $request_type;
133
+
134
+
135
+
136
+	/**
137
+	 * @singleton method used to instantiate class object
138
+	 * @param EE_Registry|null         $registry
139
+	 * @param LoaderInterface|null     $loader
140
+	 * @param RequestInterface|null          $request
141
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
142
+	 * @return EE_System
143
+	 */
144
+	public static function instance(
145
+		EE_Registry $registry = null,
146
+		LoaderInterface $loader = null,
147
+		RequestInterface $request = null,
148
+		EE_Maintenance_Mode $maintenance_mode = null
149
+	) {
150
+		// check if class object is instantiated
151
+		if (! self::$_instance instanceof EE_System) {
152
+			self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
153
+		}
154
+		return self::$_instance;
155
+	}
156
+
157
+
158
+
159
+	/**
160
+	 * resets the instance and returns it
161
+	 *
162
+	 * @return EE_System
163
+	 */
164
+	public static function reset()
165
+	{
166
+		self::$_instance->_req_type = null;
167
+		//make sure none of the old hooks are left hanging around
168
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
169
+		//we need to reset the migration manager in order for it to detect DMSs properly
170
+		EE_Data_Migration_Manager::reset();
171
+		self::instance()->detect_activations_or_upgrades();
172
+		self::instance()->perform_activations_upgrades_and_migrations();
173
+		return self::instance();
174
+	}
175
+
176
+
177
+
178
+	/**
179
+	 * sets hooks for running rest of system
180
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
181
+	 * starting EE Addons from any other point may lead to problems
182
+	 *
183
+	 * @param EE_Registry         $registry
184
+	 * @param LoaderInterface     $loader
185
+	 * @param RequestInterface          $request
186
+	 * @param EE_Maintenance_Mode $maintenance_mode
187
+	 */
188
+	private function __construct(
189
+		EE_Registry $registry,
190
+		LoaderInterface $loader,
191
+		RequestInterface $request,
192
+		EE_Maintenance_Mode $maintenance_mode
193
+	) {
194
+		$this->registry         = $registry;
195
+		$this->loader           = $loader;
196
+		$this->request          = $request;
197
+		$this->maintenance_mode = $maintenance_mode;
198
+		do_action('AHEE__EE_System__construct__begin', $this);
199
+		add_action(
200
+			'AHEE__EE_Bootstrap__load_espresso_addons',
201
+			array($this, 'loadCapabilities'),
202
+			5
203
+		);
204
+		add_action(
205
+			'AHEE__EE_Bootstrap__load_espresso_addons',
206
+			array($this, 'loadCommandBus'),
207
+			7
208
+		);
209
+		add_action(
210
+			'AHEE__EE_Bootstrap__load_espresso_addons',
211
+			array($this, 'loadPluginApi'),
212
+			9
213
+		);
214
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
215
+		add_action(
216
+			'AHEE__EE_Bootstrap__load_espresso_addons',
217
+			array($this, 'load_espresso_addons')
218
+		);
219
+		// when an ee addon is activated, we want to call the core hook(s) again
220
+		// because the newly-activated addon didn't get a chance to run at all
221
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
222
+		// detect whether install or upgrade
223
+		add_action(
224
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
225
+			array($this, 'detect_activations_or_upgrades'),
226
+			3
227
+		);
228
+		// load EE_Config, EE_Textdomain, etc
229
+		add_action(
230
+			'AHEE__EE_Bootstrap__load_core_configuration',
231
+			array($this, 'load_core_configuration'),
232
+			5
233
+		);
234
+		// load EE_Config, EE_Textdomain, etc
235
+		add_action(
236
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
237
+			array($this, 'register_shortcodes_modules_and_widgets'),
238
+			7
239
+		);
240
+		// you wanna get going? I wanna get going... let's get going!
241
+		add_action(
242
+			'AHEE__EE_Bootstrap__brew_espresso',
243
+			array($this, 'brew_espresso'),
244
+			9
245
+		);
246
+		//other housekeeping
247
+		//exclude EE critical pages from wp_list_pages
248
+		add_filter(
249
+			'wp_list_pages_excludes',
250
+			array($this, 'remove_pages_from_wp_list_pages'),
251
+			10
252
+		);
253
+		// ALL EE Addons should use the following hook point to attach their initial setup too
254
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
255
+		do_action('AHEE__EE_System__construct__complete', $this);
256
+	}
257
+
258
+
259
+	/**
260
+	 * load and setup EE_Capabilities
261
+	 *
262
+	 * @return void
263
+	 * @throws EE_Error
264
+	 */
265
+	public function loadCapabilities()
266
+	{
267
+		$this->capabilities = $this->loader->getShared('EE_Capabilities');
268
+		add_action(
269
+			'AHEE__EE_Capabilities__init_caps__before_initialization',
270
+			function ()
271
+			{
272
+				LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
273
+			}
274
+		);
275
+	}
276
+
277
+
278
+
279
+	/**
280
+	 * create and cache the CommandBus, and also add middleware
281
+	 * The CapChecker middleware requires the use of EE_Capabilities
282
+	 * which is why we need to load the CommandBus after Caps are set up
283
+	 *
284
+	 * @return void
285
+	 * @throws EE_Error
286
+	 */
287
+	public function loadCommandBus()
288
+	{
289
+		$this->loader->getShared(
290
+			'CommandBusInterface',
291
+			array(
292
+				null,
293
+				apply_filters(
294
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
295
+					array(
296
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
297
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
298
+					)
299
+				),
300
+			)
301
+		);
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * @return void
308
+	 * @throws EE_Error
309
+	 */
310
+	public function loadPluginApi()
311
+	{
312
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
313
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
314
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
315
+		$this->loader->getShared('EE_Request_Handler');
316
+	}
317
+
318
+
319
+	/**
320
+	 * @param string $addon_name
321
+	 * @param string $version_constant
322
+	 * @param string $min_version_required
323
+	 * @param string $load_callback
324
+	 * @param string $plugin_file_constant
325
+	 * @return void
326
+	 */
327
+	private function deactivateIncompatibleAddon(
328
+		$addon_name,
329
+		$version_constant,
330
+		$min_version_required,
331
+		$load_callback,
332
+		$plugin_file_constant
333
+	) {
334
+		if (! defined($version_constant)) {
335
+			return;
336
+		}
337
+		$addon_version = constant($version_constant);
338
+		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
339
+			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
340
+			if (! function_exists('deactivate_plugins')) {
341
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
342
+			}
343
+			deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
344
+			unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
345
+			EE_Error::add_error(
346
+				sprintf(
347
+					esc_html__(
348
+						'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
349
+						'event_espresso'
350
+					),
351
+					$addon_name,
352
+					$min_version_required
353
+				),
354
+				__FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
355
+			);
356
+			EE_Error::get_notices(false, true);
357
+		}
358
+	}
359
+
360
+
361
+	/**
362
+	 * load_espresso_addons
363
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
364
+	 * this is hooked into both:
365
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
366
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
367
+	 *    and the WP 'activate_plugin' hook point
368
+	 *
369
+	 * @access public
370
+	 * @return void
371
+	 */
372
+	public function load_espresso_addons()
373
+	{
374
+		$this->deactivateIncompatibleAddon(
375
+			'Wait Lists',
376
+			'EE_WAIT_LISTS_VERSION',
377
+			'1.0.0.beta.074',
378
+			'load_espresso_wait_lists',
379
+			'EE_WAIT_LISTS_PLUGIN_FILE'
380
+		);
381
+		$this->deactivateIncompatibleAddon(
382
+			'Automated Upcoming Event Notifications',
383
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
384
+			'1.0.0.beta.091',
385
+			'load_espresso_automated_upcoming_event_notification',
386
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
387
+		);
388
+		do_action('AHEE__EE_System__load_espresso_addons');
389
+		//if the WP API basic auth plugin isn't already loaded, load it now.
390
+		//We want it for mobile apps. Just include the entire plugin
391
+		//also, don't load the basic auth when a plugin is getting activated, because
392
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
393
+		//and causes a fatal error
394
+		if (
395
+			$this->request->getRequestParam('activate') !== 'true'
396
+			&& ! function_exists('json_basic_auth_handler')
397
+			&& ! function_exists('json_basic_auth_error')
398
+			&& ! in_array(
399
+				$this->request->getRequestParam('action'),
400
+				array('activate', 'activate-selected'),
401
+				true
402
+			)
403
+		) {
404
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
405
+		}
406
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
407
+	}
408
+
409
+
410
+
411
+	/**
412
+	 * detect_activations_or_upgrades
413
+	 * Checks for activation or upgrade of core first;
414
+	 * then also checks if any registered addons have been activated or upgraded
415
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
416
+	 * which runs during the WP 'plugins_loaded' action at priority 3
417
+	 *
418
+	 * @access public
419
+	 * @return void
420
+	 */
421
+	public function detect_activations_or_upgrades()
422
+	{
423
+		//first off: let's make sure to handle core
424
+		$this->detect_if_activation_or_upgrade();
425
+		foreach ($this->registry->addons as $addon) {
426
+			if ($addon instanceof EE_Addon) {
427
+				//detect teh request type for that addon
428
+				$addon->detect_activation_or_upgrade();
429
+			}
430
+		}
431
+	}
432
+
433
+
434
+
435
+	/**
436
+	 * detect_if_activation_or_upgrade
437
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
438
+	 * and either setting up the DB or setting up maintenance mode etc.
439
+	 *
440
+	 * @access public
441
+	 * @return void
442
+	 */
443
+	public function detect_if_activation_or_upgrade()
444
+	{
445
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
446
+		// check if db has been updated, or if its a brand-new installation
447
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
448
+		$request_type       = $this->detect_req_type($espresso_db_update);
449
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
450
+		switch ($request_type) {
451
+			case EE_System::req_type_new_activation:
452
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
453
+				$this->_handle_core_version_change($espresso_db_update);
454
+				break;
455
+			case EE_System::req_type_reactivation:
456
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
457
+				$this->_handle_core_version_change($espresso_db_update);
458
+				break;
459
+			case EE_System::req_type_upgrade:
460
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
461
+				//migrations may be required now that we've upgraded
462
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
463
+				$this->_handle_core_version_change($espresso_db_update);
464
+				//				echo "done upgrade";die;
465
+				break;
466
+			case EE_System::req_type_downgrade:
467
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
468
+				//its possible migrations are no longer required
469
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
470
+				$this->_handle_core_version_change($espresso_db_update);
471
+				break;
472
+			case EE_System::req_type_normal:
473
+			default:
474
+				break;
475
+		}
476
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
477
+	}
478
+
479
+
480
+
481
+	/**
482
+	 * Updates the list of installed versions and sets hooks for
483
+	 * initializing the database later during the request
484
+	 *
485
+	 * @param array $espresso_db_update
486
+	 */
487
+	private function _handle_core_version_change($espresso_db_update)
488
+	{
489
+		$this->update_list_of_installed_versions($espresso_db_update);
490
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
491
+		add_action(
492
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
493
+			array($this, 'initialize_db_if_no_migrations_required')
494
+		);
495
+	}
496
+
497
+
498
+
499
+	/**
500
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
501
+	 * information about what versions of EE have been installed and activated,
502
+	 * NOT necessarily the state of the database
503
+	 *
504
+	 * @param mixed $espresso_db_update           the value of the WordPress option.
505
+	 *                                            If not supplied, fetches it from the options table
506
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
507
+	 */
508
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
509
+	{
510
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
511
+		if (! $espresso_db_update) {
512
+			$espresso_db_update = get_option('espresso_db_update');
513
+		}
514
+		// check that option is an array
515
+		if (! is_array($espresso_db_update)) {
516
+			// if option is FALSE, then it never existed
517
+			if ($espresso_db_update === false) {
518
+				// make $espresso_db_update an array and save option with autoload OFF
519
+				$espresso_db_update = array();
520
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
521
+			} else {
522
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
523
+				$espresso_db_update = array($espresso_db_update => array());
524
+				update_option('espresso_db_update', $espresso_db_update);
525
+			}
526
+		} else {
527
+			$corrected_db_update = array();
528
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
529
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
530
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
531
+					//the key is an int, and the value IS NOT an array
532
+					//so it must be numerically-indexed, where values are versions installed...
533
+					//fix it!
534
+					$version_string                         = $should_be_array;
535
+					$corrected_db_update[ $version_string ] = array('unknown-date');
536
+				} else {
537
+					//ok it checks out
538
+					$corrected_db_update[ $should_be_version_string ] = $should_be_array;
539
+				}
540
+			}
541
+			$espresso_db_update = $corrected_db_update;
542
+			update_option('espresso_db_update', $espresso_db_update);
543
+		}
544
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
545
+		return $espresso_db_update;
546
+	}
547
+
548
+
549
+
550
+	/**
551
+	 * Does the traditional work of setting up the plugin's database and adding default data.
552
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
553
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
554
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
555
+	 * so that it will be done when migrations are finished
556
+	 *
557
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
558
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
559
+	 *                                       This is a resource-intensive job
560
+	 *                                       so we prefer to only do it when necessary
561
+	 * @return void
562
+	 * @throws EE_Error
563
+	 */
564
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
565
+	{
566
+		$request_type = $this->detect_req_type();
567
+		//only initialize system if we're not in maintenance mode.
568
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
569
+			update_option('ee_flush_rewrite_rules', true);
570
+			if ($verify_schema) {
571
+				EEH_Activation::initialize_db_and_folders();
572
+			}
573
+			EEH_Activation::initialize_db_content();
574
+			EEH_Activation::system_initialization();
575
+			if ($initialize_addons_too) {
576
+				$this->initialize_addons();
577
+			}
578
+		} else {
579
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
580
+		}
581
+		if ($request_type === EE_System::req_type_new_activation
582
+			|| $request_type === EE_System::req_type_reactivation
583
+			|| (
584
+				$request_type === EE_System::req_type_upgrade
585
+				&& $this->is_major_version_change()
586
+			)
587
+		) {
588
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
589
+		}
590
+	}
591
+
592
+
593
+
594
+	/**
595
+	 * Initializes the db for all registered addons
596
+	 *
597
+	 * @throws EE_Error
598
+	 */
599
+	public function initialize_addons()
600
+	{
601
+		//foreach registered addon, make sure its db is up-to-date too
602
+		foreach ($this->registry->addons as $addon) {
603
+			if ($addon instanceof EE_Addon) {
604
+				$addon->initialize_db_if_no_migrations_required();
605
+			}
606
+		}
607
+	}
608
+
609
+
610
+
611
+	/**
612
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
613
+	 *
614
+	 * @param    array  $version_history
615
+	 * @param    string $current_version_to_add version to be added to the version history
616
+	 * @return    boolean success as to whether or not this option was changed
617
+	 */
618
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
619
+	{
620
+		if (! $version_history) {
621
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
622
+		}
623
+		if ($current_version_to_add === null) {
624
+			$current_version_to_add = espresso_version();
625
+		}
626
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
627
+		// re-save
628
+		return update_option('espresso_db_update', $version_history);
629
+	}
630
+
631
+
632
+
633
+	/**
634
+	 * Detects if the current version indicated in the has existed in the list of
635
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
636
+	 *
637
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
638
+	 *                                  If not supplied, fetches it from the options table.
639
+	 *                                  Also, caches its result so later parts of the code can also know whether
640
+	 *                                  there's been an update or not. This way we can add the current version to
641
+	 *                                  espresso_db_update, but still know if this is a new install or not
642
+	 * @return int one of the constants on EE_System::req_type_
643
+	 */
644
+	public function detect_req_type($espresso_db_update = null)
645
+	{
646
+		if ($this->_req_type === null) {
647
+			$espresso_db_update          = ! empty($espresso_db_update)
648
+				? $espresso_db_update
649
+				: $this->fix_espresso_db_upgrade_option();
650
+			$this->_req_type             = EE_System::detect_req_type_given_activation_history(
651
+				$espresso_db_update,
652
+				'ee_espresso_activation', espresso_version()
653
+			);
654
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
655
+			$this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
656
+		}
657
+		return $this->_req_type;
658
+	}
659
+
660
+
661
+
662
+	/**
663
+	 * Returns whether or not there was a non-micro version change (ie, change in either
664
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
665
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
666
+	 *
667
+	 * @param $activation_history
668
+	 * @return bool
669
+	 */
670
+	private function _detect_major_version_change($activation_history)
671
+	{
672
+		$previous_version       = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
673
+		$previous_version_parts = explode('.', $previous_version);
674
+		$current_version_parts  = explode('.', espresso_version());
675
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
676
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
677
+				   || $previous_version_parts[1] !== $current_version_parts[1]
678
+			   );
679
+	}
680
+
681
+
682
+
683
+	/**
684
+	 * Returns true if either the major or minor version of EE changed during this request.
685
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
686
+	 *
687
+	 * @return bool
688
+	 */
689
+	public function is_major_version_change()
690
+	{
691
+		return $this->_major_version_change;
692
+	}
693
+
694
+
695
+
696
+	/**
697
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
698
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
699
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
700
+	 * just activated to (for core that will always be espresso_version())
701
+	 *
702
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
703
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
704
+	 * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
705
+	 *                                                 indicate that this plugin was just activated
706
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
707
+	 *                                                 espresso_version())
708
+	 * @return int one of the constants on EE_System::req_type_*
709
+	 */
710
+	public static function detect_req_type_given_activation_history(
711
+		$activation_history_for_addon,
712
+		$activation_indicator_option_name,
713
+		$version_to_upgrade_to
714
+	) {
715
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
716
+		if ($activation_history_for_addon) {
717
+			//it exists, so this isn't a completely new install
718
+			//check if this version already in that list of previously installed versions
719
+			if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
720
+				//it a version we haven't seen before
721
+				if ($version_is_higher === 1) {
722
+					$req_type = EE_System::req_type_upgrade;
723
+				} else {
724
+					$req_type = EE_System::req_type_downgrade;
725
+				}
726
+				delete_option($activation_indicator_option_name);
727
+			} else {
728
+				// its not an update. maybe a reactivation?
729
+				if (get_option($activation_indicator_option_name, false)) {
730
+					if ($version_is_higher === -1) {
731
+						$req_type = EE_System::req_type_downgrade;
732
+					} elseif ($version_is_higher === 0) {
733
+						//we've seen this version before, but it's an activation. must be a reactivation
734
+						$req_type = EE_System::req_type_reactivation;
735
+					} else {//$version_is_higher === 1
736
+						$req_type = EE_System::req_type_upgrade;
737
+					}
738
+					delete_option($activation_indicator_option_name);
739
+				} else {
740
+					//we've seen this version before and the activation indicate doesn't show it was just activated
741
+					if ($version_is_higher === -1) {
742
+						$req_type = EE_System::req_type_downgrade;
743
+					} elseif ($version_is_higher === 0) {
744
+						//we've seen this version before and it's not an activation. its normal request
745
+						$req_type = EE_System::req_type_normal;
746
+					} else {//$version_is_higher === 1
747
+						$req_type = EE_System::req_type_upgrade;
748
+					}
749
+				}
750
+			}
751
+		} else {
752
+			//brand new install
753
+			$req_type = EE_System::req_type_new_activation;
754
+			delete_option($activation_indicator_option_name);
755
+		}
756
+		return $req_type;
757
+	}
758
+
759
+
760
+
761
+	/**
762
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
763
+	 * the $activation_history_for_addon
764
+	 *
765
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
766
+	 *                                             sometimes containing 'unknown-date'
767
+	 * @param string $version_to_upgrade_to        (current version)
768
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
769
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
770
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
771
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
772
+	 */
773
+	private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
774
+	{
775
+		//find the most recently-activated version
776
+		$most_recently_active_version =
777
+			EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
778
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
779
+	}
780
+
781
+
782
+
783
+	/**
784
+	 * Gets the most recently active version listed in the activation history,
785
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
786
+	 *
787
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
788
+	 *                                   sometimes containing 'unknown-date'
789
+	 * @return string
790
+	 */
791
+	private static function _get_most_recently_active_version_from_activation_history($activation_history)
792
+	{
793
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
794
+		$most_recently_active_version            = '0.0.0.dev.000';
795
+		if (is_array($activation_history)) {
796
+			foreach ($activation_history as $version => $times_activated) {
797
+				//check there is a record of when this version was activated. Otherwise,
798
+				//mark it as unknown
799
+				if (! $times_activated) {
800
+					$times_activated = array('unknown-date');
801
+				}
802
+				if (is_string($times_activated)) {
803
+					$times_activated = array($times_activated);
804
+				}
805
+				foreach ($times_activated as $an_activation) {
806
+					if ($an_activation !== 'unknown-date'
807
+						&& $an_activation
808
+						   > $most_recently_active_version_activation) {
809
+						$most_recently_active_version            = $version;
810
+						$most_recently_active_version_activation = $an_activation === 'unknown-date'
811
+							? '1970-01-01 00:00:00'
812
+							: $an_activation;
813
+					}
814
+				}
815
+			}
816
+		}
817
+		return $most_recently_active_version;
818
+	}
819
+
820
+
821
+
822
+	/**
823
+	 * This redirects to the about EE page after activation
824
+	 *
825
+	 * @return void
826
+	 */
827
+	public function redirect_to_about_ee()
828
+	{
829
+		$notices = EE_Error::get_notices(false);
830
+		//if current user is an admin and it's not an ajax or rest request
831
+		if (
832
+			! isset($notices['errors'])
833
+			&& $this->request->isAdmin()
834
+			&& apply_filters(
835
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
836
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
837
+			)
838
+		) {
839
+			$query_params = array('page' => 'espresso_about');
840
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
841
+				$query_params['new_activation'] = true;
842
+			}
843
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
844
+				$query_params['reactivation'] = true;
845
+			}
846
+			$url = add_query_arg($query_params, admin_url('admin.php'));
847
+			wp_safe_redirect($url);
848
+			exit();
849
+		}
850
+	}
851
+
852
+
853
+
854
+	/**
855
+	 * load_core_configuration
856
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
857
+	 * which runs during the WP 'plugins_loaded' action at priority 5
858
+	 *
859
+	 * @return void
860
+	 * @throws ReflectionException
861
+	 */
862
+	public function load_core_configuration()
863
+	{
864
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
865
+		$this->loader->getShared('EE_Load_Textdomain');
866
+		//load textdomain
867
+		EE_Load_Textdomain::load_textdomain();
868
+		// load and setup EE_Config and EE_Network_Config
869
+		$config = $this->loader->getShared('EE_Config');
870
+		$this->loader->getShared('EE_Network_Config');
871
+		// setup autoloaders
872
+		// enable logging?
873
+		if ($config->admin->use_full_logging) {
874
+			$this->loader->getShared('EE_Log');
875
+		}
876
+		// check for activation errors
877
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
878
+		if ($activation_errors) {
879
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
880
+			update_option('ee_plugin_activation_errors', false);
881
+		}
882
+		// get model names
883
+		$this->_parse_model_names();
884
+		//load caf stuff a chance to play during the activation process too.
885
+		$this->_maybe_brew_regular();
886
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
887
+	}
888
+
889
+
890
+
891
+	/**
892
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
893
+	 *
894
+	 * @return void
895
+	 * @throws ReflectionException
896
+	 */
897
+	private function _parse_model_names()
898
+	{
899
+		//get all the files in the EE_MODELS folder that end in .model.php
900
+		$models                 = glob(EE_MODELS . '*.model.php');
901
+		$model_names            = array();
902
+		$non_abstract_db_models = array();
903
+		foreach ($models as $model) {
904
+			// get model classname
905
+			$classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
906
+			$short_name      = str_replace('EEM_', '', $classname);
907
+			$reflectionClass = new ReflectionClass($classname);
908
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
909
+				$non_abstract_db_models[ $short_name ] = $classname;
910
+			}
911
+			$model_names[ $short_name ] = $classname;
912
+		}
913
+		$this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
914
+		$this->registry->non_abstract_db_models = apply_filters(
915
+			'FHEE__EE_System__parse_implemented_model_names',
916
+			$non_abstract_db_models
917
+		);
918
+	}
919
+
920
+
921
+	/**
922
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
923
+	 * that need to be setup before our EE_System launches.
924
+	 *
925
+	 * @return void
926
+	 * @throws DomainException
927
+	 * @throws InvalidArgumentException
928
+	 * @throws InvalidDataTypeException
929
+	 * @throws InvalidInterfaceException
930
+	 * @throws InvalidClassException
931
+	 * @throws InvalidFilePathException
932
+	 */
933
+	private function _maybe_brew_regular()
934
+	{
935
+		/** @var Domain $domain */
936
+		$domain = DomainFactory::getShared(
937
+			new FullyQualifiedName(
938
+				'EventEspresso\core\domain\Domain'
939
+			),
940
+			array(
941
+				new FilePath(EVENT_ESPRESSO_MAIN_FILE),
942
+				Version::fromString(espresso_version())
943
+			)
944
+		);
945
+		if ($domain->isCaffeinated()) {
946
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
947
+		}
948
+	}
949
+
950
+
951
+
952
+	/**
953
+	 * register_shortcodes_modules_and_widgets
954
+	 * generate lists of shortcodes and modules, then verify paths and classes
955
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
956
+	 * which runs during the WP 'plugins_loaded' action at priority 7
957
+	 *
958
+	 * @access public
959
+	 * @return void
960
+	 * @throws Exception
961
+	 */
962
+	public function register_shortcodes_modules_and_widgets()
963
+	{
964
+		if ($this->request->isFrontend() || $this->request->isIframe()) {
965
+			try {
966
+				// load, register, and add shortcodes the new way
967
+				$this->loader->getShared(
968
+					'EventEspresso\core\services\shortcodes\ShortcodesManager',
969
+					array(
970
+						// and the old way, but we'll put it under control of the new system
971
+						EE_Config::getLegacyShortcodesManager(),
972
+					)
973
+				);
974
+			} catch (Exception $exception) {
975
+				new ExceptionStackTraceDisplay($exception);
976
+			}
977
+		}
978
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
979
+		// check for addons using old hook point
980
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
981
+			$this->_incompatible_addon_error();
982
+		}
983
+	}
984
+
985
+
986
+
987
+	/**
988
+	 * _incompatible_addon_error
989
+	 *
990
+	 * @access public
991
+	 * @return void
992
+	 */
993
+	private function _incompatible_addon_error()
994
+	{
995
+		// get array of classes hooking into here
996
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
997
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
998
+		);
999
+		if (! empty($class_names)) {
1000
+			$msg = __(
1001
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
1002
+				'event_espresso'
1003
+			);
1004
+			$msg .= '<ul>';
1005
+			foreach ($class_names as $class_name) {
1006
+				$msg .= '<li><b>Event Espresso - ' . str_replace(
1007
+						array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
1008
+						$class_name
1009
+					) . '</b></li>';
1010
+			}
1011
+			$msg .= '</ul>';
1012
+			$msg .= __(
1013
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1014
+				'event_espresso'
1015
+			);
1016
+			// save list of incompatible addons to wp-options for later use
1017
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
1018
+			if (is_admin()) {
1019
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1020
+			}
1021
+		}
1022
+	}
1023
+
1024
+
1025
+
1026
+	/**
1027
+	 * brew_espresso
1028
+	 * begins the process of setting hooks for initializing EE in the correct order
1029
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1030
+	 * which runs during the WP 'plugins_loaded' action at priority 9
1031
+	 *
1032
+	 * @return void
1033
+	 */
1034
+	public function brew_espresso()
1035
+	{
1036
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
1037
+		// load some final core systems
1038
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
1039
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1040
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
1041
+		add_action('init', array($this, 'load_controllers'), 7);
1042
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
1043
+		add_action('init', array($this, 'initialize'), 10);
1044
+		add_action('init', array($this, 'initialize_last'), 100);
1045
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1046
+			// pew pew pew
1047
+			$this->loader->getShared('EventEspresso\core\services\licensing\LicenseService');
1048
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1049
+		}
1050
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
1051
+	}
1052
+
1053
+
1054
+
1055
+	/**
1056
+	 *    set_hooks_for_core
1057
+	 *
1058
+	 * @access public
1059
+	 * @return    void
1060
+	 * @throws EE_Error
1061
+	 */
1062
+	public function set_hooks_for_core()
1063
+	{
1064
+		$this->_deactivate_incompatible_addons();
1065
+		do_action('AHEE__EE_System__set_hooks_for_core');
1066
+		$this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1067
+		//caps need to be initialized on every request so that capability maps are set.
1068
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1069
+		$this->registry->CAP->init_caps();
1070
+	}
1071
+
1072
+
1073
+
1074
+	/**
1075
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
1076
+	 * deactivates any addons considered incompatible with the current version of EE
1077
+	 */
1078
+	private function _deactivate_incompatible_addons()
1079
+	{
1080
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
1081
+		if (! empty($incompatible_addons)) {
1082
+			$active_plugins = get_option('active_plugins', array());
1083
+			foreach ($active_plugins as $active_plugin) {
1084
+				foreach ($incompatible_addons as $incompatible_addon) {
1085
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
1086
+						unset($_GET['activate']);
1087
+						espresso_deactivate_plugin($active_plugin);
1088
+					}
1089
+				}
1090
+			}
1091
+		}
1092
+	}
1093
+
1094
+
1095
+
1096
+	/**
1097
+	 *    perform_activations_upgrades_and_migrations
1098
+	 *
1099
+	 * @access public
1100
+	 * @return    void
1101
+	 */
1102
+	public function perform_activations_upgrades_and_migrations()
1103
+	{
1104
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1105
+	}
1106
+
1107
+
1108
+
1109
+	/**
1110
+	 *    load_CPTs_and_session
1111
+	 *
1112
+	 * @access public
1113
+	 * @return    void
1114
+	 */
1115
+	public function load_CPTs_and_session()
1116
+	{
1117
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
1118
+		// register Custom Post Types
1119
+		$this->loader->getShared('EE_Register_CPTs');
1120
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1121
+	}
1122
+
1123
+
1124
+
1125
+	/**
1126
+	 * load_controllers
1127
+	 * this is the best place to load any additional controllers that needs access to EE core.
1128
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1129
+	 * time
1130
+	 *
1131
+	 * @access public
1132
+	 * @return void
1133
+	 */
1134
+	public function load_controllers()
1135
+	{
1136
+		do_action('AHEE__EE_System__load_controllers__start');
1137
+		// let's get it started
1138
+		if (
1139
+			! $this->maintenance_mode->level()
1140
+			&& ($this->request->isFrontend() || $this->request->isFrontAjax())
1141
+		) {
1142
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1143
+			$this->loader->getShared('EE_Front_Controller');
1144
+		} elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1145
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1146
+			$this->loader->getShared('EE_Admin');
1147
+		}
1148
+		do_action('AHEE__EE_System__load_controllers__complete');
1149
+	}
1150
+
1151
+
1152
+
1153
+	/**
1154
+	 * core_loaded_and_ready
1155
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1156
+	 *
1157
+	 * @access public
1158
+	 * @return void
1159
+	 */
1160
+	public function core_loaded_and_ready()
1161
+	{
1162
+		if (
1163
+			$this->request->isAdmin()
1164
+			|| $this->request->isEeAjax()
1165
+			|| $this->request->isFrontend()
1166
+		) {
1167
+			$this->loader->getShared('EE_Session');
1168
+		}
1169
+		do_action('AHEE__EE_System__core_loaded_and_ready');
1170
+		// load_espresso_template_tags
1171
+		if (
1172
+			is_readable(EE_PUBLIC . 'template_tags.php')
1173
+			&& ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isFeed())
1174
+		) {
1175
+			require_once EE_PUBLIC . 'template_tags.php';
1176
+		}
1177
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1178
+		if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1179
+			$this->loader->getShared('EventEspresso\core\services\assets\Registry');
1180
+		}
1181
+	}
1182
+
1183
+
1184
+
1185
+	/**
1186
+	 * initialize
1187
+	 * this is the best place to begin initializing client code
1188
+	 *
1189
+	 * @access public
1190
+	 * @return void
1191
+	 */
1192
+	public function initialize()
1193
+	{
1194
+		do_action('AHEE__EE_System__initialize');
1195
+	}
1196
+
1197
+
1198
+
1199
+	/**
1200
+	 * initialize_last
1201
+	 * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1202
+	 * initialize has done so
1203
+	 *
1204
+	 * @access public
1205
+	 * @return void
1206
+	 */
1207
+	public function initialize_last()
1208
+	{
1209
+		do_action('AHEE__EE_System__initialize_last');
1210
+		add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1211
+	}
1212
+
1213
+
1214
+
1215
+	/**
1216
+	 * @return void
1217
+	 * @throws EE_Error
1218
+	 */
1219
+	public function addEspressoToolbar()
1220
+	{
1221
+		$this->loader->getShared(
1222
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
1223
+			array($this->registry->CAP)
1224
+		);
1225
+	}
1226
+
1227
+
1228
+
1229
+	/**
1230
+	 * do_not_cache
1231
+	 * sets no cache headers and defines no cache constants for WP plugins
1232
+	 *
1233
+	 * @access public
1234
+	 * @return void
1235
+	 */
1236
+	public static function do_not_cache()
1237
+	{
1238
+		// set no cache constants
1239
+		if (! defined('DONOTCACHEPAGE')) {
1240
+			define('DONOTCACHEPAGE', true);
1241
+		}
1242
+		if (! defined('DONOTCACHCEOBJECT')) {
1243
+			define('DONOTCACHCEOBJECT', true);
1244
+		}
1245
+		if (! defined('DONOTCACHEDB')) {
1246
+			define('DONOTCACHEDB', true);
1247
+		}
1248
+		// add no cache headers
1249
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1250
+		// plus a little extra for nginx and Google Chrome
1251
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1252
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1253
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1254
+	}
1255
+
1256
+
1257
+
1258
+	/**
1259
+	 *    extra_nocache_headers
1260
+	 *
1261
+	 * @access    public
1262
+	 * @param $headers
1263
+	 * @return    array
1264
+	 */
1265
+	public static function extra_nocache_headers($headers)
1266
+	{
1267
+		// for NGINX
1268
+		$headers['X-Accel-Expires'] = 0;
1269
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1270
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1271
+		return $headers;
1272
+	}
1273
+
1274
+
1275
+
1276
+	/**
1277
+	 *    nocache_headers
1278
+	 *
1279
+	 * @access    public
1280
+	 * @return    void
1281
+	 */
1282
+	public static function nocache_headers()
1283
+	{
1284
+		nocache_headers();
1285
+	}
1286
+
1287
+
1288
+
1289
+	/**
1290
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1291
+	 * never returned with the function.
1292
+	 *
1293
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1294
+	 * @return array
1295
+	 */
1296
+	public function remove_pages_from_wp_list_pages($exclude_array)
1297
+	{
1298
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1299
+	}
1300 1300
 
1301 1301
 
1302 1302
 
Please login to merge, or discard this patch.
core/services/assets/Registry.php 1 patch
Indentation   +634 added lines, -634 removed lines patch added patch discarded remove patch
@@ -25,642 +25,642 @@
 block discarded – undo
25 25
 class Registry
26 26
 {
27 27
 
28
-    const ASSET_TYPE_CSS = 'css';
29
-    const ASSET_TYPE_JS = 'js';
30
-    const ASSET_NAMESPACE = 'core';
31
-
32
-    /**
33
-     * @var EE_Template_Config $template_config
34
-     */
35
-    protected $template_config;
36
-
37
-    /**
38
-     * @var EE_Currency_Config $currency_config
39
-     */
40
-    protected $currency_config;
41
-
42
-    /**
43
-     * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
44
-     *
45
-     * @var array
46
-     */
47
-    protected $jsdata = array();
48
-
49
-
50
-    /**
51
-     * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
52
-     * page source.
53
-     * @var array
54
-     */
55
-    protected $script_handles_with_data = array();
56
-
57
-
58
-    /**
59
-     * @var DomainInterface
60
-     */
61
-    protected $domain;
62
-
63
-
64
-
65
-    /**
66
-     * Holds the manifest data obtained from registered manifest files.
67
-     * Manifests are maps of asset chunk name to actual built asset file names.
68
-     * Shape of this array is:
69
-     *
70
-     * array(
71
-     *  'some_namespace_slug' => array(
72
-     *      'some_chunk_name' => array(
73
-     *          'js' => 'filename.js'
74
-     *          'css' => 'filename.js'
75
-     *      ),
76
-     *      'url_base' => 'https://baseurl.com/to/assets
77
-     *  )
78
-     * )
79
-     *
80
-     * @var array
81
-     */
82
-    private $manifest_data = array();
83
-
84
-
85
-    /**
86
-     * Registry constructor.
87
-     * Hooking into WP actions for script registry.
88
-     *
89
-     * @param EE_Template_Config $template_config
90
-     * @param EE_Currency_Config $currency_config
91
-     * @param DomainInterface    $domain
92
-     * @throws InvalidArgumentException
93
-     * @throws InvalidFilePathException
94
-     */
95
-    public function __construct(
96
-        EE_Template_Config $template_config,
97
-        EE_Currency_Config $currency_config,
98
-        DomainInterface $domain
99
-    ) {
100
-        $this->template_config = $template_config;
101
-        $this->currency_config = $currency_config;
102
-        $this->domain = $domain;
103
-        $this->registerManifestFile(
104
-            self::ASSET_NAMESPACE,
105
-            $this->domain->distributionAssetsUrl(),
106
-            $this->domain->distributionAssetsPath() . 'build-manifest.json'
107
-        );
108
-        add_action('wp_enqueue_scripts', array($this, 'scripts'), 1);
109
-        add_action('admin_enqueue_scripts', array($this, 'scripts'), 1);
110
-        add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2);
111
-        add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2);
112
-        add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
113
-        add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
114
-    }
115
-
116
-    /**
117
-     * Callback for the WP script actions.
118
-     * Used to register globally accessible core scripts.
119
-     * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency.
120
-     *
121
-     */
122
-    public function scripts()
123
-    {
124
-        global $wp_version;
125
-        wp_register_script(
126
-            'ee-manifest',
127
-            $this->getJsUrl(self::ASSET_NAMESPACE, 'manifest'),
128
-            array(),
129
-            null,
130
-            true
131
-        );
132
-        wp_register_script(
133
-            'eejs-core',
134
-            $this->getJsUrl(self::ASSET_NAMESPACE, 'eejs'),
135
-            array('ee-manifest'),
136
-            null,
137
-            true
138
-        );
139
-        wp_register_script(
140
-            'ee-vendor-react',
141
-            $this->getJsUrl(self::ASSET_NAMESPACE, 'reactVendor'),
142
-            array('eejs-core'),
143
-            null,
144
-            true
145
-        );
146
-        //only run this if WordPress 4.4.0 > is in use.
147
-        if (version_compare($wp_version, '4.4.0', '>')) {
148
-            //js.api
149
-            wp_register_script(
150
-                'eejs-api',
151
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
152
-                array('underscore', 'eejs-core'),
153
-                EVENT_ESPRESSO_VERSION,
154
-                true
155
-            );
156
-            $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest');
157
-            $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/'));
158
-        }
159
-        if (! is_admin()) {
160
-            $this->loadCoreCss();
161
-        }
162
-        $this->loadCoreJs();
163
-        $this->loadJqueryValidate();
164
-        $this->loadAccountingJs();
165
-        $this->loadQtipJs();
166
-        $this->registerAdminAssets();
167
-    }
168
-
169
-
170
-
171
-    /**
172
-     * Call back for the script print in frontend and backend.
173
-     * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
174
-     *
175
-     * @since 4.9.31.rc.015
176
-     */
177
-    public function enqueueData()
178
-    {
179
-        $this->removeAlreadyRegisteredDataForScriptHandles();
180
-        wp_localize_script('eejs-core', 'eejsdata', array('data' => $this->jsdata));
181
-        wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
182
-        $this->localizeAccountingJs();
183
-        $this->addRegisteredScriptHandlesWithData('eejs-core');
184
-        $this->addRegisteredScriptHandlesWithData('espresso_core');
185
-    }
186
-
187
-
188
-
189
-    /**
190
-     * Used to add data to eejs.data object.
191
-     * Note:  Overriding existing data is not allowed.
192
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
193
-     * If the data you add is something like this:
194
-     *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
195
-     * It will be exposed in the page source as:
196
-     *  eejs.data.my_plugin_data.foo == gar
197
-     *
198
-     * @param string       $key   Key used to access your data
199
-     * @param string|array $value Value to attach to key
200
-     * @throws InvalidArgumentException
201
-     */
202
-    public function addData($key, $value)
203
-    {
204
-        if ($this->verifyDataNotExisting($key)) {
205
-            $this->jsdata[$key] = $value;
206
-        }
207
-    }
208
-
209
-
210
-
211
-    /**
212
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
213
-     * elements in an array.
214
-     * When you use this method, the value you include will be appended to the end of an array on $key.
215
-     * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
216
-     * object like this, eejs.data.test = [ my_data,
217
-     * ]
218
-     * If there has already been a scalar value attached to the data object given key, then
219
-     * this will throw an exception.
220
-     *
221
-     * @param string       $key   Key to attach data to.
222
-     * @param string|array $value Value being registered.
223
-     * @throws InvalidArgumentException
224
-     */
225
-    public function pushData($key, $value)
226
-    {
227
-        if (isset($this->jsdata[$key])
228
-            && ! is_array($this->jsdata[$key])
229
-        ) {
230
-            throw new invalidArgumentException(
231
-                sprintf(
232
-                    __(
233
-                        'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
28
+	const ASSET_TYPE_CSS = 'css';
29
+	const ASSET_TYPE_JS = 'js';
30
+	const ASSET_NAMESPACE = 'core';
31
+
32
+	/**
33
+	 * @var EE_Template_Config $template_config
34
+	 */
35
+	protected $template_config;
36
+
37
+	/**
38
+	 * @var EE_Currency_Config $currency_config
39
+	 */
40
+	protected $currency_config;
41
+
42
+	/**
43
+	 * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
44
+	 *
45
+	 * @var array
46
+	 */
47
+	protected $jsdata = array();
48
+
49
+
50
+	/**
51
+	 * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
52
+	 * page source.
53
+	 * @var array
54
+	 */
55
+	protected $script_handles_with_data = array();
56
+
57
+
58
+	/**
59
+	 * @var DomainInterface
60
+	 */
61
+	protected $domain;
62
+
63
+
64
+
65
+	/**
66
+	 * Holds the manifest data obtained from registered manifest files.
67
+	 * Manifests are maps of asset chunk name to actual built asset file names.
68
+	 * Shape of this array is:
69
+	 *
70
+	 * array(
71
+	 *  'some_namespace_slug' => array(
72
+	 *      'some_chunk_name' => array(
73
+	 *          'js' => 'filename.js'
74
+	 *          'css' => 'filename.js'
75
+	 *      ),
76
+	 *      'url_base' => 'https://baseurl.com/to/assets
77
+	 *  )
78
+	 * )
79
+	 *
80
+	 * @var array
81
+	 */
82
+	private $manifest_data = array();
83
+
84
+
85
+	/**
86
+	 * Registry constructor.
87
+	 * Hooking into WP actions for script registry.
88
+	 *
89
+	 * @param EE_Template_Config $template_config
90
+	 * @param EE_Currency_Config $currency_config
91
+	 * @param DomainInterface    $domain
92
+	 * @throws InvalidArgumentException
93
+	 * @throws InvalidFilePathException
94
+	 */
95
+	public function __construct(
96
+		EE_Template_Config $template_config,
97
+		EE_Currency_Config $currency_config,
98
+		DomainInterface $domain
99
+	) {
100
+		$this->template_config = $template_config;
101
+		$this->currency_config = $currency_config;
102
+		$this->domain = $domain;
103
+		$this->registerManifestFile(
104
+			self::ASSET_NAMESPACE,
105
+			$this->domain->distributionAssetsUrl(),
106
+			$this->domain->distributionAssetsPath() . 'build-manifest.json'
107
+		);
108
+		add_action('wp_enqueue_scripts', array($this, 'scripts'), 1);
109
+		add_action('admin_enqueue_scripts', array($this, 'scripts'), 1);
110
+		add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2);
111
+		add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2);
112
+		add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
113
+		add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
114
+	}
115
+
116
+	/**
117
+	 * Callback for the WP script actions.
118
+	 * Used to register globally accessible core scripts.
119
+	 * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency.
120
+	 *
121
+	 */
122
+	public function scripts()
123
+	{
124
+		global $wp_version;
125
+		wp_register_script(
126
+			'ee-manifest',
127
+			$this->getJsUrl(self::ASSET_NAMESPACE, 'manifest'),
128
+			array(),
129
+			null,
130
+			true
131
+		);
132
+		wp_register_script(
133
+			'eejs-core',
134
+			$this->getJsUrl(self::ASSET_NAMESPACE, 'eejs'),
135
+			array('ee-manifest'),
136
+			null,
137
+			true
138
+		);
139
+		wp_register_script(
140
+			'ee-vendor-react',
141
+			$this->getJsUrl(self::ASSET_NAMESPACE, 'reactVendor'),
142
+			array('eejs-core'),
143
+			null,
144
+			true
145
+		);
146
+		//only run this if WordPress 4.4.0 > is in use.
147
+		if (version_compare($wp_version, '4.4.0', '>')) {
148
+			//js.api
149
+			wp_register_script(
150
+				'eejs-api',
151
+				EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
152
+				array('underscore', 'eejs-core'),
153
+				EVENT_ESPRESSO_VERSION,
154
+				true
155
+			);
156
+			$this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest');
157
+			$this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/'));
158
+		}
159
+		if (! is_admin()) {
160
+			$this->loadCoreCss();
161
+		}
162
+		$this->loadCoreJs();
163
+		$this->loadJqueryValidate();
164
+		$this->loadAccountingJs();
165
+		$this->loadQtipJs();
166
+		$this->registerAdminAssets();
167
+	}
168
+
169
+
170
+
171
+	/**
172
+	 * Call back for the script print in frontend and backend.
173
+	 * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
174
+	 *
175
+	 * @since 4.9.31.rc.015
176
+	 */
177
+	public function enqueueData()
178
+	{
179
+		$this->removeAlreadyRegisteredDataForScriptHandles();
180
+		wp_localize_script('eejs-core', 'eejsdata', array('data' => $this->jsdata));
181
+		wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
182
+		$this->localizeAccountingJs();
183
+		$this->addRegisteredScriptHandlesWithData('eejs-core');
184
+		$this->addRegisteredScriptHandlesWithData('espresso_core');
185
+	}
186
+
187
+
188
+
189
+	/**
190
+	 * Used to add data to eejs.data object.
191
+	 * Note:  Overriding existing data is not allowed.
192
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
193
+	 * If the data you add is something like this:
194
+	 *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
195
+	 * It will be exposed in the page source as:
196
+	 *  eejs.data.my_plugin_data.foo == gar
197
+	 *
198
+	 * @param string       $key   Key used to access your data
199
+	 * @param string|array $value Value to attach to key
200
+	 * @throws InvalidArgumentException
201
+	 */
202
+	public function addData($key, $value)
203
+	{
204
+		if ($this->verifyDataNotExisting($key)) {
205
+			$this->jsdata[$key] = $value;
206
+		}
207
+	}
208
+
209
+
210
+
211
+	/**
212
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
213
+	 * elements in an array.
214
+	 * When you use this method, the value you include will be appended to the end of an array on $key.
215
+	 * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
216
+	 * object like this, eejs.data.test = [ my_data,
217
+	 * ]
218
+	 * If there has already been a scalar value attached to the data object given key, then
219
+	 * this will throw an exception.
220
+	 *
221
+	 * @param string       $key   Key to attach data to.
222
+	 * @param string|array $value Value being registered.
223
+	 * @throws InvalidArgumentException
224
+	 */
225
+	public function pushData($key, $value)
226
+	{
227
+		if (isset($this->jsdata[$key])
228
+			&& ! is_array($this->jsdata[$key])
229
+		) {
230
+			throw new invalidArgumentException(
231
+				sprintf(
232
+					__(
233
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
234 234
                          push values to this data element when it is an array.',
235
-                        'event_espresso'
236
-                    ),
237
-                    $key,
238
-                    __METHOD__
239
-                )
240
-            );
241
-        }
242
-        $this->jsdata[$key][] = $value;
243
-    }
244
-
245
-
246
-
247
-    /**
248
-     * Used to set content used by javascript for a template.
249
-     * Note: Overrides of existing registered templates are not allowed.
250
-     *
251
-     * @param string $template_reference
252
-     * @param string $template_content
253
-     * @throws InvalidArgumentException
254
-     */
255
-    public function addTemplate($template_reference, $template_content)
256
-    {
257
-        if (! isset($this->jsdata['templates'])) {
258
-            $this->jsdata['templates'] = array();
259
-        }
260
-        //no overrides allowed.
261
-        if (isset($this->jsdata['templates'][$template_reference])) {
262
-            throw new invalidArgumentException(
263
-                sprintf(
264
-                    __(
265
-                        'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
266
-                        'event_espresso'
267
-                    ),
268
-                    $template_reference
269
-                )
270
-            );
271
-        }
272
-        $this->jsdata['templates'][$template_reference] = $template_content;
273
-    }
274
-
275
-
276
-
277
-    /**
278
-     * Retrieve the template content already registered for the given reference.
279
-     *
280
-     * @param string $template_reference
281
-     * @return string
282
-     */
283
-    public function getTemplate($template_reference)
284
-    {
285
-        return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference])
286
-            ? $this->jsdata['templates'][$template_reference]
287
-            : '';
288
-    }
289
-
290
-
291
-
292
-    /**
293
-     * Retrieve registered data.
294
-     *
295
-     * @param string $key Name of key to attach data to.
296
-     * @return mixed                If there is no for the given key, then false is returned.
297
-     */
298
-    public function getData($key)
299
-    {
300
-        return isset($this->jsdata[$key])
301
-            ? $this->jsdata[$key]
302
-            : false;
303
-    }
304
-
305
-
306
-    /**
307
-     * Get the actual asset path for asset manifests.
308
-     * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
309
-     * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
310
-     *                           asset file location.
311
-     * @param string $chunk_name
312
-     * @param string $asset_type
313
-     * @return string
314
-     * @since 4.9.59.p
315
-     */
316
-    public function getAssetUrl($namespace, $chunk_name, $asset_type)
317
-    {
318
-        $url = isset(
319
-            $this->manifest_data[$namespace][$chunk_name][$asset_type],
320
-            $this->manifest_data[$namespace]['url_base']
321
-        )
322
-            ? $this->manifest_data[$namespace]['url_base']
323
-              . $this->manifest_data[$namespace][$chunk_name][$asset_type]
324
-            : $chunk_name;
325
-        return apply_filters(
326
-            'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
327
-            $url,
328
-            $namespace,
329
-            $chunk_name,
330
-            $asset_type
331
-        );
332
-    }
333
-
334
-
335
-    /**
336
-     * Return the url to a js file for the given namespace and chunk name.
337
-     *
338
-     * @param string $namespace
339
-     * @param string $chunk_name
340
-     * @return string
341
-     */
342
-    public function getJsUrl($namespace, $chunk_name)
343
-    {
344
-        return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_JS);
345
-    }
346
-
347
-
348
-    /**
349
-     * Return the url to a css file for the given namespace and chunk name.
350
-     *
351
-     * @param string $namespace
352
-     * @param string $chunk_name
353
-     * @return string
354
-     */
355
-    public function getCssUrl($namespace, $chunk_name)
356
-    {
357
-        return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_CSS);
358
-    }
359
-
360
-
361
-    /**
362
-     * Used to register a js/css manifest file with the registered_manifest_files property.
363
-     *
364
-     * @param string $namespace     Provided to associate the manifest file with a specific namespace.
365
-     * @param string $url_base      The url base for the manifest file location.
366
-     * @param string $manifest_file The absolute path to the manifest file.
367
-     * @throws InvalidArgumentException
368
-     * @throws InvalidFilePathException
369
-     * @since 4.9.59.p
370
-     */
371
-    public function registerManifestFile($namespace, $url_base, $manifest_file)
372
-    {
373
-        if (isset($this->manifest_data[$namespace])) {
374
-            throw new InvalidArgumentException(
375
-                sprintf(
376
-                    esc_html__(
377
-                        'The namespace for this manifest file has already been registered, choose a namespace other than %s',
378
-                        'event_espresso'
379
-                    ),
380
-                    $namespace
381
-                )
382
-            );
383
-        }
384
-        if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
385
-            throw new InvalidArgumentException(
386
-                sprintf(
387
-                    esc_html__(
388
-                        'The provided value for %1$s is not a valid url.  The url provided was: %2$s',
389
-                        'event_espresso'
390
-                    ),
391
-                    '$url_base',
392
-                    $url_base
393
-                )
394
-            );
395
-        }
396
-        $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file);
397
-        if (! isset($this->manifest_data[$namespace]['url_base'])) {
398
-            $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base);
399
-        }
400
-    }
401
-
402
-
403
-
404
-    /**
405
-     * Decodes json from the provided manifest file.
406
-     *
407
-     * @since 4.9.59.p
408
-     * @param string $manifest_file Path to manifest file.
409
-     * @return array
410
-     * @throws InvalidFilePathException
411
-     */
412
-    private function decodeManifestFile($manifest_file)
413
-    {
414
-        if (! file_exists($manifest_file)) {
415
-            throw new InvalidFilePathException($manifest_file);
416
-        }
417
-        return json_decode(file_get_contents($manifest_file), true);
418
-    }
419
-
420
-
421
-
422
-    /**
423
-     * Verifies whether the given data exists already on the jsdata array.
424
-     * Overriding data is not allowed.
425
-     *
426
-     * @param string $key Index for data.
427
-     * @return bool        If valid then return true.
428
-     * @throws InvalidArgumentException if data already exists.
429
-     */
430
-    protected function verifyDataNotExisting($key)
431
-    {
432
-        if (isset($this->jsdata[$key])) {
433
-            if (is_array($this->jsdata[$key])) {
434
-                throw new InvalidArgumentException(
435
-                    sprintf(
436
-                        __(
437
-                            'The value for %1$s already exists in the Registry::eejs object.
235
+						'event_espresso'
236
+					),
237
+					$key,
238
+					__METHOD__
239
+				)
240
+			);
241
+		}
242
+		$this->jsdata[$key][] = $value;
243
+	}
244
+
245
+
246
+
247
+	/**
248
+	 * Used to set content used by javascript for a template.
249
+	 * Note: Overrides of existing registered templates are not allowed.
250
+	 *
251
+	 * @param string $template_reference
252
+	 * @param string $template_content
253
+	 * @throws InvalidArgumentException
254
+	 */
255
+	public function addTemplate($template_reference, $template_content)
256
+	{
257
+		if (! isset($this->jsdata['templates'])) {
258
+			$this->jsdata['templates'] = array();
259
+		}
260
+		//no overrides allowed.
261
+		if (isset($this->jsdata['templates'][$template_reference])) {
262
+			throw new invalidArgumentException(
263
+				sprintf(
264
+					__(
265
+						'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
266
+						'event_espresso'
267
+					),
268
+					$template_reference
269
+				)
270
+			);
271
+		}
272
+		$this->jsdata['templates'][$template_reference] = $template_content;
273
+	}
274
+
275
+
276
+
277
+	/**
278
+	 * Retrieve the template content already registered for the given reference.
279
+	 *
280
+	 * @param string $template_reference
281
+	 * @return string
282
+	 */
283
+	public function getTemplate($template_reference)
284
+	{
285
+		return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference])
286
+			? $this->jsdata['templates'][$template_reference]
287
+			: '';
288
+	}
289
+
290
+
291
+
292
+	/**
293
+	 * Retrieve registered data.
294
+	 *
295
+	 * @param string $key Name of key to attach data to.
296
+	 * @return mixed                If there is no for the given key, then false is returned.
297
+	 */
298
+	public function getData($key)
299
+	{
300
+		return isset($this->jsdata[$key])
301
+			? $this->jsdata[$key]
302
+			: false;
303
+	}
304
+
305
+
306
+	/**
307
+	 * Get the actual asset path for asset manifests.
308
+	 * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
309
+	 * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
310
+	 *                           asset file location.
311
+	 * @param string $chunk_name
312
+	 * @param string $asset_type
313
+	 * @return string
314
+	 * @since 4.9.59.p
315
+	 */
316
+	public function getAssetUrl($namespace, $chunk_name, $asset_type)
317
+	{
318
+		$url = isset(
319
+			$this->manifest_data[$namespace][$chunk_name][$asset_type],
320
+			$this->manifest_data[$namespace]['url_base']
321
+		)
322
+			? $this->manifest_data[$namespace]['url_base']
323
+			  . $this->manifest_data[$namespace][$chunk_name][$asset_type]
324
+			: $chunk_name;
325
+		return apply_filters(
326
+			'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
327
+			$url,
328
+			$namespace,
329
+			$chunk_name,
330
+			$asset_type
331
+		);
332
+	}
333
+
334
+
335
+	/**
336
+	 * Return the url to a js file for the given namespace and chunk name.
337
+	 *
338
+	 * @param string $namespace
339
+	 * @param string $chunk_name
340
+	 * @return string
341
+	 */
342
+	public function getJsUrl($namespace, $chunk_name)
343
+	{
344
+		return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_JS);
345
+	}
346
+
347
+
348
+	/**
349
+	 * Return the url to a css file for the given namespace and chunk name.
350
+	 *
351
+	 * @param string $namespace
352
+	 * @param string $chunk_name
353
+	 * @return string
354
+	 */
355
+	public function getCssUrl($namespace, $chunk_name)
356
+	{
357
+		return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_CSS);
358
+	}
359
+
360
+
361
+	/**
362
+	 * Used to register a js/css manifest file with the registered_manifest_files property.
363
+	 *
364
+	 * @param string $namespace     Provided to associate the manifest file with a specific namespace.
365
+	 * @param string $url_base      The url base for the manifest file location.
366
+	 * @param string $manifest_file The absolute path to the manifest file.
367
+	 * @throws InvalidArgumentException
368
+	 * @throws InvalidFilePathException
369
+	 * @since 4.9.59.p
370
+	 */
371
+	public function registerManifestFile($namespace, $url_base, $manifest_file)
372
+	{
373
+		if (isset($this->manifest_data[$namespace])) {
374
+			throw new InvalidArgumentException(
375
+				sprintf(
376
+					esc_html__(
377
+						'The namespace for this manifest file has already been registered, choose a namespace other than %s',
378
+						'event_espresso'
379
+					),
380
+					$namespace
381
+				)
382
+			);
383
+		}
384
+		if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
385
+			throw new InvalidArgumentException(
386
+				sprintf(
387
+					esc_html__(
388
+						'The provided value for %1$s is not a valid url.  The url provided was: %2$s',
389
+						'event_espresso'
390
+					),
391
+					'$url_base',
392
+					$url_base
393
+				)
394
+			);
395
+		}
396
+		$this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file);
397
+		if (! isset($this->manifest_data[$namespace]['url_base'])) {
398
+			$this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base);
399
+		}
400
+	}
401
+
402
+
403
+
404
+	/**
405
+	 * Decodes json from the provided manifest file.
406
+	 *
407
+	 * @since 4.9.59.p
408
+	 * @param string $manifest_file Path to manifest file.
409
+	 * @return array
410
+	 * @throws InvalidFilePathException
411
+	 */
412
+	private function decodeManifestFile($manifest_file)
413
+	{
414
+		if (! file_exists($manifest_file)) {
415
+			throw new InvalidFilePathException($manifest_file);
416
+		}
417
+		return json_decode(file_get_contents($manifest_file), true);
418
+	}
419
+
420
+
421
+
422
+	/**
423
+	 * Verifies whether the given data exists already on the jsdata array.
424
+	 * Overriding data is not allowed.
425
+	 *
426
+	 * @param string $key Index for data.
427
+	 * @return bool        If valid then return true.
428
+	 * @throws InvalidArgumentException if data already exists.
429
+	 */
430
+	protected function verifyDataNotExisting($key)
431
+	{
432
+		if (isset($this->jsdata[$key])) {
433
+			if (is_array($this->jsdata[$key])) {
434
+				throw new InvalidArgumentException(
435
+					sprintf(
436
+						__(
437
+							'The value for %1$s already exists in the Registry::eejs object.
438 438
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
439 439
                             %2$s method to push your value to the array.',
440
-                            'event_espresso'
441
-                        ),
442
-                        $key,
443
-                        'pushData()'
444
-                    )
445
-                );
446
-            }
447
-            throw new InvalidArgumentException(
448
-                sprintf(
449
-                    __(
450
-                        'The value for %1$s already exists in the Registry::eejs object. Overrides are not
440
+							'event_espresso'
441
+						),
442
+						$key,
443
+						'pushData()'
444
+					)
445
+				);
446
+			}
447
+			throw new InvalidArgumentException(
448
+				sprintf(
449
+					__(
450
+						'The value for %1$s already exists in the Registry::eejs object. Overrides are not
451 451
                         allowed.  Consider attaching your value to a different key',
452
-                        'event_espresso'
453
-                    ),
454
-                    $key
455
-                )
456
-            );
457
-        }
458
-        return true;
459
-    }
460
-
461
-
462
-
463
-    /**
464
-     * registers core default stylesheets
465
-     */
466
-    private function loadCoreCss()
467
-    {
468
-        if ($this->template_config->enable_default_style) {
469
-            $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
470
-                ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
471
-                : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
472
-            wp_register_style(
473
-                'espresso_default',
474
-                $default_stylesheet_path,
475
-                array('dashicons'),
476
-                EVENT_ESPRESSO_VERSION
477
-            );
478
-            //Load custom style sheet if available
479
-            if ($this->template_config->custom_style_sheet !== null) {
480
-                wp_register_style(
481
-                    'espresso_custom_css',
482
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
483
-                    array('espresso_default'),
484
-                    EVENT_ESPRESSO_VERSION
485
-                );
486
-            }
487
-        }
488
-    }
489
-
490
-
491
-
492
-    /**
493
-     * registers core default javascript
494
-     */
495
-    private function loadCoreJs()
496
-    {
497
-        // load core js
498
-        wp_register_script(
499
-            'espresso_core',
500
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
501
-            array('jquery'),
502
-            EVENT_ESPRESSO_VERSION,
503
-            true
504
-        );
505
-    }
506
-
507
-
508
-
509
-    /**
510
-     * registers jQuery Validate for form validation
511
-     */
512
-    private function loadJqueryValidate()
513
-    {
514
-        // register jQuery Validate and additional methods
515
-        wp_register_script(
516
-            'jquery-validate',
517
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
518
-            array('jquery'),
519
-            '1.15.0',
520
-            true
521
-        );
522
-        wp_register_script(
523
-            'jquery-validate-extra-methods',
524
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
525
-            array('jquery', 'jquery-validate'),
526
-            '1.15.0',
527
-            true
528
-        );
529
-    }
530
-
531
-
532
-
533
-    /**
534
-     * registers accounting.js for performing client-side calculations
535
-     */
536
-    private function loadAccountingJs()
537
-    {
538
-        //accounting.js library
539
-        // @link http://josscrowcroft.github.io/accounting.js/
540
-        wp_register_script(
541
-            'ee-accounting-core',
542
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
543
-            array('underscore'),
544
-            '0.3.2',
545
-            true
546
-        );
547
-        wp_register_script(
548
-            'ee-accounting',
549
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
550
-            array('ee-accounting-core'),
551
-            EVENT_ESPRESSO_VERSION,
552
-            true
553
-        );
554
-    }
555
-
556
-
557
-
558
-    /**
559
-     * registers accounting.js for performing client-side calculations
560
-     */
561
-    private function localizeAccountingJs()
562
-    {
563
-        wp_localize_script(
564
-            'ee-accounting',
565
-            'EE_ACCOUNTING_CFG',
566
-            array(
567
-                'currency' => array(
568
-                    'symbol'    => $this->currency_config->sign,
569
-                    'format'    => array(
570
-                        'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
571
-                        'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
572
-                        'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
573
-                    ),
574
-                    'decimal'   => $this->currency_config->dec_mrk,
575
-                    'thousand'  => $this->currency_config->thsnds,
576
-                    'precision' => $this->currency_config->dec_plc,
577
-                ),
578
-                'number'   => array(
579
-                    'precision' => $this->currency_config->dec_plc,
580
-                    'thousand'  => $this->currency_config->thsnds,
581
-                    'decimal'   => $this->currency_config->dec_mrk,
582
-                ),
583
-            )
584
-        );
585
-        $this->addRegisteredScriptHandlesWithData('ee-accounting');
586
-    }
587
-
588
-
589
-
590
-    /**
591
-     * registers assets for cleaning your ears
592
-     */
593
-    private function loadQtipJs()
594
-    {
595
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
596
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
597
-        if (apply_filters('FHEE_load_qtip', false)) {
598
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
599
-        }
600
-    }
601
-
602
-
603
-    /**
604
-     * This is used to set registered script handles that have data.
605
-     * @param string $script_handle
606
-     */
607
-    private function addRegisteredScriptHandlesWithData($script_handle)
608
-    {
609
-        $this->script_handles_with_data[$script_handle] = $script_handle;
610
-    }
611
-
612
-
613
-    /**
614
-     * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
615
-     * Dependency stored in WP_Scripts if its set.
616
-     */
617
-    private function removeAlreadyRegisteredDataForScriptHandles()
618
-    {
619
-        if (empty($this->script_handles_with_data)) {
620
-            return;
621
-        }
622
-        foreach ($this->script_handles_with_data as $script_handle) {
623
-            $this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
624
-        }
625
-    }
626
-
627
-
628
-    /**
629
-     * Removes any data dependency registered in WP_Scripts if its set.
630
-     * @param string $script_handle
631
-     */
632
-    private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
633
-    {
634
-        if (isset($this->script_handles_with_data[$script_handle])) {
635
-            global $wp_scripts;
636
-            if ($wp_scripts->get_data($script_handle, 'data')) {
637
-                unset($wp_scripts->registered[$script_handle]->extra['data']);
638
-                unset($this->script_handles_with_data[$script_handle]);
639
-            }
640
-        }
641
-    }
642
-
643
-
644
-    /**
645
-     * Registers assets that are used in the WordPress admin.
646
-     */
647
-    private function registerAdminAssets()
648
-    {
649
-        wp_register_script(
650
-            'ee-wp-plugins-page',
651
-            $this->getJsUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'),
652
-            array(
653
-                'jquery',
654
-                'ee-vendor-react'
655
-            ),
656
-            null,
657
-            true
658
-        );
659
-        wp_register_style(
660
-            'ee-wp-plugins-page',
661
-            $this->getCssUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'),
662
-            array(),
663
-            null
664
-        );
665
-    }
452
+						'event_espresso'
453
+					),
454
+					$key
455
+				)
456
+			);
457
+		}
458
+		return true;
459
+	}
460
+
461
+
462
+
463
+	/**
464
+	 * registers core default stylesheets
465
+	 */
466
+	private function loadCoreCss()
467
+	{
468
+		if ($this->template_config->enable_default_style) {
469
+			$default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
470
+				? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
471
+				: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
472
+			wp_register_style(
473
+				'espresso_default',
474
+				$default_stylesheet_path,
475
+				array('dashicons'),
476
+				EVENT_ESPRESSO_VERSION
477
+			);
478
+			//Load custom style sheet if available
479
+			if ($this->template_config->custom_style_sheet !== null) {
480
+				wp_register_style(
481
+					'espresso_custom_css',
482
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
483
+					array('espresso_default'),
484
+					EVENT_ESPRESSO_VERSION
485
+				);
486
+			}
487
+		}
488
+	}
489
+
490
+
491
+
492
+	/**
493
+	 * registers core default javascript
494
+	 */
495
+	private function loadCoreJs()
496
+	{
497
+		// load core js
498
+		wp_register_script(
499
+			'espresso_core',
500
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
501
+			array('jquery'),
502
+			EVENT_ESPRESSO_VERSION,
503
+			true
504
+		);
505
+	}
506
+
507
+
508
+
509
+	/**
510
+	 * registers jQuery Validate for form validation
511
+	 */
512
+	private function loadJqueryValidate()
513
+	{
514
+		// register jQuery Validate and additional methods
515
+		wp_register_script(
516
+			'jquery-validate',
517
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
518
+			array('jquery'),
519
+			'1.15.0',
520
+			true
521
+		);
522
+		wp_register_script(
523
+			'jquery-validate-extra-methods',
524
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
525
+			array('jquery', 'jquery-validate'),
526
+			'1.15.0',
527
+			true
528
+		);
529
+	}
530
+
531
+
532
+
533
+	/**
534
+	 * registers accounting.js for performing client-side calculations
535
+	 */
536
+	private function loadAccountingJs()
537
+	{
538
+		//accounting.js library
539
+		// @link http://josscrowcroft.github.io/accounting.js/
540
+		wp_register_script(
541
+			'ee-accounting-core',
542
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
543
+			array('underscore'),
544
+			'0.3.2',
545
+			true
546
+		);
547
+		wp_register_script(
548
+			'ee-accounting',
549
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
550
+			array('ee-accounting-core'),
551
+			EVENT_ESPRESSO_VERSION,
552
+			true
553
+		);
554
+	}
555
+
556
+
557
+
558
+	/**
559
+	 * registers accounting.js for performing client-side calculations
560
+	 */
561
+	private function localizeAccountingJs()
562
+	{
563
+		wp_localize_script(
564
+			'ee-accounting',
565
+			'EE_ACCOUNTING_CFG',
566
+			array(
567
+				'currency' => array(
568
+					'symbol'    => $this->currency_config->sign,
569
+					'format'    => array(
570
+						'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
571
+						'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
572
+						'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
573
+					),
574
+					'decimal'   => $this->currency_config->dec_mrk,
575
+					'thousand'  => $this->currency_config->thsnds,
576
+					'precision' => $this->currency_config->dec_plc,
577
+				),
578
+				'number'   => array(
579
+					'precision' => $this->currency_config->dec_plc,
580
+					'thousand'  => $this->currency_config->thsnds,
581
+					'decimal'   => $this->currency_config->dec_mrk,
582
+				),
583
+			)
584
+		);
585
+		$this->addRegisteredScriptHandlesWithData('ee-accounting');
586
+	}
587
+
588
+
589
+
590
+	/**
591
+	 * registers assets for cleaning your ears
592
+	 */
593
+	private function loadQtipJs()
594
+	{
595
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
596
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
597
+		if (apply_filters('FHEE_load_qtip', false)) {
598
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
599
+		}
600
+	}
601
+
602
+
603
+	/**
604
+	 * This is used to set registered script handles that have data.
605
+	 * @param string $script_handle
606
+	 */
607
+	private function addRegisteredScriptHandlesWithData($script_handle)
608
+	{
609
+		$this->script_handles_with_data[$script_handle] = $script_handle;
610
+	}
611
+
612
+
613
+	/**
614
+	 * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
615
+	 * Dependency stored in WP_Scripts if its set.
616
+	 */
617
+	private function removeAlreadyRegisteredDataForScriptHandles()
618
+	{
619
+		if (empty($this->script_handles_with_data)) {
620
+			return;
621
+		}
622
+		foreach ($this->script_handles_with_data as $script_handle) {
623
+			$this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
624
+		}
625
+	}
626
+
627
+
628
+	/**
629
+	 * Removes any data dependency registered in WP_Scripts if its set.
630
+	 * @param string $script_handle
631
+	 */
632
+	private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
633
+	{
634
+		if (isset($this->script_handles_with_data[$script_handle])) {
635
+			global $wp_scripts;
636
+			if ($wp_scripts->get_data($script_handle, 'data')) {
637
+				unset($wp_scripts->registered[$script_handle]->extra['data']);
638
+				unset($this->script_handles_with_data[$script_handle]);
639
+			}
640
+		}
641
+	}
642
+
643
+
644
+	/**
645
+	 * Registers assets that are used in the WordPress admin.
646
+	 */
647
+	private function registerAdminAssets()
648
+	{
649
+		wp_register_script(
650
+			'ee-wp-plugins-page',
651
+			$this->getJsUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'),
652
+			array(
653
+				'jquery',
654
+				'ee-vendor-react'
655
+			),
656
+			null,
657
+			true
658
+		);
659
+		wp_register_style(
660
+			'ee-wp-plugins-page',
661
+			$this->getCssUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'),
662
+			array(),
663
+			null
664
+		);
665
+	}
666 666
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Proper.form.php 1 patch
Indentation   +1524 added lines, -1524 removed lines patch added patch discarded remove patch
@@ -14,1529 +14,1529 @@
 block discarded – undo
14 14
 class EE_Form_Section_Proper extends EE_Form_Section_Validatable
15 15
 {
16 16
 
17
-    const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
18
-
19
-    /**
20
-     * Subsections
21
-     *
22
-     * @var EE_Form_Section_Validatable[]
23
-     */
24
-    protected $_subsections = array();
25
-
26
-    /**
27
-     * Strategy for laying out the form
28
-     *
29
-     * @var EE_Form_Section_Layout_Base
30
-     */
31
-    protected $_layout_strategy;
32
-
33
-    /**
34
-     * Whether or not this form has received and validated a form submission yet
35
-     *
36
-     * @var boolean
37
-     */
38
-    protected $_received_submission = false;
39
-
40
-    /**
41
-     * message displayed to users upon successful form submission
42
-     *
43
-     * @var string
44
-     */
45
-    protected $_form_submission_success_message = '';
46
-
47
-    /**
48
-     * message displayed to users upon unsuccessful form submission
49
-     *
50
-     * @var string
51
-     */
52
-    protected $_form_submission_error_message = '';
53
-
54
-    /**
55
-     * @var array like $_REQUEST
56
-     */
57
-    protected $cached_request_data;
58
-
59
-    /**
60
-     * Stores whether this form (and its sub-sections) were found to be valid or not.
61
-     * Starts off as null, but once the form is validated, it set to either true or false
62
-     * @var boolean|null
63
-     */
64
-    protected $is_valid;
65
-
66
-    /**
67
-     * Stores all the data that will localized for form validation
68
-     *
69
-     * @var array
70
-     */
71
-    static protected $_js_localization = array();
72
-
73
-    /**
74
-     * whether or not the form's localized validation JS vars have been set
75
-     *
76
-     * @type boolean
77
-     */
78
-    static protected $_scripts_localized = false;
79
-
80
-
81
-    /**
82
-     * when constructing a proper form section, calls _construct_finalize on children
83
-     * so that they know who their parent is, and what name they've been given.
84
-     *
85
-     * @param array[] $options_array   {
86
-     * @type          $subsections     EE_Form_Section_Validatable[] where keys are the section's name
87
-     * @type          $include         string[] numerically-indexed where values are section names to be included,
88
-     *                                 and in that order. This is handy if you want
89
-     *                                 the subsections to be ordered differently than the default, and if you override
90
-     *                                 which fields are shown
91
-     * @type          $exclude         string[] values are subsections to be excluded. This is handy if you want
92
-     *                                 to remove certain default subsections (note: if you specify BOTH 'include' AND
93
-     *                                 'exclude', the inclusions will be applied first, and the exclusions will exclude
94
-     *                                 items from that list of inclusions)
95
-     * @type          $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
96
-     *                                 } @see EE_Form_Section_Validatable::__construct()
97
-     * @throws EE_Error
98
-     */
99
-    public function __construct($options_array = array())
100
-    {
101
-        $options_array = (array) apply_filters(
102
-            'FHEE__EE_Form_Section_Proper___construct__options_array',
103
-            $options_array,
104
-            $this
105
-        );
106
-        //call parent first, as it may be setting the name
107
-        parent::__construct($options_array);
108
-        //if they've included subsections in the constructor, add them now
109
-        if (isset($options_array['include'])) {
110
-            //we are going to make sure we ONLY have those subsections to include
111
-            //AND we are going to make sure they're in that specified order
112
-            $reordered_subsections = array();
113
-            foreach ($options_array['include'] as $input_name) {
114
-                if (isset($this->_subsections[ $input_name ])) {
115
-                    $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ];
116
-                }
117
-            }
118
-            $this->_subsections = $reordered_subsections;
119
-        }
120
-        if (isset($options_array['exclude'])) {
121
-            $exclude            = $options_array['exclude'];
122
-            $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
123
-        }
124
-        if (isset($options_array['layout_strategy'])) {
125
-            $this->_layout_strategy = $options_array['layout_strategy'];
126
-        }
127
-        if (! $this->_layout_strategy) {
128
-            $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
129
-        }
130
-        $this->_layout_strategy->_construct_finalize($this);
131
-        //ok so we are definitely going to want the forms JS,
132
-        //so enqueue it or remember to enqueue it during wp_enqueue_scripts
133
-        if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
134
-            //ok so they've constructed this object after when they should have.
135
-            //just enqueue the generic form scripts and initialize the form immediately in the JS
136
-            EE_Form_Section_Proper::wp_enqueue_scripts(true);
137
-        } else {
138
-            add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
139
-            add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
140
-        }
141
-        add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
142
-        /**
143
-         * Gives other plugins a chance to hook in before construct finalize is called.
144
-         * The form probably doesn't yet have a parent form section.
145
-         * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form,
146
-         * assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
147
-         * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
148
-         *
149
-         * @since 4.9.32
150
-         * @param EE_Form_Section_Proper $this          before __construct is done, but all of its logic,
151
-         *                                              except maybe calling _construct_finalize has been done
152
-         * @param array                  $options_array options passed into the constructor
153
-         */
154
-        do_action(
155
-            'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called',
156
-            $this,
157
-            $options_array
158
-        );
159
-        if (isset($options_array['name'])) {
160
-            $this->_construct_finalize(null, $options_array['name']);
161
-        }
162
-    }
163
-
164
-
165
-    /**
166
-     * Finishes construction given the parent form section and this form section's name
167
-     *
168
-     * @param EE_Form_Section_Proper $parent_form_section
169
-     * @param string                 $name
170
-     * @throws EE_Error
171
-     */
172
-    public function _construct_finalize($parent_form_section, $name)
173
-    {
174
-        parent::_construct_finalize($parent_form_section, $name);
175
-        $this->_set_default_name_if_empty();
176
-        $this->_set_default_html_id_if_empty();
177
-        foreach ($this->_subsections as $subsection_name => $subsection) {
178
-            if ($subsection instanceof EE_Form_Section_Base) {
179
-                $subsection->_construct_finalize($this, $subsection_name);
180
-            } else {
181
-                throw new EE_Error(
182
-                    sprintf(
183
-                        esc_html__(
184
-                            'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
185
-                            'event_espresso'
186
-                        ),
187
-                        $subsection_name,
188
-                        get_class($this),
189
-                        $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
190
-                    )
191
-                );
192
-            }
193
-        }
194
-        /**
195
-         * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
196
-         * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID
197
-         * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done.
198
-         * This might only happen just before displaying the form, or just before it receives form submission data.
199
-         * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
200
-         * ensured it has a name, HTML IDs, etc
201
-         *
202
-         * @param EE_Form_Section_Proper      $this
203
-         * @param EE_Form_Section_Proper|null $parent_form_section
204
-         * @param string                      $name
205
-         */
206
-        do_action(
207
-            'AHEE__EE_Form_Section_Proper___construct_finalize__end',
208
-            $this,
209
-            $parent_form_section,
210
-            $name
211
-        );
212
-    }
213
-
214
-
215
-    /**
216
-     * Gets the layout strategy for this form section
217
-     *
218
-     * @return EE_Form_Section_Layout_Base
219
-     */
220
-    public function get_layout_strategy()
221
-    {
222
-        return $this->_layout_strategy;
223
-    }
224
-
225
-
226
-    /**
227
-     * Gets the HTML for a single input for this form section according
228
-     * to the layout strategy
229
-     *
230
-     * @param EE_Form_Input_Base $input
231
-     * @return string
232
-     */
233
-    public function get_html_for_input($input)
234
-    {
235
-        return $this->_layout_strategy->layout_input($input);
236
-    }
237
-
238
-
239
-    /**
240
-     * was_submitted - checks if form inputs are present in request data
241
-     * Basically an alias for form_data_present_in() (which is used by both
242
-     * proper form sections and form inputs)
243
-     *
244
-     * @param null $form_data
245
-     * @return boolean
246
-     * @throws EE_Error
247
-     */
248
-    public function was_submitted($form_data = null)
249
-    {
250
-        return $this->form_data_present_in($form_data);
251
-    }
252
-
253
-    /**
254
-     * Gets the cached request data; but if there is none, or $req_data was set with
255
-     * something different, refresh the cache, and then return it
256
-     * @param null $req_data
257
-     * @return array
258
-     */
259
-    protected function getCachedRequest($req_data = null)
260
-    {
261
-        if ($this->cached_request_data === null
262
-            || (
263
-                $req_data !== null &&
264
-                $req_data !== $this->cached_request_data
265
-            )
266
-        ) {
267
-            $req_data = apply_filters(
268
-                'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data',
269
-                $req_data,
270
-                $this
271
-            );
272
-            if ($req_data === null) {
273
-                $req_data = array_merge($_GET, $_POST);
274
-            }
275
-            $req_data = apply_filters(
276
-                'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
277
-                $req_data,
278
-                $this
279
-            );
280
-            $this->cached_request_data = (array)$req_data;
281
-        }
282
-        return $this->cached_request_data;
283
-    }
284
-
285
-
286
-    /**
287
-     * After the form section is initially created, call this to sanitize the data in the submission
288
-     * which relates to this form section, validate it, and set it as properties on the form.
289
-     *
290
-     * @param array|null $req_data should usually be $_POST (the default).
291
-     *                             However, you CAN supply a different array.
292
-     *                             Consider using set_defaults() instead however.
293
-     *                             (If you rendered the form in the page using echo $form_x->get_html()
294
-     *                             the inputs will have the correct name in the request data for this function
295
-     *                             to find them and populate the form with them.
296
-     *                             If you have a flat form (with only input subsections),
297
-     *                             you can supply a flat array where keys
298
-     *                             are the form input names and values are their values)
299
-     * @param boolean    $validate whether or not to perform validation on this data. Default is,
300
-     *                             of course, to validate that data, and set errors on the invalid values.
301
-     *                             But if the data has already been validated
302
-     *                             (eg you validated the data then stored it in the DB)
303
-     *                             you may want to skip this step.
304
-     * @throws InvalidArgumentException
305
-     * @throws InvalidInterfaceException
306
-     * @throws InvalidDataTypeException
307
-     * @throws EE_Error
308
-     */
309
-    public function receive_form_submission($req_data = null, $validate = true)
310
-    {
311
-        $req_data = $this->getCachedRequest($req_data);
312
-        $this->_normalize($req_data);
313
-        if ($validate) {
314
-            $this->_validate();
315
-            //if it's invalid, we're going to want to re-display so remember what they submitted
316
-            if (! $this->is_valid()) {
317
-                $this->store_submitted_form_data_in_session();
318
-            }
319
-        }
320
-        if ($this->submission_error_message() === '' && ! $this->is_valid()) {
321
-            $this->set_submission_error_message();
322
-        }
323
-        do_action(
324
-            'AHEE__EE_Form_Section_Proper__receive_form_submission__end',
325
-            $req_data,
326
-            $this,
327
-            $validate
328
-        );
329
-    }
330
-
331
-
332
-    /**
333
-     * caches the originally submitted input values in the session
334
-     * so that they can be used to repopulate the form if it failed validation
335
-     *
336
-     * @return boolean whether or not the data was successfully stored in the session
337
-     * @throws InvalidArgumentException
338
-     * @throws InvalidInterfaceException
339
-     * @throws InvalidDataTypeException
340
-     * @throws EE_Error
341
-     */
342
-    protected function store_submitted_form_data_in_session()
343
-    {
344
-        return EE_Registry::instance()->SSN->set_session_data(
345
-            array(
346
-                EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
347
-            )
348
-        );
349
-    }
350
-
351
-
352
-    /**
353
-     * retrieves the originally submitted input values in the session
354
-     * so that they can be used to repopulate the form if it failed validation
355
-     *
356
-     * @return array
357
-     * @throws InvalidArgumentException
358
-     * @throws InvalidInterfaceException
359
-     * @throws InvalidDataTypeException
360
-     */
361
-    protected function get_submitted_form_data_from_session()
362
-    {
363
-        $session = EE_Registry::instance()->SSN;
364
-        if ($session instanceof EE_Session) {
365
-            return $session->get_session_data(
366
-                EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
367
-            );
368
-        }
369
-        return array();
370
-    }
371
-
372
-
373
-    /**
374
-     * flushed the originally submitted input values from the session
375
-     *
376
-     * @return boolean whether or not the data was successfully removed from the session
377
-     * @throws InvalidArgumentException
378
-     * @throws InvalidInterfaceException
379
-     * @throws InvalidDataTypeException
380
-     */
381
-    protected function flush_submitted_form_data_from_session()
382
-    {
383
-        return EE_Registry::instance()->SSN->reset_data(
384
-            array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
385
-        );
386
-    }
387
-
388
-
389
-    /**
390
-     * Populates this form and its subsections with data from the session.
391
-     * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
392
-     * validation errors when displaying too)
393
-     * Returns true if the form was populated from the session, false otherwise
394
-     *
395
-     * @return boolean
396
-     * @throws InvalidArgumentException
397
-     * @throws InvalidInterfaceException
398
-     * @throws InvalidDataTypeException
399
-     * @throws EE_Error
400
-     */
401
-    public function populate_from_session()
402
-    {
403
-        $form_data_in_session = $this->get_submitted_form_data_from_session();
404
-        if (empty($form_data_in_session)) {
405
-            return false;
406
-        }
407
-        $this->receive_form_submission($form_data_in_session);
408
-        $this->flush_submitted_form_data_from_session();
409
-        if ($this->form_data_present_in($form_data_in_session)) {
410
-            return true;
411
-        }
412
-        return false;
413
-    }
414
-
415
-
416
-    /**
417
-     * Populates the default data for the form, given an array where keys are
418
-     * the input names, and values are their values (preferably normalized to be their
419
-     * proper PHP types, not all strings... although that should be ok too).
420
-     * Proper subsections are sub-arrays, the key being the subsection's name, and
421
-     * the value being an array formatted in teh same way
422
-     *
423
-     * @param array $default_data
424
-     * @throws EE_Error
425
-     */
426
-    public function populate_defaults($default_data)
427
-    {
428
-        foreach ($this->subsections(false) as $subsection_name => $subsection) {
429
-            if (isset($default_data[ $subsection_name ])) {
430
-                if ($subsection instanceof EE_Form_Input_Base) {
431
-                    $subsection->set_default($default_data[ $subsection_name ]);
432
-                } elseif ($subsection instanceof EE_Form_Section_Proper) {
433
-                    $subsection->populate_defaults($default_data[ $subsection_name ]);
434
-                }
435
-            }
436
-        }
437
-    }
438
-
439
-
440
-    /**
441
-     * returns true if subsection exists
442
-     *
443
-     * @param string $name
444
-     * @return boolean
445
-     */
446
-    public function subsection_exists($name)
447
-    {
448
-        return isset($this->_subsections[ $name ]) ? true : false;
449
-    }
450
-
451
-
452
-    /**
453
-     * Gets the subsection specified by its name
454
-     *
455
-     * @param string  $name
456
-     * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
457
-     *                                                      so that the inputs will be properly configured.
458
-     *                                                      However, some client code may be ok
459
-     *                                                      with construction finalize being called later
460
-     *                                                      (realizing that the subsections' html names
461
-     *                                                      might not be set yet, etc.)
462
-     * @return EE_Form_Section_Base
463
-     * @throws EE_Error
464
-     */
465
-    public function get_subsection($name, $require_construction_to_be_finalized = true)
466
-    {
467
-        if ($require_construction_to_be_finalized) {
468
-            $this->ensure_construct_finalized_called();
469
-        }
470
-        return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null;
471
-    }
472
-
473
-
474
-    /**
475
-     * Gets all the validatable subsections of this form section
476
-     *
477
-     * @return EE_Form_Section_Validatable[]
478
-     * @throws EE_Error
479
-     */
480
-    public function get_validatable_subsections()
481
-    {
482
-        $validatable_subsections = array();
483
-        foreach ($this->subsections() as $name => $obj) {
484
-            if ($obj instanceof EE_Form_Section_Validatable) {
485
-                $validatable_subsections[ $name ] = $obj;
486
-            }
487
-        }
488
-        return $validatable_subsections;
489
-    }
490
-
491
-
492
-    /**
493
-     * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
494
-     * throw an EE_Error.
495
-     *
496
-     * @param string  $name
497
-     * @param boolean $require_construction_to_be_finalized most client code should
498
-     *                                                      leave this as TRUE so that the inputs will be properly
499
-     *                                                      configured. However, some client code may be ok with
500
-     *                                                      construction finalize being called later
501
-     *                                                      (realizing that the subsections' html names might not be
502
-     *                                                      set yet, etc.)
503
-     * @return EE_Form_Input_Base
504
-     * @throws EE_Error
505
-     */
506
-    public function get_input($name, $require_construction_to_be_finalized = true)
507
-    {
508
-        $subsection = $this->get_subsection(
509
-            $name,
510
-            $require_construction_to_be_finalized
511
-        );
512
-        if (! $subsection instanceof EE_Form_Input_Base) {
513
-            throw new EE_Error(
514
-                sprintf(
515
-                    esc_html__(
516
-                        "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
517
-                        'event_espresso'
518
-                    ),
519
-                    $name,
520
-                    get_class($this),
521
-                    $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
522
-                )
523
-            );
524
-        }
525
-        return $subsection;
526
-    }
527
-
528
-
529
-    /**
530
-     * Like get_input(), gets the proper subsection of the form given the name,
531
-     * otherwise throws an EE_Error
532
-     *
533
-     * @param string  $name
534
-     * @param boolean $require_construction_to_be_finalized most client code should
535
-     *                                                      leave this as TRUE so that the inputs will be properly
536
-     *                                                      configured. However, some client code may be ok with
537
-     *                                                      construction finalize being called later
538
-     *                                                      (realizing that the subsections' html names might not be
539
-     *                                                      set yet, etc.)
540
-     * @return EE_Form_Section_Proper
541
-     * @throws EE_Error
542
-     */
543
-    public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
544
-    {
545
-        $subsection = $this->get_subsection(
546
-            $name,
547
-            $require_construction_to_be_finalized
548
-        );
549
-        if (! $subsection instanceof EE_Form_Section_Proper) {
550
-            throw new EE_Error(
551
-                sprintf(
552
-                    esc_html__(
553
-                        "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'",
554
-                        'event_espresso'
555
-                    ),
556
-                    $name,
557
-                    get_class($this)
558
-                )
559
-            );
560
-        }
561
-        return $subsection;
562
-    }
563
-
564
-
565
-    /**
566
-     * Gets the value of the specified input. Should be called after receive_form_submission()
567
-     * or populate_defaults() on the form, where the normalized value on the input is set.
568
-     *
569
-     * @param string $name
570
-     * @return mixed depending on the input's type and its normalization strategy
571
-     * @throws EE_Error
572
-     */
573
-    public function get_input_value($name)
574
-    {
575
-        $input = $this->get_input($name);
576
-        return $input->normalized_value();
577
-    }
578
-
579
-
580
-    /**
581
-     * Checks if this form section itself is valid, and then checks its subsections
582
-     *
583
-     * @throws EE_Error
584
-     * @return boolean
585
-     */
586
-    public function is_valid()
587
-    {
588
-        if($this->is_valid === null) {
589
-            if (! $this->has_received_submission()) {
590
-                throw new EE_Error(
591
-                    sprintf(
592
-                        esc_html__(
593
-                            'You cannot check if a form is valid before receiving the form submission using receive_form_submission',
594
-                            'event_espresso'
595
-                        )
596
-                    )
597
-                );
598
-            }
599
-            if (! parent::is_valid()) {
600
-                $this->is_valid = false;
601
-            } else {
602
-                // ok so no general errors to this entire form section.
603
-                // so let's check the subsections, but only set errors if that hasn't been done yet
604
-                $this->is_valid = true;
605
-                foreach ($this->get_validatable_subsections() as $subsection) {
606
-                    if (! $subsection->is_valid()) {
607
-                        $this->is_valid = false;
608
-                    }
609
-                }
610
-            }
611
-        }
612
-        return $this->is_valid;
613
-    }
614
-
615
-
616
-    /**
617
-     * gets the default name of this form section if none is specified
618
-     *
619
-     * @return void
620
-     */
621
-    protected function _set_default_name_if_empty()
622
-    {
623
-        if (! $this->_name) {
624
-            $classname    = get_class($this);
625
-            $default_name = str_replace('EE_', '', $classname);
626
-            $this->_name  = $default_name;
627
-        }
628
-    }
629
-
630
-
631
-    /**
632
-     * Returns the HTML for the form, except for the form opening and closing tags
633
-     * (as the form section doesn't know where you necessarily want to send the information to),
634
-     * and except for a submit button. Enqueues JS and CSS; if called early enough we will
635
-     * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
636
-     * Not doing_it_wrong because theoretically this CAN be used properly,
637
-     * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
638
-     * any CSS.
639
-     *
640
-     * @throws InvalidArgumentException
641
-     * @throws InvalidInterfaceException
642
-     * @throws InvalidDataTypeException
643
-     * @throws EE_Error
644
-     */
645
-    public function get_html_and_js()
646
-    {
647
-        $this->enqueue_js();
648
-        return $this->get_html();
649
-    }
650
-
651
-
652
-    /**
653
-     * returns HTML for displaying this form section. recursively calls display_section() on all subsections
654
-     *
655
-     * @param bool $display_previously_submitted_data
656
-     * @return string
657
-     * @throws InvalidArgumentException
658
-     * @throws InvalidInterfaceException
659
-     * @throws InvalidDataTypeException
660
-     * @throws EE_Error
661
-     * @throws EE_Error
662
-     * @throws EE_Error
663
-     */
664
-    public function get_html($display_previously_submitted_data = true)
665
-    {
666
-        $this->ensure_construct_finalized_called();
667
-        if ($display_previously_submitted_data) {
668
-            $this->populate_from_session();
669
-        }
670
-        return $this->_form_html_filter
671
-            ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
672
-            : $this->_layout_strategy->layout_form();
673
-    }
674
-
675
-
676
-    /**
677
-     * enqueues JS and CSS for the form.
678
-     * It is preferred to call this before wp_enqueue_scripts so the
679
-     * scripts and styles can be put in the header, but if called later
680
-     * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
681
-     * only be in the header; but in HTML5 its ok in the body.
682
-     * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
683
-     * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
684
-     *
685
-     * @return void
686
-     * @throws EE_Error
687
-     */
688
-    public function enqueue_js()
689
-    {
690
-        $this->_enqueue_and_localize_form_js();
691
-        foreach ($this->subsections() as $subsection) {
692
-            $subsection->enqueue_js();
693
-        }
694
-    }
695
-
696
-
697
-    /**
698
-     * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
699
-     * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
700
-     * the wp_enqueue_scripts hook.
701
-     * However, registering the form js and localizing it can happen when we
702
-     * actually output the form (which is preferred, seeing how teh form's fields
703
-     * could change until it's actually outputted)
704
-     *
705
-     * @param boolean $init_form_validation_automatically whether or not we want the form validation
706
-     *                                                    to be triggered automatically or not
707
-     * @return void
708
-     */
709
-    public static function wp_enqueue_scripts($init_form_validation_automatically = true)
710
-    {
711
-        wp_register_script(
712
-            'ee_form_section_validation',
713
-            EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
714
-            array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
715
-            EVENT_ESPRESSO_VERSION,
716
-            true
717
-        );
718
-        wp_localize_script(
719
-            'ee_form_section_validation',
720
-            'ee_form_section_validation_init',
721
-            array('init' => $init_form_validation_automatically ? '1' : '0')
722
-        );
723
-    }
724
-
725
-
726
-    /**
727
-     * gets the variables used by form_section_validation.js.
728
-     * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
729
-     * but before the wordpress hook wp_loaded
730
-     *
731
-     * @throws EE_Error
732
-     */
733
-    public function _enqueue_and_localize_form_js()
734
-    {
735
-        $this->ensure_construct_finalized_called();
736
-        //actually, we don't want to localize just yet. There may be other forms on the page.
737
-        //so we need to add our form section data to a static variable accessible by all form sections
738
-        //and localize it just before the footer
739
-        $this->localize_validation_rules();
740
-        add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
741
-        add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
742
-    }
743
-
744
-
745
-    /**
746
-     * add our form section data to a static variable accessible by all form sections
747
-     *
748
-     * @param bool $return_for_subsection
749
-     * @return void
750
-     * @throws EE_Error
751
-     */
752
-    public function localize_validation_rules($return_for_subsection = false)
753
-    {
754
-        // we only want to localize vars ONCE for the entire form,
755
-        // so if the form section doesn't have a parent, then it must be the top dog
756
-        if ($return_for_subsection || ! $this->parent_section()) {
757
-            EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array(
758
-                'form_section_id'  => $this->html_id(true),
759
-                'validation_rules' => $this->get_jquery_validation_rules(),
760
-                'other_data'       => $this->get_other_js_data(),
761
-                'errors'           => $this->subsection_validation_errors_by_html_name(),
762
-            );
763
-            EE_Form_Section_Proper::$_scripts_localized                                = true;
764
-        }
765
-    }
766
-
767
-
768
-    /**
769
-     * Gets an array of extra data that will be useful for client-side javascript.
770
-     * This is primarily data added by inputs and forms in addition to any
771
-     * scripts they might enqueue
772
-     *
773
-     * @param array $form_other_js_data
774
-     * @return array
775
-     * @throws EE_Error
776
-     */
777
-    public function get_other_js_data($form_other_js_data = array())
778
-    {
779
-        foreach ($this->subsections() as $subsection) {
780
-            $form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
781
-        }
782
-        return $form_other_js_data;
783
-    }
784
-
785
-
786
-    /**
787
-     * Gets a flat array of inputs for this form section and its subsections.
788
-     * Keys are their form names, and values are the inputs themselves
789
-     *
790
-     * @return EE_Form_Input_Base
791
-     * @throws EE_Error
792
-     */
793
-    public function inputs_in_subsections()
794
-    {
795
-        $inputs = array();
796
-        foreach ($this->subsections() as $subsection) {
797
-            if ($subsection instanceof EE_Form_Input_Base) {
798
-                $inputs[ $subsection->html_name() ] = $subsection;
799
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
800
-                $inputs += $subsection->inputs_in_subsections();
801
-            }
802
-        }
803
-        return $inputs;
804
-    }
805
-
806
-
807
-    /**
808
-     * Gets a flat array of all the validation errors.
809
-     * Keys are html names (because those should be unique)
810
-     * and values are a string of all their validation errors
811
-     *
812
-     * @return string[]
813
-     * @throws EE_Error
814
-     */
815
-    public function subsection_validation_errors_by_html_name()
816
-    {
817
-        $inputs = $this->inputs();
818
-        $errors = array();
819
-        foreach ($inputs as $form_input) {
820
-            if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
821
-                $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string();
822
-            }
823
-        }
824
-        return $errors;
825
-    }
826
-
827
-
828
-    /**
829
-     * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
830
-     * Should be setup by each form during the _enqueues_and_localize_form_js
831
-     *
832
-     * @throws InvalidArgumentException
833
-     * @throws InvalidInterfaceException
834
-     * @throws InvalidDataTypeException
835
-     */
836
-    public static function localize_script_for_all_forms()
837
-    {
838
-        //allow inputs and stuff to hook in their JS and stuff here
839
-        do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
840
-        EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
841
-        $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
842
-            ? EE_Registry::instance()->CFG->registration->email_validation_level
843
-            : 'wp_default';
844
-        EE_Form_Section_Proper::$_js_localization['email_validation_level']   = $email_validation_level;
845
-        wp_enqueue_script('ee_form_section_validation');
846
-        wp_localize_script(
847
-            'ee_form_section_validation',
848
-            'ee_form_section_vars',
849
-            EE_Form_Section_Proper::$_js_localization
850
-        );
851
-    }
852
-
853
-
854
-    /**
855
-     * ensure_scripts_localized
856
-     *
857
-     * @throws EE_Error
858
-     */
859
-    public function ensure_scripts_localized()
860
-    {
861
-        if (! EE_Form_Section_Proper::$_scripts_localized) {
862
-            $this->_enqueue_and_localize_form_js();
863
-        }
864
-    }
865
-
866
-
867
-    /**
868
-     * Gets the hard-coded validation error messages to be used in the JS. The convention
869
-     * is that the key here should be the same as the custom validation rule put in the JS file
870
-     *
871
-     * @return array keys are custom validation rules, and values are internationalized strings
872
-     */
873
-    private static function _get_localized_error_messages()
874
-    {
875
-        return array(
876
-            'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'),
877
-            'regex'    => esc_html__('Please check your input', 'event_espresso'),
878
-        );
879
-    }
880
-
881
-
882
-    /**
883
-     * @return array
884
-     */
885
-    public static function js_localization()
886
-    {
887
-        return self::$_js_localization;
888
-    }
889
-
890
-
891
-    /**
892
-     * @return void
893
-     */
894
-    public static function reset_js_localization()
895
-    {
896
-        self::$_js_localization = array();
897
-    }
898
-
899
-
900
-    /**
901
-     * Gets the JS to put inside the jquery validation rules for subsection of this form section.
902
-     * See parent function for more...
903
-     *
904
-     * @return array
905
-     * @throws EE_Error
906
-     */
907
-    public function get_jquery_validation_rules()
908
-    {
909
-        $jquery_validation_rules = array();
910
-        foreach ($this->get_validatable_subsections() as $subsection) {
911
-            $jquery_validation_rules = array_merge(
912
-                $jquery_validation_rules,
913
-                $subsection->get_jquery_validation_rules()
914
-            );
915
-        }
916
-        return $jquery_validation_rules;
917
-    }
918
-
919
-
920
-    /**
921
-     * Sanitizes all the data and sets the sanitized value of each field
922
-     *
923
-     * @param array $req_data like $_POST
924
-     * @return void
925
-     * @throws EE_Error
926
-     */
927
-    protected function _normalize($req_data)
928
-    {
929
-        $this->_received_submission = true;
930
-        $this->_validation_errors   = array();
931
-        foreach ($this->get_validatable_subsections() as $subsection) {
932
-            try {
933
-                $subsection->_normalize($req_data);
934
-            } catch (EE_Validation_Error $e) {
935
-                $subsection->add_validation_error($e);
936
-            }
937
-        }
938
-    }
939
-
940
-
941
-    /**
942
-     * Performs validation on this form section and its subsections.
943
-     * For each subsection,
944
-     * calls _validate_{subsection_name} on THIS form (if the function exists)
945
-     * and passes it the subsection, then calls _validate on that subsection.
946
-     * If you need to perform validation on the form as a whole (considering multiple)
947
-     * you would be best to override this _validate method,
948
-     * calling parent::_validate() first.
949
-     *
950
-     * @throws EE_Error
951
-     */
952
-    protected function _validate()
953
-    {
954
-        //reset the cache of whether this form is valid or not- we're re-validating it now
955
-        $this->is_valid = null;
956
-        foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
957
-            if (method_exists($this, '_validate_' . $subsection_name)) {
958
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
959
-            }
960
-            $subsection->_validate();
961
-        }
962
-    }
963
-
964
-
965
-    /**
966
-     * Gets all the validated inputs for the form section
967
-     *
968
-     * @return array
969
-     * @throws EE_Error
970
-     */
971
-    public function valid_data()
972
-    {
973
-        $inputs = array();
974
-        foreach ($this->subsections() as $subsection_name => $subsection) {
975
-            if ($subsection instanceof EE_Form_Section_Proper) {
976
-                $inputs[ $subsection_name ] = $subsection->valid_data();
977
-            } elseif ($subsection instanceof EE_Form_Input_Base) {
978
-                $inputs[ $subsection_name ] = $subsection->normalized_value();
979
-            }
980
-        }
981
-        return $inputs;
982
-    }
983
-
984
-
985
-    /**
986
-     * Gets all the inputs on this form section
987
-     *
988
-     * @return EE_Form_Input_Base[]
989
-     * @throws EE_Error
990
-     */
991
-    public function inputs()
992
-    {
993
-        $inputs = array();
994
-        foreach ($this->subsections() as $subsection_name => $subsection) {
995
-            if ($subsection instanceof EE_Form_Input_Base) {
996
-                $inputs[ $subsection_name ] = $subsection;
997
-            }
998
-        }
999
-        return $inputs;
1000
-    }
1001
-
1002
-
1003
-    /**
1004
-     * Gets all the subsections which are a proper form
1005
-     *
1006
-     * @return EE_Form_Section_Proper[]
1007
-     * @throws EE_Error
1008
-     */
1009
-    public function subforms()
1010
-    {
1011
-        $form_sections = array();
1012
-        foreach ($this->subsections() as $name => $obj) {
1013
-            if ($obj instanceof EE_Form_Section_Proper) {
1014
-                $form_sections[ $name ] = $obj;
1015
-            }
1016
-        }
1017
-        return $form_sections;
1018
-    }
1019
-
1020
-
1021
-    /**
1022
-     * Gets all the subsections (inputs, proper subsections, or html-only sections).
1023
-     * Consider using inputs() or subforms()
1024
-     * if you only want form inputs or proper form sections.
1025
-     *
1026
-     * @param boolean $require_construction_to_be_finalized most client code should
1027
-     *                                                      leave this as TRUE so that the inputs will be properly
1028
-     *                                                      configured. However, some client code may be ok with
1029
-     *                                                      construction finalize being called later
1030
-     *                                                      (realizing that the subsections' html names might not be
1031
-     *                                                      set yet, etc.)
1032
-     * @return EE_Form_Section_Proper[]
1033
-     * @throws EE_Error
1034
-     */
1035
-    public function subsections($require_construction_to_be_finalized = true)
1036
-    {
1037
-        if ($require_construction_to_be_finalized) {
1038
-            $this->ensure_construct_finalized_called();
1039
-        }
1040
-        return $this->_subsections;
1041
-    }
1042
-
1043
-
1044
-    /**
1045
-     * Returns whether this form has any subforms or inputs
1046
-     * @return bool
1047
-     */
1048
-    public function hasSubsections()
1049
-    {
1050
-        return ! empty($this->_subsections);
1051
-    }
1052
-
1053
-
1054
-    /**
1055
-     * Returns a simple array where keys are input names, and values are their normalized
1056
-     * values. (Similar to calling get_input_value on inputs)
1057
-     *
1058
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1059
-     *                                        or just this forms' direct children inputs
1060
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1061
-     *                                        or allow multidimensional array
1062
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
1063
-     *                                        with array keys being input names
1064
-     *                                        (regardless of whether they are from a subsection or not),
1065
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1066
-     *                                        where keys are always subsection names and values are either
1067
-     *                                        the input's normalized value, or an array like the top-level array
1068
-     * @throws EE_Error
1069
-     */
1070
-    public function input_values($include_subform_inputs = false, $flatten = false)
1071
-    {
1072
-        return $this->_input_values(false, $include_subform_inputs, $flatten);
1073
-    }
1074
-
1075
-
1076
-    /**
1077
-     * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
1078
-     * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
1079
-     * is not necessarily the value we want to display to users. This creates an array
1080
-     * where keys are the input names, and values are their display values
1081
-     *
1082
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1083
-     *                                        or just this forms' direct children inputs
1084
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1085
-     *                                        or allow multidimensional array
1086
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
1087
-     *                                        with array keys being input names
1088
-     *                                        (regardless of whether they are from a subsection or not),
1089
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1090
-     *                                        where keys are always subsection names and values are either
1091
-     *                                        the input's normalized value, or an array like the top-level array
1092
-     * @throws EE_Error
1093
-     */
1094
-    public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1095
-    {
1096
-        return $this->_input_values(true, $include_subform_inputs, $flatten);
1097
-    }
1098
-
1099
-
1100
-    /**
1101
-     * Gets the input values from the form
1102
-     *
1103
-     * @param boolean $pretty                 Whether to retrieve the pretty value,
1104
-     *                                        or just the normalized value
1105
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1106
-     *                                        or just this forms' direct children inputs
1107
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1108
-     *                                        or allow multidimensional array
1109
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1110
-     *                                        input names (regardless of whether they are from a subsection or not),
1111
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1112
-     *                                        where keys are always subsection names and values are either
1113
-     *                                        the input's normalized value, or an array like the top-level array
1114
-     * @throws EE_Error
1115
-     */
1116
-    public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1117
-    {
1118
-        $input_values = array();
1119
-        foreach ($this->subsections() as $subsection_name => $subsection) {
1120
-            if ($subsection instanceof EE_Form_Input_Base) {
1121
-                $input_values[ $subsection_name ] = $pretty
1122
-                    ? $subsection->pretty_value()
1123
-                    : $subsection->normalized_value();
1124
-            } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1125
-                $subform_input_values = $subsection->_input_values(
1126
-                    $pretty,
1127
-                    $include_subform_inputs,
1128
-                    $flatten
1129
-                );
1130
-                if ($flatten) {
1131
-                    $input_values = array_merge($input_values, $subform_input_values);
1132
-                } else {
1133
-                    $input_values[ $subsection_name ] = $subform_input_values;
1134
-                }
1135
-            }
1136
-        }
1137
-        return $input_values;
1138
-    }
1139
-
1140
-
1141
-    /**
1142
-     * Gets the originally submitted input values from the form
1143
-     *
1144
-     * @param boolean $include_subforms  Whether to include inputs from subforms,
1145
-     *                                   or just this forms' direct children inputs
1146
-     * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1147
-     *                                   with array keys being input names
1148
-     *                                   (regardless of whether they are from a subsection or not),
1149
-     *                                   and if $flatten is FALSE it can be a multidimensional array
1150
-     *                                   where keys are always subsection names and values are either
1151
-     *                                   the input's normalized value, or an array like the top-level array
1152
-     * @throws EE_Error
1153
-     */
1154
-    public function submitted_values($include_subforms = false)
1155
-    {
1156
-        $submitted_values = array();
1157
-        foreach ($this->subsections() as $subsection) {
1158
-            if ($subsection instanceof EE_Form_Input_Base) {
1159
-                // is this input part of an array of inputs?
1160
-                if (strpos($subsection->html_name(), '[') !== false) {
1161
-                    $full_input_name  = EEH_Array::convert_array_values_to_keys(
1162
-                        explode(
1163
-                            '[',
1164
-                            str_replace(']', '', $subsection->html_name())
1165
-                        ),
1166
-                        $subsection->raw_value()
1167
-                    );
1168
-                    $submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1169
-                } else {
1170
-                    $submitted_values[ $subsection->html_name() ] = $subsection->raw_value();
1171
-                }
1172
-            } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1173
-                $subform_input_values = $subsection->submitted_values($include_subforms);
1174
-                $submitted_values     = array_replace_recursive($submitted_values, $subform_input_values);
1175
-            }
1176
-        }
1177
-        return $submitted_values;
1178
-    }
1179
-
1180
-
1181
-    /**
1182
-     * Indicates whether or not this form has received a submission yet
1183
-     * (ie, had receive_form_submission called on it yet)
1184
-     *
1185
-     * @return boolean
1186
-     * @throws EE_Error
1187
-     */
1188
-    public function has_received_submission()
1189
-    {
1190
-        $this->ensure_construct_finalized_called();
1191
-        return $this->_received_submission;
1192
-    }
1193
-
1194
-
1195
-    /**
1196
-     * Equivalent to passing 'exclude' in the constructor's options array.
1197
-     * Removes the listed inputs from the form
1198
-     *
1199
-     * @param array $inputs_to_exclude values are the input names
1200
-     * @return void
1201
-     */
1202
-    public function exclude(array $inputs_to_exclude = array())
1203
-    {
1204
-        foreach ($inputs_to_exclude as $input_to_exclude_name) {
1205
-            unset($this->_subsections[ $input_to_exclude_name ]);
1206
-        }
1207
-    }
1208
-
1209
-
1210
-    /**
1211
-     * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy.
1212
-     * @param array $inputs_to_hide
1213
-     * @throws EE_Error
1214
-     */
1215
-    public function hide(array $inputs_to_hide = array())
1216
-    {
1217
-        foreach ($inputs_to_hide as $input_to_hide) {
1218
-            $input = $this->get_input($input_to_hide);
1219
-            $input->set_display_strategy(new EE_Hidden_Display_Strategy());
1220
-        }
1221
-    }
1222
-
1223
-
1224
-    /**
1225
-     * add_subsections
1226
-     * Adds the listed subsections to the form section.
1227
-     * If $subsection_name_to_target is provided,
1228
-     * then new subsections are added before or after that subsection,
1229
-     * otherwise to the start or end of the entire subsections array.
1230
-     *
1231
-     * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1232
-     *                                                          where keys are their names
1233
-     * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1234
-     *                                                          should be added before or after
1235
-     *                                                          IF $subsection_name_to_target is null,
1236
-     *                                                          then $new_subsections will be added to
1237
-     *                                                          the beginning or end of the entire subsections array
1238
-     * @param boolean                $add_before                whether to add $new_subsections, before or after
1239
-     *                                                          $subsection_name_to_target,
1240
-     *                                                          or if $subsection_name_to_target is null,
1241
-     *                                                          before or after entire subsections array
1242
-     * @return void
1243
-     * @throws EE_Error
1244
-     */
1245
-    public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1246
-    {
1247
-        foreach ($new_subsections as $subsection_name => $subsection) {
1248
-            if (! $subsection instanceof EE_Form_Section_Base) {
1249
-                EE_Error::add_error(
1250
-                    sprintf(
1251
-                        esc_html__(
1252
-                            "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1253
-                            'event_espresso'
1254
-                        ),
1255
-                        get_class($subsection),
1256
-                        $subsection_name,
1257
-                        $this->name()
1258
-                    )
1259
-                );
1260
-                unset($new_subsections[ $subsection_name ]);
1261
-            }
1262
-        }
1263
-        $this->_subsections = EEH_Array::insert_into_array(
1264
-            $this->_subsections,
1265
-            $new_subsections,
1266
-            $subsection_name_to_target,
1267
-            $add_before
1268
-        );
1269
-        if ($this->_construction_finalized) {
1270
-            foreach ($this->_subsections as $name => $subsection) {
1271
-                $subsection->_construct_finalize($this, $name);
1272
-            }
1273
-        }
1274
-    }
1275
-
1276
-
1277
-    /**
1278
-     * @param string $subsection_name
1279
-     * @param bool   $recursive
1280
-     * @return bool
1281
-     */
1282
-    public function has_subsection($subsection_name, $recursive = false)
1283
-    {
1284
-        foreach ($this->_subsections as $name => $subsection) {if(
1285
-                $name === $subsection_name
1286
-                || (
1287
-                    $recursive
1288
-                    && $subsection instanceof EE_Form_Section_Proper
1289
-                    && $subsection->has_subsection($subsection_name, $recursive)
1290
-                )
1291
-            ) {
1292
-                return true;
1293
-            }
1294
-        }
1295
-        return false;
1296
-    }
1297
-
1298
-
1299
-
1300
-    /**
1301
-     * Just gets all validatable subsections to clean their sensitive data
1302
-     *
1303
-     * @throws EE_Error
1304
-     */
1305
-    public function clean_sensitive_data()
1306
-    {
1307
-        foreach ($this->get_validatable_subsections() as $subsection) {
1308
-            $subsection->clean_sensitive_data();
1309
-        }
1310
-    }
1311
-
1312
-
1313
-    /**
1314
-     * Sets the submission error message (aka validation error message for this form section and all sub-sections)
1315
-     * @param string                           $form_submission_error_message
1316
-     * @param EE_Form_Section_Validatable $form_section unused
1317
-     * @throws EE_Error
1318
-     */
1319
-    public function set_submission_error_message(
1320
-        $form_submission_error_message = ''
1321
-    ) {
1322
-        $this->_form_submission_error_message = ! empty($form_submission_error_message)
1323
-            ? $form_submission_error_message
1324
-            : $this->getAllValidationErrorsString();
1325
-    }
1326
-
1327
-
1328
-    /**
1329
-     * Returns the cached error message. A default value is set for this during _validate(),
1330
-     * (called during receive_form_submission) but it can be explicitly set using
1331
-     * set_submission_error_message
1332
-     *
1333
-     * @return string
1334
-     */
1335
-    public function submission_error_message()
1336
-    {
1337
-        return $this->_form_submission_error_message;
1338
-    }
1339
-
1340
-
1341
-    /**
1342
-     * Sets a message to display if the data submitted to the form was valid.
1343
-     * @param string $form_submission_success_message
1344
-     */
1345
-    public function set_submission_success_message($form_submission_success_message = '')
1346
-    {
1347
-        $this->_form_submission_success_message = ! empty($form_submission_success_message)
1348
-            ? $form_submission_success_message
1349
-            : esc_html__('Form submitted successfully', 'event_espresso');
1350
-    }
1351
-
1352
-
1353
-    /**
1354
-     * Gets a message appropriate for display when the form is correctly submitted
1355
-     * @return string
1356
-     */
1357
-    public function submission_success_message()
1358
-    {
1359
-        return $this->_form_submission_success_message;
1360
-    }
1361
-
1362
-
1363
-    /**
1364
-     * Returns the prefix that should be used on child of this form section for
1365
-     * their html names. If this form section itself has a parent, prepends ITS
1366
-     * prefix onto this form section's prefix. Used primarily by
1367
-     * EE_Form_Input_Base::_set_default_html_name_if_empty
1368
-     *
1369
-     * @return string
1370
-     * @throws EE_Error
1371
-     */
1372
-    public function html_name_prefix()
1373
-    {
1374
-        if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1375
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1376
-        }
1377
-        return $this->name();
1378
-    }
1379
-
1380
-
1381
-    /**
1382
-     * Gets the name, but first checks _construct_finalize has been called. If not,
1383
-     * calls it (assumes there is no parent and that we want the name to be whatever
1384
-     * was set, which is probably nothing, or the classname)
1385
-     *
1386
-     * @return string
1387
-     * @throws EE_Error
1388
-     */
1389
-    public function name()
1390
-    {
1391
-        $this->ensure_construct_finalized_called();
1392
-        return parent::name();
1393
-    }
1394
-
1395
-
1396
-    /**
1397
-     * @return EE_Form_Section_Proper
1398
-     * @throws EE_Error
1399
-     */
1400
-    public function parent_section()
1401
-    {
1402
-        $this->ensure_construct_finalized_called();
1403
-        return parent::parent_section();
1404
-    }
1405
-
1406
-
1407
-    /**
1408
-     * make sure construction finalized was called, otherwise children might not be ready
1409
-     *
1410
-     * @return void
1411
-     * @throws EE_Error
1412
-     */
1413
-    public function ensure_construct_finalized_called()
1414
-    {
1415
-        if (! $this->_construction_finalized) {
1416
-            $this->_construct_finalize($this->_parent_section, $this->_name);
1417
-        }
1418
-    }
1419
-
1420
-
1421
-    /**
1422
-     * Checks if any of this form section's inputs, or any of its children's inputs,
1423
-     * are in teh form data. If any are found, returns true. Else false
1424
-     *
1425
-     * @param array $req_data
1426
-     * @return boolean
1427
-     * @throws EE_Error
1428
-     */
1429
-    public function form_data_present_in($req_data = null)
1430
-    {
1431
-        $req_data = $this->getCachedRequest($req_data);
1432
-        foreach ($this->subsections() as $subsection) {
1433
-            if ($subsection instanceof EE_Form_Input_Base) {
1434
-                if ($subsection->form_data_present_in($req_data)) {
1435
-                    return true;
1436
-                }
1437
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
1438
-                if ($subsection->form_data_present_in($req_data)) {
1439
-                    return true;
1440
-                }
1441
-            }
1442
-        }
1443
-        return false;
1444
-    }
1445
-
1446
-
1447
-    /**
1448
-     * Gets validation errors for this form section and subsections
1449
-     * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1450
-     * gets the validation errors for ALL subsection
1451
-     *
1452
-     * @return EE_Validation_Error[]
1453
-     * @throws EE_Error
1454
-     */
1455
-    public function get_validation_errors_accumulated()
1456
-    {
1457
-        $validation_errors = $this->get_validation_errors();
1458
-        foreach ($this->get_validatable_subsections() as $subsection) {
1459
-            if ($subsection instanceof EE_Form_Section_Proper) {
1460
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1461
-            } else {
1462
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors();
1463
-            }
1464
-            if ($validation_errors_on_this_subsection) {
1465
-                $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1466
-            }
1467
-        }
1468
-        return $validation_errors;
1469
-    }
1470
-
1471
-    /**
1472
-     * Fetch validation errors from children and grandchildren and puts them in a single string.
1473
-     * This traverses the form section tree to generate this, but you probably want to instead use
1474
-     * get_form_submission_error_message() which is usually this message cached (or a custom validation error message)
1475
-     *
1476
-     * @return string
1477
-     * @since 4.9.59.p
1478
-     */
1479
-    protected function getAllValidationErrorsString()
1480
-    {
1481
-        $submission_error_messages = array();
1482
-        // bad, bad, bad registrant
1483
-        foreach ($this->get_validation_errors_accumulated() as $validation_error) {
1484
-            if ($validation_error instanceof EE_Validation_Error) {
1485
-                $form_section = $validation_error->get_form_section();
1486
-                if ($form_section instanceof EE_Form_Input_Base) {
1487
-                   $label = $validation_error->get_form_section()->html_label_text();
1488
-                } elseif($form_section instanceof EE_Form_Section_Validatable) {
1489
-                    $label = $validation_error->get_form_section()->name();
1490
-                } else {
1491
-                    $label = esc_html__('Unknown', 'event_espresso');
1492
-                }
1493
-                $submission_error_messages[] = sprintf(
1494
-                    __('%s : %s', 'event_espresso'),
1495
-                    $label,
1496
-                    $validation_error->getMessage()
1497
-                );
1498
-            }
1499
-        }
1500
-        return implode('<br', $submission_error_messages);
1501
-    }
1502
-
1503
-
1504
-    /**
1505
-     * This isn't just the name of an input, it's a path pointing to an input. The
1506
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
1507
-     * dot-dot-slash (../) means to ascend into the parent section.
1508
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1509
-     * which will be returned.
1510
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1511
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1512
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1513
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1514
-     * Etc
1515
-     *
1516
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1517
-     * @return EE_Form_Section_Base
1518
-     * @throws EE_Error
1519
-     */
1520
-    public function find_section_from_path($form_section_path)
1521
-    {
1522
-        //check if we can find the input from purely going straight up the tree
1523
-        $input = parent::find_section_from_path($form_section_path);
1524
-        if ($input instanceof EE_Form_Section_Base) {
1525
-            return $input;
1526
-        }
1527
-        $next_slash_pos = strpos($form_section_path, '/');
1528
-        if ($next_slash_pos !== false) {
1529
-            $child_section_name = substr($form_section_path, 0, $next_slash_pos);
1530
-            $subpath            = substr($form_section_path, $next_slash_pos + 1);
1531
-        } else {
1532
-            $child_section_name = $form_section_path;
1533
-            $subpath            = '';
1534
-        }
1535
-        $child_section = $this->get_subsection($child_section_name);
1536
-        if ($child_section instanceof EE_Form_Section_Base) {
1537
-            return $child_section->find_section_from_path($subpath);
1538
-        }
1539
-        return null;
1540
-    }
17
+	const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
18
+
19
+	/**
20
+	 * Subsections
21
+	 *
22
+	 * @var EE_Form_Section_Validatable[]
23
+	 */
24
+	protected $_subsections = array();
25
+
26
+	/**
27
+	 * Strategy for laying out the form
28
+	 *
29
+	 * @var EE_Form_Section_Layout_Base
30
+	 */
31
+	protected $_layout_strategy;
32
+
33
+	/**
34
+	 * Whether or not this form has received and validated a form submission yet
35
+	 *
36
+	 * @var boolean
37
+	 */
38
+	protected $_received_submission = false;
39
+
40
+	/**
41
+	 * message displayed to users upon successful form submission
42
+	 *
43
+	 * @var string
44
+	 */
45
+	protected $_form_submission_success_message = '';
46
+
47
+	/**
48
+	 * message displayed to users upon unsuccessful form submission
49
+	 *
50
+	 * @var string
51
+	 */
52
+	protected $_form_submission_error_message = '';
53
+
54
+	/**
55
+	 * @var array like $_REQUEST
56
+	 */
57
+	protected $cached_request_data;
58
+
59
+	/**
60
+	 * Stores whether this form (and its sub-sections) were found to be valid or not.
61
+	 * Starts off as null, but once the form is validated, it set to either true or false
62
+	 * @var boolean|null
63
+	 */
64
+	protected $is_valid;
65
+
66
+	/**
67
+	 * Stores all the data that will localized for form validation
68
+	 *
69
+	 * @var array
70
+	 */
71
+	static protected $_js_localization = array();
72
+
73
+	/**
74
+	 * whether or not the form's localized validation JS vars have been set
75
+	 *
76
+	 * @type boolean
77
+	 */
78
+	static protected $_scripts_localized = false;
79
+
80
+
81
+	/**
82
+	 * when constructing a proper form section, calls _construct_finalize on children
83
+	 * so that they know who their parent is, and what name they've been given.
84
+	 *
85
+	 * @param array[] $options_array   {
86
+	 * @type          $subsections     EE_Form_Section_Validatable[] where keys are the section's name
87
+	 * @type          $include         string[] numerically-indexed where values are section names to be included,
88
+	 *                                 and in that order. This is handy if you want
89
+	 *                                 the subsections to be ordered differently than the default, and if you override
90
+	 *                                 which fields are shown
91
+	 * @type          $exclude         string[] values are subsections to be excluded. This is handy if you want
92
+	 *                                 to remove certain default subsections (note: if you specify BOTH 'include' AND
93
+	 *                                 'exclude', the inclusions will be applied first, and the exclusions will exclude
94
+	 *                                 items from that list of inclusions)
95
+	 * @type          $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
96
+	 *                                 } @see EE_Form_Section_Validatable::__construct()
97
+	 * @throws EE_Error
98
+	 */
99
+	public function __construct($options_array = array())
100
+	{
101
+		$options_array = (array) apply_filters(
102
+			'FHEE__EE_Form_Section_Proper___construct__options_array',
103
+			$options_array,
104
+			$this
105
+		);
106
+		//call parent first, as it may be setting the name
107
+		parent::__construct($options_array);
108
+		//if they've included subsections in the constructor, add them now
109
+		if (isset($options_array['include'])) {
110
+			//we are going to make sure we ONLY have those subsections to include
111
+			//AND we are going to make sure they're in that specified order
112
+			$reordered_subsections = array();
113
+			foreach ($options_array['include'] as $input_name) {
114
+				if (isset($this->_subsections[ $input_name ])) {
115
+					$reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ];
116
+				}
117
+			}
118
+			$this->_subsections = $reordered_subsections;
119
+		}
120
+		if (isset($options_array['exclude'])) {
121
+			$exclude            = $options_array['exclude'];
122
+			$this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
123
+		}
124
+		if (isset($options_array['layout_strategy'])) {
125
+			$this->_layout_strategy = $options_array['layout_strategy'];
126
+		}
127
+		if (! $this->_layout_strategy) {
128
+			$this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
129
+		}
130
+		$this->_layout_strategy->_construct_finalize($this);
131
+		//ok so we are definitely going to want the forms JS,
132
+		//so enqueue it or remember to enqueue it during wp_enqueue_scripts
133
+		if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
134
+			//ok so they've constructed this object after when they should have.
135
+			//just enqueue the generic form scripts and initialize the form immediately in the JS
136
+			EE_Form_Section_Proper::wp_enqueue_scripts(true);
137
+		} else {
138
+			add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
139
+			add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
140
+		}
141
+		add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
142
+		/**
143
+		 * Gives other plugins a chance to hook in before construct finalize is called.
144
+		 * The form probably doesn't yet have a parent form section.
145
+		 * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form,
146
+		 * assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
147
+		 * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
148
+		 *
149
+		 * @since 4.9.32
150
+		 * @param EE_Form_Section_Proper $this          before __construct is done, but all of its logic,
151
+		 *                                              except maybe calling _construct_finalize has been done
152
+		 * @param array                  $options_array options passed into the constructor
153
+		 */
154
+		do_action(
155
+			'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called',
156
+			$this,
157
+			$options_array
158
+		);
159
+		if (isset($options_array['name'])) {
160
+			$this->_construct_finalize(null, $options_array['name']);
161
+		}
162
+	}
163
+
164
+
165
+	/**
166
+	 * Finishes construction given the parent form section and this form section's name
167
+	 *
168
+	 * @param EE_Form_Section_Proper $parent_form_section
169
+	 * @param string                 $name
170
+	 * @throws EE_Error
171
+	 */
172
+	public function _construct_finalize($parent_form_section, $name)
173
+	{
174
+		parent::_construct_finalize($parent_form_section, $name);
175
+		$this->_set_default_name_if_empty();
176
+		$this->_set_default_html_id_if_empty();
177
+		foreach ($this->_subsections as $subsection_name => $subsection) {
178
+			if ($subsection instanceof EE_Form_Section_Base) {
179
+				$subsection->_construct_finalize($this, $subsection_name);
180
+			} else {
181
+				throw new EE_Error(
182
+					sprintf(
183
+						esc_html__(
184
+							'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
185
+							'event_espresso'
186
+						),
187
+						$subsection_name,
188
+						get_class($this),
189
+						$subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
190
+					)
191
+				);
192
+			}
193
+		}
194
+		/**
195
+		 * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
196
+		 * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID
197
+		 * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done.
198
+		 * This might only happen just before displaying the form, or just before it receives form submission data.
199
+		 * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
200
+		 * ensured it has a name, HTML IDs, etc
201
+		 *
202
+		 * @param EE_Form_Section_Proper      $this
203
+		 * @param EE_Form_Section_Proper|null $parent_form_section
204
+		 * @param string                      $name
205
+		 */
206
+		do_action(
207
+			'AHEE__EE_Form_Section_Proper___construct_finalize__end',
208
+			$this,
209
+			$parent_form_section,
210
+			$name
211
+		);
212
+	}
213
+
214
+
215
+	/**
216
+	 * Gets the layout strategy for this form section
217
+	 *
218
+	 * @return EE_Form_Section_Layout_Base
219
+	 */
220
+	public function get_layout_strategy()
221
+	{
222
+		return $this->_layout_strategy;
223
+	}
224
+
225
+
226
+	/**
227
+	 * Gets the HTML for a single input for this form section according
228
+	 * to the layout strategy
229
+	 *
230
+	 * @param EE_Form_Input_Base $input
231
+	 * @return string
232
+	 */
233
+	public function get_html_for_input($input)
234
+	{
235
+		return $this->_layout_strategy->layout_input($input);
236
+	}
237
+
238
+
239
+	/**
240
+	 * was_submitted - checks if form inputs are present in request data
241
+	 * Basically an alias for form_data_present_in() (which is used by both
242
+	 * proper form sections and form inputs)
243
+	 *
244
+	 * @param null $form_data
245
+	 * @return boolean
246
+	 * @throws EE_Error
247
+	 */
248
+	public function was_submitted($form_data = null)
249
+	{
250
+		return $this->form_data_present_in($form_data);
251
+	}
252
+
253
+	/**
254
+	 * Gets the cached request data; but if there is none, or $req_data was set with
255
+	 * something different, refresh the cache, and then return it
256
+	 * @param null $req_data
257
+	 * @return array
258
+	 */
259
+	protected function getCachedRequest($req_data = null)
260
+	{
261
+		if ($this->cached_request_data === null
262
+			|| (
263
+				$req_data !== null &&
264
+				$req_data !== $this->cached_request_data
265
+			)
266
+		) {
267
+			$req_data = apply_filters(
268
+				'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data',
269
+				$req_data,
270
+				$this
271
+			);
272
+			if ($req_data === null) {
273
+				$req_data = array_merge($_GET, $_POST);
274
+			}
275
+			$req_data = apply_filters(
276
+				'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
277
+				$req_data,
278
+				$this
279
+			);
280
+			$this->cached_request_data = (array)$req_data;
281
+		}
282
+		return $this->cached_request_data;
283
+	}
284
+
285
+
286
+	/**
287
+	 * After the form section is initially created, call this to sanitize the data in the submission
288
+	 * which relates to this form section, validate it, and set it as properties on the form.
289
+	 *
290
+	 * @param array|null $req_data should usually be $_POST (the default).
291
+	 *                             However, you CAN supply a different array.
292
+	 *                             Consider using set_defaults() instead however.
293
+	 *                             (If you rendered the form in the page using echo $form_x->get_html()
294
+	 *                             the inputs will have the correct name in the request data for this function
295
+	 *                             to find them and populate the form with them.
296
+	 *                             If you have a flat form (with only input subsections),
297
+	 *                             you can supply a flat array where keys
298
+	 *                             are the form input names and values are their values)
299
+	 * @param boolean    $validate whether or not to perform validation on this data. Default is,
300
+	 *                             of course, to validate that data, and set errors on the invalid values.
301
+	 *                             But if the data has already been validated
302
+	 *                             (eg you validated the data then stored it in the DB)
303
+	 *                             you may want to skip this step.
304
+	 * @throws InvalidArgumentException
305
+	 * @throws InvalidInterfaceException
306
+	 * @throws InvalidDataTypeException
307
+	 * @throws EE_Error
308
+	 */
309
+	public function receive_form_submission($req_data = null, $validate = true)
310
+	{
311
+		$req_data = $this->getCachedRequest($req_data);
312
+		$this->_normalize($req_data);
313
+		if ($validate) {
314
+			$this->_validate();
315
+			//if it's invalid, we're going to want to re-display so remember what they submitted
316
+			if (! $this->is_valid()) {
317
+				$this->store_submitted_form_data_in_session();
318
+			}
319
+		}
320
+		if ($this->submission_error_message() === '' && ! $this->is_valid()) {
321
+			$this->set_submission_error_message();
322
+		}
323
+		do_action(
324
+			'AHEE__EE_Form_Section_Proper__receive_form_submission__end',
325
+			$req_data,
326
+			$this,
327
+			$validate
328
+		);
329
+	}
330
+
331
+
332
+	/**
333
+	 * caches the originally submitted input values in the session
334
+	 * so that they can be used to repopulate the form if it failed validation
335
+	 *
336
+	 * @return boolean whether or not the data was successfully stored in the session
337
+	 * @throws InvalidArgumentException
338
+	 * @throws InvalidInterfaceException
339
+	 * @throws InvalidDataTypeException
340
+	 * @throws EE_Error
341
+	 */
342
+	protected function store_submitted_form_data_in_session()
343
+	{
344
+		return EE_Registry::instance()->SSN->set_session_data(
345
+			array(
346
+				EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
347
+			)
348
+		);
349
+	}
350
+
351
+
352
+	/**
353
+	 * retrieves the originally submitted input values in the session
354
+	 * so that they can be used to repopulate the form if it failed validation
355
+	 *
356
+	 * @return array
357
+	 * @throws InvalidArgumentException
358
+	 * @throws InvalidInterfaceException
359
+	 * @throws InvalidDataTypeException
360
+	 */
361
+	protected function get_submitted_form_data_from_session()
362
+	{
363
+		$session = EE_Registry::instance()->SSN;
364
+		if ($session instanceof EE_Session) {
365
+			return $session->get_session_data(
366
+				EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
367
+			);
368
+		}
369
+		return array();
370
+	}
371
+
372
+
373
+	/**
374
+	 * flushed the originally submitted input values from the session
375
+	 *
376
+	 * @return boolean whether or not the data was successfully removed from the session
377
+	 * @throws InvalidArgumentException
378
+	 * @throws InvalidInterfaceException
379
+	 * @throws InvalidDataTypeException
380
+	 */
381
+	protected function flush_submitted_form_data_from_session()
382
+	{
383
+		return EE_Registry::instance()->SSN->reset_data(
384
+			array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
385
+		);
386
+	}
387
+
388
+
389
+	/**
390
+	 * Populates this form and its subsections with data from the session.
391
+	 * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
392
+	 * validation errors when displaying too)
393
+	 * Returns true if the form was populated from the session, false otherwise
394
+	 *
395
+	 * @return boolean
396
+	 * @throws InvalidArgumentException
397
+	 * @throws InvalidInterfaceException
398
+	 * @throws InvalidDataTypeException
399
+	 * @throws EE_Error
400
+	 */
401
+	public function populate_from_session()
402
+	{
403
+		$form_data_in_session = $this->get_submitted_form_data_from_session();
404
+		if (empty($form_data_in_session)) {
405
+			return false;
406
+		}
407
+		$this->receive_form_submission($form_data_in_session);
408
+		$this->flush_submitted_form_data_from_session();
409
+		if ($this->form_data_present_in($form_data_in_session)) {
410
+			return true;
411
+		}
412
+		return false;
413
+	}
414
+
415
+
416
+	/**
417
+	 * Populates the default data for the form, given an array where keys are
418
+	 * the input names, and values are their values (preferably normalized to be their
419
+	 * proper PHP types, not all strings... although that should be ok too).
420
+	 * Proper subsections are sub-arrays, the key being the subsection's name, and
421
+	 * the value being an array formatted in teh same way
422
+	 *
423
+	 * @param array $default_data
424
+	 * @throws EE_Error
425
+	 */
426
+	public function populate_defaults($default_data)
427
+	{
428
+		foreach ($this->subsections(false) as $subsection_name => $subsection) {
429
+			if (isset($default_data[ $subsection_name ])) {
430
+				if ($subsection instanceof EE_Form_Input_Base) {
431
+					$subsection->set_default($default_data[ $subsection_name ]);
432
+				} elseif ($subsection instanceof EE_Form_Section_Proper) {
433
+					$subsection->populate_defaults($default_data[ $subsection_name ]);
434
+				}
435
+			}
436
+		}
437
+	}
438
+
439
+
440
+	/**
441
+	 * returns true if subsection exists
442
+	 *
443
+	 * @param string $name
444
+	 * @return boolean
445
+	 */
446
+	public function subsection_exists($name)
447
+	{
448
+		return isset($this->_subsections[ $name ]) ? true : false;
449
+	}
450
+
451
+
452
+	/**
453
+	 * Gets the subsection specified by its name
454
+	 *
455
+	 * @param string  $name
456
+	 * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
457
+	 *                                                      so that the inputs will be properly configured.
458
+	 *                                                      However, some client code may be ok
459
+	 *                                                      with construction finalize being called later
460
+	 *                                                      (realizing that the subsections' html names
461
+	 *                                                      might not be set yet, etc.)
462
+	 * @return EE_Form_Section_Base
463
+	 * @throws EE_Error
464
+	 */
465
+	public function get_subsection($name, $require_construction_to_be_finalized = true)
466
+	{
467
+		if ($require_construction_to_be_finalized) {
468
+			$this->ensure_construct_finalized_called();
469
+		}
470
+		return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null;
471
+	}
472
+
473
+
474
+	/**
475
+	 * Gets all the validatable subsections of this form section
476
+	 *
477
+	 * @return EE_Form_Section_Validatable[]
478
+	 * @throws EE_Error
479
+	 */
480
+	public function get_validatable_subsections()
481
+	{
482
+		$validatable_subsections = array();
483
+		foreach ($this->subsections() as $name => $obj) {
484
+			if ($obj instanceof EE_Form_Section_Validatable) {
485
+				$validatable_subsections[ $name ] = $obj;
486
+			}
487
+		}
488
+		return $validatable_subsections;
489
+	}
490
+
491
+
492
+	/**
493
+	 * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
494
+	 * throw an EE_Error.
495
+	 *
496
+	 * @param string  $name
497
+	 * @param boolean $require_construction_to_be_finalized most client code should
498
+	 *                                                      leave this as TRUE so that the inputs will be properly
499
+	 *                                                      configured. However, some client code may be ok with
500
+	 *                                                      construction finalize being called later
501
+	 *                                                      (realizing that the subsections' html names might not be
502
+	 *                                                      set yet, etc.)
503
+	 * @return EE_Form_Input_Base
504
+	 * @throws EE_Error
505
+	 */
506
+	public function get_input($name, $require_construction_to_be_finalized = true)
507
+	{
508
+		$subsection = $this->get_subsection(
509
+			$name,
510
+			$require_construction_to_be_finalized
511
+		);
512
+		if (! $subsection instanceof EE_Form_Input_Base) {
513
+			throw new EE_Error(
514
+				sprintf(
515
+					esc_html__(
516
+						"Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
517
+						'event_espresso'
518
+					),
519
+					$name,
520
+					get_class($this),
521
+					$subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso')
522
+				)
523
+			);
524
+		}
525
+		return $subsection;
526
+	}
527
+
528
+
529
+	/**
530
+	 * Like get_input(), gets the proper subsection of the form given the name,
531
+	 * otherwise throws an EE_Error
532
+	 *
533
+	 * @param string  $name
534
+	 * @param boolean $require_construction_to_be_finalized most client code should
535
+	 *                                                      leave this as TRUE so that the inputs will be properly
536
+	 *                                                      configured. However, some client code may be ok with
537
+	 *                                                      construction finalize being called later
538
+	 *                                                      (realizing that the subsections' html names might not be
539
+	 *                                                      set yet, etc.)
540
+	 * @return EE_Form_Section_Proper
541
+	 * @throws EE_Error
542
+	 */
543
+	public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
544
+	{
545
+		$subsection = $this->get_subsection(
546
+			$name,
547
+			$require_construction_to_be_finalized
548
+		);
549
+		if (! $subsection instanceof EE_Form_Section_Proper) {
550
+			throw new EE_Error(
551
+				sprintf(
552
+					esc_html__(
553
+						"Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'",
554
+						'event_espresso'
555
+					),
556
+					$name,
557
+					get_class($this)
558
+				)
559
+			);
560
+		}
561
+		return $subsection;
562
+	}
563
+
564
+
565
+	/**
566
+	 * Gets the value of the specified input. Should be called after receive_form_submission()
567
+	 * or populate_defaults() on the form, where the normalized value on the input is set.
568
+	 *
569
+	 * @param string $name
570
+	 * @return mixed depending on the input's type and its normalization strategy
571
+	 * @throws EE_Error
572
+	 */
573
+	public function get_input_value($name)
574
+	{
575
+		$input = $this->get_input($name);
576
+		return $input->normalized_value();
577
+	}
578
+
579
+
580
+	/**
581
+	 * Checks if this form section itself is valid, and then checks its subsections
582
+	 *
583
+	 * @throws EE_Error
584
+	 * @return boolean
585
+	 */
586
+	public function is_valid()
587
+	{
588
+		if($this->is_valid === null) {
589
+			if (! $this->has_received_submission()) {
590
+				throw new EE_Error(
591
+					sprintf(
592
+						esc_html__(
593
+							'You cannot check if a form is valid before receiving the form submission using receive_form_submission',
594
+							'event_espresso'
595
+						)
596
+					)
597
+				);
598
+			}
599
+			if (! parent::is_valid()) {
600
+				$this->is_valid = false;
601
+			} else {
602
+				// ok so no general errors to this entire form section.
603
+				// so let's check the subsections, but only set errors if that hasn't been done yet
604
+				$this->is_valid = true;
605
+				foreach ($this->get_validatable_subsections() as $subsection) {
606
+					if (! $subsection->is_valid()) {
607
+						$this->is_valid = false;
608
+					}
609
+				}
610
+			}
611
+		}
612
+		return $this->is_valid;
613
+	}
614
+
615
+
616
+	/**
617
+	 * gets the default name of this form section if none is specified
618
+	 *
619
+	 * @return void
620
+	 */
621
+	protected function _set_default_name_if_empty()
622
+	{
623
+		if (! $this->_name) {
624
+			$classname    = get_class($this);
625
+			$default_name = str_replace('EE_', '', $classname);
626
+			$this->_name  = $default_name;
627
+		}
628
+	}
629
+
630
+
631
+	/**
632
+	 * Returns the HTML for the form, except for the form opening and closing tags
633
+	 * (as the form section doesn't know where you necessarily want to send the information to),
634
+	 * and except for a submit button. Enqueues JS and CSS; if called early enough we will
635
+	 * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
636
+	 * Not doing_it_wrong because theoretically this CAN be used properly,
637
+	 * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
638
+	 * any CSS.
639
+	 *
640
+	 * @throws InvalidArgumentException
641
+	 * @throws InvalidInterfaceException
642
+	 * @throws InvalidDataTypeException
643
+	 * @throws EE_Error
644
+	 */
645
+	public function get_html_and_js()
646
+	{
647
+		$this->enqueue_js();
648
+		return $this->get_html();
649
+	}
650
+
651
+
652
+	/**
653
+	 * returns HTML for displaying this form section. recursively calls display_section() on all subsections
654
+	 *
655
+	 * @param bool $display_previously_submitted_data
656
+	 * @return string
657
+	 * @throws InvalidArgumentException
658
+	 * @throws InvalidInterfaceException
659
+	 * @throws InvalidDataTypeException
660
+	 * @throws EE_Error
661
+	 * @throws EE_Error
662
+	 * @throws EE_Error
663
+	 */
664
+	public function get_html($display_previously_submitted_data = true)
665
+	{
666
+		$this->ensure_construct_finalized_called();
667
+		if ($display_previously_submitted_data) {
668
+			$this->populate_from_session();
669
+		}
670
+		return $this->_form_html_filter
671
+			? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
672
+			: $this->_layout_strategy->layout_form();
673
+	}
674
+
675
+
676
+	/**
677
+	 * enqueues JS and CSS for the form.
678
+	 * It is preferred to call this before wp_enqueue_scripts so the
679
+	 * scripts and styles can be put in the header, but if called later
680
+	 * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
681
+	 * only be in the header; but in HTML5 its ok in the body.
682
+	 * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
683
+	 * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
684
+	 *
685
+	 * @return void
686
+	 * @throws EE_Error
687
+	 */
688
+	public function enqueue_js()
689
+	{
690
+		$this->_enqueue_and_localize_form_js();
691
+		foreach ($this->subsections() as $subsection) {
692
+			$subsection->enqueue_js();
693
+		}
694
+	}
695
+
696
+
697
+	/**
698
+	 * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
699
+	 * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
700
+	 * the wp_enqueue_scripts hook.
701
+	 * However, registering the form js and localizing it can happen when we
702
+	 * actually output the form (which is preferred, seeing how teh form's fields
703
+	 * could change until it's actually outputted)
704
+	 *
705
+	 * @param boolean $init_form_validation_automatically whether or not we want the form validation
706
+	 *                                                    to be triggered automatically or not
707
+	 * @return void
708
+	 */
709
+	public static function wp_enqueue_scripts($init_form_validation_automatically = true)
710
+	{
711
+		wp_register_script(
712
+			'ee_form_section_validation',
713
+			EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
714
+			array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
715
+			EVENT_ESPRESSO_VERSION,
716
+			true
717
+		);
718
+		wp_localize_script(
719
+			'ee_form_section_validation',
720
+			'ee_form_section_validation_init',
721
+			array('init' => $init_form_validation_automatically ? '1' : '0')
722
+		);
723
+	}
724
+
725
+
726
+	/**
727
+	 * gets the variables used by form_section_validation.js.
728
+	 * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
729
+	 * but before the wordpress hook wp_loaded
730
+	 *
731
+	 * @throws EE_Error
732
+	 */
733
+	public function _enqueue_and_localize_form_js()
734
+	{
735
+		$this->ensure_construct_finalized_called();
736
+		//actually, we don't want to localize just yet. There may be other forms on the page.
737
+		//so we need to add our form section data to a static variable accessible by all form sections
738
+		//and localize it just before the footer
739
+		$this->localize_validation_rules();
740
+		add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
741
+		add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
742
+	}
743
+
744
+
745
+	/**
746
+	 * add our form section data to a static variable accessible by all form sections
747
+	 *
748
+	 * @param bool $return_for_subsection
749
+	 * @return void
750
+	 * @throws EE_Error
751
+	 */
752
+	public function localize_validation_rules($return_for_subsection = false)
753
+	{
754
+		// we only want to localize vars ONCE for the entire form,
755
+		// so if the form section doesn't have a parent, then it must be the top dog
756
+		if ($return_for_subsection || ! $this->parent_section()) {
757
+			EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array(
758
+				'form_section_id'  => $this->html_id(true),
759
+				'validation_rules' => $this->get_jquery_validation_rules(),
760
+				'other_data'       => $this->get_other_js_data(),
761
+				'errors'           => $this->subsection_validation_errors_by_html_name(),
762
+			);
763
+			EE_Form_Section_Proper::$_scripts_localized                                = true;
764
+		}
765
+	}
766
+
767
+
768
+	/**
769
+	 * Gets an array of extra data that will be useful for client-side javascript.
770
+	 * This is primarily data added by inputs and forms in addition to any
771
+	 * scripts they might enqueue
772
+	 *
773
+	 * @param array $form_other_js_data
774
+	 * @return array
775
+	 * @throws EE_Error
776
+	 */
777
+	public function get_other_js_data($form_other_js_data = array())
778
+	{
779
+		foreach ($this->subsections() as $subsection) {
780
+			$form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
781
+		}
782
+		return $form_other_js_data;
783
+	}
784
+
785
+
786
+	/**
787
+	 * Gets a flat array of inputs for this form section and its subsections.
788
+	 * Keys are their form names, and values are the inputs themselves
789
+	 *
790
+	 * @return EE_Form_Input_Base
791
+	 * @throws EE_Error
792
+	 */
793
+	public function inputs_in_subsections()
794
+	{
795
+		$inputs = array();
796
+		foreach ($this->subsections() as $subsection) {
797
+			if ($subsection instanceof EE_Form_Input_Base) {
798
+				$inputs[ $subsection->html_name() ] = $subsection;
799
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
800
+				$inputs += $subsection->inputs_in_subsections();
801
+			}
802
+		}
803
+		return $inputs;
804
+	}
805
+
806
+
807
+	/**
808
+	 * Gets a flat array of all the validation errors.
809
+	 * Keys are html names (because those should be unique)
810
+	 * and values are a string of all their validation errors
811
+	 *
812
+	 * @return string[]
813
+	 * @throws EE_Error
814
+	 */
815
+	public function subsection_validation_errors_by_html_name()
816
+	{
817
+		$inputs = $this->inputs();
818
+		$errors = array();
819
+		foreach ($inputs as $form_input) {
820
+			if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
821
+				$errors[ $form_input->html_name() ] = $form_input->get_validation_error_string();
822
+			}
823
+		}
824
+		return $errors;
825
+	}
826
+
827
+
828
+	/**
829
+	 * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
830
+	 * Should be setup by each form during the _enqueues_and_localize_form_js
831
+	 *
832
+	 * @throws InvalidArgumentException
833
+	 * @throws InvalidInterfaceException
834
+	 * @throws InvalidDataTypeException
835
+	 */
836
+	public static function localize_script_for_all_forms()
837
+	{
838
+		//allow inputs and stuff to hook in their JS and stuff here
839
+		do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
840
+		EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
841
+		$email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
842
+			? EE_Registry::instance()->CFG->registration->email_validation_level
843
+			: 'wp_default';
844
+		EE_Form_Section_Proper::$_js_localization['email_validation_level']   = $email_validation_level;
845
+		wp_enqueue_script('ee_form_section_validation');
846
+		wp_localize_script(
847
+			'ee_form_section_validation',
848
+			'ee_form_section_vars',
849
+			EE_Form_Section_Proper::$_js_localization
850
+		);
851
+	}
852
+
853
+
854
+	/**
855
+	 * ensure_scripts_localized
856
+	 *
857
+	 * @throws EE_Error
858
+	 */
859
+	public function ensure_scripts_localized()
860
+	{
861
+		if (! EE_Form_Section_Proper::$_scripts_localized) {
862
+			$this->_enqueue_and_localize_form_js();
863
+		}
864
+	}
865
+
866
+
867
+	/**
868
+	 * Gets the hard-coded validation error messages to be used in the JS. The convention
869
+	 * is that the key here should be the same as the custom validation rule put in the JS file
870
+	 *
871
+	 * @return array keys are custom validation rules, and values are internationalized strings
872
+	 */
873
+	private static function _get_localized_error_messages()
874
+	{
875
+		return array(
876
+			'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'),
877
+			'regex'    => esc_html__('Please check your input', 'event_espresso'),
878
+		);
879
+	}
880
+
881
+
882
+	/**
883
+	 * @return array
884
+	 */
885
+	public static function js_localization()
886
+	{
887
+		return self::$_js_localization;
888
+	}
889
+
890
+
891
+	/**
892
+	 * @return void
893
+	 */
894
+	public static function reset_js_localization()
895
+	{
896
+		self::$_js_localization = array();
897
+	}
898
+
899
+
900
+	/**
901
+	 * Gets the JS to put inside the jquery validation rules for subsection of this form section.
902
+	 * See parent function for more...
903
+	 *
904
+	 * @return array
905
+	 * @throws EE_Error
906
+	 */
907
+	public function get_jquery_validation_rules()
908
+	{
909
+		$jquery_validation_rules = array();
910
+		foreach ($this->get_validatable_subsections() as $subsection) {
911
+			$jquery_validation_rules = array_merge(
912
+				$jquery_validation_rules,
913
+				$subsection->get_jquery_validation_rules()
914
+			);
915
+		}
916
+		return $jquery_validation_rules;
917
+	}
918
+
919
+
920
+	/**
921
+	 * Sanitizes all the data and sets the sanitized value of each field
922
+	 *
923
+	 * @param array $req_data like $_POST
924
+	 * @return void
925
+	 * @throws EE_Error
926
+	 */
927
+	protected function _normalize($req_data)
928
+	{
929
+		$this->_received_submission = true;
930
+		$this->_validation_errors   = array();
931
+		foreach ($this->get_validatable_subsections() as $subsection) {
932
+			try {
933
+				$subsection->_normalize($req_data);
934
+			} catch (EE_Validation_Error $e) {
935
+				$subsection->add_validation_error($e);
936
+			}
937
+		}
938
+	}
939
+
940
+
941
+	/**
942
+	 * Performs validation on this form section and its subsections.
943
+	 * For each subsection,
944
+	 * calls _validate_{subsection_name} on THIS form (if the function exists)
945
+	 * and passes it the subsection, then calls _validate on that subsection.
946
+	 * If you need to perform validation on the form as a whole (considering multiple)
947
+	 * you would be best to override this _validate method,
948
+	 * calling parent::_validate() first.
949
+	 *
950
+	 * @throws EE_Error
951
+	 */
952
+	protected function _validate()
953
+	{
954
+		//reset the cache of whether this form is valid or not- we're re-validating it now
955
+		$this->is_valid = null;
956
+		foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
957
+			if (method_exists($this, '_validate_' . $subsection_name)) {
958
+				call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
959
+			}
960
+			$subsection->_validate();
961
+		}
962
+	}
963
+
964
+
965
+	/**
966
+	 * Gets all the validated inputs for the form section
967
+	 *
968
+	 * @return array
969
+	 * @throws EE_Error
970
+	 */
971
+	public function valid_data()
972
+	{
973
+		$inputs = array();
974
+		foreach ($this->subsections() as $subsection_name => $subsection) {
975
+			if ($subsection instanceof EE_Form_Section_Proper) {
976
+				$inputs[ $subsection_name ] = $subsection->valid_data();
977
+			} elseif ($subsection instanceof EE_Form_Input_Base) {
978
+				$inputs[ $subsection_name ] = $subsection->normalized_value();
979
+			}
980
+		}
981
+		return $inputs;
982
+	}
983
+
984
+
985
+	/**
986
+	 * Gets all the inputs on this form section
987
+	 *
988
+	 * @return EE_Form_Input_Base[]
989
+	 * @throws EE_Error
990
+	 */
991
+	public function inputs()
992
+	{
993
+		$inputs = array();
994
+		foreach ($this->subsections() as $subsection_name => $subsection) {
995
+			if ($subsection instanceof EE_Form_Input_Base) {
996
+				$inputs[ $subsection_name ] = $subsection;
997
+			}
998
+		}
999
+		return $inputs;
1000
+	}
1001
+
1002
+
1003
+	/**
1004
+	 * Gets all the subsections which are a proper form
1005
+	 *
1006
+	 * @return EE_Form_Section_Proper[]
1007
+	 * @throws EE_Error
1008
+	 */
1009
+	public function subforms()
1010
+	{
1011
+		$form_sections = array();
1012
+		foreach ($this->subsections() as $name => $obj) {
1013
+			if ($obj instanceof EE_Form_Section_Proper) {
1014
+				$form_sections[ $name ] = $obj;
1015
+			}
1016
+		}
1017
+		return $form_sections;
1018
+	}
1019
+
1020
+
1021
+	/**
1022
+	 * Gets all the subsections (inputs, proper subsections, or html-only sections).
1023
+	 * Consider using inputs() or subforms()
1024
+	 * if you only want form inputs or proper form sections.
1025
+	 *
1026
+	 * @param boolean $require_construction_to_be_finalized most client code should
1027
+	 *                                                      leave this as TRUE so that the inputs will be properly
1028
+	 *                                                      configured. However, some client code may be ok with
1029
+	 *                                                      construction finalize being called later
1030
+	 *                                                      (realizing that the subsections' html names might not be
1031
+	 *                                                      set yet, etc.)
1032
+	 * @return EE_Form_Section_Proper[]
1033
+	 * @throws EE_Error
1034
+	 */
1035
+	public function subsections($require_construction_to_be_finalized = true)
1036
+	{
1037
+		if ($require_construction_to_be_finalized) {
1038
+			$this->ensure_construct_finalized_called();
1039
+		}
1040
+		return $this->_subsections;
1041
+	}
1042
+
1043
+
1044
+	/**
1045
+	 * Returns whether this form has any subforms or inputs
1046
+	 * @return bool
1047
+	 */
1048
+	public function hasSubsections()
1049
+	{
1050
+		return ! empty($this->_subsections);
1051
+	}
1052
+
1053
+
1054
+	/**
1055
+	 * Returns a simple array where keys are input names, and values are their normalized
1056
+	 * values. (Similar to calling get_input_value on inputs)
1057
+	 *
1058
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1059
+	 *                                        or just this forms' direct children inputs
1060
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1061
+	 *                                        or allow multidimensional array
1062
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
1063
+	 *                                        with array keys being input names
1064
+	 *                                        (regardless of whether they are from a subsection or not),
1065
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1066
+	 *                                        where keys are always subsection names and values are either
1067
+	 *                                        the input's normalized value, or an array like the top-level array
1068
+	 * @throws EE_Error
1069
+	 */
1070
+	public function input_values($include_subform_inputs = false, $flatten = false)
1071
+	{
1072
+		return $this->_input_values(false, $include_subform_inputs, $flatten);
1073
+	}
1074
+
1075
+
1076
+	/**
1077
+	 * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
1078
+	 * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
1079
+	 * is not necessarily the value we want to display to users. This creates an array
1080
+	 * where keys are the input names, and values are their display values
1081
+	 *
1082
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1083
+	 *                                        or just this forms' direct children inputs
1084
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1085
+	 *                                        or allow multidimensional array
1086
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
1087
+	 *                                        with array keys being input names
1088
+	 *                                        (regardless of whether they are from a subsection or not),
1089
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1090
+	 *                                        where keys are always subsection names and values are either
1091
+	 *                                        the input's normalized value, or an array like the top-level array
1092
+	 * @throws EE_Error
1093
+	 */
1094
+	public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1095
+	{
1096
+		return $this->_input_values(true, $include_subform_inputs, $flatten);
1097
+	}
1098
+
1099
+
1100
+	/**
1101
+	 * Gets the input values from the form
1102
+	 *
1103
+	 * @param boolean $pretty                 Whether to retrieve the pretty value,
1104
+	 *                                        or just the normalized value
1105
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1106
+	 *                                        or just this forms' direct children inputs
1107
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1108
+	 *                                        or allow multidimensional array
1109
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1110
+	 *                                        input names (regardless of whether they are from a subsection or not),
1111
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1112
+	 *                                        where keys are always subsection names and values are either
1113
+	 *                                        the input's normalized value, or an array like the top-level array
1114
+	 * @throws EE_Error
1115
+	 */
1116
+	public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1117
+	{
1118
+		$input_values = array();
1119
+		foreach ($this->subsections() as $subsection_name => $subsection) {
1120
+			if ($subsection instanceof EE_Form_Input_Base) {
1121
+				$input_values[ $subsection_name ] = $pretty
1122
+					? $subsection->pretty_value()
1123
+					: $subsection->normalized_value();
1124
+			} elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1125
+				$subform_input_values = $subsection->_input_values(
1126
+					$pretty,
1127
+					$include_subform_inputs,
1128
+					$flatten
1129
+				);
1130
+				if ($flatten) {
1131
+					$input_values = array_merge($input_values, $subform_input_values);
1132
+				} else {
1133
+					$input_values[ $subsection_name ] = $subform_input_values;
1134
+				}
1135
+			}
1136
+		}
1137
+		return $input_values;
1138
+	}
1139
+
1140
+
1141
+	/**
1142
+	 * Gets the originally submitted input values from the form
1143
+	 *
1144
+	 * @param boolean $include_subforms  Whether to include inputs from subforms,
1145
+	 *                                   or just this forms' direct children inputs
1146
+	 * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1147
+	 *                                   with array keys being input names
1148
+	 *                                   (regardless of whether they are from a subsection or not),
1149
+	 *                                   and if $flatten is FALSE it can be a multidimensional array
1150
+	 *                                   where keys are always subsection names and values are either
1151
+	 *                                   the input's normalized value, or an array like the top-level array
1152
+	 * @throws EE_Error
1153
+	 */
1154
+	public function submitted_values($include_subforms = false)
1155
+	{
1156
+		$submitted_values = array();
1157
+		foreach ($this->subsections() as $subsection) {
1158
+			if ($subsection instanceof EE_Form_Input_Base) {
1159
+				// is this input part of an array of inputs?
1160
+				if (strpos($subsection->html_name(), '[') !== false) {
1161
+					$full_input_name  = EEH_Array::convert_array_values_to_keys(
1162
+						explode(
1163
+							'[',
1164
+							str_replace(']', '', $subsection->html_name())
1165
+						),
1166
+						$subsection->raw_value()
1167
+					);
1168
+					$submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1169
+				} else {
1170
+					$submitted_values[ $subsection->html_name() ] = $subsection->raw_value();
1171
+				}
1172
+			} elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1173
+				$subform_input_values = $subsection->submitted_values($include_subforms);
1174
+				$submitted_values     = array_replace_recursive($submitted_values, $subform_input_values);
1175
+			}
1176
+		}
1177
+		return $submitted_values;
1178
+	}
1179
+
1180
+
1181
+	/**
1182
+	 * Indicates whether or not this form has received a submission yet
1183
+	 * (ie, had receive_form_submission called on it yet)
1184
+	 *
1185
+	 * @return boolean
1186
+	 * @throws EE_Error
1187
+	 */
1188
+	public function has_received_submission()
1189
+	{
1190
+		$this->ensure_construct_finalized_called();
1191
+		return $this->_received_submission;
1192
+	}
1193
+
1194
+
1195
+	/**
1196
+	 * Equivalent to passing 'exclude' in the constructor's options array.
1197
+	 * Removes the listed inputs from the form
1198
+	 *
1199
+	 * @param array $inputs_to_exclude values are the input names
1200
+	 * @return void
1201
+	 */
1202
+	public function exclude(array $inputs_to_exclude = array())
1203
+	{
1204
+		foreach ($inputs_to_exclude as $input_to_exclude_name) {
1205
+			unset($this->_subsections[ $input_to_exclude_name ]);
1206
+		}
1207
+	}
1208
+
1209
+
1210
+	/**
1211
+	 * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy.
1212
+	 * @param array $inputs_to_hide
1213
+	 * @throws EE_Error
1214
+	 */
1215
+	public function hide(array $inputs_to_hide = array())
1216
+	{
1217
+		foreach ($inputs_to_hide as $input_to_hide) {
1218
+			$input = $this->get_input($input_to_hide);
1219
+			$input->set_display_strategy(new EE_Hidden_Display_Strategy());
1220
+		}
1221
+	}
1222
+
1223
+
1224
+	/**
1225
+	 * add_subsections
1226
+	 * Adds the listed subsections to the form section.
1227
+	 * If $subsection_name_to_target is provided,
1228
+	 * then new subsections are added before or after that subsection,
1229
+	 * otherwise to the start or end of the entire subsections array.
1230
+	 *
1231
+	 * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1232
+	 *                                                          where keys are their names
1233
+	 * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1234
+	 *                                                          should be added before or after
1235
+	 *                                                          IF $subsection_name_to_target is null,
1236
+	 *                                                          then $new_subsections will be added to
1237
+	 *                                                          the beginning or end of the entire subsections array
1238
+	 * @param boolean                $add_before                whether to add $new_subsections, before or after
1239
+	 *                                                          $subsection_name_to_target,
1240
+	 *                                                          or if $subsection_name_to_target is null,
1241
+	 *                                                          before or after entire subsections array
1242
+	 * @return void
1243
+	 * @throws EE_Error
1244
+	 */
1245
+	public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1246
+	{
1247
+		foreach ($new_subsections as $subsection_name => $subsection) {
1248
+			if (! $subsection instanceof EE_Form_Section_Base) {
1249
+				EE_Error::add_error(
1250
+					sprintf(
1251
+						esc_html__(
1252
+							"Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1253
+							'event_espresso'
1254
+						),
1255
+						get_class($subsection),
1256
+						$subsection_name,
1257
+						$this->name()
1258
+					)
1259
+				);
1260
+				unset($new_subsections[ $subsection_name ]);
1261
+			}
1262
+		}
1263
+		$this->_subsections = EEH_Array::insert_into_array(
1264
+			$this->_subsections,
1265
+			$new_subsections,
1266
+			$subsection_name_to_target,
1267
+			$add_before
1268
+		);
1269
+		if ($this->_construction_finalized) {
1270
+			foreach ($this->_subsections as $name => $subsection) {
1271
+				$subsection->_construct_finalize($this, $name);
1272
+			}
1273
+		}
1274
+	}
1275
+
1276
+
1277
+	/**
1278
+	 * @param string $subsection_name
1279
+	 * @param bool   $recursive
1280
+	 * @return bool
1281
+	 */
1282
+	public function has_subsection($subsection_name, $recursive = false)
1283
+	{
1284
+		foreach ($this->_subsections as $name => $subsection) {if(
1285
+				$name === $subsection_name
1286
+				|| (
1287
+					$recursive
1288
+					&& $subsection instanceof EE_Form_Section_Proper
1289
+					&& $subsection->has_subsection($subsection_name, $recursive)
1290
+				)
1291
+			) {
1292
+				return true;
1293
+			}
1294
+		}
1295
+		return false;
1296
+	}
1297
+
1298
+
1299
+
1300
+	/**
1301
+	 * Just gets all validatable subsections to clean their sensitive data
1302
+	 *
1303
+	 * @throws EE_Error
1304
+	 */
1305
+	public function clean_sensitive_data()
1306
+	{
1307
+		foreach ($this->get_validatable_subsections() as $subsection) {
1308
+			$subsection->clean_sensitive_data();
1309
+		}
1310
+	}
1311
+
1312
+
1313
+	/**
1314
+	 * Sets the submission error message (aka validation error message for this form section and all sub-sections)
1315
+	 * @param string                           $form_submission_error_message
1316
+	 * @param EE_Form_Section_Validatable $form_section unused
1317
+	 * @throws EE_Error
1318
+	 */
1319
+	public function set_submission_error_message(
1320
+		$form_submission_error_message = ''
1321
+	) {
1322
+		$this->_form_submission_error_message = ! empty($form_submission_error_message)
1323
+			? $form_submission_error_message
1324
+			: $this->getAllValidationErrorsString();
1325
+	}
1326
+
1327
+
1328
+	/**
1329
+	 * Returns the cached error message. A default value is set for this during _validate(),
1330
+	 * (called during receive_form_submission) but it can be explicitly set using
1331
+	 * set_submission_error_message
1332
+	 *
1333
+	 * @return string
1334
+	 */
1335
+	public function submission_error_message()
1336
+	{
1337
+		return $this->_form_submission_error_message;
1338
+	}
1339
+
1340
+
1341
+	/**
1342
+	 * Sets a message to display if the data submitted to the form was valid.
1343
+	 * @param string $form_submission_success_message
1344
+	 */
1345
+	public function set_submission_success_message($form_submission_success_message = '')
1346
+	{
1347
+		$this->_form_submission_success_message = ! empty($form_submission_success_message)
1348
+			? $form_submission_success_message
1349
+			: esc_html__('Form submitted successfully', 'event_espresso');
1350
+	}
1351
+
1352
+
1353
+	/**
1354
+	 * Gets a message appropriate for display when the form is correctly submitted
1355
+	 * @return string
1356
+	 */
1357
+	public function submission_success_message()
1358
+	{
1359
+		return $this->_form_submission_success_message;
1360
+	}
1361
+
1362
+
1363
+	/**
1364
+	 * Returns the prefix that should be used on child of this form section for
1365
+	 * their html names. If this form section itself has a parent, prepends ITS
1366
+	 * prefix onto this form section's prefix. Used primarily by
1367
+	 * EE_Form_Input_Base::_set_default_html_name_if_empty
1368
+	 *
1369
+	 * @return string
1370
+	 * @throws EE_Error
1371
+	 */
1372
+	public function html_name_prefix()
1373
+	{
1374
+		if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1375
+			return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1376
+		}
1377
+		return $this->name();
1378
+	}
1379
+
1380
+
1381
+	/**
1382
+	 * Gets the name, but first checks _construct_finalize has been called. If not,
1383
+	 * calls it (assumes there is no parent and that we want the name to be whatever
1384
+	 * was set, which is probably nothing, or the classname)
1385
+	 *
1386
+	 * @return string
1387
+	 * @throws EE_Error
1388
+	 */
1389
+	public function name()
1390
+	{
1391
+		$this->ensure_construct_finalized_called();
1392
+		return parent::name();
1393
+	}
1394
+
1395
+
1396
+	/**
1397
+	 * @return EE_Form_Section_Proper
1398
+	 * @throws EE_Error
1399
+	 */
1400
+	public function parent_section()
1401
+	{
1402
+		$this->ensure_construct_finalized_called();
1403
+		return parent::parent_section();
1404
+	}
1405
+
1406
+
1407
+	/**
1408
+	 * make sure construction finalized was called, otherwise children might not be ready
1409
+	 *
1410
+	 * @return void
1411
+	 * @throws EE_Error
1412
+	 */
1413
+	public function ensure_construct_finalized_called()
1414
+	{
1415
+		if (! $this->_construction_finalized) {
1416
+			$this->_construct_finalize($this->_parent_section, $this->_name);
1417
+		}
1418
+	}
1419
+
1420
+
1421
+	/**
1422
+	 * Checks if any of this form section's inputs, or any of its children's inputs,
1423
+	 * are in teh form data. If any are found, returns true. Else false
1424
+	 *
1425
+	 * @param array $req_data
1426
+	 * @return boolean
1427
+	 * @throws EE_Error
1428
+	 */
1429
+	public function form_data_present_in($req_data = null)
1430
+	{
1431
+		$req_data = $this->getCachedRequest($req_data);
1432
+		foreach ($this->subsections() as $subsection) {
1433
+			if ($subsection instanceof EE_Form_Input_Base) {
1434
+				if ($subsection->form_data_present_in($req_data)) {
1435
+					return true;
1436
+				}
1437
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
1438
+				if ($subsection->form_data_present_in($req_data)) {
1439
+					return true;
1440
+				}
1441
+			}
1442
+		}
1443
+		return false;
1444
+	}
1445
+
1446
+
1447
+	/**
1448
+	 * Gets validation errors for this form section and subsections
1449
+	 * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1450
+	 * gets the validation errors for ALL subsection
1451
+	 *
1452
+	 * @return EE_Validation_Error[]
1453
+	 * @throws EE_Error
1454
+	 */
1455
+	public function get_validation_errors_accumulated()
1456
+	{
1457
+		$validation_errors = $this->get_validation_errors();
1458
+		foreach ($this->get_validatable_subsections() as $subsection) {
1459
+			if ($subsection instanceof EE_Form_Section_Proper) {
1460
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1461
+			} else {
1462
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors();
1463
+			}
1464
+			if ($validation_errors_on_this_subsection) {
1465
+				$validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1466
+			}
1467
+		}
1468
+		return $validation_errors;
1469
+	}
1470
+
1471
+	/**
1472
+	 * Fetch validation errors from children and grandchildren and puts them in a single string.
1473
+	 * This traverses the form section tree to generate this, but you probably want to instead use
1474
+	 * get_form_submission_error_message() which is usually this message cached (or a custom validation error message)
1475
+	 *
1476
+	 * @return string
1477
+	 * @since 4.9.59.p
1478
+	 */
1479
+	protected function getAllValidationErrorsString()
1480
+	{
1481
+		$submission_error_messages = array();
1482
+		// bad, bad, bad registrant
1483
+		foreach ($this->get_validation_errors_accumulated() as $validation_error) {
1484
+			if ($validation_error instanceof EE_Validation_Error) {
1485
+				$form_section = $validation_error->get_form_section();
1486
+				if ($form_section instanceof EE_Form_Input_Base) {
1487
+				   $label = $validation_error->get_form_section()->html_label_text();
1488
+				} elseif($form_section instanceof EE_Form_Section_Validatable) {
1489
+					$label = $validation_error->get_form_section()->name();
1490
+				} else {
1491
+					$label = esc_html__('Unknown', 'event_espresso');
1492
+				}
1493
+				$submission_error_messages[] = sprintf(
1494
+					__('%s : %s', 'event_espresso'),
1495
+					$label,
1496
+					$validation_error->getMessage()
1497
+				);
1498
+			}
1499
+		}
1500
+		return implode('<br', $submission_error_messages);
1501
+	}
1502
+
1503
+
1504
+	/**
1505
+	 * This isn't just the name of an input, it's a path pointing to an input. The
1506
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
1507
+	 * dot-dot-slash (../) means to ascend into the parent section.
1508
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1509
+	 * which will be returned.
1510
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1511
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1512
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1513
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1514
+	 * Etc
1515
+	 *
1516
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1517
+	 * @return EE_Form_Section_Base
1518
+	 * @throws EE_Error
1519
+	 */
1520
+	public function find_section_from_path($form_section_path)
1521
+	{
1522
+		//check if we can find the input from purely going straight up the tree
1523
+		$input = parent::find_section_from_path($form_section_path);
1524
+		if ($input instanceof EE_Form_Section_Base) {
1525
+			return $input;
1526
+		}
1527
+		$next_slash_pos = strpos($form_section_path, '/');
1528
+		if ($next_slash_pos !== false) {
1529
+			$child_section_name = substr($form_section_path, 0, $next_slash_pos);
1530
+			$subpath            = substr($form_section_path, $next_slash_pos + 1);
1531
+		} else {
1532
+			$child_section_name = $form_section_path;
1533
+			$subpath            = '';
1534
+		}
1535
+		$child_section = $this->get_subsection($child_section_name);
1536
+		if ($child_section instanceof EE_Form_Section_Base) {
1537
+			return $child_section->find_section_from_path($subpath);
1538
+		}
1539
+		return null;
1540
+	}
1541 1541
 }
1542 1542
 
Please login to merge, or discard this patch.
core/domain/Domain.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -19,54 +19,54 @@
 block discarded – undo
19 19
 class Domain extends DomainBase implements CaffeinatedInterface
20 20
 {
21 21
 
22
-    /**
23
-     * URL path component used to denote an API request
24
-     */
25
-    const API_NAMESPACE = 'ee/v';
22
+	/**
23
+	 * URL path component used to denote an API request
24
+	 */
25
+	const API_NAMESPACE = 'ee/v';
26 26
 
27
-    /**
28
-     * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin
29
-     * Page ui.
30
-     */
31
-    const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN
32
-        = 'manual_registration_status_change_from_registration_admin';
27
+	/**
28
+	 * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin
29
+	 * Page ui.
30
+	 */
31
+	const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN
32
+		= 'manual_registration_status_change_from_registration_admin';
33 33
 
34
-    const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
35
-        = 'manual_registration_status_change_from_registration_admin_and_notify';
34
+	const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
35
+		= 'manual_registration_status_change_from_registration_admin_and_notify';
36 36
 
37 37
 
38
-    /**
39
-     * Whether or not EE core is the full premium version.
40
-     * @since 4.9.59.p
41
-     * @var bool
42
-     */
43
-    private $caffeinated;
38
+	/**
39
+	 * Whether or not EE core is the full premium version.
40
+	 * @since 4.9.59.p
41
+	 * @var bool
42
+	 */
43
+	private $caffeinated;
44 44
 
45 45
 
46
-    public function __construct(FilePath $plugin_file, Version $version)
47
-    {
48
-        parent::__construct($plugin_file, $version);
49
-        $this->setCaffeinated();
50
-    }
46
+	public function __construct(FilePath $plugin_file, Version $version)
47
+	{
48
+		parent::__construct($plugin_file, $version);
49
+		$this->setCaffeinated();
50
+	}
51 51
 
52
-    /**
53
-     * Whether or not EE core is the full premium version.
54
-     * @since 4.9.59.p
55
-     * @return bool
56
-     */
57
-    public function isCaffeinated()
58
-    {
59
-        return $this->caffeinated;
60
-    }
52
+	/**
53
+	 * Whether or not EE core is the full premium version.
54
+	 * @since 4.9.59.p
55
+	 * @return bool
56
+	 */
57
+	public function isCaffeinated()
58
+	{
59
+		return $this->caffeinated;
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * Setter for $is_caffeinated property.
65
-     * @since 4.9.59.p
66
-     */
67
-    private function setCaffeinated()
68
-    {
69
-        $this->caffeinated = (! defined('EE_DECAF') || EE_DECAF !== true)
70
-            && is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php');
71
-    }
63
+	/**
64
+	 * Setter for $is_caffeinated property.
65
+	 * @since 4.9.59.p
66
+	 */
67
+	private function setCaffeinated()
68
+	{
69
+		$this->caffeinated = (! defined('EE_DECAF') || EE_DECAF !== true)
70
+			&& is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php');
71
+	}
72 72
 }
Please login to merge, or discard this patch.
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 1 patch
Indentation   +1844 added lines, -1844 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use EventEspresso\core\exceptions\InvalidEntityException;
6 6
 
7 7
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
8
-    exit('No direct script access allowed');
8
+	exit('No direct script access allowed');
9 9
 }
10 10
 
11 11
 
@@ -20,1849 +20,1849 @@  discard block
 block discarded – undo
20 20
 class EED_Single_Page_Checkout extends EED_Module
21 21
 {
22 22
 
23
-    /**
24
-     * $_initialized - has the SPCO controller already been initialized ?
25
-     *
26
-     * @access private
27
-     * @var bool $_initialized
28
-     */
29
-    private static $_initialized = false;
30
-
31
-
32
-    /**
33
-     * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
34
-     *
35
-     * @access private
36
-     * @var bool $_valid_checkout
37
-     */
38
-    private static $_checkout_verified = true;
39
-
40
-    /**
41
-     *    $_reg_steps_array - holds initial array of reg steps
42
-     *
43
-     * @access private
44
-     * @var array $_reg_steps_array
45
-     */
46
-    private static $_reg_steps_array = array();
47
-
48
-    /**
49
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
50
-     *
51
-     * @access public
52
-     * @var EE_Checkout $checkout
53
-     */
54
-    public $checkout;
55
-
56
-
57
-
58
-    /**
59
-     * @return EED_Module|EED_Single_Page_Checkout
60
-     */
61
-    public static function instance()
62
-    {
63
-        add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
64
-        return parent::get_instance(__CLASS__);
65
-    }
66
-
67
-
68
-
69
-    /**
70
-     * @return EE_CART
71
-     */
72
-    public function cart()
73
-    {
74
-        return $this->checkout->cart;
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * @return EE_Transaction
81
-     */
82
-    public function transaction()
83
-    {
84
-        return $this->checkout->transaction;
85
-    }
86
-
87
-
88
-
89
-    /**
90
-     *    set_hooks - for hooking into EE Core, other modules, etc
91
-     *
92
-     * @access    public
93
-     * @return    void
94
-     * @throws EE_Error
95
-     */
96
-    public static function set_hooks()
97
-    {
98
-        EED_Single_Page_Checkout::set_definitions();
99
-    }
100
-
101
-
102
-
103
-    /**
104
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
105
-     *
106
-     * @access    public
107
-     * @return    void
108
-     * @throws EE_Error
109
-     */
110
-    public static function set_hooks_admin()
111
-    {
112
-        EED_Single_Page_Checkout::set_definitions();
113
-        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
114
-            return;
115
-        }
116
-        // going to start an output buffer in case anything gets accidentally output
117
-        // that might disrupt our JSON response
118
-        ob_start();
119
-        EED_Single_Page_Checkout::load_request_handler();
120
-        EED_Single_Page_Checkout::load_reg_steps();
121
-        // set ajax hooks
122
-        add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
123
-        add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
-        add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
125
-        add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
-        add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
127
-        add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     *    process ajax request
134
-     *
135
-     * @param string $ajax_action
136
-     * @throws EE_Error
137
-     */
138
-    public static function process_ajax_request($ajax_action)
139
-    {
140
-        EE_Registry::instance()->REQ->set('action', $ajax_action);
141
-        EED_Single_Page_Checkout::instance()->_initialize();
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     *    ajax display registration step
148
-     *
149
-     * @throws EE_Error
150
-     */
151
-    public static function display_reg_step()
152
-    {
153
-        EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     *    ajax process registration step
160
-     *
161
-     * @throws EE_Error
162
-     */
163
-    public static function process_reg_step()
164
-    {
165
-        EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     *    ajax process registration step
172
-     *
173
-     * @throws EE_Error
174
-     */
175
-    public static function update_reg_step()
176
-    {
177
-        EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     *   update_checkout
184
-     *
185
-     * @access public
186
-     * @return void
187
-     * @throws EE_Error
188
-     */
189
-    public static function update_checkout()
190
-    {
191
-        EED_Single_Page_Checkout::process_ajax_request('update_checkout');
192
-    }
193
-
194
-
195
-
196
-    /**
197
-     *    load_request_handler
198
-     *
199
-     * @access    public
200
-     * @return    void
201
-     */
202
-    public static function load_request_handler()
203
-    {
204
-        // load core Request_Handler class
205
-        if (EE_Registry::instance()->REQ !== null) {
206
-            EE_Registry::instance()->load_core('Request_Handler');
207
-        }
208
-    }
209
-
210
-
211
-
212
-    /**
213
-     *    set_definitions
214
-     *
215
-     * @access    public
216
-     * @return    void
217
-     * @throws EE_Error
218
-     */
219
-    public static function set_definitions()
220
-    {
221
-        if(defined('SPCO_BASE_PATH')) {
222
-            return;
223
-        }
224
-        define(
225
-            'SPCO_BASE_PATH',
226
-            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
227
-        );
228
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
234
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
236
-    }
237
-
238
-
239
-
240
-    /**
241
-     * load_reg_steps
242
-     * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
243
-     *
244
-     * @access    private
245
-     * @throws EE_Error
246
-     */
247
-    public static function load_reg_steps()
248
-    {
249
-        static $reg_steps_loaded = false;
250
-        if ($reg_steps_loaded) {
251
-            return;
252
-        }
253
-        // filter list of reg_steps
254
-        $reg_steps_to_load = (array)apply_filters(
255
-            'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
256
-            EED_Single_Page_Checkout::get_reg_steps()
257
-        );
258
-        // sort by key (order)
259
-        ksort($reg_steps_to_load);
260
-        // loop through folders
261
-        foreach ($reg_steps_to_load as $order => $reg_step) {
262
-            // we need a
263
-            if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
264
-                // copy over to the reg_steps_array
265
-                EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
266
-                // register custom key route for each reg step
267
-                // ie: step=>"slug" - this is the entire reason we load the reg steps array now
268
-                EE_Config::register_route(
269
-                    $reg_step['slug'],
270
-                    'EED_Single_Page_Checkout',
271
-                    'run',
272
-                    'step'
273
-                );
274
-                // add AJAX or other hooks
275
-                if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
276
-                    // setup autoloaders if necessary
277
-                    if ( ! class_exists($reg_step['class_name'])) {
278
-                        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
279
-                            $reg_step['file_path'],
280
-                            true
281
-                        );
282
-                    }
283
-                    if (is_callable($reg_step['class_name'], 'set_hooks')) {
284
-                        call_user_func(array($reg_step['class_name'], 'set_hooks'));
285
-                    }
286
-                }
287
-            }
288
-        }
289
-        $reg_steps_loaded = true;
290
-    }
291
-
292
-
293
-
294
-    /**
295
-     *    get_reg_steps
296
-     *
297
-     * @access    public
298
-     * @return    array
299
-     */
300
-    public static function get_reg_steps()
301
-    {
302
-        $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
303
-        if (empty($reg_steps)) {
304
-            $reg_steps = array(
305
-                10  => array(
306
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
307
-                    'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
308
-                    'slug'       => 'attendee_information',
309
-                    'has_hooks'  => false,
310
-                ),
311
-                20  => array(
312
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
313
-                    'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
314
-                    'slug'       => 'registration_confirmation',
315
-                    'has_hooks'  => false,
316
-                ),
317
-                30  => array(
318
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
319
-                    'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
320
-                    'slug'       => 'payment_options',
321
-                    'has_hooks'  => true,
322
-                ),
323
-                999 => array(
324
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
325
-                    'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
326
-                    'slug'       => 'finalize_registration',
327
-                    'has_hooks'  => false,
328
-                ),
329
-            );
330
-        }
331
-        return $reg_steps;
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     *    registration_checkout_for_admin
338
-     *
339
-     * @access    public
340
-     * @return    string
341
-     * @throws EE_Error
342
-     */
343
-    public static function registration_checkout_for_admin()
344
-    {
345
-        EED_Single_Page_Checkout::load_request_handler();
346
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
347
-        EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
348
-        EE_Registry::instance()->REQ->set('process_form_submission', false);
349
-        EED_Single_Page_Checkout::instance()->_initialize();
350
-        EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
351
-        return EE_Registry::instance()->REQ->get_output();
352
-    }
353
-
354
-
355
-
356
-    /**
357
-     * process_registration_from_admin
358
-     *
359
-     * @access public
360
-     * @return \EE_Transaction
361
-     * @throws EE_Error
362
-     */
363
-    public static function process_registration_from_admin()
364
-    {
365
-        EED_Single_Page_Checkout::load_request_handler();
366
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
367
-        EE_Registry::instance()->REQ->set('action', 'process_reg_step');
368
-        EE_Registry::instance()->REQ->set('process_form_submission', true);
369
-        EED_Single_Page_Checkout::instance()->_initialize();
370
-        if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
371
-            $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
372
-            if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
373
-                EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
374
-                if ($final_reg_step->process_reg_step()) {
375
-                    $final_reg_step->set_completed();
376
-                    EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
377
-                    return EED_Single_Page_Checkout::instance()->checkout->transaction;
378
-                }
379
-            }
380
-        }
381
-        return null;
382
-    }
383
-
384
-
385
-
386
-    /**
387
-     *    run
388
-     *
389
-     * @access    public
390
-     * @param WP_Query $WP_Query
391
-     * @return    void
392
-     * @throws EE_Error
393
-     */
394
-    public function run($WP_Query)
395
-    {
396
-        if (
397
-            $WP_Query instanceof WP_Query
398
-            && $WP_Query->is_main_query()
399
-            && apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
400
-            && $this->_is_reg_checkout()
401
-        ) {
402
-            $this->_initialize();
403
-        }
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * determines whether current url matches reg page url
410
-     *
411
-     * @return bool
412
-     */
413
-    protected function _is_reg_checkout()
414
-    {
415
-        // get current permalink for reg page without any extra query args
416
-        $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
417
-        // get request URI for current request, but without the scheme or host
418
-        $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
419
-        $current_request_uri = html_entity_decode($current_request_uri);
420
-        // get array of query args from the current request URI
421
-        $query_args = \EEH_URL::get_query_string($current_request_uri);
422
-        // grab page id if it is set
423
-        $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
424
-        // and remove the page id from the query args (we will re-add it later)
425
-        unset($query_args['page_id']);
426
-        // now strip all query args from current request URI
427
-        $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
428
-        // and re-add the page id if it was set
429
-        if ($page_id) {
430
-            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
431
-        }
432
-        // remove slashes and ?
433
-        $current_request_uri = trim($current_request_uri, '?/');
434
-        // is current request URI part of the known full reg page URL ?
435
-        return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
436
-    }
437
-
438
-
439
-
440
-    /**
441
-     * @param WP_Query $wp_query
442
-     * @return    void
443
-     * @throws EE_Error
444
-     */
445
-    public static function init($wp_query)
446
-    {
447
-        EED_Single_Page_Checkout::instance()->run($wp_query);
448
-    }
449
-
450
-
451
-
452
-    /**
453
-     *    _initialize - initial module setup
454
-     *
455
-     * @access    private
456
-     * @throws EE_Error
457
-     * @return    void
458
-     */
459
-    private function _initialize()
460
-    {
461
-        // ensure SPCO doesn't run twice
462
-        if (EED_Single_Page_Checkout::$_initialized) {
463
-            return;
464
-        }
465
-        try {
466
-            EED_Single_Page_Checkout::load_reg_steps();
467
-            $this->_verify_session();
468
-            // setup the EE_Checkout object
469
-            $this->checkout = $this->_initialize_checkout();
470
-            // filter checkout
471
-            $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
472
-            // get the $_GET
473
-            $this->_get_request_vars();
474
-            if ($this->_block_bots()) {
475
-                return;
476
-            }
477
-            // filter continue_reg
478
-            $this->checkout->continue_reg = apply_filters(
479
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
480
-                true,
481
-                $this->checkout
482
-            );
483
-            // load the reg steps array
484
-            if ( ! $this->_load_and_instantiate_reg_steps()) {
485
-                EED_Single_Page_Checkout::$_initialized = true;
486
-                return;
487
-            }
488
-            // set the current step
489
-            $this->checkout->set_current_step($this->checkout->step);
490
-            // and the next step
491
-            $this->checkout->set_next_step();
492
-            // verify that everything has been setup correctly
493
-            if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
494
-                EED_Single_Page_Checkout::$_initialized = true;
495
-                return;
496
-            }
497
-            // lock the transaction
498
-            $this->checkout->transaction->lock();
499
-            // make sure all of our cached objects are added to their respective model entity mappers
500
-            $this->checkout->refresh_all_entities();
501
-            // set amount owing
502
-            $this->checkout->amount_owing = $this->checkout->transaction->remaining();
503
-            // initialize each reg step, which gives them the chance to potentially alter the process
504
-            $this->_initialize_reg_steps();
505
-            // DEBUG LOG
506
-            //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
507
-            // get reg form
508
-            if( ! $this->_check_form_submission()) {
509
-                EED_Single_Page_Checkout::$_initialized = true;
510
-                return;
511
-            }
512
-            // checkout the action!!!
513
-            $this->_process_form_action();
514
-            // add some style and make it dance
515
-            $this->add_styles_and_scripts();
516
-            // kk... SPCO has successfully run
517
-            EED_Single_Page_Checkout::$_initialized = true;
518
-            // set no cache headers and constants
519
-            EE_System::do_not_cache();
520
-            // add anchor
521
-            add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
522
-            // remove transaction lock
523
-            add_action('shutdown', array($this, 'unlock_transaction'), 1);
524
-        } catch (Exception $e) {
525
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
526
-        }
527
-    }
528
-
529
-
530
-
531
-    /**
532
-     *    _verify_session
533
-     * checks that the session is valid and not expired
534
-     *
535
-     * @access    private
536
-     * @throws EE_Error
537
-     */
538
-    private function _verify_session()
539
-    {
540
-        if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
541
-            throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
542
-        }
543
-        $clear_session_requested = filter_var(
544
-            EE_Registry::instance()->REQ->get('clear_session', false),
545
-            FILTER_VALIDATE_BOOLEAN
546
-        );
547
-        // is session still valid ?
548
-        if ($clear_session_requested
549
-            || ( EE_Registry::instance()->SSN->expired()
550
-              && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
551
-            )
552
-        ) {
553
-            $this->checkout = new EE_Checkout();
554
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
555
-            // EE_Registry::instance()->SSN->reset_cart();
556
-            // EE_Registry::instance()->SSN->reset_checkout();
557
-            // EE_Registry::instance()->SSN->reset_transaction();
558
-            if (! $clear_session_requested) {
559
-                EE_Error::add_attention(
560
-                    EE_Registry::$i18n_js_strings['registration_expiration_notice'],
561
-                    __FILE__, __FUNCTION__, __LINE__
562
-                );
563
-            }
564
-            // EE_Registry::instance()->SSN->reset_expired();
565
-        }
566
-    }
567
-
568
-
569
-
570
-    /**
571
-     *    _initialize_checkout
572
-     * loads and instantiates EE_Checkout
573
-     *
574
-     * @access    private
575
-     * @throws EE_Error
576
-     * @return EE_Checkout
577
-     */
578
-    private function _initialize_checkout()
579
-    {
580
-        // look in session for existing checkout
581
-        /** @type EE_Checkout $checkout */
582
-        $checkout = EE_Registry::instance()->SSN->checkout();
583
-        // verify
584
-        if ( ! $checkout instanceof EE_Checkout) {
585
-            // instantiate EE_Checkout object for handling the properties of the current checkout process
586
-            $checkout = EE_Registry::instance()->load_file(
587
-                SPCO_INC_PATH,
588
-                'EE_Checkout',
589
-                'class', array(),
590
-                false
591
-            );
592
-        } else {
593
-            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
594
-                $this->unlock_transaction();
595
-                wp_safe_redirect($checkout->redirect_url);
596
-                exit();
597
-            }
598
-        }
599
-        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
600
-        // verify again
601
-        if ( ! $checkout instanceof EE_Checkout) {
602
-            throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
603
-        }
604
-        // reset anything that needs a clean slate for each request
605
-        $checkout->reset_for_current_request();
606
-        return $checkout;
607
-    }
608
-
609
-
610
-
611
-    /**
612
-     *    _get_request_vars
613
-     *
614
-     * @access    private
615
-     * @return    void
616
-     * @throws EE_Error
617
-     */
618
-    private function _get_request_vars()
619
-    {
620
-        // load classes
621
-        EED_Single_Page_Checkout::load_request_handler();
622
-        //make sure this request is marked as belonging to EE
623
-        EE_Registry::instance()->REQ->set_espresso_page(true);
624
-        // which step is being requested ?
625
-        $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
626
-        // which step is being edited ?
627
-        $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
628
-        // and what we're doing on the current step
629
-        $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
630
-        // timestamp
631
-        $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
632
-        // returning to edit ?
633
-        $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
634
-        // add reg url link to registration query params
635
-        if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
636
-            $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
637
-        }
638
-        // or some other kind of revisit ?
639
-        $this->checkout->revisit = filter_var(
640
-            EE_Registry::instance()->REQ->get('revisit', false),
641
-            FILTER_VALIDATE_BOOLEAN
642
-        );
643
-        // and whether or not to generate a reg form for this request
644
-        $this->checkout->generate_reg_form = filter_var(
645
-            EE_Registry::instance()->REQ->get('generate_reg_form', true),
646
-            FILTER_VALIDATE_BOOLEAN
647
-        );
648
-        // and whether or not to process a reg form submission for this request
649
-        $this->checkout->process_form_submission = filter_var(
650
-            EE_Registry::instance()->REQ->get(
651
-                'process_form_submission',
652
-                $this->checkout->action === 'process_reg_step'
653
-            ),
654
-            FILTER_VALIDATE_BOOLEAN
655
-        );
656
-        $this->checkout->process_form_submission = filter_var(
657
-            $this->checkout->action !== 'display_spco_reg_step'
658
-                ? $this->checkout->process_form_submission
659
-                : false,
660
-            FILTER_VALIDATE_BOOLEAN
661
-        );
662
-        // $this->_display_request_vars();
663
-    }
664
-
665
-
666
-
667
-    /**
668
-     *  _display_request_vars
669
-     *
670
-     * @access    protected
671
-     * @return    void
672
-     */
673
-    protected function _display_request_vars()
674
-    {
675
-        if ( ! WP_DEBUG) {
676
-            return;
677
-        }
678
-        EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
679
-        EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
680
-        EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
681
-        EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
682
-        EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
683
-        EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
684
-        EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
685
-        EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
686
-    }
687
-
688
-
689
-
690
-    /**
691
-     * _block_bots
692
-     * checks that the incoming request has either of the following set:
693
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
694
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
695
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
696
-     * then where you coming from man?
697
-     *
698
-     * @return boolean
699
-     */
700
-    private function _block_bots()
701
-    {
702
-        $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
703
-        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
704
-            return true;
705
-        }
706
-        return false;
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     *    _get_first_step
713
-     *  gets slug for first step in $_reg_steps_array
714
-     *
715
-     * @access    private
716
-     * @throws EE_Error
717
-     * @return    string
718
-     */
719
-    private function _get_first_step()
720
-    {
721
-        $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
722
-        return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
723
-    }
724
-
725
-
726
-
727
-    /**
728
-     *    _load_and_instantiate_reg_steps
729
-     *  instantiates each reg step based on the loaded reg_steps array
730
-     *
731
-     * @access    private
732
-     * @throws EE_Error
733
-     * @return    bool
734
-     */
735
-    private function _load_and_instantiate_reg_steps()
736
-    {
737
-        do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
738
-        // have reg_steps already been instantiated ?
739
-        if (
740
-            empty($this->checkout->reg_steps)
741
-            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
742
-        ) {
743
-            // if not, then loop through raw reg steps array
744
-            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
745
-                if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
746
-                    return false;
747
-                }
748
-            }
749
-            EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
750
-            EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
751
-            // skip the registration_confirmation page ?
752
-            if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
753
-                // just remove it from the reg steps array
754
-                $this->checkout->remove_reg_step('registration_confirmation', false);
755
-            } else if (
756
-                isset($this->checkout->reg_steps['registration_confirmation'])
757
-                && EE_Registry::instance()->CFG->registration->reg_confirmation_last
758
-            ) {
759
-                // set the order to something big like 100
760
-                $this->checkout->set_reg_step_order('registration_confirmation', 100);
761
-            }
762
-            // filter the array for good luck
763
-            $this->checkout->reg_steps = apply_filters(
764
-                'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
765
-                $this->checkout->reg_steps
766
-            );
767
-            // finally re-sort based on the reg step class order properties
768
-            $this->checkout->sort_reg_steps();
769
-        } else {
770
-            foreach ($this->checkout->reg_steps as $reg_step) {
771
-                // set all current step stati to FALSE
772
-                $reg_step->set_is_current_step(false);
773
-            }
774
-        }
775
-        if (empty($this->checkout->reg_steps)) {
776
-            EE_Error::add_error(
777
-                __('No Reg Steps were loaded..', 'event_espresso'),
778
-                __FILE__, __FUNCTION__, __LINE__
779
-            );
780
-            return false;
781
-        }
782
-        // make reg step details available to JS
783
-        $this->checkout->set_reg_step_JSON_info();
784
-        return true;
785
-    }
786
-
787
-
788
-
789
-    /**
790
-     *     _load_and_instantiate_reg_step
791
-     *
792
-     * @access    private
793
-     * @param array $reg_step
794
-     * @param int   $order
795
-     * @return bool
796
-     */
797
-    private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
798
-    {
799
-        // we need a file_path, class_name, and slug to add a reg step
800
-        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
801
-            // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
802
-            if (
803
-                $this->checkout->reg_url_link
804
-                && $this->checkout->step !== $reg_step['slug']
805
-                && $reg_step['slug'] !== 'finalize_registration'
806
-                // normally at this point we would NOT load the reg step, but this filter can change that
807
-                && apply_filters(
808
-                    'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
809
-                    true,
810
-                    $reg_step,
811
-                    $this->checkout
812
-                )
813
-            ) {
814
-                return true;
815
-            }
816
-            // instantiate step class using file path and class name
817
-            $reg_step_obj = EE_Registry::instance()->load_file(
818
-                $reg_step['file_path'],
819
-                $reg_step['class_name'],
820
-                'class',
821
-                $this->checkout,
822
-                false
823
-            );
824
-            // did we gets the goods ?
825
-            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
826
-                // set reg step order based on config
827
-                $reg_step_obj->set_order($order);
828
-                // add instantiated reg step object to the master reg steps array
829
-                $this->checkout->add_reg_step($reg_step_obj);
830
-            } else {
831
-                EE_Error::add_error(
832
-                    __('The current step could not be set.', 'event_espresso'),
833
-                    __FILE__, __FUNCTION__, __LINE__
834
-                );
835
-                return false;
836
-            }
837
-        } else {
838
-            if (WP_DEBUG) {
839
-                EE_Error::add_error(
840
-                    sprintf(
841
-                        __(
842
-                            'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
843
-                            'event_espresso'
844
-                        ),
845
-                        isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
846
-                        isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
847
-                        isset($reg_step['slug']) ? $reg_step['slug'] : '',
848
-                        '<ul>',
849
-                        '<li>',
850
-                        '</li>',
851
-                        '</ul>'
852
-                    ),
853
-                    __FILE__, __FUNCTION__, __LINE__
854
-                );
855
-            }
856
-            return false;
857
-        }
858
-        return true;
859
-    }
860
-
861
-
862
-    /**
863
-     * _verify_transaction_and_get_registrations
864
-     *
865
-     * @access private
866
-     * @return bool
867
-     * @throws InvalidDataTypeException
868
-     * @throws InvalidEntityException
869
-     * @throws EE_Error
870
-     */
871
-    private function _verify_transaction_and_get_registrations()
872
-    {
873
-        // was there already a valid transaction in the checkout from the session ?
874
-        if ( ! $this->checkout->transaction instanceof EE_Transaction) {
875
-            // get transaction from db or session
876
-            $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
877
-                ? $this->_get_transaction_and_cart_for_previous_visit()
878
-                : $this->_get_cart_for_current_session_and_setup_new_transaction();
879
-            if ( ! $this->checkout->transaction instanceof EE_Transaction) {
880
-                EE_Error::add_error(
881
-                    __('Your Registration and Transaction information could not be retrieved from the db.',
882
-                        'event_espresso'),
883
-                    __FILE__, __FUNCTION__, __LINE__
884
-                );
885
-                $this->checkout->transaction = EE_Transaction::new_instance();
886
-                // add some style and make it dance
887
-                $this->add_styles_and_scripts();
888
-                EED_Single_Page_Checkout::$_initialized = true;
889
-                return false;
890
-            }
891
-            // and the registrations for the transaction
892
-            $this->_get_registrations($this->checkout->transaction);
893
-        }
894
-        return true;
895
-    }
896
-
897
-
898
-
899
-    /**
900
-     * _get_transaction_and_cart_for_previous_visit
901
-     *
902
-     * @access private
903
-     * @return mixed EE_Transaction|NULL
904
-     */
905
-    private function _get_transaction_and_cart_for_previous_visit()
906
-    {
907
-        /** @var $TXN_model EEM_Transaction */
908
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
909
-        // because the reg_url_link is present in the request,
910
-        // this is a return visit to SPCO, so we'll get the transaction data from the db
911
-        $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
912
-        // verify transaction
913
-        if ($transaction instanceof EE_Transaction) {
914
-            // and get the cart that was used for that transaction
915
-            $this->checkout->cart = $this->_get_cart_for_transaction($transaction);
916
-            return $transaction;
917
-        }
918
-        EE_Error::add_error(
919
-            __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
920
-            __FILE__, __FUNCTION__, __LINE__
921
-        );
922
-        return null;
923
-
924
-    }
925
-
926
-
927
-
928
-    /**
929
-     * _get_cart_for_transaction
930
-     *
931
-     * @access private
932
-     * @param EE_Transaction $transaction
933
-     * @return EE_Cart
934
-     */
935
-    private function _get_cart_for_transaction($transaction)
936
-    {
937
-        return $this->checkout->get_cart_for_transaction($transaction);
938
-    }
939
-
940
-
941
-
942
-    /**
943
-     * get_cart_for_transaction
944
-     *
945
-     * @access public
946
-     * @param EE_Transaction $transaction
947
-     * @return EE_Cart
948
-     */
949
-    public function get_cart_for_transaction(EE_Transaction $transaction)
950
-    {
951
-        return $this->checkout->get_cart_for_transaction($transaction);
952
-    }
953
-
954
-
955
-
956
-    /**
957
-     * _get_transaction_and_cart_for_current_session
958
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
959
-     *
960
-     * @access private
961
-     * @return EE_Transaction
962
-     * @throws EE_Error
963
-     */
964
-    private function _get_cart_for_current_session_and_setup_new_transaction()
965
-    {
966
-        //  if there's no transaction, then this is the FIRST visit to SPCO
967
-        // so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
968
-        $this->checkout->cart = $this->_get_cart_for_transaction(null);
969
-        // and then create a new transaction
970
-        $transaction = $this->_initialize_transaction();
971
-        // verify transaction
972
-        if ($transaction instanceof EE_Transaction) {
973
-            // save it so that we have an ID for other objects to use
974
-            $transaction->save();
975
-            // and save TXN data to the cart
976
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
977
-        } else {
978
-            EE_Error::add_error(
979
-                __('A Valid Transaction could not be initialized.', 'event_espresso'),
980
-                __FILE__, __FUNCTION__, __LINE__
981
-            );
982
-        }
983
-        return $transaction;
984
-    }
985
-
986
-
987
-
988
-    /**
989
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
990
-     *
991
-     * @access private
992
-     * @return mixed EE_Transaction|NULL
993
-     */
994
-    private function _initialize_transaction()
995
-    {
996
-        try {
997
-            // ensure cart totals have been calculated
998
-            $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
999
-            // grab the cart grand total
1000
-            $cart_total = $this->checkout->cart->get_cart_grand_total();
1001
-            // create new TXN
1002
-            $transaction = EE_Transaction::new_instance(
1003
-                array(
1004
-                    'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
1005
-                    'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
1006
-                    'TXN_paid'      => 0,
1007
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
1008
-                )
1009
-            );
1010
-            // save it so that we have an ID for other objects to use
1011
-            $transaction->save();
1012
-            // set cron job for following up on TXNs after their session has expired
1013
-            EE_Cron_Tasks::schedule_expired_transaction_check(
1014
-                EE_Registry::instance()->SSN->expiration() + 1,
1015
-                $transaction->ID()
1016
-            );
1017
-            return $transaction;
1018
-        } catch (Exception $e) {
1019
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1020
-        }
1021
-        return null;
1022
-    }
1023
-
1024
-
1025
-    /**
1026
-     * _get_registrations
1027
-     *
1028
-     * @access private
1029
-     * @param EE_Transaction $transaction
1030
-     * @return void
1031
-     * @throws InvalidDataTypeException
1032
-     * @throws InvalidEntityException
1033
-     * @throws EE_Error
1034
-     */
1035
-    private function _get_registrations(EE_Transaction $transaction)
1036
-    {
1037
-        // first step: grab the registrants  { : o
1038
-        $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1039
-        $this->checkout->total_ticket_count = count($registrations);
1040
-        // verify registrations have been set
1041
-        if (empty($registrations)) {
1042
-            // if no cached registrations, then check the db
1043
-            $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1044
-            // still nothing ? well as long as this isn't a revisit
1045
-            if (empty($registrations) && ! $this->checkout->revisit) {
1046
-                // generate new registrations from scratch
1047
-                $registrations = $this->_initialize_registrations($transaction);
1048
-            }
1049
-        }
1050
-        // sort by their original registration order
1051
-        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1052
-        // then loop thru the array
1053
-        foreach ($registrations as $registration) {
1054
-            // verify each registration
1055
-            if ($registration instanceof EE_Registration) {
1056
-                // we display all attendee info for the primary registrant
1057
-                if ($this->checkout->reg_url_link === $registration->reg_url_link()
1058
-                    && $registration->is_primary_registrant()
1059
-                ) {
1060
-                    $this->checkout->primary_revisit = true;
1061
-                    break;
1062
-                }
1063
-                if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1064
-                    // but hide info if it doesn't belong to you
1065
-                    $transaction->clear_cache('Registration', $registration->ID());
1066
-                    $this->checkout->total_ticket_count--;
1067
-                }
1068
-                $this->checkout->set_reg_status_updated($registration->ID(), false);
1069
-            }
1070
-        }
1071
-    }
1072
-
1073
-
1074
-    /**
1075
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1076
-     *
1077
-     * @access private
1078
-     * @param EE_Transaction $transaction
1079
-     * @return    array
1080
-     * @throws InvalidDataTypeException
1081
-     * @throws InvalidEntityException
1082
-     * @throws EE_Error
1083
-     */
1084
-    private function _initialize_registrations(EE_Transaction $transaction)
1085
-    {
1086
-        $att_nmbr = 0;
1087
-        $registrations = array();
1088
-        if ($transaction instanceof EE_Transaction) {
1089
-            /** @type EE_Registration_Processor $registration_processor */
1090
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1091
-            $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1092
-            // now let's add the cart items to the $transaction
1093
-            foreach ($this->checkout->cart->get_tickets() as $line_item) {
1094
-                //do the following for each ticket of this type they selected
1095
-                for ($x = 1; $x <= $line_item->quantity(); $x++) {
1096
-                    $att_nmbr++;
1097
-                    /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1098
-                    $CreateRegistrationCommand = EE_Registry::instance()->create(
1099
-                        'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1100
-                        array(
1101
-                            $transaction,
1102
-                            $line_item,
1103
-                            $att_nmbr,
1104
-                            $this->checkout->total_ticket_count,
1105
-                        )
1106
-                    );
1107
-                    // override capabilities for frontend registrations
1108
-                    if ( ! is_admin()) {
1109
-                        $CreateRegistrationCommand->setCapCheck(
1110
-                            new PublicCapabilities('', 'create_new_registration')
1111
-                        );
1112
-                    }
1113
-                    $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1114
-                    if ( ! $registration instanceof EE_Registration) {
1115
-                        throw new InvalidEntityException($registration, 'EE_Registration');
1116
-                    }
1117
-                    $registrations[ $registration->ID() ] = $registration;
1118
-                }
1119
-            }
1120
-            $registration_processor->fix_reg_final_price_rounding_issue($transaction);
1121
-        }
1122
-        return $registrations;
1123
-    }
1124
-
1125
-
1126
-
1127
-    /**
1128
-     * sorts registrations by REG_count
1129
-     *
1130
-     * @access public
1131
-     * @param EE_Registration $reg_A
1132
-     * @param EE_Registration $reg_B
1133
-     * @return int
1134
-     */
1135
-    public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1136
-    {
1137
-        // this shouldn't ever happen within the same TXN, but oh well
1138
-        if ($reg_A->count() === $reg_B->count()) {
1139
-            return 0;
1140
-        }
1141
-        return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1142
-    }
1143
-
1144
-
1145
-
1146
-    /**
1147
-     *    _final_verifications
1148
-     * just makes sure that everything is set up correctly before proceeding
1149
-     *
1150
-     * @access    private
1151
-     * @return    bool
1152
-     * @throws EE_Error
1153
-     */
1154
-    private function _final_verifications()
1155
-    {
1156
-        // filter checkout
1157
-        $this->checkout = apply_filters(
1158
-            'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1159
-            $this->checkout
1160
-        );
1161
-        //verify that current step is still set correctly
1162
-        if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1163
-            EE_Error::add_error(
1164
-                __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'),
1165
-                __FILE__,
1166
-                __FUNCTION__,
1167
-                __LINE__
1168
-            );
1169
-            return false;
1170
-        }
1171
-        // if returning to SPCO, then verify that primary registrant is set
1172
-        if ( ! empty($this->checkout->reg_url_link)) {
1173
-            $valid_registrant = $this->checkout->transaction->primary_registration();
1174
-            if ( ! $valid_registrant instanceof EE_Registration) {
1175
-                EE_Error::add_error(
1176
-                    __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'),
1177
-                    __FILE__,
1178
-                    __FUNCTION__,
1179
-                    __LINE__
1180
-                );
1181
-                return false;
1182
-            }
1183
-            $valid_registrant = null;
1184
-            foreach (
1185
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1186
-            ) {
1187
-                if (
1188
-                    $registration instanceof EE_Registration
1189
-                    && $registration->reg_url_link() === $this->checkout->reg_url_link
1190
-                ) {
1191
-                    $valid_registrant = $registration;
1192
-                }
1193
-            }
1194
-            if ( ! $valid_registrant instanceof EE_Registration) {
1195
-                // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1196
-                if (EED_Single_Page_Checkout::$_checkout_verified) {
1197
-                    // clear the session, mark the checkout as unverified, and try again
1198
-                    EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1199
-                    EED_Single_Page_Checkout::$_initialized = false;
1200
-                    EED_Single_Page_Checkout::$_checkout_verified = false;
1201
-                    $this->_initialize();
1202
-                    EE_Error::reset_notices();
1203
-                    return false;
1204
-                }
1205
-                EE_Error::add_error(
1206
-                    __(
1207
-                        'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1208
-                        'event_espresso'
1209
-                    ),
1210
-                    __FILE__,
1211
-                    __FUNCTION__,
1212
-                    __LINE__
1213
-                );
1214
-                return false;
1215
-            }
1216
-        }
1217
-        // now that things have been kinda sufficiently verified,
1218
-        // let's add the checkout to the session so that it's available to other systems
1219
-        EE_Registry::instance()->SSN->set_checkout($this->checkout);
1220
-        return true;
1221
-    }
1222
-
1223
-
1224
-
1225
-    /**
1226
-     *    _initialize_reg_steps
1227
-     * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1228
-     * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1229
-     *
1230
-     * @access    private
1231
-     * @param bool $reinitializing
1232
-     * @throws EE_Error
1233
-     */
1234
-    private function _initialize_reg_steps($reinitializing = false)
1235
-    {
1236
-        $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1237
-        // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1238
-        foreach ($this->checkout->reg_steps as $reg_step) {
1239
-            if ( ! $reg_step->initialize_reg_step()) {
1240
-                // if not initialized then maybe this step is being removed...
1241
-                if ( ! $reinitializing && $reg_step->is_current_step()) {
1242
-                    // if it was the current step, then we need to start over here
1243
-                    $this->_initialize_reg_steps(true);
1244
-                    return;
1245
-                }
1246
-                continue;
1247
-            }
1248
-            // add css and JS for current step
1249
-            $reg_step->enqueue_styles_and_scripts();
1250
-            // i18n
1251
-            $reg_step->translate_js_strings();
1252
-            if ($reg_step->is_current_step()) {
1253
-                // the text that appears on the reg step form submit button
1254
-                $reg_step->set_submit_button_text();
1255
-            }
1256
-        }
1257
-        // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1258
-        do_action(
1259
-            "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1260
-            $this->checkout->current_step
1261
-        );
1262
-    }
1263
-
1264
-
1265
-
1266
-    /**
1267
-     * _check_form_submission
1268
-     *
1269
-     * @access private
1270
-     * @return boolean
1271
-     */
1272
-    private function _check_form_submission()
1273
-    {
1274
-        //does this request require the reg form to be generated ?
1275
-        if ($this->checkout->generate_reg_form) {
1276
-            // ever heard that song by Blue Rodeo ?
1277
-            try {
1278
-                $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1279
-                // if not displaying a form, then check for form submission
1280
-                if (
1281
-                    $this->checkout->process_form_submission
1282
-                    && $this->checkout->current_step->reg_form->was_submitted()
1283
-                ) {
1284
-                    // clear out any old data in case this step is being run again
1285
-                    $this->checkout->current_step->set_valid_data(array());
1286
-                    // capture submitted form data
1287
-                    $this->checkout->current_step->reg_form->receive_form_submission(
1288
-                        apply_filters(
1289
-                            'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1290
-                            EE_Registry::instance()->REQ->params(),
1291
-                            $this->checkout
1292
-                        )
1293
-                    );
1294
-                    // validate submitted form data
1295
-                    if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1296
-                        // thou shall not pass !!!
1297
-                        $this->checkout->continue_reg = false;
1298
-                        // any form validation errors?
1299
-                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1300
-                            EE_Error::add_error(
1301
-                                $this->checkout->current_step->reg_form->submission_error_message(),
1302
-                                __FILE__, __FUNCTION__, __LINE__
1303
-                            );
1304
-                        }
1305
-                        // well not really... what will happen is
1306
-                        // we'll just get redirected back to redo the current step
1307
-                        $this->go_to_next_step();
1308
-                        return false;
1309
-                    }
1310
-                }
1311
-            } catch (EE_Error $e) {
1312
-                $e->get_error();
1313
-            }
1314
-        }
1315
-        return true;
1316
-    }
1317
-
1318
-
1319
-
1320
-    /**
1321
-     * _process_action
1322
-     *
1323
-     * @access private
1324
-     * @return void
1325
-     * @throws EE_Error
1326
-     */
1327
-    private function _process_form_action()
1328
-    {
1329
-        // what cha wanna do?
1330
-        switch ($this->checkout->action) {
1331
-            // AJAX next step reg form
1332
-            case 'display_spco_reg_step' :
1333
-                $this->checkout->redirect = false;
1334
-                if (EE_Registry::instance()->REQ->ajax) {
1335
-                    $this->checkout->json_response->set_reg_step_html(
1336
-                        $this->checkout->current_step->display_reg_form()
1337
-                    );
1338
-                }
1339
-                break;
1340
-            default :
1341
-                // meh... do one of those other steps first
1342
-                if (
1343
-                    ! empty($this->checkout->action)
1344
-                    && is_callable(array($this->checkout->current_step, $this->checkout->action))
1345
-                ) {
1346
-                    // dynamically creates hook point like:
1347
-                    //   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1348
-                    do_action(
1349
-                        "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1350
-                        $this->checkout->current_step
1351
-                    );
1352
-                    // call action on current step
1353
-                    if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1354
-                        // good registrant, you get to proceed
1355
-                        if (
1356
-                            $this->checkout->current_step->success_message() !== ''
1357
-                            && apply_filters(
1358
-                                'FHEE__Single_Page_Checkout___process_form_action__display_success',
1359
-                                false
1360
-                            )
1361
-                        ) {
1362
-                            EE_Error::add_success(
1363
-                                $this->checkout->current_step->success_message()
1364
-                                . '<br />' . $this->checkout->next_step->_instructions()
1365
-                            );
1366
-                        }
1367
-                        // pack it up, pack it in...
1368
-                        $this->_setup_redirect();
1369
-                    }
1370
-                    // dynamically creates hook point like:
1371
-                    //  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1372
-                    do_action(
1373
-                        "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1374
-                        $this->checkout->current_step
1375
-                    );
1376
-                } else {
1377
-                    EE_Error::add_error(
1378
-                        sprintf(
1379
-                            __(
1380
-                                'The requested form action "%s" does not exist for the current "%s" registration step.',
1381
-                                'event_espresso'
1382
-                            ),
1383
-                            $this->checkout->action,
1384
-                            $this->checkout->current_step->name()
1385
-                        ),
1386
-                        __FILE__,
1387
-                        __FUNCTION__,
1388
-                        __LINE__
1389
-                    );
1390
-                }
1391
-            // end default
1392
-        }
1393
-        // store our progress so far
1394
-        $this->checkout->stash_transaction_and_checkout();
1395
-        // advance to the next step! If you pass GO, collect $200
1396
-        $this->go_to_next_step();
1397
-    }
1398
-
1399
-
1400
-
1401
-    /**
1402
-     *        add_styles_and_scripts
1403
-     *
1404
-     * @access        public
1405
-     * @return        void
1406
-     */
1407
-    public function add_styles_and_scripts()
1408
-    {
1409
-        // i18n
1410
-        $this->translate_js_strings();
1411
-        if ($this->checkout->admin_request) {
1412
-            add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1413
-        } else {
1414
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1415
-        }
1416
-    }
1417
-
1418
-
1419
-
1420
-    /**
1421
-     *        translate_js_strings
1422
-     *
1423
-     * @access        public
1424
-     * @return        void
1425
-     */
1426
-    public function translate_js_strings()
1427
-    {
1428
-        EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1429
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1430
-        EE_Registry::$i18n_js_strings['server_error'] = __(
1431
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1432
-            'event_espresso'
1433
-        );
1434
-        EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1435
-            'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1436
-            'event_espresso'
1437
-        );
1438
-        EE_Registry::$i18n_js_strings['validation_error'] = __(
1439
-            'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1440
-            'event_espresso'
1441
-        );
1442
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1443
-            'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1444
-            'event_espresso'
1445
-        );
1446
-        EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1447
-            'This registration step could not be completed. Please refresh the page and try again.',
1448
-            'event_espresso'
1449
-        );
1450
-        EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1451
-            'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1452
-            'event_espresso'
1453
-        );
1454
-        EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1455
-            __(
1456
-                'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1457
-                'event_espresso'
1458
-            ),
1459
-            '<br/>',
1460
-            '<br/>'
1461
-        );
1462
-        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1463
-        EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1464
-        EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1465
-        EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1466
-        EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1467
-        EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1468
-        EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1469
-        EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1470
-        EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1471
-        EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1472
-        EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1473
-        EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1474
-        EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1475
-        EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1476
-        EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1477
-        EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1478
-        EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1479
-        EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1480
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
1481
-        EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1482
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1483
-            true
1484
-        );
1485
-        EE_Registry::$i18n_js_strings['session_extension'] = absint(
1486
-            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1487
-        );
1488
-        EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1489
-            'M d, Y H:i:s',
1490
-            EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1491
-        );
1492
-    }
1493
-
1494
-
1495
-
1496
-    /**
1497
-     *    enqueue_styles_and_scripts
1498
-     *
1499
-     * @access        public
1500
-     * @return        void
1501
-     * @throws EE_Error
1502
-     */
1503
-    public function enqueue_styles_and_scripts()
1504
-    {
1505
-        // load css
1506
-        wp_register_style(
1507
-            'single_page_checkout',
1508
-            SPCO_CSS_URL . 'single_page_checkout.css',
1509
-            array('espresso_default'),
1510
-            EVENT_ESPRESSO_VERSION
1511
-        );
1512
-        wp_enqueue_style('single_page_checkout');
1513
-        // load JS
1514
-        wp_register_script(
1515
-            'jquery_plugin',
1516
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1517
-            array('jquery'),
1518
-            '1.0.1',
1519
-            true
1520
-        );
1521
-        wp_register_script(
1522
-            'jquery_countdown',
1523
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1524
-            array('jquery_plugin'),
1525
-            '2.0.2',
1526
-            true
1527
-        );
1528
-        wp_register_script(
1529
-            'single_page_checkout',
1530
-            SPCO_JS_URL . 'single_page_checkout.js',
1531
-            array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1532
-            EVENT_ESPRESSO_VERSION,
1533
-            true
1534
-        );
1535
-        if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1536
-            $this->checkout->registration_form->enqueue_js();
1537
-        }
1538
-        if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1539
-            $this->checkout->current_step->reg_form->enqueue_js();
1540
-        }
1541
-        wp_enqueue_script('single_page_checkout');
1542
-        /**
1543
-         * global action hook for enqueueing styles and scripts with
1544
-         * spco calls.
1545
-         */
1546
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1547
-        /**
1548
-         * dynamic action hook for enqueueing styles and scripts with spco calls.
1549
-         * The hook will end up being something like:
1550
-         *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1551
-         */
1552
-        do_action(
1553
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1554
-            $this
1555
-        );
1556
-    }
1557
-
1558
-
1559
-
1560
-    /**
1561
-     *    display the Registration Single Page Checkout Form
1562
-     *
1563
-     * @access    private
1564
-     * @return    void
1565
-     * @throws EE_Error
1566
-     */
1567
-    private function _display_spco_reg_form()
1568
-    {
1569
-        // if registering via the admin, just display the reg form for the current step
1570
-        if ($this->checkout->admin_request) {
1571
-            EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1572
-        } else {
1573
-            // add powered by EE msg
1574
-            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1575
-            $empty_cart = count(
1576
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1577
-            ) < 1;
1578
-            EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1579
-            $cookies_not_set_msg = '';
1580
-            if ($empty_cart) {
1581
-                $cookies_not_set_msg = apply_filters(
1582
-                    'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1583
-                    sprintf(
1584
-                        __(
1585
-                            '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1586
-                            'event_espresso'
1587
-                        ),
1588
-                        '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1589
-                        '</div>',
1590
-                        '<h6 class="important-notice">',
1591
-                        '</h6>',
1592
-                        '<p>',
1593
-                        '</p>',
1594
-                        '<br />',
1595
-                        '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1596
-                        '</a>'
1597
-                    )
1598
-                );
1599
-            }
1600
-            $this->checkout->registration_form = new EE_Form_Section_Proper(
1601
-                array(
1602
-                    'name'            => 'single-page-checkout',
1603
-                    'html_id'         => 'ee-single-page-checkout-dv',
1604
-                    'layout_strategy' =>
1605
-                        new EE_Template_Layout(
1606
-                            array(
1607
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1608
-                                'template_args'        => array(
1609
-                                    'empty_cart'              => $empty_cart,
1610
-                                    'revisit'                 => $this->checkout->revisit,
1611
-                                    'reg_steps'               => $this->checkout->reg_steps,
1612
-                                    'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1613
-                                        ? $this->checkout->next_step->slug()
1614
-                                        : '',
1615
-                                    'empty_msg'               => apply_filters(
1616
-                                        'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1617
-                                        sprintf(
1618
-                                            __(
1619
-                                                'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1620
-                                                'event_espresso'
1621
-                                            ),
1622
-                                            '<a href="'
1623
-                                            . get_post_type_archive_link('espresso_events')
1624
-                                            . '" title="',
1625
-                                            '">',
1626
-                                            '</a>'
1627
-                                        )
1628
-                                    ),
1629
-                                    'cookies_not_set_msg'     => $cookies_not_set_msg,
1630
-                                    'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1631
-                                    'session_expiration'      => gmdate(
1632
-                                        'M d, Y H:i:s',
1633
-                                        EE_Registry::instance()->SSN->expiration()
1634
-                                        + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1635
-                                    ),
1636
-                                ),
1637
-                            )
1638
-                        ),
1639
-                )
1640
-            );
1641
-            // load template and add to output sent that gets filtered into the_content()
1642
-            EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1643
-        }
1644
-    }
1645
-
1646
-
1647
-
1648
-    /**
1649
-     *    add_extra_finalize_registration_inputs
1650
-     *
1651
-     * @access    public
1652
-     * @param $next_step
1653
-     * @internal  param string $label
1654
-     * @return void
1655
-     */
1656
-    public function add_extra_finalize_registration_inputs($next_step)
1657
-    {
1658
-        if ($next_step === 'finalize_registration') {
1659
-            echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1660
-        }
1661
-    }
1662
-
1663
-
1664
-
1665
-    /**
1666
-     *    display_registration_footer
1667
-     *
1668
-     * @access    public
1669
-     * @return    string
1670
-     */
1671
-    public static function display_registration_footer()
1672
-    {
1673
-        if (
1674
-        apply_filters(
1675
-            'FHEE__EE_Front__Controller__show_reg_footer',
1676
-            EE_Registry::instance()->CFG->admin->show_reg_footer
1677
-        )
1678
-        ) {
1679
-            add_filter(
1680
-                'FHEE__EEH_Template__powered_by_event_espresso__url',
1681
-                function ($url) {
1682
-                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1683
-                }
1684
-            );
1685
-            echo apply_filters(
1686
-                'FHEE__EE_Front_Controller__display_registration_footer',
1687
-                \EEH_Template::powered_by_event_espresso(
1688
-                    '',
1689
-                    'espresso-registration-footer-dv',
1690
-                    array('utm_content' => 'registration_checkout')
1691
-                )
1692
-            );
1693
-        }
1694
-        return '';
1695
-    }
1696
-
1697
-
1698
-
1699
-    /**
1700
-     *    unlock_transaction
1701
-     *
1702
-     * @access    public
1703
-     * @return    void
1704
-     * @throws EE_Error
1705
-     */
1706
-    public function unlock_transaction()
1707
-    {
1708
-        if ($this->checkout->transaction instanceof EE_Transaction) {
1709
-            $this->checkout->transaction->unlock();
1710
-        }
1711
-    }
1712
-
1713
-
1714
-
1715
-    /**
1716
-     *        _setup_redirect
1717
-     *
1718
-     * @access    private
1719
-     * @return void
1720
-     */
1721
-    private function _setup_redirect()
1722
-    {
1723
-        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1724
-            $this->checkout->redirect = true;
1725
-            if (empty($this->checkout->redirect_url)) {
1726
-                $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1727
-            }
1728
-            $this->checkout->redirect_url = apply_filters(
1729
-                'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1730
-                $this->checkout->redirect_url,
1731
-                $this->checkout
1732
-            );
1733
-        }
1734
-    }
1735
-
1736
-
1737
-
1738
-    /**
1739
-     *   handle ajax message responses and redirects
1740
-     *
1741
-     * @access public
1742
-     * @return void
1743
-     * @throws EE_Error
1744
-     */
1745
-    public function go_to_next_step()
1746
-    {
1747
-        if (EE_Registry::instance()->REQ->ajax) {
1748
-            // capture contents of output buffer we started earlier in the request, and insert into JSON response
1749
-            $this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1750
-        }
1751
-        $this->unlock_transaction();
1752
-        // just return for these conditions
1753
-        if (
1754
-            $this->checkout->admin_request
1755
-            || $this->checkout->action === 'redirect_form'
1756
-            || $this->checkout->action === 'update_checkout'
1757
-        ) {
1758
-            return;
1759
-        }
1760
-        // AJAX response
1761
-        $this->_handle_json_response();
1762
-        // redirect to next step or the Thank You page
1763
-        $this->_handle_html_redirects();
1764
-        // hmmm... must be something wrong, so let's just display the form again !
1765
-        $this->_display_spco_reg_form();
1766
-    }
1767
-
1768
-
1769
-
1770
-    /**
1771
-     *   _handle_json_response
1772
-     *
1773
-     * @access protected
1774
-     * @return void
1775
-     */
1776
-    protected function _handle_json_response()
1777
-    {
1778
-        // if this is an ajax request
1779
-        if (EE_Registry::instance()->REQ->ajax) {
1780
-            // DEBUG LOG
1781
-            //$this->checkout->log(
1782
-            //	__CLASS__, __FUNCTION__, __LINE__,
1783
-            //	array(
1784
-            //		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1785
-            //		'redirect'                   => $this->checkout->redirect,
1786
-            //		'continue_reg'               => $this->checkout->continue_reg,
1787
-            //	)
1788
-            //);
1789
-            $this->checkout->json_response->set_registration_time_limit(
1790
-                $this->checkout->get_registration_time_limit()
1791
-            );
1792
-            $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1793
-            // just send the ajax (
1794
-            $json_response = apply_filters(
1795
-                'FHEE__EE_Single_Page_Checkout__JSON_response',
1796
-                $this->checkout->json_response
1797
-            );
1798
-            echo $json_response;
1799
-            exit();
1800
-        }
1801
-    }
1802
-
1803
-
1804
-
1805
-    /**
1806
-     *   _handle_redirects
1807
-     *
1808
-     * @access protected
1809
-     * @return void
1810
-     */
1811
-    protected function _handle_html_redirects()
1812
-    {
1813
-        // going somewhere ?
1814
-        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1815
-            // store notices in a transient
1816
-            EE_Error::get_notices(false, true, true);
1817
-            // DEBUG LOG
1818
-            //$this->checkout->log(
1819
-            //	__CLASS__, __FUNCTION__, __LINE__,
1820
-            //	array(
1821
-            //		'headers_sent' => headers_sent(),
1822
-            //		'redirect_url'     => $this->checkout->redirect_url,
1823
-            //		'headers_list'    => headers_list(),
1824
-            //	)
1825
-            //);
1826
-            wp_safe_redirect($this->checkout->redirect_url);
1827
-            exit();
1828
-        }
1829
-    }
1830
-
1831
-
1832
-
1833
-    /**
1834
-     *   set_checkout_anchor
1835
-     *
1836
-     * @access public
1837
-     * @return void
1838
-     */
1839
-    public function set_checkout_anchor()
1840
-    {
1841
-        echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1842
-    }
1843
-
1844
-    /**
1845
-     *    getRegistrationExpirationNotice
1846
-     *
1847
-     * @since 4.9.59.p
1848
-     * @access    public
1849
-     * @return    string
1850
-     */
1851
-    public static function getRegistrationExpirationNotice()
1852
-    {
1853
-        return sprintf(
1854
-            __('%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s',
1855
-                'event_espresso'),
1856
-            '<h4 class="important-notice">',
1857
-            '</h4>',
1858
-            '<br />',
1859
-            '<p>',
1860
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1861
-            '">',
1862
-            '</a>',
1863
-            '</p>'
1864
-        );
1865
-    }
23
+	/**
24
+	 * $_initialized - has the SPCO controller already been initialized ?
25
+	 *
26
+	 * @access private
27
+	 * @var bool $_initialized
28
+	 */
29
+	private static $_initialized = false;
30
+
31
+
32
+	/**
33
+	 * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
34
+	 *
35
+	 * @access private
36
+	 * @var bool $_valid_checkout
37
+	 */
38
+	private static $_checkout_verified = true;
39
+
40
+	/**
41
+	 *    $_reg_steps_array - holds initial array of reg steps
42
+	 *
43
+	 * @access private
44
+	 * @var array $_reg_steps_array
45
+	 */
46
+	private static $_reg_steps_array = array();
47
+
48
+	/**
49
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
50
+	 *
51
+	 * @access public
52
+	 * @var EE_Checkout $checkout
53
+	 */
54
+	public $checkout;
55
+
56
+
57
+
58
+	/**
59
+	 * @return EED_Module|EED_Single_Page_Checkout
60
+	 */
61
+	public static function instance()
62
+	{
63
+		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
64
+		return parent::get_instance(__CLASS__);
65
+	}
66
+
67
+
68
+
69
+	/**
70
+	 * @return EE_CART
71
+	 */
72
+	public function cart()
73
+	{
74
+		return $this->checkout->cart;
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * @return EE_Transaction
81
+	 */
82
+	public function transaction()
83
+	{
84
+		return $this->checkout->transaction;
85
+	}
86
+
87
+
88
+
89
+	/**
90
+	 *    set_hooks - for hooking into EE Core, other modules, etc
91
+	 *
92
+	 * @access    public
93
+	 * @return    void
94
+	 * @throws EE_Error
95
+	 */
96
+	public static function set_hooks()
97
+	{
98
+		EED_Single_Page_Checkout::set_definitions();
99
+	}
100
+
101
+
102
+
103
+	/**
104
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
105
+	 *
106
+	 * @access    public
107
+	 * @return    void
108
+	 * @throws EE_Error
109
+	 */
110
+	public static function set_hooks_admin()
111
+	{
112
+		EED_Single_Page_Checkout::set_definitions();
113
+		if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
114
+			return;
115
+		}
116
+		// going to start an output buffer in case anything gets accidentally output
117
+		// that might disrupt our JSON response
118
+		ob_start();
119
+		EED_Single_Page_Checkout::load_request_handler();
120
+		EED_Single_Page_Checkout::load_reg_steps();
121
+		// set ajax hooks
122
+		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
123
+		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
+		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
125
+		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
+		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
127
+		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 *    process ajax request
134
+	 *
135
+	 * @param string $ajax_action
136
+	 * @throws EE_Error
137
+	 */
138
+	public static function process_ajax_request($ajax_action)
139
+	{
140
+		EE_Registry::instance()->REQ->set('action', $ajax_action);
141
+		EED_Single_Page_Checkout::instance()->_initialize();
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 *    ajax display registration step
148
+	 *
149
+	 * @throws EE_Error
150
+	 */
151
+	public static function display_reg_step()
152
+	{
153
+		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 *    ajax process registration step
160
+	 *
161
+	 * @throws EE_Error
162
+	 */
163
+	public static function process_reg_step()
164
+	{
165
+		EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 *    ajax process registration step
172
+	 *
173
+	 * @throws EE_Error
174
+	 */
175
+	public static function update_reg_step()
176
+	{
177
+		EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 *   update_checkout
184
+	 *
185
+	 * @access public
186
+	 * @return void
187
+	 * @throws EE_Error
188
+	 */
189
+	public static function update_checkout()
190
+	{
191
+		EED_Single_Page_Checkout::process_ajax_request('update_checkout');
192
+	}
193
+
194
+
195
+
196
+	/**
197
+	 *    load_request_handler
198
+	 *
199
+	 * @access    public
200
+	 * @return    void
201
+	 */
202
+	public static function load_request_handler()
203
+	{
204
+		// load core Request_Handler class
205
+		if (EE_Registry::instance()->REQ !== null) {
206
+			EE_Registry::instance()->load_core('Request_Handler');
207
+		}
208
+	}
209
+
210
+
211
+
212
+	/**
213
+	 *    set_definitions
214
+	 *
215
+	 * @access    public
216
+	 * @return    void
217
+	 * @throws EE_Error
218
+	 */
219
+	public static function set_definitions()
220
+	{
221
+		if(defined('SPCO_BASE_PATH')) {
222
+			return;
223
+		}
224
+		define(
225
+			'SPCO_BASE_PATH',
226
+			rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
227
+		);
228
+		define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
229
+		define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
230
+		define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
231
+		define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
232
+		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
233
+		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
234
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
235
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
236
+	}
237
+
238
+
239
+
240
+	/**
241
+	 * load_reg_steps
242
+	 * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
243
+	 *
244
+	 * @access    private
245
+	 * @throws EE_Error
246
+	 */
247
+	public static function load_reg_steps()
248
+	{
249
+		static $reg_steps_loaded = false;
250
+		if ($reg_steps_loaded) {
251
+			return;
252
+		}
253
+		// filter list of reg_steps
254
+		$reg_steps_to_load = (array)apply_filters(
255
+			'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
256
+			EED_Single_Page_Checkout::get_reg_steps()
257
+		);
258
+		// sort by key (order)
259
+		ksort($reg_steps_to_load);
260
+		// loop through folders
261
+		foreach ($reg_steps_to_load as $order => $reg_step) {
262
+			// we need a
263
+			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
264
+				// copy over to the reg_steps_array
265
+				EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
266
+				// register custom key route for each reg step
267
+				// ie: step=>"slug" - this is the entire reason we load the reg steps array now
268
+				EE_Config::register_route(
269
+					$reg_step['slug'],
270
+					'EED_Single_Page_Checkout',
271
+					'run',
272
+					'step'
273
+				);
274
+				// add AJAX or other hooks
275
+				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
276
+					// setup autoloaders if necessary
277
+					if ( ! class_exists($reg_step['class_name'])) {
278
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
279
+							$reg_step['file_path'],
280
+							true
281
+						);
282
+					}
283
+					if (is_callable($reg_step['class_name'], 'set_hooks')) {
284
+						call_user_func(array($reg_step['class_name'], 'set_hooks'));
285
+					}
286
+				}
287
+			}
288
+		}
289
+		$reg_steps_loaded = true;
290
+	}
291
+
292
+
293
+
294
+	/**
295
+	 *    get_reg_steps
296
+	 *
297
+	 * @access    public
298
+	 * @return    array
299
+	 */
300
+	public static function get_reg_steps()
301
+	{
302
+		$reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
303
+		if (empty($reg_steps)) {
304
+			$reg_steps = array(
305
+				10  => array(
306
+					'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
307
+					'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
308
+					'slug'       => 'attendee_information',
309
+					'has_hooks'  => false,
310
+				),
311
+				20  => array(
312
+					'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
313
+					'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
314
+					'slug'       => 'registration_confirmation',
315
+					'has_hooks'  => false,
316
+				),
317
+				30  => array(
318
+					'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
319
+					'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
320
+					'slug'       => 'payment_options',
321
+					'has_hooks'  => true,
322
+				),
323
+				999 => array(
324
+					'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
325
+					'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
326
+					'slug'       => 'finalize_registration',
327
+					'has_hooks'  => false,
328
+				),
329
+			);
330
+		}
331
+		return $reg_steps;
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 *    registration_checkout_for_admin
338
+	 *
339
+	 * @access    public
340
+	 * @return    string
341
+	 * @throws EE_Error
342
+	 */
343
+	public static function registration_checkout_for_admin()
344
+	{
345
+		EED_Single_Page_Checkout::load_request_handler();
346
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
347
+		EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
348
+		EE_Registry::instance()->REQ->set('process_form_submission', false);
349
+		EED_Single_Page_Checkout::instance()->_initialize();
350
+		EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
351
+		return EE_Registry::instance()->REQ->get_output();
352
+	}
353
+
354
+
355
+
356
+	/**
357
+	 * process_registration_from_admin
358
+	 *
359
+	 * @access public
360
+	 * @return \EE_Transaction
361
+	 * @throws EE_Error
362
+	 */
363
+	public static function process_registration_from_admin()
364
+	{
365
+		EED_Single_Page_Checkout::load_request_handler();
366
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
367
+		EE_Registry::instance()->REQ->set('action', 'process_reg_step');
368
+		EE_Registry::instance()->REQ->set('process_form_submission', true);
369
+		EED_Single_Page_Checkout::instance()->_initialize();
370
+		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
371
+			$final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
372
+			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
373
+				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
374
+				if ($final_reg_step->process_reg_step()) {
375
+					$final_reg_step->set_completed();
376
+					EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
377
+					return EED_Single_Page_Checkout::instance()->checkout->transaction;
378
+				}
379
+			}
380
+		}
381
+		return null;
382
+	}
383
+
384
+
385
+
386
+	/**
387
+	 *    run
388
+	 *
389
+	 * @access    public
390
+	 * @param WP_Query $WP_Query
391
+	 * @return    void
392
+	 * @throws EE_Error
393
+	 */
394
+	public function run($WP_Query)
395
+	{
396
+		if (
397
+			$WP_Query instanceof WP_Query
398
+			&& $WP_Query->is_main_query()
399
+			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
400
+			&& $this->_is_reg_checkout()
401
+		) {
402
+			$this->_initialize();
403
+		}
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * determines whether current url matches reg page url
410
+	 *
411
+	 * @return bool
412
+	 */
413
+	protected function _is_reg_checkout()
414
+	{
415
+		// get current permalink for reg page without any extra query args
416
+		$reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
417
+		// get request URI for current request, but without the scheme or host
418
+		$current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
419
+		$current_request_uri = html_entity_decode($current_request_uri);
420
+		// get array of query args from the current request URI
421
+		$query_args = \EEH_URL::get_query_string($current_request_uri);
422
+		// grab page id if it is set
423
+		$page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
424
+		// and remove the page id from the query args (we will re-add it later)
425
+		unset($query_args['page_id']);
426
+		// now strip all query args from current request URI
427
+		$current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
428
+		// and re-add the page id if it was set
429
+		if ($page_id) {
430
+			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
431
+		}
432
+		// remove slashes and ?
433
+		$current_request_uri = trim($current_request_uri, '?/');
434
+		// is current request URI part of the known full reg page URL ?
435
+		return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
436
+	}
437
+
438
+
439
+
440
+	/**
441
+	 * @param WP_Query $wp_query
442
+	 * @return    void
443
+	 * @throws EE_Error
444
+	 */
445
+	public static function init($wp_query)
446
+	{
447
+		EED_Single_Page_Checkout::instance()->run($wp_query);
448
+	}
449
+
450
+
451
+
452
+	/**
453
+	 *    _initialize - initial module setup
454
+	 *
455
+	 * @access    private
456
+	 * @throws EE_Error
457
+	 * @return    void
458
+	 */
459
+	private function _initialize()
460
+	{
461
+		// ensure SPCO doesn't run twice
462
+		if (EED_Single_Page_Checkout::$_initialized) {
463
+			return;
464
+		}
465
+		try {
466
+			EED_Single_Page_Checkout::load_reg_steps();
467
+			$this->_verify_session();
468
+			// setup the EE_Checkout object
469
+			$this->checkout = $this->_initialize_checkout();
470
+			// filter checkout
471
+			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
472
+			// get the $_GET
473
+			$this->_get_request_vars();
474
+			if ($this->_block_bots()) {
475
+				return;
476
+			}
477
+			// filter continue_reg
478
+			$this->checkout->continue_reg = apply_filters(
479
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
480
+				true,
481
+				$this->checkout
482
+			);
483
+			// load the reg steps array
484
+			if ( ! $this->_load_and_instantiate_reg_steps()) {
485
+				EED_Single_Page_Checkout::$_initialized = true;
486
+				return;
487
+			}
488
+			// set the current step
489
+			$this->checkout->set_current_step($this->checkout->step);
490
+			// and the next step
491
+			$this->checkout->set_next_step();
492
+			// verify that everything has been setup correctly
493
+			if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
494
+				EED_Single_Page_Checkout::$_initialized = true;
495
+				return;
496
+			}
497
+			// lock the transaction
498
+			$this->checkout->transaction->lock();
499
+			// make sure all of our cached objects are added to their respective model entity mappers
500
+			$this->checkout->refresh_all_entities();
501
+			// set amount owing
502
+			$this->checkout->amount_owing = $this->checkout->transaction->remaining();
503
+			// initialize each reg step, which gives them the chance to potentially alter the process
504
+			$this->_initialize_reg_steps();
505
+			// DEBUG LOG
506
+			//$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
507
+			// get reg form
508
+			if( ! $this->_check_form_submission()) {
509
+				EED_Single_Page_Checkout::$_initialized = true;
510
+				return;
511
+			}
512
+			// checkout the action!!!
513
+			$this->_process_form_action();
514
+			// add some style and make it dance
515
+			$this->add_styles_and_scripts();
516
+			// kk... SPCO has successfully run
517
+			EED_Single_Page_Checkout::$_initialized = true;
518
+			// set no cache headers and constants
519
+			EE_System::do_not_cache();
520
+			// add anchor
521
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
522
+			// remove transaction lock
523
+			add_action('shutdown', array($this, 'unlock_transaction'), 1);
524
+		} catch (Exception $e) {
525
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
526
+		}
527
+	}
528
+
529
+
530
+
531
+	/**
532
+	 *    _verify_session
533
+	 * checks that the session is valid and not expired
534
+	 *
535
+	 * @access    private
536
+	 * @throws EE_Error
537
+	 */
538
+	private function _verify_session()
539
+	{
540
+		if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
541
+			throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
542
+		}
543
+		$clear_session_requested = filter_var(
544
+			EE_Registry::instance()->REQ->get('clear_session', false),
545
+			FILTER_VALIDATE_BOOLEAN
546
+		);
547
+		// is session still valid ?
548
+		if ($clear_session_requested
549
+			|| ( EE_Registry::instance()->SSN->expired()
550
+			  && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
551
+			)
552
+		) {
553
+			$this->checkout = new EE_Checkout();
554
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
555
+			// EE_Registry::instance()->SSN->reset_cart();
556
+			// EE_Registry::instance()->SSN->reset_checkout();
557
+			// EE_Registry::instance()->SSN->reset_transaction();
558
+			if (! $clear_session_requested) {
559
+				EE_Error::add_attention(
560
+					EE_Registry::$i18n_js_strings['registration_expiration_notice'],
561
+					__FILE__, __FUNCTION__, __LINE__
562
+				);
563
+			}
564
+			// EE_Registry::instance()->SSN->reset_expired();
565
+		}
566
+	}
567
+
568
+
569
+
570
+	/**
571
+	 *    _initialize_checkout
572
+	 * loads and instantiates EE_Checkout
573
+	 *
574
+	 * @access    private
575
+	 * @throws EE_Error
576
+	 * @return EE_Checkout
577
+	 */
578
+	private function _initialize_checkout()
579
+	{
580
+		// look in session for existing checkout
581
+		/** @type EE_Checkout $checkout */
582
+		$checkout = EE_Registry::instance()->SSN->checkout();
583
+		// verify
584
+		if ( ! $checkout instanceof EE_Checkout) {
585
+			// instantiate EE_Checkout object for handling the properties of the current checkout process
586
+			$checkout = EE_Registry::instance()->load_file(
587
+				SPCO_INC_PATH,
588
+				'EE_Checkout',
589
+				'class', array(),
590
+				false
591
+			);
592
+		} else {
593
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
594
+				$this->unlock_transaction();
595
+				wp_safe_redirect($checkout->redirect_url);
596
+				exit();
597
+			}
598
+		}
599
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
600
+		// verify again
601
+		if ( ! $checkout instanceof EE_Checkout) {
602
+			throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
603
+		}
604
+		// reset anything that needs a clean slate for each request
605
+		$checkout->reset_for_current_request();
606
+		return $checkout;
607
+	}
608
+
609
+
610
+
611
+	/**
612
+	 *    _get_request_vars
613
+	 *
614
+	 * @access    private
615
+	 * @return    void
616
+	 * @throws EE_Error
617
+	 */
618
+	private function _get_request_vars()
619
+	{
620
+		// load classes
621
+		EED_Single_Page_Checkout::load_request_handler();
622
+		//make sure this request is marked as belonging to EE
623
+		EE_Registry::instance()->REQ->set_espresso_page(true);
624
+		// which step is being requested ?
625
+		$this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
626
+		// which step is being edited ?
627
+		$this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
628
+		// and what we're doing on the current step
629
+		$this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
630
+		// timestamp
631
+		$this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
632
+		// returning to edit ?
633
+		$this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
634
+		// add reg url link to registration query params
635
+		if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
636
+			$this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
637
+		}
638
+		// or some other kind of revisit ?
639
+		$this->checkout->revisit = filter_var(
640
+			EE_Registry::instance()->REQ->get('revisit', false),
641
+			FILTER_VALIDATE_BOOLEAN
642
+		);
643
+		// and whether or not to generate a reg form for this request
644
+		$this->checkout->generate_reg_form = filter_var(
645
+			EE_Registry::instance()->REQ->get('generate_reg_form', true),
646
+			FILTER_VALIDATE_BOOLEAN
647
+		);
648
+		// and whether or not to process a reg form submission for this request
649
+		$this->checkout->process_form_submission = filter_var(
650
+			EE_Registry::instance()->REQ->get(
651
+				'process_form_submission',
652
+				$this->checkout->action === 'process_reg_step'
653
+			),
654
+			FILTER_VALIDATE_BOOLEAN
655
+		);
656
+		$this->checkout->process_form_submission = filter_var(
657
+			$this->checkout->action !== 'display_spco_reg_step'
658
+				? $this->checkout->process_form_submission
659
+				: false,
660
+			FILTER_VALIDATE_BOOLEAN
661
+		);
662
+		// $this->_display_request_vars();
663
+	}
664
+
665
+
666
+
667
+	/**
668
+	 *  _display_request_vars
669
+	 *
670
+	 * @access    protected
671
+	 * @return    void
672
+	 */
673
+	protected function _display_request_vars()
674
+	{
675
+		if ( ! WP_DEBUG) {
676
+			return;
677
+		}
678
+		EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
679
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
680
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
681
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
682
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
683
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
684
+		EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
685
+		EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
686
+	}
687
+
688
+
689
+
690
+	/**
691
+	 * _block_bots
692
+	 * checks that the incoming request has either of the following set:
693
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
694
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
695
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
696
+	 * then where you coming from man?
697
+	 *
698
+	 * @return boolean
699
+	 */
700
+	private function _block_bots()
701
+	{
702
+		$invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
703
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
704
+			return true;
705
+		}
706
+		return false;
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 *    _get_first_step
713
+	 *  gets slug for first step in $_reg_steps_array
714
+	 *
715
+	 * @access    private
716
+	 * @throws EE_Error
717
+	 * @return    string
718
+	 */
719
+	private function _get_first_step()
720
+	{
721
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
722
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
723
+	}
724
+
725
+
726
+
727
+	/**
728
+	 *    _load_and_instantiate_reg_steps
729
+	 *  instantiates each reg step based on the loaded reg_steps array
730
+	 *
731
+	 * @access    private
732
+	 * @throws EE_Error
733
+	 * @return    bool
734
+	 */
735
+	private function _load_and_instantiate_reg_steps()
736
+	{
737
+		do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
738
+		// have reg_steps already been instantiated ?
739
+		if (
740
+			empty($this->checkout->reg_steps)
741
+			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
742
+		) {
743
+			// if not, then loop through raw reg steps array
744
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
745
+				if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
746
+					return false;
747
+				}
748
+			}
749
+			EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
750
+			EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
751
+			// skip the registration_confirmation page ?
752
+			if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
753
+				// just remove it from the reg steps array
754
+				$this->checkout->remove_reg_step('registration_confirmation', false);
755
+			} else if (
756
+				isset($this->checkout->reg_steps['registration_confirmation'])
757
+				&& EE_Registry::instance()->CFG->registration->reg_confirmation_last
758
+			) {
759
+				// set the order to something big like 100
760
+				$this->checkout->set_reg_step_order('registration_confirmation', 100);
761
+			}
762
+			// filter the array for good luck
763
+			$this->checkout->reg_steps = apply_filters(
764
+				'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
765
+				$this->checkout->reg_steps
766
+			);
767
+			// finally re-sort based on the reg step class order properties
768
+			$this->checkout->sort_reg_steps();
769
+		} else {
770
+			foreach ($this->checkout->reg_steps as $reg_step) {
771
+				// set all current step stati to FALSE
772
+				$reg_step->set_is_current_step(false);
773
+			}
774
+		}
775
+		if (empty($this->checkout->reg_steps)) {
776
+			EE_Error::add_error(
777
+				__('No Reg Steps were loaded..', 'event_espresso'),
778
+				__FILE__, __FUNCTION__, __LINE__
779
+			);
780
+			return false;
781
+		}
782
+		// make reg step details available to JS
783
+		$this->checkout->set_reg_step_JSON_info();
784
+		return true;
785
+	}
786
+
787
+
788
+
789
+	/**
790
+	 *     _load_and_instantiate_reg_step
791
+	 *
792
+	 * @access    private
793
+	 * @param array $reg_step
794
+	 * @param int   $order
795
+	 * @return bool
796
+	 */
797
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
798
+	{
799
+		// we need a file_path, class_name, and slug to add a reg step
800
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
801
+			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
802
+			if (
803
+				$this->checkout->reg_url_link
804
+				&& $this->checkout->step !== $reg_step['slug']
805
+				&& $reg_step['slug'] !== 'finalize_registration'
806
+				// normally at this point we would NOT load the reg step, but this filter can change that
807
+				&& apply_filters(
808
+					'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
809
+					true,
810
+					$reg_step,
811
+					$this->checkout
812
+				)
813
+			) {
814
+				return true;
815
+			}
816
+			// instantiate step class using file path and class name
817
+			$reg_step_obj = EE_Registry::instance()->load_file(
818
+				$reg_step['file_path'],
819
+				$reg_step['class_name'],
820
+				'class',
821
+				$this->checkout,
822
+				false
823
+			);
824
+			// did we gets the goods ?
825
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
826
+				// set reg step order based on config
827
+				$reg_step_obj->set_order($order);
828
+				// add instantiated reg step object to the master reg steps array
829
+				$this->checkout->add_reg_step($reg_step_obj);
830
+			} else {
831
+				EE_Error::add_error(
832
+					__('The current step could not be set.', 'event_espresso'),
833
+					__FILE__, __FUNCTION__, __LINE__
834
+				);
835
+				return false;
836
+			}
837
+		} else {
838
+			if (WP_DEBUG) {
839
+				EE_Error::add_error(
840
+					sprintf(
841
+						__(
842
+							'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
843
+							'event_espresso'
844
+						),
845
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
846
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
847
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
848
+						'<ul>',
849
+						'<li>',
850
+						'</li>',
851
+						'</ul>'
852
+					),
853
+					__FILE__, __FUNCTION__, __LINE__
854
+				);
855
+			}
856
+			return false;
857
+		}
858
+		return true;
859
+	}
860
+
861
+
862
+	/**
863
+	 * _verify_transaction_and_get_registrations
864
+	 *
865
+	 * @access private
866
+	 * @return bool
867
+	 * @throws InvalidDataTypeException
868
+	 * @throws InvalidEntityException
869
+	 * @throws EE_Error
870
+	 */
871
+	private function _verify_transaction_and_get_registrations()
872
+	{
873
+		// was there already a valid transaction in the checkout from the session ?
874
+		if ( ! $this->checkout->transaction instanceof EE_Transaction) {
875
+			// get transaction from db or session
876
+			$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
877
+				? $this->_get_transaction_and_cart_for_previous_visit()
878
+				: $this->_get_cart_for_current_session_and_setup_new_transaction();
879
+			if ( ! $this->checkout->transaction instanceof EE_Transaction) {
880
+				EE_Error::add_error(
881
+					__('Your Registration and Transaction information could not be retrieved from the db.',
882
+						'event_espresso'),
883
+					__FILE__, __FUNCTION__, __LINE__
884
+				);
885
+				$this->checkout->transaction = EE_Transaction::new_instance();
886
+				// add some style and make it dance
887
+				$this->add_styles_and_scripts();
888
+				EED_Single_Page_Checkout::$_initialized = true;
889
+				return false;
890
+			}
891
+			// and the registrations for the transaction
892
+			$this->_get_registrations($this->checkout->transaction);
893
+		}
894
+		return true;
895
+	}
896
+
897
+
898
+
899
+	/**
900
+	 * _get_transaction_and_cart_for_previous_visit
901
+	 *
902
+	 * @access private
903
+	 * @return mixed EE_Transaction|NULL
904
+	 */
905
+	private function _get_transaction_and_cart_for_previous_visit()
906
+	{
907
+		/** @var $TXN_model EEM_Transaction */
908
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
909
+		// because the reg_url_link is present in the request,
910
+		// this is a return visit to SPCO, so we'll get the transaction data from the db
911
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
912
+		// verify transaction
913
+		if ($transaction instanceof EE_Transaction) {
914
+			// and get the cart that was used for that transaction
915
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
916
+			return $transaction;
917
+		}
918
+		EE_Error::add_error(
919
+			__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
920
+			__FILE__, __FUNCTION__, __LINE__
921
+		);
922
+		return null;
923
+
924
+	}
925
+
926
+
927
+
928
+	/**
929
+	 * _get_cart_for_transaction
930
+	 *
931
+	 * @access private
932
+	 * @param EE_Transaction $transaction
933
+	 * @return EE_Cart
934
+	 */
935
+	private function _get_cart_for_transaction($transaction)
936
+	{
937
+		return $this->checkout->get_cart_for_transaction($transaction);
938
+	}
939
+
940
+
941
+
942
+	/**
943
+	 * get_cart_for_transaction
944
+	 *
945
+	 * @access public
946
+	 * @param EE_Transaction $transaction
947
+	 * @return EE_Cart
948
+	 */
949
+	public function get_cart_for_transaction(EE_Transaction $transaction)
950
+	{
951
+		return $this->checkout->get_cart_for_transaction($transaction);
952
+	}
953
+
954
+
955
+
956
+	/**
957
+	 * _get_transaction_and_cart_for_current_session
958
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
959
+	 *
960
+	 * @access private
961
+	 * @return EE_Transaction
962
+	 * @throws EE_Error
963
+	 */
964
+	private function _get_cart_for_current_session_and_setup_new_transaction()
965
+	{
966
+		//  if there's no transaction, then this is the FIRST visit to SPCO
967
+		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
968
+		$this->checkout->cart = $this->_get_cart_for_transaction(null);
969
+		// and then create a new transaction
970
+		$transaction = $this->_initialize_transaction();
971
+		// verify transaction
972
+		if ($transaction instanceof EE_Transaction) {
973
+			// save it so that we have an ID for other objects to use
974
+			$transaction->save();
975
+			// and save TXN data to the cart
976
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
977
+		} else {
978
+			EE_Error::add_error(
979
+				__('A Valid Transaction could not be initialized.', 'event_espresso'),
980
+				__FILE__, __FUNCTION__, __LINE__
981
+			);
982
+		}
983
+		return $transaction;
984
+	}
985
+
986
+
987
+
988
+	/**
989
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
990
+	 *
991
+	 * @access private
992
+	 * @return mixed EE_Transaction|NULL
993
+	 */
994
+	private function _initialize_transaction()
995
+	{
996
+		try {
997
+			// ensure cart totals have been calculated
998
+			$this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
999
+			// grab the cart grand total
1000
+			$cart_total = $this->checkout->cart->get_cart_grand_total();
1001
+			// create new TXN
1002
+			$transaction = EE_Transaction::new_instance(
1003
+				array(
1004
+					'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
1005
+					'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
1006
+					'TXN_paid'      => 0,
1007
+					'STS_ID'        => EEM_Transaction::failed_status_code,
1008
+				)
1009
+			);
1010
+			// save it so that we have an ID for other objects to use
1011
+			$transaction->save();
1012
+			// set cron job for following up on TXNs after their session has expired
1013
+			EE_Cron_Tasks::schedule_expired_transaction_check(
1014
+				EE_Registry::instance()->SSN->expiration() + 1,
1015
+				$transaction->ID()
1016
+			);
1017
+			return $transaction;
1018
+		} catch (Exception $e) {
1019
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1020
+		}
1021
+		return null;
1022
+	}
1023
+
1024
+
1025
+	/**
1026
+	 * _get_registrations
1027
+	 *
1028
+	 * @access private
1029
+	 * @param EE_Transaction $transaction
1030
+	 * @return void
1031
+	 * @throws InvalidDataTypeException
1032
+	 * @throws InvalidEntityException
1033
+	 * @throws EE_Error
1034
+	 */
1035
+	private function _get_registrations(EE_Transaction $transaction)
1036
+	{
1037
+		// first step: grab the registrants  { : o
1038
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1039
+		$this->checkout->total_ticket_count = count($registrations);
1040
+		// verify registrations have been set
1041
+		if (empty($registrations)) {
1042
+			// if no cached registrations, then check the db
1043
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1044
+			// still nothing ? well as long as this isn't a revisit
1045
+			if (empty($registrations) && ! $this->checkout->revisit) {
1046
+				// generate new registrations from scratch
1047
+				$registrations = $this->_initialize_registrations($transaction);
1048
+			}
1049
+		}
1050
+		// sort by their original registration order
1051
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1052
+		// then loop thru the array
1053
+		foreach ($registrations as $registration) {
1054
+			// verify each registration
1055
+			if ($registration instanceof EE_Registration) {
1056
+				// we display all attendee info for the primary registrant
1057
+				if ($this->checkout->reg_url_link === $registration->reg_url_link()
1058
+					&& $registration->is_primary_registrant()
1059
+				) {
1060
+					$this->checkout->primary_revisit = true;
1061
+					break;
1062
+				}
1063
+				if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1064
+					// but hide info if it doesn't belong to you
1065
+					$transaction->clear_cache('Registration', $registration->ID());
1066
+					$this->checkout->total_ticket_count--;
1067
+				}
1068
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
1069
+			}
1070
+		}
1071
+	}
1072
+
1073
+
1074
+	/**
1075
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1076
+	 *
1077
+	 * @access private
1078
+	 * @param EE_Transaction $transaction
1079
+	 * @return    array
1080
+	 * @throws InvalidDataTypeException
1081
+	 * @throws InvalidEntityException
1082
+	 * @throws EE_Error
1083
+	 */
1084
+	private function _initialize_registrations(EE_Transaction $transaction)
1085
+	{
1086
+		$att_nmbr = 0;
1087
+		$registrations = array();
1088
+		if ($transaction instanceof EE_Transaction) {
1089
+			/** @type EE_Registration_Processor $registration_processor */
1090
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1091
+			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1092
+			// now let's add the cart items to the $transaction
1093
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
1094
+				//do the following for each ticket of this type they selected
1095
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
1096
+					$att_nmbr++;
1097
+					/** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1098
+					$CreateRegistrationCommand = EE_Registry::instance()->create(
1099
+						'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1100
+						array(
1101
+							$transaction,
1102
+							$line_item,
1103
+							$att_nmbr,
1104
+							$this->checkout->total_ticket_count,
1105
+						)
1106
+					);
1107
+					// override capabilities for frontend registrations
1108
+					if ( ! is_admin()) {
1109
+						$CreateRegistrationCommand->setCapCheck(
1110
+							new PublicCapabilities('', 'create_new_registration')
1111
+						);
1112
+					}
1113
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1114
+					if ( ! $registration instanceof EE_Registration) {
1115
+						throw new InvalidEntityException($registration, 'EE_Registration');
1116
+					}
1117
+					$registrations[ $registration->ID() ] = $registration;
1118
+				}
1119
+			}
1120
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
1121
+		}
1122
+		return $registrations;
1123
+	}
1124
+
1125
+
1126
+
1127
+	/**
1128
+	 * sorts registrations by REG_count
1129
+	 *
1130
+	 * @access public
1131
+	 * @param EE_Registration $reg_A
1132
+	 * @param EE_Registration $reg_B
1133
+	 * @return int
1134
+	 */
1135
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1136
+	{
1137
+		// this shouldn't ever happen within the same TXN, but oh well
1138
+		if ($reg_A->count() === $reg_B->count()) {
1139
+			return 0;
1140
+		}
1141
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1142
+	}
1143
+
1144
+
1145
+
1146
+	/**
1147
+	 *    _final_verifications
1148
+	 * just makes sure that everything is set up correctly before proceeding
1149
+	 *
1150
+	 * @access    private
1151
+	 * @return    bool
1152
+	 * @throws EE_Error
1153
+	 */
1154
+	private function _final_verifications()
1155
+	{
1156
+		// filter checkout
1157
+		$this->checkout = apply_filters(
1158
+			'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1159
+			$this->checkout
1160
+		);
1161
+		//verify that current step is still set correctly
1162
+		if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1163
+			EE_Error::add_error(
1164
+				__('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'),
1165
+				__FILE__,
1166
+				__FUNCTION__,
1167
+				__LINE__
1168
+			);
1169
+			return false;
1170
+		}
1171
+		// if returning to SPCO, then verify that primary registrant is set
1172
+		if ( ! empty($this->checkout->reg_url_link)) {
1173
+			$valid_registrant = $this->checkout->transaction->primary_registration();
1174
+			if ( ! $valid_registrant instanceof EE_Registration) {
1175
+				EE_Error::add_error(
1176
+					__('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'),
1177
+					__FILE__,
1178
+					__FUNCTION__,
1179
+					__LINE__
1180
+				);
1181
+				return false;
1182
+			}
1183
+			$valid_registrant = null;
1184
+			foreach (
1185
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1186
+			) {
1187
+				if (
1188
+					$registration instanceof EE_Registration
1189
+					&& $registration->reg_url_link() === $this->checkout->reg_url_link
1190
+				) {
1191
+					$valid_registrant = $registration;
1192
+				}
1193
+			}
1194
+			if ( ! $valid_registrant instanceof EE_Registration) {
1195
+				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1196
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1197
+					// clear the session, mark the checkout as unverified, and try again
1198
+					EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1199
+					EED_Single_Page_Checkout::$_initialized = false;
1200
+					EED_Single_Page_Checkout::$_checkout_verified = false;
1201
+					$this->_initialize();
1202
+					EE_Error::reset_notices();
1203
+					return false;
1204
+				}
1205
+				EE_Error::add_error(
1206
+					__(
1207
+						'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1208
+						'event_espresso'
1209
+					),
1210
+					__FILE__,
1211
+					__FUNCTION__,
1212
+					__LINE__
1213
+				);
1214
+				return false;
1215
+			}
1216
+		}
1217
+		// now that things have been kinda sufficiently verified,
1218
+		// let's add the checkout to the session so that it's available to other systems
1219
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1220
+		return true;
1221
+	}
1222
+
1223
+
1224
+
1225
+	/**
1226
+	 *    _initialize_reg_steps
1227
+	 * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1228
+	 * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1229
+	 *
1230
+	 * @access    private
1231
+	 * @param bool $reinitializing
1232
+	 * @throws EE_Error
1233
+	 */
1234
+	private function _initialize_reg_steps($reinitializing = false)
1235
+	{
1236
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1237
+		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1238
+		foreach ($this->checkout->reg_steps as $reg_step) {
1239
+			if ( ! $reg_step->initialize_reg_step()) {
1240
+				// if not initialized then maybe this step is being removed...
1241
+				if ( ! $reinitializing && $reg_step->is_current_step()) {
1242
+					// if it was the current step, then we need to start over here
1243
+					$this->_initialize_reg_steps(true);
1244
+					return;
1245
+				}
1246
+				continue;
1247
+			}
1248
+			// add css and JS for current step
1249
+			$reg_step->enqueue_styles_and_scripts();
1250
+			// i18n
1251
+			$reg_step->translate_js_strings();
1252
+			if ($reg_step->is_current_step()) {
1253
+				// the text that appears on the reg step form submit button
1254
+				$reg_step->set_submit_button_text();
1255
+			}
1256
+		}
1257
+		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1258
+		do_action(
1259
+			"AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1260
+			$this->checkout->current_step
1261
+		);
1262
+	}
1263
+
1264
+
1265
+
1266
+	/**
1267
+	 * _check_form_submission
1268
+	 *
1269
+	 * @access private
1270
+	 * @return boolean
1271
+	 */
1272
+	private function _check_form_submission()
1273
+	{
1274
+		//does this request require the reg form to be generated ?
1275
+		if ($this->checkout->generate_reg_form) {
1276
+			// ever heard that song by Blue Rodeo ?
1277
+			try {
1278
+				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1279
+				// if not displaying a form, then check for form submission
1280
+				if (
1281
+					$this->checkout->process_form_submission
1282
+					&& $this->checkout->current_step->reg_form->was_submitted()
1283
+				) {
1284
+					// clear out any old data in case this step is being run again
1285
+					$this->checkout->current_step->set_valid_data(array());
1286
+					// capture submitted form data
1287
+					$this->checkout->current_step->reg_form->receive_form_submission(
1288
+						apply_filters(
1289
+							'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1290
+							EE_Registry::instance()->REQ->params(),
1291
+							$this->checkout
1292
+						)
1293
+					);
1294
+					// validate submitted form data
1295
+					if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1296
+						// thou shall not pass !!!
1297
+						$this->checkout->continue_reg = false;
1298
+						// any form validation errors?
1299
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1300
+							EE_Error::add_error(
1301
+								$this->checkout->current_step->reg_form->submission_error_message(),
1302
+								__FILE__, __FUNCTION__, __LINE__
1303
+							);
1304
+						}
1305
+						// well not really... what will happen is
1306
+						// we'll just get redirected back to redo the current step
1307
+						$this->go_to_next_step();
1308
+						return false;
1309
+					}
1310
+				}
1311
+			} catch (EE_Error $e) {
1312
+				$e->get_error();
1313
+			}
1314
+		}
1315
+		return true;
1316
+	}
1317
+
1318
+
1319
+
1320
+	/**
1321
+	 * _process_action
1322
+	 *
1323
+	 * @access private
1324
+	 * @return void
1325
+	 * @throws EE_Error
1326
+	 */
1327
+	private function _process_form_action()
1328
+	{
1329
+		// what cha wanna do?
1330
+		switch ($this->checkout->action) {
1331
+			// AJAX next step reg form
1332
+			case 'display_spco_reg_step' :
1333
+				$this->checkout->redirect = false;
1334
+				if (EE_Registry::instance()->REQ->ajax) {
1335
+					$this->checkout->json_response->set_reg_step_html(
1336
+						$this->checkout->current_step->display_reg_form()
1337
+					);
1338
+				}
1339
+				break;
1340
+			default :
1341
+				// meh... do one of those other steps first
1342
+				if (
1343
+					! empty($this->checkout->action)
1344
+					&& is_callable(array($this->checkout->current_step, $this->checkout->action))
1345
+				) {
1346
+					// dynamically creates hook point like:
1347
+					//   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1348
+					do_action(
1349
+						"AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1350
+						$this->checkout->current_step
1351
+					);
1352
+					// call action on current step
1353
+					if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1354
+						// good registrant, you get to proceed
1355
+						if (
1356
+							$this->checkout->current_step->success_message() !== ''
1357
+							&& apply_filters(
1358
+								'FHEE__Single_Page_Checkout___process_form_action__display_success',
1359
+								false
1360
+							)
1361
+						) {
1362
+							EE_Error::add_success(
1363
+								$this->checkout->current_step->success_message()
1364
+								. '<br />' . $this->checkout->next_step->_instructions()
1365
+							);
1366
+						}
1367
+						// pack it up, pack it in...
1368
+						$this->_setup_redirect();
1369
+					}
1370
+					// dynamically creates hook point like:
1371
+					//  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1372
+					do_action(
1373
+						"AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1374
+						$this->checkout->current_step
1375
+					);
1376
+				} else {
1377
+					EE_Error::add_error(
1378
+						sprintf(
1379
+							__(
1380
+								'The requested form action "%s" does not exist for the current "%s" registration step.',
1381
+								'event_espresso'
1382
+							),
1383
+							$this->checkout->action,
1384
+							$this->checkout->current_step->name()
1385
+						),
1386
+						__FILE__,
1387
+						__FUNCTION__,
1388
+						__LINE__
1389
+					);
1390
+				}
1391
+			// end default
1392
+		}
1393
+		// store our progress so far
1394
+		$this->checkout->stash_transaction_and_checkout();
1395
+		// advance to the next step! If you pass GO, collect $200
1396
+		$this->go_to_next_step();
1397
+	}
1398
+
1399
+
1400
+
1401
+	/**
1402
+	 *        add_styles_and_scripts
1403
+	 *
1404
+	 * @access        public
1405
+	 * @return        void
1406
+	 */
1407
+	public function add_styles_and_scripts()
1408
+	{
1409
+		// i18n
1410
+		$this->translate_js_strings();
1411
+		if ($this->checkout->admin_request) {
1412
+			add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1413
+		} else {
1414
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1415
+		}
1416
+	}
1417
+
1418
+
1419
+
1420
+	/**
1421
+	 *        translate_js_strings
1422
+	 *
1423
+	 * @access        public
1424
+	 * @return        void
1425
+	 */
1426
+	public function translate_js_strings()
1427
+	{
1428
+		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1429
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1430
+		EE_Registry::$i18n_js_strings['server_error'] = __(
1431
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1432
+			'event_espresso'
1433
+		);
1434
+		EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1435
+			'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1436
+			'event_espresso'
1437
+		);
1438
+		EE_Registry::$i18n_js_strings['validation_error'] = __(
1439
+			'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1440
+			'event_espresso'
1441
+		);
1442
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1443
+			'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1444
+			'event_espresso'
1445
+		);
1446
+		EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1447
+			'This registration step could not be completed. Please refresh the page and try again.',
1448
+			'event_espresso'
1449
+		);
1450
+		EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1451
+			'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1452
+			'event_espresso'
1453
+		);
1454
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1455
+			__(
1456
+				'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1457
+				'event_espresso'
1458
+			),
1459
+			'<br/>',
1460
+			'<br/>'
1461
+		);
1462
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1463
+		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1464
+		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1465
+		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1466
+		EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1467
+		EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1468
+		EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1469
+		EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1470
+		EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1471
+		EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1472
+		EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1473
+		EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1474
+		EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1475
+		EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1476
+		EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1477
+		EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1478
+		EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1479
+		EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1480
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
1481
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1482
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1483
+			true
1484
+		);
1485
+		EE_Registry::$i18n_js_strings['session_extension'] = absint(
1486
+			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1487
+		);
1488
+		EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1489
+			'M d, Y H:i:s',
1490
+			EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1491
+		);
1492
+	}
1493
+
1494
+
1495
+
1496
+	/**
1497
+	 *    enqueue_styles_and_scripts
1498
+	 *
1499
+	 * @access        public
1500
+	 * @return        void
1501
+	 * @throws EE_Error
1502
+	 */
1503
+	public function enqueue_styles_and_scripts()
1504
+	{
1505
+		// load css
1506
+		wp_register_style(
1507
+			'single_page_checkout',
1508
+			SPCO_CSS_URL . 'single_page_checkout.css',
1509
+			array('espresso_default'),
1510
+			EVENT_ESPRESSO_VERSION
1511
+		);
1512
+		wp_enqueue_style('single_page_checkout');
1513
+		// load JS
1514
+		wp_register_script(
1515
+			'jquery_plugin',
1516
+			EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1517
+			array('jquery'),
1518
+			'1.0.1',
1519
+			true
1520
+		);
1521
+		wp_register_script(
1522
+			'jquery_countdown',
1523
+			EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1524
+			array('jquery_plugin'),
1525
+			'2.0.2',
1526
+			true
1527
+		);
1528
+		wp_register_script(
1529
+			'single_page_checkout',
1530
+			SPCO_JS_URL . 'single_page_checkout.js',
1531
+			array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1532
+			EVENT_ESPRESSO_VERSION,
1533
+			true
1534
+		);
1535
+		if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1536
+			$this->checkout->registration_form->enqueue_js();
1537
+		}
1538
+		if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1539
+			$this->checkout->current_step->reg_form->enqueue_js();
1540
+		}
1541
+		wp_enqueue_script('single_page_checkout');
1542
+		/**
1543
+		 * global action hook for enqueueing styles and scripts with
1544
+		 * spco calls.
1545
+		 */
1546
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1547
+		/**
1548
+		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1549
+		 * The hook will end up being something like:
1550
+		 *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1551
+		 */
1552
+		do_action(
1553
+			'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1554
+			$this
1555
+		);
1556
+	}
1557
+
1558
+
1559
+
1560
+	/**
1561
+	 *    display the Registration Single Page Checkout Form
1562
+	 *
1563
+	 * @access    private
1564
+	 * @return    void
1565
+	 * @throws EE_Error
1566
+	 */
1567
+	private function _display_spco_reg_form()
1568
+	{
1569
+		// if registering via the admin, just display the reg form for the current step
1570
+		if ($this->checkout->admin_request) {
1571
+			EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1572
+		} else {
1573
+			// add powered by EE msg
1574
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1575
+			$empty_cart = count(
1576
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1577
+			) < 1;
1578
+			EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1579
+			$cookies_not_set_msg = '';
1580
+			if ($empty_cart) {
1581
+				$cookies_not_set_msg = apply_filters(
1582
+					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1583
+					sprintf(
1584
+						__(
1585
+							'%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1586
+							'event_espresso'
1587
+						),
1588
+						'<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1589
+						'</div>',
1590
+						'<h6 class="important-notice">',
1591
+						'</h6>',
1592
+						'<p>',
1593
+						'</p>',
1594
+						'<br />',
1595
+						'<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1596
+						'</a>'
1597
+					)
1598
+				);
1599
+			}
1600
+			$this->checkout->registration_form = new EE_Form_Section_Proper(
1601
+				array(
1602
+					'name'            => 'single-page-checkout',
1603
+					'html_id'         => 'ee-single-page-checkout-dv',
1604
+					'layout_strategy' =>
1605
+						new EE_Template_Layout(
1606
+							array(
1607
+								'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1608
+								'template_args'        => array(
1609
+									'empty_cart'              => $empty_cart,
1610
+									'revisit'                 => $this->checkout->revisit,
1611
+									'reg_steps'               => $this->checkout->reg_steps,
1612
+									'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1613
+										? $this->checkout->next_step->slug()
1614
+										: '',
1615
+									'empty_msg'               => apply_filters(
1616
+										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1617
+										sprintf(
1618
+											__(
1619
+												'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1620
+												'event_espresso'
1621
+											),
1622
+											'<a href="'
1623
+											. get_post_type_archive_link('espresso_events')
1624
+											. '" title="',
1625
+											'">',
1626
+											'</a>'
1627
+										)
1628
+									),
1629
+									'cookies_not_set_msg'     => $cookies_not_set_msg,
1630
+									'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1631
+									'session_expiration'      => gmdate(
1632
+										'M d, Y H:i:s',
1633
+										EE_Registry::instance()->SSN->expiration()
1634
+										+ (get_option('gmt_offset') * HOUR_IN_SECONDS)
1635
+									),
1636
+								),
1637
+							)
1638
+						),
1639
+				)
1640
+			);
1641
+			// load template and add to output sent that gets filtered into the_content()
1642
+			EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1643
+		}
1644
+	}
1645
+
1646
+
1647
+
1648
+	/**
1649
+	 *    add_extra_finalize_registration_inputs
1650
+	 *
1651
+	 * @access    public
1652
+	 * @param $next_step
1653
+	 * @internal  param string $label
1654
+	 * @return void
1655
+	 */
1656
+	public function add_extra_finalize_registration_inputs($next_step)
1657
+	{
1658
+		if ($next_step === 'finalize_registration') {
1659
+			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1660
+		}
1661
+	}
1662
+
1663
+
1664
+
1665
+	/**
1666
+	 *    display_registration_footer
1667
+	 *
1668
+	 * @access    public
1669
+	 * @return    string
1670
+	 */
1671
+	public static function display_registration_footer()
1672
+	{
1673
+		if (
1674
+		apply_filters(
1675
+			'FHEE__EE_Front__Controller__show_reg_footer',
1676
+			EE_Registry::instance()->CFG->admin->show_reg_footer
1677
+		)
1678
+		) {
1679
+			add_filter(
1680
+				'FHEE__EEH_Template__powered_by_event_espresso__url',
1681
+				function ($url) {
1682
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1683
+				}
1684
+			);
1685
+			echo apply_filters(
1686
+				'FHEE__EE_Front_Controller__display_registration_footer',
1687
+				\EEH_Template::powered_by_event_espresso(
1688
+					'',
1689
+					'espresso-registration-footer-dv',
1690
+					array('utm_content' => 'registration_checkout')
1691
+				)
1692
+			);
1693
+		}
1694
+		return '';
1695
+	}
1696
+
1697
+
1698
+
1699
+	/**
1700
+	 *    unlock_transaction
1701
+	 *
1702
+	 * @access    public
1703
+	 * @return    void
1704
+	 * @throws EE_Error
1705
+	 */
1706
+	public function unlock_transaction()
1707
+	{
1708
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1709
+			$this->checkout->transaction->unlock();
1710
+		}
1711
+	}
1712
+
1713
+
1714
+
1715
+	/**
1716
+	 *        _setup_redirect
1717
+	 *
1718
+	 * @access    private
1719
+	 * @return void
1720
+	 */
1721
+	private function _setup_redirect()
1722
+	{
1723
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1724
+			$this->checkout->redirect = true;
1725
+			if (empty($this->checkout->redirect_url)) {
1726
+				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1727
+			}
1728
+			$this->checkout->redirect_url = apply_filters(
1729
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1730
+				$this->checkout->redirect_url,
1731
+				$this->checkout
1732
+			);
1733
+		}
1734
+	}
1735
+
1736
+
1737
+
1738
+	/**
1739
+	 *   handle ajax message responses and redirects
1740
+	 *
1741
+	 * @access public
1742
+	 * @return void
1743
+	 * @throws EE_Error
1744
+	 */
1745
+	public function go_to_next_step()
1746
+	{
1747
+		if (EE_Registry::instance()->REQ->ajax) {
1748
+			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1749
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1750
+		}
1751
+		$this->unlock_transaction();
1752
+		// just return for these conditions
1753
+		if (
1754
+			$this->checkout->admin_request
1755
+			|| $this->checkout->action === 'redirect_form'
1756
+			|| $this->checkout->action === 'update_checkout'
1757
+		) {
1758
+			return;
1759
+		}
1760
+		// AJAX response
1761
+		$this->_handle_json_response();
1762
+		// redirect to next step or the Thank You page
1763
+		$this->_handle_html_redirects();
1764
+		// hmmm... must be something wrong, so let's just display the form again !
1765
+		$this->_display_spco_reg_form();
1766
+	}
1767
+
1768
+
1769
+
1770
+	/**
1771
+	 *   _handle_json_response
1772
+	 *
1773
+	 * @access protected
1774
+	 * @return void
1775
+	 */
1776
+	protected function _handle_json_response()
1777
+	{
1778
+		// if this is an ajax request
1779
+		if (EE_Registry::instance()->REQ->ajax) {
1780
+			// DEBUG LOG
1781
+			//$this->checkout->log(
1782
+			//	__CLASS__, __FUNCTION__, __LINE__,
1783
+			//	array(
1784
+			//		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1785
+			//		'redirect'                   => $this->checkout->redirect,
1786
+			//		'continue_reg'               => $this->checkout->continue_reg,
1787
+			//	)
1788
+			//);
1789
+			$this->checkout->json_response->set_registration_time_limit(
1790
+				$this->checkout->get_registration_time_limit()
1791
+			);
1792
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1793
+			// just send the ajax (
1794
+			$json_response = apply_filters(
1795
+				'FHEE__EE_Single_Page_Checkout__JSON_response',
1796
+				$this->checkout->json_response
1797
+			);
1798
+			echo $json_response;
1799
+			exit();
1800
+		}
1801
+	}
1802
+
1803
+
1804
+
1805
+	/**
1806
+	 *   _handle_redirects
1807
+	 *
1808
+	 * @access protected
1809
+	 * @return void
1810
+	 */
1811
+	protected function _handle_html_redirects()
1812
+	{
1813
+		// going somewhere ?
1814
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1815
+			// store notices in a transient
1816
+			EE_Error::get_notices(false, true, true);
1817
+			// DEBUG LOG
1818
+			//$this->checkout->log(
1819
+			//	__CLASS__, __FUNCTION__, __LINE__,
1820
+			//	array(
1821
+			//		'headers_sent' => headers_sent(),
1822
+			//		'redirect_url'     => $this->checkout->redirect_url,
1823
+			//		'headers_list'    => headers_list(),
1824
+			//	)
1825
+			//);
1826
+			wp_safe_redirect($this->checkout->redirect_url);
1827
+			exit();
1828
+		}
1829
+	}
1830
+
1831
+
1832
+
1833
+	/**
1834
+	 *   set_checkout_anchor
1835
+	 *
1836
+	 * @access public
1837
+	 * @return void
1838
+	 */
1839
+	public function set_checkout_anchor()
1840
+	{
1841
+		echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1842
+	}
1843
+
1844
+	/**
1845
+	 *    getRegistrationExpirationNotice
1846
+	 *
1847
+	 * @since 4.9.59.p
1848
+	 * @access    public
1849
+	 * @return    string
1850
+	 */
1851
+	public static function getRegistrationExpirationNotice()
1852
+	{
1853
+		return sprintf(
1854
+			__('%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s',
1855
+				'event_espresso'),
1856
+			'<h4 class="important-notice">',
1857
+			'</h4>',
1858
+			'<br />',
1859
+			'<p>',
1860
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1861
+			'">',
1862
+			'</a>',
1863
+			'</p>'
1864
+		);
1865
+	}
1866 1866
 
1867 1867
 }
1868 1868
 // End of file EED_Single_Page_Checkout.module.php
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since       4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 
64 64
 } else {
65
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
66
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
-        /**
68
-         * espresso_minimum_php_version_error
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
65
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
66
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
+		/**
68
+		 * espresso_minimum_php_version_error
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.61.rc.001');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.61.rc.001');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.