Completed
Branch BETA-4.9-messages-queue-fixed (941081)
by
unknown
17:38 queued 10s
created

EED_Events_Archive::instance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
/**
3
 * Event Espresso
4
 *
5
 * Event Registration and Management Plugin for WordPress
6
 *
7
 * @ package			Event Espresso
8
 * @ author			Seth Shoultes
9
 * @ copyright		(c) 2008-2011 Event Espresso  All Rights Reserved.
10
 * @ license			http://eventespresso.com/support/terms-conditions/   * see Plugin Licensing *
11
 * @ link					http://www.eventespresso.com
12
 * @ version		 	4.0
13
 *
14
 * ------------------------------------------------------------------------
15
 *
16
 * Event List
17
 *
18
 * @package		Event Espresso
19
 * @subpackage	/modules/events_archive/
20
 * @author		Brent Christensen
21
 *
22
 * ------------------------------------------------------------------------
23
 */
24
class EED_Events_Archive  extends EED_Module {
25
26
27
	public static $espresso_event_list_ID = 0;
28
	public static $espresso_grid_event_lists = array();
29
30
	/**
31
	 * @type bool $using_get_the_excerpt
32
	 */
33
	protected static $using_get_the_excerpt = false;
34
35
	/**
36
	 * @type EE_Template_Part_Manager $template_parts
37
	 */
38
	protected $template_parts;
39
40
41
42
	/**
43
	 * @return EED_Events_Archive
44
	 */
45
	public static function instance() {
46
		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...
47
	}
48
49
50
51
	/**
52
	 * 	set_hooks - for hooking into EE Core, other modules, etc
53
	 *
54
	 *  @access 	public
55
	 *  @return 	void
56
	 */
57
	public static function set_hooks() {
58
		EE_Config::register_route( EE_Registry::instance()->CFG->core->event_cpt_slug, 'Events_Archive', 'run' );
59
		EE_Config::register_route( 'event_list', 'Events_Archive', 'event_list' );
60
		add_action( 'wp_loaded', array( 'EED_Events_Archive', 'set_definitions' ), 2 );
61
	}
62
63
	/**
64
	 * 	set_hooks_admin - for hooking into EE Admin Core, other modules, etc
65
	 *
66
	 *  @access 	public
67
	 *  @return 	void
68
	 */
69
	public static function set_hooks_admin() {
70
		add_action( 'wp_loaded', array( 'EED_Events_Archive', 'set_definitions' ), 2 );
71
	}
72
73
74
75
76
	/**
77
	 * 	set_definitions
78
	 *
79
	 *  @access 	public
80
	 *  @return 	void
81
	 */
82
	public static function set_definitions() {
83
		define( 'EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS );
84
		define( 'EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS );
85
	}
86
87
88
89
	/**
90
	 *    set_config
91
	 *
92
	 * @return \EE_Events_Archive_Config
93
	 */
94
	protected function set_config(){
95
		$this->set_config_section( 'template_settings' );
96
		$this->set_config_class( 'EE_Events_Archive_Config' );
97
		$this->set_config_name( 'EED_Events_Archive' );
98
	}
99
100
101
102
	/**
103
	 *    initialize_template_parts
104
	 *
105
	 * @access    public
106
	 * @param \EE_Events_Archive_Config $config
107
	 * @return \EE_Template_Part_Manager
108
	 */
109 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...
110
		$config = $config instanceof EE_Events_Archive_Config ? $config : $this->config();
111
		EEH_Autoloader::instance()->register_template_part_autoloaders();
112
		$template_parts = new EE_Template_Part_Manager();
113
		$template_parts->add_template_part(
114
			'tickets',
115
			__( 'Ticket Selector', 'event_espresso' ),
116
			'content-espresso_events-tickets.php',
117
			$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...
118
		);
119
		$template_parts->add_template_part(
120
			'datetimes',
121
			__( 'Dates and Times', 'event_espresso' ),
122
			'content-espresso_events-datetimes.php',
123
			$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...
124
		);
125
		$template_parts->add_template_part(
126
			'event',
127
			__( 'Event Description', 'event_espresso' ),
128
			'content-espresso_events-details.php',
129
			$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...
130
		);
131
		$template_parts->add_template_part(
132
			'venue',
133
			__( 'Venue Information', 'event_espresso' ),
134
			'content-espresso_events-venues.php',
135
			$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...
136
		);
137
		do_action( 'AHEE__EED_Event_Archive__initialize_template_parts', $template_parts );
138
		return $template_parts;
139
	}
140
141
142
143
	/**
144
	 *    run - initial module setup - this gets called by the EE_Front_Controller if the module route is found in the incoming request
145
	 *
146
	 * @access    public
147
	 * @param WP $WP
148
	 * @return    void
149
	 */
150
	public function run( $WP ) {
151
		do_action( 'AHEE__EED_Events_Archive__before_run' );
152
		// ensure valid EE_Events_Archive_Config() object exists
153
		$this->set_config();
154
		/** @type EE_Events_Archive_Config $config */
155
		$config = $this->config();
156
		// load other required components
157
		$this->load_event_list_assets();
158
		// filter the WP posts_join, posts_where, and posts_orderby SQL clauses
159
		EE_Registry::instance()->load_helper( 'Event_Query' );
160
		//add query filters
161
		EEH_Event_Query::add_query_filters();
162
		// set params that will get used by the filters
163
		EEH_Event_Query::set_query_params(
164
			'', 	// month
165
			'', 	// category
166
			$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...
167
			'start_date', 	// orderby
168
			'ASC' 	// sort
169
		);
170
		// check what template is loaded
171
		add_filter( 'template_include',  array( $this, 'template_include' ), 999, 1 );
172
	}
173
174
175
176
	/**
177
	 * 	event_list - most likely called by the EES_Espresso_Events shortcode which uses this module to do some of it's lifting
178
	 *
179
	 *  @access 	public
180
	 *  @return 	void
181
	 */
182
	public function event_list() {
183
		// ensure valid EE_Events_Archive_Config() object exists
184
		$this->set_config();
185
		// load other required components
186
		$this->load_event_list_assets();
187
	}
188
189
190
191
192
193
194
195
196
	/**
197
	 *    template_include
198
	 *
199
	 * @access    public
200
	 * @param string $template
201
	 * @return    string
202
	 */
203
	public function template_include( $template = '' ) {
204
		// don't add content filter for dedicated EE child themes or private posts
205
		EE_Registry::instance()->load_helper( 'Template' );
206
		if ( ! EEH_Template::is_espresso_theme() ) {
207
			/** @type EE_Events_Archive_Config $config */
208
			$config = $this->config();
209
			// add status banner ?
210
			if ( $config->display_status_banner ) {
211
				add_filter( 'the_title', array( 'EED_Events_Archive', 'the_title' ), 100, 2 );
212
			}
213
			// if NOT a custom template
214
			if ( EE_Front_Controller::instance()->get_selected_template() != 'archive-espresso_events.php' ) {
215
				// don't display entry meta because the existing theme will take care of that
216
				add_filter( 'FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true' );
217
				// load functions.php file for the theme (loaded by WP if using child theme)
218
				EEH_Template::load_espresso_theme_functions();
219
				// because we don't know if the theme is using the_excerpt()
220
				add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
221
				// or the_content
222
				add_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
223
				// and just in case they are running get_the_excerpt() which DESTROYS things
224
				add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 );
225
				// don't display entry meta because the existing theme will take care of that
226
				add_filter( 'FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false' );
227
			}
228
		}
229
		return $template;
230
	}
231
232
233
234
	/**
235
	 * 	get_the_excerpt - kinda hacky, but if a theme is using get_the_excerpt(), then we need to remove our filters on the_content()
236
	 *
237
	 * 	@access 	public
238
	 * 	@param		string 	$excerpt
239
	 * 	@return 		string
240
	 */
241
	public static function get_the_excerpt( $excerpt = '' ) {
242
		if ( post_password_required() ) {
243
			return $excerpt;
244
		}
245
		if ( apply_filters( 'FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false ) ) {
246
			remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100 );
247
			remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100 );
248
			$excerpt = EED_Events_Archive::event_details( $excerpt );
249
		} else {
250
			EED_Events_Archive::$using_get_the_excerpt = true;
251
			add_filter( 'wp_trim_excerpt', array( 'EED_Events_Archive', 'end_get_the_excerpt' ), 999, 1 );
252
		}
253
		return $excerpt;
254
	}
255
256
257
258
	/**
259
	 * end_get_the_excerpt
260
	 *
261
	 * @access public
262
	 * @param  string $text
263
	 * @return string
264
	 */
265
	public static function end_get_the_excerpt( $text = '' ) {
266
		EED_Events_Archive::$using_get_the_excerpt = false;
267
		return $text;
268
	}
269
270
271
272
	/**
273
	 *    the_title
274
	 *
275
	 * @access    	public
276
	 * @param 		string 		$title
277
	 * @param 		string 		$id
278
	 * @return 		string
279
	 */
280
	public static function the_title( $title = '', $id = '' ) {
281
	global $post;
282
	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...
283
		return in_the_loop() && $post->ID == $id ? espresso_event_status_banner( $post->ID  ) . $title :  $title;
284
	}
285
	return $title;
286
}
287
288
289
290
	/**
291
	 * 	event_details
292
	 *
293
	 * 	@access 	public
294
	 * 	@param		string 	$content
295
	 * 	@return 		string
296
	 */
297
	public static function event_details( $content ) {
298
		global $post;
299
		static $current_post_ID = 0;
300
		if (
301
			$current_post_ID != $post->ID
302
			&& $post->post_type == 'espresso_events'
303
			&& ! EED_Events_Archive::$using_get_the_excerpt
304
			&& ! post_password_required()
305
			&& (
306
				apply_filters( 'FHEE__EES_Espresso_Events__process_shortcode__true', false )
307
				|| ! apply_filters( 'FHEE__content_espresso_events__template_loaded', false )
308
			)
309
		) {
310
			// Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
311
			// Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
312
			// BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
313
			// We want to allow those plugins to still do their thing and have access to our content, but depending on
314
			// how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
315
			// so the following allows this filter to be applied multiple times, but only once for real
316
			$current_post_ID = did_action( 'loop_start' ) ? $post->ID : 0;
317
			if ( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order ) {
318
				$content = \EED_Events_Archive::use_sortable_display_order();
319
			} else {
320
				$content = \EED_Events_Archive::use_filterable_display_order();
321
			}
322
		}
323
		return $content;
324
	}
325
326
327
328
	/**
329
	 *    use_sortable_display_order
330
	 *
331
	 * @access    protected
332
	 * @return string
333
	 */
334
	protected static function use_sortable_display_order() {
335
		// no further password checks required atm
336
		add_filter( 'FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true' );
337
		// 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)
338
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100 );
339
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100 );
340
		remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
341
		// now add additional content depending on whether event is using the_excerpt() or the_content()
342
		EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts();
343
		$content = EEH_Template::locate_template( 'content-espresso_events-details.php' );
344
		$content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters( $content );
345
		// re-add our main filters (or else the next event won't have them)
346
		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
347
		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
348
		add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 );
349
		remove_filter( 'FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true' );
350
		return $content;
351
	}
352
353
354
355
	/**
356
	 *    use_filterable_display_order
357
	 *
358
	 * @access 	protected
359
	 * @return 	string
360
	 */
361
	protected static function use_filterable_display_order() {
362
		// we need to first remove this callback from being applied to the_content()
363
		// (otherwise it will recurse and blow up the interweb)
364
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100 );
365
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100 );
366
		remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
367
		//now add additional content depending on whether event is using the_excerpt() or the_content()
368
		EED_Events_Archive::_add_additional_excerpt_filters();
369
		EED_Events_Archive::_add_additional_content_filters();
370
		do_action( 'AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters' );
371
		// now load our template
372
		$content = EEH_Template::locate_template( 'content-espresso_events-details.php' );
373
		// re-add our main filters (or else the next event won't have them)
374
		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
375
		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
376
		add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 );
377
		// but remove the other filters so that they don't get applied to the next post
378
		EED_Events_Archive::_remove_additional_events_archive_filters();
379
		do_action( 'AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters' );
380
		// we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
381
		//return ! empty( $template ) ? $template : $content;
382
		return $content;
383
	}
384
385
386
387
	/**
388
	 * 	event_datetimes - adds datetimes ABOVE content
389
	 *
390
	 *  	@access 	public
391
	 * 	@param		string 	$content
392
	 *  	@return 		string
393
	 */
394
	public static function event_datetimes( $content ) {
395
		if ( post_password_required() ) {
396
			return $content;
397
		}
398
		return EEH_Template::locate_template( 'content-espresso_events-datetimes.php' ) . $content;
399
	}
400
401
	/**
402
	 * 	event_tickets - adds tickets ABOVE content (which includes datetimes)
403
	 *
404
	 *  	@access 	public
405
	 * 	@param		string 	$content
406
	 *  	@return 		string
407
	 */
408
	public static function event_tickets( $content ) {
409
		if ( post_password_required() ) {
410
			return $content;
411
		}
412
		return EEH_Template::locate_template( 'content-espresso_events-tickets.php' ) . $content;
413
	}
414
415
416
417
	/**
418
	 *    event_venues - adds venues BELOW content
419
	 *
420
	 * @access    public
421
	 * @param    string $content
422
	 * @return    string
423
	 */
424
	public static function event_venue( $content ) {
425
		return EED_Events_Archive::event_venues( $content );
426
	}
427
428
	/**
429
	 * 	event_venues - adds venues BELOW content
430
	 *
431
	 *  	@access 	public
432
	 * 	@param		string 	$content
433
	 *  	@return 		string
434
	 */
435
	public static function event_venues( $content ) {
436
		if ( post_password_required() ) {
437
			return $content;
438
		}
439
		return $content . EEH_Template::locate_template( 'content-espresso_events-venues.php' );
440
	}
441
442
443
444
	/**
445
	 *    _add_additional_content_filters
446
	 *
447
	 * @access    private
448
	 * @return        void
449
	 */
450
	private static function _add_additional_excerpt_filters() {
451
		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_datetimes' ), 110, 1 );
452
		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_tickets' ), 120, 1 );
453
		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_venues' ), 130, 1 );
454
	}
455
456
457
458
	/**
459
	 *    _add_additional_content_filters
460
	 *
461
	 * @access    private
462
	 * @return        void
463
	 */
464
	private static function _add_additional_content_filters() {
465
		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_datetimes' ), 110, 1 );
466
		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_tickets' ), 120, 1 );
467
		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_venues' ), 130, 1 );
468
	}
469
470
471
472
	/**
473
	 *    _remove_additional_events_archive_filters
474
	 *
475
	 * @access    private
476
	 * @return        void
477
	 */
478
	private static function _remove_additional_events_archive_filters() {
479
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_datetimes' ), 110 );
480
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_tickets' ), 120 );
481
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_venues' ), 130 );
482
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_datetimes' ), 110 );
483
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_tickets' ), 120 );
484
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_venues' ), 130 );
485
	}
486
487
488
489
	/**
490
	 * 	remove_all_events_archive_filters
491
	 *
492
	 *  	@access 	public
493
	 *  	@return 		void
494
	 */
495
	public static function remove_all_events_archive_filters() {
496
		//remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
497
		remove_filter( 'the_title', array( 'EED_Events_Archive', 'the_title' ), 100 );
498
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100 );
499
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_datetimes' ), 110 );
500
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_tickets' ), 120 );
501
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_venues' ), 130 );
502
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100 );
503
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_datetimes' ), 110 );
504
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_tickets' ), 120 );
505
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_venues' ), 130 );
506
		// don't display entry meta because the existing theme will take care of that
507
		remove_filter( 'FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false' );
508
	}
509
510
511
512
513
514
515
	/**
516
	 * 	load_event_list_assets
517
	 *
518
	 *  @access 	public
519
	 *  @return 	void
520
	 */
521 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...
522
		do_action( 'AHEE__EED_Events_Archive__before_load_assets' );
523
		add_filter( 'FHEE_load_EE_Session', '__return_true' );
524
		add_filter( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true' );
525
		add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 );
526
		if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) {
527
			EE_Registry::instance()->load_helper( 'Maps' );
528
			add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 );
529
		}
530
		EE_Registry::instance()->load_helper( 'Event_View' );
531
	}
532
533
534
535
536
537
538
	/**
539
	 * 	wp_enqueue_scripts
540
	 *
541
	 *  @access 	public
542
	 *  @return 	void
543
	 */
544
	public function wp_enqueue_scripts() {
545
		// get some style
546
		if ( apply_filters( 'FHEE_enable_default_espresso_css', FALSE ) ) {
547
			// first check uploads folder
548
			EE_Registry::instance()->load_helper( 'File' );
549
			if ( EEH_File::is_readable( get_stylesheet_directory() . $this->theme . DS . 'style.css' )) {
550
				wp_register_style( $this->theme, get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', array( 'dashicons', 'espresso_default' ));
551
			} 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...
552
		}
553
		wp_enqueue_style( $this->theme );
554
555
	}
556
}
557
558
559
560
561
562
	/**
563
	 * 	template_settings_form
564
	 *
565
	 *  @access 	public
566
	 *  @static
567
	 *  @return 	string
568
	 */
569
	public static function template_settings_form() {
570
	$template_settings = EE_Registry::instance()->CFG->template_settings;
571
	$template_settings->EED_Events_Archive = isset( $template_settings->EED_Events_Archive ) ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config();
572
	$template_settings->EED_Events_Archive = apply_filters( 'FHEE__EED_Events_Archive__template_settings_form__event_list_config', $template_settings->EED_Events_Archive );
573
	$events_archive_settings = array(
574
		'display_status_banner' => 0,
575
		'display_description' => 1,
576
		'display_ticket_selector' => 0,
577
		'display_datetimes' => 1,
578
		'display_venue' => 0,
579
		'display_expired_events' => 0
580
	);
581
	$events_archive_settings = array_merge( $events_archive_settings, (array)$template_settings->EED_Events_Archive );
582
	EEH_Template::display_template( EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $events_archive_settings );
583
}
584
585
586
587
588
589
590
	/**
591
	 * 	update_template_settings
592
	 *
593
	 *  @access 	public
594
	 *  @param 	EE_Template_Config $CFG
595
	 *  @param 	EE_Request_Handler $REQ
596
	 *  @return 	EE_Template_Config
597
	 */
598
	public static function update_template_settings( $CFG, $REQ ) {
599
		$CFG->EED_Events_Archive = new EE_Events_Archive_Config();
600
		// unless we are resetting the config...
601
		if ( ! isset( $REQ['EED_Events_Archive_reset_event_list_settings'] ) || absint( $REQ['EED_Events_Archive_reset_event_list_settings'] ) !== 1 ) {
602
			$CFG->EED_Events_Archive->display_status_banner = isset( $REQ['EED_Events_Archive_display_status_banner'] ) ? absint( $REQ['EED_Events_Archive_display_status_banner'] ) : 0;
603
			$CFG->EED_Events_Archive->display_description = isset( $REQ['EED_Events_Archive_display_description'] ) ? absint( $REQ['EED_Events_Archive_display_description'] ) : 1;
604
			$CFG->EED_Events_Archive->display_ticket_selector = isset( $REQ['EED_Events_Archive_display_ticket_selector'] ) ? absint( $REQ['EED_Events_Archive_display_ticket_selector'] ) : 0;
605
			$CFG->EED_Events_Archive->display_datetimes = isset( $REQ['EED_Events_Archive_display_datetimes'] ) ? absint( $REQ['EED_Events_Archive_display_datetimes'] ) : 1;
606
			$CFG->EED_Events_Archive->display_venue = isset( $REQ['EED_Events_Archive_display_venue'] ) ? absint( $REQ['EED_Events_Archive_display_venue'] ) : 0;
607
			$CFG->EED_Events_Archive->display_expired_events = isset( $REQ['EED_Events_Archive_display_expired_events'] ) ? absint( $REQ['EED_Events_Archive_display_expired_events'] ) : 0;			}
608
		return $CFG;
609
	}
610
611
612
613
	/**
614
	 *    event_list_css
615
	 *
616
	 * @access    public
617
	 * @param string $extra_class
618
	 * @return    string
619
	 */
620
	public static function event_list_css( $extra_class = '' ) {
621
		$event_list_css = ! empty( $extra_class ) ? array( $extra_class ) : array();
622
		$event_list_css[] = 'espresso-event-list-event';
623
		return implode( ' ', $event_list_css );
624
	}
625
626
627
628
629
630
631
	/**
632
	 * 	event_categories
633
	 *
634
	 *  @access 	public
635
	 *  @return 	array
636
	 */
637
	public static function event_categories() {
638
	return EE_Registry::instance()->load_model('Term')->get_all_ee_categories();
0 ignored issues
show
Bug introduced by
The method get_all_ee_categories cannot be called on \EE_Registry::instance()->load_model('Term') (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
639
}
640
641
642
643
	/**
644
	 *    display_description
645
	 *
646
	 * @access    public
647
	 * @param $value
648
	 * @return    bool
649
	 */
650
	public static function display_description( $value ) {
651
		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
652
		$display_description= isset( $config->display_description ) ? $config->display_description : 1;
653
		return $display_description === $value ? TRUE : FALSE;
654
	}
655
656
657
	/**
658
	 * 	display_ticket_selector
659
	 *
660
	 *  @access 	public
661
	 *  @return 	bool
662
	 */
663
	public static function display_ticket_selector() {
664
		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
665
		return isset( $config->display_ticket_selector ) && $config->display_ticket_selector ? TRUE : FALSE;
666
	}
667
668
669
670
	/**
671
	 * 	display_venue
672
	 *
673
	 *  @access 	public
674
	 *  @return 	bool
675
	 */
676
	public static function display_venue() {
677
		EE_Registry::instance()->load_helper( 'Venue_View' );
678
		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
679
		return isset( $config->display_venue ) && $config->display_venue && EEH_Venue_View::venue_name() ? TRUE : FALSE;
680
	}
681
682
683
	/**
684
	 * 	display_datetimes
685
	 *
686
	 *  @access 	public
687
	 *  @return 	bool
688
	 */
689
	public static function display_datetimes() {
690
		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
691
		return isset( $config->display_datetimes ) && $config->display_datetimes ? TRUE : FALSE;
692
}
693
694
695
696
697
698
699
	/**
700
	 * 	event_list_title
701
	 *
702
	 *  @access 	public
703
	 *  @return 	string
704
	 */
705
	public static function event_list_title() {
706
		return apply_filters( 'FHEE__archive_espresso_events_template__upcoming_events_h1', __( 'Upcoming Events', 'event_espresso' ));
707
	}
708
709
710
	// GRAVEYARD
711
712
	/**
713
	 * 	@since 4.4.0
714
	 */
715
	public static function _doing_it_wrong_notice( $function = '' ) {
716
		EE_Error::doing_it_wrong(
717
			__FUNCTION__,
718
			sprintf(
719
				__( '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' ),
720
				$function,
721
				'<br />',
722
				'4.6.0'
723
			),
724
			'4.4.0'
725
		);
726
	}
727
728
729
730
	/**
731
	 * 	@deprecated
732
	 * 	@since 4.4.0
733
	 */
734
	public function get_post_data() {
735
		EE_Registry::instance()->load_helper( 'Event_Query' );
736
		EEH_Event_Query::set_query_params();
737
	}
738
	/**
739
	 * 	@deprecated
740
	 * 	@since 4.4.0
741
	 */
742
	public function posts_fields( $SQL, WP_Query $wp_query ) {
743
		EE_Registry::instance()->load_helper( 'Event_Query' );
744
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
745
		return EEH_Event_Query::posts_fields( $SQL, $wp_query );
746
	}
747
	/**
748
	 * 	@deprecated
749
	 * 	@since 4.4.0
750
	 */
751
	public static function posts_fields_sql_for_orderby( $orderby_params = array() ) {
752
		EE_Registry::instance()->load_helper( 'Event_Query' );
753
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
754
		return EEH_Event_Query::posts_fields_sql_for_orderby( $orderby_params );
755
	}
756
	/**
757
	 * 	@deprecated
758
	 * 	@since 4.4.0
759
	 */
760
	public function posts_join( $SQL, WP_Query $wp_query ) {
761
		EE_Registry::instance()->load_helper( 'Event_Query' );
762
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
763
		return EEH_Event_Query::posts_join( $SQL, $wp_query );
764
	}
765
	/**
766
	 * 	@deprecated
767
	 * 	@since 4.4.0
768
	 */
769
	public static function posts_join_sql_for_terms( $join_terms = NULL ) {
770
		EE_Registry::instance()->load_helper( 'Event_Query' );
771
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
772
		return EEH_Event_Query::posts_join_sql_for_terms( $join_terms );
773
	}
774
	/**
775
	 * 	@deprecated
776
	 * 	@since 4.4.0
777
	 */
778
	public static function posts_join_for_orderby( $orderby_params = array() ) {
779
		EE_Registry::instance()->load_helper( 'Event_Query' );
780
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
781
		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...
782
	}
783
	/**
784
	 * 	@deprecated
785
	 * 	@since 4.4.0
786
	 */
787
	public function posts_where( $SQL, WP_Query $wp_query ) {
788
		EE_Registry::instance()->load_helper( 'Event_Query' );
789
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
790
		return EEH_Event_Query::posts_where( $SQL, $wp_query );
791
	}
792
	/**
793
	 * 	@deprecated
794
	 * 	@since 4.4.0
795
	 */
796
	public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) {
797
		EE_Registry::instance()->load_helper( 'Event_Query' );
798
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
799
		return EEH_Event_Query::posts_where_sql_for_show_expired( $show_expired );
800
	}
801
	/**
802
	 * 	@deprecated
803
	 * 	@since 4.4.0
804
	 */
805
	public static function posts_where_sql_for_event_category_slug( $event_category_slug = NULL ) {
806
		EE_Registry::instance()->load_helper( 'Event_Query' );
807
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
808
		return EEH_Event_Query::posts_where_sql_for_event_category_slug( $event_category_slug );
809
	}
810
	/**
811
	 * 	@deprecated
812
	 * 	@since 4.4.0
813
	 */
814
	public static function posts_where_sql_for_event_list_month( $month = NULL ) {
815
		EE_Registry::instance()->load_helper( 'Event_Query' );
816
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
817
		return EEH_Event_Query::posts_where_sql_for_event_list_month( $month );
818
	}
819
	/**
820
	 * 	@deprecated
821
	 * 	@since 4.4.0
822
	 */
823
	public function posts_orderby( $SQL, WP_Query $wp_query ) {
824
		EE_Registry::instance()->load_helper( 'Event_Query' );
825
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
826
		return EEH_Event_Query::posts_orderby( $SQL, $wp_query );
827
	}
828
	/**
829
	 * 	@deprecated
830
	 * 	@since 4.4.0
831
	 */
832
	public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) {
833
		EE_Registry::instance()->load_helper( 'Event_Query' );
834
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
835
		return EEH_Event_Query::posts_orderby_sql( $orderby_params, $sort );
836
	}
837
838
839
840
}
841
842
843
844
845
846
/**
847
 * @return int
848
 */
849
function espresso_get_event_list_ID() {
850
	EED_Events_Archive::$espresso_event_list_ID++;
851
	EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID;
852
	return EED_Events_Archive::$espresso_event_list_ID;
853
}
854
855
/**
856
 * @return string
857
 */
858
function espresso_event_list_title() {
859
	return EED_Events_Archive::event_list_title();
860
}
861
862
/**
863
 * @param string $extra_class
864
 * @return string
865
 */
866
function espresso_event_list_css( $extra_class = '' ) {
867
	return EED_Events_Archive::event_list_css( $extra_class );
868
}
869
870
/**
871
 * @return array
872
 */
873
function espresso_get_event_categories() {
874
	return EED_Events_Archive::event_categories();
875
}
876
877
/**
878
 * @return bool
879
 */
880
function espresso_display_full_description_in_event_list() {
881
	return EED_Events_Archive::display_description( 2 );
882
}
883
884
/**
885
 * @return bool
886
 */
887
function espresso_display_excerpt_in_event_list() {
888
	return EED_Events_Archive::display_description( 1 );
889
}
890
891
/**
892
 * @return bool
893
 */
894
function espresso_display_ticket_selector_in_event_list() {
895
	return EED_Events_Archive::display_ticket_selector();
896
}
897
898
/**
899
 * @return bool
900
 */
901
function espresso_display_venue_in_event_list() {
902
	return EED_Events_Archive::display_venue();
903
}
904
905
/**
906
 * @return bool
907
 */
908
function espresso_display_datetimes_in_event_list() {
909
	return EED_Events_Archive::display_datetimes();
910
}
911
912
913
914
915
916
917
918
// End of file EED_Events_Archive.module.php
919
// Location: /modules/events_archive/EED_Events_Archive.module.php
920