Completed
Branch FET-8284-automagic-dependency-... (a299cf)
by
unknown
1189:26 queued 1175:37
created

EE_Admin::get_request()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 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
 * EE_Admin
17
 *
18
 * @package			Event Espresso
19
 * @subpackage	/core/admin/
20
 * @author				Brent Christensen
21
 *
22
 * ------------------------------------------------------------------------
23
 */
24
final class EE_Admin {
25
26
   /**
27
     * 	EE_Admin Object
28
     * 	@private _instance
29
	 * 	@private 	protected
30
     */
31
	private static $_instance = NULL;
32
33
	/**
34
	 * 	EE_Registry Object
35
	 *	@var 	EE_Registry	$EE
36
	 * 	@access 	protected
37
	 */
38
	protected $EE = NULL;
39
40
41
42
43
	/**
44
	 *@ singleton method used to instantiate class object
45
	 *@ access public
46
	 *@ return class instance
47
	 */
48
	public static function instance() {
49
		// check if class object is instantiated
50
		if (  ! self::$_instance instanceof EE_Admin ) {
51
			self::$_instance = new self();
52
		}
53
		return self::$_instance;
54
	}
55
56
57
58
   /**
59
     * class constructor
60
     */
61
	protected function __construct() {
62
		// define global EE_Admin constants
63
		$this->_define_all_constants();
64
		// set autoloaders for our admin page classes based on included path information
65
		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder( EE_ADMIN );
66
		// admin hooks
67
		add_filter( 'plugin_action_links', array( $this, 'filter_plugin_actions' ), 10, 2 );
68
		// load EE_Request_Handler early
69
		add_action( 'AHEE__EE_System__core_loaded_and_ready', array( $this, 'get_request' ));
70
		add_action( 'AHEE__EE_System__initialize_last', array( $this, 'init' ));
71
		add_action( 'AHEE__EE_Admin_Page__route_admin_request', array( $this, 'route_admin_request' ), 100, 2 );
72
		add_action( 'wp_loaded', array( $this, 'wp_loaded' ), 100 );
73
		add_action( 'admin_init', array( $this, 'admin_init' ), 100 );
74
		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ), 20 );
75
		add_action( 'admin_notices', array( $this, 'display_admin_notices' ), 10 );
76
		add_action( 'network_admin_notices', array( $this, 'display_admin_notices' ), 10 );
77
		add_filter( 'pre_update_option', array( $this, 'check_for_invalid_datetime_formats' ), 100, 2 );
78
		add_filter('admin_footer_text', array( $this, 'espresso_admin_footer' ));
79
80
		//reset Environment config (we only do this on admin page loads);
81
		EE_Registry::instance()->CFG->environment->recheck_values();
82
83
		do_action( 'AHEE__EE_Admin__loaded' );
84
	}
85
86
87
88
89
90
	/**
91
	 * _define_all_constants
92
	 * define constants that are set globally for all admin pages
93
	 *
94
	 * @access private
95
	 * @return void
96
	 */
97
	private function _define_all_constants() {
98
		define( 'EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/' );
99
		define( 'EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/' );
100
		define( 'EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS );
101
		define( 'WP_ADMIN_PATH', ABSPATH . 'wp-admin/' );
102
		define( 'WP_AJAX_URL', admin_url( 'admin-ajax.php' ));
103
	}
104
105
106
107
	/**
108
	 *    filter_plugin_actions - adds links to the Plugins page listing
109
	 *
110
	 * @access 	public
111
	 * @param 	array 	$links
112
	 * @param 	string 	$plugin
113
	 * @return 	array
114
	 */
115
	public function filter_plugin_actions( $links, $plugin ) {
116
		// set $main_file in stone
117
		static $main_file;
118
		// if $main_file is not set yet
119
		if ( ! $main_file ) {
120
			$main_file = plugin_basename( EVENT_ESPRESSO_MAIN_FILE );
121
		}
122
		 if ( $plugin == $main_file ) {
123
		 	// compare current plugin to this one
124
			if ( EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance ) {
125
				$maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings" title="Event Espresso is in maintenance mode.  Click this link to learn why.">' . __('Maintenance Mode Active', 'event_espresso' ) . '</a>';
126
				array_unshift( $links, $maintenance_link );
127
			} else {
128
				$org_settings_link = '<a href="admin.php?page=espresso_general_settings">' . __( 'Settings', 'event_espresso' ) . '</a>';
129
				$events_link = '<a href="admin.php?page=espresso_events">' . __( 'Events', 'event_espresso' ) . '</a>';
130
				// add before other links
131
				array_unshift( $links, $org_settings_link, $events_link );
132
			}
133
		}
134
		return $links;
135
	}
136
137
138
139
	/**
140
	 *	_get_request
141
	 *
142
	 *	@access public
143
	 *	@return void
144
	 */
145
	public function get_request() {
146
		EE_Registry::instance()->load_core( 'Request_Handler' );
147
		EE_Registry::instance()->load_core( 'CPT_Strategy' );
148
	}
149
150
151
152
	/**
153
	 *    hide_admin_pages_except_maintenance_mode
154
	 *
155
	 * @access public
156
	 * @param array $admin_page_folder_names
157
	 * @return array
158
	 */
159
	public function hide_admin_pages_except_maintenance_mode( $admin_page_folder_names = array() ){
0 ignored issues
show
Unused Code introduced by
The parameter $admin_page_folder_names is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
160
		return array(
161
			'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
162
			'about' => EE_ADMIN_PAGES . 'about' . DS,
163
			'support' => EE_ADMIN_PAGES . 'support' . DS
164
		);
165
	}
166
167
168
169
	/**
170
	* init- should fire after shortcode, module,  addon, other plugin (default priority), and even EE_Front_Controller's init phases have run
171
	*
172
	* @access public
173
	* @return void
174
	*/
175
	public function init() {
176
177
		//only enable most of the EE_Admin IF we're not in full maintenance mode
178
		if ( EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance ){
179
			//ok so we want to enable the entire admin
180
			add_action( 'wp_ajax_dismiss_ee_nag_notice', array( $this, 'dismiss_ee_nag_notice_callback' ));
181
			add_action( 'save_post', array( 'EE_Admin', 'parse_post_content_on_save' ), 100, 2 );
182
			add_action( 'update_option', array( $this, 'reset_page_for_posts_on_change' ), 100, 3 );
183
			add_filter( 'content_save_pre', array( $this, 'its_eSpresso' ), 10, 1 );
184
			add_action( 'admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 );
185
			add_action( 'network_admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 );
186
			//at a glance dashboard widget
187
			add_filter( 'dashboard_glance_items', array( $this, 'dashboard_glance_items'), 10 );
188
			//filter for get_edit_post_link used on comments for custom post types
189
			add_filter('get_edit_post_link', array( $this, 'modify_edit_post_link' ), 10, 3 );
190
		}
191
192
		// run the admin page factory but ONLY if we are doing an ee admin ajax request
193
		if ( !defined('DOING_AJAX') || EE_ADMIN_AJAX ) {
194
			try {
195
				//this loads the controller for the admin pages which will setup routing etc
196
				EE_Registry::instance()->load_core( 'Admin_Page_Loader' );
197
			} catch ( EE_Error $e ) {
198
				$e->get_error();
199
			}
200
		}
201
202
		//make sure our CPTs and custom taxonomy metaboxes get shown for first time users
203
		add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes' ), 10 );
204
		add_action('admin_head', array( $this, 'register_custom_nav_menu_boxes' ), 10 );
205
206
		//exclude EE critical pages from all nav menus and wp_list_pages
207
		add_filter('nav_menu_meta_box_object', array( $this, 'remove_pages_from_nav_menu'), 10 );
208
	}
209
210
211
212
213
	/**
214
	 * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from the list of options.
215
	 *
216
	 * the wp function "wp_nav_menu_item_post_type_meta_box" found in wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that to override any queries found in the existing query for the given post type.  Note that _default_query is not a normal property on the post_type object.  It's found ONLY in this particular context.
217
	 * @param  object $post_type WP post type object
218
	 * @return object            WP post type object
219
	 */
220
	public function remove_pages_from_nav_menu( $post_type ) {
221
		//if this isn't the "pages" post type let's get out
222
		if ( $post_type->name !== 'page' )
223
			return $post_type;
224
225
		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
226
227
		$post_type->_default_query = array(
228
			'post__not_in' => $critical_pages );
229
		return $post_type;
230
	}
231
232
233
234
	/**
235
	 * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our metaboxes get shown as well
236
	 *
237
	 * @access public
238
	 * @return void
239
	 */
240
	public function enable_hidden_ee_nav_menu_metaboxes() {
241
		global $wp_meta_boxes, $pagenow;
242
		if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php' ) {
243
			return;
244
		}
245
		$user = wp_get_current_user();
246
		//has this been done yet?
247
		if ( get_user_option( 'ee_nav_menu_initialized', $user->ID ) ) {
248
			return;
249
		}
250
251
		$hidden_meta_boxes = get_user_option( 'metaboxhidden_nav-menus', $user->ID );
252
		$initial_meta_boxes = apply_filters( 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', array( 'nav-menu-theme-locations', 'add-page', 'add-custom-links', 'add-category', 'add-espresso_events', 'add-espresso_venues', 'add-espresso_event_categories', 'add-espresso_venue_categories', 'add-post-type-post', 'add-post-type-page' ) );
253
254
		if ( is_array( $hidden_meta_boxes ) ) {
255
			foreach ( $hidden_meta_boxes as $key => $meta_box_id ) {
256
				if ( in_array( $meta_box_id, $initial_meta_boxes ) ) {
257
					unset( $hidden_meta_boxes[ $key ] );
258
				}
259
			}
260
		}
261
262
		update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true );
263
		update_user_option( $user->ID, 'ee_nav_menu_initialized', 1, true );
264
	}
265
266
267
268
269
270
271
	/**
272
	 * This method simply registers custom nav menu boxes for "nav_menus.php route"
273
	 *
274
	 * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
275
	 *
276
	 * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by addons etc.
277
	 *
278
	 * @access public
279
	 * @return void
280
	 */
281
	public function register_custom_nav_menu_boxes() {
282
		add_meta_box( 'add-extra-nav-menu-pages', __('Event Espresso Pages', 'event_espresso'), array( $this, 'ee_cpt_archive_pages' ), 'nav-menus', 'side', 'core' );
283
	}
284
285
286
287
288
	/**
289
	 * Use this to edit the post link for our cpts so that the edit link points to the correct page.
290
	 *
291
	 * @since   4.3.0
292
	 *
293
	 * @param string $link    the original link generated by wp
294
	 * @param int      $id      post id
295
	 * @param string $context optional, defaults to display. How to write the '&'
296
	 *
297
	 * @return string  the (maybe) modified link
298
	 */
299
	public function modify_edit_post_link( $link, $id, $context ) {
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
300
		if ( ! $post = get_post( $id ) )
301
			return $link;
302
303
		if ( $post->post_type == 'espresso_attendees' ) {
304
			$query_args = array(
305
				'action' => 'edit_attendee',
306
				'post' => $id
307
				);
308
			EE_Registry::instance()->load_helper('URL');
309
			return EEH_URL::add_query_args_and_nonce( $query_args, admin_url('admin.php?page=espresso_registrations') );
310
		}
311
		return $link;
312
	}
313
314
315
316
317
	public function ee_cpt_archive_pages() {
318
		global $nav_menu_selected_id;
319
320
		$db_fields = false;
321
		$walker = new Walker_Nav_Menu_Checklist( $db_fields );
322
		$current_tab = 'event-archives';
323
324
		/*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) {
325
			$current_tab = 'search';
326
		}/**/
327
328
		$removed_args = array(
329
			'action',
330
			'customlink-tab',
331
			'edit-menu-item',
332
			'menu-item',
333
			'page-tab',
334
			'_wpnonce',
335
		);
336
337
		?>
338
		<div id="posttype-extra-nav-menu-pages" class="posttypediv">
339
			<ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs">
340
				<li <?php echo ( 'event-archives' == $current_tab ? ' class="tabs"' : '' ); ?>>
341
					<a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg('extra-nav-menu-pages-tab', 'event-archives', remove_query_arg($removed_args))); ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
342
						<?php _e( 'Event Archive Pages', 'event_espresso' ); ?>
343
					</a>
344
				</li>
345
			<?php /* // temporarily removing but leaving skeleton in place in case we ever decide to add more tabs.
346
				<li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>>
347
					<a class="nav-tab-link" data-type="<?php echo esc_attr( $post_type_name ); ?>-all" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'all', remove_query_arg($removed_args))); ?>#<?php echo $post_type_name; ?>-all">
348
						<?php _e( 'View All' ); ?>
349
					</a>
350
				</li>
351
				<li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>>
352
					<a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-search" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg('extra-nav-menu-pages-tab', 'search', remove_query_arg($removed_args))); ?>#tabs-panel-posttype-extra-nav-menu-pages-search">
353
						<?php _e( 'Search'); ?>
354
					</a>
355
				</li> -->
356
			</ul><!-- .posttype-tabs -->
357
 			<?php */ ?>
358
359
			<div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php
360
			echo ( 'event-archives' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
361
			?>">
362
				<ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear">
363
					<?php
364
					$pages = $this->_get_extra_nav_menu_pages_items();
365
					$args['walker'] = $walker;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $args = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
366
					echo walk_nav_menu_tree( array_map( array( $this, '_setup_extra_nav_menu_pages_items' ), $pages), 0, (object) $args );
367
					?>
368
				</ul>
369
			</div><!-- /.tabs-panel -->
370
371
			<p class="button-controls">
372
				<span class="list-controls">
373
					<a href="<?php
374
						echo esc_url( add_query_arg(
375
							array(
376
								'extra-nav-menu-pages-tab' => 'event-archives',
377
								'selectall' => 1,
378
							),
379
							remove_query_arg( $removed_args )
380
						));
381
					?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a>
382
				</span>
383
384
				<span class="add-to-menu">
385
					<input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( __( 'Add to Menu' ) ); ?>" name="add-post-type-menu-item" id="<?php esc_attr_e( 'submit-posttype-extra-nav-menu-pages' ); ?>" />
386
					<span class="spinner"></span>
387
				</span>
388
			</p>
389
390
		</div><!-- /.posttypediv -->
391
392
		<?php
393
	}
394
395
396
397
	/**
398
	 * Returns an array of event archive nav items.
399
	 *
400
	 * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever method we use for getting the extra nav menu items
401
	 * @return array
402
	 */
403 View Code Duplication
	private function _get_extra_nav_menu_pages_items() {
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...
404
		$menuitems[] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$menuitems was never initialized. Although not strictly required by PHP, it is generally a good practice to add $menuitems = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
405
			'title' => __('Event List', 'event_espresso'),
406
			'url' => get_post_type_archive_link( 'espresso_events' ),
407
			'description' => __('Archive page for all events.', 'event_espresso')
408
		);
409
		return apply_filters( 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems );
410
	}
411
412
413
414
	/**
415
	 * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with the properites and converts it to the menu item object.
416
	 *
417
	 * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
418
	 * @param $menuitem
419
	 * @return stdClass
420
	 */
421
	private function _setup_extra_nav_menu_pages_items( $menuitem ) {
422
		$menu_item = new stdClass();
423
		$keys = array(
424
			'ID' => 0,
425
			'db_id' => 0,
426
			'menu_item_parent' => 0,
427
			'object_id' => -1,
428
			'post_parent' => 0,
429
			'type' => 'custom',
430
			'object' => '',
431
			'type_label' => __('Extra Nav Menu Item', 'event_espresso'),
432
			'title' => '',
433
			'url' => '',
434
			'target' => '',
435
			'attr_title' => '',
436
			'description' => '',
437
			'classes' => array(),
438
			'xfn' => ''
439
			);
440
441
		foreach ( $keys as $key => $value) {
442
			$menu_item->$key = isset($menuitem[$key]) ? $menuitem[$key] : $value;
443
		}
444
		return $menu_item;
445
	}
446
447
448
	/**
449
	 * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an EE_Admin_Page route is called.
450
	 *
451
	 * @return void
452
	 */
453
	public function route_admin_request() {}
454
455
456
457
	/**
458
	 * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
459
	 * @return void
460
	 */
461
	public function wp_loaded() {}
462
463
464
465
466
	/**
467
	* admin_init
468
	*
469
	* @access public
470
	* @return void
471
	*/
472
	public function admin_init() {
473
474
		/**
475
		 * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
476
		 * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
477
		 * - check if doing post processing.
478
		 * - check if doing post processing of one of EE CPTs
479
		 * - instantiate the corresponding EE CPT model for the post_type being processed.
480
		 */
481
		if ( isset( $_POST['action'] ) && $_POST['action'] == 'editpost' ) {
482
			if ( isset( $_POST['post_type'] ) ) {
483
				EE_Registry::instance()->load_core( 'Register_CPTs' );
484
				EE_Register_CPTs::instantiate_cpt_models( $_POST['post_type'] );
485
			}
486
		}
487
488
489
		/**
490
		 * This code is for removing any set EE critical pages from the "Static Page" option dropdowns on the
491
		 * 'options-reading.php' core WordPress admin settings page.  This is for user-proofing.
492
		 */
493
		global $pagenow;
494
		if ( $pagenow == 'options-reading.php' ) {
495
			add_filter( 'wp_dropdown_pages', array( $this, 'modify_dropdown_pages' ) );
496
		}
497
498
	}
499
500
501
	/**
502
	 * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
503
	 *
504
	 * @param string $output  Current output.
505
	 * @return string
506
	 */
507
	public function modify_dropdown_pages( $output ) {
508
		//get critical pages
509
		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
510
511
		//split current output by line break for easier parsing.
512
		$split_output = explode( "\n", $output );
513
514
		//loop through to remove any critical pages from the array.
515
		foreach ( $critical_pages as $page_id ) {
516
			$needle = 'value="' . $page_id . '"';
517
			foreach( $split_output as $key => $haystack ) {
518
				if( strpos( $haystack, $needle ) !== false ) {
519
					unset( $split_output[$key] );
520
				}
521
			}
522
		}
523
524
		//replace output with the new contents
525
		$output = implode( "\n", $split_output );
526
527
		return $output;
528
	}
529
530
531
532
	/**
533
	 * enqueue all admin scripts that need loaded for admin pages
534
	 *
535
	 * @access public
536
	 * @return void
537
	 */
538
	public function enqueue_admin_scripts() {
539
		// this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
540
		// Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script calls.
541
		wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE);
542
		// register cookie script for future dependencies
543
		wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', array('jquery'), '2.1', TRUE );
544
		// jquery_validate loading is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again via:  add_filter( 'FHEE_load_jquery_validate', '__return_true' );
545 View Code Duplication
		if ( apply_filters( 'FHEE_load_jquery_validate', FALSE ) ) {
546
			// register jQuery Validate
547
			wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', array('jquery'), '1.11.1', TRUE);
548
		}
549
		//joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again vai: add_filter('FHEE_load_joyride', '__return_true' );
550
		if ( apply_filters( 'FHEE_load_joyride', FALSE ) ) {
551
			//joyride style
552
			wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
553
			wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', array('joyride-css'), EVENT_ESPRESSO_VERSION );
554
			wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', array(), '2.1', TRUE );
555
			//joyride JS
556
			wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', array('jquery-cookie', 'joyride-modernizr'), '2.1', TRUE );
557
			// wanna go for a joyride?
558
			wp_enqueue_style('ee-joyride-css');
559
			wp_enqueue_script('jquery-joyride');
560
		}
561
		//qtip is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again via: add_filter('FHEE_load_qtips', '__return_true' );
562
		if ( apply_filters( 'FHEE_load_qtip', FALSE ) ) {
563
			EE_Registry::instance()->load_helper('Qtip_Loader');
564
			EEH_Qtip_Loader::instance()->register_and_enqueue();
565
		}
566
		//accounting.js library
567
		// @link http://josscrowcroft.github.io/accounting.js/
568
		if ( apply_filters( 'FHEE_load_accounting_js', FALSE ) ) {
569
			wp_register_script( 'ee-accounting', EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, TRUE );
570
			wp_register_script( 'ee-accounting-core', EE_THIRD_PARTY_URL . 'accounting/accounting.js', array('underscore'), '0.3.2', TRUE );
571
			wp_enqueue_script( 'ee-accounting' );
572
			// array of settings to get converted to JSON array via wp_localize_script
573
			$currency_config = array(
574
				'currency' => array(
575
					'symbol' => EE_Registry::instance()->CFG->currency->sign,
576
					'format' => array(
577
						'pos' => EE_Registry::instance()->CFG->currency->sign_b4 ? '%s%v' : '%v%s',
578
						'neg' => EE_Registry::instance()->CFG->currency->sign_b4 ? '- %s%v' : '- %v%s',
579
						'zero' => EE_Registry::instance()->CFG->currency->sign_b4 ? '%s--' : '--%s'
580
						 ),
581
					'decimal' => EE_Registry::instance()->CFG->currency->dec_mrk,
582
					'thousand' => EE_Registry::instance()->CFG->currency->thsnds,
583
					'precision' => EE_Registry::instance()->CFG->currency->dec_plc
584
					),
585
				'number' => array(
586
					'precision' => EE_Registry::instance()->CFG->currency->dec_plc,
587
					'thousand' => EE_Registry::instance()->CFG->currency->thsnds,
588
					'decimal' => EE_Registry::instance()->CFG->currency->dec_mrk
589
					)
590
				);
591
			wp_localize_script('ee-accounting', 'EE_ACCOUNTING_CFG', $currency_config);
592
		}
593
	}
594
595
596
597
	/**
598
	 * 	display_admin_notices
599
	 *
600
	 *  @access 	public
601
	 *  @return 	string
602
	 */
603
	public function display_admin_notices() {
604
		echo EE_Error::get_notices();
605
	}
606
607
608
609
	/**
610
	 * 	get_persistent_admin_notices
611
	 *
612
	 *  	@access 	public
613
	 *  	@return 		void
614
	 */
615
	public function get_persistent_admin_notices() {
616
		// http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30
617
		$args = array(
618
			'page' => EE_Registry::instance()->REQ->is_set( 'page' ) ? EE_Registry::instance()->REQ->get( 'page' ) : '',
619
			'action' => EE_Registry::instance()->REQ->is_set( 'action' ) ? EE_Registry::instance()->REQ->get( 'action' ) : '',
620
		);
621
		$return_url = EE_Admin_Page::add_query_args_and_nonce( $args, EE_ADMIN_URL );
622
		echo EE_Error::get_persistent_admin_notices( $return_url );
623
	}
624
625
626
627
	/**
628
	* 	dismiss_persistent_admin_notice
629
	*
630
	*	@access 	public
631
	* 	@return 		void
632
	*/
633
	public function dismiss_ee_nag_notice_callback() {
634
		EE_Error::dismiss_persistent_admin_notice();
635
	}
636
637
638
639
	/**
640
	 * @param $elements
641
	 * @return array
642
	 */
643
	public function dashboard_glance_items( $elements ) {
644
		$events = EEM_Event::instance()->count();
645
		$items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_events'), admin_url('admin.php') );
0 ignored issues
show
Coding Style Comprehensibility introduced by
$items was never initialized. Although not strictly required by PHP, it is generally a good practice to add $items = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
646
		$items['events']['text'] = sprintf( _n( '%s Event', '%s Events', $events ), number_format_i18n( $events ) );
647
		$items['events']['title'] = __('Click to view all Events', 'event_espresso');
648
		$registrations = EEM_Registration::instance()->count(
649
			array(
650
				array(
651
					'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete )
652
				)
653
			)
654
		);
655
		$items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_registrations' ), admin_url('admin.php') );
656
		$items['registrations']['text'] = sprintf( _n( '%s Registration', '%s Registrations', $registrations ), number_format_i18n($registrations) );
657
		$items['registrations']['title'] = __('Click to view all registrations', 'event_espresso');
658
659
		$items = apply_filters( 'FHEE__EE_Admin__dashboard_glance_items__items', $items );
660
661
		foreach ( $items as $type => $item_properties ) {
662
			$elements[] = sprintf( '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', $item_properties['url'], $item_properties['title'], $item_properties['text'] );
663
		}
664
		return $elements;
665
	}
666
667
668
669
	/**
670
	 *    parse_post_content_on_save
671
	 *
672
	 *    any time a post is saved, we need to check for any EE shortcodes that may be embedded in the content,
673
	 *    and then track what posts those shortcodes are on, so that we can initialize shortcodes well before the_content() runs.
674
	 *    this allows us to do things like enqueue scripts for shortcodes ONLY on the pages the shortcodes are actually used on
675
	 *
676
	 * @access    public
677
	 * @param $post_ID
678
	 * @param $post
679
	 * @return    void
680
	 */
681
	public static function parse_post_content_on_save( $post_ID, $post ) {
682
		// default post types
683
		$post_types = array( 'post' => 0, 'page' => 1 );
684
		// add CPTs
685
		$CPTs = EE_Register_CPTs::get_CPTs();
686
		$post_types = array_merge( $post_types, $CPTs );
687
		// for default or CPT posts...
688
		if ( isset( $post_types[ $post->post_type ] )) {
689
			// post on frontpage ?
690
			$page_for_posts = EE_Config::get_page_for_posts();
691
			$maybe_remove_from_posts = array();
692
			// critical page shortcodes that we do NOT want added to the Posts page (blog)
693
			$critical_shortcodes = EE_Registry::instance()->CFG->core->get_critical_pages_shortcodes_array();
694
			// array of shortcodes indexed by post name
695
			EE_Registry::instance()->CFG->core->post_shortcodes = isset( EE_Registry::instance()->CFG->core->post_shortcodes ) ? EE_Registry::instance()->CFG->core->post_shortcodes : array();
696
			// whether to proceed with update, if an entry already exists for this post, then we want to update
697
			$update_post_shortcodes = isset( EE_Registry::instance()->CFG->core->post_shortcodes[ $post->post_name ] ) ? true : false;
698
			// empty both arrays
699
			EE_Registry::instance()->CFG->core->post_shortcodes[ $post->post_name ] = array();
700
			// check that posts page is already being tracked
701
			if ( ! isset( EE_Registry::instance()->CFG->core->post_shortcodes[ $page_for_posts ] ) ) {
702
				// if not, then ensure that it is properly added
703
				EE_Registry::instance()->CFG->core->post_shortcodes[ $page_for_posts ] = array();
704
			}
705
			// loop thru shortcodes
706
			foreach ( EE_Registry::instance()->shortcodes as $EES_Shortcode => $shortcode_dir ) {
707
				// convert to UPPERCASE to get actual shortcode
708
				$EES_Shortcode = strtoupper( $EES_Shortcode );
709
				// is the shortcode in the post_content ?
710
				if ( strpos( $post->post_content, $EES_Shortcode ) !== FALSE ) {
711
					// map shortcode to post names and post IDs
712
					EE_Registry::instance()->CFG->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] = $post_ID;
713
					// if the shortcode is NOT one of the critical page shortcodes like ESPRESSO_TXN_PAGE
714
					if ( ! in_array( $EES_Shortcode, $critical_shortcodes )) {
715
						// add shortcode to "Posts page" tracking
716
						EE_Registry::instance()->CFG->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = $post_ID;
717
					}
718
					$update_post_shortcodes = TRUE;
719
					unset( $maybe_remove_from_posts[ $EES_Shortcode ] );
720
				} else {
721
					$maybe_remove_from_posts[ $EES_Shortcode ] = $post_ID;
722
				}
723
			}
724
			if ( $update_post_shortcodes ) {
725
				// remove shortcodes from $maybe_remove_from_posts that are still being used
726
				foreach ( EE_Registry::instance()->CFG->core->post_shortcodes as $post_name => $shortcodes ) {
727
					if ( $post_name == $page_for_posts ) {
728
						continue;
729
					}
730
					// compute difference between active post_shortcodes array and $maybe_remove_from_posts array
731
					$maybe_remove_from_posts = array_diff_key( $maybe_remove_from_posts, $shortcodes );
732
				}
733
				// now unset unused shortcodes from the $page_for_posts post_shortcodes
734
				foreach ( $maybe_remove_from_posts as $shortcode => $post_ID ) {
735
					unset( EE_Registry::instance()->CFG->core->post_shortcodes[ $page_for_posts ][ $shortcode ] );
736
				}
737
				EE_Registry::instance()->CFG->update_post_shortcodes( $page_for_posts );
738
			}
739
		}
740
	}
741
742
743
744
	/**
745
	 *    check_for_invalid_datetime_formats
746
	 *
747
	 *    if an admin changes their date or time format settings on the WP General Settings admin page, verify that their selected format can be parsed by PHP
748
	 *
749
	 * @access    public
750
	 * @param    $value
751
	 * @param    $option
752
	 * @throws EE_Error
753
	 * @return    string
754
	 */
755
	public function check_for_invalid_datetime_formats( $value, $option ) {
756
		EE_Registry::instance()->load_helper( 'DTT_Helper' );
757
		// check for date_format or time_format
758
		switch ( $option ) {
759
			case 'date_format' :
760
				$date_time_format = $value . ' ' . get_option('time_format');
761
				break;
762
			case 'time_format' :
763
				$date_time_format = get_option('date_format') . ' ' . $value;
764
				break;
765
			default :
766
				$date_time_format = FALSE;
767
		}
768
		// do we have a date_time format to check ?
769
		if ( $date_time_format ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $date_time_format of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
770
			$error_msg = EEH_DTT_Helper::validate_format_string( $date_time_format );
771
772
			if ( is_array( $error_msg ) ) {
773
				$msg = '<p>' . sprintf( __( 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', 'event_espresso' ), date( $date_time_format ) , $date_time_format  ) . '</p><p><ul>';
774
775
776
				foreach ( $error_msg as $error ) {
777
					$msg .= '<li>' . $error . '</li>';
778
				}
779
780
				$msg .= '</ul></p><p>' . sprintf( __( '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', 'event_espresso' ), '<span style="color:#D54E21;">', '</span>' ) . '</p>';
781
782
				// trigger WP settings error
783
				add_settings_error(
784
					'date_format',
785
					'date_format',
786
					$msg
787
				);
788
789
				// set format to something valid
790
				switch ( $option ) {
791
					case 'date_format' :
792
						$value = 'F j, Y';
793
						break;
794
					case 'time_format' :
795
						$value = 'g:i a';
796
						break;
797
				}
798
			}
799
		}
800
		return $value;
801
	}
802
803
804
805
	/**
806
	 *    reset_page_for_posts_on_change
807
	 *
808
	 * 	if an admin is on the WP Reading Settings page and changes the option for "Posts page", then we need to attribute any shortcodes for the previous blog page to the new blog page
809
	 *
810
	 * @access 	public
811
	 * @param 	$option
812
	 * @param 	$old_value
813
	 * @param 	$value
814
	 * @return 	void
815
	 */
816
	public function reset_page_for_posts_on_change( $option, $old_value, $value ) {
817
		if ( $option == 'page_for_posts' ) {
818
			global $wpdb;
819
			$SQL = 'SELECT post_name from ' . $wpdb->posts . ' WHERE post_type="posts" OR post_type="page" AND post_status="publish" AND ID=%s';
820
			$old_page_for_posts = $old_value ? $wpdb->get_var( $wpdb->prepare( $SQL, $old_value )) : 'posts';
821
			$new_page_for_posts = $value ? $wpdb->get_var( $wpdb->prepare( $SQL, $value )) : 'posts';
822
			EE_Registry::instance()->CFG->core->post_shortcodes[ $new_page_for_posts ] = EE_Registry::instance()->CFG->core->post_shortcodes[ $old_page_for_posts ];
823
			EE_Registry::instance()->CFG->update_post_shortcodes( $new_page_for_posts );
824
		}
825
	}
826
827
828
829
	/**
830
	 *    its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
831
	 *
832
	 * @access    public
833
	 * @param $content
834
	 * @return    string
835
	 */
836
	public function its_eSpresso( $content ) {
837
		return str_replace( '[EXPRESSO_', '[ESPRESSO_', $content );
838
	}
839
840
841
842
	/**
843
	 * 	espresso_admin_footer
844
	 *
845
	 *  @access 	public
846
	 *  @return 	string
847
	 */
848
	public function espresso_admin_footer() {
849
		return sprintf(
850
			__( 'Event Registration and Ticketing Powered by %sEvent Registration Powered by Event Espresso%s', 'event_espresso' ),
851
			'<a href="https://eventespresso.com/" title="',
852
			'">' . EVENT_ESPRESSO_POWERED_BY . '</a>'
853
		);
854
	}
855
856
857
858
	/**
859
	 * static method for registering ee admin page.
860
	 *
861
	 * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
862
	 *
863
	 * @since      4.3.0
864
	 * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
865
	 * @see        EE_Register_Admin_Page::register()
866
	 *
867
	 * @param       $page_basename
868
	 * @param       $page_path
869
	 * @param array $config
870
	 * @return void
871
	 */
872
	public static function register_ee_admin_page( $page_basename, $page_path, $config = array() ) {
873
		EE_Error::doing_it_wrong( __METHOD__, sprintf( __('Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.', 'event_espresso'), $page_basename), '4.3' );
874
		if ( class_exists( 'EE_Register_Admin_Page' ) )
875
			$config['page_path'] = $page_path;
876
			EE_Register_Admin_Page::register( $page_basename, $config );
877
	}
878
879
880
}
881
// End of file EE_Admin.core.php
882
// Location: /core/admin/EE_Admin.core.php
883