Completed
Branch decaf-fixes/more-request-fixes (02d799)
by
unknown
07:01 queued 05:08
created
admin/extend/registrations/EE_Event_Registrations_List_Table.class.php 1 patch
Indentation   +561 added lines, -561 removed lines patch added patch discarded remove patch
@@ -12,570 +12,570 @@
 block discarded – undo
12 12
 class EE_Event_Registrations_List_Table extends EE_Admin_List_Table
13 13
 {
14 14
 
15
-    /**
16
-     * This property will hold the related Datetimes on an event IF the event id is included in the request.
17
-     *
18
-     * @var EE_Datetime[]
19
-     */
20
-    protected $_dtts_for_event = array();
21
-
22
-
23
-    /**
24
-     * The event if one is specified in the request
25
-     *
26
-     * @var EE_Event
27
-     */
28
-    protected $_evt = null;
29
-
30
-
31
-    /**
32
-     * The DTT_ID if the current view has a specified datetime.
33
-     *
34
-     * @var int $_cur_dtt_id
35
-     */
36
-    protected $_cur_dtt_id = 0;
37
-
38
-
39
-    /**
40
-     * EE_Event_Registrations_List_Table constructor.
41
-     *
42
-     * @param \Registrations_Admin_Page $admin_page
43
-     */
44
-    public function __construct($admin_page)
45
-    {
46
-        parent::__construct($admin_page);
47
-        $this->_status = $this->_admin_page->get_registration_status_array();
48
-    }
49
-
50
-
51
-    protected function _setup_data()
52
-    {
53
-        $this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page)
54
-            : $this->_admin_page->get_event_attendees($this->_per_page, false, true);
55
-        $this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees(
56
-            $this->_per_page,
57
-            true
58
-        ) : $this->_admin_page->get_event_attendees($this->_per_page, true, true);
59
-    }
60
-
61
-
62
-    protected function _set_properties()
63
-    {
64
-        $return_url = $this->getReturnUrl();
65
-
66
-        $evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
67
-        $this->_wp_list_args = array(
68
-            'singular' => esc_html__('registrant', 'event_espresso'),
69
-            'plural'   => esc_html__('registrants', 'event_espresso'),
70
-            'ajax'     => true,
71
-            'screen'   => $this->_admin_page->get_current_screen()->id,
72
-        );
73
-        $columns = array();
74
-        // $columns['_Reg_Status'] = '';
75
-        $this->_columns = array(
76
-            '_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>',
77
-            'ATT_name'            => esc_html__('Registrant', 'event_espresso'),
78
-            'ATT_email'           => esc_html__('Email Address', 'event_espresso'),
79
-            'Event'               => esc_html__('Event', 'event_espresso'),
80
-            'PRC_name'            => esc_html__('TKT Option', 'event_espresso'),
81
-            '_REG_final_price'    => esc_html__('Price', 'event_espresso'),
82
-            'TXN_paid'            => esc_html__('Paid', 'event_espresso'),
83
-            'TXN_total'           => esc_html__('Total', 'event_espresso'),
84
-        );
85
-        // Add/remove columns when an event has been selected
86
-        if (! empty($evt_id)) {
87
-            // Render a checkbox column
88
-            $columns['cb'] = '<input type="checkbox" />';
89
-            $this->_has_checkbox_column = true;
90
-            // Remove the 'Event' column
91
-            unset($this->_columns['Event']);
92
-        }
93
-        $this->_columns = array_merge($columns, $this->_columns);
94
-        $this->_primary_column = '_REG_att_checked_in';
95
-        if (
96
-            ! empty($evt_id)
97
-            && EE_Registry::instance()->CAP->current_user_can(
98
-                'ee_read_registrations',
99
-                'espresso_registrations_registrations_reports',
100
-                $evt_id
101
-            )
102
-        ) {
103
-            $this->_bottom_buttons = array(
104
-                'report' => array(
105
-                    'route'         => 'registrations_report',
106
-                    'extra_request' =>
107
-                        array(
108
-                            'EVT_ID'     => $evt_id,
109
-                            'return_url' => $return_url,
110
-                        ),
111
-                ),
112
-            );
113
-        }
114
-        $this->_bottom_buttons['report_filtered'] = array(
115
-            'route'         => 'registrations_checkin_report',
116
-            'extra_request' => array(
117
-                'use_filters' => true,
118
-                'filters'     => array_merge(
119
-                    array(
120
-                        'EVT_ID' => $evt_id,
121
-                    ),
122
-                    array_diff_key(
123
-                        $this->_req_data,
124
-                        array_flip(
125
-                            array(
126
-                                'page',
127
-                                'action',
128
-                                'default_nonce',
129
-                            )
130
-                        )
131
-                    )
132
-                ),
133
-                'return_url'  => $return_url,
134
-            ),
135
-        );
136
-        $this->_sortable_columns = array(
137
-            /**
138
-             * Allows users to change the default sort if they wish.
139
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
140
-             *
141
-             * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to
142
-             * change the sorts on any list table involving registration contacts.  If you want to only change the filter
143
-             * for a specific list table you can use the provided reference to this object instance.
144
-             */
145
-            'ATT_name' => array(
146
-                'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
147
-                true,
148
-                $this,
149
-            )
150
-                ? array('ATT_lname' => true)
151
-                : array('ATT_fname' => true),
152
-            'Event'    => array('Event.EVT_name' => false),
153
-        );
154
-        $this->_hidden_columns = array();
155
-        $this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id);
156
-        $this->_dtts_for_event = $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : array();
157
-    }
158
-
159
-
160
-    /**
161
-     * @param \EE_Registration $item
162
-     * @return string
163
-     */
164
-    protected function _get_row_class($item)
165
-    {
166
-        $class = parent::_get_row_class($item);
167
-        // add status class
168
-        $class .= ' ee-status-strip reg-status-' . $item->status_ID();
169
-        if ($this->_has_checkbox_column) {
170
-            $class .= ' has-checkbox-column';
171
-        }
172
-        return $class;
173
-    }
174
-
175
-
176
-    /**
177
-     * @return array
178
-     * @throws \EE_Error
179
-     */
180
-    protected function _get_table_filters()
181
-    {
182
-        $filters = $where = array();
183
-        $current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0;
184
-        if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) {
185
-            // this means we don't have an event so let's setup a filter dropdown for all the events to select
186
-            // note possible capability restrictions
187
-            if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
188
-                $where['status**'] = array('!=', 'private');
189
-            }
190
-            if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
191
-                $where['EVT_wp_user'] = get_current_user_id();
192
-            }
193
-            $events = EEM_Event::instance()->get_all(
194
-                array(
195
-                    $where,
196
-                    'order_by' => array('Datetime.DTT_EVT_start' => 'DESC'),
197
-                )
198
-            );
199
-            $evts[] = array(
200
-                'id'   => 0,
201
-                'text' => esc_html__('To toggle Check-in status, select an event', 'event_espresso'),
202
-            );
203
-            $checked = 'checked';
204
-            /** @var EE_Event $evt */
205
-            foreach ($events as $evt) {
206
-                // any registrations for this event?
207
-                if (! $evt->get_count_of_all_registrations()) {
208
-                    continue;
209
-                }
210
-                $evts[] = array(
211
-                    'id'    => $evt->ID(),
212
-                    'text'  => apply_filters(
213
-                        'FHEE__EE_Event_Registrations___get_table_filters__event_name',
214
-                        $evt->get('EVT_name'),
215
-                        $evt
216
-                    ),
217
-                    'class' => $evt->is_expired() ? 'ee-expired-event' : '',
218
-                );
219
-                if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) {
220
-                    $checked = '';
221
-                }
222
-            }
223
-            $event_filter = '<div class="ee-event-filter">';
224
-            $event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID);
225
-            $event_filter .= '<span class="ee-event-filter-toggle">';
226
-            $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> ';
227
-            $event_filter .= esc_html__('Hide Expired Events', 'event_espresso');
228
-            $event_filter .= '</span>';
229
-            $event_filter .= '</div>';
230
-            $filters[] = $event_filter;
231
-        }
232
-        if (! empty($this->_dtts_for_event)) {
233
-            // DTT datetimes filter
234
-            $this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0;
235
-            if (count($this->_dtts_for_event) > 1) {
236
-                $dtts[0] = esc_html__('To toggle check-in status, select a datetime.', 'event_espresso');
237
-                foreach ($this->_dtts_for_event as $dtt) {
238
-                    $datetime_string = $dtt->name();
239
-                    $datetime_string = ! empty($datetime_string) ? ' (' . $datetime_string . ')' : '';
240
-                    $datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string;
241
-                    $dtts[ $dtt->ID() ] = $datetime_string;
242
-                }
243
-                $input = new EE_Select_Input(
244
-                    $dtts,
245
-                    array(
246
-                        'html_name' => 'DTT_ID',
247
-                        'html_id'   => 'DTT_ID',
248
-                        'default'   => $this->_cur_dtt_id,
249
-                    )
250
-                );
251
-                $filters[] = $input->get_html_for_input();
252
-                $filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">';
253
-            }
254
-        }
255
-        return $filters;
256
-    }
257
-
258
-
259
-    protected function _add_view_counts()
260
-    {
261
-        $this->_views['all']['count'] = $this->_get_total_event_attendees();
262
-    }
263
-
264
-
265
-    /**
266
-     * @return int
267
-     * @throws \EE_Error
268
-     */
269
-    protected function _get_total_event_attendees()
270
-    {
271
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
272
-        $DTT_ID = $this->_cur_dtt_id;
273
-        $query_params = array();
274
-        if ($EVT_ID) {
275
-            $query_params[0]['EVT_ID'] = $EVT_ID;
276
-        }
277
-        // if DTT is included we only show for that datetime.  Otherwise we're showing for all datetimes (the event).
278
-        if ($DTT_ID) {
279
-            $query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID;
280
-        }
281
-        $status_ids_array = apply_filters(
282
-            'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
283
-            array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
284
-        );
285
-        $query_params[0]['STS_ID'] = array('IN', $status_ids_array);
286
-        return EEM_Registration::instance()->count($query_params);
287
-    }
288
-
289
-
290
-    /**
291
-     * @param \EE_Registration $item
292
-     * @return string
293
-     */
294
-    public function column__Reg_Status(EE_Registration $item)
295
-    {
296
-        return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>';
297
-    }
298
-
299
-
300
-    /**
301
-     * @param \EE_Registration $item
302
-     * @return string
303
-     * @throws \EE_Error
304
-     */
305
-    public function column_cb($item)
306
-    {
307
-        return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID());
308
-    }
309
-
310
-
311
-    /**
312
-     * column_REG_att_checked_in
313
-     *
314
-     * @param EE_Registration $item
315
-     * @return string
316
-     * @throws EE_Error
317
-     * @throws InvalidArgumentException
318
-     * @throws InvalidDataTypeException
319
-     * @throws InvalidInterfaceException
320
-     */
321
-    public function column__REG_att_checked_in(EE_Registration $item)
322
-    {
323
-        $attendee = $item->attendee();
324
-        $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
325
-
326
-        if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) {
327
-            $latest_related_datetime = $item->get_latest_related_datetime();
328
-            if ($latest_related_datetime instanceof EE_Datetime) {
329
-                $this->_cur_dtt_id = $latest_related_datetime->ID();
330
-            }
331
-        }
332
-        $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId(
333
-            $item,
334
-            $this->_cur_dtt_id
335
-        );
336
-        $nonce = wp_create_nonce('checkin_nonce');
337
-        $toggle_active = ! empty($this->_cur_dtt_id)
338
-                         && EE_Registry::instance()->CAP->current_user_can(
339
-                             'ee_edit_checkin',
340
-                             'espresso_registrations_toggle_checkin_status',
341
-                             $item->ID()
342
-                         )
343
-            ? ' clickable trigger-checkin'
344
-            : '';
345
-        $mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
346
-        return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"'
347
-               . ' data-_regid="' . $item->ID() . '"'
348
-               . ' data-dttid="' . $this->_cur_dtt_id . '"'
349
-               . ' data-nonce="' . $nonce . '">'
350
-               . '</span>'
351
-               . $mobile_view_content;
352
-    }
353
-
354
-
355
-    /**
356
-     * @param \EE_Registration $item
357
-     * @return mixed|string|void
358
-     * @throws \EE_Error
359
-     */
360
-    public function column_ATT_name(EE_Registration $item)
361
-    {
362
-        $attendee = $item->attendee();
363
-        if (! $attendee instanceof EE_Attendee) {
364
-            return esc_html__('No contact record for this registration.', 'event_espresso');
365
-        }
366
-        // edit attendee link
367
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
368
-            array('action' => 'view_registration', '_REG_ID' => $item->ID()),
369
-            REG_ADMIN_URL
370
-        );
371
-        $name_link = EE_Registry::instance()->CAP->current_user_can(
372
-            'ee_edit_contacts',
373
-            'espresso_registrations_edit_attendee'
374
-        )
375
-            ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
376
-              . $item->attendee()->full_name()
377
-              . '</a>'
378
-            : $item->attendee()->full_name();
379
-        $name_link .= $item->count() === 1
380
-            ? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>	'
381
-            : '';
382
-        // add group details
383
-        $name_link .= '&nbsp;' . sprintf(esc_html__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size());
384
-        // add regcode
385
-        $link = EE_Admin_Page::add_query_args_and_nonce(
386
-            array('action' => 'view_registration', '_REG_ID' => $item->ID()),
387
-            REG_ADMIN_URL
388
-        );
389
-        $name_link .= '<br>';
390
-        $name_link .= EE_Registry::instance()->instance()->CAP->current_user_can(
391
-            'ee_read_registration',
392
-            'view_registration',
393
-            $item->ID()
394
-        )
395
-            ? '<a href="' . $link . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
396
-              . $item->reg_code()
397
-              . '</a>'
398
-            : $item->reg_code();
399
-        // status
400
-        $name_link .= '<br><span class="ee-status-text-small">';
401
-        $name_link .= EEH_Template::pretty_status($item->status_ID(), false, 'sentence');
402
-        $name_link .= '</span>';
403
-        $actions = array();
404
-        $DTT_ID = $this->_cur_dtt_id;
405
-        $latest_related_datetime = empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $item instanceof EE_Registration
406
-            ? $item->get_latest_related_datetime()
407
-            : null;
408
-        $DTT_ID = $latest_related_datetime instanceof EE_Datetime
409
-            ? $latest_related_datetime->ID()
410
-            : $DTT_ID;
411
-        if (
412
-            ! empty($DTT_ID)
413
-            && EE_Registry::instance()->CAP->current_user_can(
414
-                'ee_read_checkins',
415
-                'espresso_registrations_registration_checkins'
416
-            )
417
-        ) {
418
-            $checkin_list_url = EE_Admin_Page::add_query_args_and_nonce(
419
-                array('action' => 'registration_checkins', '_REG_ID' => $item->ID(), 'DTT_ID' => $DTT_ID),
420
-                REG_ADMIN_URL
421
-            );
422
-            // get the timestamps for this registration's checkins, related to the selected datetime
423
-            $timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID)));
424
-            if (! empty($timestamps)) {
425
-                // get the last timestamp
426
-                $last_timestamp = end($timestamps);
427
-                // checked in or checked out?
428
-                $checkin_status = $last_timestamp->get('CHK_in')
429
-                    ? esc_html__('Checked In', 'event_espresso')
430
-                    : esc_html__('Checked Out', 'event_espresso');
431
-                // get timestamp string
432
-                $timestamp_string = $last_timestamp->get_datetime('CHK_timestamp');
433
-                $actions['checkin'] = '<a href="' . $checkin_list_url . '" title="'
434
-                                      . esc_attr__(
435
-                                          'View this registrant\'s check-ins/checkouts for the datetime',
436
-                                          'event_espresso'
437
-                                      ) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>';
438
-            }
439
-        }
440
-        return (! empty($DTT_ID) && ! empty($timestamps))
441
-            ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true))
442
-            : $name_link;
443
-    }
444
-
445
-
446
-    /**
447
-     * @param \EE_Registration $item
448
-     * @return string
449
-     */
450
-    public function column_ATT_email(EE_Registration $item)
451
-    {
452
-        $attendee = $item->attendee();
453
-        return $attendee instanceof EE_Attendee ? $attendee->email() : '';
454
-    }
455
-
456
-
457
-    /**
458
-     * @param \EE_Registration $item
459
-     * @return bool|string
460
-     * @throws \EE_Error
461
-     */
462
-    public function column_Event(EE_Registration $item)
463
-    {
464
-        try {
465
-            $event = $this->_evt instanceof EE_Event ? $this->_evt : $item->event();
466
-            $chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
467
-                array('action' => 'event_registrations', 'event_id' => $event->ID()),
468
-                REG_ADMIN_URL
469
-            );
470
-            $event_label = EE_Registry::instance()->CAP->current_user_can(
471
-                'ee_read_checkins',
472
-                'espresso_registrations_registration_checkins'
473
-            ) ? '<a href="' . $chkin_lnk_url . '" title="'
474
-                . esc_attr__(
475
-                    'View Checkins for this Event',
476
-                    'event_espresso'
477
-                ) . '">' . $event->name() . '</a>' : $event->name();
478
-        } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) {
479
-            $event_label = esc_html__('Unknown', 'event_espresso');
480
-        }
481
-        return $event_label;
482
-    }
483
-
484
-
485
-    /**
486
-     * @param \EE_Registration $item
487
-     * @return mixed|string|void
488
-     */
489
-    public function column_PRC_name(EE_Registration $item)
490
-    {
491
-        return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : esc_html__("Unknown", "event_espresso");
492
-    }
493
-
494
-
495
-    /**
496
-     * column_REG_final_price
497
-     *
498
-     * @param \EE_Registration $item
499
-     * @return string
500
-     */
501
-    public function column__REG_final_price(EE_Registration $item)
502
-    {
503
-        return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>';
504
-    }
505
-
506
-
507
-    /**
508
-     * column_TXN_paid
509
-     *
510
-     * @param \EE_Registration $item
511
-     * @return string
512
-     * @throws \EE_Error
513
-     */
514
-    public function column_TXN_paid(EE_Registration $item)
515
-    {
516
-        if ($item->count() === 1) {
517
-            if ($item->transaction()->paid() >= $item->transaction()->total()) {
518
-                return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
519
-            } else {
520
-                $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
521
-                    array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()),
522
-                    TXN_ADMIN_URL
523
-                );
524
-                return EE_Registry::instance()->CAP->current_user_can(
525
-                    'ee_read_transaction',
526
-                    'espresso_transactions_view_transaction'
527
-                ) ? '
15
+	/**
16
+	 * This property will hold the related Datetimes on an event IF the event id is included in the request.
17
+	 *
18
+	 * @var EE_Datetime[]
19
+	 */
20
+	protected $_dtts_for_event = array();
21
+
22
+
23
+	/**
24
+	 * The event if one is specified in the request
25
+	 *
26
+	 * @var EE_Event
27
+	 */
28
+	protected $_evt = null;
29
+
30
+
31
+	/**
32
+	 * The DTT_ID if the current view has a specified datetime.
33
+	 *
34
+	 * @var int $_cur_dtt_id
35
+	 */
36
+	protected $_cur_dtt_id = 0;
37
+
38
+
39
+	/**
40
+	 * EE_Event_Registrations_List_Table constructor.
41
+	 *
42
+	 * @param \Registrations_Admin_Page $admin_page
43
+	 */
44
+	public function __construct($admin_page)
45
+	{
46
+		parent::__construct($admin_page);
47
+		$this->_status = $this->_admin_page->get_registration_status_array();
48
+	}
49
+
50
+
51
+	protected function _setup_data()
52
+	{
53
+		$this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page)
54
+			: $this->_admin_page->get_event_attendees($this->_per_page, false, true);
55
+		$this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees(
56
+			$this->_per_page,
57
+			true
58
+		) : $this->_admin_page->get_event_attendees($this->_per_page, true, true);
59
+	}
60
+
61
+
62
+	protected function _set_properties()
63
+	{
64
+		$return_url = $this->getReturnUrl();
65
+
66
+		$evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
67
+		$this->_wp_list_args = array(
68
+			'singular' => esc_html__('registrant', 'event_espresso'),
69
+			'plural'   => esc_html__('registrants', 'event_espresso'),
70
+			'ajax'     => true,
71
+			'screen'   => $this->_admin_page->get_current_screen()->id,
72
+		);
73
+		$columns = array();
74
+		// $columns['_Reg_Status'] = '';
75
+		$this->_columns = array(
76
+			'_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>',
77
+			'ATT_name'            => esc_html__('Registrant', 'event_espresso'),
78
+			'ATT_email'           => esc_html__('Email Address', 'event_espresso'),
79
+			'Event'               => esc_html__('Event', 'event_espresso'),
80
+			'PRC_name'            => esc_html__('TKT Option', 'event_espresso'),
81
+			'_REG_final_price'    => esc_html__('Price', 'event_espresso'),
82
+			'TXN_paid'            => esc_html__('Paid', 'event_espresso'),
83
+			'TXN_total'           => esc_html__('Total', 'event_espresso'),
84
+		);
85
+		// Add/remove columns when an event has been selected
86
+		if (! empty($evt_id)) {
87
+			// Render a checkbox column
88
+			$columns['cb'] = '<input type="checkbox" />';
89
+			$this->_has_checkbox_column = true;
90
+			// Remove the 'Event' column
91
+			unset($this->_columns['Event']);
92
+		}
93
+		$this->_columns = array_merge($columns, $this->_columns);
94
+		$this->_primary_column = '_REG_att_checked_in';
95
+		if (
96
+			! empty($evt_id)
97
+			&& EE_Registry::instance()->CAP->current_user_can(
98
+				'ee_read_registrations',
99
+				'espresso_registrations_registrations_reports',
100
+				$evt_id
101
+			)
102
+		) {
103
+			$this->_bottom_buttons = array(
104
+				'report' => array(
105
+					'route'         => 'registrations_report',
106
+					'extra_request' =>
107
+						array(
108
+							'EVT_ID'     => $evt_id,
109
+							'return_url' => $return_url,
110
+						),
111
+				),
112
+			);
113
+		}
114
+		$this->_bottom_buttons['report_filtered'] = array(
115
+			'route'         => 'registrations_checkin_report',
116
+			'extra_request' => array(
117
+				'use_filters' => true,
118
+				'filters'     => array_merge(
119
+					array(
120
+						'EVT_ID' => $evt_id,
121
+					),
122
+					array_diff_key(
123
+						$this->_req_data,
124
+						array_flip(
125
+							array(
126
+								'page',
127
+								'action',
128
+								'default_nonce',
129
+							)
130
+						)
131
+					)
132
+				),
133
+				'return_url'  => $return_url,
134
+			),
135
+		);
136
+		$this->_sortable_columns = array(
137
+			/**
138
+			 * Allows users to change the default sort if they wish.
139
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
140
+			 *
141
+			 * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to
142
+			 * change the sorts on any list table involving registration contacts.  If you want to only change the filter
143
+			 * for a specific list table you can use the provided reference to this object instance.
144
+			 */
145
+			'ATT_name' => array(
146
+				'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
147
+				true,
148
+				$this,
149
+			)
150
+				? array('ATT_lname' => true)
151
+				: array('ATT_fname' => true),
152
+			'Event'    => array('Event.EVT_name' => false),
153
+		);
154
+		$this->_hidden_columns = array();
155
+		$this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id);
156
+		$this->_dtts_for_event = $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : array();
157
+	}
158
+
159
+
160
+	/**
161
+	 * @param \EE_Registration $item
162
+	 * @return string
163
+	 */
164
+	protected function _get_row_class($item)
165
+	{
166
+		$class = parent::_get_row_class($item);
167
+		// add status class
168
+		$class .= ' ee-status-strip reg-status-' . $item->status_ID();
169
+		if ($this->_has_checkbox_column) {
170
+			$class .= ' has-checkbox-column';
171
+		}
172
+		return $class;
173
+	}
174
+
175
+
176
+	/**
177
+	 * @return array
178
+	 * @throws \EE_Error
179
+	 */
180
+	protected function _get_table_filters()
181
+	{
182
+		$filters = $where = array();
183
+		$current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0;
184
+		if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) {
185
+			// this means we don't have an event so let's setup a filter dropdown for all the events to select
186
+			// note possible capability restrictions
187
+			if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
188
+				$where['status**'] = array('!=', 'private');
189
+			}
190
+			if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
191
+				$where['EVT_wp_user'] = get_current_user_id();
192
+			}
193
+			$events = EEM_Event::instance()->get_all(
194
+				array(
195
+					$where,
196
+					'order_by' => array('Datetime.DTT_EVT_start' => 'DESC'),
197
+				)
198
+			);
199
+			$evts[] = array(
200
+				'id'   => 0,
201
+				'text' => esc_html__('To toggle Check-in status, select an event', 'event_espresso'),
202
+			);
203
+			$checked = 'checked';
204
+			/** @var EE_Event $evt */
205
+			foreach ($events as $evt) {
206
+				// any registrations for this event?
207
+				if (! $evt->get_count_of_all_registrations()) {
208
+					continue;
209
+				}
210
+				$evts[] = array(
211
+					'id'    => $evt->ID(),
212
+					'text'  => apply_filters(
213
+						'FHEE__EE_Event_Registrations___get_table_filters__event_name',
214
+						$evt->get('EVT_name'),
215
+						$evt
216
+					),
217
+					'class' => $evt->is_expired() ? 'ee-expired-event' : '',
218
+				);
219
+				if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) {
220
+					$checked = '';
221
+				}
222
+			}
223
+			$event_filter = '<div class="ee-event-filter">';
224
+			$event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID);
225
+			$event_filter .= '<span class="ee-event-filter-toggle">';
226
+			$event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> ';
227
+			$event_filter .= esc_html__('Hide Expired Events', 'event_espresso');
228
+			$event_filter .= '</span>';
229
+			$event_filter .= '</div>';
230
+			$filters[] = $event_filter;
231
+		}
232
+		if (! empty($this->_dtts_for_event)) {
233
+			// DTT datetimes filter
234
+			$this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0;
235
+			if (count($this->_dtts_for_event) > 1) {
236
+				$dtts[0] = esc_html__('To toggle check-in status, select a datetime.', 'event_espresso');
237
+				foreach ($this->_dtts_for_event as $dtt) {
238
+					$datetime_string = $dtt->name();
239
+					$datetime_string = ! empty($datetime_string) ? ' (' . $datetime_string . ')' : '';
240
+					$datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string;
241
+					$dtts[ $dtt->ID() ] = $datetime_string;
242
+				}
243
+				$input = new EE_Select_Input(
244
+					$dtts,
245
+					array(
246
+						'html_name' => 'DTT_ID',
247
+						'html_id'   => 'DTT_ID',
248
+						'default'   => $this->_cur_dtt_id,
249
+					)
250
+				);
251
+				$filters[] = $input->get_html_for_input();
252
+				$filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">';
253
+			}
254
+		}
255
+		return $filters;
256
+	}
257
+
258
+
259
+	protected function _add_view_counts()
260
+	{
261
+		$this->_views['all']['count'] = $this->_get_total_event_attendees();
262
+	}
263
+
264
+
265
+	/**
266
+	 * @return int
267
+	 * @throws \EE_Error
268
+	 */
269
+	protected function _get_total_event_attendees()
270
+	{
271
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
272
+		$DTT_ID = $this->_cur_dtt_id;
273
+		$query_params = array();
274
+		if ($EVT_ID) {
275
+			$query_params[0]['EVT_ID'] = $EVT_ID;
276
+		}
277
+		// if DTT is included we only show for that datetime.  Otherwise we're showing for all datetimes (the event).
278
+		if ($DTT_ID) {
279
+			$query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID;
280
+		}
281
+		$status_ids_array = apply_filters(
282
+			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
283
+			array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
284
+		);
285
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
286
+		return EEM_Registration::instance()->count($query_params);
287
+	}
288
+
289
+
290
+	/**
291
+	 * @param \EE_Registration $item
292
+	 * @return string
293
+	 */
294
+	public function column__Reg_Status(EE_Registration $item)
295
+	{
296
+		return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>';
297
+	}
298
+
299
+
300
+	/**
301
+	 * @param \EE_Registration $item
302
+	 * @return string
303
+	 * @throws \EE_Error
304
+	 */
305
+	public function column_cb($item)
306
+	{
307
+		return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID());
308
+	}
309
+
310
+
311
+	/**
312
+	 * column_REG_att_checked_in
313
+	 *
314
+	 * @param EE_Registration $item
315
+	 * @return string
316
+	 * @throws EE_Error
317
+	 * @throws InvalidArgumentException
318
+	 * @throws InvalidDataTypeException
319
+	 * @throws InvalidInterfaceException
320
+	 */
321
+	public function column__REG_att_checked_in(EE_Registration $item)
322
+	{
323
+		$attendee = $item->attendee();
324
+		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
325
+
326
+		if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) {
327
+			$latest_related_datetime = $item->get_latest_related_datetime();
328
+			if ($latest_related_datetime instanceof EE_Datetime) {
329
+				$this->_cur_dtt_id = $latest_related_datetime->ID();
330
+			}
331
+		}
332
+		$checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId(
333
+			$item,
334
+			$this->_cur_dtt_id
335
+		);
336
+		$nonce = wp_create_nonce('checkin_nonce');
337
+		$toggle_active = ! empty($this->_cur_dtt_id)
338
+						 && EE_Registry::instance()->CAP->current_user_can(
339
+							 'ee_edit_checkin',
340
+							 'espresso_registrations_toggle_checkin_status',
341
+							 $item->ID()
342
+						 )
343
+			? ' clickable trigger-checkin'
344
+			: '';
345
+		$mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
346
+		return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"'
347
+			   . ' data-_regid="' . $item->ID() . '"'
348
+			   . ' data-dttid="' . $this->_cur_dtt_id . '"'
349
+			   . ' data-nonce="' . $nonce . '">'
350
+			   . '</span>'
351
+			   . $mobile_view_content;
352
+	}
353
+
354
+
355
+	/**
356
+	 * @param \EE_Registration $item
357
+	 * @return mixed|string|void
358
+	 * @throws \EE_Error
359
+	 */
360
+	public function column_ATT_name(EE_Registration $item)
361
+	{
362
+		$attendee = $item->attendee();
363
+		if (! $attendee instanceof EE_Attendee) {
364
+			return esc_html__('No contact record for this registration.', 'event_espresso');
365
+		}
366
+		// edit attendee link
367
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
368
+			array('action' => 'view_registration', '_REG_ID' => $item->ID()),
369
+			REG_ADMIN_URL
370
+		);
371
+		$name_link = EE_Registry::instance()->CAP->current_user_can(
372
+			'ee_edit_contacts',
373
+			'espresso_registrations_edit_attendee'
374
+		)
375
+			? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
376
+			  . $item->attendee()->full_name()
377
+			  . '</a>'
378
+			: $item->attendee()->full_name();
379
+		$name_link .= $item->count() === 1
380
+			? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>	'
381
+			: '';
382
+		// add group details
383
+		$name_link .= '&nbsp;' . sprintf(esc_html__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size());
384
+		// add regcode
385
+		$link = EE_Admin_Page::add_query_args_and_nonce(
386
+			array('action' => 'view_registration', '_REG_ID' => $item->ID()),
387
+			REG_ADMIN_URL
388
+		);
389
+		$name_link .= '<br>';
390
+		$name_link .= EE_Registry::instance()->instance()->CAP->current_user_can(
391
+			'ee_read_registration',
392
+			'view_registration',
393
+			$item->ID()
394
+		)
395
+			? '<a href="' . $link . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
396
+			  . $item->reg_code()
397
+			  . '</a>'
398
+			: $item->reg_code();
399
+		// status
400
+		$name_link .= '<br><span class="ee-status-text-small">';
401
+		$name_link .= EEH_Template::pretty_status($item->status_ID(), false, 'sentence');
402
+		$name_link .= '</span>';
403
+		$actions = array();
404
+		$DTT_ID = $this->_cur_dtt_id;
405
+		$latest_related_datetime = empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $item instanceof EE_Registration
406
+			? $item->get_latest_related_datetime()
407
+			: null;
408
+		$DTT_ID = $latest_related_datetime instanceof EE_Datetime
409
+			? $latest_related_datetime->ID()
410
+			: $DTT_ID;
411
+		if (
412
+			! empty($DTT_ID)
413
+			&& EE_Registry::instance()->CAP->current_user_can(
414
+				'ee_read_checkins',
415
+				'espresso_registrations_registration_checkins'
416
+			)
417
+		) {
418
+			$checkin_list_url = EE_Admin_Page::add_query_args_and_nonce(
419
+				array('action' => 'registration_checkins', '_REG_ID' => $item->ID(), 'DTT_ID' => $DTT_ID),
420
+				REG_ADMIN_URL
421
+			);
422
+			// get the timestamps for this registration's checkins, related to the selected datetime
423
+			$timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID)));
424
+			if (! empty($timestamps)) {
425
+				// get the last timestamp
426
+				$last_timestamp = end($timestamps);
427
+				// checked in or checked out?
428
+				$checkin_status = $last_timestamp->get('CHK_in')
429
+					? esc_html__('Checked In', 'event_espresso')
430
+					: esc_html__('Checked Out', 'event_espresso');
431
+				// get timestamp string
432
+				$timestamp_string = $last_timestamp->get_datetime('CHK_timestamp');
433
+				$actions['checkin'] = '<a href="' . $checkin_list_url . '" title="'
434
+									  . esc_attr__(
435
+										  'View this registrant\'s check-ins/checkouts for the datetime',
436
+										  'event_espresso'
437
+									  ) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>';
438
+			}
439
+		}
440
+		return (! empty($DTT_ID) && ! empty($timestamps))
441
+			? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true))
442
+			: $name_link;
443
+	}
444
+
445
+
446
+	/**
447
+	 * @param \EE_Registration $item
448
+	 * @return string
449
+	 */
450
+	public function column_ATT_email(EE_Registration $item)
451
+	{
452
+		$attendee = $item->attendee();
453
+		return $attendee instanceof EE_Attendee ? $attendee->email() : '';
454
+	}
455
+
456
+
457
+	/**
458
+	 * @param \EE_Registration $item
459
+	 * @return bool|string
460
+	 * @throws \EE_Error
461
+	 */
462
+	public function column_Event(EE_Registration $item)
463
+	{
464
+		try {
465
+			$event = $this->_evt instanceof EE_Event ? $this->_evt : $item->event();
466
+			$chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
467
+				array('action' => 'event_registrations', 'event_id' => $event->ID()),
468
+				REG_ADMIN_URL
469
+			);
470
+			$event_label = EE_Registry::instance()->CAP->current_user_can(
471
+				'ee_read_checkins',
472
+				'espresso_registrations_registration_checkins'
473
+			) ? '<a href="' . $chkin_lnk_url . '" title="'
474
+				. esc_attr__(
475
+					'View Checkins for this Event',
476
+					'event_espresso'
477
+				) . '">' . $event->name() . '</a>' : $event->name();
478
+		} catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) {
479
+			$event_label = esc_html__('Unknown', 'event_espresso');
480
+		}
481
+		return $event_label;
482
+	}
483
+
484
+
485
+	/**
486
+	 * @param \EE_Registration $item
487
+	 * @return mixed|string|void
488
+	 */
489
+	public function column_PRC_name(EE_Registration $item)
490
+	{
491
+		return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : esc_html__("Unknown", "event_espresso");
492
+	}
493
+
494
+
495
+	/**
496
+	 * column_REG_final_price
497
+	 *
498
+	 * @param \EE_Registration $item
499
+	 * @return string
500
+	 */
501
+	public function column__REG_final_price(EE_Registration $item)
502
+	{
503
+		return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>';
504
+	}
505
+
506
+
507
+	/**
508
+	 * column_TXN_paid
509
+	 *
510
+	 * @param \EE_Registration $item
511
+	 * @return string
512
+	 * @throws \EE_Error
513
+	 */
514
+	public function column_TXN_paid(EE_Registration $item)
515
+	{
516
+		if ($item->count() === 1) {
517
+			if ($item->transaction()->paid() >= $item->transaction()->total()) {
518
+				return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
519
+			} else {
520
+				$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
521
+					array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()),
522
+					TXN_ADMIN_URL
523
+				);
524
+				return EE_Registry::instance()->CAP->current_user_can(
525
+					'ee_read_transaction',
526
+					'espresso_transactions_view_transaction'
527
+				) ? '
528 528
 				<span class="reg-pad-rght">
529 529
 					<a class="status-'
530
-                    . $item->transaction()->status_ID()
531
-                    . '" href="'
532
-                    . $view_txn_lnk_url
533
-                    . '"  title="'
534
-                    . esc_attr__('View Transaction', 'event_espresso')
535
-                    . '">
530
+					. $item->transaction()->status_ID()
531
+					. '" href="'
532
+					. $view_txn_lnk_url
533
+					. '"  title="'
534
+					. esc_attr__('View Transaction', 'event_espresso')
535
+					. '">
536 536
 						'
537
-                    . $item->transaction()->pretty_paid()
538
-                    . '
537
+					. $item->transaction()->pretty_paid()
538
+					. '
539 539
 					</a>
540 540
 				<span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
541
-            }
542
-        } else {
543
-            return '<span class="reg-pad-rght"></span>';
544
-        }
545
-    }
546
-
547
-
548
-    /**
549
-     *        column_TXN_total
550
-     *
551
-     * @param \EE_Registration $item
552
-     * @return string
553
-     * @throws \EE_Error
554
-     */
555
-    public function column_TXN_total(EE_Registration $item)
556
-    {
557
-        $txn = $item->transaction();
558
-        $view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL);
559
-        if ($item->get('REG_count') === 1) {
560
-            $line_total_obj = $txn->total_line_item();
561
-            $txn_total = $line_total_obj instanceof EE_Line_Item
562
-                ? $line_total_obj->get_pretty('LIN_total')
563
-                : esc_html__(
564
-                    'View Transaction',
565
-                    'event_espresso'
566
-                );
567
-            return EE_Registry::instance()->CAP->current_user_can(
568
-                'ee_read_transaction',
569
-                'espresso_transactions_view_transaction'
570
-            ) ? '<a href="'
571
-                . $view_txn_url
572
-                . '" title="'
573
-                . esc_attr__('View Transaction', 'event_espresso')
574
-                . '"><span class="reg-pad-rght">'
575
-                . $txn_total
576
-                . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
577
-        } else {
578
-            return '<span class="reg-pad-rght"></span>';
579
-        }
580
-    }
541
+			}
542
+		} else {
543
+			return '<span class="reg-pad-rght"></span>';
544
+		}
545
+	}
546
+
547
+
548
+	/**
549
+	 *        column_TXN_total
550
+	 *
551
+	 * @param \EE_Registration $item
552
+	 * @return string
553
+	 * @throws \EE_Error
554
+	 */
555
+	public function column_TXN_total(EE_Registration $item)
556
+	{
557
+		$txn = $item->transaction();
558
+		$view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL);
559
+		if ($item->get('REG_count') === 1) {
560
+			$line_total_obj = $txn->total_line_item();
561
+			$txn_total = $line_total_obj instanceof EE_Line_Item
562
+				? $line_total_obj->get_pretty('LIN_total')
563
+				: esc_html__(
564
+					'View Transaction',
565
+					'event_espresso'
566
+				);
567
+			return EE_Registry::instance()->CAP->current_user_can(
568
+				'ee_read_transaction',
569
+				'espresso_transactions_view_transaction'
570
+			) ? '<a href="'
571
+				. $view_txn_url
572
+				. '" title="'
573
+				. esc_attr__('View Transaction', 'event_espresso')
574
+				. '"><span class="reg-pad-rght">'
575
+				. $txn_total
576
+				. '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
577
+		} else {
578
+			return '<span class="reg-pad-rght"></span>';
579
+		}
580
+	}
581 581
 }
Please login to merge, or discard this patch.
admin/extend/registrations/Extend_EE_Attendee_Contact_List_Table.class.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -15,17 +15,17 @@
 block discarded – undo
15 15
 class Extend_EE_Attendee_Contact_List_Table extends EE_Attendee_Contact_List_Table
16 16
 {
17 17
 
18
-    protected function _set_properties()
19
-    {
20
-        parent::_set_properties();
21
-        $this->_bottom_buttons = array(
22
-            'contact_list_report' => array(
23
-                'route'         => 'contact_list_report',
24
-                'extra_request' =>
25
-                    array(
26
-                        'return_url' => $this->getReturnUrl(),
27
-                    ),
28
-            ),
29
-        );
30
-    }
18
+	protected function _set_properties()
19
+	{
20
+		parent::_set_properties();
21
+		$this->_bottom_buttons = array(
22
+			'contact_list_report' => array(
23
+				'route'         => 'contact_list_report',
24
+				'extra_request' =>
25
+					array(
26
+						'return_url' => $this->getReturnUrl(),
27
+					),
28
+			),
29
+		);
30
+	}
31 31
 }
Please login to merge, or discard this patch.
caffeinated/modules/event_single_caff/EED_Event_Single_Caff.module.php 2 patches
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -26,228 +26,228 @@
 block discarded – undo
26 26
 {
27 27
 
28 28
 
29
-    /**
30
-     * @return EED_Event_Single_Caff
31
-     */
32
-    public static function instance()
33
-    {
34
-        return parent::get_instance(__CLASS__);
35
-    }
36
-
37
-
38
-    /**
39
-     *    set_hooks - for hooking into EE Core, other modules, etc
40
-     *
41
-     * @access    public
42
-     * @return    void
43
-     */
44
-    public static function set_hooks()
45
-    {
46
-    }
47
-
48
-    /**
49
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
50
-     *
51
-     * @access    public
52
-     * @return    void
53
-     */
54
-    public static function set_hooks_admin()
55
-    {
56
-        self::setDefinitions();
57
-        add_action(
58
-            'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__template_settings',
59
-            array('EED_Event_Single_Caff', 'load_scripts_styles'),
60
-            10
61
-        );
62
-        add_action(
63
-            'AHEE__template_settings__template__before_settings_form',
64
-            array('EED_Event_Single_Caff', 'template_settings_form'),
65
-            10
66
-        );
67
-        add_filter(
68
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
69
-            array('EED_Event_Single_Caff', 'update_template_settings'),
70
-            10,
71
-            2
72
-        );
73
-        // AJAX
74
-        add_action(
75
-            'wp_ajax_espresso_update_event_single_order',
76
-            array('EED_Event_Single_Caff', 'update_event_single_order')
77
-        );
78
-        add_action(
79
-            'wp_ajax_nopriv_espresso_update_event_single_order',
80
-            array('EED_Event_Single_Caff', 'update_event_single_order')
81
-        );
82
-    }
83
-
84
-
85
-    public static function load_scripts_styles()
86
-    {
87
-        add_action('admin_enqueue_scripts', array('EED_Event_Single_Caff', 'enqueue_scripts_styles'), 10);
88
-    }
89
-
90
-
91
-    public static function enqueue_scripts_styles()
92
-    {
93
-        wp_register_style(
94
-            'eed-event-single-sortable',
95
-            EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.css',
96
-            array(),
97
-            EVENT_ESPRESSO_VERSION
98
-        );
99
-        wp_enqueue_style('eed-event-single-sortable');
100
-        wp_register_script(
101
-            'eed-event-single-sortable',
102
-            EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.js',
103
-            array('jquery-ui-sortable'),
104
-            EVENT_ESPRESSO_VERSION,
105
-            true
106
-        );
107
-        wp_enqueue_script('eed-event-single-sortable');
108
-    }
109
-
110
-
111
-    /**
112
-     * Set constants only if they haven't been set yet.
113
-     */
114
-    public static function setDefinitions()
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/');
119
-        }
120
-    }
121
-
122
-
123
-    /**
124
-     *    template_settings_form
125
-     *
126
-     * @access    public
127
-     * @static
128
-     * @return    void
129
-     */
130
-    public static function template_settings_form()
131
-    {
132
-        $config = EE_Registry::instance()->CFG->template_settings;
133
-        $config = isset($config->EED_Event_Single) && $config->EED_Event_Single instanceof EE_Event_Single_Config
134
-            ? $config->EED_Event_Single : new EE_Event_Single_Config();
135
-        $config->use_sortable_display_order = isset($config->use_sortable_display_order)
136
-            ? $config->use_sortable_display_order : false;
137
-        $config = apply_filters('FHEE__EED_Event_Single__template_settings_form__event_list_config', $config);
138
-
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';
144
-        // get template parts
145
-        $template_parts = EED_Event_Single::instance()->initialize_template_parts($config);
146
-        // convert to array so that we can add more properties
147
-        $config = get_object_vars($config);
148
-        $config['event_single_display_order'] = $template_parts->generate_sortable_list_of_template_parts(
149
-            'event-single-sortable-js',
150
-            '',
151
-            'single-sortable-li single-sortable-js'
152
-        );
153
-        EEH_Template::display_template(
154
-            EVENT_SINGLE_CAFF_TEMPLATES_PATH . 'admin-event-single-settings.template.php',
155
-            $config
156
-        );
157
-    }
158
-
159
-
160
-    /**
161
-     * update_template_settings
162
-     *
163
-     * @param EE_Template_Config $CFG
164
-     * @param array              $REQ
165
-     * @return EE_Template_Config
166
-     */
167
-    public static function update_template_settings(EE_Template_Config $CFG, $REQ)
168
-    {
169
-        if (! $CFG->EED_Event_Single instanceof EE_Event_Single_Config) {
170
-            $CFG->EED_Event_Single = new EE_Event_Single_Config();
171
-        }
172
-        $display_order_event = $CFG->EED_Event_Single->display_order_event !== null
173
-            ? $CFG->EED_Event_Single->display_order_event
174
-            : EED_Event_Single::EVENT_DETAILS_PRIORITY;
175
-        $display_order_datetimes = $CFG->EED_Event_Single->display_order_datetimes !== null
176
-            ? $CFG->EED_Event_Single->display_order_datetimes
177
-            : EED_Event_Single::EVENT_DATETIMES_PRIORITY;
178
-        $display_order_tickets = $CFG->EED_Event_Single->display_order_tickets !== null
179
-            ? $CFG->EED_Event_Single->display_order_tickets
180
-            : EED_Event_Single::EVENT_TICKETS_PRIORITY;
181
-        $display_order_venue = $CFG->EED_Event_Single->display_order_venue !== null
182
-            ? $CFG->EED_Event_Single->display_order_venue
183
-            : EED_Event_Single::EVENT_VENUES_PRIORITY;
184
-        $CFG->EED_Event_Single = new EE_Event_Single_Config();
185
-        $CFG->EED_Event_Single->display_status_banner_single = ! empty($REQ['display_status_banner_single'])
186
-                                                               && $REQ['display_status_banner_single'];
187
-        $CFG->EED_Event_Single->display_venue = ! empty($REQ['display_venue']) && $REQ['display_venue'];
188
-        $CFG->EED_Event_Single->use_sortable_display_order = ! empty($REQ['EED_Events_Single_use_sortable_display_order'])
189
-            ? absint($REQ['EED_Events_Single_use_sortable_display_order'])
190
-            : 0;
191
-        $CFG->EED_Event_Single->display_order_event = $CFG->EED_Event_Single->use_sortable_display_order
192
-            ? $display_order_event
193
-            : EED_Event_Single::EVENT_DETAILS_PRIORITY;
194
-        $CFG->EED_Event_Single->display_order_datetimes = $CFG->EED_Event_Single->use_sortable_display_order
195
-            ? $display_order_datetimes
196
-            : EED_Event_Single::EVENT_DATETIMES_PRIORITY;
197
-        $CFG->EED_Event_Single->display_order_tickets = $CFG->EED_Event_Single->use_sortable_display_order
198
-            ? $display_order_tickets
199
-            : EED_Event_Single::EVENT_TICKETS_PRIORITY;
200
-        $CFG->EED_Event_Single->display_order_venue = $CFG->EED_Event_Single->use_sortable_display_order
201
-            ? $display_order_venue
202
-            : EED_Event_Single::EVENT_VENUES_PRIORITY;
203
-        do_action('AHEE__EED_Event_Single__update_template_settings__after_update', $CFG, $REQ);
204
-        return $CFG;
205
-    }
206
-
207
-
208
-    /**
209
-     * update_event_single_order
210
-     *
211
-     * @access    public
212
-     * @return    void
213
-     */
214
-    public static function update_event_single_order()
215
-    {
216
-        $config_saved = false;
217
-        $template_parts = EED_Event_Single_Caff::getRequest()->getRequestParam('elements');
218
-        if (! empty($template_parts)) {
219
-            $template_parts = explode(',', trim($template_parts, ','));
220
-            foreach ($template_parts as $key => $template_part) {
221
-                $template_part = "display_order_$template_part";
222
-                $priority = ($key * 10) + EED_Event_Single::EVENT_DETAILS_PRIORITY;
223
-                EE_Registry::instance()->CFG->template_settings->EED_Event_Single->{$template_part} = $priority;
224
-                do_action("AHEE__EED_Event_Single__update_event_single_order__$template_part", $priority);
225
-            }
226
-            $config_saved = EE_Registry::instance()->CFG->update_espresso_config(false, false);
227
-        }
228
-        if ($config_saved) {
229
-            EE_Error::add_success(esc_html__('Display Order has been successfully updated.', 'event_espresso'));
230
-        } else {
231
-            EE_Error::add_error(
232
-                esc_html__('Display Order was not updated.', 'event_espresso'),
233
-                __FILE__,
234
-                __FUNCTION__,
235
-                __LINE__
236
-            );
237
-        }
238
-        echo wp_json_encode(EE_Error::get_notices(false));
239
-        exit();
240
-    }
241
-
242
-
243
-    /**
244
-     *    run - initial module setup
245
-     *
246
-     * @access    public
247
-     * @param WP $WP
248
-     * @return    void
249
-     */
250
-    public function run($WP)
251
-    {
252
-    }
29
+	/**
30
+	 * @return EED_Event_Single_Caff
31
+	 */
32
+	public static function instance()
33
+	{
34
+		return parent::get_instance(__CLASS__);
35
+	}
36
+
37
+
38
+	/**
39
+	 *    set_hooks - for hooking into EE Core, other modules, etc
40
+	 *
41
+	 * @access    public
42
+	 * @return    void
43
+	 */
44
+	public static function set_hooks()
45
+	{
46
+	}
47
+
48
+	/**
49
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
50
+	 *
51
+	 * @access    public
52
+	 * @return    void
53
+	 */
54
+	public static function set_hooks_admin()
55
+	{
56
+		self::setDefinitions();
57
+		add_action(
58
+			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__template_settings',
59
+			array('EED_Event_Single_Caff', 'load_scripts_styles'),
60
+			10
61
+		);
62
+		add_action(
63
+			'AHEE__template_settings__template__before_settings_form',
64
+			array('EED_Event_Single_Caff', 'template_settings_form'),
65
+			10
66
+		);
67
+		add_filter(
68
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
69
+			array('EED_Event_Single_Caff', 'update_template_settings'),
70
+			10,
71
+			2
72
+		);
73
+		// AJAX
74
+		add_action(
75
+			'wp_ajax_espresso_update_event_single_order',
76
+			array('EED_Event_Single_Caff', 'update_event_single_order')
77
+		);
78
+		add_action(
79
+			'wp_ajax_nopriv_espresso_update_event_single_order',
80
+			array('EED_Event_Single_Caff', 'update_event_single_order')
81
+		);
82
+	}
83
+
84
+
85
+	public static function load_scripts_styles()
86
+	{
87
+		add_action('admin_enqueue_scripts', array('EED_Event_Single_Caff', 'enqueue_scripts_styles'), 10);
88
+	}
89
+
90
+
91
+	public static function enqueue_scripts_styles()
92
+	{
93
+		wp_register_style(
94
+			'eed-event-single-sortable',
95
+			EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.css',
96
+			array(),
97
+			EVENT_ESPRESSO_VERSION
98
+		);
99
+		wp_enqueue_style('eed-event-single-sortable');
100
+		wp_register_script(
101
+			'eed-event-single-sortable',
102
+			EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.js',
103
+			array('jquery-ui-sortable'),
104
+			EVENT_ESPRESSO_VERSION,
105
+			true
106
+		);
107
+		wp_enqueue_script('eed-event-single-sortable');
108
+	}
109
+
110
+
111
+	/**
112
+	 * Set constants only if they haven't been set yet.
113
+	 */
114
+	public static function setDefinitions()
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/');
119
+		}
120
+	}
121
+
122
+
123
+	/**
124
+	 *    template_settings_form
125
+	 *
126
+	 * @access    public
127
+	 * @static
128
+	 * @return    void
129
+	 */
130
+	public static function template_settings_form()
131
+	{
132
+		$config = EE_Registry::instance()->CFG->template_settings;
133
+		$config = isset($config->EED_Event_Single) && $config->EED_Event_Single instanceof EE_Event_Single_Config
134
+			? $config->EED_Event_Single : new EE_Event_Single_Config();
135
+		$config->use_sortable_display_order = isset($config->use_sortable_display_order)
136
+			? $config->use_sortable_display_order : false;
137
+		$config = apply_filters('FHEE__EED_Event_Single__template_settings_form__event_list_config', $config);
138
+
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';
144
+		// get template parts
145
+		$template_parts = EED_Event_Single::instance()->initialize_template_parts($config);
146
+		// convert to array so that we can add more properties
147
+		$config = get_object_vars($config);
148
+		$config['event_single_display_order'] = $template_parts->generate_sortable_list_of_template_parts(
149
+			'event-single-sortable-js',
150
+			'',
151
+			'single-sortable-li single-sortable-js'
152
+		);
153
+		EEH_Template::display_template(
154
+			EVENT_SINGLE_CAFF_TEMPLATES_PATH . 'admin-event-single-settings.template.php',
155
+			$config
156
+		);
157
+	}
158
+
159
+
160
+	/**
161
+	 * update_template_settings
162
+	 *
163
+	 * @param EE_Template_Config $CFG
164
+	 * @param array              $REQ
165
+	 * @return EE_Template_Config
166
+	 */
167
+	public static function update_template_settings(EE_Template_Config $CFG, $REQ)
168
+	{
169
+		if (! $CFG->EED_Event_Single instanceof EE_Event_Single_Config) {
170
+			$CFG->EED_Event_Single = new EE_Event_Single_Config();
171
+		}
172
+		$display_order_event = $CFG->EED_Event_Single->display_order_event !== null
173
+			? $CFG->EED_Event_Single->display_order_event
174
+			: EED_Event_Single::EVENT_DETAILS_PRIORITY;
175
+		$display_order_datetimes = $CFG->EED_Event_Single->display_order_datetimes !== null
176
+			? $CFG->EED_Event_Single->display_order_datetimes
177
+			: EED_Event_Single::EVENT_DATETIMES_PRIORITY;
178
+		$display_order_tickets = $CFG->EED_Event_Single->display_order_tickets !== null
179
+			? $CFG->EED_Event_Single->display_order_tickets
180
+			: EED_Event_Single::EVENT_TICKETS_PRIORITY;
181
+		$display_order_venue = $CFG->EED_Event_Single->display_order_venue !== null
182
+			? $CFG->EED_Event_Single->display_order_venue
183
+			: EED_Event_Single::EVENT_VENUES_PRIORITY;
184
+		$CFG->EED_Event_Single = new EE_Event_Single_Config();
185
+		$CFG->EED_Event_Single->display_status_banner_single = ! empty($REQ['display_status_banner_single'])
186
+															   && $REQ['display_status_banner_single'];
187
+		$CFG->EED_Event_Single->display_venue = ! empty($REQ['display_venue']) && $REQ['display_venue'];
188
+		$CFG->EED_Event_Single->use_sortable_display_order = ! empty($REQ['EED_Events_Single_use_sortable_display_order'])
189
+			? absint($REQ['EED_Events_Single_use_sortable_display_order'])
190
+			: 0;
191
+		$CFG->EED_Event_Single->display_order_event = $CFG->EED_Event_Single->use_sortable_display_order
192
+			? $display_order_event
193
+			: EED_Event_Single::EVENT_DETAILS_PRIORITY;
194
+		$CFG->EED_Event_Single->display_order_datetimes = $CFG->EED_Event_Single->use_sortable_display_order
195
+			? $display_order_datetimes
196
+			: EED_Event_Single::EVENT_DATETIMES_PRIORITY;
197
+		$CFG->EED_Event_Single->display_order_tickets = $CFG->EED_Event_Single->use_sortable_display_order
198
+			? $display_order_tickets
199
+			: EED_Event_Single::EVENT_TICKETS_PRIORITY;
200
+		$CFG->EED_Event_Single->display_order_venue = $CFG->EED_Event_Single->use_sortable_display_order
201
+			? $display_order_venue
202
+			: EED_Event_Single::EVENT_VENUES_PRIORITY;
203
+		do_action('AHEE__EED_Event_Single__update_template_settings__after_update', $CFG, $REQ);
204
+		return $CFG;
205
+	}
206
+
207
+
208
+	/**
209
+	 * update_event_single_order
210
+	 *
211
+	 * @access    public
212
+	 * @return    void
213
+	 */
214
+	public static function update_event_single_order()
215
+	{
216
+		$config_saved = false;
217
+		$template_parts = EED_Event_Single_Caff::getRequest()->getRequestParam('elements');
218
+		if (! empty($template_parts)) {
219
+			$template_parts = explode(',', trim($template_parts, ','));
220
+			foreach ($template_parts as $key => $template_part) {
221
+				$template_part = "display_order_$template_part";
222
+				$priority = ($key * 10) + EED_Event_Single::EVENT_DETAILS_PRIORITY;
223
+				EE_Registry::instance()->CFG->template_settings->EED_Event_Single->{$template_part} = $priority;
224
+				do_action("AHEE__EED_Event_Single__update_event_single_order__$template_part", $priority);
225
+			}
226
+			$config_saved = EE_Registry::instance()->CFG->update_espresso_config(false, false);
227
+		}
228
+		if ($config_saved) {
229
+			EE_Error::add_success(esc_html__('Display Order has been successfully updated.', 'event_espresso'));
230
+		} else {
231
+			EE_Error::add_error(
232
+				esc_html__('Display Order was not updated.', 'event_espresso'),
233
+				__FILE__,
234
+				__FUNCTION__,
235
+				__LINE__
236
+			);
237
+		}
238
+		echo wp_json_encode(EE_Error::get_notices(false));
239
+		exit();
240
+	}
241
+
242
+
243
+	/**
244
+	 *    run - initial module setup
245
+	 *
246
+	 * @access    public
247
+	 * @param WP $WP
248
+	 * @return    void
249
+	 */
250
+	public function run($WP)
251
+	{
252
+	}
253 253
 }
Please login to merge, or discard this patch.
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.
caffeinated/modules/events_archive_caff/EED_Events_Archive_Caff.module.php 2 patches
Indentation   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -13,262 +13,262 @@
 block discarded – undo
13 13
 class EED_Events_Archive_Caff extends EED_Events_Archive
14 14
 {
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
-        // grab general settings admin page and remove the existing hook callback
102
-        $gen_set_admin = EE_Registry::instance()->LIB->EE_Admin_Page_Loader->get_admin_page_object('general_settings');
103
-        if ($gen_set_admin instanceof General_Settings_Admin_Page) {
104
-            remove_action(
105
-                'AHEE__template_settings__template__before_settings_form',
106
-                array($gen_set_admin, 'template_settings_caff_features'),
107
-                100
108
-            );
109
-        }
110
-        // first just grab the template settings
111
-        $config = EE_Registry::instance()->CFG->template_settings;
112
-        // then if the Event Archive config is valid, use that, else create a new one
113
-        $config = $config instanceof EE_Template_Config
114
-                  && $config->EED_Events_Archive instanceof EE_Events_Archive_Config
115
-            ? $config->EED_Events_Archive
116
-            : new EE_Events_Archive_Config();
117
-        $config = apply_filters(
118
-            'FHEE__EED_Events_Archive__template_settings_form__event_list_config',
119
-            $config
120
-        );
121
-        $config->display_status_banner = isset($config->display_status_banner)
122
-            ? $config->display_status_banner
123
-            : 0;
124
-        $config->display_description = isset($config->display_description)
125
-            ? $config->display_description
126
-            : 1;
127
-        $config->display_ticket_selector = isset($config->display_ticket_selector)
128
-            ? $config->display_ticket_selector
129
-            : 0;
130
-        $config->display_datetimes = isset($config->display_datetimes)
131
-            ? $config->display_datetimes
132
-            : 1;
133
-        $config->display_venue = isset($config->display_venue)
134
-            ? $config->display_venue
135
-            : 0;
136
-        $config->display_expired_events = isset($config->display_expired_events)
137
-            ? $config->display_expired_events
138
-            : 0;
139
-        // display order options
140
-        $config->use_sortable_display_order = isset($config->use_sortable_display_order)
141
-            ? $config->use_sortable_display_order
142
-            : false;
143
-        $config->display_order_tickets = isset($config->display_order_tickets)
144
-            ? $config->display_order_tickets
145
-            : 120;
146
-        $config->display_order_datetimes = isset($config->display_order_datetimes)
147
-            ? $config->display_order_datetimes
148
-            : 110;
149
-        $config->display_order_event = isset($config->display_order_event)
150
-            ? $config->display_order_event
151
-            : 100;
152
-        $config->display_order_venue = isset($config->display_order_venue)
153
-            ? $config->display_order_venue
154
-            : 130;
155
-        // get template parts
156
-        $template_parts = EED_Events_Archive::instance()->initialize_template_parts($config);
157
-        // convert to array so that we can add more properties
158
-        $config = get_object_vars($config);
159
-        $config['event_archive_display_order'] = $template_parts->generate_sortable_list_of_template_parts(
160
-            'event-archive-sortable-js',
161
-            '',
162
-            'archive-sortable-li archive-sortable-js'
163
-        );
164
-        EEH_Template::display_template(
165
-            EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
166
-            $config
167
-        );
168
-    }
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
+		// grab general settings admin page and remove the existing hook callback
102
+		$gen_set_admin = EE_Registry::instance()->LIB->EE_Admin_Page_Loader->get_admin_page_object('general_settings');
103
+		if ($gen_set_admin instanceof General_Settings_Admin_Page) {
104
+			remove_action(
105
+				'AHEE__template_settings__template__before_settings_form',
106
+				array($gen_set_admin, 'template_settings_caff_features'),
107
+				100
108
+			);
109
+		}
110
+		// first just grab the template settings
111
+		$config = EE_Registry::instance()->CFG->template_settings;
112
+		// then if the Event Archive config is valid, use that, else create a new one
113
+		$config = $config instanceof EE_Template_Config
114
+				  && $config->EED_Events_Archive instanceof EE_Events_Archive_Config
115
+			? $config->EED_Events_Archive
116
+			: new EE_Events_Archive_Config();
117
+		$config = apply_filters(
118
+			'FHEE__EED_Events_Archive__template_settings_form__event_list_config',
119
+			$config
120
+		);
121
+		$config->display_status_banner = isset($config->display_status_banner)
122
+			? $config->display_status_banner
123
+			: 0;
124
+		$config->display_description = isset($config->display_description)
125
+			? $config->display_description
126
+			: 1;
127
+		$config->display_ticket_selector = isset($config->display_ticket_selector)
128
+			? $config->display_ticket_selector
129
+			: 0;
130
+		$config->display_datetimes = isset($config->display_datetimes)
131
+			? $config->display_datetimes
132
+			: 1;
133
+		$config->display_venue = isset($config->display_venue)
134
+			? $config->display_venue
135
+			: 0;
136
+		$config->display_expired_events = isset($config->display_expired_events)
137
+			? $config->display_expired_events
138
+			: 0;
139
+		// display order options
140
+		$config->use_sortable_display_order = isset($config->use_sortable_display_order)
141
+			? $config->use_sortable_display_order
142
+			: false;
143
+		$config->display_order_tickets = isset($config->display_order_tickets)
144
+			? $config->display_order_tickets
145
+			: 120;
146
+		$config->display_order_datetimes = isset($config->display_order_datetimes)
147
+			? $config->display_order_datetimes
148
+			: 110;
149
+		$config->display_order_event = isset($config->display_order_event)
150
+			? $config->display_order_event
151
+			: 100;
152
+		$config->display_order_venue = isset($config->display_order_venue)
153
+			? $config->display_order_venue
154
+			: 130;
155
+		// get template parts
156
+		$template_parts = EED_Events_Archive::instance()->initialize_template_parts($config);
157
+		// convert to array so that we can add more properties
158
+		$config = get_object_vars($config);
159
+		$config['event_archive_display_order'] = $template_parts->generate_sortable_list_of_template_parts(
160
+			'event-archive-sortable-js',
161
+			'',
162
+			'archive-sortable-li archive-sortable-js'
163
+		);
164
+		EEH_Template::display_template(
165
+			EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
166
+			$config
167
+		);
168
+	}
169 169
 
170 170
 
171
-    /**
172
-     * @param EE_Template_Config $CFG
173
-     * @param array              $REQ
174
-     * @return EE_Template_Config
175
-     */
176
-    public static function update_template_settings($CFG, $REQ)
177
-    {
178
-        /** @var EE_Events_Archive_Config $config */
179
-        $config = $CFG->EED_Events_Archive instanceof EE_Events_Archive_Config
180
-            ? $CFG->EED_Events_Archive
181
-            : new EE_Events_Archive_Config();
182
-        // unless we are resetting the config...
183
-        if (
184
-            ! isset($REQ['EED_Events_Archive_reset_event_list_settings'])
185
-            || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1
186
-        ) {
187
-            $config->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner'])
188
-                ? absint($REQ['EED_Events_Archive_display_status_banner'])
189
-                : 0;
190
-            $config->display_description = isset($REQ['EED_Events_Archive_display_description'])
191
-                ? absint($REQ['EED_Events_Archive_display_description'])
192
-                : 1;
193
-            $config->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector'])
194
-                ? absint($REQ['EED_Events_Archive_display_ticket_selector'])
195
-                : 0;
196
-            $config->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes'])
197
-                ? absint($REQ['EED_Events_Archive_display_datetimes'])
198
-                : 1;
199
-            $config->display_venue = isset($REQ['EED_Events_Archive_display_venue'])
200
-                ? absint($REQ['EED_Events_Archive_display_venue'])
201
-                : 0;
202
-            $config->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events'])
203
-                ? absint($REQ['EED_Events_Archive_display_expired_events'])
204
-                : 0;
205
-            $config->use_sortable_display_order = isset($REQ['EED_Events_Archive_use_sortable_display_order'])
206
-                ? absint($REQ['EED_Events_Archive_use_sortable_display_order'])
207
-                : 0;
208
-            $config->display_order_event = $config->display_order_event !== null
209
-                                           && $config->use_sortable_display_order
210
-                ? $config->display_order_event
211
-                : EED_Events_Archive::EVENT_DETAILS_PRIORITY;
212
-            $config->display_order_datetimes = $config->display_order_datetimes !== null
213
-                                               && $config->use_sortable_display_order
214
-                ? $config->display_order_datetimes
215
-                : EED_Events_Archive::EVENT_DATETIMES_PRIORITY;
216
-            $config->display_order_tickets = $config->display_order_tickets !== null
217
-                                             && $config->use_sortable_display_order
218
-                ? $config->display_order_tickets
219
-                : EED_Events_Archive::EVENT_TICKETS_PRIORITY;
220
-            $config->display_order_venue = $config->display_order_venue !== null
221
-                                           && $config->use_sortable_display_order
222
-                ? $config->display_order_venue
223
-                : EED_Events_Archive::EVENT_VENUES_PRIORITY;
224
-        }
225
-        $CFG->EED_Events_Archive = $config;
226
-        do_action('AHEE__EED_Events_Archive__update_template_settings__after_update', $CFG, $REQ);
227
-        return $CFG;
228
-    }
171
+	/**
172
+	 * @param EE_Template_Config $CFG
173
+	 * @param array              $REQ
174
+	 * @return EE_Template_Config
175
+	 */
176
+	public static function update_template_settings($CFG, $REQ)
177
+	{
178
+		/** @var EE_Events_Archive_Config $config */
179
+		$config = $CFG->EED_Events_Archive instanceof EE_Events_Archive_Config
180
+			? $CFG->EED_Events_Archive
181
+			: new EE_Events_Archive_Config();
182
+		// unless we are resetting the config...
183
+		if (
184
+			! isset($REQ['EED_Events_Archive_reset_event_list_settings'])
185
+			|| absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1
186
+		) {
187
+			$config->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner'])
188
+				? absint($REQ['EED_Events_Archive_display_status_banner'])
189
+				: 0;
190
+			$config->display_description = isset($REQ['EED_Events_Archive_display_description'])
191
+				? absint($REQ['EED_Events_Archive_display_description'])
192
+				: 1;
193
+			$config->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector'])
194
+				? absint($REQ['EED_Events_Archive_display_ticket_selector'])
195
+				: 0;
196
+			$config->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes'])
197
+				? absint($REQ['EED_Events_Archive_display_datetimes'])
198
+				: 1;
199
+			$config->display_venue = isset($REQ['EED_Events_Archive_display_venue'])
200
+				? absint($REQ['EED_Events_Archive_display_venue'])
201
+				: 0;
202
+			$config->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events'])
203
+				? absint($REQ['EED_Events_Archive_display_expired_events'])
204
+				: 0;
205
+			$config->use_sortable_display_order = isset($REQ['EED_Events_Archive_use_sortable_display_order'])
206
+				? absint($REQ['EED_Events_Archive_use_sortable_display_order'])
207
+				: 0;
208
+			$config->display_order_event = $config->display_order_event !== null
209
+										   && $config->use_sortable_display_order
210
+				? $config->display_order_event
211
+				: EED_Events_Archive::EVENT_DETAILS_PRIORITY;
212
+			$config->display_order_datetimes = $config->display_order_datetimes !== null
213
+											   && $config->use_sortable_display_order
214
+				? $config->display_order_datetimes
215
+				: EED_Events_Archive::EVENT_DATETIMES_PRIORITY;
216
+			$config->display_order_tickets = $config->display_order_tickets !== null
217
+											 && $config->use_sortable_display_order
218
+				? $config->display_order_tickets
219
+				: EED_Events_Archive::EVENT_TICKETS_PRIORITY;
220
+			$config->display_order_venue = $config->display_order_venue !== null
221
+										   && $config->use_sortable_display_order
222
+				? $config->display_order_venue
223
+				: EED_Events_Archive::EVENT_VENUES_PRIORITY;
224
+		}
225
+		$CFG->EED_Events_Archive = $config;
226
+		do_action('AHEE__EED_Events_Archive__update_template_settings__after_update', $CFG, $REQ);
227
+		return $CFG;
228
+	}
229 229
 
230 230
 
231
-    /**
232
-     * @return void
233
-     * @throws InvalidArgumentException
234
-     * @throws InvalidDataTypeException
235
-     * @throws InvalidInterfaceException
236
-     */
237
-    public static function update_event_archive_order()
238
-    {
239
-        /** @var EE_Config $config */
240
-        $config = EE_Registry::instance()->CFG;
241
-        $config_saved = false;
242
-        $template_parts = EED_Events_Archive_Caff::getRequest()->getRequestParam('elements');
243
-        if (! empty($template_parts)) {
244
-            $template_parts = explode(',', trim($template_parts, ','));
245
-            foreach ($template_parts as $key => $template_part) {
246
-                $template_part = "display_order_$template_part";
247
-                $priority = ($key * 10) + EED_Events_Archive::EVENT_DETAILS_PRIORITY;
248
-                if (
249
-                    $config->template_settings->EED_Events_Archive instanceof EE_Events_Archive_Config
250
-                    && property_exists(
251
-                        $config->template_settings->EED_Events_Archive,
252
-                        $template_part
253
-                    )
254
-                ) {
255
-                    $config->template_settings->EED_Events_Archive->{$template_part} = $priority;
256
-                }
257
-                do_action("AHEE__EED_Events_Archive__update_event_archive_order__$template_part", $priority);
258
-            }
259
-            $config_saved = $config->update_espresso_config(false, false);
260
-        }
261
-        if ($config_saved) {
262
-            EE_Error::add_success(esc_html__('Display Order has been successfully updated.', 'event_espresso'));
263
-        } else {
264
-            EE_Error::add_error(
265
-                esc_html__('Display Order was not updated.', 'event_espresso'),
266
-                __FILE__,
267
-                __FUNCTION__,
268
-                __LINE__
269
-            );
270
-        }
271
-        echo wp_json_encode(EE_Error::get_notices(false));
272
-        exit();
273
-    }
231
+	/**
232
+	 * @return void
233
+	 * @throws InvalidArgumentException
234
+	 * @throws InvalidDataTypeException
235
+	 * @throws InvalidInterfaceException
236
+	 */
237
+	public static function update_event_archive_order()
238
+	{
239
+		/** @var EE_Config $config */
240
+		$config = EE_Registry::instance()->CFG;
241
+		$config_saved = false;
242
+		$template_parts = EED_Events_Archive_Caff::getRequest()->getRequestParam('elements');
243
+		if (! empty($template_parts)) {
244
+			$template_parts = explode(',', trim($template_parts, ','));
245
+			foreach ($template_parts as $key => $template_part) {
246
+				$template_part = "display_order_$template_part";
247
+				$priority = ($key * 10) + EED_Events_Archive::EVENT_DETAILS_PRIORITY;
248
+				if (
249
+					$config->template_settings->EED_Events_Archive instanceof EE_Events_Archive_Config
250
+					&& property_exists(
251
+						$config->template_settings->EED_Events_Archive,
252
+						$template_part
253
+					)
254
+				) {
255
+					$config->template_settings->EED_Events_Archive->{$template_part} = $priority;
256
+				}
257
+				do_action("AHEE__EED_Events_Archive__update_event_archive_order__$template_part", $priority);
258
+			}
259
+			$config_saved = $config->update_espresso_config(false, false);
260
+		}
261
+		if ($config_saved) {
262
+			EE_Error::add_success(esc_html__('Display Order has been successfully updated.', 'event_espresso'));
263
+		} else {
264
+			EE_Error::add_error(
265
+				esc_html__('Display Order was not updated.', 'event_espresso'),
266
+				__FILE__,
267
+				__FUNCTION__,
268
+				__LINE__
269
+			);
270
+		}
271
+		echo wp_json_encode(EE_Error::get_notices(false));
272
+		exit();
273
+	}
274 274
 }
Please login to merge, or discard this patch.
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.
caffeinated/modules/recaptcha/EED_Recaptcha.module.php 2 patches
Indentation   +378 added lines, -378 removed lines patch added patch discarded remove patch
@@ -18,382 +18,382 @@
 block discarded – undo
18 18
 class EED_Recaptcha extends EED_Module
19 19
 {
20 20
 
21
-    /**
22
-     * @var EE_Registration_Config $config
23
-     */
24
-    private static $config;
25
-
26
-    /**
27
-     * @type bool $_not_a_robot
28
-     */
29
-    private static $_not_a_robot;
30
-
31
-    /**
32
-     * @type string $_recaptcha_response
33
-     */
34
-    private static $_recaptcha_response;
35
-
36
-
37
-    /**
38
-     * @return EED_Module|EED_Recaptcha
39
-     */
40
-    public static function instance()
41
-    {
42
-        return parent::get_instance(__CLASS__);
43
-    }
44
-
45
-
46
-    /**
47
-     * set_hooks - for hooking into EE Core, other modules, etc
48
-     *
49
-     * @return void
50
-     * @throws InvalidArgumentException
51
-     * @throws InvalidInterfaceException
52
-     * @throws InvalidDataTypeException
53
-     */
54
-    public static function set_hooks()
55
-    {
56
-        EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration;
57
-        // use_captcha ?
58
-        if (
59
-            EED_Recaptcha::useRecaptcha()
60
-            && EED_Recaptcha::notPaymentOptionsRevisit()
61
-        ) {
62
-            EED_Recaptcha::set_definitions();
63
-            EED_Recaptcha::enqueue_styles_and_scripts();
64
-            add_action('wp', array('EED_Recaptcha', 'set_late_hooks'), 1, 0);
65
-            add_action(
66
-                'AHEE__before_spco_whats_next_buttons',
67
-                array('EED_Recaptcha', 'display_recaptcha'),
68
-                10,
69
-                0
70
-            );
71
-            add_filter(
72
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
73
-                array('EED_Recaptcha', 'not_a_robot')
74
-            );
75
-            add_filter(
76
-                'FHEE__EE_SPCO_Reg_Step__set_completed___completed',
77
-                array('EED_Recaptcha', 'not_a_robot')
78
-            );
79
-            add_filter(
80
-                'FHEE__EE_SPCO_JSON_Response___toString__JSON_response',
81
-                array('EED_Recaptcha', 'recaptcha_response')
82
-            );
83
-            add_filter(
84
-                'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
85
-                array('EED_Recaptcha', 'bypass_recaptcha_for_spco_load_payment_method')
86
-            );
87
-        }
88
-    }
89
-
90
-
91
-    /**
92
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
93
-     *
94
-     * @return void
95
-     * @throws InvalidArgumentException
96
-     * @throws InvalidInterfaceException
97
-     * @throws InvalidDataTypeException
98
-     */
99
-    public static function set_hooks_admin()
100
-    {
101
-        EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration;
102
-        EED_Recaptcha::set_definitions();
103
-        // use_captcha ?
104
-        if (
105
-            EED_Recaptcha::useRecaptcha()
106
-            && EED_Recaptcha::notPaymentOptionsRevisit()
107
-            && EED_Recaptcha::getRequest()->getRequestParam('step', '') !== ''
108
-        ) {
109
-            EED_Recaptcha::enqueue_styles_and_scripts();
110
-            add_filter(
111
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
112
-                array('EED_Recaptcha', 'not_a_robot')
113
-            );
114
-            add_filter(
115
-                'FHEE__EE_SPCO_Reg_Step__set_completed___completed',
116
-                array('EED_Recaptcha', 'not_a_robot')
117
-            );
118
-            add_filter(
119
-                'FHEE__EE_SPCO_JSON_Response___toString__JSON_response',
120
-                array('EED_Recaptcha', 'recaptcha_response')
121
-            );
122
-        }
123
-    }
124
-
125
-
126
-    /**
127
-     * @return void
128
-     */
129
-    public static function set_definitions()
130
-    {
131
-        if (is_user_logged_in()) {
132
-            EED_Recaptcha::$_not_a_robot = true;
133
-        }
134
-        define(
135
-            'RECAPTCHA_BASE_PATH',
136
-            rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
137
-        );
138
-        define('RECAPTCHA_BASE_URL', plugin_dir_url(__FILE__));
139
-    }
140
-
141
-
142
-    /**
143
-     * @return void
144
-     */
145
-    public static function set_late_hooks()
146
-    {
147
-        add_filter(
148
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
149
-            array('EED_Recaptcha', 'not_a_robot')
150
-        );
151
-    }
152
-
153
-
154
-    /**
155
-     * @return boolean
156
-     */
157
-    public static function useRecaptcha()
158
-    {
159
-        return EED_Recaptcha::$config->use_captcha
160
-               && EED_Recaptcha::$config->recaptcha_theme !== 'invisible';
161
-    }
162
-
163
-
164
-    /**
165
-     * @return boolean
166
-     * @throws InvalidArgumentException
167
-     * @throws InvalidInterfaceException
168
-     * @throws InvalidDataTypeException
169
-     */
170
-    public static function notPaymentOptionsRevisit()
171
-    {
172
-        $request = EED_Recaptcha::getRequest();
173
-        return ! (
174
-            $request->getRequestParam('step', '') === 'payment_options'
175
-            && $request->getRequestParam('revisit', false, 'bool') === true
176
-        );
177
-    }
178
-
179
-
180
-    /**
181
-     * @return void
182
-     * @throws InvalidArgumentException
183
-     * @throws InvalidInterfaceException
184
-     * @throws InvalidDataTypeException
185
-     */
186
-    public static function enqueue_styles_and_scripts()
187
-    {
188
-        wp_register_script(
189
-            'espresso_recaptcha',
190
-            RECAPTCHA_BASE_URL . 'scripts/espresso_recaptcha.js',
191
-            array('single_page_checkout'),
192
-            EVENT_ESPRESSO_VERSION,
193
-            true
194
-        );
195
-        wp_register_script(
196
-            'google_recaptcha',
197
-            'https://www.google.com/recaptcha/api.js?hl=' . EED_Recaptcha::$config->recaptcha_language,
198
-            array('espresso_recaptcha'),
199
-            EVENT_ESPRESSO_VERSION,
200
-            true
201
-        );
202
-        EE_Registry::$i18n_js_strings['no_SPCO_error'] = __(
203
-            'It appears the Single Page Checkout javascript was not loaded properly! Please refresh the page and try again or contact support.',
204
-            'event_espresso'
205
-        );
206
-        EE_Registry::$i18n_js_strings['no_recaptcha_error'] = __(
207
-            'There appears to be a problem with the reCAPTCHA configuration! Please check the admin settings or contact support.',
208
-            'event_espresso'
209
-        );
210
-        EE_Registry::$i18n_js_strings['recaptcha_fail'] = __(
211
-            'Please complete the anti-spam test before proceeding.',
212
-            'event_espresso'
213
-        );
214
-    }
215
-
216
-
217
-    /**
218
-     * @param WP $WP
219
-     */
220
-    public function run($WP)
221
-    {
222
-    }
223
-
224
-
225
-    /**
226
-     * @return boolean
227
-     * @throws InvalidArgumentException
228
-     * @throws InvalidInterfaceException
229
-     * @throws InvalidDataTypeException
230
-     */
231
-    public static function not_a_robot()
232
-    {
233
-        return is_bool(EED_Recaptcha::$_not_a_robot)
234
-            ? EED_Recaptcha::$_not_a_robot
235
-            : EED_Recaptcha::recaptcha_passed();
236
-    }
237
-
238
-
239
-    /**
240
-     * @return void
241
-     * @throws DomainException
242
-     * @throws InvalidArgumentException
243
-     * @throws InvalidInterfaceException
244
-     * @throws InvalidDataTypeException
245
-     */
246
-    public static function display_recaptcha()
247
-    {
248
-        // logged in means you have already passed a turing test of sorts
249
-        if (is_user_logged_in()) {
250
-            return;
251
-        }
252
-        // don't display if not using recaptcha or user is logged in
253
-        if (EED_Recaptcha::useRecaptcha() && ! EED_Recaptcha::$_not_a_robot) {
254
-            // only display if they have NOT passed the test yet
255
-            EEH_Template::display_template(
256
-                RECAPTCHA_BASE_PATH . '/templates/recaptcha.template.php',
257
-                array(
258
-                    'recaptcha_publickey' => EED_Recaptcha::$config->recaptcha_publickey,
259
-                    'recaptcha_theme'     => EED_Recaptcha::$config->recaptcha_theme,
260
-                    'recaptcha_type'      => EED_Recaptcha::$config->recaptcha_type,
261
-                )
262
-            );
263
-            wp_enqueue_script('google_recaptcha');
264
-        }
265
-    }
266
-
267
-
268
-    /**
269
-     * @return array
270
-     * @throws InvalidArgumentException
271
-     * @throws InvalidInterfaceException
272
-     * @throws InvalidDataTypeException
273
-     */
274
-    public static function bypass_recaptcha_for_spco_load_payment_method()
275
-    {
276
-        return array(
277
-            'EESID'  => EE_Registry::instance()->SSN->id(),
278
-            'step'   => 'payment_options',
279
-            'action' => 'switch_spco_billing_form',
280
-        );
281
-    }
282
-
283
-
284
-    /**
285
-     * @return boolean
286
-     * @throws InvalidArgumentException
287
-     * @throws InvalidInterfaceException
288
-     * @throws InvalidDataTypeException
289
-     */
290
-    public static function recaptcha_passed()
291
-    {
292
-        // logged in means you have already passed a turing test of sorts
293
-        if (is_user_logged_in() || EED_Recaptcha::_bypass_recaptcha()) {
294
-            return true;
295
-        }
296
-        // was test already passed?
297
-        $recaptcha_passed = EE_Registry::instance()->SSN->get_session_data('recaptcha_passed');
298
-        $recaptcha_passed = filter_var($recaptcha_passed, FILTER_VALIDATE_BOOLEAN);
299
-        // verify recaptcha
300
-        EED_Recaptcha::_get_recaptcha_response();
301
-        if (! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) {
302
-            $recaptcha_passed = EED_Recaptcha::_process_recaptcha_response();
303
-            EE_Registry::instance()->SSN->set_session_data(array('recaptcha_passed' => $recaptcha_passed));
304
-        }
305
-        EED_Recaptcha::$_not_a_robot = $recaptcha_passed;
306
-        return $recaptcha_passed;
307
-    }
308
-
309
-
310
-    /**
311
-     * @param array $recaptcha_response
312
-     * @return array
313
-     */
314
-    public static function recaptcha_response($recaptcha_response = array())
315
-    {
316
-        if (EED_Recaptcha::_bypass_recaptcha()) {
317
-            $recaptcha_response['bypass_recaptcha'] = true;
318
-            $recaptcha_response['recaptcha_passed'] = true;
319
-        } else {
320
-            $recaptcha_response['recaptcha_passed'] = EED_Recaptcha::$_not_a_robot;
321
-        }
322
-        return $recaptcha_response;
323
-    }
324
-
325
-
326
-    /**
327
-     * @return boolean
328
-     */
329
-    private static function _bypass_recaptcha()
330
-    {
331
-        // an array of key value pairs that must match exactly with the incoming request,
332
-        // in order to bypass recaptcha for the current request ONLY
333
-        $bypass_request_params_array = (array) apply_filters(
334
-            'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
335
-            array()
336
-        );
337
-        // does $bypass_request_params_array have any values ?
338
-        if (empty($bypass_request_params_array)) {
339
-            return false;
340
-        }
341
-        $request = EED_Recaptcha::getRequest();
342
-        // initially set bypass to TRUE
343
-        $bypass_recaptcha = true;
344
-        foreach ($bypass_request_params_array as $key => $value) {
345
-            // if $key is not found or value doesn't match exactly, then toggle bypass to FALSE,
346
-            // otherwise carry over it's value. This way, one missed setting results in no bypass
347
-            $bypass_recaptcha = $request->getRequestParam($key) === $value
348
-                ? $bypass_recaptcha
349
-                : false;
350
-        }
351
-        return $bypass_recaptcha;
352
-    }
353
-
354
-
355
-    /**
356
-     * @return void
357
-     * @throws InvalidArgumentException
358
-     * @throws InvalidInterfaceException
359
-     * @throws InvalidDataTypeException
360
-     */
361
-    private static function _get_recaptcha_response()
362
-    {
363
-        EED_Recaptcha::$_recaptcha_response = EED_Recaptcha::getRequest()->getRequestParam(
364
-            'g-recaptcha-response'
365
-        );
366
-    }
367
-
368
-
369
-    /**
370
-     * @return boolean
371
-     * @throws InvalidArgumentException
372
-     * @throws InvalidInterfaceException
373
-     * @throws InvalidDataTypeException
374
-     */
375
-    private static function _process_recaptcha_response()
376
-    {
377
-        // verify library is loaded
378
-        if (! class_exists('\ReCaptcha\ReCaptcha')) {
379
-            require_once RECAPTCHA_BASE_PATH . '/autoload.php';
380
-        }
381
-        // The response from reCAPTCHA
382
-        EED_Recaptcha::_get_recaptcha_response();
383
-        $recaptcha_response = EED_Recaptcha::$_recaptcha_response;
384
-        // Was there a reCAPTCHA response?
385
-        if ($recaptcha_response) {
386
-            // if allow_url_fopen is Off, then set a different request method
387
-            $request_method = ! ini_get('allow_url_fopen') ? new SocketPost() : null;
388
-            $recaptcha = new ReCaptcha(
389
-                EED_Recaptcha::$config->recaptcha_privatekey,
390
-                $request_method
391
-            );
392
-            $recaptcha_response = $recaptcha->verify(
393
-                EED_Recaptcha::$_recaptcha_response,
394
-                EED_Recaptcha::getRequest()->getServerParam('REMOTE_ADDR')
395
-            );
396
-        }
397
-        return $recaptcha_response instanceof Response && $recaptcha_response->isSuccess();
398
-    }
21
+	/**
22
+	 * @var EE_Registration_Config $config
23
+	 */
24
+	private static $config;
25
+
26
+	/**
27
+	 * @type bool $_not_a_robot
28
+	 */
29
+	private static $_not_a_robot;
30
+
31
+	/**
32
+	 * @type string $_recaptcha_response
33
+	 */
34
+	private static $_recaptcha_response;
35
+
36
+
37
+	/**
38
+	 * @return EED_Module|EED_Recaptcha
39
+	 */
40
+	public static function instance()
41
+	{
42
+		return parent::get_instance(__CLASS__);
43
+	}
44
+
45
+
46
+	/**
47
+	 * set_hooks - for hooking into EE Core, other modules, etc
48
+	 *
49
+	 * @return void
50
+	 * @throws InvalidArgumentException
51
+	 * @throws InvalidInterfaceException
52
+	 * @throws InvalidDataTypeException
53
+	 */
54
+	public static function set_hooks()
55
+	{
56
+		EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration;
57
+		// use_captcha ?
58
+		if (
59
+			EED_Recaptcha::useRecaptcha()
60
+			&& EED_Recaptcha::notPaymentOptionsRevisit()
61
+		) {
62
+			EED_Recaptcha::set_definitions();
63
+			EED_Recaptcha::enqueue_styles_and_scripts();
64
+			add_action('wp', array('EED_Recaptcha', 'set_late_hooks'), 1, 0);
65
+			add_action(
66
+				'AHEE__before_spco_whats_next_buttons',
67
+				array('EED_Recaptcha', 'display_recaptcha'),
68
+				10,
69
+				0
70
+			);
71
+			add_filter(
72
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
73
+				array('EED_Recaptcha', 'not_a_robot')
74
+			);
75
+			add_filter(
76
+				'FHEE__EE_SPCO_Reg_Step__set_completed___completed',
77
+				array('EED_Recaptcha', 'not_a_robot')
78
+			);
79
+			add_filter(
80
+				'FHEE__EE_SPCO_JSON_Response___toString__JSON_response',
81
+				array('EED_Recaptcha', 'recaptcha_response')
82
+			);
83
+			add_filter(
84
+				'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
85
+				array('EED_Recaptcha', 'bypass_recaptcha_for_spco_load_payment_method')
86
+			);
87
+		}
88
+	}
89
+
90
+
91
+	/**
92
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
93
+	 *
94
+	 * @return void
95
+	 * @throws InvalidArgumentException
96
+	 * @throws InvalidInterfaceException
97
+	 * @throws InvalidDataTypeException
98
+	 */
99
+	public static function set_hooks_admin()
100
+	{
101
+		EED_Recaptcha::$config = EE_Registry::instance()->CFG->registration;
102
+		EED_Recaptcha::set_definitions();
103
+		// use_captcha ?
104
+		if (
105
+			EED_Recaptcha::useRecaptcha()
106
+			&& EED_Recaptcha::notPaymentOptionsRevisit()
107
+			&& EED_Recaptcha::getRequest()->getRequestParam('step', '') !== ''
108
+		) {
109
+			EED_Recaptcha::enqueue_styles_and_scripts();
110
+			add_filter(
111
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
112
+				array('EED_Recaptcha', 'not_a_robot')
113
+			);
114
+			add_filter(
115
+				'FHEE__EE_SPCO_Reg_Step__set_completed___completed',
116
+				array('EED_Recaptcha', 'not_a_robot')
117
+			);
118
+			add_filter(
119
+				'FHEE__EE_SPCO_JSON_Response___toString__JSON_response',
120
+				array('EED_Recaptcha', 'recaptcha_response')
121
+			);
122
+		}
123
+	}
124
+
125
+
126
+	/**
127
+	 * @return void
128
+	 */
129
+	public static function set_definitions()
130
+	{
131
+		if (is_user_logged_in()) {
132
+			EED_Recaptcha::$_not_a_robot = true;
133
+		}
134
+		define(
135
+			'RECAPTCHA_BASE_PATH',
136
+			rtrim(str_replace(array('\\', '/'), '/', plugin_dir_path(__FILE__)), '/') . '/'
137
+		);
138
+		define('RECAPTCHA_BASE_URL', plugin_dir_url(__FILE__));
139
+	}
140
+
141
+
142
+	/**
143
+	 * @return void
144
+	 */
145
+	public static function set_late_hooks()
146
+	{
147
+		add_filter(
148
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
149
+			array('EED_Recaptcha', 'not_a_robot')
150
+		);
151
+	}
152
+
153
+
154
+	/**
155
+	 * @return boolean
156
+	 */
157
+	public static function useRecaptcha()
158
+	{
159
+		return EED_Recaptcha::$config->use_captcha
160
+			   && EED_Recaptcha::$config->recaptcha_theme !== 'invisible';
161
+	}
162
+
163
+
164
+	/**
165
+	 * @return boolean
166
+	 * @throws InvalidArgumentException
167
+	 * @throws InvalidInterfaceException
168
+	 * @throws InvalidDataTypeException
169
+	 */
170
+	public static function notPaymentOptionsRevisit()
171
+	{
172
+		$request = EED_Recaptcha::getRequest();
173
+		return ! (
174
+			$request->getRequestParam('step', '') === 'payment_options'
175
+			&& $request->getRequestParam('revisit', false, 'bool') === true
176
+		);
177
+	}
178
+
179
+
180
+	/**
181
+	 * @return void
182
+	 * @throws InvalidArgumentException
183
+	 * @throws InvalidInterfaceException
184
+	 * @throws InvalidDataTypeException
185
+	 */
186
+	public static function enqueue_styles_and_scripts()
187
+	{
188
+		wp_register_script(
189
+			'espresso_recaptcha',
190
+			RECAPTCHA_BASE_URL . 'scripts/espresso_recaptcha.js',
191
+			array('single_page_checkout'),
192
+			EVENT_ESPRESSO_VERSION,
193
+			true
194
+		);
195
+		wp_register_script(
196
+			'google_recaptcha',
197
+			'https://www.google.com/recaptcha/api.js?hl=' . EED_Recaptcha::$config->recaptcha_language,
198
+			array('espresso_recaptcha'),
199
+			EVENT_ESPRESSO_VERSION,
200
+			true
201
+		);
202
+		EE_Registry::$i18n_js_strings['no_SPCO_error'] = __(
203
+			'It appears the Single Page Checkout javascript was not loaded properly! Please refresh the page and try again or contact support.',
204
+			'event_espresso'
205
+		);
206
+		EE_Registry::$i18n_js_strings['no_recaptcha_error'] = __(
207
+			'There appears to be a problem with the reCAPTCHA configuration! Please check the admin settings or contact support.',
208
+			'event_espresso'
209
+		);
210
+		EE_Registry::$i18n_js_strings['recaptcha_fail'] = __(
211
+			'Please complete the anti-spam test before proceeding.',
212
+			'event_espresso'
213
+		);
214
+	}
215
+
216
+
217
+	/**
218
+	 * @param WP $WP
219
+	 */
220
+	public function run($WP)
221
+	{
222
+	}
223
+
224
+
225
+	/**
226
+	 * @return boolean
227
+	 * @throws InvalidArgumentException
228
+	 * @throws InvalidInterfaceException
229
+	 * @throws InvalidDataTypeException
230
+	 */
231
+	public static function not_a_robot()
232
+	{
233
+		return is_bool(EED_Recaptcha::$_not_a_robot)
234
+			? EED_Recaptcha::$_not_a_robot
235
+			: EED_Recaptcha::recaptcha_passed();
236
+	}
237
+
238
+
239
+	/**
240
+	 * @return void
241
+	 * @throws DomainException
242
+	 * @throws InvalidArgumentException
243
+	 * @throws InvalidInterfaceException
244
+	 * @throws InvalidDataTypeException
245
+	 */
246
+	public static function display_recaptcha()
247
+	{
248
+		// logged in means you have already passed a turing test of sorts
249
+		if (is_user_logged_in()) {
250
+			return;
251
+		}
252
+		// don't display if not using recaptcha or user is logged in
253
+		if (EED_Recaptcha::useRecaptcha() && ! EED_Recaptcha::$_not_a_robot) {
254
+			// only display if they have NOT passed the test yet
255
+			EEH_Template::display_template(
256
+				RECAPTCHA_BASE_PATH . '/templates/recaptcha.template.php',
257
+				array(
258
+					'recaptcha_publickey' => EED_Recaptcha::$config->recaptcha_publickey,
259
+					'recaptcha_theme'     => EED_Recaptcha::$config->recaptcha_theme,
260
+					'recaptcha_type'      => EED_Recaptcha::$config->recaptcha_type,
261
+				)
262
+			);
263
+			wp_enqueue_script('google_recaptcha');
264
+		}
265
+	}
266
+
267
+
268
+	/**
269
+	 * @return array
270
+	 * @throws InvalidArgumentException
271
+	 * @throws InvalidInterfaceException
272
+	 * @throws InvalidDataTypeException
273
+	 */
274
+	public static function bypass_recaptcha_for_spco_load_payment_method()
275
+	{
276
+		return array(
277
+			'EESID'  => EE_Registry::instance()->SSN->id(),
278
+			'step'   => 'payment_options',
279
+			'action' => 'switch_spco_billing_form',
280
+		);
281
+	}
282
+
283
+
284
+	/**
285
+	 * @return boolean
286
+	 * @throws InvalidArgumentException
287
+	 * @throws InvalidInterfaceException
288
+	 * @throws InvalidDataTypeException
289
+	 */
290
+	public static function recaptcha_passed()
291
+	{
292
+		// logged in means you have already passed a turing test of sorts
293
+		if (is_user_logged_in() || EED_Recaptcha::_bypass_recaptcha()) {
294
+			return true;
295
+		}
296
+		// was test already passed?
297
+		$recaptcha_passed = EE_Registry::instance()->SSN->get_session_data('recaptcha_passed');
298
+		$recaptcha_passed = filter_var($recaptcha_passed, FILTER_VALIDATE_BOOLEAN);
299
+		// verify recaptcha
300
+		EED_Recaptcha::_get_recaptcha_response();
301
+		if (! $recaptcha_passed && EED_Recaptcha::$_recaptcha_response) {
302
+			$recaptcha_passed = EED_Recaptcha::_process_recaptcha_response();
303
+			EE_Registry::instance()->SSN->set_session_data(array('recaptcha_passed' => $recaptcha_passed));
304
+		}
305
+		EED_Recaptcha::$_not_a_robot = $recaptcha_passed;
306
+		return $recaptcha_passed;
307
+	}
308
+
309
+
310
+	/**
311
+	 * @param array $recaptcha_response
312
+	 * @return array
313
+	 */
314
+	public static function recaptcha_response($recaptcha_response = array())
315
+	{
316
+		if (EED_Recaptcha::_bypass_recaptcha()) {
317
+			$recaptcha_response['bypass_recaptcha'] = true;
318
+			$recaptcha_response['recaptcha_passed'] = true;
319
+		} else {
320
+			$recaptcha_response['recaptcha_passed'] = EED_Recaptcha::$_not_a_robot;
321
+		}
322
+		return $recaptcha_response;
323
+	}
324
+
325
+
326
+	/**
327
+	 * @return boolean
328
+	 */
329
+	private static function _bypass_recaptcha()
330
+	{
331
+		// an array of key value pairs that must match exactly with the incoming request,
332
+		// in order to bypass recaptcha for the current request ONLY
333
+		$bypass_request_params_array = (array) apply_filters(
334
+			'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
335
+			array()
336
+		);
337
+		// does $bypass_request_params_array have any values ?
338
+		if (empty($bypass_request_params_array)) {
339
+			return false;
340
+		}
341
+		$request = EED_Recaptcha::getRequest();
342
+		// initially set bypass to TRUE
343
+		$bypass_recaptcha = true;
344
+		foreach ($bypass_request_params_array as $key => $value) {
345
+			// if $key is not found or value doesn't match exactly, then toggle bypass to FALSE,
346
+			// otherwise carry over it's value. This way, one missed setting results in no bypass
347
+			$bypass_recaptcha = $request->getRequestParam($key) === $value
348
+				? $bypass_recaptcha
349
+				: false;
350
+		}
351
+		return $bypass_recaptcha;
352
+	}
353
+
354
+
355
+	/**
356
+	 * @return void
357
+	 * @throws InvalidArgumentException
358
+	 * @throws InvalidInterfaceException
359
+	 * @throws InvalidDataTypeException
360
+	 */
361
+	private static function _get_recaptcha_response()
362
+	{
363
+		EED_Recaptcha::$_recaptcha_response = EED_Recaptcha::getRequest()->getRequestParam(
364
+			'g-recaptcha-response'
365
+		);
366
+	}
367
+
368
+
369
+	/**
370
+	 * @return boolean
371
+	 * @throws InvalidArgumentException
372
+	 * @throws InvalidInterfaceException
373
+	 * @throws InvalidDataTypeException
374
+	 */
375
+	private static function _process_recaptcha_response()
376
+	{
377
+		// verify library is loaded
378
+		if (! class_exists('\ReCaptcha\ReCaptcha')) {
379
+			require_once RECAPTCHA_BASE_PATH . '/autoload.php';
380
+		}
381
+		// The response from reCAPTCHA
382
+		EED_Recaptcha::_get_recaptcha_response();
383
+		$recaptcha_response = EED_Recaptcha::$_recaptcha_response;
384
+		// Was there a reCAPTCHA response?
385
+		if ($recaptcha_response) {
386
+			// if allow_url_fopen is Off, then set a different request method
387
+			$request_method = ! ini_get('allow_url_fopen') ? new SocketPost() : null;
388
+			$recaptcha = new ReCaptcha(
389
+				EED_Recaptcha::$config->recaptcha_privatekey,
390
+				$request_method
391
+			);
392
+			$recaptcha_response = $recaptcha->verify(
393
+				EED_Recaptcha::$_recaptcha_response,
394
+				EED_Recaptcha::getRequest()->getServerParam('REMOTE_ADDR')
395
+			);
396
+		}
397
+		return $recaptcha_response instanceof Response && $recaptcha_response->isSuccess();
398
+	}
399 399
 }
Please login to merge, or discard this patch.
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.