Completed
Branch BUG-10537-cart-ticket-reservat... (885a0b)
by
unknown
27:03 queued 14:27
created

EED_Events_Archive::is_iframe()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
use EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton;
4
use EventEspresso\modules\events_archive\EventsArchiveIframe;
5
6
if ( ! defined( 'EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
7
/**
8
 * Event Espresso
9
 *
10
 * Event Registration and Management Plugin for WordPress
11
 *
12
 * @ package			Event Espresso
13
 * @ author			Seth Shoultes
14
 * @ copyright		(c) 2008-2011 Event Espresso  All Rights Reserved.
15
 * @ license			http://eventespresso.com/support/terms-conditions/   * see Plugin Licensing *
16
 * @ link					http://www.eventespresso.com
17
 * @ version		 	4.0
18
 *
19
 * ------------------------------------------------------------------------
20
 *
21
 * Event List
22
 *
23
 * @package		Event Espresso
24
 * @subpackage	/modules/events_archive/
25
 * @author		Brent Christensen
26
 *
27
 * ------------------------------------------------------------------------
28
 */
29
class EED_Events_Archive  extends EED_Module {
30
31
32
	public static $espresso_event_list_ID = 0;
33
	public static $espresso_grid_event_lists = array();
34
35
	/**
36
	 * @type bool $using_get_the_excerpt
37
	 */
38
	protected static $using_get_the_excerpt = false;
39
40
    /**
41
     * Used to flag when the event list is being called from an external iframe.
42
     *
43
     * @var bool $iframe
44
     */
45
    protected static $iframe = false;
46
47
    /**
48
	 * @var \EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton $_iframe_embed_button
49
	 */
50
	private static $_iframe_embed_button;
51
52
    /**
53
	 * @type EE_Template_Part_Manager $template_parts
54
	 */
55
	protected $template_parts;
56
57
58
59
	/**
60
	 * @return EED_Events_Archive
61
	 */
62
	public static function instance() {
63
		return parent::get_instance( __CLASS__ );
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (get_instance() instead of instance()). Are you sure this is correct? If so, you might want to change this to $this->get_instance().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
64
	}
65
66
67
68
	/**
69
	 * 	set_hooks - for hooking into EE Core, other modules, etc
70
	 *
71
	 *  @access 	public
72
	 *  @return 	void
73
	 */
74
	public static function set_hooks() {
75
		EE_Config::register_route( EE_Registry::instance()->CFG->core->event_cpt_slug, 'Events_Archive', 'run' );
76
		EE_Config::register_route( 'event_list', 'Events_Archive', 'event_list' );
77
		EE_Config::register_route( 'iframe', 'Events_Archive', 'event_list_iframe', 'event_list' );
78
		add_action( 'wp_loaded', array( 'EED_Events_Archive', 'set_definitions' ), 2 );
79
	}
80
81
	/**
82
	 * 	set_hooks_admin - for hooking into EE Admin Core, other modules, etc
83
	 *
84
	 *  @access 	public
85
	 *  @return 	void
86
	 */
87
	public static function set_hooks_admin() {
88
		add_action( 'wp_loaded', array( 'EED_Events_Archive', 'set_definitions' ), 2 );
89
		// hook into the end of the \EE_Admin_Page::_load_page_dependencies()
90
		// to load assets for "espresso_events" page on the "default" route (action)
91
		add_action(
92
			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default',
93
			array( 'EED_Events_Archive', 'event_list_iframe_embed_button' ),
94
			10
95
		);
96
	}
97
98
99
100
101
	/**
102
	 * 	set_definitions
103
	 *
104
	 *  @access 	public
105
	 *  @return 	void
106
	 */
107
	public static function set_definitions() {
108
		define( 'EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS );
109
		define( 'EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS );
110
	}
111
112
113
114
	/**
115
	 * set up EE_Events_Archive_Config
116
	 */
117
	protected function set_config(){
118
		$this->set_config_section( 'template_settings' );
119
		$this->set_config_class( 'EE_Events_Archive_Config' );
120
		$this->set_config_name( 'EED_Events_Archive' );
121
	}
122
123
124
125
	/**
126
	 * @return EventListIframeEmbedButton
127
	 */
128
	public static function get_iframe_embed_button() {
129
		if ( ! self::$_iframe_embed_button instanceof EventListIframeEmbedButton ) {
130
			self::$_iframe_embed_button = new EventListIframeEmbedButton();
131
		}
132
		return self::$_iframe_embed_button;
133
	}
134
135
136
137
	/**
138
	 * event_list_iframe_embed_button
139
	 *
140
	 * @return    void
141
	 * @throws \EE_Error
142
	 */
143
	public static function event_list_iframe_embed_button() {
144
		$iframe_embed_button = \EED_Events_Archive::get_iframe_embed_button();
145
		$iframe_embed_button->addEmbedButton();
146
	}
147
148
	/**
149
	 *    initialize_template_parts
150
	 *
151
	 * @access    public
152
	 * @param \EE_Events_Archive_Config $config
153
	 * @return \EE_Template_Part_Manager
154
	 */
155 View Code Duplication
	public function initialize_template_parts( EE_Events_Archive_Config $config = null ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
156
		$config = $config instanceof EE_Events_Archive_Config ? $config : $this->config();
157
		EEH_Autoloader::instance()->register_template_part_autoloaders();
158
		$template_parts = new EE_Template_Part_Manager();
159
		$template_parts->add_template_part(
160
			'tickets',
161
			__( 'Ticket Selector', 'event_espresso' ),
162
			'content-espresso_events-tickets.php',
163
			$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...
164
		);
165
		$template_parts->add_template_part(
166
			'datetimes',
167
			__( 'Dates and Times', 'event_espresso' ),
168
			'content-espresso_events-datetimes.php',
169
			$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...
170
		);
171
		$template_parts->add_template_part(
172
			'event',
173
			__( 'Event Description', 'event_espresso' ),
174
			'content-espresso_events-details.php',
175
			$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...
176
		);
177
		$template_parts->add_template_part(
178
			'venue',
179
			__( 'Venue Information', 'event_espresso' ),
180
			'content-espresso_events-venues.php',
181
			$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...
182
		);
183
		do_action( 'AHEE__EED_Event_Archive__initialize_template_parts', $template_parts );
184
		return $template_parts;
185
	}
186
187
188
189
	/**
190
	 *    run - initial module setup - this gets called by the EE_Front_Controller if the module route is found in the incoming request
191
	 *
192
	 * @access    public
193
	 * @param WP $WP
194
	 * @return    void
195
	 */
196
	public function run( $WP ) {
197
		do_action( 'AHEE__EED_Events_Archive__before_run' );
198
		// ensure valid EE_Events_Archive_Config() object exists
199
		$this->set_config();
200
		/** @type EE_Events_Archive_Config $config */
201
		$config = $this->config();
202
		// load other required components
203
		$this->load_event_list_assets();
204
		// filter the WP posts_join, posts_where, and posts_orderby SQL clauses
205
		//add query filters
206
		EEH_Event_Query::add_query_filters();
207
		// set params that will get used by the filters
208
		EEH_Event_Query::set_query_params(
209
			'', 	// month
210
			'', 	// category
211
			$config->display_expired_events, 	// show_expired
0 ignored issues
show
Documentation introduced by
$config->display_expired_events is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
212
			'start_date', 	// orderby
213
			'ASC' 	// sort
214
		);
215
		// check what template is loaded
216
		add_filter( 'template_include',  array( $this, 'template_include' ), 999, 1 );
217
	}
218
219
220
221
	/**
222
	 * 	event_list - most likely called by the EES_Espresso_Events shortcode which uses this module to do some of it's lifting
223
	 *
224
	 *  @access 	public
225
	 *  @return 	void
226
	 */
227
	public function event_list() {
228
		// ensure valid EE_Events_Archive_Config() object exists
229
		$this->set_config();
230
		// load other required components
231
		$this->load_event_list_assets();
232
	}
233
234
235
236
    /**
237
     * @access    public
238
     * @return    void
239
     * @throws \EE_Error
240
     * @throws \DomainException
241
     */
242
	public function event_list_iframe() {
243
        \EED_Events_Archive::$iframe = true;
244
		$event_list_iframe = new EventsArchiveIframe( $this );
245
		$event_list_iframe->display();
246
	}
247
248
249
250
    /**
251
     * @access public
252
     * @return string
253
     */
254
	public static function is_iframe() {
255
        return \EED_Events_Archive::$iframe;
256
	}
257
258
259
260
    /**
261
     * @access public
262
     * @return string
263
     */
264
	public static function link_target() {
265
        return \EED_Events_Archive::$iframe ? ' target="_blank"' : '';
266
	}
267
268
269
270
271
272
273
274
275
	/**
276
	 *    template_include
277
	 *
278
	 * @access    public
279
	 * @param string $template
280
	 * @return    string
281
	 */
282
	public function template_include( $template = '' ) {
283
		// don't add content filter for dedicated EE child themes or private posts
284
		if ( ! EEH_Template::is_espresso_theme() ) {
285
			/** @type EE_Events_Archive_Config $config */
286
			$config = $this->config();
287
			// add status banner ?
288
			if ( $config->display_status_banner ) {
289
				add_filter( 'the_title', array( 'EED_Events_Archive', 'the_title' ), 100, 2 );
290
			}
291
			// if NOT a custom template
292
			if (
293
				EE_Registry::instance()->load_core( 'Front_Controller', array(), false, true )->get_selected_template() != 'archive-espresso_events.php'
0 ignored issues
show
Unused Code introduced by
The call to EE_Registry::load_core() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
294
				|| apply_filters( 'FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', FALSE )
295
			) {
296
				// don't display entry meta because the existing theme will take care of that
297
				add_filter( 'FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true' );
298
			// load functions.php file for the theme (loaded by WP if using child theme)
299
				EEH_Template::load_espresso_theme_functions();
300
				// because we don't know if the theme is using the_excerpt()
301
				add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
302
				// or the_content
303
				add_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
304
				// and just in case they are running get_the_excerpt() which DESTROYS things
305
				add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 );
306
				// don't display entry meta because the existing theme will take care of that
307
				add_filter( 'FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false' );
308
			}
309
		}
310
		return $template;
311
	}
312
313
314
315
	/**
316
	 * 	get_the_excerpt - kinda hacky, but if a theme is using get_the_excerpt(), then we need to remove our filters on the_content()
317
	 *
318
	 * 	@access 	public
319
	 * 	@param		string 	$excerpt
320
	 * 	@return 		string
321
	 */
322
	public static function get_the_excerpt( $excerpt = '' ) {
323
		if ( post_password_required() ) {
324
			return $excerpt;
325
		}
326
		if ( apply_filters( 'FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false ) ) {
327
			remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100 );
328
			remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100 );
329
			$excerpt = EED_Events_Archive::event_details( $excerpt );
330
		} else {
331
			EED_Events_Archive::$using_get_the_excerpt = true;
332
			add_filter( 'wp_trim_excerpt', array( 'EED_Events_Archive', 'end_get_the_excerpt' ), 999, 1 );
333
		}
334
		return $excerpt;
335
	}
336
337
338
339
	/**
340
	 * end_get_the_excerpt
341
	 *
342
	 * @access public
343
	 * @param  string $text
344
	 * @return string
345
	 */
346
	public static function end_get_the_excerpt( $text = '' ) {
347
		EED_Events_Archive::$using_get_the_excerpt = false;
348
		return $text;
349
	}
350
351
352
353
	/**
354
	 *    the_title
355
	 *
356
	 * @access    	public
357
	 * @param 		string 		$title
358
	 * @param 		string 		$id
359
	 * @return 		string
360
	 */
361
	public static function the_title( $title = '', $id = '' ) {
362
	global $post;
363
	if ( $post instanceof WP_Post ) {
0 ignored issues
show
Bug introduced by
The class WP_Post does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
364
		return in_the_loop() && $post->ID == $id ? espresso_event_status_banner( $post->ID  ) . $title :  $title;
365
	}
366
	return $title;
367
}
368
369
370
371
	/**
372
	 * 	event_details
373
	 *
374
	 * 	@access 	public
375
	 * 	@param		string 	$content
376
	 * 	@return 		string
377
	 */
378
	public static function event_details( $content ) {
379
		global $post;
380
		static $current_post_ID = 0;
381
		if (
382
			$current_post_ID != $post->ID
383
			&& $post->post_type == 'espresso_events'
384
			&& ! EED_Events_Archive::$using_get_the_excerpt
385
			&& ! post_password_required()
386
			&& (
387
				apply_filters( 'FHEE__EES_Espresso_Events__process_shortcode__true', false )
388
				|| ! apply_filters( 'FHEE__content_espresso_events__template_loaded', false )
389
			)
390
		) {
391
			// Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
392
			// Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
393
			// BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
394
			// We want to allow those plugins to still do their thing and have access to our content, but depending on
395
			// how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
396
			// so the following allows this filter to be applied multiple times, but only once for real
397
			$current_post_ID = did_action( 'loop_start' ) ? $post->ID : 0;
398
			if ( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order ) {
399
				$content = \EED_Events_Archive::use_sortable_display_order();
400
			} else {
401
				$content = \EED_Events_Archive::use_filterable_display_order();
402
			}
403
		}
404
		return $content;
405
	}
406
407
408
409
	/**
410
	 *    use_sortable_display_order
411
	 *
412
	 * @access    protected
413
	 * @return string
414
	 */
415
	protected static function use_sortable_display_order() {
416
		// no further password checks required atm
417
		add_filter( 'FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true' );
418
		// we need to first remove this callback from being applied to the_content() or the_excerpt() (otherwise it will recurse and blow up the interweb)
419
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100 );
420
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100 );
421
		remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
422
		// now add additional content depending on whether event is using the_excerpt() or the_content()
423
		EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts();
424
		$content = EEH_Template::locate_template( 'content-espresso_events-details.php' );
425
		$content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters( $content );
426
		// re-add our main filters (or else the next event won't have them)
427
		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
428
		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
429
		add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 );
430
		remove_filter( 'FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true' );
431
		return $content;
432
	}
433
434
435
436
	/**
437
	 *    use_filterable_display_order
438
	 *
439
	 * @access 	protected
440
	 * @return 	string
441
	 */
442
	protected static function use_filterable_display_order() {
443
		// we need to first remove this callback from being applied to the_content()
444
		// (otherwise it will recurse and blow up the interweb)
445
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100 );
446
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100 );
447
		remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
448
		//now add additional content depending on whether event is using the_excerpt() or the_content()
449
		EED_Events_Archive::_add_additional_excerpt_filters();
450
		EED_Events_Archive::_add_additional_content_filters();
451
		do_action( 'AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters' );
452
		// now load our template
453
		$content = EEH_Template::locate_template( 'content-espresso_events-details.php' );
454
		// re-add our main filters (or else the next event won't have them)
455
		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
456
		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
457
		add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 );
458
		// but remove the other filters so that they don't get applied to the next post
459
		EED_Events_Archive::_remove_additional_events_archive_filters();
460
		do_action( 'AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters' );
461
		// we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
462
		//return ! empty( $template ) ? $template : $content;
463
		return $content;
464
	}
465
466
467
468
	/**
469
	 * 	event_datetimes - adds datetimes ABOVE content
470
	 *
471
	 *  	@access 	public
472
	 * 	@param		string 	$content
473
	 *  	@return 		string
474
	 */
475
	public static function event_datetimes( $content ) {
476
		if ( post_password_required() ) {
477
			return $content;
478
		}
479
		return EEH_Template::locate_template( 'content-espresso_events-datetimes.php' ) . $content;
480
	}
481
482
	/**
483
	 * 	event_tickets - adds tickets ABOVE content (which includes datetimes)
484
	 *
485
	 *  	@access 	public
486
	 * 	@param		string 	$content
487
	 *  	@return 		string
488
	 */
489
	public static function event_tickets( $content ) {
490
		if ( post_password_required() ) {
491
			return $content;
492
		}
493
		return EEH_Template::locate_template( 'content-espresso_events-tickets.php' ) . $content;
494
	}
495
496
497
498
	/**
499
	 *    event_venues - adds venues BELOW content
500
	 *
501
	 * @access    public
502
	 * @param    string $content
503
	 * @return    string
504
	 */
505
	public static function event_venue( $content ) {
506
		return EED_Events_Archive::event_venues( $content );
507
	}
508
509
	/**
510
	 * 	event_venues - adds venues BELOW content
511
	 *
512
	 *  	@access 	public
513
	 * 	@param		string 	$content
514
	 *  	@return 		string
515
	 */
516
	public static function event_venues( $content ) {
517
		if ( post_password_required() ) {
518
			return $content;
519
		}
520
		return $content . EEH_Template::locate_template( 'content-espresso_events-venues.php' );
521
	}
522
523
524
525
	/**
526
	 *    _add_additional_content_filters
527
	 *
528
	 * @access    private
529
	 * @return        void
530
	 */
531
	private static function _add_additional_excerpt_filters() {
532
		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_datetimes' ), 110, 1 );
533
		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_tickets' ), 120, 1 );
534
		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_venues' ), 130, 1 );
535
	}
536
537
538
539
	/**
540
	 *    _add_additional_content_filters
541
	 *
542
	 * @access    private
543
	 * @return        void
544
	 */
545
	private static function _add_additional_content_filters() {
546
		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_datetimes' ), 110, 1 );
547
		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_tickets' ), 120, 1 );
548
		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_venues' ), 130, 1 );
549
	}
550
551
552
553
	/**
554
	 *    _remove_additional_events_archive_filters
555
	 *
556
	 * @access    private
557
	 * @return        void
558
	 */
559
	private static function _remove_additional_events_archive_filters() {
560
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_datetimes' ), 110 );
561
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_tickets' ), 120 );
562
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_venues' ), 130 );
563
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_datetimes' ), 110 );
564
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_tickets' ), 120 );
565
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_venues' ), 130 );
566
	}
567
568
569
570
	/**
571
	 * 	remove_all_events_archive_filters
572
	 *
573
	 *  	@access 	public
574
	 *  	@return 		void
575
	 */
576
	public static function remove_all_events_archive_filters() {
577
		//remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
578
		remove_filter( 'the_title', array( 'EED_Events_Archive', 'the_title' ), 100 );
579
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100 );
580
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_datetimes' ), 110 );
581
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_tickets' ), 120 );
582
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_venues' ), 130 );
583
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100 );
584
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_datetimes' ), 110 );
585
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_tickets' ), 120 );
586
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_venues' ), 130 );
587
		// don't display entry meta because the existing theme will take care of that
588
		remove_filter( 'FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false' );
589
	}
590
591
592
593
594
595
596
	/**
597
	 * 	load_event_list_assets
598
	 *
599
	 *  @access 	public
600
	 *  @return 	void
601
	 */
602 View Code Duplication
	public function load_event_list_assets() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
603
        do_action( 'AHEE__EED_Events_Archive__before_load_assets' );
604
		add_filter( 'FHEE_load_EE_Session', '__return_true' );
605
		add_filter( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true' );
606
		add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 );
607
		if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) {
608
			add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 );
609
		}
610
	}
611
612
613
614
615
616
617
	/**
618
	 * 	wp_enqueue_scripts
619
	 *
620
	 *  @access 	public
621
	 *  @return 	void
622
	 */
623
	public function wp_enqueue_scripts() {
624
		// get some style
625
		if ( apply_filters( 'FHEE_enable_default_espresso_css', FALSE ) ) {
626
			// first check uploads folder
627
			if ( EEH_File::is_readable( get_stylesheet_directory() . $this->theme . DS . 'style.css' )) {
628
				wp_register_style( $this->theme, get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', array( 'dashicons', 'espresso_default' ));
629
			} 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...
630
		}
631
		wp_enqueue_style( $this->theme );
632
633
	}
634
}
635
636
637
638
639
640
	/**
641
	 * 	template_settings_form
642
	 *
643
	 *  @access 	public
644
	 *  @static
645
	 *  @return 	string
646
	 */
647
	public static function template_settings_form() {
648
	$template_settings = EE_Registry::instance()->CFG->template_settings;
649
	$template_settings->EED_Events_Archive = isset( $template_settings->EED_Events_Archive ) ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config();
650
	$template_settings->EED_Events_Archive = apply_filters( 'FHEE__EED_Events_Archive__template_settings_form__event_list_config', $template_settings->EED_Events_Archive );
651
	$events_archive_settings = array(
652
		'display_status_banner' => 0,
653
		'display_description' => 1,
654
		'display_ticket_selector' => 0,
655
		'display_datetimes' => 1,
656
		'display_venue' => 0,
657
		'display_expired_events' => 0
658
	);
659
	$events_archive_settings = array_merge( $events_archive_settings, (array)$template_settings->EED_Events_Archive );
660
	EEH_Template::display_template( EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $events_archive_settings );
661
}
662
663
664
665
666
667
668
	/**
669
	 * 	update_template_settings
670
	 *
671
	 *  @access 	public
672
	 *  @param 	EE_Template_Config $CFG
673
	 *  @param 	EE_Request_Handler $REQ
674
	 *  @return 	EE_Template_Config
675
	 */
676
	public static function update_template_settings( $CFG, $REQ ) {
677
		$CFG->EED_Events_Archive = new EE_Events_Archive_Config();
678
		// unless we are resetting the config...
679
		if ( ! isset( $REQ['EED_Events_Archive_reset_event_list_settings'] ) || absint( $REQ['EED_Events_Archive_reset_event_list_settings'] ) !== 1 ) {
680
			$CFG->EED_Events_Archive->display_status_banner = isset( $REQ['EED_Events_Archive_display_status_banner'] ) ? absint( $REQ['EED_Events_Archive_display_status_banner'] ) : 0;
681
			$CFG->EED_Events_Archive->display_description = isset( $REQ['EED_Events_Archive_display_description'] ) ? absint( $REQ['EED_Events_Archive_display_description'] ) : 1;
682
			$CFG->EED_Events_Archive->display_ticket_selector = isset( $REQ['EED_Events_Archive_display_ticket_selector'] ) ? absint( $REQ['EED_Events_Archive_display_ticket_selector'] ) : 0;
683
			$CFG->EED_Events_Archive->display_datetimes = isset( $REQ['EED_Events_Archive_display_datetimes'] ) ? absint( $REQ['EED_Events_Archive_display_datetimes'] ) : 1;
684
			$CFG->EED_Events_Archive->display_venue = isset( $REQ['EED_Events_Archive_display_venue'] ) ? absint( $REQ['EED_Events_Archive_display_venue'] ) : 0;
685
			$CFG->EED_Events_Archive->display_expired_events = isset( $REQ['EED_Events_Archive_display_expired_events'] ) ? absint( $REQ['EED_Events_Archive_display_expired_events'] ) : 0;			}
686
		return $CFG;
687
	}
688
689
690
691
	/**
692
	 *    event_list_css
693
	 *
694
	 * @access    public
695
	 * @param string $extra_class
696
	 * @return    string
697
	 */
698
	public static function event_list_css( $extra_class = '' ) {
699
		$event_list_css = ! empty( $extra_class ) ? array( $extra_class ) : array();
700
		$event_list_css[] = 'espresso-event-list-event';
701
		return implode( ' ', $event_list_css );
702
	}
703
704
705
706
707
708
709
	/**
710
	 * 	event_categories
711
	 *
712
	 *  @access 	public
713
	 *  @return 	array
714
	 */
715
	public static function event_categories() {
716
	return EE_Registry::instance()->load_model('Term')->get_all_ee_categories();
0 ignored issues
show
Documentation Bug introduced by
The method get_all_ee_categories does not exist on object<EEM_Base>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
717
}
718
719
720
721
	/**
722
	 *    display_description
723
	 *
724
	 * @access    public
725
	 * @param $value
726
	 * @return    bool
727
	 */
728
	public static function display_description( $value ) {
729
		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
730
		$display_description= isset( $config->display_description ) ? $config->display_description : 1;
731
		return $display_description === $value ? TRUE : FALSE;
732
	}
733
734
735
	/**
736
	 * 	display_ticket_selector
737
	 *
738
	 *  @access 	public
739
	 *  @return 	bool
740
	 */
741
	public static function display_ticket_selector() {
742
		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
743
		return isset( $config->display_ticket_selector ) && $config->display_ticket_selector ? TRUE : FALSE;
744
	}
745
746
747
748
	/**
749
	 * 	display_venue
750
	 *
751
	 *  @access 	public
752
	 *  @return 	bool
753
	 */
754
	public static function display_venue() {
755
		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
756
		return isset( $config->display_venue ) && $config->display_venue && EEH_Venue_View::venue_name() ? TRUE : FALSE;
757
	}
758
759
760
	/**
761
	 * 	display_datetimes
762
	 *
763
	 *  @access 	public
764
	 *  @return 	bool
765
	 */
766
	public static function display_datetimes() {
767
		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
768
		return isset( $config->display_datetimes ) && $config->display_datetimes ? TRUE : FALSE;
769
}
770
771
772
773
774
775
776
	/**
777
	 * 	event_list_title
778
	 *
779
	 *  @access 	public
780
	 *  @return 	string
781
	 */
782
	public static function event_list_title() {
783
		return apply_filters( 'FHEE__archive_espresso_events_template__upcoming_events_h1', __( 'Upcoming Events', 'event_espresso' ));
784
	}
785
786
787
	// GRAVEYARD
788
789
	/**
790
	 * 	@since 4.4.0
791
	 */
792
	public static function _doing_it_wrong_notice( $function = '' ) {
793
		EE_Error::doing_it_wrong(
794
			__FUNCTION__,
795
			sprintf(
796
				__( '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' ),
797
				$function,
798
				'<br />',
799
				'4.6.0'
800
			),
801
			'4.4.0'
802
		);
803
	}
804
805
806
807
	/**
808
	 * 	@deprecated
809
	 * 	@since 4.4.0
810
	 */
811
	public function get_post_data() {
812
		EEH_Event_Query::set_query_params();
813
	}
814
	/**
815
	 * 	@deprecated
816
	 * 	@since 4.4.0
817
	 */
818
	public function posts_fields( $SQL, WP_Query $wp_query ) {
819
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
820
		return EEH_Event_Query::posts_fields( $SQL, $wp_query );
821
	}
822
	/**
823
	 * 	@deprecated
824
	 * 	@since 4.4.0
825
	 */
826
	public static function posts_fields_sql_for_orderby( $orderby_params = array() ) {
827
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
828
		return EEH_Event_Query::posts_fields_sql_for_orderby( $orderby_params );
829
	}
830
	/**
831
	 * 	@deprecated
832
	 * 	@since 4.4.0
833
	 */
834
	public function posts_join( $SQL, WP_Query $wp_query ) {
835
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
836
		return EEH_Event_Query::posts_join( $SQL, $wp_query );
837
	}
838
	/**
839
	 * 	@deprecated
840
	 * 	@since 4.4.0
841
	 */
842
	public static function posts_join_sql_for_terms( $join_terms = NULL ) {
843
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
844
		return EEH_Event_Query::posts_join_sql_for_terms( $join_terms );
845
	}
846
	/**
847
	 * 	@deprecated
848
	 * 	@since 4.4.0
849
	 */
850
	public static function posts_join_for_orderby( $orderby_params = array() ) {
851
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
852
		return EEH_Event_Query::posts_join_for_orderby( $orderby_params );
0 ignored issues
show
Documentation introduced by
$orderby_params is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
853
	}
854
	/**
855
	 * 	@deprecated
856
	 * 	@since 4.4.0
857
	 */
858
	public function posts_where( $SQL, WP_Query $wp_query ) {
859
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
860
		return EEH_Event_Query::posts_where( $SQL, $wp_query );
861
	}
862
	/**
863
	 * 	@deprecated
864
	 * 	@since 4.4.0
865
	 */
866
	public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) {
867
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
868
		return EEH_Event_Query::posts_where_sql_for_show_expired( $show_expired );
869
	}
870
	/**
871
	 * 	@deprecated
872
	 * 	@since 4.4.0
873
	 */
874
	public static function posts_where_sql_for_event_category_slug( $event_category_slug = NULL ) {
875
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
876
		return EEH_Event_Query::posts_where_sql_for_event_category_slug( $event_category_slug );
877
	}
878
	/**
879
	 * 	@deprecated
880
	 * 	@since 4.4.0
881
	 */
882
	public static function posts_where_sql_for_event_list_month( $month = NULL ) {
883
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
884
		return EEH_Event_Query::posts_where_sql_for_event_list_month( $month );
885
	}
886
	/**
887
	 * 	@deprecated
888
	 * 	@since 4.4.0
889
	 */
890
	public function posts_orderby( $SQL, WP_Query $wp_query ) {
891
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
892
		return EEH_Event_Query::posts_orderby( $SQL, $wp_query );
893
	}
894
	/**
895
	 * 	@deprecated
896
	 * 	@since 4.4.0
897
	 */
898
	public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) {
899
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
900
		return EEH_Event_Query::posts_orderby_sql( $orderby_params, $sort );
901
	}
902
903
904
905
}
906
907
908
909
910
911
/**
912
 * @return int
913
 */
914
function espresso_get_event_list_ID() {
915
	EED_Events_Archive::$espresso_event_list_ID++;
916
	EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID;
917
	return EED_Events_Archive::$espresso_event_list_ID;
918
}
919
920
/**
921
 * @return string
922
 */
923
function espresso_event_list_title() {
924
	return EED_Events_Archive::event_list_title();
925
}
926
927
/**
928
 * @param string $extra_class
929
 * @return string
930
 */
931
function espresso_event_list_css( $extra_class = '' ) {
932
	return EED_Events_Archive::event_list_css( $extra_class );
933
}
934
935
/**
936
 * @return array
937
 */
938
function espresso_get_event_categories() {
939
	return EED_Events_Archive::event_categories();
940
}
941
942
/**
943
 * @return bool
944
 */
945
function espresso_display_full_description_in_event_list() {
946
	return EED_Events_Archive::display_description( 2 );
947
}
948
949
/**
950
 * @return bool
951
 */
952
function espresso_display_excerpt_in_event_list() {
953
	return EED_Events_Archive::display_description( 1 );
954
}
955
956
/**
957
 * @return bool
958
 */
959
function espresso_display_ticket_selector_in_event_list() {
960
	return EED_Events_Archive::display_ticket_selector();
961
}
962
963
/**
964
 * @return bool
965
 */
966
function espresso_display_venue_in_event_list() {
967
	return EED_Events_Archive::display_venue();
968
}
969
970
/**
971
 * @return bool
972
 */
973
function espresso_display_datetimes_in_event_list() {
974
	return EED_Events_Archive::display_datetimes();
975
}
976
977
978
979
980
981
982
983
// End of file EED_Events_Archive.module.php
984
// Location: /modules/events_archive/EED_Events_Archive.module.php
985