Completed
Branch FET/337/reserved-instance-inte... (8ac9b7)
by
unknown
73:19 queued 58:57
created

EED_Events_Archive::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 1
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
1
<?php
2
3
use EventEspresso\core\exceptions\InvalidDataTypeException;
4
use EventEspresso\core\exceptions\InvalidInterfaceException;
5
use EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton;
6
use EventEspresso\core\services\loaders\LoaderFactory;
7
use EventEspresso\modules\events_archive\EventsArchiveIframe;
8
9
defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed');
10
11
12
13
/**
14
 * Event List
15
 *
16
 * @package        Event Espresso
17
 * @subpackage     /modules/events_archive/
18
 * @author         Brent Christensen
19
 */
20
class EED_Events_Archive extends EED_Module
21
{
22
23
    const EVENT_DETAILS_PRIORITY   = 100;
24
25
    const EVENT_DATETIMES_PRIORITY = 110;
26
27
    const EVENT_TICKETS_PRIORITY   = 120;
28
29
    const EVENT_VENUES_PRIORITY    = 130;
30
31
32
    public static $espresso_event_list_ID    = 0;
33
34
    public static $espresso_grid_event_lists = array();
35
36
    /**
37
     * @type bool $using_get_the_excerpt
38
     */
39
    protected static $using_get_the_excerpt = false;
40
41
    /**
42
     * Used to flag when the event list is being called from an external iframe.
43
     *
44
     * @var bool $iframe
45
     */
46
    protected static $iframe = false;
47
48
    /**
49
     * @var \EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton $_iframe_embed_button
50
     */
51
    private static $_iframe_embed_button;
52
53
    /**
54
     * @type EE_Template_Part_Manager $template_parts
55
     */
56
    protected $template_parts;
57
58
59
60
    /**
61
     * @return EED_Events_Archive
62
     */
63
    public static function instance()
64
    {
65
        return parent::get_instance(__CLASS__);
66
    }
67
68
69
    /**
70
     * set_hooks - for hooking into EE Core, other modules, etc
71
     *
72
     * @return void
73
     * @throws InvalidArgumentException
74
     * @throws InvalidDataTypeException
75
     * @throws InvalidInterfaceException
76
     */
77
    public static function set_hooks()
78
    {
79
        /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */
80
        $custom_post_type_definitions = LoaderFactory::getLoader()->getShared(
81
            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
82
        );
83
        $custom_post_types = $custom_post_type_definitions->getDefinitions();
84
        EE_Config::register_route(
85
            $custom_post_types['espresso_events']['plural_slug'],
86
            'Events_Archive',
87
            'run'
88
        );
89
        EE_Config::register_route(
90
            'event_list',
91
            'Events_Archive',
92
            'event_list'
93
        );
94
        EE_Config::register_route(
95
            'iframe',
96
            'Events_Archive',
97
            'event_list_iframe',
98
            'event_list'
99
        );
100
        add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2);
101
    }
102
103
104
105
    /**
106
     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
107
     *
108
     * @access    public
109
     * @return    void
110
     */
111
    public static function set_hooks_admin()
112
    {
113
        add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2);
114
        // hook into the end of the \EE_Admin_Page::_load_page_dependencies()
115
        // to load assets for "espresso_events" page on the "default" route (action)
116
        add_action(
117
            'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default',
118
            array('EED_Events_Archive', 'event_list_iframe_embed_button'),
119
            10
120
        );
121
    }
122
123
124
125
    /**
126
     *    set_definitions
127
     *
128
     * @access    public
129
     * @return    void
130
     */
131
    public static function set_definitions()
132
    {
133
        define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
134
        define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS);
135
    }
136
137
138
139
    /**
140
     * set up EE_Events_Archive_Config
141
     */
142
    protected function set_config()
143
    {
144
        $this->set_config_section('template_settings');
145
        $this->set_config_class('EE_Events_Archive_Config');
146
        $this->set_config_name('EED_Events_Archive');
147
    }
148
149
150
151
    /**
152
     * @return EventListIframeEmbedButton
153
     */
154
    public static function get_iframe_embed_button()
155
    {
156
        if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) {
157
            self::$_iframe_embed_button = new EventListIframeEmbedButton();
158
        }
159
        return self::$_iframe_embed_button;
160
    }
161
162
163
164
    /**
165
     * event_list_iframe_embed_button
166
     *
167
     * @return    void
168
     * @throws \EE_Error
169
     */
170
    public static function event_list_iframe_embed_button()
171
    {
172
        $iframe_embed_button = \EED_Events_Archive::get_iframe_embed_button();
173
        $iframe_embed_button->addEmbedButton();
174
    }
175
176
177
178
    /**
179
     *    initialize_template_parts
180
     *
181
     * @access    public
182
     * @param \EE_Events_Archive_Config $config
183
     * @return \EE_Template_Part_Manager
184
     */
185 View Code Duplication
    public function initialize_template_parts(EE_Events_Archive_Config $config = null)
186
    {
187
        $config = $config instanceof EE_Events_Archive_Config ? $config : $this->config();
188
        EEH_Autoloader::instance()->register_template_part_autoloaders();
189
        $template_parts = new EE_Template_Part_Manager();
190
        $template_parts->add_template_part(
191
            'tickets',
192
            __('Ticket Selector', 'event_espresso'),
193
            'content-espresso_events-tickets.php',
194
            $config->display_order_tickets
0 ignored issues
show
Bug introduced by
The property display_order_tickets does not seem to exist in EE_Config_Base.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
195
        );
196
        $template_parts->add_template_part(
197
            'datetimes',
198
            __('Dates and Times', 'event_espresso'),
199
            'content-espresso_events-datetimes.php',
200
            $config->display_order_datetimes
0 ignored issues
show
Bug introduced by
The property display_order_datetimes does not seem to exist in EE_Config_Base.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
201
        );
202
        $template_parts->add_template_part(
203
            'event',
204
            __('Event Description', 'event_espresso'),
205
            'content-espresso_events-details.php',
206
            $config->display_order_event
0 ignored issues
show
Bug introduced by
The property display_order_event does not seem to exist in EE_Config_Base.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
207
        );
208
        $template_parts->add_template_part(
209
            'venue',
210
            __('Venue Information', 'event_espresso'),
211
            'content-espresso_events-venues.php',
212
            $config->display_order_venue
0 ignored issues
show
Bug introduced by
The property display_order_venue does not seem to exist in EE_Config_Base.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
213
        );
214
        do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts);
215
        return $template_parts;
216
    }
217
218
219
220
    /**
221
     *    run - initial module setup - this gets called by the EE_Front_Controller if the module route is found in the incoming request
222
     *
223
     * @access    public
224
     * @param WP $WP
225
     * @return    void
226
     */
227
    public function run($WP)
228
    {
229
        do_action('AHEE__EED_Events_Archive__before_run');
230
        // ensure valid EE_Events_Archive_Config() object exists
231
        $this->set_config();
232
        /** @type EE_Events_Archive_Config $config */
233
        $config = $this->config();
234
        // load other required components
235
        $this->load_event_list_assets();
236
        // filter the WP posts_join, posts_where, and posts_orderby SQL clauses
237
        //add query filters
238
        EEH_Event_Query::add_query_filters();
239
        // set params that will get used by the filters
240
        EEH_Event_Query::set_query_params(
241
            '',    // month
242
            '',    // category
243
            $config->display_expired_events,    // show_expired
244
            'start_date',    // orderby
245
            'ASC'    // sort
246
        );
247
        // check what template is loaded
248
        add_filter('template_include', array($this, 'template_include'), 999, 1);
249
    }
250
251
252
253
    /**
254
     * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting
255
     *
256
     * @return    void
257
     */
258
    public function event_list()
259
    {
260
        // ensure valid EE_Events_Archive_Config() object exists
261
        $this->set_config();
262
        // load other required components
263
        $this->load_event_list_assets();
264
    }
265
266
267
268
    /**
269
     * @access    public
270
     * @return    void
271
     * @throws \EE_Error
272
     * @throws \DomainException
273
     */
274
    public function event_list_iframe()
275
    {
276
        \EED_Events_Archive::$iframe = true;
277
        $event_list_iframe = new EventsArchiveIframe($this);
278
        $event_list_iframe->display();
279
    }
280
281
282
283
    /**
284
     * @access public
285
     * @return string
286
     */
287
    public static function is_iframe()
288
    {
289
        return \EED_Events_Archive::$iframe;
290
    }
291
292
293
294
    /**
295
     * @access public
296
     * @return string
297
     */
298
    public static function link_target()
299
    {
300
        return \EED_Events_Archive::$iframe ? ' target="_blank"' : '';
301
    }
302
303
304
305
    /**
306
     *    template_include
307
     *
308
     * @access    public
309
     * @param string $template
310
     * @return    string
311
     */
312
    public function template_include($template = '')
313
    {
314
        // don't add content filter for dedicated EE child themes or private posts
315
        if (! EEH_Template::is_espresso_theme()) {
316
            /** @type EE_Events_Archive_Config $config */
317
            $config = $this->config();
318
            // add status banner ?
319
            if ($config->display_status_banner) {
320
                add_filter('the_title', array('EED_Events_Archive', 'the_title'), 100, 2);
321
            }
322
            // if NOT a custom template
323
            if (
324
                apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false)
325
                || EE_Registry::instance()
326
                              ->load_core('Front_Controller')
327
                              ->get_selected_template() !== 'archive-espresso_events.php'
328
            ) {
329
                // don't display entry meta because the existing theme will take care of that
330
                add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true');
331
                // load functions.php file for the theme (loaded by WP if using child theme)
332
                EEH_Template::load_espresso_theme_functions();
333
                // because we don't know if the theme is using the_excerpt()
334
                add_filter(
335
                    'the_excerpt',
336
                    array('EED_Events_Archive', 'event_details'),
337
                    EED_Events_Archive::EVENT_DETAILS_PRIORITY
338
                );
339
                // or the_content
340
                add_filter(
341
                    'the_content',
342
                    array('EED_Events_Archive', 'event_details'),
343
                    EED_Events_Archive::EVENT_DETAILS_PRIORITY
344
                );
345
                // and just in case they are running get_the_excerpt() which DESTROYS things
346
                add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1);
347
                // don't display entry meta because the existing theme will take care of that
348
                add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
349
            }
350
        }
351
        return $template;
352
    }
353
354
355
356
    /**
357
     *    get_the_excerpt - kinda hacky, but if a theme is using get_the_excerpt(), then we need to remove our filters on the_content()
358
     *
359
     * @access    public
360
     * @param        string $excerpt
361
     * @return        string
362
     */
363
    public static function get_the_excerpt($excerpt = '')
364
    {
365
        if (post_password_required()) {
366
            return $excerpt;
367
        }
368
        if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) {
369
            remove_filter(
370
                'the_excerpt',
371
                array('EED_Events_Archive', 'event_details'),
372
                EED_Events_Archive::EVENT_DETAILS_PRIORITY
373
            );
374
            remove_filter(
375
                'the_content',
376
                array('EED_Events_Archive', 'event_details'),
377
                EED_Events_Archive::EVENT_DETAILS_PRIORITY
378
            );
379
            $excerpt = EED_Events_Archive::event_details($excerpt);
380
        } else {
381
            EED_Events_Archive::$using_get_the_excerpt = true;
382
            add_filter('wp_trim_excerpt', array('EED_Events_Archive', 'end_get_the_excerpt'), 999, 1);
383
        }
384
        return $excerpt;
385
    }
386
387
388
389
    /**
390
     * end_get_the_excerpt
391
     *
392
     * @access public
393
     * @param  string $text
394
     * @return string
395
     */
396
    public static function end_get_the_excerpt($text = '')
397
    {
398
        EED_Events_Archive::$using_get_the_excerpt = false;
399
        return $text;
400
    }
401
402
403
404
    /**
405
     *    the_title
406
     *
407
     * @access        public
408
     * @param        string $title
409
     * @param        string $id
410
     * @return        string
411
     */
412
    public static function the_title($title = '', $id = '')
413
    {
414
        global $post;
415
        if ($post instanceof WP_Post) {
416
            return in_the_loop() && $post->ID == $id ? espresso_event_status_banner($post->ID) . $title : $title;
417
        }
418
        return $title;
419
    }
420
421
422
423
    /**
424
     *    event_details
425
     *
426
     * @access    public
427
     * @param        string $content
428
     * @return        string
429
     */
430
    public static function event_details($content)
431
    {
432
        global $post;
433
        static $current_post_ID = 0;
434
        if (
435
            $current_post_ID !== $post->ID
436
            && $post->post_type === 'espresso_events'
437
            && ! EED_Events_Archive::$using_get_the_excerpt
438
            && ! post_password_required()
439
            && (
440
                apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false)
441
                || ! apply_filters('FHEE__content_espresso_events__template_loaded', false)
442
            )
443
        ) {
444
            // Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
445
            // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
446
            // BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
447
            // We want to allow those plugins to still do their thing and have access to our content, but depending on
448
            // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
449
            // so the following allows this filter to be applied multiple times, but only once for real
450
            $current_post_ID = did_action('loop_start') ? $post->ID : 0;
451
            if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) {
452
                $content = \EED_Events_Archive::use_sortable_display_order();
453
            } else {
454
                $content = \EED_Events_Archive::use_filterable_display_order();
455
            }
456
        }
457
        return $content;
458
    }
459
460
461
462
    /**
463
     *    use_sortable_display_order
464
     *
465
     * @access    protected
466
     * @return string
467
     */
468
    protected static function use_sortable_display_order()
469
    {
470
        // no further password checks required atm
471
        add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true');
472
        // we need to first remove this callback from being applied to the_content() or the_excerpt()
473
        // (otherwise it will recurse and blow up the interweb)
474
        remove_filter(
475
            'the_excerpt',
476
            array('EED_Events_Archive', 'event_details'),
477
            EED_Events_Archive::EVENT_DETAILS_PRIORITY
478
        );
479
        remove_filter(
480
            'the_content',
481
            array('EED_Events_Archive', 'event_details'),
482
            EED_Events_Archive::EVENT_DETAILS_PRIORITY
483
        );
484
        remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1);
485
        // now add additional content depending on whether event is using the_excerpt() or the_content()
486
        EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts();
487
        $content = EEH_Template::locate_template('content-espresso_events-details.php');
488
        $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content);
489
        // re-add our main filters (or else the next event won't have them)
490
        add_filter(
491
            'the_excerpt',
492
            array('EED_Events_Archive', 'event_details'),
493
            EED_Events_Archive::EVENT_DETAILS_PRIORITY
494
        );
495
        add_filter(
496
            'the_content',
497
            array('EED_Events_Archive', 'event_details'),
498
            EED_Events_Archive::EVENT_DETAILS_PRIORITY
499
        );
500
        add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1);
501
        remove_filter(
502
            'FHEE__EED_Events_Archive__event_details__no_post_password_required',
503
            '__return_true'
504
        );
505
        return $content;
506
    }
507
508
509
510
    /**
511
     *    use_filterable_display_order
512
     *
513
     * @access    protected
514
     * @return    string
515
     */
516
    protected static function use_filterable_display_order()
517
    {
518
        // we need to first remove this callback from being applied to the_content()
519
        // (otherwise it will recurse and blow up the interweb)
520
        remove_filter(
521
            'the_excerpt',
522
            array('EED_Events_Archive', 'event_details'),
523
            EED_Events_Archive::EVENT_DETAILS_PRIORITY
524
        );
525
        remove_filter(
526
            'the_content',
527
            array('EED_Events_Archive', 'event_details'),
528
            EED_Events_Archive::EVENT_DETAILS_PRIORITY
529
        );
530
        remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1);
531
        //now add additional content depending on whether event is using the_excerpt() or the_content()
532
        EED_Events_Archive::_add_additional_excerpt_filters();
533
        EED_Events_Archive::_add_additional_content_filters();
534
        do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters');
535
        // now load our template
536
        $content = EEH_Template::locate_template('content-espresso_events-details.php');
537
        // re-add our main filters (or else the next event won't have them)
538
        add_filter(
539
            'the_excerpt',
540
            array('EED_Events_Archive', 'event_details'),
541
            EED_Events_Archive::EVENT_DETAILS_PRIORITY
542
        );
543
        add_filter(
544
            'the_content',
545
            array('EED_Events_Archive', 'event_details'),
546
            EED_Events_Archive::EVENT_DETAILS_PRIORITY
547
        );
548
        add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1);
549
        // but remove the other filters so that they don't get applied to the next post
550
        EED_Events_Archive::_remove_additional_events_archive_filters();
551
        do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters');
552
        // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
553
        //return ! empty( $template ) ? $template : $content;
554
        return $content;
555
    }
556
557
558
559
    /**
560
     *    event_datetimes - adds datetimes ABOVE content
561
     *
562
     * @access    public
563
     * @param        string $content
564
     * @return        string
565
     */
566
    public static function event_datetimes($content)
567
    {
568
        if (post_password_required()) {
569
            return $content;
570
        }
571
        return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
572
    }
573
574
575
576
    /**
577
     *    event_tickets - adds tickets ABOVE content (which includes datetimes)
578
     *
579
     * @access    public
580
     * @param        string $content
581
     * @return        string
582
     */
583
    public static function event_tickets($content)
584
    {
585
        if (post_password_required()) {
586
            return $content;
587
        }
588
        return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
589
    }
590
591
592
593
    /**
594
     *    event_venues - adds venues BELOW content
595
     *
596
     * @access    public
597
     * @param    string $content
598
     * @return    string
599
     */
600
    public static function event_venue($content)
601
    {
602
        return EED_Events_Archive::event_venues($content);
603
    }
604
605
606
607
    /**
608
     *    event_venues - adds venues BELOW content
609
     *
610
     * @access    public
611
     * @param        string $content
612
     * @return        string
613
     */
614
    public static function event_venues($content)
615
    {
616
        if (post_password_required()) {
617
            return $content;
618
        }
619
        return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
620
    }
621
622
623
624
    /**
625
     *    _add_additional_content_filters
626
     *
627
     * @access    private
628
     * @return        void
629
     */
630 View Code Duplication
    private static function _add_additional_excerpt_filters()
631
    {
632
        add_filter(
633
            'the_excerpt',
634
            array('EED_Events_Archive', 'event_datetimes'),
635
            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
636
        );
637
        add_filter(
638
            'the_excerpt',
639
            array('EED_Events_Archive', 'event_tickets'),
640
            EED_Events_Archive::EVENT_TICKETS_PRIORITY
641
        );
642
        add_filter(
643
            'the_excerpt',
644
            array('EED_Events_Archive', 'event_venues'),
645
            EED_Events_Archive::EVENT_VENUES_PRIORITY
646
        );
647
    }
648
649
650
651
    /**
652
     *    _add_additional_content_filters
653
     *
654
     * @access    private
655
     * @return        void
656
     */
657 View Code Duplication
    private static function _add_additional_content_filters()
658
    {
659
        add_filter(
660
            'the_content',
661
            array('EED_Events_Archive', 'event_datetimes'),
662
            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
663
        );
664
        add_filter(
665
            'the_content',
666
            array('EED_Events_Archive', 'event_tickets'),
667
            EED_Events_Archive::EVENT_TICKETS_PRIORITY
668
        );
669
        add_filter(
670
            'the_content',
671
            array('EED_Events_Archive', 'event_venues'),
672
            EED_Events_Archive::EVENT_VENUES_PRIORITY
673
        );
674
    }
675
676
677
678
    /**
679
     *    _remove_additional_events_archive_filters
680
     *
681
     * @access    private
682
     * @return        void
683
     */
684
    private static function _remove_additional_events_archive_filters()
685
    {
686
        remove_filter(
687
            'the_excerpt',
688
            array('EED_Events_Archive', 'event_datetimes'),
689
            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
690
        );
691
        remove_filter(
692
            'the_excerpt',
693
            array('EED_Events_Archive', 'event_tickets'),
694
            EED_Events_Archive::EVENT_TICKETS_PRIORITY
695
        );
696
        remove_filter(
697
            'the_excerpt',
698
            array('EED_Events_Archive', 'event_venues'),
699
            EED_Events_Archive::EVENT_VENUES_PRIORITY
700
        );
701
        remove_filter(
702
            'the_content',
703
            array('EED_Events_Archive', 'event_datetimes'),
704
            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
705
        );
706
        remove_filter(
707
            'the_content',
708
            array('EED_Events_Archive', 'event_tickets'),
709
            EED_Events_Archive::EVENT_TICKETS_PRIORITY
710
        );
711
        remove_filter(
712
            'the_content',
713
            array('EED_Events_Archive', 'event_venues'),
714
            EED_Events_Archive::EVENT_VENUES_PRIORITY
715
        );
716
    }
717
718
719
720
    /**
721
     *    remove_all_events_archive_filters
722
     *
723
     * @access    public
724
     * @return        void
725
     */
726
    public static function remove_all_events_archive_filters()
727
    {
728
        //remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
729
        remove_filter('the_title', array('EED_Events_Archive', 'the_title'), 1);
730
        remove_filter(
731
            'the_excerpt',
732
            array('EED_Events_Archive', 'event_details'),
733
            EED_Events_Archive::EVENT_DETAILS_PRIORITY
734
        );
735
        remove_filter(
736
            'the_excerpt',
737
            array('EED_Events_Archive', 'event_datetimes'),
738
            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
739
        );
740
        remove_filter(
741
            'the_excerpt',
742
            array('EED_Events_Archive', 'event_tickets'),
743
            EED_Events_Archive::EVENT_TICKETS_PRIORITY
744
        );
745
        remove_filter(
746
            'the_excerpt',
747
            array('EED_Events_Archive', 'event_venues'),
748
            EED_Events_Archive::EVENT_VENUES_PRIORITY
749
        );
750
        remove_filter(
751
            'the_content',
752
            array('EED_Events_Archive', 'event_details'),
753
            EED_Events_Archive::EVENT_DETAILS_PRIORITY
754
        );
755
        remove_filter(
756
            'the_content',
757
            array('EED_Events_Archive', 'event_datetimes'),
758
            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
759
        );
760
        remove_filter(
761
            'the_content',
762
            array('EED_Events_Archive', 'event_tickets'),
763
            EED_Events_Archive::EVENT_TICKETS_PRIORITY
764
        );
765
        remove_filter(
766
            'the_content',
767
            array('EED_Events_Archive', 'event_venues'),
768
            EED_Events_Archive::EVENT_VENUES_PRIORITY
769
        );
770
        // don't display entry meta because the existing theme will take care of that
771
        remove_filter(
772
            'FHEE__content_espresso_events_details_template__display_entry_meta',
773
            '__return_false'
774
        );
775
    }
776
777
778
779
    /**
780
     *    load_event_list_assets
781
     *
782
     * @access    public
783
     * @return    void
784
     */
785 View Code Duplication
    public function load_event_list_assets()
786
    {
787
        do_action('AHEE__EED_Events_Archive__before_load_assets');
788
        add_filter('FHEE_load_EE_Session', '__return_true');
789
        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
790
        add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
791
        if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
792
            add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
793
        }
794
    }
795
796
797
798
    /**
799
     *    wp_enqueue_scripts
800
     *
801
     * @access    public
802
     * @return    void
803
     */
804
    public function wp_enqueue_scripts()
805
    {
806
        // get some style
807
        if (apply_filters('FHEE_enable_default_espresso_css', false)) {
808
            // first check uploads folder
809
            if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) {
810
                wp_register_style($this->theme, get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', array('dashicons', 'espresso_default'));
811
            } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
812
            }
813
            wp_enqueue_style($this->theme);
814
        }
815
    }
816
817
818
819
    /**
820
     *    template_settings_form
821
     *
822
     * @access    public
823
     * @static
824
     * @return    string
825
     */
826
    public static function template_settings_form()
827
    {
828
        $template_settings = EE_Registry::instance()->CFG->template_settings;
829
        $template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive) ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config();
830
        $template_settings->EED_Events_Archive = apply_filters('FHEE__EED_Events_Archive__template_settings_form__event_list_config', $template_settings->EED_Events_Archive);
831
        $events_archive_settings = array(
832
            'display_status_banner'   => 0,
833
            'display_description'     => 1,
834
            'display_ticket_selector' => 0,
835
            'display_datetimes'       => 1,
836
            'display_venue'           => 0,
837
            'display_expired_events'  => 0,
838
        );
839
        $events_archive_settings = array_merge($events_archive_settings, (array)$template_settings->EED_Events_Archive);
840
        EEH_Template::display_template(EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $events_archive_settings);
841
    }
842
843
844
845
    /**
846
     *    update_template_settings
847
     *
848
     * @access    public
849
     * @param    EE_Template_Config $CFG
850
     * @param    EE_Request_Handler $REQ
851
     * @return    EE_Template_Config
852
     */
853
    public static function update_template_settings($CFG, $REQ)
854
    {
855
        $CFG->EED_Events_Archive = new EE_Events_Archive_Config();
856
        // unless we are resetting the config...
857
        if (! isset($REQ['EED_Events_Archive_reset_event_list_settings']) || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1) {
858
            $CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) ? absint($REQ['EED_Events_Archive_display_status_banner']) : 0;
859
            $CFG->EED_Events_Archive->display_description = isset($REQ['EED_Events_Archive_display_description']) ? absint($REQ['EED_Events_Archive_display_description']) : 1;
860
            $CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector']) ? absint($REQ['EED_Events_Archive_display_ticket_selector']) : 0;
861
            $CFG->EED_Events_Archive->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes']) ? absint($REQ['EED_Events_Archive_display_datetimes']) : 1;
862
            $CFG->EED_Events_Archive->display_venue = isset($REQ['EED_Events_Archive_display_venue']) ? absint($REQ['EED_Events_Archive_display_venue']) : 0;
863
            $CFG->EED_Events_Archive->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events']) ? absint($REQ['EED_Events_Archive_display_expired_events']) : 0;
864
        }
865
        return $CFG;
866
    }
867
868
869
870
    /**
871
     *    event_list_css
872
     *
873
     * @access    public
874
     * @param string $extra_class
875
     * @return    string
876
     */
877
    public static function event_list_css($extra_class = '')
878
    {
879
        $event_list_css = ! empty($extra_class) ? array($extra_class) : array();
880
        $event_list_css[] = 'espresso-event-list-event';
881
        return implode(' ', $event_list_css);
882
    }
883
884
885
886
    /**
887
     *    event_categories
888
     *
889
     * @access    public
890
     * @return    array
891
     */
892
    public static function event_categories()
893
    {
894
        return EE_Registry::instance()->load_model('Term')->get_all_ee_categories();
895
    }
896
897
898
899
    /**
900
     *    display_description
901
     *
902
     * @access    public
903
     * @param $value
904
     * @return    bool
905
     */
906
    public static function display_description($value)
907
    {
908
        $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
909
        $display_description = isset($config->display_description) ? $config->display_description : 1;
910
        return $display_description === $value ? true : false;
911
    }
912
913
914
915
    /**
916
     *    display_ticket_selector
917
     *
918
     * @access    public
919
     * @return    bool
920
     */
921
    public static function display_ticket_selector()
922
    {
923
        $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
924
        return isset($config->display_ticket_selector) && $config->display_ticket_selector ? true : false;
925
    }
926
927
928
929
    /**
930
     *    display_venue
931
     *
932
     * @access    public
933
     * @return    bool
934
     */
935
    public static function display_venue()
936
    {
937
        $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
938
        return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name() ? true : false;
939
    }
940
941
942
943
    /**
944
     *    display_datetimes
945
     *
946
     * @access    public
947
     * @return    bool
948
     */
949
    public static function display_datetimes()
950
    {
951
        $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
952
        return isset($config->display_datetimes) && $config->display_datetimes ? true : false;
953
    }
954
955
956
957
    /**
958
     *    event_list_title
959
     *
960
     * @access    public
961
     * @return    string
962
     */
963
    public static function event_list_title()
964
    {
965
        return apply_filters('FHEE__archive_espresso_events_template__upcoming_events_h1', __('Upcoming Events', 'event_espresso'));
966
    }
967
968
969
    // GRAVEYARD
970
971
972
973
    /**
974
     * @since 4.4.0
975
     */
976
    public static function _doing_it_wrong_notice($function = '')
977
    {
978
        EE_Error::doing_it_wrong(
979
            __FUNCTION__,
980
            sprintf(
981
                __('EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s', 'event_espresso'),
982
                $function,
983
                '<br />',
984
                '4.6.0'
985
            ),
986
            '4.4.0'
987
        );
988
    }
989
990
991
992
    /**
993
     * @deprecated
994
     * @since 4.4.0
995
     */
996
    public function get_post_data()
997
    {
998
        EEH_Event_Query::set_query_params();
999
    }
1000
1001
1002
1003
    /**
1004
     * @deprecated
1005
     * @since 4.4.0
1006
     */
1007
    public function posts_fields($SQL, WP_Query $wp_query)
1008
    {
1009
        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1010
        return EEH_Event_Query::posts_fields($SQL, $wp_query);
1011
    }
1012
1013
1014
1015
    /**
1016
     * @deprecated
1017
     * @since 4.4.0
1018
     */
1019
    public static function posts_fields_sql_for_orderby($orderby_params = array())
1020
    {
1021
        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1022
        return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params);
1023
    }
1024
1025
1026
1027
    /**
1028
     * @deprecated
1029
     * @since 4.4.0
1030
     */
1031
    public function posts_join($SQL, WP_Query $wp_query)
1032
    {
1033
        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1034
        return EEH_Event_Query::posts_join($SQL, $wp_query);
1035
    }
1036
1037
1038
1039
    /**
1040
     * @deprecated
1041
     * @since 4.4.0
1042
     */
1043
    public static function posts_join_sql_for_terms($join_terms = null)
1044
    {
1045
        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1046
        return EEH_Event_Query::posts_join_sql_for_terms($join_terms);
1047
    }
1048
1049
1050
1051
    /**
1052
     * @deprecated
1053
     * @since 4.4.0
1054
     */
1055
    public static function posts_join_for_orderby($orderby_params = array())
1056
    {
1057
        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1058
        return EEH_Event_Query::posts_join_for_orderby($orderby_params);
1059
    }
1060
1061
1062
1063
    /**
1064
     * @deprecated
1065
     * @since 4.4.0
1066
     */
1067
    public function posts_where($SQL, WP_Query $wp_query)
1068
    {
1069
        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1070
        return EEH_Event_Query::posts_where($SQL, $wp_query);
1071
    }
1072
1073
1074
1075
    /**
1076
     * @deprecated
1077
     * @since 4.4.0
1078
     */
1079
    public static function posts_where_sql_for_show_expired($show_expired = false)
1080
    {
1081
        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1082
        return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired);
1083
    }
1084
1085
1086
1087
    /**
1088
     * @deprecated
1089
     * @since 4.4.0
1090
     */
1091
    public static function posts_where_sql_for_event_category_slug($event_category_slug = null)
1092
    {
1093
        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1094
        return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug);
1095
    }
1096
1097
1098
1099
    /**
1100
     * @deprecated
1101
     * @since 4.4.0
1102
     */
1103
    public static function posts_where_sql_for_event_list_month($month = null)
1104
    {
1105
        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1106
        return EEH_Event_Query::posts_where_sql_for_event_list_month($month);
1107
    }
1108
1109
1110
1111
    /**
1112
     * @deprecated
1113
     * @since 4.4.0
1114
     */
1115
    public function posts_orderby($SQL, WP_Query $wp_query)
1116
    {
1117
        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1118
        return EEH_Event_Query::posts_orderby($SQL, $wp_query);
1119
    }
1120
1121
1122
1123
    /**
1124
     * @deprecated
1125
     * @since 4.4.0
1126
     */
1127
    public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC')
1128
    {
1129
        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1130
        return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort);
1131
    }
1132
1133
1134
1135
}
1136
1137
1138
1139
/**
1140
 * @return int
1141
 */
1142
function espresso_get_event_list_ID()
1143
{
1144
    EED_Events_Archive::$espresso_event_list_ID++;
1145
    EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID;
1146
    return EED_Events_Archive::$espresso_event_list_ID;
1147
}
1148
1149
/**
1150
 * @return string
1151
 */
1152
function espresso_event_list_title()
1153
{
1154
    return EED_Events_Archive::event_list_title();
1155
}
1156
1157
/**
1158
 * @param string $extra_class
1159
 * @return string
1160
 */
1161
function espresso_event_list_css($extra_class = '')
1162
{
1163
    return EED_Events_Archive::event_list_css($extra_class);
1164
}
1165
1166
/**
1167
 * @return array
1168
 */
1169
function espresso_get_event_categories()
1170
{
1171
    return EED_Events_Archive::event_categories();
1172
}
1173
1174
/**
1175
 * @return bool
1176
 */
1177
function espresso_display_full_description_in_event_list()
1178
{
1179
    return EED_Events_Archive::display_description(2);
1180
}
1181
1182
/**
1183
 * @return bool
1184
 */
1185
function espresso_display_excerpt_in_event_list()
1186
{
1187
    return EED_Events_Archive::display_description(1);
1188
}
1189
1190
/**
1191
 * @return bool
1192
 */
1193
function espresso_display_ticket_selector_in_event_list()
1194
{
1195
    return EED_Events_Archive::display_ticket_selector();
1196
}
1197
1198
/**
1199
 * @return bool
1200
 */
1201
function espresso_display_venue_in_event_list()
1202
{
1203
    return EED_Events_Archive::display_venue();
1204
}
1205
1206
/**
1207
 * @return bool
1208
 */
1209
function espresso_display_datetimes_in_event_list()
1210
{
1211
    return EED_Events_Archive::display_datetimes();
1212
}
1213
1214
1215
1216
1217
1218
1219
1220
// End of file EED_Events_Archive.module.php
1221
// Location: /modules/events_archive/EED_Events_Archive.module.php
1222