Completed
Branch FET/editor-dates-tickets-refac... (fd7b07)
by
unknown
40:32 queued 30:39
created
core/db_classes/EE_Event.class.php 1 patch
Indentation   +1353 added lines, -1353 removed lines patch added patch discarded remove patch
@@ -13,1357 +13,1357 @@
 block discarded – undo
13 13
 class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event
14 14
 {
15 15
 
16
-    /**
17
-     * cached value for the the logical active status for the event
18
-     *
19
-     * @see get_active_status()
20
-     * @var string
21
-     */
22
-    protected $_active_status = '';
23
-
24
-    /**
25
-     * This is just used for caching the Primary Datetime for the Event on initial retrieval
26
-     *
27
-     * @var EE_Datetime
28
-     */
29
-    protected $_Primary_Datetime;
30
-
31
-    /**
32
-     * @var EventSpacesCalculator $available_spaces_calculator
33
-     */
34
-    protected $available_spaces_calculator;
35
-
36
-
37
-    /**
38
-     * @param array  $props_n_values          incoming values
39
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
40
-     *                                        used.)
41
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
42
-     *                                        date_format and the second value is the time format
43
-     * @return EE_Event
44
-     * @throws EE_Error
45
-     */
46
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
47
-    {
48
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
49
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
50
-    }
51
-
52
-
53
-    /**
54
-     * @param array  $props_n_values  incoming values from the database
55
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
56
-     *                                the website will be used.
57
-     * @return EE_Event
58
-     * @throws EE_Error
59
-     */
60
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
61
-    {
62
-        return new self($props_n_values, true, $timezone);
63
-    }
64
-
65
-
66
-    /**
67
-     * @return EventSpacesCalculator
68
-     * @throws \EE_Error
69
-     */
70
-    public function getAvailableSpacesCalculator()
71
-    {
72
-        if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) {
73
-            $this->available_spaces_calculator = new EventSpacesCalculator($this);
74
-        }
75
-        return $this->available_spaces_calculator;
76
-    }
77
-
78
-
79
-    /**
80
-     * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods
81
-     *
82
-     * @param string $field_name
83
-     * @param mixed  $field_value
84
-     * @param bool   $use_default
85
-     * @throws EE_Error
86
-     */
87
-    public function set($field_name, $field_value, $use_default = false)
88
-    {
89
-        switch ($field_name) {
90
-            case 'status':
91
-                $this->set_status($field_value, $use_default);
92
-                break;
93
-            default:
94
-                parent::set($field_name, $field_value, $use_default);
95
-        }
96
-    }
97
-
98
-
99
-    /**
100
-     *    set_status
101
-     * Checks if event status is being changed to SOLD OUT
102
-     * and updates event meta data with previous event status
103
-     * so that we can revert things if/when the event is no longer sold out
104
-     *
105
-     * @access public
106
-     * @param string $new_status
107
-     * @param bool   $use_default
108
-     * @return void
109
-     * @throws EE_Error
110
-     */
111
-    public function set_status($new_status = null, $use_default = false)
112
-    {
113
-        // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave
114
-        if (empty($new_status) && ! $use_default) {
115
-            return;
116
-        }
117
-        // get current Event status
118
-        $old_status = $this->status();
119
-        // if status has changed
120
-        if ($old_status !== $new_status) {
121
-            // TO sold_out
122
-            if ($new_status === EEM_Event::sold_out) {
123
-                // save the previous event status so that we can revert if the event is no longer sold out
124
-                $this->add_post_meta('_previous_event_status', $old_status);
125
-                do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status);
126
-                // OR FROM  sold_out
127
-            } elseif ($old_status === EEM_Event::sold_out) {
128
-                $this->delete_post_meta('_previous_event_status');
129
-                do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status);
130
-            }
131
-            // clear out the active status so that it gets reset the next time it is requested
132
-            $this->_active_status = null;
133
-            // update status
134
-            parent::set('status', $new_status, $use_default);
135
-            do_action('AHEE__EE_Event__set_status__after_update', $this);
136
-            return;
137
-        }
138
-        // even though the old value matches the new value, it's still good to
139
-        // allow the parent set method to have a say
140
-        parent::set('status', $new_status, $use_default);
141
-    }
142
-
143
-
144
-    /**
145
-     * Gets all the datetimes for this event
146
-     *
147
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
148
-     * @return EE_Base_Class[]|EE_Datetime[]
149
-     * @throws EE_Error
150
-     */
151
-    public function datetimes($query_params = array())
152
-    {
153
-        return $this->get_many_related('Datetime', $query_params);
154
-    }
155
-
156
-
157
-    /**
158
-     * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order
159
-     *
160
-     * @return EE_Base_Class[]|EE_Datetime[]
161
-     * @throws EE_Error
162
-     */
163
-    public function datetimes_in_chronological_order()
164
-    {
165
-        return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC')));
166
-    }
167
-
168
-
169
-    /**
170
-     * Gets all the datetimes for this event, ordered by the DTT_order on the datetime.
171
-     * @darren, we should probably UNSET timezone on the EEM_Datetime model
172
-     * after running our query, so that this timezone isn't set for EVERY query
173
-     * on EEM_Datetime for the rest of the request, no?
174
-     *
175
-     * @param boolean $show_expired whether or not to include expired events
176
-     * @param boolean $show_deleted whether or not to include deleted events
177
-     * @param null    $limit
178
-     * @return EE_Datetime[]
179
-     * @throws EE_Error
180
-     */
181
-    public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null)
182
-    {
183
-        return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order(
184
-            $this->ID(),
185
-            $show_expired,
186
-            $show_deleted,
187
-            $limit
188
-        );
189
-    }
190
-
191
-
192
-    /**
193
-     * Returns one related datetime. Mostly only used by some legacy code.
194
-     *
195
-     * @return EE_Base_Class|EE_Datetime
196
-     * @throws EE_Error
197
-     */
198
-    public function first_datetime()
199
-    {
200
-        return $this->get_first_related('Datetime');
201
-    }
202
-
203
-
204
-    /**
205
-     * Returns the 'primary' datetime for the event
206
-     *
207
-     * @param bool $try_to_exclude_expired
208
-     * @param bool $try_to_exclude_deleted
209
-     * @return EE_Datetime
210
-     * @throws EE_Error
211
-     */
212
-    public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
213
-    {
214
-        if (! empty($this->_Primary_Datetime)) {
215
-            return $this->_Primary_Datetime;
216
-        }
217
-        $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event(
218
-            $this->ID(),
219
-            $try_to_exclude_expired,
220
-            $try_to_exclude_deleted
221
-        );
222
-        return $this->_Primary_Datetime;
223
-    }
224
-
225
-
226
-    /**
227
-     * Gets all the tickets available for purchase of this event
228
-     *
229
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
230
-     * @return EE_Base_Class[]|EE_Ticket[]
231
-     * @throws EE_Error
232
-     */
233
-    public function tickets($query_params = array())
234
-    {
235
-        // first get all datetimes
236
-        $datetimes = $this->datetimes_ordered();
237
-        if (! $datetimes) {
238
-            return array();
239
-        }
240
-        $datetime_ids = array();
241
-        foreach ($datetimes as $datetime) {
242
-            $datetime_ids[] = $datetime->ID();
243
-        }
244
-        $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids));
245
-        // if incoming $query_params has where conditions let's merge but not override existing.
246
-        if (is_array($query_params) && isset($query_params[0])) {
247
-            $where_params = array_merge($query_params[0], $where_params);
248
-            unset($query_params[0]);
249
-        }
250
-        // now add $where_params to $query_params
251
-        $query_params[0] = $where_params;
252
-        return EEM_Ticket::instance()->get_all($query_params);
253
-    }
254
-
255
-
256
-    /**
257
-     * get all unexpired untrashed tickets
258
-     *
259
-     * @return EE_Ticket[]
260
-     * @throws EE_Error
261
-     */
262
-    public function active_tickets()
263
-    {
264
-        return $this->tickets(
265
-            array(
266
-                array(
267
-                    'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
268
-                    'TKT_deleted'  => false,
269
-                ),
270
-            )
271
-        );
272
-    }
273
-
274
-
275
-    /**
276
-     * @return bool
277
-     * @throws EE_Error
278
-     */
279
-    public function additional_limit()
280
-    {
281
-        return $this->get('EVT_additional_limit');
282
-    }
283
-
284
-
285
-    /**
286
-     * @return bool
287
-     * @throws EE_Error
288
-     */
289
-    public function allow_overflow()
290
-    {
291
-        return $this->get('EVT_allow_overflow');
292
-    }
293
-
294
-
295
-    /**
296
-     * @return bool
297
-     * @throws EE_Error
298
-     */
299
-    public function created()
300
-    {
301
-        return $this->get('EVT_created');
302
-    }
303
-
304
-
305
-    /**
306
-     * @return bool
307
-     * @throws EE_Error
308
-     */
309
-    public function description()
310
-    {
311
-        return $this->get('EVT_desc');
312
-    }
313
-
314
-
315
-    /**
316
-     * Runs do_shortcode and wpautop on the description
317
-     *
318
-     * @return string of html
319
-     * @throws EE_Error
320
-     */
321
-    public function description_filtered()
322
-    {
323
-        return $this->get_pretty('EVT_desc');
324
-    }
325
-
326
-
327
-    /**
328
-     * @return bool
329
-     * @throws EE_Error
330
-     */
331
-    public function display_description()
332
-    {
333
-        return $this->get('EVT_display_desc');
334
-    }
335
-
336
-
337
-    /**
338
-     * @return bool
339
-     * @throws EE_Error
340
-     */
341
-    public function display_ticket_selector()
342
-    {
343
-        return (bool) $this->get('EVT_display_ticket_selector');
344
-    }
345
-
346
-
347
-    /**
348
-     * @return bool
349
-     * @throws EE_Error
350
-     */
351
-    public function external_url()
352
-    {
353
-        return $this->get('EVT_external_URL');
354
-    }
355
-
356
-
357
-    /**
358
-     * @return bool
359
-     * @throws EE_Error
360
-     */
361
-    public function member_only()
362
-    {
363
-        return $this->get('EVT_member_only');
364
-    }
365
-
366
-
367
-    /**
368
-     * @return bool
369
-     * @throws EE_Error
370
-     */
371
-    public function phone()
372
-    {
373
-        return $this->get('EVT_phone');
374
-    }
375
-
376
-
377
-    /**
378
-     * @return bool
379
-     * @throws EE_Error
380
-     */
381
-    public function modified()
382
-    {
383
-        return $this->get('EVT_modified');
384
-    }
385
-
386
-
387
-    /**
388
-     * @return bool
389
-     * @throws EE_Error
390
-     */
391
-    public function name()
392
-    {
393
-        return $this->get('EVT_name');
394
-    }
395
-
396
-
397
-    /**
398
-     * @return bool
399
-     * @throws EE_Error
400
-     */
401
-    public function order()
402
-    {
403
-        return $this->get('EVT_order');
404
-    }
405
-
406
-
407
-    /**
408
-     * @return bool|string
409
-     * @throws EE_Error
410
-     */
411
-    public function default_registration_status()
412
-    {
413
-        $event_default_registration_status = $this->get('EVT_default_registration_status');
414
-        return ! empty($event_default_registration_status)
415
-            ? $event_default_registration_status
416
-            : EE_Registry::instance()->CFG->registration->default_STS_ID;
417
-    }
418
-
419
-
420
-    /**
421
-     * @param int  $num_words
422
-     * @param null $more
423
-     * @param bool $not_full_desc
424
-     * @return bool|string
425
-     * @throws EE_Error
426
-     */
427
-    public function short_description($num_words = 55, $more = null, $not_full_desc = false)
428
-    {
429
-        $short_desc = $this->get('EVT_short_desc');
430
-        if (! empty($short_desc) || $not_full_desc) {
431
-            return $short_desc;
432
-        }
433
-        $full_desc = $this->get('EVT_desc');
434
-        return wp_trim_words($full_desc, $num_words, $more);
435
-    }
436
-
437
-
438
-    /**
439
-     * @return bool
440
-     * @throws EE_Error
441
-     */
442
-    public function slug()
443
-    {
444
-        return $this->get('EVT_slug');
445
-    }
446
-
447
-
448
-    /**
449
-     * @return bool
450
-     * @throws EE_Error
451
-     */
452
-    public function timezone_string()
453
-    {
454
-        return $this->get('EVT_timezone_string');
455
-    }
456
-
457
-
458
-    /**
459
-     * @return bool
460
-     * @throws EE_Error
461
-     */
462
-    public function visible_on()
463
-    {
464
-        return $this->get('EVT_visible_on');
465
-    }
466
-
467
-
468
-    /**
469
-     * @return int
470
-     * @throws EE_Error
471
-     */
472
-    public function wp_user()
473
-    {
474
-        return $this->get('EVT_wp_user');
475
-    }
476
-
477
-
478
-    /**
479
-     * @return bool
480
-     * @throws EE_Error
481
-     */
482
-    public function donations()
483
-    {
484
-        return $this->get('EVT_donations');
485
-    }
486
-
487
-
488
-    /**
489
-     * @param $limit
490
-     * @throws EE_Error
491
-     */
492
-    public function set_additional_limit($limit)
493
-    {
494
-        $this->set('EVT_additional_limit', $limit);
495
-    }
496
-
497
-
498
-    /**
499
-     * @param $created
500
-     * @throws EE_Error
501
-     */
502
-    public function set_created($created)
503
-    {
504
-        $this->set('EVT_created', $created);
505
-    }
506
-
507
-
508
-    /**
509
-     * @param $desc
510
-     * @throws EE_Error
511
-     */
512
-    public function set_description($desc)
513
-    {
514
-        $this->set('EVT_desc', $desc);
515
-    }
516
-
517
-
518
-    /**
519
-     * @param $display_desc
520
-     * @throws EE_Error
521
-     */
522
-    public function set_display_description($display_desc)
523
-    {
524
-        $this->set('EVT_display_desc', $display_desc);
525
-    }
526
-
527
-
528
-    /**
529
-     * @param $display_ticket_selector
530
-     * @throws EE_Error
531
-     */
532
-    public function set_display_ticket_selector($display_ticket_selector)
533
-    {
534
-        $this->set('EVT_display_ticket_selector', $display_ticket_selector);
535
-    }
536
-
537
-
538
-    /**
539
-     * @param $external_url
540
-     * @throws EE_Error
541
-     */
542
-    public function set_external_url($external_url)
543
-    {
544
-        $this->set('EVT_external_URL', $external_url);
545
-    }
546
-
547
-
548
-    /**
549
-     * @param $member_only
550
-     * @throws EE_Error
551
-     */
552
-    public function set_member_only($member_only)
553
-    {
554
-        $this->set('EVT_member_only', $member_only);
555
-    }
556
-
557
-
558
-    /**
559
-     * @param $event_phone
560
-     * @throws EE_Error
561
-     */
562
-    public function set_event_phone($event_phone)
563
-    {
564
-        $this->set('EVT_phone', $event_phone);
565
-    }
566
-
567
-
568
-    /**
569
-     * @param $modified
570
-     * @throws EE_Error
571
-     */
572
-    public function set_modified($modified)
573
-    {
574
-        $this->set('EVT_modified', $modified);
575
-    }
576
-
577
-
578
-    /**
579
-     * @param $name
580
-     * @throws EE_Error
581
-     */
582
-    public function set_name($name)
583
-    {
584
-        $this->set('EVT_name', $name);
585
-    }
586
-
587
-
588
-    /**
589
-     * @param $order
590
-     * @throws EE_Error
591
-     */
592
-    public function set_order($order)
593
-    {
594
-        $this->set('EVT_order', $order);
595
-    }
596
-
597
-
598
-    /**
599
-     * @param $short_desc
600
-     * @throws EE_Error
601
-     */
602
-    public function set_short_description($short_desc)
603
-    {
604
-        $this->set('EVT_short_desc', $short_desc);
605
-    }
606
-
607
-
608
-    /**
609
-     * @param $slug
610
-     * @throws EE_Error
611
-     */
612
-    public function set_slug($slug)
613
-    {
614
-        $this->set('EVT_slug', $slug);
615
-    }
616
-
617
-
618
-    /**
619
-     * @param $timezone_string
620
-     * @throws EE_Error
621
-     */
622
-    public function set_timezone_string($timezone_string)
623
-    {
624
-        $this->set('EVT_timezone_string', $timezone_string);
625
-    }
626
-
627
-
628
-    /**
629
-     * @param $visible_on
630
-     * @throws EE_Error
631
-     */
632
-    public function set_visible_on($visible_on)
633
-    {
634
-        $this->set('EVT_visible_on', $visible_on);
635
-    }
636
-
637
-
638
-    /**
639
-     * @param $wp_user
640
-     * @throws EE_Error
641
-     */
642
-    public function set_wp_user($wp_user)
643
-    {
644
-        $this->set('EVT_wp_user', $wp_user);
645
-    }
646
-
647
-
648
-    /**
649
-     * @param $default_registration_status
650
-     * @throws EE_Error
651
-     */
652
-    public function set_default_registration_status($default_registration_status)
653
-    {
654
-        $this->set('EVT_default_registration_status', $default_registration_status);
655
-    }
656
-
657
-
658
-    /**
659
-     * @param $donations
660
-     * @throws EE_Error
661
-     */
662
-    public function set_donations($donations)
663
-    {
664
-        $this->set('EVT_donations', $donations);
665
-    }
666
-
667
-
668
-    /**
669
-     * Adds a venue to this event
670
-     *
671
-     * @param EE_Venue /int $venue_id_or_obj
672
-     * @return EE_Base_Class|EE_Venue
673
-     * @throws EE_Error
674
-     */
675
-    public function add_venue($venue_id_or_obj)
676
-    {
677
-        return $this->_add_relation_to($venue_id_or_obj, 'Venue');
678
-    }
679
-
680
-
681
-    /**
682
-     * Removes a venue from the event
683
-     *
684
-     * @param EE_Venue /int $venue_id_or_obj
685
-     * @return EE_Base_Class|EE_Venue
686
-     * @throws EE_Error
687
-     */
688
-    public function remove_venue($venue_id_or_obj)
689
-    {
690
-        return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
691
-    }
692
-
693
-
694
-    /**
695
-     * Gets all the venues related ot the event. May provide additional $query_params if desired
696
-     *
697
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
698
-     * @return EE_Base_Class[]|EE_Venue[]
699
-     * @throws EE_Error
700
-     */
701
-    public function venues($query_params = array())
702
-    {
703
-        return $this->get_many_related('Venue', $query_params);
704
-    }
705
-
706
-
707
-    /**
708
-     * check if event id is present and if event is published
709
-     *
710
-     * @access public
711
-     * @return boolean true yes, false no
712
-     * @throws EE_Error
713
-     */
714
-    private function _has_ID_and_is_published()
715
-    {
716
-        // first check if event id is present and not NULL,
717
-        // then check if this event is published (or any of the equivalent "published" statuses)
718
-        return
719
-            $this->ID() && $this->ID() !== null
720
-            && (
721
-                $this->status() === 'publish'
722
-                || $this->status() === EEM_Event::sold_out
723
-                || $this->status() === EEM_Event::postponed
724
-                || $this->status() === EEM_Event::cancelled
725
-            );
726
-    }
727
-
728
-
729
-    /**
730
-     * This simply compares the internal dates with NOW and determines if the event is upcoming or not.
731
-     *
732
-     * @access public
733
-     * @return boolean true yes, false no
734
-     * @throws EE_Error
735
-     */
736
-    public function is_upcoming()
737
-    {
738
-        // check if event id is present and if this event is published
739
-        if ($this->is_inactive()) {
740
-            return false;
741
-        }
742
-        // set initial value
743
-        $upcoming = false;
744
-        // next let's get all datetimes and loop through them
745
-        $datetimes = $this->datetimes_in_chronological_order();
746
-        foreach ($datetimes as $datetime) {
747
-            if ($datetime instanceof EE_Datetime) {
748
-                // if this dtt is expired then we continue cause one of the other datetimes might be upcoming.
749
-                if ($datetime->is_expired()) {
750
-                    continue;
751
-                }
752
-                // if this dtt is active then we return false.
753
-                if ($datetime->is_active()) {
754
-                    return false;
755
-                }
756
-                // otherwise let's check upcoming status
757
-                $upcoming = $datetime->is_upcoming();
758
-            }
759
-        }
760
-        return $upcoming;
761
-    }
762
-
763
-
764
-    /**
765
-     * @return bool
766
-     * @throws EE_Error
767
-     */
768
-    public function is_active()
769
-    {
770
-        // check if event id is present and if this event is published
771
-        if ($this->is_inactive()) {
772
-            return false;
773
-        }
774
-        // set initial value
775
-        $active = false;
776
-        // next let's get all datetimes and loop through them
777
-        $datetimes = $this->datetimes_in_chronological_order();
778
-        foreach ($datetimes as $datetime) {
779
-            if ($datetime instanceof EE_Datetime) {
780
-                // if this dtt is expired then we continue cause one of the other datetimes might be active.
781
-                if ($datetime->is_expired()) {
782
-                    continue;
783
-                }
784
-                // if this dtt is upcoming then we return false.
785
-                if ($datetime->is_upcoming()) {
786
-                    return false;
787
-                }
788
-                // otherwise let's check active status
789
-                $active = $datetime->is_active();
790
-            }
791
-        }
792
-        return $active;
793
-    }
794
-
795
-
796
-    /**
797
-     * @return bool
798
-     * @throws EE_Error
799
-     */
800
-    public function is_expired()
801
-    {
802
-        // check if event id is present and if this event is published
803
-        if ($this->is_inactive()) {
804
-            return false;
805
-        }
806
-        // set initial value
807
-        $expired = false;
808
-        // first let's get all datetimes and loop through them
809
-        $datetimes = $this->datetimes_in_chronological_order();
810
-        foreach ($datetimes as $datetime) {
811
-            if ($datetime instanceof EE_Datetime) {
812
-                // if this dtt is upcoming or active then we return false.
813
-                if ($datetime->is_upcoming() || $datetime->is_active()) {
814
-                    return false;
815
-                }
816
-                // otherwise let's check active status
817
-                $expired = $datetime->is_expired();
818
-            }
819
-        }
820
-        return $expired;
821
-    }
822
-
823
-
824
-    /**
825
-     * @return bool
826
-     * @throws EE_Error
827
-     */
828
-    public function is_inactive()
829
-    {
830
-        // check if event id is present and if this event is published
831
-        if ($this->_has_ID_and_is_published()) {
832
-            return false;
833
-        }
834
-        return true;
835
-    }
836
-
837
-
838
-    /**
839
-     * calculate spaces remaining based on "saleable" tickets
840
-     *
841
-     * @param array $tickets
842
-     * @param bool  $filtered
843
-     * @return int|float
844
-     * @throws EE_Error
845
-     * @throws DomainException
846
-     * @throws UnexpectedEntityException
847
-     */
848
-    public function spaces_remaining($tickets = array(), $filtered = true)
849
-    {
850
-        $this->getAvailableSpacesCalculator()->setActiveTickets($tickets);
851
-        $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining();
852
-        return $filtered
853
-            ? apply_filters(
854
-                'FHEE_EE_Event__spaces_remaining',
855
-                $spaces_remaining,
856
-                $this,
857
-                $tickets
858
-            )
859
-            : $spaces_remaining;
860
-    }
861
-
862
-
863
-    /**
864
-     *    perform_sold_out_status_check
865
-     *    checks all of this events's datetime  reg_limit - sold values to determine if ANY datetimes have spaces
866
-     *    available... if NOT, then the event status will get toggled to 'sold_out'
867
-     *
868
-     * @return bool    return the ACTUAL sold out state.
869
-     * @throws EE_Error
870
-     * @throws DomainException
871
-     * @throws UnexpectedEntityException
872
-     */
873
-    public function perform_sold_out_status_check()
874
-    {
875
-        // get all tickets
876
-        $tickets = $this->tickets(
877
-            array(
878
-                'default_where_conditions' => 'none',
879
-                'order_by' => array('TKT_qty' => 'ASC'),
880
-            )
881
-        );
882
-        $all_expired = true;
883
-        foreach ($tickets as $ticket) {
884
-            if (! $ticket->is_expired()) {
885
-                $all_expired = false;
886
-                break;
887
-            }
888
-        }
889
-        // if all the tickets are just expired, then don't update the event status to sold out
890
-        if ($all_expired) {
891
-            return true;
892
-        }
893
-        $spaces_remaining = $this->spaces_remaining($tickets);
894
-        if ($spaces_remaining < 1) {
895
-            if ($this->status() !== EEM_Event::post_status_private) {
896
-                $this->set_status(EEM_Event::sold_out);
897
-                $this->save();
898
-            }
899
-            $sold_out = true;
900
-        } else {
901
-            $sold_out = false;
902
-            // was event previously marked as sold out ?
903
-            if ($this->status() === EEM_Event::sold_out) {
904
-                // revert status to previous value, if it was set
905
-                $previous_event_status = $this->get_post_meta('_previous_event_status', true);
906
-                if ($previous_event_status) {
907
-                    $this->set_status($previous_event_status);
908
-                    $this->save();
909
-                }
910
-            }
911
-        }
912
-        do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets);
913
-        return $sold_out;
914
-    }
915
-
916
-
917
-    /**
918
-     * This returns the total remaining spaces for sale on this event.
919
-     *
920
-     * @uses EE_Event::total_available_spaces()
921
-     * @return float|int
922
-     * @throws EE_Error
923
-     * @throws DomainException
924
-     * @throws UnexpectedEntityException
925
-     */
926
-    public function spaces_remaining_for_sale()
927
-    {
928
-        return $this->total_available_spaces(true);
929
-    }
930
-
931
-
932
-    /**
933
-     * This returns the total spaces available for an event
934
-     * while considering all the qtys on the tickets and the reg limits
935
-     * on the datetimes attached to this event.
936
-     *
937
-     * @param   bool $consider_sold Whether to consider any tickets that have already sold in our calculation.
938
-     *                              If this is false, then we return the most tickets that could ever be sold
939
-     *                              for this event with the datetime and tickets setup on the event under optimal
940
-     *                              selling conditions.  Otherwise we return a live calculation of spaces available
941
-     *                              based on tickets sold.  Depending on setup and stage of sales, this
942
-     *                              may appear to equal remaining tickets.  However, the more tickets are
943
-     *                              sold out, the more accurate the "live" total is.
944
-     * @return float|int
945
-     * @throws EE_Error
946
-     * @throws DomainException
947
-     * @throws UnexpectedEntityException
948
-     */
949
-    public function total_available_spaces($consider_sold = false)
950
-    {
951
-        $spaces_available = $consider_sold
952
-            ? $this->getAvailableSpacesCalculator()->spacesRemaining()
953
-            : $this->getAvailableSpacesCalculator()->totalSpacesAvailable();
954
-        return apply_filters(
955
-            'FHEE_EE_Event__total_available_spaces__spaces_available',
956
-            $spaces_available,
957
-            $this,
958
-            $this->getAvailableSpacesCalculator()->getDatetimes(),
959
-            $this->getAvailableSpacesCalculator()->getActiveTickets()
960
-        );
961
-    }
962
-
963
-
964
-    /**
965
-     * Checks if the event is set to sold out
966
-     *
967
-     * @param  bool $actual whether or not to perform calculations to not only figure the
968
-     *                      actual status but also to flip the status if necessary to sold
969
-     *                      out If false, we just check the existing status of the event
970
-     * @return boolean
971
-     * @throws EE_Error
972
-     */
973
-    public function is_sold_out($actual = false)
974
-    {
975
-        if (! $actual) {
976
-            return $this->status() === EEM_Event::sold_out;
977
-        }
978
-        return $this->perform_sold_out_status_check();
979
-    }
980
-
981
-
982
-    /**
983
-     * Checks if the event is marked as postponed
984
-     *
985
-     * @return boolean
986
-     */
987
-    public function is_postponed()
988
-    {
989
-        return $this->status() === EEM_Event::postponed;
990
-    }
991
-
992
-
993
-    /**
994
-     * Checks if the event is marked as cancelled
995
-     *
996
-     * @return boolean
997
-     */
998
-    public function is_cancelled()
999
-    {
1000
-        return $this->status() === EEM_Event::cancelled;
1001
-    }
1002
-
1003
-
1004
-    /**
1005
-     * Get the logical active status in a hierarchical order for all the datetimes.  Note
1006
-     * Basically, we order the datetimes by EVT_start_date.  Then first test on whether the event is published.  If its
1007
-     * NOT published then we test for whether its expired or not.  IF it IS published then we test first on whether an
1008
-     * event has any active dates.  If no active dates then we check for any upcoming dates.  If no upcoming dates then
1009
-     * the event is considered expired.
1010
-     * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published.  Sold Out is a
1011
-     * status set on the EVENT when it is not published and thus is done
1012
-     *
1013
-     * @param bool $reset
1014
-     * @return bool | string - based on EE_Datetime active constants or FALSE if error.
1015
-     * @throws EE_Error
1016
-     */
1017
-    public function get_active_status($reset = false)
1018
-    {
1019
-        // if the active status has already been set, then just use that value (unless we are resetting it)
1020
-        if (! empty($this->_active_status) && ! $reset) {
1021
-            return $this->_active_status;
1022
-        }
1023
-        // first check if event id is present on this object
1024
-        if (! $this->ID()) {
1025
-            return false;
1026
-        }
1027
-        $where_params_for_event = array(array('EVT_ID' => $this->ID()));
1028
-        // if event is published:
1029
-        if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) {
1030
-            // active?
1031
-            if (EEM_Datetime::instance()->get_datetime_count_for_status(
1032
-                EE_Datetime::active,
1033
-                $where_params_for_event
1034
-            ) > 0) {
1035
-                $this->_active_status = EE_Datetime::active;
1036
-            } else {
1037
-                // upcoming?
1038
-                if (EEM_Datetime::instance()->get_datetime_count_for_status(
1039
-                    EE_Datetime::upcoming,
1040
-                    $where_params_for_event
1041
-                ) > 0) {
1042
-                    $this->_active_status = EE_Datetime::upcoming;
1043
-                } else {
1044
-                    // expired?
1045
-                    if (EEM_Datetime::instance()->get_datetime_count_for_status(
1046
-                        EE_Datetime::expired,
1047
-                        $where_params_for_event
1048
-                    ) > 0
1049
-                    ) {
1050
-                        $this->_active_status = EE_Datetime::expired;
1051
-                    } else {
1052
-                        // it would be odd if things make it this far because it basically means there are no datetime's
1053
-                        // attached to the event.  So in this case it will just be considered inactive.
1054
-                        $this->_active_status = EE_Datetime::inactive;
1055
-                    }
1056
-                }
1057
-            }
1058
-        } else {
1059
-            // the event is not published, so let's just set it's active status according to its' post status
1060
-            switch ($this->status()) {
1061
-                case EEM_Event::sold_out:
1062
-                    $this->_active_status = EE_Datetime::sold_out;
1063
-                    break;
1064
-                case EEM_Event::cancelled:
1065
-                    $this->_active_status = EE_Datetime::cancelled;
1066
-                    break;
1067
-                case EEM_Event::postponed:
1068
-                    $this->_active_status = EE_Datetime::postponed;
1069
-                    break;
1070
-                default:
1071
-                    $this->_active_status = EE_Datetime::inactive;
1072
-            }
1073
-        }
1074
-        return $this->_active_status;
1075
-    }
1076
-
1077
-
1078
-    /**
1079
-     *    pretty_active_status
1080
-     *
1081
-     * @access public
1082
-     * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1083
-     * @return mixed void|string
1084
-     * @throws EE_Error
1085
-     */
1086
-    public function pretty_active_status($echo = true)
1087
-    {
1088
-        $active_status = $this->get_active_status();
1089
-        $status = '<span class="ee-status event-active-status-'
1090
-                  . $active_status
1091
-                  . '">'
1092
-                  . EEH_Template::pretty_status($active_status, false, 'sentence')
1093
-                  . '</span>';
1094
-        if ($echo) {
1095
-            echo $status;
1096
-            return '';
1097
-        }
1098
-        return $status;
1099
-    }
1100
-
1101
-
1102
-    /**
1103
-     * @return bool|int
1104
-     * @throws EE_Error
1105
-     */
1106
-    public function get_number_of_tickets_sold()
1107
-    {
1108
-        $tkt_sold = 0;
1109
-        if (! $this->ID()) {
1110
-            return 0;
1111
-        }
1112
-        $datetimes = $this->datetimes();
1113
-        foreach ($datetimes as $datetime) {
1114
-            if ($datetime instanceof EE_Datetime) {
1115
-                $tkt_sold += $datetime->sold();
1116
-            }
1117
-        }
1118
-        return $tkt_sold;
1119
-    }
1120
-
1121
-
1122
-    /**
1123
-     * This just returns a count of all the registrations for this event
1124
-     *
1125
-     * @access  public
1126
-     * @return int
1127
-     * @throws EE_Error
1128
-     */
1129
-    public function get_count_of_all_registrations()
1130
-    {
1131
-        return EEM_Event::instance()->count_related($this, 'Registration');
1132
-    }
1133
-
1134
-
1135
-    /**
1136
-     * This returns the ticket with the earliest start time that is
1137
-     * available for this event (across all datetimes attached to the event)
1138
-     *
1139
-     * @return EE_Base_Class|EE_Ticket|null
1140
-     * @throws EE_Error
1141
-     */
1142
-    public function get_ticket_with_earliest_start_time()
1143
-    {
1144
-        $where['Datetime.EVT_ID'] = $this->ID();
1145
-        $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC'));
1146
-        return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1147
-    }
1148
-
1149
-
1150
-    /**
1151
-     * This returns the ticket with the latest end time that is available
1152
-     * for this event (across all datetimes attached to the event)
1153
-     *
1154
-     * @return EE_Base_Class|EE_Ticket|null
1155
-     * @throws EE_Error
1156
-     */
1157
-    public function get_ticket_with_latest_end_time()
1158
-    {
1159
-        $where['Datetime.EVT_ID'] = $this->ID();
1160
-        $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC'));
1161
-        return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1162
-    }
1163
-
1164
-
1165
-    /**
1166
-     * This returns the number of different ticket types currently on sale for this event.
1167
-     *
1168
-     * @return int
1169
-     * @throws EE_Error
1170
-     */
1171
-    public function countTicketsOnSale()
1172
-    {
1173
-        $where = array(
1174
-            'Datetime.EVT_ID' => $this->ID(),
1175
-            'TKT_start_date'  => array('<', time()),
1176
-            'TKT_end_date'    => array('>', time()),
1177
-        );
1178
-        return EEM_Ticket::instance()->count(array($where));
1179
-    }
1180
-
1181
-
1182
-    /**
1183
-     * This returns whether there are any tickets on sale for this event.
1184
-     *
1185
-     * @return bool true = YES tickets on sale.
1186
-     * @throws EE_Error
1187
-     */
1188
-    public function tickets_on_sale()
1189
-    {
1190
-        return $this->countTicketsOnSale() > 0;
1191
-    }
1192
-
1193
-
1194
-    /**
1195
-     * Gets the URL for viewing this event on the front-end. Overrides parent
1196
-     * to check for an external URL first
1197
-     *
1198
-     * @return string
1199
-     * @throws EE_Error
1200
-     */
1201
-    public function get_permalink()
1202
-    {
1203
-        if ($this->external_url()) {
1204
-            return $this->external_url();
1205
-        }
1206
-        return parent::get_permalink();
1207
-    }
1208
-
1209
-
1210
-    /**
1211
-     * Gets the first term for 'espresso_event_categories' we can find
1212
-     *
1213
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1214
-     * @return EE_Base_Class|EE_Term|null
1215
-     * @throws EE_Error
1216
-     */
1217
-    public function first_event_category($query_params = array())
1218
-    {
1219
-        $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1220
-        $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1221
-        return EEM_Term::instance()->get_one($query_params);
1222
-    }
1223
-
1224
-
1225
-    /**
1226
-     * Gets all terms for 'espresso_event_categories' we can find
1227
-     *
1228
-     * @param array $query_params
1229
-     * @return EE_Base_Class[]|EE_Term[]
1230
-     * @throws EE_Error
1231
-     */
1232
-    public function get_all_event_categories($query_params = array())
1233
-    {
1234
-        $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1235
-        $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1236
-        return EEM_Term::instance()->get_all($query_params);
1237
-    }
1238
-
1239
-
1240
-    /**
1241
-     * Adds a question group to this event
1242
-     *
1243
-     * @param EE_Question_Group|int $question_group_id_or_obj
1244
-     * @param bool                  $for_primary if true, the question group will be added for the primary
1245
-     *                                           registrant, if false will be added for others. default: false
1246
-     * @return EE_Base_Class|EE_Question_Group
1247
-     * @throws EE_Error
1248
-     */
1249
-    public function add_question_group($question_group_id_or_obj, $for_primary = false)
1250
-    {
1251
-        $extra = $for_primary
1252
-            ? array('EQG_primary' => 1)
1253
-            : array();
1254
-        return $this->_add_relation_to($question_group_id_or_obj, 'Question_Group', $extra);
1255
-    }
1256
-
1257
-
1258
-    /**
1259
-     * Removes a question group from the event
1260
-     *
1261
-     * @param EE_Question_Group|int $question_group_id_or_obj
1262
-     * @param bool                  $for_primary if true, the question group will be removed from the primary
1263
-     *                                           registrant, if false will be removed from others. default: false
1264
-     * @return EE_Base_Class|EE_Question_Group
1265
-     * @throws EE_Error
1266
-     */
1267
-    public function remove_question_group($question_group_id_or_obj, $for_primary = false)
1268
-    {
1269
-        $where = $for_primary
1270
-            ? array('EQG_primary' => 1)
1271
-            : array();
1272
-        return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group', $where);
1273
-    }
1274
-
1275
-
1276
-    /**
1277
-     * Gets all the question groups, ordering them by QSG_order ascending
1278
-     *
1279
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1280
-     * @return EE_Base_Class[]|EE_Question_Group[]
1281
-     * @throws EE_Error
1282
-     */
1283
-    public function question_groups($query_params = array())
1284
-    {
1285
-        $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1286
-        return $this->get_many_related('Question_Group', $query_params);
1287
-    }
1288
-
1289
-
1290
-    /**
1291
-     * Implementation for EEI_Has_Icon interface method.
1292
-     *
1293
-     * @see EEI_Visual_Representation for comments
1294
-     * @return string
1295
-     */
1296
-    public function get_icon()
1297
-    {
1298
-        return '<span class="dashicons dashicons-flag"></span>';
1299
-    }
1300
-
1301
-
1302
-    /**
1303
-     * Implementation for EEI_Admin_Links interface method.
1304
-     *
1305
-     * @see EEI_Admin_Links for comments
1306
-     * @return string
1307
-     * @throws EE_Error
1308
-     */
1309
-    public function get_admin_details_link()
1310
-    {
1311
-        return $this->get_admin_edit_link();
1312
-    }
1313
-
1314
-
1315
-    /**
1316
-     * Implementation for EEI_Admin_Links interface method.
1317
-     *
1318
-     * @see EEI_Admin_Links for comments
1319
-     * @return string
1320
-     * @throws EE_Error
1321
-     */
1322
-    public function get_admin_edit_link()
1323
-    {
1324
-        return EEH_URL::add_query_args_and_nonce(
1325
-            array(
1326
-                'page'   => 'espresso_events',
1327
-                'action' => 'edit',
1328
-                'post'   => $this->ID(),
1329
-            ),
1330
-            admin_url('admin.php')
1331
-        );
1332
-    }
1333
-
1334
-
1335
-    /**
1336
-     * Implementation for EEI_Admin_Links interface method.
1337
-     *
1338
-     * @see EEI_Admin_Links for comments
1339
-     * @return string
1340
-     */
1341
-    public function get_admin_settings_link()
1342
-    {
1343
-        return EEH_URL::add_query_args_and_nonce(
1344
-            array(
1345
-                'page'   => 'espresso_events',
1346
-                'action' => 'default_event_settings',
1347
-            ),
1348
-            admin_url('admin.php')
1349
-        );
1350
-    }
1351
-
1352
-
1353
-    /**
1354
-     * Implementation for EEI_Admin_Links interface method.
1355
-     *
1356
-     * @see EEI_Admin_Links for comments
1357
-     * @return string
1358
-     */
1359
-    public function get_admin_overview_link()
1360
-    {
1361
-        return EEH_URL::add_query_args_and_nonce(
1362
-            array(
1363
-                'page'   => 'espresso_events',
1364
-                'action' => 'default',
1365
-            ),
1366
-            admin_url('admin.php')
1367
-        );
1368
-    }
16
+	/**
17
+	 * cached value for the the logical active status for the event
18
+	 *
19
+	 * @see get_active_status()
20
+	 * @var string
21
+	 */
22
+	protected $_active_status = '';
23
+
24
+	/**
25
+	 * This is just used for caching the Primary Datetime for the Event on initial retrieval
26
+	 *
27
+	 * @var EE_Datetime
28
+	 */
29
+	protected $_Primary_Datetime;
30
+
31
+	/**
32
+	 * @var EventSpacesCalculator $available_spaces_calculator
33
+	 */
34
+	protected $available_spaces_calculator;
35
+
36
+
37
+	/**
38
+	 * @param array  $props_n_values          incoming values
39
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
40
+	 *                                        used.)
41
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
42
+	 *                                        date_format and the second value is the time format
43
+	 * @return EE_Event
44
+	 * @throws EE_Error
45
+	 */
46
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
47
+	{
48
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
49
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
50
+	}
51
+
52
+
53
+	/**
54
+	 * @param array  $props_n_values  incoming values from the database
55
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
56
+	 *                                the website will be used.
57
+	 * @return EE_Event
58
+	 * @throws EE_Error
59
+	 */
60
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
61
+	{
62
+		return new self($props_n_values, true, $timezone);
63
+	}
64
+
65
+
66
+	/**
67
+	 * @return EventSpacesCalculator
68
+	 * @throws \EE_Error
69
+	 */
70
+	public function getAvailableSpacesCalculator()
71
+	{
72
+		if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) {
73
+			$this->available_spaces_calculator = new EventSpacesCalculator($this);
74
+		}
75
+		return $this->available_spaces_calculator;
76
+	}
77
+
78
+
79
+	/**
80
+	 * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods
81
+	 *
82
+	 * @param string $field_name
83
+	 * @param mixed  $field_value
84
+	 * @param bool   $use_default
85
+	 * @throws EE_Error
86
+	 */
87
+	public function set($field_name, $field_value, $use_default = false)
88
+	{
89
+		switch ($field_name) {
90
+			case 'status':
91
+				$this->set_status($field_value, $use_default);
92
+				break;
93
+			default:
94
+				parent::set($field_name, $field_value, $use_default);
95
+		}
96
+	}
97
+
98
+
99
+	/**
100
+	 *    set_status
101
+	 * Checks if event status is being changed to SOLD OUT
102
+	 * and updates event meta data with previous event status
103
+	 * so that we can revert things if/when the event is no longer sold out
104
+	 *
105
+	 * @access public
106
+	 * @param string $new_status
107
+	 * @param bool   $use_default
108
+	 * @return void
109
+	 * @throws EE_Error
110
+	 */
111
+	public function set_status($new_status = null, $use_default = false)
112
+	{
113
+		// if nothing is set, and we aren't explicitly wanting to reset the status, then just leave
114
+		if (empty($new_status) && ! $use_default) {
115
+			return;
116
+		}
117
+		// get current Event status
118
+		$old_status = $this->status();
119
+		// if status has changed
120
+		if ($old_status !== $new_status) {
121
+			// TO sold_out
122
+			if ($new_status === EEM_Event::sold_out) {
123
+				// save the previous event status so that we can revert if the event is no longer sold out
124
+				$this->add_post_meta('_previous_event_status', $old_status);
125
+				do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status);
126
+				// OR FROM  sold_out
127
+			} elseif ($old_status === EEM_Event::sold_out) {
128
+				$this->delete_post_meta('_previous_event_status');
129
+				do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status);
130
+			}
131
+			// clear out the active status so that it gets reset the next time it is requested
132
+			$this->_active_status = null;
133
+			// update status
134
+			parent::set('status', $new_status, $use_default);
135
+			do_action('AHEE__EE_Event__set_status__after_update', $this);
136
+			return;
137
+		}
138
+		// even though the old value matches the new value, it's still good to
139
+		// allow the parent set method to have a say
140
+		parent::set('status', $new_status, $use_default);
141
+	}
142
+
143
+
144
+	/**
145
+	 * Gets all the datetimes for this event
146
+	 *
147
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
148
+	 * @return EE_Base_Class[]|EE_Datetime[]
149
+	 * @throws EE_Error
150
+	 */
151
+	public function datetimes($query_params = array())
152
+	{
153
+		return $this->get_many_related('Datetime', $query_params);
154
+	}
155
+
156
+
157
+	/**
158
+	 * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order
159
+	 *
160
+	 * @return EE_Base_Class[]|EE_Datetime[]
161
+	 * @throws EE_Error
162
+	 */
163
+	public function datetimes_in_chronological_order()
164
+	{
165
+		return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC')));
166
+	}
167
+
168
+
169
+	/**
170
+	 * Gets all the datetimes for this event, ordered by the DTT_order on the datetime.
171
+	 * @darren, we should probably UNSET timezone on the EEM_Datetime model
172
+	 * after running our query, so that this timezone isn't set for EVERY query
173
+	 * on EEM_Datetime for the rest of the request, no?
174
+	 *
175
+	 * @param boolean $show_expired whether or not to include expired events
176
+	 * @param boolean $show_deleted whether or not to include deleted events
177
+	 * @param null    $limit
178
+	 * @return EE_Datetime[]
179
+	 * @throws EE_Error
180
+	 */
181
+	public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null)
182
+	{
183
+		return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order(
184
+			$this->ID(),
185
+			$show_expired,
186
+			$show_deleted,
187
+			$limit
188
+		);
189
+	}
190
+
191
+
192
+	/**
193
+	 * Returns one related datetime. Mostly only used by some legacy code.
194
+	 *
195
+	 * @return EE_Base_Class|EE_Datetime
196
+	 * @throws EE_Error
197
+	 */
198
+	public function first_datetime()
199
+	{
200
+		return $this->get_first_related('Datetime');
201
+	}
202
+
203
+
204
+	/**
205
+	 * Returns the 'primary' datetime for the event
206
+	 *
207
+	 * @param bool $try_to_exclude_expired
208
+	 * @param bool $try_to_exclude_deleted
209
+	 * @return EE_Datetime
210
+	 * @throws EE_Error
211
+	 */
212
+	public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
213
+	{
214
+		if (! empty($this->_Primary_Datetime)) {
215
+			return $this->_Primary_Datetime;
216
+		}
217
+		$this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event(
218
+			$this->ID(),
219
+			$try_to_exclude_expired,
220
+			$try_to_exclude_deleted
221
+		);
222
+		return $this->_Primary_Datetime;
223
+	}
224
+
225
+
226
+	/**
227
+	 * Gets all the tickets available for purchase of this event
228
+	 *
229
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
230
+	 * @return EE_Base_Class[]|EE_Ticket[]
231
+	 * @throws EE_Error
232
+	 */
233
+	public function tickets($query_params = array())
234
+	{
235
+		// first get all datetimes
236
+		$datetimes = $this->datetimes_ordered();
237
+		if (! $datetimes) {
238
+			return array();
239
+		}
240
+		$datetime_ids = array();
241
+		foreach ($datetimes as $datetime) {
242
+			$datetime_ids[] = $datetime->ID();
243
+		}
244
+		$where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids));
245
+		// if incoming $query_params has where conditions let's merge but not override existing.
246
+		if (is_array($query_params) && isset($query_params[0])) {
247
+			$where_params = array_merge($query_params[0], $where_params);
248
+			unset($query_params[0]);
249
+		}
250
+		// now add $where_params to $query_params
251
+		$query_params[0] = $where_params;
252
+		return EEM_Ticket::instance()->get_all($query_params);
253
+	}
254
+
255
+
256
+	/**
257
+	 * get all unexpired untrashed tickets
258
+	 *
259
+	 * @return EE_Ticket[]
260
+	 * @throws EE_Error
261
+	 */
262
+	public function active_tickets()
263
+	{
264
+		return $this->tickets(
265
+			array(
266
+				array(
267
+					'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
268
+					'TKT_deleted'  => false,
269
+				),
270
+			)
271
+		);
272
+	}
273
+
274
+
275
+	/**
276
+	 * @return bool
277
+	 * @throws EE_Error
278
+	 */
279
+	public function additional_limit()
280
+	{
281
+		return $this->get('EVT_additional_limit');
282
+	}
283
+
284
+
285
+	/**
286
+	 * @return bool
287
+	 * @throws EE_Error
288
+	 */
289
+	public function allow_overflow()
290
+	{
291
+		return $this->get('EVT_allow_overflow');
292
+	}
293
+
294
+
295
+	/**
296
+	 * @return bool
297
+	 * @throws EE_Error
298
+	 */
299
+	public function created()
300
+	{
301
+		return $this->get('EVT_created');
302
+	}
303
+
304
+
305
+	/**
306
+	 * @return bool
307
+	 * @throws EE_Error
308
+	 */
309
+	public function description()
310
+	{
311
+		return $this->get('EVT_desc');
312
+	}
313
+
314
+
315
+	/**
316
+	 * Runs do_shortcode and wpautop on the description
317
+	 *
318
+	 * @return string of html
319
+	 * @throws EE_Error
320
+	 */
321
+	public function description_filtered()
322
+	{
323
+		return $this->get_pretty('EVT_desc');
324
+	}
325
+
326
+
327
+	/**
328
+	 * @return bool
329
+	 * @throws EE_Error
330
+	 */
331
+	public function display_description()
332
+	{
333
+		return $this->get('EVT_display_desc');
334
+	}
335
+
336
+
337
+	/**
338
+	 * @return bool
339
+	 * @throws EE_Error
340
+	 */
341
+	public function display_ticket_selector()
342
+	{
343
+		return (bool) $this->get('EVT_display_ticket_selector');
344
+	}
345
+
346
+
347
+	/**
348
+	 * @return bool
349
+	 * @throws EE_Error
350
+	 */
351
+	public function external_url()
352
+	{
353
+		return $this->get('EVT_external_URL');
354
+	}
355
+
356
+
357
+	/**
358
+	 * @return bool
359
+	 * @throws EE_Error
360
+	 */
361
+	public function member_only()
362
+	{
363
+		return $this->get('EVT_member_only');
364
+	}
365
+
366
+
367
+	/**
368
+	 * @return bool
369
+	 * @throws EE_Error
370
+	 */
371
+	public function phone()
372
+	{
373
+		return $this->get('EVT_phone');
374
+	}
375
+
376
+
377
+	/**
378
+	 * @return bool
379
+	 * @throws EE_Error
380
+	 */
381
+	public function modified()
382
+	{
383
+		return $this->get('EVT_modified');
384
+	}
385
+
386
+
387
+	/**
388
+	 * @return bool
389
+	 * @throws EE_Error
390
+	 */
391
+	public function name()
392
+	{
393
+		return $this->get('EVT_name');
394
+	}
395
+
396
+
397
+	/**
398
+	 * @return bool
399
+	 * @throws EE_Error
400
+	 */
401
+	public function order()
402
+	{
403
+		return $this->get('EVT_order');
404
+	}
405
+
406
+
407
+	/**
408
+	 * @return bool|string
409
+	 * @throws EE_Error
410
+	 */
411
+	public function default_registration_status()
412
+	{
413
+		$event_default_registration_status = $this->get('EVT_default_registration_status');
414
+		return ! empty($event_default_registration_status)
415
+			? $event_default_registration_status
416
+			: EE_Registry::instance()->CFG->registration->default_STS_ID;
417
+	}
418
+
419
+
420
+	/**
421
+	 * @param int  $num_words
422
+	 * @param null $more
423
+	 * @param bool $not_full_desc
424
+	 * @return bool|string
425
+	 * @throws EE_Error
426
+	 */
427
+	public function short_description($num_words = 55, $more = null, $not_full_desc = false)
428
+	{
429
+		$short_desc = $this->get('EVT_short_desc');
430
+		if (! empty($short_desc) || $not_full_desc) {
431
+			return $short_desc;
432
+		}
433
+		$full_desc = $this->get('EVT_desc');
434
+		return wp_trim_words($full_desc, $num_words, $more);
435
+	}
436
+
437
+
438
+	/**
439
+	 * @return bool
440
+	 * @throws EE_Error
441
+	 */
442
+	public function slug()
443
+	{
444
+		return $this->get('EVT_slug');
445
+	}
446
+
447
+
448
+	/**
449
+	 * @return bool
450
+	 * @throws EE_Error
451
+	 */
452
+	public function timezone_string()
453
+	{
454
+		return $this->get('EVT_timezone_string');
455
+	}
456
+
457
+
458
+	/**
459
+	 * @return bool
460
+	 * @throws EE_Error
461
+	 */
462
+	public function visible_on()
463
+	{
464
+		return $this->get('EVT_visible_on');
465
+	}
466
+
467
+
468
+	/**
469
+	 * @return int
470
+	 * @throws EE_Error
471
+	 */
472
+	public function wp_user()
473
+	{
474
+		return $this->get('EVT_wp_user');
475
+	}
476
+
477
+
478
+	/**
479
+	 * @return bool
480
+	 * @throws EE_Error
481
+	 */
482
+	public function donations()
483
+	{
484
+		return $this->get('EVT_donations');
485
+	}
486
+
487
+
488
+	/**
489
+	 * @param $limit
490
+	 * @throws EE_Error
491
+	 */
492
+	public function set_additional_limit($limit)
493
+	{
494
+		$this->set('EVT_additional_limit', $limit);
495
+	}
496
+
497
+
498
+	/**
499
+	 * @param $created
500
+	 * @throws EE_Error
501
+	 */
502
+	public function set_created($created)
503
+	{
504
+		$this->set('EVT_created', $created);
505
+	}
506
+
507
+
508
+	/**
509
+	 * @param $desc
510
+	 * @throws EE_Error
511
+	 */
512
+	public function set_description($desc)
513
+	{
514
+		$this->set('EVT_desc', $desc);
515
+	}
516
+
517
+
518
+	/**
519
+	 * @param $display_desc
520
+	 * @throws EE_Error
521
+	 */
522
+	public function set_display_description($display_desc)
523
+	{
524
+		$this->set('EVT_display_desc', $display_desc);
525
+	}
526
+
527
+
528
+	/**
529
+	 * @param $display_ticket_selector
530
+	 * @throws EE_Error
531
+	 */
532
+	public function set_display_ticket_selector($display_ticket_selector)
533
+	{
534
+		$this->set('EVT_display_ticket_selector', $display_ticket_selector);
535
+	}
536
+
537
+
538
+	/**
539
+	 * @param $external_url
540
+	 * @throws EE_Error
541
+	 */
542
+	public function set_external_url($external_url)
543
+	{
544
+		$this->set('EVT_external_URL', $external_url);
545
+	}
546
+
547
+
548
+	/**
549
+	 * @param $member_only
550
+	 * @throws EE_Error
551
+	 */
552
+	public function set_member_only($member_only)
553
+	{
554
+		$this->set('EVT_member_only', $member_only);
555
+	}
556
+
557
+
558
+	/**
559
+	 * @param $event_phone
560
+	 * @throws EE_Error
561
+	 */
562
+	public function set_event_phone($event_phone)
563
+	{
564
+		$this->set('EVT_phone', $event_phone);
565
+	}
566
+
567
+
568
+	/**
569
+	 * @param $modified
570
+	 * @throws EE_Error
571
+	 */
572
+	public function set_modified($modified)
573
+	{
574
+		$this->set('EVT_modified', $modified);
575
+	}
576
+
577
+
578
+	/**
579
+	 * @param $name
580
+	 * @throws EE_Error
581
+	 */
582
+	public function set_name($name)
583
+	{
584
+		$this->set('EVT_name', $name);
585
+	}
586
+
587
+
588
+	/**
589
+	 * @param $order
590
+	 * @throws EE_Error
591
+	 */
592
+	public function set_order($order)
593
+	{
594
+		$this->set('EVT_order', $order);
595
+	}
596
+
597
+
598
+	/**
599
+	 * @param $short_desc
600
+	 * @throws EE_Error
601
+	 */
602
+	public function set_short_description($short_desc)
603
+	{
604
+		$this->set('EVT_short_desc', $short_desc);
605
+	}
606
+
607
+
608
+	/**
609
+	 * @param $slug
610
+	 * @throws EE_Error
611
+	 */
612
+	public function set_slug($slug)
613
+	{
614
+		$this->set('EVT_slug', $slug);
615
+	}
616
+
617
+
618
+	/**
619
+	 * @param $timezone_string
620
+	 * @throws EE_Error
621
+	 */
622
+	public function set_timezone_string($timezone_string)
623
+	{
624
+		$this->set('EVT_timezone_string', $timezone_string);
625
+	}
626
+
627
+
628
+	/**
629
+	 * @param $visible_on
630
+	 * @throws EE_Error
631
+	 */
632
+	public function set_visible_on($visible_on)
633
+	{
634
+		$this->set('EVT_visible_on', $visible_on);
635
+	}
636
+
637
+
638
+	/**
639
+	 * @param $wp_user
640
+	 * @throws EE_Error
641
+	 */
642
+	public function set_wp_user($wp_user)
643
+	{
644
+		$this->set('EVT_wp_user', $wp_user);
645
+	}
646
+
647
+
648
+	/**
649
+	 * @param $default_registration_status
650
+	 * @throws EE_Error
651
+	 */
652
+	public function set_default_registration_status($default_registration_status)
653
+	{
654
+		$this->set('EVT_default_registration_status', $default_registration_status);
655
+	}
656
+
657
+
658
+	/**
659
+	 * @param $donations
660
+	 * @throws EE_Error
661
+	 */
662
+	public function set_donations($donations)
663
+	{
664
+		$this->set('EVT_donations', $donations);
665
+	}
666
+
667
+
668
+	/**
669
+	 * Adds a venue to this event
670
+	 *
671
+	 * @param EE_Venue /int $venue_id_or_obj
672
+	 * @return EE_Base_Class|EE_Venue
673
+	 * @throws EE_Error
674
+	 */
675
+	public function add_venue($venue_id_or_obj)
676
+	{
677
+		return $this->_add_relation_to($venue_id_or_obj, 'Venue');
678
+	}
679
+
680
+
681
+	/**
682
+	 * Removes a venue from the event
683
+	 *
684
+	 * @param EE_Venue /int $venue_id_or_obj
685
+	 * @return EE_Base_Class|EE_Venue
686
+	 * @throws EE_Error
687
+	 */
688
+	public function remove_venue($venue_id_or_obj)
689
+	{
690
+		return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
691
+	}
692
+
693
+
694
+	/**
695
+	 * Gets all the venues related ot the event. May provide additional $query_params if desired
696
+	 *
697
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
698
+	 * @return EE_Base_Class[]|EE_Venue[]
699
+	 * @throws EE_Error
700
+	 */
701
+	public function venues($query_params = array())
702
+	{
703
+		return $this->get_many_related('Venue', $query_params);
704
+	}
705
+
706
+
707
+	/**
708
+	 * check if event id is present and if event is published
709
+	 *
710
+	 * @access public
711
+	 * @return boolean true yes, false no
712
+	 * @throws EE_Error
713
+	 */
714
+	private function _has_ID_and_is_published()
715
+	{
716
+		// first check if event id is present and not NULL,
717
+		// then check if this event is published (or any of the equivalent "published" statuses)
718
+		return
719
+			$this->ID() && $this->ID() !== null
720
+			&& (
721
+				$this->status() === 'publish'
722
+				|| $this->status() === EEM_Event::sold_out
723
+				|| $this->status() === EEM_Event::postponed
724
+				|| $this->status() === EEM_Event::cancelled
725
+			);
726
+	}
727
+
728
+
729
+	/**
730
+	 * This simply compares the internal dates with NOW and determines if the event is upcoming or not.
731
+	 *
732
+	 * @access public
733
+	 * @return boolean true yes, false no
734
+	 * @throws EE_Error
735
+	 */
736
+	public function is_upcoming()
737
+	{
738
+		// check if event id is present and if this event is published
739
+		if ($this->is_inactive()) {
740
+			return false;
741
+		}
742
+		// set initial value
743
+		$upcoming = false;
744
+		// next let's get all datetimes and loop through them
745
+		$datetimes = $this->datetimes_in_chronological_order();
746
+		foreach ($datetimes as $datetime) {
747
+			if ($datetime instanceof EE_Datetime) {
748
+				// if this dtt is expired then we continue cause one of the other datetimes might be upcoming.
749
+				if ($datetime->is_expired()) {
750
+					continue;
751
+				}
752
+				// if this dtt is active then we return false.
753
+				if ($datetime->is_active()) {
754
+					return false;
755
+				}
756
+				// otherwise let's check upcoming status
757
+				$upcoming = $datetime->is_upcoming();
758
+			}
759
+		}
760
+		return $upcoming;
761
+	}
762
+
763
+
764
+	/**
765
+	 * @return bool
766
+	 * @throws EE_Error
767
+	 */
768
+	public function is_active()
769
+	{
770
+		// check if event id is present and if this event is published
771
+		if ($this->is_inactive()) {
772
+			return false;
773
+		}
774
+		// set initial value
775
+		$active = false;
776
+		// next let's get all datetimes and loop through them
777
+		$datetimes = $this->datetimes_in_chronological_order();
778
+		foreach ($datetimes as $datetime) {
779
+			if ($datetime instanceof EE_Datetime) {
780
+				// if this dtt is expired then we continue cause one of the other datetimes might be active.
781
+				if ($datetime->is_expired()) {
782
+					continue;
783
+				}
784
+				// if this dtt is upcoming then we return false.
785
+				if ($datetime->is_upcoming()) {
786
+					return false;
787
+				}
788
+				// otherwise let's check active status
789
+				$active = $datetime->is_active();
790
+			}
791
+		}
792
+		return $active;
793
+	}
794
+
795
+
796
+	/**
797
+	 * @return bool
798
+	 * @throws EE_Error
799
+	 */
800
+	public function is_expired()
801
+	{
802
+		// check if event id is present and if this event is published
803
+		if ($this->is_inactive()) {
804
+			return false;
805
+		}
806
+		// set initial value
807
+		$expired = false;
808
+		// first let's get all datetimes and loop through them
809
+		$datetimes = $this->datetimes_in_chronological_order();
810
+		foreach ($datetimes as $datetime) {
811
+			if ($datetime instanceof EE_Datetime) {
812
+				// if this dtt is upcoming or active then we return false.
813
+				if ($datetime->is_upcoming() || $datetime->is_active()) {
814
+					return false;
815
+				}
816
+				// otherwise let's check active status
817
+				$expired = $datetime->is_expired();
818
+			}
819
+		}
820
+		return $expired;
821
+	}
822
+
823
+
824
+	/**
825
+	 * @return bool
826
+	 * @throws EE_Error
827
+	 */
828
+	public function is_inactive()
829
+	{
830
+		// check if event id is present and if this event is published
831
+		if ($this->_has_ID_and_is_published()) {
832
+			return false;
833
+		}
834
+		return true;
835
+	}
836
+
837
+
838
+	/**
839
+	 * calculate spaces remaining based on "saleable" tickets
840
+	 *
841
+	 * @param array $tickets
842
+	 * @param bool  $filtered
843
+	 * @return int|float
844
+	 * @throws EE_Error
845
+	 * @throws DomainException
846
+	 * @throws UnexpectedEntityException
847
+	 */
848
+	public function spaces_remaining($tickets = array(), $filtered = true)
849
+	{
850
+		$this->getAvailableSpacesCalculator()->setActiveTickets($tickets);
851
+		$spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining();
852
+		return $filtered
853
+			? apply_filters(
854
+				'FHEE_EE_Event__spaces_remaining',
855
+				$spaces_remaining,
856
+				$this,
857
+				$tickets
858
+			)
859
+			: $spaces_remaining;
860
+	}
861
+
862
+
863
+	/**
864
+	 *    perform_sold_out_status_check
865
+	 *    checks all of this events's datetime  reg_limit - sold values to determine if ANY datetimes have spaces
866
+	 *    available... if NOT, then the event status will get toggled to 'sold_out'
867
+	 *
868
+	 * @return bool    return the ACTUAL sold out state.
869
+	 * @throws EE_Error
870
+	 * @throws DomainException
871
+	 * @throws UnexpectedEntityException
872
+	 */
873
+	public function perform_sold_out_status_check()
874
+	{
875
+		// get all tickets
876
+		$tickets = $this->tickets(
877
+			array(
878
+				'default_where_conditions' => 'none',
879
+				'order_by' => array('TKT_qty' => 'ASC'),
880
+			)
881
+		);
882
+		$all_expired = true;
883
+		foreach ($tickets as $ticket) {
884
+			if (! $ticket->is_expired()) {
885
+				$all_expired = false;
886
+				break;
887
+			}
888
+		}
889
+		// if all the tickets are just expired, then don't update the event status to sold out
890
+		if ($all_expired) {
891
+			return true;
892
+		}
893
+		$spaces_remaining = $this->spaces_remaining($tickets);
894
+		if ($spaces_remaining < 1) {
895
+			if ($this->status() !== EEM_Event::post_status_private) {
896
+				$this->set_status(EEM_Event::sold_out);
897
+				$this->save();
898
+			}
899
+			$sold_out = true;
900
+		} else {
901
+			$sold_out = false;
902
+			// was event previously marked as sold out ?
903
+			if ($this->status() === EEM_Event::sold_out) {
904
+				// revert status to previous value, if it was set
905
+				$previous_event_status = $this->get_post_meta('_previous_event_status', true);
906
+				if ($previous_event_status) {
907
+					$this->set_status($previous_event_status);
908
+					$this->save();
909
+				}
910
+			}
911
+		}
912
+		do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets);
913
+		return $sold_out;
914
+	}
915
+
916
+
917
+	/**
918
+	 * This returns the total remaining spaces for sale on this event.
919
+	 *
920
+	 * @uses EE_Event::total_available_spaces()
921
+	 * @return float|int
922
+	 * @throws EE_Error
923
+	 * @throws DomainException
924
+	 * @throws UnexpectedEntityException
925
+	 */
926
+	public function spaces_remaining_for_sale()
927
+	{
928
+		return $this->total_available_spaces(true);
929
+	}
930
+
931
+
932
+	/**
933
+	 * This returns the total spaces available for an event
934
+	 * while considering all the qtys on the tickets and the reg limits
935
+	 * on the datetimes attached to this event.
936
+	 *
937
+	 * @param   bool $consider_sold Whether to consider any tickets that have already sold in our calculation.
938
+	 *                              If this is false, then we return the most tickets that could ever be sold
939
+	 *                              for this event with the datetime and tickets setup on the event under optimal
940
+	 *                              selling conditions.  Otherwise we return a live calculation of spaces available
941
+	 *                              based on tickets sold.  Depending on setup and stage of sales, this
942
+	 *                              may appear to equal remaining tickets.  However, the more tickets are
943
+	 *                              sold out, the more accurate the "live" total is.
944
+	 * @return float|int
945
+	 * @throws EE_Error
946
+	 * @throws DomainException
947
+	 * @throws UnexpectedEntityException
948
+	 */
949
+	public function total_available_spaces($consider_sold = false)
950
+	{
951
+		$spaces_available = $consider_sold
952
+			? $this->getAvailableSpacesCalculator()->spacesRemaining()
953
+			: $this->getAvailableSpacesCalculator()->totalSpacesAvailable();
954
+		return apply_filters(
955
+			'FHEE_EE_Event__total_available_spaces__spaces_available',
956
+			$spaces_available,
957
+			$this,
958
+			$this->getAvailableSpacesCalculator()->getDatetimes(),
959
+			$this->getAvailableSpacesCalculator()->getActiveTickets()
960
+		);
961
+	}
962
+
963
+
964
+	/**
965
+	 * Checks if the event is set to sold out
966
+	 *
967
+	 * @param  bool $actual whether or not to perform calculations to not only figure the
968
+	 *                      actual status but also to flip the status if necessary to sold
969
+	 *                      out If false, we just check the existing status of the event
970
+	 * @return boolean
971
+	 * @throws EE_Error
972
+	 */
973
+	public function is_sold_out($actual = false)
974
+	{
975
+		if (! $actual) {
976
+			return $this->status() === EEM_Event::sold_out;
977
+		}
978
+		return $this->perform_sold_out_status_check();
979
+	}
980
+
981
+
982
+	/**
983
+	 * Checks if the event is marked as postponed
984
+	 *
985
+	 * @return boolean
986
+	 */
987
+	public function is_postponed()
988
+	{
989
+		return $this->status() === EEM_Event::postponed;
990
+	}
991
+
992
+
993
+	/**
994
+	 * Checks if the event is marked as cancelled
995
+	 *
996
+	 * @return boolean
997
+	 */
998
+	public function is_cancelled()
999
+	{
1000
+		return $this->status() === EEM_Event::cancelled;
1001
+	}
1002
+
1003
+
1004
+	/**
1005
+	 * Get the logical active status in a hierarchical order for all the datetimes.  Note
1006
+	 * Basically, we order the datetimes by EVT_start_date.  Then first test on whether the event is published.  If its
1007
+	 * NOT published then we test for whether its expired or not.  IF it IS published then we test first on whether an
1008
+	 * event has any active dates.  If no active dates then we check for any upcoming dates.  If no upcoming dates then
1009
+	 * the event is considered expired.
1010
+	 * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published.  Sold Out is a
1011
+	 * status set on the EVENT when it is not published and thus is done
1012
+	 *
1013
+	 * @param bool $reset
1014
+	 * @return bool | string - based on EE_Datetime active constants or FALSE if error.
1015
+	 * @throws EE_Error
1016
+	 */
1017
+	public function get_active_status($reset = false)
1018
+	{
1019
+		// if the active status has already been set, then just use that value (unless we are resetting it)
1020
+		if (! empty($this->_active_status) && ! $reset) {
1021
+			return $this->_active_status;
1022
+		}
1023
+		// first check if event id is present on this object
1024
+		if (! $this->ID()) {
1025
+			return false;
1026
+		}
1027
+		$where_params_for_event = array(array('EVT_ID' => $this->ID()));
1028
+		// if event is published:
1029
+		if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) {
1030
+			// active?
1031
+			if (EEM_Datetime::instance()->get_datetime_count_for_status(
1032
+				EE_Datetime::active,
1033
+				$where_params_for_event
1034
+			) > 0) {
1035
+				$this->_active_status = EE_Datetime::active;
1036
+			} else {
1037
+				// upcoming?
1038
+				if (EEM_Datetime::instance()->get_datetime_count_for_status(
1039
+					EE_Datetime::upcoming,
1040
+					$where_params_for_event
1041
+				) > 0) {
1042
+					$this->_active_status = EE_Datetime::upcoming;
1043
+				} else {
1044
+					// expired?
1045
+					if (EEM_Datetime::instance()->get_datetime_count_for_status(
1046
+						EE_Datetime::expired,
1047
+						$where_params_for_event
1048
+					) > 0
1049
+					) {
1050
+						$this->_active_status = EE_Datetime::expired;
1051
+					} else {
1052
+						// it would be odd if things make it this far because it basically means there are no datetime's
1053
+						// attached to the event.  So in this case it will just be considered inactive.
1054
+						$this->_active_status = EE_Datetime::inactive;
1055
+					}
1056
+				}
1057
+			}
1058
+		} else {
1059
+			// the event is not published, so let's just set it's active status according to its' post status
1060
+			switch ($this->status()) {
1061
+				case EEM_Event::sold_out:
1062
+					$this->_active_status = EE_Datetime::sold_out;
1063
+					break;
1064
+				case EEM_Event::cancelled:
1065
+					$this->_active_status = EE_Datetime::cancelled;
1066
+					break;
1067
+				case EEM_Event::postponed:
1068
+					$this->_active_status = EE_Datetime::postponed;
1069
+					break;
1070
+				default:
1071
+					$this->_active_status = EE_Datetime::inactive;
1072
+			}
1073
+		}
1074
+		return $this->_active_status;
1075
+	}
1076
+
1077
+
1078
+	/**
1079
+	 *    pretty_active_status
1080
+	 *
1081
+	 * @access public
1082
+	 * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1083
+	 * @return mixed void|string
1084
+	 * @throws EE_Error
1085
+	 */
1086
+	public function pretty_active_status($echo = true)
1087
+	{
1088
+		$active_status = $this->get_active_status();
1089
+		$status = '<span class="ee-status event-active-status-'
1090
+				  . $active_status
1091
+				  . '">'
1092
+				  . EEH_Template::pretty_status($active_status, false, 'sentence')
1093
+				  . '</span>';
1094
+		if ($echo) {
1095
+			echo $status;
1096
+			return '';
1097
+		}
1098
+		return $status;
1099
+	}
1100
+
1101
+
1102
+	/**
1103
+	 * @return bool|int
1104
+	 * @throws EE_Error
1105
+	 */
1106
+	public function get_number_of_tickets_sold()
1107
+	{
1108
+		$tkt_sold = 0;
1109
+		if (! $this->ID()) {
1110
+			return 0;
1111
+		}
1112
+		$datetimes = $this->datetimes();
1113
+		foreach ($datetimes as $datetime) {
1114
+			if ($datetime instanceof EE_Datetime) {
1115
+				$tkt_sold += $datetime->sold();
1116
+			}
1117
+		}
1118
+		return $tkt_sold;
1119
+	}
1120
+
1121
+
1122
+	/**
1123
+	 * This just returns a count of all the registrations for this event
1124
+	 *
1125
+	 * @access  public
1126
+	 * @return int
1127
+	 * @throws EE_Error
1128
+	 */
1129
+	public function get_count_of_all_registrations()
1130
+	{
1131
+		return EEM_Event::instance()->count_related($this, 'Registration');
1132
+	}
1133
+
1134
+
1135
+	/**
1136
+	 * This returns the ticket with the earliest start time that is
1137
+	 * available for this event (across all datetimes attached to the event)
1138
+	 *
1139
+	 * @return EE_Base_Class|EE_Ticket|null
1140
+	 * @throws EE_Error
1141
+	 */
1142
+	public function get_ticket_with_earliest_start_time()
1143
+	{
1144
+		$where['Datetime.EVT_ID'] = $this->ID();
1145
+		$query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC'));
1146
+		return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1147
+	}
1148
+
1149
+
1150
+	/**
1151
+	 * This returns the ticket with the latest end time that is available
1152
+	 * for this event (across all datetimes attached to the event)
1153
+	 *
1154
+	 * @return EE_Base_Class|EE_Ticket|null
1155
+	 * @throws EE_Error
1156
+	 */
1157
+	public function get_ticket_with_latest_end_time()
1158
+	{
1159
+		$where['Datetime.EVT_ID'] = $this->ID();
1160
+		$query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC'));
1161
+		return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1162
+	}
1163
+
1164
+
1165
+	/**
1166
+	 * This returns the number of different ticket types currently on sale for this event.
1167
+	 *
1168
+	 * @return int
1169
+	 * @throws EE_Error
1170
+	 */
1171
+	public function countTicketsOnSale()
1172
+	{
1173
+		$where = array(
1174
+			'Datetime.EVT_ID' => $this->ID(),
1175
+			'TKT_start_date'  => array('<', time()),
1176
+			'TKT_end_date'    => array('>', time()),
1177
+		);
1178
+		return EEM_Ticket::instance()->count(array($where));
1179
+	}
1180
+
1181
+
1182
+	/**
1183
+	 * This returns whether there are any tickets on sale for this event.
1184
+	 *
1185
+	 * @return bool true = YES tickets on sale.
1186
+	 * @throws EE_Error
1187
+	 */
1188
+	public function tickets_on_sale()
1189
+	{
1190
+		return $this->countTicketsOnSale() > 0;
1191
+	}
1192
+
1193
+
1194
+	/**
1195
+	 * Gets the URL for viewing this event on the front-end. Overrides parent
1196
+	 * to check for an external URL first
1197
+	 *
1198
+	 * @return string
1199
+	 * @throws EE_Error
1200
+	 */
1201
+	public function get_permalink()
1202
+	{
1203
+		if ($this->external_url()) {
1204
+			return $this->external_url();
1205
+		}
1206
+		return parent::get_permalink();
1207
+	}
1208
+
1209
+
1210
+	/**
1211
+	 * Gets the first term for 'espresso_event_categories' we can find
1212
+	 *
1213
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1214
+	 * @return EE_Base_Class|EE_Term|null
1215
+	 * @throws EE_Error
1216
+	 */
1217
+	public function first_event_category($query_params = array())
1218
+	{
1219
+		$query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1220
+		$query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1221
+		return EEM_Term::instance()->get_one($query_params);
1222
+	}
1223
+
1224
+
1225
+	/**
1226
+	 * Gets all terms for 'espresso_event_categories' we can find
1227
+	 *
1228
+	 * @param array $query_params
1229
+	 * @return EE_Base_Class[]|EE_Term[]
1230
+	 * @throws EE_Error
1231
+	 */
1232
+	public function get_all_event_categories($query_params = array())
1233
+	{
1234
+		$query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1235
+		$query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1236
+		return EEM_Term::instance()->get_all($query_params);
1237
+	}
1238
+
1239
+
1240
+	/**
1241
+	 * Adds a question group to this event
1242
+	 *
1243
+	 * @param EE_Question_Group|int $question_group_id_or_obj
1244
+	 * @param bool                  $for_primary if true, the question group will be added for the primary
1245
+	 *                                           registrant, if false will be added for others. default: false
1246
+	 * @return EE_Base_Class|EE_Question_Group
1247
+	 * @throws EE_Error
1248
+	 */
1249
+	public function add_question_group($question_group_id_or_obj, $for_primary = false)
1250
+	{
1251
+		$extra = $for_primary
1252
+			? array('EQG_primary' => 1)
1253
+			: array();
1254
+		return $this->_add_relation_to($question_group_id_or_obj, 'Question_Group', $extra);
1255
+	}
1256
+
1257
+
1258
+	/**
1259
+	 * Removes a question group from the event
1260
+	 *
1261
+	 * @param EE_Question_Group|int $question_group_id_or_obj
1262
+	 * @param bool                  $for_primary if true, the question group will be removed from the primary
1263
+	 *                                           registrant, if false will be removed from others. default: false
1264
+	 * @return EE_Base_Class|EE_Question_Group
1265
+	 * @throws EE_Error
1266
+	 */
1267
+	public function remove_question_group($question_group_id_or_obj, $for_primary = false)
1268
+	{
1269
+		$where = $for_primary
1270
+			? array('EQG_primary' => 1)
1271
+			: array();
1272
+		return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group', $where);
1273
+	}
1274
+
1275
+
1276
+	/**
1277
+	 * Gets all the question groups, ordering them by QSG_order ascending
1278
+	 *
1279
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1280
+	 * @return EE_Base_Class[]|EE_Question_Group[]
1281
+	 * @throws EE_Error
1282
+	 */
1283
+	public function question_groups($query_params = array())
1284
+	{
1285
+		$query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1286
+		return $this->get_many_related('Question_Group', $query_params);
1287
+	}
1288
+
1289
+
1290
+	/**
1291
+	 * Implementation for EEI_Has_Icon interface method.
1292
+	 *
1293
+	 * @see EEI_Visual_Representation for comments
1294
+	 * @return string
1295
+	 */
1296
+	public function get_icon()
1297
+	{
1298
+		return '<span class="dashicons dashicons-flag"></span>';
1299
+	}
1300
+
1301
+
1302
+	/**
1303
+	 * Implementation for EEI_Admin_Links interface method.
1304
+	 *
1305
+	 * @see EEI_Admin_Links for comments
1306
+	 * @return string
1307
+	 * @throws EE_Error
1308
+	 */
1309
+	public function get_admin_details_link()
1310
+	{
1311
+		return $this->get_admin_edit_link();
1312
+	}
1313
+
1314
+
1315
+	/**
1316
+	 * Implementation for EEI_Admin_Links interface method.
1317
+	 *
1318
+	 * @see EEI_Admin_Links for comments
1319
+	 * @return string
1320
+	 * @throws EE_Error
1321
+	 */
1322
+	public function get_admin_edit_link()
1323
+	{
1324
+		return EEH_URL::add_query_args_and_nonce(
1325
+			array(
1326
+				'page'   => 'espresso_events',
1327
+				'action' => 'edit',
1328
+				'post'   => $this->ID(),
1329
+			),
1330
+			admin_url('admin.php')
1331
+		);
1332
+	}
1333
+
1334
+
1335
+	/**
1336
+	 * Implementation for EEI_Admin_Links interface method.
1337
+	 *
1338
+	 * @see EEI_Admin_Links for comments
1339
+	 * @return string
1340
+	 */
1341
+	public function get_admin_settings_link()
1342
+	{
1343
+		return EEH_URL::add_query_args_and_nonce(
1344
+			array(
1345
+				'page'   => 'espresso_events',
1346
+				'action' => 'default_event_settings',
1347
+			),
1348
+			admin_url('admin.php')
1349
+		);
1350
+	}
1351
+
1352
+
1353
+	/**
1354
+	 * Implementation for EEI_Admin_Links interface method.
1355
+	 *
1356
+	 * @see EEI_Admin_Links for comments
1357
+	 * @return string
1358
+	 */
1359
+	public function get_admin_overview_link()
1360
+	{
1361
+		return EEH_URL::add_query_args_and_nonce(
1362
+			array(
1363
+				'page'   => 'espresso_events',
1364
+				'action' => 'default',
1365
+			),
1366
+			admin_url('admin.php')
1367
+		);
1368
+	}
1369 1369
 }
Please login to merge, or discard this patch.
caffeinated/payment_methods/Aim/EEG_Aim.gateway.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
     /**
363 363
      * Posts the request to AuthorizeNet & returns response.
364 364
      *
365
-     * @param $payment
365
+     * @param EEI_Payment $payment
366 366
      * @return \EE_AuthorizeNetAIM_Response
367 367
      */
368 368
     private function _sendRequest($payment)
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
     /**
452 452
      * Removes characters Authorize.net doesn't handle well.
453 453
      * @since 4.9.82.p
454
-     * @param $text
454
+     * @param string $text
455 455
      * @return string
456 456
      */
457 457
     private function prepareStringForAuthnet($text)
Please login to merge, or discard this patch.
Indentation   +620 added lines, -620 removed lines patch added patch discarded remove patch
@@ -26,442 +26,442 @@  discard block
 block discarded – undo
26 26
 class EEG_Aim extends EE_Onsite_Gateway
27 27
 {
28 28
 
29
-    const LIVE_URL    = 'https://secure2.authorize.net/gateway/transact.dll'; // Authnet URL
30
-
31
-    const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll';
32
-
33
-    protected $_login_id;
34
-
35
-    protected $_transaction_key;
36
-
37
-    protected $_server;
38
-
39
-    protected $_currencies_supported = array(
40
-        'AUD',
41
-        'USD',
42
-        'CAD',
43
-        'EUR',
44
-        'GBP',
45
-        'NZD',
46
-    );
47
-
48
-    /**
49
-     * Whether to send test transactions (even to live site)
50
-     *
51
-     * @var boolean
52
-     */
53
-    protected $_test_transactions;
54
-
55
-    private $VERIFY_PEER = false;
56
-
57
-    private $_x_post_fields = array(
58
-        "version"        => "3.1",
59
-        "delim_char"     => ",",
60
-        "delim_data"     => "TRUE",
61
-        "relay_response" => "FALSE",
62
-        "encap_char"     => "|",
63
-    );
64
-
65
-    private $_additional_line_items = array();
66
-
67
-    /**
68
-     * A list of all fields in the AIM API.
69
-     * Used to warn user if they try to set a field not offered in the API.
70
-     */
71
-    private $_all_aim_fields = array(
72
-        "address",
73
-        "allow_partial_auth",
74
-        "amount",
75
-        "auth_code",
76
-        "authentication_indicator",
77
-        "bank_aba_code",
78
-        "bank_acct_name",
79
-        "bank_acct_num",
80
-        "bank_acct_type",
81
-        "bank_check_number",
82
-        "bank_name",
83
-        "card_code",
84
-        "card_num",
85
-        "cardholder_authentication_value",
86
-        "city",
87
-        "company",
88
-        "country",
89
-        "cust_id",
90
-        "customer_ip",
91
-        "delim_char",
92
-        "delim_data",
93
-        "description",
94
-        "duplicate_window",
95
-        "duty",
96
-        "echeck_type",
97
-        "email",
98
-        "email_customer",
99
-        "encap_char",
100
-        "exp_date",
101
-        "fax",
102
-        "first_name",
103
-        "footer_email_receipt",
104
-        "freight",
105
-        "header_email_receipt",
106
-        "invoice_num",
107
-        "last_name",
108
-        "line_item",
109
-        "login",
110
-        "method",
111
-        "phone",
112
-        "po_num",
113
-        "recurring_billing",
114
-        "relay_response",
115
-        "ship_to_address",
116
-        "ship_to_city",
117
-        "ship_to_company",
118
-        "ship_to_country",
119
-        "ship_to_first_name",
120
-        "ship_to_last_name",
121
-        "ship_to_state",
122
-        "ship_to_zip",
123
-        "split_tender_id",
124
-        "state",
125
-        "tax",
126
-        "tax_exempt",
127
-        "test_request",
128
-        "tran_key",
129
-        "trans_id",
130
-        "type",
131
-        "version",
132
-        "zip",
133
-        "solution_id",
134
-        "currency_code"
135
-    );
136
-
137
-
138
-    /**
139
-     * Gets the URL where the request should go. This is filterable
140
-     *
141
-     * @return string
142
-     */
143
-    protected function _get_server_url()
144
-    {
145
-        return apply_filters(
146
-            'FHEE__EEG_Aim___get_server_url',
147
-            $this->_debug_mode ? self::SANDBOX_URL : self::LIVE_URL,
148
-            $this
149
-        );
150
-    }
151
-
152
-
153
-    /**
154
-     * TEMPORARY CALLBACK! Do not use
155
-     * Callback which filters the server url. This is added so site admins can revert to using
156
-     * the old AIM server in case Akamai service breaks their integration.
157
-     * Using Akamai will, however, be mandatory on June 30th 2016 Authorize.net
158
-     * (see http://www.authorize.net/support/akamaifaqs/#firewall?utm_campaign=April%202016%20Technical%20Updates%20for%20Merchants.html&utm_medium=email&utm_source=Eloqua&elqTrackId=46103bdc375c411a979c2f658fc99074&elq=7026706360154fee9b6d588b27d8eb6a&elqaid=506&elqat=1&elqCampaignId=343)
159
-     * Once that happens, this will be obsolete and WILL BE REMOVED.
160
-     *
161
-     * @param string $url
162
-     * @param EEG_Aim $gateway_object
163
-     * @return string
164
-     */
165
-    public function possibly_use_deprecated_aim_server($url, EEG_Aim $gateway_object)
166
-    {
167
-        if ($gateway_object->_server === 'authorize.net' && ! $gateway_object->_debug_mode) {
168
-            return 'https://secure.authorize.net/gateway/transact.dll';
169
-        } else {
170
-            return $url;
171
-        }
172
-    }
173
-
174
-
175
-    /**
176
-     * Asks the gateway to do whatever it does to process the payment. Onsite gateways will
177
-     * usually send a request directly to the payment provider and update the payment's status based on that;
178
-     * whereas offsite gateways will usually just update the payment with the URL and query parameters to use
179
-     * for sending the request via http_remote_request()
180
-     *
181
-     * @param EEI_Payment $payment
182
-     * @param array $billing_info {
183
-     *  @type $credit_card string
184
-     *  @type $cvv string
185
-     *  @type $exp_month string
186
-     *  @type $exp_year string
187
-     *  @see parent::do_direct_payment
188
-     * }
189
-     * @return EEI_Payment updated
190
-     */
191
-    public function do_direct_payment($payment, $billing_info = null)
192
-    {
193
-        add_filter('FHEE__EEG_Aim___get_server_url', array($this, 'possibly_use_deprecated_aim_server'), 10, 2);
194
-        // Enable test mode if needed
195
-        // 4007000000027  <-- test successful visa
196
-        // 4222222222222  <-- test failure card number
197
-
198
-        $item_num = 1;
199
-        $transaction = $payment->transaction();
200
-        $gateway_formatter = $this->_get_gateway_formatter();
201
-        $order_description = $this->prepareStringForAuthnet($gateway_formatter->formatOrderDescription($payment));
202
-        $primary_registrant = $transaction->primary_registration();
203
-        // if we're are charging for the full amount, show the normal line items
204
-        // and the itemized total adds up properly
205
-        if ($this->_can_easily_itemize_transaction_for($payment)) {
206
-            $total_line_item = $transaction->total_line_item();
207
-            foreach ($total_line_item->get_items() as $line_item) {
208
-                if ($line_item->quantity() == 0) {
209
-                    continue;
210
-                }
211
-                $this->addLineItem(
212
-                    $item_num++,
213
-                    $gateway_formatter->formatLineItemName($line_item, $payment),
214
-                    $gateway_formatter->formatLineItemDesc($line_item, $payment),
215
-                    $line_item->quantity(),
216
-                    $line_item->unit_price(),
217
-                    'N'
218
-                );
219
-                $order_description .= $this->prepareStringForAuthnet($line_item->desc()) . ', ';
220
-            }
221
-            foreach ($total_line_item->tax_descendants() as $tax_line_item) {
222
-                $this->addLineItem(
223
-                    $item_num++,
224
-                    $tax_line_item->name(),
225
-                    $tax_line_item->desc(),
226
-                    1,
227
-                    $tax_line_item->total(),
228
-                    'N'
229
-                );
230
-            }
231
-        }
232
-
233
-        // start transaction
234
-        // if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id
235
-        $partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363';
236
-        $this->setField('solution_id', $partner_id);
237
-        $this->setField('amount', $gateway_formatter->formatCurrency($payment->amount()));
238
-        $this->setField('description', substr(rtrim($order_description, ', '), 0, 255));
239
-        $this->_set_sensitive_billing_data($billing_info);
240
-        $this->setField('first_name', $billing_info['first_name']);
241
-        $this->setField('last_name', $billing_info['last_name']);
242
-        $this->setField('email', $billing_info['email']);
243
-        $this->setField('company', $billing_info['company']);
244
-        $this->setField('address', $billing_info['address'].' '.$billing_info['address2']);
245
-        $this->setField('city', $billing_info['city']);
246
-        $this->setField('state', $billing_info['state']);
247
-        $this->setField('country', $billing_info['country']);
248
-        $this->setField('zip', $billing_info['zip']);
249
-        $this->setField('fax', $billing_info['fax']);
250
-        $this->setField('cust_id', $primary_registrant->ID());
251
-        $this->setField('phone', $billing_info['phone']);
252
-        $currency_config = LoaderFactory::getLoader()->load('EE_Currency_Config');
253
-        $this->setField('currency_code', $currency_config->code);
254
-        // invoice_num would be nice to have it be unique per SPCO page-load, that way if users
255
-        // press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page
256
-        // in which case, we need to generate teh invoice num per request right here...
257
-        $this->setField('invoice_num', wp_generate_password(12, false));// $billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']);
258
-        // tell AIM that any duplicates sent in the next 5 minutes are to be ignored
259
-        $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS);
260
-
261
-        if ($this->_test_transactions) {
262
-            $this->test_request = "true";
263
-        }
264
-
265
-        // Capture response
266
-        $this->type = "AUTH_CAPTURE";
267
-        $response = $this->_sendRequest($payment);
268
-        if (! empty($response)) {
269
-            if ($response->error_message) {
270
-                $payment->set_status($this->_pay_model->failed_status());
271
-                $payment->set_gateway_response($response->error_message);
272
-            } else {
273
-                $payment_status = $response->approved
274
-                    ? $this->_pay_model->approved_status()
275
-                    : $this->_pay_model->declined_status();
276
-                $payment->set_status($payment_status);
277
-                // make sure we interpret the AMT as a float, not an international string (where periods are thousand separators)
278
-                $payment->set_amount((float) $response->amount);
279
-                $payment->set_gateway_response(
280
-                    sprintf(
281
-                        esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'),
282
-                        $response->response_reason_text,
283
-                        $response->response_reason_code
284
-                    )
285
-                );
286
-                if ($this->_debug_mode) {
287
-                    $txn_id = $response->invoice_number;
288
-                } else {
289
-                    $txn_id = $response->transaction_id;
290
-                }
291
-                $payment->set_txn_id_chq_nmbr($txn_id);
292
-            }
293
-            $payment->set_extra_accntng($primary_registrant->reg_code());
294
-            $payment->set_details(print_r($response, true));
295
-        } else {
296
-            $payment->set_status($this->_pay_model->failed_status());
297
-            $payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso'));
298
-            $payment->set_details(print_r($response, true));
299
-        }
300
-        return $payment;
301
-    }
302
-
303
-
304
-    /**
305
-     * Sets billing data for the upcoming request to AIM that is considered sensitive;
306
-     * also this method can be overridden by children classes to easily change
307
-     * what billing data gets sent
308
-     *
309
-     * @param array $billing_info
310
-     */
311
-    protected function _set_sensitive_billing_data($billing_info)
312
-    {
313
-        $this->setField('card_num', $billing_info['credit_card']);
314
-        $this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']);
315
-        $this->setField('card_code', $billing_info['cvv']);
316
-    }
317
-
318
-
319
-    /**
320
-     * Add a line item.
321
-     *
322
-     * @param string $item_id
323
-     * @param string $item_name
324
-     * @param string $item_description
325
-     * @param string $item_quantity
326
-     * @param string $item_unit_price
327
-     * @param string $item_taxable
328
-     */
329
-    public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable)
330
-    {
331
-        $args = array(
332
-            substr($item_id, 0, 31),
333
-            substr($this->prepareStringForAuthnet($item_name), 0, 31),
334
-            substr($this->prepareStringForAuthnet($item_description), 0, 255),
335
-            number_format(abs($item_quantity), 2, '.', ''),
336
-            number_format(abs($item_unit_price), 2, '.', ''),
337
-            $item_taxable === 'N' ? 'N' : 'Y'
338
-        );
339
-        $this->_additional_line_items[] = implode('<|>', $args);
340
-    }
341
-
342
-
343
-    /**
344
-     * Set an individual name/value pair. This will append x_ to the name
345
-     * before posting.
346
-     *
347
-     * @param string $name
348
-     * @param string $value
349
-     * @throws AuthorizeNetException
350
-     */
351
-    protected function setField($name, $value)
352
-    {
353
-        if (in_array($name, $this->_all_aim_fields)) {
354
-            $this->_x_post_fields[ $name ] = $value;
355
-        } else {
356
-            throw new AuthorizeNetException("Error: no field $name exists in the AIM API.
29
+	const LIVE_URL    = 'https://secure2.authorize.net/gateway/transact.dll'; // Authnet URL
30
+
31
+	const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll';
32
+
33
+	protected $_login_id;
34
+
35
+	protected $_transaction_key;
36
+
37
+	protected $_server;
38
+
39
+	protected $_currencies_supported = array(
40
+		'AUD',
41
+		'USD',
42
+		'CAD',
43
+		'EUR',
44
+		'GBP',
45
+		'NZD',
46
+	);
47
+
48
+	/**
49
+	 * Whether to send test transactions (even to live site)
50
+	 *
51
+	 * @var boolean
52
+	 */
53
+	protected $_test_transactions;
54
+
55
+	private $VERIFY_PEER = false;
56
+
57
+	private $_x_post_fields = array(
58
+		"version"        => "3.1",
59
+		"delim_char"     => ",",
60
+		"delim_data"     => "TRUE",
61
+		"relay_response" => "FALSE",
62
+		"encap_char"     => "|",
63
+	);
64
+
65
+	private $_additional_line_items = array();
66
+
67
+	/**
68
+	 * A list of all fields in the AIM API.
69
+	 * Used to warn user if they try to set a field not offered in the API.
70
+	 */
71
+	private $_all_aim_fields = array(
72
+		"address",
73
+		"allow_partial_auth",
74
+		"amount",
75
+		"auth_code",
76
+		"authentication_indicator",
77
+		"bank_aba_code",
78
+		"bank_acct_name",
79
+		"bank_acct_num",
80
+		"bank_acct_type",
81
+		"bank_check_number",
82
+		"bank_name",
83
+		"card_code",
84
+		"card_num",
85
+		"cardholder_authentication_value",
86
+		"city",
87
+		"company",
88
+		"country",
89
+		"cust_id",
90
+		"customer_ip",
91
+		"delim_char",
92
+		"delim_data",
93
+		"description",
94
+		"duplicate_window",
95
+		"duty",
96
+		"echeck_type",
97
+		"email",
98
+		"email_customer",
99
+		"encap_char",
100
+		"exp_date",
101
+		"fax",
102
+		"first_name",
103
+		"footer_email_receipt",
104
+		"freight",
105
+		"header_email_receipt",
106
+		"invoice_num",
107
+		"last_name",
108
+		"line_item",
109
+		"login",
110
+		"method",
111
+		"phone",
112
+		"po_num",
113
+		"recurring_billing",
114
+		"relay_response",
115
+		"ship_to_address",
116
+		"ship_to_city",
117
+		"ship_to_company",
118
+		"ship_to_country",
119
+		"ship_to_first_name",
120
+		"ship_to_last_name",
121
+		"ship_to_state",
122
+		"ship_to_zip",
123
+		"split_tender_id",
124
+		"state",
125
+		"tax",
126
+		"tax_exempt",
127
+		"test_request",
128
+		"tran_key",
129
+		"trans_id",
130
+		"type",
131
+		"version",
132
+		"zip",
133
+		"solution_id",
134
+		"currency_code"
135
+	);
136
+
137
+
138
+	/**
139
+	 * Gets the URL where the request should go. This is filterable
140
+	 *
141
+	 * @return string
142
+	 */
143
+	protected function _get_server_url()
144
+	{
145
+		return apply_filters(
146
+			'FHEE__EEG_Aim___get_server_url',
147
+			$this->_debug_mode ? self::SANDBOX_URL : self::LIVE_URL,
148
+			$this
149
+		);
150
+	}
151
+
152
+
153
+	/**
154
+	 * TEMPORARY CALLBACK! Do not use
155
+	 * Callback which filters the server url. This is added so site admins can revert to using
156
+	 * the old AIM server in case Akamai service breaks their integration.
157
+	 * Using Akamai will, however, be mandatory on June 30th 2016 Authorize.net
158
+	 * (see http://www.authorize.net/support/akamaifaqs/#firewall?utm_campaign=April%202016%20Technical%20Updates%20for%20Merchants.html&utm_medium=email&utm_source=Eloqua&elqTrackId=46103bdc375c411a979c2f658fc99074&elq=7026706360154fee9b6d588b27d8eb6a&elqaid=506&elqat=1&elqCampaignId=343)
159
+	 * Once that happens, this will be obsolete and WILL BE REMOVED.
160
+	 *
161
+	 * @param string $url
162
+	 * @param EEG_Aim $gateway_object
163
+	 * @return string
164
+	 */
165
+	public function possibly_use_deprecated_aim_server($url, EEG_Aim $gateway_object)
166
+	{
167
+		if ($gateway_object->_server === 'authorize.net' && ! $gateway_object->_debug_mode) {
168
+			return 'https://secure.authorize.net/gateway/transact.dll';
169
+		} else {
170
+			return $url;
171
+		}
172
+	}
173
+
174
+
175
+	/**
176
+	 * Asks the gateway to do whatever it does to process the payment. Onsite gateways will
177
+	 * usually send a request directly to the payment provider and update the payment's status based on that;
178
+	 * whereas offsite gateways will usually just update the payment with the URL and query parameters to use
179
+	 * for sending the request via http_remote_request()
180
+	 *
181
+	 * @param EEI_Payment $payment
182
+	 * @param array $billing_info {
183
+	 *  @type $credit_card string
184
+	 *  @type $cvv string
185
+	 *  @type $exp_month string
186
+	 *  @type $exp_year string
187
+	 *  @see parent::do_direct_payment
188
+	 * }
189
+	 * @return EEI_Payment updated
190
+	 */
191
+	public function do_direct_payment($payment, $billing_info = null)
192
+	{
193
+		add_filter('FHEE__EEG_Aim___get_server_url', array($this, 'possibly_use_deprecated_aim_server'), 10, 2);
194
+		// Enable test mode if needed
195
+		// 4007000000027  <-- test successful visa
196
+		// 4222222222222  <-- test failure card number
197
+
198
+		$item_num = 1;
199
+		$transaction = $payment->transaction();
200
+		$gateway_formatter = $this->_get_gateway_formatter();
201
+		$order_description = $this->prepareStringForAuthnet($gateway_formatter->formatOrderDescription($payment));
202
+		$primary_registrant = $transaction->primary_registration();
203
+		// if we're are charging for the full amount, show the normal line items
204
+		// and the itemized total adds up properly
205
+		if ($this->_can_easily_itemize_transaction_for($payment)) {
206
+			$total_line_item = $transaction->total_line_item();
207
+			foreach ($total_line_item->get_items() as $line_item) {
208
+				if ($line_item->quantity() == 0) {
209
+					continue;
210
+				}
211
+				$this->addLineItem(
212
+					$item_num++,
213
+					$gateway_formatter->formatLineItemName($line_item, $payment),
214
+					$gateway_formatter->formatLineItemDesc($line_item, $payment),
215
+					$line_item->quantity(),
216
+					$line_item->unit_price(),
217
+					'N'
218
+				);
219
+				$order_description .= $this->prepareStringForAuthnet($line_item->desc()) . ', ';
220
+			}
221
+			foreach ($total_line_item->tax_descendants() as $tax_line_item) {
222
+				$this->addLineItem(
223
+					$item_num++,
224
+					$tax_line_item->name(),
225
+					$tax_line_item->desc(),
226
+					1,
227
+					$tax_line_item->total(),
228
+					'N'
229
+				);
230
+			}
231
+		}
232
+
233
+		// start transaction
234
+		// if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id
235
+		$partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363';
236
+		$this->setField('solution_id', $partner_id);
237
+		$this->setField('amount', $gateway_formatter->formatCurrency($payment->amount()));
238
+		$this->setField('description', substr(rtrim($order_description, ', '), 0, 255));
239
+		$this->_set_sensitive_billing_data($billing_info);
240
+		$this->setField('first_name', $billing_info['first_name']);
241
+		$this->setField('last_name', $billing_info['last_name']);
242
+		$this->setField('email', $billing_info['email']);
243
+		$this->setField('company', $billing_info['company']);
244
+		$this->setField('address', $billing_info['address'].' '.$billing_info['address2']);
245
+		$this->setField('city', $billing_info['city']);
246
+		$this->setField('state', $billing_info['state']);
247
+		$this->setField('country', $billing_info['country']);
248
+		$this->setField('zip', $billing_info['zip']);
249
+		$this->setField('fax', $billing_info['fax']);
250
+		$this->setField('cust_id', $primary_registrant->ID());
251
+		$this->setField('phone', $billing_info['phone']);
252
+		$currency_config = LoaderFactory::getLoader()->load('EE_Currency_Config');
253
+		$this->setField('currency_code', $currency_config->code);
254
+		// invoice_num would be nice to have it be unique per SPCO page-load, that way if users
255
+		// press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page
256
+		// in which case, we need to generate teh invoice num per request right here...
257
+		$this->setField('invoice_num', wp_generate_password(12, false));// $billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']);
258
+		// tell AIM that any duplicates sent in the next 5 minutes are to be ignored
259
+		$this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS);
260
+
261
+		if ($this->_test_transactions) {
262
+			$this->test_request = "true";
263
+		}
264
+
265
+		// Capture response
266
+		$this->type = "AUTH_CAPTURE";
267
+		$response = $this->_sendRequest($payment);
268
+		if (! empty($response)) {
269
+			if ($response->error_message) {
270
+				$payment->set_status($this->_pay_model->failed_status());
271
+				$payment->set_gateway_response($response->error_message);
272
+			} else {
273
+				$payment_status = $response->approved
274
+					? $this->_pay_model->approved_status()
275
+					: $this->_pay_model->declined_status();
276
+				$payment->set_status($payment_status);
277
+				// make sure we interpret the AMT as a float, not an international string (where periods are thousand separators)
278
+				$payment->set_amount((float) $response->amount);
279
+				$payment->set_gateway_response(
280
+					sprintf(
281
+						esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'),
282
+						$response->response_reason_text,
283
+						$response->response_reason_code
284
+					)
285
+				);
286
+				if ($this->_debug_mode) {
287
+					$txn_id = $response->invoice_number;
288
+				} else {
289
+					$txn_id = $response->transaction_id;
290
+				}
291
+				$payment->set_txn_id_chq_nmbr($txn_id);
292
+			}
293
+			$payment->set_extra_accntng($primary_registrant->reg_code());
294
+			$payment->set_details(print_r($response, true));
295
+		} else {
296
+			$payment->set_status($this->_pay_model->failed_status());
297
+			$payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso'));
298
+			$payment->set_details(print_r($response, true));
299
+		}
300
+		return $payment;
301
+	}
302
+
303
+
304
+	/**
305
+	 * Sets billing data for the upcoming request to AIM that is considered sensitive;
306
+	 * also this method can be overridden by children classes to easily change
307
+	 * what billing data gets sent
308
+	 *
309
+	 * @param array $billing_info
310
+	 */
311
+	protected function _set_sensitive_billing_data($billing_info)
312
+	{
313
+		$this->setField('card_num', $billing_info['credit_card']);
314
+		$this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']);
315
+		$this->setField('card_code', $billing_info['cvv']);
316
+	}
317
+
318
+
319
+	/**
320
+	 * Add a line item.
321
+	 *
322
+	 * @param string $item_id
323
+	 * @param string $item_name
324
+	 * @param string $item_description
325
+	 * @param string $item_quantity
326
+	 * @param string $item_unit_price
327
+	 * @param string $item_taxable
328
+	 */
329
+	public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable)
330
+	{
331
+		$args = array(
332
+			substr($item_id, 0, 31),
333
+			substr($this->prepareStringForAuthnet($item_name), 0, 31),
334
+			substr($this->prepareStringForAuthnet($item_description), 0, 255),
335
+			number_format(abs($item_quantity), 2, '.', ''),
336
+			number_format(abs($item_unit_price), 2, '.', ''),
337
+			$item_taxable === 'N' ? 'N' : 'Y'
338
+		);
339
+		$this->_additional_line_items[] = implode('<|>', $args);
340
+	}
341
+
342
+
343
+	/**
344
+	 * Set an individual name/value pair. This will append x_ to the name
345
+	 * before posting.
346
+	 *
347
+	 * @param string $name
348
+	 * @param string $value
349
+	 * @throws AuthorizeNetException
350
+	 */
351
+	protected function setField($name, $value)
352
+	{
353
+		if (in_array($name, $this->_all_aim_fields)) {
354
+			$this->_x_post_fields[ $name ] = $value;
355
+		} else {
356
+			throw new AuthorizeNetException("Error: no field $name exists in the AIM API.
357 357
             To set a custom field use setCustomField('field','value') instead.");
358
-        }
359
-    }
360
-
361
-
362
-    /**
363
-     * Posts the request to AuthorizeNet & returns response.
364
-     *
365
-     * @param $payment
366
-     * @return \EE_AuthorizeNetAIM_Response
367
-     */
368
-    private function _sendRequest($payment)
369
-    {
370
-        $this->_x_post_fields['login'] = $this->_login_id;
371
-        $this->_x_post_fields['tran_key'] = $this->_transaction_key;
372
-        $x_keys = array();
373
-        foreach ($this->_x_post_fields as $key => $value) {
374
-            $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value));
375
-        }
376
-        // Add line items
377
-        foreach ($this->_additional_line_items as $key => $value) {
378
-            $x_keys[] =  "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value));
379
-        }
380
-        $this->_log_clean_request($x_keys, $payment);
381
-        $post_url = $this->_get_server_url();
382
-        $curl_request = curl_init($post_url);
383
-        $post_body = implode("&", $x_keys);
384
-        curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body);
385
-        curl_setopt($curl_request, CURLOPT_HEADER, 0);
386
-        curl_setopt($curl_request, CURLOPT_TIMEOUT, 45);
387
-        curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
388
-        curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2);
389
-        if ($this->VERIFY_PEER) {
390
-            curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem');
391
-        } else {
392
-            curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false);
393
-        }
394
-
395
-        if (preg_match('/xml/', $post_url)) {
396
-            curl_setopt($curl_request, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
397
-        }
398
-
399
-        $response = curl_exec($curl_request);
400
-
401
-        curl_close($curl_request);
402
-        $response_obj =  new EE_AuthorizeNetAIM_Response($response);
403
-
404
-        return $this->_log_and_clean_response($response_obj, $payment);
405
-    }
406
-
407
-
408
-    /**
409
-     * Logs the clean data only
410
-     *
411
-     * @param array $request_array
412
-     * @param EEI_Payment $payment
413
-     */
414
-    protected function _log_clean_request($request_array, $payment)
415
-    {
416
-        $keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date');
417
-        foreach ($request_array as $index => $keyvaltogether) {
418
-            foreach ($keys_to_filter_out as $key) {
419
-                if (strpos($keyvaltogether, $key) === 0) {
420
-                    // found it at the first character
421
-                    // so its one of them
422
-                    unset($request_array[ $index ]);
423
-                }
424
-            }
425
-        }
426
-        $this->log(
427
-            array(
428
-                'AIM Request sent:' => $request_array,
429
-                'Server URL'        => $this->_get_server_url()
430
-            ),
431
-            $payment
432
-        );
433
-    }
434
-
435
-
436
-
437
-    /**
438
-     * Logs the response and cleans it
439
-     *
440
-     * @param EE_AuthorizeNetAIM_Response $response_obj
441
-     * @param EE_Payment                  $payment
442
-     * @return \EE_AuthorizeNetAIM_Response
443
-     */
444
-    private function _log_and_clean_response($response_obj, $payment)
445
-    {
446
-        $response_obj->account_number = '';
447
-        $this->log(array('AIM Response received:' => (array) $response_obj), $payment);
448
-        return $response_obj;
449
-    }
450
-
451
-    /**
452
-     * Removes characters Authorize.net doesn't handle well.
453
-     * @since 4.9.82.p
454
-     * @param $text
455
-     * @return string
456
-     */
457
-    private function prepareStringForAuthnet($text)
458
-    {
459
-        return str_replace(
460
-            '\'',
461
-            '',
462
-            $text
463
-        );
464
-    }
358
+		}
359
+	}
360
+
361
+
362
+	/**
363
+	 * Posts the request to AuthorizeNet & returns response.
364
+	 *
365
+	 * @param $payment
366
+	 * @return \EE_AuthorizeNetAIM_Response
367
+	 */
368
+	private function _sendRequest($payment)
369
+	{
370
+		$this->_x_post_fields['login'] = $this->_login_id;
371
+		$this->_x_post_fields['tran_key'] = $this->_transaction_key;
372
+		$x_keys = array();
373
+		foreach ($this->_x_post_fields as $key => $value) {
374
+			$x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value));
375
+		}
376
+		// Add line items
377
+		foreach ($this->_additional_line_items as $key => $value) {
378
+			$x_keys[] =  "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value));
379
+		}
380
+		$this->_log_clean_request($x_keys, $payment);
381
+		$post_url = $this->_get_server_url();
382
+		$curl_request = curl_init($post_url);
383
+		$post_body = implode("&", $x_keys);
384
+		curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body);
385
+		curl_setopt($curl_request, CURLOPT_HEADER, 0);
386
+		curl_setopt($curl_request, CURLOPT_TIMEOUT, 45);
387
+		curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
388
+		curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2);
389
+		if ($this->VERIFY_PEER) {
390
+			curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem');
391
+		} else {
392
+			curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false);
393
+		}
394
+
395
+		if (preg_match('/xml/', $post_url)) {
396
+			curl_setopt($curl_request, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
397
+		}
398
+
399
+		$response = curl_exec($curl_request);
400
+
401
+		curl_close($curl_request);
402
+		$response_obj =  new EE_AuthorizeNetAIM_Response($response);
403
+
404
+		return $this->_log_and_clean_response($response_obj, $payment);
405
+	}
406
+
407
+
408
+	/**
409
+	 * Logs the clean data only
410
+	 *
411
+	 * @param array $request_array
412
+	 * @param EEI_Payment $payment
413
+	 */
414
+	protected function _log_clean_request($request_array, $payment)
415
+	{
416
+		$keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date');
417
+		foreach ($request_array as $index => $keyvaltogether) {
418
+			foreach ($keys_to_filter_out as $key) {
419
+				if (strpos($keyvaltogether, $key) === 0) {
420
+					// found it at the first character
421
+					// so its one of them
422
+					unset($request_array[ $index ]);
423
+				}
424
+			}
425
+		}
426
+		$this->log(
427
+			array(
428
+				'AIM Request sent:' => $request_array,
429
+				'Server URL'        => $this->_get_server_url()
430
+			),
431
+			$payment
432
+		);
433
+	}
434
+
435
+
436
+
437
+	/**
438
+	 * Logs the response and cleans it
439
+	 *
440
+	 * @param EE_AuthorizeNetAIM_Response $response_obj
441
+	 * @param EE_Payment                  $payment
442
+	 * @return \EE_AuthorizeNetAIM_Response
443
+	 */
444
+	private function _log_and_clean_response($response_obj, $payment)
445
+	{
446
+		$response_obj->account_number = '';
447
+		$this->log(array('AIM Response received:' => (array) $response_obj), $payment);
448
+		return $response_obj;
449
+	}
450
+
451
+	/**
452
+	 * Removes characters Authorize.net doesn't handle well.
453
+	 * @since 4.9.82.p
454
+	 * @param $text
455
+	 * @return string
456
+	 */
457
+	private function prepareStringForAuthnet($text)
458
+	{
459
+		return str_replace(
460
+			'\'',
461
+			'',
462
+			$text
463
+		);
464
+	}
465 465
 }
466 466
 
467 467
 
@@ -477,192 +477,192 @@  discard block
 block discarded – undo
477 477
 class EE_AuthorizeNetAIM_Response
478 478
 {
479 479
 
480
-    const APPROVED = '1';
481
-    const DECLINED = '2';
482
-    const ERROR = '3';
483
-    const HELD = '4';
484
-
485
-    protected $_x_post_fields = array(
486
-        "version"        => "3.1",
487
-        "delim_char"     => ",",
488
-        "delim_data"     => "TRUE",
489
-        "relay_response" => "FALSE",
490
-        "encap_char"     => "|",
491
-    );
492
-    public $approved;
493
-    public $declined;
494
-    public $error;
495
-    public $held;
496
-    public $response_code;
497
-    public $response_subcode;
498
-    public $response_reason_code;
499
-    public $response_reason_text;
500
-    public $authorization_code;
501
-    public $avs_response;
502
-    public $transaction_id;
503
-    public $invoice_number;
504
-    public $description;
505
-    public $amount;
506
-    public $method;
507
-    public $transaction_type;
508
-    public $customer_id;
509
-    public $first_name;
510
-    public $last_name;
511
-    public $company;
512
-    public $address;
513
-    public $city;
514
-    public $state;
515
-    public $zip_code;
516
-    public $country;
517
-    public $phone;
518
-    public $fax;
519
-    public $email_address;
520
-    public $ship_to_first_name;
521
-    public $ship_to_last_name;
522
-    public $ship_to_company;
523
-    public $ship_to_address;
524
-    public $ship_to_city;
525
-    public $ship_to_state;
526
-    public $ship_to_zip_code;
527
-    public $ship_to_country;
528
-    public $tax;
529
-    public $duty;
530
-    public $freight;
531
-    public $tax_exempt;
532
-    public $purchase_order_number;
533
-    public $md5_hash;
534
-    public $card_code_response;
535
-    public $cavv_response; // cardholder_authentication_verification_response
536
-    public $account_number;
537
-    public $card_type;
538
-    public $split_tender_id;
539
-    public $requested_amount;
540
-    public $balance_on_card;
541
-    public $response; // The response string from AuthorizeNet.
542
-    public $error_message;
543
-    private $_response_array = array(); // An array with the split response.
544
-
545
-
546
-    /**
547
-     * Constructor. Parses the AuthorizeNet response string
548
-     *
549
-     * @param string $response The response from the AuthNet server.
550
-     * @var string   $delimiter The delimiter used (default is ",")
551
-     * @var string   $encap_char The encap_char used (default is "|")
552
-     * @var array    $custom_fields Any custom fields set in the request.
553
-     */
554
-
555
-    public function __construct($response)
556
-    {
557
-        $encap_char = $this->_x_post_fields['encap_char'];
558
-        $delimiter = $this->_x_post_fields['delim_char'];
559
-        if ($response) {
560
-            // Split Array
561
-            $this->response = $response;
562
-            if ($encap_char) {
563
-                $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1));
564
-            } else {
565
-                $this->_response_array = explode($delimiter, $response);
566
-            }
567
-
568
-            /**
569
-             * If AuthorizeNet doesn't return a delimited response.
570
-             */
571
-            if (count($this->_response_array) < 10) {
572
-                $this->approved = false;
573
-                $this->error = true;
574
-                $this->error_message = sprintf(
575
-                    esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'),
576
-                    esc_html($response)
577
-                );
578
-                return;
579
-            }
580
-
581
-
582
-
583
-            // Set all fields
584
-            $this->response_code = $this->_response_array[0];
585
-            $this->response_subcode = $this->_response_array[1];
586
-            $this->response_reason_code = $this->_response_array[2];
587
-            $this->response_reason_text = $this->_response_array[3];
588
-            $this->authorization_code = $this->_response_array[4];
589
-            $this->avs_response = $this->_response_array[5];
590
-            $this->transaction_id = $this->_response_array[6];
591
-            $this->invoice_number = $this->_response_array[7];
592
-            $this->description = $this->_response_array[8];
593
-            $this->amount = $this->_response_array[9];
594
-            $this->method = $this->_response_array[10];
595
-            $this->transaction_type = $this->_response_array[11];
596
-            $this->customer_id = $this->_response_array[12];
597
-            $this->first_name = $this->_response_array[13];
598
-            $this->last_name = $this->_response_array[14];
599
-            $this->company = $this->_response_array[15];
600
-            $this->address = $this->_response_array[16];
601
-            $this->city = $this->_response_array[17];
602
-            $this->state = $this->_response_array[18];
603
-            $this->zip_code = $this->_response_array[19];
604
-            $this->country = $this->_response_array[20];
605
-            $this->phone = $this->_response_array[21];
606
-            $this->fax = $this->_response_array[22];
607
-            $this->email_address = $this->_response_array[23];
608
-            $this->ship_to_first_name = $this->_response_array[24];
609
-            $this->ship_to_last_name = $this->_response_array[25];
610
-            $this->ship_to_company = $this->_response_array[26];
611
-            $this->ship_to_address = $this->_response_array[27];
612
-            $this->ship_to_city = $this->_response_array[28];
613
-            $this->ship_to_state = $this->_response_array[29];
614
-            $this->ship_to_zip_code = $this->_response_array[30];
615
-            $this->ship_to_country = $this->_response_array[31];
616
-            $this->tax = $this->_response_array[32];
617
-            $this->duty = $this->_response_array[33];
618
-            $this->freight = $this->_response_array[34];
619
-            $this->tax_exempt = $this->_response_array[35];
620
-            $this->purchase_order_number = $this->_response_array[36];
621
-            $this->md5_hash = $this->_response_array[37];
622
-            $this->card_code_response = $this->_response_array[38];
623
-            $this->cavv_response = $this->_response_array[39];
624
-            $this->account_number = $this->_response_array[50];
625
-            $this->card_type = $this->_response_array[51];
626
-            $this->split_tender_id = $this->_response_array[52];
627
-            $this->requested_amount = $this->_response_array[53];
628
-            $this->balance_on_card = $this->_response_array[54];
629
-
630
-            $this->approved = ($this->response_code === self::APPROVED);
631
-            $this->declined = ($this->response_code === self::DECLINED);
632
-            $this->error = ($this->response_code === self::ERROR);
633
-            $this->held = ($this->response_code === self::HELD);
634
-        } else {
635
-            $this->approved = false;
636
-            $this->error = true;
637
-            $this->error_message = esc_html__(
638
-                'Error connecting to Authorize.net',
639
-                'event_espresso'
640
-            );
641
-        }
642
-    }
480
+	const APPROVED = '1';
481
+	const DECLINED = '2';
482
+	const ERROR = '3';
483
+	const HELD = '4';
484
+
485
+	protected $_x_post_fields = array(
486
+		"version"        => "3.1",
487
+		"delim_char"     => ",",
488
+		"delim_data"     => "TRUE",
489
+		"relay_response" => "FALSE",
490
+		"encap_char"     => "|",
491
+	);
492
+	public $approved;
493
+	public $declined;
494
+	public $error;
495
+	public $held;
496
+	public $response_code;
497
+	public $response_subcode;
498
+	public $response_reason_code;
499
+	public $response_reason_text;
500
+	public $authorization_code;
501
+	public $avs_response;
502
+	public $transaction_id;
503
+	public $invoice_number;
504
+	public $description;
505
+	public $amount;
506
+	public $method;
507
+	public $transaction_type;
508
+	public $customer_id;
509
+	public $first_name;
510
+	public $last_name;
511
+	public $company;
512
+	public $address;
513
+	public $city;
514
+	public $state;
515
+	public $zip_code;
516
+	public $country;
517
+	public $phone;
518
+	public $fax;
519
+	public $email_address;
520
+	public $ship_to_first_name;
521
+	public $ship_to_last_name;
522
+	public $ship_to_company;
523
+	public $ship_to_address;
524
+	public $ship_to_city;
525
+	public $ship_to_state;
526
+	public $ship_to_zip_code;
527
+	public $ship_to_country;
528
+	public $tax;
529
+	public $duty;
530
+	public $freight;
531
+	public $tax_exempt;
532
+	public $purchase_order_number;
533
+	public $md5_hash;
534
+	public $card_code_response;
535
+	public $cavv_response; // cardholder_authentication_verification_response
536
+	public $account_number;
537
+	public $card_type;
538
+	public $split_tender_id;
539
+	public $requested_amount;
540
+	public $balance_on_card;
541
+	public $response; // The response string from AuthorizeNet.
542
+	public $error_message;
543
+	private $_response_array = array(); // An array with the split response.
544
+
545
+
546
+	/**
547
+	 * Constructor. Parses the AuthorizeNet response string
548
+	 *
549
+	 * @param string $response The response from the AuthNet server.
550
+	 * @var string   $delimiter The delimiter used (default is ",")
551
+	 * @var string   $encap_char The encap_char used (default is "|")
552
+	 * @var array    $custom_fields Any custom fields set in the request.
553
+	 */
554
+
555
+	public function __construct($response)
556
+	{
557
+		$encap_char = $this->_x_post_fields['encap_char'];
558
+		$delimiter = $this->_x_post_fields['delim_char'];
559
+		if ($response) {
560
+			// Split Array
561
+			$this->response = $response;
562
+			if ($encap_char) {
563
+				$this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1));
564
+			} else {
565
+				$this->_response_array = explode($delimiter, $response);
566
+			}
567
+
568
+			/**
569
+			 * If AuthorizeNet doesn't return a delimited response.
570
+			 */
571
+			if (count($this->_response_array) < 10) {
572
+				$this->approved = false;
573
+				$this->error = true;
574
+				$this->error_message = sprintf(
575
+					esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'),
576
+					esc_html($response)
577
+				);
578
+				return;
579
+			}
580
+
581
+
582
+
583
+			// Set all fields
584
+			$this->response_code = $this->_response_array[0];
585
+			$this->response_subcode = $this->_response_array[1];
586
+			$this->response_reason_code = $this->_response_array[2];
587
+			$this->response_reason_text = $this->_response_array[3];
588
+			$this->authorization_code = $this->_response_array[4];
589
+			$this->avs_response = $this->_response_array[5];
590
+			$this->transaction_id = $this->_response_array[6];
591
+			$this->invoice_number = $this->_response_array[7];
592
+			$this->description = $this->_response_array[8];
593
+			$this->amount = $this->_response_array[9];
594
+			$this->method = $this->_response_array[10];
595
+			$this->transaction_type = $this->_response_array[11];
596
+			$this->customer_id = $this->_response_array[12];
597
+			$this->first_name = $this->_response_array[13];
598
+			$this->last_name = $this->_response_array[14];
599
+			$this->company = $this->_response_array[15];
600
+			$this->address = $this->_response_array[16];
601
+			$this->city = $this->_response_array[17];
602
+			$this->state = $this->_response_array[18];
603
+			$this->zip_code = $this->_response_array[19];
604
+			$this->country = $this->_response_array[20];
605
+			$this->phone = $this->_response_array[21];
606
+			$this->fax = $this->_response_array[22];
607
+			$this->email_address = $this->_response_array[23];
608
+			$this->ship_to_first_name = $this->_response_array[24];
609
+			$this->ship_to_last_name = $this->_response_array[25];
610
+			$this->ship_to_company = $this->_response_array[26];
611
+			$this->ship_to_address = $this->_response_array[27];
612
+			$this->ship_to_city = $this->_response_array[28];
613
+			$this->ship_to_state = $this->_response_array[29];
614
+			$this->ship_to_zip_code = $this->_response_array[30];
615
+			$this->ship_to_country = $this->_response_array[31];
616
+			$this->tax = $this->_response_array[32];
617
+			$this->duty = $this->_response_array[33];
618
+			$this->freight = $this->_response_array[34];
619
+			$this->tax_exempt = $this->_response_array[35];
620
+			$this->purchase_order_number = $this->_response_array[36];
621
+			$this->md5_hash = $this->_response_array[37];
622
+			$this->card_code_response = $this->_response_array[38];
623
+			$this->cavv_response = $this->_response_array[39];
624
+			$this->account_number = $this->_response_array[50];
625
+			$this->card_type = $this->_response_array[51];
626
+			$this->split_tender_id = $this->_response_array[52];
627
+			$this->requested_amount = $this->_response_array[53];
628
+			$this->balance_on_card = $this->_response_array[54];
629
+
630
+			$this->approved = ($this->response_code === self::APPROVED);
631
+			$this->declined = ($this->response_code === self::DECLINED);
632
+			$this->error = ($this->response_code === self::ERROR);
633
+			$this->held = ($this->response_code === self::HELD);
634
+		} else {
635
+			$this->approved = false;
636
+			$this->error = true;
637
+			$this->error_message = esc_html__(
638
+				'Error connecting to Authorize.net',
639
+				'event_espresso'
640
+			);
641
+		}
642
+	}
643 643
 }
644 644
 
645 645
 if (! class_exists('AuthorizeNetException')) {
646
-    /**
647
-     * Class AuthorizeNetException
648
-     *
649
-     * @package    AuthorizeNet
650
-     */
651
-    class AuthorizeNetException extends Exception
652
-    {
653
-
654
-        /**
655
-         * Construct the exception. Note: The message is NOT binary safe.
656
-         *
657
-         * @link http://php.net/manual/en/exception.construct.php
658
-         * @param string $message [optional] The Exception message to throw.
659
-         * @param int $code [optional] The Exception code.
660
-         * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0
661
-         * @since 5.1.0
662
-         */
663
-        public function __construct($message = "", $code = 0, Exception $previous = null)
664
-        {
665
-            parent::__construct($message, $code, $previous);
666
-        }
667
-    }
646
+	/**
647
+	 * Class AuthorizeNetException
648
+	 *
649
+	 * @package    AuthorizeNet
650
+	 */
651
+	class AuthorizeNetException extends Exception
652
+	{
653
+
654
+		/**
655
+		 * Construct the exception. Note: The message is NOT binary safe.
656
+		 *
657
+		 * @link http://php.net/manual/en/exception.construct.php
658
+		 * @param string $message [optional] The Exception message to throw.
659
+		 * @param int $code [optional] The Exception code.
660
+		 * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0
661
+		 * @since 5.1.0
662
+		 */
663
+		public function __construct($message = "", $code = 0, Exception $previous = null)
664
+		{
665
+			parent::__construct($message, $code, $previous);
666
+		}
667
+	}
668 668
 }
Please login to merge, or discard this patch.
core/services/assets/Registry.php 1 patch
Indentation   +732 added lines, -732 removed lines patch added patch discarded remove patch
@@ -25,743 +25,743 @@
 block discarded – undo
25 25
 class Registry
26 26
 {
27 27
 
28
-    const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
29
-
30
-    /**
31
-     * @var AssetCollection $assets
32
-     */
33
-    protected $assets;
34
-
35
-    /**
36
-     * @var I18nRegistry
37
-     */
38
-    private $i18n_registry;
39
-
40
-    /**
41
-     * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
42
-     *
43
-     * @var array
44
-     */
45
-    protected $jsdata = array();
46
-
47
-    /**
48
-     * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
49
-     * page source.
50
-     *
51
-     * @var array
52
-     */
53
-    private $script_handles_with_data = array();
54
-
55
-
56
-    /**
57
-     * Holds the manifest data obtained from registered manifest files.
58
-     * Manifests are maps of asset chunk name to actual built asset file names.
59
-     * Shape of this array is:
60
-     * array(
61
-     *  'some_namespace_slug' => array(
62
-     *      'some_chunk_name' => array(
63
-     *          'js' => 'filename.js'
64
-     *          'css' => 'filename.js'
65
-     *      ),
66
-     *      'url_base' => 'https://baseurl.com/to/assets
67
-     *  )
68
-     * )
69
-     *
70
-     * @var array
71
-     */
72
-    private $manifest_data = array();
73
-
74
-
75
-    /**
76
-     * Holds any dependency data obtained from registered dependency map json.
77
-     * Dependency map json is generated via the @wordpress/dependency-extraction-webpack-plugin via the webpack config.
78
-     * @see https://github.com/WordPress/gutenberg/tree/master/packages/dependency-extraction-webpack-plugin
79
-     *
80
-     * @var array
81
-     */
82
-    private $dependencies_data = [];
83
-
84
-
85
-    /**
86
-     * This is a known array of possible wp css handles that correspond to what may be exposed as dependencies in our
87
-     * build process.  Currently the dependency export process in webpack does not consider css imports, so we derive
88
-     * them via the js dependencies (WP uses the same handle for both js and css). This is a list of known handles that
89
-     * are used for both js and css.
90
-     * @var array
91
-     */
92
-    private $wp_css_handle_dependencies = [
93
-        'wp-components',
94
-        'wp-block-editor',
95
-        'wp-block-library',
96
-        'wp-edit-post',
97
-        'wp-edit-widgets',
98
-        'wp-editor',
99
-        'wp-format-library',
100
-        'wp-list-reusable-blocks',
101
-        'wp-nux',
102
-    ];
103
-
104
-
105
-    /**
106
-     * Registry constructor.
107
-     * Hooking into WP actions for script registry.
108
-     *
109
-     * @param AssetCollection      $assets
110
-     * @param I18nRegistry         $i18n_registry
111
-     * @throws InvalidArgumentException
112
-     * @throws InvalidDataTypeException
113
-     * @throws InvalidInterfaceException
114
-     */
115
-    public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
116
-    {
117
-        $this->assets = $assets;
118
-        $this->i18n_registry = $i18n_registry;
119
-        add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
120
-        add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
121
-        add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
122
-        add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
123
-        add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4);
124
-        add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4);
125
-        add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
126
-        add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
127
-    }
128
-
129
-
130
-    /**
131
-     * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
132
-     * translation handling.
133
-     *
134
-     * @return I18nRegistry
135
-     */
136
-    public function getI18nRegistry()
137
-    {
138
-        return $this->i18n_registry;
139
-    }
140
-
141
-
142
-    /**
143
-     * Callback for the wp_enqueue_scripts actions used to register assets.
144
-     *
145
-     * @since 4.9.62.p
146
-     * @throws Exception
147
-     */
148
-    public function registerScriptsAndStyles()
149
-    {
150
-        try {
151
-            $this->registerScripts($this->assets->getJavascriptAssets());
152
-            $this->registerStyles($this->assets->getStylesheetAssets());
153
-        } catch (Exception $exception) {
154
-            new ExceptionStackTraceDisplay($exception);
155
-        }
156
-    }
157
-
158
-
159
-    /**
160
-     * Registers JS assets with WP core
161
-     *
162
-     * @since 4.9.62.p
163
-     * @param JavascriptAsset[] $scripts
164
-     * @throws AssetRegistrationException
165
-     * @throws InvalidDataTypeException
166
-     */
167
-    public function registerScripts(array $scripts)
168
-    {
169
-        foreach ($scripts as $script) {
170
-            // skip to next script if this has already been done
171
-            if ($script->isRegistered()) {
172
-                continue;
173
-            }
174
-            do_action(
175
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
176
-                $script
177
-            );
178
-            $registered = wp_register_script(
179
-                $script->handle(),
180
-                $script->source(),
181
-                $script->dependencies(),
182
-                $script->version(),
183
-                $script->loadInFooter()
184
-            );
185
-            if (! $registered && $this->debug()) {
186
-                throw new AssetRegistrationException($script->handle());
187
-            }
188
-            $script->setRegistered($registered);
189
-            if ($script->requiresTranslation()) {
190
-                $this->registerTranslation($script->handle());
191
-            }
192
-            do_action(
193
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
194
-                $script
195
-            );
196
-        }
197
-    }
198
-
199
-
200
-    /**
201
-     * Registers CSS assets with WP core
202
-     *
203
-     * @since 4.9.62.p
204
-     * @param StylesheetAsset[] $styles
205
-     * @throws InvalidDataTypeException
206
-     */
207
-    public function registerStyles(array $styles)
208
-    {
209
-        foreach ($styles as $style) {
210
-            // skip to next style if this has already been done
211
-            if ($style->isRegistered()) {
212
-                continue;
213
-            }
214
-            do_action(
215
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
216
-                $style
217
-            );
218
-            wp_register_style(
219
-                $style->handle(),
220
-                $style->source(),
221
-                $style->dependencies(),
222
-                $style->version(),
223
-                $style->media()
224
-            );
225
-            $style->setRegistered();
226
-            do_action(
227
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
228
-                $style
229
-            );
230
-        }
231
-    }
232
-
233
-
234
-    /**
235
-     * Call back for the script print in frontend and backend.
236
-     * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
237
-     *
238
-     * @since 4.9.31.rc.015
239
-     */
240
-    public function enqueueData()
241
-    {
242
-        $this->removeAlreadyRegisteredDataForScriptHandles();
243
-        wp_add_inline_script(
244
-            'eejs-core',
245
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
246
-            'before'
247
-        );
248
-        $scripts = $this->assets->getJavascriptAssetsWithData();
249
-        foreach ($scripts as $script) {
250
-            $this->addRegisteredScriptHandlesWithData($script->handle());
251
-            if ($script->hasInlineDataCallback()) {
252
-                $localize = $script->inlineDataCallback();
253
-                $localize();
254
-            }
255
-        }
256
-    }
257
-
258
-
259
-    /**
260
-     * Used to add data to eejs.data object.
261
-     * Note:  Overriding existing data is not allowed.
262
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
263
-     * If the data you add is something like this:
264
-     *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
265
-     * It will be exposed in the page source as:
266
-     *  eejs.data.my_plugin_data.foo == gar
267
-     *
268
-     * @param string       $key   Key used to access your data
269
-     * @param string|array $value Value to attach to key
270
-     * @throws InvalidArgumentException
271
-     */
272
-    public function addData($key, $value)
273
-    {
274
-        if ($this->verifyDataNotExisting($key)) {
275
-            $this->jsdata[ $key ] = $value;
276
-        }
277
-    }
278
-
279
-
280
-    /**
281
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
282
-     * elements in an array.
283
-     *
284
-     * When you use this method, the value you include will be merged with the array on $key.
285
-     * So if the $key was 'test' and you added a value of ['my_data'] then it would be represented in the javascript
286
-     * object like this, eejs.data.test = [ my_data,
287
-     * ]
288
-     * If there has already been a scalar value attached to the data object given key (via addData for instance), then
289
-     * this will throw an exception.
290
-     *
291
-     * Caution: Only add data using this method if you are okay with the potential for additional data added on the same
292
-     * key potentially overriding the existing data on merge (specifically with associative arrays).
293
-     *
294
-     * @param string       $key   Key to attach data to.
295
-     * @param string|array $value Value being registered.
296
-     * @throws InvalidArgumentException
297
-     */
298
-    public function pushData($key, $value)
299
-    {
300
-        if (isset($this->jsdata[ $key ])
301
-            && ! is_array($this->jsdata[ $key ])
302
-        ) {
303
-            if (! $this->debug()) {
304
-                return;
305
-            }
306
-            throw new InvalidArgumentException(
307
-                sprintf(
308
-                    __(
309
-                        '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 FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
29
+
30
+	/**
31
+	 * @var AssetCollection $assets
32
+	 */
33
+	protected $assets;
34
+
35
+	/**
36
+	 * @var I18nRegistry
37
+	 */
38
+	private $i18n_registry;
39
+
40
+	/**
41
+	 * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
42
+	 *
43
+	 * @var array
44
+	 */
45
+	protected $jsdata = array();
46
+
47
+	/**
48
+	 * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
49
+	 * page source.
50
+	 *
51
+	 * @var array
52
+	 */
53
+	private $script_handles_with_data = array();
54
+
55
+
56
+	/**
57
+	 * Holds the manifest data obtained from registered manifest files.
58
+	 * Manifests are maps of asset chunk name to actual built asset file names.
59
+	 * Shape of this array is:
60
+	 * array(
61
+	 *  'some_namespace_slug' => array(
62
+	 *      'some_chunk_name' => array(
63
+	 *          'js' => 'filename.js'
64
+	 *          'css' => 'filename.js'
65
+	 *      ),
66
+	 *      'url_base' => 'https://baseurl.com/to/assets
67
+	 *  )
68
+	 * )
69
+	 *
70
+	 * @var array
71
+	 */
72
+	private $manifest_data = array();
73
+
74
+
75
+	/**
76
+	 * Holds any dependency data obtained from registered dependency map json.
77
+	 * Dependency map json is generated via the @wordpress/dependency-extraction-webpack-plugin via the webpack config.
78
+	 * @see https://github.com/WordPress/gutenberg/tree/master/packages/dependency-extraction-webpack-plugin
79
+	 *
80
+	 * @var array
81
+	 */
82
+	private $dependencies_data = [];
83
+
84
+
85
+	/**
86
+	 * This is a known array of possible wp css handles that correspond to what may be exposed as dependencies in our
87
+	 * build process.  Currently the dependency export process in webpack does not consider css imports, so we derive
88
+	 * them via the js dependencies (WP uses the same handle for both js and css). This is a list of known handles that
89
+	 * are used for both js and css.
90
+	 * @var array
91
+	 */
92
+	private $wp_css_handle_dependencies = [
93
+		'wp-components',
94
+		'wp-block-editor',
95
+		'wp-block-library',
96
+		'wp-edit-post',
97
+		'wp-edit-widgets',
98
+		'wp-editor',
99
+		'wp-format-library',
100
+		'wp-list-reusable-blocks',
101
+		'wp-nux',
102
+	];
103
+
104
+
105
+	/**
106
+	 * Registry constructor.
107
+	 * Hooking into WP actions for script registry.
108
+	 *
109
+	 * @param AssetCollection      $assets
110
+	 * @param I18nRegistry         $i18n_registry
111
+	 * @throws InvalidArgumentException
112
+	 * @throws InvalidDataTypeException
113
+	 * @throws InvalidInterfaceException
114
+	 */
115
+	public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
116
+	{
117
+		$this->assets = $assets;
118
+		$this->i18n_registry = $i18n_registry;
119
+		add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
120
+		add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
121
+		add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
122
+		add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
123
+		add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4);
124
+		add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4);
125
+		add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
126
+		add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
127
+	}
128
+
129
+
130
+	/**
131
+	 * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
132
+	 * translation handling.
133
+	 *
134
+	 * @return I18nRegistry
135
+	 */
136
+	public function getI18nRegistry()
137
+	{
138
+		return $this->i18n_registry;
139
+	}
140
+
141
+
142
+	/**
143
+	 * Callback for the wp_enqueue_scripts actions used to register assets.
144
+	 *
145
+	 * @since 4.9.62.p
146
+	 * @throws Exception
147
+	 */
148
+	public function registerScriptsAndStyles()
149
+	{
150
+		try {
151
+			$this->registerScripts($this->assets->getJavascriptAssets());
152
+			$this->registerStyles($this->assets->getStylesheetAssets());
153
+		} catch (Exception $exception) {
154
+			new ExceptionStackTraceDisplay($exception);
155
+		}
156
+	}
157
+
158
+
159
+	/**
160
+	 * Registers JS assets with WP core
161
+	 *
162
+	 * @since 4.9.62.p
163
+	 * @param JavascriptAsset[] $scripts
164
+	 * @throws AssetRegistrationException
165
+	 * @throws InvalidDataTypeException
166
+	 */
167
+	public function registerScripts(array $scripts)
168
+	{
169
+		foreach ($scripts as $script) {
170
+			// skip to next script if this has already been done
171
+			if ($script->isRegistered()) {
172
+				continue;
173
+			}
174
+			do_action(
175
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
176
+				$script
177
+			);
178
+			$registered = wp_register_script(
179
+				$script->handle(),
180
+				$script->source(),
181
+				$script->dependencies(),
182
+				$script->version(),
183
+				$script->loadInFooter()
184
+			);
185
+			if (! $registered && $this->debug()) {
186
+				throw new AssetRegistrationException($script->handle());
187
+			}
188
+			$script->setRegistered($registered);
189
+			if ($script->requiresTranslation()) {
190
+				$this->registerTranslation($script->handle());
191
+			}
192
+			do_action(
193
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
194
+				$script
195
+			);
196
+		}
197
+	}
198
+
199
+
200
+	/**
201
+	 * Registers CSS assets with WP core
202
+	 *
203
+	 * @since 4.9.62.p
204
+	 * @param StylesheetAsset[] $styles
205
+	 * @throws InvalidDataTypeException
206
+	 */
207
+	public function registerStyles(array $styles)
208
+	{
209
+		foreach ($styles as $style) {
210
+			// skip to next style if this has already been done
211
+			if ($style->isRegistered()) {
212
+				continue;
213
+			}
214
+			do_action(
215
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
216
+				$style
217
+			);
218
+			wp_register_style(
219
+				$style->handle(),
220
+				$style->source(),
221
+				$style->dependencies(),
222
+				$style->version(),
223
+				$style->media()
224
+			);
225
+			$style->setRegistered();
226
+			do_action(
227
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
228
+				$style
229
+			);
230
+		}
231
+	}
232
+
233
+
234
+	/**
235
+	 * Call back for the script print in frontend and backend.
236
+	 * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
237
+	 *
238
+	 * @since 4.9.31.rc.015
239
+	 */
240
+	public function enqueueData()
241
+	{
242
+		$this->removeAlreadyRegisteredDataForScriptHandles();
243
+		wp_add_inline_script(
244
+			'eejs-core',
245
+			'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
246
+			'before'
247
+		);
248
+		$scripts = $this->assets->getJavascriptAssetsWithData();
249
+		foreach ($scripts as $script) {
250
+			$this->addRegisteredScriptHandlesWithData($script->handle());
251
+			if ($script->hasInlineDataCallback()) {
252
+				$localize = $script->inlineDataCallback();
253
+				$localize();
254
+			}
255
+		}
256
+	}
257
+
258
+
259
+	/**
260
+	 * Used to add data to eejs.data object.
261
+	 * Note:  Overriding existing data is not allowed.
262
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
263
+	 * If the data you add is something like this:
264
+	 *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
265
+	 * It will be exposed in the page source as:
266
+	 *  eejs.data.my_plugin_data.foo == gar
267
+	 *
268
+	 * @param string       $key   Key used to access your data
269
+	 * @param string|array $value Value to attach to key
270
+	 * @throws InvalidArgumentException
271
+	 */
272
+	public function addData($key, $value)
273
+	{
274
+		if ($this->verifyDataNotExisting($key)) {
275
+			$this->jsdata[ $key ] = $value;
276
+		}
277
+	}
278
+
279
+
280
+	/**
281
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
282
+	 * elements in an array.
283
+	 *
284
+	 * When you use this method, the value you include will be merged with the array on $key.
285
+	 * So if the $key was 'test' and you added a value of ['my_data'] then it would be represented in the javascript
286
+	 * object like this, eejs.data.test = [ my_data,
287
+	 * ]
288
+	 * If there has already been a scalar value attached to the data object given key (via addData for instance), then
289
+	 * this will throw an exception.
290
+	 *
291
+	 * Caution: Only add data using this method if you are okay with the potential for additional data added on the same
292
+	 * key potentially overriding the existing data on merge (specifically with associative arrays).
293
+	 *
294
+	 * @param string       $key   Key to attach data to.
295
+	 * @param string|array $value Value being registered.
296
+	 * @throws InvalidArgumentException
297
+	 */
298
+	public function pushData($key, $value)
299
+	{
300
+		if (isset($this->jsdata[ $key ])
301
+			&& ! is_array($this->jsdata[ $key ])
302
+		) {
303
+			if (! $this->debug()) {
304
+				return;
305
+			}
306
+			throw new InvalidArgumentException(
307
+				sprintf(
308
+					__(
309
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
310 310
                          push values to this data element when it is an array.',
311
-                        'event_espresso'
312
-                    ),
313
-                    $key,
314
-                    __METHOD__
315
-                )
316
-            );
317
-        }
318
-        if ( ! isset( $this->jsdata[ $key ] ) ) {
319
-            $this->jsdata[ $key ] = is_array($value) ? $value : [$value];
320
-        } else {
321
-            $this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value);
322
-        }
323
-    }
324
-
325
-
326
-    /**
327
-     * Used to set content used by javascript for a template.
328
-     * Note: Overrides of existing registered templates are not allowed.
329
-     *
330
-     * @param string $template_reference
331
-     * @param string $template_content
332
-     * @throws InvalidArgumentException
333
-     */
334
-    public function addTemplate($template_reference, $template_content)
335
-    {
336
-        if (! isset($this->jsdata['templates'])) {
337
-            $this->jsdata['templates'] = array();
338
-        }
339
-        //no overrides allowed.
340
-        if (isset($this->jsdata['templates'][ $template_reference ])) {
341
-            if (! $this->debug()) {
342
-                return;
343
-            }
344
-            throw new InvalidArgumentException(
345
-                sprintf(
346
-                    __(
347
-                        'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
348
-                        'event_espresso'
349
-                    ),
350
-                    $template_reference
351
-                )
352
-            );
353
-        }
354
-        $this->jsdata['templates'][ $template_reference ] = $template_content;
355
-    }
356
-
357
-
358
-    /**
359
-     * Retrieve the template content already registered for the given reference.
360
-     *
361
-     * @param string $template_reference
362
-     * @return string
363
-     */
364
-    public function getTemplate($template_reference)
365
-    {
366
-        return isset($this->jsdata['templates'][ $template_reference ])
367
-            ? $this->jsdata['templates'][ $template_reference ]
368
-            : '';
369
-    }
370
-
371
-
372
-    /**
373
-     * Retrieve registered data.
374
-     *
375
-     * @param string $key Name of key to attach data to.
376
-     * @return mixed                If there is no for the given key, then false is returned.
377
-     */
378
-    public function getData($key)
379
-    {
380
-        return isset($this->jsdata[ $key ])
381
-            ? $this->jsdata[ $key ]
382
-            : false;
383
-    }
384
-
385
-
386
-    /**
387
-     * Verifies whether the given data exists already on the jsdata array.
388
-     * Overriding data is not allowed.
389
-     *
390
-     * @param string $key Index for data.
391
-     * @return bool        If valid then return true.
392
-     * @throws InvalidArgumentException if data already exists.
393
-     */
394
-    protected function verifyDataNotExisting($key)
395
-    {
396
-        if (isset($this->jsdata[ $key ])) {
397
-            if (! $this->debug()) {
398
-                return false;
399
-            }
400
-            if (is_array($this->jsdata[ $key ])) {
401
-                throw new InvalidArgumentException(
402
-                    sprintf(
403
-                        __(
404
-                            'The value for %1$s already exists in the Registry::eejs object.
311
+						'event_espresso'
312
+					),
313
+					$key,
314
+					__METHOD__
315
+				)
316
+			);
317
+		}
318
+		if ( ! isset( $this->jsdata[ $key ] ) ) {
319
+			$this->jsdata[ $key ] = is_array($value) ? $value : [$value];
320
+		} else {
321
+			$this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value);
322
+		}
323
+	}
324
+
325
+
326
+	/**
327
+	 * Used to set content used by javascript for a template.
328
+	 * Note: Overrides of existing registered templates are not allowed.
329
+	 *
330
+	 * @param string $template_reference
331
+	 * @param string $template_content
332
+	 * @throws InvalidArgumentException
333
+	 */
334
+	public function addTemplate($template_reference, $template_content)
335
+	{
336
+		if (! isset($this->jsdata['templates'])) {
337
+			$this->jsdata['templates'] = array();
338
+		}
339
+		//no overrides allowed.
340
+		if (isset($this->jsdata['templates'][ $template_reference ])) {
341
+			if (! $this->debug()) {
342
+				return;
343
+			}
344
+			throw new InvalidArgumentException(
345
+				sprintf(
346
+					__(
347
+						'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
348
+						'event_espresso'
349
+					),
350
+					$template_reference
351
+				)
352
+			);
353
+		}
354
+		$this->jsdata['templates'][ $template_reference ] = $template_content;
355
+	}
356
+
357
+
358
+	/**
359
+	 * Retrieve the template content already registered for the given reference.
360
+	 *
361
+	 * @param string $template_reference
362
+	 * @return string
363
+	 */
364
+	public function getTemplate($template_reference)
365
+	{
366
+		return isset($this->jsdata['templates'][ $template_reference ])
367
+			? $this->jsdata['templates'][ $template_reference ]
368
+			: '';
369
+	}
370
+
371
+
372
+	/**
373
+	 * Retrieve registered data.
374
+	 *
375
+	 * @param string $key Name of key to attach data to.
376
+	 * @return mixed                If there is no for the given key, then false is returned.
377
+	 */
378
+	public function getData($key)
379
+	{
380
+		return isset($this->jsdata[ $key ])
381
+			? $this->jsdata[ $key ]
382
+			: false;
383
+	}
384
+
385
+
386
+	/**
387
+	 * Verifies whether the given data exists already on the jsdata array.
388
+	 * Overriding data is not allowed.
389
+	 *
390
+	 * @param string $key Index for data.
391
+	 * @return bool        If valid then return true.
392
+	 * @throws InvalidArgumentException if data already exists.
393
+	 */
394
+	protected function verifyDataNotExisting($key)
395
+	{
396
+		if (isset($this->jsdata[ $key ])) {
397
+			if (! $this->debug()) {
398
+				return false;
399
+			}
400
+			if (is_array($this->jsdata[ $key ])) {
401
+				throw new InvalidArgumentException(
402
+					sprintf(
403
+						__(
404
+							'The value for %1$s already exists in the Registry::eejs object.
405 405
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
406 406
                             %2$s method to push your value to the array.',
407
-                            'event_espresso'
408
-                        ),
409
-                        $key,
410
-                        'pushData()'
411
-                    )
412
-                );
413
-            }
414
-            throw new InvalidArgumentException(
415
-                sprintf(
416
-                    __(
417
-                        'The value for %1$s already exists in the Registry::eejs object. Overrides are not
407
+							'event_espresso'
408
+						),
409
+						$key,
410
+						'pushData()'
411
+					)
412
+				);
413
+			}
414
+			throw new InvalidArgumentException(
415
+				sprintf(
416
+					__(
417
+						'The value for %1$s already exists in the Registry::eejs object. Overrides are not
418 418
                         allowed.  Consider attaching your value to a different key',
419
-                        'event_espresso'
420
-                    ),
421
-                    $key
422
-                )
423
-            );
424
-        }
425
-        return true;
426
-    }
427
-
428
-
429
-    /**
430
-     * Get the actual asset path for asset manifests.
431
-     * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
432
-     *
433
-     * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
434
-     *                           asset file location.
435
-     * @param string $chunk_name
436
-     * @param string $asset_type
437
-     * @return string
438
-     * @since 4.9.59.p
439
-     */
440
-    public function getAssetUrl($namespace, $chunk_name, $asset_type)
441
-    {
442
-        $url = isset(
443
-            $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
444
-            $this->manifest_data[ $namespace ]['url_base']
445
-        )
446
-            ? $this->manifest_data[ $namespace ]['url_base']
447
-              . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
448
-            : $chunk_name;
449
-
450
-        return apply_filters(
451
-            'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
452
-            $url,
453
-            $namespace,
454
-            $chunk_name,
455
-            $asset_type
456
-        );
457
-    }
458
-
459
-
460
-
461
-    /**
462
-     * Return the url to a js file for the given namespace and chunk name.
463
-     *
464
-     * @param string $namespace
465
-     * @param string $chunk_name
466
-     * @return string
467
-     */
468
-    public function getJsUrl($namespace, $chunk_name)
469
-    {
470
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
471
-    }
472
-
473
-
474
-    /**
475
-     * Return the url to a css file for the given namespace and chunk name.
476
-     *
477
-     * @param string $namespace
478
-     * @param string $chunk_name
479
-     * @return string
480
-     */
481
-    public function getCssUrl($namespace, $chunk_name)
482
-    {
483
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
484
-    }
485
-
486
-
487
-    /**
488
-     * Return the dependencies for a given asset $chunk_name
489
-     *
490
-     * @param string $namespace
491
-     * @param string $chunk_name
492
-     * @param string $asset_type
493
-     * @return array
494
-     * @since 4.9.82.p
495
-     */
496
-    private function getDependenciesForAsset($namespace, $chunk_name, $asset_type)
497
-    {
498
-        $asset_index = $chunk_name . '.' . $asset_type;
499
-        if (! isset( $this->dependencies_data[ $namespace ][ $asset_index ])) {
500
-            $path = isset($this->manifest_data[ $namespace ]['path'])
501
-                ? $this->manifest_data[ $namespace ]['path']
502
-                : '';
503
-            $dependencies_index = $chunk_name . '.' . Asset::TYPE_JSON;
504
-            $file_path = isset($this->manifest_data[ $namespace ][ $dependencies_index ])
505
-                ? $path . $this->manifest_data[ $namespace ][ $dependencies_index ]
506
-                :
507
-                '';
508
-            $this->dependencies_data[ $namespace ][ $asset_index ] = $file_path !== '' && file_exists($file_path)
509
-                ? $this->getDependenciesForAssetType($namespace, $asset_type, $file_path, $chunk_name)
510
-                : [];
511
-        }
512
-        return $this->dependencies_data[ $namespace ][ $asset_index ];
513
-    }
514
-
515
-
516
-    /**
517
-     * Return dependencies according to asset type.
518
-     *
519
-     * For css assets, this filters the auto generated dependencies by css type.
520
-     *
521
-     * @param string $namespace
522
-     * @param string $asset_type
523
-     * @param string $file_path
524
-     * @param string $chunk_name
525
-     * @return array
526
-     * @since 4.9.82.p
527
-     */
528
-    private function getDependenciesForAssetType($namespace, $asset_type, $file_path, $chunk_name)
529
-    {
530
-        $asset_dependencies = json_decode(file_get_contents($file_path), true);
531
-        if ($asset_type === Asset::TYPE_JS) {
532
-            return $chunk_name === 'eejs-core' ? $asset_dependencies : array_merge(
533
-                $asset_dependencies,
534
-                [ CoreAssetManager::JS_HANDLE_JS_CORE ]
535
-            );
536
-        }
537
-        // for css we need to make sure there is actually a css file related to this chunk.
538
-        if (isset($this->manifest_data[ $namespace ])) {
539
-            // array of css chunk files for ee.
540
-            $css_chunks = array_map(
541
-                function ($value) {
542
-                    return str_replace('.css', '', $value);
543
-                },
544
-                array_filter(
545
-                    array_keys($this->manifest_data[ $namespace ]),
546
-                    function ($value) {
547
-                        return strpos($value, '.css') !== false;
548
-                    }
549
-                )
550
-            );
551
-            // add known wp chunks with css
552
-            $css_chunks = array_merge( $css_chunks, $this->wp_css_handle_dependencies);
553
-            // flip for easier search
554
-            $css_chunks = array_flip($css_chunks);
555
-
556
-            // now let's filter the dependencies for the incoming chunk to actual chunks that have styles
557
-            return array_filter(
558
-                $asset_dependencies,
559
-                function ($chunk_name) use ($css_chunks) {
560
-                    return isset($css_chunks[ $chunk_name ]);
561
-                }
562
-            );
563
-        }
564
-        return [];
565
-    }
566
-
567
-
568
-    /**
569
-     * Get the dependencies array for the given js asset chunk name
570
-     *
571
-     * @param string $namespace
572
-     * @param string $chunk_name
573
-     * @return array
574
-     * @since 4.9.82.p
575
-     */
576
-    public function getJsDependencies($namespace, $chunk_name)
577
-    {
578
-        return $this->getDependenciesForAsset($namespace, $chunk_name, Asset::TYPE_JS);
579
-    }
580
-
581
-
582
-    /**
583
-     * Get the dependencies array for the given css asset chunk name
584
-     *
585
-     * @param string $namespace
586
-     * @param string $chunk_name
587
-     * @return array
588
-     * @since 4.9.82.p
589
-     */
590
-    public function getCssDependencies($namespace, $chunk_name)
591
-    {
592
-        return $this->getDependenciesForAsset($namespace, $chunk_name, Asset::TYPE_CSS);
593
-    }
594
-
595
-
596
-    /**
597
-     * @since 4.9.62.p
598
-     * @throws InvalidArgumentException
599
-     * @throws InvalidFilePathException
600
-     */
601
-    public function registerManifestFiles()
602
-    {
603
-        $manifest_files = $this->assets->getManifestFiles();
604
-        foreach ($manifest_files as $manifest_file) {
605
-            $this->registerManifestFile(
606
-                $manifest_file->assetNamespace(),
607
-                $manifest_file->urlBase(),
608
-                $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST,
609
-                $manifest_file->filepath()
610
-            );
611
-        }
612
-    }
613
-
614
-
615
-    /**
616
-     * Used to register a js/css manifest file with the registered_manifest_files property.
617
-     *
618
-     * @param string $namespace     Provided to associate the manifest file with a specific namespace.
619
-     * @param string $url_base      The url base for the manifest file location.
620
-     * @param string $manifest_file The absolute path to the manifest file.
621
-     * @param string $manifest_file_path  The path to the folder containing the manifest file. If not provided will be
622
-     *                                    default to `plugin_root/assets/dist`.
623
-     * @throws InvalidArgumentException
624
-     * @throws InvalidFilePathException
625
-     * @since 4.9.59.p
626
-     */
627
-    public function registerManifestFile($namespace, $url_base, $manifest_file, $manifest_file_path = '')
628
-    {
629
-        if (isset($this->manifest_data[ $namespace ])) {
630
-            if (! $this->debug()) {
631
-                return;
632
-            }
633
-            throw new InvalidArgumentException(
634
-                sprintf(
635
-                    esc_html__(
636
-                        'The namespace for this manifest file has already been registered, choose a namespace other than %s',
637
-                        'event_espresso'
638
-                    ),
639
-                    $namespace
640
-                )
641
-            );
642
-        }
643
-        if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
644
-            if (is_admin()) {
645
-                EE_Error::add_error(
646
-                    sprintf(
647
-                        esc_html__(
648
-                            'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
649
-                            'event_espresso'
650
-                        ),
651
-                        'Event Espresso',
652
-                        $url_base,
653
-                        'plugins_url',
654
-                        'WP_PLUGIN_URL'
655
-                    ),
656
-                    __FILE__,
657
-                    __FUNCTION__,
658
-                    __LINE__
659
-                );
660
-            }
661
-            return;
662
-        }
663
-        $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
664
-        if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
665
-            $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
666
-        }
667
-        if (! isset($this->manifest_data[ $namespace ]['path'])) {
668
-            $this->manifest_data[ $namespace ]['path'] = $manifest_file_path;
669
-        }
670
-    }
671
-
672
-
673
-    /**
674
-     * Decodes json from the provided manifest file.
675
-     *
676
-     * @since 4.9.59.p
677
-     * @param string $manifest_file Path to manifest file.
678
-     * @return array
679
-     * @throws InvalidFilePathException
680
-     */
681
-    private function decodeManifestFile($manifest_file)
682
-    {
683
-        if (! file_exists($manifest_file)) {
684
-            throw new InvalidFilePathException($manifest_file);
685
-        }
686
-        return json_decode(file_get_contents($manifest_file), true);
687
-    }
688
-
689
-
690
-    /**
691
-     * This is used to set registered script handles that have data.
692
-     *
693
-     * @param string $script_handle
694
-     */
695
-    private function addRegisteredScriptHandlesWithData($script_handle)
696
-    {
697
-        $this->script_handles_with_data[ $script_handle ] = $script_handle;
698
-    }
699
-
700
-
701
-    /**i
419
+						'event_espresso'
420
+					),
421
+					$key
422
+				)
423
+			);
424
+		}
425
+		return true;
426
+	}
427
+
428
+
429
+	/**
430
+	 * Get the actual asset path for asset manifests.
431
+	 * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
432
+	 *
433
+	 * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
434
+	 *                           asset file location.
435
+	 * @param string $chunk_name
436
+	 * @param string $asset_type
437
+	 * @return string
438
+	 * @since 4.9.59.p
439
+	 */
440
+	public function getAssetUrl($namespace, $chunk_name, $asset_type)
441
+	{
442
+		$url = isset(
443
+			$this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
444
+			$this->manifest_data[ $namespace ]['url_base']
445
+		)
446
+			? $this->manifest_data[ $namespace ]['url_base']
447
+			  . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
448
+			: $chunk_name;
449
+
450
+		return apply_filters(
451
+			'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
452
+			$url,
453
+			$namespace,
454
+			$chunk_name,
455
+			$asset_type
456
+		);
457
+	}
458
+
459
+
460
+
461
+	/**
462
+	 * Return the url to a js file for the given namespace and chunk name.
463
+	 *
464
+	 * @param string $namespace
465
+	 * @param string $chunk_name
466
+	 * @return string
467
+	 */
468
+	public function getJsUrl($namespace, $chunk_name)
469
+	{
470
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
471
+	}
472
+
473
+
474
+	/**
475
+	 * Return the url to a css file for the given namespace and chunk name.
476
+	 *
477
+	 * @param string $namespace
478
+	 * @param string $chunk_name
479
+	 * @return string
480
+	 */
481
+	public function getCssUrl($namespace, $chunk_name)
482
+	{
483
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
484
+	}
485
+
486
+
487
+	/**
488
+	 * Return the dependencies for a given asset $chunk_name
489
+	 *
490
+	 * @param string $namespace
491
+	 * @param string $chunk_name
492
+	 * @param string $asset_type
493
+	 * @return array
494
+	 * @since 4.9.82.p
495
+	 */
496
+	private function getDependenciesForAsset($namespace, $chunk_name, $asset_type)
497
+	{
498
+		$asset_index = $chunk_name . '.' . $asset_type;
499
+		if (! isset( $this->dependencies_data[ $namespace ][ $asset_index ])) {
500
+			$path = isset($this->manifest_data[ $namespace ]['path'])
501
+				? $this->manifest_data[ $namespace ]['path']
502
+				: '';
503
+			$dependencies_index = $chunk_name . '.' . Asset::TYPE_JSON;
504
+			$file_path = isset($this->manifest_data[ $namespace ][ $dependencies_index ])
505
+				? $path . $this->manifest_data[ $namespace ][ $dependencies_index ]
506
+				:
507
+				'';
508
+			$this->dependencies_data[ $namespace ][ $asset_index ] = $file_path !== '' && file_exists($file_path)
509
+				? $this->getDependenciesForAssetType($namespace, $asset_type, $file_path, $chunk_name)
510
+				: [];
511
+		}
512
+		return $this->dependencies_data[ $namespace ][ $asset_index ];
513
+	}
514
+
515
+
516
+	/**
517
+	 * Return dependencies according to asset type.
518
+	 *
519
+	 * For css assets, this filters the auto generated dependencies by css type.
520
+	 *
521
+	 * @param string $namespace
522
+	 * @param string $asset_type
523
+	 * @param string $file_path
524
+	 * @param string $chunk_name
525
+	 * @return array
526
+	 * @since 4.9.82.p
527
+	 */
528
+	private function getDependenciesForAssetType($namespace, $asset_type, $file_path, $chunk_name)
529
+	{
530
+		$asset_dependencies = json_decode(file_get_contents($file_path), true);
531
+		if ($asset_type === Asset::TYPE_JS) {
532
+			return $chunk_name === 'eejs-core' ? $asset_dependencies : array_merge(
533
+				$asset_dependencies,
534
+				[ CoreAssetManager::JS_HANDLE_JS_CORE ]
535
+			);
536
+		}
537
+		// for css we need to make sure there is actually a css file related to this chunk.
538
+		if (isset($this->manifest_data[ $namespace ])) {
539
+			// array of css chunk files for ee.
540
+			$css_chunks = array_map(
541
+				function ($value) {
542
+					return str_replace('.css', '', $value);
543
+				},
544
+				array_filter(
545
+					array_keys($this->manifest_data[ $namespace ]),
546
+					function ($value) {
547
+						return strpos($value, '.css') !== false;
548
+					}
549
+				)
550
+			);
551
+			// add known wp chunks with css
552
+			$css_chunks = array_merge( $css_chunks, $this->wp_css_handle_dependencies);
553
+			// flip for easier search
554
+			$css_chunks = array_flip($css_chunks);
555
+
556
+			// now let's filter the dependencies for the incoming chunk to actual chunks that have styles
557
+			return array_filter(
558
+				$asset_dependencies,
559
+				function ($chunk_name) use ($css_chunks) {
560
+					return isset($css_chunks[ $chunk_name ]);
561
+				}
562
+			);
563
+		}
564
+		return [];
565
+	}
566
+
567
+
568
+	/**
569
+	 * Get the dependencies array for the given js asset chunk name
570
+	 *
571
+	 * @param string $namespace
572
+	 * @param string $chunk_name
573
+	 * @return array
574
+	 * @since 4.9.82.p
575
+	 */
576
+	public function getJsDependencies($namespace, $chunk_name)
577
+	{
578
+		return $this->getDependenciesForAsset($namespace, $chunk_name, Asset::TYPE_JS);
579
+	}
580
+
581
+
582
+	/**
583
+	 * Get the dependencies array for the given css asset chunk name
584
+	 *
585
+	 * @param string $namespace
586
+	 * @param string $chunk_name
587
+	 * @return array
588
+	 * @since 4.9.82.p
589
+	 */
590
+	public function getCssDependencies($namespace, $chunk_name)
591
+	{
592
+		return $this->getDependenciesForAsset($namespace, $chunk_name, Asset::TYPE_CSS);
593
+	}
594
+
595
+
596
+	/**
597
+	 * @since 4.9.62.p
598
+	 * @throws InvalidArgumentException
599
+	 * @throws InvalidFilePathException
600
+	 */
601
+	public function registerManifestFiles()
602
+	{
603
+		$manifest_files = $this->assets->getManifestFiles();
604
+		foreach ($manifest_files as $manifest_file) {
605
+			$this->registerManifestFile(
606
+				$manifest_file->assetNamespace(),
607
+				$manifest_file->urlBase(),
608
+				$manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST,
609
+				$manifest_file->filepath()
610
+			);
611
+		}
612
+	}
613
+
614
+
615
+	/**
616
+	 * Used to register a js/css manifest file with the registered_manifest_files property.
617
+	 *
618
+	 * @param string $namespace     Provided to associate the manifest file with a specific namespace.
619
+	 * @param string $url_base      The url base for the manifest file location.
620
+	 * @param string $manifest_file The absolute path to the manifest file.
621
+	 * @param string $manifest_file_path  The path to the folder containing the manifest file. If not provided will be
622
+	 *                                    default to `plugin_root/assets/dist`.
623
+	 * @throws InvalidArgumentException
624
+	 * @throws InvalidFilePathException
625
+	 * @since 4.9.59.p
626
+	 */
627
+	public function registerManifestFile($namespace, $url_base, $manifest_file, $manifest_file_path = '')
628
+	{
629
+		if (isset($this->manifest_data[ $namespace ])) {
630
+			if (! $this->debug()) {
631
+				return;
632
+			}
633
+			throw new InvalidArgumentException(
634
+				sprintf(
635
+					esc_html__(
636
+						'The namespace for this manifest file has already been registered, choose a namespace other than %s',
637
+						'event_espresso'
638
+					),
639
+					$namespace
640
+				)
641
+			);
642
+		}
643
+		if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
644
+			if (is_admin()) {
645
+				EE_Error::add_error(
646
+					sprintf(
647
+						esc_html__(
648
+							'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
649
+							'event_espresso'
650
+						),
651
+						'Event Espresso',
652
+						$url_base,
653
+						'plugins_url',
654
+						'WP_PLUGIN_URL'
655
+					),
656
+					__FILE__,
657
+					__FUNCTION__,
658
+					__LINE__
659
+				);
660
+			}
661
+			return;
662
+		}
663
+		$this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
664
+		if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
665
+			$this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
666
+		}
667
+		if (! isset($this->manifest_data[ $namespace ]['path'])) {
668
+			$this->manifest_data[ $namespace ]['path'] = $manifest_file_path;
669
+		}
670
+	}
671
+
672
+
673
+	/**
674
+	 * Decodes json from the provided manifest file.
675
+	 *
676
+	 * @since 4.9.59.p
677
+	 * @param string $manifest_file Path to manifest file.
678
+	 * @return array
679
+	 * @throws InvalidFilePathException
680
+	 */
681
+	private function decodeManifestFile($manifest_file)
682
+	{
683
+		if (! file_exists($manifest_file)) {
684
+			throw new InvalidFilePathException($manifest_file);
685
+		}
686
+		return json_decode(file_get_contents($manifest_file), true);
687
+	}
688
+
689
+
690
+	/**
691
+	 * This is used to set registered script handles that have data.
692
+	 *
693
+	 * @param string $script_handle
694
+	 */
695
+	private function addRegisteredScriptHandlesWithData($script_handle)
696
+	{
697
+		$this->script_handles_with_data[ $script_handle ] = $script_handle;
698
+	}
699
+
700
+
701
+	/**i
702 702
      * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
703 703
      * Dependency stored in WP_Scripts if its set.
704 704
      */
705
-    private function removeAlreadyRegisteredDataForScriptHandles()
706
-    {
707
-        if (empty($this->script_handles_with_data)) {
708
-            return;
709
-        }
710
-        foreach ($this->script_handles_with_data as $script_handle) {
711
-            $this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
712
-        }
713
-    }
714
-
715
-
716
-    /**
717
-     * Removes any data dependency registered in WP_Scripts if its set.
718
-     *
719
-     * @param string $script_handle
720
-     */
721
-    private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
722
-    {
723
-        if (isset($this->script_handles_with_data[ $script_handle ])) {
724
-            global $wp_scripts;
725
-            $unset_handle = false;
726
-            if ($wp_scripts->get_data($script_handle, 'data')) {
727
-                unset($wp_scripts->registered[ $script_handle ]->extra['data']);
728
-                $unset_handle = true;
729
-            }
730
-            //deal with inline_scripts
731
-            if ($wp_scripts->get_data($script_handle, 'before')) {
732
-                unset($wp_scripts->registered[ $script_handle ]->extra['before']);
733
-                $unset_handle = true;
734
-            }
735
-            if ($wp_scripts->get_data($script_handle, 'after')) {
736
-                unset($wp_scripts->registered[ $script_handle ]->extra['after']);
737
-            }
738
-            if ($unset_handle) {
739
-                unset($this->script_handles_with_data[ $script_handle ]);
740
-            }
741
-        }
742
-    }
743
-
744
-
745
-    /**
746
-     * register translations for a registered script
747
-     *
748
-     * @param string $handle
749
-     */
750
-    public function registerTranslation($handle)
751
-    {
752
-        $this->i18n_registry->registerScriptI18n($handle);
753
-    }
754
-
755
-
756
-    /**
757
-     * @since 4.9.63.p
758
-     * @return bool
759
-     */
760
-    private function debug()
761
-    {
762
-        return apply_filters(
763
-            'FHEE__EventEspresso_core_services_assets_Registry__debug',
764
-            defined('EE_DEBUG') && EE_DEBUG
765
-        );
766
-    }
705
+	private function removeAlreadyRegisteredDataForScriptHandles()
706
+	{
707
+		if (empty($this->script_handles_with_data)) {
708
+			return;
709
+		}
710
+		foreach ($this->script_handles_with_data as $script_handle) {
711
+			$this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
712
+		}
713
+	}
714
+
715
+
716
+	/**
717
+	 * Removes any data dependency registered in WP_Scripts if its set.
718
+	 *
719
+	 * @param string $script_handle
720
+	 */
721
+	private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
722
+	{
723
+		if (isset($this->script_handles_with_data[ $script_handle ])) {
724
+			global $wp_scripts;
725
+			$unset_handle = false;
726
+			if ($wp_scripts->get_data($script_handle, 'data')) {
727
+				unset($wp_scripts->registered[ $script_handle ]->extra['data']);
728
+				$unset_handle = true;
729
+			}
730
+			//deal with inline_scripts
731
+			if ($wp_scripts->get_data($script_handle, 'before')) {
732
+				unset($wp_scripts->registered[ $script_handle ]->extra['before']);
733
+				$unset_handle = true;
734
+			}
735
+			if ($wp_scripts->get_data($script_handle, 'after')) {
736
+				unset($wp_scripts->registered[ $script_handle ]->extra['after']);
737
+			}
738
+			if ($unset_handle) {
739
+				unset($this->script_handles_with_data[ $script_handle ]);
740
+			}
741
+		}
742
+	}
743
+
744
+
745
+	/**
746
+	 * register translations for a registered script
747
+	 *
748
+	 * @param string $handle
749
+	 */
750
+	public function registerTranslation($handle)
751
+	{
752
+		$this->i18n_registry->registerScriptI18n($handle);
753
+	}
754
+
755
+
756
+	/**
757
+	 * @since 4.9.63.p
758
+	 * @return bool
759
+	 */
760
+	private function debug()
761
+	{
762
+		return apply_filters(
763
+			'FHEE__EventEspresso_core_services_assets_Registry__debug',
764
+			defined('EE_DEBUG') && EE_DEBUG
765
+		);
766
+	}
767 767
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 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
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
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.83.rc.002');
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.83.rc.002');
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.