Completed
Branch TASK-9118-extensions-page (04eaec)
by
unknown
856:31 queued 840:33
created

EED_Events_Archive   F

Complexity

Total Complexity 90

Size/Duplication

Total Lines 819
Duplicated Lines 5.13 %

Coupling/Cohesion

Components 3
Dependencies 15

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 42
loc 819
rs 1.263
wmc 90
lcom 3
cbo 15

47 Methods

Rating   Name   Duplication   Size   Complexity  
B template_include() 0 30 5
A get_the_excerpt() 0 14 3
A end_get_the_excerpt() 0 4 1
A the_title() 0 7 4
D event_details() 0 28 9
A instance() 0 3 1
A set_hooks() 0 5 1
A set_hooks_admin() 0 3 1
A set_definitions() 0 4 1
A set_config() 0 5 1
B initialize_template_parts() 31 31 2
A run() 0 23 1
A event_list() 0 6 1
A use_sortable_display_order() 0 18 1
A use_filterable_display_order() 0 23 1
A event_datetimes() 0 6 2
A event_tickets() 0 6 2
A event_venue() 0 3 1
A event_venues() 0 6 2
A _add_additional_excerpt_filters() 0 5 1
A _add_additional_content_filters() 0 5 1
A _remove_additional_events_archive_filters() 0 8 1
A remove_all_events_archive_filters() 0 14 1
A load_event_list_assets() 11 11 2
A wp_enqueue_scripts() 0 13 3
A template_settings_form() 0 15 2
B update_template_settings() 0 12 9
A event_list_css() 0 5 2
A event_categories() 0 3 1
A display_description() 0 5 3
A display_ticket_selector() 0 4 3
A display_venue() 0 5 4
A display_datetimes() 0 4 3
A event_list_title() 0 3 1
A _doing_it_wrong_notice() 0 12 1
A get_post_data() 0 4 1
A posts_fields() 0 5 1
A posts_fields_sql_for_orderby() 0 5 1
A posts_join() 0 5 1
A posts_join_sql_for_terms() 0 5 1
A posts_join_for_orderby() 0 5 1
A posts_where() 0 5 1
A posts_where_sql_for_show_expired() 0 5 1
A posts_where_sql_for_event_category_slug() 0 5 1
A posts_where_sql_for_event_list_month() 0 5 1
A posts_orderby() 0 5 1
A posts_orderby_sql() 0 5 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like EED_Events_Archive often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use EED_Events_Archive, and based on these observations, apply Extract Interface, too.

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
				|| apply_filters( 'FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', FALSE )
216
			) {
217
				// don't display entry meta because the existing theme will take care of that
218
				add_filter( 'FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true' );
219
				// load functions.php file for the theme (loaded by WP if using child theme)
220
				EEH_Template::load_espresso_theme_functions();
221
				// because we don't know if the theme is using the_excerpt()
222
				add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
223
				// or the_content
224
				add_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
225
				// and just in case they are running get_the_excerpt() which DESTROYS things
226
				add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 );
227
				// don't display entry meta because the existing theme will take care of that
228
				add_filter( 'FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false' );
229
			}
230
		}
231
		return $template;
232
	}
233
234
235
236
	/**
237
	 * 	get_the_excerpt - kinda hacky, but if a theme is using get_the_excerpt(), then we need to remove our filters on the_content()
238
	 *
239
	 * 	@access 	public
240
	 * 	@param		string 	$excerpt
241
	 * 	@return 		string
242
	 */
243
	public static function get_the_excerpt( $excerpt = '' ) {
244
		if ( post_password_required() ) {
245
			return $excerpt;
246
		}
247
		if ( apply_filters( 'FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false ) ) {
248
			remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100 );
249
			remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100 );
250
			$excerpt = EED_Events_Archive::event_details( $excerpt );
251
		} else {
252
			EED_Events_Archive::$using_get_the_excerpt = true;
253
			add_filter( 'wp_trim_excerpt', array( 'EED_Events_Archive', 'end_get_the_excerpt' ), 999, 1 );
254
		}
255
		return $excerpt;
256
	}
257
258
259
260
	/**
261
	 * end_get_the_excerpt
262
	 *
263
	 * @access public
264
	 * @param  string $text
265
	 * @return string
266
	 */
267
	public static function end_get_the_excerpt( $text = '' ) {
268
		EED_Events_Archive::$using_get_the_excerpt = false;
269
		return $text;
270
	}
271
272
273
274
	/**
275
	 *    the_title
276
	 *
277
	 * @access    	public
278
	 * @param 		string 		$title
279
	 * @param 		string 		$id
280
	 * @return 		string
281
	 */
282
	public static function the_title( $title = '', $id = '' ) {
283
	global $post;
284
	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...
285
		return in_the_loop() && $post->ID == $id ? espresso_event_status_banner( $post->ID  ) . $title :  $title;
286
	}
287
	return $title;
288
}
289
290
291
292
	/**
293
	 * 	event_details
294
	 *
295
	 * 	@access 	public
296
	 * 	@param		string 	$content
297
	 * 	@return 		string
298
	 */
299
	public static function event_details( $content ) {
300
		global $post;
301
		static $current_post_ID = 0;
302
		if (
303
			$current_post_ID != $post->ID
304
			&& $post->post_type == 'espresso_events'
305
			&& ! EED_Events_Archive::$using_get_the_excerpt
306
			&& ! post_password_required()
307
			&& (
308
				apply_filters( 'FHEE__EES_Espresso_Events__process_shortcode__true', false )
309
				|| ! apply_filters( 'FHEE__content_espresso_events__template_loaded', false )
310
			)
311
		) {
312
			// Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
313
			// Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
314
			// BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
315
			// We want to allow those plugins to still do their thing and have access to our content, but depending on
316
			// how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
317
			// so the following allows this filter to be applied multiple times, but only once for real
318
			$current_post_ID = did_action( 'loop_start' ) ? $post->ID : 0;
319
			if ( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order ) {
320
				$content = \EED_Events_Archive::use_sortable_display_order();
321
			} else {
322
				$content = \EED_Events_Archive::use_filterable_display_order();
323
			}
324
		}
325
		return $content;
326
	}
327
328
329
330
	/**
331
	 *    use_sortable_display_order
332
	 *
333
	 * @access    protected
334
	 * @return string
335
	 */
336
	protected static function use_sortable_display_order() {
337
		// no further password checks required atm
338
		add_filter( 'FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true' );
339
		// 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)
340
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100 );
341
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100 );
342
		remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
343
		// now add additional content depending on whether event is using the_excerpt() or the_content()
344
		EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts();
345
		$content = EEH_Template::locate_template( 'content-espresso_events-details.php' );
346
		$content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters( $content );
347
		// re-add our main filters (or else the next event won't have them)
348
		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
349
		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
350
		add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 );
351
		remove_filter( 'FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true' );
352
		return $content;
353
	}
354
355
356
357
	/**
358
	 *    use_filterable_display_order
359
	 *
360
	 * @access 	protected
361
	 * @return 	string
362
	 */
363
	protected static function use_filterable_display_order() {
364
		// we need to first remove this callback from being applied to the_content()
365
		// (otherwise it will recurse and blow up the interweb)
366
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100 );
367
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100 );
368
		remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
369
		//now add additional content depending on whether event is using the_excerpt() or the_content()
370
		EED_Events_Archive::_add_additional_excerpt_filters();
371
		EED_Events_Archive::_add_additional_content_filters();
372
		do_action( 'AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters' );
373
		// now load our template
374
		$content = EEH_Template::locate_template( 'content-espresso_events-details.php' );
375
		// re-add our main filters (or else the next event won't have them)
376
		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
377
		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
378
		add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 );
379
		// but remove the other filters so that they don't get applied to the next post
380
		EED_Events_Archive::_remove_additional_events_archive_filters();
381
		do_action( 'AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters' );
382
		// we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
383
		//return ! empty( $template ) ? $template : $content;
384
		return $content;
385
	}
386
387
388
389
	/**
390
	 * 	event_datetimes - adds datetimes ABOVE content
391
	 *
392
	 *  	@access 	public
393
	 * 	@param		string 	$content
394
	 *  	@return 		string
395
	 */
396
	public static function event_datetimes( $content ) {
397
		if ( post_password_required() ) {
398
			return $content;
399
		}
400
		return EEH_Template::locate_template( 'content-espresso_events-datetimes.php' ) . $content;
401
	}
402
403
	/**
404
	 * 	event_tickets - adds tickets ABOVE content (which includes datetimes)
405
	 *
406
	 *  	@access 	public
407
	 * 	@param		string 	$content
408
	 *  	@return 		string
409
	 */
410
	public static function event_tickets( $content ) {
411
		if ( post_password_required() ) {
412
			return $content;
413
		}
414
		return EEH_Template::locate_template( 'content-espresso_events-tickets.php' ) . $content;
415
	}
416
417
418
419
	/**
420
	 *    event_venues - adds venues BELOW content
421
	 *
422
	 * @access    public
423
	 * @param    string $content
424
	 * @return    string
425
	 */
426
	public static function event_venue( $content ) {
427
		return EED_Events_Archive::event_venues( $content );
428
	}
429
430
	/**
431
	 * 	event_venues - adds venues BELOW content
432
	 *
433
	 *  	@access 	public
434
	 * 	@param		string 	$content
435
	 *  	@return 		string
436
	 */
437
	public static function event_venues( $content ) {
438
		if ( post_password_required() ) {
439
			return $content;
440
		}
441
		return $content . EEH_Template::locate_template( 'content-espresso_events-venues.php' );
442
	}
443
444
445
446
	/**
447
	 *    _add_additional_content_filters
448
	 *
449
	 * @access    private
450
	 * @return        void
451
	 */
452
	private static function _add_additional_excerpt_filters() {
453
		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_datetimes' ), 110, 1 );
454
		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_tickets' ), 120, 1 );
455
		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_venues' ), 130, 1 );
456
	}
457
458
459
460
	/**
461
	 *    _add_additional_content_filters
462
	 *
463
	 * @access    private
464
	 * @return        void
465
	 */
466
	private static function _add_additional_content_filters() {
467
		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_datetimes' ), 110, 1 );
468
		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_tickets' ), 120, 1 );
469
		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_venues' ), 130, 1 );
470
	}
471
472
473
474
	/**
475
	 *    _remove_additional_events_archive_filters
476
	 *
477
	 * @access    private
478
	 * @return        void
479
	 */
480
	private static function _remove_additional_events_archive_filters() {
481
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_datetimes' ), 110 );
482
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_tickets' ), 120 );
483
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_venues' ), 130 );
484
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_datetimes' ), 110 );
485
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_tickets' ), 120 );
486
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_venues' ), 130 );
487
	}
488
489
490
491
	/**
492
	 * 	remove_all_events_archive_filters
493
	 *
494
	 *  	@access 	public
495
	 *  	@return 		void
496
	 */
497
	public static function remove_all_events_archive_filters() {
498
		//remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
499
		remove_filter( 'the_title', array( 'EED_Events_Archive', 'the_title' ), 100 );
500
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100 );
501
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_datetimes' ), 110 );
502
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_tickets' ), 120 );
503
		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_venues' ), 130 );
504
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100 );
505
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_datetimes' ), 110 );
506
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_tickets' ), 120 );
507
		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_venues' ), 130 );
508
		// don't display entry meta because the existing theme will take care of that
509
		remove_filter( 'FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false' );
510
	}
511
512
513
514
515
516
517
	/**
518
	 * 	load_event_list_assets
519
	 *
520
	 *  @access 	public
521
	 *  @return 	void
522
	 */
523 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...
524
		do_action( 'AHEE__EED_Events_Archive__before_load_assets' );
525
		add_filter( 'FHEE_load_EE_Session', '__return_true' );
526
		add_filter( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true' );
527
		add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 );
528
		if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) {
529
			EE_Registry::instance()->load_helper( 'Maps' );
530
			add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 );
531
		}
532
		EE_Registry::instance()->load_helper( 'Event_View' );
533
	}
534
535
536
537
538
539
540
	/**
541
	 * 	wp_enqueue_scripts
542
	 *
543
	 *  @access 	public
544
	 *  @return 	void
545
	 */
546
	public function wp_enqueue_scripts() {
547
		// get some style
548
		if ( apply_filters( 'FHEE_enable_default_espresso_css', FALSE ) ) {
549
			// first check uploads folder
550
			EE_Registry::instance()->load_helper( 'File' );
551
			if ( EEH_File::is_readable( get_stylesheet_directory() . $this->theme . DS . 'style.css' )) {
552
				wp_register_style( $this->theme, get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', array( 'dashicons', 'espresso_default' ));
553
			} 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...
554
		}
555
		wp_enqueue_style( $this->theme );
556
557
	}
558
}
559
560
561
562
563
564
	/**
565
	 * 	template_settings_form
566
	 *
567
	 *  @access 	public
568
	 *  @static
569
	 *  @return 	string
570
	 */
571
	public static function template_settings_form() {
572
	$template_settings = EE_Registry::instance()->CFG->template_settings;
573
	$template_settings->EED_Events_Archive = isset( $template_settings->EED_Events_Archive ) ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config();
574
	$template_settings->EED_Events_Archive = apply_filters( 'FHEE__EED_Events_Archive__template_settings_form__event_list_config', $template_settings->EED_Events_Archive );
575
	$events_archive_settings = array(
576
		'display_status_banner' => 0,
577
		'display_description' => 1,
578
		'display_ticket_selector' => 0,
579
		'display_datetimes' => 1,
580
		'display_venue' => 0,
581
		'display_expired_events' => 0
582
	);
583
	$events_archive_settings = array_merge( $events_archive_settings, (array)$template_settings->EED_Events_Archive );
584
	EEH_Template::display_template( EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $events_archive_settings );
585
}
586
587
588
589
590
591
592
	/**
593
	 * 	update_template_settings
594
	 *
595
	 *  @access 	public
596
	 *  @param 	EE_Template_Config $CFG
597
	 *  @param 	EE_Request_Handler $REQ
598
	 *  @return 	EE_Template_Config
599
	 */
600
	public static function update_template_settings( $CFG, $REQ ) {
601
		$CFG->EED_Events_Archive = new EE_Events_Archive_Config();
602
		// unless we are resetting the config...
603
		if ( ! isset( $REQ['EED_Events_Archive_reset_event_list_settings'] ) || absint( $REQ['EED_Events_Archive_reset_event_list_settings'] ) !== 1 ) {
604
			$CFG->EED_Events_Archive->display_status_banner = isset( $REQ['EED_Events_Archive_display_status_banner'] ) ? absint( $REQ['EED_Events_Archive_display_status_banner'] ) : 0;
605
			$CFG->EED_Events_Archive->display_description = isset( $REQ['EED_Events_Archive_display_description'] ) ? absint( $REQ['EED_Events_Archive_display_description'] ) : 1;
606
			$CFG->EED_Events_Archive->display_ticket_selector = isset( $REQ['EED_Events_Archive_display_ticket_selector'] ) ? absint( $REQ['EED_Events_Archive_display_ticket_selector'] ) : 0;
607
			$CFG->EED_Events_Archive->display_datetimes = isset( $REQ['EED_Events_Archive_display_datetimes'] ) ? absint( $REQ['EED_Events_Archive_display_datetimes'] ) : 1;
608
			$CFG->EED_Events_Archive->display_venue = isset( $REQ['EED_Events_Archive_display_venue'] ) ? absint( $REQ['EED_Events_Archive_display_venue'] ) : 0;
609
			$CFG->EED_Events_Archive->display_expired_events = isset( $REQ['EED_Events_Archive_display_expired_events'] ) ? absint( $REQ['EED_Events_Archive_display_expired_events'] ) : 0;			}
610
		return $CFG;
611
	}
612
613
614
615
	/**
616
	 *    event_list_css
617
	 *
618
	 * @access    public
619
	 * @param string $extra_class
620
	 * @return    string
621
	 */
622
	public static function event_list_css( $extra_class = '' ) {
623
		$event_list_css = ! empty( $extra_class ) ? array( $extra_class ) : array();
624
		$event_list_css[] = 'espresso-event-list-event';
625
		return implode( ' ', $event_list_css );
626
	}
627
628
629
630
631
632
633
	/**
634
	 * 	event_categories
635
	 *
636
	 *  @access 	public
637
	 *  @return 	array
638
	 */
639
	public static function event_categories() {
640
	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...
641
}
642
643
644
645
	/**
646
	 *    display_description
647
	 *
648
	 * @access    public
649
	 * @param $value
650
	 * @return    bool
651
	 */
652
	public static function display_description( $value ) {
653
		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
654
		$display_description= isset( $config->display_description ) ? $config->display_description : 1;
655
		return $display_description === $value ? TRUE : FALSE;
656
	}
657
658
659
	/**
660
	 * 	display_ticket_selector
661
	 *
662
	 *  @access 	public
663
	 *  @return 	bool
664
	 */
665
	public static function display_ticket_selector() {
666
		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
667
		return isset( $config->display_ticket_selector ) && $config->display_ticket_selector ? TRUE : FALSE;
668
	}
669
670
671
672
	/**
673
	 * 	display_venue
674
	 *
675
	 *  @access 	public
676
	 *  @return 	bool
677
	 */
678
	public static function display_venue() {
679
		EE_Registry::instance()->load_helper( 'Venue_View' );
680
		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
681
		return isset( $config->display_venue ) && $config->display_venue && EEH_Venue_View::venue_name() ? TRUE : FALSE;
682
	}
683
684
685
	/**
686
	 * 	display_datetimes
687
	 *
688
	 *  @access 	public
689
	 *  @return 	bool
690
	 */
691
	public static function display_datetimes() {
692
		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
693
		return isset( $config->display_datetimes ) && $config->display_datetimes ? TRUE : FALSE;
694
}
695
696
697
698
699
700
701
	/**
702
	 * 	event_list_title
703
	 *
704
	 *  @access 	public
705
	 *  @return 	string
706
	 */
707
	public static function event_list_title() {
708
		return apply_filters( 'FHEE__archive_espresso_events_template__upcoming_events_h1', __( 'Upcoming Events', 'event_espresso' ));
709
	}
710
711
712
	// GRAVEYARD
713
714
	/**
715
	 * 	@since 4.4.0
716
	 */
717
	public static function _doing_it_wrong_notice( $function = '' ) {
718
		EE_Error::doing_it_wrong(
719
			__FUNCTION__,
720
			sprintf(
721
				__( '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' ),
722
				$function,
723
				'<br />',
724
				'4.6.0'
725
			),
726
			'4.4.0'
727
		);
728
	}
729
730
731
732
	/**
733
	 * 	@deprecated
734
	 * 	@since 4.4.0
735
	 */
736
	public function get_post_data() {
737
		EE_Registry::instance()->load_helper( 'Event_Query' );
738
		EEH_Event_Query::set_query_params();
739
	}
740
	/**
741
	 * 	@deprecated
742
	 * 	@since 4.4.0
743
	 */
744
	public function posts_fields( $SQL, WP_Query $wp_query ) {
745
		EE_Registry::instance()->load_helper( 'Event_Query' );
746
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
747
		return EEH_Event_Query::posts_fields( $SQL, $wp_query );
748
	}
749
	/**
750
	 * 	@deprecated
751
	 * 	@since 4.4.0
752
	 */
753
	public static function posts_fields_sql_for_orderby( $orderby_params = array() ) {
754
		EE_Registry::instance()->load_helper( 'Event_Query' );
755
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
756
		return EEH_Event_Query::posts_fields_sql_for_orderby( $orderby_params );
757
	}
758
	/**
759
	 * 	@deprecated
760
	 * 	@since 4.4.0
761
	 */
762
	public function posts_join( $SQL, WP_Query $wp_query ) {
763
		EE_Registry::instance()->load_helper( 'Event_Query' );
764
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
765
		return EEH_Event_Query::posts_join( $SQL, $wp_query );
766
	}
767
	/**
768
	 * 	@deprecated
769
	 * 	@since 4.4.0
770
	 */
771
	public static function posts_join_sql_for_terms( $join_terms = NULL ) {
772
		EE_Registry::instance()->load_helper( 'Event_Query' );
773
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
774
		return EEH_Event_Query::posts_join_sql_for_terms( $join_terms );
775
	}
776
	/**
777
	 * 	@deprecated
778
	 * 	@since 4.4.0
779
	 */
780
	public static function posts_join_for_orderby( $orderby_params = array() ) {
781
		EE_Registry::instance()->load_helper( 'Event_Query' );
782
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
783
		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...
784
	}
785
	/**
786
	 * 	@deprecated
787
	 * 	@since 4.4.0
788
	 */
789
	public function posts_where( $SQL, WP_Query $wp_query ) {
790
		EE_Registry::instance()->load_helper( 'Event_Query' );
791
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
792
		return EEH_Event_Query::posts_where( $SQL, $wp_query );
793
	}
794
	/**
795
	 * 	@deprecated
796
	 * 	@since 4.4.0
797
	 */
798
	public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) {
799
		EE_Registry::instance()->load_helper( 'Event_Query' );
800
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
801
		return EEH_Event_Query::posts_where_sql_for_show_expired( $show_expired );
802
	}
803
	/**
804
	 * 	@deprecated
805
	 * 	@since 4.4.0
806
	 */
807
	public static function posts_where_sql_for_event_category_slug( $event_category_slug = NULL ) {
808
		EE_Registry::instance()->load_helper( 'Event_Query' );
809
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
810
		return EEH_Event_Query::posts_where_sql_for_event_category_slug( $event_category_slug );
811
	}
812
	/**
813
	 * 	@deprecated
814
	 * 	@since 4.4.0
815
	 */
816
	public static function posts_where_sql_for_event_list_month( $month = NULL ) {
817
		EE_Registry::instance()->load_helper( 'Event_Query' );
818
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
819
		return EEH_Event_Query::posts_where_sql_for_event_list_month( $month );
820
	}
821
	/**
822
	 * 	@deprecated
823
	 * 	@since 4.4.0
824
	 */
825
	public function posts_orderby( $SQL, WP_Query $wp_query ) {
826
		EE_Registry::instance()->load_helper( 'Event_Query' );
827
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
828
		return EEH_Event_Query::posts_orderby( $SQL, $wp_query );
829
	}
830
	/**
831
	 * 	@deprecated
832
	 * 	@since 4.4.0
833
	 */
834
	public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) {
835
		EE_Registry::instance()->load_helper( 'Event_Query' );
836
		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
837
		return EEH_Event_Query::posts_orderby_sql( $orderby_params, $sort );
838
	}
839
840
841
842
}
843
844
845
846
847
848
/**
849
 * @return int
850
 */
851
function espresso_get_event_list_ID() {
852
	EED_Events_Archive::$espresso_event_list_ID++;
853
	EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID;
854
	return EED_Events_Archive::$espresso_event_list_ID;
855
}
856
857
/**
858
 * @return string
859
 */
860
function espresso_event_list_title() {
861
	return EED_Events_Archive::event_list_title();
862
}
863
864
/**
865
 * @param string $extra_class
866
 * @return string
867
 */
868
function espresso_event_list_css( $extra_class = '' ) {
869
	return EED_Events_Archive::event_list_css( $extra_class );
870
}
871
872
/**
873
 * @return array
874
 */
875
function espresso_get_event_categories() {
876
	return EED_Events_Archive::event_categories();
877
}
878
879
/**
880
 * @return bool
881
 */
882
function espresso_display_full_description_in_event_list() {
883
	return EED_Events_Archive::display_description( 2 );
884
}
885
886
/**
887
 * @return bool
888
 */
889
function espresso_display_excerpt_in_event_list() {
890
	return EED_Events_Archive::display_description( 1 );
891
}
892
893
/**
894
 * @return bool
895
 */
896
function espresso_display_ticket_selector_in_event_list() {
897
	return EED_Events_Archive::display_ticket_selector();
898
}
899
900
/**
901
 * @return bool
902
 */
903
function espresso_display_venue_in_event_list() {
904
	return EED_Events_Archive::display_venue();
905
}
906
907
/**
908
 * @return bool
909
 */
910
function espresso_display_datetimes_in_event_list() {
911
	return EED_Events_Archive::display_datetimes();
912
}
913
914
915
916
917
918
919
920
// End of file EED_Events_Archive.module.php
921
// Location: /modules/events_archive/EED_Events_Archive.module.php
922