Completed
Branch ENH/contextual-event-check-in-... (d32e27)
by
unknown
04:02 queued 23s
created
modules/ticket_selector/DisplayTicketSelector.php 2 patches
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -155,11 +155,11 @@  discard block
 block discarded – undo
155 155
             }
156 156
         } else {
157 157
             $user_msg = esc_html__('No Event object or an invalid Event object was supplied.', 'event_espresso');
158
-            $dev_msg  = $user_msg . esc_html__(
158
+            $dev_msg  = $user_msg.esc_html__(
159 159
                 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
160 160
                 'event_espresso'
161 161
             );
162
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
162
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
163 163
             return false;
164 164
         }
165 165
         return true;
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
         // reset filter for displaying submit button
223 223
         remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
224 224
         // poke and prod incoming event till it tells us what it is
225
-        if (! $this->setEvent($event)) {
225
+        if ( ! $this->setEvent($event)) {
226 226
             return $this->handleMissingEvent();
227 227
         }
228 228
         // is the event expired ?
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
             : $this->loadTicketSelector($tickets, $template_args);
266 266
         // now set up the form (but not for the admin)
267 267
         $ticket_selector = $this->display_full_ui()
268
-            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
268
+            ? $this->formOpen($this->event->ID(), $external_url).$ticket_selector
269 269
             : $ticket_selector;
270 270
         // submit button and form close tag
271 271
         $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : '';
@@ -313,10 +313,10 @@  discard block
 block discarded – undo
313 313
      */
314 314
     protected function expiredEventMessage()
315 315
     {
316
-        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
316
+        return '<div class="ee-event-expired-notice"><span class="important-notice">'.esc_html__(
317 317
             'We\'re sorry, but all tickets sales have ended because the event is expired.',
318 318
             'event_espresso'
319
-        ) . '</span></div><!-- .ee-event-expired-notice -->';
319
+        ).'</span></div><!-- .ee-event-expired-notice -->';
320 320
     }
321 321
 
322 322
 
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
         }
348 348
         return '
349 349
             <div class="ee-event-expired-notice">
350
-                <span class="important-notice">' . $no_ticket_available_msg . '</span>
350
+                <span class="important-notice">' . $no_ticket_available_msg.'</span>
351 351
             </div><!-- .ee-event-expired-notice -->';
352 352
     }
353 353
 
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
                 '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
381 381
             );
382 382
         }
383
-        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
383
+        return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>';
384 384
     }
385 385
 
386 386
 
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
                 'Datetime.DTT_EVT_start' => 'DESC',
409 409
             ],
410 410
         ];
411
-        if (! $show_expired_tickets) {
411
+        if ( ! $show_expired_tickets) {
412 412
             // use the correct applicable time query depending on what version of core is being run.
413 413
             $current_time                         = method_exists('EEM_Datetime', 'current_time_for_query')
414 414
                 ? time()
@@ -445,9 +445,9 @@  discard block
 block discarded – undo
445 445
          * @param int $EVT_ID The Event ID
446 446
          * @since 4.9.13
447 447
          */
448
-        $template_args['anchor_id']    = apply_filters(
448
+        $template_args['anchor_id'] = apply_filters(
449 449
             'FHEE__EE_Ticket_Selector__redirect_anchor_id',
450
-            '#tkt-slctr-tbl-' . $this->event->ID(),
450
+            '#tkt-slctr-tbl-'.$this->event->ID(),
451 451
             $this->event->ID()
452 452
         );
453 453
         $template_args['tickets']      = $tickets;
@@ -539,30 +539,30 @@  discard block
 block discarded – undo
539 539
         // if redirecting, we don't need any anything else
540 540
         if ($external_url) {
541 541
             $html = '<form method="GET" ';
542
-            $html .= 'action="' . EEH_URL::refactor_url($external_url) . '" ';
543
-            $html .= 'name="ticket-selector-form-' . $ID . '"';
542
+            $html .= 'action="'.EEH_URL::refactor_url($external_url).'" ';
543
+            $html .= 'name="ticket-selector-form-'.$ID.'"';
544 544
             // open link in new window ?
545
-            $html       .= apply_filters(
545
+            $html .= apply_filters(
546 546
                 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
547 547
                 $this->isIframe(),
548 548
                 $this
549 549
             )
550 550
                 ? ' target="_blank"'
551 551
                 : '';
552
-            $html       .= '>';
552
+            $html .= '>';
553 553
             $query_args = EEH_URL::get_query_string($external_url);
554 554
             foreach ((array) $query_args as $query_arg => $value) {
555
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
555
+                $html .= '<input type="hidden" name="'.$query_arg.'" value="'.$value.'">';
556 556
             }
557 557
             return $html;
558 558
         }
559 559
         // if there is no submit button, then don't start building a form
560 560
         // because the "View Details" button will build its own form
561
-        if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
561
+        if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
562 562
             return '';
563 563
         }
564 564
         $checkout_url = EEH_Event_View::event_link_url($ID);
565
-        if (! $checkout_url) {
565
+        if ( ! $checkout_url) {
566 566
             EE_Error::add_error(
567 567
                 esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
568 568
                 __FILE__,
@@ -573,8 +573,8 @@  discard block
 block discarded – undo
573 573
         // set no cache headers and constants
574 574
         EE_System::do_not_cache();
575 575
         $html = '<form method="POST" ';
576
-        $html .= 'action="' . $checkout_url . '" ';
577
-        $html .= 'name="ticket-selector-form-' . $ID . '"';
576
+        $html .= 'action="'.$checkout_url.'" ';
577
+        $html .= 'name="ticket-selector-form-'.$ID.'"';
578 578
         $html .= $this->iframe ? ' target="_blank"' : '';
579 579
         $html .= '>';
580 580
         $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
                 $html .= empty($external_url)
601 601
                     ? $this->ticketSelectorEndDiv()
602 602
                     : $this->clearTicketSelector();
603
-                $html .= '<br/>' . $this->formClose();
603
+                $html .= '<br/>'.$this->formClose();
604 604
             } elseif ($this->getMaxAttendees() === 1) {
605 605
                 // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
606 606
                 if ($this->event->is_sold_out()) {
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
                 // no submit or view details button, and no additional content
659 659
                 $html .= $this->ticketSelectorEndDiv();
660 660
             }
661
-            if (! $this->iframe && ! is_archive()) {
661
+            if ( ! $this->iframe && ! is_archive()) {
662 662
                 $html .= EEH_Template::powered_by_event_espresso('', '', ['utm_content' => 'ticket_selector']);
663 663
             }
664 664
         }
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
      */
679 679
     public function displayRegisterNowButton()
680 680
     {
681
-        $btn_text     = apply_filters(
681
+        $btn_text = apply_filters(
682 682
             'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
683 683
             esc_html__('Register Now', 'event_espresso'),
684 684
             $this->event
@@ -687,16 +687,16 @@  discard block
 block discarded – undo
687 687
                         && $this->event->external_url() !== get_the_permalink()
688 688
             ? $this->event->external_url()
689 689
             : '';
690
-        $html         = EEH_HTML::div(
690
+        $html = EEH_HTML::div(
691 691
             '',
692
-            'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap',
692
+            'ticket-selector-submit-'.$this->event->ID().'-btn-wrap',
693 693
             'ticket-selector-submit-btn-wrap'
694 694
         );
695
-        $html         .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
695
+        $html         .= '<input id="ticket-selector-submit-'.$this->event->ID().'-btn"';
696 696
         $html         .= ' class="ticket-selector-submit-btn ';
697 697
         $html         .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
698
-        $html         .= ' type="submit" value="' . $btn_text . '" data-ee-disable-after-recaptcha="true" />';
699
-        $html         .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
698
+        $html         .= ' type="submit" value="'.$btn_text.'" data-ee-disable-after-recaptcha="true" />';
699
+        $html         .= EEH_HTML::divx().'<!-- .ticket-selector-submit-btn-wrap -->';
700 700
         $html         .= apply_filters(
701 701
             'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
702 702
             '',
@@ -720,7 +720,7 @@  discard block
 block discarded – undo
720 720
      */
721 721
     public function displayViewDetailsButton($DWMTS = false)
722 722
     {
723
-        if (! $this->event->get_permalink()) {
723
+        if ( ! $this->event->get_permalink()) {
724 724
             EE_Error::add_error(
725 725
                 esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
726 726
                 __FILE__,
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
             ? ' target="_blank"'
745 745
             : '';
746 746
         $view_details_btn .= '>';
747
-        $btn_text         = apply_filters(
747
+        $btn_text = apply_filters(
748 748
             'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
749 749
             esc_html__('View Details', 'event_espresso'),
750 750
             $this->event
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
      */
774 774
     public function ticketSelectorEndDiv()
775 775
     {
776
-        return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
776
+        return $this->clearTicketSelector().'</div><!-- ticketSelectorEndDiv -->';
777 777
     }
778 778
 
779 779
 
@@ -809,7 +809,7 @@  discard block
 block discarded – undo
809 809
     protected function handleMissingEvent()
810 810
     {
811 811
         // If this is not an iFrame request, simply return false.
812
-        if (! $this->isIframe()) {
812
+        if ( ! $this->isIframe()) {
813 813
             return '';
814 814
         }
815 815
         // This is an iFrame so return an error.
Please login to merge, or discard this patch.
Indentation   +810 added lines, -810 removed lines patch added patch discarded remove patch
@@ -39,817 +39,817 @@
 block discarded – undo
39 39
  */
40 40
 class DisplayTicketSelector
41 41
 {
42
-    /**
43
-     * @var RequestInterface
44
-     */
45
-    protected $request;
46
-
47
-    /**
48
-     * @var EE_Ticket_Selector_Config
49
-     */
50
-    protected $config;
51
-
52
-    /**
53
-     * event that ticket selector is being generated for
54
-     *
55
-     * @access protected
56
-     * @var EE_Event $event
57
-     */
58
-    protected $event;
59
-
60
-    /**
61
-     * Used to flag when the ticket selector is being called from an external iframe.
62
-     *
63
-     * @var bool $iframe
64
-     */
65
-    protected $iframe = false;
66
-
67
-    /**
68
-     * max attendees that can register for event at one time
69
-     *
70
-     * @var int $max_attendees
71
-     */
72
-    private $max_attendees = EE_INF;
73
-
74
-    /**
75
-     * @var string $date_format
76
-     */
77
-    private $date_format;
78
-
79
-    /**
80
-     * @var string $time_format
81
-     */
82
-    private $time_format;
83
-
84
-    /**
85
-     * @var boolean $display_full_ui
86
-     */
87
-    private $display_full_ui;
88
-
89
-
90
-    /**
91
-     * DisplayTicketSelector constructor.
92
-     *
93
-     * @param RequestInterface          $request
94
-     * @param EE_Ticket_Selector_Config $config
95
-     * @param bool                      $iframe
96
-     */
97
-    public function __construct(RequestInterface $request, EE_Ticket_Selector_Config $config, $iframe = false)
98
-    {
99
-        $this->request     = $request;
100
-        $this->config      = $config;
101
-        $this->iframe      = $iframe;
102
-        $this->date_format = apply_filters(
103
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
104
-            get_option('date_format')
105
-        );
106
-        $this->time_format = apply_filters(
107
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
108
-            get_option('time_format')
109
-        );
110
-    }
111
-
112
-
113
-    /**
114
-     * @return bool
115
-     */
116
-    public function isIframe()
117
-    {
118
-        return $this->iframe;
119
-    }
120
-
121
-
122
-    /**
123
-     * @param boolean $iframe
124
-     */
125
-    public function setIframe($iframe = true)
126
-    {
127
-        $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN);
128
-    }
129
-
130
-
131
-    /**
132
-     * finds and sets the \EE_Event object for use throughout class
133
-     *
134
-     * @param mixed $event
135
-     * @return bool
136
-     * @throws EE_Error
137
-     * @throws InvalidDataTypeException
138
-     * @throws InvalidInterfaceException
139
-     * @throws InvalidArgumentException
140
-     */
141
-    protected function setEvent($event = null)
142
-    {
143
-        if ($event === null) {
144
-            global $post;
145
-            $event = $post;
146
-        }
147
-        if ($event instanceof EE_Event) {
148
-            $this->event = $event;
149
-        } elseif ($event instanceof WP_Post) {
150
-            if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
151
-                $this->event = $event->EE_Event;
152
-            } elseif ($event->post_type === 'espresso_events') {
153
-                $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
154
-                $this->event     = $event->EE_Event;
155
-            }
156
-        } else {
157
-            $user_msg = esc_html__('No Event object or an invalid Event object was supplied.', 'event_espresso');
158
-            $dev_msg  = $user_msg . esc_html__(
159
-                'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
160
-                'event_espresso'
161
-            );
162
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
163
-            return false;
164
-        }
165
-        return true;
166
-    }
167
-
168
-
169
-    /**
170
-     * @return int
171
-     */
172
-    public function getMaxAttendees()
173
-    {
174
-        return $this->max_attendees;
175
-    }
176
-
177
-
178
-    /**
179
-     * @param int $max_attendees
180
-     */
181
-    public function setMaxAttendees($max_attendees)
182
-    {
183
-        $this->max_attendees = absint(
184
-            apply_filters(
185
-                'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
186
-                $max_attendees
187
-            )
188
-        );
189
-    }
190
-
191
-
192
-    /**
193
-     * Returns whether or not the full ticket selector should be shown or not.
194
-     * Currently, it displays on the frontend (including ajax requests) but not the backend
195
-     *
196
-     * @return bool
197
-     */
198
-    private function display_full_ui()
199
-    {
200
-        if ($this->display_full_ui === null) {
201
-            $this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX);
202
-        }
203
-        return $this->display_full_ui;
204
-    }
205
-
206
-
207
-    /**
208
-     * creates buttons for selecting number of attendees for an event
209
-     *
210
-     * @param WP_Post|int $event
211
-     * @param bool        $view_details
212
-     * @return string
213
-     * @throws EE_Error
214
-     * @throws InvalidArgumentException
215
-     * @throws InvalidDataTypeException
216
-     * @throws InvalidInterfaceException
217
-     * @throws ReflectionException
218
-     * @throws Exception
219
-     */
220
-    public function display($event = null, $view_details = false)
221
-    {
222
-        // reset filter for displaying submit button
223
-        remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
224
-        // poke and prod incoming event till it tells us what it is
225
-        if (! $this->setEvent($event)) {
226
-            return $this->handleMissingEvent();
227
-        }
228
-        // is the event expired ?
229
-        $template_args['event_is_expired'] = ! is_admin() && $this->event->is_expired();
230
-        if ($template_args['event_is_expired']) {
231
-            return is_single()
232
-                ? $this->expiredEventMessage()
233
-                : $this->expiredEventMessage()
234
-                  . $this->displayViewDetailsButton();
235
-        }
236
-        // begin gathering template arguments by getting event status
237
-        $template_args = ['event_status' => $this->event->get_active_status()];
238
-        if (
239
-            $this->activeEventAndShowTicketSelector(
240
-                $event,
241
-                $template_args['event_status'],
242
-                $view_details
243
-            )
244
-        ) {
245
-            return ! is_single() ? $this->displayViewDetailsButton() : '';
246
-        }
247
-        // filter the maximum qty that can appear in the Ticket Selector qty dropdowns
248
-        $this->setMaxAttendees($this->event->additional_limit());
249
-        if ($this->getMaxAttendees() < 1) {
250
-            return $this->ticketSalesClosedMessage();
251
-        }
252
-        // get all tickets for this event ordered by the datetime
253
-        $tickets = $this->getTickets();
254
-        if (count($tickets) < 1) {
255
-            return $this->noTicketAvailableMessage();
256
-        }
257
-        // redirecting to another site for registration ??
258
-        $external_url = (string) $this->event->external_url()
259
-                        && $this->event->external_url() !== get_the_permalink()
260
-            ? $this->event->external_url()
261
-            : '';
262
-        // if redirecting to another site for registration, then we don't load the TS
263
-        $ticket_selector = $external_url
264
-            ? $this->externalEventRegistration()
265
-            : $this->loadTicketSelector($tickets, $template_args);
266
-        // now set up the form (but not for the admin)
267
-        $ticket_selector = $this->display_full_ui()
268
-            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
269
-            : $ticket_selector;
270
-        // submit button and form close tag
271
-        $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : '';
272
-        return $ticket_selector;
273
-    }
274
-
275
-
276
-    /**
277
-     * displayTicketSelector
278
-     * examines the event properties and determines whether a Ticket Selector should be displayed
279
-     *
280
-     * @param WP_Post|int $event
281
-     * @param string      $_event_active_status
282
-     * @param bool        $view_details
283
-     * @return bool
284
-     * @throws EE_Error
285
-     * @throws ReflectionException
286
-     */
287
-    protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
288
-    {
289
-        $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
290
-        return $this->display_full_ui()
291
-               && (
292
-                   ! $this->event->display_ticket_selector()
293
-                   || $view_details
294
-                   || post_password_required($event_post)
295
-                   || (
296
-                       $_event_active_status !== EE_Datetime::active
297
-                       && $_event_active_status !== EE_Datetime::upcoming
298
-                       && $_event_active_status !== EE_Datetime::sold_out
299
-                       && ! (
300
-                           $_event_active_status === EE_Datetime::inactive
301
-                           && is_user_logged_in()
302
-                       )
303
-                   )
304
-               );
305
-    }
306
-
307
-
308
-    /**
309
-     * noTicketAvailableMessage
310
-     * notice displayed if event is expired
311
-     *
312
-     * @return string
313
-     */
314
-    protected function expiredEventMessage()
315
-    {
316
-        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
317
-            'We\'re sorry, but all tickets sales have ended because the event is expired.',
318
-            'event_espresso'
319
-        ) . '</span></div><!-- .ee-event-expired-notice -->';
320
-    }
321
-
322
-
323
-    /**
324
-     * noTicketAvailableMessage
325
-     * notice displayed if event has no more tickets available
326
-     *
327
-     * @return string
328
-     * @throws EE_Error
329
-     * @throws ReflectionException
330
-     */
331
-    protected function noTicketAvailableMessage()
332
-    {
333
-        $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso');
334
-        if (current_user_can('edit_post', $this->event->ID())) {
335
-            $no_ticket_available_msg .= sprintf(
336
-                esc_html__(
337
-                    '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
338
-                    'event_espresso'
339
-                ),
340
-                '<div class="ee-attention" style="text-align: left;"><b>',
341
-                '</b><br />',
342
-                '<span class="edit-link"><a class="post-edit-link" href="'
343
-                . get_edit_post_link($this->event->ID())
344
-                . '">',
345
-                '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
346
-            );
347
-        }
348
-        return '
42
+	/**
43
+	 * @var RequestInterface
44
+	 */
45
+	protected $request;
46
+
47
+	/**
48
+	 * @var EE_Ticket_Selector_Config
49
+	 */
50
+	protected $config;
51
+
52
+	/**
53
+	 * event that ticket selector is being generated for
54
+	 *
55
+	 * @access protected
56
+	 * @var EE_Event $event
57
+	 */
58
+	protected $event;
59
+
60
+	/**
61
+	 * Used to flag when the ticket selector is being called from an external iframe.
62
+	 *
63
+	 * @var bool $iframe
64
+	 */
65
+	protected $iframe = false;
66
+
67
+	/**
68
+	 * max attendees that can register for event at one time
69
+	 *
70
+	 * @var int $max_attendees
71
+	 */
72
+	private $max_attendees = EE_INF;
73
+
74
+	/**
75
+	 * @var string $date_format
76
+	 */
77
+	private $date_format;
78
+
79
+	/**
80
+	 * @var string $time_format
81
+	 */
82
+	private $time_format;
83
+
84
+	/**
85
+	 * @var boolean $display_full_ui
86
+	 */
87
+	private $display_full_ui;
88
+
89
+
90
+	/**
91
+	 * DisplayTicketSelector constructor.
92
+	 *
93
+	 * @param RequestInterface          $request
94
+	 * @param EE_Ticket_Selector_Config $config
95
+	 * @param bool                      $iframe
96
+	 */
97
+	public function __construct(RequestInterface $request, EE_Ticket_Selector_Config $config, $iframe = false)
98
+	{
99
+		$this->request     = $request;
100
+		$this->config      = $config;
101
+		$this->iframe      = $iframe;
102
+		$this->date_format = apply_filters(
103
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
104
+			get_option('date_format')
105
+		);
106
+		$this->time_format = apply_filters(
107
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
108
+			get_option('time_format')
109
+		);
110
+	}
111
+
112
+
113
+	/**
114
+	 * @return bool
115
+	 */
116
+	public function isIframe()
117
+	{
118
+		return $this->iframe;
119
+	}
120
+
121
+
122
+	/**
123
+	 * @param boolean $iframe
124
+	 */
125
+	public function setIframe($iframe = true)
126
+	{
127
+		$this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN);
128
+	}
129
+
130
+
131
+	/**
132
+	 * finds and sets the \EE_Event object for use throughout class
133
+	 *
134
+	 * @param mixed $event
135
+	 * @return bool
136
+	 * @throws EE_Error
137
+	 * @throws InvalidDataTypeException
138
+	 * @throws InvalidInterfaceException
139
+	 * @throws InvalidArgumentException
140
+	 */
141
+	protected function setEvent($event = null)
142
+	{
143
+		if ($event === null) {
144
+			global $post;
145
+			$event = $post;
146
+		}
147
+		if ($event instanceof EE_Event) {
148
+			$this->event = $event;
149
+		} elseif ($event instanceof WP_Post) {
150
+			if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
151
+				$this->event = $event->EE_Event;
152
+			} elseif ($event->post_type === 'espresso_events') {
153
+				$event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
154
+				$this->event     = $event->EE_Event;
155
+			}
156
+		} else {
157
+			$user_msg = esc_html__('No Event object or an invalid Event object was supplied.', 'event_espresso');
158
+			$dev_msg  = $user_msg . esc_html__(
159
+				'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
160
+				'event_espresso'
161
+			);
162
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
163
+			return false;
164
+		}
165
+		return true;
166
+	}
167
+
168
+
169
+	/**
170
+	 * @return int
171
+	 */
172
+	public function getMaxAttendees()
173
+	{
174
+		return $this->max_attendees;
175
+	}
176
+
177
+
178
+	/**
179
+	 * @param int $max_attendees
180
+	 */
181
+	public function setMaxAttendees($max_attendees)
182
+	{
183
+		$this->max_attendees = absint(
184
+			apply_filters(
185
+				'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
186
+				$max_attendees
187
+			)
188
+		);
189
+	}
190
+
191
+
192
+	/**
193
+	 * Returns whether or not the full ticket selector should be shown or not.
194
+	 * Currently, it displays on the frontend (including ajax requests) but not the backend
195
+	 *
196
+	 * @return bool
197
+	 */
198
+	private function display_full_ui()
199
+	{
200
+		if ($this->display_full_ui === null) {
201
+			$this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX);
202
+		}
203
+		return $this->display_full_ui;
204
+	}
205
+
206
+
207
+	/**
208
+	 * creates buttons for selecting number of attendees for an event
209
+	 *
210
+	 * @param WP_Post|int $event
211
+	 * @param bool        $view_details
212
+	 * @return string
213
+	 * @throws EE_Error
214
+	 * @throws InvalidArgumentException
215
+	 * @throws InvalidDataTypeException
216
+	 * @throws InvalidInterfaceException
217
+	 * @throws ReflectionException
218
+	 * @throws Exception
219
+	 */
220
+	public function display($event = null, $view_details = false)
221
+	{
222
+		// reset filter for displaying submit button
223
+		remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
224
+		// poke and prod incoming event till it tells us what it is
225
+		if (! $this->setEvent($event)) {
226
+			return $this->handleMissingEvent();
227
+		}
228
+		// is the event expired ?
229
+		$template_args['event_is_expired'] = ! is_admin() && $this->event->is_expired();
230
+		if ($template_args['event_is_expired']) {
231
+			return is_single()
232
+				? $this->expiredEventMessage()
233
+				: $this->expiredEventMessage()
234
+				  . $this->displayViewDetailsButton();
235
+		}
236
+		// begin gathering template arguments by getting event status
237
+		$template_args = ['event_status' => $this->event->get_active_status()];
238
+		if (
239
+			$this->activeEventAndShowTicketSelector(
240
+				$event,
241
+				$template_args['event_status'],
242
+				$view_details
243
+			)
244
+		) {
245
+			return ! is_single() ? $this->displayViewDetailsButton() : '';
246
+		}
247
+		// filter the maximum qty that can appear in the Ticket Selector qty dropdowns
248
+		$this->setMaxAttendees($this->event->additional_limit());
249
+		if ($this->getMaxAttendees() < 1) {
250
+			return $this->ticketSalesClosedMessage();
251
+		}
252
+		// get all tickets for this event ordered by the datetime
253
+		$tickets = $this->getTickets();
254
+		if (count($tickets) < 1) {
255
+			return $this->noTicketAvailableMessage();
256
+		}
257
+		// redirecting to another site for registration ??
258
+		$external_url = (string) $this->event->external_url()
259
+						&& $this->event->external_url() !== get_the_permalink()
260
+			? $this->event->external_url()
261
+			: '';
262
+		// if redirecting to another site for registration, then we don't load the TS
263
+		$ticket_selector = $external_url
264
+			? $this->externalEventRegistration()
265
+			: $this->loadTicketSelector($tickets, $template_args);
266
+		// now set up the form (but not for the admin)
267
+		$ticket_selector = $this->display_full_ui()
268
+			? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
269
+			: $ticket_selector;
270
+		// submit button and form close tag
271
+		$ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : '';
272
+		return $ticket_selector;
273
+	}
274
+
275
+
276
+	/**
277
+	 * displayTicketSelector
278
+	 * examines the event properties and determines whether a Ticket Selector should be displayed
279
+	 *
280
+	 * @param WP_Post|int $event
281
+	 * @param string      $_event_active_status
282
+	 * @param bool        $view_details
283
+	 * @return bool
284
+	 * @throws EE_Error
285
+	 * @throws ReflectionException
286
+	 */
287
+	protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
288
+	{
289
+		$event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
290
+		return $this->display_full_ui()
291
+			   && (
292
+				   ! $this->event->display_ticket_selector()
293
+				   || $view_details
294
+				   || post_password_required($event_post)
295
+				   || (
296
+					   $_event_active_status !== EE_Datetime::active
297
+					   && $_event_active_status !== EE_Datetime::upcoming
298
+					   && $_event_active_status !== EE_Datetime::sold_out
299
+					   && ! (
300
+						   $_event_active_status === EE_Datetime::inactive
301
+						   && is_user_logged_in()
302
+					   )
303
+				   )
304
+			   );
305
+	}
306
+
307
+
308
+	/**
309
+	 * noTicketAvailableMessage
310
+	 * notice displayed if event is expired
311
+	 *
312
+	 * @return string
313
+	 */
314
+	protected function expiredEventMessage()
315
+	{
316
+		return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
317
+			'We\'re sorry, but all tickets sales have ended because the event is expired.',
318
+			'event_espresso'
319
+		) . '</span></div><!-- .ee-event-expired-notice -->';
320
+	}
321
+
322
+
323
+	/**
324
+	 * noTicketAvailableMessage
325
+	 * notice displayed if event has no more tickets available
326
+	 *
327
+	 * @return string
328
+	 * @throws EE_Error
329
+	 * @throws ReflectionException
330
+	 */
331
+	protected function noTicketAvailableMessage()
332
+	{
333
+		$no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso');
334
+		if (current_user_can('edit_post', $this->event->ID())) {
335
+			$no_ticket_available_msg .= sprintf(
336
+				esc_html__(
337
+					'%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
338
+					'event_espresso'
339
+				),
340
+				'<div class="ee-attention" style="text-align: left;"><b>',
341
+				'</b><br />',
342
+				'<span class="edit-link"><a class="post-edit-link" href="'
343
+				. get_edit_post_link($this->event->ID())
344
+				. '">',
345
+				'</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
346
+			);
347
+		}
348
+		return '
349 349
             <div class="ee-event-expired-notice">
350 350
                 <span class="important-notice">' . $no_ticket_available_msg . '</span>
351 351
             </div><!-- .ee-event-expired-notice -->';
352
-    }
353
-
354
-
355
-    /**
356
-     * ticketSalesClosed
357
-     * notice displayed if event ticket sales are turned off
358
-     *
359
-     * @return string
360
-     * @throws EE_Error
361
-     * @throws ReflectionException
362
-     */
363
-    protected function ticketSalesClosedMessage()
364
-    {
365
-        $sales_closed_msg = esc_html__(
366
-            'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
367
-            'event_espresso'
368
-        );
369
-        if (current_user_can('edit_post', $this->event->ID())) {
370
-            $sales_closed_msg .= sprintf(
371
-                esc_html__(
372
-                    '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
373
-                    'event_espresso'
374
-                ),
375
-                '<div class="ee-attention" style="text-align: left;"><b>',
376
-                '</b><br />',
377
-                '<span class="edit-link"><a class="post-edit-link" href="'
378
-                . get_edit_post_link($this->event->ID())
379
-                . '">',
380
-                '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
381
-            );
382
-        }
383
-        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
384
-    }
385
-
386
-
387
-    /**
388
-     * getTickets
389
-     *
390
-     * @return EE_Base_Class[]|EE_Ticket[]
391
-     * @throws EE_Error
392
-     * @throws InvalidDataTypeException
393
-     * @throws InvalidInterfaceException
394
-     * @throws InvalidArgumentException
395
-     * @throws ReflectionException
396
-     */
397
-    protected function getTickets()
398
-    {
399
-        $show_expired_tickets = is_admin() || $this->config->show_expired_tickets;
400
-
401
-        $ticket_query_args = [
402
-            ['Datetime.EVT_ID' => $this->event->ID()],
403
-            'order_by' => [
404
-                'TKT_order'              => 'ASC',
405
-                'TKT_required'           => 'DESC',
406
-                'TKT_start_date'         => 'ASC',
407
-                'TKT_end_date'           => 'ASC',
408
-                'Datetime.DTT_EVT_start' => 'DESC',
409
-            ],
410
-        ];
411
-        if (! $show_expired_tickets) {
412
-            // use the correct applicable time query depending on what version of core is being run.
413
-            $current_time                         = method_exists('EEM_Datetime', 'current_time_for_query')
414
-                ? time()
415
-                : current_time('timestamp');
416
-            $ticket_query_args[0]['TKT_end_date'] = ['>', $current_time];
417
-        }
418
-        return EEM_Ticket::instance()->get_all($ticket_query_args);
419
-    }
420
-
421
-
422
-    /**
423
-     * loadTicketSelector
424
-     * begins to assemble template arguments
425
-     * and decides whether to load a "simple" ticket selector, or the standard
426
-     *
427
-     * @param EE_Ticket[] $tickets
428
-     * @param array       $template_args
429
-     * @return TicketSelectorSimple|TicketSelectorStandard
430
-     * @throws EE_Error
431
-     * @throws ReflectionException
432
-     */
433
-    protected function loadTicketSelector(array $tickets, array $template_args)
434
-    {
435
-        $template_args['event']            = $this->event;
436
-        $template_args['EVT_ID']           = $this->event->ID();
437
-        $template_args['event_is_expired'] = $this->event->is_expired();
438
-        $template_args['max_atndz']        = $this->getMaxAttendees();
439
-        $template_args['date_format']      = $this->date_format;
440
-        $template_args['time_format']      = $this->time_format;
441
-        /**
442
-         * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
443
-         *
444
-         * @param string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
445
-         * @param int $EVT_ID The Event ID
446
-         * @since 4.9.13
447
-         */
448
-        $template_args['anchor_id']    = apply_filters(
449
-            'FHEE__EE_Ticket_Selector__redirect_anchor_id',
450
-            '#tkt-slctr-tbl-' . $this->event->ID(),
451
-            $this->event->ID()
452
-        );
453
-        $template_args['tickets']      = $tickets;
454
-        $template_args['ticket_count'] = count($tickets);
455
-        $ticket_selector               = $this->simpleTicketSelector($tickets, $template_args);
456
-        if ($ticket_selector instanceof TicketSelectorSimple) {
457
-            return $ticket_selector;
458
-        }
459
-        return new TicketSelectorStandard(
460
-            $this->config,
461
-            $this->getTaxConfig(),
462
-            $this->event,
463
-            $tickets,
464
-            $this->getMaxAttendees(),
465
-            $template_args,
466
-            $this->date_format,
467
-            $this->time_format
468
-        );
469
-    }
470
-
471
-
472
-    /**
473
-     * simpleTicketSelector
474
-     * there's one ticket, and max attendees is set to one,
475
-     * so if the event is free, then this is a "simple" ticket selector
476
-     * a.k.a. "Dude Where's my Ticket Selector?"
477
-     *
478
-     * @param EE_Ticket[] $tickets
479
-     * @param array       $template_args
480
-     * @return string
481
-     * @throws EE_Error
482
-     * @throws ReflectionException
483
-     */
484
-    protected function simpleTicketSelector($tickets, array $template_args)
485
-    {
486
-        // if there is only ONE ticket with a max qty of ONE
487
-        if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
488
-            return '';
489
-        }
490
-        /** @var EE_Ticket $ticket */
491
-        $ticket = reset($tickets);
492
-        // if the ticket is free... then not much need for the ticket selector
493
-        if (
494
-            apply_filters(
495
-                'FHEE__ticket_selector_chart_template__hide_ticket_selector',
496
-                $ticket->is_free(),
497
-                $this->event->ID()
498
-            )
499
-        ) {
500
-            return new TicketSelectorSimple(
501
-                $this->event,
502
-                $ticket,
503
-                $this->getMaxAttendees(),
504
-                $template_args
505
-            );
506
-        }
507
-        return '';
508
-    }
509
-
510
-
511
-    /**
512
-     * externalEventRegistration
513
-     *
514
-     * @return string
515
-     */
516
-    public function externalEventRegistration()
517
-    {
518
-        // if not we still need to trigger the display of the submit button
519
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
520
-        // display notice to admin that registration is external
521
-        return $this->display_full_ui()
522
-            ? esc_html__(
523
-                'Registration is at an external URL for this event.',
524
-                'event_espresso'
525
-            )
526
-            : '';
527
-    }
528
-
529
-
530
-    /**
531
-     * formOpen
532
-     *
533
-     * @param int    $ID
534
-     * @param string $external_url
535
-     * @return        string
536
-     */
537
-    public function formOpen($ID = 0, $external_url = '')
538
-    {
539
-        // if redirecting, we don't need any anything else
540
-        if ($external_url) {
541
-            $html = '<form method="GET" ';
542
-            $html .= 'action="' . EEH_URL::refactor_url($external_url) . '" ';
543
-            $html .= 'name="ticket-selector-form-' . $ID . '"';
544
-            // open link in new window ?
545
-            $html       .= apply_filters(
546
-                'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
547
-                $this->isIframe(),
548
-                $this
549
-            )
550
-                ? ' target="_blank"'
551
-                : '';
552
-            $html       .= '>';
553
-            $query_args = EEH_URL::get_query_string($external_url);
554
-            foreach ((array) $query_args as $query_arg => $value) {
555
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
556
-            }
557
-            return $html;
558
-        }
559
-        // if there is no submit button, then don't start building a form
560
-        // because the "View Details" button will build its own form
561
-        if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
562
-            return '';
563
-        }
564
-        $checkout_url = EEH_Event_View::event_link_url($ID);
565
-        if (! $checkout_url) {
566
-            EE_Error::add_error(
567
-                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
568
-                __FILE__,
569
-                __FUNCTION__,
570
-                __LINE__
571
-            );
572
-        }
573
-        // set no cache headers and constants
574
-        EE_System::do_not_cache();
575
-        $html = '<form method="POST" ';
576
-        $html .= 'action="' . $checkout_url . '" ';
577
-        $html .= 'name="ticket-selector-form-' . $ID . '"';
578
-        $html .= $this->iframe ? ' target="_blank"' : '';
579
-        $html .= '>';
580
-        $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
581
-        return apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event);
582
-    }
583
-
584
-
585
-    /**
586
-     * displaySubmitButton
587
-     *
588
-     * @param string $external_url
589
-     * @return string
590
-     * @throws EE_Error
591
-     * @throws ReflectionException
592
-     */
593
-    public function displaySubmitButton($external_url = '')
594
-    {
595
-        $html = '';
596
-        if ($this->display_full_ui()) {
597
-            // standard TS displayed with submit button, ie: "Register Now"
598
-            if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
599
-                $html .= $this->displayRegisterNowButton();
600
-                $html .= empty($external_url)
601
-                    ? $this->ticketSelectorEndDiv()
602
-                    : $this->clearTicketSelector();
603
-                $html .= '<br/>' . $this->formClose();
604
-            } elseif ($this->getMaxAttendees() === 1) {
605
-                // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
606
-                if ($this->event->is_sold_out()) {
607
-                    // then instead of a View Details or Submit button, just display a "Sold Out" message
608
-                    $html .= apply_filters(
609
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
610
-                        sprintf(
611
-                            esc_html__(
612
-                                '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
613
-                                'event_espresso'
614
-                            ),
615
-                            '<p class="no-ticket-selector-msg clear-float">',
616
-                            $this->event->name(),
617
-                            '</p>',
618
-                            '<br />'
619
-                        ),
620
-                        $this->event
621
-                    );
622
-                    if (
623
-                        apply_filters(
624
-                            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
625
-                            false,
626
-                            $this->event
627
-                        )
628
-                    ) {
629
-                        $html .= $this->displayRegisterNowButton();
630
-                    }
631
-                    // sold out DWMTS event, no TS, no submit or view details button, but has additional content
632
-                    $html .= $this->ticketSelectorEndDiv();
633
-                } elseif (
634
-                    apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
635
-                          && ! is_single()
636
-                ) {
637
-                    // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
638
-                    // but no tickets are available, so display event's "View Details" button.
639
-                    // it is being viewed via somewhere other than a single post
640
-                    $html .= $this->displayViewDetailsButton(true);
641
-                } else {
642
-                    $html .= $this->ticketSelectorEndDiv();
643
-                }
644
-            } elseif (is_archive()) {
645
-                // event list, no tickets available so display event's "View Details" button
646
-                $html .= $this->ticketSelectorEndDiv();
647
-                $html .= $this->displayViewDetailsButton();
648
-            } else {
649
-                if (
650
-                    apply_filters(
651
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
652
-                        false,
653
-                        $this->event
654
-                    )
655
-                ) {
656
-                    $html .= $this->displayRegisterNowButton();
657
-                }
658
-                // no submit or view details button, and no additional content
659
-                $html .= $this->ticketSelectorEndDiv();
660
-            }
661
-            if (! $this->iframe && ! is_archive()) {
662
-                $html .= EEH_Template::powered_by_event_espresso('', '', ['utm_content' => 'ticket_selector']);
663
-            }
664
-        }
665
-        return apply_filters(
666
-            'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
667
-            $html,
668
-            $this->event,
669
-            $this
670
-        );
671
-    }
672
-
673
-
674
-    /**
675
-     * @return string
676
-     * @throws EE_Error
677
-     * @throws ReflectionException
678
-     */
679
-    public function displayRegisterNowButton()
680
-    {
681
-        $btn_text     = apply_filters(
682
-            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
683
-            esc_html__('Register Now', 'event_espresso'),
684
-            $this->event
685
-        );
686
-        $external_url = (string) $this->event->external_url()
687
-                        && $this->event->external_url() !== get_the_permalink()
688
-            ? $this->event->external_url()
689
-            : '';
690
-        $html         = EEH_HTML::div(
691
-            '',
692
-            'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap',
693
-            'ticket-selector-submit-btn-wrap'
694
-        );
695
-        $html         .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
696
-        $html         .= ' class="ticket-selector-submit-btn ';
697
-        $html         .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
698
-        $html         .= ' type="submit" value="' . $btn_text . '" data-ee-disable-after-recaptcha="true" />';
699
-        $html         .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
700
-        $html         .= apply_filters(
701
-            'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
702
-            '',
703
-            $this->event,
704
-            $this->iframe
705
-        );
706
-        return $html;
707
-    }
708
-
709
-
710
-    /**
711
-     * displayViewDetailsButton
712
-     *
713
-     * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
714
-     *                    (ie: $_max_atndz === 1) where there are no available tickets,
715
-     *                    either because they are sold out, expired, or not yet on sale.
716
-     *                    In this case, we need to close the form BEFORE adding any closing divs
717
-     * @return string
718
-     * @throws EE_Error
719
-     * @throws ReflectionException
720
-     */
721
-    public function displayViewDetailsButton($DWMTS = false)
722
-    {
723
-        if (! $this->event->get_permalink()) {
724
-            EE_Error::add_error(
725
-                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
726
-                __FILE__,
727
-                __FUNCTION__,
728
-                __LINE__
729
-            );
730
-        }
731
-        $view_details_btn = '<form method="GET" action="';
732
-        $view_details_btn .= apply_filters(
733
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
734
-            $this->event->get_permalink(),
735
-            $this->event
736
-        );
737
-        $view_details_btn .= '"';
738
-        // open link in new window ?
739
-        $view_details_btn .= apply_filters(
740
-            'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
741
-            $this->isIframe(),
742
-            $this
743
-        )
744
-            ? ' target="_blank"'
745
-            : '';
746
-        $view_details_btn .= '>';
747
-        $btn_text         = apply_filters(
748
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
749
-            esc_html__('View Details', 'event_espresso'),
750
-            $this->event
751
-        );
752
-        $view_details_btn .= '<input id="ticket-selector-submit-'
753
-                             . $this->event->ID()
754
-                             . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
755
-                             . $btn_text
756
-                             . '" />';
757
-        $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event);
758
-        if ($DWMTS) {
759
-            $view_details_btn .= $this->formClose();
760
-            $view_details_btn .= $this->ticketSelectorEndDiv();
761
-            $view_details_btn .= '<br/>';
762
-        } else {
763
-            $view_details_btn .= $this->clearTicketSelector();
764
-            $view_details_btn .= '<br/>';
765
-            $view_details_btn .= $this->formClose();
766
-        }
767
-        return $view_details_btn;
768
-    }
769
-
770
-
771
-    /**
772
-     * @return string
773
-     */
774
-    public function ticketSelectorEndDiv()
775
-    {
776
-        return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
777
-    }
778
-
779
-
780
-    /**
781
-     * @return string
782
-     */
783
-    public function clearTicketSelector()
784
-    {
785
-        // standard TS displayed, appears after a "Register Now" or "view Details" button
786
-        return '<div class="clear"></div><!-- clearTicketSelector -->';
787
-    }
788
-
789
-
790
-    /**
791
-     * @access        public
792
-     * @return        string
793
-     */
794
-    public function formClose()
795
-    {
796
-        return '</form>';
797
-    }
798
-
799
-
800
-    /**
801
-     * handleMissingEvent
802
-     * Returns either false or an error to display when no valid event is passed.
803
-     *
804
-     * @return string
805
-     * @throws ExceptionStackTraceDisplay
806
-     * @throws InvalidInterfaceException
807
-     * @throws Exception
808
-     */
809
-    protected function handleMissingEvent()
810
-    {
811
-        // If this is not an iFrame request, simply return false.
812
-        if (! $this->isIframe()) {
813
-            return '';
814
-        }
815
-        // This is an iFrame so return an error.
816
-        // Display stack trace if WP_DEBUG is enabled.
817
-        if (WP_DEBUG === true && current_user_can('edit_pages')) {
818
-            $event_id = $this->request->getRequestParam('event', 0, 'int');
819
-            new ExceptionStackTraceDisplay(
820
-                new InvalidArgumentException(
821
-                    sprintf(
822
-                        esc_html__(
823
-                            'A valid Event ID is required to display the ticket selector.%3$sAn Event with an ID of "%1$s" could not be found.%3$sPlease verify that the embed code added to this post\'s content includes an "%2$s" argument and that its value corresponds to a valid Event ID.',
824
-                            'event_espresso'
825
-                        ),
826
-                        $event_id,
827
-                        'event',
828
-                        '<br />'
829
-                    )
830
-                )
831
-            );
832
-            return '';
833
-        }
834
-        // If WP_DEBUG is not enabled, display a message stating the event could not be found.
835
-        return EEH_HTML::p(
836
-            esc_html__(
837
-                'A valid Event could not be found. Please contact the event administrator for assistance.',
838
-                'event_espresso'
839
-            )
840
-        );
841
-    }
842
-
843
-
844
-    /**
845
-     * @return EE_Tax_Config
846
-     * @since   4.10.14.p
847
-     */
848
-    protected function getTaxConfig()
849
-    {
850
-        return isset(EE_Registry::instance()->CFG->tax_settings)
851
-               && EE_Registry::instance()->CFG->tax_settings instanceof EE_Tax_Config
852
-            ? EE_Registry::instance()->CFG->tax_settings
853
-            : new EE_Tax_Config();
854
-    }
352
+	}
353
+
354
+
355
+	/**
356
+	 * ticketSalesClosed
357
+	 * notice displayed if event ticket sales are turned off
358
+	 *
359
+	 * @return string
360
+	 * @throws EE_Error
361
+	 * @throws ReflectionException
362
+	 */
363
+	protected function ticketSalesClosedMessage()
364
+	{
365
+		$sales_closed_msg = esc_html__(
366
+			'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
367
+			'event_espresso'
368
+		);
369
+		if (current_user_can('edit_post', $this->event->ID())) {
370
+			$sales_closed_msg .= sprintf(
371
+				esc_html__(
372
+					'%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
373
+					'event_espresso'
374
+				),
375
+				'<div class="ee-attention" style="text-align: left;"><b>',
376
+				'</b><br />',
377
+				'<span class="edit-link"><a class="post-edit-link" href="'
378
+				. get_edit_post_link($this->event->ID())
379
+				. '">',
380
+				'</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
381
+			);
382
+		}
383
+		return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
384
+	}
385
+
386
+
387
+	/**
388
+	 * getTickets
389
+	 *
390
+	 * @return EE_Base_Class[]|EE_Ticket[]
391
+	 * @throws EE_Error
392
+	 * @throws InvalidDataTypeException
393
+	 * @throws InvalidInterfaceException
394
+	 * @throws InvalidArgumentException
395
+	 * @throws ReflectionException
396
+	 */
397
+	protected function getTickets()
398
+	{
399
+		$show_expired_tickets = is_admin() || $this->config->show_expired_tickets;
400
+
401
+		$ticket_query_args = [
402
+			['Datetime.EVT_ID' => $this->event->ID()],
403
+			'order_by' => [
404
+				'TKT_order'              => 'ASC',
405
+				'TKT_required'           => 'DESC',
406
+				'TKT_start_date'         => 'ASC',
407
+				'TKT_end_date'           => 'ASC',
408
+				'Datetime.DTT_EVT_start' => 'DESC',
409
+			],
410
+		];
411
+		if (! $show_expired_tickets) {
412
+			// use the correct applicable time query depending on what version of core is being run.
413
+			$current_time                         = method_exists('EEM_Datetime', 'current_time_for_query')
414
+				? time()
415
+				: current_time('timestamp');
416
+			$ticket_query_args[0]['TKT_end_date'] = ['>', $current_time];
417
+		}
418
+		return EEM_Ticket::instance()->get_all($ticket_query_args);
419
+	}
420
+
421
+
422
+	/**
423
+	 * loadTicketSelector
424
+	 * begins to assemble template arguments
425
+	 * and decides whether to load a "simple" ticket selector, or the standard
426
+	 *
427
+	 * @param EE_Ticket[] $tickets
428
+	 * @param array       $template_args
429
+	 * @return TicketSelectorSimple|TicketSelectorStandard
430
+	 * @throws EE_Error
431
+	 * @throws ReflectionException
432
+	 */
433
+	protected function loadTicketSelector(array $tickets, array $template_args)
434
+	{
435
+		$template_args['event']            = $this->event;
436
+		$template_args['EVT_ID']           = $this->event->ID();
437
+		$template_args['event_is_expired'] = $this->event->is_expired();
438
+		$template_args['max_atndz']        = $this->getMaxAttendees();
439
+		$template_args['date_format']      = $this->date_format;
440
+		$template_args['time_format']      = $this->time_format;
441
+		/**
442
+		 * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
443
+		 *
444
+		 * @param string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
445
+		 * @param int $EVT_ID The Event ID
446
+		 * @since 4.9.13
447
+		 */
448
+		$template_args['anchor_id']    = apply_filters(
449
+			'FHEE__EE_Ticket_Selector__redirect_anchor_id',
450
+			'#tkt-slctr-tbl-' . $this->event->ID(),
451
+			$this->event->ID()
452
+		);
453
+		$template_args['tickets']      = $tickets;
454
+		$template_args['ticket_count'] = count($tickets);
455
+		$ticket_selector               = $this->simpleTicketSelector($tickets, $template_args);
456
+		if ($ticket_selector instanceof TicketSelectorSimple) {
457
+			return $ticket_selector;
458
+		}
459
+		return new TicketSelectorStandard(
460
+			$this->config,
461
+			$this->getTaxConfig(),
462
+			$this->event,
463
+			$tickets,
464
+			$this->getMaxAttendees(),
465
+			$template_args,
466
+			$this->date_format,
467
+			$this->time_format
468
+		);
469
+	}
470
+
471
+
472
+	/**
473
+	 * simpleTicketSelector
474
+	 * there's one ticket, and max attendees is set to one,
475
+	 * so if the event is free, then this is a "simple" ticket selector
476
+	 * a.k.a. "Dude Where's my Ticket Selector?"
477
+	 *
478
+	 * @param EE_Ticket[] $tickets
479
+	 * @param array       $template_args
480
+	 * @return string
481
+	 * @throws EE_Error
482
+	 * @throws ReflectionException
483
+	 */
484
+	protected function simpleTicketSelector($tickets, array $template_args)
485
+	{
486
+		// if there is only ONE ticket with a max qty of ONE
487
+		if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
488
+			return '';
489
+		}
490
+		/** @var EE_Ticket $ticket */
491
+		$ticket = reset($tickets);
492
+		// if the ticket is free... then not much need for the ticket selector
493
+		if (
494
+			apply_filters(
495
+				'FHEE__ticket_selector_chart_template__hide_ticket_selector',
496
+				$ticket->is_free(),
497
+				$this->event->ID()
498
+			)
499
+		) {
500
+			return new TicketSelectorSimple(
501
+				$this->event,
502
+				$ticket,
503
+				$this->getMaxAttendees(),
504
+				$template_args
505
+			);
506
+		}
507
+		return '';
508
+	}
509
+
510
+
511
+	/**
512
+	 * externalEventRegistration
513
+	 *
514
+	 * @return string
515
+	 */
516
+	public function externalEventRegistration()
517
+	{
518
+		// if not we still need to trigger the display of the submit button
519
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
520
+		// display notice to admin that registration is external
521
+		return $this->display_full_ui()
522
+			? esc_html__(
523
+				'Registration is at an external URL for this event.',
524
+				'event_espresso'
525
+			)
526
+			: '';
527
+	}
528
+
529
+
530
+	/**
531
+	 * formOpen
532
+	 *
533
+	 * @param int    $ID
534
+	 * @param string $external_url
535
+	 * @return        string
536
+	 */
537
+	public function formOpen($ID = 0, $external_url = '')
538
+	{
539
+		// if redirecting, we don't need any anything else
540
+		if ($external_url) {
541
+			$html = '<form method="GET" ';
542
+			$html .= 'action="' . EEH_URL::refactor_url($external_url) . '" ';
543
+			$html .= 'name="ticket-selector-form-' . $ID . '"';
544
+			// open link in new window ?
545
+			$html       .= apply_filters(
546
+				'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
547
+				$this->isIframe(),
548
+				$this
549
+			)
550
+				? ' target="_blank"'
551
+				: '';
552
+			$html       .= '>';
553
+			$query_args = EEH_URL::get_query_string($external_url);
554
+			foreach ((array) $query_args as $query_arg => $value) {
555
+				$html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
556
+			}
557
+			return $html;
558
+		}
559
+		// if there is no submit button, then don't start building a form
560
+		// because the "View Details" button will build its own form
561
+		if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
562
+			return '';
563
+		}
564
+		$checkout_url = EEH_Event_View::event_link_url($ID);
565
+		if (! $checkout_url) {
566
+			EE_Error::add_error(
567
+				esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
568
+				__FILE__,
569
+				__FUNCTION__,
570
+				__LINE__
571
+			);
572
+		}
573
+		// set no cache headers and constants
574
+		EE_System::do_not_cache();
575
+		$html = '<form method="POST" ';
576
+		$html .= 'action="' . $checkout_url . '" ';
577
+		$html .= 'name="ticket-selector-form-' . $ID . '"';
578
+		$html .= $this->iframe ? ' target="_blank"' : '';
579
+		$html .= '>';
580
+		$html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
581
+		return apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event);
582
+	}
583
+
584
+
585
+	/**
586
+	 * displaySubmitButton
587
+	 *
588
+	 * @param string $external_url
589
+	 * @return string
590
+	 * @throws EE_Error
591
+	 * @throws ReflectionException
592
+	 */
593
+	public function displaySubmitButton($external_url = '')
594
+	{
595
+		$html = '';
596
+		if ($this->display_full_ui()) {
597
+			// standard TS displayed with submit button, ie: "Register Now"
598
+			if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
599
+				$html .= $this->displayRegisterNowButton();
600
+				$html .= empty($external_url)
601
+					? $this->ticketSelectorEndDiv()
602
+					: $this->clearTicketSelector();
603
+				$html .= '<br/>' . $this->formClose();
604
+			} elseif ($this->getMaxAttendees() === 1) {
605
+				// its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
606
+				if ($this->event->is_sold_out()) {
607
+					// then instead of a View Details or Submit button, just display a "Sold Out" message
608
+					$html .= apply_filters(
609
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
610
+						sprintf(
611
+							esc_html__(
612
+								'%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
613
+								'event_espresso'
614
+							),
615
+							'<p class="no-ticket-selector-msg clear-float">',
616
+							$this->event->name(),
617
+							'</p>',
618
+							'<br />'
619
+						),
620
+						$this->event
621
+					);
622
+					if (
623
+						apply_filters(
624
+							'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
625
+							false,
626
+							$this->event
627
+						)
628
+					) {
629
+						$html .= $this->displayRegisterNowButton();
630
+					}
631
+					// sold out DWMTS event, no TS, no submit or view details button, but has additional content
632
+					$html .= $this->ticketSelectorEndDiv();
633
+				} elseif (
634
+					apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
635
+						  && ! is_single()
636
+				) {
637
+					// this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
638
+					// but no tickets are available, so display event's "View Details" button.
639
+					// it is being viewed via somewhere other than a single post
640
+					$html .= $this->displayViewDetailsButton(true);
641
+				} else {
642
+					$html .= $this->ticketSelectorEndDiv();
643
+				}
644
+			} elseif (is_archive()) {
645
+				// event list, no tickets available so display event's "View Details" button
646
+				$html .= $this->ticketSelectorEndDiv();
647
+				$html .= $this->displayViewDetailsButton();
648
+			} else {
649
+				if (
650
+					apply_filters(
651
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
652
+						false,
653
+						$this->event
654
+					)
655
+				) {
656
+					$html .= $this->displayRegisterNowButton();
657
+				}
658
+				// no submit or view details button, and no additional content
659
+				$html .= $this->ticketSelectorEndDiv();
660
+			}
661
+			if (! $this->iframe && ! is_archive()) {
662
+				$html .= EEH_Template::powered_by_event_espresso('', '', ['utm_content' => 'ticket_selector']);
663
+			}
664
+		}
665
+		return apply_filters(
666
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
667
+			$html,
668
+			$this->event,
669
+			$this
670
+		);
671
+	}
672
+
673
+
674
+	/**
675
+	 * @return string
676
+	 * @throws EE_Error
677
+	 * @throws ReflectionException
678
+	 */
679
+	public function displayRegisterNowButton()
680
+	{
681
+		$btn_text     = apply_filters(
682
+			'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
683
+			esc_html__('Register Now', 'event_espresso'),
684
+			$this->event
685
+		);
686
+		$external_url = (string) $this->event->external_url()
687
+						&& $this->event->external_url() !== get_the_permalink()
688
+			? $this->event->external_url()
689
+			: '';
690
+		$html         = EEH_HTML::div(
691
+			'',
692
+			'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap',
693
+			'ticket-selector-submit-btn-wrap'
694
+		);
695
+		$html         .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
696
+		$html         .= ' class="ticket-selector-submit-btn ';
697
+		$html         .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
698
+		$html         .= ' type="submit" value="' . $btn_text . '" data-ee-disable-after-recaptcha="true" />';
699
+		$html         .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
700
+		$html         .= apply_filters(
701
+			'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
702
+			'',
703
+			$this->event,
704
+			$this->iframe
705
+		);
706
+		return $html;
707
+	}
708
+
709
+
710
+	/**
711
+	 * displayViewDetailsButton
712
+	 *
713
+	 * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
714
+	 *                    (ie: $_max_atndz === 1) where there are no available tickets,
715
+	 *                    either because they are sold out, expired, or not yet on sale.
716
+	 *                    In this case, we need to close the form BEFORE adding any closing divs
717
+	 * @return string
718
+	 * @throws EE_Error
719
+	 * @throws ReflectionException
720
+	 */
721
+	public function displayViewDetailsButton($DWMTS = false)
722
+	{
723
+		if (! $this->event->get_permalink()) {
724
+			EE_Error::add_error(
725
+				esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
726
+				__FILE__,
727
+				__FUNCTION__,
728
+				__LINE__
729
+			);
730
+		}
731
+		$view_details_btn = '<form method="GET" action="';
732
+		$view_details_btn .= apply_filters(
733
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
734
+			$this->event->get_permalink(),
735
+			$this->event
736
+		);
737
+		$view_details_btn .= '"';
738
+		// open link in new window ?
739
+		$view_details_btn .= apply_filters(
740
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
741
+			$this->isIframe(),
742
+			$this
743
+		)
744
+			? ' target="_blank"'
745
+			: '';
746
+		$view_details_btn .= '>';
747
+		$btn_text         = apply_filters(
748
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
749
+			esc_html__('View Details', 'event_espresso'),
750
+			$this->event
751
+		);
752
+		$view_details_btn .= '<input id="ticket-selector-submit-'
753
+							 . $this->event->ID()
754
+							 . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
755
+							 . $btn_text
756
+							 . '" />';
757
+		$view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event);
758
+		if ($DWMTS) {
759
+			$view_details_btn .= $this->formClose();
760
+			$view_details_btn .= $this->ticketSelectorEndDiv();
761
+			$view_details_btn .= '<br/>';
762
+		} else {
763
+			$view_details_btn .= $this->clearTicketSelector();
764
+			$view_details_btn .= '<br/>';
765
+			$view_details_btn .= $this->formClose();
766
+		}
767
+		return $view_details_btn;
768
+	}
769
+
770
+
771
+	/**
772
+	 * @return string
773
+	 */
774
+	public function ticketSelectorEndDiv()
775
+	{
776
+		return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
777
+	}
778
+
779
+
780
+	/**
781
+	 * @return string
782
+	 */
783
+	public function clearTicketSelector()
784
+	{
785
+		// standard TS displayed, appears after a "Register Now" or "view Details" button
786
+		return '<div class="clear"></div><!-- clearTicketSelector -->';
787
+	}
788
+
789
+
790
+	/**
791
+	 * @access        public
792
+	 * @return        string
793
+	 */
794
+	public function formClose()
795
+	{
796
+		return '</form>';
797
+	}
798
+
799
+
800
+	/**
801
+	 * handleMissingEvent
802
+	 * Returns either false or an error to display when no valid event is passed.
803
+	 *
804
+	 * @return string
805
+	 * @throws ExceptionStackTraceDisplay
806
+	 * @throws InvalidInterfaceException
807
+	 * @throws Exception
808
+	 */
809
+	protected function handleMissingEvent()
810
+	{
811
+		// If this is not an iFrame request, simply return false.
812
+		if (! $this->isIframe()) {
813
+			return '';
814
+		}
815
+		// This is an iFrame so return an error.
816
+		// Display stack trace if WP_DEBUG is enabled.
817
+		if (WP_DEBUG === true && current_user_can('edit_pages')) {
818
+			$event_id = $this->request->getRequestParam('event', 0, 'int');
819
+			new ExceptionStackTraceDisplay(
820
+				new InvalidArgumentException(
821
+					sprintf(
822
+						esc_html__(
823
+							'A valid Event ID is required to display the ticket selector.%3$sAn Event with an ID of "%1$s" could not be found.%3$sPlease verify that the embed code added to this post\'s content includes an "%2$s" argument and that its value corresponds to a valid Event ID.',
824
+							'event_espresso'
825
+						),
826
+						$event_id,
827
+						'event',
828
+						'<br />'
829
+					)
830
+				)
831
+			);
832
+			return '';
833
+		}
834
+		// If WP_DEBUG is not enabled, display a message stating the event could not be found.
835
+		return EEH_HTML::p(
836
+			esc_html__(
837
+				'A valid Event could not be found. Please contact the event administrator for assistance.',
838
+				'event_espresso'
839
+			)
840
+		);
841
+	}
842
+
843
+
844
+	/**
845
+	 * @return EE_Tax_Config
846
+	 * @since   4.10.14.p
847
+	 */
848
+	protected function getTaxConfig()
849
+	{
850
+		return isset(EE_Registry::instance()->CFG->tax_settings)
851
+			   && EE_Registry::instance()->CFG->tax_settings instanceof EE_Tax_Config
852
+			? EE_Registry::instance()->CFG->tax_settings
853
+			: new EE_Tax_Config();
854
+	}
855 855
 }
Please login to merge, or discard this patch.
modules/ticket_selector/TicketDetails.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public function getShowHideLinks()
113 113
     {
114
-        if (! $this->showTicketDetails()) {
114
+        if ( ! $this->showTicketDetails()) {
115 115
             return '';
116 116
         }
117 117
         return \EEH_HTML::link(
@@ -126,8 +126,8 @@  discard block
 block discarded – undo
126 126
             "display-{$this->cssId()}",
127 127
             'display-tckt-slctr-tkt-details display-the-hidden lt-grey-text smaller-text hide-if-no-js',
128 128
             '',
129
-            'rel="' . $this->cssId() . '"'
130
-        ) . \EEH_HTML::link(
129
+            'rel="'.$this->cssId().'"'
130
+        ).\EEH_HTML::link(
131 131
             '',
132 132
             sprintf(esc_html__('hide%1$sdetails%1$s-', 'event_espresso'), '&nbsp;'),
133 133
             esc_attr(
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
             "hide-{$this->cssId()}",
140 140
             'hide-tckt-slctr-tkt-details hide-the-displayed lt-grey-text smaller-text hide-if-no-js',
141 141
             'display:none;',
142
-            'rel="' . $this->cssId() . '"'
142
+            'rel="'.$this->cssId().'"'
143 143
         );
144 144
     }
145 145
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
         return \EEH_Template::locate_template(
192 192
             apply_filters(
193 193
                 'FHEE__EventEspresso_modules_ticket_selector_TicketDetails__display__template_path',
194
-                TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_details.template.php',
194
+                TICKET_SELECTOR_TEMPLATES_PATH.'ticket_details.template.php',
195 195
                 $this->ticket
196 196
             ),
197 197
             $template_args
Please login to merge, or discard this patch.
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -13,186 +13,186 @@
 block discarded – undo
13 13
  */
14 14
 class TicketDetails
15 15
 {
16
-    /**
17
-     * @var \EE_Ticket $ticket
18
-     */
19
-    protected $ticket;
20
-
21
-    /**
22
-     * @var \EE_Ticket_Selector_Config $template_settings
23
-     */
24
-    protected $template_settings;
25
-
26
-    /**
27
-     * @var string $date_format
28
-     */
29
-    protected $date_format;
30
-
31
-    /**
32
-     * @var string $time_format
33
-     */
34
-    protected $time_format;
35
-
36
-    /**
37
-     * @var boolean $event_is_expired
38
-     */
39
-    protected $event_is_expired;
40
-
41
-
42
-    /**
43
-     * TicketDetails constructor.
44
-     *
45
-     * @param \EE_Ticket                 $ticket
46
-     * @param \EE_Ticket_Selector_Config $template_settings
47
-     * @param array                      $template_args
48
-     */
49
-    public function __construct(
50
-        \EE_Ticket $ticket,
51
-        \EE_Ticket_Selector_Config $template_settings,
52
-        array $template_args
53
-    ) {
54
-        $this->ticket = $ticket;
55
-        $this->template_settings = $template_settings;
56
-        $this->date_format = $template_args['date_format'];
57
-        $this->time_format = $template_args['time_format'];
58
-        $this->event_is_expired = $template_args['event_is_expired'];
59
-    }
60
-
61
-
62
-    /**
63
-     * @return \EE_Ticket
64
-     */
65
-    public function getTicket()
66
-    {
67
-        return $this->ticket;
68
-    }
69
-
70
-
71
-    /**
72
-     * @return bool
73
-     */
74
-    public function showTicketDetails()
75
-    {
76
-        return $this->template_settings->show_ticket_details;
77
-    }
78
-
79
-
80
-    /**
81
-     * @return \EE_Ticket_Selector_Config
82
-     */
83
-    public function getTemplateSettings()
84
-    {
85
-        return $this->template_settings;
86
-    }
87
-
88
-
89
-    /**
90
-     * @return string
91
-     */
92
-    public function getDateFormat()
93
-    {
94
-        return $this->date_format;
95
-    }
96
-
97
-
98
-    /**
99
-     * @return string
100
-     */
101
-    public function getTimeFormat()
102
-    {
103
-        return $this->time_format;
104
-    }
105
-
106
-
107
-    /**
108
-     * @return string
109
-     */
110
-    public function getShowHideLinks()
111
-    {
112
-        if (! $this->showTicketDetails()) {
113
-            return '';
114
-        }
115
-        return \EEH_HTML::link(
116
-            '',
117
-            sprintf(esc_html__('show%1$sdetails%1$s+', 'event_espresso'), '&nbsp;'),
118
-            esc_attr(
119
-                apply_filters(
120
-                    'FHEE__ticket_selector_chart_template__show_ticket_details_link_title',
121
-                    esc_html__('click to show additional ticket details', 'event_espresso')
122
-                )
123
-            ),
124
-            "display-{$this->cssId()}",
125
-            'display-tckt-slctr-tkt-details display-the-hidden lt-grey-text smaller-text hide-if-no-js',
126
-            '',
127
-            'rel="' . $this->cssId() . '"'
128
-        ) . \EEH_HTML::link(
129
-            '',
130
-            sprintf(esc_html__('hide%1$sdetails%1$s-', 'event_espresso'), '&nbsp;'),
131
-            esc_attr(
132
-                apply_filters(
133
-                    'FHEE__ticket_selector_chart_template__hide_ticket_details_link_title',
134
-                    esc_html__('click to hide additional ticket details', 'event_espresso')
135
-                )
136
-            ),
137
-            "hide-{$this->cssId()}",
138
-            'hide-tckt-slctr-tkt-details hide-the-displayed lt-grey-text smaller-text hide-if-no-js',
139
-            'display:none;',
140
-            'rel="' . $this->cssId() . '"'
141
-        );
142
-    }
143
-
144
-
145
-    /**
146
-     * @return string
147
-     */
148
-    public function cssId()
149
-    {
150
-        return apply_filters(
151
-            'FHEE__ticket_selector_chart_template__ticket_details_css_id',
152
-            "tckt-slctr-tkt-details-{$this->ticket->get_event_ID()}-{$this->ticket->ID()}"
153
-        );
154
-    }
155
-
156
-
157
-    /**
158
-     * @param float $ticket_price
159
-     * @param int   $remaining
160
-     * @param int   $cols
161
-     * @return string
162
-     */
163
-    public function display(
164
-        $ticket_price = 0.00,
165
-        $remaining,
166
-        $cols = 2
167
-    ) {
168
-        $template_args = array();
169
-        $template_args['ticket'] = $this->ticket;
170
-        $template_args['ticket_price'] = $ticket_price;
171
-        $template_args['remaining'] = $remaining;
172
-        $template_args['cols'] = $cols;
173
-        $template_args['show_ticket_details'] = $this->template_settings->show_ticket_details;
174
-        $template_args['show_ticket_sale_columns'] = $this->template_settings->show_ticket_sale_columns;
175
-        $template_args['ticket_details_row_class'] = espresso_get_object_css_class($this->ticket, '', 'details');
176
-        $template_args['ticket_details_css_id'] = $this->cssId();
177
-        $template_args['display_ticket_price'] = $ticket_price !== 0 && apply_filters(
178
-            'FHEE__ticket_selector_chart_template__display_ticket_price_details',
179
-            true
180
-        );
181
-        $template_args['price_breakdown_heading'] = apply_filters(
182
-            'FHEE__ticket_selector_chart_template__ticket_details_price_breakdown_heading',
183
-            esc_html__('Price', 'event_espresso')
184
-        );
185
-        $template_args['date_format'] = $this->date_format;
186
-        $template_args['time_format'] = $this->time_format;
187
-        $template_args['event_is_expired'] = $this->event_is_expired;
188
-
189
-        return \EEH_Template::locate_template(
190
-            apply_filters(
191
-                'FHEE__EventEspresso_modules_ticket_selector_TicketDetails__display__template_path',
192
-                TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_details.template.php',
193
-                $this->ticket
194
-            ),
195
-            $template_args
196
-        );
197
-    }
16
+	/**
17
+	 * @var \EE_Ticket $ticket
18
+	 */
19
+	protected $ticket;
20
+
21
+	/**
22
+	 * @var \EE_Ticket_Selector_Config $template_settings
23
+	 */
24
+	protected $template_settings;
25
+
26
+	/**
27
+	 * @var string $date_format
28
+	 */
29
+	protected $date_format;
30
+
31
+	/**
32
+	 * @var string $time_format
33
+	 */
34
+	protected $time_format;
35
+
36
+	/**
37
+	 * @var boolean $event_is_expired
38
+	 */
39
+	protected $event_is_expired;
40
+
41
+
42
+	/**
43
+	 * TicketDetails constructor.
44
+	 *
45
+	 * @param \EE_Ticket                 $ticket
46
+	 * @param \EE_Ticket_Selector_Config $template_settings
47
+	 * @param array                      $template_args
48
+	 */
49
+	public function __construct(
50
+		\EE_Ticket $ticket,
51
+		\EE_Ticket_Selector_Config $template_settings,
52
+		array $template_args
53
+	) {
54
+		$this->ticket = $ticket;
55
+		$this->template_settings = $template_settings;
56
+		$this->date_format = $template_args['date_format'];
57
+		$this->time_format = $template_args['time_format'];
58
+		$this->event_is_expired = $template_args['event_is_expired'];
59
+	}
60
+
61
+
62
+	/**
63
+	 * @return \EE_Ticket
64
+	 */
65
+	public function getTicket()
66
+	{
67
+		return $this->ticket;
68
+	}
69
+
70
+
71
+	/**
72
+	 * @return bool
73
+	 */
74
+	public function showTicketDetails()
75
+	{
76
+		return $this->template_settings->show_ticket_details;
77
+	}
78
+
79
+
80
+	/**
81
+	 * @return \EE_Ticket_Selector_Config
82
+	 */
83
+	public function getTemplateSettings()
84
+	{
85
+		return $this->template_settings;
86
+	}
87
+
88
+
89
+	/**
90
+	 * @return string
91
+	 */
92
+	public function getDateFormat()
93
+	{
94
+		return $this->date_format;
95
+	}
96
+
97
+
98
+	/**
99
+	 * @return string
100
+	 */
101
+	public function getTimeFormat()
102
+	{
103
+		return $this->time_format;
104
+	}
105
+
106
+
107
+	/**
108
+	 * @return string
109
+	 */
110
+	public function getShowHideLinks()
111
+	{
112
+		if (! $this->showTicketDetails()) {
113
+			return '';
114
+		}
115
+		return \EEH_HTML::link(
116
+			'',
117
+			sprintf(esc_html__('show%1$sdetails%1$s+', 'event_espresso'), '&nbsp;'),
118
+			esc_attr(
119
+				apply_filters(
120
+					'FHEE__ticket_selector_chart_template__show_ticket_details_link_title',
121
+					esc_html__('click to show additional ticket details', 'event_espresso')
122
+				)
123
+			),
124
+			"display-{$this->cssId()}",
125
+			'display-tckt-slctr-tkt-details display-the-hidden lt-grey-text smaller-text hide-if-no-js',
126
+			'',
127
+			'rel="' . $this->cssId() . '"'
128
+		) . \EEH_HTML::link(
129
+			'',
130
+			sprintf(esc_html__('hide%1$sdetails%1$s-', 'event_espresso'), '&nbsp;'),
131
+			esc_attr(
132
+				apply_filters(
133
+					'FHEE__ticket_selector_chart_template__hide_ticket_details_link_title',
134
+					esc_html__('click to hide additional ticket details', 'event_espresso')
135
+				)
136
+			),
137
+			"hide-{$this->cssId()}",
138
+			'hide-tckt-slctr-tkt-details hide-the-displayed lt-grey-text smaller-text hide-if-no-js',
139
+			'display:none;',
140
+			'rel="' . $this->cssId() . '"'
141
+		);
142
+	}
143
+
144
+
145
+	/**
146
+	 * @return string
147
+	 */
148
+	public function cssId()
149
+	{
150
+		return apply_filters(
151
+			'FHEE__ticket_selector_chart_template__ticket_details_css_id',
152
+			"tckt-slctr-tkt-details-{$this->ticket->get_event_ID()}-{$this->ticket->ID()}"
153
+		);
154
+	}
155
+
156
+
157
+	/**
158
+	 * @param float $ticket_price
159
+	 * @param int   $remaining
160
+	 * @param int   $cols
161
+	 * @return string
162
+	 */
163
+	public function display(
164
+		$ticket_price = 0.00,
165
+		$remaining,
166
+		$cols = 2
167
+	) {
168
+		$template_args = array();
169
+		$template_args['ticket'] = $this->ticket;
170
+		$template_args['ticket_price'] = $ticket_price;
171
+		$template_args['remaining'] = $remaining;
172
+		$template_args['cols'] = $cols;
173
+		$template_args['show_ticket_details'] = $this->template_settings->show_ticket_details;
174
+		$template_args['show_ticket_sale_columns'] = $this->template_settings->show_ticket_sale_columns;
175
+		$template_args['ticket_details_row_class'] = espresso_get_object_css_class($this->ticket, '', 'details');
176
+		$template_args['ticket_details_css_id'] = $this->cssId();
177
+		$template_args['display_ticket_price'] = $ticket_price !== 0 && apply_filters(
178
+			'FHEE__ticket_selector_chart_template__display_ticket_price_details',
179
+			true
180
+		);
181
+		$template_args['price_breakdown_heading'] = apply_filters(
182
+			'FHEE__ticket_selector_chart_template__ticket_details_price_breakdown_heading',
183
+			esc_html__('Price', 'event_espresso')
184
+		);
185
+		$template_args['date_format'] = $this->date_format;
186
+		$template_args['time_format'] = $this->time_format;
187
+		$template_args['event_is_expired'] = $this->event_is_expired;
188
+
189
+		return \EEH_Template::locate_template(
190
+			apply_filters(
191
+				'FHEE__EventEspresso_modules_ticket_selector_TicketDetails__display__template_path',
192
+				TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_details.template.php',
193
+				$this->ticket
194
+			),
195
+			$template_args
196
+		);
197
+	}
198 198
 }
Please login to merge, or discard this patch.
registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php 2 patches
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -20,198 +20,198 @@
 block discarded – undo
20 20
  */
21 21
 class EE_Registration_Custom_Questions_Form extends EE_Form_Section_Proper
22 22
 {
23
-    /**
24
-     *
25
-     * @var EE_Registration
26
-     */
27
-    protected $_registration = null;
23
+	/**
24
+	 *
25
+	 * @var EE_Registration
26
+	 */
27
+	protected $_registration = null;
28 28
 
29 29
 
30
-    /**
31
-     *
32
-     * @param EE_Registration $reg
33
-     * @param array           $options
34
-     * @throws EE_Error
35
-     * @throws ReflectionException
36
-     */
37
-    public function __construct(EE_Registration $reg, $options = array())
38
-    {
39
-        $this->_registration = $reg;
40
-        if (! isset($options['layout_strategy'])) {
41
-            $options['layout_strategy'] = new EE_Admin_Two_Column_Layout();
42
-        }
43
-        if (! isset($options['html_id'])) {
44
-            $options['html_id'] = 'reg-admin-attendee-questions-frm';
45
-        }
46
-        $this->build_form_from_registration();
47
-        parent::__construct($options);
48
-    }
30
+	/**
31
+	 *
32
+	 * @param EE_Registration $reg
33
+	 * @param array           $options
34
+	 * @throws EE_Error
35
+	 * @throws ReflectionException
36
+	 */
37
+	public function __construct(EE_Registration $reg, $options = array())
38
+	{
39
+		$this->_registration = $reg;
40
+		if (! isset($options['layout_strategy'])) {
41
+			$options['layout_strategy'] = new EE_Admin_Two_Column_Layout();
42
+		}
43
+		if (! isset($options['html_id'])) {
44
+			$options['html_id'] = 'reg-admin-attendee-questions-frm';
45
+		}
46
+		$this->build_form_from_registration();
47
+		parent::__construct($options);
48
+	}
49 49
 
50 50
 
51
-    /**
52
-     * Gets the registration object this form is about
53
-     * @return EE_Registration
54
-     */
55
-    public function get_registration()
56
-    {
57
-        return $this->_registration;
58
-    }
51
+	/**
52
+	 * Gets the registration object this form is about
53
+	 * @return EE_Registration
54
+	 */
55
+	public function get_registration()
56
+	{
57
+		return $this->_registration;
58
+	}
59 59
 
60
-    /**
61
-     * @since 4.10.0.p
62
-     * @throws EE_Error
63
-     * @throws InvalidArgumentException
64
-     * @throws ReflectionException
65
-     * @throws InvalidDataTypeException
66
-     * @throws InvalidInterfaceException
67
-     */
68
-    public function build_form_from_registration()
69
-    {
70
-        $reg = $this->get_registration();
71
-        if (! $reg instanceof EE_Registration) {
72
-            throw new EE_Error(esc_html__('We cannot build the registration custom questions form because there is no registration set on it yet', 'event_espresso'));
73
-        }
74
-        // we want to get all their question groups
75
-        $question_groups = EEM_Question_Group::instance()->get_all(
76
-            [
77
-                [
78
-                    'Event_Question_Group.EVT_ID' => $reg->event_ID(),
79
-                    'OR' => [
80
-                        'Question.QST_system*blank' =>  '',
81
-                        'Question.QST_system*null' => ['IS_NULL']
82
-                    ],
83
-                    'Event_Question_Group.'
84
-                    . EEM_Event_Question_Group::instance()->fieldNameForContext(
85
-                        $reg->is_primary_registrant()
86
-                    ) => true
87
-                ],
88
-                'order_by' => ['QSG_order' => 'ASC']
89
-            ]
90
-        );
91
-        // get each question groups questions
92
-        foreach ($question_groups as $question_group) {
93
-            if ($question_group instanceof EE_Question_Group) {
94
-                $this->_subsections[ $question_group->ID() ] = $this->build_subform_from_question_group(
95
-                    $question_group,
96
-                    $reg
97
-                );
98
-            }
99
-        }
100
-    }
60
+	/**
61
+	 * @since 4.10.0.p
62
+	 * @throws EE_Error
63
+	 * @throws InvalidArgumentException
64
+	 * @throws ReflectionException
65
+	 * @throws InvalidDataTypeException
66
+	 * @throws InvalidInterfaceException
67
+	 */
68
+	public function build_form_from_registration()
69
+	{
70
+		$reg = $this->get_registration();
71
+		if (! $reg instanceof EE_Registration) {
72
+			throw new EE_Error(esc_html__('We cannot build the registration custom questions form because there is no registration set on it yet', 'event_espresso'));
73
+		}
74
+		// we want to get all their question groups
75
+		$question_groups = EEM_Question_Group::instance()->get_all(
76
+			[
77
+				[
78
+					'Event_Question_Group.EVT_ID' => $reg->event_ID(),
79
+					'OR' => [
80
+						'Question.QST_system*blank' =>  '',
81
+						'Question.QST_system*null' => ['IS_NULL']
82
+					],
83
+					'Event_Question_Group.'
84
+					. EEM_Event_Question_Group::instance()->fieldNameForContext(
85
+						$reg->is_primary_registrant()
86
+					) => true
87
+				],
88
+				'order_by' => ['QSG_order' => 'ASC']
89
+			]
90
+		);
91
+		// get each question groups questions
92
+		foreach ($question_groups as $question_group) {
93
+			if ($question_group instanceof EE_Question_Group) {
94
+				$this->_subsections[ $question_group->ID() ] = $this->build_subform_from_question_group(
95
+					$question_group,
96
+					$reg
97
+				);
98
+			}
99
+		}
100
+	}
101 101
 
102 102
 
103
-    /**
104
-     *
105
-     * @param EE_Question_Group $question_group
106
-     * @param EE_Registration   $registration
107
-     * @return EE_Form_Section_Proper
108
-     * @throws EE_Error
109
-     * @throws ReflectionException
110
-     */
111
-    public function build_subform_from_question_group($question_group, $registration)
112
-    {
113
-        if (
114
-            ! $question_group instanceof EE_Question_Group ||
115
-            ! $registration instanceof EE_Registration
116
-        ) {
117
-            throw new EE_Error(esc_html__('A valid question group and registration must be passed to EE_Registration_Custom_Question_Form', 'event_espresso'));
118
-        }
119
-        $parts_of_subsection = array(
120
-            'title' => new EE_Form_Section_HTML(
121
-                EEH_HTML::h5(
122
-                    $question_group->name(),
123
-                    $question_group->identifier(),
124
-                    'espresso-question-group-title-h5 section-title'
125
-                )
126
-            )
127
-        );
128
-        $questions = $question_group->questions(
129
-            array(
130
-                array(
131
-                    'OR' => array(
132
-                        'QST_system*blank' => '',
133
-                        'QST_system*null' => array( 'IS_NULL' )
134
-                    )
135
-                )
136
-            )
137
-        );
138
-        foreach ($questions as $question) {
139
-            $parts_of_subsection[ $question->ID() ] = $question->generate_form_input($registration);
140
-        }
141
-        if (
142
-            EE_Registry::instance()->CAP->current_user_can(
143
-                'ee_edit_registration',
144
-                'edit-reg-questions-mbox',
145
-                $this->_registration->ID()
146
-            )
147
-        ) {
148
-            $parts_of_subsection['edit_link'] = new EE_Form_Section_HTML(
149
-                EEH_HTML::table(
150
-                    EEH_HTML::tr(
151
-                        '<th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" aria-label="' . esc_attr__('click to edit question', 'event_espresso') . '">
103
+	/**
104
+	 *
105
+	 * @param EE_Question_Group $question_group
106
+	 * @param EE_Registration   $registration
107
+	 * @return EE_Form_Section_Proper
108
+	 * @throws EE_Error
109
+	 * @throws ReflectionException
110
+	 */
111
+	public function build_subform_from_question_group($question_group, $registration)
112
+	{
113
+		if (
114
+			! $question_group instanceof EE_Question_Group ||
115
+			! $registration instanceof EE_Registration
116
+		) {
117
+			throw new EE_Error(esc_html__('A valid question group and registration must be passed to EE_Registration_Custom_Question_Form', 'event_espresso'));
118
+		}
119
+		$parts_of_subsection = array(
120
+			'title' => new EE_Form_Section_HTML(
121
+				EEH_HTML::h5(
122
+					$question_group->name(),
123
+					$question_group->identifier(),
124
+					'espresso-question-group-title-h5 section-title'
125
+				)
126
+			)
127
+		);
128
+		$questions = $question_group->questions(
129
+			array(
130
+				array(
131
+					'OR' => array(
132
+						'QST_system*blank' => '',
133
+						'QST_system*null' => array( 'IS_NULL' )
134
+					)
135
+				)
136
+			)
137
+		);
138
+		foreach ($questions as $question) {
139
+			$parts_of_subsection[ $question->ID() ] = $question->generate_form_input($registration);
140
+		}
141
+		if (
142
+			EE_Registry::instance()->CAP->current_user_can(
143
+				'ee_edit_registration',
144
+				'edit-reg-questions-mbox',
145
+				$this->_registration->ID()
146
+			)
147
+		) {
148
+			$parts_of_subsection['edit_link'] = new EE_Form_Section_HTML(
149
+				EEH_HTML::table(
150
+					EEH_HTML::tr(
151
+						'<th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" aria-label="' . esc_attr__('click to edit question', 'event_espresso') . '">
152 152
 		  			<span class="reg-admin-edit-question-group-spn">' . esc_html__('edit the above question group', 'event_espresso') . '</span>
153 153
 		  			<div class="dashicons dashicons-edit"></div>
154 154
 		  		</a></td>'
155
-                    ) .
156
-                    EEH_HTML::no_row()
157
-                )
158
-            );
159
-        }
160
-        return new EE_Form_Section_Proper(
161
-            array(
162
-                'subsections' => $parts_of_subsection,
163
-                'html_class' => 'question-group-questions',
164
-            )
165
-        );
166
-    }
155
+					) .
156
+					EEH_HTML::no_row()
157
+				)
158
+			);
159
+		}
160
+		return new EE_Form_Section_Proper(
161
+			array(
162
+				'subsections' => $parts_of_subsection,
163
+				'html_class' => 'question-group-questions',
164
+			)
165
+		);
166
+	}
167 167
 
168 168
 
169
-    /**
170
-     * Overrides parent so if inputs were disabled, we leave those with their defaults
171
-     * from the answers in the DB
172
-     *
173
-     * @param array $req_data like $_POST
174
-     * @return void
175
-     * @throws EE_Error
176
-     */
177
-    protected function _normalize($req_data)
178
-    {
179
-        $this->_received_submission = true;
180
-        $this->_validation_errors = array();
181
-        foreach ($this->get_validatable_subsections() as $subsection) {
182
-            if ($subsection->form_data_present_in($req_data)) {
183
-                try {
184
-                    $subsection->_normalize($req_data);
185
-                } catch (EE_Validation_Error $e) {
186
-                    $subsection->add_validation_error($e);
187
-                }
188
-            }
189
-        }
190
-    }
169
+	/**
170
+	 * Overrides parent so if inputs were disabled, we leave those with their defaults
171
+	 * from the answers in the DB
172
+	 *
173
+	 * @param array $req_data like $_POST
174
+	 * @return void
175
+	 * @throws EE_Error
176
+	 */
177
+	protected function _normalize($req_data)
178
+	{
179
+		$this->_received_submission = true;
180
+		$this->_validation_errors = array();
181
+		foreach ($this->get_validatable_subsections() as $subsection) {
182
+			if ($subsection->form_data_present_in($req_data)) {
183
+				try {
184
+					$subsection->_normalize($req_data);
185
+				} catch (EE_Validation_Error $e) {
186
+					$subsection->add_validation_error($e);
187
+				}
188
+			}
189
+		}
190
+	}
191 191
 
192 192
 
193
-    /**
194
-     * Performs validation on this form section and its subsections. For each subsection,
195
-     * calls _validate_{subsection_name} on THIS form (if the function exists) and passes it the subsection, then calls
196
-     * _validate on that subsection. If you need to perform validation on the form as a whole (considering multiple)
197
-     * you would be best to override this _validate method, calling parent::_validate() first.
198
-     *
199
-     * @throws EE_Error
200
-     */
201
-    protected function _validate()
202
-    {
203
-        /** @var RequestInterface $request */
204
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
205
-        $form_data = $request->requestParams();
206
-        foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
207
-            if ($subsection->form_data_present_in($form_data)) {
208
-                if (method_exists($this, '_validate_' . $subsection_name)) {
209
-                    call_user_func_array(array($this,'_validate_' . $subsection_name), array($subsection));
210
-                }
211
-                $subsection->_validate();
212
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
213
-                $subsection->_received_submission = true;
214
-            }
215
-        }
216
-    }
193
+	/**
194
+	 * Performs validation on this form section and its subsections. For each subsection,
195
+	 * calls _validate_{subsection_name} on THIS form (if the function exists) and passes it the subsection, then calls
196
+	 * _validate on that subsection. If you need to perform validation on the form as a whole (considering multiple)
197
+	 * you would be best to override this _validate method, calling parent::_validate() first.
198
+	 *
199
+	 * @throws EE_Error
200
+	 */
201
+	protected function _validate()
202
+	{
203
+		/** @var RequestInterface $request */
204
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
205
+		$form_data = $request->requestParams();
206
+		foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
207
+			if ($subsection->form_data_present_in($form_data)) {
208
+				if (method_exists($this, '_validate_' . $subsection_name)) {
209
+					call_user_func_array(array($this,'_validate_' . $subsection_name), array($subsection));
210
+				}
211
+				$subsection->_validate();
212
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
213
+				$subsection->_received_submission = true;
214
+			}
215
+		}
216
+	}
217 217
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
     public function __construct(EE_Registration $reg, $options = array())
38 38
     {
39 39
         $this->_registration = $reg;
40
-        if (! isset($options['layout_strategy'])) {
40
+        if ( ! isset($options['layout_strategy'])) {
41 41
             $options['layout_strategy'] = new EE_Admin_Two_Column_Layout();
42 42
         }
43
-        if (! isset($options['html_id'])) {
43
+        if ( ! isset($options['html_id'])) {
44 44
             $options['html_id'] = 'reg-admin-attendee-questions-frm';
45 45
         }
46 46
         $this->build_form_from_registration();
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     public function build_form_from_registration()
69 69
     {
70 70
         $reg = $this->get_registration();
71
-        if (! $reg instanceof EE_Registration) {
71
+        if ( ! $reg instanceof EE_Registration) {
72 72
             throw new EE_Error(esc_html__('We cannot build the registration custom questions form because there is no registration set on it yet', 'event_espresso'));
73 73
         }
74 74
         // we want to get all their question groups
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
         // get each question groups questions
92 92
         foreach ($question_groups as $question_group) {
93 93
             if ($question_group instanceof EE_Question_Group) {
94
-                $this->_subsections[ $question_group->ID() ] = $this->build_subform_from_question_group(
94
+                $this->_subsections[$question_group->ID()] = $this->build_subform_from_question_group(
95 95
                     $question_group,
96 96
                     $reg
97 97
                 );
@@ -130,13 +130,13 @@  discard block
 block discarded – undo
130 130
                 array(
131 131
                     'OR' => array(
132 132
                         'QST_system*blank' => '',
133
-                        'QST_system*null' => array( 'IS_NULL' )
133
+                        'QST_system*null' => array('IS_NULL')
134 134
                     )
135 135
                 )
136 136
             )
137 137
         );
138 138
         foreach ($questions as $question) {
139
-            $parts_of_subsection[ $question->ID() ] = $question->generate_form_input($registration);
139
+            $parts_of_subsection[$question->ID()] = $question->generate_form_input($registration);
140 140
         }
141 141
         if (
142 142
             EE_Registry::instance()->CAP->current_user_can(
@@ -148,11 +148,11 @@  discard block
 block discarded – undo
148 148
             $parts_of_subsection['edit_link'] = new EE_Form_Section_HTML(
149 149
                 EEH_HTML::table(
150 150
                     EEH_HTML::tr(
151
-                        '<th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" aria-label="' . esc_attr__('click to edit question', 'event_espresso') . '">
152
-		  			<span class="reg-admin-edit-question-group-spn">' . esc_html__('edit the above question group', 'event_espresso') . '</span>
151
+                        '<th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" aria-label="'.esc_attr__('click to edit question', 'event_espresso').'">
152
+		  			<span class="reg-admin-edit-question-group-spn">' . esc_html__('edit the above question group', 'event_espresso').'</span>
153 153
 		  			<div class="dashicons dashicons-edit"></div>
154 154
 		  		</a></td>'
155
-                    ) .
155
+                    ).
156 156
                     EEH_HTML::no_row()
157 157
                 )
158 158
             );
@@ -205,8 +205,8 @@  discard block
 block discarded – undo
205 205
         $form_data = $request->requestParams();
206 206
         foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
207 207
             if ($subsection->form_data_present_in($form_data)) {
208
-                if (method_exists($this, '_validate_' . $subsection_name)) {
209
-                    call_user_func_array(array($this,'_validate_' . $subsection_name), array($subsection));
208
+                if (method_exists($this, '_validate_'.$subsection_name)) {
209
+                    call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection));
210 210
                 }
211 211
                 $subsection->_validate();
212 212
             } elseif ($subsection instanceof EE_Form_Section_Proper) {
Please login to merge, or discard this patch.
payment_methods/Paypal_Standard/EE_PMT_Paypal_Standard.pm.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
      */
30 30
     public function __construct($pm_instance = null)
31 31
     {
32
-        require_once($this->file_folder() . 'EEG_Paypal_Standard.gateway.php');
32
+        require_once($this->file_folder().'EEG_Paypal_Standard.gateway.php');
33 33
         $this->_gateway             = new EEG_Paypal_Standard();
34 34
         $this->_pretty_name         = esc_html__("PayPal Standard", 'event_espresso');
35 35
         $this->_default_description = sprintf(
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
             '</strong>'
42 42
         );
43 43
         parent::__construct($pm_instance);
44
-        $this->_default_button_url = $this->file_url() . 'lib/paypal-logo.png';
44
+        $this->_default_button_url = $this->file_url().'lib/paypal-logo.png';
45 45
     }
46 46
 
47 47
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
      */
66 66
     public function generate_new_settings_form()
67 67
     {
68
-        require_once($this->file_folder() . 'EE_Paypal_Standard_Form.form.php');
68
+        require_once($this->file_folder().'EE_Paypal_Standard_Form.form.php');
69 69
         $form = new EE_Paypal_Standard_Form($this);
70 70
         $form->get_input('PMD_debug_mode')->set_html_label_text(
71 71
             sprintf(esc_html__("Use PayPal Sandbox %s", 'event_espresso'), $this->get_help_tab_link())
Please login to merge, or discard this patch.
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -15,105 +15,105 @@
 block discarded – undo
15 15
  */
16 16
 class EE_PMT_Paypal_Standard extends EE_PMT_Base
17 17
 {
18
-    const shipping_info_none     = 1;
18
+	const shipping_info_none     = 1;
19 19
 
20
-    const shipping_info_optional = 0;
20
+	const shipping_info_optional = 0;
21 21
 
22
-    const shipping_info_required = 2;
22
+	const shipping_info_required = 2;
23 23
 
24 24
 
25
-    /**
26
-     * @param null $pm_instance
27
-     * @throws EE_Error
28
-     */
29
-    public function __construct($pm_instance = null)
30
-    {
31
-        require_once($this->file_folder() . 'EEG_Paypal_Standard.gateway.php');
32
-        $this->_gateway             = new EEG_Paypal_Standard();
33
-        $this->_pretty_name         = esc_html__("PayPal Standard", 'event_espresso');
34
-        $this->_default_description = sprintf(
35
-            esc_html__(
36
-                'Upon submitting this form, you will be forwarded to PayPal to make your payment. %1$sMake sure you return to this site in order to properly finalize your registration.%2$s',
37
-                'event_espresso'
38
-            ),
39
-            '<strong>',
40
-            '</strong>'
41
-        );
42
-        parent::__construct($pm_instance);
43
-        $this->_default_button_url = $this->file_url() . 'lib/paypal-logo.png';
44
-    }
25
+	/**
26
+	 * @param null $pm_instance
27
+	 * @throws EE_Error
28
+	 */
29
+	public function __construct($pm_instance = null)
30
+	{
31
+		require_once($this->file_folder() . 'EEG_Paypal_Standard.gateway.php');
32
+		$this->_gateway             = new EEG_Paypal_Standard();
33
+		$this->_pretty_name         = esc_html__("PayPal Standard", 'event_espresso');
34
+		$this->_default_description = sprintf(
35
+			esc_html__(
36
+				'Upon submitting this form, you will be forwarded to PayPal to make your payment. %1$sMake sure you return to this site in order to properly finalize your registration.%2$s',
37
+				'event_espresso'
38
+			),
39
+			'<strong>',
40
+			'</strong>'
41
+		);
42
+		parent::__construct($pm_instance);
43
+		$this->_default_button_url = $this->file_url() . 'lib/paypal-logo.png';
44
+	}
45 45
 
46 46
 
47
-    /**
48
-     * Creates the billing form for this payment method type
49
-     *
50
-     * @param EE_Transaction $transaction
51
-     * @return NULL
52
-     */
53
-    public function generate_new_billing_form(EE_Transaction $transaction = null)
54
-    {
55
-        return null;
56
-    }
47
+	/**
48
+	 * Creates the billing form for this payment method type
49
+	 *
50
+	 * @param EE_Transaction $transaction
51
+	 * @return NULL
52
+	 */
53
+	public function generate_new_billing_form(EE_Transaction $transaction = null)
54
+	{
55
+		return null;
56
+	}
57 57
 
58 58
 
59
-    /**
60
-     * Gets the form for all the settings related to this payment method type
61
-     *
62
-     * @return EE_Payment_Method_Form
63
-     * @throws EE_Error
64
-     */
65
-    public function generate_new_settings_form()
66
-    {
67
-        require_once($this->file_folder() . 'EE_Paypal_Standard_Form.form.php');
68
-        $form = new EE_Paypal_Standard_Form($this);
69
-        $form->get_input('PMD_debug_mode')->set_html_label_text(
70
-            sprintf(esc_html__("Use PayPal Sandbox %s", 'event_espresso'), $this->get_help_tab_link())
71
-        );
72
-        $form->get_input('shipping_details')->set_html_label_text(
73
-            sprintf(esc_html__("Shipping Address Options %s", "event_espresso"), $this->get_help_tab_link())
74
-        );
75
-        return $form;
76
-    }
59
+	/**
60
+	 * Gets the form for all the settings related to this payment method type
61
+	 *
62
+	 * @return EE_Payment_Method_Form
63
+	 * @throws EE_Error
64
+	 */
65
+	public function generate_new_settings_form()
66
+	{
67
+		require_once($this->file_folder() . 'EE_Paypal_Standard_Form.form.php');
68
+		$form = new EE_Paypal_Standard_Form($this);
69
+		$form->get_input('PMD_debug_mode')->set_html_label_text(
70
+			sprintf(esc_html__("Use PayPal Sandbox %s", 'event_espresso'), $this->get_help_tab_link())
71
+		);
72
+		$form->get_input('shipping_details')->set_html_label_text(
73
+			sprintf(esc_html__("Shipping Address Options %s", "event_espresso"), $this->get_help_tab_link())
74
+		);
75
+		return $form;
76
+	}
77 77
 
78 78
 
79
-    /**
80
-     * Adds the help tab
81
-     *
82
-     * @return array
83
-     * @see EE_PMT_Base::help_tabs_config()
84
-     */
85
-    public function help_tabs_config()
86
-    {
87
-        return [
88
-            $this->get_help_tab_name() => [
89
-                'title'    => esc_html__("PayPal Standard Settings", 'event_espresso'),
90
-                'filename' => 'payment_methods_overview_paypalstandard',
91
-            ],
92
-        ];
93
-    }
79
+	/**
80
+	 * Adds the help tab
81
+	 *
82
+	 * @return array
83
+	 * @see EE_PMT_Base::help_tabs_config()
84
+	 */
85
+	public function help_tabs_config()
86
+	{
87
+		return [
88
+			$this->get_help_tab_name() => [
89
+				'title'    => esc_html__("PayPal Standard Settings", 'event_espresso'),
90
+				'filename' => 'payment_methods_overview_paypalstandard',
91
+			],
92
+		];
93
+	}
94 94
 
95 95
 
96
-    /**
97
-     * Logic to be accomplished when the payment attempt is complete.
98
-     * Most payment methods don't need to do anything at this point; but some, like Mijireh, do.
99
-     * (Mijireh was an offsite gateway which doesn't send an IPN. So when the user returns to EE from
100
-     * Mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status
101
-     * of the payment). Fed a transaction because it's always assumed to be the last payment that
102
-     *
103
-     * @param EE_Transaction $transaction
104
-     * @return EE_Payment
105
-     * @throws EE_Error
106
-     */
107
-    public function finalize_payment_for($transaction)
108
-    {
109
-        /** @var RequestInterface $request */
110
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
111
-        // PayPal standard actually sends the IPN info along with the user when they return to our site
112
-        // so in case the IPN is arriving later, let's try to process an IPN!
113
-        if ($request->getServerParam('REQUEST_METHOD') === 'POST') {
114
-            return $this->handle_ipn($request->postParams(), $transaction);
115
-        } else {
116
-            return parent::finalize_payment_for($transaction);
117
-        }
118
-    }
96
+	/**
97
+	 * Logic to be accomplished when the payment attempt is complete.
98
+	 * Most payment methods don't need to do anything at this point; but some, like Mijireh, do.
99
+	 * (Mijireh was an offsite gateway which doesn't send an IPN. So when the user returns to EE from
100
+	 * Mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status
101
+	 * of the payment). Fed a transaction because it's always assumed to be the last payment that
102
+	 *
103
+	 * @param EE_Transaction $transaction
104
+	 * @return EE_Payment
105
+	 * @throws EE_Error
106
+	 */
107
+	public function finalize_payment_for($transaction)
108
+	{
109
+		/** @var RequestInterface $request */
110
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
111
+		// PayPal standard actually sends the IPN info along with the user when they return to our site
112
+		// so in case the IPN is arriving later, let's try to process an IPN!
113
+		if ($request->getServerParam('REQUEST_METHOD') === 'POST') {
114
+			return $this->handle_ipn($request->postParams(), $transaction);
115
+		} else {
116
+			return parent::finalize_payment_for($transaction);
117
+		}
118
+	}
119 119
 }
Please login to merge, or discard this patch.
modules/invalid_checkout_access/InvalidCheckoutAccess.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -59,14 +59,14 @@
 block discarded – undo
59 59
                 $ee_bot_checkout = array();
60 60
                 add_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout, '', false);
61 61
             }
62
-            if (! isset($ee_bot_checkout[ $ip_address ])) {
63
-                $ee_bot_checkout[ $ip_address ] = array();
62
+            if ( ! isset($ee_bot_checkout[$ip_address])) {
63
+                $ee_bot_checkout[$ip_address] = array();
64 64
             }
65 65
             $http_referer = esc_attr($request->getServerParam('HTTP_REFERER', 0));
66
-            if (! isset($ee_bot_checkout[ $ip_address ][ $http_referer ])) {
67
-                $ee_bot_checkout[ $ip_address ][ $http_referer ] = 0;
66
+            if ( ! isset($ee_bot_checkout[$ip_address][$http_referer])) {
67
+                $ee_bot_checkout[$ip_address][$http_referer] = 0;
68 68
             }
69
-            $ee_bot_checkout[ $ip_address ][ $http_referer ]++;
69
+            $ee_bot_checkout[$ip_address][$http_referer]++;
70 70
             update_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout);
71 71
             if (WP_DEBUG) {
72 72
                 EE_Error::add_error(
Please login to merge, or discard this patch.
Indentation   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -26,181 +26,181 @@
 block discarded – undo
26 26
  */
27 27
 class InvalidCheckoutAccess
28 28
 {
29
-    /**
30
-     * key used for saving invalid checkout access data to the wp_options table
31
-     */
32
-    const OPTION_KEY = 'ee_invalid_checkout_access';
29
+	/**
30
+	 * key used for saving invalid checkout access data to the wp_options table
31
+	 */
32
+	const OPTION_KEY = 'ee_invalid_checkout_access';
33 33
 
34 34
 
35
-    /**
36
-     * _block_bots
37
-     * checks that the incoming request has either of the following set:
38
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
39
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
40
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
41
-     * then where you coming from man?
42
-     *
43
-     * @param EE_Checkout $checkout
44
-     * @return bool true if access to registration checkout appears to be invalid
45
-     */
46
-    public function checkoutAccessIsInvalid(EE_Checkout $checkout)
47
-    {
48
-        if (
49
-            ! ($checkout->uts || $checkout->reg_url_link)
50
-            && ! (defined('DOING_AJAX') && DOING_AJAX)
51
-            && EE_Config::instance()->registration->track_invalid_checkout_access()
52
-        ) {
53
-            /** @var RequestInterface $request */
54
-            $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface');
55
-            $ip_address = $request->ipAddress();
56
-            $ee_bot_checkout = get_option(InvalidCheckoutAccess::OPTION_KEY);
57
-            if ($ee_bot_checkout === false) {
58
-                $ee_bot_checkout = array();
59
-                add_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout, '', false);
60
-            }
61
-            if (! isset($ee_bot_checkout[ $ip_address ])) {
62
-                $ee_bot_checkout[ $ip_address ] = array();
63
-            }
64
-            $http_referer = esc_attr($request->getServerParam('HTTP_REFERER', 0));
65
-            if (! isset($ee_bot_checkout[ $ip_address ][ $http_referer ])) {
66
-                $ee_bot_checkout[ $ip_address ][ $http_referer ] = 0;
67
-            }
68
-            $ee_bot_checkout[ $ip_address ][ $http_referer ]++;
69
-            update_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout);
70
-            if (WP_DEBUG) {
71
-                EE_Error::add_error(
72
-                    esc_html__('Direct access to the registration checkout page is not allowed.', 'event_espresso'),
73
-                    __FILE__,
74
-                    __FUNCTION__,
75
-                    __LINE__
76
-                );
77
-            }
78
-            return true;
79
-        }
80
-        return false;
81
-    }
35
+	/**
36
+	 * _block_bots
37
+	 * checks that the incoming request has either of the following set:
38
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
39
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
40
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
41
+	 * then where you coming from man?
42
+	 *
43
+	 * @param EE_Checkout $checkout
44
+	 * @return bool true if access to registration checkout appears to be invalid
45
+	 */
46
+	public function checkoutAccessIsInvalid(EE_Checkout $checkout)
47
+	{
48
+		if (
49
+			! ($checkout->uts || $checkout->reg_url_link)
50
+			&& ! (defined('DOING_AJAX') && DOING_AJAX)
51
+			&& EE_Config::instance()->registration->track_invalid_checkout_access()
52
+		) {
53
+			/** @var RequestInterface $request */
54
+			$request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface');
55
+			$ip_address = $request->ipAddress();
56
+			$ee_bot_checkout = get_option(InvalidCheckoutAccess::OPTION_KEY);
57
+			if ($ee_bot_checkout === false) {
58
+				$ee_bot_checkout = array();
59
+				add_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout, '', false);
60
+			}
61
+			if (! isset($ee_bot_checkout[ $ip_address ])) {
62
+				$ee_bot_checkout[ $ip_address ] = array();
63
+			}
64
+			$http_referer = esc_attr($request->getServerParam('HTTP_REFERER', 0));
65
+			if (! isset($ee_bot_checkout[ $ip_address ][ $http_referer ])) {
66
+				$ee_bot_checkout[ $ip_address ][ $http_referer ] = 0;
67
+			}
68
+			$ee_bot_checkout[ $ip_address ][ $http_referer ]++;
69
+			update_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout);
70
+			if (WP_DEBUG) {
71
+				EE_Error::add_error(
72
+					esc_html__('Direct access to the registration checkout page is not allowed.', 'event_espresso'),
73
+					__FILE__,
74
+					__FUNCTION__,
75
+					__LINE__
76
+				);
77
+			}
78
+			return true;
79
+		}
80
+		return false;
81
+	}
82 82
 
83 83
 
84
-    /**
85
-     * _invalid_checkout_access_form
86
-     *
87
-     * @return EE_Form_Section_Proper
88
-     * @throws EE_Error
89
-     */
90
-    public function getForm()
91
-    {
92
-        return new EE_Form_Section_Proper(
93
-            array(
94
-                'name'            => 'invalid_checkout_access',
95
-                'html_id'         => 'invalid_checkout_access',
96
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
97
-                'subsections'     => array(
98
-                    'invalid_checkout_access_hdr'   => new EE_Form_Section_HTML(
99
-                        EEH_HTML::h2(esc_html__('Invalid Checkout Access', 'event_espresso'))
100
-                    ),
101
-                    'ee_bot_checkout_data'          => new EE_Text_Area_Input(
102
-                        array(
103
-                            'html_label_text' => esc_html__('Invalid Checkout Data', 'event_espresso'),
104
-                            'default'         => var_export(
105
-                                get_option(InvalidCheckoutAccess::OPTION_KEY, array()),
106
-                                true
107
-                            ),
108
-                            'required'        => false,
109
-                            'html_help_text'  => esc_html__(
110
-                                'Event Espresso blocks any attempt to directly access the registration checkout page, that is NOT from a Ticket Selector or for a return visit for a valid transaction. These are not valid requests accessing your checkout page, so we track the IP addresses, what web page they just came from, and the number of times that they have attempted to access your registration page. This information may help you with protecting your site by other means, such as firewalls, etc, but please note that IP addresses are almost guaranteed to be spoofed by malicious agents.',
111
-                                'event_espresso'
112
-                            ),
113
-                        )
114
-                    ),
115
-                    'track_invalid_checkout_access' => new EE_Yes_No_Input(
116
-                        array(
117
-                            'html_label_text'         => esc_html__('Track Invalid Checkout Access?', 'event_espresso'),
118
-                            'html_help_text'          => esc_html__(
119
-                                'Controls whether or not invalid attempts to directly access the registration checkout page should be tracked. Setting this to "No" means that the above data will no longer be collected.',
120
-                                'event_espresso'
121
-                            ),
122
-                            'default'                 => EE_Config::instance()
123
-                                ->registration
124
-                                ->track_invalid_checkout_access(),
125
-                            'display_html_label_text' => false,
126
-                        )
127
-                    ),
128
-                    'delete_invalid_checkout_data'  => new EE_Yes_No_Input(
129
-                        array(
130
-                            'html_label_text'         => esc_html__('Reset Invalid Checkout Data', 'event_espresso'),
131
-                            'html_help_text'          => esc_html__(
132
-                                'Setting this to "Yes" will delete all existing invalid checkout access data.',
133
-                                'event_espresso'
134
-                            ),
135
-                            'default'                 => false,
136
-                            'display_html_label_text' => false,
137
-                        )
138
-                    ),
139
-                ),
140
-            )
141
-        );
142
-    }
84
+	/**
85
+	 * _invalid_checkout_access_form
86
+	 *
87
+	 * @return EE_Form_Section_Proper
88
+	 * @throws EE_Error
89
+	 */
90
+	public function getForm()
91
+	{
92
+		return new EE_Form_Section_Proper(
93
+			array(
94
+				'name'            => 'invalid_checkout_access',
95
+				'html_id'         => 'invalid_checkout_access',
96
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
97
+				'subsections'     => array(
98
+					'invalid_checkout_access_hdr'   => new EE_Form_Section_HTML(
99
+						EEH_HTML::h2(esc_html__('Invalid Checkout Access', 'event_espresso'))
100
+					),
101
+					'ee_bot_checkout_data'          => new EE_Text_Area_Input(
102
+						array(
103
+							'html_label_text' => esc_html__('Invalid Checkout Data', 'event_espresso'),
104
+							'default'         => var_export(
105
+								get_option(InvalidCheckoutAccess::OPTION_KEY, array()),
106
+								true
107
+							),
108
+							'required'        => false,
109
+							'html_help_text'  => esc_html__(
110
+								'Event Espresso blocks any attempt to directly access the registration checkout page, that is NOT from a Ticket Selector or for a return visit for a valid transaction. These are not valid requests accessing your checkout page, so we track the IP addresses, what web page they just came from, and the number of times that they have attempted to access your registration page. This information may help you with protecting your site by other means, such as firewalls, etc, but please note that IP addresses are almost guaranteed to be spoofed by malicious agents.',
111
+								'event_espresso'
112
+							),
113
+						)
114
+					),
115
+					'track_invalid_checkout_access' => new EE_Yes_No_Input(
116
+						array(
117
+							'html_label_text'         => esc_html__('Track Invalid Checkout Access?', 'event_espresso'),
118
+							'html_help_text'          => esc_html__(
119
+								'Controls whether or not invalid attempts to directly access the registration checkout page should be tracked. Setting this to "No" means that the above data will no longer be collected.',
120
+								'event_espresso'
121
+							),
122
+							'default'                 => EE_Config::instance()
123
+								->registration
124
+								->track_invalid_checkout_access(),
125
+							'display_html_label_text' => false,
126
+						)
127
+					),
128
+					'delete_invalid_checkout_data'  => new EE_Yes_No_Input(
129
+						array(
130
+							'html_label_text'         => esc_html__('Reset Invalid Checkout Data', 'event_espresso'),
131
+							'html_help_text'          => esc_html__(
132
+								'Setting this to "Yes" will delete all existing invalid checkout access data.',
133
+								'event_espresso'
134
+							),
135
+							'default'                 => false,
136
+							'display_html_label_text' => false,
137
+						)
138
+					),
139
+				),
140
+			)
141
+		);
142
+	}
143 143
 
144 144
 
145
-    /**
146
-     * update_invalid_checkout_access_form
147
-     *
148
-     * @param EE_Registration_Config $EE_Registration_Config
149
-     * @return EE_Registration_Config
150
-     * @throws EE_Error
151
-     * @throws ReflectionException
152
-     */
153
-    public function processForm(EE_Registration_Config $EE_Registration_Config)
154
-    {
155
-        try {
156
-            $invalid_checkout_access_form = $this->getForm();
157
-            // if not displaying a form, then check for form submission
158
-            if ($invalid_checkout_access_form->was_submitted()) {
159
-                // capture form data
160
-                $invalid_checkout_access_form->receive_form_submission();
161
-                // validate form data
162
-                if ($invalid_checkout_access_form->is_valid()) {
163
-                    // grab validated data from form
164
-                    $valid_data = $invalid_checkout_access_form->valid_data();
165
-                    // ensure form inputs we want are set
166
-                    if (
167
-                        isset(
168
-                            $valid_data['track_invalid_checkout_access'],
169
-                            $valid_data['delete_invalid_checkout_data']
170
-                        )
171
-                    ) {
172
-                        $EE_Registration_Config->set_track_invalid_checkout_access(
173
-                            $valid_data['track_invalid_checkout_access']
174
-                        );
175
-                        // if deleting, then update option with empty array
176
-                        if (filter_var($valid_data['delete_invalid_checkout_data'], FILTER_VALIDATE_BOOLEAN)) {
177
-                            update_option(InvalidCheckoutAccess::OPTION_KEY, array());
178
-                        }
179
-                    } else {
180
-                        EE_Error::add_error(
181
-                            esc_html__(
182
-                                'Invalid or missing Invalid Checkout Access form data. Please refresh the form and try again.',
183
-                                'event_espresso'
184
-                            ),
185
-                            __FILE__,
186
-                            __FUNCTION__,
187
-                            __LINE__
188
-                        );
189
-                    }
190
-                } else {
191
-                    if ($invalid_checkout_access_form->submission_error_message() !== '') {
192
-                        EE_Error::add_error(
193
-                            $invalid_checkout_access_form->submission_error_message(),
194
-                            __FILE__,
195
-                            __FUNCTION__,
196
-                            __LINE__
197
-                        );
198
-                    }
199
-                }
200
-            }
201
-        } catch (EE_Error $e) {
202
-            $e->get_error();
203
-        }
204
-        return $EE_Registration_Config;
205
-    }
145
+	/**
146
+	 * update_invalid_checkout_access_form
147
+	 *
148
+	 * @param EE_Registration_Config $EE_Registration_Config
149
+	 * @return EE_Registration_Config
150
+	 * @throws EE_Error
151
+	 * @throws ReflectionException
152
+	 */
153
+	public function processForm(EE_Registration_Config $EE_Registration_Config)
154
+	{
155
+		try {
156
+			$invalid_checkout_access_form = $this->getForm();
157
+			// if not displaying a form, then check for form submission
158
+			if ($invalid_checkout_access_form->was_submitted()) {
159
+				// capture form data
160
+				$invalid_checkout_access_form->receive_form_submission();
161
+				// validate form data
162
+				if ($invalid_checkout_access_form->is_valid()) {
163
+					// grab validated data from form
164
+					$valid_data = $invalid_checkout_access_form->valid_data();
165
+					// ensure form inputs we want are set
166
+					if (
167
+						isset(
168
+							$valid_data['track_invalid_checkout_access'],
169
+							$valid_data['delete_invalid_checkout_data']
170
+						)
171
+					) {
172
+						$EE_Registration_Config->set_track_invalid_checkout_access(
173
+							$valid_data['track_invalid_checkout_access']
174
+						);
175
+						// if deleting, then update option with empty array
176
+						if (filter_var($valid_data['delete_invalid_checkout_data'], FILTER_VALIDATE_BOOLEAN)) {
177
+							update_option(InvalidCheckoutAccess::OPTION_KEY, array());
178
+						}
179
+					} else {
180
+						EE_Error::add_error(
181
+							esc_html__(
182
+								'Invalid or missing Invalid Checkout Access form data. Please refresh the form and try again.',
183
+								'event_espresso'
184
+							),
185
+							__FILE__,
186
+							__FUNCTION__,
187
+							__LINE__
188
+						);
189
+					}
190
+				} else {
191
+					if ($invalid_checkout_access_form->submission_error_message() !== '') {
192
+						EE_Error::add_error(
193
+							$invalid_checkout_access_form->submission_error_message(),
194
+							__FILE__,
195
+							__FUNCTION__,
196
+							__LINE__
197
+						);
198
+					}
199
+				}
200
+			}
201
+		} catch (EE_Error $e) {
202
+			$e->get_error();
203
+		}
204
+		return $EE_Registration_Config;
205
+	}
206 206
 }
Please login to merge, or discard this patch.
messages/defaults/default/html_receipt_ticket_line_item_no_pms.template.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
 <tr class="item">
9 9
     <td>[LINE_ITEM_NAME][LINE_ITEM_TAXABLE_*]</td>
10 10
     <td colspan="2">[LINE_ITEM_DESCRIPTION]
11
-        <p class="ticket-note"><?php echo sprintf(esc_html__('This ticket can be used once at %s of the dates/times below.', 'event_espresso'), '[TKT_USES_* schema=' . esc_html__('any', 'event_espresso') . ']'); ?></p>
11
+        <p class="ticket-note"><?php echo sprintf(esc_html__('This ticket can be used once at %s of the dates/times below.', 'event_espresso'), '[TKT_USES_* schema='.esc_html__('any', 'event_espresso').']'); ?></p>
12 12
     </td>
13 13
     <td class="item_c">[LINE_ITEM_QUANTITY]</td>
14 14
     <td class="item_c">[LINE_ITEM_AMOUNT]</td>
Please login to merge, or discard this patch.
caffeinated/modules/event_single_caff/EED_Event_Single_Caff.module.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
     {
93 93
         wp_register_style(
94 94
             'eed-event-single-sortable',
95
-            EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.css',
95
+            EVENT_SINGLE_CAFF_ASSETS_URL.'eed_event_single_sortable.css',
96 96
             array(),
97 97
             EVENT_ESPRESSO_VERSION
98 98
         );
99 99
         wp_enqueue_style('eed-event-single-sortable');
100 100
         wp_register_script(
101 101
             'eed-event-single-sortable',
102
-            EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.js',
102
+            EVENT_SINGLE_CAFF_ASSETS_URL.'eed_event_single_sortable.js',
103 103
             array('jquery-ui-sortable'),
104 104
             EVENT_ESPRESSO_VERSION,
105 105
             true
@@ -113,9 +113,9 @@  discard block
 block discarded – undo
113 113
      */
114 114
     public static function setDefinitions()
115 115
     {
116
-        if (! defined('EVENT_SINGLE_CAFF_TEMPLATES_PATH')) {
117
-            define('EVENT_SINGLE_CAFF_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/');
118
-            define('EVENT_SINGLE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
116
+        if ( ! defined('EVENT_SINGLE_CAFF_TEMPLATES_PATH')) {
117
+            define('EVENT_SINGLE_CAFF_TEMPLATES_PATH', plugin_dir_path(__FILE__).'templates/');
118
+            define('EVENT_SINGLE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__).'assets/');
119 119
         }
120 120
     }
121 121
 
@@ -137,10 +137,10 @@  discard block
 block discarded – undo
137 137
         $config = apply_filters('FHEE__EED_Event_Single__template_settings_form__event_list_config', $config);
138 138
 
139 139
         $event_single_order_array = array();
140
-        $event_single_order_array[ $config->display_order_tickets ] = 'tickets';
141
-        $event_single_order_array[ $config->display_order_datetimes ] = 'datetimes';
142
-        $event_single_order_array[ $config->display_order_event ] = 'event';
143
-        $event_single_order_array[ $config->display_order_venue ] = 'venue';
140
+        $event_single_order_array[$config->display_order_tickets] = 'tickets';
141
+        $event_single_order_array[$config->display_order_datetimes] = 'datetimes';
142
+        $event_single_order_array[$config->display_order_event] = 'event';
143
+        $event_single_order_array[$config->display_order_venue] = 'venue';
144 144
         // get template parts
145 145
         $template_parts = EED_Event_Single::instance()->initialize_template_parts($config);
146 146
         // convert to array so that we can add more properties
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
             'single-sortable-li single-sortable-js'
152 152
         );
153 153
         EEH_Template::display_template(
154
-            EVENT_SINGLE_CAFF_TEMPLATES_PATH . 'admin-event-single-settings.template.php',
154
+            EVENT_SINGLE_CAFF_TEMPLATES_PATH.'admin-event-single-settings.template.php',
155 155
             $config
156 156
         );
157 157
     }
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
      */
167 167
     public static function update_template_settings(EE_Template_Config $CFG, $REQ)
168 168
     {
169
-        if (! $CFG->EED_Event_Single instanceof EE_Event_Single_Config) {
169
+        if ( ! $CFG->EED_Event_Single instanceof EE_Event_Single_Config) {
170 170
             $CFG->EED_Event_Single = new EE_Event_Single_Config();
171 171
         }
172 172
         $display_order_event = $CFG->EED_Event_Single->display_order_event !== null
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
     {
216 216
         $config_saved = false;
217 217
         $template_parts = EED_Event_Single_Caff::getRequest()->getRequestParam('elements');
218
-        if (! empty($template_parts)) {
218
+        if ( ! empty($template_parts)) {
219 219
             $template_parts = explode(',', trim($template_parts, ','));
220 220
             foreach ($template_parts as $key => $template_part) {
221 221
                 $template_part = "display_order_$template_part";
Please login to merge, or discard this patch.
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -24,228 +24,228 @@
 block discarded – undo
24 24
  */
25 25
 class EED_Event_Single_Caff extends EED_Event_Single
26 26
 {
27
-    /**
28
-     * @return EED_Event_Single_Caff
29
-     */
30
-    public static function instance()
31
-    {
32
-        return parent::get_instance(__CLASS__);
33
-    }
34
-
35
-
36
-    /**
37
-     *    set_hooks - for hooking into EE Core, other modules, etc
38
-     *
39
-     * @access    public
40
-     * @return    void
41
-     */
42
-    public static function set_hooks()
43
-    {
44
-    }
45
-
46
-    /**
47
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
48
-     *
49
-     * @access    public
50
-     * @return    void
51
-     */
52
-    public static function set_hooks_admin()
53
-    {
54
-        self::setDefinitions();
55
-        add_action(
56
-            'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__template_settings',
57
-            array('EED_Event_Single_Caff', 'load_scripts_styles'),
58
-            10
59
-        );
60
-        add_action(
61
-            'AHEE__template_settings__template__before_settings_form',
62
-            array('EED_Event_Single_Caff', 'template_settings_form'),
63
-            10
64
-        );
65
-        add_filter(
66
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
67
-            array('EED_Event_Single_Caff', 'update_template_settings'),
68
-            10,
69
-            2
70
-        );
71
-        // AJAX
72
-        add_action(
73
-            'wp_ajax_espresso_update_event_single_order',
74
-            array('EED_Event_Single_Caff', 'update_event_single_order')
75
-        );
76
-        add_action(
77
-            'wp_ajax_nopriv_espresso_update_event_single_order',
78
-            array('EED_Event_Single_Caff', 'update_event_single_order')
79
-        );
80
-    }
81
-
82
-
83
-    public static function load_scripts_styles()
84
-    {
85
-        add_action('admin_enqueue_scripts', array('EED_Event_Single_Caff', 'enqueue_scripts_styles'), 10);
86
-    }
87
-
88
-
89
-    public static function enqueue_scripts_styles()
90
-    {
91
-        wp_register_style(
92
-            'eed-event-single-sortable',
93
-            EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.css',
94
-            array(),
95
-            EVENT_ESPRESSO_VERSION
96
-        );
97
-        wp_enqueue_style('eed-event-single-sortable');
98
-        wp_register_script(
99
-            'eed-event-single-sortable',
100
-            EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.js',
101
-            array('jquery-ui-sortable'),
102
-            EVENT_ESPRESSO_VERSION,
103
-            true
104
-        );
105
-        wp_enqueue_script('eed-event-single-sortable');
106
-    }
107
-
108
-
109
-    /**
110
-     * Set constants only if they haven't been set yet.
111
-     */
112
-    public static function setDefinitions()
113
-    {
114
-        if (! defined('EVENT_SINGLE_CAFF_TEMPLATES_PATH')) {
115
-            define('EVENT_SINGLE_CAFF_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/');
116
-            define('EVENT_SINGLE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
117
-        }
118
-    }
119
-
120
-
121
-    /**
122
-     *    template_settings_form
123
-     *
124
-     * @access    public
125
-     * @static
126
-     * @return    void
127
-     */
128
-    public static function template_settings_form()
129
-    {
130
-        $config = EE_Registry::instance()->CFG->template_settings;
131
-        $config = isset($config->EED_Event_Single) && $config->EED_Event_Single instanceof EE_Event_Single_Config
132
-            ? $config->EED_Event_Single : new EE_Event_Single_Config();
133
-        $config->use_sortable_display_order = isset($config->use_sortable_display_order)
134
-            ? $config->use_sortable_display_order : false;
135
-        $config = apply_filters('FHEE__EED_Event_Single__template_settings_form__event_list_config', $config);
136
-
137
-        $event_single_order_array = array();
138
-        $event_single_order_array[ $config->display_order_tickets ] = 'tickets';
139
-        $event_single_order_array[ $config->display_order_datetimes ] = 'datetimes';
140
-        $event_single_order_array[ $config->display_order_event ] = 'event';
141
-        $event_single_order_array[ $config->display_order_venue ] = 'venue';
142
-        // get template parts
143
-        $template_parts = EED_Event_Single::instance()->initialize_template_parts($config);
144
-        // convert to array so that we can add more properties
145
-        $config = get_object_vars($config);
146
-        $config['event_single_display_order'] = $template_parts->generate_sortable_list_of_template_parts(
147
-            'event-single-sortable-js',
148
-            '',
149
-            'single-sortable-li single-sortable-js'
150
-        );
151
-        EEH_Template::display_template(
152
-            EVENT_SINGLE_CAFF_TEMPLATES_PATH . 'admin-event-single-settings.template.php',
153
-            $config
154
-        );
155
-    }
156
-
157
-
158
-    /**
159
-     * update_template_settings
160
-     *
161
-     * @param EE_Template_Config $CFG
162
-     * @param array              $REQ
163
-     * @return EE_Template_Config
164
-     */
165
-    public static function update_template_settings(EE_Template_Config $CFG, $REQ)
166
-    {
167
-        if (! $CFG->EED_Event_Single instanceof EE_Event_Single_Config) {
168
-            $CFG->EED_Event_Single = new EE_Event_Single_Config();
169
-        }
170
-        $display_order_event = $CFG->EED_Event_Single->display_order_event !== null
171
-            ? $CFG->EED_Event_Single->display_order_event
172
-            : EED_Event_Single::EVENT_DETAILS_PRIORITY;
173
-        $display_order_datetimes = $CFG->EED_Event_Single->display_order_datetimes !== null
174
-            ? $CFG->EED_Event_Single->display_order_datetimes
175
-            : EED_Event_Single::EVENT_DATETIMES_PRIORITY;
176
-        $display_order_tickets = $CFG->EED_Event_Single->display_order_tickets !== null
177
-            ? $CFG->EED_Event_Single->display_order_tickets
178
-            : EED_Event_Single::EVENT_TICKETS_PRIORITY;
179
-        $display_order_venue = $CFG->EED_Event_Single->display_order_venue !== null
180
-            ? $CFG->EED_Event_Single->display_order_venue
181
-            : EED_Event_Single::EVENT_VENUES_PRIORITY;
182
-        $CFG->EED_Event_Single = new EE_Event_Single_Config();
183
-        $CFG->EED_Event_Single->display_status_banner_single = ! empty($REQ['display_status_banner_single'])
184
-                                                               && $REQ['display_status_banner_single'];
185
-        $CFG->EED_Event_Single->display_venue = ! empty($REQ['display_venue']) && $REQ['display_venue'];
186
-        $CFG->EED_Event_Single->use_sortable_display_order = ! empty($REQ['EED_Events_Single_use_sortable_display_order'])
187
-            ? absint($REQ['EED_Events_Single_use_sortable_display_order'])
188
-            : 0;
189
-        $CFG->EED_Event_Single->display_order_event = $CFG->EED_Event_Single->use_sortable_display_order
190
-            ? $display_order_event
191
-            : EED_Event_Single::EVENT_DETAILS_PRIORITY;
192
-        $CFG->EED_Event_Single->display_order_datetimes = $CFG->EED_Event_Single->use_sortable_display_order
193
-            ? $display_order_datetimes
194
-            : EED_Event_Single::EVENT_DATETIMES_PRIORITY;
195
-        $CFG->EED_Event_Single->display_order_tickets = $CFG->EED_Event_Single->use_sortable_display_order
196
-            ? $display_order_tickets
197
-            : EED_Event_Single::EVENT_TICKETS_PRIORITY;
198
-        $CFG->EED_Event_Single->display_order_venue = $CFG->EED_Event_Single->use_sortable_display_order
199
-            ? $display_order_venue
200
-            : EED_Event_Single::EVENT_VENUES_PRIORITY;
201
-        do_action('AHEE__EED_Event_Single__update_template_settings__after_update', $CFG, $REQ);
202
-        return $CFG;
203
-    }
204
-
205
-
206
-    /**
207
-     * update_event_single_order
208
-     *
209
-     * @access    public
210
-     * @return    void
211
-     */
212
-    public static function update_event_single_order()
213
-    {
214
-        $config_saved = false;
215
-        $template_parts = EED_Event_Single_Caff::getRequest()->getRequestParam('elements');
216
-        if (! empty($template_parts)) {
217
-            $template_parts = explode(',', trim($template_parts, ','));
218
-            foreach ($template_parts as $key => $template_part) {
219
-                $template_part = "display_order_$template_part";
220
-                $priority = ($key * 10) + EED_Event_Single::EVENT_DETAILS_PRIORITY;
221
-                EE_Registry::instance()->CFG->template_settings->EED_Event_Single->{$template_part} = $priority;
222
-                do_action("AHEE__EED_Event_Single__update_event_single_order__$template_part", $priority);
223
-            }
224
-            $config_saved = EE_Registry::instance()->CFG->update_espresso_config(false, false);
225
-        }
226
-        if ($config_saved) {
227
-            EE_Error::add_success(esc_html__('Display Order has been successfully updated.', 'event_espresso'));
228
-        } else {
229
-            EE_Error::add_error(
230
-                esc_html__('Display Order was not updated.', 'event_espresso'),
231
-                __FILE__,
232
-                __FUNCTION__,
233
-                __LINE__
234
-            );
235
-        }
236
-        echo wp_json_encode(EE_Error::get_notices(false));
237
-        exit();
238
-    }
239
-
240
-
241
-    /**
242
-     *    run - initial module setup
243
-     *
244
-     * @access    public
245
-     * @param WP $WP
246
-     * @return    void
247
-     */
248
-    public function run($WP)
249
-    {
250
-    }
27
+	/**
28
+	 * @return EED_Event_Single_Caff
29
+	 */
30
+	public static function instance()
31
+	{
32
+		return parent::get_instance(__CLASS__);
33
+	}
34
+
35
+
36
+	/**
37
+	 *    set_hooks - for hooking into EE Core, other modules, etc
38
+	 *
39
+	 * @access    public
40
+	 * @return    void
41
+	 */
42
+	public static function set_hooks()
43
+	{
44
+	}
45
+
46
+	/**
47
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
48
+	 *
49
+	 * @access    public
50
+	 * @return    void
51
+	 */
52
+	public static function set_hooks_admin()
53
+	{
54
+		self::setDefinitions();
55
+		add_action(
56
+			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__template_settings',
57
+			array('EED_Event_Single_Caff', 'load_scripts_styles'),
58
+			10
59
+		);
60
+		add_action(
61
+			'AHEE__template_settings__template__before_settings_form',
62
+			array('EED_Event_Single_Caff', 'template_settings_form'),
63
+			10
64
+		);
65
+		add_filter(
66
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
67
+			array('EED_Event_Single_Caff', 'update_template_settings'),
68
+			10,
69
+			2
70
+		);
71
+		// AJAX
72
+		add_action(
73
+			'wp_ajax_espresso_update_event_single_order',
74
+			array('EED_Event_Single_Caff', 'update_event_single_order')
75
+		);
76
+		add_action(
77
+			'wp_ajax_nopriv_espresso_update_event_single_order',
78
+			array('EED_Event_Single_Caff', 'update_event_single_order')
79
+		);
80
+	}
81
+
82
+
83
+	public static function load_scripts_styles()
84
+	{
85
+		add_action('admin_enqueue_scripts', array('EED_Event_Single_Caff', 'enqueue_scripts_styles'), 10);
86
+	}
87
+
88
+
89
+	public static function enqueue_scripts_styles()
90
+	{
91
+		wp_register_style(
92
+			'eed-event-single-sortable',
93
+			EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.css',
94
+			array(),
95
+			EVENT_ESPRESSO_VERSION
96
+		);
97
+		wp_enqueue_style('eed-event-single-sortable');
98
+		wp_register_script(
99
+			'eed-event-single-sortable',
100
+			EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.js',
101
+			array('jquery-ui-sortable'),
102
+			EVENT_ESPRESSO_VERSION,
103
+			true
104
+		);
105
+		wp_enqueue_script('eed-event-single-sortable');
106
+	}
107
+
108
+
109
+	/**
110
+	 * Set constants only if they haven't been set yet.
111
+	 */
112
+	public static function setDefinitions()
113
+	{
114
+		if (! defined('EVENT_SINGLE_CAFF_TEMPLATES_PATH')) {
115
+			define('EVENT_SINGLE_CAFF_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/');
116
+			define('EVENT_SINGLE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
117
+		}
118
+	}
119
+
120
+
121
+	/**
122
+	 *    template_settings_form
123
+	 *
124
+	 * @access    public
125
+	 * @static
126
+	 * @return    void
127
+	 */
128
+	public static function template_settings_form()
129
+	{
130
+		$config = EE_Registry::instance()->CFG->template_settings;
131
+		$config = isset($config->EED_Event_Single) && $config->EED_Event_Single instanceof EE_Event_Single_Config
132
+			? $config->EED_Event_Single : new EE_Event_Single_Config();
133
+		$config->use_sortable_display_order = isset($config->use_sortable_display_order)
134
+			? $config->use_sortable_display_order : false;
135
+		$config = apply_filters('FHEE__EED_Event_Single__template_settings_form__event_list_config', $config);
136
+
137
+		$event_single_order_array = array();
138
+		$event_single_order_array[ $config->display_order_tickets ] = 'tickets';
139
+		$event_single_order_array[ $config->display_order_datetimes ] = 'datetimes';
140
+		$event_single_order_array[ $config->display_order_event ] = 'event';
141
+		$event_single_order_array[ $config->display_order_venue ] = 'venue';
142
+		// get template parts
143
+		$template_parts = EED_Event_Single::instance()->initialize_template_parts($config);
144
+		// convert to array so that we can add more properties
145
+		$config = get_object_vars($config);
146
+		$config['event_single_display_order'] = $template_parts->generate_sortable_list_of_template_parts(
147
+			'event-single-sortable-js',
148
+			'',
149
+			'single-sortable-li single-sortable-js'
150
+		);
151
+		EEH_Template::display_template(
152
+			EVENT_SINGLE_CAFF_TEMPLATES_PATH . 'admin-event-single-settings.template.php',
153
+			$config
154
+		);
155
+	}
156
+
157
+
158
+	/**
159
+	 * update_template_settings
160
+	 *
161
+	 * @param EE_Template_Config $CFG
162
+	 * @param array              $REQ
163
+	 * @return EE_Template_Config
164
+	 */
165
+	public static function update_template_settings(EE_Template_Config $CFG, $REQ)
166
+	{
167
+		if (! $CFG->EED_Event_Single instanceof EE_Event_Single_Config) {
168
+			$CFG->EED_Event_Single = new EE_Event_Single_Config();
169
+		}
170
+		$display_order_event = $CFG->EED_Event_Single->display_order_event !== null
171
+			? $CFG->EED_Event_Single->display_order_event
172
+			: EED_Event_Single::EVENT_DETAILS_PRIORITY;
173
+		$display_order_datetimes = $CFG->EED_Event_Single->display_order_datetimes !== null
174
+			? $CFG->EED_Event_Single->display_order_datetimes
175
+			: EED_Event_Single::EVENT_DATETIMES_PRIORITY;
176
+		$display_order_tickets = $CFG->EED_Event_Single->display_order_tickets !== null
177
+			? $CFG->EED_Event_Single->display_order_tickets
178
+			: EED_Event_Single::EVENT_TICKETS_PRIORITY;
179
+		$display_order_venue = $CFG->EED_Event_Single->display_order_venue !== null
180
+			? $CFG->EED_Event_Single->display_order_venue
181
+			: EED_Event_Single::EVENT_VENUES_PRIORITY;
182
+		$CFG->EED_Event_Single = new EE_Event_Single_Config();
183
+		$CFG->EED_Event_Single->display_status_banner_single = ! empty($REQ['display_status_banner_single'])
184
+															   && $REQ['display_status_banner_single'];
185
+		$CFG->EED_Event_Single->display_venue = ! empty($REQ['display_venue']) && $REQ['display_venue'];
186
+		$CFG->EED_Event_Single->use_sortable_display_order = ! empty($REQ['EED_Events_Single_use_sortable_display_order'])
187
+			? absint($REQ['EED_Events_Single_use_sortable_display_order'])
188
+			: 0;
189
+		$CFG->EED_Event_Single->display_order_event = $CFG->EED_Event_Single->use_sortable_display_order
190
+			? $display_order_event
191
+			: EED_Event_Single::EVENT_DETAILS_PRIORITY;
192
+		$CFG->EED_Event_Single->display_order_datetimes = $CFG->EED_Event_Single->use_sortable_display_order
193
+			? $display_order_datetimes
194
+			: EED_Event_Single::EVENT_DATETIMES_PRIORITY;
195
+		$CFG->EED_Event_Single->display_order_tickets = $CFG->EED_Event_Single->use_sortable_display_order
196
+			? $display_order_tickets
197
+			: EED_Event_Single::EVENT_TICKETS_PRIORITY;
198
+		$CFG->EED_Event_Single->display_order_venue = $CFG->EED_Event_Single->use_sortable_display_order
199
+			? $display_order_venue
200
+			: EED_Event_Single::EVENT_VENUES_PRIORITY;
201
+		do_action('AHEE__EED_Event_Single__update_template_settings__after_update', $CFG, $REQ);
202
+		return $CFG;
203
+	}
204
+
205
+
206
+	/**
207
+	 * update_event_single_order
208
+	 *
209
+	 * @access    public
210
+	 * @return    void
211
+	 */
212
+	public static function update_event_single_order()
213
+	{
214
+		$config_saved = false;
215
+		$template_parts = EED_Event_Single_Caff::getRequest()->getRequestParam('elements');
216
+		if (! empty($template_parts)) {
217
+			$template_parts = explode(',', trim($template_parts, ','));
218
+			foreach ($template_parts as $key => $template_part) {
219
+				$template_part = "display_order_$template_part";
220
+				$priority = ($key * 10) + EED_Event_Single::EVENT_DETAILS_PRIORITY;
221
+				EE_Registry::instance()->CFG->template_settings->EED_Event_Single->{$template_part} = $priority;
222
+				do_action("AHEE__EED_Event_Single__update_event_single_order__$template_part", $priority);
223
+			}
224
+			$config_saved = EE_Registry::instance()->CFG->update_espresso_config(false, false);
225
+		}
226
+		if ($config_saved) {
227
+			EE_Error::add_success(esc_html__('Display Order has been successfully updated.', 'event_espresso'));
228
+		} else {
229
+			EE_Error::add_error(
230
+				esc_html__('Display Order was not updated.', 'event_espresso'),
231
+				__FILE__,
232
+				__FUNCTION__,
233
+				__LINE__
234
+			);
235
+		}
236
+		echo wp_json_encode(EE_Error::get_notices(false));
237
+		exit();
238
+	}
239
+
240
+
241
+	/**
242
+	 *    run - initial module setup
243
+	 *
244
+	 * @access    public
245
+	 * @param WP $WP
246
+	 * @return    void
247
+	 */
248
+	public function run($WP)
249
+	{
250
+	}
251 251
 }
Please login to merge, or discard this patch.
caffeinated/modules/events_archive_caff/EED_Events_Archive_Caff.module.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -79,12 +79,12 @@  discard block
 block discarded – undo
79 79
      */
80 80
     public static function setDefinitions()
81 81
     {
82
-        if (! defined('EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH')) {
82
+        if ( ! defined('EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH')) {
83 83
             define(
84 84
                 'EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH',
85
-                str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates/'
85
+                str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates/'
86 86
             );
87
-            define('EVENT_ARCHIVE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
87
+            define('EVENT_ARCHIVE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__).'assets/');
88 88
         }
89 89
     }
90 90
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
             'archive-sortable-li archive-sortable-js'
163 163
         );
164 164
         EEH_Template::display_template(
165
-            EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
165
+            EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH.'admin-event-list-settings.template.php',
166 166
             $config
167 167
         );
168 168
     }
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
         $config = EE_Registry::instance()->CFG;
241 241
         $config_saved = false;
242 242
         $template_parts = EED_Events_Archive_Caff::getRequest()->getRequestParam('elements');
243
-        if (! empty($template_parts)) {
243
+        if ( ! empty($template_parts)) {
244 244
             $template_parts = explode(',', trim($template_parts, ','));
245 245
             foreach ($template_parts as $key => $template_part) {
246 246
                 $template_part = "display_order_$template_part";
Please login to merge, or discard this patch.
Indentation   +249 added lines, -249 removed lines patch added patch discarded remove patch
@@ -13,268 +13,268 @@
 block discarded – undo
13 13
  */
14 14
 class EED_Events_Archive_Caff extends EED_Events_Archive
15 15
 {
16
-    /**
17
-     * @return EED_Events_Archive_Caff|EED_Module
18
-     */
19
-    public static function instance()
20
-    {
21
-        return parent::get_instance(__CLASS__);
22
-    }
16
+	/**
17
+	 * @return EED_Events_Archive_Caff|EED_Module
18
+	 */
19
+	public static function instance()
20
+	{
21
+		return parent::get_instance(__CLASS__);
22
+	}
23 23
 
24 24
 
25
-    /**
26
-     * set_hooks - for hooking into EE Core, other modules, etc
27
-     *
28
-     * @return    void
29
-     */
30
-    public static function set_hooks()
31
-    {
32
-    }
25
+	/**
26
+	 * set_hooks - for hooking into EE Core, other modules, etc
27
+	 *
28
+	 * @return    void
29
+	 */
30
+	public static function set_hooks()
31
+	{
32
+	}
33 33
 
34
-    /**
35
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
36
-     *
37
-     * @access    public
38
-     * @return    void
39
-     */
40
-    public static function set_hooks_admin()
41
-    {
42
-        self::setDefinitions();
43
-        add_action(
44
-            'AHEE__template_settings__template__before_settings_form',
45
-            array('EED_Events_Archive_Caff', 'template_settings_form'),
46
-            10
47
-        );
48
-        add_filter(
49
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
50
-            array('EED_Events_Archive_Caff', 'update_template_settings'),
51
-            10,
52
-            2
53
-        );
54
-        // AJAX
55
-        add_action(
56
-            'wp_ajax_espresso_update_event_archive_order',
57
-            array('EED_Events_Archive_Caff', 'update_event_archive_order')
58
-        );
59
-        add_action(
60
-            'wp_ajax_nopriv_espresso_update_event_archive_order',
61
-            array('EED_Events_Archive_Caff', 'update_event_archive_order')
62
-        );
63
-    }
34
+	/**
35
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
36
+	 *
37
+	 * @access    public
38
+	 * @return    void
39
+	 */
40
+	public static function set_hooks_admin()
41
+	{
42
+		self::setDefinitions();
43
+		add_action(
44
+			'AHEE__template_settings__template__before_settings_form',
45
+			array('EED_Events_Archive_Caff', 'template_settings_form'),
46
+			10
47
+		);
48
+		add_filter(
49
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
50
+			array('EED_Events_Archive_Caff', 'update_template_settings'),
51
+			10,
52
+			2
53
+		);
54
+		// AJAX
55
+		add_action(
56
+			'wp_ajax_espresso_update_event_archive_order',
57
+			array('EED_Events_Archive_Caff', 'update_event_archive_order')
58
+		);
59
+		add_action(
60
+			'wp_ajax_nopriv_espresso_update_event_archive_order',
61
+			array('EED_Events_Archive_Caff', 'update_event_archive_order')
62
+		);
63
+	}
64 64
 
65 65
 
66
-    /**
67
-     * run - initial module setup
68
-     *
69
-     * @param    WP $WP
70
-     * @return    void
71
-     */
72
-    public function run($WP)
73
-    {
74
-    }
66
+	/**
67
+	 * run - initial module setup
68
+	 *
69
+	 * @param    WP $WP
70
+	 * @return    void
71
+	 */
72
+	public function run($WP)
73
+	{
74
+	}
75 75
 
76 76
 
77
-    /**
78
-     * Conditionally set constants if they haven't been defined yet.
79
-     */
80
-    public static function setDefinitions()
81
-    {
82
-        if (! defined('EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH')) {
83
-            define(
84
-                'EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH',
85
-                str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates/'
86
-            );
87
-            define('EVENT_ARCHIVE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
88
-        }
89
-    }
77
+	/**
78
+	 * Conditionally set constants if they haven't been defined yet.
79
+	 */
80
+	public static function setDefinitions()
81
+	{
82
+		if (! defined('EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH')) {
83
+			define(
84
+				'EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH',
85
+				str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates/'
86
+			);
87
+			define('EVENT_ARCHIVE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
88
+		}
89
+	}
90 90
 
91 91
 
92
-    /**
93
-     * @return void
94
-     * @throws DomainException
95
-     * @throws InvalidArgumentException
96
-     * @throws InvalidDataTypeException
97
-     * @throws InvalidInterfaceException
98
-     */
99
-    public static function template_settings_form()
100
-    {
101
-        /** @var EE_Admin_Page_Loader $admin_page_loader */
102
-        $admin_page_loader = LoaderFactory::getLoader()->getShared('EE_Admin_Page_Loader');
103
-        // grab general settings admin page and remove the existing hook callback
104
-        $gen_set_admin = $admin_page_loader->get_admin_page_object('general_settings');
105
-        if ($gen_set_admin instanceof General_Settings_Admin_Page) {
106
-            remove_action(
107
-                'AHEE__template_settings__template__before_settings_form',
108
-                array($gen_set_admin, 'template_settings_caff_features'),
109
-                100
110
-            );
111
-        }
112
-        // first just grab the template settings
113
-        $config = EE_Registry::instance()->CFG->template_settings;
114
-        // then if the Event Archive config is valid, use that, else create a new one
115
-        $config = $config instanceof EE_Template_Config
116
-                  && $config->EED_Events_Archive instanceof EE_Events_Archive_Config
117
-            ? $config->EED_Events_Archive
118
-            : new EE_Events_Archive_Config();
119
-        $config = apply_filters(
120
-            'FHEE__EED_Events_Archive__template_settings_form__event_list_config',
121
-            $config
122
-        );
123
-        $config->display_status_banner = isset($config->display_status_banner)
124
-            ? $config->display_status_banner
125
-            : 0;
126
-        $config->display_description = isset($config->display_description)
127
-            ? $config->display_description
128
-            : 1;
129
-        $config->display_ticket_selector = isset($config->display_ticket_selector)
130
-            ? $config->display_ticket_selector
131
-            : 0;
132
-        $config->display_datetimes = isset($config->display_datetimes)
133
-            ? $config->display_datetimes
134
-            : 1;
135
-        $config->display_venue = isset($config->display_venue)
136
-            ? $config->display_venue
137
-            : 0;
138
-        $config->display_expired_events = isset($config->display_expired_events)
139
-            ? $config->display_expired_events
140
-            : 0;
141
-        // display order options
142
-        $config->use_sortable_display_order = isset($config->use_sortable_display_order)
143
-            ? $config->use_sortable_display_order
144
-            : false;
145
-        $config->display_order_tickets = isset($config->display_order_tickets)
146
-            ? $config->display_order_tickets
147
-            : 120;
148
-        $config->display_order_datetimes = isset($config->display_order_datetimes)
149
-            ? $config->display_order_datetimes
150
-            : 110;
151
-        $config->display_order_event = isset($config->display_order_event)
152
-            ? $config->display_order_event
153
-            : 100;
154
-        $config->display_order_venue = isset($config->display_order_venue)
155
-            ? $config->display_order_venue
156
-            : 130;
157
-        // get template parts
158
-        $template_parts = EED_Events_Archive::instance()->initialize_template_parts($config);
159
-        // convert to array so that we can add more properties
160
-        $config = get_object_vars($config);
161
-        $config['event_archive_display_order'] = $template_parts->generate_sortable_list_of_template_parts(
162
-            'event-archive-sortable-js',
163
-            '',
164
-            'archive-sortable-li archive-sortable-js'
165
-        );
166
-        EEH_Template::display_template(
167
-            EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
168
-            $config
169
-        );
170
-    }
92
+	/**
93
+	 * @return void
94
+	 * @throws DomainException
95
+	 * @throws InvalidArgumentException
96
+	 * @throws InvalidDataTypeException
97
+	 * @throws InvalidInterfaceException
98
+	 */
99
+	public static function template_settings_form()
100
+	{
101
+		/** @var EE_Admin_Page_Loader $admin_page_loader */
102
+		$admin_page_loader = LoaderFactory::getLoader()->getShared('EE_Admin_Page_Loader');
103
+		// grab general settings admin page and remove the existing hook callback
104
+		$gen_set_admin = $admin_page_loader->get_admin_page_object('general_settings');
105
+		if ($gen_set_admin instanceof General_Settings_Admin_Page) {
106
+			remove_action(
107
+				'AHEE__template_settings__template__before_settings_form',
108
+				array($gen_set_admin, 'template_settings_caff_features'),
109
+				100
110
+			);
111
+		}
112
+		// first just grab the template settings
113
+		$config = EE_Registry::instance()->CFG->template_settings;
114
+		// then if the Event Archive config is valid, use that, else create a new one
115
+		$config = $config instanceof EE_Template_Config
116
+				  && $config->EED_Events_Archive instanceof EE_Events_Archive_Config
117
+			? $config->EED_Events_Archive
118
+			: new EE_Events_Archive_Config();
119
+		$config = apply_filters(
120
+			'FHEE__EED_Events_Archive__template_settings_form__event_list_config',
121
+			$config
122
+		);
123
+		$config->display_status_banner = isset($config->display_status_banner)
124
+			? $config->display_status_banner
125
+			: 0;
126
+		$config->display_description = isset($config->display_description)
127
+			? $config->display_description
128
+			: 1;
129
+		$config->display_ticket_selector = isset($config->display_ticket_selector)
130
+			? $config->display_ticket_selector
131
+			: 0;
132
+		$config->display_datetimes = isset($config->display_datetimes)
133
+			? $config->display_datetimes
134
+			: 1;
135
+		$config->display_venue = isset($config->display_venue)
136
+			? $config->display_venue
137
+			: 0;
138
+		$config->display_expired_events = isset($config->display_expired_events)
139
+			? $config->display_expired_events
140
+			: 0;
141
+		// display order options
142
+		$config->use_sortable_display_order = isset($config->use_sortable_display_order)
143
+			? $config->use_sortable_display_order
144
+			: false;
145
+		$config->display_order_tickets = isset($config->display_order_tickets)
146
+			? $config->display_order_tickets
147
+			: 120;
148
+		$config->display_order_datetimes = isset($config->display_order_datetimes)
149
+			? $config->display_order_datetimes
150
+			: 110;
151
+		$config->display_order_event = isset($config->display_order_event)
152
+			? $config->display_order_event
153
+			: 100;
154
+		$config->display_order_venue = isset($config->display_order_venue)
155
+			? $config->display_order_venue
156
+			: 130;
157
+		// get template parts
158
+		$template_parts = EED_Events_Archive::instance()->initialize_template_parts($config);
159
+		// convert to array so that we can add more properties
160
+		$config = get_object_vars($config);
161
+		$config['event_archive_display_order'] = $template_parts->generate_sortable_list_of_template_parts(
162
+			'event-archive-sortable-js',
163
+			'',
164
+			'archive-sortable-li archive-sortable-js'
165
+		);
166
+		EEH_Template::display_template(
167
+			EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
168
+			$config
169
+		);
170
+	}
171 171
 
172 172
 
173
-    /**
174
-     * @param EE_Template_Config $CFG
175
-     * @param array              $REQ
176
-     * @return EE_Template_Config
177
-     */
178
-    public static function update_template_settings($CFG, $REQ)
179
-    {
180
-        // unless we are resetting the config...
181
-        if (
182
-            ! isset($REQ['EED_Events_Archive_reset_event_list_settings'])
183
-            || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1
184
-        ) {
185
-            /** @var EE_Events_Archive_Config $config */
186
-            $config = $CFG->EED_Events_Archive instanceof EE_Events_Archive_Config
187
-                ? $CFG->EED_Events_Archive
188
-                : new EE_Events_Archive_Config();
173
+	/**
174
+	 * @param EE_Template_Config $CFG
175
+	 * @param array              $REQ
176
+	 * @return EE_Template_Config
177
+	 */
178
+	public static function update_template_settings($CFG, $REQ)
179
+	{
180
+		// unless we are resetting the config...
181
+		if (
182
+			! isset($REQ['EED_Events_Archive_reset_event_list_settings'])
183
+			|| absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1
184
+		) {
185
+			/** @var EE_Events_Archive_Config $config */
186
+			$config = $CFG->EED_Events_Archive instanceof EE_Events_Archive_Config
187
+				? $CFG->EED_Events_Archive
188
+				: new EE_Events_Archive_Config();
189 189
 
190
-            $config->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner'])
191
-                ? absint($REQ['EED_Events_Archive_display_status_banner'])
192
-                : 0;
193
-            $config->display_description = isset($REQ['EED_Events_Archive_display_description'])
194
-                ? absint($REQ['EED_Events_Archive_display_description'])
195
-                : 1;
196
-            $config->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector'])
197
-                ? absint($REQ['EED_Events_Archive_display_ticket_selector'])
198
-                : 0;
199
-            $config->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes'])
200
-                ? absint($REQ['EED_Events_Archive_display_datetimes'])
201
-                : 1;
202
-            $config->display_venue = isset($REQ['EED_Events_Archive_display_venue'])
203
-                ? absint($REQ['EED_Events_Archive_display_venue'])
204
-                : 0;
205
-            $config->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events'])
206
-                ? absint($REQ['EED_Events_Archive_display_expired_events'])
207
-                : 0;
208
-            $config->use_sortable_display_order = isset($REQ['EED_Events_Archive_use_sortable_display_order'])
209
-                ? absint($REQ['EED_Events_Archive_use_sortable_display_order'])
210
-                : 0;
211
-            $config->display_order_event = $config->display_order_event !== null
212
-                                           && $config->use_sortable_display_order
213
-                ? $config->display_order_event
214
-                : EED_Events_Archive::EVENT_DETAILS_PRIORITY;
215
-            $config->display_order_datetimes = $config->display_order_datetimes !== null
216
-                                               && $config->use_sortable_display_order
217
-                ? $config->display_order_datetimes
218
-                : EED_Events_Archive::EVENT_DATETIMES_PRIORITY;
219
-            $config->display_order_tickets = $config->display_order_tickets !== null
220
-                                             && $config->use_sortable_display_order
221
-                ? $config->display_order_tickets
222
-                : EED_Events_Archive::EVENT_TICKETS_PRIORITY;
223
-            $config->display_order_venue = $config->display_order_venue !== null
224
-                                           && $config->use_sortable_display_order
225
-                ? $config->display_order_venue
226
-                : EED_Events_Archive::EVENT_VENUES_PRIORITY;
227
-        } else {
228
-            $config = new EE_Events_Archive_Config();
229
-        }
190
+			$config->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner'])
191
+				? absint($REQ['EED_Events_Archive_display_status_banner'])
192
+				: 0;
193
+			$config->display_description = isset($REQ['EED_Events_Archive_display_description'])
194
+				? absint($REQ['EED_Events_Archive_display_description'])
195
+				: 1;
196
+			$config->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector'])
197
+				? absint($REQ['EED_Events_Archive_display_ticket_selector'])
198
+				: 0;
199
+			$config->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes'])
200
+				? absint($REQ['EED_Events_Archive_display_datetimes'])
201
+				: 1;
202
+			$config->display_venue = isset($REQ['EED_Events_Archive_display_venue'])
203
+				? absint($REQ['EED_Events_Archive_display_venue'])
204
+				: 0;
205
+			$config->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events'])
206
+				? absint($REQ['EED_Events_Archive_display_expired_events'])
207
+				: 0;
208
+			$config->use_sortable_display_order = isset($REQ['EED_Events_Archive_use_sortable_display_order'])
209
+				? absint($REQ['EED_Events_Archive_use_sortable_display_order'])
210
+				: 0;
211
+			$config->display_order_event = $config->display_order_event !== null
212
+										   && $config->use_sortable_display_order
213
+				? $config->display_order_event
214
+				: EED_Events_Archive::EVENT_DETAILS_PRIORITY;
215
+			$config->display_order_datetimes = $config->display_order_datetimes !== null
216
+											   && $config->use_sortable_display_order
217
+				? $config->display_order_datetimes
218
+				: EED_Events_Archive::EVENT_DATETIMES_PRIORITY;
219
+			$config->display_order_tickets = $config->display_order_tickets !== null
220
+											 && $config->use_sortable_display_order
221
+				? $config->display_order_tickets
222
+				: EED_Events_Archive::EVENT_TICKETS_PRIORITY;
223
+			$config->display_order_venue = $config->display_order_venue !== null
224
+										   && $config->use_sortable_display_order
225
+				? $config->display_order_venue
226
+				: EED_Events_Archive::EVENT_VENUES_PRIORITY;
227
+		} else {
228
+			$config = new EE_Events_Archive_Config();
229
+		}
230 230
 
231
-        $CFG->EED_Events_Archive = $config;
232
-        do_action('AHEE__EED_Events_Archive__update_template_settings__after_update', $CFG, $REQ);
233
-        return $CFG;
234
-    }
231
+		$CFG->EED_Events_Archive = $config;
232
+		do_action('AHEE__EED_Events_Archive__update_template_settings__after_update', $CFG, $REQ);
233
+		return $CFG;
234
+	}
235 235
 
236 236
 
237
-    /**
238
-     * @return void
239
-     * @throws InvalidArgumentException
240
-     * @throws InvalidDataTypeException
241
-     * @throws InvalidInterfaceException
242
-     */
243
-    public static function update_event_archive_order()
244
-    {
245
-        /** @var EE_Config $config */
246
-        $config = EE_Registry::instance()->CFG;
247
-        $config_saved = false;
248
-        $template_parts = EED_Events_Archive_Caff::getRequest()->getRequestParam('elements');
249
-        if (! empty($template_parts)) {
250
-            $template_parts = explode(',', trim($template_parts, ','));
251
-            foreach ($template_parts as $key => $template_part) {
252
-                $template_part = "display_order_$template_part";
253
-                $priority = ($key * 10) + EED_Events_Archive::EVENT_DETAILS_PRIORITY;
254
-                if (
255
-                    $config->template_settings->EED_Events_Archive instanceof EE_Events_Archive_Config
256
-                    && property_exists(
257
-                        $config->template_settings->EED_Events_Archive,
258
-                        $template_part
259
-                    )
260
-                ) {
261
-                    $config->template_settings->EED_Events_Archive->{$template_part} = $priority;
262
-                }
263
-                do_action("AHEE__EED_Events_Archive__update_event_archive_order__$template_part", $priority);
264
-            }
265
-            $config_saved = $config->update_espresso_config(false, false);
266
-        }
267
-        if ($config_saved) {
268
-            EE_Error::add_success(esc_html__('Display Order has been successfully updated.', 'event_espresso'));
269
-        } else {
270
-            EE_Error::add_error(
271
-                esc_html__('Display Order was not updated.', 'event_espresso'),
272
-                __FILE__,
273
-                __FUNCTION__,
274
-                __LINE__
275
-            );
276
-        }
277
-        echo wp_json_encode(EE_Error::get_notices(false));
278
-        exit();
279
-    }
237
+	/**
238
+	 * @return void
239
+	 * @throws InvalidArgumentException
240
+	 * @throws InvalidDataTypeException
241
+	 * @throws InvalidInterfaceException
242
+	 */
243
+	public static function update_event_archive_order()
244
+	{
245
+		/** @var EE_Config $config */
246
+		$config = EE_Registry::instance()->CFG;
247
+		$config_saved = false;
248
+		$template_parts = EED_Events_Archive_Caff::getRequest()->getRequestParam('elements');
249
+		if (! empty($template_parts)) {
250
+			$template_parts = explode(',', trim($template_parts, ','));
251
+			foreach ($template_parts as $key => $template_part) {
252
+				$template_part = "display_order_$template_part";
253
+				$priority = ($key * 10) + EED_Events_Archive::EVENT_DETAILS_PRIORITY;
254
+				if (
255
+					$config->template_settings->EED_Events_Archive instanceof EE_Events_Archive_Config
256
+					&& property_exists(
257
+						$config->template_settings->EED_Events_Archive,
258
+						$template_part
259
+					)
260
+				) {
261
+					$config->template_settings->EED_Events_Archive->{$template_part} = $priority;
262
+				}
263
+				do_action("AHEE__EED_Events_Archive__update_event_archive_order__$template_part", $priority);
264
+			}
265
+			$config_saved = $config->update_espresso_config(false, false);
266
+		}
267
+		if ($config_saved) {
268
+			EE_Error::add_success(esc_html__('Display Order has been successfully updated.', 'event_espresso'));
269
+		} else {
270
+			EE_Error::add_error(
271
+				esc_html__('Display Order was not updated.', 'event_espresso'),
272
+				__FILE__,
273
+				__FUNCTION__,
274
+				__LINE__
275
+			);
276
+		}
277
+		echo wp_json_encode(EE_Error::get_notices(false));
278
+		exit();
279
+	}
280 280
 }
Please login to merge, or discard this patch.
caffeinated/modules/recaptcha/EED_Recaptcha.module.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
         }
134 134
         define(
135 135
             'RECAPTCHA_BASE_PATH',
136
-            rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
136
+            rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/').'/'
137 137
         );
138 138
         define('RECAPTCHA_BASE_URL', plugin_dir_url(__FILE__));
139 139
     }
@@ -187,14 +187,14 @@  discard block
 block discarded – undo
187 187
     {
188 188
         wp_register_script(
189 189
             'espresso_recaptcha',
190
-            RECAPTCHA_BASE_URL . 'scripts/espresso_recaptcha.js',
190
+            RECAPTCHA_BASE_URL.'scripts/espresso_recaptcha.js',
191 191
             array('single_page_checkout'),
192 192
             EVENT_ESPRESSO_VERSION,
193 193
             true
194 194
         );
195 195
         wp_register_script(
196 196
             'google_recaptcha',
197
-            'https://www.google.com/recaptcha/api.js?hl=' . EED_Recaptcha::$config->recaptcha_language,
197
+            'https://www.google.com/recaptcha/api.js?hl='.EED_Recaptcha::$config->recaptcha_language,
198 198
             array('espresso_recaptcha'),
199 199
             EVENT_ESPRESSO_VERSION,
200 200
             true
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
         if (EED_Recaptcha::useRecaptcha() && ! EED_Recaptcha::$_not_a_robot) {
254 254
             // only display if they have NOT passed the test yet
255 255
             EEH_Template::display_template(
256
-                RECAPTCHA_BASE_PATH . '/templates/recaptcha.template.php',
256
+                RECAPTCHA_BASE_PATH.'/templates/recaptcha.template.php',
257 257
                 array(
258 258
                     'recaptcha_publickey' => EED_Recaptcha::$config->recaptcha_publickey,
259 259
                     'recaptcha_theme'     => EED_Recaptcha::$config->recaptcha_theme,
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
         $recaptcha_passed = filter_var($recaptcha_passed, FILTER_VALIDATE_BOOLEAN);
299 299
         // verify recaptcha
300 300
         EED_Recaptcha::_get_recaptcha_response();
301
-        if (! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) {
301
+        if ( ! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) {
302 302
             $recaptcha_passed = EED_Recaptcha::_process_recaptcha_response();
303 303
             EE_Registry::instance()->SSN->set_session_data(array('recaptcha_passed' => $recaptcha_passed));
304 304
         }
@@ -375,8 +375,8 @@  discard block
 block discarded – undo
375 375
     private static function _process_recaptcha_response()
376 376
     {
377 377
         // verify library is loaded
378
-        if (! class_exists('\ReCaptcha\ReCaptcha')) {
379
-            require_once RECAPTCHA_BASE_PATH . '/autoload.php';
378
+        if ( ! class_exists('\ReCaptcha\ReCaptcha')) {
379
+            require_once RECAPTCHA_BASE_PATH.'/autoload.php';
380 380
         }
381 381
         // The response from reCAPTCHA
382 382
         EED_Recaptcha::_get_recaptcha_response();
Please login to merge, or discard this patch.
Indentation   +378 added lines, -378 removed lines patch added patch discarded remove patch
@@ -17,382 +17,382 @@
 block discarded – undo
17 17
  */
18 18
 class EED_Recaptcha extends EED_Module
19 19
 {
20
-    /**
21
-     * @var EE_Registration_Config $config
22
-     */
23
-    private static $config;
24
-
25
-    /**
26
-     * @type bool $_not_a_robot
27
-     */
28
-    private static $_not_a_robot;
29
-
30
-    /**
31
-     * @type string $_recaptcha_response
32
-     */
33
-    private static $_recaptcha_response;
34
-
35
-
36
-    /**
37
-     * @return EED_Module|EED_Recaptcha
38
-     */
39
-    public static function instance()
40
-    {
41
-        return parent::get_instance(__CLASS__);
42
-    }
43
-
44
-
45
-    /**
46
-     * set_hooks - for hooking into EE Core, other modules, etc
47
-     *
48
-     * @return void
49
-     * @throws InvalidArgumentException
50
-     * @throws InvalidInterfaceException
51
-     * @throws InvalidDataTypeException
52
-     */
53
-    public static function set_hooks()
54
-    {
55
-        EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration;
56
-        // use_captcha ?
57
-        if (
58
-            EED_Recaptcha::useRecaptcha()
59
-            && EED_Recaptcha::notPaymentOptionsRevisit()
60
-        ) {
61
-            EED_Recaptcha::set_definitions();
62
-            EED_Recaptcha::enqueue_styles_and_scripts();
63
-            add_action('wp', array('EED_Recaptcha', 'set_late_hooks'), 1, 0);
64
-            add_action(
65
-                'AHEE__before_spco_whats_next_buttons',
66
-                array('EED_Recaptcha', 'display_recaptcha'),
67
-                10,
68
-                0
69
-            );
70
-            add_filter(
71
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
72
-                array('EED_Recaptcha', 'not_a_robot')
73
-            );
74
-            add_filter(
75
-                'FHEE__EE_SPCO_Reg_Step__set_completed___completed',
76
-                array('EED_Recaptcha', 'not_a_robot')
77
-            );
78
-            add_filter(
79
-                'FHEE__EE_SPCO_JSON_Response___toString__JSON_response',
80
-                array('EED_Recaptcha', 'recaptcha_response')
81
-            );
82
-            add_filter(
83
-                'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
84
-                array('EED_Recaptcha', 'bypass_recaptcha_for_spco_load_payment_method')
85
-            );
86
-        }
87
-    }
88
-
89
-
90
-    /**
91
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
92
-     *
93
-     * @return void
94
-     * @throws InvalidArgumentException
95
-     * @throws InvalidInterfaceException
96
-     * @throws InvalidDataTypeException
97
-     */
98
-    public static function set_hooks_admin()
99
-    {
100
-        EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration;
101
-        EED_Recaptcha::set_definitions();
102
-        // use_captcha ?
103
-        if (
104
-            EED_Recaptcha::useRecaptcha()
105
-            && EED_Recaptcha::notPaymentOptionsRevisit()
106
-            && EED_Recaptcha::getRequest()->getRequestParam('step', '') !== ''
107
-        ) {
108
-            EED_Recaptcha::enqueue_styles_and_scripts();
109
-            add_filter(
110
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
111
-                array('EED_Recaptcha', 'not_a_robot')
112
-            );
113
-            add_filter(
114
-                'FHEE__EE_SPCO_Reg_Step__set_completed___completed',
115
-                array('EED_Recaptcha', 'not_a_robot')
116
-            );
117
-            add_filter(
118
-                'FHEE__EE_SPCO_JSON_Response___toString__JSON_response',
119
-                array('EED_Recaptcha', 'recaptcha_response')
120
-            );
121
-        }
122
-    }
123
-
124
-
125
-    /**
126
-     * @return void
127
-     */
128
-    public static function set_definitions()
129
-    {
130
-        if (is_user_logged_in()) {
131
-            EED_Recaptcha::$_not_a_robot = true;
132
-        }
133
-        define(
134
-            'RECAPTCHA_BASE_PATH',
135
-            rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
136
-        );
137
-        define('RECAPTCHA_BASE_URL', plugin_dir_url(__FILE__));
138
-    }
139
-
140
-
141
-    /**
142
-     * @return void
143
-     */
144
-    public static function set_late_hooks()
145
-    {
146
-        add_filter(
147
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
148
-            array('EED_Recaptcha', 'not_a_robot')
149
-        );
150
-    }
151
-
152
-
153
-    /**
154
-     * @return boolean
155
-     */
156
-    public static function useRecaptcha()
157
-    {
158
-        return EED_Recaptcha::$config->use_captcha
159
-               && EED_Recaptcha::$config->recaptcha_theme !== 'invisible';
160
-    }
161
-
162
-
163
-    /**
164
-     * @return boolean
165
-     * @throws InvalidArgumentException
166
-     * @throws InvalidInterfaceException
167
-     * @throws InvalidDataTypeException
168
-     */
169
-    public static function notPaymentOptionsRevisit()
170
-    {
171
-        $request = EED_Recaptcha::getRequest();
172
-        return ! (
173
-            $request->getRequestParam('step', '') === 'payment_options'
174
-            && $request->getRequestParam('revisit', false, 'bool') === true
175
-        );
176
-    }
177
-
178
-
179
-    /**
180
-     * @return void
181
-     * @throws InvalidArgumentException
182
-     * @throws InvalidInterfaceException
183
-     * @throws InvalidDataTypeException
184
-     */
185
-    public static function enqueue_styles_and_scripts()
186
-    {
187
-        wp_register_script(
188
-            'espresso_recaptcha',
189
-            RECAPTCHA_BASE_URL . 'scripts/espresso_recaptcha.js',
190
-            array('single_page_checkout'),
191
-            EVENT_ESPRESSO_VERSION,
192
-            true
193
-        );
194
-        wp_register_script(
195
-            'google_recaptcha',
196
-            'https://www.google.com/recaptcha/api.js?hl=' . EED_Recaptcha::$config->recaptcha_language,
197
-            array('espresso_recaptcha'),
198
-            EVENT_ESPRESSO_VERSION,
199
-            true
200
-        );
201
-        EE_Registry::$i18n_js_strings['no_SPCO_error'] = __(
202
-            'It appears the Single Page Checkout javascript was not loaded properly! Please refresh the page and try again or contact support.',
203
-            'event_espresso'
204
-        );
205
-        EE_Registry::$i18n_js_strings['no_recaptcha_error'] = __(
206
-            'There appears to be a problem with the reCAPTCHA configuration! Please check the admin settings or contact support.',
207
-            'event_espresso'
208
-        );
209
-        EE_Registry::$i18n_js_strings['recaptcha_fail'] = __(
210
-            'Please complete the anti-spam test before proceeding.',
211
-            'event_espresso'
212
-        );
213
-    }
214
-
215
-
216
-    /**
217
-     * @param WP $WP
218
-     */
219
-    public function run($WP)
220
-    {
221
-    }
222
-
223
-
224
-    /**
225
-     * @return boolean
226
-     * @throws InvalidArgumentException
227
-     * @throws InvalidInterfaceException
228
-     * @throws InvalidDataTypeException
229
-     */
230
-    public static function not_a_robot()
231
-    {
232
-        return is_bool(EED_Recaptcha::$_not_a_robot)
233
-            ? EED_Recaptcha::$_not_a_robot
234
-            : EED_Recaptcha::recaptcha_passed();
235
-    }
236
-
237
-
238
-    /**
239
-     * @return void
240
-     * @throws DomainException
241
-     * @throws InvalidArgumentException
242
-     * @throws InvalidInterfaceException
243
-     * @throws InvalidDataTypeException
244
-     */
245
-    public static function display_recaptcha()
246
-    {
247
-        // logged in means you have already passed a turing test of sorts
248
-        if (is_user_logged_in()) {
249
-            return;
250
-        }
251
-        // don't display if not using recaptcha or user is logged in
252
-        if (EED_Recaptcha::useRecaptcha() && ! EED_Recaptcha::$_not_a_robot) {
253
-            // only display if they have NOT passed the test yet
254
-            EEH_Template::display_template(
255
-                RECAPTCHA_BASE_PATH . '/templates/recaptcha.template.php',
256
-                array(
257
-                    'recaptcha_publickey' => EED_Recaptcha::$config->recaptcha_publickey,
258
-                    'recaptcha_theme'     => EED_Recaptcha::$config->recaptcha_theme,
259
-                    'recaptcha_type'      => EED_Recaptcha::$config->recaptcha_type,
260
-                )
261
-            );
262
-            wp_enqueue_script('google_recaptcha');
263
-        }
264
-    }
265
-
266
-
267
-    /**
268
-     * @return array
269
-     * @throws InvalidArgumentException
270
-     * @throws InvalidInterfaceException
271
-     * @throws InvalidDataTypeException
272
-     */
273
-    public static function bypass_recaptcha_for_spco_load_payment_method()
274
-    {
275
-        return array(
276
-            'EESID'  => EE_Registry::instance()->SSN->id(),
277
-            'step'   => 'payment_options',
278
-            'action' => 'switch_spco_billing_form',
279
-        );
280
-    }
281
-
282
-
283
-    /**
284
-     * @return boolean
285
-     * @throws InvalidArgumentException
286
-     * @throws InvalidInterfaceException
287
-     * @throws InvalidDataTypeException
288
-     */
289
-    public static function recaptcha_passed()
290
-    {
291
-        // logged in means you have already passed a turing test of sorts
292
-        if (is_user_logged_in() || EED_Recaptcha::_bypass_recaptcha()) {
293
-            return true;
294
-        }
295
-        // was test already passed?
296
-        $recaptcha_passed = EE_Registry::instance()->SSN->get_session_data('recaptcha_passed');
297
-        $recaptcha_passed = filter_var($recaptcha_passed, FILTER_VALIDATE_BOOLEAN);
298
-        // verify recaptcha
299
-        EED_Recaptcha::_get_recaptcha_response();
300
-        if (! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) {
301
-            $recaptcha_passed = EED_Recaptcha::_process_recaptcha_response();
302
-            EE_Registry::instance()->SSN->set_session_data(array('recaptcha_passed' => $recaptcha_passed));
303
-        }
304
-        EED_Recaptcha::$_not_a_robot = $recaptcha_passed;
305
-        return $recaptcha_passed;
306
-    }
307
-
308
-
309
-    /**
310
-     * @param array $recaptcha_response
311
-     * @return array
312
-     */
313
-    public static function recaptcha_response($recaptcha_response = array())
314
-    {
315
-        if (EED_Recaptcha::_bypass_recaptcha()) {
316
-            $recaptcha_response['bypass_recaptcha'] = true;
317
-            $recaptcha_response['recaptcha_passed'] = true;
318
-        } else {
319
-            $recaptcha_response['recaptcha_passed'] = EED_Recaptcha::$_not_a_robot;
320
-        }
321
-        return $recaptcha_response;
322
-    }
323
-
324
-
325
-    /**
326
-     * @return boolean
327
-     */
328
-    private static function _bypass_recaptcha()
329
-    {
330
-        // an array of key value pairs that must match exactly with the incoming request,
331
-        // in order to bypass recaptcha for the current request ONLY
332
-        $bypass_request_params_array = (array) apply_filters(
333
-            'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
334
-            array()
335
-        );
336
-        // does $bypass_request_params_array have any values ?
337
-        if (empty($bypass_request_params_array)) {
338
-            return false;
339
-        }
340
-        $request = EED_Recaptcha::getRequest();
341
-        // initially set bypass to TRUE
342
-        $bypass_recaptcha = true;
343
-        foreach ($bypass_request_params_array as $key => $value) {
344
-            // if $key is not found or value doesn't match exactly, then toggle bypass to FALSE,
345
-            // otherwise carry over it's value. This way, one missed setting results in no bypass
346
-            $bypass_recaptcha = $request->getRequestParam($key) === $value
347
-                ? $bypass_recaptcha
348
-                : false;
349
-        }
350
-        return $bypass_recaptcha;
351
-    }
352
-
353
-
354
-    /**
355
-     * @return void
356
-     * @throws InvalidArgumentException
357
-     * @throws InvalidInterfaceException
358
-     * @throws InvalidDataTypeException
359
-     */
360
-    private static function _get_recaptcha_response()
361
-    {
362
-        EED_Recaptcha::$_recaptcha_response = EED_Recaptcha::getRequest()->getRequestParam(
363
-            'g-recaptcha-response'
364
-        );
365
-    }
366
-
367
-
368
-    /**
369
-     * @return boolean
370
-     * @throws InvalidArgumentException
371
-     * @throws InvalidInterfaceException
372
-     * @throws InvalidDataTypeException
373
-     */
374
-    private static function _process_recaptcha_response()
375
-    {
376
-        // verify library is loaded
377
-        if (! class_exists('\ReCaptcha\ReCaptcha')) {
378
-            require_once RECAPTCHA_BASE_PATH . '/autoload.php';
379
-        }
380
-        // The response from reCAPTCHA
381
-        EED_Recaptcha::_get_recaptcha_response();
382
-        $recaptcha_response = EED_Recaptcha::$_recaptcha_response;
383
-        // Was there a reCAPTCHA response?
384
-        if ($recaptcha_response) {
385
-            // if allow_url_fopen is Off, then set a different request method
386
-            $request_method = ! ini_get('allow_url_fopen') ? new SocketPost() : null;
387
-            $recaptcha = new ReCaptcha(
388
-                EED_Recaptcha::$config->recaptcha_privatekey,
389
-                $request_method
390
-            );
391
-            $recaptcha_response = $recaptcha->verify(
392
-                EED_Recaptcha::$_recaptcha_response,
393
-                EED_Recaptcha::getRequest()->getServerParam('REMOTE_ADDR')
394
-            );
395
-        }
396
-        return $recaptcha_response instanceof Response && $recaptcha_response->isSuccess();
397
-    }
20
+	/**
21
+	 * @var EE_Registration_Config $config
22
+	 */
23
+	private static $config;
24
+
25
+	/**
26
+	 * @type bool $_not_a_robot
27
+	 */
28
+	private static $_not_a_robot;
29
+
30
+	/**
31
+	 * @type string $_recaptcha_response
32
+	 */
33
+	private static $_recaptcha_response;
34
+
35
+
36
+	/**
37
+	 * @return EED_Module|EED_Recaptcha
38
+	 */
39
+	public static function instance()
40
+	{
41
+		return parent::get_instance(__CLASS__);
42
+	}
43
+
44
+
45
+	/**
46
+	 * set_hooks - for hooking into EE Core, other modules, etc
47
+	 *
48
+	 * @return void
49
+	 * @throws InvalidArgumentException
50
+	 * @throws InvalidInterfaceException
51
+	 * @throws InvalidDataTypeException
52
+	 */
53
+	public static function set_hooks()
54
+	{
55
+		EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration;
56
+		// use_captcha ?
57
+		if (
58
+			EED_Recaptcha::useRecaptcha()
59
+			&& EED_Recaptcha::notPaymentOptionsRevisit()
60
+		) {
61
+			EED_Recaptcha::set_definitions();
62
+			EED_Recaptcha::enqueue_styles_and_scripts();
63
+			add_action('wp', array('EED_Recaptcha', 'set_late_hooks'), 1, 0);
64
+			add_action(
65
+				'AHEE__before_spco_whats_next_buttons',
66
+				array('EED_Recaptcha', 'display_recaptcha'),
67
+				10,
68
+				0
69
+			);
70
+			add_filter(
71
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
72
+				array('EED_Recaptcha', 'not_a_robot')
73
+			);
74
+			add_filter(
75
+				'FHEE__EE_SPCO_Reg_Step__set_completed___completed',
76
+				array('EED_Recaptcha', 'not_a_robot')
77
+			);
78
+			add_filter(
79
+				'FHEE__EE_SPCO_JSON_Response___toString__JSON_response',
80
+				array('EED_Recaptcha', 'recaptcha_response')
81
+			);
82
+			add_filter(
83
+				'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
84
+				array('EED_Recaptcha', 'bypass_recaptcha_for_spco_load_payment_method')
85
+			);
86
+		}
87
+	}
88
+
89
+
90
+	/**
91
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
92
+	 *
93
+	 * @return void
94
+	 * @throws InvalidArgumentException
95
+	 * @throws InvalidInterfaceException
96
+	 * @throws InvalidDataTypeException
97
+	 */
98
+	public static function set_hooks_admin()
99
+	{
100
+		EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration;
101
+		EED_Recaptcha::set_definitions();
102
+		// use_captcha ?
103
+		if (
104
+			EED_Recaptcha::useRecaptcha()
105
+			&& EED_Recaptcha::notPaymentOptionsRevisit()
106
+			&& EED_Recaptcha::getRequest()->getRequestParam('step', '') !== ''
107
+		) {
108
+			EED_Recaptcha::enqueue_styles_and_scripts();
109
+			add_filter(
110
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
111
+				array('EED_Recaptcha', 'not_a_robot')
112
+			);
113
+			add_filter(
114
+				'FHEE__EE_SPCO_Reg_Step__set_completed___completed',
115
+				array('EED_Recaptcha', 'not_a_robot')
116
+			);
117
+			add_filter(
118
+				'FHEE__EE_SPCO_JSON_Response___toString__JSON_response',
119
+				array('EED_Recaptcha', 'recaptcha_response')
120
+			);
121
+		}
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return void
127
+	 */
128
+	public static function set_definitions()
129
+	{
130
+		if (is_user_logged_in()) {
131
+			EED_Recaptcha::$_not_a_robot = true;
132
+		}
133
+		define(
134
+			'RECAPTCHA_BASE_PATH',
135
+			rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
136
+		);
137
+		define('RECAPTCHA_BASE_URL', plugin_dir_url(__FILE__));
138
+	}
139
+
140
+
141
+	/**
142
+	 * @return void
143
+	 */
144
+	public static function set_late_hooks()
145
+	{
146
+		add_filter(
147
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
148
+			array('EED_Recaptcha', 'not_a_robot')
149
+		);
150
+	}
151
+
152
+
153
+	/**
154
+	 * @return boolean
155
+	 */
156
+	public static function useRecaptcha()
157
+	{
158
+		return EED_Recaptcha::$config->use_captcha
159
+			   && EED_Recaptcha::$config->recaptcha_theme !== 'invisible';
160
+	}
161
+
162
+
163
+	/**
164
+	 * @return boolean
165
+	 * @throws InvalidArgumentException
166
+	 * @throws InvalidInterfaceException
167
+	 * @throws InvalidDataTypeException
168
+	 */
169
+	public static function notPaymentOptionsRevisit()
170
+	{
171
+		$request = EED_Recaptcha::getRequest();
172
+		return ! (
173
+			$request->getRequestParam('step', '') === 'payment_options'
174
+			&& $request->getRequestParam('revisit', false, 'bool') === true
175
+		);
176
+	}
177
+
178
+
179
+	/**
180
+	 * @return void
181
+	 * @throws InvalidArgumentException
182
+	 * @throws InvalidInterfaceException
183
+	 * @throws InvalidDataTypeException
184
+	 */
185
+	public static function enqueue_styles_and_scripts()
186
+	{
187
+		wp_register_script(
188
+			'espresso_recaptcha',
189
+			RECAPTCHA_BASE_URL . 'scripts/espresso_recaptcha.js',
190
+			array('single_page_checkout'),
191
+			EVENT_ESPRESSO_VERSION,
192
+			true
193
+		);
194
+		wp_register_script(
195
+			'google_recaptcha',
196
+			'https://www.google.com/recaptcha/api.js?hl=' . EED_Recaptcha::$config->recaptcha_language,
197
+			array('espresso_recaptcha'),
198
+			EVENT_ESPRESSO_VERSION,
199
+			true
200
+		);
201
+		EE_Registry::$i18n_js_strings['no_SPCO_error'] = __(
202
+			'It appears the Single Page Checkout javascript was not loaded properly! Please refresh the page and try again or contact support.',
203
+			'event_espresso'
204
+		);
205
+		EE_Registry::$i18n_js_strings['no_recaptcha_error'] = __(
206
+			'There appears to be a problem with the reCAPTCHA configuration! Please check the admin settings or contact support.',
207
+			'event_espresso'
208
+		);
209
+		EE_Registry::$i18n_js_strings['recaptcha_fail'] = __(
210
+			'Please complete the anti-spam test before proceeding.',
211
+			'event_espresso'
212
+		);
213
+	}
214
+
215
+
216
+	/**
217
+	 * @param WP $WP
218
+	 */
219
+	public function run($WP)
220
+	{
221
+	}
222
+
223
+
224
+	/**
225
+	 * @return boolean
226
+	 * @throws InvalidArgumentException
227
+	 * @throws InvalidInterfaceException
228
+	 * @throws InvalidDataTypeException
229
+	 */
230
+	public static function not_a_robot()
231
+	{
232
+		return is_bool(EED_Recaptcha::$_not_a_robot)
233
+			? EED_Recaptcha::$_not_a_robot
234
+			: EED_Recaptcha::recaptcha_passed();
235
+	}
236
+
237
+
238
+	/**
239
+	 * @return void
240
+	 * @throws DomainException
241
+	 * @throws InvalidArgumentException
242
+	 * @throws InvalidInterfaceException
243
+	 * @throws InvalidDataTypeException
244
+	 */
245
+	public static function display_recaptcha()
246
+	{
247
+		// logged in means you have already passed a turing test of sorts
248
+		if (is_user_logged_in()) {
249
+			return;
250
+		}
251
+		// don't display if not using recaptcha or user is logged in
252
+		if (EED_Recaptcha::useRecaptcha() && ! EED_Recaptcha::$_not_a_robot) {
253
+			// only display if they have NOT passed the test yet
254
+			EEH_Template::display_template(
255
+				RECAPTCHA_BASE_PATH . '/templates/recaptcha.template.php',
256
+				array(
257
+					'recaptcha_publickey' => EED_Recaptcha::$config->recaptcha_publickey,
258
+					'recaptcha_theme'     => EED_Recaptcha::$config->recaptcha_theme,
259
+					'recaptcha_type'      => EED_Recaptcha::$config->recaptcha_type,
260
+				)
261
+			);
262
+			wp_enqueue_script('google_recaptcha');
263
+		}
264
+	}
265
+
266
+
267
+	/**
268
+	 * @return array
269
+	 * @throws InvalidArgumentException
270
+	 * @throws InvalidInterfaceException
271
+	 * @throws InvalidDataTypeException
272
+	 */
273
+	public static function bypass_recaptcha_for_spco_load_payment_method()
274
+	{
275
+		return array(
276
+			'EESID'  => EE_Registry::instance()->SSN->id(),
277
+			'step'   => 'payment_options',
278
+			'action' => 'switch_spco_billing_form',
279
+		);
280
+	}
281
+
282
+
283
+	/**
284
+	 * @return boolean
285
+	 * @throws InvalidArgumentException
286
+	 * @throws InvalidInterfaceException
287
+	 * @throws InvalidDataTypeException
288
+	 */
289
+	public static function recaptcha_passed()
290
+	{
291
+		// logged in means you have already passed a turing test of sorts
292
+		if (is_user_logged_in() || EED_Recaptcha::_bypass_recaptcha()) {
293
+			return true;
294
+		}
295
+		// was test already passed?
296
+		$recaptcha_passed = EE_Registry::instance()->SSN->get_session_data('recaptcha_passed');
297
+		$recaptcha_passed = filter_var($recaptcha_passed, FILTER_VALIDATE_BOOLEAN);
298
+		// verify recaptcha
299
+		EED_Recaptcha::_get_recaptcha_response();
300
+		if (! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) {
301
+			$recaptcha_passed = EED_Recaptcha::_process_recaptcha_response();
302
+			EE_Registry::instance()->SSN->set_session_data(array('recaptcha_passed' => $recaptcha_passed));
303
+		}
304
+		EED_Recaptcha::$_not_a_robot = $recaptcha_passed;
305
+		return $recaptcha_passed;
306
+	}
307
+
308
+
309
+	/**
310
+	 * @param array $recaptcha_response
311
+	 * @return array
312
+	 */
313
+	public static function recaptcha_response($recaptcha_response = array())
314
+	{
315
+		if (EED_Recaptcha::_bypass_recaptcha()) {
316
+			$recaptcha_response['bypass_recaptcha'] = true;
317
+			$recaptcha_response['recaptcha_passed'] = true;
318
+		} else {
319
+			$recaptcha_response['recaptcha_passed'] = EED_Recaptcha::$_not_a_robot;
320
+		}
321
+		return $recaptcha_response;
322
+	}
323
+
324
+
325
+	/**
326
+	 * @return boolean
327
+	 */
328
+	private static function _bypass_recaptcha()
329
+	{
330
+		// an array of key value pairs that must match exactly with the incoming request,
331
+		// in order to bypass recaptcha for the current request ONLY
332
+		$bypass_request_params_array = (array) apply_filters(
333
+			'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
334
+			array()
335
+		);
336
+		// does $bypass_request_params_array have any values ?
337
+		if (empty($bypass_request_params_array)) {
338
+			return false;
339
+		}
340
+		$request = EED_Recaptcha::getRequest();
341
+		// initially set bypass to TRUE
342
+		$bypass_recaptcha = true;
343
+		foreach ($bypass_request_params_array as $key => $value) {
344
+			// if $key is not found or value doesn't match exactly, then toggle bypass to FALSE,
345
+			// otherwise carry over it's value. This way, one missed setting results in no bypass
346
+			$bypass_recaptcha = $request->getRequestParam($key) === $value
347
+				? $bypass_recaptcha
348
+				: false;
349
+		}
350
+		return $bypass_recaptcha;
351
+	}
352
+
353
+
354
+	/**
355
+	 * @return void
356
+	 * @throws InvalidArgumentException
357
+	 * @throws InvalidInterfaceException
358
+	 * @throws InvalidDataTypeException
359
+	 */
360
+	private static function _get_recaptcha_response()
361
+	{
362
+		EED_Recaptcha::$_recaptcha_response = EED_Recaptcha::getRequest()->getRequestParam(
363
+			'g-recaptcha-response'
364
+		);
365
+	}
366
+
367
+
368
+	/**
369
+	 * @return boolean
370
+	 * @throws InvalidArgumentException
371
+	 * @throws InvalidInterfaceException
372
+	 * @throws InvalidDataTypeException
373
+	 */
374
+	private static function _process_recaptcha_response()
375
+	{
376
+		// verify library is loaded
377
+		if (! class_exists('\ReCaptcha\ReCaptcha')) {
378
+			require_once RECAPTCHA_BASE_PATH . '/autoload.php';
379
+		}
380
+		// The response from reCAPTCHA
381
+		EED_Recaptcha::_get_recaptcha_response();
382
+		$recaptcha_response = EED_Recaptcha::$_recaptcha_response;
383
+		// Was there a reCAPTCHA response?
384
+		if ($recaptcha_response) {
385
+			// if allow_url_fopen is Off, then set a different request method
386
+			$request_method = ! ini_get('allow_url_fopen') ? new SocketPost() : null;
387
+			$recaptcha = new ReCaptcha(
388
+				EED_Recaptcha::$config->recaptcha_privatekey,
389
+				$request_method
390
+			);
391
+			$recaptcha_response = $recaptcha->verify(
392
+				EED_Recaptcha::$_recaptcha_response,
393
+				EED_Recaptcha::getRequest()->getServerParam('REMOTE_ADDR')
394
+			);
395
+		}
396
+		return $recaptcha_response instanceof Response && $recaptcha_response->isSuccess();
397
+	}
398 398
 }
Please login to merge, or discard this patch.