Completed
Branch TASK-9118-extensions-page (b89c2b)
by
unknown
506:56 queued 485:08
created

EED_Event_Single::event_details()   C

Complexity

Conditions 7
Paths 5

Size

Total Lines 30
Code Lines 18

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 30
rs 6.7273
cc 7
eloc 18
nc 5
nop 1
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 Details
17
 *
18
 * @package		Event Espresso
19
 * @subpackage	/modules/event_details/
20
 * @author		Brent Christensen
21
 *
22
 * ------------------------------------------------------------------------
23
 */
24
class EED_Event_Single  extends EED_Module {
25
26
	/**
27
	 * @type bool $using_get_the_excerpt
28
	 */
29
	protected static $using_get_the_excerpt = false;
30
31
32
	/**
33
	 * @type EE_Template_Part_Manager $template_parts
34
	 */
35
	protected $template_parts;
36
37
38
39
	/**
40
	 * @return EED_Event_Single
41
	 */
42
	public static function instance() {
43
		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...
44
	}
45
46
47
48
	/**
49
	 * 	set_hooks - for hooking into EE Core, other modules, etc
50
	 *
51
	 *  @access 	public
52
	 *  @return 	void
53
	 */
54
	public static function set_hooks() {
55
		add_filter( 'FHEE_run_EE_wp', '__return_true' );
56
		add_action( 'wp_loaded', array( 'EED_Event_Single', 'set_definitions' ), 2 );
57
		EE_Config::register_route( __( 'event', 'event_espresso' ), 'Event_Single', 'run' );
58
	}
59
60
	/**
61
	 * 	set_hooks_admin - for hooking into EE Admin Core, other modules, etc
62
	 *
63
	 *  @access 	public
64
	 *  @return 	void
65
	 */
66
	public static function set_hooks_admin() {
67
		add_action( 'wp_loaded', array( 'EED_Event_Single', 'set_definitions' ), 2 );
68
	}
69
70
71
72
73
	/**
74
	 * set_definitions
75
	 *
76
	 * @access public
77
	 * @static
78
	 * @return void
79
	 */
80
	public static function set_definitions() {
81
		define( 'EVENT_SINGLE_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS );
82
		define( 'EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path( __FILE__ ) . 'templates' . DS );
83
	}
84
85
86
87
	/**
88
	 *    set_config
89
	 *
90
	 * @void
91
	 */
92
	protected function set_config(){
93
		$this->set_config_section( 'template_settings' );
94
		$this->set_config_class( 'EE_Event_Single_Config' );
95
		$this->set_config_name( 'EED_Event_Single' );
96
	}
97
98
99
100
101
	/**
102
	 *    initialize_template_parts
103
	 *
104
	 * @access    public
105
	 * @param \EE_Event_Single_Config $config
106
	 * @return \EE_Template_Part_Manager
107
	 */
108 View Code Duplication
	public function initialize_template_parts( EE_Event_Single_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...
109
		$config = $config instanceof EE_Event_Single_Config ? $config : $this->config();
110
		EEH_Autoloader::instance()->register_template_part_autoloaders();
111
		$template_parts = new EE_Template_Part_Manager();
112
		$template_parts->add_template_part(
113
			'tickets',
114
			__( 'Ticket Selector', 'event_espresso' ),
115
			'content-espresso_events-tickets.php',
116
			$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...
117
		);
118
		$template_parts->add_template_part(
119
			'datetimes',
120
			__( 'Dates and Times', 'event_espresso' ),
121
			'content-espresso_events-datetimes.php',
122
			$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...
123
		);
124
		$template_parts->add_template_part(
125
			'event',
126
			__( 'Event Description', 'event_espresso' ),
127
			'content-espresso_events-details.php',
128
			$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...
129
		);
130
		$template_parts->add_template_part(
131
			'venue',
132
			__( 'Venue Information', 'event_espresso' ),
133
			'content-espresso_events-venues.php',
134
			$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...
135
		);
136
		do_action( 'AHEE__EED_Event_Single__initialize_template_parts', $template_parts );
137
		return $template_parts;
138
	}
139
140
141
142
143
	/**
144
	 *    run - initial module setup
145
	 *
146
	 * @access    public
147
	 * @param WP $WP
148
	 * @return    void
149
	 */
150
	public function run( $WP ) {
151
		// ensure valid EE_Events_Single_Config() object exists
152
		$this->set_config();
153
		// check what template is loaded
154
		add_filter( 'template_include',  array( $this, 'template_include' ), 999, 1 );
155
		add_filter( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true' );
156
		// load css
157
		add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 );
158
		EE_Registry::instance()->load_helper( 'Venue_View' );
159
	}
160
161
162
163
	/**
164
	 *    template_include
165
	 *
166
	 * @access 	public
167
	 * @param 	string $template
168
	 * @return 	string
169
	 */
170
	public function template_include( $template ) {
171
		global $post;
172
		/** @type EE_Event_Single_Config $config */
173
		$config = $this->config();
174
		if ( $config->display_status_banner_single ) {
175
			add_filter( 'the_title', array( 'EED_Event_Single', 'the_title' ), 100, 2 );
176
		}
177
		// not a custom template?
178
		if (
179
			EE_Front_Controller::instance()->get_selected_template() != 'single-espresso_events.php'
180
			|| apply_filters( 'FHEE__EED_Event_Single__template_include__allow_custom_selected_template', FALSE )
181
			&& ! post_password_required( $post )
182
		) {
183
			EEH_Template::load_espresso_theme_functions();
184
			// then add extra event data via hooks
185
			add_action( 'loop_start', array( 'EED_Event_Single', 'loop_start' ));
186
			add_filter( 'get_the_excerpt', array( 'EED_Event_Single', 'get_the_excerpt' ), 1, 1 );
187
			add_filter( 'the_content', array( 'EED_Event_Single', 'event_details' ), 100 );
188
			add_action( 'loop_end', array( 'EED_Event_Single', 'loop_end' ));
189
			// don't display entry meta because the existing theme will take car of that
190
			add_filter( 'FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false' );
191
		}
192
		return $template;
193
	}
194
195
196
197
	/**
198
	 * 	loop_start
199
	 *
200
	 * @access 	public
201
	 * @param 	array $wp_query_array an array containing the WP_Query object
202
	 * @return 	void
203
	 */
204
	public static function loop_start( $wp_query_array ) {
205
		global $post;
206
		do_action( 'AHEE_event_details_before_post', $post, $wp_query_array );
207
	}
208
209
210
211
	/**
212
	 *    the_title
213
	 *
214
	 * @access 	public
215
	 * @param 	string $title
216
	 * @param 	int 	$id
217
	 * @return 	string
218
	 */
219
	public static function the_title( $title = '', $id = 0 ) {
220
		global $post;
221
		return in_the_loop() && $post->ID == $id ? espresso_event_status_banner( $post->ID ) . $title :  $title;
222
	}
223
224
225
226
	/**
227
	 *    get_the_excerpt - kinda hacky, but if a theme is using get_the_excerpt(), then we need to remove our filters on the_content()
228
	 *
229
	 * @access    public
230
	 * @param        string $excerpt
231
	 * @return        string
232
	 */
233
	public static function get_the_excerpt( $excerpt = '' ) {
234
		EED_Event_Single::$using_get_the_excerpt = true;
235
		add_filter( 'wp_trim_excerpt', array( 'EED_Event_Single', 'end_get_the_excerpt' ), 999, 1 );
236
		return $excerpt;
237
	}
238
239
240
241
	/**
242
	 * end_get_the_excerpt
243
	 *
244
	 * @access public
245
	 * @param  string $text
246
	 * @return string
247
	 */
248
	public static function end_get_the_excerpt( $text = '' ) {
249
		EED_Event_Single::$using_get_the_excerpt = false;
250
		return $text;
251
	}
252
253
254
255
	/**
256
	 * 	event_details
257
	 *
258
	 * @access 	public
259
	 * @param 	string 	$content
260
	 * @return 	string
261
	 */
262
	public static function event_details( $content ) {
263
		global $post;
264
		static $current_post_ID = 0;
265
		if (
266
			$current_post_ID != $post->ID
267
			&& $post->post_type == 'espresso_events'
268
			&& ! EED_Event_Single::$using_get_the_excerpt
269
			&& ! post_password_required()
270
		) {
271
			// Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
272
			// Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
273
			// BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
274
			// We want to allow those plugins to still do their thing and have access to our content, but depending on
275
			// how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
276
			// so the following allows this filter to be applied multiple times, but only once for real
277
			$current_post_ID = did_action( 'loop_start' ) ? $post->ID : 0;
278
			if ( EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order ) {
279
				// we need to first remove this callback from being applied to the_content()
280
				// (otherwise it will recurse and blow up the interweb)
281
				remove_filter( 'the_content', array( 'EED_Event_Single', 'event_details' ), 100 );
282
				EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts();
283
				$content = EEH_Template::locate_template( 'content-espresso_events-details.php' );
284
				$content = EED_Event_Single::instance()->template_parts->apply_template_part_filters( $content );
285
				add_filter( 'the_content', array( 'EED_Event_Single', 'event_details' ), 100 );
286
			} else {
287
				$content = EED_Event_Single::use_filterable_display_order();
288
			}
289
		}
290
 		return $content;
291
	}
292
293
294
295
	/**
296
	 *    use_filterable_display_order
297
	 *
298
	 * @access    protected
299
	 * @return string
300
	 */
301
	protected static function use_filterable_display_order() {
302
		// since the 'content-espresso_events-details.php' template might be used directly from within a theme,
303
		// it uses the_content() for displaying the $post->post_content
304
		// so in order to load a template that uses the_content() from within a callback being used to filter the_content(),
305
		// we need to first remove this callback from being applied to the_content() (otherwise it will recurse and blow up the interweb)
306
		remove_filter( 'the_content', array( 'EED_Event_Single', 'event_details' ), 100 );
307
		//now add additional content
308
		add_filter( 'the_content', array( 'EED_Event_Single', 'event_datetimes' ), 110, 1 );
309
		add_filter( 'the_content', array( 'EED_Event_Single', 'event_tickets' ), 120, 1 );
310
		add_filter( 'the_content', array( 'EED_Event_Single', 'event_venues' ), 130, 1 );
311
		do_action( 'AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters' );
312
		// now load our template
313
		$content = EEH_Template::locate_template( 'content-espresso_events-details.php' );
314
		//now add our filter back in, plus some others
315
		add_filter( 'the_content', array( 'EED_Event_Single', 'event_details' ), 100 );
316
		remove_filter( 'the_content', array( 'EED_Event_Single', 'event_datetimes' ), 110 );
317
		remove_filter( 'the_content', array( 'EED_Event_Single', 'event_tickets' ), 120 );
318
		remove_filter( 'the_content', array( 'EED_Event_Single', 'event_venues' ), 130 );
319
		// we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
320
		return $content;
321
	}
322
323
324
325
	/**
326
	 *    event_datetimes - adds datetimes ABOVE content
327
	 *
328
	 * @access    public
329
	 * @param        string $content
330
	 * @return        string
331
	 */
332
	public static function event_datetimes( $content ) {
333
		return EEH_Template::locate_template( 'content-espresso_events-datetimes.php' ) . $content;
334
	}
335
336
337
338
	/**
339
	 *    event_tickets - adds tickets ABOVE content (which includes datetimes)
340
	 *
341
	 * @access    public
342
	 * @param        string $content
343
	 * @return        string
344
	 */
345
	public static function event_tickets( $content ) {
346
		return EEH_Template::locate_template( 'content-espresso_events-tickets.php' ) . $content;
347
	}
348
349
350
351
	/**
352
	 *    event_venues
353
	 *
354
	 * @access 	public
355
	 * @param 	string $content
356
	 * @return 	string
357
	 */
358
	public static function event_venue( $content ) {
359
		return EED_Event_Single::event_venues( $content );
360
	}
361
362
363
364
	/**
365
	 *    event_venues - adds venues BELOW content
366
	 *
367
	 * @access    public
368
	 * @param        string $content
369
	 * @return        string
370
	 */
371
	public static function event_venues( $content ) {
372
		return $content . EEH_Template::locate_template( 'content-espresso_events-venues.php' );
373
	}
374
375
376
377
	/**
378
	 * 	loop_end
379
	 *
380
	 *  	@access 	public
381
	 * 	@param		array 	$wp_query_array an array containing the WP_Query object
382
	 *  	@return 		void
383
	 */
384
	public static function loop_end( $wp_query_array ) {
385
		global $post;
386
		do_action( 'AHEE_event_details_after_post', $post, $wp_query_array );
387
	}
388
389
390
391
	/**
392
	 * 	wp_enqueue_scripts
393
	 *
394
	 *  @access 	public
395
	 *  @return 	void
396
	 */
397
	public function wp_enqueue_scripts() {
398
		// get some style
399
		if ( apply_filters( 'FHEE_enable_default_espresso_css', TRUE ) && apply_filters( 'FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', TRUE )) {
400
			EE_Registry::instance()->load_helper( 'File' );
401
			// first check uploads folder
402
			if ( is_readable( get_stylesheet_directory() . $this->theme . DS . 'style.css' )) {
403
				wp_register_style( $this->theme, get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', array( 'dashicons', 'espresso_default' ));
404
			} else {
405
				wp_register_style( $this->theme, EE_TEMPLATES_URL . $this->theme . DS . 'style.css', array( 'dashicons', 'espresso_default' ));
406
			}
407
			wp_enqueue_script( $this->theme );
408
			if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) {
409
				EE_Registry::instance()->load_helper( 'Maps' );
410
				add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 );
411
			}
412
		}
413
	}
414
415
416
417
418
419
420
421
422
	/**
423
	 * 	display_venue
424
	 *
425
	 *  @access 	public
426
	 *  @return 	bool
427
	 */
428
	public static function display_venue() {
429
		EE_Registry::instance()->load_helper( 'Venue_View' );
430
		/** @type EE_Event_Single_Config $config */
431
		$config = EED_Event_Single::instance()->config();
432
		$display_venue= isset( $config->display_venue ) ? $config->display_venue : TRUE;
433
		$venue_name = EEH_Venue_View::venue_name();
434
		return $display_venue && ! empty( $venue_name ) ? TRUE : FALSE;
435
	}
436
437
438
439
}
440
441
442
443
444
445
/**
446
 * espresso_display_venue_in_event_details
447
 *
448
 * @see EED_Event_Single::display_venue()
449
 * @return bool
450
 */
451
function espresso_display_venue_in_event_details() {
452
	return EED_Event_Single::display_venue();
453
}
454
455
456
457
// End of file EED_Event_Single.module.php
458
// Location: /modules/event_details/EED_Event_Single.module.php