Completed
Branch FET-9222-rest-api-writes (9a0487)
by
unknown
71:42 queued 58:38
created
core/services/shortcodes/ShortcodeInterface.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -8,52 +8,52 @@
 block discarded – undo
8 8
 interface ShortcodeInterface
9 9
 {
10 10
 
11
-    /**
12
-     * the actual shortcode tag that gets registered with WordPress
13
-     *
14
-     * @return string
15
-     */
16
-    public function getTag();
17
-
18
-    /**
19
-     * the length of time in seconds to cache the results of the processShortcode() method
20
-     * 0 means the processShortcode() results will NOT be cached at all
21
-     *
22
-     * @return int
23
-     */
24
-    public function cacheExpiration();
25
-
26
-    /**
27
-     * a place for adding any initialization code that needs to run prior to wp_header().
28
-     * this may be required for shortcodes that utilize a corresponding module,
29
-     * and need to enqueue assets for that module
30
-     *
31
-     * !!! IMPORTANT !!!
32
-     * After performing any logic within this method required for initialization
33
-     *         $this->shortcodeHasBeenInitialized();
34
-     * should be called to ensure that the shortcode is setup correctly.
35
-     *
36
-     * @return void
37
-     */
38
-    public function initializeShortcode();
39
-
40
-    /**
41
-     * callback that runs when the shortcode is encountered in post content.
42
-     * IMPORTANT !!!
43
-     * remember that shortcode content should be RETURNED and NOT echoed out
44
-     *
45
-     * @param array $attributes
46
-     * @return string
47
-     */
48
-    public function processShortcode($attributes = array());
49
-
50
-
51
-
52
-    /**
53
-     * Returns whether or not this shortcode class has already been initialized
54
-     * @return boolean
55
-     */
56
-    public function initialized();
11
+	/**
12
+	 * the actual shortcode tag that gets registered with WordPress
13
+	 *
14
+	 * @return string
15
+	 */
16
+	public function getTag();
17
+
18
+	/**
19
+	 * the length of time in seconds to cache the results of the processShortcode() method
20
+	 * 0 means the processShortcode() results will NOT be cached at all
21
+	 *
22
+	 * @return int
23
+	 */
24
+	public function cacheExpiration();
25
+
26
+	/**
27
+	 * a place for adding any initialization code that needs to run prior to wp_header().
28
+	 * this may be required for shortcodes that utilize a corresponding module,
29
+	 * and need to enqueue assets for that module
30
+	 *
31
+	 * !!! IMPORTANT !!!
32
+	 * After performing any logic within this method required for initialization
33
+	 *         $this->shortcodeHasBeenInitialized();
34
+	 * should be called to ensure that the shortcode is setup correctly.
35
+	 *
36
+	 * @return void
37
+	 */
38
+	public function initializeShortcode();
39
+
40
+	/**
41
+	 * callback that runs when the shortcode is encountered in post content.
42
+	 * IMPORTANT !!!
43
+	 * remember that shortcode content should be RETURNED and NOT echoed out
44
+	 *
45
+	 * @param array $attributes
46
+	 * @return string
47
+	 */
48
+	public function processShortcode($attributes = array());
49
+
50
+
51
+
52
+	/**
53
+	 * Returns whether or not this shortcode class has already been initialized
54
+	 * @return boolean
55
+	 */
56
+	public function initialized();
57 57
 
58 58
 }
59 59
 // End of file ShortcodeInterface.php
Please login to merge, or discard this patch.
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 1 patch
Indentation   +1260 added lines, -1260 removed lines patch added patch discarded remove patch
@@ -14,1264 +14,1264 @@
 block discarded – undo
14 14
 {
15 15
 
16 16
 
17
-    /**
18
-     * Extend_Events_Admin_Page constructor.
19
-     *
20
-     * @param bool $routing
21
-     */
22
-    public function __construct($routing = true)
23
-    {
24
-        parent::__construct($routing);
25
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
26
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
27
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
28
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
29
-        }
30
-    }
31
-
32
-
33
-    /**
34
-     * Sets routes.
35
-     */
36
-    protected function _extend_page_config()
37
-    {
38
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
39
-        //is there a evt_id in the request?
40
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
41
-            ? $this->_req_data['EVT_ID']
42
-            : 0;
43
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
44
-        //tkt_id?
45
-        $tkt_id             = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
46
-            ? $this->_req_data['TKT_ID']
47
-            : 0;
48
-        $new_page_routes    = array(
49
-            'duplicate_event'          => array(
50
-                'func'       => '_duplicate_event',
51
-                'capability' => 'ee_edit_event',
52
-                'obj_id'     => $evt_id,
53
-                'noheader'   => true,
54
-            ),
55
-            'ticket_list_table'        => array(
56
-                'func'       => '_tickets_overview_list_table',
57
-                'capability' => 'ee_read_default_tickets',
58
-            ),
59
-            'trash_ticket'             => array(
60
-                'func'       => '_trash_or_restore_ticket',
61
-                'capability' => 'ee_delete_default_ticket',
62
-                'obj_id'     => $tkt_id,
63
-                'noheader'   => true,
64
-                'args'       => array('trash' => true),
65
-            ),
66
-            'trash_tickets'            => array(
67
-                'func'       => '_trash_or_restore_ticket',
68
-                'capability' => 'ee_delete_default_tickets',
69
-                'noheader'   => true,
70
-                'args'       => array('trash' => true),
71
-            ),
72
-            'restore_ticket'           => array(
73
-                'func'       => '_trash_or_restore_ticket',
74
-                'capability' => 'ee_delete_default_ticket',
75
-                'obj_id'     => $tkt_id,
76
-                'noheader'   => true,
77
-            ),
78
-            'restore_tickets'          => array(
79
-                'func'       => '_trash_or_restore_ticket',
80
-                'capability' => 'ee_delete_default_tickets',
81
-                'noheader'   => true,
82
-            ),
83
-            'delete_ticket'            => array(
84
-                'func'       => '_delete_ticket',
85
-                'capability' => 'ee_delete_default_ticket',
86
-                'obj_id'     => $tkt_id,
87
-                'noheader'   => true,
88
-            ),
89
-            'delete_tickets'           => array(
90
-                'func'       => '_delete_ticket',
91
-                'capability' => 'ee_delete_default_tickets',
92
-                'noheader'   => true,
93
-            ),
94
-            'import_page'              => array(
95
-                'func'       => '_import_page',
96
-                'capability' => 'import',
97
-            ),
98
-            'import'                   => array(
99
-                'func'       => '_import_events',
100
-                'capability' => 'import',
101
-                'noheader'   => true,
102
-            ),
103
-            'import_events'            => array(
104
-                'func'       => '_import_events',
105
-                'capability' => 'import',
106
-                'noheader'   => true,
107
-            ),
108
-            'export_events'            => array(
109
-                'func'       => '_events_export',
110
-                'capability' => 'export',
111
-                'noheader'   => true,
112
-            ),
113
-            'export_categories'        => array(
114
-                'func'       => '_categories_export',
115
-                'capability' => 'export',
116
-                'noheader'   => true,
117
-            ),
118
-            'sample_export_file'       => array(
119
-                'func'       => '_sample_export_file',
120
-                'capability' => 'export',
121
-                'noheader'   => true,
122
-            ),
123
-            'update_template_settings' => array(
124
-                'func'       => '_update_template_settings',
125
-                'capability' => 'manage_options',
126
-                'noheader'   => true,
127
-            ),
128
-        );
129
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
130
-        //partial route/config override
131
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
132
-        $this->_page_config['create_new']['metaboxes'][]  = '_premium_event_editor_meta_boxes';
133
-        $this->_page_config['create_new']['qtips'][]      = 'EE_Event_Editor_Tips';
134
-        $this->_page_config['edit']['qtips'][]            = 'EE_Event_Editor_Tips';
135
-        $this->_page_config['edit']['metaboxes'][]        = '_premium_event_editor_meta_boxes';
136
-        $this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
137
-        //add tickets tab but only if there are more than one default ticket!
138
-        $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
139
-            array(array('TKT_is_default' => 1)),
140
-            'TKT_ID',
141
-            true
142
-        );
143
-        if ($tkt_count > 1) {
144
-            $new_page_config = array(
145
-                'ticket_list_table' => array(
146
-                    'nav'           => array(
147
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
148
-                        'order' => 60,
149
-                    ),
150
-                    'list_table'    => 'Tickets_List_Table',
151
-                    'require_nonce' => false,
152
-                ),
153
-            );
154
-        }
155
-        //template settings
156
-        $new_page_config['template_settings'] = array(
157
-            'nav'           => array(
158
-                'label' => esc_html__('Templates', 'event_espresso'),
159
-                'order' => 30,
160
-            ),
161
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
162
-            'help_tabs'     => array(
163
-                'general_settings_templates_help_tab' => array(
164
-                    'title'    => esc_html__('Templates', 'event_espresso'),
165
-                    'filename' => 'general_settings_templates',
166
-                ),
167
-            ),
168
-            'help_tour'     => array('Templates_Help_Tour'),
169
-            'require_nonce' => false,
170
-        );
171
-        $this->_page_config                   = array_merge($this->_page_config, $new_page_config);
172
-        //add filters and actions
173
-        //modifying _views
174
-        add_filter(
175
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
176
-            array($this, 'add_additional_datetime_button'),
177
-            10,
178
-            2
179
-        );
180
-        add_filter(
181
-            'FHEE_event_datetime_metabox_clone_button_template',
182
-            array($this, 'add_datetime_clone_button'),
183
-            10,
184
-            2
185
-        );
186
-        add_filter(
187
-            'FHEE_event_datetime_metabox_timezones_template',
188
-            array($this, 'datetime_timezones_template'),
189
-            10,
190
-            2
191
-        );
192
-        //filters for event list table
193
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
194
-        add_filter(
195
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
196
-            array($this, 'extra_list_table_actions'),
197
-            10,
198
-            2
199
-        );
200
-        //legend item
201
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
202
-        add_action('admin_init', array($this, 'admin_init'));
203
-        //heartbeat stuff
204
-        add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2);
205
-    }
206
-
207
-
208
-    /**
209
-     * admin_init
210
-     */
211
-    public function admin_init()
212
-    {
213
-        EE_Registry::$i18n_js_strings = array_merge(
214
-            EE_Registry::$i18n_js_strings,
215
-            array(
216
-                'image_confirm'          => esc_html__(
217
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
218
-                    'event_espresso'
219
-                ),
220
-                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
221
-                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
222
-                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
223
-                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
224
-                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
225
-            )
226
-        );
227
-    }
228
-
229
-
230
-    /**
231
-     * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
232
-     * accordingly.
233
-     *
234
-     * @param array $response The existing heartbeat response array.
235
-     * @param array $data     The incoming data package.
236
-     * @return array  possibly appended response.
237
-     */
238
-    public function heartbeat_response($response, $data)
239
-    {
240
-        /**
241
-         * check whether count of tickets is approaching the potential
242
-         * limits for the server.
243
-         */
244
-        if (! empty($data['input_count'])) {
245
-            $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
246
-                $data['input_count']
247
-            );
248
-        }
249
-        return $response;
250
-    }
251
-
252
-
253
-    /**
254
-     * Add per page screen options to the default ticket list table view.
255
-     */
256
-    protected function _add_screen_options_ticket_list_table()
257
-    {
258
-        $this->_per_page_screen_option();
259
-    }
260
-
261
-
262
-    /**
263
-     * @param string $return
264
-     * @param int    $id
265
-     * @param string $new_title
266
-     * @param string $new_slug
267
-     * @return string
268
-     */
269
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
270
-    {
271
-        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
272
-        //make sure this is only when editing
273
-        if (! empty($id)) {
274
-            $href   = EE_Admin_Page::add_query_args_and_nonce(
275
-                array('action' => 'duplicate_event', 'EVT_ID' => $id),
276
-                $this->_admin_base_url
277
-            );
278
-            $title  = esc_attr__('Duplicate Event', 'event_espresso');
279
-            $return .= '<a href="'
280
-                       . $href
281
-                       . '" title="'
282
-                       . $title
283
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
284
-                       . $title
285
-                       . '</button>';
286
-        }
287
-        return $return;
288
-    }
289
-
290
-
291
-    /**
292
-     * Set the list table views for the default ticket list table view.
293
-     */
294
-    public function _set_list_table_views_ticket_list_table()
295
-    {
296
-        $this->_views = array(
297
-            'all'     => array(
298
-                'slug'        => 'all',
299
-                'label'       => esc_html__('All', 'event_espresso'),
300
-                'count'       => 0,
301
-                'bulk_action' => array(
302
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
303
-                ),
304
-            ),
305
-            'trashed' => array(
306
-                'slug'        => 'trashed',
307
-                'label'       => esc_html__('Trash', 'event_espresso'),
308
-                'count'       => 0,
309
-                'bulk_action' => array(
310
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
311
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
312
-                ),
313
-            ),
314
-        );
315
-    }
316
-
317
-
318
-    /**
319
-     * Enqueue scripts and styles for the event editor.
320
-     */
321
-    public function load_scripts_styles_edit()
322
-    {
323
-        wp_register_script(
324
-            'ee-event-editor-heartbeat',
325
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
326
-            array('ee_admin_js', 'heartbeat'),
327
-            EVENT_ESPRESSO_VERSION,
328
-            true
329
-        );
330
-        wp_enqueue_script('ee-accounting');
331
-        //styles
332
-        wp_enqueue_style('espresso-ui-theme');
333
-        wp_enqueue_script('event_editor_js');
334
-        wp_enqueue_script('ee-event-editor-heartbeat');
335
-    }
336
-
337
-
338
-    /**
339
-     * Returns template for the additional datetime.
340
-     * @param $template
341
-     * @param $template_args
342
-     * @return mixed
343
-     * @throws DomainException
344
-     */
345
-    public function add_additional_datetime_button($template, $template_args)
346
-    {
347
-        return EEH_Template::display_template(
348
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
349
-            $template_args,
350
-            true
351
-        );
352
-    }
353
-
354
-
355
-    /**
356
-     * Returns the template for cloning a datetime.
357
-     * @param $template
358
-     * @param $template_args
359
-     * @return mixed
360
-     * @throws DomainException
361
-     */
362
-    public function add_datetime_clone_button($template, $template_args)
363
-    {
364
-        return EEH_Template::display_template(
365
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
366
-            $template_args,
367
-            true
368
-        );
369
-    }
370
-
371
-
372
-    /**
373
-     * Returns the template for datetime timezones.
374
-     * @param $template
375
-     * @param $template_args
376
-     * @return mixed
377
-     * @throws DomainException
378
-     */
379
-    public function datetime_timezones_template($template, $template_args)
380
-    {
381
-        return EEH_Template::display_template(
382
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
383
-            $template_args,
384
-            true
385
-        );
386
-    }
387
-
388
-
389
-    /**
390
-     * Sets the views for the default list table view.
391
-     */
392
-    protected function _set_list_table_views_default()
393
-    {
394
-        parent::_set_list_table_views_default();
395
-        $new_views    = array(
396
-            'today' => array(
397
-                'slug'        => 'today',
398
-                'label'       => esc_html__('Today', 'event_espresso'),
399
-                'count'       => $this->total_events_today(),
400
-                'bulk_action' => array(
401
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
402
-                ),
403
-            ),
404
-            'month' => array(
405
-                'slug'        => 'month',
406
-                'label'       => esc_html__('This Month', 'event_espresso'),
407
-                'count'       => $this->total_events_this_month(),
408
-                'bulk_action' => array(
409
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
410
-                ),
411
-            ),
412
-        );
413
-        $this->_views = array_merge($this->_views, $new_views);
414
-    }
415
-
416
-
417
-    /**
418
-     * Returns the extra action links for the default list table view.
419
-     * @param array     $action_links
420
-     * @param \EE_Event $event
421
-     * @return array
422
-     * @throws EE_Error
423
-     */
424
-    public function extra_list_table_actions(array $action_links, \EE_Event $event)
425
-    {
426
-        if (EE_Registry::instance()->CAP->current_user_can(
427
-            'ee_read_registrations',
428
-            'espresso_registrations_reports',
429
-            $event->ID()
430
-        )
431
-        ) {
432
-            $reports_query_args = array(
433
-                'action' => 'reports',
434
-                'EVT_ID' => $event->ID(),
435
-            );
436
-            $reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
437
-            $action_links[]     = '<a href="'
438
-                                  . $reports_link
439
-                                  . '" title="'
440
-                                  . esc_attr__('View Report', 'event_espresso')
441
-                                  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
442
-                                  . "\n\t";
443
-        }
444
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
445
-            EE_Registry::instance()->load_helper('MSG_Template');
446
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
447
-                'see_notifications_for',
448
-                null,
449
-                array('EVT_ID' => $event->ID())
450
-            );
451
-        }
452
-        return $action_links;
453
-    }
454
-
455
-
456
-    /**
457
-     * @param $items
458
-     * @return mixed
459
-     */
460
-    public function additional_legend_items($items)
461
-    {
462
-        if (EE_Registry::instance()->CAP->current_user_can(
463
-            'ee_read_registrations',
464
-            'espresso_registrations_reports'
465
-        )
466
-        ) {
467
-            $items['reports'] = array(
468
-                'class' => 'dashicons dashicons-chart-bar',
469
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
470
-            );
471
-        }
472
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
473
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
474
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
475
-                $items['view_related_messages'] = array(
476
-                    'class' => $related_for_icon['css_class'],
477
-                    'desc'  => $related_for_icon['label'],
478
-                );
479
-            }
480
-        }
481
-        return $items;
482
-    }
483
-
484
-
485
-    /**
486
-     * This is the callback method for the duplicate event route
487
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
488
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
489
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
490
-     * After duplication the redirect is to the new event edit page.
491
-     *
492
-     * @return void
493
-     * @access protected
494
-     * @throws EE_Error If EE_Event is not available with given ID
495
-     */
496
-    protected function _duplicate_event()
497
-    {
498
-        // first make sure the ID for the event is in the request.
499
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
500
-        if (! isset($this->_req_data['EVT_ID'])) {
501
-            EE_Error::add_error(
502
-                esc_html__(
503
-                    'In order to duplicate an event an Event ID is required.  None was given.',
504
-                    'event_espresso'
505
-                ),
506
-                __FILE__,
507
-                __FUNCTION__,
508
-                __LINE__
509
-            );
510
-            $this->_redirect_after_action(false, '', '', array(), true);
511
-            return;
512
-        }
513
-        //k we've got EVT_ID so let's use that to get the event we'll duplicate
514
-        $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
515
-        if (! $orig_event instanceof EE_Event) {
516
-            throw new EE_Error(
517
-                sprintf(
518
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
519
-                    $this->_req_data['EVT_ID']
520
-                )
521
-            );
522
-        }
523
-        //k now let's clone the $orig_event before getting relations
524
-        $new_event = clone $orig_event;
525
-        //original datetimes
526
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
527
-        //other original relations
528
-        $orig_ven = $orig_event->get_many_related('Venue');
529
-        //reset the ID and modify other details to make it clear this is a dupe
530
-        $new_event->set('EVT_ID', 0);
531
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
532
-        $new_event->set('EVT_name', $new_name);
533
-        $new_event->set(
534
-            'EVT_slug',
535
-            wp_unique_post_slug(
536
-                sanitize_title($orig_event->name()),
537
-                0,
538
-                'publish',
539
-                'espresso_events',
540
-                0
541
-            )
542
-        );
543
-        $new_event->set('status', 'draft');
544
-        //duplicate discussion settings
545
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
546
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
547
-        //save the new event
548
-        $new_event->save();
549
-        //venues
550
-        foreach ($orig_ven as $ven) {
551
-            $new_event->_add_relation_to($ven, 'Venue');
552
-        }
553
-        $new_event->save();
554
-        //now we need to get the question group relations and handle that
555
-        //first primary question groups
556
-        $orig_primary_qgs = $orig_event->get_many_related(
557
-            'Question_Group',
558
-            array(array('Event_Question_Group.EQG_primary' => 1))
559
-        );
560
-        if (! empty($orig_primary_qgs)) {
561
-            foreach ($orig_primary_qgs as $id => $obj) {
562
-                if ($obj instanceof EE_Question_Group) {
563
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
564
-                }
565
-            }
566
-        }
567
-        //next additional attendee question groups
568
-        $orig_additional_qgs = $orig_event->get_many_related(
569
-            'Question_Group',
570
-            array(array('Event_Question_Group.EQG_primary' => 0))
571
-        );
572
-        if (! empty($orig_additional_qgs)) {
573
-            foreach ($orig_additional_qgs as $id => $obj) {
574
-                if ($obj instanceof EE_Question_Group) {
575
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
576
-                }
577
-            }
578
-        }
579
-
580
-        $new_event->save();
581
-
582
-        //k now that we have the new event saved we can loop through the datetimes and start adding relations.
583
-        $cloned_tickets = array();
584
-        foreach ($orig_datetimes as $orig_dtt) {
585
-            if (! $orig_dtt instanceof EE_Datetime) {
586
-                continue;
587
-            }
588
-            $new_dtt   = clone $orig_dtt;
589
-            $orig_tkts = $orig_dtt->tickets();
590
-            //save new dtt then add to event
591
-            $new_dtt->set('DTT_ID', 0);
592
-            $new_dtt->set('DTT_sold', 0);
593
-            $new_dtt->set_reserved(0);
594
-            $new_dtt->save();
595
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
596
-            $new_event->save();
597
-            //now let's get the ticket relations setup.
598
-            foreach ((array)$orig_tkts as $orig_tkt) {
599
-                //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
600
-                if (! $orig_tkt instanceof EE_Ticket) {
601
-                    continue;
602
-                }
603
-                //is this ticket archived?  If it is then let's skip
604
-                if ($orig_tkt->get('TKT_deleted')) {
605
-                    continue;
606
-                }
607
-                // does this original ticket already exist in the clone_tickets cache?
608
-                //  If so we'll just use the new ticket from it.
609
-                if (isset($cloned_tickets[$orig_tkt->ID()])) {
610
-                    $new_tkt = $cloned_tickets[$orig_tkt->ID()];
611
-                } else {
612
-                    $new_tkt = clone $orig_tkt;
613
-                    //get relations on the $orig_tkt that we need to setup.
614
-                    $orig_prices = $orig_tkt->prices();
615
-                    $new_tkt->set('TKT_ID', 0);
616
-                    $new_tkt->set('TKT_sold', 0);
617
-                    $new_tkt->set('TKT_reserved', 0);
618
-                    $new_tkt->save(); //make sure new ticket has ID.
619
-                    //price relations on new ticket need to be setup.
620
-                    foreach ($orig_prices as $orig_price) {
621
-                        $new_price = clone $orig_price;
622
-                        $new_price->set('PRC_ID', 0);
623
-                        $new_price->save();
624
-                        $new_tkt->_add_relation_to($new_price, 'Price');
625
-                        $new_tkt->save();
626
-                    }
627
-
628
-                    do_action(
629
-                        'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
630
-                        $orig_tkt,
631
-                        $new_tkt,
632
-                        $orig_prices,
633
-                        $orig_event,
634
-                        $orig_dtt,
635
-                        $new_dtt
636
-                    );
637
-                }
638
-                // k now we can add the new ticket as a relation to the new datetime
639
-                // and make sure its added to our cached $cloned_tickets array
640
-                // for use with later datetimes that have the same ticket.
641
-                $new_dtt->_add_relation_to($new_tkt, 'Ticket');
642
-                $new_dtt->save();
643
-                $cloned_tickets[$orig_tkt->ID()] = $new_tkt;
644
-            }
645
-        }
646
-        //clone taxonomy information
647
-        $taxonomies_to_clone_with = apply_filters(
648
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
649
-            array('espresso_event_categories', 'espresso_event_type', 'post_tag')
650
-        );
651
-        //get terms for original event (notice)
652
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
653
-        //loop through terms and add them to new event.
654
-        foreach ($orig_terms as $term) {
655
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
656
-        }
657
-
658
-        //duplicate other core WP_Post items for this event.
659
-        //post thumbnail (feature image).
660
-        $feature_image_id = get_post_thumbnail_id($orig_event->ID());
661
-        if ($feature_image_id) {
662
-            update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
663
-        }
664
-
665
-        //duplicate page_template setting
666
-        $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
667
-        if ($page_template) {
668
-            update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
669
-        }
670
-
671
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
672
-        //now let's redirect to the edit page for this duplicated event if we have a new event id.
673
-        if ($new_event->ID()) {
674
-            $redirect_args = array(
675
-                'post'   => $new_event->ID(),
676
-                'action' => 'edit',
677
-            );
678
-            EE_Error::add_success(
679
-                esc_html__(
680
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
681
-                    'event_espresso'
682
-                )
683
-            );
684
-        } else {
685
-            $redirect_args = array(
686
-                'action' => 'default',
687
-            );
688
-            EE_Error::add_error(
689
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
690
-                __FILE__,
691
-                __FUNCTION__,
692
-                __LINE__
693
-            );
694
-        }
695
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
696
-    }
697
-
698
-
699
-    /**
700
-     * Generates output for the import page.
701
-     * @throws DomainException
702
-     */
703
-    protected function _import_page()
704
-    {
705
-        $title                                      = esc_html__('Import', 'event_espresso');
706
-        $intro                                      = esc_html__(
707
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
708
-            'event_espresso'
709
-        );
710
-        $form_url                                   = EVENTS_ADMIN_URL;
711
-        $action                                     = 'import_events';
712
-        $type                                       = 'csv';
713
-        $this->_template_args['form']               = EE_Import::instance()->upload_form(
714
-            $title, $intro, $form_url, $action, $type
715
-        );
716
-        $this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
717
-            array('action' => 'sample_export_file'),
718
-            $this->_admin_base_url
719
-        );
720
-        $content                                    = EEH_Template::display_template(
721
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
722
-            $this->_template_args,
723
-            true
724
-        );
725
-        $this->_template_args['admin_page_content'] = $content;
726
-        $this->display_admin_page_with_sidebar();
727
-    }
728
-
729
-
730
-    /**
731
-     * _import_events
732
-     * This handles displaying the screen and running imports for importing events.
733
-     *
734
-     * @return void
735
-     */
736
-    protected function _import_events()
737
-    {
738
-        require_once(EE_CLASSES . 'EE_Import.class.php');
739
-        $success = EE_Import::instance()->import();
740
-        $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
741
-    }
742
-
743
-
744
-    /**
745
-     * _events_export
746
-     * Will export all (or just the given event) to a Excel compatible file.
747
-     *
748
-     * @access protected
749
-     * @return void
750
-     */
751
-    protected function _events_export()
752
-    {
753
-        if (isset($this->_req_data['EVT_ID'])) {
754
-            $event_ids = $this->_req_data['EVT_ID'];
755
-        } elseif (isset($this->_req_data['EVT_IDs'])) {
756
-            $event_ids = $this->_req_data['EVT_IDs'];
757
-        } else {
758
-            $event_ids = null;
759
-        }
760
-        //todo: I don't like doing this but it'll do until we modify EE_Export Class.
761
-        $new_request_args = array(
762
-            'export' => 'report',
763
-            'action' => 'all_event_data',
764
-            'EVT_ID' => $event_ids,
765
-        );
766
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
767
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
768
-            require_once(EE_CLASSES . 'EE_Export.class.php');
769
-            $EE_Export = EE_Export::instance($this->_req_data);
770
-            $EE_Export->export();
771
-        }
772
-    }
773
-
774
-
775
-    /**
776
-     * handle category exports()
777
-     *
778
-     * @return void
779
-     */
780
-    protected function _categories_export()
781
-    {
782
-        //todo: I don't like doing this but it'll do until we modify EE_Export Class.
783
-        $new_request_args = array(
784
-            'export'       => 'report',
785
-            'action'       => 'categories',
786
-            'category_ids' => $this->_req_data['EVT_CAT_ID'],
787
-        );
788
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
789
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
790
-            require_once(EE_CLASSES . 'EE_Export.class.php');
791
-            $EE_Export = EE_Export::instance($this->_req_data);
792
-            $EE_Export->export();
793
-        }
794
-    }
795
-
796
-
797
-    /**
798
-     * Creates a sample CSV file for importing
799
-     */
800
-    protected function _sample_export_file()
801
-    {
802
-        //		require_once(EE_CLASSES . 'EE_Export.class.php');
803
-        EE_Export::instance()->export_sample();
804
-    }
805
-
806
-
807
-    /*************        Template Settings        *************/
808
-    /**
809
-     * Generates template settings page output
810
-     * @throws DomainException
811
-     * @throws EE_Error
812
-     */
813
-    protected function _template_settings()
814
-    {
815
-        $this->_template_args['values'] = $this->_yes_no_values;
816
-        /**
817
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
818
-         * from General_Settings_Admin_Page to here.
819
-         */
820
-        $this->_template_args = apply_filters(
821
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
822
-            $this->_template_args
823
-        );
824
-        $this->_set_add_edit_form_tags('update_template_settings');
825
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
826
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
827
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
828
-            $this->_template_args,
829
-            true
830
-        );
831
-        $this->display_admin_page_with_sidebar();
832
-    }
833
-
834
-
835
-    /**
836
-     * Handler for updating template settings.
837
-     */
838
-    protected function _update_template_settings()
839
-    {
840
-        /**
841
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
842
-         * from General_Settings_Admin_Page to here.
843
-         */
844
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
845
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
846
-            EE_Registry::instance()->CFG->template_settings,
847
-            $this->_req_data
848
-        );
849
-        //update custom post type slugs and detect if we need to flush rewrite rules
850
-        $old_slug                                          = EE_Registry::instance()->CFG->core->event_cpt_slug;
851
-        EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
852
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
853
-            : sanitize_title_with_dashes($this->_req_data['event_cpt_slug']);
854
-        $what                                              = 'Template Settings';
855
-        $success                                           = $this->_update_espresso_configuration(
856
-            $what,
857
-            EE_Registry::instance()->CFG->template_settings,
858
-            __FILE__,
859
-            __FUNCTION__,
860
-            __LINE__
861
-        );
862
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
863
-            update_option('ee_flush_rewrite_rules', true);
864
-        }
865
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
866
-    }
867
-
868
-
869
-    /**
870
-     * _premium_event_editor_meta_boxes
871
-     * add all metaboxes related to the event_editor
872
-     *
873
-     * @access protected
874
-     * @return void
875
-     * @throws EE_Error
876
-     */
877
-    protected function _premium_event_editor_meta_boxes()
878
-    {
879
-        $this->verify_cpt_object();
880
-        add_meta_box(
881
-            'espresso_event_editor_event_options',
882
-            esc_html__('Event Registration Options', 'event_espresso'),
883
-            array($this, 'registration_options_meta_box'),
884
-            $this->page_slug,
885
-            'side',
886
-            'core'
887
-        );
888
-    }
889
-
890
-
891
-    /**
892
-     * override caf metabox
893
-     *
894
-     * @return void
895
-     * @throws DomainException
896
-     */
897
-    public function registration_options_meta_box()
898
-    {
899
-        $yes_no_values                                    = array(
900
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
901
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
902
-        );
903
-        $default_reg_status_values                        = EEM_Registration::reg_status_array(
904
-            array(
905
-                EEM_Registration::status_id_cancelled,
906
-                EEM_Registration::status_id_declined,
907
-                EEM_Registration::status_id_incomplete,
908
-                EEM_Registration::status_id_wait_list,
909
-            ),
910
-            true
911
-        );
912
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
913
-        $template_args['_event']                          = $this->_cpt_model_obj;
914
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
915
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
916
-            'default_reg_status',
917
-            $default_reg_status_values,
918
-            $this->_cpt_model_obj->default_registration_status()
919
-        );
920
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
921
-            'display_desc',
922
-            $yes_no_values,
923
-            $this->_cpt_model_obj->display_description()
924
-        );
925
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
926
-            'display_ticket_selector',
927
-            $yes_no_values,
928
-            $this->_cpt_model_obj->display_ticket_selector(),
929
-            '',
930
-            '',
931
-            false
932
-        );
933
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
934
-            'EVT_default_registration_status',
935
-            $default_reg_status_values,
936
-            $this->_cpt_model_obj->default_registration_status()
937
-        );
938
-        $template_args['additional_registration_options'] = apply_filters(
939
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
940
-            '',
941
-            $template_args,
942
-            $yes_no_values,
943
-            $default_reg_status_values
944
-        );
945
-        EEH_Template::display_template(
946
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
947
-            $template_args
948
-        );
949
-    }
950
-
951
-
952
-
953
-    /**
954
-     * wp_list_table_mods for caf
955
-     * ============================
956
-     */
957
-    /**
958
-     * hook into list table filters and provide filters for caffeinated list table
959
-     *
960
-     * @param  array $old_filters    any existing filters present
961
-     * @param  array $list_table_obj the list table object
962
-     * @return array                  new filters
963
-     */
964
-    public function list_table_filters($old_filters, $list_table_obj)
965
-    {
966
-        $filters = array();
967
-        //first month/year filters
968
-        $filters[] = $this->espresso_event_months_dropdown();
969
-        $status    = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
970
-        //active status dropdown
971
-        if ($status !== 'draft') {
972
-            $filters[] = $this->active_status_dropdown(
973
-                isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
974
-            );
975
-        }
976
-        //category filter
977
-        $filters[] = $this->category_dropdown();
978
-        return array_merge($old_filters, $filters);
979
-    }
980
-
981
-
982
-    /**
983
-     * espresso_event_months_dropdown
984
-     *
985
-     * @access public
986
-     * @return string                dropdown listing month/year selections for events.
987
-     */
988
-    public function espresso_event_months_dropdown()
989
-    {
990
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
991
-        // Note we need to include any other filters that are set!
992
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
993
-        //categories?
994
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
995
-            ? $this->_req_data['EVT_CAT']
996
-            : null;
997
-        //active status?
998
-        $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
999
-        $cur_date      = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
1000
-        return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
1001
-    }
1002
-
1003
-
1004
-    /**
1005
-     * returns a list of "active" statuses on the event
1006
-     *
1007
-     * @param  string $current_value whatever the current active status is
1008
-     * @return string
1009
-     */
1010
-    public function active_status_dropdown($current_value = '')
1011
-    {
1012
-        $select_name = 'active_status';
1013
-        $values      = array(
1014
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1015
-            'active'   => esc_html__('Active', 'event_espresso'),
1016
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1017
-            'expired'  => esc_html__('Expired', 'event_espresso'),
1018
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
1019
-        );
1020
-        $id          = 'id="espresso-active-status-dropdown-filter"';
1021
-        $class       = 'wide';
1022
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
1023
-    }
1024
-
1025
-
1026
-    /**
1027
-     * output a dropdown of the categories for the category filter on the event admin list table
1028
-     *
1029
-     * @access  public
1030
-     * @return string html
1031
-     */
1032
-    public function category_dropdown()
1033
-    {
1034
-        $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1035
-        return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1036
-    }
1037
-
1038
-
1039
-    /**
1040
-     * get total number of events today
1041
-     *
1042
-     * @access public
1043
-     * @return int
1044
-     * @throws EE_Error
1045
-     */
1046
-    public function total_events_today()
1047
-    {
1048
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1049
-            'DTT_EVT_start',
1050
-            date('Y-m-d') . ' 00:00:00',
1051
-            'Y-m-d H:i:s',
1052
-            'UTC'
1053
-        );
1054
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1055
-            'DTT_EVT_start',
1056
-            date('Y-m-d') . ' 23:59:59',
1057
-            'Y-m-d H:i:s',
1058
-            'UTC'
1059
-        );
1060
-        $where = array(
1061
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1062
-        );
1063
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1064
-        return $count;
1065
-    }
1066
-
1067
-
1068
-    /**
1069
-     * get total number of events this month
1070
-     *
1071
-     * @access public
1072
-     * @return int
1073
-     * @throws EE_Error
1074
-     */
1075
-    public function total_events_this_month()
1076
-    {
1077
-        //Dates
1078
-        $this_year_r     = date('Y');
1079
-        $this_month_r    = date('m');
1080
-        $days_this_month = date('t');
1081
-        $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1082
-            'DTT_EVT_start',
1083
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1084
-            'Y-m-d H:i:s',
1085
-            'UTC'
1086
-        );
1087
-        $end             = EEM_Datetime::instance()->convert_datetime_for_query(
1088
-            'DTT_EVT_start',
1089
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1090
-            'Y-m-d H:i:s',
1091
-            'UTC'
1092
-        );
1093
-        $where           = array(
1094
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1095
-        );
1096
-        $count           = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1097
-        return $count;
1098
-    }
1099
-
1100
-
1101
-    /** DEFAULT TICKETS STUFF **/
1102
-
1103
-    /**
1104
-     * Output default tickets list table view.
1105
-     */
1106
-    public function _tickets_overview_list_table()
1107
-    {
1108
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1109
-        $this->display_admin_list_table_page_with_no_sidebar();
1110
-    }
1111
-
1112
-
1113
-    /**
1114
-     * @param int  $per_page
1115
-     * @param bool $count
1116
-     * @param bool $trashed
1117
-     * @return \EE_Soft_Delete_Base_Class[]|int
1118
-     */
1119
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1120
-    {
1121
-        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1122
-        $order   = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1123
-        switch ($orderby) {
1124
-            case 'TKT_name':
1125
-                $orderby = array('TKT_name' => $order);
1126
-                break;
1127
-            case 'TKT_price':
1128
-                $orderby = array('TKT_price' => $order);
1129
-                break;
1130
-            case 'TKT_uses':
1131
-                $orderby = array('TKT_uses' => $order);
1132
-                break;
1133
-            case 'TKT_min':
1134
-                $orderby = array('TKT_min' => $order);
1135
-                break;
1136
-            case 'TKT_max':
1137
-                $orderby = array('TKT_max' => $order);
1138
-                break;
1139
-            case 'TKT_qty':
1140
-                $orderby = array('TKT_qty' => $order);
1141
-                break;
1142
-        }
1143
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1144
-            ? $this->_req_data['paged']
1145
-            : 1;
1146
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1147
-            ? $this->_req_data['perpage']
1148
-            : $per_page;
1149
-        $_where       = array(
1150
-            'TKT_is_default' => 1,
1151
-            'TKT_deleted'    => $trashed,
1152
-        );
1153
-        $offset       = ($current_page - 1) * $per_page;
1154
-        $limit        = array($offset, $per_page);
1155
-        if (isset($this->_req_data['s'])) {
1156
-            $sstr         = '%' . $this->_req_data['s'] . '%';
1157
-            $_where['OR'] = array(
1158
-                'TKT_name'        => array('LIKE', $sstr),
1159
-                'TKT_description' => array('LIKE', $sstr),
1160
-            );
1161
-        }
1162
-        $query_params = array(
1163
-            $_where,
1164
-            'order_by' => $orderby,
1165
-            'limit'    => $limit,
1166
-            'group_by' => 'TKT_ID',
1167
-        );
1168
-        if ($count) {
1169
-            return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1170
-        } else {
1171
-            return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1172
-        }
1173
-    }
1174
-
1175
-
1176
-    /**
1177
-     * @param bool $trash
1178
-     * @throws EE_Error
1179
-     */
1180
-    protected function _trash_or_restore_ticket($trash = false)
1181
-    {
1182
-        $success = 1;
1183
-        $TKT     = EEM_Ticket::instance();
1184
-        //checkboxes?
1185
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1186
-            //if array has more than one element then success message should be plural
1187
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1188
-            //cycle thru the boxes
1189
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1190
-                if ($trash) {
1191
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1192
-                        $success = 0;
1193
-                    }
1194
-                } else {
1195
-                    if (! $TKT->restore_by_ID($TKT_ID)) {
1196
-                        $success = 0;
1197
-                    }
1198
-                }
1199
-            }
1200
-        } else {
1201
-            //grab single id and trash
1202
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1203
-            if ($trash) {
1204
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1205
-                    $success = 0;
1206
-                }
1207
-            } else {
1208
-                if (! $TKT->restore_by_ID($TKT_ID)) {
1209
-                    $success = 0;
1210
-                }
1211
-            }
1212
-        }
1213
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1214
-        $query_args  = array(
1215
-            'action' => 'ticket_list_table',
1216
-            'status' => $trash ? '' : 'trashed',
1217
-        );
1218
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1219
-    }
1220
-
1221
-
1222
-    /**
1223
-     * Handles trashing default ticket.
1224
-     */
1225
-    protected function _delete_ticket()
1226
-    {
1227
-        $success = 1;
1228
-        //checkboxes?
1229
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1230
-            //if array has more than one element then success message should be plural
1231
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1232
-            //cycle thru the boxes
1233
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1234
-                //delete
1235
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1236
-                    $success = 0;
1237
-                }
1238
-            }
1239
-        } else {
1240
-            //grab single id and trash
1241
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1242
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1243
-                $success = 0;
1244
-            }
1245
-        }
1246
-        $action_desc = 'deleted';
1247
-        $query_args  = array(
1248
-            'action' => 'ticket_list_table',
1249
-            'status' => 'trashed',
1250
-        );
1251
-        //fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1252
-        if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1253
-            array(array('TKT_is_default' => 1)),
1254
-            'TKT_ID',
1255
-            true
1256
-        )
1257
-        ) {
1258
-            $query_args = array();
1259
-        }
1260
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1261
-    }
1262
-
1263
-
1264
-    /**
1265
-     * @param int $TKT_ID
1266
-     * @return bool|int
1267
-     * @throws EE_Error
1268
-     */
1269
-    protected function _delete_the_ticket($TKT_ID)
1270
-    {
1271
-        $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1272
-        $tkt->_remove_relations('Datetime');
1273
-        //delete all related prices first
1274
-        $tkt->delete_related_permanently('Price');
1275
-        return $tkt->delete_permanently();
1276
-    }
17
+	/**
18
+	 * Extend_Events_Admin_Page constructor.
19
+	 *
20
+	 * @param bool $routing
21
+	 */
22
+	public function __construct($routing = true)
23
+	{
24
+		parent::__construct($routing);
25
+		if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
26
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
27
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
28
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
29
+		}
30
+	}
31
+
32
+
33
+	/**
34
+	 * Sets routes.
35
+	 */
36
+	protected function _extend_page_config()
37
+	{
38
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
39
+		//is there a evt_id in the request?
40
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
41
+			? $this->_req_data['EVT_ID']
42
+			: 0;
43
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
44
+		//tkt_id?
45
+		$tkt_id             = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
46
+			? $this->_req_data['TKT_ID']
47
+			: 0;
48
+		$new_page_routes    = array(
49
+			'duplicate_event'          => array(
50
+				'func'       => '_duplicate_event',
51
+				'capability' => 'ee_edit_event',
52
+				'obj_id'     => $evt_id,
53
+				'noheader'   => true,
54
+			),
55
+			'ticket_list_table'        => array(
56
+				'func'       => '_tickets_overview_list_table',
57
+				'capability' => 'ee_read_default_tickets',
58
+			),
59
+			'trash_ticket'             => array(
60
+				'func'       => '_trash_or_restore_ticket',
61
+				'capability' => 'ee_delete_default_ticket',
62
+				'obj_id'     => $tkt_id,
63
+				'noheader'   => true,
64
+				'args'       => array('trash' => true),
65
+			),
66
+			'trash_tickets'            => array(
67
+				'func'       => '_trash_or_restore_ticket',
68
+				'capability' => 'ee_delete_default_tickets',
69
+				'noheader'   => true,
70
+				'args'       => array('trash' => true),
71
+			),
72
+			'restore_ticket'           => array(
73
+				'func'       => '_trash_or_restore_ticket',
74
+				'capability' => 'ee_delete_default_ticket',
75
+				'obj_id'     => $tkt_id,
76
+				'noheader'   => true,
77
+			),
78
+			'restore_tickets'          => array(
79
+				'func'       => '_trash_or_restore_ticket',
80
+				'capability' => 'ee_delete_default_tickets',
81
+				'noheader'   => true,
82
+			),
83
+			'delete_ticket'            => array(
84
+				'func'       => '_delete_ticket',
85
+				'capability' => 'ee_delete_default_ticket',
86
+				'obj_id'     => $tkt_id,
87
+				'noheader'   => true,
88
+			),
89
+			'delete_tickets'           => array(
90
+				'func'       => '_delete_ticket',
91
+				'capability' => 'ee_delete_default_tickets',
92
+				'noheader'   => true,
93
+			),
94
+			'import_page'              => array(
95
+				'func'       => '_import_page',
96
+				'capability' => 'import',
97
+			),
98
+			'import'                   => array(
99
+				'func'       => '_import_events',
100
+				'capability' => 'import',
101
+				'noheader'   => true,
102
+			),
103
+			'import_events'            => array(
104
+				'func'       => '_import_events',
105
+				'capability' => 'import',
106
+				'noheader'   => true,
107
+			),
108
+			'export_events'            => array(
109
+				'func'       => '_events_export',
110
+				'capability' => 'export',
111
+				'noheader'   => true,
112
+			),
113
+			'export_categories'        => array(
114
+				'func'       => '_categories_export',
115
+				'capability' => 'export',
116
+				'noheader'   => true,
117
+			),
118
+			'sample_export_file'       => array(
119
+				'func'       => '_sample_export_file',
120
+				'capability' => 'export',
121
+				'noheader'   => true,
122
+			),
123
+			'update_template_settings' => array(
124
+				'func'       => '_update_template_settings',
125
+				'capability' => 'manage_options',
126
+				'noheader'   => true,
127
+			),
128
+		);
129
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
130
+		//partial route/config override
131
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
132
+		$this->_page_config['create_new']['metaboxes'][]  = '_premium_event_editor_meta_boxes';
133
+		$this->_page_config['create_new']['qtips'][]      = 'EE_Event_Editor_Tips';
134
+		$this->_page_config['edit']['qtips'][]            = 'EE_Event_Editor_Tips';
135
+		$this->_page_config['edit']['metaboxes'][]        = '_premium_event_editor_meta_boxes';
136
+		$this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
137
+		//add tickets tab but only if there are more than one default ticket!
138
+		$tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
139
+			array(array('TKT_is_default' => 1)),
140
+			'TKT_ID',
141
+			true
142
+		);
143
+		if ($tkt_count > 1) {
144
+			$new_page_config = array(
145
+				'ticket_list_table' => array(
146
+					'nav'           => array(
147
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
148
+						'order' => 60,
149
+					),
150
+					'list_table'    => 'Tickets_List_Table',
151
+					'require_nonce' => false,
152
+				),
153
+			);
154
+		}
155
+		//template settings
156
+		$new_page_config['template_settings'] = array(
157
+			'nav'           => array(
158
+				'label' => esc_html__('Templates', 'event_espresso'),
159
+				'order' => 30,
160
+			),
161
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
162
+			'help_tabs'     => array(
163
+				'general_settings_templates_help_tab' => array(
164
+					'title'    => esc_html__('Templates', 'event_espresso'),
165
+					'filename' => 'general_settings_templates',
166
+				),
167
+			),
168
+			'help_tour'     => array('Templates_Help_Tour'),
169
+			'require_nonce' => false,
170
+		);
171
+		$this->_page_config                   = array_merge($this->_page_config, $new_page_config);
172
+		//add filters and actions
173
+		//modifying _views
174
+		add_filter(
175
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
176
+			array($this, 'add_additional_datetime_button'),
177
+			10,
178
+			2
179
+		);
180
+		add_filter(
181
+			'FHEE_event_datetime_metabox_clone_button_template',
182
+			array($this, 'add_datetime_clone_button'),
183
+			10,
184
+			2
185
+		);
186
+		add_filter(
187
+			'FHEE_event_datetime_metabox_timezones_template',
188
+			array($this, 'datetime_timezones_template'),
189
+			10,
190
+			2
191
+		);
192
+		//filters for event list table
193
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
194
+		add_filter(
195
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
196
+			array($this, 'extra_list_table_actions'),
197
+			10,
198
+			2
199
+		);
200
+		//legend item
201
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
202
+		add_action('admin_init', array($this, 'admin_init'));
203
+		//heartbeat stuff
204
+		add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2);
205
+	}
206
+
207
+
208
+	/**
209
+	 * admin_init
210
+	 */
211
+	public function admin_init()
212
+	{
213
+		EE_Registry::$i18n_js_strings = array_merge(
214
+			EE_Registry::$i18n_js_strings,
215
+			array(
216
+				'image_confirm'          => esc_html__(
217
+					'Do you really want to delete this image? Please remember to update your event to complete the removal.',
218
+					'event_espresso'
219
+				),
220
+				'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
221
+				'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
222
+				'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
223
+				'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
224
+				'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
225
+			)
226
+		);
227
+	}
228
+
229
+
230
+	/**
231
+	 * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
232
+	 * accordingly.
233
+	 *
234
+	 * @param array $response The existing heartbeat response array.
235
+	 * @param array $data     The incoming data package.
236
+	 * @return array  possibly appended response.
237
+	 */
238
+	public function heartbeat_response($response, $data)
239
+	{
240
+		/**
241
+		 * check whether count of tickets is approaching the potential
242
+		 * limits for the server.
243
+		 */
244
+		if (! empty($data['input_count'])) {
245
+			$response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
246
+				$data['input_count']
247
+			);
248
+		}
249
+		return $response;
250
+	}
251
+
252
+
253
+	/**
254
+	 * Add per page screen options to the default ticket list table view.
255
+	 */
256
+	protected function _add_screen_options_ticket_list_table()
257
+	{
258
+		$this->_per_page_screen_option();
259
+	}
260
+
261
+
262
+	/**
263
+	 * @param string $return
264
+	 * @param int    $id
265
+	 * @param string $new_title
266
+	 * @param string $new_slug
267
+	 * @return string
268
+	 */
269
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
270
+	{
271
+		$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
272
+		//make sure this is only when editing
273
+		if (! empty($id)) {
274
+			$href   = EE_Admin_Page::add_query_args_and_nonce(
275
+				array('action' => 'duplicate_event', 'EVT_ID' => $id),
276
+				$this->_admin_base_url
277
+			);
278
+			$title  = esc_attr__('Duplicate Event', 'event_espresso');
279
+			$return .= '<a href="'
280
+					   . $href
281
+					   . '" title="'
282
+					   . $title
283
+					   . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
284
+					   . $title
285
+					   . '</button>';
286
+		}
287
+		return $return;
288
+	}
289
+
290
+
291
+	/**
292
+	 * Set the list table views for the default ticket list table view.
293
+	 */
294
+	public function _set_list_table_views_ticket_list_table()
295
+	{
296
+		$this->_views = array(
297
+			'all'     => array(
298
+				'slug'        => 'all',
299
+				'label'       => esc_html__('All', 'event_espresso'),
300
+				'count'       => 0,
301
+				'bulk_action' => array(
302
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
303
+				),
304
+			),
305
+			'trashed' => array(
306
+				'slug'        => 'trashed',
307
+				'label'       => esc_html__('Trash', 'event_espresso'),
308
+				'count'       => 0,
309
+				'bulk_action' => array(
310
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
311
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
312
+				),
313
+			),
314
+		);
315
+	}
316
+
317
+
318
+	/**
319
+	 * Enqueue scripts and styles for the event editor.
320
+	 */
321
+	public function load_scripts_styles_edit()
322
+	{
323
+		wp_register_script(
324
+			'ee-event-editor-heartbeat',
325
+			EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
326
+			array('ee_admin_js', 'heartbeat'),
327
+			EVENT_ESPRESSO_VERSION,
328
+			true
329
+		);
330
+		wp_enqueue_script('ee-accounting');
331
+		//styles
332
+		wp_enqueue_style('espresso-ui-theme');
333
+		wp_enqueue_script('event_editor_js');
334
+		wp_enqueue_script('ee-event-editor-heartbeat');
335
+	}
336
+
337
+
338
+	/**
339
+	 * Returns template for the additional datetime.
340
+	 * @param $template
341
+	 * @param $template_args
342
+	 * @return mixed
343
+	 * @throws DomainException
344
+	 */
345
+	public function add_additional_datetime_button($template, $template_args)
346
+	{
347
+		return EEH_Template::display_template(
348
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
349
+			$template_args,
350
+			true
351
+		);
352
+	}
353
+
354
+
355
+	/**
356
+	 * Returns the template for cloning a datetime.
357
+	 * @param $template
358
+	 * @param $template_args
359
+	 * @return mixed
360
+	 * @throws DomainException
361
+	 */
362
+	public function add_datetime_clone_button($template, $template_args)
363
+	{
364
+		return EEH_Template::display_template(
365
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
366
+			$template_args,
367
+			true
368
+		);
369
+	}
370
+
371
+
372
+	/**
373
+	 * Returns the template for datetime timezones.
374
+	 * @param $template
375
+	 * @param $template_args
376
+	 * @return mixed
377
+	 * @throws DomainException
378
+	 */
379
+	public function datetime_timezones_template($template, $template_args)
380
+	{
381
+		return EEH_Template::display_template(
382
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
383
+			$template_args,
384
+			true
385
+		);
386
+	}
387
+
388
+
389
+	/**
390
+	 * Sets the views for the default list table view.
391
+	 */
392
+	protected function _set_list_table_views_default()
393
+	{
394
+		parent::_set_list_table_views_default();
395
+		$new_views    = array(
396
+			'today' => array(
397
+				'slug'        => 'today',
398
+				'label'       => esc_html__('Today', 'event_espresso'),
399
+				'count'       => $this->total_events_today(),
400
+				'bulk_action' => array(
401
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
402
+				),
403
+			),
404
+			'month' => array(
405
+				'slug'        => 'month',
406
+				'label'       => esc_html__('This Month', 'event_espresso'),
407
+				'count'       => $this->total_events_this_month(),
408
+				'bulk_action' => array(
409
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
410
+				),
411
+			),
412
+		);
413
+		$this->_views = array_merge($this->_views, $new_views);
414
+	}
415
+
416
+
417
+	/**
418
+	 * Returns the extra action links for the default list table view.
419
+	 * @param array     $action_links
420
+	 * @param \EE_Event $event
421
+	 * @return array
422
+	 * @throws EE_Error
423
+	 */
424
+	public function extra_list_table_actions(array $action_links, \EE_Event $event)
425
+	{
426
+		if (EE_Registry::instance()->CAP->current_user_can(
427
+			'ee_read_registrations',
428
+			'espresso_registrations_reports',
429
+			$event->ID()
430
+		)
431
+		) {
432
+			$reports_query_args = array(
433
+				'action' => 'reports',
434
+				'EVT_ID' => $event->ID(),
435
+			);
436
+			$reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
437
+			$action_links[]     = '<a href="'
438
+								  . $reports_link
439
+								  . '" title="'
440
+								  . esc_attr__('View Report', 'event_espresso')
441
+								  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
442
+								  . "\n\t";
443
+		}
444
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
445
+			EE_Registry::instance()->load_helper('MSG_Template');
446
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
447
+				'see_notifications_for',
448
+				null,
449
+				array('EVT_ID' => $event->ID())
450
+			);
451
+		}
452
+		return $action_links;
453
+	}
454
+
455
+
456
+	/**
457
+	 * @param $items
458
+	 * @return mixed
459
+	 */
460
+	public function additional_legend_items($items)
461
+	{
462
+		if (EE_Registry::instance()->CAP->current_user_can(
463
+			'ee_read_registrations',
464
+			'espresso_registrations_reports'
465
+		)
466
+		) {
467
+			$items['reports'] = array(
468
+				'class' => 'dashicons dashicons-chart-bar',
469
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
470
+			);
471
+		}
472
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
473
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
474
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
475
+				$items['view_related_messages'] = array(
476
+					'class' => $related_for_icon['css_class'],
477
+					'desc'  => $related_for_icon['label'],
478
+				);
479
+			}
480
+		}
481
+		return $items;
482
+	}
483
+
484
+
485
+	/**
486
+	 * This is the callback method for the duplicate event route
487
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
488
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
489
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
490
+	 * After duplication the redirect is to the new event edit page.
491
+	 *
492
+	 * @return void
493
+	 * @access protected
494
+	 * @throws EE_Error If EE_Event is not available with given ID
495
+	 */
496
+	protected function _duplicate_event()
497
+	{
498
+		// first make sure the ID for the event is in the request.
499
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
500
+		if (! isset($this->_req_data['EVT_ID'])) {
501
+			EE_Error::add_error(
502
+				esc_html__(
503
+					'In order to duplicate an event an Event ID is required.  None was given.',
504
+					'event_espresso'
505
+				),
506
+				__FILE__,
507
+				__FUNCTION__,
508
+				__LINE__
509
+			);
510
+			$this->_redirect_after_action(false, '', '', array(), true);
511
+			return;
512
+		}
513
+		//k we've got EVT_ID so let's use that to get the event we'll duplicate
514
+		$orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
515
+		if (! $orig_event instanceof EE_Event) {
516
+			throw new EE_Error(
517
+				sprintf(
518
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
519
+					$this->_req_data['EVT_ID']
520
+				)
521
+			);
522
+		}
523
+		//k now let's clone the $orig_event before getting relations
524
+		$new_event = clone $orig_event;
525
+		//original datetimes
526
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
527
+		//other original relations
528
+		$orig_ven = $orig_event->get_many_related('Venue');
529
+		//reset the ID and modify other details to make it clear this is a dupe
530
+		$new_event->set('EVT_ID', 0);
531
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
532
+		$new_event->set('EVT_name', $new_name);
533
+		$new_event->set(
534
+			'EVT_slug',
535
+			wp_unique_post_slug(
536
+				sanitize_title($orig_event->name()),
537
+				0,
538
+				'publish',
539
+				'espresso_events',
540
+				0
541
+			)
542
+		);
543
+		$new_event->set('status', 'draft');
544
+		//duplicate discussion settings
545
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
546
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
547
+		//save the new event
548
+		$new_event->save();
549
+		//venues
550
+		foreach ($orig_ven as $ven) {
551
+			$new_event->_add_relation_to($ven, 'Venue');
552
+		}
553
+		$new_event->save();
554
+		//now we need to get the question group relations and handle that
555
+		//first primary question groups
556
+		$orig_primary_qgs = $orig_event->get_many_related(
557
+			'Question_Group',
558
+			array(array('Event_Question_Group.EQG_primary' => 1))
559
+		);
560
+		if (! empty($orig_primary_qgs)) {
561
+			foreach ($orig_primary_qgs as $id => $obj) {
562
+				if ($obj instanceof EE_Question_Group) {
563
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
564
+				}
565
+			}
566
+		}
567
+		//next additional attendee question groups
568
+		$orig_additional_qgs = $orig_event->get_many_related(
569
+			'Question_Group',
570
+			array(array('Event_Question_Group.EQG_primary' => 0))
571
+		);
572
+		if (! empty($orig_additional_qgs)) {
573
+			foreach ($orig_additional_qgs as $id => $obj) {
574
+				if ($obj instanceof EE_Question_Group) {
575
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
576
+				}
577
+			}
578
+		}
579
+
580
+		$new_event->save();
581
+
582
+		//k now that we have the new event saved we can loop through the datetimes and start adding relations.
583
+		$cloned_tickets = array();
584
+		foreach ($orig_datetimes as $orig_dtt) {
585
+			if (! $orig_dtt instanceof EE_Datetime) {
586
+				continue;
587
+			}
588
+			$new_dtt   = clone $orig_dtt;
589
+			$orig_tkts = $orig_dtt->tickets();
590
+			//save new dtt then add to event
591
+			$new_dtt->set('DTT_ID', 0);
592
+			$new_dtt->set('DTT_sold', 0);
593
+			$new_dtt->set_reserved(0);
594
+			$new_dtt->save();
595
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
596
+			$new_event->save();
597
+			//now let's get the ticket relations setup.
598
+			foreach ((array)$orig_tkts as $orig_tkt) {
599
+				//it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
600
+				if (! $orig_tkt instanceof EE_Ticket) {
601
+					continue;
602
+				}
603
+				//is this ticket archived?  If it is then let's skip
604
+				if ($orig_tkt->get('TKT_deleted')) {
605
+					continue;
606
+				}
607
+				// does this original ticket already exist in the clone_tickets cache?
608
+				//  If so we'll just use the new ticket from it.
609
+				if (isset($cloned_tickets[$orig_tkt->ID()])) {
610
+					$new_tkt = $cloned_tickets[$orig_tkt->ID()];
611
+				} else {
612
+					$new_tkt = clone $orig_tkt;
613
+					//get relations on the $orig_tkt that we need to setup.
614
+					$orig_prices = $orig_tkt->prices();
615
+					$new_tkt->set('TKT_ID', 0);
616
+					$new_tkt->set('TKT_sold', 0);
617
+					$new_tkt->set('TKT_reserved', 0);
618
+					$new_tkt->save(); //make sure new ticket has ID.
619
+					//price relations on new ticket need to be setup.
620
+					foreach ($orig_prices as $orig_price) {
621
+						$new_price = clone $orig_price;
622
+						$new_price->set('PRC_ID', 0);
623
+						$new_price->save();
624
+						$new_tkt->_add_relation_to($new_price, 'Price');
625
+						$new_tkt->save();
626
+					}
627
+
628
+					do_action(
629
+						'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
630
+						$orig_tkt,
631
+						$new_tkt,
632
+						$orig_prices,
633
+						$orig_event,
634
+						$orig_dtt,
635
+						$new_dtt
636
+					);
637
+				}
638
+				// k now we can add the new ticket as a relation to the new datetime
639
+				// and make sure its added to our cached $cloned_tickets array
640
+				// for use with later datetimes that have the same ticket.
641
+				$new_dtt->_add_relation_to($new_tkt, 'Ticket');
642
+				$new_dtt->save();
643
+				$cloned_tickets[$orig_tkt->ID()] = $new_tkt;
644
+			}
645
+		}
646
+		//clone taxonomy information
647
+		$taxonomies_to_clone_with = apply_filters(
648
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
649
+			array('espresso_event_categories', 'espresso_event_type', 'post_tag')
650
+		);
651
+		//get terms for original event (notice)
652
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
653
+		//loop through terms and add them to new event.
654
+		foreach ($orig_terms as $term) {
655
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
656
+		}
657
+
658
+		//duplicate other core WP_Post items for this event.
659
+		//post thumbnail (feature image).
660
+		$feature_image_id = get_post_thumbnail_id($orig_event->ID());
661
+		if ($feature_image_id) {
662
+			update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
663
+		}
664
+
665
+		//duplicate page_template setting
666
+		$page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
667
+		if ($page_template) {
668
+			update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
669
+		}
670
+
671
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
672
+		//now let's redirect to the edit page for this duplicated event if we have a new event id.
673
+		if ($new_event->ID()) {
674
+			$redirect_args = array(
675
+				'post'   => $new_event->ID(),
676
+				'action' => 'edit',
677
+			);
678
+			EE_Error::add_success(
679
+				esc_html__(
680
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
681
+					'event_espresso'
682
+				)
683
+			);
684
+		} else {
685
+			$redirect_args = array(
686
+				'action' => 'default',
687
+			);
688
+			EE_Error::add_error(
689
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
690
+				__FILE__,
691
+				__FUNCTION__,
692
+				__LINE__
693
+			);
694
+		}
695
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
696
+	}
697
+
698
+
699
+	/**
700
+	 * Generates output for the import page.
701
+	 * @throws DomainException
702
+	 */
703
+	protected function _import_page()
704
+	{
705
+		$title                                      = esc_html__('Import', 'event_espresso');
706
+		$intro                                      = esc_html__(
707
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
708
+			'event_espresso'
709
+		);
710
+		$form_url                                   = EVENTS_ADMIN_URL;
711
+		$action                                     = 'import_events';
712
+		$type                                       = 'csv';
713
+		$this->_template_args['form']               = EE_Import::instance()->upload_form(
714
+			$title, $intro, $form_url, $action, $type
715
+		);
716
+		$this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
717
+			array('action' => 'sample_export_file'),
718
+			$this->_admin_base_url
719
+		);
720
+		$content                                    = EEH_Template::display_template(
721
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
722
+			$this->_template_args,
723
+			true
724
+		);
725
+		$this->_template_args['admin_page_content'] = $content;
726
+		$this->display_admin_page_with_sidebar();
727
+	}
728
+
729
+
730
+	/**
731
+	 * _import_events
732
+	 * This handles displaying the screen and running imports for importing events.
733
+	 *
734
+	 * @return void
735
+	 */
736
+	protected function _import_events()
737
+	{
738
+		require_once(EE_CLASSES . 'EE_Import.class.php');
739
+		$success = EE_Import::instance()->import();
740
+		$this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
741
+	}
742
+
743
+
744
+	/**
745
+	 * _events_export
746
+	 * Will export all (or just the given event) to a Excel compatible file.
747
+	 *
748
+	 * @access protected
749
+	 * @return void
750
+	 */
751
+	protected function _events_export()
752
+	{
753
+		if (isset($this->_req_data['EVT_ID'])) {
754
+			$event_ids = $this->_req_data['EVT_ID'];
755
+		} elseif (isset($this->_req_data['EVT_IDs'])) {
756
+			$event_ids = $this->_req_data['EVT_IDs'];
757
+		} else {
758
+			$event_ids = null;
759
+		}
760
+		//todo: I don't like doing this but it'll do until we modify EE_Export Class.
761
+		$new_request_args = array(
762
+			'export' => 'report',
763
+			'action' => 'all_event_data',
764
+			'EVT_ID' => $event_ids,
765
+		);
766
+		$this->_req_data  = array_merge($this->_req_data, $new_request_args);
767
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
768
+			require_once(EE_CLASSES . 'EE_Export.class.php');
769
+			$EE_Export = EE_Export::instance($this->_req_data);
770
+			$EE_Export->export();
771
+		}
772
+	}
773
+
774
+
775
+	/**
776
+	 * handle category exports()
777
+	 *
778
+	 * @return void
779
+	 */
780
+	protected function _categories_export()
781
+	{
782
+		//todo: I don't like doing this but it'll do until we modify EE_Export Class.
783
+		$new_request_args = array(
784
+			'export'       => 'report',
785
+			'action'       => 'categories',
786
+			'category_ids' => $this->_req_data['EVT_CAT_ID'],
787
+		);
788
+		$this->_req_data  = array_merge($this->_req_data, $new_request_args);
789
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
790
+			require_once(EE_CLASSES . 'EE_Export.class.php');
791
+			$EE_Export = EE_Export::instance($this->_req_data);
792
+			$EE_Export->export();
793
+		}
794
+	}
795
+
796
+
797
+	/**
798
+	 * Creates a sample CSV file for importing
799
+	 */
800
+	protected function _sample_export_file()
801
+	{
802
+		//		require_once(EE_CLASSES . 'EE_Export.class.php');
803
+		EE_Export::instance()->export_sample();
804
+	}
805
+
806
+
807
+	/*************        Template Settings        *************/
808
+	/**
809
+	 * Generates template settings page output
810
+	 * @throws DomainException
811
+	 * @throws EE_Error
812
+	 */
813
+	protected function _template_settings()
814
+	{
815
+		$this->_template_args['values'] = $this->_yes_no_values;
816
+		/**
817
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
818
+		 * from General_Settings_Admin_Page to here.
819
+		 */
820
+		$this->_template_args = apply_filters(
821
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
822
+			$this->_template_args
823
+		);
824
+		$this->_set_add_edit_form_tags('update_template_settings');
825
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
826
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
827
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
828
+			$this->_template_args,
829
+			true
830
+		);
831
+		$this->display_admin_page_with_sidebar();
832
+	}
833
+
834
+
835
+	/**
836
+	 * Handler for updating template settings.
837
+	 */
838
+	protected function _update_template_settings()
839
+	{
840
+		/**
841
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
842
+		 * from General_Settings_Admin_Page to here.
843
+		 */
844
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
845
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
846
+			EE_Registry::instance()->CFG->template_settings,
847
+			$this->_req_data
848
+		);
849
+		//update custom post type slugs and detect if we need to flush rewrite rules
850
+		$old_slug                                          = EE_Registry::instance()->CFG->core->event_cpt_slug;
851
+		EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
852
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
853
+			: sanitize_title_with_dashes($this->_req_data['event_cpt_slug']);
854
+		$what                                              = 'Template Settings';
855
+		$success                                           = $this->_update_espresso_configuration(
856
+			$what,
857
+			EE_Registry::instance()->CFG->template_settings,
858
+			__FILE__,
859
+			__FUNCTION__,
860
+			__LINE__
861
+		);
862
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
863
+			update_option('ee_flush_rewrite_rules', true);
864
+		}
865
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
866
+	}
867
+
868
+
869
+	/**
870
+	 * _premium_event_editor_meta_boxes
871
+	 * add all metaboxes related to the event_editor
872
+	 *
873
+	 * @access protected
874
+	 * @return void
875
+	 * @throws EE_Error
876
+	 */
877
+	protected function _premium_event_editor_meta_boxes()
878
+	{
879
+		$this->verify_cpt_object();
880
+		add_meta_box(
881
+			'espresso_event_editor_event_options',
882
+			esc_html__('Event Registration Options', 'event_espresso'),
883
+			array($this, 'registration_options_meta_box'),
884
+			$this->page_slug,
885
+			'side',
886
+			'core'
887
+		);
888
+	}
889
+
890
+
891
+	/**
892
+	 * override caf metabox
893
+	 *
894
+	 * @return void
895
+	 * @throws DomainException
896
+	 */
897
+	public function registration_options_meta_box()
898
+	{
899
+		$yes_no_values                                    = array(
900
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
901
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
902
+		);
903
+		$default_reg_status_values                        = EEM_Registration::reg_status_array(
904
+			array(
905
+				EEM_Registration::status_id_cancelled,
906
+				EEM_Registration::status_id_declined,
907
+				EEM_Registration::status_id_incomplete,
908
+				EEM_Registration::status_id_wait_list,
909
+			),
910
+			true
911
+		);
912
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
913
+		$template_args['_event']                          = $this->_cpt_model_obj;
914
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
915
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
916
+			'default_reg_status',
917
+			$default_reg_status_values,
918
+			$this->_cpt_model_obj->default_registration_status()
919
+		);
920
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
921
+			'display_desc',
922
+			$yes_no_values,
923
+			$this->_cpt_model_obj->display_description()
924
+		);
925
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
926
+			'display_ticket_selector',
927
+			$yes_no_values,
928
+			$this->_cpt_model_obj->display_ticket_selector(),
929
+			'',
930
+			'',
931
+			false
932
+		);
933
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
934
+			'EVT_default_registration_status',
935
+			$default_reg_status_values,
936
+			$this->_cpt_model_obj->default_registration_status()
937
+		);
938
+		$template_args['additional_registration_options'] = apply_filters(
939
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
940
+			'',
941
+			$template_args,
942
+			$yes_no_values,
943
+			$default_reg_status_values
944
+		);
945
+		EEH_Template::display_template(
946
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
947
+			$template_args
948
+		);
949
+	}
950
+
951
+
952
+
953
+	/**
954
+	 * wp_list_table_mods for caf
955
+	 * ============================
956
+	 */
957
+	/**
958
+	 * hook into list table filters and provide filters for caffeinated list table
959
+	 *
960
+	 * @param  array $old_filters    any existing filters present
961
+	 * @param  array $list_table_obj the list table object
962
+	 * @return array                  new filters
963
+	 */
964
+	public function list_table_filters($old_filters, $list_table_obj)
965
+	{
966
+		$filters = array();
967
+		//first month/year filters
968
+		$filters[] = $this->espresso_event_months_dropdown();
969
+		$status    = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
970
+		//active status dropdown
971
+		if ($status !== 'draft') {
972
+			$filters[] = $this->active_status_dropdown(
973
+				isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
974
+			);
975
+		}
976
+		//category filter
977
+		$filters[] = $this->category_dropdown();
978
+		return array_merge($old_filters, $filters);
979
+	}
980
+
981
+
982
+	/**
983
+	 * espresso_event_months_dropdown
984
+	 *
985
+	 * @access public
986
+	 * @return string                dropdown listing month/year selections for events.
987
+	 */
988
+	public function espresso_event_months_dropdown()
989
+	{
990
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
991
+		// Note we need to include any other filters that are set!
992
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
993
+		//categories?
994
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
995
+			? $this->_req_data['EVT_CAT']
996
+			: null;
997
+		//active status?
998
+		$active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
999
+		$cur_date      = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
1000
+		return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
1001
+	}
1002
+
1003
+
1004
+	/**
1005
+	 * returns a list of "active" statuses on the event
1006
+	 *
1007
+	 * @param  string $current_value whatever the current active status is
1008
+	 * @return string
1009
+	 */
1010
+	public function active_status_dropdown($current_value = '')
1011
+	{
1012
+		$select_name = 'active_status';
1013
+		$values      = array(
1014
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1015
+			'active'   => esc_html__('Active', 'event_espresso'),
1016
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1017
+			'expired'  => esc_html__('Expired', 'event_espresso'),
1018
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
1019
+		);
1020
+		$id          = 'id="espresso-active-status-dropdown-filter"';
1021
+		$class       = 'wide';
1022
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
1023
+	}
1024
+
1025
+
1026
+	/**
1027
+	 * output a dropdown of the categories for the category filter on the event admin list table
1028
+	 *
1029
+	 * @access  public
1030
+	 * @return string html
1031
+	 */
1032
+	public function category_dropdown()
1033
+	{
1034
+		$cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1035
+		return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1036
+	}
1037
+
1038
+
1039
+	/**
1040
+	 * get total number of events today
1041
+	 *
1042
+	 * @access public
1043
+	 * @return int
1044
+	 * @throws EE_Error
1045
+	 */
1046
+	public function total_events_today()
1047
+	{
1048
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1049
+			'DTT_EVT_start',
1050
+			date('Y-m-d') . ' 00:00:00',
1051
+			'Y-m-d H:i:s',
1052
+			'UTC'
1053
+		);
1054
+		$end   = EEM_Datetime::instance()->convert_datetime_for_query(
1055
+			'DTT_EVT_start',
1056
+			date('Y-m-d') . ' 23:59:59',
1057
+			'Y-m-d H:i:s',
1058
+			'UTC'
1059
+		);
1060
+		$where = array(
1061
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1062
+		);
1063
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1064
+		return $count;
1065
+	}
1066
+
1067
+
1068
+	/**
1069
+	 * get total number of events this month
1070
+	 *
1071
+	 * @access public
1072
+	 * @return int
1073
+	 * @throws EE_Error
1074
+	 */
1075
+	public function total_events_this_month()
1076
+	{
1077
+		//Dates
1078
+		$this_year_r     = date('Y');
1079
+		$this_month_r    = date('m');
1080
+		$days_this_month = date('t');
1081
+		$start           = EEM_Datetime::instance()->convert_datetime_for_query(
1082
+			'DTT_EVT_start',
1083
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1084
+			'Y-m-d H:i:s',
1085
+			'UTC'
1086
+		);
1087
+		$end             = EEM_Datetime::instance()->convert_datetime_for_query(
1088
+			'DTT_EVT_start',
1089
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1090
+			'Y-m-d H:i:s',
1091
+			'UTC'
1092
+		);
1093
+		$where           = array(
1094
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1095
+		);
1096
+		$count           = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1097
+		return $count;
1098
+	}
1099
+
1100
+
1101
+	/** DEFAULT TICKETS STUFF **/
1102
+
1103
+	/**
1104
+	 * Output default tickets list table view.
1105
+	 */
1106
+	public function _tickets_overview_list_table()
1107
+	{
1108
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1109
+		$this->display_admin_list_table_page_with_no_sidebar();
1110
+	}
1111
+
1112
+
1113
+	/**
1114
+	 * @param int  $per_page
1115
+	 * @param bool $count
1116
+	 * @param bool $trashed
1117
+	 * @return \EE_Soft_Delete_Base_Class[]|int
1118
+	 */
1119
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1120
+	{
1121
+		$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1122
+		$order   = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1123
+		switch ($orderby) {
1124
+			case 'TKT_name':
1125
+				$orderby = array('TKT_name' => $order);
1126
+				break;
1127
+			case 'TKT_price':
1128
+				$orderby = array('TKT_price' => $order);
1129
+				break;
1130
+			case 'TKT_uses':
1131
+				$orderby = array('TKT_uses' => $order);
1132
+				break;
1133
+			case 'TKT_min':
1134
+				$orderby = array('TKT_min' => $order);
1135
+				break;
1136
+			case 'TKT_max':
1137
+				$orderby = array('TKT_max' => $order);
1138
+				break;
1139
+			case 'TKT_qty':
1140
+				$orderby = array('TKT_qty' => $order);
1141
+				break;
1142
+		}
1143
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1144
+			? $this->_req_data['paged']
1145
+			: 1;
1146
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1147
+			? $this->_req_data['perpage']
1148
+			: $per_page;
1149
+		$_where       = array(
1150
+			'TKT_is_default' => 1,
1151
+			'TKT_deleted'    => $trashed,
1152
+		);
1153
+		$offset       = ($current_page - 1) * $per_page;
1154
+		$limit        = array($offset, $per_page);
1155
+		if (isset($this->_req_data['s'])) {
1156
+			$sstr         = '%' . $this->_req_data['s'] . '%';
1157
+			$_where['OR'] = array(
1158
+				'TKT_name'        => array('LIKE', $sstr),
1159
+				'TKT_description' => array('LIKE', $sstr),
1160
+			);
1161
+		}
1162
+		$query_params = array(
1163
+			$_where,
1164
+			'order_by' => $orderby,
1165
+			'limit'    => $limit,
1166
+			'group_by' => 'TKT_ID',
1167
+		);
1168
+		if ($count) {
1169
+			return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1170
+		} else {
1171
+			return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1172
+		}
1173
+	}
1174
+
1175
+
1176
+	/**
1177
+	 * @param bool $trash
1178
+	 * @throws EE_Error
1179
+	 */
1180
+	protected function _trash_or_restore_ticket($trash = false)
1181
+	{
1182
+		$success = 1;
1183
+		$TKT     = EEM_Ticket::instance();
1184
+		//checkboxes?
1185
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1186
+			//if array has more than one element then success message should be plural
1187
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1188
+			//cycle thru the boxes
1189
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1190
+				if ($trash) {
1191
+					if (! $TKT->delete_by_ID($TKT_ID)) {
1192
+						$success = 0;
1193
+					}
1194
+				} else {
1195
+					if (! $TKT->restore_by_ID($TKT_ID)) {
1196
+						$success = 0;
1197
+					}
1198
+				}
1199
+			}
1200
+		} else {
1201
+			//grab single id and trash
1202
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1203
+			if ($trash) {
1204
+				if (! $TKT->delete_by_ID($TKT_ID)) {
1205
+					$success = 0;
1206
+				}
1207
+			} else {
1208
+				if (! $TKT->restore_by_ID($TKT_ID)) {
1209
+					$success = 0;
1210
+				}
1211
+			}
1212
+		}
1213
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1214
+		$query_args  = array(
1215
+			'action' => 'ticket_list_table',
1216
+			'status' => $trash ? '' : 'trashed',
1217
+		);
1218
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1219
+	}
1220
+
1221
+
1222
+	/**
1223
+	 * Handles trashing default ticket.
1224
+	 */
1225
+	protected function _delete_ticket()
1226
+	{
1227
+		$success = 1;
1228
+		//checkboxes?
1229
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1230
+			//if array has more than one element then success message should be plural
1231
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1232
+			//cycle thru the boxes
1233
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1234
+				//delete
1235
+				if (! $this->_delete_the_ticket($TKT_ID)) {
1236
+					$success = 0;
1237
+				}
1238
+			}
1239
+		} else {
1240
+			//grab single id and trash
1241
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1242
+			if (! $this->_delete_the_ticket($TKT_ID)) {
1243
+				$success = 0;
1244
+			}
1245
+		}
1246
+		$action_desc = 'deleted';
1247
+		$query_args  = array(
1248
+			'action' => 'ticket_list_table',
1249
+			'status' => 'trashed',
1250
+		);
1251
+		//fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1252
+		if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1253
+			array(array('TKT_is_default' => 1)),
1254
+			'TKT_ID',
1255
+			true
1256
+		)
1257
+		) {
1258
+			$query_args = array();
1259
+		}
1260
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1261
+	}
1262
+
1263
+
1264
+	/**
1265
+	 * @param int $TKT_ID
1266
+	 * @return bool|int
1267
+	 * @throws EE_Error
1268
+	 */
1269
+	protected function _delete_the_ticket($TKT_ID)
1270
+	{
1271
+		$tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1272
+		$tkt->_remove_relations('Datetime');
1273
+		//delete all related prices first
1274
+		$tkt->delete_related_permanently('Price');
1275
+		return $tkt->delete_permanently();
1276
+	}
1277 1277
 }
Please login to merge, or discard this patch.
modules/ticket_selector/DisplayTicketSelector.php 1 patch
Indentation   +680 added lines, -680 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 use WP_Post;
18 18
 
19 19
 if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
20
-    exit( 'No direct script access allowed' );
20
+	exit( 'No direct script access allowed' );
21 21
 }
22 22
 
23 23
 
@@ -34,688 +34,688 @@  discard block
 block discarded – undo
34 34
 class DisplayTicketSelector
35 35
 {
36 36
 
37
-    /**
38
-     * event that ticket selector is being generated for
39
-     *
40
-     * @access protected
41
-     * @var EE_Event $event
42
-     */
43
-    protected $event;
44
-
45
-    /**
46
-     * Used to flag when the ticket selector is being called from an external iframe.
47
-     *
48
-     * @var bool $iframe
49
-     */
50
-    protected $iframe = false;
51
-
52
-    /**
53
-     * max attendees that can register for event at one time
54
-     *
55
-     * @var int $max_attendees
56
-     */
57
-    private $max_attendees = EE_INF;
58
-
59
-    /**
60
-     *@var string $date_format
61
-     */
62
-    private $date_format;
63
-
64
-    /**
65
-     *@var string $time_format
66
-     */
67
-    private $time_format;
68
-
69
-
70
-
71
-    /**
72
-     * DisplayTicketSelector constructor.
73
-     */
74
-    public function __construct()
75
-    {
76
-        $this->date_format = apply_filters(
77
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
78
-            get_option('date_format')
79
-        );
80
-        $this->time_format = apply_filters(
81
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
82
-            get_option('time_format')
83
-        );
84
-    }
85
-
86
-
87
-
88
-    /**
89
-     * @param boolean $iframe
90
-     */
91
-    public function setIframe( $iframe = true )
92
-    {
93
-        $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN );
94
-    }
95
-
96
-
97
-    /**
98
-     * finds and sets the \EE_Event object for use throughout class
99
-     *
100
-     * @param mixed $event
101
-     * @return bool
102
-     * @throws EE_Error
103
-     */
104
-    protected function setEvent( $event = null )
105
-    {
106
-        if ( $event === null ) {
107
-            global $post;
108
-            $event = $post;
109
-        }
110
-        if ( $event instanceof EE_Event ) {
111
-            $this->event = $event;
112
-        } else if ( $event instanceof WP_Post ) {
113
-            if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) {
114
-                $this->event = $event->EE_Event;
115
-            } else if ( $event->post_type === 'espresso_events' ) {
116
-                $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event );
117
-                $this->event = $event->EE_Event;
118
-            }
119
-        } else {
120
-            $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' );
121
-            $dev_msg = $user_msg . __(
122
-                    'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
123
-                    'event_espresso'
124
-                );
125
-            EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ );
126
-            return false;
127
-        }
128
-        return true;
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     * @return int
135
-     */
136
-    public function getMaxAttendees()
137
-    {
138
-        return $this->max_attendees;
139
-    }
140
-
141
-
142
-
143
-    /**
144
-     * @param int $max_attendees
145
-     */
146
-    public function setMaxAttendees($max_attendees)
147
-    {
148
-        $this->max_attendees = absint(
149
-            apply_filters(
150
-                'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
151
-                $max_attendees
152
-            )
153
-        );
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     * creates buttons for selecting number of attendees for an event
160
-     *
161
-     * @param WP_Post|int $event
162
-     * @param bool         $view_details
163
-     * @return string
164
-     * @throws EE_Error
165
-     */
166
-    public function display( $event = null, $view_details = false )
167
-    {
168
-        // reset filter for displaying submit button
169
-        remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' );
170
-        // poke and prod incoming event till it tells us what it is
171
-        if ( ! $this->setEvent( $event ) ) {
172
-            return false;
173
-        }
174
-        // begin gathering template arguments by getting event status
175
-        $template_args = array( 'event_status' => $this->event->get_active_status() );
176
-        if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) {
177
-            return ! is_single() ? $this->displayViewDetailsButton() : '';
178
-        }
179
-        // filter the maximum qty that can appear in the Ticket Selector qty dropdowns
180
-        $this->setMaxAttendees($this->event->additional_limit());
181
-        if ($this->getMaxAttendees() < 1) {
182
-            return $this->ticketSalesClosedMessage();
183
-        }
184
-        // is the event expired ?
185
-        $template_args['event_is_expired'] = $this->event->is_expired();
186
-        if ( $template_args[ 'event_is_expired' ] ) {
187
-            return $this->expiredEventMessage();
188
-        }
189
-        // get all tickets for this event ordered by the datetime
190
-        $tickets = $this->getTickets();
191
-        if (count($tickets) < 1) {
192
-            return $this->noTicketAvailableMessage();
193
-        }
194
-        if (EED_Events_Archive::is_iframe()){
195
-            $this->setIframe();
196
-        }
197
-        // redirecting to another site for registration ??
198
-        $external_url = (string) $this->event->external_url();
199
-        // if redirecting to another site for registration, then we don't load the TS
200
-        $ticket_selector = $external_url
201
-            ? $this->externalEventRegistration()
202
-            : $this->loadTicketSelector($tickets,$template_args);
203
-        // now set up the form (but not for the admin)
204
-        $ticket_selector = ! is_admin()
205
-            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
206
-            : $ticket_selector;
207
-        // submit button and form close tag
208
-        $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : '';
209
-        return $ticket_selector;
210
-    }
211
-
212
-
213
-
214
-    /**
215
-     * displayTicketSelector
216
-     * examines the event properties and determines whether a Ticket Selector should be displayed
217
-     *
218
-     * @param WP_Post|int $event
219
-     * @param string       $_event_active_status
220
-     * @param bool         $view_details
221
-     * @return bool
222
-     * @throws EE_Error
223
-     */
224
-    protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
225
-    {
226
-        $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
227
-        return ! is_admin()
228
-               && (
229
-                   ! $this->event->display_ticket_selector()
230
-                   || $view_details
231
-                   || post_password_required($event_post)
232
-                   || (
233
-                       $_event_active_status !== EE_Datetime::active
234
-                       && $_event_active_status !== EE_Datetime::upcoming
235
-                       && $_event_active_status !== EE_Datetime::sold_out
236
-                       && ! (
237
-                           $_event_active_status === EE_Datetime::inactive
238
-                           && is_user_logged_in()
239
-                       )
240
-                   )
241
-               );
242
-    }
243
-
244
-
245
-
246
-    /**
247
-     * noTicketAvailableMessage
248
-     * notice displayed if event is expired
249
-     *
250
-     * @return string
251
-     * @throws EE_Error
252
-     */
253
-    protected function expiredEventMessage()
254
-    {
255
-        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
256
-            'We\'re sorry, but all tickets sales have ended because the event is expired.',
257
-            'event_espresso'
258
-        ) . '</span></div><!-- .ee-event-expired-notice -->';
259
-    }
260
-
261
-
262
-
263
-    /**
264
-     * noTicketAvailableMessage
265
-     * notice displayed if event has no more tickets available
266
-     *
267
-     * @return string
268
-     * @throws EE_Error
269
-     */
270
-    protected function noTicketAvailableMessage()
271
-    {
272
-        $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' );
273
-        if (current_user_can('edit_post', $this->event->ID())) {
274
-            $no_ticket_available_msg .= sprintf(
275
-                esc_html__(
276
-                    '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
277
-                    'event_espresso'
278
-                ),
279
-                '<div class="ee-attention" style="text-align: left;"><b>',
280
-                '</b><br />',
281
-                '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',
282
-                '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
283
-            );
284
-        }
285
-        return '
37
+	/**
38
+	 * event that ticket selector is being generated for
39
+	 *
40
+	 * @access protected
41
+	 * @var EE_Event $event
42
+	 */
43
+	protected $event;
44
+
45
+	/**
46
+	 * Used to flag when the ticket selector is being called from an external iframe.
47
+	 *
48
+	 * @var bool $iframe
49
+	 */
50
+	protected $iframe = false;
51
+
52
+	/**
53
+	 * max attendees that can register for event at one time
54
+	 *
55
+	 * @var int $max_attendees
56
+	 */
57
+	private $max_attendees = EE_INF;
58
+
59
+	/**
60
+	 *@var string $date_format
61
+	 */
62
+	private $date_format;
63
+
64
+	/**
65
+	 *@var string $time_format
66
+	 */
67
+	private $time_format;
68
+
69
+
70
+
71
+	/**
72
+	 * DisplayTicketSelector constructor.
73
+	 */
74
+	public function __construct()
75
+	{
76
+		$this->date_format = apply_filters(
77
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
78
+			get_option('date_format')
79
+		);
80
+		$this->time_format = apply_filters(
81
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
82
+			get_option('time_format')
83
+		);
84
+	}
85
+
86
+
87
+
88
+	/**
89
+	 * @param boolean $iframe
90
+	 */
91
+	public function setIframe( $iframe = true )
92
+	{
93
+		$this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN );
94
+	}
95
+
96
+
97
+	/**
98
+	 * finds and sets the \EE_Event object for use throughout class
99
+	 *
100
+	 * @param mixed $event
101
+	 * @return bool
102
+	 * @throws EE_Error
103
+	 */
104
+	protected function setEvent( $event = null )
105
+	{
106
+		if ( $event === null ) {
107
+			global $post;
108
+			$event = $post;
109
+		}
110
+		if ( $event instanceof EE_Event ) {
111
+			$this->event = $event;
112
+		} else if ( $event instanceof WP_Post ) {
113
+			if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) {
114
+				$this->event = $event->EE_Event;
115
+			} else if ( $event->post_type === 'espresso_events' ) {
116
+				$event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event );
117
+				$this->event = $event->EE_Event;
118
+			}
119
+		} else {
120
+			$user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' );
121
+			$dev_msg = $user_msg . __(
122
+					'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
123
+					'event_espresso'
124
+				);
125
+			EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ );
126
+			return false;
127
+		}
128
+		return true;
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 * @return int
135
+	 */
136
+	public function getMaxAttendees()
137
+	{
138
+		return $this->max_attendees;
139
+	}
140
+
141
+
142
+
143
+	/**
144
+	 * @param int $max_attendees
145
+	 */
146
+	public function setMaxAttendees($max_attendees)
147
+	{
148
+		$this->max_attendees = absint(
149
+			apply_filters(
150
+				'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
151
+				$max_attendees
152
+			)
153
+		);
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 * creates buttons for selecting number of attendees for an event
160
+	 *
161
+	 * @param WP_Post|int $event
162
+	 * @param bool         $view_details
163
+	 * @return string
164
+	 * @throws EE_Error
165
+	 */
166
+	public function display( $event = null, $view_details = false )
167
+	{
168
+		// reset filter for displaying submit button
169
+		remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' );
170
+		// poke and prod incoming event till it tells us what it is
171
+		if ( ! $this->setEvent( $event ) ) {
172
+			return false;
173
+		}
174
+		// begin gathering template arguments by getting event status
175
+		$template_args = array( 'event_status' => $this->event->get_active_status() );
176
+		if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) {
177
+			return ! is_single() ? $this->displayViewDetailsButton() : '';
178
+		}
179
+		// filter the maximum qty that can appear in the Ticket Selector qty dropdowns
180
+		$this->setMaxAttendees($this->event->additional_limit());
181
+		if ($this->getMaxAttendees() < 1) {
182
+			return $this->ticketSalesClosedMessage();
183
+		}
184
+		// is the event expired ?
185
+		$template_args['event_is_expired'] = $this->event->is_expired();
186
+		if ( $template_args[ 'event_is_expired' ] ) {
187
+			return $this->expiredEventMessage();
188
+		}
189
+		// get all tickets for this event ordered by the datetime
190
+		$tickets = $this->getTickets();
191
+		if (count($tickets) < 1) {
192
+			return $this->noTicketAvailableMessage();
193
+		}
194
+		if (EED_Events_Archive::is_iframe()){
195
+			$this->setIframe();
196
+		}
197
+		// redirecting to another site for registration ??
198
+		$external_url = (string) $this->event->external_url();
199
+		// if redirecting to another site for registration, then we don't load the TS
200
+		$ticket_selector = $external_url
201
+			? $this->externalEventRegistration()
202
+			: $this->loadTicketSelector($tickets,$template_args);
203
+		// now set up the form (but not for the admin)
204
+		$ticket_selector = ! is_admin()
205
+			? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
206
+			: $ticket_selector;
207
+		// submit button and form close tag
208
+		$ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : '';
209
+		return $ticket_selector;
210
+	}
211
+
212
+
213
+
214
+	/**
215
+	 * displayTicketSelector
216
+	 * examines the event properties and determines whether a Ticket Selector should be displayed
217
+	 *
218
+	 * @param WP_Post|int $event
219
+	 * @param string       $_event_active_status
220
+	 * @param bool         $view_details
221
+	 * @return bool
222
+	 * @throws EE_Error
223
+	 */
224
+	protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
225
+	{
226
+		$event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
227
+		return ! is_admin()
228
+			   && (
229
+				   ! $this->event->display_ticket_selector()
230
+				   || $view_details
231
+				   || post_password_required($event_post)
232
+				   || (
233
+					   $_event_active_status !== EE_Datetime::active
234
+					   && $_event_active_status !== EE_Datetime::upcoming
235
+					   && $_event_active_status !== EE_Datetime::sold_out
236
+					   && ! (
237
+						   $_event_active_status === EE_Datetime::inactive
238
+						   && is_user_logged_in()
239
+					   )
240
+				   )
241
+			   );
242
+	}
243
+
244
+
245
+
246
+	/**
247
+	 * noTicketAvailableMessage
248
+	 * notice displayed if event is expired
249
+	 *
250
+	 * @return string
251
+	 * @throws EE_Error
252
+	 */
253
+	protected function expiredEventMessage()
254
+	{
255
+		return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
256
+			'We\'re sorry, but all tickets sales have ended because the event is expired.',
257
+			'event_espresso'
258
+		) . '</span></div><!-- .ee-event-expired-notice -->';
259
+	}
260
+
261
+
262
+
263
+	/**
264
+	 * noTicketAvailableMessage
265
+	 * notice displayed if event has no more tickets available
266
+	 *
267
+	 * @return string
268
+	 * @throws EE_Error
269
+	 */
270
+	protected function noTicketAvailableMessage()
271
+	{
272
+		$no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' );
273
+		if (current_user_can('edit_post', $this->event->ID())) {
274
+			$no_ticket_available_msg .= sprintf(
275
+				esc_html__(
276
+					'%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
277
+					'event_espresso'
278
+				),
279
+				'<div class="ee-attention" style="text-align: left;"><b>',
280
+				'</b><br />',
281
+				'<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',
282
+				'</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
283
+			);
284
+		}
285
+		return '
286 286
             <div class="ee-event-expired-notice">
287 287
                 <span class="important-notice">' . $no_ticket_available_msg . '</span>
288 288
             </div><!-- .ee-event-expired-notice -->';
289
-    }
290
-
291
-
292
-
293
-    /**
294
-     * ticketSalesClosed
295
-     * notice displayed if event ticket sales are turned off
296
-     *
297
-     * @return string
298
-     * @throws EE_Error
299
-     */
300
-    protected function ticketSalesClosedMessage()
301
-    {
302
-        $sales_closed_msg = esc_html__(
303
-            'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
304
-            'event_espresso'
305
-        );
306
-        if (current_user_can('edit_post', $this->event->ID())) {
307
-            $sales_closed_msg .= sprintf(
308
-                esc_html__(
309
-                    '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
310
-                    'event_espresso'
311
-                ),
312
-                '<div class="ee-attention" style="text-align: left;"><b>',
313
-                '</b><br />',
314
-                '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',
315
-                '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
316
-            );
317
-        }
318
-        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
319
-    }
320
-
321
-
322
-
323
-    /**
324
-     * getTickets
325
-     *
326
-     * @return \EE_Base_Class[]|\EE_Ticket[]
327
-     * @throws EE_Error
328
-     */
329
-    protected function getTickets()
330
-    {
331
-        $ticket_query_args = array(
332
-            array('Datetime.EVT_ID' => $this->event->ID()),
333
-            'order_by' => array(
334
-                'TKT_order'              => 'ASC',
335
-                'TKT_required'           => 'DESC',
336
-                'TKT_start_date'         => 'ASC',
337
-                'TKT_end_date'           => 'ASC',
338
-                'Datetime.DTT_EVT_start' => 'DESC',
339
-            ),
340
-        );
341
-        if (
342
-            ! (
343
-                EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
344
-                && EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets
345
-            )
346
-        ) {
347
-            //use the correct applicable time query depending on what version of core is being run.
348
-            $current_time = method_exists('EEM_Datetime', 'current_time_for_query')
349
-                ? time()
350
-                : current_time('timestamp');
351
-            $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
352
-        }
353
-        return EEM_Ticket::instance()->get_all($ticket_query_args);
354
-    }
355
-
356
-
357
-
358
-    /**
359
-     * loadTicketSelector
360
-     * begins to assemble template arguments
361
-     * and decides whether to load a "simple" ticket selector, or the standard
362
-     *
363
-     * @param \EE_Ticket[] $tickets
364
-     * @param array $template_args
365
-     * @return string
366
-     * @throws EE_Error
367
-     */
368
-    protected function loadTicketSelector(array $tickets, array $template_args)
369
-    {
370
-        $template_args['event'] = $this->event;
371
-        $template_args['EVT_ID'] = $this->event->ID();
372
-        $template_args['event_is_expired'] = $this->event->is_expired();
373
-        $template_args['max_atndz'] = $this->getMaxAttendees();
374
-        $template_args['date_format'] = $this->date_format;
375
-        $template_args['time_format'] = $this->time_format;
376
-        /**
377
-         * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
378
-         *
379
-         * @since 4.9.13
380
-         * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
381
-         * @param int $EVT_ID The Event ID
382
-         */
383
-        $template_args['anchor_id'] = apply_filters(
384
-            'FHEE__EE_Ticket_Selector__redirect_anchor_id',
385
-            '#tkt-slctr-tbl-' . $this->event->ID(),
386
-            $this->event->ID()
387
-        );
388
-        $template_args['tickets'] = $tickets;
389
-        $template_args['ticket_count'] = count($tickets);
390
-        $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args);
391
-        return $ticket_selector instanceof TicketSelectorSimple
392
-            ? $ticket_selector
393
-            : new TicketSelectorStandard(
394
-                $this->event,
395
-                $tickets,
396
-                $this->getMaxAttendees(),
397
-                $template_args,
398
-                $this->date_format,
399
-                $this->time_format
400
-            );
401
-    }
402
-
403
-
404
-
405
-    /**
406
-     * simpleTicketSelector
407
-     * there's one ticket, and max attendees is set to one,
408
-     * so if the event is free, then this is a "simple" ticket selector
409
-     * a.k.a. "Dude Where's my Ticket Selector?"
410
-     *
411
-     * @param \EE_Ticket[] $tickets
412
-     * @param array  $template_args
413
-     * @return string
414
-     * @throws EE_Error
415
-     */
416
-    protected function simpleTicketSelector($tickets, array $template_args)
417
-    {
418
-        // if there is only ONE ticket with a max qty of ONE
419
-        if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
420
-            return '';
421
-        }
422
-        /** @var \EE_Ticket $ticket */
423
-        $ticket = reset($tickets);
424
-        // if the ticket is free... then not much need for the ticket selector
425
-        if (
426
-            apply_filters(
427
-                'FHEE__ticket_selector_chart_template__hide_ticket_selector',
428
-                $ticket->is_free(),
429
-                $this->event->ID()
430
-            )
431
-        ) {
432
-            return new TicketSelectorSimple(
433
-                $this->event,
434
-                $ticket,
435
-                $this->getMaxAttendees(),
436
-                $template_args
437
-            );
438
-        }
439
-        return '';
440
-    }
441
-
442
-
443
-
444
-    /**
445
-     * externalEventRegistration
446
-     *
447
-     * @return string
448
-     */
449
-    public function externalEventRegistration()
450
-    {
451
-        // if not we still need to trigger the display of the submit button
452
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
453
-        //display notice to admin that registration is external
454
-        return is_admin()
455
-            ? esc_html__(
456
-                'Registration is at an external URL for this event.',
457
-                'event_espresso'
458
-            )
459
-            : '';
460
-    }
461
-
462
-
463
-
464
-    /**
465
-     * formOpen
466
-     *
467
-     * @param        int    $ID
468
-     * @param        string $external_url
469
-     * @return        string
470
-     */
471
-    public function formOpen( $ID = 0, $external_url = '' )
472
-    {
473
-        // if redirecting, we don't need any anything else
474
-        if ( $external_url ) {
475
-            $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"';
476
-            // open link in new window ?
477
-            $html .= apply_filters(
478
-                'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
479
-                EED_Events_Archive::is_iframe()
480
-            )
481
-                ? ' target="_blank"'
482
-                : '';
483
-            $html .= '>';
484
-            $query_args = EEH_URL::get_query_string( $external_url );
485
-            foreach ( (array)$query_args as $query_arg => $value ) {
486
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
487
-            }
488
-            return $html;
489
-        }
490
-        // if there is no submit button, then don't start building a form
491
-        // because the "View Details" button will build its own form
492
-        if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) {
493
-            return '';
494
-        }
495
-        $checkout_url = EEH_Event_View::event_link_url( $ID );
496
-        if ( ! $checkout_url ) {
497
-            EE_Error::add_error(
498
-                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
499
-                __FILE__,
500
-                __FUNCTION__,
501
-                __LINE__
502
-            );
503
-        }
504
-        // set no cache headers and constants
505
-        EE_System::do_not_cache();
506
-        $extra_params = $this->iframe ? ' target="_blank"' : '';
507
-        $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
508
-        $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
509
-        $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event );
510
-        return $html;
511
-    }
512
-
513
-
514
-
515
-    /**
516
-     * displaySubmitButton
517
-     *
518
-     * @param  string $external_url
519
-     * @return string
520
-     * @throws EE_Error
521
-     */
522
-    public function displaySubmitButton($external_url = '')
523
-    {
524
-        $html = '';
525
-        if ( ! is_admin()) {
526
-            // standard TS displayed with submit button, ie: "Register Now"
527
-            if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
528
-                $html .= $this->displayRegisterNowButton();
529
-                $html .= empty($external_url)
530
-                    ? $this->ticketSelectorEndDiv()
531
-                    : $this->clearTicketSelector();
532
-                $html .= '<br/>' . $this->formClose();
533
-            } else if ($this->getMaxAttendees() === 1) {
534
-                // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
535
-                if ($this->event->is_sold_out()) {
536
-                    // then instead of a View Details or Submit button, just display a "Sold Out" message
537
-                    $html .= apply_filters(
538
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
539
-                        sprintf(
540
-                            __(
541
-                                '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
542
-                                'event_espresso'
543
-                            ),
544
-                            '<p class="no-ticket-selector-msg clear-float">',
545
-                            $this->event->name(),
546
-                            '</p>',
547
-                            '<br />'
548
-                        ),
549
-                        $this->event
550
-                    );
551
-                    if (
552
-                        apply_filters(
553
-                            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
554
-                            false,
555
-                            $this->event
556
-                        )
557
-                    ) {
558
-                        $html .= $this->displayRegisterNowButton();
559
-                    }
560
-                    // sold out DWMTS event, no TS, no submit or view details button, but has additional content
561
-                    $html .=  $this->ticketSelectorEndDiv();
562
-                } else if (
563
-                    apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
564
-                    && ! is_single()
565
-                ) {
566
-                    // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
567
-                    // but no tickets are available, so display event's "View Details" button.
568
-                    // it is being viewed via somewhere other than a single post
569
-                    $html .= $this->displayViewDetailsButton(true);
570
-                } else {
571
-                    $html .= $this->ticketSelectorEndDiv();
572
-                }
573
-            } else if (is_archive()) {
574
-                // event list, no tickets available so display event's "View Details" button
575
-                $html .= $this->ticketSelectorEndDiv();
576
-                $html .= $this->displayViewDetailsButton();
577
-            } else {
578
-                if (
579
-                    apply_filters(
580
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
581
-                        false,
582
-                        $this->event
583
-                    )
584
-                ) {
585
-                    $html .= $this->displayRegisterNowButton();
586
-                }
587
-                // no submit or view details button, and no additional content
588
-                $html .= $this->ticketSelectorEndDiv();
589
-            }
590
-            if ( ! $this->iframe && ! is_archive()) {
591
-                $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
592
-            }
593
-        }
594
-	    return apply_filters(
595
-		    'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
596
-		    $html,
597
-		    $this->event
598
-	    );
599
-    }
600
-
601
-
602
-
603
-    /**
604
-     * @return string
605
-     * @throws EE_Error
606
-     */
607
-    public function displayRegisterNowButton()
608
-    {
609
-        $btn_text = apply_filters(
610
-            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
611
-            __('Register Now', 'event_espresso'),
612
-            $this->event
613
-        );
614
-        $external_url = $this->event->external_url();
615
-        $html = EEH_HTML::div(
616
-            '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap'
617
-        );
618
-        $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
619
-        $html .= ' class="ticket-selector-submit-btn ';
620
-        $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
621
-        $html .= ' type="submit" value="' . $btn_text . '" />';
622
-        $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
623
-        $html .= apply_filters(
624
-            'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
625
-            '',
626
-            $this->event
627
-        );
628
-        return $html;
629
-    }
630
-
631
-
632
-    /**
633
-     * displayViewDetailsButton
634
-     *
635
-     * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
636
-     *                    (ie: $_max_atndz === 1) where there are no available tickets,
637
-     *                    either because they are sold out, expired, or not yet on sale.
638
-     *                    In this case, we need to close the form BEFORE adding any closing divs
639
-     * @return string
640
-     * @throws EE_Error
641
-     */
642
-    public function displayViewDetailsButton( $DWMTS = false )
643
-    {
644
-        if ( ! $this->event->get_permalink() ) {
645
-            EE_Error::add_error(
646
-                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
647
-                __FILE__, __FUNCTION__, __LINE__
648
-            );
649
-        }
650
-        $view_details_btn = '<form method="POST" action="';
651
-        $view_details_btn .= apply_filters(
652
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
653
-            $this->event->get_permalink(),
654
-            $this->event
655
-        );
656
-        $view_details_btn .= '"';
657
-        // open link in new window ?
658
-        $view_details_btn .= apply_filters(
659
-            'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
660
-            EED_Events_Archive::is_iframe()
661
-        )
662
-            ? ' target="_blank"'
663
-            : '';
664
-        $view_details_btn .='>';
665
-        $btn_text = apply_filters(
666
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
667
-            esc_html__('View Details', 'event_espresso'),
668
-            $this->event
669
-        );
670
-        $view_details_btn .= '<input id="ticket-selector-submit-'
671
-                             . $this->event->ID()
672
-                             . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
673
-                             . $btn_text
674
-                             . '" />';
675
-        $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event );
676
-        if ($DWMTS) {
677
-            $view_details_btn .= $this->formClose();
678
-            $view_details_btn .= $this->ticketSelectorEndDiv();
679
-            $view_details_btn .= '<br/>';
680
-        } else {
681
-            $view_details_btn .= $this->clearTicketSelector();
682
-            $view_details_btn .= '<br/>';
683
-            $view_details_btn .= $this->formClose();
684
-        }
685
-        return $view_details_btn;
686
-    }
687
-
688
-
689
-
690
-    /**
691
-     * @return string
692
-     */
693
-    public function ticketSelectorEndDiv()
694
-    {
695
-        return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
696
-    }
697
-
698
-
699
-
700
-    /**
701
-     * @return string
702
-     */
703
-    public function clearTicketSelector()
704
-    {
705
-        // standard TS displayed, appears after a "Register Now" or "view Details" button
706
-        return '<div class="clear"></div><!-- clearTicketSelector -->';
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     * @access        public
713
-     * @return        string
714
-     */
715
-    public function formClose()
716
-    {
717
-        return '</form>';
718
-    }
289
+	}
290
+
291
+
292
+
293
+	/**
294
+	 * ticketSalesClosed
295
+	 * notice displayed if event ticket sales are turned off
296
+	 *
297
+	 * @return string
298
+	 * @throws EE_Error
299
+	 */
300
+	protected function ticketSalesClosedMessage()
301
+	{
302
+		$sales_closed_msg = esc_html__(
303
+			'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
304
+			'event_espresso'
305
+		);
306
+		if (current_user_can('edit_post', $this->event->ID())) {
307
+			$sales_closed_msg .= sprintf(
308
+				esc_html__(
309
+					'%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
310
+					'event_espresso'
311
+				),
312
+				'<div class="ee-attention" style="text-align: left;"><b>',
313
+				'</b><br />',
314
+				'<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',
315
+				'</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
316
+			);
317
+		}
318
+		return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
319
+	}
320
+
321
+
322
+
323
+	/**
324
+	 * getTickets
325
+	 *
326
+	 * @return \EE_Base_Class[]|\EE_Ticket[]
327
+	 * @throws EE_Error
328
+	 */
329
+	protected function getTickets()
330
+	{
331
+		$ticket_query_args = array(
332
+			array('Datetime.EVT_ID' => $this->event->ID()),
333
+			'order_by' => array(
334
+				'TKT_order'              => 'ASC',
335
+				'TKT_required'           => 'DESC',
336
+				'TKT_start_date'         => 'ASC',
337
+				'TKT_end_date'           => 'ASC',
338
+				'Datetime.DTT_EVT_start' => 'DESC',
339
+			),
340
+		);
341
+		if (
342
+			! (
343
+				EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
344
+				&& EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets
345
+			)
346
+		) {
347
+			//use the correct applicable time query depending on what version of core is being run.
348
+			$current_time = method_exists('EEM_Datetime', 'current_time_for_query')
349
+				? time()
350
+				: current_time('timestamp');
351
+			$ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
352
+		}
353
+		return EEM_Ticket::instance()->get_all($ticket_query_args);
354
+	}
355
+
356
+
357
+
358
+	/**
359
+	 * loadTicketSelector
360
+	 * begins to assemble template arguments
361
+	 * and decides whether to load a "simple" ticket selector, or the standard
362
+	 *
363
+	 * @param \EE_Ticket[] $tickets
364
+	 * @param array $template_args
365
+	 * @return string
366
+	 * @throws EE_Error
367
+	 */
368
+	protected function loadTicketSelector(array $tickets, array $template_args)
369
+	{
370
+		$template_args['event'] = $this->event;
371
+		$template_args['EVT_ID'] = $this->event->ID();
372
+		$template_args['event_is_expired'] = $this->event->is_expired();
373
+		$template_args['max_atndz'] = $this->getMaxAttendees();
374
+		$template_args['date_format'] = $this->date_format;
375
+		$template_args['time_format'] = $this->time_format;
376
+		/**
377
+		 * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
378
+		 *
379
+		 * @since 4.9.13
380
+		 * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
381
+		 * @param int $EVT_ID The Event ID
382
+		 */
383
+		$template_args['anchor_id'] = apply_filters(
384
+			'FHEE__EE_Ticket_Selector__redirect_anchor_id',
385
+			'#tkt-slctr-tbl-' . $this->event->ID(),
386
+			$this->event->ID()
387
+		);
388
+		$template_args['tickets'] = $tickets;
389
+		$template_args['ticket_count'] = count($tickets);
390
+		$ticket_selector = $this->simpleTicketSelector( $tickets, $template_args);
391
+		return $ticket_selector instanceof TicketSelectorSimple
392
+			? $ticket_selector
393
+			: new TicketSelectorStandard(
394
+				$this->event,
395
+				$tickets,
396
+				$this->getMaxAttendees(),
397
+				$template_args,
398
+				$this->date_format,
399
+				$this->time_format
400
+			);
401
+	}
402
+
403
+
404
+
405
+	/**
406
+	 * simpleTicketSelector
407
+	 * there's one ticket, and max attendees is set to one,
408
+	 * so if the event is free, then this is a "simple" ticket selector
409
+	 * a.k.a. "Dude Where's my Ticket Selector?"
410
+	 *
411
+	 * @param \EE_Ticket[] $tickets
412
+	 * @param array  $template_args
413
+	 * @return string
414
+	 * @throws EE_Error
415
+	 */
416
+	protected function simpleTicketSelector($tickets, array $template_args)
417
+	{
418
+		// if there is only ONE ticket with a max qty of ONE
419
+		if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
420
+			return '';
421
+		}
422
+		/** @var \EE_Ticket $ticket */
423
+		$ticket = reset($tickets);
424
+		// if the ticket is free... then not much need for the ticket selector
425
+		if (
426
+			apply_filters(
427
+				'FHEE__ticket_selector_chart_template__hide_ticket_selector',
428
+				$ticket->is_free(),
429
+				$this->event->ID()
430
+			)
431
+		) {
432
+			return new TicketSelectorSimple(
433
+				$this->event,
434
+				$ticket,
435
+				$this->getMaxAttendees(),
436
+				$template_args
437
+			);
438
+		}
439
+		return '';
440
+	}
441
+
442
+
443
+
444
+	/**
445
+	 * externalEventRegistration
446
+	 *
447
+	 * @return string
448
+	 */
449
+	public function externalEventRegistration()
450
+	{
451
+		// if not we still need to trigger the display of the submit button
452
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
453
+		//display notice to admin that registration is external
454
+		return is_admin()
455
+			? esc_html__(
456
+				'Registration is at an external URL for this event.',
457
+				'event_espresso'
458
+			)
459
+			: '';
460
+	}
461
+
462
+
463
+
464
+	/**
465
+	 * formOpen
466
+	 *
467
+	 * @param        int    $ID
468
+	 * @param        string $external_url
469
+	 * @return        string
470
+	 */
471
+	public function formOpen( $ID = 0, $external_url = '' )
472
+	{
473
+		// if redirecting, we don't need any anything else
474
+		if ( $external_url ) {
475
+			$html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"';
476
+			// open link in new window ?
477
+			$html .= apply_filters(
478
+				'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
479
+				EED_Events_Archive::is_iframe()
480
+			)
481
+				? ' target="_blank"'
482
+				: '';
483
+			$html .= '>';
484
+			$query_args = EEH_URL::get_query_string( $external_url );
485
+			foreach ( (array)$query_args as $query_arg => $value ) {
486
+				$html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
487
+			}
488
+			return $html;
489
+		}
490
+		// if there is no submit button, then don't start building a form
491
+		// because the "View Details" button will build its own form
492
+		if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) {
493
+			return '';
494
+		}
495
+		$checkout_url = EEH_Event_View::event_link_url( $ID );
496
+		if ( ! $checkout_url ) {
497
+			EE_Error::add_error(
498
+				esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
499
+				__FILE__,
500
+				__FUNCTION__,
501
+				__LINE__
502
+			);
503
+		}
504
+		// set no cache headers and constants
505
+		EE_System::do_not_cache();
506
+		$extra_params = $this->iframe ? ' target="_blank"' : '';
507
+		$html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
508
+		$html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
509
+		$html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event );
510
+		return $html;
511
+	}
512
+
513
+
514
+
515
+	/**
516
+	 * displaySubmitButton
517
+	 *
518
+	 * @param  string $external_url
519
+	 * @return string
520
+	 * @throws EE_Error
521
+	 */
522
+	public function displaySubmitButton($external_url = '')
523
+	{
524
+		$html = '';
525
+		if ( ! is_admin()) {
526
+			// standard TS displayed with submit button, ie: "Register Now"
527
+			if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
528
+				$html .= $this->displayRegisterNowButton();
529
+				$html .= empty($external_url)
530
+					? $this->ticketSelectorEndDiv()
531
+					: $this->clearTicketSelector();
532
+				$html .= '<br/>' . $this->formClose();
533
+			} else if ($this->getMaxAttendees() === 1) {
534
+				// its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
535
+				if ($this->event->is_sold_out()) {
536
+					// then instead of a View Details or Submit button, just display a "Sold Out" message
537
+					$html .= apply_filters(
538
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
539
+						sprintf(
540
+							__(
541
+								'%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
542
+								'event_espresso'
543
+							),
544
+							'<p class="no-ticket-selector-msg clear-float">',
545
+							$this->event->name(),
546
+							'</p>',
547
+							'<br />'
548
+						),
549
+						$this->event
550
+					);
551
+					if (
552
+						apply_filters(
553
+							'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
554
+							false,
555
+							$this->event
556
+						)
557
+					) {
558
+						$html .= $this->displayRegisterNowButton();
559
+					}
560
+					// sold out DWMTS event, no TS, no submit or view details button, but has additional content
561
+					$html .=  $this->ticketSelectorEndDiv();
562
+				} else if (
563
+					apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
564
+					&& ! is_single()
565
+				) {
566
+					// this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
567
+					// but no tickets are available, so display event's "View Details" button.
568
+					// it is being viewed via somewhere other than a single post
569
+					$html .= $this->displayViewDetailsButton(true);
570
+				} else {
571
+					$html .= $this->ticketSelectorEndDiv();
572
+				}
573
+			} else if (is_archive()) {
574
+				// event list, no tickets available so display event's "View Details" button
575
+				$html .= $this->ticketSelectorEndDiv();
576
+				$html .= $this->displayViewDetailsButton();
577
+			} else {
578
+				if (
579
+					apply_filters(
580
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
581
+						false,
582
+						$this->event
583
+					)
584
+				) {
585
+					$html .= $this->displayRegisterNowButton();
586
+				}
587
+				// no submit or view details button, and no additional content
588
+				$html .= $this->ticketSelectorEndDiv();
589
+			}
590
+			if ( ! $this->iframe && ! is_archive()) {
591
+				$html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
592
+			}
593
+		}
594
+		return apply_filters(
595
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
596
+			$html,
597
+			$this->event
598
+		);
599
+	}
600
+
601
+
602
+
603
+	/**
604
+	 * @return string
605
+	 * @throws EE_Error
606
+	 */
607
+	public function displayRegisterNowButton()
608
+	{
609
+		$btn_text = apply_filters(
610
+			'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
611
+			__('Register Now', 'event_espresso'),
612
+			$this->event
613
+		);
614
+		$external_url = $this->event->external_url();
615
+		$html = EEH_HTML::div(
616
+			'', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap'
617
+		);
618
+		$html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
619
+		$html .= ' class="ticket-selector-submit-btn ';
620
+		$html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
621
+		$html .= ' type="submit" value="' . $btn_text . '" />';
622
+		$html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
623
+		$html .= apply_filters(
624
+			'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
625
+			'',
626
+			$this->event
627
+		);
628
+		return $html;
629
+	}
630
+
631
+
632
+	/**
633
+	 * displayViewDetailsButton
634
+	 *
635
+	 * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
636
+	 *                    (ie: $_max_atndz === 1) where there are no available tickets,
637
+	 *                    either because they are sold out, expired, or not yet on sale.
638
+	 *                    In this case, we need to close the form BEFORE adding any closing divs
639
+	 * @return string
640
+	 * @throws EE_Error
641
+	 */
642
+	public function displayViewDetailsButton( $DWMTS = false )
643
+	{
644
+		if ( ! $this->event->get_permalink() ) {
645
+			EE_Error::add_error(
646
+				esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
647
+				__FILE__, __FUNCTION__, __LINE__
648
+			);
649
+		}
650
+		$view_details_btn = '<form method="POST" action="';
651
+		$view_details_btn .= apply_filters(
652
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
653
+			$this->event->get_permalink(),
654
+			$this->event
655
+		);
656
+		$view_details_btn .= '"';
657
+		// open link in new window ?
658
+		$view_details_btn .= apply_filters(
659
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
660
+			EED_Events_Archive::is_iframe()
661
+		)
662
+			? ' target="_blank"'
663
+			: '';
664
+		$view_details_btn .='>';
665
+		$btn_text = apply_filters(
666
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
667
+			esc_html__('View Details', 'event_espresso'),
668
+			$this->event
669
+		);
670
+		$view_details_btn .= '<input id="ticket-selector-submit-'
671
+							 . $this->event->ID()
672
+							 . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
673
+							 . $btn_text
674
+							 . '" />';
675
+		$view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event );
676
+		if ($DWMTS) {
677
+			$view_details_btn .= $this->formClose();
678
+			$view_details_btn .= $this->ticketSelectorEndDiv();
679
+			$view_details_btn .= '<br/>';
680
+		} else {
681
+			$view_details_btn .= $this->clearTicketSelector();
682
+			$view_details_btn .= '<br/>';
683
+			$view_details_btn .= $this->formClose();
684
+		}
685
+		return $view_details_btn;
686
+	}
687
+
688
+
689
+
690
+	/**
691
+	 * @return string
692
+	 */
693
+	public function ticketSelectorEndDiv()
694
+	{
695
+		return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
696
+	}
697
+
698
+
699
+
700
+	/**
701
+	 * @return string
702
+	 */
703
+	public function clearTicketSelector()
704
+	{
705
+		// standard TS displayed, appears after a "Register Now" or "view Details" button
706
+		return '<div class="clear"></div><!-- clearTicketSelector -->';
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 * @access        public
713
+	 * @return        string
714
+	 */
715
+	public function formClose()
716
+	{
717
+		return '</form>';
718
+	}
719 719
 
720 720
 
721 721
 
Please login to merge, or discard this patch.
core/domain/entities/shortcodes/EspressoEventAttendees.php 2 patches
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -29,266 +29,266 @@
 block discarded – undo
29 29
 class EspressoEventAttendees extends EspressoShortcode
30 30
 {
31 31
 
32
-    private $query_params = array(
33
-        0 => array()
34
-    );
35
-
36
-    private $template_args = array(
37
-        'contacts'      => array(),
38
-        'event'         => null,
39
-        'datetime'      => null,
40
-        'ticket'        => null,
41
-    );
42
-
43
-    /**
44
-     * the actual shortcode tag that gets registered with WordPress
45
-     *
46
-     * @return string
47
-     */
48
-    public function getTag()
49
-    {
50
-        return 'ESPRESSO_EVENT_ATTENDEES';
51
-    }
52
-
53
-
54
-
55
-    /**
56
-     * the time in seconds to cache the results of the processShortcode() method
57
-     * 0 means the processShortcode() results will NOT be cached at all
58
-     *
59
-     * @return int
60
-     */
61
-    public function cacheExpiration()
62
-    {
63
-        return 0;
64
-    }
65
-
66
-
67
-
68
-    /**
69
-     * a place for adding any initialization code that needs to run prior to wp_header().
70
-     * this may be required for shortcodes that utilize a corresponding module,
71
-     * and need to enqueue assets for that module
72
-     *
73
-     * @return void
74
-     */
75
-    public function initializeShortcode()
76
-    {
77
-        $this->shortcodeHasBeenInitialized();
78
-    }
79
-
80
-
81
-
82
-    /**
83
-     * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event.
84
-     *  [ESPRESSO_EVENT_ATTENDEES]
85
-     *  - defaults to attendees for earliest active event, or earliest upcoming event.
86
-     *
87
-     *  [ESPRESSO_EVENT_ATTENDEES event_id=123]
88
-     *  - attendees for specific event.
89
-     *
90
-     *  [ESPRESSO_EVENT_ATTENDEES datetime_id=245]
91
-     *  - attendees for a specific datetime.
92
-     *
93
-     *  [ESPRESSO_EVENT_ATTENDEES ticket_id=123]
94
-     *  - attendees for a specific ticket.
95
-     *
96
-     *  [ESPRESSO_EVENT_ATTENDEES status=all]
97
-     *  - specific registration status (use status id) or all for all attendees regardless of status.
98
-     *  Note default is to only return approved attendees
99
-     *
100
-     *  [ESPRESSO_EVENT_ATTENDEES show_gravatar=true]
101
-     *  - default is to not return gravatar.  Otherwise if this is set then return gravatar for email address given.
102
-     *
103
-     *  [ESPRESSO_EVENT_ATTENDEES display_on_archives=true]
104
-     *  - default is to not display attendees list on archive pages.
105
-     *
106
-     * Note: because of the relationship between event_id, ticket_id, and datetime_id:
107
-     * If more than one of those params is included, then preference is given to the following:
108
-     *  - event_id is used whenever its present and any others are ignored.
109
-     *  - if no event_id then datetime is used whenever its present and any others are ignored.
110
-     *  - otherwise ticket_id is used if present.
111
-     *
112
-     * @param array $attributes
113
-     * @return string
114
-     * @throws EE_Error
115
-     */
116
-    public function processShortcode($attributes = array())
117
-    {
118
-        // grab attributes and merge with defaults
119
-        $attributes = $this->getAttributes((array)$attributes);
120
-        $archive = is_archive();
121
-        $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN);
122
-        // don't display on archives unless 'display_on_archives' is true
123
-        if($archive && ! $display_on_archives) {
124
-            return '';
125
-        }
126
-        // add attributes to template args
127
-        $this->template_args['show_gravatar'] = $attributes['show_gravatar'];
128
-        // add required objects: event, datetime, and ticket
129
-        $this->template_args['event'] = $this->getEventAndQueryParams($attributes);
130
-        $this->template_args['datetime'] = $this->getDatetimeAndQueryParams($attributes);
131
-        $this->template_args['ticket'] = $this->getTicketAndQueryParams($attributes);
132
-
133
-        // if any of the above objects is invalid or missing,
134
-        // then there was an invalid parameter or the shortcode was used incorrectly
135
-        // so when WP_DEBUG is set and true, we'll show a message,
136
-        // otherwise we'll just return an empty string.
137
-         if (
138
-            ! $this->template_args['event'] instanceof EE_Event
139
-            || empty($this->query_params[0])
140
-            || ($attributes['datetime_id'] && ! $this->template_args['datetime'] instanceof EE_Datetime)
141
-            || ($attributes['ticket_id'] && ! $this->template_args['ticket'] instanceof EE_Ticket)
142
-        ) {
143
-            if (WP_DEBUG) {
144
-                return '<div class="important-notice ee-attention">'
145
-                       . esc_html__('The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly.  Please double check the arguments you used for any typos.  In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.',
146
-                        'event_espresso')
147
-                       . '</div>';
148
-            }
149
-             return '';
150
-        }
151
-        $this->setAdditionalQueryParams($attributes);
152
-        //get contacts!
153
-        $this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params);
154
-        //all set let's load up the template and return.
155
-        return EEH_Template::locate_template(
156
-            'loop-espresso_event_attendees.php',
157
-            $this->template_args
158
-        );
159
-
160
-    }
161
-
162
-
163
-
164
-    /**
165
-     * merge incoming attributes with filtered defaults
166
-     *
167
-     * @param array $attributes
168
-     * @return array
169
-     */
170
-    private function getAttributes(array $attributes)
171
-    {
172
-        return (array) apply_filters(
173
-            'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts',
174
-            $attributes + array(
175
-                'event_id'            => null,
176
-                'datetime_id'         => null,
177
-                'ticket_id'           => null,
178
-                'status'              => EEM_Registration::status_id_approved,
179
-                'show_gravatar'       => false,
180
-                'display_on_archives' => false,
181
-            )
182
-        );
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     * @param array $attributes
189
-     * @return EE_Event|null
190
-     * @throws EE_Error
191
-     */
192
-    private function getEventAndQueryParams(array $attributes){
193
-        if ( ! empty($attributes['event_id'])) {
194
-            $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']);
195
-            if ($event instanceof EE_Event) {
196
-                $this->query_params[0]['Registration.EVT_ID'] = $attributes['event_id'];
197
-                return $event;
198
-            }
199
-        }
200
-        if (is_espresso_event()) {
201
-            $event = EEH_Event_View::get_event();
202
-            if ($event instanceof EE_Event) {
203
-                $this->query_params[0]['Registration.EVT_ID'] = $event->ID();
204
-                return $event;
205
-            }
206
-        }
207
-        // one last shot...
208
-        // try getting the earliest active event
209
-        $events = EEM_Event::instance()->get_active_events(array(
210
-            'limit'    => 1,
211
-            'order_by' => array('Datetime.DTT_EVT_start' => 'ASC')
212
-        ));
213
-        //  if none then get the next upcoming
214
-        $events = empty($events)
215
-            ? EEM_Event::instance()->get_upcoming_events(array(
216
-                'limit'    => 1,
217
-                'order_by' => array('Datetime.DTT_EVT_start' => 'ASC')
218
-            ))
219
-            : $events;
220
-        $event = reset($events);
221
-        if ($event instanceof EE_Event) {
222
-            $this->query_params[0]['Registration.EVT_ID'] = $event->ID();
223
-            return $event;
224
-        }
225
-        return null;
226
-    }
227
-
228
-
229
-
230
-    /**
231
-     * @param array $attributes
232
-     * @return EE_Datetime|null
233
-     */
234
-    private function getDatetimeAndQueryParams(array $attributes)
235
-    {
236
-        if ( ! empty($attributes['datetime_id'])) {
237
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']);
238
-            if ($datetime instanceof EE_Datetime) {
239
-                $this->query_params[0]['Registration.Ticket.Datetime.DTT_ID'] = $attributes['datetime_id'];
240
-                $this->query_params['default_where_conditions'] = 'this_model_only';
241
-                if ( ! $this->template_args['event'] instanceof EE_Event) {
242
-                    $this->template_args['event'] = $datetime->event();
243
-                }
244
-                return $datetime;
245
-            }
246
-        }
247
-        return null;
248
-    }
249
-
250
-
251
-
252
-    /**
253
-     * @param array $attributes
254
-     * @return \EE_Base_Class|null
255
-     * @throws EE_Error
256
-     */
257
-    private function getTicketAndQueryParams(array $attributes)
258
-    {
259
-        if ( ! empty($attributes['ticket_id']) && empty($attributes['event_id']) && empty($attributes['datetime_id'])) {
260
-            $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']);
261
-            if ($ticket instanceof EE_Ticket) {
262
-                $this->query_params[0]['Registration.TKT_ID'] = $attributes['ticket_id'];
263
-                if ( ! $this->template_args['event'] instanceof EE_Event) {
264
-                    $this->template_args['event'] = $ticket->first_datetime() instanceof EE_Datetime
265
-                        ? $ticket->first_datetime()->event()
266
-                        : null;
267
-                }
268
-                return $ticket;
269
-            }
270
-        }
271
-        return null;
272
-    }
273
-
274
-
275
-
276
-    /**
277
-     * @param array $attributes
278
-     * @throws EE_Error
279
-     */
280
-    private function setAdditionalQueryParams(array $attributes)
281
-    {
282
-        $reg_status_array = EEM_Registration::reg_status_array();
283
-        if ($attributes['status'] !== 'all' && isset($reg_status_array[$attributes['status']])) {
284
-            $this->query_params[0]['Registration.STS_ID'] = $attributes['status'];
285
-        }
286
-        $this->query_params['group_by'] = array('ATT_ID');
287
-        $this->query_params['order_by'] = (array) apply_filters(
288
-            'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by',
289
-            array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC')
290
-        );
291
-    }
32
+	private $query_params = array(
33
+		0 => array()
34
+	);
35
+
36
+	private $template_args = array(
37
+		'contacts'      => array(),
38
+		'event'         => null,
39
+		'datetime'      => null,
40
+		'ticket'        => null,
41
+	);
42
+
43
+	/**
44
+	 * the actual shortcode tag that gets registered with WordPress
45
+	 *
46
+	 * @return string
47
+	 */
48
+	public function getTag()
49
+	{
50
+		return 'ESPRESSO_EVENT_ATTENDEES';
51
+	}
52
+
53
+
54
+
55
+	/**
56
+	 * the time in seconds to cache the results of the processShortcode() method
57
+	 * 0 means the processShortcode() results will NOT be cached at all
58
+	 *
59
+	 * @return int
60
+	 */
61
+	public function cacheExpiration()
62
+	{
63
+		return 0;
64
+	}
65
+
66
+
67
+
68
+	/**
69
+	 * a place for adding any initialization code that needs to run prior to wp_header().
70
+	 * this may be required for shortcodes that utilize a corresponding module,
71
+	 * and need to enqueue assets for that module
72
+	 *
73
+	 * @return void
74
+	 */
75
+	public function initializeShortcode()
76
+	{
77
+		$this->shortcodeHasBeenInitialized();
78
+	}
79
+
80
+
81
+
82
+	/**
83
+	 * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event.
84
+	 *  [ESPRESSO_EVENT_ATTENDEES]
85
+	 *  - defaults to attendees for earliest active event, or earliest upcoming event.
86
+	 *
87
+	 *  [ESPRESSO_EVENT_ATTENDEES event_id=123]
88
+	 *  - attendees for specific event.
89
+	 *
90
+	 *  [ESPRESSO_EVENT_ATTENDEES datetime_id=245]
91
+	 *  - attendees for a specific datetime.
92
+	 *
93
+	 *  [ESPRESSO_EVENT_ATTENDEES ticket_id=123]
94
+	 *  - attendees for a specific ticket.
95
+	 *
96
+	 *  [ESPRESSO_EVENT_ATTENDEES status=all]
97
+	 *  - specific registration status (use status id) or all for all attendees regardless of status.
98
+	 *  Note default is to only return approved attendees
99
+	 *
100
+	 *  [ESPRESSO_EVENT_ATTENDEES show_gravatar=true]
101
+	 *  - default is to not return gravatar.  Otherwise if this is set then return gravatar for email address given.
102
+	 *
103
+	 *  [ESPRESSO_EVENT_ATTENDEES display_on_archives=true]
104
+	 *  - default is to not display attendees list on archive pages.
105
+	 *
106
+	 * Note: because of the relationship between event_id, ticket_id, and datetime_id:
107
+	 * If more than one of those params is included, then preference is given to the following:
108
+	 *  - event_id is used whenever its present and any others are ignored.
109
+	 *  - if no event_id then datetime is used whenever its present and any others are ignored.
110
+	 *  - otherwise ticket_id is used if present.
111
+	 *
112
+	 * @param array $attributes
113
+	 * @return string
114
+	 * @throws EE_Error
115
+	 */
116
+	public function processShortcode($attributes = array())
117
+	{
118
+		// grab attributes and merge with defaults
119
+		$attributes = $this->getAttributes((array)$attributes);
120
+		$archive = is_archive();
121
+		$display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN);
122
+		// don't display on archives unless 'display_on_archives' is true
123
+		if($archive && ! $display_on_archives) {
124
+			return '';
125
+		}
126
+		// add attributes to template args
127
+		$this->template_args['show_gravatar'] = $attributes['show_gravatar'];
128
+		// add required objects: event, datetime, and ticket
129
+		$this->template_args['event'] = $this->getEventAndQueryParams($attributes);
130
+		$this->template_args['datetime'] = $this->getDatetimeAndQueryParams($attributes);
131
+		$this->template_args['ticket'] = $this->getTicketAndQueryParams($attributes);
132
+
133
+		// if any of the above objects is invalid or missing,
134
+		// then there was an invalid parameter or the shortcode was used incorrectly
135
+		// so when WP_DEBUG is set and true, we'll show a message,
136
+		// otherwise we'll just return an empty string.
137
+		 if (
138
+			! $this->template_args['event'] instanceof EE_Event
139
+			|| empty($this->query_params[0])
140
+			|| ($attributes['datetime_id'] && ! $this->template_args['datetime'] instanceof EE_Datetime)
141
+			|| ($attributes['ticket_id'] && ! $this->template_args['ticket'] instanceof EE_Ticket)
142
+		) {
143
+			if (WP_DEBUG) {
144
+				return '<div class="important-notice ee-attention">'
145
+					   . esc_html__('The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly.  Please double check the arguments you used for any typos.  In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.',
146
+						'event_espresso')
147
+					   . '</div>';
148
+			}
149
+			 return '';
150
+		}
151
+		$this->setAdditionalQueryParams($attributes);
152
+		//get contacts!
153
+		$this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params);
154
+		//all set let's load up the template and return.
155
+		return EEH_Template::locate_template(
156
+			'loop-espresso_event_attendees.php',
157
+			$this->template_args
158
+		);
159
+
160
+	}
161
+
162
+
163
+
164
+	/**
165
+	 * merge incoming attributes with filtered defaults
166
+	 *
167
+	 * @param array $attributes
168
+	 * @return array
169
+	 */
170
+	private function getAttributes(array $attributes)
171
+	{
172
+		return (array) apply_filters(
173
+			'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts',
174
+			$attributes + array(
175
+				'event_id'            => null,
176
+				'datetime_id'         => null,
177
+				'ticket_id'           => null,
178
+				'status'              => EEM_Registration::status_id_approved,
179
+				'show_gravatar'       => false,
180
+				'display_on_archives' => false,
181
+			)
182
+		);
183
+	}
184
+
185
+
186
+
187
+	/**
188
+	 * @param array $attributes
189
+	 * @return EE_Event|null
190
+	 * @throws EE_Error
191
+	 */
192
+	private function getEventAndQueryParams(array $attributes){
193
+		if ( ! empty($attributes['event_id'])) {
194
+			$event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']);
195
+			if ($event instanceof EE_Event) {
196
+				$this->query_params[0]['Registration.EVT_ID'] = $attributes['event_id'];
197
+				return $event;
198
+			}
199
+		}
200
+		if (is_espresso_event()) {
201
+			$event = EEH_Event_View::get_event();
202
+			if ($event instanceof EE_Event) {
203
+				$this->query_params[0]['Registration.EVT_ID'] = $event->ID();
204
+				return $event;
205
+			}
206
+		}
207
+		// one last shot...
208
+		// try getting the earliest active event
209
+		$events = EEM_Event::instance()->get_active_events(array(
210
+			'limit'    => 1,
211
+			'order_by' => array('Datetime.DTT_EVT_start' => 'ASC')
212
+		));
213
+		//  if none then get the next upcoming
214
+		$events = empty($events)
215
+			? EEM_Event::instance()->get_upcoming_events(array(
216
+				'limit'    => 1,
217
+				'order_by' => array('Datetime.DTT_EVT_start' => 'ASC')
218
+			))
219
+			: $events;
220
+		$event = reset($events);
221
+		if ($event instanceof EE_Event) {
222
+			$this->query_params[0]['Registration.EVT_ID'] = $event->ID();
223
+			return $event;
224
+		}
225
+		return null;
226
+	}
227
+
228
+
229
+
230
+	/**
231
+	 * @param array $attributes
232
+	 * @return EE_Datetime|null
233
+	 */
234
+	private function getDatetimeAndQueryParams(array $attributes)
235
+	{
236
+		if ( ! empty($attributes['datetime_id'])) {
237
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']);
238
+			if ($datetime instanceof EE_Datetime) {
239
+				$this->query_params[0]['Registration.Ticket.Datetime.DTT_ID'] = $attributes['datetime_id'];
240
+				$this->query_params['default_where_conditions'] = 'this_model_only';
241
+				if ( ! $this->template_args['event'] instanceof EE_Event) {
242
+					$this->template_args['event'] = $datetime->event();
243
+				}
244
+				return $datetime;
245
+			}
246
+		}
247
+		return null;
248
+	}
249
+
250
+
251
+
252
+	/**
253
+	 * @param array $attributes
254
+	 * @return \EE_Base_Class|null
255
+	 * @throws EE_Error
256
+	 */
257
+	private function getTicketAndQueryParams(array $attributes)
258
+	{
259
+		if ( ! empty($attributes['ticket_id']) && empty($attributes['event_id']) && empty($attributes['datetime_id'])) {
260
+			$ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']);
261
+			if ($ticket instanceof EE_Ticket) {
262
+				$this->query_params[0]['Registration.TKT_ID'] = $attributes['ticket_id'];
263
+				if ( ! $this->template_args['event'] instanceof EE_Event) {
264
+					$this->template_args['event'] = $ticket->first_datetime() instanceof EE_Datetime
265
+						? $ticket->first_datetime()->event()
266
+						: null;
267
+				}
268
+				return $ticket;
269
+			}
270
+		}
271
+		return null;
272
+	}
273
+
274
+
275
+
276
+	/**
277
+	 * @param array $attributes
278
+	 * @throws EE_Error
279
+	 */
280
+	private function setAdditionalQueryParams(array $attributes)
281
+	{
282
+		$reg_status_array = EEM_Registration::reg_status_array();
283
+		if ($attributes['status'] !== 'all' && isset($reg_status_array[$attributes['status']])) {
284
+			$this->query_params[0]['Registration.STS_ID'] = $attributes['status'];
285
+		}
286
+		$this->query_params['group_by'] = array('ATT_ID');
287
+		$this->query_params['order_by'] = (array) apply_filters(
288
+			'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by',
289
+			array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC')
290
+		);
291
+	}
292 292
 
293 293
 
294 294
 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -116,11 +116,11 @@  discard block
 block discarded – undo
116 116
     public function processShortcode($attributes = array())
117 117
     {
118 118
         // grab attributes and merge with defaults
119
-        $attributes = $this->getAttributes((array)$attributes);
119
+        $attributes = $this->getAttributes((array) $attributes);
120 120
         $archive = is_archive();
121 121
         $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN);
122 122
         // don't display on archives unless 'display_on_archives' is true
123
-        if($archive && ! $display_on_archives) {
123
+        if ($archive && ! $display_on_archives) {
124 124
             return '';
125 125
         }
126 126
         // add attributes to template args
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
      * @return EE_Event|null
190 190
      * @throws EE_Error
191 191
      */
192
-    private function getEventAndQueryParams(array $attributes){
192
+    private function getEventAndQueryParams(array $attributes) {
193 193
         if ( ! empty($attributes['event_id'])) {
194 194
             $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']);
195 195
             if ($event instanceof EE_Event) {
Please login to merge, or discard this patch.
core/EE_Request_Handler.core.php 1 patch
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\interfaces\InterminableInterface;
2 2
 
3
-if ( ! defined( 'EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');}
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); }
4 4
 /**
5 5
  * class EE_Request_Handler
6 6
  *
@@ -51,13 +51,13 @@  discard block
 block discarded – undo
51 51
 	 * @access public
52 52
 	 * @param  EE_Request $request
53 53
 	 */
54
-	public function __construct( EE_Request $request ) {
54
+	public function __construct(EE_Request $request) {
55 55
 		// grab request vars
56 56
 		$this->_params = $request->params();
57 57
 		// AJAX ???
58
-		$this->ajax = defined( 'DOING_AJAX' ) && DOING_AJAX ? true : false;
59
-		$this->front_ajax = defined( 'EE_FRONT_AJAX' ) && EE_FRONT_AJAX ? true : false;
60
-		do_action( 'AHEE__EE_Request_Handler__construct__complete' );
58
+		$this->ajax = defined('DOING_AJAX') && DOING_AJAX ? true : false;
59
+		$this->front_ajax = defined('EE_FRONT_AJAX') && EE_FRONT_AJAX ? true : false;
60
+		do_action('AHEE__EE_Request_Handler__construct__complete');
61 61
 	}
62 62
 
63 63
 
@@ -69,12 +69,12 @@  discard block
 block discarded – undo
69 69
 	 * @param WP $wp
70 70
 	 * @return void
71 71
 	 */
72
-	public function parse_request( $wp = null ) {
72
+	public function parse_request($wp = null) {
73 73
 		//if somebody forgot to provide us with WP, that's ok because its global
74
-		if ( ! $wp instanceof WP ) {
74
+		if ( ! $wp instanceof WP) {
75 75
 			global $wp;
76 76
 		}
77
-		$this->set_request_vars( $wp );
77
+		$this->set_request_vars($wp);
78 78
 	}
79 79
 
80 80
 
@@ -86,14 +86,14 @@  discard block
 block discarded – undo
86 86
 	 * @param WP $wp
87 87
 	 * @return void
88 88
 	 */
89
-	public function set_request_vars( $wp = null ) {
90
-		if ( ! is_admin() ) {
89
+	public function set_request_vars($wp = null) {
90
+		if ( ! is_admin()) {
91 91
 			// set request post_id
92
-			$this->set( 'post_id', $this->get_post_id_from_request( $wp ));
92
+			$this->set('post_id', $this->get_post_id_from_request($wp));
93 93
 			// set request post name
94
-			$this->set( 'post_name', $this->get_post_name_from_request( $wp ));
94
+			$this->set('post_name', $this->get_post_name_from_request($wp));
95 95
 			// set request post_type
96
-			$this->set( 'post_type', $this->get_post_type_from_request( $wp ));
96
+			$this->set('post_type', $this->get_post_type_from_request($wp));
97 97
 			// true or false ? is this page being used by EE ?
98 98
 			$this->set_espresso_page();
99 99
 		}
@@ -108,19 +108,19 @@  discard block
 block discarded – undo
108 108
 	 * @param WP $wp
109 109
 	 * @return int
110 110
 	 */
111
-	public function get_post_id_from_request( $wp = null ) {
112
-		if ( ! $wp instanceof WP ){
111
+	public function get_post_id_from_request($wp = null) {
112
+		if ( ! $wp instanceof WP) {
113 113
 			global $wp;
114 114
 		}
115 115
 		$post_id = null;
116
-		if ( isset( $wp->query_vars['p'] )) {
116
+		if (isset($wp->query_vars['p'])) {
117 117
 			$post_id = $wp->query_vars['p'];
118 118
 		}
119
-		if ( ! $post_id && isset( $wp->query_vars['page_id'] )) {
119
+		if ( ! $post_id && isset($wp->query_vars['page_id'])) {
120 120
 			$post_id = $wp->query_vars['page_id'];
121 121
 		}
122
-		if ( ! $post_id && isset( $wp->request ) && is_numeric( basename( $wp->request ))) {
123
-			$post_id = basename( $wp->request );
122
+		if ( ! $post_id && isset($wp->request) && is_numeric(basename($wp->request))) {
123
+			$post_id = basename($wp->request);
124 124
 		}
125 125
 		return $post_id;
126 126
 	}
@@ -134,35 +134,35 @@  discard block
 block discarded – undo
134 134
 	 * @param WP $wp
135 135
 	 * @return string
136 136
 	 */
137
-	public function get_post_name_from_request( $wp = null ) {
138
-		if ( ! $wp instanceof WP ){
137
+	public function get_post_name_from_request($wp = null) {
138
+		if ( ! $wp instanceof WP) {
139 139
 			global $wp;
140 140
 		}
141 141
 		$post_name = null;
142
-		if ( isset( $wp->query_vars['name'] ) && ! empty( $wp->query_vars['name'] )) {
142
+		if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) {
143 143
 			$post_name = $wp->query_vars['name'];
144 144
 		}
145
-		if ( ! $post_name && isset( $wp->query_vars['pagename'] ) && ! empty( $wp->query_vars['pagename'] )) {
145
+		if ( ! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) {
146 146
 			$post_name = $wp->query_vars['pagename'];
147 147
 		}
148
-		if ( ! $post_name && isset( $wp->request ) && ! empty( $wp->request )) {
149
-			$possible_post_name = basename( $wp->request );
150
-			if ( ! is_numeric( $possible_post_name )) {
148
+		if ( ! $post_name && isset($wp->request) && ! empty($wp->request)) {
149
+			$possible_post_name = basename($wp->request);
150
+			if ( ! is_numeric($possible_post_name)) {
151 151
 				/** @type WPDB $wpdb */
152 152
 				global $wpdb;
153 153
 				$SQL = "SELECT ID from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s";
154
-				$possible_post_name = $wpdb->get_var( $wpdb->prepare( $SQL, $possible_post_name ));
155
-				if ( $possible_post_name ) {
154
+				$possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name));
155
+				if ($possible_post_name) {
156 156
 					$post_name = $possible_post_name;
157 157
 				}
158 158
 			}
159 159
 		}
160
-		if ( ! $post_name && $this->get( 'post_id' )) {
160
+		if ( ! $post_name && $this->get('post_id')) {
161 161
 			/** @type WPDB $wpdb */
162 162
 			global $wpdb;
163 163
 			$SQL = "SELECT post_name from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d";
164
-			$possible_post_name = $wpdb->get_var( $wpdb->prepare( $SQL, $this->get( 'post_id' )));
165
-			if( $possible_post_name ) {
164
+			$possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->get('post_id')));
165
+			if ($possible_post_name) {
166 166
 				$post_name = $possible_post_name;
167 167
 			}
168 168
 		}
@@ -178,11 +178,11 @@  discard block
 block discarded – undo
178 178
 	 * @param WP $wp
179 179
 	 * @return mixed
180 180
 	 */
181
-	public function get_post_type_from_request( $wp = null ) {
182
-		if ( ! $wp instanceof WP ){
181
+	public function get_post_type_from_request($wp = null) {
182
+		if ( ! $wp instanceof WP) {
183 183
 			global $wp;
184 184
 		}
185
-		return isset( $wp->query_vars['post_type'] ) ? $wp->query_vars['post_type'] : null;
185
+		return isset($wp->query_vars['post_type']) ? $wp->query_vars['post_type'] : null;
186 186
 	}
187 187
 
188 188
 
@@ -192,18 +192,18 @@  discard block
 block discarded – undo
192 192
 	 * @param  WP $wp
193 193
 	 * @return string
194 194
 	 */
195
-	public function get_current_page_permalink( $wp = null ) {
196
-		$post_id = $this->get_post_id_from_request( $wp );
197
-		if ( $post_id ) {
198
-			$current_page_permalink = get_permalink( $post_id );
195
+	public function get_current_page_permalink($wp = null) {
196
+		$post_id = $this->get_post_id_from_request($wp);
197
+		if ($post_id) {
198
+			$current_page_permalink = get_permalink($post_id);
199 199
 		} else {
200
-			if ( ! $wp instanceof WP ) {
200
+			if ( ! $wp instanceof WP) {
201 201
 				global $wp;
202 202
 			}
203
-			if ( $wp->request ) {
204
-				$current_page_permalink = site_url( $wp->request );
203
+			if ($wp->request) {
204
+				$current_page_permalink = site_url($wp->request);
205 205
 			} else {
206
-				$current_page_permalink = esc_url( site_url( $_SERVER[ 'REQUEST_URI' ] ) );
206
+				$current_page_permalink = esc_url(site_url($_SERVER['REQUEST_URI']));
207 207
 			}
208 208
 		}
209 209
 		return $current_page_permalink;
@@ -220,31 +220,31 @@  discard block
 block discarded – undo
220 220
 	public function test_for_espresso_page() {
221 221
 		global $wp;
222 222
 		/** @type EE_CPT_Strategy $EE_CPT_Strategy */
223
-		$EE_CPT_Strategy = EE_Registry::instance()->load_core( 'CPT_Strategy' );
223
+		$EE_CPT_Strategy = EE_Registry::instance()->load_core('CPT_Strategy');
224 224
 		$espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies();
225
-		if ( is_array( $espresso_CPT_taxonomies ) ) {
226
-			foreach ( $espresso_CPT_taxonomies as $espresso_CPT_taxonomy =>$details ) {
227
-				if ( isset( $wp->query_vars, $wp->query_vars[ $espresso_CPT_taxonomy ] ) ) {
225
+		if (is_array($espresso_CPT_taxonomies)) {
226
+			foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy =>$details) {
227
+				if (isset($wp->query_vars, $wp->query_vars[$espresso_CPT_taxonomy])) {
228 228
 					return true;
229 229
 				}
230 230
 			}
231 231
 		}
232 232
 		// load espresso CPT endpoints
233 233
 		$espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints();
234
-		$post_type_CPT_endpoints = array_flip( $espresso_CPT_endpoints );
235
-		$post_types = (array)$this->get( 'post_type' );
236
-		foreach ( $post_types as $post_type ) {
234
+		$post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
235
+		$post_types = (array) $this->get('post_type');
236
+		foreach ($post_types as $post_type) {
237 237
 			// was a post name passed ?
238
-			if ( isset( $post_type_CPT_endpoints[ $post_type ] ) ) {
238
+			if (isset($post_type_CPT_endpoints[$post_type])) {
239 239
 				// kk we know this is an espresso page, but is it a specific post ?
240
-				if ( ! $this->get( 'post_name' ) ) {
240
+				if ( ! $this->get('post_name')) {
241 241
 					// there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
242
-					$post_name = isset( $post_type_CPT_endpoints[ $this->get( 'post_type' ) ] )
243
-                        ? $post_type_CPT_endpoints[ $this->get( 'post_type' ) ]
242
+					$post_name = isset($post_type_CPT_endpoints[$this->get('post_type')])
243
+                        ? $post_type_CPT_endpoints[$this->get('post_type')]
244 244
                         : '';
245 245
 					// if the post type matches on of our then set the endpoint
246
-					if ( $post_name ) {
247
-						$this->set( 'post_name', $post_name );
246
+					if ($post_name) {
247
+						$this->set('post_name', $post_name);
248 248
 					}
249 249
 				}
250 250
 				return true;
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 	 * @param null|bool $value
263 263
 	 * @return    void
264 264
 	 */
265
-	public function set_espresso_page( $value = null ) {
265
+	public function set_espresso_page($value = null) {
266 266
         $this->_params['is_espresso_page'] = ! empty($value) ? $value : $this->test_for_espresso_page();
267 267
 	}
268 268
 
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 	 *  @return 	mixed
276 276
 	 */
277 277
 	public function is_espresso_page() {
278
-		return isset( $this->_params['is_espresso_page'] ) ? $this->_params['is_espresso_page'] : false;
278
+		return isset($this->_params['is_espresso_page']) ? $this->_params['is_espresso_page'] : false;
279 279
 	}
280 280
 
281 281
 
@@ -299,14 +299,14 @@  discard block
 block discarded – undo
299 299
 	 * @param bool $override_ee
300 300
 	 * @return    void
301 301
 	 */
302
-	public function set( $key, $value, $override_ee = false ) {
302
+	public function set($key, $value, $override_ee = false) {
303 303
 		// don't allow "ee" to be overwritten unless explicitly instructed to do so
304 304
 		if (
305 305
 			$key !== 'ee' ||
306
-			( $key === 'ee' && empty( $this->_params['ee'] ))
307
-			|| ( $key === 'ee' && ! empty( $this->_params['ee'] ) && $override_ee )
306
+			($key === 'ee' && empty($this->_params['ee']))
307
+			|| ($key === 'ee' && ! empty($this->_params['ee']) && $override_ee)
308 308
 		) {
309
-			$this->_params[ $key ] = $value;
309
+			$this->_params[$key] = $value;
310 310
 		}
311 311
 	}
312 312
 
@@ -320,8 +320,8 @@  discard block
 block discarded – undo
320 320
 	 * @param null $default
321 321
 	 * @return    mixed
322 322
 	 */
323
-	public function get( $key, $default = null ) {
324
-		return isset( $this->_params[ $key ] ) ? $this->_params[ $key ] : $default;
323
+	public function get($key, $default = null) {
324
+		return isset($this->_params[$key]) ? $this->_params[$key] : $default;
325 325
 	}
326 326
 
327 327
 
@@ -333,8 +333,8 @@  discard block
 block discarded – undo
333 333
 	 * @param $key
334 334
 	 * @return    boolean
335 335
 	 */
336
-	public function is_set( $key ) {
337
-		return isset( $this->_params[ $key ] ) ? true : false;
336
+	public function is_set($key) {
337
+		return isset($this->_params[$key]) ? true : false;
338 338
 	}
339 339
 
340 340
 
@@ -346,8 +346,8 @@  discard block
 block discarded – undo
346 346
 	 * @param $key
347 347
 	 * @return    void
348 348
 	 */
349
-	public function un_set( $key ) {
350
-		unset( $this->_params[ $key ] );
349
+	public function un_set($key) {
350
+		unset($this->_params[$key]);
351 351
 	}
352 352
 
353 353
 
@@ -360,8 +360,8 @@  discard block
 block discarded – undo
360 360
 	 * @param $value
361 361
 	 * @return    void
362 362
 	 */
363
-	public function set_notice( $key, $value ) {
364
-		$this->_notice[ $key ] = $value;
363
+	public function set_notice($key, $value) {
364
+		$this->_notice[$key] = $value;
365 365
 	}
366 366
 
367 367
 
@@ -373,8 +373,8 @@  discard block
 block discarded – undo
373 373
 	 * @param $key
374 374
 	 * @return    mixed
375 375
 	 */
376
-	public function get_notice( $key ) {
377
-		return isset( $this->_notice[ $key ] ) ? $this->_notice[ $key ] : null;
376
+	public function get_notice($key) {
377
+		return isset($this->_notice[$key]) ? $this->_notice[$key] : null;
378 378
 	}
379 379
 
380 380
 
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 	 * @param $string
387 387
 	 * @return    void
388 388
 	 */
389
-	public function add_output( $string ) {
389
+	public function add_output($string) {
390 390
 		$this->_output .= $string;
391 391
 	}
392 392
 
@@ -408,8 +408,8 @@  discard block
 block discarded – undo
408 408
 	 * @param $item
409 409
 	 * @param $key
410 410
 	 */
411
-	public function sanitize_text_field_for_array_walk( &$item, &$key ) {
412
-		$item = strpos( $item, 'email' ) !== false ? sanitize_email( $item ) : sanitize_text_field( $item );
411
+	public function sanitize_text_field_for_array_walk(&$item, &$key) {
412
+		$item = strpos($item, 'email') !== false ? sanitize_email($item) : sanitize_text_field($item);
413 413
 	}
414 414
 
415 415
 
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 	 * @param $b
420 420
 	 * @return bool
421 421
 	 */
422
-	public function __set($a,$b) { return false; }
422
+	public function __set($a, $b) { return false; }
423 423
 
424 424
 
425 425
 
Please login to merge, or discard this patch.
core/helpers/EEH_Debug_Tools.helper.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
 
376 376
 
377 377
     /**
378
-     * @param mixed      $var
378
+     * @param string      $var
379 379
      * @param string     $var_name
380 380
      * @param string     $file
381 381
      * @param int|string $line
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
      * @param mixed      $var
514 514
      * @param string     $var_name
515 515
      * @param string     $file
516
-     * @param int|string $line
516
+     * @param integer $line
517 517
      * @param int        $heading_tag
518 518
      * @param bool       $die
519 519
      */
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
 
577 577
     /**
578 578
      * @deprecated 4.9.39.rc.034
579
-     * @param null $timer_name
579
+     * @param string $timer_name
580 580
      */
581 581
     public function start_timer($timer_name = null)
582 582
     {
Please login to merge, or discard this patch.
Indentation   +642 added lines, -642 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\services\Benchmark;
2 2
 
3 3
 if (! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 
@@ -17,632 +17,632 @@  discard block
 block discarded – undo
17 17
 class EEH_Debug_Tools
18 18
 {
19 19
 
20
-    /**
21
-     *    instance of the EEH_Autoloader object
22
-     *
23
-     * @var    $_instance
24
-     * @access    private
25
-     */
26
-    private static $_instance;
27
-
28
-    /**
29
-     * @var array
30
-     */
31
-    protected $_memory_usage_points = array();
32
-
33
-
34
-
35
-    /**
36
-     * @singleton method used to instantiate class object
37
-     * @access    public
38
-     * @return EEH_Debug_Tools
39
-     */
40
-    public static function instance()
41
-    {
42
-        // check if class object is instantiated, and instantiated properly
43
-        if (! self::$_instance instanceof EEH_Debug_Tools) {
44
-            self::$_instance = new self();
45
-        }
46
-        return self::$_instance;
47
-    }
48
-
49
-
50
-
51
-    /**
52
-     * private class constructor
53
-     */
54
-    private function __construct()
55
-    {
56
-        // load Kint PHP debugging library
57
-        if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) {
58
-            // despite EE4 having a check for an existing copy of the Kint debugging class,
59
-            // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
60
-            // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
61
-            // so we've moved it to our test folder so that it is not included with production releases
62
-            // plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
63
-            require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php');
64
-        }
65
-        // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
66
-        //add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
67
-        // }
68
-        $plugin = basename(EE_PLUGIN_DIR_PATH);
69
-        add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
70
-        add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
71
-        add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     *    show_db_name
78
-     *
79
-     * @return void
80
-     */
81
-    public static function show_db_name()
82
-    {
83
-        if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84
-            echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85
-                 . DB_NAME
86
-                 . '</p>';
87
-        }
88
-        if (EE_DEBUG) {
89
-            Benchmark::displayResults();
90
-        }
91
-    }
92
-
93
-
94
-
95
-    /**
96
-     *    dump EE_Session object at bottom of page after everything else has happened
97
-     *
98
-     * @return void
99
-     */
100
-    public function espresso_session_footer_dump()
101
-    {
102
-        if (
103
-            (defined('WP_DEBUG') && WP_DEBUG)
104
-            && ! defined('DOING_AJAX')
105
-            && class_exists('Kint')
106
-            && function_exists('wp_get_current_user')
107
-            && current_user_can('update_core')
108
-            && class_exists('EE_Registry')
109
-        ) {
110
-            Kint::dump(EE_Registry::instance()->SSN->id());
111
-            Kint::dump(EE_Registry::instance()->SSN);
112
-            //			Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
113
-            $this->espresso_list_hooked_functions();
114
-            Benchmark::displayResults();
115
-        }
116
-    }
117
-
118
-
119
-
120
-    /**
121
-     *    List All Hooked Functions
122
-     *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
123
-     *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
124
-     *
125
-     * @param string $tag
126
-     * @return void
127
-     */
128
-    public function espresso_list_hooked_functions($tag = '')
129
-    {
130
-        global $wp_filter;
131
-        echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132
-        if ($tag) {
133
-            $hook[$tag] = $wp_filter[$tag];
134
-            if (! is_array($hook[$tag])) {
135
-                trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136
-                return;
137
-            }
138
-            echo '<h5>For Tag: ' . $tag . '</h5>';
139
-        } else {
140
-            $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141
-            ksort($hook);
142
-        }
143
-        foreach ($hook as $tag_name => $priorities) {
144
-            echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>$tag_name</strong><br />";
145
-            ksort($priorities);
146
-            foreach ($priorities as $priority => $function) {
147
-                echo $priority;
148
-                foreach ($function as $name => $properties) {
149
-                    echo "\t$name<br />";
150
-                }
151
-            }
152
-        }
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     *    registered_filter_callbacks
159
-     *
160
-     * @param string $hook_name
161
-     * @return array
162
-     */
163
-    public static function registered_filter_callbacks($hook_name = '')
164
-    {
165
-        $filters = array();
166
-        global $wp_filter;
167
-        if (isset($wp_filter[$hook_name])) {
168
-            $filters[$hook_name] = array();
169
-            foreach ($wp_filter[$hook_name] as $priority => $callbacks) {
170
-                $filters[$hook_name][$priority] = array();
171
-                foreach ($callbacks as $callback) {
172
-                    $filters[$hook_name][$priority][] = $callback['function'];
173
-                }
174
-            }
175
-        }
176
-        return $filters;
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     *    captures plugin activation errors for debugging
183
-     *
184
-     * @return void
185
-     * @throws EE_Error
186
-     */
187
-    public static function ee_plugin_activation_errors()
188
-    {
189
-        if (WP_DEBUG) {
190
-            $activation_errors = ob_get_contents();
191
-            if (! empty($activation_errors)) {
192
-                $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
193
-            }
194
-            espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
195
-            if (class_exists('EEH_File')) {
196
-                try {
197
-                    EEH_File::ensure_file_exists_and_is_writable(
198
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'
199
-                    );
200
-                    EEH_File::write_to_file(
201
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
202
-                        $activation_errors
203
-                    );
204
-                } catch (EE_Error $e) {
205
-                    EE_Error::add_error(
206
-                        sprintf(
207
-                            __(
208
-                                'The Event Espresso activation errors file could not be setup because: %s',
209
-                                'event_espresso'
210
-                            ),
211
-                            $e->getMessage()
212
-                        ),
213
-                        __FILE__, __FUNCTION__, __LINE__
214
-                    );
215
-                }
216
-            } else {
217
-                // old school attempt
218
-                file_put_contents(
219
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
220
-                    $activation_errors
221
-                );
222
-            }
223
-            $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
224
-            update_option('ee_plugin_activation_errors', $activation_errors);
225
-        }
226
-    }
227
-
228
-
229
-
230
-    /**
231
-     * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
232
-     * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
233
-     * or we want to make sure they use something the right way.
234
-     *
235
-     * @access public
236
-     * @param string $function      The function that was called
237
-     * @param string $message       A message explaining what has been done incorrectly
238
-     * @param string $version       The version of Event Espresso where the error was added
239
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
240
-     *                              for a deprecated function. This allows deprecation to occur during one version,
241
-     *                              but not have any notices appear until a later version. This allows developers
242
-     *                              extra time to update their code before notices appear.
243
-     * @param int    $error_type
244
-     * @uses   trigger_error()
245
-     */
246
-    public function doing_it_wrong(
247
-        $function,
248
-        $message,
249
-        $version,
250
-        $applies_when = '',
251
-        $error_type = null
252
-    ) {
253
-        $applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
254
-        $error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
255
-        // because we swapped the parameter order around for the last two params,
256
-        // let's verify that some third party isn't still passing an error type value for the third param
257
-        if (is_int($applies_when)) {
258
-            $error_type = $applies_when;
259
-            $applies_when = espresso_version();
260
-        }
261
-        // if not displaying notices yet, then just leave
262
-        if (version_compare(espresso_version(), $applies_when, '<')) {
263
-            return;
264
-        }
265
-        do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
266
-        $version = $version === null
267
-            ? ''
268
-            : sprintf(
269
-                __('(This message was added in version %s of Event Espresso)', 'event_espresso'),
270
-                $version
271
-            );
272
-        $error_message = sprintf(
273
-            esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
274
-            $function,
275
-            '<strong>',
276
-            '</strong>',
277
-            $message,
278
-            $version
279
-        );
280
-        // don't trigger error if doing ajax,
281
-        // instead we'll add a transient EE_Error notice that in theory should show on the next request.
282
-        if (defined('DOING_AJAX') && DOING_AJAX) {
283
-            $error_message .= ' ' . esc_html__(
284
-                    'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
285
-                    'event_espresso'
286
-                );
287
-            $error_message .= '<ul><li>';
288
-            $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params());
289
-            $error_message .= '</ul>';
290
-            EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
291
-            //now we set this on the transient so it shows up on the next request.
292
-            EE_Error::get_notices(false, true);
293
-        } else {
294
-            trigger_error($error_message, $error_type);
295
-        }
296
-    }
297
-
298
-
299
-
300
-
301
-    /**
302
-     * Logger helpers
303
-     */
304
-    /**
305
-     * debug
306
-     *
307
-     * @param string $class
308
-     * @param string $func
309
-     * @param string $line
310
-     * @param array  $info
311
-     * @param bool   $display_request
312
-     * @param string $debug_index
313
-     * @param string $debug_key
314
-     * @throws EE_Error
315
-     * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
316
-     */
317
-    public static function log(
318
-        $class = '',
319
-        $func = '',
320
-        $line = '',
321
-        $info = array(),
322
-        $display_request = false,
323
-        $debug_index = '',
324
-        $debug_key = 'EE_DEBUG_SPCO'
325
-    ) {
326
-        if (WP_DEBUG) {
327
-            $debug_key = $debug_key . '_' . EE_Session::instance()->id();
328
-            $debug_data = get_option($debug_key, array());
329
-            $default_data = array(
330
-                $class => $func . '() : ' . $line,
331
-                'REQ'  => $display_request ? $_REQUEST : '',
332
-            );
333
-            // don't serialize objects
334
-            $info = self::strip_objects($info);
335
-            $index = ! empty($debug_index) ? $debug_index : 0;
336
-            if (! isset($debug_data[$index])) {
337
-                $debug_data[$index] = array();
338
-            }
339
-            $debug_data[$index][microtime()] = array_merge($default_data, $info);
340
-            update_option($debug_key, $debug_data);
341
-        }
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     * strip_objects
348
-     *
349
-     * @param array $info
350
-     * @return array
351
-     */
352
-    public static function strip_objects($info = array())
353
-    {
354
-        foreach ($info as $key => $value) {
355
-            if (is_array($value)) {
356
-                $info[$key] = self::strip_objects($value);
357
-            } else if (is_object($value)) {
358
-                $object_class = get_class($value);
359
-                $info[$object_class] = array();
360
-                $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
361
-                if (method_exists($value, 'ID')) {
362
-                    $info[$object_class]['ID'] = $value->ID();
363
-                }
364
-                if (method_exists($value, 'status')) {
365
-                    $info[$object_class]['status'] = $value->status();
366
-                } else if (method_exists($value, 'status_ID')) {
367
-                    $info[$object_class]['status'] = $value->status_ID();
368
-                }
369
-                unset($info[$key]);
370
-            }
371
-        }
372
-        return (array)$info;
373
-    }
374
-
375
-
376
-
377
-    /**
378
-     * @param mixed      $var
379
-     * @param string     $var_name
380
-     * @param string     $file
381
-     * @param int|string $line
382
-     * @param int        $heading_tag
383
-     * @param bool       $die
384
-     * @param string     $margin
385
-     */
386
-    public static function printv(
387
-        $var,
388
-        $var_name = '',
389
-        $file = '',
390
-        $line = '',
391
-        $heading_tag = 5,
392
-        $die = false,
393
-        $margin = ''
394
-    ) {
395
-        $var_name = ! $var_name ? 'string' : $var_name;
396
-        $var_name = ucwords(str_replace('$', '', $var_name));
397
-        $is_method = method_exists($var_name, $var);
398
-        $var_name = ucwords(str_replace('_', ' ', $var_name));
399
-        $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
400
-        $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
401
-        $result .= $is_method
402
-            ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
403
-            : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
404
-        $result .= EEH_Debug_Tools::file_and_line($file, $line);
405
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
406
-        if ($die) {
407
-            die($result);
408
-        }
409
-        echo $result;
410
-    }
411
-
412
-
413
-
414
-    /**
415
-     * @param string $var_name
416
-     * @param string $heading_tag
417
-     * @param string $margin
418
-     * @return string
419
-     */
420
-    protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '')
421
-    {
422
-        if (defined('EE_TESTS_DIR')) {
423
-            return "\n{$var_name}";
424
-        }
425
-        $margin = "25px 0 0 {$margin}";
426
-        return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
427
-    }
428
-
429
-
430
-
431
-    /**
432
-     * @param string $heading_tag
433
-     * @return string
434
-     */
435
-    protected static function headingX($heading_tag = 'h5')
436
-    {
437
-        if (defined('EE_TESTS_DIR')) {
438
-            return '';
439
-        }
440
-        return '</' . $heading_tag . '>';
441
-    }
442
-
443
-
444
-
445
-    /**
446
-     * @param string $content
447
-     * @return string
448
-     */
449
-    protected static function grey_span($content = '')
450
-    {
451
-        if (defined('EE_TESTS_DIR')) {
452
-            return $content;
453
-        }
454
-        return '<span style="color:#999">' . $content . '</span>';
455
-    }
456
-
457
-
458
-
459
-    /**
460
-     * @param string $file
461
-     * @param int    $line
462
-     * @return string
463
-     */
464
-    protected static function file_and_line($file, $line)
465
-    {
466
-        if ($file === '' || $line === '') {
467
-            return '';
468
-        }
469
-        if (defined('EE_TESTS_DIR')) {
470
-            return "\n\t(" . $file . ' line no: ' . $line . ' ) ';
471
-        }
472
-        return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
473
-               . $file
474
-               . '<br />line no: '
475
-               . $line
476
-               . '</span>';
477
-    }
478
-
479
-
480
-
481
-    /**
482
-     * @param string $content
483
-     * @return string
484
-     */
485
-    protected static function orange_span($content = '')
486
-    {
487
-        if (defined('EE_TESTS_DIR')) {
488
-            return $content;
489
-        }
490
-        return '<span style="color:#E76700">' . $content . '</span>';
491
-    }
492
-
493
-
494
-
495
-    /**
496
-     * @param mixed $var
497
-     * @return string
498
-     */
499
-    protected static function pre_span($var)
500
-    {
501
-        ob_start();
502
-        var_dump($var);
503
-        $var = ob_get_clean();
504
-        if (defined('EE_TESTS_DIR')) {
505
-            return "\n" . $var;
506
-        }
507
-        return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
508
-    }
509
-
510
-
511
-
512
-    /**
513
-     * @param mixed      $var
514
-     * @param string     $var_name
515
-     * @param string     $file
516
-     * @param int|string $line
517
-     * @param int        $heading_tag
518
-     * @param bool       $die
519
-     */
520
-    public static function printr(
521
-        $var,
522
-        $var_name = '',
523
-        $file = '',
524
-        $line = '',
525
-        $heading_tag = 5,
526
-        $die = false
527
-    ) {
528
-        // return;
529
-        $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
530
-        $margin = is_admin() ? ' 180px' : '0';
531
-        //$print_r = false;
532
-        if (is_string($var)) {
533
-            EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
534
-            return;
535
-        }
536
-        if (is_object($var)) {
537
-            $var_name = ! $var_name ? 'object' : $var_name;
538
-            //$print_r = true;
539
-        } else if (is_array($var)) {
540
-            $var_name = ! $var_name ? 'array' : $var_name;
541
-            //$print_r = true;
542
-        } else if (is_numeric($var)) {
543
-            $var_name = ! $var_name ? 'numeric' : $var_name;
544
-        } else if ($var === null) {
545
-            $var_name = ! $var_name ? 'null' : $var_name;
546
-        }
547
-        $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
548
-        $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
549
-        $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
550
-        $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
551
-                EEH_Debug_Tools::pre_span($var)
552
-            );
553
-        $result .= EEH_Debug_Tools::file_and_line($file, $line);
554
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
555
-        if ($die) {
556
-            die($result);
557
-        }
558
-        echo $result;
559
-    }
560
-
561
-
562
-
563
-    /******************** deprecated ********************/
564
-
565
-
566
-
567
-    /**
568
-     * @deprecated 4.9.39.rc.034
569
-     */
570
-    public function reset_times()
571
-    {
572
-        Benchmark::resetTimes();
573
-    }
574
-
575
-
576
-
577
-    /**
578
-     * @deprecated 4.9.39.rc.034
579
-     * @param null $timer_name
580
-     */
581
-    public function start_timer($timer_name = null)
582
-    {
583
-        Benchmark::startTimer($timer_name);
584
-    }
585
-
586
-
587
-
588
-    /**
589
-     * @deprecated 4.9.39.rc.034
590
-     * @param string $timer_name
591
-     */
592
-    public function stop_timer($timer_name = '')
593
-    {
594
-        Benchmark::stopTimer($timer_name);
595
-    }
596
-
597
-
598
-
599
-    /**
600
-     * @deprecated 4.9.39.rc.034
601
-     * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
602
-     * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
603
-     * @return void
604
-     */
605
-    public function measure_memory($label, $output_now = false)
606
-    {
607
-        Benchmark::measureMemory($label, $output_now);
608
-    }
609
-
610
-
611
-
612
-    /**
613
-     * @deprecated 4.9.39.rc.034
614
-     * @param int $size
615
-     * @return string
616
-     */
617
-    public function convert($size)
618
-    {
619
-        return Benchmark::convert($size);
620
-    }
621
-
622
-
623
-
624
-    /**
625
-     * @deprecated 4.9.39.rc.034
626
-     * @param bool $output_now
627
-     * @return string
628
-     */
629
-    public function show_times($output_now = true)
630
-    {
631
-        return Benchmark::displayResults($output_now);
632
-    }
633
-
634
-
635
-
636
-    /**
637
-     * @deprecated 4.9.39.rc.034
638
-     * @param string $timer_name
639
-     * @param float  $total_time
640
-     * @return string
641
-     */
642
-    public function format_time($timer_name, $total_time)
643
-    {
644
-        return Benchmark::formatTime($timer_name, $total_time);
645
-    }
20
+	/**
21
+	 *    instance of the EEH_Autoloader object
22
+	 *
23
+	 * @var    $_instance
24
+	 * @access    private
25
+	 */
26
+	private static $_instance;
27
+
28
+	/**
29
+	 * @var array
30
+	 */
31
+	protected $_memory_usage_points = array();
32
+
33
+
34
+
35
+	/**
36
+	 * @singleton method used to instantiate class object
37
+	 * @access    public
38
+	 * @return EEH_Debug_Tools
39
+	 */
40
+	public static function instance()
41
+	{
42
+		// check if class object is instantiated, and instantiated properly
43
+		if (! self::$_instance instanceof EEH_Debug_Tools) {
44
+			self::$_instance = new self();
45
+		}
46
+		return self::$_instance;
47
+	}
48
+
49
+
50
+
51
+	/**
52
+	 * private class constructor
53
+	 */
54
+	private function __construct()
55
+	{
56
+		// load Kint PHP debugging library
57
+		if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) {
58
+			// despite EE4 having a check for an existing copy of the Kint debugging class,
59
+			// if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
60
+			// then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
61
+			// so we've moved it to our test folder so that it is not included with production releases
62
+			// plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
63
+			require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php');
64
+		}
65
+		// if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
66
+		//add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
67
+		// }
68
+		$plugin = basename(EE_PLUGIN_DIR_PATH);
69
+		add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
70
+		add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
71
+		add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 *    show_db_name
78
+	 *
79
+	 * @return void
80
+	 */
81
+	public static function show_db_name()
82
+	{
83
+		if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84
+			echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85
+				 . DB_NAME
86
+				 . '</p>';
87
+		}
88
+		if (EE_DEBUG) {
89
+			Benchmark::displayResults();
90
+		}
91
+	}
92
+
93
+
94
+
95
+	/**
96
+	 *    dump EE_Session object at bottom of page after everything else has happened
97
+	 *
98
+	 * @return void
99
+	 */
100
+	public function espresso_session_footer_dump()
101
+	{
102
+		if (
103
+			(defined('WP_DEBUG') && WP_DEBUG)
104
+			&& ! defined('DOING_AJAX')
105
+			&& class_exists('Kint')
106
+			&& function_exists('wp_get_current_user')
107
+			&& current_user_can('update_core')
108
+			&& class_exists('EE_Registry')
109
+		) {
110
+			Kint::dump(EE_Registry::instance()->SSN->id());
111
+			Kint::dump(EE_Registry::instance()->SSN);
112
+			//			Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
113
+			$this->espresso_list_hooked_functions();
114
+			Benchmark::displayResults();
115
+		}
116
+	}
117
+
118
+
119
+
120
+	/**
121
+	 *    List All Hooked Functions
122
+	 *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
123
+	 *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
124
+	 *
125
+	 * @param string $tag
126
+	 * @return void
127
+	 */
128
+	public function espresso_list_hooked_functions($tag = '')
129
+	{
130
+		global $wp_filter;
131
+		echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132
+		if ($tag) {
133
+			$hook[$tag] = $wp_filter[$tag];
134
+			if (! is_array($hook[$tag])) {
135
+				trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136
+				return;
137
+			}
138
+			echo '<h5>For Tag: ' . $tag . '</h5>';
139
+		} else {
140
+			$hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141
+			ksort($hook);
142
+		}
143
+		foreach ($hook as $tag_name => $priorities) {
144
+			echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>$tag_name</strong><br />";
145
+			ksort($priorities);
146
+			foreach ($priorities as $priority => $function) {
147
+				echo $priority;
148
+				foreach ($function as $name => $properties) {
149
+					echo "\t$name<br />";
150
+				}
151
+			}
152
+		}
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 *    registered_filter_callbacks
159
+	 *
160
+	 * @param string $hook_name
161
+	 * @return array
162
+	 */
163
+	public static function registered_filter_callbacks($hook_name = '')
164
+	{
165
+		$filters = array();
166
+		global $wp_filter;
167
+		if (isset($wp_filter[$hook_name])) {
168
+			$filters[$hook_name] = array();
169
+			foreach ($wp_filter[$hook_name] as $priority => $callbacks) {
170
+				$filters[$hook_name][$priority] = array();
171
+				foreach ($callbacks as $callback) {
172
+					$filters[$hook_name][$priority][] = $callback['function'];
173
+				}
174
+			}
175
+		}
176
+		return $filters;
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 *    captures plugin activation errors for debugging
183
+	 *
184
+	 * @return void
185
+	 * @throws EE_Error
186
+	 */
187
+	public static function ee_plugin_activation_errors()
188
+	{
189
+		if (WP_DEBUG) {
190
+			$activation_errors = ob_get_contents();
191
+			if (! empty($activation_errors)) {
192
+				$activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
193
+			}
194
+			espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
195
+			if (class_exists('EEH_File')) {
196
+				try {
197
+					EEH_File::ensure_file_exists_and_is_writable(
198
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'
199
+					);
200
+					EEH_File::write_to_file(
201
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
202
+						$activation_errors
203
+					);
204
+				} catch (EE_Error $e) {
205
+					EE_Error::add_error(
206
+						sprintf(
207
+							__(
208
+								'The Event Espresso activation errors file could not be setup because: %s',
209
+								'event_espresso'
210
+							),
211
+							$e->getMessage()
212
+						),
213
+						__FILE__, __FUNCTION__, __LINE__
214
+					);
215
+				}
216
+			} else {
217
+				// old school attempt
218
+				file_put_contents(
219
+					EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
220
+					$activation_errors
221
+				);
222
+			}
223
+			$activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
224
+			update_option('ee_plugin_activation_errors', $activation_errors);
225
+		}
226
+	}
227
+
228
+
229
+
230
+	/**
231
+	 * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
232
+	 * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
233
+	 * or we want to make sure they use something the right way.
234
+	 *
235
+	 * @access public
236
+	 * @param string $function      The function that was called
237
+	 * @param string $message       A message explaining what has been done incorrectly
238
+	 * @param string $version       The version of Event Espresso where the error was added
239
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
240
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
241
+	 *                              but not have any notices appear until a later version. This allows developers
242
+	 *                              extra time to update their code before notices appear.
243
+	 * @param int    $error_type
244
+	 * @uses   trigger_error()
245
+	 */
246
+	public function doing_it_wrong(
247
+		$function,
248
+		$message,
249
+		$version,
250
+		$applies_when = '',
251
+		$error_type = null
252
+	) {
253
+		$applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
254
+		$error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
255
+		// because we swapped the parameter order around for the last two params,
256
+		// let's verify that some third party isn't still passing an error type value for the third param
257
+		if (is_int($applies_when)) {
258
+			$error_type = $applies_when;
259
+			$applies_when = espresso_version();
260
+		}
261
+		// if not displaying notices yet, then just leave
262
+		if (version_compare(espresso_version(), $applies_when, '<')) {
263
+			return;
264
+		}
265
+		do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
266
+		$version = $version === null
267
+			? ''
268
+			: sprintf(
269
+				__('(This message was added in version %s of Event Espresso)', 'event_espresso'),
270
+				$version
271
+			);
272
+		$error_message = sprintf(
273
+			esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
274
+			$function,
275
+			'<strong>',
276
+			'</strong>',
277
+			$message,
278
+			$version
279
+		);
280
+		// don't trigger error if doing ajax,
281
+		// instead we'll add a transient EE_Error notice that in theory should show on the next request.
282
+		if (defined('DOING_AJAX') && DOING_AJAX) {
283
+			$error_message .= ' ' . esc_html__(
284
+					'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
285
+					'event_espresso'
286
+				);
287
+			$error_message .= '<ul><li>';
288
+			$error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params());
289
+			$error_message .= '</ul>';
290
+			EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
291
+			//now we set this on the transient so it shows up on the next request.
292
+			EE_Error::get_notices(false, true);
293
+		} else {
294
+			trigger_error($error_message, $error_type);
295
+		}
296
+	}
297
+
298
+
299
+
300
+
301
+	/**
302
+	 * Logger helpers
303
+	 */
304
+	/**
305
+	 * debug
306
+	 *
307
+	 * @param string $class
308
+	 * @param string $func
309
+	 * @param string $line
310
+	 * @param array  $info
311
+	 * @param bool   $display_request
312
+	 * @param string $debug_index
313
+	 * @param string $debug_key
314
+	 * @throws EE_Error
315
+	 * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
316
+	 */
317
+	public static function log(
318
+		$class = '',
319
+		$func = '',
320
+		$line = '',
321
+		$info = array(),
322
+		$display_request = false,
323
+		$debug_index = '',
324
+		$debug_key = 'EE_DEBUG_SPCO'
325
+	) {
326
+		if (WP_DEBUG) {
327
+			$debug_key = $debug_key . '_' . EE_Session::instance()->id();
328
+			$debug_data = get_option($debug_key, array());
329
+			$default_data = array(
330
+				$class => $func . '() : ' . $line,
331
+				'REQ'  => $display_request ? $_REQUEST : '',
332
+			);
333
+			// don't serialize objects
334
+			$info = self::strip_objects($info);
335
+			$index = ! empty($debug_index) ? $debug_index : 0;
336
+			if (! isset($debug_data[$index])) {
337
+				$debug_data[$index] = array();
338
+			}
339
+			$debug_data[$index][microtime()] = array_merge($default_data, $info);
340
+			update_option($debug_key, $debug_data);
341
+		}
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 * strip_objects
348
+	 *
349
+	 * @param array $info
350
+	 * @return array
351
+	 */
352
+	public static function strip_objects($info = array())
353
+	{
354
+		foreach ($info as $key => $value) {
355
+			if (is_array($value)) {
356
+				$info[$key] = self::strip_objects($value);
357
+			} else if (is_object($value)) {
358
+				$object_class = get_class($value);
359
+				$info[$object_class] = array();
360
+				$info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
361
+				if (method_exists($value, 'ID')) {
362
+					$info[$object_class]['ID'] = $value->ID();
363
+				}
364
+				if (method_exists($value, 'status')) {
365
+					$info[$object_class]['status'] = $value->status();
366
+				} else if (method_exists($value, 'status_ID')) {
367
+					$info[$object_class]['status'] = $value->status_ID();
368
+				}
369
+				unset($info[$key]);
370
+			}
371
+		}
372
+		return (array)$info;
373
+	}
374
+
375
+
376
+
377
+	/**
378
+	 * @param mixed      $var
379
+	 * @param string     $var_name
380
+	 * @param string     $file
381
+	 * @param int|string $line
382
+	 * @param int        $heading_tag
383
+	 * @param bool       $die
384
+	 * @param string     $margin
385
+	 */
386
+	public static function printv(
387
+		$var,
388
+		$var_name = '',
389
+		$file = '',
390
+		$line = '',
391
+		$heading_tag = 5,
392
+		$die = false,
393
+		$margin = ''
394
+	) {
395
+		$var_name = ! $var_name ? 'string' : $var_name;
396
+		$var_name = ucwords(str_replace('$', '', $var_name));
397
+		$is_method = method_exists($var_name, $var);
398
+		$var_name = ucwords(str_replace('_', ' ', $var_name));
399
+		$heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
400
+		$result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
401
+		$result .= $is_method
402
+			? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
403
+			: EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
404
+		$result .= EEH_Debug_Tools::file_and_line($file, $line);
405
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
406
+		if ($die) {
407
+			die($result);
408
+		}
409
+		echo $result;
410
+	}
411
+
412
+
413
+
414
+	/**
415
+	 * @param string $var_name
416
+	 * @param string $heading_tag
417
+	 * @param string $margin
418
+	 * @return string
419
+	 */
420
+	protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '')
421
+	{
422
+		if (defined('EE_TESTS_DIR')) {
423
+			return "\n{$var_name}";
424
+		}
425
+		$margin = "25px 0 0 {$margin}";
426
+		return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
427
+	}
428
+
429
+
430
+
431
+	/**
432
+	 * @param string $heading_tag
433
+	 * @return string
434
+	 */
435
+	protected static function headingX($heading_tag = 'h5')
436
+	{
437
+		if (defined('EE_TESTS_DIR')) {
438
+			return '';
439
+		}
440
+		return '</' . $heading_tag . '>';
441
+	}
442
+
443
+
444
+
445
+	/**
446
+	 * @param string $content
447
+	 * @return string
448
+	 */
449
+	protected static function grey_span($content = '')
450
+	{
451
+		if (defined('EE_TESTS_DIR')) {
452
+			return $content;
453
+		}
454
+		return '<span style="color:#999">' . $content . '</span>';
455
+	}
456
+
457
+
458
+
459
+	/**
460
+	 * @param string $file
461
+	 * @param int    $line
462
+	 * @return string
463
+	 */
464
+	protected static function file_and_line($file, $line)
465
+	{
466
+		if ($file === '' || $line === '') {
467
+			return '';
468
+		}
469
+		if (defined('EE_TESTS_DIR')) {
470
+			return "\n\t(" . $file . ' line no: ' . $line . ' ) ';
471
+		}
472
+		return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
473
+			   . $file
474
+			   . '<br />line no: '
475
+			   . $line
476
+			   . '</span>';
477
+	}
478
+
479
+
480
+
481
+	/**
482
+	 * @param string $content
483
+	 * @return string
484
+	 */
485
+	protected static function orange_span($content = '')
486
+	{
487
+		if (defined('EE_TESTS_DIR')) {
488
+			return $content;
489
+		}
490
+		return '<span style="color:#E76700">' . $content . '</span>';
491
+	}
492
+
493
+
494
+
495
+	/**
496
+	 * @param mixed $var
497
+	 * @return string
498
+	 */
499
+	protected static function pre_span($var)
500
+	{
501
+		ob_start();
502
+		var_dump($var);
503
+		$var = ob_get_clean();
504
+		if (defined('EE_TESTS_DIR')) {
505
+			return "\n" . $var;
506
+		}
507
+		return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
508
+	}
509
+
510
+
511
+
512
+	/**
513
+	 * @param mixed      $var
514
+	 * @param string     $var_name
515
+	 * @param string     $file
516
+	 * @param int|string $line
517
+	 * @param int        $heading_tag
518
+	 * @param bool       $die
519
+	 */
520
+	public static function printr(
521
+		$var,
522
+		$var_name = '',
523
+		$file = '',
524
+		$line = '',
525
+		$heading_tag = 5,
526
+		$die = false
527
+	) {
528
+		// return;
529
+		$file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
530
+		$margin = is_admin() ? ' 180px' : '0';
531
+		//$print_r = false;
532
+		if (is_string($var)) {
533
+			EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
534
+			return;
535
+		}
536
+		if (is_object($var)) {
537
+			$var_name = ! $var_name ? 'object' : $var_name;
538
+			//$print_r = true;
539
+		} else if (is_array($var)) {
540
+			$var_name = ! $var_name ? 'array' : $var_name;
541
+			//$print_r = true;
542
+		} else if (is_numeric($var)) {
543
+			$var_name = ! $var_name ? 'numeric' : $var_name;
544
+		} else if ($var === null) {
545
+			$var_name = ! $var_name ? 'null' : $var_name;
546
+		}
547
+		$var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
548
+		$heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
549
+		$result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
550
+		$result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
551
+				EEH_Debug_Tools::pre_span($var)
552
+			);
553
+		$result .= EEH_Debug_Tools::file_and_line($file, $line);
554
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
555
+		if ($die) {
556
+			die($result);
557
+		}
558
+		echo $result;
559
+	}
560
+
561
+
562
+
563
+	/******************** deprecated ********************/
564
+
565
+
566
+
567
+	/**
568
+	 * @deprecated 4.9.39.rc.034
569
+	 */
570
+	public function reset_times()
571
+	{
572
+		Benchmark::resetTimes();
573
+	}
574
+
575
+
576
+
577
+	/**
578
+	 * @deprecated 4.9.39.rc.034
579
+	 * @param null $timer_name
580
+	 */
581
+	public function start_timer($timer_name = null)
582
+	{
583
+		Benchmark::startTimer($timer_name);
584
+	}
585
+
586
+
587
+
588
+	/**
589
+	 * @deprecated 4.9.39.rc.034
590
+	 * @param string $timer_name
591
+	 */
592
+	public function stop_timer($timer_name = '')
593
+	{
594
+		Benchmark::stopTimer($timer_name);
595
+	}
596
+
597
+
598
+
599
+	/**
600
+	 * @deprecated 4.9.39.rc.034
601
+	 * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
602
+	 * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
603
+	 * @return void
604
+	 */
605
+	public function measure_memory($label, $output_now = false)
606
+	{
607
+		Benchmark::measureMemory($label, $output_now);
608
+	}
609
+
610
+
611
+
612
+	/**
613
+	 * @deprecated 4.9.39.rc.034
614
+	 * @param int $size
615
+	 * @return string
616
+	 */
617
+	public function convert($size)
618
+	{
619
+		return Benchmark::convert($size);
620
+	}
621
+
622
+
623
+
624
+	/**
625
+	 * @deprecated 4.9.39.rc.034
626
+	 * @param bool $output_now
627
+	 * @return string
628
+	 */
629
+	public function show_times($output_now = true)
630
+	{
631
+		return Benchmark::displayResults($output_now);
632
+	}
633
+
634
+
635
+
636
+	/**
637
+	 * @deprecated 4.9.39.rc.034
638
+	 * @param string $timer_name
639
+	 * @param float  $total_time
640
+	 * @return string
641
+	 */
642
+	public function format_time($timer_name, $total_time)
643
+	{
644
+		return Benchmark::formatTime($timer_name, $total_time);
645
+	}
646 646
 
647 647
 
648 648
 
@@ -655,31 +655,31 @@  discard block
 block discarded – undo
655 655
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
656 656
  */
657 657
 if (class_exists('Kint') && ! function_exists('dump_wp_query')) {
658
-    function dump_wp_query()
659
-    {
660
-        global $wp_query;
661
-        d($wp_query);
662
-    }
658
+	function dump_wp_query()
659
+	{
660
+		global $wp_query;
661
+		d($wp_query);
662
+	}
663 663
 }
664 664
 /**
665 665
  * borrowed from Kint Debugger
666 666
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
667 667
  */
668 668
 if (class_exists('Kint') && ! function_exists('dump_wp')) {
669
-    function dump_wp()
670
-    {
671
-        global $wp;
672
-        d($wp);
673
-    }
669
+	function dump_wp()
670
+	{
671
+		global $wp;
672
+		d($wp);
673
+	}
674 674
 }
675 675
 /**
676 676
  * borrowed from Kint Debugger
677 677
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
678 678
  */
679 679
 if (class_exists('Kint') && ! function_exists('dump_post')) {
680
-    function dump_post()
681
-    {
682
-        global $post;
683
-        d($post);
684
-    }
680
+	function dump_post()
681
+	{
682
+		global $post;
683
+		d($post);
684
+	}
685 685
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\services\Benchmark;
2 2
 
3
-if (! defined('EVENT_ESPRESSO_VERSION')) {
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('No direct script access allowed');
5 5
 }
6 6
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
     public static function instance()
41 41
     {
42 42
         // check if class object is instantiated, and instantiated properly
43
-        if (! self::$_instance instanceof EEH_Debug_Tools) {
43
+        if ( ! self::$_instance instanceof EEH_Debug_Tools) {
44 44
             self::$_instance = new self();
45 45
         }
46 46
         return self::$_instance;
@@ -54,13 +54,13 @@  discard block
 block discarded – undo
54 54
     private function __construct()
55 55
     {
56 56
         // load Kint PHP debugging library
57
-        if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) {
57
+        if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) {
58 58
             // despite EE4 having a check for an existing copy of the Kint debugging class,
59 59
             // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
60 60
             // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
61 61
             // so we've moved it to our test folder so that it is not included with production releases
62 62
             // plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
63
-            require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php');
63
+            require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php');
64 64
         }
65 65
         // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
66 66
         //add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      */
81 81
     public static function show_db_name()
82 82
     {
83
-        if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
83
+        if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
84 84
             echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
85 85
                  . DB_NAME
86 86
                  . '</p>';
@@ -131,11 +131,11 @@  discard block
 block discarded – undo
131 131
         echo '<br/><br/><br/><h3>Hooked Functions</h3>';
132 132
         if ($tag) {
133 133
             $hook[$tag] = $wp_filter[$tag];
134
-            if (! is_array($hook[$tag])) {
134
+            if ( ! is_array($hook[$tag])) {
135 135
                 trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
136 136
                 return;
137 137
             }
138
-            echo '<h5>For Tag: ' . $tag . '</h5>';
138
+            echo '<h5>For Tag: '.$tag.'</h5>';
139 139
         } else {
140 140
             $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
141 141
             ksort($hook);
@@ -188,17 +188,17 @@  discard block
 block discarded – undo
188 188
     {
189 189
         if (WP_DEBUG) {
190 190
             $activation_errors = ob_get_contents();
191
-            if (! empty($activation_errors)) {
192
-                $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
191
+            if ( ! empty($activation_errors)) {
192
+                $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors;
193 193
             }
194
-            espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
194
+            espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php');
195 195
             if (class_exists('EEH_File')) {
196 196
                 try {
197 197
                     EEH_File::ensure_file_exists_and_is_writable(
198
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html'
198
+                        EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html'
199 199
                     );
200 200
                     EEH_File::write_to_file(
201
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
201
+                        EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html',
202 202
                         $activation_errors
203 203
                     );
204 204
                 } catch (EE_Error $e) {
@@ -216,11 +216,11 @@  discard block
 block discarded – undo
216 216
             } else {
217 217
                 // old school attempt
218 218
                 file_put_contents(
219
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html',
219
+                    EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html',
220 220
                     $activation_errors
221 221
                 );
222 222
             }
223
-            $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
223
+            $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors;
224 224
             update_option('ee_plugin_activation_errors', $activation_errors);
225 225
         }
226 226
     }
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
         // don't trigger error if doing ajax,
281 281
         // instead we'll add a transient EE_Error notice that in theory should show on the next request.
282 282
         if (defined('DOING_AJAX') && DOING_AJAX) {
283
-            $error_message .= ' ' . esc_html__(
283
+            $error_message .= ' '.esc_html__(
284 284
                     'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
285 285
                     'event_espresso'
286 286
                 );
@@ -324,16 +324,16 @@  discard block
 block discarded – undo
324 324
         $debug_key = 'EE_DEBUG_SPCO'
325 325
     ) {
326 326
         if (WP_DEBUG) {
327
-            $debug_key = $debug_key . '_' . EE_Session::instance()->id();
327
+            $debug_key = $debug_key.'_'.EE_Session::instance()->id();
328 328
             $debug_data = get_option($debug_key, array());
329 329
             $default_data = array(
330
-                $class => $func . '() : ' . $line,
330
+                $class => $func.'() : '.$line,
331 331
                 'REQ'  => $display_request ? $_REQUEST : '',
332 332
             );
333 333
             // don't serialize objects
334 334
             $info = self::strip_objects($info);
335 335
             $index = ! empty($debug_index) ? $debug_index : 0;
336
-            if (! isset($debug_data[$index])) {
336
+            if ( ! isset($debug_data[$index])) {
337 337
                 $debug_data[$index] = array();
338 338
             }
339 339
             $debug_data[$index][microtime()] = array_merge($default_data, $info);
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
                 unset($info[$key]);
370 370
             }
371 371
         }
372
-        return (array)$info;
372
+        return (array) $info;
373 373
     }
374 374
 
375 375
 
@@ -399,8 +399,8 @@  discard block
 block discarded – undo
399 399
         $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
400 400
         $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
401 401
         $result .= $is_method
402
-            ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
403
-            : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
402
+            ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()')
403
+            : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var);
404 404
         $result .= EEH_Debug_Tools::file_and_line($file, $line);
405 405
         $result .= EEH_Debug_Tools::headingX($heading_tag);
406 406
         if ($die) {
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
             return "\n{$var_name}";
424 424
         }
425 425
         $margin = "25px 0 0 {$margin}";
426
-        return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
426
+        return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>';
427 427
     }
428 428
 
429 429
 
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
         if (defined('EE_TESTS_DIR')) {
438 438
             return '';
439 439
         }
440
-        return '</' . $heading_tag . '>';
440
+        return '</'.$heading_tag.'>';
441 441
     }
442 442
 
443 443
 
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
         if (defined('EE_TESTS_DIR')) {
452 452
             return $content;
453 453
         }
454
-        return '<span style="color:#999">' . $content . '</span>';
454
+        return '<span style="color:#999">'.$content.'</span>';
455 455
     }
456 456
 
457 457
 
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
             return '';
468 468
         }
469 469
         if (defined('EE_TESTS_DIR')) {
470
-            return "\n\t(" . $file . ' line no: ' . $line . ' ) ';
470
+            return "\n\t(".$file.' line no: '.$line.' ) ';
471 471
         }
472 472
         return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
473 473
                . $file
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
         if (defined('EE_TESTS_DIR')) {
488 488
             return $content;
489 489
         }
490
-        return '<span style="color:#E76700">' . $content . '</span>';
490
+        return '<span style="color:#E76700">'.$content.'</span>';
491 491
     }
492 492
 
493 493
 
@@ -502,9 +502,9 @@  discard block
 block discarded – undo
502 502
         var_dump($var);
503 503
         $var = ob_get_clean();
504 504
         if (defined('EE_TESTS_DIR')) {
505
-            return "\n" . $var;
505
+            return "\n".$var;
506 506
         }
507
-        return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
507
+        return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>';
508 508
     }
509 509
 
510 510
 
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
         $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
548 548
         $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5';
549 549
         $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
550
-        $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
550
+        $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span(
551 551
                 EEH_Debug_Tools::pre_span($var)
552 552
             );
553 553
         $result .= EEH_Debug_Tools::file_and_line($file, $line);
Please login to merge, or discard this patch.
core/EED_Module.module.php 1 patch
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -14,121 +14,121 @@
 block discarded – undo
14 14
 abstract class EED_Module extends EE_Configurable implements ResettableInterface
15 15
 {
16 16
 
17
-    /**
18
-     * rendered output to be returned to WP
19
-     *
20
-     * @var    string $output
21
-     */
22
-    protected $output = '';
23
-
24
-    /**
25
-     * the current active espresso template theme
26
-     *
27
-     * @var    string $theme
28
-     */
29
-    protected $theme = '';
30
-
31
-
32
-
33
-    /**
34
-     * @return void
35
-     */
36
-    public static function reset()
37
-    {
38
-        $module_name = get_called_class();
39
-        new $module_name();
40
-    }
41
-
42
-
43
-
44
-    /**
45
-     *    set_hooks - for hooking into EE Core, other modules, etc
46
-     *
47
-     * @access    public
48
-     * @return    void
49
-     */
50
-    public static function set_hooks()
51
-    {
52
-    }
53
-
54
-
55
-
56
-    /**
57
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
58
-     *
59
-     * @access    public
60
-     * @return    void
61
-     */
62
-    public static function set_hooks_admin()
63
-    {
64
-    }
65
-
66
-
67
-
68
-    /**
69
-     *    run - initial module setup
70
-     *    this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters
71
-     *
72
-     * @access    public
73
-     * @var            WP $WP
74
-     * @return    void
75
-     */
76
-    abstract public function run($WP);
77
-
78
-
79
-
80
-    /**
81
-     * EED_Module constructor.
82
-     */
83
-    final public function __construct()
84
-    {
85
-        $this->theme = EE_Config::get_current_theme();
86
-        $module_name = $this->module_name();
87
-        EE_Registry::instance()->modules->{$module_name} = $this;
88
-    }
89
-
90
-
91
-
92
-    /**
93
-     * @param $module_name
94
-     * @return EED_Module
95
-     */
96
-    protected static function get_instance($module_name = '')
97
-    {
98
-        $module_name = ! empty($module_name)
99
-            ? $module_name
100
-            : get_called_class();
101
-        if (
102
-            ! isset(EE_Registry::instance()->modules->{$module_name})
103
-            || ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module
104
-        ) {
105
-            EE_Registry::instance()->add_module($module_name);
106
-        }
107
-        return EE_Registry::instance()->get_module($module_name);
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     *    module_name
114
-     *
115
-     * @access    public
116
-     * @return    string
117
-     */
118
-    public function module_name()
119
-    {
120
-        return get_class($this);
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * @return string
127
-     */
128
-    public function theme()
129
-    {
130
-        return $this->theme;
131
-    }
17
+	/**
18
+	 * rendered output to be returned to WP
19
+	 *
20
+	 * @var    string $output
21
+	 */
22
+	protected $output = '';
23
+
24
+	/**
25
+	 * the current active espresso template theme
26
+	 *
27
+	 * @var    string $theme
28
+	 */
29
+	protected $theme = '';
30
+
31
+
32
+
33
+	/**
34
+	 * @return void
35
+	 */
36
+	public static function reset()
37
+	{
38
+		$module_name = get_called_class();
39
+		new $module_name();
40
+	}
41
+
42
+
43
+
44
+	/**
45
+	 *    set_hooks - for hooking into EE Core, other modules, etc
46
+	 *
47
+	 * @access    public
48
+	 * @return    void
49
+	 */
50
+	public static function set_hooks()
51
+	{
52
+	}
53
+
54
+
55
+
56
+	/**
57
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
58
+	 *
59
+	 * @access    public
60
+	 * @return    void
61
+	 */
62
+	public static function set_hooks_admin()
63
+	{
64
+	}
65
+
66
+
67
+
68
+	/**
69
+	 *    run - initial module setup
70
+	 *    this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters
71
+	 *
72
+	 * @access    public
73
+	 * @var            WP $WP
74
+	 * @return    void
75
+	 */
76
+	abstract public function run($WP);
77
+
78
+
79
+
80
+	/**
81
+	 * EED_Module constructor.
82
+	 */
83
+	final public function __construct()
84
+	{
85
+		$this->theme = EE_Config::get_current_theme();
86
+		$module_name = $this->module_name();
87
+		EE_Registry::instance()->modules->{$module_name} = $this;
88
+	}
89
+
90
+
91
+
92
+	/**
93
+	 * @param $module_name
94
+	 * @return EED_Module
95
+	 */
96
+	protected static function get_instance($module_name = '')
97
+	{
98
+		$module_name = ! empty($module_name)
99
+			? $module_name
100
+			: get_called_class();
101
+		if (
102
+			! isset(EE_Registry::instance()->modules->{$module_name})
103
+			|| ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module
104
+		) {
105
+			EE_Registry::instance()->add_module($module_name);
106
+		}
107
+		return EE_Registry::instance()->get_module($module_name);
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 *    module_name
114
+	 *
115
+	 * @access    public
116
+	 * @return    string
117
+	 */
118
+	public function module_name()
119
+	{
120
+		return get_class($this);
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * @return string
127
+	 */
128
+	public function theme()
129
+	{
130
+		return $this->theme;
131
+	}
132 132
 
133 133
 
134 134
 
Please login to merge, or discard this patch.
core/helpers/EEH_Schema.helper.php 2 patches
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -17,74 +17,74 @@  discard block
 block discarded – undo
17 17
 class EEH_Schema {
18 18
 
19 19
 
20
-    /**
21
-     * generates JSON-based linked data for an event
22
-     *
23
-     * @param EE_Event $event
24
-     * @throws EE_Error
25
-     */
26
-    public static function add_json_linked_data_for_event(EE_Event $event)
27
-    {
28
-    	//Check we have a valid datetime for the event
29
-    	if(! $event->primary_datetime() instanceof EE_Datetime) {
30
-    		return;
31
-    	}
32
-
33
-        $template_args = array(
34
-            'event_permalink' => '',
35
-            'event_name' => '',
36
-            'event_description' => '',
37
-            'event_start' => '',
38
-            'event_end' => '',
39
-            'currency' => '',
40
-            'event_tickets' => array(),
41
-            'venue_name' => '',
42
-            'venue_url' => '',
43
-            'venue_locality' => '',
44
-            'venue_region' => '',
45
-            'event_image' => '',
46
-        );
47
-        $template_args['event_permalink'] = $event->get_permalink();
48
-        $template_args['event_name'] = $event->name();
49
-        $template_args['event_description'] = wp_strip_all_tags($event->short_description(200));
50
-        // clone datetime so that date formats don't override those for the original datetime
51
-        $primary_datetime = clone $event->primary_datetime();
52
-        $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM);
53
-        $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM);
54
-        unset($primary_datetime);
55
-        $template_args['currency'] = EE_Registry::instance()->CFG->currency->code;
56
-        foreach ($event->tickets() as $original_ticket) {
57
-            // clone tickets so that date formats don't override those for the original ticket
58
-            $ticket= clone $original_ticket;
59
-            $ID = $ticket->ID();
60
-            $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null);
61
-            $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null);
62
-            $template_args['event_tickets'][$ID]['price'] = number_format(
63
-                $ticket->price(),
64
-                EE_Registry::instance()->CFG->currency->dec_plc,
65
-                EE_Registry::instance()->CFG->currency->dec_mrk,
66
-                EE_Registry::instance()->CFG->currency->thsnds
67
-            );
68
-            unset($ticket);
69
-        }
70
-        $VNU_ID = espresso_venue_id();
71
-        if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) {
72
-            $venue = EEH_Venue_View::get_venue($VNU_ID);
73
-            $template_args['venue_name'] = get_the_title($VNU_ID);
74
-            $template_args['venue_url'] = get_permalink($VNU_ID);
75
-            $template_args['venue_locality'] = $venue->city();
76
-            $template_args['venue_region'] = $venue->state_name();
77
-        }
78
-        $template_args['event_image'] = $event->feature_image_url();
79
-        $template_args = apply_filters(
80
-            'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args',
81
-            $template_args,
82
-            $event,
83
-            $VNU_ID
84
-        );
85
-        extract($template_args, EXTR_OVERWRITE);
86
-        include EE_TEMPLATES . 'json_linked_data_for_event.template.php';
87
-    }
20
+	/**
21
+	 * generates JSON-based linked data for an event
22
+	 *
23
+	 * @param EE_Event $event
24
+	 * @throws EE_Error
25
+	 */
26
+	public static function add_json_linked_data_for_event(EE_Event $event)
27
+	{
28
+		//Check we have a valid datetime for the event
29
+		if(! $event->primary_datetime() instanceof EE_Datetime) {
30
+			return;
31
+		}
32
+
33
+		$template_args = array(
34
+			'event_permalink' => '',
35
+			'event_name' => '',
36
+			'event_description' => '',
37
+			'event_start' => '',
38
+			'event_end' => '',
39
+			'currency' => '',
40
+			'event_tickets' => array(),
41
+			'venue_name' => '',
42
+			'venue_url' => '',
43
+			'venue_locality' => '',
44
+			'venue_region' => '',
45
+			'event_image' => '',
46
+		);
47
+		$template_args['event_permalink'] = $event->get_permalink();
48
+		$template_args['event_name'] = $event->name();
49
+		$template_args['event_description'] = wp_strip_all_tags($event->short_description(200));
50
+		// clone datetime so that date formats don't override those for the original datetime
51
+		$primary_datetime = clone $event->primary_datetime();
52
+		$template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM);
53
+		$template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM);
54
+		unset($primary_datetime);
55
+		$template_args['currency'] = EE_Registry::instance()->CFG->currency->code;
56
+		foreach ($event->tickets() as $original_ticket) {
57
+			// clone tickets so that date formats don't override those for the original ticket
58
+			$ticket= clone $original_ticket;
59
+			$ID = $ticket->ID();
60
+			$template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null);
61
+			$template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null);
62
+			$template_args['event_tickets'][$ID]['price'] = number_format(
63
+				$ticket->price(),
64
+				EE_Registry::instance()->CFG->currency->dec_plc,
65
+				EE_Registry::instance()->CFG->currency->dec_mrk,
66
+				EE_Registry::instance()->CFG->currency->thsnds
67
+			);
68
+			unset($ticket);
69
+		}
70
+		$VNU_ID = espresso_venue_id();
71
+		if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) {
72
+			$venue = EEH_Venue_View::get_venue($VNU_ID);
73
+			$template_args['venue_name'] = get_the_title($VNU_ID);
74
+			$template_args['venue_url'] = get_permalink($VNU_ID);
75
+			$template_args['venue_locality'] = $venue->city();
76
+			$template_args['venue_region'] = $venue->state_name();
77
+		}
78
+		$template_args['event_image'] = $event->feature_image_url();
79
+		$template_args = apply_filters(
80
+			'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args',
81
+			$template_args,
82
+			$event,
83
+			$VNU_ID
84
+		);
85
+		extract($template_args, EXTR_OVERWRITE);
86
+		include EE_TEMPLATES . 'json_linked_data_for_event.template.php';
87
+	}
88 88
 
89 89
 
90 90
 	/**
@@ -98,8 +98,8 @@  discard block
 block discarded – undo
98 98
 	 */
99 99
 	public static function location( $location = null ) {
100 100
 		return ! empty( $location ) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">'
101
-		                              . $location
102
-		                              . '</div>' : '';
101
+									  . $location
102
+									  . '</div>' : '';
103 103
 	}
104 104
 
105 105
 
@@ -219,8 +219,8 @@  discard block
 block discarded – undo
219 219
 	 */
220 220
 	public static function postalCode( EEI_Address $obj_with_address = null ) {
221 221
 		return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">'
222
-		                                                                              . $obj_with_address->zip()
223
-		                                                                              . '</span>' : '';
222
+																					  . $obj_with_address->zip()
223
+																					  . '</span>' : '';
224 224
 	}
225 225
 
226 226
 
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 		//Check the URL includes a scheme
255 255
 		$parsed_url = parse_url($url);
256 256
 		if ( empty($parsed_url['scheme']) ) {
257
-		    $url = 'http://' . ltrim($url, '/');
257
+			$url = 'http://' . ltrim($url, '/');
258 258
 		}
259 259
 
260 260
 		$atts = '';
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
4
-	exit( 'No direct script access allowed' );
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
     public static function add_json_linked_data_for_event(EE_Event $event)
27 27
     {
28 28
     	//Check we have a valid datetime for the event
29
-    	if(! $event->primary_datetime() instanceof EE_Datetime) {
29
+    	if ( ! $event->primary_datetime() instanceof EE_Datetime) {
30 30
     		return;
31 31
     	}
32 32
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
         $template_args['currency'] = EE_Registry::instance()->CFG->currency->code;
56 56
         foreach ($event->tickets() as $original_ticket) {
57 57
             // clone tickets so that date formats don't override those for the original ticket
58
-            $ticket= clone $original_ticket;
58
+            $ticket = clone $original_ticket;
59 59
             $ID = $ticket->ID();
60 60
             $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null);
61 61
             $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null);
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
             $VNU_ID
84 84
         );
85 85
         extract($template_args, EXTR_OVERWRITE);
86
-        include EE_TEMPLATES . 'json_linked_data_for_event.template.php';
86
+        include EE_TEMPLATES.'json_linked_data_for_event.template.php';
87 87
     }
88 88
 
89 89
 
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
 	 * @param string $location
97 97
 	 * @return string
98 98
 	 */
99
-	public static function location( $location = null ) {
100
-		return ! empty( $location ) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">'
99
+	public static function location($location = null) {
100
+		return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">'
101 101
 		                              . $location
102 102
 		                              . '</div>' : '';
103 103
 	}
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
 	 * @param string $name
113 113
 	 * @return string
114 114
 	 */
115
-	public static function name( $name = null ) {
116
-		return ! empty( $name ) ? '<span itemprop="name">' . $name . '</span>' : '';
115
+	public static function name($name = null) {
116
+		return ! empty($name) ? '<span itemprop="name">'.$name.'</span>' : '';
117 117
 	}
118 118
 
119 119
 
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 	 * @param EEI_Address $obj_with_address
127 127
 	 * @return string
128 128
 	 */
129
-	public static function streetAddress( EEI_Address $obj_with_address = null ) {
129
+	public static function streetAddress(EEI_Address $obj_with_address = null) {
130 130
 		return $obj_with_address->address() !== null && $obj_with_address->address() !== ''
131
-			? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : '';
131
+			? '<span itemprop="streetAddress">'.$obj_with_address->address().'</span>' : '';
132 132
 	}
133 133
 
134 134
 
@@ -141,14 +141,14 @@  discard block
 block discarded – undo
141 141
 	 * @param EEI_Address $obj_with_address
142 142
 	 * @return string
143 143
 	 */
144
-	public static function postOfficeBoxNumber( EEI_Address $obj_with_address = null ) {
144
+	public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null) {
145 145
 		// regex check for some form of PO Box or P.O. Box, etc, etc, etc
146
-		if ( preg_match(
146
+		if (preg_match(
147 147
 			"/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i",
148 148
 			$obj_with_address->address2()
149
-		) ) {
149
+		)) {
150 150
 			return $obj_with_address->address2() !== null && $obj_with_address->address2() !== ''
151
-				? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : '';
151
+				? '<span itemprop="postOfficeBoxNumber">'.$obj_with_address->address2().'</span>' : '';
152 152
 		} else {
153 153
 			return $obj_with_address->address2();
154 154
 		}
@@ -164,9 +164,9 @@  discard block
 block discarded – undo
164 164
 	 * @param EEI_Address $obj_with_address
165 165
 	 * @return string
166 166
 	 */
167
-	public static function addressLocality( EEI_Address $obj_with_address = null ) {
167
+	public static function addressLocality(EEI_Address $obj_with_address = null) {
168 168
 		return $obj_with_address->city() !== null && $obj_with_address->city() !== ''
169
-			? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : '';
169
+			? '<span itemprop="addressLocality">'.$obj_with_address->city().'</span>' : '';
170 170
 	}
171 171
 
172 172
 
@@ -179,10 +179,10 @@  discard block
 block discarded – undo
179 179
 	 * @param EEI_Address $obj_with_address
180 180
 	 * @return string
181 181
 	 */
182
-	public static function addressRegion( EEI_Address $obj_with_address = null ) {
182
+	public static function addressRegion(EEI_Address $obj_with_address = null) {
183 183
 		$state = $obj_with_address->state_name();
184
-		if ( ! empty( $state ) ) {
185
-			return '<span itemprop="addressRegion">' . $state . '</span>';
184
+		if ( ! empty($state)) {
185
+			return '<span itemprop="addressRegion">'.$state.'</span>';
186 186
 		} else {
187 187
 			return '';
188 188
 		}
@@ -198,10 +198,10 @@  discard block
 block discarded – undo
198 198
 	 * @param EEI_Address $obj_with_address
199 199
 	 * @return string
200 200
 	 */
201
-	public static function addressCountry( EEI_Address $obj_with_address = null ) {
201
+	public static function addressCountry(EEI_Address $obj_with_address = null) {
202 202
 		$country = $obj_with_address->country_name();
203
-		if ( ! empty( $country ) ) {
204
-			return '<span itemprop="addressCountry">' . $country . '</span>';
203
+		if ( ! empty($country)) {
204
+			return '<span itemprop="addressCountry">'.$country.'</span>';
205 205
 		} else {
206 206
 			return '';
207 207
 		}
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	 * @param EEI_Address $obj_with_address
218 218
 	 * @return string
219 219
 	 */
220
-	public static function postalCode( EEI_Address $obj_with_address = null ) {
220
+	public static function postalCode(EEI_Address $obj_with_address = null) {
221 221
 		return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">'
222 222
 		                                                                              . $obj_with_address->zip()
223 223
 		                                                                              . '</span>' : '';
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
 	 * @param string $phone_nmbr
234 234
 	 * @return string
235 235
 	 */
236
-	public static function telephone( $phone_nmbr = null ) {
237
-		return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>'
236
+	public static function telephone($phone_nmbr = null) {
237
+		return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">'.$phone_nmbr.'</span>'
238 238
 			: '';
239 239
 	}
240 240
 
@@ -250,19 +250,19 @@  discard block
 block discarded – undo
250 250
 	 * @param array  $attributes - array of additional link attributes in  attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' )
251 251
 	 * @return string (link)
252 252
 	 */
253
-	public static function url( $url = null, $text = null, $attributes = array() ) {
253
+	public static function url($url = null, $text = null, $attributes = array()) {
254 254
 		//Check the URL includes a scheme
255 255
 		$parsed_url = parse_url($url);
256
-		if ( empty($parsed_url['scheme']) ) {
257
-		    $url = 'http://' . ltrim($url, '/');
256
+		if (empty($parsed_url['scheme'])) {
257
+		    $url = 'http://'.ltrim($url, '/');
258 258
 		}
259 259
 
260 260
 		$atts = '';
261
-		foreach ( $attributes as $attribute => $value ) {
262
-			$atts .= ' ' . $attribute . '="' . $value . '"';
261
+		foreach ($attributes as $attribute => $value) {
262
+			$atts .= ' '.$attribute.'="'.$value.'"';
263 263
 		}
264 264
 		$text = $text !== null && $text !== '' ? $text : $url;
265
-		return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>'
265
+		return $url !== null && $url !== '' ? '<a itemprop="url" href="'.$url.'"'.$atts.'>'.$text.'</a>'
266 266
 			: '';
267 267
 	}
268 268
 
Please login to merge, or discard this patch.
form_sections/strategies/display/EE_Number_Input_Display_Strategy.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -64,6 +64,9 @@
 block discarded – undo
64 64
     }
65 65
 
66 66
 
67
+    /**
68
+     * @param string $argument_label
69
+     */
67 70
     private function throwValidationException($argument_label, $argument_value)
68 71
     {
69 72
         throw new InvalidArgumentException(
Please login to merge, or discard this patch.
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -14,111 +14,111 @@
 block discarded – undo
14 14
 class EE_Number_Input_Display_Strategy extends EE_Display_Strategy_Base
15 15
 {
16 16
 
17
-    /**
18
-     * minimum value for number field
19
-     *
20
-     * @var int|null $min
21
-     */
22
-    protected $min;
23
-
24
-    /**
25
-     * maximum value for number field
26
-     *
27
-     * @var int|null $max
28
-     */
29
-    protected $max;
30
-
31
-
32
-    /**
33
-     * This is used to set the "step" attribute for the html5 number input.
34
-     * Controls the increments on the input when incrementing or decrementing the value.
35
-     * Note:  Although the step attribute allows for the string "any" to be used, Firefox and Chrome will interpret that
36
-     * to increment by 1.  So although "any" is accepted as a value, it is converted to 1.
37
-     * @var float
38
-     */
39
-    protected $step;
40
-
41
-
42
-    /**
43
-     * EE_Number_Input_Display_Strategy constructor.
44
-     * Null is the default value for the incoming arguments because 0 is a valid value.  So we use null
45
-     * to indicate NOT setting this attribute.
46
-     *
47
-     * @param int|null $min
48
-     * @param int|null $max
49
-     * @param int|null $step
50
-     * @throws InvalidArgumentException
51
-     */
52
-    public function __construct($min = null, $max = null, $step = null)
53
-    {
54
-        $this->min = is_numeric($min) || $min === null
55
-            ? $min
56
-            : $this->throwValidationException('min', $min);
57
-        $this->max = is_numeric($max) || $max === null
58
-            ? $max
59
-            : $this->throwValidationException('max', $max);
60
-        $step = $step === 'any' ? 1 : $step;
61
-        $this->step = is_numeric($step) || $step === null
62
-            ? $step
63
-            : $this->throwValidationException('step', $step);
64
-    }
65
-
66
-
67
-    private function throwValidationException($argument_label, $argument_value)
68
-    {
69
-        throw new InvalidArgumentException(
70
-            sprintf(
71
-                esc_html__(
72
-                    'The %1$s parameter value for %2$s must be numeric or null, %3$s was passed into the constructor.',
73
-                    'event_espresso'
74
-                ),
75
-                $argument_label,
76
-                __CLASS__,
77
-                $argument_value
78
-            )
79
-        );
80
-    }
81
-
82
-
83
-
84
-    /**
85
-     * @return string of html to display the field
86
-     */
87
-    public function display()
88
-    {
89
-        $input = $this->_opening_tag('input');
90
-        $input .= $this->_attributes_string(
91
-            array_merge(
92
-                $this->_standard_attributes_array(),
93
-                $this->getNumberInputAttributes()
94
-            )
95
-        );
96
-        $input .= $this->_close_tag();
97
-        return $input;
98
-    }
99
-
100
-
101
-    /**
102
-     * Return the attributes specific to this display strategy
103
-     * @return array
104
-     */
105
-    private function getNumberInputAttributes()
106
-    {
107
-        $attributes = array(
108
-            'type' => 'number',
109
-            'value' => $this->_input->raw_value_in_form()
110
-        );
111
-        if ($this->min !== null) {
112
-            $attributes['min'] = $this->min;
113
-        }
114
-        if ($this->max !== null) {
115
-            $attributes['max'] = $this->max;
116
-        }
117
-        if ($this->step !== null) {
118
-            $attributes['step'] = $this->step;
119
-        }
120
-        return $attributes;
121
-    }
17
+	/**
18
+	 * minimum value for number field
19
+	 *
20
+	 * @var int|null $min
21
+	 */
22
+	protected $min;
23
+
24
+	/**
25
+	 * maximum value for number field
26
+	 *
27
+	 * @var int|null $max
28
+	 */
29
+	protected $max;
30
+
31
+
32
+	/**
33
+	 * This is used to set the "step" attribute for the html5 number input.
34
+	 * Controls the increments on the input when incrementing or decrementing the value.
35
+	 * Note:  Although the step attribute allows for the string "any" to be used, Firefox and Chrome will interpret that
36
+	 * to increment by 1.  So although "any" is accepted as a value, it is converted to 1.
37
+	 * @var float
38
+	 */
39
+	protected $step;
40
+
41
+
42
+	/**
43
+	 * EE_Number_Input_Display_Strategy constructor.
44
+	 * Null is the default value for the incoming arguments because 0 is a valid value.  So we use null
45
+	 * to indicate NOT setting this attribute.
46
+	 *
47
+	 * @param int|null $min
48
+	 * @param int|null $max
49
+	 * @param int|null $step
50
+	 * @throws InvalidArgumentException
51
+	 */
52
+	public function __construct($min = null, $max = null, $step = null)
53
+	{
54
+		$this->min = is_numeric($min) || $min === null
55
+			? $min
56
+			: $this->throwValidationException('min', $min);
57
+		$this->max = is_numeric($max) || $max === null
58
+			? $max
59
+			: $this->throwValidationException('max', $max);
60
+		$step = $step === 'any' ? 1 : $step;
61
+		$this->step = is_numeric($step) || $step === null
62
+			? $step
63
+			: $this->throwValidationException('step', $step);
64
+	}
65
+
66
+
67
+	private function throwValidationException($argument_label, $argument_value)
68
+	{
69
+		throw new InvalidArgumentException(
70
+			sprintf(
71
+				esc_html__(
72
+					'The %1$s parameter value for %2$s must be numeric or null, %3$s was passed into the constructor.',
73
+					'event_espresso'
74
+				),
75
+				$argument_label,
76
+				__CLASS__,
77
+				$argument_value
78
+			)
79
+		);
80
+	}
81
+
82
+
83
+
84
+	/**
85
+	 * @return string of html to display the field
86
+	 */
87
+	public function display()
88
+	{
89
+		$input = $this->_opening_tag('input');
90
+		$input .= $this->_attributes_string(
91
+			array_merge(
92
+				$this->_standard_attributes_array(),
93
+				$this->getNumberInputAttributes()
94
+			)
95
+		);
96
+		$input .= $this->_close_tag();
97
+		return $input;
98
+	}
99
+
100
+
101
+	/**
102
+	 * Return the attributes specific to this display strategy
103
+	 * @return array
104
+	 */
105
+	private function getNumberInputAttributes()
106
+	{
107
+		$attributes = array(
108
+			'type' => 'number',
109
+			'value' => $this->_input->raw_value_in_form()
110
+		);
111
+		if ($this->min !== null) {
112
+			$attributes['min'] = $this->min;
113
+		}
114
+		if ($this->max !== null) {
115
+			$attributes['max'] = $this->max;
116
+		}
117
+		if ($this->step !== null) {
118
+			$attributes['step'] = $this->step;
119
+		}
120
+		return $attributes;
121
+	}
122 122
 
123 123
 }
124 124
 // End of file EE_Number_Input_Display_Strategy.php
Please login to merge, or discard this patch.