Completed
Branch FET-3467-waitlists (bb55f8)
by
unknown
68:09 queued 54:37
created
modules/events_archive_filters/EED_Events_Archive_Filters.module.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -589,9 +589,9 @@
 block discarded – undo
589 589
 	 */
590 590
 	private function _load_assests() {
591 591
 		do_action( 'AHEE__EED_Events_Archive_Filters__before_load_assests' );
592
-        wp_enqueue_style('espresso_default');
593
-        wp_enqueue_style('espresso_custom_css');
594
-        add_filter( 'FHEE_load_EE_Session', '__return_true' );
592
+		wp_enqueue_style('espresso_default');
593
+		wp_enqueue_style('espresso_custom_css');
594
+		add_filter( 'FHEE_load_EE_Session', '__return_true' );
595 595
 		add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 );
596 596
 		if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) {
597 597
 			add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 );
Please login to merge, or discard this patch.
Spacing   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * @return EED_Events_Archive_Filters
30 30
 	 */
31 31
 	public static function instance() {
32
-		return parent::get_instance( __CLASS__ );
32
+		return parent::get_instance(__CLASS__);
33 33
 	}
34 34
 
35 35
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	 *	@var 	$_types
72 72
 	 * 	@access 	protected
73 73
 	 */
74
-	protected static $_types = array( 'grid', 'text', 'dates' );
74
+	protected static $_types = array('grid', 'text', 'dates');
75 75
 
76 76
 
77 77
 //	public static $espresso_event_list_ID = 0;
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 	 *  @access 	public
126 126
 	 *  @return 	void
127 127
 	 */
128
-	public function run( $WP ) {
128
+	public function run($WP) {
129 129
 //		do_action( 'AHEE__EED_Events_Archive_Filters__before_run' );
130 130
 //		// set config
131 131
 //		if ( ! isset( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters ) || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters instanceof EE_Events_Archive_Config ) {
@@ -170,9 +170,9 @@  discard block
 block discarded – undo
170 170
 	 */
171 171
 	private function _filter_query_parts() {
172 172
 		// build event list query
173
-		add_filter( 'posts_join', array( $this, 'posts_join' ), 1, 2 );
174
-		add_filter( 'posts_where', array( $this, 'posts_where' ), 1, 2 );
175
-		add_filter( 'posts_orderby', array( $this, 'posts_orderby' ), 1, 2 );
173
+		add_filter('posts_join', array($this, 'posts_join'), 1, 2);
174
+		add_filter('posts_where', array($this, 'posts_where'), 1, 2);
175
+		add_filter('posts_orderby', array($this, 'posts_orderby'), 1, 2);
176 176
 	}
177 177
 
178 178
 	/**
@@ -182,13 +182,13 @@  discard block
 block discarded – undo
182 182
 	 *  @return 	string
183 183
 	 */
184 184
 	public static function set_type() {
185
-		do_action( 'AHEE__EED_Events_Archive_Filters__before_set_type' );
186
-		EED_Events_Archive_Filters::$_types = apply_filters( 'EED_Events_Archive_Filters__set_type__types', EED_Events_Archive_Filters::$_types );
187
-		$view = isset( EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] ) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] : 'grid';
188
-		$elf_type = EE_Registry::instance()->REQ->is_set( 'elf_type' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_type' )) : '';
189
-		$view = ! empty( $elf_type ) ? $elf_type : $view;
190
-		$view = apply_filters( 'EED_Events_Archive_Filters__set_type__type', $view );
191
-		if ( ! empty( $view ) && in_array( $view, EED_Events_Archive_Filters::$_types )) {
185
+		do_action('AHEE__EED_Events_Archive_Filters__before_set_type');
186
+		EED_Events_Archive_Filters::$_types = apply_filters('EED_Events_Archive_Filters__set_type__types', EED_Events_Archive_Filters::$_types);
187
+		$view = isset(EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type']) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] : 'grid';
188
+		$elf_type = EE_Registry::instance()->REQ->is_set('elf_type') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_type')) : '';
189
+		$view = ! empty($elf_type) ? $elf_type : $view;
190
+		$view = apply_filters('EED_Events_Archive_Filters__set_type__type', $view);
191
+		if ( ! empty($view) && in_array($view, EED_Events_Archive_Filters::$_types)) {
192 192
 			self::$_type = $view;
193 193
 		}
194 194
 	}
@@ -200,11 +200,11 @@  discard block
 block discarded – undo
200 200
 	 *  @param	boolean	$req_only if TRUE, then ignore defaults and only return $_POST value
201 201
 	 *  @return 	boolean
202 202
 	 */
203
-	private static function _show_expired( $req_only = FALSE ) {
203
+	private static function _show_expired($req_only = FALSE) {
204 204
 		// get default value for "display_expired_events" as set in the EE General Settings > Templates > Event Listings
205
-		$show_expired = ! $req_only && isset( EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] ) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] : FALSE;
205
+		$show_expired = ! $req_only && isset(EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events']) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] : FALSE;
206 206
 		// override default expired option if set via filter
207
-		$show_expired = EE_Registry::instance()->REQ->is_set( 'elf_expired_chk' ) ? absint( EE_Registry::instance()->REQ->get( 'elf_expired_chk' )) : $show_expired;
207
+		$show_expired = EE_Registry::instance()->REQ->is_set('elf_expired_chk') ? absint(EE_Registry::instance()->REQ->get('elf_expired_chk')) : $show_expired;
208 208
 		return $show_expired ? TRUE : FALSE;
209 209
 	}
210 210
 
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 	 *  @return 	string
216 216
 	 */
217 217
 	private static function _event_category_slug() {
218
-		return EE_Registry::instance()->REQ->is_set( 'elf_category_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_category_dd' )) : '';
218
+		return EE_Registry::instance()->REQ->is_set('elf_category_dd') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_category_dd')) : '';
219 219
 	}
220 220
 
221 221
 	/**
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 	 *  @return 	string
226 226
 	 */
227 227
 	private static function _display_month() {
228
-		return EE_Registry::instance()->REQ->is_set( 'elf_month_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_month_dd' )) : '';
228
+		return EE_Registry::instance()->REQ->is_set('elf_month_dd') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_month_dd')) : '';
229 229
 	}
230 230
 
231 231
 
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 	public function get_post_data() {
240 240
 		$this->_elf_month = EED_Events_Archive_Filters::_display_month();
241 241
 		$this->_elf_category = EED_Events_Archive_Filters::_event_category_slug();
242
-		$this->_show_expired = EED_Events_Archive_Filters::_show_expired( TRUE );
242
+		$this->_show_expired = EED_Events_Archive_Filters::_show_expired(TRUE);
243 243
 //		EEH_Debug_Tools::printr( EE_Registry::instance()->REQ, 'EE_Registry::instance()->REQ  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
244 244
 //		echo '<h4>$this->_elf_month : ' . $this->_elf_month . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
245 245
 //		echo '<h4>$this->_elf_category : ' . $this->_elf_category . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
@@ -256,11 +256,11 @@  discard block
 block discarded – undo
256 256
 	 *  @access 	public
257 257
 	 *  @return 	void
258 258
 	 */
259
-	public function posts_join( $SQL, WP_Query $wp_query ) {
260
-		if ( isset( $wp_query->query ) && isset( $wp_query->query['post_type'] ) && $wp_query->query['post_type'] == 'espresso_events' ) {
259
+	public function posts_join($SQL, WP_Query $wp_query) {
260
+		if (isset($wp_query->query) && isset($wp_query->query['post_type']) && $wp_query->query['post_type'] == 'espresso_events') {
261 261
 			// Category
262 262
 //			$elf_category = EE_Registry::instance()->REQ->is_set( 'elf_category_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_category_dd' )) : '';
263
-			$SQL .= EED_Events_Archive_Filters::posts_join_sql_for_terms( EED_Events_Archive_Filters::_event_category_slug() );
263
+			$SQL .= EED_Events_Archive_Filters::posts_join_sql_for_terms(EED_Events_Archive_Filters::_event_category_slug());
264 264
 		}
265 265
 		return $SQL;
266 266
 	}
@@ -273,9 +273,9 @@  discard block
 block discarded – undo
273 273
 	 *  @param	mixed boolean|string	$join_terms pass TRUE or term string, doesn't really matter since this value doesn't really get used for anything yet
274 274
 	 *  @return 	string
275 275
 	 */
276
-	public static function posts_join_sql_for_terms( $join_terms = NULL ) {
277
-		$SQL= '';
278
-		if ( ! empty( $join_terms )) {
276
+	public static function posts_join_sql_for_terms($join_terms = NULL) {
277
+		$SQL = '';
278
+		if ( ! empty($join_terms)) {
279 279
 			global $wpdb;
280 280
 			$SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)";
281 281
 			$SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
@@ -293,28 +293,28 @@  discard block
 block discarded – undo
293 293
 	 *  @param	array	$orderby_params
294 294
 	 *  @return 	string
295 295
 	 */
296
-	public static function posts_join_for_orderby( $orderby_params = array() ) {
296
+	public static function posts_join_for_orderby($orderby_params = array()) {
297 297
 		global $wpdb;
298
-		$SQL= '';
299
-		$orderby_params = is_array( $orderby_params ) ? $orderby_params : array( $orderby_params );
300
-		foreach( $orderby_params as $orderby ) {
301
-			switch ( $orderby ) {
298
+		$SQL = '';
299
+		$orderby_params = is_array($orderby_params) ? $orderby_params : array($orderby_params);
300
+		foreach ($orderby_params as $orderby) {
301
+			switch ($orderby) {
302 302
 
303 303
 				case 'ticket_start' :
304 304
 				case 'ticket_end' :
305
-					$SQL .= ' LEFT JOIN ' . EEM_Datetime_Ticket::instance()->table() . ' ON (' . EEM_Datetime::instance()->table() . '.DTT_ID = ' . EEM_Datetime_Ticket::instance()->table() . '.DTT_ID )';
306
-					$SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table() . ' ON (' . EEM_Datetime_Ticket::instance()->table() . '.TKT_ID = ' . EEM_Ticket::instance()->table() . '.TKT_ID )';
305
+					$SQL .= ' LEFT JOIN '.EEM_Datetime_Ticket::instance()->table().' ON ('.EEM_Datetime::instance()->table().'.DTT_ID = '.EEM_Datetime_Ticket::instance()->table().'.DTT_ID )';
306
+					$SQL .= ' LEFT JOIN '.EEM_Ticket::instance()->table().' ON ('.EEM_Datetime_Ticket::instance()->table().'.TKT_ID = '.EEM_Ticket::instance()->table().'.TKT_ID )';
307 307
 					break;
308 308
 
309 309
 				case 'venue_title' :
310 310
 				case 'city' :
311
-					$SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->table() . ' ON (' . $wpdb->posts . '.ID = ' . EEM_Event_Venue::instance()->table() . '.EVT_ID )';
312
-					$SQL .= ' LEFT JOIN ' . EEM_Venue::instance()->table() . ' ON (' . EEM_Event_Venue::instance()->table() . '.VNU_ID = ' . EEM_Venue::instance()->table() . '.VNU_ID )';
311
+					$SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->table().' ON ('.$wpdb->posts.'.ID = '.EEM_Event_Venue::instance()->table().'.EVT_ID )';
312
+					$SQL .= ' LEFT JOIN '.EEM_Venue::instance()->table().' ON ('.EEM_Event_Venue::instance()->table().'.VNU_ID = '.EEM_Venue::instance()->table().'.VNU_ID )';
313 313
 					break;
314 314
 
315 315
 				case 'state' :
316
-					$SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->table() . ' ON (' . $wpdb->posts . '.ID = ' . EEM_Event_Venue::instance()->table() . '.EVT_ID )';
317
-					$SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->second_table() . ' ON (' . EEM_Event_Venue::instance()->table() . '.VNU_ID = ' . EEM_Event_Venue::instance()->second_table() . '.VNU_ID )';
316
+					$SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->table().' ON ('.$wpdb->posts.'.ID = '.EEM_Event_Venue::instance()->table().'.EVT_ID )';
317
+					$SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->second_table().' ON ('.EEM_Event_Venue::instance()->table().'.VNU_ID = '.EEM_Event_Venue::instance()->second_table().'.VNU_ID )';
318 318
 					break;
319 319
 
320 320
 				break;
@@ -331,16 +331,16 @@  discard block
 block discarded – undo
331 331
 	 *  @access 	public
332 332
 	 *  @return 	void
333 333
 	 */
334
-	public function posts_where( $SQL, WP_Query $wp_query ) {
335
-		if ( isset( $wp_query->query_vars ) && isset( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'espresso_events'  ) {
334
+	public function posts_where($SQL, WP_Query $wp_query) {
335
+		if (isset($wp_query->query_vars) && isset($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'espresso_events') {
336 336
 			// Show Expired ?
337
-			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_show_expired( EED_Events_Archive_Filters::_show_expired() );
337
+			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_show_expired(EED_Events_Archive_Filters::_show_expired());
338 338
 			// Category
339 339
 			//$elf_category = EED_Events_Archive_Filters::_event_category_slug();
340
-			$SQL .=  EED_Events_Archive_Filters::posts_where_sql_for_event_category_slug( EED_Events_Archive_Filters::_event_category_slug() );
340
+			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_category_slug(EED_Events_Archive_Filters::_event_category_slug());
341 341
 			// Start Date
342 342
 			//$elf_month = EED_Events_Archive_Filters::_display_month();
343
-			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_list_month( EED_Events_Archive_Filters::_display_month() );
343
+			$SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_list_month(EED_Events_Archive_Filters::_display_month());
344 344
 		}
345 345
 		return $SQL;
346 346
 	}
@@ -353,8 +353,8 @@  discard block
 block discarded – undo
353 353
 	 *  @param	boolean	$show_expired if TRUE, then displayed past events
354 354
 	 *  @return 	string
355 355
 	 */
356
-	public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) {
357
-		return  ! $show_expired ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > "' . date('Y-m-d H:s:i') . '" ' : '';
356
+	public static function posts_where_sql_for_show_expired($show_expired = FALSE) {
357
+		return  ! $show_expired ? ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end > "'.date('Y-m-d H:s:i').'" ' : '';
358 358
 	}
359 359
 
360 360
 
@@ -365,9 +365,9 @@  discard block
 block discarded – undo
365 365
 	 *  @param	boolean	$event_category_slug
366 366
 	 *  @return 	string
367 367
 	 */
368
-	public static function posts_where_sql_for_event_category_slug( $event_category_slug = NULL ) {
368
+	public static function posts_where_sql_for_event_category_slug($event_category_slug = NULL) {
369 369
 		global $wpdb;
370
-		return  ! empty( $event_category_slug ) ? ' AND ' . $wpdb->terms . '.slug = "' . $event_category_slug . '" ' : '';
370
+		return  ! empty($event_category_slug) ? ' AND '.$wpdb->terms.'.slug = "'.$event_category_slug.'" ' : '';
371 371
 	}
372 372
 
373 373
 	/**
@@ -377,15 +377,15 @@  discard block
 block discarded – undo
377 377
 	 *  @param	boolean	$month
378 378
 	 *  @return 	string
379 379
 	 */
380
-	public static function posts_where_sql_for_event_list_month( $month = NULL ) {
381
-		$SQL= '';
382
-		if ( ! empty( $month )) {
380
+	public static function posts_where_sql_for_event_list_month($month = NULL) {
381
+		$SQL = '';
382
+		if ( ! empty($month)) {
383 383
 			// event start date is LESS than the end of the month ( so nothing that doesn't start until next month )
384
-			$SQL = ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start';
385
-			$SQL .= ' <= "' . date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . '"';
384
+			$SQL = ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_start';
385
+			$SQL .= ' <= "'.date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)).'"';
386 386
 			// event end date is GREATER than the start of the month ( so nothing that ended before this month )
387
-			$SQL .= ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end';
388
-			$SQL .= ' >= "' . date('Y-m-d 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . '" ';
387
+			$SQL .= ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end';
388
+			$SQL .= ' >= "'.date('Y-m-d 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)).'" ';
389 389
 		}
390 390
 		return $SQL;
391 391
 	}
@@ -397,9 +397,9 @@  discard block
 block discarded – undo
397 397
 	 *  @access 	public
398 398
 	 *  @return 	void
399 399
 	 */
400
-	public function posts_orderby( $SQL, WP_Query $wp_query ) {
401
-		if ( isset( $wp_query->query ) && isset( $wp_query->query['post_type'] ) && $wp_query->query['post_type'] == 'espresso_events' ) {
402
-			$SQL = EED_Events_Archive_Filters::posts_orderby_sql( array( 'start_date' ));
400
+	public function posts_orderby($SQL, WP_Query $wp_query) {
401
+		if (isset($wp_query->query) && isset($wp_query->query['post_type']) && $wp_query->query['post_type'] == 'espresso_events') {
402
+			$SQL = EED_Events_Archive_Filters::posts_orderby_sql(array('start_date'));
403 403
 		}
404 404
 		return $SQL;
405 405
 	}
@@ -428,54 +428,54 @@  discard block
 block discarded – undo
428 428
 	 *  @param	boolean	$orderby_params
429 429
 	 *  @return 	string
430 430
 	 */
431
-	public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) {
431
+	public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') {
432 432
 		global $wpdb;
433 433
 		$SQL = '';
434 434
 		$cntr = 1;
435
-		$orderby_params = is_array( $orderby_params ) ? $orderby_params : array( $orderby_params );
436
-		foreach( $orderby_params as $orderby ) {
437
-			$glue = $cntr == 1 || $cntr == count( $orderby_params ) ? ' ' : ', ';
438
-			switch ( $orderby ) {
435
+		$orderby_params = is_array($orderby_params) ? $orderby_params : array($orderby_params);
436
+		foreach ($orderby_params as $orderby) {
437
+			$glue = $cntr == 1 || $cntr == count($orderby_params) ? ' ' : ', ';
438
+			switch ($orderby) {
439 439
 
440 440
 				case 'id' :
441 441
 				case 'ID' :
442
-					$SQL .= $glue . $wpdb->posts . '.ID ' . $sort;
442
+					$SQL .= $glue.$wpdb->posts.'.ID '.$sort;
443 443
 					break;
444 444
 
445 445
 				case 'start_date' :
446
-					$SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_start ' . $sort;
446
+					$SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_start '.$sort;
447 447
 					break;
448 448
 
449 449
 				case 'end_date' :
450
-					$SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort;
450
+					$SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_end '.$sort;
451 451
 					break;
452 452
 
453 453
 				case 'event_name' :
454
-					$SQL .= $glue . $wpdb->posts . '.post_title ' . $sort;
454
+					$SQL .= $glue.$wpdb->posts.'.post_title '.$sort;
455 455
 					break;
456 456
 
457 457
 				case 'category_slug' :
458
-					$SQL .= $glue . $wpdb->terms . '.slug ' . $sort;
458
+					$SQL .= $glue.$wpdb->terms.'.slug '.$sort;
459 459
 					break;
460 460
 
461 461
 				case 'ticket_start' :
462
-					$SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort;
462
+					$SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_start_date '.$sort;
463 463
 					break;
464 464
 
465 465
 				case 'ticket_end' :
466
-					$SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort;
466
+					$SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_end_date '.$sort;
467 467
 					break;
468 468
 
469 469
 				case 'venue_title' :
470
-					$SQL .= $glue . 'venue_title ' . $sort;
470
+					$SQL .= $glue.'venue_title '.$sort;
471 471
 					break;
472 472
 
473 473
 				case 'city' :
474
-					$SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort;
474
+					$SQL .= $glue.EEM_Venue::instance()->second_table().'.VNU_city '.$sort;
475 475
 				break;
476 476
 
477 477
 				case 'state' :
478
-					$SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort;
478
+					$SQL .= $glue.EEM_State::instance()->table().'.STA_name '.$sort;
479 479
 				break;
480 480
 
481 481
 			}
@@ -495,26 +495,26 @@  discard block
 block discarded – undo
495 495
 	 */
496 496
 	public function template_redirect() {
497 497
 		// add event list filters
498
-		add_action( 'loop_start', array( $this, 'event_list_template_filters' ));
498
+		add_action('loop_start', array($this, 'event_list_template_filters'));
499 499
 		// and pagination
500
-		add_action( 'loop_start', array( $this, 'event_list_pagination' ));
501
-		add_action( 'loop_end', array( $this, 'event_list_pagination' ));
500
+		add_action('loop_start', array($this, 'event_list_pagination'));
501
+		add_action('loop_end', array($this, 'event_list_pagination'));
502 502
 		// if NOT a custom template
503
-		if ( EE_Registry::instance()->load_core( 'Front_Controller', array(), false, true )->get_selected_template() != 'archive-espresso_events.php' ) {
503
+		if (EE_Registry::instance()->load_core('Front_Controller', array(), false, true)->get_selected_template() != 'archive-espresso_events.php') {
504 504
 			// don't know if theme uses the_excerpt
505
-			add_filter( 'the_excerpt', array( $this, 'event_details' ), 100 );
506
-			add_filter( 'the_excerpt', array( $this, 'event_tickets' ), 110 );
507
-			add_filter( 'the_excerpt', array( $this, 'event_datetimes' ), 120 );
508
-			add_filter( 'the_excerpt', array( $this, 'event_venues' ), 130 );
505
+			add_filter('the_excerpt', array($this, 'event_details'), 100);
506
+			add_filter('the_excerpt', array($this, 'event_tickets'), 110);
507
+			add_filter('the_excerpt', array($this, 'event_datetimes'), 120);
508
+			add_filter('the_excerpt', array($this, 'event_venues'), 130);
509 509
 			// or the_content
510
-			add_filter( 'the_content', array( $this, 'event_details' ), 100 );
511
-			add_filter( 'the_content', array( $this, 'event_tickets' ), 110 );
512
-			add_filter( 'the_content', array( $this, 'event_datetimes' ), 120 );
513
-			add_filter( 'the_content', array( $this, 'event_venues' ), 130 );
510
+			add_filter('the_content', array($this, 'event_details'), 100);
511
+			add_filter('the_content', array($this, 'event_tickets'), 110);
512
+			add_filter('the_content', array($this, 'event_datetimes'), 120);
513
+			add_filter('the_content', array($this, 'event_venues'), 130);
514 514
 		} else {
515
-			remove_all_filters( 'excerpt_length' );
516
-			add_filter( 'excerpt_length', array( $this, 'excerpt_length' ), 10 );
517
-			add_filter( 'excerpt_more', array( $this, 'excerpt_more' ), 10 );
515
+			remove_all_filters('excerpt_length');
516
+			add_filter('excerpt_length', array($this, 'excerpt_length'), 10);
517
+			add_filter('excerpt_more', array($this, 'excerpt_more'), 10);
518 518
 		}
519 519
 	}
520 520
 
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
 	 *  	@return 		void
528 528
 	 */
529 529
 	public function event_list_pagination() {
530
-		echo '<div class="ee-pagination-dv clear">' . espresso_event_list_pagination() . '</div>';
530
+		echo '<div class="ee-pagination-dv clear">'.espresso_event_list_pagination().'</div>';
531 531
 	}
532 532
 
533 533
 
@@ -538,8 +538,8 @@  discard block
 block discarded – undo
538 538
 	 * 	@param		string 	$content
539 539
 	 *  	@return 		void
540 540
 	 */
541
-	public function event_details( $content ) {
542
-		return EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-details.php', array( 'the_content' => $content ), TRUE );
541
+	public function event_details($content) {
542
+		return EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-details.php', array('the_content' => $content), TRUE);
543 543
 	}
544 544
 
545 545
 
@@ -550,8 +550,8 @@  discard block
 block discarded – undo
550 550
 	 * 	@param		string 	$content
551 551
 	 *  	@return 		void
552 552
 	 */
553
-	public function event_tickets( $content ) {
554
-		return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-tickets.php', array(), TRUE );
553
+	public function event_tickets($content) {
554
+		return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-tickets.php', array(), TRUE);
555 555
 	}
556 556
 
557 557
 	/**
@@ -561,8 +561,8 @@  discard block
 block discarded – undo
561 561
 	 * 	@param		string 	$content
562 562
 	 *  	@return 		void
563 563
 	 */
564
-	public function event_datetimes( $content ) {
565
-		return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-datetimes.php', array(), TRUE );
564
+	public function event_datetimes($content) {
565
+		return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-datetimes.php', array(), TRUE);
566 566
 	}
567 567
 
568 568
 	/**
@@ -572,8 +572,8 @@  discard block
 block discarded – undo
572 572
 	 * 	@param		string 	$content
573 573
 	 *  	@return 		void
574 574
 	 */
575
-	public function event_venues( $content ) {
576
-		return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-venues.php', array(), TRUE );
575
+	public function event_venues($content) {
576
+		return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-venues.php', array(), TRUE);
577 577
 	}
578 578
 
579 579
 
@@ -588,13 +588,13 @@  discard block
 block discarded – undo
588 588
 	 *  @return 	void
589 589
 	 */
590 590
 	private function _load_assests() {
591
-		do_action( 'AHEE__EED_Events_Archive_Filters__before_load_assests' );
591
+		do_action('AHEE__EED_Events_Archive_Filters__before_load_assests');
592 592
         wp_enqueue_style('espresso_default');
593 593
         wp_enqueue_style('espresso_custom_css');
594
-        add_filter( 'FHEE_load_EE_Session', '__return_true' );
595
-		add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 );
596
-		if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) {
597
-			add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 );
594
+        add_filter('FHEE_load_EE_Session', '__return_true');
595
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
596
+		if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
597
+			add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
598 598
 		}
599 599
 		//add_filter( 'the_excerpt', array( $this, 'the_excerpt' ), 999 );
600 600
 	}
@@ -609,8 +609,8 @@  discard block
 block discarded – undo
609 609
 	 *  @access 	private
610 610
 	 *  @return 	string
611 611
 	 */
612
-	private function _get_template( $which = 'part' ) {
613
-		return EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php';
612
+	private function _get_template($which = 'part') {
613
+		return EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php';
614 614
 	}
615 615
 
616 616
 
@@ -621,13 +621,13 @@  discard block
 block discarded – undo
621 621
 	 *  @access 	public
622 622
 	 *  @return 	void
623 623
 	 */
624
-	public function excerpt_length( $length ) {
624
+	public function excerpt_length($length) {
625 625
 
626
-		if ( self::$_type == 'grid' ) {
626
+		if (self::$_type == 'grid') {
627 627
 			return 36;
628 628
 		}
629 629
 
630
-		switch ( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size ) {
630
+		switch (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size) {
631 631
 			case 'tiny' :
632 632
 				return 12;
633 633
 				break;
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
 	 *  @access 	public
652 652
 	 *  @return 	void
653 653
 	 */
654
-	public function excerpt_more( $more ) {
654
+	public function excerpt_more($more) {
655 655
 		return '&hellip;';
656 656
 	}
657 657
 
@@ -681,22 +681,22 @@  discard block
 block discarded – undo
681 681
 	 */
682 682
 	public function wp_enqueue_scripts() {
683 683
 		// get some style
684
-		if ( apply_filters( 'FHEE_enable_default_espresso_css', FALSE ) ) {
684
+		if (apply_filters('FHEE_enable_default_espresso_css', FALSE)) {
685 685
 			// first check uploads folder
686
-			if ( is_readable( get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css' )) {
687
-				wp_register_style( 'archive-espresso_events', get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css', array( 'dashicons', 'espresso_default' ));
686
+			if (is_readable(get_stylesheet_directory().EE_Config::get_current_theme().DS.'archive-espresso_events.css')) {
687
+				wp_register_style('archive-espresso_events', get_stylesheet_directory_uri().EE_Config::get_current_theme().DS.'archive-espresso_events.css', array('dashicons', 'espresso_default'));
688 688
 			} else {
689
-				wp_register_style( 'archive-espresso_events', EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css', array( 'dashicons', 'espresso_default' ));
689
+				wp_register_style('archive-espresso_events', EE_TEMPLATES_URL.EE_Config::get_current_theme().DS.'archive-espresso_events.css', array('dashicons', 'espresso_default'));
690 690
 			}
691
-			if ( is_readable( get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.js' )) {
692
-				wp_register_script( 'archive-espresso_events', get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.js', array( 'jquery-masonry' ), '1.0', TRUE  );
691
+			if (is_readable(get_stylesheet_directory().EE_Config::get_current_theme().DS.'archive-espresso_events.js')) {
692
+				wp_register_script('archive-espresso_events', get_stylesheet_directory_uri().EE_Config::get_current_theme().DS.'archive-espresso_events.js', array('jquery-masonry'), '1.0', TRUE);
693 693
 			} else {
694
-				wp_register_script( 'archive-espresso_events', EVENTS_ARCHIVE_ASSETS_URL . 'archive-espresso_events.js', array( 'jquery-masonry' ), '1.0', TRUE );
694
+				wp_register_script('archive-espresso_events', EVENTS_ARCHIVE_ASSETS_URL.'archive-espresso_events.js', array('jquery-masonry'), '1.0', TRUE);
695 695
 			}
696
-			wp_enqueue_style( 'archive-espresso_events' );
697
-			wp_enqueue_script( 'jquery-masonry' );
698
-			wp_enqueue_script( 'archive-espresso_events' );
699
-			add_action( 'wp_footer', array( 'EED_Events_Archive_Filters', 'localize_grid_event_lists' ), 1 );
696
+			wp_enqueue_style('archive-espresso_events');
697
+			wp_enqueue_script('jquery-masonry');
698
+			wp_enqueue_script('archive-espresso_events');
699
+			add_action('wp_footer', array('EED_Events_Archive_Filters', 'localize_grid_event_lists'), 1);
700 700
 		}
701 701
 	}
702 702
 
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 	 *  @return 	void
712 712
 	 */
713 713
 	public static function localize_grid_event_lists() {
714
-		wp_localize_script( 'archive-espresso_events', 'espresso_grid_event_lists', EED_Events_Archive_Filters::$espresso_grid_event_lists );
714
+		wp_localize_script('archive-espresso_events', 'espresso_grid_event_lists', EED_Events_Archive_Filters::$espresso_grid_event_lists);
715 715
 	}
716 716
 
717 717
 
@@ -726,9 +726,9 @@  discard block
 block discarded – undo
726 726
 	 */
727 727
 	public static function template_settings_form() {
728 728
 		$EE = EE_Registry::instance();
729
-		$EE->CFG->template_settings->EED_Events_Archive_Filters = isset( $EE->CFG->template_settings->EED_Events_Archive_Filters ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters : new EE_Events_Archive_Config();
730
-		$EE->CFG->template_settings->EED_Events_Archive_Filters = apply_filters( 'FHEE__Event_List__template_settings_form__event_list_config', $EE->CFG->template_settings->EED_Events_Archive_Filters );
731
-		EEH_Template::display_template( EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $EE->CFG->template_settings->EED_Events_Archive_Filters );
729
+		$EE->CFG->template_settings->EED_Events_Archive_Filters = isset($EE->CFG->template_settings->EED_Events_Archive_Filters) ? $EE->CFG->template_settings->EED_Events_Archive_Filters : new EE_Events_Archive_Config();
730
+		$EE->CFG->template_settings->EED_Events_Archive_Filters = apply_filters('FHEE__Event_List__template_settings_form__event_list_config', $EE->CFG->template_settings->EED_Events_Archive_Filters);
731
+		EEH_Template::display_template(EVENTS_ARCHIVE_TEMPLATES_PATH.'admin-event-list-settings.template.php', $EE->CFG->template_settings->EED_Events_Archive_Filters);
732 732
 	}
733 733
 
734 734
 
@@ -742,16 +742,16 @@  discard block
 block discarded – undo
742 742
 	 *  @static
743 743
 	 *  @return 	void
744 744
 	 */
745
-	public static function set_default_settings( $CFG ) {
745
+	public static function set_default_settings($CFG) {
746 746
 		//EEH_Debug_Tools::printr( $CFG, '$CFG  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
747
-		$CFG->display_description = isset( $CFG->display_description ) && ! empty( $CFG->display_description ) ? $CFG->display_description : 1;
748
-		$CFG->display_address = isset( $CFG->display_address ) && ! empty( $CFG->display_address ) ? $CFG->display_address : TRUE;
749
-		$CFG->display_venue_details = isset( $CFG->display_venue_details ) && ! empty( $CFG->display_venue_details ) ? $CFG->display_venue_details : TRUE;
750
-		$CFG->display_expired_events = isset( $CFG->display_expired_events ) && ! empty( $CFG->display_expired_events ) ? $CFG->display_expired_events : FALSE;
751
-		$CFG->default_type = isset( $CFG->default_type ) && ! empty( $CFG->default_type ) ? $CFG->default_type : 'grid';
752
-		$CFG->event_list_grid_size = isset( $CFG->event_list_grid_size ) && ! empty( $CFG->event_list_grid_size ) ? $CFG->event_list_grid_size : 'medium';
753
-		$CFG->templates['full'] = isset( $CFG->templates['full'] ) && ! empty( $CFG->templates['full'] ) ? $CFG->templates['full'] : EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php';
754
-		$CFG->templates['part'] = isset( $CFG->templates['part'] ) && ! empty( $CFG->templates['part'] ) ? $CFG->templates['part'] : EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-grid-view.php';
747
+		$CFG->display_description = isset($CFG->display_description) && ! empty($CFG->display_description) ? $CFG->display_description : 1;
748
+		$CFG->display_address = isset($CFG->display_address) && ! empty($CFG->display_address) ? $CFG->display_address : TRUE;
749
+		$CFG->display_venue_details = isset($CFG->display_venue_details) && ! empty($CFG->display_venue_details) ? $CFG->display_venue_details : TRUE;
750
+		$CFG->display_expired_events = isset($CFG->display_expired_events) && ! empty($CFG->display_expired_events) ? $CFG->display_expired_events : FALSE;
751
+		$CFG->default_type = isset($CFG->default_type) && ! empty($CFG->default_type) ? $CFG->default_type : 'grid';
752
+		$CFG->event_list_grid_size = isset($CFG->event_list_grid_size) && ! empty($CFG->event_list_grid_size) ? $CFG->event_list_grid_size : 'medium';
753
+		$CFG->templates['full'] = isset($CFG->templates['full']) && ! empty($CFG->templates['full']) ? $CFG->templates['full'] : EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php';
754
+		$CFG->templates['part'] = isset($CFG->templates['part']) && ! empty($CFG->templates['part']) ? $CFG->templates['part'] : EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-grid-view.php';
755 755
 		return $CFG;
756 756
 	}
757 757
 
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
 	 *  @access 	public
764 764
 	 *  @return 	void
765 765
 	 */
766
-	public function filter_config( $CFG ) {
766
+	public function filter_config($CFG) {
767 767
 		return $CFG;
768 768
 	}
769 769
 
@@ -776,32 +776,32 @@  discard block
 block discarded – undo
776 776
 	 *  @access 	public
777 777
 	 *  @return 	void
778 778
 	 */
779
-	public static function update_template_settings( $CFG, $REQ ) {
779
+	public static function update_template_settings($CFG, $REQ) {
780 780
 //		EEH_Debug_Tools::printr( $REQ, '$REQ  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
781 781
 //		EEH_Debug_Tools::printr( $CFG, '$CFG  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
782 782
 		//$CFG->template_settings->EED_Events_Archive_Filters = new stdClass();
783
-		$CFG->EED_Events_Archive_Filters->display_description = isset( $REQ['display_description_in_event_list'] ) ? absint( $REQ['display_description_in_event_list'] ) : 1;
784
-		$CFG->EED_Events_Archive_Filters->display_address = isset( $REQ['display_address_in_event_list'] ) ? absint( $REQ['display_address_in_event_list'] ) : TRUE;
785
-		$CFG->EED_Events_Archive_Filters->display_venue_details = isset( $REQ['display_venue_details_in_event_list'] ) ? absint( $REQ['display_venue_details_in_event_list'] ) : TRUE;
786
-		$CFG->EED_Events_Archive_Filters->display_expired_events = isset( $REQ['display_expired_events'] ) ? absint( $REQ['display_expired_events'] ) : FALSE;
787
-		$CFG->EED_Events_Archive_Filters->default_type = isset( $REQ['default_type'] ) ? sanitize_text_field( $REQ['default_type'] ) : 'grid';
788
-		$CFG->EED_Events_Archive_Filters->event_list_grid_size = isset( $REQ['event_list_grid_size'] ) ? sanitize_text_field( $REQ['event_list_grid_size'] ) : 'medium';
783
+		$CFG->EED_Events_Archive_Filters->display_description = isset($REQ['display_description_in_event_list']) ? absint($REQ['display_description_in_event_list']) : 1;
784
+		$CFG->EED_Events_Archive_Filters->display_address = isset($REQ['display_address_in_event_list']) ? absint($REQ['display_address_in_event_list']) : TRUE;
785
+		$CFG->EED_Events_Archive_Filters->display_venue_details = isset($REQ['display_venue_details_in_event_list']) ? absint($REQ['display_venue_details_in_event_list']) : TRUE;
786
+		$CFG->EED_Events_Archive_Filters->display_expired_events = isset($REQ['display_expired_events']) ? absint($REQ['display_expired_events']) : FALSE;
787
+		$CFG->EED_Events_Archive_Filters->default_type = isset($REQ['default_type']) ? sanitize_text_field($REQ['default_type']) : 'grid';
788
+		$CFG->EED_Events_Archive_Filters->event_list_grid_size = isset($REQ['event_list_grid_size']) ? sanitize_text_field($REQ['event_list_grid_size']) : 'medium';
789 789
 		$CFG->EED_Events_Archive_Filters->templates = array(
790
-				'full'  => EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php'
790
+				'full'  => EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php'
791 791
 			);
792 792
 
793
-		switch ( $CFG->EED_Events_Archive_Filters->default_type ) {
793
+		switch ($CFG->EED_Events_Archive_Filters->default_type) {
794 794
 			case 'dates' :
795
-					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-dates-view.php';
795
+					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-dates-view.php';
796 796
 				break;
797 797
 			case 'text' :
798
-					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-text-view.php';
798
+					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-text-view.php';
799 799
 				break;
800 800
 			default :
801
-					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-grid-view.php';
801
+					$CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-grid-view.php';
802 802
 		}
803 803
 
804
-		$CFG->EED_Events_Archive_Filters = isset( $REQ['reset_event_list_settings'] ) && absint( $REQ['reset_event_list_settings'] ) == 1 ? new EE_Events_Archive_Config() : $CFG->EED_Events_Archive_Filters;
804
+		$CFG->EED_Events_Archive_Filters = isset($REQ['reset_event_list_settings']) && absint($REQ['reset_event_list_settings']) == 1 ? new EE_Events_Archive_Config() : $CFG->EED_Events_Archive_Filters;
805 805
 		return $CFG;
806 806
 	}
807 807
 
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
 	 *  @return 	void
817 817
 	 */
818 818
 	public static function get_template_part() {
819
-		switch ( self::$_type ) {
819
+		switch (self::$_type) {
820 820
 			case 'dates' :
821 821
 					return 'archive-espresso_events-dates-view.php';
822 822
 				break;
@@ -840,13 +840,13 @@  discard block
 block discarded – undo
840 840
 	 */
841 841
 	public function event_list_template_filters() {
842 842
 		$args = array(
843
-			'form_url' => get_post_type_archive_link( 'espresso_events' ), //add_query_arg( array( 'post_type' => 'espresso_events' ), home_url() ),
843
+			'form_url' => get_post_type_archive_link('espresso_events'), //add_query_arg( array( 'post_type' => 'espresso_events' ), home_url() ),
844 844
 			'elf_month' => EED_Events_Archive_Filters::_display_month(),
845 845
 			'elf_category' => EED_Events_Archive_Filters::_event_category_slug(),
846 846
 			'elf_show_expired' => EED_Events_Archive_Filters::_show_expired(),
847 847
 			'elf_type' => self::$_type
848 848
 		);
849
-		EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-filters.php', $args );
849
+		EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-filters.php', $args);
850 850
 	}
851 851
 
852 852
 
@@ -859,16 +859,16 @@  discard block
 block discarded – undo
859 859
 	 *  @access 	public
860 860
 	 *  @return 	void
861 861
 	 */
862
-	public static function event_list_css( $extra_class = '' ) {
862
+	public static function event_list_css($extra_class = '') {
863 863
 		$EE = EE_Registry::instance();
864
-		$event_list_css = ! empty( $extra_class ) ? array( $extra_class ) : array();
864
+		$event_list_css = ! empty($extra_class) ? array($extra_class) : array();
865 865
 		$event_list_css[] = 'espresso-event-list-event';
866
-		if ( self::$_type == 'grid' ) {
867
-			$event_list_grid_size = isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size : 'medium';
868
-			$event_list_css[] = $event_list_grid_size . '-event-list-grid';
866
+		if (self::$_type == 'grid') {
867
+			$event_list_grid_size = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size : 'medium';
868
+			$event_list_css[] = $event_list_grid_size.'-event-list-grid';
869 869
 		}
870
-		$event_list_css = apply_filters( 'EED_Events_Archive_Filters__event_list_css__event_list_css_array', $event_list_css );
871
-		return implode( ' ', $event_list_css );
870
+		$event_list_css = apply_filters('EED_Events_Archive_Filters__event_list_css__event_list_css_array', $event_list_css);
871
+		return implode(' ', $event_list_css);
872 872
 	}
873 873
 
874 874
 
@@ -894,9 +894,9 @@  discard block
 block discarded – undo
894 894
 	 *  @access 	public
895 895
 	 *  @return 	void
896 896
 	 */
897
-	public static function display_description( $value ) {
897
+	public static function display_description($value) {
898 898
 		$EE = EE_Registry::instance();
899
-		$display_description= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description : 1;
899
+		$display_description = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_description) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description : 1;
900 900
 		return $display_description === $value ? TRUE : FALSE;
901 901
 	}
902 902
 
@@ -910,9 +910,9 @@  discard block
 block discarded – undo
910 910
 	 */
911 911
 	public static function display_venue_details() {
912 912
 		$EE = EE_Registry::instance();
913
-		$display_venue_details= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details : TRUE;
913
+		$display_venue_details = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details : TRUE;
914 914
 		$venue_name = EEH_Venue_View::venue_name();
915
-		return $display_venue_details && ! empty( $venue_name ) ? TRUE : FALSE;
915
+		return $display_venue_details && ! empty($venue_name) ? TRUE : FALSE;
916 916
 	}
917 917
 
918 918
 
@@ -924,9 +924,9 @@  discard block
 block discarded – undo
924 924
 	 */
925 925
 	public static function display_address() {
926 926
 		$EE = EE_Registry::instance();
927
-		$display_address= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address : FALSE;
927
+		$display_address = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_address) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address : FALSE;
928 928
 		$venue_name = EEH_Venue_View::venue_name();
929
-		return $display_address && ! empty( $venue_name ) ? TRUE : FALSE;
929
+		return $display_address && ! empty($venue_name) ? TRUE : FALSE;
930 930
 	}
931 931
 
932 932
 
@@ -940,22 +940,22 @@  discard block
 block discarded – undo
940 940
 	public static function pagination() {
941 941
 		global $wp_query;
942 942
 		$big = 999999999; // need an unlikely integer
943
-		$pagination = paginate_links( array(
944
-			'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
943
+		$pagination = paginate_links(array(
944
+			'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
945 945
 			'format' => '?paged=%#%',
946
-			'current' => max( 1, get_query_var('paged') ),
946
+			'current' => max(1, get_query_var('paged')),
947 947
 			'total' => $wp_query->max_num_pages,
948 948
 			'show_all'     => TRUE,
949 949
 			'end_size'     => 10,
950 950
 			'mid_size'     => 6,
951 951
 			'prev_next'    => TRUE,
952
-			'prev_text'    => __( '&lsaquo; PREV', 'event_espresso' ),
953
-			'next_text'    => __( 'NEXT &rsaquo;', 'event_espresso' ),
952
+			'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
953
+			'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
954 954
 			'type'         => 'plain',
955 955
 			'add_args'     => FALSE,
956 956
 			'add_fragment' => ''
957 957
 		));
958
-		return ! empty( $pagination ) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : '';
958
+		return ! empty($pagination) ? '<div class="ee-pagination-dv clear">'.$pagination.'</div>' : '';
959 959
 	}
960 960
 
961 961
 
@@ -969,7 +969,7 @@  discard block
 block discarded – undo
969 969
 	 *  @return 	void
970 970
 	 */
971 971
 	public static function event_list_title() {
972
-		return apply_filters( 'EED_Events_Archive_Filters__event_list_title__event_list_title', __( 'Upcoming Events', 'event_espresso' ));
972
+		return apply_filters('EED_Events_Archive_Filters__event_list_title__event_list_title', __('Upcoming Events', 'event_espresso'));
973 973
 	}
974 974
 
975 975
 
Please login to merge, or discard this patch.
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 1 patch
Indentation   +1221 added lines, -1221 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -16,1226 +16,1226 @@  discard block
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Extend_Events_Admin_Page constructor.
21
-     *
22
-     * @param bool $routing
23
-     */
24
-    public function __construct($routing = true)
25
-    {
26
-        parent::__construct($routing);
27
-        if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
31
-        }
32
-    }
33
-
34
-
35
-
36
-    protected function _extend_page_config()
37
-    {
38
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
39
-        //is there a evt_id in the request?
40
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
41
-            ? $this->_req_data['EVT_ID']
42
-            : 0;
43
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
44
-        //tkt_id?
45
-        $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
46
-            ? $this->_req_data['TKT_ID']
47
-            : 0;
48
-        $new_page_routes = array(
49
-            'duplicate_event'          => array(
50
-                'func'       => '_duplicate_event',
51
-                'capability' => 'ee_edit_event',
52
-                'obj_id'     => $evt_id,
53
-                'noheader'   => true,
54
-            ),
55
-            'ticket_list_table'        => array(
56
-                'func'       => '_tickets_overview_list_table',
57
-                'capability' => 'ee_read_default_tickets',
58
-            ),
59
-            'trash_ticket'             => array(
60
-                'func'       => '_trash_or_restore_ticket',
61
-                'capability' => 'ee_delete_default_ticket',
62
-                'obj_id'     => $tkt_id,
63
-                'noheader'   => true,
64
-                'args'       => array('trash' => true),
65
-            ),
66
-            'trash_tickets'            => array(
67
-                'func'       => '_trash_or_restore_ticket',
68
-                'capability' => 'ee_delete_default_tickets',
69
-                'noheader'   => true,
70
-                'args'       => array('trash' => true),
71
-            ),
72
-            'restore_ticket'           => array(
73
-                'func'       => '_trash_or_restore_ticket',
74
-                'capability' => 'ee_delete_default_ticket',
75
-                'obj_id'     => $tkt_id,
76
-                'noheader'   => true,
77
-            ),
78
-            'restore_tickets'          => array(
79
-                'func'       => '_trash_or_restore_ticket',
80
-                'capability' => 'ee_delete_default_tickets',
81
-                'noheader'   => true,
82
-            ),
83
-            'delete_ticket'            => array(
84
-                'func'       => '_delete_ticket',
85
-                'capability' => 'ee_delete_default_ticket',
86
-                'obj_id'     => $tkt_id,
87
-                'noheader'   => true,
88
-            ),
89
-            'delete_tickets'           => array(
90
-                'func'       => '_delete_ticket',
91
-                'capability' => 'ee_delete_default_tickets',
92
-                'noheader'   => true,
93
-            ),
94
-            'import_page'              => array(
95
-                'func'       => '_import_page',
96
-                'capability' => 'import',
97
-            ),
98
-            'import'                   => array(
99
-                'func'       => '_import_events',
100
-                'capability' => 'import',
101
-                'noheader'   => true,
102
-            ),
103
-            'import_events'            => array(
104
-                'func'       => '_import_events',
105
-                'capability' => 'import',
106
-                'noheader'   => true,
107
-            ),
108
-            'export_events'            => array(
109
-                'func'       => '_events_export',
110
-                'capability' => 'export',
111
-                'noheader'   => true,
112
-            ),
113
-            'export_categories'        => array(
114
-                'func'       => '_categories_export',
115
-                'capability' => 'export',
116
-                'noheader'   => true,
117
-            ),
118
-            'sample_export_file'       => array(
119
-                'func'       => '_sample_export_file',
120
-                'capability' => 'export',
121
-                'noheader'   => true,
122
-            ),
123
-            'update_template_settings' => array(
124
-                'func'       => '_update_template_settings',
125
-                'capability' => 'manage_options',
126
-                'noheader'   => true,
127
-            ),
128
-        );
129
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
130
-        //partial route/config override
131
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
132
-        $this->_page_config['create_new']['metaboxes'][]  = '_premium_event_editor_meta_boxes';
133
-        $this->_page_config['create_new']['qtips'][]      = 'EE_Event_Editor_Tips';
134
-        $this->_page_config['edit']['qtips'][]            = 'EE_Event_Editor_Tips';
135
-        $this->_page_config['edit']['metaboxes'][]        = '_premium_event_editor_meta_boxes';
136
-        $this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
137
-        //add tickets tab but only if there are more than one default ticket!
138
-        $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
139
-            array(array('TKT_is_default' => 1)),
140
-            'TKT_ID',
141
-            true
142
-        );
143
-        if ($tkt_count > 1) {
144
-            $new_page_config = array(
145
-                'ticket_list_table' => array(
146
-                    'nav'           => array(
147
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
148
-                        'order' => 60,
149
-                    ),
150
-                    'list_table'    => 'Tickets_List_Table',
151
-                    'require_nonce' => false,
152
-                ),
153
-            );
154
-        }
155
-        //template settings
156
-        $new_page_config['template_settings'] = array(
157
-            'nav'           => array(
158
-                'label' => esc_html__('Templates', 'event_espresso'),
159
-                'order' => 30,
160
-            ),
161
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
162
-            'help_tabs'     => array(
163
-                'general_settings_templates_help_tab' => array(
164
-                    'title'    => esc_html__('Templates', 'event_espresso'),
165
-                    'filename' => 'general_settings_templates',
166
-                ),
167
-            ),
168
-            'help_tour'     => array('Templates_Help_Tour'),
169
-            'require_nonce' => false,
170
-        );
171
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
172
-        //add filters and actions
173
-        //modifying _views
174
-        add_filter(
175
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
176
-            array($this, 'add_additional_datetime_button'),
177
-            10,
178
-            2
179
-        );
180
-        add_filter(
181
-            'FHEE_event_datetime_metabox_clone_button_template',
182
-            array($this, 'add_datetime_clone_button'),
183
-            10,
184
-            2
185
-        );
186
-        add_filter(
187
-            'FHEE_event_datetime_metabox_timezones_template',
188
-            array($this, 'datetime_timezones_template'),
189
-            10,
190
-            2
191
-        );
192
-        //filters for event list table
193
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
194
-        add_filter(
195
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
196
-            array($this, 'extra_list_table_actions'),
197
-            10,
198
-            2
199
-        );
200
-        //legend item
201
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
202
-        add_action('admin_init', array($this, 'admin_init'));
203
-        //heartbeat stuff
204
-        add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2);
205
-    }
206
-
207
-
208
-
209
-    /**
210
-     * admin_init
211
-     */
212
-    public function admin_init()
213
-    {
214
-        EE_Registry::$i18n_js_strings = array_merge(
215
-            EE_Registry::$i18n_js_strings,
216
-            array(
217
-                'image_confirm'          => esc_html__(
218
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
219
-                    'event_espresso'
220
-                ),
221
-                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
222
-                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
223
-                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
224
-                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
225
-                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
226
-            )
227
-        );
228
-    }
229
-
230
-
231
-
232
-    /**
233
-     * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
234
-     * accordingly.
235
-     *
236
-     * @param array $response The existing heartbeat response array.
237
-     * @param array $data     The incoming data package.
238
-     * @return array  possibly appended response.
239
-     */
240
-    public function heartbeat_response($response, $data)
241
-    {
242
-        /**
243
-         * check whether count of tickets is approaching the potential
244
-         * limits for the server.
245
-         */
246
-        if ( ! empty($data['input_count'])) {
247
-            $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
248
-                $data['input_count']
249
-            );
250
-        }
251
-        return $response;
252
-    }
253
-
254
-
255
-
256
-    protected function _add_screen_options_ticket_list_table()
257
-    {
258
-        $this->_per_page_screen_option();
259
-    }
260
-
261
-
262
-
263
-    /**
264
-     * @param string $return
265
-     * @param int    $id
266
-     * @param string $new_title
267
-     * @param string $new_slug
268
-     * @return string
269
-     */
270
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
271
-    {
272
-        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
273
-        //make sure this is only when editing
274
-        if ( ! empty($id)) {
275
-            $href  = EE_Admin_Page::add_query_args_and_nonce(
276
-                array('action' => 'duplicate_event', 'EVT_ID' => $id),
277
-                $this->_admin_base_url
278
-            );
279
-            $title = esc_attr__('Duplicate Event', 'event_espresso');
280
-            $return .= '<a href="'
281
-                       . $href
282
-                       . '" title="'
283
-                       . $title
284
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
285
-                       . $title
286
-                       . '</button>';
287
-        }
288
-        return $return;
289
-    }
290
-
291
-
292
-
293
-    public function _set_list_table_views_ticket_list_table()
294
-    {
295
-        $this->_views = array(
296
-            'all'     => array(
297
-                'slug'        => 'all',
298
-                'label'       => esc_html__('All', 'event_espresso'),
299
-                'count'       => 0,
300
-                'bulk_action' => array(
301
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
302
-                ),
303
-            ),
304
-            'trashed' => array(
305
-                'slug'        => 'trashed',
306
-                'label'       => esc_html__('Trash', 'event_espresso'),
307
-                'count'       => 0,
308
-                'bulk_action' => array(
309
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
310
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
311
-                ),
312
-            ),
313
-        );
314
-    }
315
-
316
-
317
-
318
-    public function load_scripts_styles_edit()
319
-    {
320
-        wp_register_script(
321
-            'ee-event-editor-heartbeat',
322
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
323
-            array('ee_admin_js', 'heartbeat'),
324
-            EVENT_ESPRESSO_VERSION,
325
-            true
326
-        );
327
-        wp_enqueue_script('ee-accounting');
328
-        //styles
329
-        wp_enqueue_style('espresso-ui-theme');
330
-        wp_enqueue_script('event_editor_js');
331
-        wp_enqueue_script('ee-event-editor-heartbeat');
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     * @param $template
338
-     * @param $template_args
339
-     * @return mixed
340
-     */
341
-    public function add_additional_datetime_button($template, $template_args)
342
-    {
343
-        return EEH_Template::display_template(
344
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
345
-            $template_args,
346
-            true
347
-        );
348
-    }
349
-
350
-
351
-
352
-    /**
353
-     * @param $template
354
-     * @param $template_args
355
-     * @return mixed
356
-     */
357
-    public function add_datetime_clone_button($template, $template_args)
358
-    {
359
-        return EEH_Template::display_template(
360
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
361
-            $template_args,
362
-            true
363
-        );
364
-    }
365
-
366
-
367
-
368
-    /**
369
-     * @param $template
370
-     * @param $template_args
371
-     * @return mixed
372
-     */
373
-    public function datetime_timezones_template($template, $template_args)
374
-    {
375
-        return EEH_Template::display_template(
376
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
377
-            $template_args,
378
-            true
379
-        );
380
-    }
381
-
382
-
383
-
384
-    protected function _set_list_table_views_default()
385
-    {
386
-        parent::_set_list_table_views_default();
387
-        $new_views = array(
388
-            'today' => array(
389
-                'slug'        => 'today',
390
-                'label'       => esc_html__('Today', 'event_espresso'),
391
-                'count'       => $this->total_events_today(),
392
-                'bulk_action' => array(
393
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
394
-                ),
395
-            ),
396
-            'month' => array(
397
-                'slug'        => 'month',
398
-                'label'       => esc_html__('This Month', 'event_espresso'),
399
-                'count'       => $this->total_events_this_month(),
400
-                'bulk_action' => array(
401
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
402
-                ),
403
-            ),
404
-        );
405
-        $this->_views = array_merge($this->_views, $new_views);
406
-    }
407
-
408
-
409
-
410
-    /**
411
-     * @param array     $action_links
412
-     * @param \EE_Event $event
413
-     * @return array
414
-     */
415
-    public function extra_list_table_actions(array $action_links, \EE_Event $event)
416
-    {
417
-        if (
418
-        EE_Registry::instance()->CAP->current_user_can(
419
-            'ee_read_registrations',
420
-            'espresso_registrations_reports',
421
-            $event->ID()
422
-        )
423
-        ) {
424
-            $reports_query_args = array(
425
-                'action' => 'reports',
426
-                'EVT_ID' => $event->ID(),
427
-            );
428
-            $reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
429
-            $action_links[]     = '<a href="'
430
-                                  . $reports_link
431
-                                  . '" title="'
432
-                                  . esc_attr__('View Report', 'event_espresso')
433
-                                  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
434
-                                  . "\n\t";
435
-        }
436
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
437
-            EE_Registry::instance()->load_helper('MSG_Template');
438
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
439
-                'see_notifications_for',
440
-                null,
441
-                array('EVT_ID' => $event->ID())
442
-            );
443
-        }
444
-        return $action_links;
445
-    }
446
-
447
-
448
-
449
-    /**
450
-     * @param $items
451
-     * @return mixed
452
-     */
453
-    public function additional_legend_items($items)
454
-    {
455
-        if (
456
-        EE_Registry::instance()->CAP->current_user_can(
457
-            'ee_read_registrations',
458
-            'espresso_registrations_reports'
459
-        )
460
-        ) {
461
-            $items['reports'] = array(
462
-                'class' => 'dashicons dashicons-chart-bar',
463
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
464
-            );
465
-        }
466
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
467
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
468
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
469
-                $items['view_related_messages'] = array(
470
-                    'class' => $related_for_icon['css_class'],
471
-                    'desc'  => $related_for_icon['label'],
472
-                );
473
-            }
474
-        }
475
-        return $items;
476
-    }
477
-
478
-
479
-
480
-    /**
481
-     * This is the callback method for the duplicate event route
482
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
483
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
484
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
485
-     * After duplication the redirect is to the new event edit page.
486
-     *
487
-     * @return void
488
-     * @access protected
489
-     * @throws EE_Error If EE_Event is not available with given ID
490
-     */
491
-    protected function _duplicate_event()
492
-    {
493
-        // first make sure the ID for the event is in the request.
494
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
495
-        if ( ! isset($this->_req_data['EVT_ID'])) {
496
-            EE_Error::add_error(
497
-                esc_html__(
498
-                    'In order to duplicate an event an Event ID is required.  None was given.',
499
-                    'event_espresso'
500
-                ),
501
-                __FILE__,
502
-                __FUNCTION__,
503
-                __LINE__
504
-            );
505
-            $this->_redirect_after_action(false, '', '', array(), true);
506
-            return;
507
-        }
508
-        //k we've got EVT_ID so let's use that to get the event we'll duplicate
509
-        $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
510
-        if ( ! $orig_event instanceof EE_Event) {
511
-            throw new EE_Error(
512
-                sprintf(
513
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
514
-                    $this->_req_data['EVT_ID']
515
-                )
516
-            );
517
-        }
518
-        //k now let's clone the $orig_event before getting relations
519
-        $new_event = clone $orig_event;
520
-        //original datetimes
521
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
522
-        //other original relations
523
-        $orig_ven = $orig_event->get_many_related('Venue');
524
-        //reset the ID and modify other details to make it clear this is a dupe
525
-        $new_event->set('EVT_ID', 0);
526
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
527
-        $new_event->set('EVT_name', $new_name);
528
-        $new_event->set(
529
-            'EVT_slug',
530
-            wp_unique_post_slug(
531
-                sanitize_title($orig_event->name()),
532
-                0,
533
-                'publish',
534
-                'espresso_events',
535
-                0
536
-            )
537
-        );
538
-        $new_event->set('status', 'draft');
539
-        //duplicate discussion settings
540
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
541
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
542
-        //save the new event
543
-        $new_event->save();
544
-        //venues
545
-        foreach ($orig_ven as $ven) {
546
-            $new_event->_add_relation_to($ven, 'Venue');
547
-        }
548
-        $new_event->save();
549
-        //now we need to get the question group relations and handle that
550
-        //first primary question groups
551
-        $orig_primary_qgs = $orig_event->get_many_related(
552
-            'Question_Group',
553
-            array(array('Event_Question_Group.EQG_primary' => 1))
554
-        );
555
-        if ( ! empty($orig_primary_qgs)) {
556
-            foreach ($orig_primary_qgs as $id => $obj) {
557
-                if ($obj instanceof EE_Question_Group) {
558
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
559
-                }
560
-            }
561
-        }
562
-        //next additional attendee question groups
563
-        $orig_additional_qgs = $orig_event->get_many_related(
564
-            'Question_Group',
565
-            array(array('Event_Question_Group.EQG_primary' => 0))
566
-        );
567
-        if ( ! empty($orig_additional_qgs)) {
568
-            foreach ($orig_additional_qgs as $id => $obj) {
569
-                if ($obj instanceof EE_Question_Group) {
570
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
571
-                }
572
-            }
573
-        }
574
-        //now save
575
-        $new_event->save();
576
-        //k now that we have the new event saved we can loop through the datetimes and start adding relations.
577
-        $cloned_tickets = array();
578
-        foreach ($orig_datetimes as $orig_dtt) {
579
-            if ( ! $orig_dtt instanceof EE_Datetime) {
580
-                continue;
581
-            }
582
-            $new_dtt   = clone $orig_dtt;
583
-            $orig_tkts = $orig_dtt->tickets();
584
-            //save new dtt then add to event
585
-            $new_dtt->set('DTT_ID', 0);
586
-            $new_dtt->set('DTT_sold', 0);
587
-            $new_dtt->save();
588
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
589
-            $new_event->save();
590
-            //now let's get the ticket relations setup.
591
-            foreach ((array)$orig_tkts as $orig_tkt) {
592
-                //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
593
-                if ( ! $orig_tkt instanceof EE_Ticket) {
594
-                    continue;
595
-                }
596
-                //is this ticket archived?  If it is then let's skip
597
-                if ($orig_tkt->get('TKT_deleted')) {
598
-                    continue;
599
-                }
600
-                // does this original ticket already exist in the clone_tickets cache?
601
-                //  If so we'll just use the new ticket from it.
602
-                if (isset($cloned_tickets[$orig_tkt->ID()])) {
603
-                    $new_tkt = $cloned_tickets[$orig_tkt->ID()];
604
-                } else {
605
-                    $new_tkt = clone $orig_tkt;
606
-                    //get relations on the $orig_tkt that we need to setup.
607
-                    $orig_prices = $orig_tkt->prices();
608
-                    $new_tkt->set('TKT_ID', 0);
609
-                    $new_tkt->set('TKT_sold', 0);
610
-                    $new_tkt->set('TKT_reserved', 0);
611
-                    $new_tkt->save(); //make sure new ticket has ID.
612
-                    //price relations on new ticket need to be setup.
613
-                    foreach ($orig_prices as $orig_price) {
614
-                        $new_price = clone $orig_price;
615
-                        $new_price->set('PRC_ID', 0);
616
-                        $new_price->save();
617
-                        $new_tkt->_add_relation_to($new_price, 'Price');
618
-                        $new_tkt->save();
619
-                    }
620
-                }
621
-                // k now we can add the new ticket as a relation to the new datetime
622
-                // and make sure its added to our cached $cloned_tickets array
623
-                // for use with later datetimes that have the same ticket.
624
-                $new_dtt->_add_relation_to($new_tkt, 'Ticket');
625
-                $new_dtt->save();
626
-                $cloned_tickets[$orig_tkt->ID()] = $new_tkt;
627
-            }
628
-        }
629
-        //clone taxonomy information
630
-        $taxonomies_to_clone_with = apply_filters(
631
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
632
-            array('espresso_event_categories', 'espresso_event_type', 'post_tag')
633
-        );
634
-        //get terms for original event (notice)
635
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
636
-        //loop through terms and add them to new event.
637
-        foreach ($orig_terms as $term) {
638
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
639
-        }
640
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
641
-        //now let's redirect to the edit page for this duplicated event if we have a new event id.
642
-        if ($new_event->ID()) {
643
-            $redirect_args = array(
644
-                'post'   => $new_event->ID(),
645
-                'action' => 'edit',
646
-            );
647
-            EE_Error::add_success(
648
-                esc_html__(
649
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
650
-                    'event_espresso'
651
-                )
652
-            );
653
-        } else {
654
-            $redirect_args = array(
655
-                'action' => 'default',
656
-            );
657
-            EE_Error::add_error(
658
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
659
-                __FILE__,
660
-                __FUNCTION__,
661
-                __LINE__
662
-            );
663
-        }
664
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
665
-    }
666
-
667
-
668
-    protected function _import_page()
669
-    {
670
-        $title                                      = esc_html__('Import', 'event_espresso');
671
-        $intro                                      = esc_html__(
672
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
673
-            'event_espresso'
674
-        );
675
-        $form_url                                   = EVENTS_ADMIN_URL;
676
-        $action                                     = 'import_events';
677
-        $type                                       = 'csv';
678
-        $this->_template_args['form']               = EE_Import::instance()->upload_form(
679
-            $title, $intro, $form_url, $action, $type
680
-        );
681
-        $this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
682
-            array('action' => 'sample_export_file'),
683
-            $this->_admin_base_url
684
-        );
685
-        $content                                    = EEH_Template::display_template(
686
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
687
-            $this->_template_args,
688
-            true
689
-        );
690
-        $this->_template_args['admin_page_content'] = $content;
691
-        $this->display_admin_page_with_sidebar();
692
-    }
693
-
694
-
695
-
696
-    /**
697
-     * _import_events
698
-     * This handles displaying the screen and running imports for importing events.
699
-     *
700
-     * @return void
701
-     */
702
-    protected function _import_events()
703
-    {
704
-        require_once(EE_CLASSES . 'EE_Import.class.php');
705
-        $success = EE_Import::instance()->import();
706
-        $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     * _events_export
713
-     * Will export all (or just the given event) to a Excel compatible file.
714
-     *
715
-     * @access protected
716
-     * @return void
717
-     */
718
-    protected function _events_export()
719
-    {
720
-        if (isset($this->_req_data['EVT_ID'])) {
721
-            $event_ids = $this->_req_data['EVT_ID'];
722
-        } elseif (isset($this->_req_data['EVT_IDs'])) {
723
-            $event_ids = $this->_req_data['EVT_IDs'];
724
-        } else {
725
-            $event_ids = null;
726
-        }
727
-        //todo: I don't like doing this but it'll do until we modify EE_Export Class.
728
-        $new_request_args = array(
729
-            'export' => 'report',
730
-            'action' => 'all_event_data',
731
-            'EVT_ID' => $event_ids,
732
-        );
733
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
734
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
735
-            require_once(EE_CLASSES . 'EE_Export.class.php');
736
-            $EE_Export = EE_Export::instance($this->_req_data);
737
-            $EE_Export->export();
738
-        }
739
-    }
740
-
741
-
742
-
743
-    /**
744
-     * handle category exports()
745
-     *
746
-     * @return void
747
-     */
748
-    protected function _categories_export()
749
-    {
750
-        //todo: I don't like doing this but it'll do until we modify EE_Export Class.
751
-        $new_request_args = array(
752
-            'export'       => 'report',
753
-            'action'       => 'categories',
754
-            'category_ids' => $this->_req_data['EVT_CAT_ID'],
755
-        );
756
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
757
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
758
-            require_once(EE_CLASSES . 'EE_Export.class.php');
759
-            $EE_Export = EE_Export::instance($this->_req_data);
760
-            $EE_Export->export();
761
-        }
762
-    }
763
-
764
-
765
-
766
-    /**
767
-     * Creates a sample CSV file for importing
768
-     */
769
-    protected function _sample_export_file()
770
-    {
771
-        //		require_once(EE_CLASSES . 'EE_Export.class.php');
772
-        EE_Export::instance()->export_sample();
773
-    }
774
-
775
-
776
-
777
-    /*************        Template Settings        *************/
778
-    protected function _template_settings()
779
-    {
780
-        $this->_template_args['values'] = $this->_yes_no_values;
781
-        /**
782
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
783
-         * from General_Settings_Admin_Page to here.
784
-         */
785
-        $this->_template_args = apply_filters(
786
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
787
-            $this->_template_args
788
-        );
789
-        $this->_set_add_edit_form_tags('update_template_settings');
790
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
791
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
792
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
793
-            $this->_template_args,
794
-            true
795
-        );
796
-        $this->display_admin_page_with_sidebar();
797
-    }
798
-
799
-
800
-
801
-    protected function _update_template_settings()
802
-    {
803
-        /**
804
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
805
-         * from General_Settings_Admin_Page to here.
806
-         */
807
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
808
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
809
-            EE_Registry::instance()->CFG->template_settings,
810
-            $this->_req_data
811
-        );
812
-        //update custom post type slugs and detect if we need to flush rewrite rules
813
-        $old_slug                                          = EE_Registry::instance()->CFG->core->event_cpt_slug;
814
-        EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
815
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
816
-            : sanitize_title_with_dashes($this->_req_data['event_cpt_slug']);
817
-        $what                                              = 'Template Settings';
818
-        $success                                           = $this->_update_espresso_configuration(
819
-            $what,
820
-            EE_Registry::instance()->CFG->template_settings,
821
-            __FILE__,
822
-            __FUNCTION__,
823
-            __LINE__
824
-        );
825
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
826
-            update_option('ee_flush_rewrite_rules', true);
827
-        }
828
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
829
-    }
830
-
831
-
832
-
833
-    /**
834
-     * _premium_event_editor_meta_boxes
835
-     * add all metaboxes related to the event_editor
836
-     *
837
-     * @access protected
838
-     * @return void
839
-     */
840
-    protected function _premium_event_editor_meta_boxes()
841
-    {
842
-        $this->verify_cpt_object();
843
-        add_meta_box(
844
-            'espresso_event_editor_event_options',
845
-            esc_html__('Event Registration Options', 'event_espresso'),
846
-            array($this, 'registration_options_meta_box'),
847
-            $this->page_slug,
848
-            'side',
849
-            'core'
850
-        );
851
-    }
852
-
853
-
854
-
855
-    /**
856
-     * override caf metabox
857
-     *
858
-     * @return void
859
-     */
860
-    public function registration_options_meta_box()
861
-    {
862
-        $yes_no_values = array(
863
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
864
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
865
-        );
866
-        $default_reg_status_values = EEM_Registration::reg_status_array(
867
-            array(
868
-                EEM_Registration::status_id_cancelled,
869
-                EEM_Registration::status_id_declined,
870
-                EEM_Registration::status_id_incomplete,
871
-                EEM_Registration::status_id_wait_list,
872
-            ),
873
-            true
874
-        );
875
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
876
-        $template_args['_event']                          = $this->_cpt_model_obj;
877
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
878
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
879
-            'default_reg_status',
880
-            $default_reg_status_values,
881
-            $this->_cpt_model_obj->default_registration_status()
882
-        );
883
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
884
-            'display_desc',
885
-            $yes_no_values,
886
-            $this->_cpt_model_obj->display_description()
887
-        );
888
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
889
-            'display_ticket_selector',
890
-            $yes_no_values,
891
-            $this->_cpt_model_obj->display_ticket_selector(),
892
-            '',
893
-            '',
894
-            false
895
-        );
896
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
897
-            'EVT_default_registration_status',
898
-            $default_reg_status_values,
899
-            $this->_cpt_model_obj->default_registration_status()
900
-        );
901
-        $template_args['additional_registration_options'] = apply_filters(
902
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
903
-            '',
904
-            $template_args,
905
-            $yes_no_values,
906
-            $default_reg_status_values
907
-        );
908
-        EEH_Template::display_template(
909
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
910
-            $template_args
911
-        );
912
-    }
913
-
914
-
915
-
916
-    /**
917
-     * wp_list_table_mods for caf
918
-     * ============================
919
-     */
920
-    /**
921
-     * hook into list table filters and provide filters for caffeinated list table
922
-     *
923
-     * @param  array $old_filters    any existing filters present
924
-     * @param  array $list_table_obj the list table object
925
-     * @return array                  new filters
926
-     */
927
-    public function list_table_filters($old_filters, $list_table_obj)
928
-    {
929
-        $filters = array();
930
-        //first month/year filters
931
-        $filters[] = $this->espresso_event_months_dropdown();
932
-        $status    = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
933
-        //active status dropdown
934
-        if ($status !== 'draft') {
935
-            $filters[] = $this->active_status_dropdown(
936
-                isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
937
-            );
938
-        }
939
-        //category filter
940
-        $filters[] = $this->category_dropdown();
941
-        return array_merge($old_filters, $filters);
942
-    }
943
-
944
-
945
-
946
-    /**
947
-     * espresso_event_months_dropdown
948
-     *
949
-     * @access public
950
-     * @return string                dropdown listing month/year selections for events.
951
-     */
952
-    public function espresso_event_months_dropdown()
953
-    {
954
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
955
-        // Note we need to include any other filters that are set!
956
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
957
-        //categories?
958
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
959
-            ? $this->_req_data['EVT_CAT']
960
-            : null;
961
-        //active status?
962
-        $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
963
-        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
964
-        return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
965
-    }
966
-
967
-
968
-
969
-    /**
970
-     * returns a list of "active" statuses on the event
971
-     *
972
-     * @param  string $current_value whatever the current active status is
973
-     * @return string
974
-     */
975
-    public function active_status_dropdown($current_value = '')
976
-    {
977
-        $select_name = 'active_status';
978
-        $values      = array(
979
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
980
-            'active'   => esc_html__('Active', 'event_espresso'),
981
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
982
-            'expired'  => esc_html__('Expired', 'event_espresso'),
983
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
984
-        );
985
-        $id          = 'id="espresso-active-status-dropdown-filter"';
986
-        $class       = 'wide';
987
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
988
-    }
989
-
990
-
991
-
992
-    /**
993
-     * output a dropdown of the categories for the category filter on the event admin list table
994
-     *
995
-     * @access  public
996
-     * @return string html
997
-     */
998
-    public function category_dropdown()
999
-    {
1000
-        $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1001
-        return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1002
-    }
1003
-
1004
-
1005
-
1006
-    /**
1007
-     * get total number of events today
1008
-     *
1009
-     * @access public
1010
-     * @return int
1011
-     */
1012
-    public function total_events_today()
1013
-    {
1014
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1015
-            'DTT_EVT_start',
1016
-            date('Y-m-d') . ' 00:00:00',
1017
-            'Y-m-d H:i:s',
1018
-            'UTC'
1019
-        );
1020
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1021
-            'DTT_EVT_start',
1022
-            date('Y-m-d') . ' 23:59:59',
1023
-            'Y-m-d H:i:s',
1024
-            'UTC'
1025
-        );
1026
-        $where = array(
1027
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1028
-        );
1029
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1030
-        return $count;
1031
-    }
1032
-
1033
-
1034
-
1035
-    /**
1036
-     * get total number of events this month
1037
-     *
1038
-     * @access public
1039
-     * @return int
1040
-     */
1041
-    public function total_events_this_month()
1042
-    {
1043
-        //Dates
1044
-        $this_year_r     = date('Y');
1045
-        $this_month_r    = date('m');
1046
-        $days_this_month = date('t');
1047
-        $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1048
-            'DTT_EVT_start',
1049
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1050
-            'Y-m-d H:i:s',
1051
-            'UTC'
1052
-        );
1053
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1054
-            'DTT_EVT_start',
1055
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1056
-            'Y-m-d H:i:s',
1057
-            'UTC'
1058
-        );
1059
-        $where = array(
1060
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1061
-        );
1062
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1063
-        return $count;
1064
-    }
1065
-
1066
-
1067
-
1068
-    /** DEFAULT TICKETS STUFF **/
1069
-    public function _tickets_overview_list_table()
1070
-    {
1071
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1072
-        $this->display_admin_list_table_page_with_no_sidebar();
1073
-    }
1074
-
1075
-
1076
-
1077
-    /**
1078
-     * @param int  $per_page
1079
-     * @param bool $count
1080
-     * @param bool $trashed
1081
-     * @return \EE_Soft_Delete_Base_Class[]|int
1082
-     */
1083
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1084
-    {
1085
-        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1086
-        $order   = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1087
-        switch ($orderby) {
1088
-            case 'TKT_name' :
1089
-                $orderby = array('TKT_name' => $order);
1090
-                break;
1091
-            case 'TKT_price' :
1092
-                $orderby = array('TKT_price' => $order);
1093
-                break;
1094
-            case 'TKT_uses' :
1095
-                $orderby = array('TKT_uses' => $order);
1096
-                break;
1097
-            case 'TKT_min' :
1098
-                $orderby = array('TKT_min' => $order);
1099
-                break;
1100
-            case 'TKT_max' :
1101
-                $orderby = array('TKT_max' => $order);
1102
-                break;
1103
-            case 'TKT_qty' :
1104
-                $orderby = array('TKT_qty' => $order);
1105
-                break;
1106
-        }
1107
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1108
-            ? $this->_req_data['paged']
1109
-            : 1;
1110
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1111
-            ? $this->_req_data['perpage']
1112
-            : $per_page;
1113
-        $_where       = array(
1114
-            'TKT_is_default' => 1,
1115
-            'TKT_deleted'    => $trashed,
1116
-        );
1117
-        $offset       = ($current_page - 1) * $per_page;
1118
-        $limit        = array($offset, $per_page);
1119
-        if (isset($this->_req_data['s'])) {
1120
-            $sstr         = '%' . $this->_req_data['s'] . '%';
1121
-            $_where['OR'] = array(
1122
-                'TKT_name'        => array('LIKE', $sstr),
1123
-                'TKT_description' => array('LIKE', $sstr),
1124
-            );
1125
-        }
1126
-        $query_params = array(
1127
-            $_where,
1128
-            'order_by' => $orderby,
1129
-            'limit'    => $limit,
1130
-            'group_by' => 'TKT_ID',
1131
-        );
1132
-        if ($count) {
1133
-            return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1134
-        } else {
1135
-            return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1136
-        }
1137
-    }
1138
-
1139
-
1140
-
1141
-    /**
1142
-     * @param bool $trash
1143
-     */
1144
-    protected function _trash_or_restore_ticket($trash = false)
1145
-    {
1146
-        $success = 1;
1147
-        $TKT = EEM_Ticket::instance();
1148
-        //checkboxes?
1149
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1150
-            //if array has more than one element then success message should be plural
1151
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1152
-            //cycle thru the boxes
1153
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1154
-                if ($trash) {
1155
-                    if ( ! $TKT->delete_by_ID($TKT_ID)) {
1156
-                        $success = 0;
1157
-                    }
1158
-                } else {
1159
-                    if ( ! $TKT->restore_by_ID($TKT_ID)) {
1160
-                        $success = 0;
1161
-                    }
1162
-                }
1163
-            }
1164
-        } else {
1165
-            //grab single id and trash
1166
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1167
-            if ($trash) {
1168
-                if ( ! $TKT->delete_by_ID($TKT_ID)) {
1169
-                    $success = 0;
1170
-                }
1171
-            } else {
1172
-                if ( ! $TKT->restore_by_ID($TKT_ID)) {
1173
-                    $success = 0;
1174
-                }
1175
-            }
1176
-        }
1177
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1178
-        $query_args  = array(
1179
-            'action' => 'ticket_list_table',
1180
-            'status' => $trash ? '' : 'trashed',
1181
-        );
1182
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1183
-    }
1184
-
1185
-
1186
-
1187
-    protected function _delete_ticket()
1188
-    {
1189
-        $success = 1;
1190
-        //checkboxes?
1191
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1192
-            //if array has more than one element then success message should be plural
1193
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1194
-            //cycle thru the boxes
1195
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1196
-                //delete
1197
-                if ( ! $this->_delete_the_ticket($TKT_ID)) {
1198
-                    $success = 0;
1199
-                }
1200
-            }
1201
-        } else {
1202
-            //grab single id and trash
1203
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1204
-            if ( ! $this->_delete_the_ticket($TKT_ID)) {
1205
-                $success = 0;
1206
-            }
1207
-        }
1208
-        $action_desc = 'deleted';
1209
-        $query_args  = array(
1210
-            'action' => 'ticket_list_table',
1211
-            'status' => 'trashed',
1212
-        );
1213
-        //fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1214
-        if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1215
-            array(array('TKT_is_default' => 1)),
1216
-            'TKT_ID',
1217
-            true
1218
-        )
1219
-        ) {
1220
-            $query_args = array();
1221
-        }
1222
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1223
-    }
1224
-
1225
-
1226
-
1227
-    /**
1228
-     * @param int $TKT_ID
1229
-     * @return bool|int
1230
-     */
1231
-    protected function _delete_the_ticket($TKT_ID)
1232
-    {
1233
-        $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1234
-        $tkt->_remove_relations('Datetime');
1235
-        //delete all related prices first
1236
-        $tkt->delete_related_permanently('Price');
1237
-        return $tkt->delete_permanently();
1238
-    }
19
+	/**
20
+	 * Extend_Events_Admin_Page constructor.
21
+	 *
22
+	 * @param bool $routing
23
+	 */
24
+	public function __construct($routing = true)
25
+	{
26
+		parent::__construct($routing);
27
+		if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
31
+		}
32
+	}
33
+
34
+
35
+
36
+	protected function _extend_page_config()
37
+	{
38
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
39
+		//is there a evt_id in the request?
40
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
41
+			? $this->_req_data['EVT_ID']
42
+			: 0;
43
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
44
+		//tkt_id?
45
+		$tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
46
+			? $this->_req_data['TKT_ID']
47
+			: 0;
48
+		$new_page_routes = array(
49
+			'duplicate_event'          => array(
50
+				'func'       => '_duplicate_event',
51
+				'capability' => 'ee_edit_event',
52
+				'obj_id'     => $evt_id,
53
+				'noheader'   => true,
54
+			),
55
+			'ticket_list_table'        => array(
56
+				'func'       => '_tickets_overview_list_table',
57
+				'capability' => 'ee_read_default_tickets',
58
+			),
59
+			'trash_ticket'             => array(
60
+				'func'       => '_trash_or_restore_ticket',
61
+				'capability' => 'ee_delete_default_ticket',
62
+				'obj_id'     => $tkt_id,
63
+				'noheader'   => true,
64
+				'args'       => array('trash' => true),
65
+			),
66
+			'trash_tickets'            => array(
67
+				'func'       => '_trash_or_restore_ticket',
68
+				'capability' => 'ee_delete_default_tickets',
69
+				'noheader'   => true,
70
+				'args'       => array('trash' => true),
71
+			),
72
+			'restore_ticket'           => array(
73
+				'func'       => '_trash_or_restore_ticket',
74
+				'capability' => 'ee_delete_default_ticket',
75
+				'obj_id'     => $tkt_id,
76
+				'noheader'   => true,
77
+			),
78
+			'restore_tickets'          => array(
79
+				'func'       => '_trash_or_restore_ticket',
80
+				'capability' => 'ee_delete_default_tickets',
81
+				'noheader'   => true,
82
+			),
83
+			'delete_ticket'            => array(
84
+				'func'       => '_delete_ticket',
85
+				'capability' => 'ee_delete_default_ticket',
86
+				'obj_id'     => $tkt_id,
87
+				'noheader'   => true,
88
+			),
89
+			'delete_tickets'           => array(
90
+				'func'       => '_delete_ticket',
91
+				'capability' => 'ee_delete_default_tickets',
92
+				'noheader'   => true,
93
+			),
94
+			'import_page'              => array(
95
+				'func'       => '_import_page',
96
+				'capability' => 'import',
97
+			),
98
+			'import'                   => array(
99
+				'func'       => '_import_events',
100
+				'capability' => 'import',
101
+				'noheader'   => true,
102
+			),
103
+			'import_events'            => array(
104
+				'func'       => '_import_events',
105
+				'capability' => 'import',
106
+				'noheader'   => true,
107
+			),
108
+			'export_events'            => array(
109
+				'func'       => '_events_export',
110
+				'capability' => 'export',
111
+				'noheader'   => true,
112
+			),
113
+			'export_categories'        => array(
114
+				'func'       => '_categories_export',
115
+				'capability' => 'export',
116
+				'noheader'   => true,
117
+			),
118
+			'sample_export_file'       => array(
119
+				'func'       => '_sample_export_file',
120
+				'capability' => 'export',
121
+				'noheader'   => true,
122
+			),
123
+			'update_template_settings' => array(
124
+				'func'       => '_update_template_settings',
125
+				'capability' => 'manage_options',
126
+				'noheader'   => true,
127
+			),
128
+		);
129
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
130
+		//partial route/config override
131
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
132
+		$this->_page_config['create_new']['metaboxes'][]  = '_premium_event_editor_meta_boxes';
133
+		$this->_page_config['create_new']['qtips'][]      = 'EE_Event_Editor_Tips';
134
+		$this->_page_config['edit']['qtips'][]            = 'EE_Event_Editor_Tips';
135
+		$this->_page_config['edit']['metaboxes'][]        = '_premium_event_editor_meta_boxes';
136
+		$this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
137
+		//add tickets tab but only if there are more than one default ticket!
138
+		$tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
139
+			array(array('TKT_is_default' => 1)),
140
+			'TKT_ID',
141
+			true
142
+		);
143
+		if ($tkt_count > 1) {
144
+			$new_page_config = array(
145
+				'ticket_list_table' => array(
146
+					'nav'           => array(
147
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
148
+						'order' => 60,
149
+					),
150
+					'list_table'    => 'Tickets_List_Table',
151
+					'require_nonce' => false,
152
+				),
153
+			);
154
+		}
155
+		//template settings
156
+		$new_page_config['template_settings'] = array(
157
+			'nav'           => array(
158
+				'label' => esc_html__('Templates', 'event_espresso'),
159
+				'order' => 30,
160
+			),
161
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
162
+			'help_tabs'     => array(
163
+				'general_settings_templates_help_tab' => array(
164
+					'title'    => esc_html__('Templates', 'event_espresso'),
165
+					'filename' => 'general_settings_templates',
166
+				),
167
+			),
168
+			'help_tour'     => array('Templates_Help_Tour'),
169
+			'require_nonce' => false,
170
+		);
171
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
172
+		//add filters and actions
173
+		//modifying _views
174
+		add_filter(
175
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
176
+			array($this, 'add_additional_datetime_button'),
177
+			10,
178
+			2
179
+		);
180
+		add_filter(
181
+			'FHEE_event_datetime_metabox_clone_button_template',
182
+			array($this, 'add_datetime_clone_button'),
183
+			10,
184
+			2
185
+		);
186
+		add_filter(
187
+			'FHEE_event_datetime_metabox_timezones_template',
188
+			array($this, 'datetime_timezones_template'),
189
+			10,
190
+			2
191
+		);
192
+		//filters for event list table
193
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
194
+		add_filter(
195
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
196
+			array($this, 'extra_list_table_actions'),
197
+			10,
198
+			2
199
+		);
200
+		//legend item
201
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
202
+		add_action('admin_init', array($this, 'admin_init'));
203
+		//heartbeat stuff
204
+		add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2);
205
+	}
206
+
207
+
208
+
209
+	/**
210
+	 * admin_init
211
+	 */
212
+	public function admin_init()
213
+	{
214
+		EE_Registry::$i18n_js_strings = array_merge(
215
+			EE_Registry::$i18n_js_strings,
216
+			array(
217
+				'image_confirm'          => esc_html__(
218
+					'Do you really want to delete this image? Please remember to update your event to complete the removal.',
219
+					'event_espresso'
220
+				),
221
+				'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
222
+				'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
223
+				'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
224
+				'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
225
+				'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
226
+			)
227
+		);
228
+	}
229
+
230
+
231
+
232
+	/**
233
+	 * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
234
+	 * accordingly.
235
+	 *
236
+	 * @param array $response The existing heartbeat response array.
237
+	 * @param array $data     The incoming data package.
238
+	 * @return array  possibly appended response.
239
+	 */
240
+	public function heartbeat_response($response, $data)
241
+	{
242
+		/**
243
+		 * check whether count of tickets is approaching the potential
244
+		 * limits for the server.
245
+		 */
246
+		if ( ! empty($data['input_count'])) {
247
+			$response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
248
+				$data['input_count']
249
+			);
250
+		}
251
+		return $response;
252
+	}
253
+
254
+
255
+
256
+	protected function _add_screen_options_ticket_list_table()
257
+	{
258
+		$this->_per_page_screen_option();
259
+	}
260
+
261
+
262
+
263
+	/**
264
+	 * @param string $return
265
+	 * @param int    $id
266
+	 * @param string $new_title
267
+	 * @param string $new_slug
268
+	 * @return string
269
+	 */
270
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
271
+	{
272
+		$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
273
+		//make sure this is only when editing
274
+		if ( ! empty($id)) {
275
+			$href  = EE_Admin_Page::add_query_args_and_nonce(
276
+				array('action' => 'duplicate_event', 'EVT_ID' => $id),
277
+				$this->_admin_base_url
278
+			);
279
+			$title = esc_attr__('Duplicate Event', 'event_espresso');
280
+			$return .= '<a href="'
281
+					   . $href
282
+					   . '" title="'
283
+					   . $title
284
+					   . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
285
+					   . $title
286
+					   . '</button>';
287
+		}
288
+		return $return;
289
+	}
290
+
291
+
292
+
293
+	public function _set_list_table_views_ticket_list_table()
294
+	{
295
+		$this->_views = array(
296
+			'all'     => array(
297
+				'slug'        => 'all',
298
+				'label'       => esc_html__('All', 'event_espresso'),
299
+				'count'       => 0,
300
+				'bulk_action' => array(
301
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
302
+				),
303
+			),
304
+			'trashed' => array(
305
+				'slug'        => 'trashed',
306
+				'label'       => esc_html__('Trash', 'event_espresso'),
307
+				'count'       => 0,
308
+				'bulk_action' => array(
309
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
310
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
311
+				),
312
+			),
313
+		);
314
+	}
315
+
316
+
317
+
318
+	public function load_scripts_styles_edit()
319
+	{
320
+		wp_register_script(
321
+			'ee-event-editor-heartbeat',
322
+			EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
323
+			array('ee_admin_js', 'heartbeat'),
324
+			EVENT_ESPRESSO_VERSION,
325
+			true
326
+		);
327
+		wp_enqueue_script('ee-accounting');
328
+		//styles
329
+		wp_enqueue_style('espresso-ui-theme');
330
+		wp_enqueue_script('event_editor_js');
331
+		wp_enqueue_script('ee-event-editor-heartbeat');
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 * @param $template
338
+	 * @param $template_args
339
+	 * @return mixed
340
+	 */
341
+	public function add_additional_datetime_button($template, $template_args)
342
+	{
343
+		return EEH_Template::display_template(
344
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
345
+			$template_args,
346
+			true
347
+		);
348
+	}
349
+
350
+
351
+
352
+	/**
353
+	 * @param $template
354
+	 * @param $template_args
355
+	 * @return mixed
356
+	 */
357
+	public function add_datetime_clone_button($template, $template_args)
358
+	{
359
+		return EEH_Template::display_template(
360
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
361
+			$template_args,
362
+			true
363
+		);
364
+	}
365
+
366
+
367
+
368
+	/**
369
+	 * @param $template
370
+	 * @param $template_args
371
+	 * @return mixed
372
+	 */
373
+	public function datetime_timezones_template($template, $template_args)
374
+	{
375
+		return EEH_Template::display_template(
376
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
377
+			$template_args,
378
+			true
379
+		);
380
+	}
381
+
382
+
383
+
384
+	protected function _set_list_table_views_default()
385
+	{
386
+		parent::_set_list_table_views_default();
387
+		$new_views = array(
388
+			'today' => array(
389
+				'slug'        => 'today',
390
+				'label'       => esc_html__('Today', 'event_espresso'),
391
+				'count'       => $this->total_events_today(),
392
+				'bulk_action' => array(
393
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
394
+				),
395
+			),
396
+			'month' => array(
397
+				'slug'        => 'month',
398
+				'label'       => esc_html__('This Month', 'event_espresso'),
399
+				'count'       => $this->total_events_this_month(),
400
+				'bulk_action' => array(
401
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
402
+				),
403
+			),
404
+		);
405
+		$this->_views = array_merge($this->_views, $new_views);
406
+	}
407
+
408
+
409
+
410
+	/**
411
+	 * @param array     $action_links
412
+	 * @param \EE_Event $event
413
+	 * @return array
414
+	 */
415
+	public function extra_list_table_actions(array $action_links, \EE_Event $event)
416
+	{
417
+		if (
418
+		EE_Registry::instance()->CAP->current_user_can(
419
+			'ee_read_registrations',
420
+			'espresso_registrations_reports',
421
+			$event->ID()
422
+		)
423
+		) {
424
+			$reports_query_args = array(
425
+				'action' => 'reports',
426
+				'EVT_ID' => $event->ID(),
427
+			);
428
+			$reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
429
+			$action_links[]     = '<a href="'
430
+								  . $reports_link
431
+								  . '" title="'
432
+								  . esc_attr__('View Report', 'event_espresso')
433
+								  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
434
+								  . "\n\t";
435
+		}
436
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
437
+			EE_Registry::instance()->load_helper('MSG_Template');
438
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
439
+				'see_notifications_for',
440
+				null,
441
+				array('EVT_ID' => $event->ID())
442
+			);
443
+		}
444
+		return $action_links;
445
+	}
446
+
447
+
448
+
449
+	/**
450
+	 * @param $items
451
+	 * @return mixed
452
+	 */
453
+	public function additional_legend_items($items)
454
+	{
455
+		if (
456
+		EE_Registry::instance()->CAP->current_user_can(
457
+			'ee_read_registrations',
458
+			'espresso_registrations_reports'
459
+		)
460
+		) {
461
+			$items['reports'] = array(
462
+				'class' => 'dashicons dashicons-chart-bar',
463
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
464
+			);
465
+		}
466
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
467
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
468
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
469
+				$items['view_related_messages'] = array(
470
+					'class' => $related_for_icon['css_class'],
471
+					'desc'  => $related_for_icon['label'],
472
+				);
473
+			}
474
+		}
475
+		return $items;
476
+	}
477
+
478
+
479
+
480
+	/**
481
+	 * This is the callback method for the duplicate event route
482
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
483
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
484
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
485
+	 * After duplication the redirect is to the new event edit page.
486
+	 *
487
+	 * @return void
488
+	 * @access protected
489
+	 * @throws EE_Error If EE_Event is not available with given ID
490
+	 */
491
+	protected function _duplicate_event()
492
+	{
493
+		// first make sure the ID for the event is in the request.
494
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
495
+		if ( ! isset($this->_req_data['EVT_ID'])) {
496
+			EE_Error::add_error(
497
+				esc_html__(
498
+					'In order to duplicate an event an Event ID is required.  None was given.',
499
+					'event_espresso'
500
+				),
501
+				__FILE__,
502
+				__FUNCTION__,
503
+				__LINE__
504
+			);
505
+			$this->_redirect_after_action(false, '', '', array(), true);
506
+			return;
507
+		}
508
+		//k we've got EVT_ID so let's use that to get the event we'll duplicate
509
+		$orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
510
+		if ( ! $orig_event instanceof EE_Event) {
511
+			throw new EE_Error(
512
+				sprintf(
513
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
514
+					$this->_req_data['EVT_ID']
515
+				)
516
+			);
517
+		}
518
+		//k now let's clone the $orig_event before getting relations
519
+		$new_event = clone $orig_event;
520
+		//original datetimes
521
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
522
+		//other original relations
523
+		$orig_ven = $orig_event->get_many_related('Venue');
524
+		//reset the ID and modify other details to make it clear this is a dupe
525
+		$new_event->set('EVT_ID', 0);
526
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
527
+		$new_event->set('EVT_name', $new_name);
528
+		$new_event->set(
529
+			'EVT_slug',
530
+			wp_unique_post_slug(
531
+				sanitize_title($orig_event->name()),
532
+				0,
533
+				'publish',
534
+				'espresso_events',
535
+				0
536
+			)
537
+		);
538
+		$new_event->set('status', 'draft');
539
+		//duplicate discussion settings
540
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
541
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
542
+		//save the new event
543
+		$new_event->save();
544
+		//venues
545
+		foreach ($orig_ven as $ven) {
546
+			$new_event->_add_relation_to($ven, 'Venue');
547
+		}
548
+		$new_event->save();
549
+		//now we need to get the question group relations and handle that
550
+		//first primary question groups
551
+		$orig_primary_qgs = $orig_event->get_many_related(
552
+			'Question_Group',
553
+			array(array('Event_Question_Group.EQG_primary' => 1))
554
+		);
555
+		if ( ! empty($orig_primary_qgs)) {
556
+			foreach ($orig_primary_qgs as $id => $obj) {
557
+				if ($obj instanceof EE_Question_Group) {
558
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
559
+				}
560
+			}
561
+		}
562
+		//next additional attendee question groups
563
+		$orig_additional_qgs = $orig_event->get_many_related(
564
+			'Question_Group',
565
+			array(array('Event_Question_Group.EQG_primary' => 0))
566
+		);
567
+		if ( ! empty($orig_additional_qgs)) {
568
+			foreach ($orig_additional_qgs as $id => $obj) {
569
+				if ($obj instanceof EE_Question_Group) {
570
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
571
+				}
572
+			}
573
+		}
574
+		//now save
575
+		$new_event->save();
576
+		//k now that we have the new event saved we can loop through the datetimes and start adding relations.
577
+		$cloned_tickets = array();
578
+		foreach ($orig_datetimes as $orig_dtt) {
579
+			if ( ! $orig_dtt instanceof EE_Datetime) {
580
+				continue;
581
+			}
582
+			$new_dtt   = clone $orig_dtt;
583
+			$orig_tkts = $orig_dtt->tickets();
584
+			//save new dtt then add to event
585
+			$new_dtt->set('DTT_ID', 0);
586
+			$new_dtt->set('DTT_sold', 0);
587
+			$new_dtt->save();
588
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
589
+			$new_event->save();
590
+			//now let's get the ticket relations setup.
591
+			foreach ((array)$orig_tkts as $orig_tkt) {
592
+				//it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
593
+				if ( ! $orig_tkt instanceof EE_Ticket) {
594
+					continue;
595
+				}
596
+				//is this ticket archived?  If it is then let's skip
597
+				if ($orig_tkt->get('TKT_deleted')) {
598
+					continue;
599
+				}
600
+				// does this original ticket already exist in the clone_tickets cache?
601
+				//  If so we'll just use the new ticket from it.
602
+				if (isset($cloned_tickets[$orig_tkt->ID()])) {
603
+					$new_tkt = $cloned_tickets[$orig_tkt->ID()];
604
+				} else {
605
+					$new_tkt = clone $orig_tkt;
606
+					//get relations on the $orig_tkt that we need to setup.
607
+					$orig_prices = $orig_tkt->prices();
608
+					$new_tkt->set('TKT_ID', 0);
609
+					$new_tkt->set('TKT_sold', 0);
610
+					$new_tkt->set('TKT_reserved', 0);
611
+					$new_tkt->save(); //make sure new ticket has ID.
612
+					//price relations on new ticket need to be setup.
613
+					foreach ($orig_prices as $orig_price) {
614
+						$new_price = clone $orig_price;
615
+						$new_price->set('PRC_ID', 0);
616
+						$new_price->save();
617
+						$new_tkt->_add_relation_to($new_price, 'Price');
618
+						$new_tkt->save();
619
+					}
620
+				}
621
+				// k now we can add the new ticket as a relation to the new datetime
622
+				// and make sure its added to our cached $cloned_tickets array
623
+				// for use with later datetimes that have the same ticket.
624
+				$new_dtt->_add_relation_to($new_tkt, 'Ticket');
625
+				$new_dtt->save();
626
+				$cloned_tickets[$orig_tkt->ID()] = $new_tkt;
627
+			}
628
+		}
629
+		//clone taxonomy information
630
+		$taxonomies_to_clone_with = apply_filters(
631
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
632
+			array('espresso_event_categories', 'espresso_event_type', 'post_tag')
633
+		);
634
+		//get terms for original event (notice)
635
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
636
+		//loop through terms and add them to new event.
637
+		foreach ($orig_terms as $term) {
638
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
639
+		}
640
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
641
+		//now let's redirect to the edit page for this duplicated event if we have a new event id.
642
+		if ($new_event->ID()) {
643
+			$redirect_args = array(
644
+				'post'   => $new_event->ID(),
645
+				'action' => 'edit',
646
+			);
647
+			EE_Error::add_success(
648
+				esc_html__(
649
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
650
+					'event_espresso'
651
+				)
652
+			);
653
+		} else {
654
+			$redirect_args = array(
655
+				'action' => 'default',
656
+			);
657
+			EE_Error::add_error(
658
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
659
+				__FILE__,
660
+				__FUNCTION__,
661
+				__LINE__
662
+			);
663
+		}
664
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
665
+	}
666
+
667
+
668
+	protected function _import_page()
669
+	{
670
+		$title                                      = esc_html__('Import', 'event_espresso');
671
+		$intro                                      = esc_html__(
672
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
673
+			'event_espresso'
674
+		);
675
+		$form_url                                   = EVENTS_ADMIN_URL;
676
+		$action                                     = 'import_events';
677
+		$type                                       = 'csv';
678
+		$this->_template_args['form']               = EE_Import::instance()->upload_form(
679
+			$title, $intro, $form_url, $action, $type
680
+		);
681
+		$this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
682
+			array('action' => 'sample_export_file'),
683
+			$this->_admin_base_url
684
+		);
685
+		$content                                    = EEH_Template::display_template(
686
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
687
+			$this->_template_args,
688
+			true
689
+		);
690
+		$this->_template_args['admin_page_content'] = $content;
691
+		$this->display_admin_page_with_sidebar();
692
+	}
693
+
694
+
695
+
696
+	/**
697
+	 * _import_events
698
+	 * This handles displaying the screen and running imports for importing events.
699
+	 *
700
+	 * @return void
701
+	 */
702
+	protected function _import_events()
703
+	{
704
+		require_once(EE_CLASSES . 'EE_Import.class.php');
705
+		$success = EE_Import::instance()->import();
706
+		$this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 * _events_export
713
+	 * Will export all (or just the given event) to a Excel compatible file.
714
+	 *
715
+	 * @access protected
716
+	 * @return void
717
+	 */
718
+	protected function _events_export()
719
+	{
720
+		if (isset($this->_req_data['EVT_ID'])) {
721
+			$event_ids = $this->_req_data['EVT_ID'];
722
+		} elseif (isset($this->_req_data['EVT_IDs'])) {
723
+			$event_ids = $this->_req_data['EVT_IDs'];
724
+		} else {
725
+			$event_ids = null;
726
+		}
727
+		//todo: I don't like doing this but it'll do until we modify EE_Export Class.
728
+		$new_request_args = array(
729
+			'export' => 'report',
730
+			'action' => 'all_event_data',
731
+			'EVT_ID' => $event_ids,
732
+		);
733
+		$this->_req_data  = array_merge($this->_req_data, $new_request_args);
734
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
735
+			require_once(EE_CLASSES . 'EE_Export.class.php');
736
+			$EE_Export = EE_Export::instance($this->_req_data);
737
+			$EE_Export->export();
738
+		}
739
+	}
740
+
741
+
742
+
743
+	/**
744
+	 * handle category exports()
745
+	 *
746
+	 * @return void
747
+	 */
748
+	protected function _categories_export()
749
+	{
750
+		//todo: I don't like doing this but it'll do until we modify EE_Export Class.
751
+		$new_request_args = array(
752
+			'export'       => 'report',
753
+			'action'       => 'categories',
754
+			'category_ids' => $this->_req_data['EVT_CAT_ID'],
755
+		);
756
+		$this->_req_data  = array_merge($this->_req_data, $new_request_args);
757
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
758
+			require_once(EE_CLASSES . 'EE_Export.class.php');
759
+			$EE_Export = EE_Export::instance($this->_req_data);
760
+			$EE_Export->export();
761
+		}
762
+	}
763
+
764
+
765
+
766
+	/**
767
+	 * Creates a sample CSV file for importing
768
+	 */
769
+	protected function _sample_export_file()
770
+	{
771
+		//		require_once(EE_CLASSES . 'EE_Export.class.php');
772
+		EE_Export::instance()->export_sample();
773
+	}
774
+
775
+
776
+
777
+	/*************        Template Settings        *************/
778
+	protected function _template_settings()
779
+	{
780
+		$this->_template_args['values'] = $this->_yes_no_values;
781
+		/**
782
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
783
+		 * from General_Settings_Admin_Page to here.
784
+		 */
785
+		$this->_template_args = apply_filters(
786
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
787
+			$this->_template_args
788
+		);
789
+		$this->_set_add_edit_form_tags('update_template_settings');
790
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
791
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
792
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
793
+			$this->_template_args,
794
+			true
795
+		);
796
+		$this->display_admin_page_with_sidebar();
797
+	}
798
+
799
+
800
+
801
+	protected function _update_template_settings()
802
+	{
803
+		/**
804
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
805
+		 * from General_Settings_Admin_Page to here.
806
+		 */
807
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
808
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
809
+			EE_Registry::instance()->CFG->template_settings,
810
+			$this->_req_data
811
+		);
812
+		//update custom post type slugs and detect if we need to flush rewrite rules
813
+		$old_slug                                          = EE_Registry::instance()->CFG->core->event_cpt_slug;
814
+		EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
815
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
816
+			: sanitize_title_with_dashes($this->_req_data['event_cpt_slug']);
817
+		$what                                              = 'Template Settings';
818
+		$success                                           = $this->_update_espresso_configuration(
819
+			$what,
820
+			EE_Registry::instance()->CFG->template_settings,
821
+			__FILE__,
822
+			__FUNCTION__,
823
+			__LINE__
824
+		);
825
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
826
+			update_option('ee_flush_rewrite_rules', true);
827
+		}
828
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
829
+	}
830
+
831
+
832
+
833
+	/**
834
+	 * _premium_event_editor_meta_boxes
835
+	 * add all metaboxes related to the event_editor
836
+	 *
837
+	 * @access protected
838
+	 * @return void
839
+	 */
840
+	protected function _premium_event_editor_meta_boxes()
841
+	{
842
+		$this->verify_cpt_object();
843
+		add_meta_box(
844
+			'espresso_event_editor_event_options',
845
+			esc_html__('Event Registration Options', 'event_espresso'),
846
+			array($this, 'registration_options_meta_box'),
847
+			$this->page_slug,
848
+			'side',
849
+			'core'
850
+		);
851
+	}
852
+
853
+
854
+
855
+	/**
856
+	 * override caf metabox
857
+	 *
858
+	 * @return void
859
+	 */
860
+	public function registration_options_meta_box()
861
+	{
862
+		$yes_no_values = array(
863
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
864
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
865
+		);
866
+		$default_reg_status_values = EEM_Registration::reg_status_array(
867
+			array(
868
+				EEM_Registration::status_id_cancelled,
869
+				EEM_Registration::status_id_declined,
870
+				EEM_Registration::status_id_incomplete,
871
+				EEM_Registration::status_id_wait_list,
872
+			),
873
+			true
874
+		);
875
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
876
+		$template_args['_event']                          = $this->_cpt_model_obj;
877
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
878
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
879
+			'default_reg_status',
880
+			$default_reg_status_values,
881
+			$this->_cpt_model_obj->default_registration_status()
882
+		);
883
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
884
+			'display_desc',
885
+			$yes_no_values,
886
+			$this->_cpt_model_obj->display_description()
887
+		);
888
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
889
+			'display_ticket_selector',
890
+			$yes_no_values,
891
+			$this->_cpt_model_obj->display_ticket_selector(),
892
+			'',
893
+			'',
894
+			false
895
+		);
896
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
897
+			'EVT_default_registration_status',
898
+			$default_reg_status_values,
899
+			$this->_cpt_model_obj->default_registration_status()
900
+		);
901
+		$template_args['additional_registration_options'] = apply_filters(
902
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
903
+			'',
904
+			$template_args,
905
+			$yes_no_values,
906
+			$default_reg_status_values
907
+		);
908
+		EEH_Template::display_template(
909
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
910
+			$template_args
911
+		);
912
+	}
913
+
914
+
915
+
916
+	/**
917
+	 * wp_list_table_mods for caf
918
+	 * ============================
919
+	 */
920
+	/**
921
+	 * hook into list table filters and provide filters for caffeinated list table
922
+	 *
923
+	 * @param  array $old_filters    any existing filters present
924
+	 * @param  array $list_table_obj the list table object
925
+	 * @return array                  new filters
926
+	 */
927
+	public function list_table_filters($old_filters, $list_table_obj)
928
+	{
929
+		$filters = array();
930
+		//first month/year filters
931
+		$filters[] = $this->espresso_event_months_dropdown();
932
+		$status    = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
933
+		//active status dropdown
934
+		if ($status !== 'draft') {
935
+			$filters[] = $this->active_status_dropdown(
936
+				isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
937
+			);
938
+		}
939
+		//category filter
940
+		$filters[] = $this->category_dropdown();
941
+		return array_merge($old_filters, $filters);
942
+	}
943
+
944
+
945
+
946
+	/**
947
+	 * espresso_event_months_dropdown
948
+	 *
949
+	 * @access public
950
+	 * @return string                dropdown listing month/year selections for events.
951
+	 */
952
+	public function espresso_event_months_dropdown()
953
+	{
954
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
955
+		// Note we need to include any other filters that are set!
956
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
957
+		//categories?
958
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
959
+			? $this->_req_data['EVT_CAT']
960
+			: null;
961
+		//active status?
962
+		$active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
963
+		$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
964
+		return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
965
+	}
966
+
967
+
968
+
969
+	/**
970
+	 * returns a list of "active" statuses on the event
971
+	 *
972
+	 * @param  string $current_value whatever the current active status is
973
+	 * @return string
974
+	 */
975
+	public function active_status_dropdown($current_value = '')
976
+	{
977
+		$select_name = 'active_status';
978
+		$values      = array(
979
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
980
+			'active'   => esc_html__('Active', 'event_espresso'),
981
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
982
+			'expired'  => esc_html__('Expired', 'event_espresso'),
983
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
984
+		);
985
+		$id          = 'id="espresso-active-status-dropdown-filter"';
986
+		$class       = 'wide';
987
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
988
+	}
989
+
990
+
991
+
992
+	/**
993
+	 * output a dropdown of the categories for the category filter on the event admin list table
994
+	 *
995
+	 * @access  public
996
+	 * @return string html
997
+	 */
998
+	public function category_dropdown()
999
+	{
1000
+		$cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1001
+		return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1002
+	}
1003
+
1004
+
1005
+
1006
+	/**
1007
+	 * get total number of events today
1008
+	 *
1009
+	 * @access public
1010
+	 * @return int
1011
+	 */
1012
+	public function total_events_today()
1013
+	{
1014
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1015
+			'DTT_EVT_start',
1016
+			date('Y-m-d') . ' 00:00:00',
1017
+			'Y-m-d H:i:s',
1018
+			'UTC'
1019
+		);
1020
+		$end   = EEM_Datetime::instance()->convert_datetime_for_query(
1021
+			'DTT_EVT_start',
1022
+			date('Y-m-d') . ' 23:59:59',
1023
+			'Y-m-d H:i:s',
1024
+			'UTC'
1025
+		);
1026
+		$where = array(
1027
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1028
+		);
1029
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1030
+		return $count;
1031
+	}
1032
+
1033
+
1034
+
1035
+	/**
1036
+	 * get total number of events this month
1037
+	 *
1038
+	 * @access public
1039
+	 * @return int
1040
+	 */
1041
+	public function total_events_this_month()
1042
+	{
1043
+		//Dates
1044
+		$this_year_r     = date('Y');
1045
+		$this_month_r    = date('m');
1046
+		$days_this_month = date('t');
1047
+		$start           = EEM_Datetime::instance()->convert_datetime_for_query(
1048
+			'DTT_EVT_start',
1049
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1050
+			'Y-m-d H:i:s',
1051
+			'UTC'
1052
+		);
1053
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1054
+			'DTT_EVT_start',
1055
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1056
+			'Y-m-d H:i:s',
1057
+			'UTC'
1058
+		);
1059
+		$where = array(
1060
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1061
+		);
1062
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1063
+		return $count;
1064
+	}
1065
+
1066
+
1067
+
1068
+	/** DEFAULT TICKETS STUFF **/
1069
+	public function _tickets_overview_list_table()
1070
+	{
1071
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1072
+		$this->display_admin_list_table_page_with_no_sidebar();
1073
+	}
1074
+
1075
+
1076
+
1077
+	/**
1078
+	 * @param int  $per_page
1079
+	 * @param bool $count
1080
+	 * @param bool $trashed
1081
+	 * @return \EE_Soft_Delete_Base_Class[]|int
1082
+	 */
1083
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1084
+	{
1085
+		$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1086
+		$order   = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1087
+		switch ($orderby) {
1088
+			case 'TKT_name' :
1089
+				$orderby = array('TKT_name' => $order);
1090
+				break;
1091
+			case 'TKT_price' :
1092
+				$orderby = array('TKT_price' => $order);
1093
+				break;
1094
+			case 'TKT_uses' :
1095
+				$orderby = array('TKT_uses' => $order);
1096
+				break;
1097
+			case 'TKT_min' :
1098
+				$orderby = array('TKT_min' => $order);
1099
+				break;
1100
+			case 'TKT_max' :
1101
+				$orderby = array('TKT_max' => $order);
1102
+				break;
1103
+			case 'TKT_qty' :
1104
+				$orderby = array('TKT_qty' => $order);
1105
+				break;
1106
+		}
1107
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1108
+			? $this->_req_data['paged']
1109
+			: 1;
1110
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1111
+			? $this->_req_data['perpage']
1112
+			: $per_page;
1113
+		$_where       = array(
1114
+			'TKT_is_default' => 1,
1115
+			'TKT_deleted'    => $trashed,
1116
+		);
1117
+		$offset       = ($current_page - 1) * $per_page;
1118
+		$limit        = array($offset, $per_page);
1119
+		if (isset($this->_req_data['s'])) {
1120
+			$sstr         = '%' . $this->_req_data['s'] . '%';
1121
+			$_where['OR'] = array(
1122
+				'TKT_name'        => array('LIKE', $sstr),
1123
+				'TKT_description' => array('LIKE', $sstr),
1124
+			);
1125
+		}
1126
+		$query_params = array(
1127
+			$_where,
1128
+			'order_by' => $orderby,
1129
+			'limit'    => $limit,
1130
+			'group_by' => 'TKT_ID',
1131
+		);
1132
+		if ($count) {
1133
+			return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1134
+		} else {
1135
+			return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1136
+		}
1137
+	}
1138
+
1139
+
1140
+
1141
+	/**
1142
+	 * @param bool $trash
1143
+	 */
1144
+	protected function _trash_or_restore_ticket($trash = false)
1145
+	{
1146
+		$success = 1;
1147
+		$TKT = EEM_Ticket::instance();
1148
+		//checkboxes?
1149
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1150
+			//if array has more than one element then success message should be plural
1151
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1152
+			//cycle thru the boxes
1153
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1154
+				if ($trash) {
1155
+					if ( ! $TKT->delete_by_ID($TKT_ID)) {
1156
+						$success = 0;
1157
+					}
1158
+				} else {
1159
+					if ( ! $TKT->restore_by_ID($TKT_ID)) {
1160
+						$success = 0;
1161
+					}
1162
+				}
1163
+			}
1164
+		} else {
1165
+			//grab single id and trash
1166
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1167
+			if ($trash) {
1168
+				if ( ! $TKT->delete_by_ID($TKT_ID)) {
1169
+					$success = 0;
1170
+				}
1171
+			} else {
1172
+				if ( ! $TKT->restore_by_ID($TKT_ID)) {
1173
+					$success = 0;
1174
+				}
1175
+			}
1176
+		}
1177
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1178
+		$query_args  = array(
1179
+			'action' => 'ticket_list_table',
1180
+			'status' => $trash ? '' : 'trashed',
1181
+		);
1182
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1183
+	}
1184
+
1185
+
1186
+
1187
+	protected function _delete_ticket()
1188
+	{
1189
+		$success = 1;
1190
+		//checkboxes?
1191
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1192
+			//if array has more than one element then success message should be plural
1193
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1194
+			//cycle thru the boxes
1195
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1196
+				//delete
1197
+				if ( ! $this->_delete_the_ticket($TKT_ID)) {
1198
+					$success = 0;
1199
+				}
1200
+			}
1201
+		} else {
1202
+			//grab single id and trash
1203
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1204
+			if ( ! $this->_delete_the_ticket($TKT_ID)) {
1205
+				$success = 0;
1206
+			}
1207
+		}
1208
+		$action_desc = 'deleted';
1209
+		$query_args  = array(
1210
+			'action' => 'ticket_list_table',
1211
+			'status' => 'trashed',
1212
+		);
1213
+		//fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1214
+		if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1215
+			array(array('TKT_is_default' => 1)),
1216
+			'TKT_ID',
1217
+			true
1218
+		)
1219
+		) {
1220
+			$query_args = array();
1221
+		}
1222
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1223
+	}
1224
+
1225
+
1226
+
1227
+	/**
1228
+	 * @param int $TKT_ID
1229
+	 * @return bool|int
1230
+	 */
1231
+	protected function _delete_the_ticket($TKT_ID)
1232
+	{
1233
+		$tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1234
+		$tkt->_remove_relations('Datetime');
1235
+		//delete all related prices first
1236
+		$tkt->delete_related_permanently('Price');
1237
+		return $tkt->delete_permanently();
1238
+	}
1239 1239
 
1240 1240
 
1241 1241
 
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Proper.form.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      */
85 85
     public function __construct($options_array = array())
86 86
     {
87
-        $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array,
87
+        $options_array = (array) apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array,
88 88
             $this);
89 89
         //call parent first, as it may be setting the name
90 90
         parent::__construct($options_array);
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
         if (isset($options_array['layout_strategy'])) {
108 108
             $this->_layout_strategy = $options_array['layout_strategy'];
109 109
         }
110
-        if (! $this->_layout_strategy) {
110
+        if ( ! $this->_layout_strategy) {
111 111
             $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
112 112
         }
113 113
         $this->_layout_strategy->_construct_finalize($this);
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
         if ($validate) {
259 259
             $this->_validate();
260 260
             //if it's invalid, we're going to want to re-display so remember what they submitted
261
-            if (! $this->is_valid()) {
261
+            if ( ! $this->is_valid()) {
262 262
                 $this->store_submitted_form_data_in_session();
263 263
             }
264 264
         }
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
     public function get_input($name, $require_construction_to_be_finalized = true)
439 439
     {
440 440
         $subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
441
-        if (! $subsection instanceof EE_Form_Input_Base) {
441
+        if ( ! $subsection instanceof EE_Form_Input_Base) {
442 442
             throw new EE_Error(
443 443
                 sprintf(
444 444
                     __(
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
     public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
474 474
     {
475 475
         $subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
476
-        if (! $subsection instanceof EE_Form_Section_Proper) {
476
+        if ( ! $subsection instanceof EE_Form_Section_Proper) {
477 477
             throw new EE_Error(
478 478
                 sprintf(
479 479
                     __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'),
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
      */
512 512
     public function is_valid()
513 513
     {
514
-        if (! $this->has_received_submission()) {
514
+        if ( ! $this->has_received_submission()) {
515 515
             throw new EE_Error(
516 516
                 sprintf(
517 517
                     __(
@@ -521,14 +521,14 @@  discard block
 block discarded – undo
521 521
                 )
522 522
             );
523 523
         }
524
-        if (! parent::is_valid()) {
524
+        if ( ! parent::is_valid()) {
525 525
             return false;
526 526
         }
527 527
         // ok so no general errors to this entire form section.
528 528
         // so let's check the subsections, but only set errors if that hasn't been done yet
529 529
         $set_submission_errors = $this->submission_error_message() === '' ? true : false;
530 530
         foreach ($this->get_validatable_subsections() as $subsection) {
531
-            if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') {
531
+            if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') {
532 532
                 if ($set_submission_errors) {
533 533
                     $this->set_submission_error_message($subsection->get_validation_error_string());
534 534
                 }
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
      */
548 548
     protected function _set_default_name_if_empty()
549 549
     {
550
-        if (! $this->_name) {
550
+        if ( ! $this->_name) {
551 551
             $classname = get_class($this);
552 552
             $default_name = str_replace("EE_", "", $classname);
553 553
             $this->_name = $default_name;
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
     {
633 633
         wp_register_script(
634 634
             'ee_form_section_validation',
635
-            EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
635
+            EE_GLOBAL_ASSETS_URL.'scripts'.DS.'form_section_validation.js',
636 636
             array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
637 637
             EVENT_ESPRESSO_VERSION,
638 638
             true
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
      */
779 779
     public function ensure_scripts_localized()
780 780
     {
781
-        if (! EE_Form_Section_Proper::$_scripts_localized) {
781
+        if ( ! EE_Form_Section_Proper::$_scripts_localized) {
782 782
             $this->_enqueue_and_localize_form_js();
783 783
         }
784 784
     }
@@ -874,8 +874,8 @@  discard block
 block discarded – undo
874 874
     protected function _validate()
875 875
     {
876 876
         foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
877
-            if (method_exists($this, '_validate_' . $subsection_name)) {
878
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
877
+            if (method_exists($this, '_validate_'.$subsection_name)) {
878
+                call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection));
879 879
             }
880 880
             $subsection->_validate();
881 881
         }
@@ -1151,7 +1151,7 @@  discard block
 block discarded – undo
1151 1151
     public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1152 1152
     {
1153 1153
         foreach ($new_subsections as $subsection_name => $subsection) {
1154
-            if (! $subsection instanceof EE_Form_Section_Base) {
1154
+            if ( ! $subsection instanceof EE_Form_Section_Base) {
1155 1155
                 EE_Error::add_error(
1156 1156
                     sprintf(
1157 1157
                         __(
@@ -1249,7 +1249,7 @@  discard block
 block discarded – undo
1249 1249
     public function html_name_prefix()
1250 1250
     {
1251 1251
         if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1252
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1252
+            return $this->parent_section()->html_name_prefix().'['.$this->name().']';
1253 1253
         } else {
1254 1254
             return $this->name();
1255 1255
         }
@@ -1293,7 +1293,7 @@  discard block
 block discarded – undo
1293 1293
      */
1294 1294
     public function ensure_construct_finalized_called()
1295 1295
     {
1296
-        if (! $this->_construction_finalized) {
1296
+        if ( ! $this->_construction_finalized) {
1297 1297
             $this->_construct_finalize($this->_parent_section, $this->_name);
1298 1298
         }
1299 1299
     }
Please login to merge, or discard this patch.
Indentation   +1379 added lines, -1379 removed lines patch added patch discarded remove patch
@@ -11,1385 +11,1385 @@
 block discarded – undo
11 11
 class EE_Form_Section_Proper extends EE_Form_Section_Validatable
12 12
 {
13 13
 
14
-    const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
15
-
16
-    /**
17
-     * Subsections
18
-     *
19
-     * @var EE_Form_Section_Validatable[]
20
-     */
21
-    protected $_subsections = array();
22
-
23
-    /**
24
-     * Strategy for laying out the form
25
-     *
26
-     * @var EE_Form_Section_Layout_Base
27
-     */
28
-    protected $_layout_strategy;
29
-
30
-    /**
31
-     * Whether or not this form has received and validated a form submission yet
32
-     *
33
-     * @var boolean
34
-     */
35
-    protected $_received_submission = false;
36
-
37
-    /**
38
-     * message displayed to users upon successful form submission
39
-     *
40
-     * @var string
41
-     */
42
-    protected $_form_submission_success_message = '';
43
-
44
-    /**
45
-     * message displayed to users upon unsuccessful form submission
46
-     *
47
-     * @var string
48
-     */
49
-    protected $_form_submission_error_message = '';
50
-
51
-    /**
52
-     * Stores all the data that will localized for form validation
53
-     *
54
-     * @var array
55
-     */
56
-    static protected $_js_localization = array();
57
-
58
-    /**
59
-     * whether or not the form's localized validation JS vars have been set
60
-     *
61
-     * @type boolean
62
-     */
63
-    static protected $_scripts_localized = false;
64
-
65
-
66
-
67
-    /**
68
-     * when constructing a proper form section, calls _construct_finalize on children
69
-     * so that they know who their parent is, and what name they've been given.
70
-     *
71
-     * @param array $options_array   {
72
-     * @type        $subsections     EE_Form_Section_Validatable[] where keys are the section's name
73
-     * @type        $include         string[] numerically-indexed where values are section names to be included,
74
-     *                               and in that order. This is handy if you want
75
-     *                               the subsections to be ordered differently than the default, and if you override
76
-     *                               which fields are shown
77
-     * @type        $exclude         string[] values are subsections to be excluded. This is handy if you want
78
-     *                               to remove certain default subsections (note: if you specify BOTH 'include' AND
79
-     *                               'exclude', the inclusions will be applied first, and the exclusions will exclude
80
-     *                               items from that list of inclusions)
81
-     * @type        $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
82
-     *                               } @see EE_Form_Section_Validatable::__construct()
83
-     * @throws \EE_Error
84
-     */
85
-    public function __construct($options_array = array())
86
-    {
87
-        $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array,
88
-            $this);
89
-        //call parent first, as it may be setting the name
90
-        parent::__construct($options_array);
91
-        //if they've included subsections in the constructor, add them now
92
-        if (isset($options_array['include'])) {
93
-            //we are going to make sure we ONLY have those subsections to include
94
-            //AND we are going to make sure they're in that specified order
95
-            $reordered_subsections = array();
96
-            foreach ($options_array['include'] as $input_name) {
97
-                if (isset($this->_subsections[$input_name])) {
98
-                    $reordered_subsections[$input_name] = $this->_subsections[$input_name];
99
-                }
100
-            }
101
-            $this->_subsections = $reordered_subsections;
102
-        }
103
-        if (isset($options_array['exclude'])) {
104
-            $exclude = $options_array['exclude'];
105
-            $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
106
-        }
107
-        if (isset($options_array['layout_strategy'])) {
108
-            $this->_layout_strategy = $options_array['layout_strategy'];
109
-        }
110
-        if (! $this->_layout_strategy) {
111
-            $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
112
-        }
113
-        $this->_layout_strategy->_construct_finalize($this);
114
-        //ok so we are definitely going to want the forms JS,
115
-        //so enqueue it or remember to enqueue it during wp_enqueue_scripts
116
-        if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
117
-            //ok so they've constructed this object after when they should have.
118
-            //just enqueue the generic form scripts and initialize the form immediately in the JS
119
-            \EE_Form_Section_Proper::wp_enqueue_scripts(true);
120
-        } else {
121
-            add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
122
-            add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
123
-        }
124
-        add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
125
-
126
-        /**
127
-         * Gives other plugins a chance to hook in before construct finalize is called. The form probably doesn't
128
-         * yet have a parent form section. Since 4.9.32, when this action was introduced, this is the best place to
129
-         * add a subsection onto a form, assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
130
-         * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
131
-         * @since 4.9.32
132
-         * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, except maybe calling
133
-         *                                      _construct_finalize has been done
134
-         * @param array $options_array options passed into the constructor
135
-         */
136
-        do_action('AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', $this, $options_array);
137
-
138
-        if (isset($options_array['name'])) {
139
-            $this->_construct_finalize(null, $options_array['name']);
140
-        }
141
-    }
142
-
143
-
144
-
145
-    /**
146
-     * Finishes construction given the parent form section and this form section's name
147
-     *
148
-     * @param EE_Form_Section_Proper $parent_form_section
149
-     * @param string                 $name
150
-     * @throws \EE_Error
151
-     */
152
-    public function _construct_finalize($parent_form_section, $name)
153
-    {
154
-        parent::_construct_finalize($parent_form_section, $name);
155
-        $this->_set_default_name_if_empty();
156
-        $this->_set_default_html_id_if_empty();
157
-        foreach ($this->_subsections as $subsection_name => $subsection) {
158
-            if ($subsection instanceof EE_Form_Section_Base) {
159
-                $subsection->_construct_finalize($this, $subsection_name);
160
-            } else {
161
-                throw new EE_Error(
162
-                    sprintf(
163
-                        __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
164
-                            'event_espresso'),
165
-                        $subsection_name,
166
-                        get_class($this),
167
-                        $subsection ? get_class($subsection) : __('NULL', 'event_espresso')
168
-                    )
169
-                );
170
-            }
171
-        }
172
-        /**
173
-         * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
174
-         * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID (or other attributes derived
175
-         * from the name like the HTML label id, etc), this is where it should be done.
176
-         * This might only happen just before displaying the form, or just before it receives form submission data.
177
-         * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
178
-         * ensured it has a name, HTML IDs, etc
179
-         * @param EE_Form_Section_Proper $this
180
-         * @param EE_Form_Section_Proper|null $parent_form_section
181
-         * @param string $name
182
-         */
183
-        do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name);
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * Gets the layout strategy for this form section
190
-     *
191
-     * @return EE_Form_Section_Layout_Base
192
-     */
193
-    public function get_layout_strategy()
194
-    {
195
-        return $this->_layout_strategy;
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * Gets the HTML for a single input for this form section according
202
-     * to the layout strategy
203
-     *
204
-     * @param EE_Form_Input_Base $input
205
-     * @return string
206
-     */
207
-    public function get_html_for_input($input)
208
-    {
209
-        return $this->_layout_strategy->layout_input($input);
210
-    }
211
-
212
-
213
-
214
-    /**
215
-     * was_submitted - checks if form inputs are present in request data
216
-     * Basically an alias for form_data_present_in() (which is used by both
217
-     * proper form sections and form inputs)
218
-     *
219
-     * @param null $form_data
220
-     * @return boolean
221
-     */
222
-    public function was_submitted($form_data = null)
223
-    {
224
-        return $this->form_data_present_in($form_data);
225
-    }
226
-
227
-
228
-
229
-    /**
230
-     * After the form section is initially created, call this to sanitize the data in the submission
231
-     * which relates to this form section, validate it, and set it as properties on the form.
232
-     *
233
-     * @param array|null $req_data should usually be $_POST (the default).
234
-     *                             However, you CAN supply a different array.
235
-     *                             Consider using set_defaults() instead however.
236
-     *                             (If you rendered the form in the page using echo $form_x->get_html()
237
-     *                             the inputs will have the correct name in the request data for this function
238
-     *                             to find them and populate the form with them.
239
-     *                             If you have a flat form (with only input subsections),
240
-     *                             you can supply a flat array where keys
241
-     *                             are the form input names and values are their values)
242
-     * @param boolean    $validate whether or not to perform validation on this data. Default is,
243
-     *                             of course, to validate that data, and set errors on the invalid values.
244
-     *                             But if the data has already been validated
245
-     *                             (eg you validated the data then stored it in the DB)
246
-     *                             you may want to skip this step.
247
-     */
248
-    public function receive_form_submission($req_data = null, $validate = true)
249
-    {
250
-        $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this,
251
-            $validate);
252
-        if ($req_data === null) {
253
-            $req_data = array_merge($_GET, $_POST);
254
-        }
255
-        $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data,
256
-            $this);
257
-        $this->_normalize($req_data);
258
-        if ($validate) {
259
-            $this->_validate();
260
-            //if it's invalid, we're going to want to re-display so remember what they submitted
261
-            if (! $this->is_valid()) {
262
-                $this->store_submitted_form_data_in_session();
263
-            }
264
-        }
265
-        do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate);
266
-    }
267
-
268
-
269
-
270
-    /**
271
-     * caches the originally submitted input values in the session
272
-     * so that they can be used to repopulate the form if it failed validation
273
-     *
274
-     * @return boolean whether or not the data was successfully stored in the session
275
-     */
276
-    protected function store_submitted_form_data_in_session()
277
-    {
278
-        return EE_Registry::instance()->SSN->set_session_data(
279
-            array(
280
-                \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
281
-            )
282
-        );
283
-    }
284
-
285
-
286
-
287
-    /**
288
-     * retrieves the originally submitted input values in the session
289
-     * so that they can be used to repopulate the form if it failed validation
290
-     *
291
-     * @return array
292
-     */
293
-    protected function get_submitted_form_data_from_session()
294
-    {
295
-        $session = EE_Registry::instance()->SSN;
296
-        if ($session instanceof EE_Session) {
297
-            return $session->get_session_data(
298
-                \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
299
-            );
300
-        } else {
301
-            return array();
302
-        }
303
-    }
304
-
305
-
306
-
307
-    /**
308
-     * flushed the originally submitted input values from the session
309
-     *
310
-     * @return boolean whether or not the data was successfully removed from the session
311
-     */
312
-    protected function flush_submitted_form_data_from_session()
313
-    {
314
-        return EE_Registry::instance()->SSN->reset_data(
315
-            array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
316
-        );
317
-    }
318
-
319
-
320
-
321
-    /**
322
-     * Populates this form and its subsections with data from the session.
323
-     * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
324
-     * validation errors when displaying too)
325
-     * Returns true if the form was populated from the session, false otherwise
326
-     *
327
-     * @return boolean
328
-     */
329
-    public function populate_from_session()
330
-    {
331
-        $form_data_in_session = $this->get_submitted_form_data_from_session();
332
-        if (empty($form_data_in_session)) {
333
-            return false;
334
-        }
335
-        $this->receive_form_submission($form_data_in_session);
336
-        $this->flush_submitted_form_data_from_session();
337
-        if ($this->form_data_present_in($form_data_in_session)) {
338
-            return true;
339
-        } else {
340
-            return false;
341
-        }
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     * Populates the default data for the form, given an array where keys are
348
-     * the input names, and values are their values (preferably normalized to be their
349
-     * proper PHP types, not all strings... although that should be ok too).
350
-     * Proper subsections are sub-arrays, the key being the subsection's name, and
351
-     * the value being an array formatted in teh same way
352
-     *
353
-     * @param array $default_data
354
-     */
355
-    public function populate_defaults($default_data)
356
-    {
357
-        foreach ($this->subsections(false) as $subsection_name => $subsection) {
358
-            if (isset($default_data[$subsection_name])) {
359
-                if ($subsection instanceof EE_Form_Input_Base) {
360
-                    $subsection->set_default($default_data[$subsection_name]);
361
-                } elseif ($subsection instanceof EE_Form_Section_Proper) {
362
-                    $subsection->populate_defaults($default_data[$subsection_name]);
363
-                }
364
-            }
365
-        }
366
-    }
367
-
368
-
369
-
370
-    /**
371
-     * returns true if subsection exists
372
-     *
373
-     * @param string $name
374
-     * @return boolean
375
-     */
376
-    public function subsection_exists($name)
377
-    {
378
-        return isset($this->_subsections[$name]) ? true : false;
379
-    }
380
-
381
-
382
-
383
-    /**
384
-     * Gets the subsection specified by its name
385
-     *
386
-     * @param string  $name
387
-     * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
388
-     *                                                      so that the inputs will be properly configured.
389
-     *                                                      However, some client code may be ok
390
-     *                                                      with construction finalize being called later
391
-     *                                                      (realizing that the subsections' html names
392
-     *                                                      might not be set yet, etc.)
393
-     * @return EE_Form_Section_Base
394
-     * @throws \EE_Error
395
-     */
396
-    public function get_subsection($name, $require_construction_to_be_finalized = true)
397
-    {
398
-        if ($require_construction_to_be_finalized) {
399
-            $this->ensure_construct_finalized_called();
400
-        }
401
-        return $this->subsection_exists($name) ? $this->_subsections[$name] : null;
402
-    }
403
-
404
-
405
-
406
-    /**
407
-     * Gets all the validatable subsections of this form section
408
-     *
409
-     * @return EE_Form_Section_Validatable[]
410
-     */
411
-    public function get_validatable_subsections()
412
-    {
413
-        $validatable_subsections = array();
414
-        foreach ($this->subsections() as $name => $obj) {
415
-            if ($obj instanceof EE_Form_Section_Validatable) {
416
-                $validatable_subsections[$name] = $obj;
417
-            }
418
-        }
419
-        return $validatable_subsections;
420
-    }
421
-
422
-
423
-
424
-    /**
425
-     * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
426
-     * throw an EE_Error.
427
-     *
428
-     * @param string  $name
429
-     * @param boolean $require_construction_to_be_finalized most client code should
430
-     *                                                      leave this as TRUE so that the inputs will be properly
431
-     *                                                      configured. However, some client code may be ok with
432
-     *                                                      construction finalize being called later
433
-     *                                                      (realizing that the subsections' html names might not be
434
-     *                                                      set yet, etc.)
435
-     * @return EE_Form_Input_Base
436
-     * @throws EE_Error
437
-     */
438
-    public function get_input($name, $require_construction_to_be_finalized = true)
439
-    {
440
-        $subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
441
-        if (! $subsection instanceof EE_Form_Input_Base) {
442
-            throw new EE_Error(
443
-                sprintf(
444
-                    __(
445
-                        "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
446
-                        'event_espresso'
447
-                    ),
448
-                    $name,
449
-                    get_class($this),
450
-                    $subsection ? get_class($subsection) : __("NULL", 'event_espresso')
451
-                )
452
-            );
453
-        }
454
-        return $subsection;
455
-    }
456
-
457
-
458
-
459
-    /**
460
-     * Like get_input(), gets the proper subsection of the form given the name,
461
-     * otherwise throws an EE_Error
462
-     *
463
-     * @param string  $name
464
-     * @param boolean $require_construction_to_be_finalized most client code should
465
-     *                                                      leave this as TRUE so that the inputs will be properly
466
-     *                                                      configured. However, some client code may be ok with
467
-     *                                                      construction finalize being called later
468
-     *                                                      (realizing that the subsections' html names might not be
469
-     *                                                      set yet, etc.)
470
-     * @return EE_Form_Section_Proper
471
-     * @throws EE_Error
472
-     */
473
-    public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
474
-    {
475
-        $subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
476
-        if (! $subsection instanceof EE_Form_Section_Proper) {
477
-            throw new EE_Error(
478
-                sprintf(
479
-                    __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'),
480
-                    $name,
481
-                    get_class($this)
482
-                )
483
-            );
484
-        }
485
-        return $subsection;
486
-    }
487
-
488
-
489
-
490
-    /**
491
-     * Gets the value of the specified input. Should be called after receive_form_submission()
492
-     * or populate_defaults() on the form, where the normalized value on the input is set.
493
-     *
494
-     * @param string $name
495
-     * @return mixed depending on the input's type and its normalization strategy
496
-     * @throws \EE_Error
497
-     */
498
-    public function get_input_value($name)
499
-    {
500
-        $input = $this->get_input($name);
501
-        return $input->normalized_value();
502
-    }
503
-
504
-
505
-
506
-    /**
507
-     * Checks if this form section itself is valid, and then checks its subsections
508
-     *
509
-     * @throws EE_Error
510
-     * @return boolean
511
-     */
512
-    public function is_valid()
513
-    {
514
-        if (! $this->has_received_submission()) {
515
-            throw new EE_Error(
516
-                sprintf(
517
-                    __(
518
-                        "You cannot check if a form is valid before receiving the form submission using receive_form_submission",
519
-                        "event_espresso"
520
-                    )
521
-                )
522
-            );
523
-        }
524
-        if (! parent::is_valid()) {
525
-            return false;
526
-        }
527
-        // ok so no general errors to this entire form section.
528
-        // so let's check the subsections, but only set errors if that hasn't been done yet
529
-        $set_submission_errors = $this->submission_error_message() === '' ? true : false;
530
-        foreach ($this->get_validatable_subsections() as $subsection) {
531
-            if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') {
532
-                if ($set_submission_errors) {
533
-                    $this->set_submission_error_message($subsection->get_validation_error_string());
534
-                }
535
-                return false;
536
-            }
537
-        }
538
-        return true;
539
-    }
540
-
541
-
542
-
543
-    /**
544
-     * gets teh default name of this form section if none is specified
545
-     *
546
-     * @return string
547
-     */
548
-    protected function _set_default_name_if_empty()
549
-    {
550
-        if (! $this->_name) {
551
-            $classname = get_class($this);
552
-            $default_name = str_replace("EE_", "", $classname);
553
-            $this->_name = $default_name;
554
-        }
555
-    }
556
-
557
-
558
-
559
-    /**
560
-     * Returns the HTML for the form, except for the form opening and closing tags
561
-     * (as the form section doesn't know where you necessarily want to send the information to),
562
-     * and except for a submit button. Enqueus JS and CSS; if called early enough we will
563
-     * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
564
-     * Not doing_it_wrong because theoretically this CAN be used properly,
565
-     * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
566
-     * any CSS.
567
-     *
568
-     * @throws \EE_Error
569
-     */
570
-    public function get_html_and_js()
571
-    {
572
-        $this->enqueue_js();
573
-        return $this->get_html();
574
-    }
575
-
576
-
577
-
578
-    /**
579
-     * returns HTML for displaying this form section. recursively calls display_section() on all subsections
580
-     *
581
-     * @param bool $display_previously_submitted_data
582
-     * @return string
583
-     */
584
-    public function get_html($display_previously_submitted_data = true)
585
-    {
586
-        $this->ensure_construct_finalized_called();
587
-        if ($display_previously_submitted_data) {
588
-            $this->populate_from_session();
589
-        }
590
-        return $this->_form_html_filter
591
-            ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
592
-            : $this->_layout_strategy->layout_form();
593
-    }
594
-
595
-
596
-
597
-    /**
598
-     * enqueues JS and CSS for the form.
599
-     * It is preferred to call this before wp_enqueue_scripts so the
600
-     * scripts and styles can be put in the header, but if called later
601
-     * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
602
-     * only be in the header; but in HTML5 its ok in the body.
603
-     * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
604
-     * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
605
-     *
606
-     * @return string
607
-     * @throws \EE_Error
608
-     */
609
-    public function enqueue_js()
610
-    {
611
-        $this->_enqueue_and_localize_form_js();
612
-        foreach ($this->subsections() as $subsection) {
613
-            $subsection->enqueue_js();
614
-        }
615
-    }
616
-
617
-
618
-
619
-    /**
620
-     * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
621
-     * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
622
-     * the wp_enqueue_scripts hook.
623
-     * However, registering the form js and localizing it can happen when we
624
-     * actually output the form (which is preferred, seeing how teh form's fields
625
-     * could change until it's actually outputted)
626
-     *
627
-     * @param boolean $init_form_validation_automatically whether or not we want the form validation
628
-     *                                                    to be triggered automatically or not
629
-     * @return void
630
-     */
631
-    public static function wp_enqueue_scripts($init_form_validation_automatically = true)
632
-    {
633
-        wp_register_script(
634
-            'ee_form_section_validation',
635
-            EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
636
-            array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
637
-            EVENT_ESPRESSO_VERSION,
638
-            true
639
-        );
640
-        wp_localize_script(
641
-            'ee_form_section_validation',
642
-            'ee_form_section_validation_init',
643
-            array('init' => $init_form_validation_automatically ? '1' : '0')
644
-        );
645
-    }
646
-
647
-
648
-
649
-    /**
650
-     * gets the variables used by form_section_validation.js.
651
-     * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
652
-     * but before the wordpress hook wp_loaded
653
-     *
654
-     * @throws \EE_Error
655
-     */
656
-    public function _enqueue_and_localize_form_js()
657
-    {
658
-        $this->ensure_construct_finalized_called();
659
-        //actually, we don't want to localize just yet. There may be other forms on the page.
660
-        //so we need to add our form section data to a static variable accessible by all form sections
661
-        //and localize it just before the footer
662
-        $this->localize_validation_rules();
663
-        add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
664
-        add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
665
-    }
666
-
667
-
668
-
669
-    /**
670
-     * add our form section data to a static variable accessible by all form sections
671
-     *
672
-     * @param bool $return_for_subsection
673
-     * @return void
674
-     * @throws \EE_Error
675
-     */
676
-    public function localize_validation_rules($return_for_subsection = false)
677
-    {
678
-        // we only want to localize vars ONCE for the entire form,
679
-        // so if the form section doesn't have a parent, then it must be the top dog
680
-        if ($return_for_subsection || ! $this->parent_section()) {
681
-            EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array(
682
-                'form_section_id'  => $this->html_id(true),
683
-                'validation_rules' => $this->get_jquery_validation_rules(),
684
-                'other_data'       => $this->get_other_js_data(),
685
-                'errors'           => $this->subsection_validation_errors_by_html_name(),
686
-            );
687
-            EE_Form_Section_Proper::$_scripts_localized = true;
688
-        }
689
-    }
690
-
691
-
692
-
693
-    /**
694
-     * Gets an array of extra data that will be useful for client-side javascript.
695
-     * This is primarily data added by inputs and forms in addition to any
696
-     * scripts they might enqueue
697
-     *
698
-     * @param array $form_other_js_data
699
-     * @return array
700
-     */
701
-    public function get_other_js_data($form_other_js_data = array())
702
-    {
703
-        foreach ($this->subsections() as $subsection) {
704
-            $form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
705
-        }
706
-        return $form_other_js_data;
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     * Gets a flat array of inputs for this form section and its subsections.
713
-     * Keys are their form names, and values are the inputs themselves
714
-     *
715
-     * @return EE_Form_Input_Base
716
-     */
717
-    public function inputs_in_subsections()
718
-    {
719
-        $inputs = array();
720
-        foreach ($this->subsections() as $subsection) {
721
-            if ($subsection instanceof EE_Form_Input_Base) {
722
-                $inputs[$subsection->html_name()] = $subsection;
723
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
724
-                $inputs += $subsection->inputs_in_subsections();
725
-            }
726
-        }
727
-        return $inputs;
728
-    }
729
-
730
-
731
-
732
-    /**
733
-     * Gets a flat array of all the validation errors.
734
-     * Keys are html names (because those should be unique)
735
-     * and values are a string of all their validation errors
736
-     *
737
-     * @return string[]
738
-     */
739
-    public function subsection_validation_errors_by_html_name()
740
-    {
741
-        $inputs = $this->inputs();
742
-        $errors = array();
743
-        foreach ($inputs as $form_input) {
744
-            if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
745
-                $errors[$form_input->html_name()] = $form_input->get_validation_error_string();
746
-            }
747
-        }
748
-        return $errors;
749
-    }
750
-
751
-
752
-
753
-    /**
754
-     * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
755
-     * Should be setup by each form during the _enqueues_and_localize_form_js
756
-     */
757
-    public static function localize_script_for_all_forms()
758
-    {
759
-        //allow inputs and stuff to hook in their JS and stuff here
760
-        do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
761
-        EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
762
-        $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
763
-            ? EE_Registry::instance()->CFG->registration->email_validation_level
764
-            : 'wp_default';
765
-        EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level;
766
-        wp_enqueue_script('ee_form_section_validation');
767
-        wp_localize_script(
768
-            'ee_form_section_validation',
769
-            'ee_form_section_vars',
770
-            EE_Form_Section_Proper::$_js_localization
771
-        );
772
-    }
773
-
774
-
775
-
776
-    /**
777
-     * ensure_scripts_localized
778
-     */
779
-    public function ensure_scripts_localized()
780
-    {
781
-        if (! EE_Form_Section_Proper::$_scripts_localized) {
782
-            $this->_enqueue_and_localize_form_js();
783
-        }
784
-    }
785
-
786
-
787
-
788
-    /**
789
-     * Gets the hard-coded validation error messages to be used in the JS. The convention
790
-     * is that the key here should be the same as the custom validation rule put in the JS file
791
-     *
792
-     * @return array keys are custom validation rules, and values are internationalized strings
793
-     */
794
-    private static function _get_localized_error_messages()
795
-    {
796
-        return array(
797
-            'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"),
798
-            'regex'    => __('Please check your input', 'event_espresso'),
799
-        );
800
-    }
801
-
802
-
803
-
804
-    /**
805
-     * @return array
806
-     */
807
-    public static function js_localization()
808
-    {
809
-        return self::$_js_localization;
810
-    }
811
-
812
-
813
-
814
-    /**
815
-     * @return array
816
-     */
817
-    public static function reset_js_localization()
818
-    {
819
-        self::$_js_localization = array();
820
-    }
821
-
822
-
823
-
824
-    /**
825
-     * Gets the JS to put inside the jquery validation rules for subsection of this form section.
826
-     * See parent function for more...
827
-     *
828
-     * @return array
829
-     */
830
-    public function get_jquery_validation_rules()
831
-    {
832
-        $jquery_validation_rules = array();
833
-        foreach ($this->get_validatable_subsections() as $subsection) {
834
-            $jquery_validation_rules = array_merge(
835
-                $jquery_validation_rules,
836
-                $subsection->get_jquery_validation_rules()
837
-            );
838
-        }
839
-        return $jquery_validation_rules;
840
-    }
841
-
842
-
843
-
844
-    /**
845
-     * Sanitizes all the data and sets the sanitized value of each field
846
-     *
847
-     * @param array $req_data like $_POST
848
-     * @return void
849
-     */
850
-    protected function _normalize($req_data)
851
-    {
852
-        $this->_received_submission = true;
853
-        $this->_validation_errors = array();
854
-        foreach ($this->get_validatable_subsections() as $subsection) {
855
-            try {
856
-                $subsection->_normalize($req_data);
857
-            } catch (EE_Validation_Error $e) {
858
-                $subsection->add_validation_error($e);
859
-            }
860
-        }
861
-    }
862
-
863
-
864
-
865
-    /**
866
-     * Performs validation on this form section and its subsections.
867
-     * For each subsection,
868
-     * calls _validate_{subsection_name} on THIS form (if the function exists)
869
-     * and passes it the subsection, then calls _validate on that subsection.
870
-     * If you need to perform validation on the form as a whole (considering multiple)
871
-     * you would be best to override this _validate method,
872
-     * calling parent::_validate() first.
873
-     */
874
-    protected function _validate()
875
-    {
876
-        foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
877
-            if (method_exists($this, '_validate_' . $subsection_name)) {
878
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
879
-            }
880
-            $subsection->_validate();
881
-        }
882
-    }
883
-
884
-
885
-
886
-    /**
887
-     * Gets all the validated inputs for the form section
888
-     *
889
-     * @return array
890
-     */
891
-    public function valid_data()
892
-    {
893
-        $inputs = array();
894
-        foreach ($this->subsections() as $subsection_name => $subsection) {
895
-            if ($subsection instanceof EE_Form_Section_Proper) {
896
-                $inputs[$subsection_name] = $subsection->valid_data();
897
-            } else if ($subsection instanceof EE_Form_Input_Base) {
898
-                $inputs[$subsection_name] = $subsection->normalized_value();
899
-            }
900
-        }
901
-        return $inputs;
902
-    }
903
-
904
-
905
-
906
-    /**
907
-     * Gets all the inputs on this form section
908
-     *
909
-     * @return EE_Form_Input_Base[]
910
-     */
911
-    public function inputs()
912
-    {
913
-        $inputs = array();
914
-        foreach ($this->subsections() as $subsection_name => $subsection) {
915
-            if ($subsection instanceof EE_Form_Input_Base) {
916
-                $inputs[$subsection_name] = $subsection;
917
-            }
918
-        }
919
-        return $inputs;
920
-    }
921
-
922
-
923
-
924
-    /**
925
-     * Gets all the subsections which are a proper form
926
-     *
927
-     * @return EE_Form_Section_Proper[]
928
-     */
929
-    public function subforms()
930
-    {
931
-        $form_sections = array();
932
-        foreach ($this->subsections() as $name => $obj) {
933
-            if ($obj instanceof EE_Form_Section_Proper) {
934
-                $form_sections[$name] = $obj;
935
-            }
936
-        }
937
-        return $form_sections;
938
-    }
939
-
940
-
941
-
942
-    /**
943
-     * Gets all the subsections (inputs, proper subsections, or html-only sections).
944
-     * Consider using inputs() or subforms()
945
-     * if you only want form inputs or proper form sections.
946
-     *
947
-     * @param boolean $require_construction_to_be_finalized most client code should
948
-     *                                                      leave this as TRUE so that the inputs will be properly
949
-     *                                                      configured. However, some client code may be ok with
950
-     *                                                      construction finalize being called later
951
-     *                                                      (realizing that the subsections' html names might not be
952
-     *                                                      set yet, etc.)
953
-     * @return EE_Form_Section_Proper[]
954
-     */
955
-    public function subsections($require_construction_to_be_finalized = true)
956
-    {
957
-        if ($require_construction_to_be_finalized) {
958
-            $this->ensure_construct_finalized_called();
959
-        }
960
-        return $this->_subsections;
961
-    }
962
-
963
-
964
-
965
-    /**
966
-     * Returns a simple array where keys are input names, and values are their normalized
967
-     * values. (Similar to calling get_input_value on inputs)
968
-     *
969
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
970
-     *                                        or just this forms' direct children inputs
971
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
972
-     *                                        or allow multidimensional array
973
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
974
-     *                                        with array keys being input names
975
-     *                                        (regardless of whether they are from a subsection or not),
976
-     *                                        and if $flatten is FALSE it can be a multidimensional array
977
-     *                                        where keys are always subsection names and values are either
978
-     *                                        the input's normalized value, or an array like the top-level array
979
-     */
980
-    public function input_values($include_subform_inputs = false, $flatten = false)
981
-    {
982
-        return $this->_input_values(false, $include_subform_inputs, $flatten);
983
-    }
984
-
985
-
986
-
987
-    /**
988
-     * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
989
-     * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
990
-     * is not necessarily the value we want to display to users. This creates an array
991
-     * where keys are the input names, and values are their display values
992
-     *
993
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
994
-     *                                        or just this forms' direct children inputs
995
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
996
-     *                                        or allow multidimensional array
997
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
998
-     *                                        with array keys being input names
999
-     *                                        (regardless of whether they are from a subsection or not),
1000
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1001
-     *                                        where keys are always subsection names and values are either
1002
-     *                                        the input's normalized value, or an array like the top-level array
1003
-     */
1004
-    public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1005
-    {
1006
-        return $this->_input_values(true, $include_subform_inputs, $flatten);
1007
-    }
1008
-
1009
-
1010
-
1011
-    /**
1012
-     * Gets the input values from the form
1013
-     *
1014
-     * @param boolean $pretty                 Whether to retrieve the pretty value,
1015
-     *                                        or just the normalized value
1016
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1017
-     *                                        or just this forms' direct children inputs
1018
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1019
-     *                                        or allow multidimensional array
1020
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1021
-     *                                        input names (regardless of whether they are from a subsection or not),
1022
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1023
-     *                                        where keys are always subsection names and values are either
1024
-     *                                        the input's normalized value, or an array like the top-level array
1025
-     */
1026
-    public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1027
-    {
1028
-        $input_values = array();
1029
-        foreach ($this->subsections() as $subsection_name => $subsection) {
1030
-            if ($subsection instanceof EE_Form_Input_Base) {
1031
-                $input_values[$subsection_name] = $pretty
1032
-                    ? $subsection->pretty_value()
1033
-                    : $subsection->normalized_value();
1034
-            } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1035
-                $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten);
1036
-                if ($flatten) {
1037
-                    $input_values = array_merge($input_values, $subform_input_values);
1038
-                } else {
1039
-                    $input_values[$subsection_name] = $subform_input_values;
1040
-                }
1041
-            }
1042
-        }
1043
-        return $input_values;
1044
-    }
1045
-
1046
-
1047
-
1048
-    /**
1049
-     * Gets the originally submitted input values from the form
1050
-     *
1051
-     * @param boolean $include_subforms  Whether to include inputs from subforms,
1052
-     *                                   or just this forms' direct children inputs
1053
-     * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1054
-     *                                   with array keys being input names
1055
-     *                                   (regardless of whether they are from a subsection or not),
1056
-     *                                   and if $flatten is FALSE it can be a multidimensional array
1057
-     *                                   where keys are always subsection names and values are either
1058
-     *                                   the input's normalized value, or an array like the top-level array
1059
-     */
1060
-    public function submitted_values($include_subforms = false)
1061
-    {
1062
-        $submitted_values = array();
1063
-        foreach ($this->subsections() as $subsection) {
1064
-            if ($subsection instanceof EE_Form_Input_Base) {
1065
-                // is this input part of an array of inputs?
1066
-                if (strpos($subsection->html_name(), '[') !== false) {
1067
-                    $full_input_name = \EEH_Array::convert_array_values_to_keys(
1068
-                        explode('[', str_replace(']', '', $subsection->html_name())),
1069
-                        $subsection->raw_value()
1070
-                    );
1071
-                    $submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1072
-                } else {
1073
-                    $submitted_values[$subsection->html_name()] = $subsection->raw_value();
1074
-                }
1075
-            } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1076
-                $subform_input_values = $subsection->submitted_values($include_subforms);
1077
-                $submitted_values = array_replace_recursive($submitted_values, $subform_input_values);
1078
-            }
1079
-        }
1080
-        return $submitted_values;
1081
-    }
1082
-
1083
-
1084
-
1085
-    /**
1086
-     * Indicates whether or not this form has received a submission yet
1087
-     * (ie, had receive_form_submission called on it yet)
1088
-     *
1089
-     * @return boolean
1090
-     * @throws \EE_Error
1091
-     */
1092
-    public function has_received_submission()
1093
-    {
1094
-        $this->ensure_construct_finalized_called();
1095
-        return $this->_received_submission;
1096
-    }
1097
-
1098
-
1099
-
1100
-    /**
1101
-     * Equivalent to passing 'exclude' in the constructor's options array.
1102
-     * Removes the listed inputs from the form
1103
-     *
1104
-     * @param array $inputs_to_exclude values are the input names
1105
-     * @return void
1106
-     */
1107
-    public function exclude(array $inputs_to_exclude = array())
1108
-    {
1109
-        foreach ($inputs_to_exclude as $input_to_exclude_name) {
1110
-            unset($this->_subsections[$input_to_exclude_name]);
1111
-        }
1112
-    }
1113
-
1114
-
1115
-
1116
-    /**
1117
-     * @param array $inputs_to_hide
1118
-     * @throws \EE_Error
1119
-     */
1120
-    public function hide(array $inputs_to_hide = array())
1121
-    {
1122
-        foreach ($inputs_to_hide as $input_to_hide) {
1123
-            $input = $this->get_input($input_to_hide);
1124
-            $input->set_display_strategy(new EE_Hidden_Display_Strategy());
1125
-        }
1126
-    }
1127
-
1128
-
1129
-
1130
-    /**
1131
-     * add_subsections
1132
-     * Adds the listed subsections to the form section.
1133
-     * If $subsection_name_to_target is provided,
1134
-     * then new subsections are added before or after that subsection,
1135
-     * otherwise to the start or end of the entire subsections array.
1136
-     *
1137
-     * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1138
-     *                                                          where keys are their names
1139
-     * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1140
-     *                                                          should be added before or after
1141
-     *                                                          IF $subsection_name_to_target is null,
1142
-     *                                                          then $new_subsections will be added to
1143
-     *                                                          the beginning or end of the entire subsections array
1144
-     * @param boolean                $add_before                whether to add $new_subsections, before or after
1145
-     *                                                          $subsection_name_to_target,
1146
-     *                                                          or if $subsection_name_to_target is null,
1147
-     *                                                          before or after entire subsections array
1148
-     * @return void
1149
-     * @throws \EE_Error
1150
-     */
1151
-    public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1152
-    {
1153
-        foreach ($new_subsections as $subsection_name => $subsection) {
1154
-            if (! $subsection instanceof EE_Form_Section_Base) {
1155
-                EE_Error::add_error(
1156
-                    sprintf(
1157
-                        __(
1158
-                            "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1159
-                            "event_espresso"
1160
-                        ),
1161
-                        get_class($subsection),
1162
-                        $subsection_name,
1163
-                        $this->name()
1164
-                    )
1165
-                );
1166
-                unset($new_subsections[$subsection_name]);
1167
-            }
1168
-        }
1169
-        $this->_subsections = EEH_Array::insert_into_array(
1170
-            $this->_subsections,
1171
-            $new_subsections,
1172
-            $subsection_name_to_target,
1173
-            $add_before
1174
-        );
1175
-        if ($this->_construction_finalized) {
1176
-            foreach ($this->_subsections as $name => $subsection) {
1177
-                $subsection->_construct_finalize($this, $name);
1178
-            }
1179
-        }
1180
-    }
1181
-
1182
-
1183
-
1184
-    /**
1185
-     * Just gets all validatable subsections to clean their sensitive data
1186
-     */
1187
-    public function clean_sensitive_data()
1188
-    {
1189
-        foreach ($this->get_validatable_subsections() as $subsection) {
1190
-            $subsection->clean_sensitive_data();
1191
-        }
1192
-    }
1193
-
1194
-
1195
-
1196
-    /**
1197
-     * @param string $form_submission_error_message
1198
-     */
1199
-    public function set_submission_error_message($form_submission_error_message = '')
1200
-    {
1201
-        $this->_form_submission_error_message .= ! empty($form_submission_error_message)
1202
-            ? $form_submission_error_message
1203
-            : __('Form submission failed due to errors', 'event_espresso');
1204
-    }
1205
-
1206
-
1207
-
1208
-    /**
1209
-     * @return string
1210
-     */
1211
-    public function submission_error_message()
1212
-    {
1213
-        return $this->_form_submission_error_message;
1214
-    }
1215
-
1216
-
1217
-
1218
-    /**
1219
-     * @param string $form_submission_success_message
1220
-     */
1221
-    public function set_submission_success_message($form_submission_success_message)
1222
-    {
1223
-        $this->_form_submission_success_message .= ! empty($form_submission_success_message)
1224
-            ? $form_submission_success_message
1225
-            : __('Form submitted successfully', 'event_espresso');
1226
-    }
1227
-
1228
-
1229
-
1230
-    /**
1231
-     * @return string
1232
-     */
1233
-    public function submission_success_message()
1234
-    {
1235
-        return $this->_form_submission_success_message;
1236
-    }
1237
-
1238
-
1239
-
1240
-    /**
1241
-     * Returns the prefix that should be used on child of this form section for
1242
-     * their html names. If this form section itself has a parent, prepends ITS
1243
-     * prefix onto this form section's prefix. Used primarily by
1244
-     * EE_Form_Input_Base::_set_default_html_name_if_empty
1245
-     *
1246
-     * @return string
1247
-     * @throws \EE_Error
1248
-     */
1249
-    public function html_name_prefix()
1250
-    {
1251
-        if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1252
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1253
-        } else {
1254
-            return $this->name();
1255
-        }
1256
-    }
1257
-
1258
-
1259
-
1260
-    /**
1261
-     * Gets the name, but first checks _construct_finalize has been called. If not,
1262
-     * calls it (assumes there is no parent and that we want the name to be whatever
1263
-     * was set, which is probably nothing, or the classname)
1264
-     *
1265
-     * @return string
1266
-     * @throws \EE_Error
1267
-     */
1268
-    public function name()
1269
-    {
1270
-        $this->ensure_construct_finalized_called();
1271
-        return parent::name();
1272
-    }
1273
-
1274
-
1275
-
1276
-    /**
1277
-     * @return EE_Form_Section_Proper
1278
-     * @throws \EE_Error
1279
-     */
1280
-    public function parent_section()
1281
-    {
1282
-        $this->ensure_construct_finalized_called();
1283
-        return parent::parent_section();
1284
-    }
1285
-
1286
-
1287
-
1288
-    /**
1289
-     * make sure construction finalized was called, otherwise children might not be ready
1290
-     *
1291
-     * @return void
1292
-     * @throws \EE_Error
1293
-     */
1294
-    public function ensure_construct_finalized_called()
1295
-    {
1296
-        if (! $this->_construction_finalized) {
1297
-            $this->_construct_finalize($this->_parent_section, $this->_name);
1298
-        }
1299
-    }
1300
-
1301
-
1302
-
1303
-    /**
1304
-     * Checks if any of this form section's inputs, or any of its children's inputs,
1305
-     * are in teh form data. If any are found, returns true. Else false
1306
-     *
1307
-     * @param array $req_data
1308
-     * @return boolean
1309
-     */
1310
-    public function form_data_present_in($req_data = null)
1311
-    {
1312
-        if ($req_data === null) {
1313
-            $req_data = $_POST;
1314
-        }
1315
-        foreach ($this->subsections() as $subsection) {
1316
-            if ($subsection instanceof EE_Form_Input_Base) {
1317
-                if ($subsection->form_data_present_in($req_data)) {
1318
-                    return true;
1319
-                }
1320
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
1321
-                if ($subsection->form_data_present_in($req_data)) {
1322
-                    return true;
1323
-                }
1324
-            }
1325
-        }
1326
-        return false;
1327
-    }
1328
-
1329
-
1330
-
1331
-    /**
1332
-     * Gets validation errors for this form section and subsections
1333
-     * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1334
-     * gets the validation errors for ALL subsection
1335
-     *
1336
-     * @return EE_Validation_Error[]
1337
-     */
1338
-    public function get_validation_errors_accumulated()
1339
-    {
1340
-        $validation_errors = $this->get_validation_errors();
1341
-        foreach ($this->get_validatable_subsections() as $subsection) {
1342
-            if ($subsection instanceof EE_Form_Section_Proper) {
1343
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1344
-            } else {
1345
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors();
1346
-            }
1347
-            if ($validation_errors_on_this_subsection) {
1348
-                $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1349
-            }
1350
-        }
1351
-        return $validation_errors;
1352
-    }
1353
-
1354
-
1355
-
1356
-    /**
1357
-     * This isn't just the name of an input, it's a path pointing to an input. The
1358
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
1359
-     * dot-dot-slash (../) means to ascend into the parent section.
1360
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1361
-     * which will be returned.
1362
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1363
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1364
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1365
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1366
-     * Etc
1367
-     *
1368
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1369
-     * @return EE_Form_Section_Base
1370
-     */
1371
-    public function find_section_from_path($form_section_path)
1372
-    {
1373
-        //check if we can find the input from purely going straight up the tree
1374
-        $input = parent::find_section_from_path($form_section_path);
1375
-        if ($input instanceof EE_Form_Section_Base) {
1376
-            return $input;
1377
-        }
1378
-        $next_slash_pos = strpos($form_section_path, '/');
1379
-        if ($next_slash_pos !== false) {
1380
-            $child_section_name = substr($form_section_path, 0, $next_slash_pos);
1381
-            $subpath = substr($form_section_path, $next_slash_pos + 1);
1382
-        } else {
1383
-            $child_section_name = $form_section_path;
1384
-            $subpath = '';
1385
-        }
1386
-        $child_section = $this->get_subsection($child_section_name);
1387
-        if ($child_section instanceof EE_Form_Section_Base) {
1388
-            return $child_section->find_section_from_path($subpath);
1389
-        } else {
1390
-            return null;
1391
-        }
1392
-    }
14
+	const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
15
+
16
+	/**
17
+	 * Subsections
18
+	 *
19
+	 * @var EE_Form_Section_Validatable[]
20
+	 */
21
+	protected $_subsections = array();
22
+
23
+	/**
24
+	 * Strategy for laying out the form
25
+	 *
26
+	 * @var EE_Form_Section_Layout_Base
27
+	 */
28
+	protected $_layout_strategy;
29
+
30
+	/**
31
+	 * Whether or not this form has received and validated a form submission yet
32
+	 *
33
+	 * @var boolean
34
+	 */
35
+	protected $_received_submission = false;
36
+
37
+	/**
38
+	 * message displayed to users upon successful form submission
39
+	 *
40
+	 * @var string
41
+	 */
42
+	protected $_form_submission_success_message = '';
43
+
44
+	/**
45
+	 * message displayed to users upon unsuccessful form submission
46
+	 *
47
+	 * @var string
48
+	 */
49
+	protected $_form_submission_error_message = '';
50
+
51
+	/**
52
+	 * Stores all the data that will localized for form validation
53
+	 *
54
+	 * @var array
55
+	 */
56
+	static protected $_js_localization = array();
57
+
58
+	/**
59
+	 * whether or not the form's localized validation JS vars have been set
60
+	 *
61
+	 * @type boolean
62
+	 */
63
+	static protected $_scripts_localized = false;
64
+
65
+
66
+
67
+	/**
68
+	 * when constructing a proper form section, calls _construct_finalize on children
69
+	 * so that they know who their parent is, and what name they've been given.
70
+	 *
71
+	 * @param array $options_array   {
72
+	 * @type        $subsections     EE_Form_Section_Validatable[] where keys are the section's name
73
+	 * @type        $include         string[] numerically-indexed where values are section names to be included,
74
+	 *                               and in that order. This is handy if you want
75
+	 *                               the subsections to be ordered differently than the default, and if you override
76
+	 *                               which fields are shown
77
+	 * @type        $exclude         string[] values are subsections to be excluded. This is handy if you want
78
+	 *                               to remove certain default subsections (note: if you specify BOTH 'include' AND
79
+	 *                               'exclude', the inclusions will be applied first, and the exclusions will exclude
80
+	 *                               items from that list of inclusions)
81
+	 * @type        $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
82
+	 *                               } @see EE_Form_Section_Validatable::__construct()
83
+	 * @throws \EE_Error
84
+	 */
85
+	public function __construct($options_array = array())
86
+	{
87
+		$options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array,
88
+			$this);
89
+		//call parent first, as it may be setting the name
90
+		parent::__construct($options_array);
91
+		//if they've included subsections in the constructor, add them now
92
+		if (isset($options_array['include'])) {
93
+			//we are going to make sure we ONLY have those subsections to include
94
+			//AND we are going to make sure they're in that specified order
95
+			$reordered_subsections = array();
96
+			foreach ($options_array['include'] as $input_name) {
97
+				if (isset($this->_subsections[$input_name])) {
98
+					$reordered_subsections[$input_name] = $this->_subsections[$input_name];
99
+				}
100
+			}
101
+			$this->_subsections = $reordered_subsections;
102
+		}
103
+		if (isset($options_array['exclude'])) {
104
+			$exclude = $options_array['exclude'];
105
+			$this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
106
+		}
107
+		if (isset($options_array['layout_strategy'])) {
108
+			$this->_layout_strategy = $options_array['layout_strategy'];
109
+		}
110
+		if (! $this->_layout_strategy) {
111
+			$this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
112
+		}
113
+		$this->_layout_strategy->_construct_finalize($this);
114
+		//ok so we are definitely going to want the forms JS,
115
+		//so enqueue it or remember to enqueue it during wp_enqueue_scripts
116
+		if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
117
+			//ok so they've constructed this object after when they should have.
118
+			//just enqueue the generic form scripts and initialize the form immediately in the JS
119
+			\EE_Form_Section_Proper::wp_enqueue_scripts(true);
120
+		} else {
121
+			add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
122
+			add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
123
+		}
124
+		add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
125
+
126
+		/**
127
+		 * Gives other plugins a chance to hook in before construct finalize is called. The form probably doesn't
128
+		 * yet have a parent form section. Since 4.9.32, when this action was introduced, this is the best place to
129
+		 * add a subsection onto a form, assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
130
+		 * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
131
+		 * @since 4.9.32
132
+		 * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, except maybe calling
133
+		 *                                      _construct_finalize has been done
134
+		 * @param array $options_array options passed into the constructor
135
+		 */
136
+		do_action('AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', $this, $options_array);
137
+
138
+		if (isset($options_array['name'])) {
139
+			$this->_construct_finalize(null, $options_array['name']);
140
+		}
141
+	}
142
+
143
+
144
+
145
+	/**
146
+	 * Finishes construction given the parent form section and this form section's name
147
+	 *
148
+	 * @param EE_Form_Section_Proper $parent_form_section
149
+	 * @param string                 $name
150
+	 * @throws \EE_Error
151
+	 */
152
+	public function _construct_finalize($parent_form_section, $name)
153
+	{
154
+		parent::_construct_finalize($parent_form_section, $name);
155
+		$this->_set_default_name_if_empty();
156
+		$this->_set_default_html_id_if_empty();
157
+		foreach ($this->_subsections as $subsection_name => $subsection) {
158
+			if ($subsection instanceof EE_Form_Section_Base) {
159
+				$subsection->_construct_finalize($this, $subsection_name);
160
+			} else {
161
+				throw new EE_Error(
162
+					sprintf(
163
+						__('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
164
+							'event_espresso'),
165
+						$subsection_name,
166
+						get_class($this),
167
+						$subsection ? get_class($subsection) : __('NULL', 'event_espresso')
168
+					)
169
+				);
170
+			}
171
+		}
172
+		/**
173
+		 * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
174
+		 * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID (or other attributes derived
175
+		 * from the name like the HTML label id, etc), this is where it should be done.
176
+		 * This might only happen just before displaying the form, or just before it receives form submission data.
177
+		 * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
178
+		 * ensured it has a name, HTML IDs, etc
179
+		 * @param EE_Form_Section_Proper $this
180
+		 * @param EE_Form_Section_Proper|null $parent_form_section
181
+		 * @param string $name
182
+		 */
183
+		do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name);
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * Gets the layout strategy for this form section
190
+	 *
191
+	 * @return EE_Form_Section_Layout_Base
192
+	 */
193
+	public function get_layout_strategy()
194
+	{
195
+		return $this->_layout_strategy;
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * Gets the HTML for a single input for this form section according
202
+	 * to the layout strategy
203
+	 *
204
+	 * @param EE_Form_Input_Base $input
205
+	 * @return string
206
+	 */
207
+	public function get_html_for_input($input)
208
+	{
209
+		return $this->_layout_strategy->layout_input($input);
210
+	}
211
+
212
+
213
+
214
+	/**
215
+	 * was_submitted - checks if form inputs are present in request data
216
+	 * Basically an alias for form_data_present_in() (which is used by both
217
+	 * proper form sections and form inputs)
218
+	 *
219
+	 * @param null $form_data
220
+	 * @return boolean
221
+	 */
222
+	public function was_submitted($form_data = null)
223
+	{
224
+		return $this->form_data_present_in($form_data);
225
+	}
226
+
227
+
228
+
229
+	/**
230
+	 * After the form section is initially created, call this to sanitize the data in the submission
231
+	 * which relates to this form section, validate it, and set it as properties on the form.
232
+	 *
233
+	 * @param array|null $req_data should usually be $_POST (the default).
234
+	 *                             However, you CAN supply a different array.
235
+	 *                             Consider using set_defaults() instead however.
236
+	 *                             (If you rendered the form in the page using echo $form_x->get_html()
237
+	 *                             the inputs will have the correct name in the request data for this function
238
+	 *                             to find them and populate the form with them.
239
+	 *                             If you have a flat form (with only input subsections),
240
+	 *                             you can supply a flat array where keys
241
+	 *                             are the form input names and values are their values)
242
+	 * @param boolean    $validate whether or not to perform validation on this data. Default is,
243
+	 *                             of course, to validate that data, and set errors on the invalid values.
244
+	 *                             But if the data has already been validated
245
+	 *                             (eg you validated the data then stored it in the DB)
246
+	 *                             you may want to skip this step.
247
+	 */
248
+	public function receive_form_submission($req_data = null, $validate = true)
249
+	{
250
+		$req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this,
251
+			$validate);
252
+		if ($req_data === null) {
253
+			$req_data = array_merge($_GET, $_POST);
254
+		}
255
+		$req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data,
256
+			$this);
257
+		$this->_normalize($req_data);
258
+		if ($validate) {
259
+			$this->_validate();
260
+			//if it's invalid, we're going to want to re-display so remember what they submitted
261
+			if (! $this->is_valid()) {
262
+				$this->store_submitted_form_data_in_session();
263
+			}
264
+		}
265
+		do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate);
266
+	}
267
+
268
+
269
+
270
+	/**
271
+	 * caches the originally submitted input values in the session
272
+	 * so that they can be used to repopulate the form if it failed validation
273
+	 *
274
+	 * @return boolean whether or not the data was successfully stored in the session
275
+	 */
276
+	protected function store_submitted_form_data_in_session()
277
+	{
278
+		return EE_Registry::instance()->SSN->set_session_data(
279
+			array(
280
+				\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
281
+			)
282
+		);
283
+	}
284
+
285
+
286
+
287
+	/**
288
+	 * retrieves the originally submitted input values in the session
289
+	 * so that they can be used to repopulate the form if it failed validation
290
+	 *
291
+	 * @return array
292
+	 */
293
+	protected function get_submitted_form_data_from_session()
294
+	{
295
+		$session = EE_Registry::instance()->SSN;
296
+		if ($session instanceof EE_Session) {
297
+			return $session->get_session_data(
298
+				\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
299
+			);
300
+		} else {
301
+			return array();
302
+		}
303
+	}
304
+
305
+
306
+
307
+	/**
308
+	 * flushed the originally submitted input values from the session
309
+	 *
310
+	 * @return boolean whether or not the data was successfully removed from the session
311
+	 */
312
+	protected function flush_submitted_form_data_from_session()
313
+	{
314
+		return EE_Registry::instance()->SSN->reset_data(
315
+			array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
316
+		);
317
+	}
318
+
319
+
320
+
321
+	/**
322
+	 * Populates this form and its subsections with data from the session.
323
+	 * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
324
+	 * validation errors when displaying too)
325
+	 * Returns true if the form was populated from the session, false otherwise
326
+	 *
327
+	 * @return boolean
328
+	 */
329
+	public function populate_from_session()
330
+	{
331
+		$form_data_in_session = $this->get_submitted_form_data_from_session();
332
+		if (empty($form_data_in_session)) {
333
+			return false;
334
+		}
335
+		$this->receive_form_submission($form_data_in_session);
336
+		$this->flush_submitted_form_data_from_session();
337
+		if ($this->form_data_present_in($form_data_in_session)) {
338
+			return true;
339
+		} else {
340
+			return false;
341
+		}
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 * Populates the default data for the form, given an array where keys are
348
+	 * the input names, and values are their values (preferably normalized to be their
349
+	 * proper PHP types, not all strings... although that should be ok too).
350
+	 * Proper subsections are sub-arrays, the key being the subsection's name, and
351
+	 * the value being an array formatted in teh same way
352
+	 *
353
+	 * @param array $default_data
354
+	 */
355
+	public function populate_defaults($default_data)
356
+	{
357
+		foreach ($this->subsections(false) as $subsection_name => $subsection) {
358
+			if (isset($default_data[$subsection_name])) {
359
+				if ($subsection instanceof EE_Form_Input_Base) {
360
+					$subsection->set_default($default_data[$subsection_name]);
361
+				} elseif ($subsection instanceof EE_Form_Section_Proper) {
362
+					$subsection->populate_defaults($default_data[$subsection_name]);
363
+				}
364
+			}
365
+		}
366
+	}
367
+
368
+
369
+
370
+	/**
371
+	 * returns true if subsection exists
372
+	 *
373
+	 * @param string $name
374
+	 * @return boolean
375
+	 */
376
+	public function subsection_exists($name)
377
+	{
378
+		return isset($this->_subsections[$name]) ? true : false;
379
+	}
380
+
381
+
382
+
383
+	/**
384
+	 * Gets the subsection specified by its name
385
+	 *
386
+	 * @param string  $name
387
+	 * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
388
+	 *                                                      so that the inputs will be properly configured.
389
+	 *                                                      However, some client code may be ok
390
+	 *                                                      with construction finalize being called later
391
+	 *                                                      (realizing that the subsections' html names
392
+	 *                                                      might not be set yet, etc.)
393
+	 * @return EE_Form_Section_Base
394
+	 * @throws \EE_Error
395
+	 */
396
+	public function get_subsection($name, $require_construction_to_be_finalized = true)
397
+	{
398
+		if ($require_construction_to_be_finalized) {
399
+			$this->ensure_construct_finalized_called();
400
+		}
401
+		return $this->subsection_exists($name) ? $this->_subsections[$name] : null;
402
+	}
403
+
404
+
405
+
406
+	/**
407
+	 * Gets all the validatable subsections of this form section
408
+	 *
409
+	 * @return EE_Form_Section_Validatable[]
410
+	 */
411
+	public function get_validatable_subsections()
412
+	{
413
+		$validatable_subsections = array();
414
+		foreach ($this->subsections() as $name => $obj) {
415
+			if ($obj instanceof EE_Form_Section_Validatable) {
416
+				$validatable_subsections[$name] = $obj;
417
+			}
418
+		}
419
+		return $validatable_subsections;
420
+	}
421
+
422
+
423
+
424
+	/**
425
+	 * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
426
+	 * throw an EE_Error.
427
+	 *
428
+	 * @param string  $name
429
+	 * @param boolean $require_construction_to_be_finalized most client code should
430
+	 *                                                      leave this as TRUE so that the inputs will be properly
431
+	 *                                                      configured. However, some client code may be ok with
432
+	 *                                                      construction finalize being called later
433
+	 *                                                      (realizing that the subsections' html names might not be
434
+	 *                                                      set yet, etc.)
435
+	 * @return EE_Form_Input_Base
436
+	 * @throws EE_Error
437
+	 */
438
+	public function get_input($name, $require_construction_to_be_finalized = true)
439
+	{
440
+		$subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
441
+		if (! $subsection instanceof EE_Form_Input_Base) {
442
+			throw new EE_Error(
443
+				sprintf(
444
+					__(
445
+						"Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
446
+						'event_espresso'
447
+					),
448
+					$name,
449
+					get_class($this),
450
+					$subsection ? get_class($subsection) : __("NULL", 'event_espresso')
451
+				)
452
+			);
453
+		}
454
+		return $subsection;
455
+	}
456
+
457
+
458
+
459
+	/**
460
+	 * Like get_input(), gets the proper subsection of the form given the name,
461
+	 * otherwise throws an EE_Error
462
+	 *
463
+	 * @param string  $name
464
+	 * @param boolean $require_construction_to_be_finalized most client code should
465
+	 *                                                      leave this as TRUE so that the inputs will be properly
466
+	 *                                                      configured. However, some client code may be ok with
467
+	 *                                                      construction finalize being called later
468
+	 *                                                      (realizing that the subsections' html names might not be
469
+	 *                                                      set yet, etc.)
470
+	 * @return EE_Form_Section_Proper
471
+	 * @throws EE_Error
472
+	 */
473
+	public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
474
+	{
475
+		$subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
476
+		if (! $subsection instanceof EE_Form_Section_Proper) {
477
+			throw new EE_Error(
478
+				sprintf(
479
+					__("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'),
480
+					$name,
481
+					get_class($this)
482
+				)
483
+			);
484
+		}
485
+		return $subsection;
486
+	}
487
+
488
+
489
+
490
+	/**
491
+	 * Gets the value of the specified input. Should be called after receive_form_submission()
492
+	 * or populate_defaults() on the form, where the normalized value on the input is set.
493
+	 *
494
+	 * @param string $name
495
+	 * @return mixed depending on the input's type and its normalization strategy
496
+	 * @throws \EE_Error
497
+	 */
498
+	public function get_input_value($name)
499
+	{
500
+		$input = $this->get_input($name);
501
+		return $input->normalized_value();
502
+	}
503
+
504
+
505
+
506
+	/**
507
+	 * Checks if this form section itself is valid, and then checks its subsections
508
+	 *
509
+	 * @throws EE_Error
510
+	 * @return boolean
511
+	 */
512
+	public function is_valid()
513
+	{
514
+		if (! $this->has_received_submission()) {
515
+			throw new EE_Error(
516
+				sprintf(
517
+					__(
518
+						"You cannot check if a form is valid before receiving the form submission using receive_form_submission",
519
+						"event_espresso"
520
+					)
521
+				)
522
+			);
523
+		}
524
+		if (! parent::is_valid()) {
525
+			return false;
526
+		}
527
+		// ok so no general errors to this entire form section.
528
+		// so let's check the subsections, but only set errors if that hasn't been done yet
529
+		$set_submission_errors = $this->submission_error_message() === '' ? true : false;
530
+		foreach ($this->get_validatable_subsections() as $subsection) {
531
+			if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') {
532
+				if ($set_submission_errors) {
533
+					$this->set_submission_error_message($subsection->get_validation_error_string());
534
+				}
535
+				return false;
536
+			}
537
+		}
538
+		return true;
539
+	}
540
+
541
+
542
+
543
+	/**
544
+	 * gets teh default name of this form section if none is specified
545
+	 *
546
+	 * @return string
547
+	 */
548
+	protected function _set_default_name_if_empty()
549
+	{
550
+		if (! $this->_name) {
551
+			$classname = get_class($this);
552
+			$default_name = str_replace("EE_", "", $classname);
553
+			$this->_name = $default_name;
554
+		}
555
+	}
556
+
557
+
558
+
559
+	/**
560
+	 * Returns the HTML for the form, except for the form opening and closing tags
561
+	 * (as the form section doesn't know where you necessarily want to send the information to),
562
+	 * and except for a submit button. Enqueus JS and CSS; if called early enough we will
563
+	 * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
564
+	 * Not doing_it_wrong because theoretically this CAN be used properly,
565
+	 * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
566
+	 * any CSS.
567
+	 *
568
+	 * @throws \EE_Error
569
+	 */
570
+	public function get_html_and_js()
571
+	{
572
+		$this->enqueue_js();
573
+		return $this->get_html();
574
+	}
575
+
576
+
577
+
578
+	/**
579
+	 * returns HTML for displaying this form section. recursively calls display_section() on all subsections
580
+	 *
581
+	 * @param bool $display_previously_submitted_data
582
+	 * @return string
583
+	 */
584
+	public function get_html($display_previously_submitted_data = true)
585
+	{
586
+		$this->ensure_construct_finalized_called();
587
+		if ($display_previously_submitted_data) {
588
+			$this->populate_from_session();
589
+		}
590
+		return $this->_form_html_filter
591
+			? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
592
+			: $this->_layout_strategy->layout_form();
593
+	}
594
+
595
+
596
+
597
+	/**
598
+	 * enqueues JS and CSS for the form.
599
+	 * It is preferred to call this before wp_enqueue_scripts so the
600
+	 * scripts and styles can be put in the header, but if called later
601
+	 * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
602
+	 * only be in the header; but in HTML5 its ok in the body.
603
+	 * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
604
+	 * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
605
+	 *
606
+	 * @return string
607
+	 * @throws \EE_Error
608
+	 */
609
+	public function enqueue_js()
610
+	{
611
+		$this->_enqueue_and_localize_form_js();
612
+		foreach ($this->subsections() as $subsection) {
613
+			$subsection->enqueue_js();
614
+		}
615
+	}
616
+
617
+
618
+
619
+	/**
620
+	 * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
621
+	 * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
622
+	 * the wp_enqueue_scripts hook.
623
+	 * However, registering the form js and localizing it can happen when we
624
+	 * actually output the form (which is preferred, seeing how teh form's fields
625
+	 * could change until it's actually outputted)
626
+	 *
627
+	 * @param boolean $init_form_validation_automatically whether or not we want the form validation
628
+	 *                                                    to be triggered automatically or not
629
+	 * @return void
630
+	 */
631
+	public static function wp_enqueue_scripts($init_form_validation_automatically = true)
632
+	{
633
+		wp_register_script(
634
+			'ee_form_section_validation',
635
+			EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
636
+			array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
637
+			EVENT_ESPRESSO_VERSION,
638
+			true
639
+		);
640
+		wp_localize_script(
641
+			'ee_form_section_validation',
642
+			'ee_form_section_validation_init',
643
+			array('init' => $init_form_validation_automatically ? '1' : '0')
644
+		);
645
+	}
646
+
647
+
648
+
649
+	/**
650
+	 * gets the variables used by form_section_validation.js.
651
+	 * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
652
+	 * but before the wordpress hook wp_loaded
653
+	 *
654
+	 * @throws \EE_Error
655
+	 */
656
+	public function _enqueue_and_localize_form_js()
657
+	{
658
+		$this->ensure_construct_finalized_called();
659
+		//actually, we don't want to localize just yet. There may be other forms on the page.
660
+		//so we need to add our form section data to a static variable accessible by all form sections
661
+		//and localize it just before the footer
662
+		$this->localize_validation_rules();
663
+		add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
664
+		add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
665
+	}
666
+
667
+
668
+
669
+	/**
670
+	 * add our form section data to a static variable accessible by all form sections
671
+	 *
672
+	 * @param bool $return_for_subsection
673
+	 * @return void
674
+	 * @throws \EE_Error
675
+	 */
676
+	public function localize_validation_rules($return_for_subsection = false)
677
+	{
678
+		// we only want to localize vars ONCE for the entire form,
679
+		// so if the form section doesn't have a parent, then it must be the top dog
680
+		if ($return_for_subsection || ! $this->parent_section()) {
681
+			EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array(
682
+				'form_section_id'  => $this->html_id(true),
683
+				'validation_rules' => $this->get_jquery_validation_rules(),
684
+				'other_data'       => $this->get_other_js_data(),
685
+				'errors'           => $this->subsection_validation_errors_by_html_name(),
686
+			);
687
+			EE_Form_Section_Proper::$_scripts_localized = true;
688
+		}
689
+	}
690
+
691
+
692
+
693
+	/**
694
+	 * Gets an array of extra data that will be useful for client-side javascript.
695
+	 * This is primarily data added by inputs and forms in addition to any
696
+	 * scripts they might enqueue
697
+	 *
698
+	 * @param array $form_other_js_data
699
+	 * @return array
700
+	 */
701
+	public function get_other_js_data($form_other_js_data = array())
702
+	{
703
+		foreach ($this->subsections() as $subsection) {
704
+			$form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
705
+		}
706
+		return $form_other_js_data;
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 * Gets a flat array of inputs for this form section and its subsections.
713
+	 * Keys are their form names, and values are the inputs themselves
714
+	 *
715
+	 * @return EE_Form_Input_Base
716
+	 */
717
+	public function inputs_in_subsections()
718
+	{
719
+		$inputs = array();
720
+		foreach ($this->subsections() as $subsection) {
721
+			if ($subsection instanceof EE_Form_Input_Base) {
722
+				$inputs[$subsection->html_name()] = $subsection;
723
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
724
+				$inputs += $subsection->inputs_in_subsections();
725
+			}
726
+		}
727
+		return $inputs;
728
+	}
729
+
730
+
731
+
732
+	/**
733
+	 * Gets a flat array of all the validation errors.
734
+	 * Keys are html names (because those should be unique)
735
+	 * and values are a string of all their validation errors
736
+	 *
737
+	 * @return string[]
738
+	 */
739
+	public function subsection_validation_errors_by_html_name()
740
+	{
741
+		$inputs = $this->inputs();
742
+		$errors = array();
743
+		foreach ($inputs as $form_input) {
744
+			if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
745
+				$errors[$form_input->html_name()] = $form_input->get_validation_error_string();
746
+			}
747
+		}
748
+		return $errors;
749
+	}
750
+
751
+
752
+
753
+	/**
754
+	 * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
755
+	 * Should be setup by each form during the _enqueues_and_localize_form_js
756
+	 */
757
+	public static function localize_script_for_all_forms()
758
+	{
759
+		//allow inputs and stuff to hook in their JS and stuff here
760
+		do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
761
+		EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
762
+		$email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
763
+			? EE_Registry::instance()->CFG->registration->email_validation_level
764
+			: 'wp_default';
765
+		EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level;
766
+		wp_enqueue_script('ee_form_section_validation');
767
+		wp_localize_script(
768
+			'ee_form_section_validation',
769
+			'ee_form_section_vars',
770
+			EE_Form_Section_Proper::$_js_localization
771
+		);
772
+	}
773
+
774
+
775
+
776
+	/**
777
+	 * ensure_scripts_localized
778
+	 */
779
+	public function ensure_scripts_localized()
780
+	{
781
+		if (! EE_Form_Section_Proper::$_scripts_localized) {
782
+			$this->_enqueue_and_localize_form_js();
783
+		}
784
+	}
785
+
786
+
787
+
788
+	/**
789
+	 * Gets the hard-coded validation error messages to be used in the JS. The convention
790
+	 * is that the key here should be the same as the custom validation rule put in the JS file
791
+	 *
792
+	 * @return array keys are custom validation rules, and values are internationalized strings
793
+	 */
794
+	private static function _get_localized_error_messages()
795
+	{
796
+		return array(
797
+			'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"),
798
+			'regex'    => __('Please check your input', 'event_espresso'),
799
+		);
800
+	}
801
+
802
+
803
+
804
+	/**
805
+	 * @return array
806
+	 */
807
+	public static function js_localization()
808
+	{
809
+		return self::$_js_localization;
810
+	}
811
+
812
+
813
+
814
+	/**
815
+	 * @return array
816
+	 */
817
+	public static function reset_js_localization()
818
+	{
819
+		self::$_js_localization = array();
820
+	}
821
+
822
+
823
+
824
+	/**
825
+	 * Gets the JS to put inside the jquery validation rules for subsection of this form section.
826
+	 * See parent function for more...
827
+	 *
828
+	 * @return array
829
+	 */
830
+	public function get_jquery_validation_rules()
831
+	{
832
+		$jquery_validation_rules = array();
833
+		foreach ($this->get_validatable_subsections() as $subsection) {
834
+			$jquery_validation_rules = array_merge(
835
+				$jquery_validation_rules,
836
+				$subsection->get_jquery_validation_rules()
837
+			);
838
+		}
839
+		return $jquery_validation_rules;
840
+	}
841
+
842
+
843
+
844
+	/**
845
+	 * Sanitizes all the data and sets the sanitized value of each field
846
+	 *
847
+	 * @param array $req_data like $_POST
848
+	 * @return void
849
+	 */
850
+	protected function _normalize($req_data)
851
+	{
852
+		$this->_received_submission = true;
853
+		$this->_validation_errors = array();
854
+		foreach ($this->get_validatable_subsections() as $subsection) {
855
+			try {
856
+				$subsection->_normalize($req_data);
857
+			} catch (EE_Validation_Error $e) {
858
+				$subsection->add_validation_error($e);
859
+			}
860
+		}
861
+	}
862
+
863
+
864
+
865
+	/**
866
+	 * Performs validation on this form section and its subsections.
867
+	 * For each subsection,
868
+	 * calls _validate_{subsection_name} on THIS form (if the function exists)
869
+	 * and passes it the subsection, then calls _validate on that subsection.
870
+	 * If you need to perform validation on the form as a whole (considering multiple)
871
+	 * you would be best to override this _validate method,
872
+	 * calling parent::_validate() first.
873
+	 */
874
+	protected function _validate()
875
+	{
876
+		foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
877
+			if (method_exists($this, '_validate_' . $subsection_name)) {
878
+				call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
879
+			}
880
+			$subsection->_validate();
881
+		}
882
+	}
883
+
884
+
885
+
886
+	/**
887
+	 * Gets all the validated inputs for the form section
888
+	 *
889
+	 * @return array
890
+	 */
891
+	public function valid_data()
892
+	{
893
+		$inputs = array();
894
+		foreach ($this->subsections() as $subsection_name => $subsection) {
895
+			if ($subsection instanceof EE_Form_Section_Proper) {
896
+				$inputs[$subsection_name] = $subsection->valid_data();
897
+			} else if ($subsection instanceof EE_Form_Input_Base) {
898
+				$inputs[$subsection_name] = $subsection->normalized_value();
899
+			}
900
+		}
901
+		return $inputs;
902
+	}
903
+
904
+
905
+
906
+	/**
907
+	 * Gets all the inputs on this form section
908
+	 *
909
+	 * @return EE_Form_Input_Base[]
910
+	 */
911
+	public function inputs()
912
+	{
913
+		$inputs = array();
914
+		foreach ($this->subsections() as $subsection_name => $subsection) {
915
+			if ($subsection instanceof EE_Form_Input_Base) {
916
+				$inputs[$subsection_name] = $subsection;
917
+			}
918
+		}
919
+		return $inputs;
920
+	}
921
+
922
+
923
+
924
+	/**
925
+	 * Gets all the subsections which are a proper form
926
+	 *
927
+	 * @return EE_Form_Section_Proper[]
928
+	 */
929
+	public function subforms()
930
+	{
931
+		$form_sections = array();
932
+		foreach ($this->subsections() as $name => $obj) {
933
+			if ($obj instanceof EE_Form_Section_Proper) {
934
+				$form_sections[$name] = $obj;
935
+			}
936
+		}
937
+		return $form_sections;
938
+	}
939
+
940
+
941
+
942
+	/**
943
+	 * Gets all the subsections (inputs, proper subsections, or html-only sections).
944
+	 * Consider using inputs() or subforms()
945
+	 * if you only want form inputs or proper form sections.
946
+	 *
947
+	 * @param boolean $require_construction_to_be_finalized most client code should
948
+	 *                                                      leave this as TRUE so that the inputs will be properly
949
+	 *                                                      configured. However, some client code may be ok with
950
+	 *                                                      construction finalize being called later
951
+	 *                                                      (realizing that the subsections' html names might not be
952
+	 *                                                      set yet, etc.)
953
+	 * @return EE_Form_Section_Proper[]
954
+	 */
955
+	public function subsections($require_construction_to_be_finalized = true)
956
+	{
957
+		if ($require_construction_to_be_finalized) {
958
+			$this->ensure_construct_finalized_called();
959
+		}
960
+		return $this->_subsections;
961
+	}
962
+
963
+
964
+
965
+	/**
966
+	 * Returns a simple array where keys are input names, and values are their normalized
967
+	 * values. (Similar to calling get_input_value on inputs)
968
+	 *
969
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
970
+	 *                                        or just this forms' direct children inputs
971
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
972
+	 *                                        or allow multidimensional array
973
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
974
+	 *                                        with array keys being input names
975
+	 *                                        (regardless of whether they are from a subsection or not),
976
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
977
+	 *                                        where keys are always subsection names and values are either
978
+	 *                                        the input's normalized value, or an array like the top-level array
979
+	 */
980
+	public function input_values($include_subform_inputs = false, $flatten = false)
981
+	{
982
+		return $this->_input_values(false, $include_subform_inputs, $flatten);
983
+	}
984
+
985
+
986
+
987
+	/**
988
+	 * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
989
+	 * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
990
+	 * is not necessarily the value we want to display to users. This creates an array
991
+	 * where keys are the input names, and values are their display values
992
+	 *
993
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
994
+	 *                                        or just this forms' direct children inputs
995
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
996
+	 *                                        or allow multidimensional array
997
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
998
+	 *                                        with array keys being input names
999
+	 *                                        (regardless of whether they are from a subsection or not),
1000
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1001
+	 *                                        where keys are always subsection names and values are either
1002
+	 *                                        the input's normalized value, or an array like the top-level array
1003
+	 */
1004
+	public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1005
+	{
1006
+		return $this->_input_values(true, $include_subform_inputs, $flatten);
1007
+	}
1008
+
1009
+
1010
+
1011
+	/**
1012
+	 * Gets the input values from the form
1013
+	 *
1014
+	 * @param boolean $pretty                 Whether to retrieve the pretty value,
1015
+	 *                                        or just the normalized value
1016
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1017
+	 *                                        or just this forms' direct children inputs
1018
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1019
+	 *                                        or allow multidimensional array
1020
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1021
+	 *                                        input names (regardless of whether they are from a subsection or not),
1022
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1023
+	 *                                        where keys are always subsection names and values are either
1024
+	 *                                        the input's normalized value, or an array like the top-level array
1025
+	 */
1026
+	public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1027
+	{
1028
+		$input_values = array();
1029
+		foreach ($this->subsections() as $subsection_name => $subsection) {
1030
+			if ($subsection instanceof EE_Form_Input_Base) {
1031
+				$input_values[$subsection_name] = $pretty
1032
+					? $subsection->pretty_value()
1033
+					: $subsection->normalized_value();
1034
+			} else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1035
+				$subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten);
1036
+				if ($flatten) {
1037
+					$input_values = array_merge($input_values, $subform_input_values);
1038
+				} else {
1039
+					$input_values[$subsection_name] = $subform_input_values;
1040
+				}
1041
+			}
1042
+		}
1043
+		return $input_values;
1044
+	}
1045
+
1046
+
1047
+
1048
+	/**
1049
+	 * Gets the originally submitted input values from the form
1050
+	 *
1051
+	 * @param boolean $include_subforms  Whether to include inputs from subforms,
1052
+	 *                                   or just this forms' direct children inputs
1053
+	 * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1054
+	 *                                   with array keys being input names
1055
+	 *                                   (regardless of whether they are from a subsection or not),
1056
+	 *                                   and if $flatten is FALSE it can be a multidimensional array
1057
+	 *                                   where keys are always subsection names and values are either
1058
+	 *                                   the input's normalized value, or an array like the top-level array
1059
+	 */
1060
+	public function submitted_values($include_subforms = false)
1061
+	{
1062
+		$submitted_values = array();
1063
+		foreach ($this->subsections() as $subsection) {
1064
+			if ($subsection instanceof EE_Form_Input_Base) {
1065
+				// is this input part of an array of inputs?
1066
+				if (strpos($subsection->html_name(), '[') !== false) {
1067
+					$full_input_name = \EEH_Array::convert_array_values_to_keys(
1068
+						explode('[', str_replace(']', '', $subsection->html_name())),
1069
+						$subsection->raw_value()
1070
+					);
1071
+					$submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1072
+				} else {
1073
+					$submitted_values[$subsection->html_name()] = $subsection->raw_value();
1074
+				}
1075
+			} else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1076
+				$subform_input_values = $subsection->submitted_values($include_subforms);
1077
+				$submitted_values = array_replace_recursive($submitted_values, $subform_input_values);
1078
+			}
1079
+		}
1080
+		return $submitted_values;
1081
+	}
1082
+
1083
+
1084
+
1085
+	/**
1086
+	 * Indicates whether or not this form has received a submission yet
1087
+	 * (ie, had receive_form_submission called on it yet)
1088
+	 *
1089
+	 * @return boolean
1090
+	 * @throws \EE_Error
1091
+	 */
1092
+	public function has_received_submission()
1093
+	{
1094
+		$this->ensure_construct_finalized_called();
1095
+		return $this->_received_submission;
1096
+	}
1097
+
1098
+
1099
+
1100
+	/**
1101
+	 * Equivalent to passing 'exclude' in the constructor's options array.
1102
+	 * Removes the listed inputs from the form
1103
+	 *
1104
+	 * @param array $inputs_to_exclude values are the input names
1105
+	 * @return void
1106
+	 */
1107
+	public function exclude(array $inputs_to_exclude = array())
1108
+	{
1109
+		foreach ($inputs_to_exclude as $input_to_exclude_name) {
1110
+			unset($this->_subsections[$input_to_exclude_name]);
1111
+		}
1112
+	}
1113
+
1114
+
1115
+
1116
+	/**
1117
+	 * @param array $inputs_to_hide
1118
+	 * @throws \EE_Error
1119
+	 */
1120
+	public function hide(array $inputs_to_hide = array())
1121
+	{
1122
+		foreach ($inputs_to_hide as $input_to_hide) {
1123
+			$input = $this->get_input($input_to_hide);
1124
+			$input->set_display_strategy(new EE_Hidden_Display_Strategy());
1125
+		}
1126
+	}
1127
+
1128
+
1129
+
1130
+	/**
1131
+	 * add_subsections
1132
+	 * Adds the listed subsections to the form section.
1133
+	 * If $subsection_name_to_target is provided,
1134
+	 * then new subsections are added before or after that subsection,
1135
+	 * otherwise to the start or end of the entire subsections array.
1136
+	 *
1137
+	 * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1138
+	 *                                                          where keys are their names
1139
+	 * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1140
+	 *                                                          should be added before or after
1141
+	 *                                                          IF $subsection_name_to_target is null,
1142
+	 *                                                          then $new_subsections will be added to
1143
+	 *                                                          the beginning or end of the entire subsections array
1144
+	 * @param boolean                $add_before                whether to add $new_subsections, before or after
1145
+	 *                                                          $subsection_name_to_target,
1146
+	 *                                                          or if $subsection_name_to_target is null,
1147
+	 *                                                          before or after entire subsections array
1148
+	 * @return void
1149
+	 * @throws \EE_Error
1150
+	 */
1151
+	public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1152
+	{
1153
+		foreach ($new_subsections as $subsection_name => $subsection) {
1154
+			if (! $subsection instanceof EE_Form_Section_Base) {
1155
+				EE_Error::add_error(
1156
+					sprintf(
1157
+						__(
1158
+							"Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1159
+							"event_espresso"
1160
+						),
1161
+						get_class($subsection),
1162
+						$subsection_name,
1163
+						$this->name()
1164
+					)
1165
+				);
1166
+				unset($new_subsections[$subsection_name]);
1167
+			}
1168
+		}
1169
+		$this->_subsections = EEH_Array::insert_into_array(
1170
+			$this->_subsections,
1171
+			$new_subsections,
1172
+			$subsection_name_to_target,
1173
+			$add_before
1174
+		);
1175
+		if ($this->_construction_finalized) {
1176
+			foreach ($this->_subsections as $name => $subsection) {
1177
+				$subsection->_construct_finalize($this, $name);
1178
+			}
1179
+		}
1180
+	}
1181
+
1182
+
1183
+
1184
+	/**
1185
+	 * Just gets all validatable subsections to clean their sensitive data
1186
+	 */
1187
+	public function clean_sensitive_data()
1188
+	{
1189
+		foreach ($this->get_validatable_subsections() as $subsection) {
1190
+			$subsection->clean_sensitive_data();
1191
+		}
1192
+	}
1193
+
1194
+
1195
+
1196
+	/**
1197
+	 * @param string $form_submission_error_message
1198
+	 */
1199
+	public function set_submission_error_message($form_submission_error_message = '')
1200
+	{
1201
+		$this->_form_submission_error_message .= ! empty($form_submission_error_message)
1202
+			? $form_submission_error_message
1203
+			: __('Form submission failed due to errors', 'event_espresso');
1204
+	}
1205
+
1206
+
1207
+
1208
+	/**
1209
+	 * @return string
1210
+	 */
1211
+	public function submission_error_message()
1212
+	{
1213
+		return $this->_form_submission_error_message;
1214
+	}
1215
+
1216
+
1217
+
1218
+	/**
1219
+	 * @param string $form_submission_success_message
1220
+	 */
1221
+	public function set_submission_success_message($form_submission_success_message)
1222
+	{
1223
+		$this->_form_submission_success_message .= ! empty($form_submission_success_message)
1224
+			? $form_submission_success_message
1225
+			: __('Form submitted successfully', 'event_espresso');
1226
+	}
1227
+
1228
+
1229
+
1230
+	/**
1231
+	 * @return string
1232
+	 */
1233
+	public function submission_success_message()
1234
+	{
1235
+		return $this->_form_submission_success_message;
1236
+	}
1237
+
1238
+
1239
+
1240
+	/**
1241
+	 * Returns the prefix that should be used on child of this form section for
1242
+	 * their html names. If this form section itself has a parent, prepends ITS
1243
+	 * prefix onto this form section's prefix. Used primarily by
1244
+	 * EE_Form_Input_Base::_set_default_html_name_if_empty
1245
+	 *
1246
+	 * @return string
1247
+	 * @throws \EE_Error
1248
+	 */
1249
+	public function html_name_prefix()
1250
+	{
1251
+		if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1252
+			return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1253
+		} else {
1254
+			return $this->name();
1255
+		}
1256
+	}
1257
+
1258
+
1259
+
1260
+	/**
1261
+	 * Gets the name, but first checks _construct_finalize has been called. If not,
1262
+	 * calls it (assumes there is no parent and that we want the name to be whatever
1263
+	 * was set, which is probably nothing, or the classname)
1264
+	 *
1265
+	 * @return string
1266
+	 * @throws \EE_Error
1267
+	 */
1268
+	public function name()
1269
+	{
1270
+		$this->ensure_construct_finalized_called();
1271
+		return parent::name();
1272
+	}
1273
+
1274
+
1275
+
1276
+	/**
1277
+	 * @return EE_Form_Section_Proper
1278
+	 * @throws \EE_Error
1279
+	 */
1280
+	public function parent_section()
1281
+	{
1282
+		$this->ensure_construct_finalized_called();
1283
+		return parent::parent_section();
1284
+	}
1285
+
1286
+
1287
+
1288
+	/**
1289
+	 * make sure construction finalized was called, otherwise children might not be ready
1290
+	 *
1291
+	 * @return void
1292
+	 * @throws \EE_Error
1293
+	 */
1294
+	public function ensure_construct_finalized_called()
1295
+	{
1296
+		if (! $this->_construction_finalized) {
1297
+			$this->_construct_finalize($this->_parent_section, $this->_name);
1298
+		}
1299
+	}
1300
+
1301
+
1302
+
1303
+	/**
1304
+	 * Checks if any of this form section's inputs, or any of its children's inputs,
1305
+	 * are in teh form data. If any are found, returns true. Else false
1306
+	 *
1307
+	 * @param array $req_data
1308
+	 * @return boolean
1309
+	 */
1310
+	public function form_data_present_in($req_data = null)
1311
+	{
1312
+		if ($req_data === null) {
1313
+			$req_data = $_POST;
1314
+		}
1315
+		foreach ($this->subsections() as $subsection) {
1316
+			if ($subsection instanceof EE_Form_Input_Base) {
1317
+				if ($subsection->form_data_present_in($req_data)) {
1318
+					return true;
1319
+				}
1320
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
1321
+				if ($subsection->form_data_present_in($req_data)) {
1322
+					return true;
1323
+				}
1324
+			}
1325
+		}
1326
+		return false;
1327
+	}
1328
+
1329
+
1330
+
1331
+	/**
1332
+	 * Gets validation errors for this form section and subsections
1333
+	 * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1334
+	 * gets the validation errors for ALL subsection
1335
+	 *
1336
+	 * @return EE_Validation_Error[]
1337
+	 */
1338
+	public function get_validation_errors_accumulated()
1339
+	{
1340
+		$validation_errors = $this->get_validation_errors();
1341
+		foreach ($this->get_validatable_subsections() as $subsection) {
1342
+			if ($subsection instanceof EE_Form_Section_Proper) {
1343
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1344
+			} else {
1345
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors();
1346
+			}
1347
+			if ($validation_errors_on_this_subsection) {
1348
+				$validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1349
+			}
1350
+		}
1351
+		return $validation_errors;
1352
+	}
1353
+
1354
+
1355
+
1356
+	/**
1357
+	 * This isn't just the name of an input, it's a path pointing to an input. The
1358
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
1359
+	 * dot-dot-slash (../) means to ascend into the parent section.
1360
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1361
+	 * which will be returned.
1362
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1363
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1364
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1365
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1366
+	 * Etc
1367
+	 *
1368
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1369
+	 * @return EE_Form_Section_Base
1370
+	 */
1371
+	public function find_section_from_path($form_section_path)
1372
+	{
1373
+		//check if we can find the input from purely going straight up the tree
1374
+		$input = parent::find_section_from_path($form_section_path);
1375
+		if ($input instanceof EE_Form_Section_Base) {
1376
+			return $input;
1377
+		}
1378
+		$next_slash_pos = strpos($form_section_path, '/');
1379
+		if ($next_slash_pos !== false) {
1380
+			$child_section_name = substr($form_section_path, 0, $next_slash_pos);
1381
+			$subpath = substr($form_section_path, $next_slash_pos + 1);
1382
+		} else {
1383
+			$child_section_name = $form_section_path;
1384
+			$subpath = '';
1385
+		}
1386
+		$child_section = $this->get_subsection($child_section_name);
1387
+		if ($child_section instanceof EE_Form_Section_Base) {
1388
+			return $child_section->find_section_from_path($subpath);
1389
+		} else {
1390
+			return null;
1391
+		}
1392
+	}
1393 1393
 
1394 1394
 }
1395 1395
 
Please login to merge, or discard this patch.
admin_pages/transactions/Transactions_Admin_Page.core.php 2 patches
Indentation   +1963 added lines, -1963 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 /**
@@ -27,1971 +27,1971 @@  discard block
 block discarded – undo
27 27
 class Transactions_Admin_Page extends EE_Admin_Page
28 28
 {
29 29
 
30
-    /**
31
-     * @var EE_Transaction
32
-     */
33
-    private $_transaction;
34
-
35
-    /**
36
-     * @var EE_Session
37
-     */
38
-    private $_session;
39
-
40
-    /**
41
-     * @var array $_txn_status
42
-     */
43
-    private static $_txn_status;
44
-
45
-    /**
46
-     * @var array $_pay_status
47
-     */
48
-    private static $_pay_status;
49
-
50
-    /**
51
-     * @var array $_existing_reg_payment_REG_IDs
52
-     */
53
-    protected $_existing_reg_payment_REG_IDs = null;
54
-
55
-
56
-    /**
57
-     * @Constructor
58
-     * @access public
59
-     *
60
-     * @param bool $routing
61
-     *
62
-     * @return Transactions_Admin_Page
63
-     */
64
-    public function __construct($routing = true)
65
-    {
66
-        parent::__construct($routing);
67
-    }
68
-
69
-
70
-    /**
71
-     *    _init_page_props
72
-     * @return void
73
-     */
74
-    protected function _init_page_props()
75
-    {
76
-        $this->page_slug        = TXN_PG_SLUG;
77
-        $this->page_label       = esc_html__('Transactions', 'event_espresso');
78
-        $this->_admin_base_url  = TXN_ADMIN_URL;
79
-        $this->_admin_base_path = TXN_ADMIN;
80
-    }
81
-
82
-
83
-    /**
84
-     *    _ajax_hooks
85
-     * @return void
86
-     */
87
-    protected function _ajax_hooks()
88
-    {
89
-        add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds'));
90
-        add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds'));
91
-        add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment'));
92
-    }
93
-
94
-
95
-    /**
96
-     *    _define_page_props
97
-     * @return void
98
-     */
99
-    protected function _define_page_props()
100
-    {
101
-        $this->_admin_page_title = $this->page_label;
102
-        $this->_labels           = array(
103
-            'buttons' => array(
104
-                'add'    => esc_html__('Add New Transaction', 'event_espresso'),
105
-                'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
106
-                'delete' => esc_html__('Delete Transaction', 'event_espresso'),
107
-            )
108
-        );
109
-    }
110
-
111
-
112
-    /**
113
-     *        grab url requests and route them
114
-     * @access private
115
-     * @return void
116
-     */
117
-    public function _set_page_routes()
118
-    {
119
-
120
-        $this->_set_transaction_status_array();
121
-
122
-        $txn_id = ! empty($this->_req_data['TXN_ID']) && ! is_array($this->_req_data['TXN_ID']) ? $this->_req_data['TXN_ID'] : 0;
123
-
124
-        $this->_page_routes = array(
125
-
126
-            'default' => array(
127
-                'func'       => '_transactions_overview_list_table',
128
-                'capability' => 'ee_read_transactions'
129
-            ),
130
-
131
-            'view_transaction' => array(
132
-                'func'       => '_transaction_details',
133
-                'capability' => 'ee_read_transaction',
134
-                'obj_id'     => $txn_id
135
-            ),
136
-
137
-            'send_payment_reminder' => array(
138
-                'func'       => '_send_payment_reminder',
139
-                'noheader'   => true,
140
-                'capability' => 'ee_send_message'
141
-            ),
142
-
143
-            'espresso_apply_payment' => array(
144
-                'func'       => 'apply_payments_or_refunds',
145
-                'noheader'   => true,
146
-                'capability' => 'ee_edit_payments'
147
-            ),
148
-
149
-            'espresso_apply_refund' => array(
150
-                'func'       => 'apply_payments_or_refunds',
151
-                'noheader'   => true,
152
-                'capability' => 'ee_edit_payments'
153
-            ),
154
-
155
-            'espresso_delete_payment' => array(
156
-                'func'       => 'delete_payment',
157
-                'noheader'   => true,
158
-                'capability' => 'ee_delete_payments'
159
-            ),
160
-
161
-        );
162
-
163
-    }
164
-
165
-
166
-    protected function _set_page_config()
167
-    {
168
-        $this->_page_config = array(
169
-            'default'          => array(
170
-                'nav'           => array(
171
-                    'label' => esc_html__('Overview', 'event_espresso'),
172
-                    'order' => 10
173
-                ),
174
-                'list_table'    => 'EE_Admin_Transactions_List_Table',
175
-                'help_tabs'     => array(
176
-                    'transactions_overview_help_tab'                       => array(
177
-                        'title'    => esc_html__('Transactions Overview', 'event_espresso'),
178
-                        'filename' => 'transactions_overview'
179
-                    ),
180
-                    'transactions_overview_table_column_headings_help_tab' => array(
181
-                        'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
182
-                        'filename' => 'transactions_overview_table_column_headings'
183
-                    ),
184
-                    'transactions_overview_views_filters_help_tab'         => array(
185
-                        'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
186
-                        'filename' => 'transactions_overview_views_filters_search'
187
-                    ),
188
-                ),
189
-                'help_tour'     => array('Transactions_Overview_Help_Tour'),
190
-                /**
191
-                 * commented out because currently we are not displaying tips for transaction list table status but this
192
-                 * may change in a later iteration so want to keep the code for then.
193
-                 */
194
-                //'qtips' => array( 'Transactions_List_Table_Tips' ),
195
-                'require_nonce' => false
196
-            ),
197
-            'view_transaction' => array(
198
-                'nav'       => array(
199
-                    'label'      => esc_html__('View Transaction', 'event_espresso'),
200
-                    'order'      => 5,
201
-                    'url'        => isset($this->_req_data['TXN_ID']) ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']),
202
-                        $this->_current_page_view_url) : $this->_admin_base_url,
203
-                    'persistent' => false
204
-                ),
205
-                'help_tabs' => array(
206
-                    'transactions_view_transaction_help_tab'                                              => array(
207
-                        'title'    => esc_html__('View Transaction', 'event_espresso'),
208
-                        'filename' => 'transactions_view_transaction'
209
-                    ),
210
-                    'transactions_view_transaction_transaction_details_table_help_tab'                    => array(
211
-                        'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
212
-                        'filename' => 'transactions_view_transaction_transaction_details_table'
213
-                    ),
214
-                    'transactions_view_transaction_attendees_registered_help_tab'                         => array(
215
-                        'title'    => esc_html__('Attendees Registered', 'event_espresso'),
216
-                        'filename' => 'transactions_view_transaction_attendees_registered'
217
-                    ),
218
-                    'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array(
219
-                        'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
220
-                        'filename' => 'transactions_view_transaction_primary_registrant_billing_information'
221
-                    ),
222
-                ),
223
-                'qtips'     => array('Transaction_Details_Tips'),
224
-                'help_tour' => array('Transaction_Details_Help_Tour'),
225
-                'metaboxes' => array('_transaction_details_metaboxes'),
226
-
227
-                'require_nonce' => false
228
-            )
229
-        );
230
-    }
231
-
232
-
233
-    /**
234
-     * The below methods aren't used by this class currently
235
-     */
236
-    protected function _add_screen_options()
237
-    {
238
-    }
239
-
240
-    protected function _add_feature_pointers()
241
-    {
242
-    }
243
-
244
-    public function admin_init()
245
-    {
246
-        // IF a registration was JUST added via the admin...
247
-        if (
248
-        isset(
249
-            $this->_req_data['redirect_from'],
250
-            $this->_req_data['EVT_ID'],
251
-            $this->_req_data['event_name']
252
-        )
253
-        ) {
254
-            // then set a cookie so that we can block any attempts to use
255
-            // the back button as a way to enter another registration.
256
-            setcookie('ee_registration_added', $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/');
257
-            // and update the global
258
-            $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID'];
259
-        }
260
-        EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__('An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
261
-            'event_espresso');
262
-        EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__('An error occurred! Please refresh the page and try again.',
263
-            'event_espresso');
264
-        EE_Registry::$i18n_js_strings['txn_status_array']        = self::$_txn_status;
265
-        EE_Registry::$i18n_js_strings['pay_status_array']        = self::$_pay_status;
266
-        EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso');
267
-        EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__('This transaction has been overpaid ! Payments Total',
268
-            'event_espresso');
269
-    }
270
-
271
-    public function admin_notices()
272
-    {
273
-    }
274
-
275
-    public function admin_footer_scripts()
276
-    {
277
-    }
278
-
279
-
280
-    /**
281
-     * _set_transaction_status_array
282
-     * sets list of transaction statuses
283
-     *
284
-     * @access private
285
-     * @return void
286
-     */
287
-    private function _set_transaction_status_array()
288
-    {
289
-        self::$_txn_status = EEM_Transaction::instance()->status_array(true);
290
-    }
291
-
292
-
293
-    /**
294
-     * get_transaction_status_array
295
-     * return the transaction status array for wp_list_table
296
-     *
297
-     * @access public
298
-     * @return array
299
-     */
300
-    public function get_transaction_status_array()
301
-    {
302
-        return self::$_txn_status;
303
-    }
304
-
305
-
306
-    /**
307
-     *    get list of payment statuses
308
-     *
309
-     * @access private
310
-     * @return void
311
-     */
312
-    private function _get_payment_status_array()
313
-    {
314
-        self::$_pay_status                      = EEM_Payment::instance()->status_array(true);
315
-        $this->_template_args['payment_status'] = self::$_pay_status;
316
-
317
-    }
318
-
319
-
320
-    /**
321
-     *    _add_screen_options_default
322
-     *
323
-     * @access protected
324
-     * @return void
325
-     */
326
-    protected function _add_screen_options_default()
327
-    {
328
-        $this->_per_page_screen_option();
329
-    }
330
-
331
-
332
-    /**
333
-     * load_scripts_styles
334
-     *
335
-     * @access public
336
-     * @return void
337
-     */
338
-    public function load_scripts_styles()
339
-    {
340
-        //enqueue style
341
-        wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(),
342
-            EVENT_ESPRESSO_VERSION);
343
-        wp_enqueue_style('espresso_txn');
344
-        //scripts
345
-        wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array(
346
-            'ee_admin_js',
347
-            'ee-datepicker',
348
-            'jquery-ui-datepicker',
349
-            'jquery-ui-draggable',
350
-            'ee-dialog',
351
-            'ee-accounting',
352
-            'ee-serialize-full-array'
353
-        ), EVENT_ESPRESSO_VERSION, true);
354
-        wp_enqueue_script('espresso_txn');
355
-
356
-    }
357
-
358
-
359
-    /**
360
-     *    load_scripts_styles_view_transaction
361
-     *
362
-     * @access public
363
-     * @return void
364
-     */
365
-    public function load_scripts_styles_view_transaction()
366
-    {
367
-        //styles
368
-        wp_enqueue_style('espresso-ui-theme');
369
-    }
370
-
371
-
372
-    /**
373
-     *    load_scripts_styles_default
374
-     *
375
-     * @access public
376
-     * @return void
377
-     */
378
-    public function load_scripts_styles_default()
379
-    {
380
-        //styles
381
-        wp_enqueue_style('espresso-ui-theme');
382
-    }
383
-
384
-
385
-    /**
386
-     *    _set_list_table_views_default
387
-     *
388
-     * @access protected
389
-     * @return void
390
-     */
391
-    protected function _set_list_table_views_default()
392
-    {
393
-        $this->_views = array(
394
-            'all'       => array(
395
-                'slug'  => 'all',
396
-                'label' => esc_html__('View All Transactions', 'event_espresso'),
397
-                'count' => 0
398
-            ),
399
-            'abandoned' => array(
400
-                'slug'  => 'abandoned',
401
-                'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
402
-                'count' => 0
403
-            ),
404
-            'failed'    => array(
405
-                'slug'  => 'failed',
406
-                'label' => esc_html__('Failed Transactions', 'event_espresso'),
407
-                'count' => 0
408
-            )
409
-        );
410
-    }
411
-
412
-
413
-    /**
414
-     * _set_transaction_object
415
-     * This sets the _transaction property for the transaction details screen
416
-     *
417
-     * @access private
418
-     * @return void
419
-     */
420
-    private function _set_transaction_object()
421
-    {
422
-        if (is_object($this->_transaction)) {
423
-            return;
424
-        } //get out we've already set the object
425
-
426
-        $TXN = EEM_Transaction::instance();
427
-
428
-        $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false;
429
-
430
-        //get transaction object
431
-        $this->_transaction = $TXN->get_one_by_ID($TXN_ID);
432
-        $this->_session     = ! empty($this->_transaction) ? $this->_transaction->get('TXN_session_data') : null;
433
-        $this->_transaction->verify_abandoned_transaction_status();
434
-
435
-        if (empty($this->_transaction)) {
436
-            $error_msg = esc_html__('An error occurred and the details for Transaction ID #',
437
-                    'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso');
438
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
439
-        }
440
-    }
441
-
442
-
443
-    /**
444
-     *    _transaction_legend_items
445
-     *
446
-     * @access protected
447
-     * @return array
448
-     */
449
-    protected function _transaction_legend_items()
450
-    {
451
-        EE_Registry::instance()->load_helper('MSG_Template');
452
-        $items = array();
453
-
454
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
455
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
456
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
457
-                $items['view_related_messages'] = array(
458
-                    'class' => $related_for_icon['css_class'],
459
-                    'desc'  => $related_for_icon['label'],
460
-                );
461
-            }
462
-        }
463
-
464
-        $items = apply_filters(
465
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
466
-            array_merge($items,
467
-                array(
468
-                    'view_details'      => array(
469
-                        'class' => 'dashicons dashicons-cart',
470
-                        'desc'  => esc_html__('View Transaction Details', 'event_espresso')
471
-                    ),
472
-                    'view_invoice'      => array(
473
-                        'class' => 'dashicons dashicons-media-spreadsheet',
474
-                        'desc'  => esc_html__('View Transaction Invoice', 'event_espresso')
475
-                    ),
476
-                    'view_receipt'      => array(
477
-                        'class' => 'dashicons dashicons-media-default',
478
-                        'desc'  => esc_html__('View Transaction Receipt', 'event_espresso')
479
-                    ),
480
-                    'view_registration' => array(
481
-                        'class' => 'dashicons dashicons-clipboard',
482
-                        'desc'  => esc_html__('View Registration Details', 'event_espresso')
483
-                    )
484
-                )
485
-            )
486
-        );
487
-
488
-        if (EE_Registry::instance()->CAP->current_user_can('ee_send_message',
489
-            'espresso_transactions_send_payment_reminder')
490
-        ) {
491
-            if (EEH_MSG_Template::is_mt_active('payment_reminder')) {
492
-                $items['send_payment_reminder'] = array(
493
-                    'class' => 'dashicons dashicons-email-alt',
494
-                    'desc'  => esc_html__('Send Payment Reminder', 'event_espresso')
495
-                );
496
-            } else {
497
-                $items['blank*'] = array(
498
-                    'class' => '',
499
-                    'desc'  => ''
500
-                );
501
-            }
502
-        } else {
503
-            $items['blank*'] = array(
504
-                'class' => '',
505
-                'desc'  => ''
506
-            );
507
-        }
508
-        $more_items = apply_filters(
509
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
510
-            array(
511
-                'overpaid'   => array(
512
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
513
-                    'desc'  => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence')
514
-                ),
515
-                'complete'   => array(
516
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
517
-                    'desc'  => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence')
518
-                ),
519
-                'incomplete' => array(
520
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
521
-                    'desc'  => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence')
522
-                ),
523
-                'abandoned'  => array(
524
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
525
-                    'desc'  => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence')
526
-                ),
527
-                'failed'     => array(
528
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
529
-                    'desc'  => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence')
530
-                )
531
-            )
532
-        );
533
-
534
-        return array_merge($items, $more_items);
535
-    }
536
-
537
-
538
-    /**
539
-     *    _transactions_overview_list_table
540
-     *
541
-     * @access protected
542
-     * @return void
543
-     */
544
-    protected function _transactions_overview_list_table()
545
-    {
546
-        $this->_admin_page_title                   = esc_html__('Transactions', 'event_espresso');
547
-        $event                                     = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null;
548
-        $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s',
549
-            'event_espresso'), '<h3>',
550
-            '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()),
551
-                EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event',
552
-                'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : '';
553
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
554
-        $this->display_admin_list_table_page_with_no_sidebar();
555
-    }
556
-
557
-
558
-    /**
559
-     *    _transaction_details
560
-     * generates HTML for the View Transaction Details Admin page
561
-     *
562
-     * @access protected
563
-     * @return void
564
-     */
565
-    protected function _transaction_details()
566
-    {
567
-        do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
568
-
569
-        $this->_set_transaction_status_array();
570
-
571
-        $this->_template_args                      = array();
572
-        $this->_template_args['transactions_page'] = $this->_wp_page_slug;
573
-
574
-        $this->_set_transaction_object();
575
-
576
-        $primary_registration = $this->_transaction->primary_registration();
577
-        $attendee             = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : null;
578
-
579
-        $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
580
-        $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
581
-
582
-        $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
583
-        $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
584
-
585
-        $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
586
-        $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
587
-        $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
588
-
589
-        $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
590
-        $this->_template_args['total_paid']  = $this->_transaction->get('TXN_paid');
591
-
592
-        if (
593
-            $attendee instanceof EE_Attendee
594
-            && EE_Registry::instance()->CAP->current_user_can(
595
-                'ee_send_message',
596
-                'espresso_transactions_send_payment_reminder'
597
-            )
598
-        ) {
599
-            $this->_template_args['send_payment_reminder_button'] =
600
-                EEH_MSG_Template::is_mt_active('payment_reminder')
601
-                && $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code
602
-                && $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code
603
-                    ? EEH_Template::get_button_or_link(
604
-                    EE_Admin_Page::add_query_args_and_nonce(
605
-                        array(
606
-                            'action'      => 'send_payment_reminder',
607
-                            'TXN_ID'      => $this->_transaction->ID(),
608
-                            'redirect_to' => 'view_transaction'
609
-                        ),
610
-                        TXN_ADMIN_URL
611
-                    ),
612
-                    __(' Send Payment Reminder', 'event_espresso'),
613
-                    'button secondary-button right',
614
-                    'dashicons dashicons-email-alt'
615
-                )
616
-                    : '';
617
-        } else {
618
-            $this->_template_args['send_payment_reminder_button'] = '';
619
-        }
620
-
621
-        $amount_due                         = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
622
-        $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true);
623
-        if (EE_Registry::instance()->CFG->currency->sign_b4) {
624
-            $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due'];
625
-        } else {
626
-            $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign;
627
-        }
628
-        $this->_template_args['amount_due_class'] = '';
629
-
630
-        if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
631
-            // paid in full
632
-            $this->_template_args['amount_due'] = false;
633
-        } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
634
-            // overpaid
635
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
636
-        } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') > 0)) {
637
-            // monies owing
638
-            $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
639
-        } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') == 0)) {
640
-            // no payments made yet
641
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
642
-        } elseif ($this->_transaction->get('TXN_total') == 0) {
643
-            // free event
644
-            $this->_template_args['amount_due'] = false;
645
-        }
646
-
647
-        $payment_method = $this->_transaction->payment_method();
648
-
649
-        $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
650
-            ? $payment_method->admin_name()
651
-            : esc_html__('Unknown', 'event_espresso');
652
-
653
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
654
-        // link back to overview
655
-        $this->_template_args['txn_overview_url'] = ! empty ($_SERVER['HTTP_REFERER'])
656
-            ? $_SERVER['HTTP_REFERER']
657
-            : TXN_ADMIN_URL;
658
-
659
-
660
-        // next link
661
-        $next_txn                                 = $this->_transaction->next(
662
-            null,
663
-            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
664
-            'TXN_ID'
665
-        );
666
-        $this->_template_args['next_transaction'] = $next_txn
667
-            ? $this->_next_link(
668
-                EE_Admin_Page::add_query_args_and_nonce(
669
-                    array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']),
670
-                    TXN_ADMIN_URL
671
-                ),
672
-                'dashicons dashicons-arrow-right ee-icon-size-22'
673
-            )
674
-            : '';
675
-        // previous link
676
-        $previous_txn                                 = $this->_transaction->previous(
677
-            null,
678
-            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
679
-            'TXN_ID'
680
-        );
681
-        $this->_template_args['previous_transaction'] = $previous_txn
682
-            ? $this->_previous_link(
683
-                EE_Admin_Page::add_query_args_and_nonce(
684
-                    array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']),
685
-                    TXN_ADMIN_URL
686
-                ),
687
-                'dashicons dashicons-arrow-left ee-icon-size-22'
688
-            )
689
-            : '';
690
-
691
-        // were we just redirected here after adding a new registration ???
692
-        if (
693
-        isset(
694
-            $this->_req_data['redirect_from'],
695
-            $this->_req_data['EVT_ID'],
696
-            $this->_req_data['event_name']
697
-        )
698
-        ) {
699
-            if (
700
-            EE_Registry::instance()->CAP->current_user_can(
701
-                'ee_edit_registrations',
702
-                'espresso_registrations_new_registration',
703
-                $this->_req_data['EVT_ID']
704
-            )
705
-            ) {
706
-                $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
707
-                $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
708
-                    array(
709
-                        'page'     => 'espresso_registrations',
710
-                        'action'   => 'new_registration',
711
-                        'return'   => 'default',
712
-                        'TXN_ID'   => $this->_transaction->ID(),
713
-                        'event_id' => $this->_req_data['EVT_ID'],
714
-                    ),
715
-                    REG_ADMIN_URL
716
-                );
717
-                $this->_admin_page_title .= '">';
718
-
719
-                $this->_admin_page_title .= sprintf(
720
-                    esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
721
-                    htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8')
722
-                );
723
-                $this->_admin_page_title .= '</a>';
724
-            }
725
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
726
-        }
727
-        // grab messages at the last second
728
-        $this->_template_args['notices'] = EE_Error::get_notices();
729
-        // path to template
730
-        $template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
731
-        $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path,
732
-            $this->_template_args, true);
733
-
734
-        // the details template wrapper
735
-        $this->display_admin_page_with_sidebar();
736
-
737
-    }
738
-
739
-
740
-    /**
741
-     *        _transaction_details_metaboxes
742
-     *
743
-     * @access protected
744
-     * @return void
745
-     */
746
-    protected function _transaction_details_metaboxes()
747
-    {
748
-
749
-        $this->_set_transaction_object();
750
-
751
-        add_meta_box('edit-txn-details-mbox', esc_html__('Transaction Details', 'event_espresso'),
752
-            array($this, 'txn_details_meta_box'), $this->_wp_page_slug, 'normal', 'high');
753
-        add_meta_box(
754
-            'edit-txn-attendees-mbox',
755
-            esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
756
-            array($this, 'txn_attendees_meta_box'),
757
-            $this->_wp_page_slug,
758
-            'normal',
759
-            'high',
760
-            array('TXN_ID' => $this->_transaction->ID())
761
-        );
762
-        add_meta_box('edit-txn-registrant-mbox', esc_html__('Primary Contact', 'event_espresso'),
763
-            array($this, 'txn_registrant_side_meta_box'), $this->_wp_page_slug, 'side', 'high');
764
-        add_meta_box('edit-txn-billing-info-mbox', esc_html__('Billing Information', 'event_espresso'),
765
-            array($this, 'txn_billing_info_side_meta_box'), $this->_wp_page_slug, 'side', 'high');
766
-
767
-    }
768
-
769
-
770
-    /**
771
-     * txn_details_meta_box
772
-     * generates HTML for the Transaction main meta box
773
-     *
774
-     * @access public
775
-     * @return void
776
-     */
777
-    public function txn_details_meta_box()
778
-    {
779
-
780
-        $this->_set_transaction_object();
781
-        $this->_template_args['TXN_ID']   = $this->_transaction->ID();
782
-        $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->attendee() : null;
783
-
784
-        //get line table
785
-        EEH_Autoloader::register_line_item_display_autoloaders();
786
-        $Line_Item_Display                       = new EE_Line_Item_Display('admin_table',
787
-            'EE_Admin_Table_Line_Item_Display_Strategy');
788
-        $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item($this->_transaction->total_line_item());
789
-        $this->_template_args['REG_code']        = $this->_transaction->get_first_related('Registration')->get('REG_code');
790
-
791
-        // process taxes
792
-        $taxes                         = $this->_transaction->get_many_related('Line_Item',
793
-            array(array('LIN_type' => EEM_Line_Item::type_tax)));
794
-        $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
795
-
796
-        $this->_template_args['grand_total']     = EEH_Template::format_currency($this->_transaction->get('TXN_total'),
797
-            false, false);
798
-        $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total');
799
-        $this->_template_args['TXN_status']      = $this->_transaction->get('STS_ID');
30
+	/**
31
+	 * @var EE_Transaction
32
+	 */
33
+	private $_transaction;
34
+
35
+	/**
36
+	 * @var EE_Session
37
+	 */
38
+	private $_session;
39
+
40
+	/**
41
+	 * @var array $_txn_status
42
+	 */
43
+	private static $_txn_status;
44
+
45
+	/**
46
+	 * @var array $_pay_status
47
+	 */
48
+	private static $_pay_status;
49
+
50
+	/**
51
+	 * @var array $_existing_reg_payment_REG_IDs
52
+	 */
53
+	protected $_existing_reg_payment_REG_IDs = null;
54
+
55
+
56
+	/**
57
+	 * @Constructor
58
+	 * @access public
59
+	 *
60
+	 * @param bool $routing
61
+	 *
62
+	 * @return Transactions_Admin_Page
63
+	 */
64
+	public function __construct($routing = true)
65
+	{
66
+		parent::__construct($routing);
67
+	}
68
+
69
+
70
+	/**
71
+	 *    _init_page_props
72
+	 * @return void
73
+	 */
74
+	protected function _init_page_props()
75
+	{
76
+		$this->page_slug        = TXN_PG_SLUG;
77
+		$this->page_label       = esc_html__('Transactions', 'event_espresso');
78
+		$this->_admin_base_url  = TXN_ADMIN_URL;
79
+		$this->_admin_base_path = TXN_ADMIN;
80
+	}
81
+
82
+
83
+	/**
84
+	 *    _ajax_hooks
85
+	 * @return void
86
+	 */
87
+	protected function _ajax_hooks()
88
+	{
89
+		add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds'));
90
+		add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds'));
91
+		add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment'));
92
+	}
93
+
94
+
95
+	/**
96
+	 *    _define_page_props
97
+	 * @return void
98
+	 */
99
+	protected function _define_page_props()
100
+	{
101
+		$this->_admin_page_title = $this->page_label;
102
+		$this->_labels           = array(
103
+			'buttons' => array(
104
+				'add'    => esc_html__('Add New Transaction', 'event_espresso'),
105
+				'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
106
+				'delete' => esc_html__('Delete Transaction', 'event_espresso'),
107
+			)
108
+		);
109
+	}
110
+
111
+
112
+	/**
113
+	 *        grab url requests and route them
114
+	 * @access private
115
+	 * @return void
116
+	 */
117
+	public function _set_page_routes()
118
+	{
119
+
120
+		$this->_set_transaction_status_array();
121
+
122
+		$txn_id = ! empty($this->_req_data['TXN_ID']) && ! is_array($this->_req_data['TXN_ID']) ? $this->_req_data['TXN_ID'] : 0;
123
+
124
+		$this->_page_routes = array(
125
+
126
+			'default' => array(
127
+				'func'       => '_transactions_overview_list_table',
128
+				'capability' => 'ee_read_transactions'
129
+			),
130
+
131
+			'view_transaction' => array(
132
+				'func'       => '_transaction_details',
133
+				'capability' => 'ee_read_transaction',
134
+				'obj_id'     => $txn_id
135
+			),
136
+
137
+			'send_payment_reminder' => array(
138
+				'func'       => '_send_payment_reminder',
139
+				'noheader'   => true,
140
+				'capability' => 'ee_send_message'
141
+			),
142
+
143
+			'espresso_apply_payment' => array(
144
+				'func'       => 'apply_payments_or_refunds',
145
+				'noheader'   => true,
146
+				'capability' => 'ee_edit_payments'
147
+			),
148
+
149
+			'espresso_apply_refund' => array(
150
+				'func'       => 'apply_payments_or_refunds',
151
+				'noheader'   => true,
152
+				'capability' => 'ee_edit_payments'
153
+			),
154
+
155
+			'espresso_delete_payment' => array(
156
+				'func'       => 'delete_payment',
157
+				'noheader'   => true,
158
+				'capability' => 'ee_delete_payments'
159
+			),
160
+
161
+		);
162
+
163
+	}
164
+
165
+
166
+	protected function _set_page_config()
167
+	{
168
+		$this->_page_config = array(
169
+			'default'          => array(
170
+				'nav'           => array(
171
+					'label' => esc_html__('Overview', 'event_espresso'),
172
+					'order' => 10
173
+				),
174
+				'list_table'    => 'EE_Admin_Transactions_List_Table',
175
+				'help_tabs'     => array(
176
+					'transactions_overview_help_tab'                       => array(
177
+						'title'    => esc_html__('Transactions Overview', 'event_espresso'),
178
+						'filename' => 'transactions_overview'
179
+					),
180
+					'transactions_overview_table_column_headings_help_tab' => array(
181
+						'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
182
+						'filename' => 'transactions_overview_table_column_headings'
183
+					),
184
+					'transactions_overview_views_filters_help_tab'         => array(
185
+						'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
186
+						'filename' => 'transactions_overview_views_filters_search'
187
+					),
188
+				),
189
+				'help_tour'     => array('Transactions_Overview_Help_Tour'),
190
+				/**
191
+				 * commented out because currently we are not displaying tips for transaction list table status but this
192
+				 * may change in a later iteration so want to keep the code for then.
193
+				 */
194
+				//'qtips' => array( 'Transactions_List_Table_Tips' ),
195
+				'require_nonce' => false
196
+			),
197
+			'view_transaction' => array(
198
+				'nav'       => array(
199
+					'label'      => esc_html__('View Transaction', 'event_espresso'),
200
+					'order'      => 5,
201
+					'url'        => isset($this->_req_data['TXN_ID']) ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']),
202
+						$this->_current_page_view_url) : $this->_admin_base_url,
203
+					'persistent' => false
204
+				),
205
+				'help_tabs' => array(
206
+					'transactions_view_transaction_help_tab'                                              => array(
207
+						'title'    => esc_html__('View Transaction', 'event_espresso'),
208
+						'filename' => 'transactions_view_transaction'
209
+					),
210
+					'transactions_view_transaction_transaction_details_table_help_tab'                    => array(
211
+						'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
212
+						'filename' => 'transactions_view_transaction_transaction_details_table'
213
+					),
214
+					'transactions_view_transaction_attendees_registered_help_tab'                         => array(
215
+						'title'    => esc_html__('Attendees Registered', 'event_espresso'),
216
+						'filename' => 'transactions_view_transaction_attendees_registered'
217
+					),
218
+					'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array(
219
+						'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
220
+						'filename' => 'transactions_view_transaction_primary_registrant_billing_information'
221
+					),
222
+				),
223
+				'qtips'     => array('Transaction_Details_Tips'),
224
+				'help_tour' => array('Transaction_Details_Help_Tour'),
225
+				'metaboxes' => array('_transaction_details_metaboxes'),
226
+
227
+				'require_nonce' => false
228
+			)
229
+		);
230
+	}
231
+
232
+
233
+	/**
234
+	 * The below methods aren't used by this class currently
235
+	 */
236
+	protected function _add_screen_options()
237
+	{
238
+	}
239
+
240
+	protected function _add_feature_pointers()
241
+	{
242
+	}
243
+
244
+	public function admin_init()
245
+	{
246
+		// IF a registration was JUST added via the admin...
247
+		if (
248
+		isset(
249
+			$this->_req_data['redirect_from'],
250
+			$this->_req_data['EVT_ID'],
251
+			$this->_req_data['event_name']
252
+		)
253
+		) {
254
+			// then set a cookie so that we can block any attempts to use
255
+			// the back button as a way to enter another registration.
256
+			setcookie('ee_registration_added', $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/');
257
+			// and update the global
258
+			$_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID'];
259
+		}
260
+		EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__('An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
261
+			'event_espresso');
262
+		EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__('An error occurred! Please refresh the page and try again.',
263
+			'event_espresso');
264
+		EE_Registry::$i18n_js_strings['txn_status_array']        = self::$_txn_status;
265
+		EE_Registry::$i18n_js_strings['pay_status_array']        = self::$_pay_status;
266
+		EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso');
267
+		EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__('This transaction has been overpaid ! Payments Total',
268
+			'event_espresso');
269
+	}
270
+
271
+	public function admin_notices()
272
+	{
273
+	}
274
+
275
+	public function admin_footer_scripts()
276
+	{
277
+	}
278
+
279
+
280
+	/**
281
+	 * _set_transaction_status_array
282
+	 * sets list of transaction statuses
283
+	 *
284
+	 * @access private
285
+	 * @return void
286
+	 */
287
+	private function _set_transaction_status_array()
288
+	{
289
+		self::$_txn_status = EEM_Transaction::instance()->status_array(true);
290
+	}
291
+
292
+
293
+	/**
294
+	 * get_transaction_status_array
295
+	 * return the transaction status array for wp_list_table
296
+	 *
297
+	 * @access public
298
+	 * @return array
299
+	 */
300
+	public function get_transaction_status_array()
301
+	{
302
+		return self::$_txn_status;
303
+	}
304
+
305
+
306
+	/**
307
+	 *    get list of payment statuses
308
+	 *
309
+	 * @access private
310
+	 * @return void
311
+	 */
312
+	private function _get_payment_status_array()
313
+	{
314
+		self::$_pay_status                      = EEM_Payment::instance()->status_array(true);
315
+		$this->_template_args['payment_status'] = self::$_pay_status;
316
+
317
+	}
318
+
319
+
320
+	/**
321
+	 *    _add_screen_options_default
322
+	 *
323
+	 * @access protected
324
+	 * @return void
325
+	 */
326
+	protected function _add_screen_options_default()
327
+	{
328
+		$this->_per_page_screen_option();
329
+	}
330
+
331
+
332
+	/**
333
+	 * load_scripts_styles
334
+	 *
335
+	 * @access public
336
+	 * @return void
337
+	 */
338
+	public function load_scripts_styles()
339
+	{
340
+		//enqueue style
341
+		wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(),
342
+			EVENT_ESPRESSO_VERSION);
343
+		wp_enqueue_style('espresso_txn');
344
+		//scripts
345
+		wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array(
346
+			'ee_admin_js',
347
+			'ee-datepicker',
348
+			'jquery-ui-datepicker',
349
+			'jquery-ui-draggable',
350
+			'ee-dialog',
351
+			'ee-accounting',
352
+			'ee-serialize-full-array'
353
+		), EVENT_ESPRESSO_VERSION, true);
354
+		wp_enqueue_script('espresso_txn');
355
+
356
+	}
357
+
358
+
359
+	/**
360
+	 *    load_scripts_styles_view_transaction
361
+	 *
362
+	 * @access public
363
+	 * @return void
364
+	 */
365
+	public function load_scripts_styles_view_transaction()
366
+	{
367
+		//styles
368
+		wp_enqueue_style('espresso-ui-theme');
369
+	}
370
+
371
+
372
+	/**
373
+	 *    load_scripts_styles_default
374
+	 *
375
+	 * @access public
376
+	 * @return void
377
+	 */
378
+	public function load_scripts_styles_default()
379
+	{
380
+		//styles
381
+		wp_enqueue_style('espresso-ui-theme');
382
+	}
383
+
384
+
385
+	/**
386
+	 *    _set_list_table_views_default
387
+	 *
388
+	 * @access protected
389
+	 * @return void
390
+	 */
391
+	protected function _set_list_table_views_default()
392
+	{
393
+		$this->_views = array(
394
+			'all'       => array(
395
+				'slug'  => 'all',
396
+				'label' => esc_html__('View All Transactions', 'event_espresso'),
397
+				'count' => 0
398
+			),
399
+			'abandoned' => array(
400
+				'slug'  => 'abandoned',
401
+				'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
402
+				'count' => 0
403
+			),
404
+			'failed'    => array(
405
+				'slug'  => 'failed',
406
+				'label' => esc_html__('Failed Transactions', 'event_espresso'),
407
+				'count' => 0
408
+			)
409
+		);
410
+	}
411
+
412
+
413
+	/**
414
+	 * _set_transaction_object
415
+	 * This sets the _transaction property for the transaction details screen
416
+	 *
417
+	 * @access private
418
+	 * @return void
419
+	 */
420
+	private function _set_transaction_object()
421
+	{
422
+		if (is_object($this->_transaction)) {
423
+			return;
424
+		} //get out we've already set the object
425
+
426
+		$TXN = EEM_Transaction::instance();
427
+
428
+		$TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false;
429
+
430
+		//get transaction object
431
+		$this->_transaction = $TXN->get_one_by_ID($TXN_ID);
432
+		$this->_session     = ! empty($this->_transaction) ? $this->_transaction->get('TXN_session_data') : null;
433
+		$this->_transaction->verify_abandoned_transaction_status();
434
+
435
+		if (empty($this->_transaction)) {
436
+			$error_msg = esc_html__('An error occurred and the details for Transaction ID #',
437
+					'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso');
438
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
439
+		}
440
+	}
441
+
442
+
443
+	/**
444
+	 *    _transaction_legend_items
445
+	 *
446
+	 * @access protected
447
+	 * @return array
448
+	 */
449
+	protected function _transaction_legend_items()
450
+	{
451
+		EE_Registry::instance()->load_helper('MSG_Template');
452
+		$items = array();
453
+
454
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
455
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
456
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
457
+				$items['view_related_messages'] = array(
458
+					'class' => $related_for_icon['css_class'],
459
+					'desc'  => $related_for_icon['label'],
460
+				);
461
+			}
462
+		}
463
+
464
+		$items = apply_filters(
465
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
466
+			array_merge($items,
467
+				array(
468
+					'view_details'      => array(
469
+						'class' => 'dashicons dashicons-cart',
470
+						'desc'  => esc_html__('View Transaction Details', 'event_espresso')
471
+					),
472
+					'view_invoice'      => array(
473
+						'class' => 'dashicons dashicons-media-spreadsheet',
474
+						'desc'  => esc_html__('View Transaction Invoice', 'event_espresso')
475
+					),
476
+					'view_receipt'      => array(
477
+						'class' => 'dashicons dashicons-media-default',
478
+						'desc'  => esc_html__('View Transaction Receipt', 'event_espresso')
479
+					),
480
+					'view_registration' => array(
481
+						'class' => 'dashicons dashicons-clipboard',
482
+						'desc'  => esc_html__('View Registration Details', 'event_espresso')
483
+					)
484
+				)
485
+			)
486
+		);
487
+
488
+		if (EE_Registry::instance()->CAP->current_user_can('ee_send_message',
489
+			'espresso_transactions_send_payment_reminder')
490
+		) {
491
+			if (EEH_MSG_Template::is_mt_active('payment_reminder')) {
492
+				$items['send_payment_reminder'] = array(
493
+					'class' => 'dashicons dashicons-email-alt',
494
+					'desc'  => esc_html__('Send Payment Reminder', 'event_espresso')
495
+				);
496
+			} else {
497
+				$items['blank*'] = array(
498
+					'class' => '',
499
+					'desc'  => ''
500
+				);
501
+			}
502
+		} else {
503
+			$items['blank*'] = array(
504
+				'class' => '',
505
+				'desc'  => ''
506
+			);
507
+		}
508
+		$more_items = apply_filters(
509
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
510
+			array(
511
+				'overpaid'   => array(
512
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
513
+					'desc'  => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence')
514
+				),
515
+				'complete'   => array(
516
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
517
+					'desc'  => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence')
518
+				),
519
+				'incomplete' => array(
520
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
521
+					'desc'  => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence')
522
+				),
523
+				'abandoned'  => array(
524
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
525
+					'desc'  => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence')
526
+				),
527
+				'failed'     => array(
528
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
529
+					'desc'  => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence')
530
+				)
531
+			)
532
+		);
533
+
534
+		return array_merge($items, $more_items);
535
+	}
536
+
537
+
538
+	/**
539
+	 *    _transactions_overview_list_table
540
+	 *
541
+	 * @access protected
542
+	 * @return void
543
+	 */
544
+	protected function _transactions_overview_list_table()
545
+	{
546
+		$this->_admin_page_title                   = esc_html__('Transactions', 'event_espresso');
547
+		$event                                     = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null;
548
+		$this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s',
549
+			'event_espresso'), '<h3>',
550
+			'<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()),
551
+				EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event',
552
+				'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : '';
553
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
554
+		$this->display_admin_list_table_page_with_no_sidebar();
555
+	}
556
+
557
+
558
+	/**
559
+	 *    _transaction_details
560
+	 * generates HTML for the View Transaction Details Admin page
561
+	 *
562
+	 * @access protected
563
+	 * @return void
564
+	 */
565
+	protected function _transaction_details()
566
+	{
567
+		do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
568
+
569
+		$this->_set_transaction_status_array();
570
+
571
+		$this->_template_args                      = array();
572
+		$this->_template_args['transactions_page'] = $this->_wp_page_slug;
573
+
574
+		$this->_set_transaction_object();
575
+
576
+		$primary_registration = $this->_transaction->primary_registration();
577
+		$attendee             = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : null;
578
+
579
+		$this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
580
+		$this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
581
+
582
+		$this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
583
+		$this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
584
+
585
+		$this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
586
+		$this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
587
+		$this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
588
+
589
+		$this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
590
+		$this->_template_args['total_paid']  = $this->_transaction->get('TXN_paid');
591
+
592
+		if (
593
+			$attendee instanceof EE_Attendee
594
+			&& EE_Registry::instance()->CAP->current_user_can(
595
+				'ee_send_message',
596
+				'espresso_transactions_send_payment_reminder'
597
+			)
598
+		) {
599
+			$this->_template_args['send_payment_reminder_button'] =
600
+				EEH_MSG_Template::is_mt_active('payment_reminder')
601
+				&& $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code
602
+				&& $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code
603
+					? EEH_Template::get_button_or_link(
604
+					EE_Admin_Page::add_query_args_and_nonce(
605
+						array(
606
+							'action'      => 'send_payment_reminder',
607
+							'TXN_ID'      => $this->_transaction->ID(),
608
+							'redirect_to' => 'view_transaction'
609
+						),
610
+						TXN_ADMIN_URL
611
+					),
612
+					__(' Send Payment Reminder', 'event_espresso'),
613
+					'button secondary-button right',
614
+					'dashicons dashicons-email-alt'
615
+				)
616
+					: '';
617
+		} else {
618
+			$this->_template_args['send_payment_reminder_button'] = '';
619
+		}
620
+
621
+		$amount_due                         = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
622
+		$this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true);
623
+		if (EE_Registry::instance()->CFG->currency->sign_b4) {
624
+			$this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due'];
625
+		} else {
626
+			$this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign;
627
+		}
628
+		$this->_template_args['amount_due_class'] = '';
629
+
630
+		if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
631
+			// paid in full
632
+			$this->_template_args['amount_due'] = false;
633
+		} elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
634
+			// overpaid
635
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
636
+		} elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') > 0)) {
637
+			// monies owing
638
+			$this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
639
+		} elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') == 0)) {
640
+			// no payments made yet
641
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
642
+		} elseif ($this->_transaction->get('TXN_total') == 0) {
643
+			// free event
644
+			$this->_template_args['amount_due'] = false;
645
+		}
646
+
647
+		$payment_method = $this->_transaction->payment_method();
648
+
649
+		$this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
650
+			? $payment_method->admin_name()
651
+			: esc_html__('Unknown', 'event_espresso');
652
+
653
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
654
+		// link back to overview
655
+		$this->_template_args['txn_overview_url'] = ! empty ($_SERVER['HTTP_REFERER'])
656
+			? $_SERVER['HTTP_REFERER']
657
+			: TXN_ADMIN_URL;
658
+
659
+
660
+		// next link
661
+		$next_txn                                 = $this->_transaction->next(
662
+			null,
663
+			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
664
+			'TXN_ID'
665
+		);
666
+		$this->_template_args['next_transaction'] = $next_txn
667
+			? $this->_next_link(
668
+				EE_Admin_Page::add_query_args_and_nonce(
669
+					array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']),
670
+					TXN_ADMIN_URL
671
+				),
672
+				'dashicons dashicons-arrow-right ee-icon-size-22'
673
+			)
674
+			: '';
675
+		// previous link
676
+		$previous_txn                                 = $this->_transaction->previous(
677
+			null,
678
+			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
679
+			'TXN_ID'
680
+		);
681
+		$this->_template_args['previous_transaction'] = $previous_txn
682
+			? $this->_previous_link(
683
+				EE_Admin_Page::add_query_args_and_nonce(
684
+					array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']),
685
+					TXN_ADMIN_URL
686
+				),
687
+				'dashicons dashicons-arrow-left ee-icon-size-22'
688
+			)
689
+			: '';
690
+
691
+		// were we just redirected here after adding a new registration ???
692
+		if (
693
+		isset(
694
+			$this->_req_data['redirect_from'],
695
+			$this->_req_data['EVT_ID'],
696
+			$this->_req_data['event_name']
697
+		)
698
+		) {
699
+			if (
700
+			EE_Registry::instance()->CAP->current_user_can(
701
+				'ee_edit_registrations',
702
+				'espresso_registrations_new_registration',
703
+				$this->_req_data['EVT_ID']
704
+			)
705
+			) {
706
+				$this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
707
+				$this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
708
+					array(
709
+						'page'     => 'espresso_registrations',
710
+						'action'   => 'new_registration',
711
+						'return'   => 'default',
712
+						'TXN_ID'   => $this->_transaction->ID(),
713
+						'event_id' => $this->_req_data['EVT_ID'],
714
+					),
715
+					REG_ADMIN_URL
716
+				);
717
+				$this->_admin_page_title .= '">';
718
+
719
+				$this->_admin_page_title .= sprintf(
720
+					esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
721
+					htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8')
722
+				);
723
+				$this->_admin_page_title .= '</a>';
724
+			}
725
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
726
+		}
727
+		// grab messages at the last second
728
+		$this->_template_args['notices'] = EE_Error::get_notices();
729
+		// path to template
730
+		$template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
731
+		$this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path,
732
+			$this->_template_args, true);
733
+
734
+		// the details template wrapper
735
+		$this->display_admin_page_with_sidebar();
736
+
737
+	}
738
+
739
+
740
+	/**
741
+	 *        _transaction_details_metaboxes
742
+	 *
743
+	 * @access protected
744
+	 * @return void
745
+	 */
746
+	protected function _transaction_details_metaboxes()
747
+	{
748
+
749
+		$this->_set_transaction_object();
750
+
751
+		add_meta_box('edit-txn-details-mbox', esc_html__('Transaction Details', 'event_espresso'),
752
+			array($this, 'txn_details_meta_box'), $this->_wp_page_slug, 'normal', 'high');
753
+		add_meta_box(
754
+			'edit-txn-attendees-mbox',
755
+			esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
756
+			array($this, 'txn_attendees_meta_box'),
757
+			$this->_wp_page_slug,
758
+			'normal',
759
+			'high',
760
+			array('TXN_ID' => $this->_transaction->ID())
761
+		);
762
+		add_meta_box('edit-txn-registrant-mbox', esc_html__('Primary Contact', 'event_espresso'),
763
+			array($this, 'txn_registrant_side_meta_box'), $this->_wp_page_slug, 'side', 'high');
764
+		add_meta_box('edit-txn-billing-info-mbox', esc_html__('Billing Information', 'event_espresso'),
765
+			array($this, 'txn_billing_info_side_meta_box'), $this->_wp_page_slug, 'side', 'high');
766
+
767
+	}
768
+
769
+
770
+	/**
771
+	 * txn_details_meta_box
772
+	 * generates HTML for the Transaction main meta box
773
+	 *
774
+	 * @access public
775
+	 * @return void
776
+	 */
777
+	public function txn_details_meta_box()
778
+	{
779
+
780
+		$this->_set_transaction_object();
781
+		$this->_template_args['TXN_ID']   = $this->_transaction->ID();
782
+		$this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->attendee() : null;
783
+
784
+		//get line table
785
+		EEH_Autoloader::register_line_item_display_autoloaders();
786
+		$Line_Item_Display                       = new EE_Line_Item_Display('admin_table',
787
+			'EE_Admin_Table_Line_Item_Display_Strategy');
788
+		$this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item($this->_transaction->total_line_item());
789
+		$this->_template_args['REG_code']        = $this->_transaction->get_first_related('Registration')->get('REG_code');
790
+
791
+		// process taxes
792
+		$taxes                         = $this->_transaction->get_many_related('Line_Item',
793
+			array(array('LIN_type' => EEM_Line_Item::type_tax)));
794
+		$this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
795
+
796
+		$this->_template_args['grand_total']     = EEH_Template::format_currency($this->_transaction->get('TXN_total'),
797
+			false, false);
798
+		$this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total');
799
+		$this->_template_args['TXN_status']      = $this->_transaction->get('STS_ID');
800 800
 
801 801
 //		$txn_status_class = 'status-' . $this->_transaction->get('STS_ID');
802 802
 
803
-        // process payment details
804
-        $payments = $this->_transaction->get_many_related('Payment');
805
-        if ( ! empty($payments)) {
806
-            $this->_template_args['payments']              = $payments;
807
-            $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
808
-        } else {
809
-            $this->_template_args['payments']              = false;
810
-            $this->_template_args['existing_reg_payments'] = array();
811
-        }
812
-
813
-        $this->_template_args['edit_payment_url']   = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL);
814
-        $this->_template_args['delete_payment_url'] = add_query_arg(array('action' => 'espresso_delete_payment'),
815
-            TXN_ADMIN_URL);
816
-
817
-        if (isset($txn_details['invoice_number'])) {
818
-            $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
819
-            $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__('Invoice Number',
820
-                'event_espresso');
821
-        }
822
-
823
-        $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction->get_first_related('Registration')->get('REG_session');
824
-        $this->_template_args['txn_details']['registration_session']['label'] = esc_html__('Registration Session',
825
-            'event_espresso');
826
-
827
-        $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '';
828
-        $this->_template_args['txn_details']['ip_address']['label'] = esc_html__('Transaction placed from IP',
829
-            'event_espresso');
830
-
831
-        $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '';
832
-        $this->_template_args['txn_details']['user_agent']['label'] = esc_html__('Registrant User Agent',
833
-            'event_espresso');
834
-
835
-        $reg_steps = '<ul>';
836
-        foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
837
-            if ($reg_step_status === true) {
838
-                $reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'),
839
-                        ucwords(str_replace('_', ' ', $reg_step))) . '</li>';
840
-            } else if (is_numeric($reg_step_status) && $reg_step_status !== false) {
841
-                $reg_steps .= '<li style="color:#2EA2CC">' . sprintf(
842
-                        esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
843
-                        ucwords(str_replace('_', ' ', $reg_step)),
844
-                        date(get_option('date_format') . ' ' . get_option('time_format'),
845
-                            ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)))
846
-                    ) . '</li>';
847
-            } else {
848
-                $reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated',
849
-                        'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>';
850
-            }
851
-        }
852
-        $reg_steps .= '</ul>';
853
-        $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
854
-        $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__('Registration Step Progress',
855
-            'event_espresso');
856
-
857
-
858
-        $this->_get_registrations_to_apply_payment_to();
859
-        $this->_get_payment_methods($payments);
860
-        $this->_get_payment_status_array();
861
-        $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction.
862
-
863
-        $this->_template_args['transaction_form_url']    = add_query_arg(array(
864
-            'action'  => 'edit_transaction',
865
-            'process' => 'transaction'
866
-        ), TXN_ADMIN_URL);
867
-        $this->_template_args['apply_payment_form_url']  = add_query_arg(array(
868
-            'page'   => 'espresso_transactions',
869
-            'action' => 'espresso_apply_payment'
870
-        ), WP_AJAX_URL);
871
-        $this->_template_args['delete_payment_form_url'] = add_query_arg(array(
872
-            'page'   => 'espresso_transactions',
873
-            'action' => 'espresso_delete_payment'
874
-        ), WP_AJAX_URL);
875
-
876
-        // 'espresso_delete_payment_nonce'
877
-
878
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
879
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
880
-
881
-    }
882
-
883
-
884
-    /**
885
-     * _get_registration_payment_IDs
886
-     *
887
-     *    generates an array of Payment IDs and their corresponding Registration IDs
888
-     *
889
-     * @access protected
890
-     *
891
-     * @param EE_Payment[] $payments
892
-     *
893
-     * @return array
894
-     */
895
-    protected function _get_registration_payment_IDs($payments = array())
896
-    {
897
-        $existing_reg_payments = array();
898
-        // get all reg payments for these payments
899
-        $reg_payments = EEM_Registration_Payment::instance()->get_all(array(
900
-            array(
901
-                'PAY_ID' => array(
902
-                    'IN',
903
-                    array_keys($payments)
904
-                )
905
-            )
906
-        ));
907
-        if ( ! empty($reg_payments)) {
908
-            foreach ($payments as $payment) {
909
-                if ( ! $payment instanceof EE_Payment) {
910
-                    continue;
911
-                } else if ( ! isset($existing_reg_payments[$payment->ID()])) {
912
-                    $existing_reg_payments[$payment->ID()] = array();
913
-                }
914
-                foreach ($reg_payments as $reg_payment) {
915
-                    if ($reg_payment instanceof EE_Registration_Payment && $reg_payment->payment_ID() === $payment->ID()) {
916
-                        $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID();
917
-                    }
918
-                }
919
-            }
920
-        }
921
-
922
-        return $existing_reg_payments;
923
-    }
924
-
925
-
926
-    /**
927
-     * _get_registrations_to_apply_payment_to
928
-     *    generates HTML for displaying a series of checkboxes in the admin payment modal window
929
-     * which allows the admin to only apply the payment to the specific registrations
930
-     *
931
-     * @access protected
932
-     * @return void
933
-     * @throws \EE_Error
934
-     */
935
-    protected function _get_registrations_to_apply_payment_to()
936
-    {
937
-        // we want any registration with an active status (ie: not deleted or cancelled)
938
-        $query_params                      = array(
939
-            array(
940
-                'STS_ID' => array(
941
-                    'IN',
942
-                    array(
943
-                        EEM_Registration::status_id_approved,
944
-                        EEM_Registration::status_id_pending_payment,
945
-                        EEM_Registration::status_id_not_approved,
946
-                    )
947
-                )
948
-            )
949
-        );
950
-        $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div(
951
-                '', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;'
952
-            );
953
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
954
-        $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
955
-        $registrations_to_apply_payment_to .= EEH_HTML::thead(
956
-            EEH_HTML::tr(
957
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
958
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
959
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
960
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
961
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
962
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
963
-                EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
964
-            )
965
-        );
966
-        $registrations_to_apply_payment_to .= EEH_HTML::tbody();
967
-        // get registrations for TXN
968
-        $registrations = $this->_transaction->registrations($query_params);
969
-        foreach ($registrations as $registration) {
970
-            if ($registration instanceof EE_Registration) {
971
-                $attendee_name = $registration->attendee() instanceof EE_Attendee
972
-                    ? $registration->attendee()->full_name()
973
-                    : esc_html__('Unknown Attendee', 'event_espresso');
974
-                $owing         = $registration->final_price() - $registration->paid();
975
-                $taxable       = $registration->ticket()->taxable()
976
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
977
-                    : '';
978
-                $checked       = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
979
-                    ? ' checked="checked"'
980
-                    : '';
981
-                $disabled      = $registration->final_price() > 0 ? '' : ' disabled';
982
-                $registrations_to_apply_payment_to .= EEH_HTML::tr(
983
-                    EEH_HTML::td($registration->ID()) .
984
-                    EEH_HTML::td($attendee_name) .
985
-                    EEH_HTML::td(
986
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
987
-                    ) .
988
-                    EEH_HTML::td($registration->event_name()) .
989
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
990
-                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
991
-                    EEH_HTML::td(
992
-                        '<input type="checkbox" value="' . $registration->ID()
993
-                        . '" name="txn_admin_payment[registrations]"'
994
-                        . $checked . $disabled . '>',
995
-                        '', 'jst-cntr'
996
-                    ),
997
-                    'apply-payment-registration-row-' . $registration->ID()
998
-                );
999
-            }
1000
-        }
1001
-        $registrations_to_apply_payment_to .= EEH_HTML::tbodyx();
1002
-        $registrations_to_apply_payment_to .= EEH_HTML::tablex();
1003
-        $registrations_to_apply_payment_to .= EEH_HTML::divx();
1004
-        $registrations_to_apply_payment_to .= EEH_HTML::p(
1005
-            esc_html__(
1006
-                'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.',
1007
-                'event_espresso'
1008
-            ),
1009
-            '', 'clear description'
1010
-        );
1011
-        $registrations_to_apply_payment_to .= EEH_HTML::divx();
1012
-        $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1013
-    }
1014
-
1015
-
1016
-    /**
1017
-     * _get_reg_status_selection
1018
-     *
1019
-     * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1020
-     *         instead of events.
1021
-     * @access protected
1022
-     * @return void
1023
-     */
1024
-    protected function _get_reg_status_selection()
1025
-    {
1026
-        //first get all possible statuses
1027
-        $statuses = EEM_Registration::reg_status_array(array(), true);
1028
-        //let's add a "don't change" option.
1029
-        $status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso');
1030
-        $status_array                                        = array_merge($status_array, $statuses);
1031
-        $this->_template_args['status_change_select']        = EEH_Form_Fields::select_input('txn_reg_status_change[reg_status]',
1032
-            $status_array, 'NAN', 'id="txn-admin-payment-reg-status-inp"', 'txn-reg-status-change-reg-status');
1033
-        $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input('delete_txn_reg_status_change[reg_status]',
1034
-            $status_array, 'NAN', 'delete-txn-admin-payment-reg-status-inp', 'delete-txn-reg-status-change-reg-status');
1035
-
1036
-    }
1037
-
1038
-
1039
-    /**
1040
-     *    _get_payment_methods
1041
-     * Gets all the payment methods available generally, or the ones that are already
1042
-     * selected on these payments (in case their payment methods are no longer active).
1043
-     * Has the side-effect of updating the template args' payment_methods item
1044
-     * @access private
1045
-     *
1046
-     * @param EE_Payment[] to show on this page
1047
-     *
1048
-     * @return void
1049
-     */
1050
-    private function _get_payment_methods($payments = array())
1051
-    {
1052
-        $payment_methods_of_payments = array();
1053
-        foreach ($payments as $payment) {
1054
-            if ($payment instanceof EE_Payment) {
1055
-                $payment_methods_of_payments[] = $payment->get('PMD_ID');
1056
-            }
1057
-        }
1058
-        if ($payment_methods_of_payments) {
1059
-            $query_args = array(
1060
-                array(
1061
-                    'OR*payment_method_for_payment' => array(
1062
-                        'PMD_ID'    => array('IN', $payment_methods_of_payments),
1063
-                        'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')
1064
-                    )
1065
-                )
1066
-            );
1067
-        } else {
1068
-            $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1069
-        }
1070
-        $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1071
-    }
1072
-
1073
-
1074
-    /**
1075
-     * txn_attendees_meta_box
1076
-     *    generates HTML for the Attendees Transaction main meta box
1077
-     *
1078
-     * @access public
1079
-     *
1080
-     * @param WP_Post $post
1081
-     * @param array   $metabox
1082
-     *
1083
-     * @return void
1084
-     */
1085
-    public function txn_attendees_meta_box($post, $metabox = array('args' => array()))
1086
-    {
1087
-
1088
-        extract($metabox['args']);
1089
-        $this->_template_args['post']            = $post;
1090
-        $this->_template_args['event_attendees'] = array();
1091
-        // process items in cart
1092
-        $line_items = $this->_transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item')));
1093
-        if ( ! empty($line_items)) {
1094
-            foreach ($line_items as $item) {
1095
-                if ($item instanceof EE_Line_Item) {
1096
-                    switch ($item->OBJ_type()) {
1097
-
1098
-                        case 'Event' :
1099
-                            break;
1100
-
1101
-                        case 'Ticket' :
1102
-                            $ticket = $item->ticket();
1103
-                            //right now we're only handling tickets here.  Cause its expected that only tickets will have attendees right?
1104
-                            if ( ! $ticket instanceof EE_Ticket) {
1105
-                                continue;
1106
-                            }
1107
-                            try {
1108
-                                $event_name = $ticket->get_event_name();
1109
-                            } catch (Exception $e) {
1110
-                                EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1111
-                                $event_name = esc_html__('Unknown Event', 'event_espresso');
1112
-                            }
1113
-                            $event_name .= ' - ' . $item->get('LIN_name');
1114
-                            $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1115
-                            // now get all of the registrations for this transaction that use this ticket
1116
-                            $registrations = $ticket->get_many_related('Registration',
1117
-                                array(array('TXN_ID' => $this->_transaction->ID())));
1118
-                            foreach ($registrations as $registration) {
1119
-                                if ( ! $registration instanceof EE_Registration) {
1120
-                                    continue;
1121
-                                }
1122
-                                $this->_template_args['event_attendees'][$registration->ID()]['STS_ID']            = $registration->status_ID();
1123
-                                $this->_template_args['event_attendees'][$registration->ID()]['att_num']           = $registration->count();
1124
-                                $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] = $event_name;
1125
-                                $this->_template_args['event_attendees'][$registration->ID()]['ticket_price']      = $ticket_price;
1126
-                                // attendee info
1127
-                                $attendee = $registration->get_first_related('Attendee');
1128
-                                if ($attendee instanceof EE_Attendee) {
1129
-                                    $this->_template_args['event_attendees'][$registration->ID()]['att_id']   = $attendee->ID();
1130
-                                    $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name();
1131
-                                    $this->_template_args['event_attendees'][$registration->ID()]['email']    = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event',
1132
-                                            'event_espresso') . '">' . $attendee->email() . '</a>';
1133
-                                    $this->_template_args['event_attendees'][$registration->ID()]['address']  = EEH_Address::format($attendee,
1134
-                                        'inline', false, false);
1135
-                                } else {
1136
-                                    $this->_template_args['event_attendees'][$registration->ID()]['att_id']   = '';
1137
-                                    $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = '';
1138
-                                    $this->_template_args['event_attendees'][$registration->ID()]['email']    = '';
1139
-                                    $this->_template_args['event_attendees'][$registration->ID()]['address']  = '';
1140
-                                }
1141
-                            }
1142
-                            break;
1143
-
1144
-                    }
1145
-                }
1146
-            }
1147
-
1148
-            $this->_template_args['transaction_form_url'] = add_query_arg(array(
1149
-                'action'  => 'edit_transaction',
1150
-                'process' => 'attendees'
1151
-            ), TXN_ADMIN_URL);
1152
-            echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1153
-                $this->_template_args, true);
1154
-
1155
-        } else {
1156
-            echo sprintf(
1157
-                esc_html__('%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1158
-                    'event_espresso'),
1159
-                '<p class="important-notice">',
1160
-                '</p>'
1161
-            );
1162
-        }
1163
-    }
1164
-
1165
-
1166
-    /**
1167
-     * txn_registrant_side_meta_box
1168
-     * generates HTML for the Edit Transaction side meta box
1169
-     *
1170
-     * @access public
1171
-     * @throws \EE_Error
1172
-     * @return void
1173
-     */
1174
-    public function txn_registrant_side_meta_box()
1175
-    {
1176
-        $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->get_first_related('Attendee') : null;
1177
-        if ( ! $primary_att instanceof EE_Attendee) {
1178
-            $this->_template_args['no_attendee_message'] = esc_html__('There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1179
-                'event_espresso');
1180
-            $primary_att                                 = EEM_Attendee::instance()->create_default_object();
1181
-        }
1182
-        $this->_template_args['ATT_ID']            = $primary_att->ID();
1183
-        $this->_template_args['prime_reg_fname']   = $primary_att->fname();
1184
-        $this->_template_args['prime_reg_lname']   = $primary_att->lname();
1185
-        $this->_template_args['prime_reg_email']   = $primary_att->email();
1186
-        $this->_template_args['prime_reg_phone']   = $primary_att->phone();
1187
-        $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array(
1188
-            'action' => 'edit_attendee',
1189
-            'post'   => $primary_att->ID()
1190
-        ), REG_ADMIN_URL);
1191
-        // get formatted address for registrant
1192
-        $this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1193
-        echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1194
-            $this->_template_args, true);
1195
-    }
1196
-
1197
-
1198
-    /**
1199
-     * txn_billing_info_side_meta_box
1200
-     *    generates HTML for the Edit Transaction side meta box
1201
-     *
1202
-     * @access public
1203
-     * @return void
1204
-     */
1205
-    public function txn_billing_info_side_meta_box()
1206
-    {
1207
-
1208
-        $this->_template_args['billing_form']     = $this->_transaction->billing_info();
1209
-        $this->_template_args['billing_form_url'] = add_query_arg(
1210
-            array('action' => 'edit_transaction', 'process' => 'billing'),
1211
-            TXN_ADMIN_URL
1212
-        );
1213
-
1214
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1215
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1216
-    }
1217
-
1218
-
1219
-    /**
1220
-     * apply_payments_or_refunds
1221
-     *    registers a payment or refund made towards a transaction
1222
-     *
1223
-     * @access public
1224
-     * @return void
1225
-     */
1226
-    public function apply_payments_or_refunds()
1227
-    {
1228
-        $json_response_data = array('return_data' => false);
1229
-        $valid_data         = $this->_validate_payment_request_data();
1230
-        if ( ! empty($valid_data)) {
1231
-            $PAY_ID = $valid_data['PAY_ID'];
1232
-            //save  the new payment
1233
-            $payment = $this->_create_payment_from_request_data($valid_data);
1234
-            // get the TXN for this payment
1235
-            $transaction = $payment->transaction();
1236
-            // verify transaction
1237
-            if ($transaction instanceof EE_Transaction) {
1238
-                // calculate_total_payments_and_update_status
1239
-                $this->_process_transaction_payments($transaction);
1240
-                $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1241
-                $this->_remove_existing_registration_payments($payment, $PAY_ID);
1242
-                // apply payment to registrations (if applicable)
1243
-                if ( ! empty($REG_IDs)) {
1244
-                    $this->_update_registration_payments($transaction, $payment, $REG_IDs);
1245
-                    $this->_maybe_send_notifications();
1246
-                    // now process status changes for the same registrations
1247
-                    $this->_process_registration_status_change($transaction, $REG_IDs);
1248
-                }
1249
-                $this->_maybe_send_notifications($payment);
1250
-                //prepare to render page
1251
-                $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1252
-                do_action('AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', $transaction,
1253
-                    $payment);
1254
-            } else {
1255
-                EE_Error::add_error(
1256
-                    esc_html__('A valid Transaction for this payment could not be retrieved.', 'event_espresso'),
1257
-                    __FILE__, __FUNCTION__, __LINE__
1258
-                );
1259
-            }
1260
-        } else {
1261
-            EE_Error::add_error(esc_html__('The payment form data could not be processed. Please try again.',
1262
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1263
-        }
1264
-
1265
-        $notices              = EE_Error::get_notices(false, false, false);
1266
-        $this->_template_args = array(
1267
-            'data'    => $json_response_data,
1268
-            'error'   => $notices['errors'],
1269
-            'success' => $notices['success']
1270
-        );
1271
-        $this->_return_json();
1272
-    }
1273
-
1274
-
1275
-    /**
1276
-     * _validate_payment_request_data
1277
-     *
1278
-     * @return array
1279
-     */
1280
-    protected function _validate_payment_request_data()
1281
-    {
1282
-        if ( ! isset($this->_req_data['txn_admin_payment'])) {
1283
-            return false;
1284
-        }
1285
-        $payment_form = $this->_generate_payment_form_section();
1286
-        try {
1287
-            if ($payment_form->was_submitted()) {
1288
-                $payment_form->receive_form_submission();
1289
-                if ( ! $payment_form->is_valid()) {
1290
-                    $submission_error_messages = array();
1291
-                    foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1292
-                        if ($validation_error instanceof EE_Validation_Error) {
1293
-                            $submission_error_messages[] = sprintf(
1294
-                                _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1295
-                                $validation_error->get_form_section()->html_label_text(),
1296
-                                $validation_error->getMessage()
1297
-                            );
1298
-                        }
1299
-                    }
1300
-                    EE_Error::add_error(join('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__);
1301
-
1302
-                    return array();
1303
-                }
1304
-            }
1305
-        } catch (EE_Error $e) {
1306
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1307
-
1308
-            return array();
1309
-        }
1310
-
1311
-        return $payment_form->valid_data();
1312
-    }
1313
-
1314
-
1315
-    /**
1316
-     * _generate_payment_form_section
1317
-     *
1318
-     * @return EE_Form_Section_Proper
1319
-     */
1320
-    protected function _generate_payment_form_section()
1321
-    {
1322
-        return new EE_Form_Section_Proper(
1323
-            array(
1324
-                'name'        => 'txn_admin_payment',
1325
-                'subsections' => array(
1326
-                    'PAY_ID'          => new EE_Text_Input(
1327
-                        array(
1328
-                            'default'               => 0,
1329
-                            'required'              => false,
1330
-                            'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1331
-                            'validation_strategies' => array(new EE_Int_Normalization())
1332
-                        )
1333
-                    ),
1334
-                    'TXN_ID'          => new EE_Text_Input(
1335
-                        array(
1336
-                            'default'               => 0,
1337
-                            'required'              => true,
1338
-                            'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1339
-                            'validation_strategies' => array(new EE_Int_Normalization())
1340
-                        )
1341
-                    ),
1342
-                    'type'            => new EE_Text_Input(
1343
-                        array(
1344
-                            'default'               => 1,
1345
-                            'required'              => true,
1346
-                            'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1347
-                            'validation_strategies' => array(new EE_Int_Normalization())
1348
-                        )
1349
-                    ),
1350
-                    'amount'          => new EE_Text_Input(
1351
-                        array(
1352
-                            'default'               => 0,
1353
-                            'required'              => true,
1354
-                            'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1355
-                            'validation_strategies' => array(new EE_Float_Normalization())
1356
-                        )
1357
-                    ),
1358
-                    'status'          => new EE_Text_Input(
1359
-                        array(
1360
-                            'default'         => EEM_Payment::status_id_approved,
1361
-                            'required'        => true,
1362
-                            'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1363
-                        )
1364
-                    ),
1365
-                    'PMD_ID'          => new EE_Text_Input(
1366
-                        array(
1367
-                            'default'               => 2,
1368
-                            'required'              => true,
1369
-                            'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1370
-                            'validation_strategies' => array(new EE_Int_Normalization())
1371
-                        )
1372
-                    ),
1373
-                    'date'            => new EE_Text_Input(
1374
-                        array(
1375
-                            'default'         => time(),
1376
-                            'required'        => true,
1377
-                            'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1378
-                        )
1379
-                    ),
1380
-                    'txn_id_chq_nmbr' => new EE_Text_Input(
1381
-                        array(
1382
-                            'default'               => '',
1383
-                            'required'              => false,
1384
-                            'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1385
-                            'validation_strategies' => array(
1386
-                                new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'),
1387
-                                    100),
1388
-                            )
1389
-                        )
1390
-                    ),
1391
-                    'po_number'       => new EE_Text_Input(
1392
-                        array(
1393
-                            'default'               => '',
1394
-                            'required'              => false,
1395
-                            'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1396
-                            'validation_strategies' => array(
1397
-                                new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'),
1398
-                                    100),
1399
-                            )
1400
-                        )
1401
-                    ),
1402
-                    'accounting'      => new EE_Text_Input(
1403
-                        array(
1404
-                            'default'               => '',
1405
-                            'required'              => false,
1406
-                            'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1407
-                            'validation_strategies' => array(
1408
-                                new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'),
1409
-                                    100),
1410
-                            )
1411
-                        )
1412
-                    ),
1413
-                )
1414
-            )
1415
-        );
1416
-    }
1417
-
1418
-
1419
-    /**
1420
-     * _create_payment_from_request_data
1421
-     *
1422
-     * @param array $valid_data
1423
-     *
1424
-     * @return EE_Payment
1425
-     */
1426
-    protected function _create_payment_from_request_data($valid_data)
1427
-    {
1428
-        $PAY_ID = $valid_data['PAY_ID'];
1429
-        // get payment amount
1430
-        $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1431
-        // payments have a type value of 1 and refunds have a type value of -1
1432
-        // so multiplying amount by type will give a positive value for payments, and negative values for refunds
1433
-        $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1434
-        // for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1435
-        $date    = $valid_data['date'] ? preg_replace('/\s+/', ' ', $valid_data['date']) : date('Y-m-d g:i a',
1436
-            current_time('timestamp'));
1437
-        $payment = EE_Payment::new_instance(
1438
-            array(
1439
-                'TXN_ID'              => $valid_data['TXN_ID'],
1440
-                'STS_ID'              => $valid_data['status'],
1441
-                'PAY_timestamp'       => $date,
1442
-                'PAY_source'          => EEM_Payment_Method::scope_admin,
1443
-                'PMD_ID'              => $valid_data['PMD_ID'],
1444
-                'PAY_amount'          => $amount,
1445
-                'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1446
-                'PAY_po_number'       => $valid_data['po_number'],
1447
-                'PAY_extra_accntng'   => $valid_data['accounting'],
1448
-                'PAY_details'         => $valid_data,
1449
-                'PAY_ID'              => $PAY_ID
1450
-            ),
1451
-            '',
1452
-            array('Y-m-d', 'g:i a')
1453
-        );
1454
-
1455
-        if ( ! $payment->save()) {
1456
-            EE_Error::add_error(
1457
-                sprintf(
1458
-                    esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1459
-                    $payment->ID()
1460
-                ),
1461
-                __FILE__, __FUNCTION__, __LINE__
1462
-            );
1463
-        }
1464
-
1465
-        return $payment;
1466
-    }
1467
-
1468
-
1469
-    /**
1470
-     * _process_transaction_payments
1471
-     *
1472
-     * @param \EE_Transaction $transaction
1473
-     *
1474
-     * @return array
1475
-     */
1476
-    protected function _process_transaction_payments(EE_Transaction $transaction)
1477
-    {
1478
-        /** @type EE_Transaction_Payments $transaction_payments */
1479
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1480
-        //update the transaction with this payment
1481
-        if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1482
-            EE_Error::add_success(esc_html__('The payment has been processed successfully.', 'event_espresso'),
1483
-                __FILE__, __FUNCTION__, __LINE__);
1484
-        } else {
1485
-            EE_Error::add_error(
1486
-                esc_html__('The payment was processed successfully but the amount paid for the transaction was not updated.',
1487
-                    'event_espresso')
1488
-                , __FILE__, __FUNCTION__, __LINE__
1489
-            );
1490
-        }
1491
-    }
1492
-
1493
-
1494
-    /**
1495
-     * _get_REG_IDs_to_apply_payment_to
1496
-     *
1497
-     * returns a list of registration IDs that the payment will apply to
1498
-     *
1499
-     * @param \EE_Payment $payment
1500
-     *
1501
-     * @return array
1502
-     */
1503
-    protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1504
-    {
1505
-        $REG_IDs = array();
1506
-        // grab array of IDs for specific registrations to apply changes to
1507
-        if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1508
-            $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations'];
1509
-        }
1510
-        //nothing specified ? then get all reg IDs
1511
-        if (empty($REG_IDs)) {
1512
-            $registrations = $payment->transaction()->registrations();
1513
-            $REG_IDs       = ! empty($registrations) ? array_keys($registrations) : $this->_get_existing_reg_payment_REG_IDs($payment);
1514
-        }
1515
-
1516
-        // ensure that REG_IDs are integers and NOT strings
1517
-        return array_map('intval', $REG_IDs);
1518
-    }
1519
-
1520
-
1521
-    /**
1522
-     * @return array
1523
-     */
1524
-    public function existing_reg_payment_REG_IDs()
1525
-    {
1526
-        return $this->_existing_reg_payment_REG_IDs;
1527
-    }
1528
-
1529
-
1530
-    /**
1531
-     * @param array $existing_reg_payment_REG_IDs
1532
-     */
1533
-    public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1534
-    {
1535
-        $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1536
-    }
1537
-
1538
-
1539
-    /**
1540
-     * _get_existing_reg_payment_REG_IDs
1541
-     *
1542
-     * returns a list of registration IDs that the payment is currently related to
1543
-     * as recorded in the database
1544
-     *
1545
-     * @param \EE_Payment $payment
1546
-     *
1547
-     * @return array
1548
-     */
1549
-    protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1550
-    {
1551
-        if ($this->existing_reg_payment_REG_IDs() === null) {
1552
-            // let's get any existing reg payment records for this payment
1553
-            $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
1554
-            // but we only want the REG IDs, so grab the array keys
1555
-            $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) ? array_keys($existing_reg_payment_REG_IDs) : array();
1556
-            $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
1557
-        }
1558
-
1559
-        return $this->existing_reg_payment_REG_IDs();
1560
-    }
1561
-
1562
-
1563
-    /**
1564
-     * _remove_existing_registration_payments
1565
-     *
1566
-     * this calculates the difference between existing relations
1567
-     * to the supplied payment and the new list registration IDs,
1568
-     * removes any related registrations that no longer apply,
1569
-     * and then updates the registration paid fields
1570
-     *
1571
-     * @param \EE_Payment $payment
1572
-     * @param int         $PAY_ID
1573
-     *
1574
-     * @return bool;
1575
-     */
1576
-    protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
1577
-    {
1578
-        // newly created payments will have nothing recorded for $PAY_ID
1579
-        if ($PAY_ID == 0) {
1580
-            return false;
1581
-        }
1582
-        $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
1583
-        if (empty($existing_reg_payment_REG_IDs)) {
1584
-            return false;
1585
-        }
1586
-        /** @type EE_Transaction_Payments $transaction_payments */
1587
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1588
-
1589
-        return $transaction_payments->delete_registration_payments_and_update_registrations(
1590
-            $payment,
1591
-            array(
1592
-                array(
1593
-                    'PAY_ID' => $payment->ID(),
1594
-                    'REG_ID' => array('IN', $existing_reg_payment_REG_IDs),
1595
-                )
1596
-            )
1597
-        );
1598
-    }
1599
-
1600
-
1601
-    /**
1602
-     * _update_registration_payments
1603
-     *
1604
-     * this applies the payments to the selected registrations
1605
-     * but only if they have not already been paid for
1606
-     *
1607
-     * @param  EE_Transaction $transaction
1608
-     * @param \EE_Payment     $payment
1609
-     * @param array           $REG_IDs
1610
-     *
1611
-     * @return bool
1612
-     */
1613
-    protected function _update_registration_payments(
1614
-        EE_Transaction $transaction,
1615
-        EE_Payment $payment,
1616
-        $REG_IDs = array()
1617
-    ) {
1618
-        // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
1619
-        // so let's do that using our set of REG_IDs from the form
1620
-        $registration_query_where_params = array(
1621
-            'REG_ID' => array('IN', $REG_IDs)
1622
-        );
1623
-        // but add in some conditions regarding payment,
1624
-        // so that we don't apply payments to registrations that are free or have already been paid for
1625
-        // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
1626
-        if ( ! $payment->is_a_refund()) {
1627
-            $registration_query_where_params['REG_final_price']  = array('!=', 0);
1628
-            $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
1629
-        }
1630
-        //EEH_Debug_Tools::printr( $registration_query_where_params, '$registration_query_where_params', __FILE__, __LINE__ );
1631
-        $registrations = $transaction->registrations(array($registration_query_where_params));
1632
-        if ( ! empty($registrations)) {
1633
-            /** @type EE_Payment_Processor $payment_processor */
1634
-            $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
1635
-            $payment_processor->process_registration_payments($transaction, $payment, $registrations);
1636
-        }
1637
-    }
1638
-
1639
-
1640
-    /**
1641
-     * _process_registration_status_change
1642
-     *
1643
-     * This processes requested registration status changes for all the registrations
1644
-     * on a given transaction and (optionally) sends out notifications for the changes.
1645
-     *
1646
-     * @param  EE_Transaction $transaction
1647
-     * @param array           $REG_IDs
1648
-     *
1649
-     * @return bool
1650
-     */
1651
-    protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array())
1652
-    {
1653
-        // first if there is no change in status then we get out.
1654
-        if (
1655
-            ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['reg_status'])
1656
-            || $this->_req_data['txn_reg_status_change']['reg_status'] == 'NAN'
1657
-        ) {
1658
-            //no error message, no change requested, just nothing to do man.
1659
-            return false;
1660
-        }
1661
-        /** @type EE_Transaction_Processor $transaction_processor */
1662
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
1663
-
1664
-        // made it here dude?  Oh WOW.  K, let's take care of changing the statuses
1665
-        return $transaction_processor->manually_update_registration_statuses(
1666
-            $transaction,
1667
-            sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']),
1668
-            array(array('REG_ID' => array('IN', $REG_IDs)))
1669
-        );
1670
-    }
1671
-
1672
-
1673
-    /**
1674
-     * _build_payment_json_response
1675
-     *
1676
-     * @access public
1677
-     *
1678
-     * @param \EE_Payment $payment
1679
-     * @param array       $REG_IDs
1680
-     * @param bool | null $delete_txn_reg_status_change
1681
-     *
1682
-     * @return array
1683
-     */
1684
-    protected function _build_payment_json_response(
1685
-        EE_Payment $payment,
1686
-        $REG_IDs = array(),
1687
-        $delete_txn_reg_status_change = null
1688
-    ) {
1689
-        // was the payment deleted ?
1690
-        if (is_bool($delete_txn_reg_status_change)) {
1691
-            return array(
1692
-                'PAY_ID'                       => $payment->ID(),
1693
-                'amount'                       => $payment->amount(),
1694
-                'total_paid'                   => $payment->transaction()->paid(),
1695
-                'txn_status'                   => $payment->transaction()->status_ID(),
1696
-                'pay_status'                   => $payment->STS_ID(),
1697
-                'registrations'                => $this->_registration_payment_data_array($REG_IDs),
1698
-                'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
1699
-            );
1700
-        } else {
1701
-            $this->_get_payment_status_array();
1702
-
1703
-            return array(
1704
-                'amount'           => $payment->amount(),
1705
-                'total_paid'       => $payment->transaction()->paid(),
1706
-                'txn_status'       => $payment->transaction()->status_ID(),
1707
-                'pay_status'       => $payment->STS_ID(),
1708
-                'PAY_ID'           => $payment->ID(),
1709
-                'STS_ID'           => $payment->STS_ID(),
1710
-                'status'           => self::$_pay_status[$payment->STS_ID()],
1711
-                'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
1712
-                'method'           => strtoupper($payment->source()),
1713
-                'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
1714
-                'gateway'          => $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown",
1715
-                    'event_espresso'),
1716
-                'gateway_response' => $payment->gateway_response(),
1717
-                'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
1718
-                'po_number'        => $payment->po_number(),
1719
-                'extra_accntng'    => $payment->extra_accntng(),
1720
-                'registrations'    => $this->_registration_payment_data_array($REG_IDs),
1721
-            );
1722
-        }
1723
-    }
1724
-
1725
-
1726
-    /**
1727
-     * delete_payment
1728
-     *    delete a payment or refund made towards a transaction
1729
-     *
1730
-     * @access public
1731
-     * @return void
1732
-     */
1733
-    public function delete_payment()
1734
-    {
1735
-        $json_response_data = array('return_data' => false);
1736
-        $PAY_ID             = isset($this->_req_data['delete_txn_admin_payment'], $this->_req_data['delete_txn_admin_payment']['PAY_ID']) ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) : 0;
1737
-        if ($PAY_ID) {
1738
-            $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) ? $this->_req_data['delete_txn_reg_status_change'] : false;
1739
-            $payment                      = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
1740
-            if ($payment instanceof EE_Payment) {
1741
-                $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
1742
-                /** @type EE_Transaction_Payments $transaction_payments */
1743
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1744
-                if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
1745
-                    $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs,
1746
-                        $delete_txn_reg_status_change);
1747
-                    if ($delete_txn_reg_status_change) {
1748
-                        $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change;
1749
-                        //MAKE sure we also add the delete_txn_req_status_change to the
1750
-                        //$_REQUEST global because that's how messages will be looking for it.
1751
-                        $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change;
1752
-                        $this->_maybe_send_notifications();
1753
-                        $this->_process_registration_status_change($payment->transaction(), $REG_IDs);
1754
-                    }
1755
-                }
1756
-            } else {
1757
-                EE_Error::add_error(
1758
-                    esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
1759
-                    __FILE__, __FUNCTION__, __LINE__
1760
-                );
1761
-            }
1762
-        } else {
1763
-            EE_Error::add_error(
1764
-                esc_html__('A valid Payment ID was not received, therefore payment form data could not be loaded.',
1765
-                    'event_espresso'),
1766
-                __FILE__, __FUNCTION__, __LINE__
1767
-            );
1768
-        }
1769
-        $notices              = EE_Error::get_notices(false, false, false);
1770
-        $this->_template_args = array(
1771
-            'data'      => $json_response_data,
1772
-            'success'   => $notices['success'],
1773
-            'error'     => $notices['errors'],
1774
-            'attention' => $notices['attention']
1775
-        );
1776
-        $this->_return_json();
1777
-    }
1778
-
1779
-
1780
-    /**
1781
-     * _registration_payment_data_array
1782
-     * adds info for 'owing' and 'paid' for each registration to the json response
1783
-     *
1784
-     * @access protected
1785
-     *
1786
-     * @param array $REG_IDs
1787
-     *
1788
-     * @return array
1789
-     */
1790
-    protected function _registration_payment_data_array($REG_IDs)
1791
-    {
1792
-        $registration_payment_data = array();
1793
-        //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
1794
-        if ( ! empty($REG_IDs)) {
1795
-            $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
1796
-            foreach ($registrations as $registration) {
1797
-                if ($registration instanceof EE_Registration) {
1798
-                    $registration_payment_data[$registration->ID()] = array(
1799
-                        'paid'  => $registration->pretty_paid(),
1800
-                        'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
1801
-                    );
1802
-                }
1803
-            }
1804
-        }
1805
-
1806
-        return $registration_payment_data;
1807
-    }
1808
-
1809
-
1810
-    /**
1811
-     * _maybe_send_notifications
1812
-     *
1813
-     * determines whether or not the admin has indicated that notifications should be sent.
1814
-     * If so, will toggle a filter switch for delivering registration notices.
1815
-     * If passed an EE_Payment object, then it will trigger payment notifications instead.
1816
-     *
1817
-     * @access protected
1818
-     *
1819
-     * @param \EE_Payment | null $payment
1820
-     */
1821
-    protected function _maybe_send_notifications($payment = null)
1822
-    {
1823
-        switch ($payment instanceof EE_Payment) {
1824
-            // payment notifications
1825
-            case true :
1826
-                if (
1827
-                    isset(
1828
-                        $this->_req_data['txn_payments'],
1829
-                        $this->_req_data['txn_payments']['send_notifications']
1830
-                    ) &&
1831
-                    filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
1832
-                ) {
1833
-                    $this->_process_payment_notification($payment);
1834
-                }
1835
-                break;
1836
-            // registration notifications
1837
-            case false :
1838
-                if (
1839
-                    isset(
1840
-                        $this->_req_data['txn_reg_status_change'],
1841
-                        $this->_req_data['txn_reg_status_change']['send_notifications']
1842
-                    ) &&
1843
-                    filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
1844
-                ) {
1845
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
1846
-                }
1847
-                break;
1848
-        }
1849
-    }
1850
-
1851
-
1852
-    /**
1853
-     * _send_payment_reminder
1854
-     *    generates HTML for the View Transaction Details Admin page
1855
-     *
1856
-     * @access protected
1857
-     * @return void
1858
-     */
1859
-    protected function _send_payment_reminder()
1860
-    {
1861
-        $TXN_ID      = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false;
1862
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
1863
-        $query_args  = isset($this->_req_data['redirect_to']) ? array(
1864
-            'action' => $this->_req_data['redirect_to'],
1865
-            'TXN_ID' => $this->_req_data['TXN_ID']
1866
-        ) : array();
1867
-        do_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
1868
-            $transaction);
1869
-        $this->_redirect_after_action(false, esc_html__('payment reminder', 'event_espresso'),
1870
-            esc_html__('sent', 'event_espresso'), $query_args, true);
1871
-    }
1872
-
1873
-
1874
-    /**
1875
-     *  get_transactions
1876
-     *    get transactions for given parameters (used by list table)
1877
-     *
1878
-     * @param  int     $perpage how many transactions displayed per page
1879
-     * @param  boolean $count   return the count or objects
1880
-     * @param string   $view
1881
-     *
1882
-     * @return mixed int = count || array of transaction objects
1883
-     */
1884
-    public function get_transactions($perpage, $count = false, $view = '')
1885
-    {
1886
-
1887
-        $TXN = EEM_Transaction::instance();
1888
-
1889
-        $start_date = isset($this->_req_data['txn-filter-start-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) : date('m/d/Y',
1890
-            strtotime('-10 year'));
1891
-        $end_date   = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y');
1892
-
1893
-        //make sure our timestamps start and end right at the boundaries for each day
1894
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1895
-        $end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1896
-
1897
-
1898
-        //convert to timestamps
1899
-        $start_date = strtotime($start_date);
1900
-        $end_date   = strtotime($end_date);
1901
-
1902
-        //makes sure start date is the lowest value and vice versa
1903
-        $start_date = min($start_date, $end_date);
1904
-        $end_date   = max($start_date, $end_date);
1905
-
1906
-        //convert to correct format for query
1907
-        $start_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp',
1908
-            date('Y-m-d H:i:s', $start_date), 'Y-m-d H:i:s');
1909
-        $end_date   = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp',
1910
-            date('Y-m-d H:i:s', $end_date), 'Y-m-d H:i:s');
1911
-
1912
-
1913
-        //set orderby
1914
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
1915
-
1916
-        switch ($this->_req_data['orderby']) {
1917
-            case 'TXN_ID':
1918
-                $orderby = 'TXN_ID';
1919
-                break;
1920
-            case 'ATT_fname':
1921
-                $orderby = 'Registration.Attendee.ATT_fname';
1922
-                break;
1923
-            case 'event_name':
1924
-                $orderby = 'Registration.Event.EVT_name';
1925
-                break;
1926
-            default: //'TXN_timestamp'
1927
-                $orderby = 'TXN_timestamp';
1928
-        }
1929
-
1930
-        $sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'DESC';
1931
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
1932
-        $per_page     = isset($perpage) && ! empty($perpage) ? $perpage : 10;
1933
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
1934
-
1935
-        $offset = ($current_page - 1) * $per_page;
1936
-        $limit  = array($offset, $per_page);
1937
-
1938
-        $_where = array(
1939
-            'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)),
1940
-            'Registration.REG_count' => 1
1941
-        );
1942
-
1943
-        if (isset($this->_req_data['EVT_ID'])) {
1944
-            $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID'];
1945
-        }
1946
-
1947
-        if (isset($this->_req_data['s'])) {
1948
-            $search_string = '%' . $this->_req_data['s'] . '%';
1949
-            $_where['OR']  = array(
1950
-                'Registration.Event.EVT_name'         => array('LIKE', $search_string),
1951
-                'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
1952
-                'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string),
1953
-                'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string),
1954
-                'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string),
1955
-                'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string),
1956
-                'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string),
1957
-                'Registration.Attendee.ATT_email'     => array('LIKE', $search_string),
1958
-                'Registration.Attendee.ATT_address'   => array('LIKE', $search_string),
1959
-                'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string),
1960
-                'Registration.Attendee.ATT_city'      => array('LIKE', $search_string),
1961
-                'Registration.REG_final_price'        => array('LIKE', $search_string),
1962
-                'Registration.REG_code'               => array('LIKE', $search_string),
1963
-                'Registration.REG_count'              => array('LIKE', $search_string),
1964
-                'Registration.REG_group_size'         => array('LIKE', $search_string),
1965
-                'Registration.Ticket.TKT_name'        => array('LIKE', $search_string),
1966
-                'Registration.Ticket.TKT_description' => array('LIKE', $search_string),
1967
-                'Payment.PAY_source'                  => array('LIKE', $search_string),
1968
-                'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string),
1969
-                'TXN_session_data'                    => array('LIKE', $search_string),
1970
-                'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string)
1971
-            );
1972
-        }
1973
-
1974
-        //failed transactions
1975
-        $failed    = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'failed' && ! $count) || ($count && $view == 'failed') ? true : false;
1976
-        $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'abandoned' && ! $count) || ($count && $view == 'abandoned') ? true : false;
1977
-
1978
-        if ($failed) {
1979
-            $_where['STS_ID'] = EEM_Transaction::failed_status_code;
1980
-        } else if ($abandoned) {
1981
-            $_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
1982
-        } else {
1983
-            $_where['STS_ID']  = array('!=', EEM_Transaction::failed_status_code);
1984
-            $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code);
1985
-        }
1986
-
1987
-        $query_params = array($_where, 'order_by' => array($orderby => $sort), 'limit' => $limit);
1988
-
1989
-        $transactions = $count ? $TXN->count(array($_where), 'TXN_ID', true) : $TXN->get_all($query_params);
1990
-
1991
-
1992
-        return $transactions;
1993
-
1994
-    }
803
+		// process payment details
804
+		$payments = $this->_transaction->get_many_related('Payment');
805
+		if ( ! empty($payments)) {
806
+			$this->_template_args['payments']              = $payments;
807
+			$this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
808
+		} else {
809
+			$this->_template_args['payments']              = false;
810
+			$this->_template_args['existing_reg_payments'] = array();
811
+		}
812
+
813
+		$this->_template_args['edit_payment_url']   = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL);
814
+		$this->_template_args['delete_payment_url'] = add_query_arg(array('action' => 'espresso_delete_payment'),
815
+			TXN_ADMIN_URL);
816
+
817
+		if (isset($txn_details['invoice_number'])) {
818
+			$this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
819
+			$this->_template_args['txn_details']['invoice_number']['label'] = esc_html__('Invoice Number',
820
+				'event_espresso');
821
+		}
822
+
823
+		$this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction->get_first_related('Registration')->get('REG_session');
824
+		$this->_template_args['txn_details']['registration_session']['label'] = esc_html__('Registration Session',
825
+			'event_espresso');
826
+
827
+		$this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '';
828
+		$this->_template_args['txn_details']['ip_address']['label'] = esc_html__('Transaction placed from IP',
829
+			'event_espresso');
830
+
831
+		$this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '';
832
+		$this->_template_args['txn_details']['user_agent']['label'] = esc_html__('Registrant User Agent',
833
+			'event_espresso');
834
+
835
+		$reg_steps = '<ul>';
836
+		foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
837
+			if ($reg_step_status === true) {
838
+				$reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'),
839
+						ucwords(str_replace('_', ' ', $reg_step))) . '</li>';
840
+			} else if (is_numeric($reg_step_status) && $reg_step_status !== false) {
841
+				$reg_steps .= '<li style="color:#2EA2CC">' . sprintf(
842
+						esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
843
+						ucwords(str_replace('_', ' ', $reg_step)),
844
+						date(get_option('date_format') . ' ' . get_option('time_format'),
845
+							($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)))
846
+					) . '</li>';
847
+			} else {
848
+				$reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated',
849
+						'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>';
850
+			}
851
+		}
852
+		$reg_steps .= '</ul>';
853
+		$this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
854
+		$this->_template_args['txn_details']['reg_steps']['label'] = esc_html__('Registration Step Progress',
855
+			'event_espresso');
856
+
857
+
858
+		$this->_get_registrations_to_apply_payment_to();
859
+		$this->_get_payment_methods($payments);
860
+		$this->_get_payment_status_array();
861
+		$this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction.
862
+
863
+		$this->_template_args['transaction_form_url']    = add_query_arg(array(
864
+			'action'  => 'edit_transaction',
865
+			'process' => 'transaction'
866
+		), TXN_ADMIN_URL);
867
+		$this->_template_args['apply_payment_form_url']  = add_query_arg(array(
868
+			'page'   => 'espresso_transactions',
869
+			'action' => 'espresso_apply_payment'
870
+		), WP_AJAX_URL);
871
+		$this->_template_args['delete_payment_form_url'] = add_query_arg(array(
872
+			'page'   => 'espresso_transactions',
873
+			'action' => 'espresso_delete_payment'
874
+		), WP_AJAX_URL);
875
+
876
+		// 'espresso_delete_payment_nonce'
877
+
878
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
879
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
880
+
881
+	}
882
+
883
+
884
+	/**
885
+	 * _get_registration_payment_IDs
886
+	 *
887
+	 *    generates an array of Payment IDs and their corresponding Registration IDs
888
+	 *
889
+	 * @access protected
890
+	 *
891
+	 * @param EE_Payment[] $payments
892
+	 *
893
+	 * @return array
894
+	 */
895
+	protected function _get_registration_payment_IDs($payments = array())
896
+	{
897
+		$existing_reg_payments = array();
898
+		// get all reg payments for these payments
899
+		$reg_payments = EEM_Registration_Payment::instance()->get_all(array(
900
+			array(
901
+				'PAY_ID' => array(
902
+					'IN',
903
+					array_keys($payments)
904
+				)
905
+			)
906
+		));
907
+		if ( ! empty($reg_payments)) {
908
+			foreach ($payments as $payment) {
909
+				if ( ! $payment instanceof EE_Payment) {
910
+					continue;
911
+				} else if ( ! isset($existing_reg_payments[$payment->ID()])) {
912
+					$existing_reg_payments[$payment->ID()] = array();
913
+				}
914
+				foreach ($reg_payments as $reg_payment) {
915
+					if ($reg_payment instanceof EE_Registration_Payment && $reg_payment->payment_ID() === $payment->ID()) {
916
+						$existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID();
917
+					}
918
+				}
919
+			}
920
+		}
921
+
922
+		return $existing_reg_payments;
923
+	}
924
+
925
+
926
+	/**
927
+	 * _get_registrations_to_apply_payment_to
928
+	 *    generates HTML for displaying a series of checkboxes in the admin payment modal window
929
+	 * which allows the admin to only apply the payment to the specific registrations
930
+	 *
931
+	 * @access protected
932
+	 * @return void
933
+	 * @throws \EE_Error
934
+	 */
935
+	protected function _get_registrations_to_apply_payment_to()
936
+	{
937
+		// we want any registration with an active status (ie: not deleted or cancelled)
938
+		$query_params                      = array(
939
+			array(
940
+				'STS_ID' => array(
941
+					'IN',
942
+					array(
943
+						EEM_Registration::status_id_approved,
944
+						EEM_Registration::status_id_pending_payment,
945
+						EEM_Registration::status_id_not_approved,
946
+					)
947
+				)
948
+			)
949
+		);
950
+		$registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div(
951
+				'', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;'
952
+			);
953
+		$registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
954
+		$registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
955
+		$registrations_to_apply_payment_to .= EEH_HTML::thead(
956
+			EEH_HTML::tr(
957
+				EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
958
+				EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
959
+				EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
960
+				EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
961
+				EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
962
+				EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
963
+				EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
964
+			)
965
+		);
966
+		$registrations_to_apply_payment_to .= EEH_HTML::tbody();
967
+		// get registrations for TXN
968
+		$registrations = $this->_transaction->registrations($query_params);
969
+		foreach ($registrations as $registration) {
970
+			if ($registration instanceof EE_Registration) {
971
+				$attendee_name = $registration->attendee() instanceof EE_Attendee
972
+					? $registration->attendee()->full_name()
973
+					: esc_html__('Unknown Attendee', 'event_espresso');
974
+				$owing         = $registration->final_price() - $registration->paid();
975
+				$taxable       = $registration->ticket()->taxable()
976
+					? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
977
+					: '';
978
+				$checked       = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
979
+					? ' checked="checked"'
980
+					: '';
981
+				$disabled      = $registration->final_price() > 0 ? '' : ' disabled';
982
+				$registrations_to_apply_payment_to .= EEH_HTML::tr(
983
+					EEH_HTML::td($registration->ID()) .
984
+					EEH_HTML::td($attendee_name) .
985
+					EEH_HTML::td(
986
+						$registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
987
+					) .
988
+					EEH_HTML::td($registration->event_name()) .
989
+					EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
990
+					EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
991
+					EEH_HTML::td(
992
+						'<input type="checkbox" value="' . $registration->ID()
993
+						. '" name="txn_admin_payment[registrations]"'
994
+						. $checked . $disabled . '>',
995
+						'', 'jst-cntr'
996
+					),
997
+					'apply-payment-registration-row-' . $registration->ID()
998
+				);
999
+			}
1000
+		}
1001
+		$registrations_to_apply_payment_to .= EEH_HTML::tbodyx();
1002
+		$registrations_to_apply_payment_to .= EEH_HTML::tablex();
1003
+		$registrations_to_apply_payment_to .= EEH_HTML::divx();
1004
+		$registrations_to_apply_payment_to .= EEH_HTML::p(
1005
+			esc_html__(
1006
+				'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.',
1007
+				'event_espresso'
1008
+			),
1009
+			'', 'clear description'
1010
+		);
1011
+		$registrations_to_apply_payment_to .= EEH_HTML::divx();
1012
+		$this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1013
+	}
1014
+
1015
+
1016
+	/**
1017
+	 * _get_reg_status_selection
1018
+	 *
1019
+	 * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1020
+	 *         instead of events.
1021
+	 * @access protected
1022
+	 * @return void
1023
+	 */
1024
+	protected function _get_reg_status_selection()
1025
+	{
1026
+		//first get all possible statuses
1027
+		$statuses = EEM_Registration::reg_status_array(array(), true);
1028
+		//let's add a "don't change" option.
1029
+		$status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso');
1030
+		$status_array                                        = array_merge($status_array, $statuses);
1031
+		$this->_template_args['status_change_select']        = EEH_Form_Fields::select_input('txn_reg_status_change[reg_status]',
1032
+			$status_array, 'NAN', 'id="txn-admin-payment-reg-status-inp"', 'txn-reg-status-change-reg-status');
1033
+		$this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input('delete_txn_reg_status_change[reg_status]',
1034
+			$status_array, 'NAN', 'delete-txn-admin-payment-reg-status-inp', 'delete-txn-reg-status-change-reg-status');
1035
+
1036
+	}
1037
+
1038
+
1039
+	/**
1040
+	 *    _get_payment_methods
1041
+	 * Gets all the payment methods available generally, or the ones that are already
1042
+	 * selected on these payments (in case their payment methods are no longer active).
1043
+	 * Has the side-effect of updating the template args' payment_methods item
1044
+	 * @access private
1045
+	 *
1046
+	 * @param EE_Payment[] to show on this page
1047
+	 *
1048
+	 * @return void
1049
+	 */
1050
+	private function _get_payment_methods($payments = array())
1051
+	{
1052
+		$payment_methods_of_payments = array();
1053
+		foreach ($payments as $payment) {
1054
+			if ($payment instanceof EE_Payment) {
1055
+				$payment_methods_of_payments[] = $payment->get('PMD_ID');
1056
+			}
1057
+		}
1058
+		if ($payment_methods_of_payments) {
1059
+			$query_args = array(
1060
+				array(
1061
+					'OR*payment_method_for_payment' => array(
1062
+						'PMD_ID'    => array('IN', $payment_methods_of_payments),
1063
+						'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')
1064
+					)
1065
+				)
1066
+			);
1067
+		} else {
1068
+			$query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1069
+		}
1070
+		$this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1071
+	}
1072
+
1073
+
1074
+	/**
1075
+	 * txn_attendees_meta_box
1076
+	 *    generates HTML for the Attendees Transaction main meta box
1077
+	 *
1078
+	 * @access public
1079
+	 *
1080
+	 * @param WP_Post $post
1081
+	 * @param array   $metabox
1082
+	 *
1083
+	 * @return void
1084
+	 */
1085
+	public function txn_attendees_meta_box($post, $metabox = array('args' => array()))
1086
+	{
1087
+
1088
+		extract($metabox['args']);
1089
+		$this->_template_args['post']            = $post;
1090
+		$this->_template_args['event_attendees'] = array();
1091
+		// process items in cart
1092
+		$line_items = $this->_transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item')));
1093
+		if ( ! empty($line_items)) {
1094
+			foreach ($line_items as $item) {
1095
+				if ($item instanceof EE_Line_Item) {
1096
+					switch ($item->OBJ_type()) {
1097
+
1098
+						case 'Event' :
1099
+							break;
1100
+
1101
+						case 'Ticket' :
1102
+							$ticket = $item->ticket();
1103
+							//right now we're only handling tickets here.  Cause its expected that only tickets will have attendees right?
1104
+							if ( ! $ticket instanceof EE_Ticket) {
1105
+								continue;
1106
+							}
1107
+							try {
1108
+								$event_name = $ticket->get_event_name();
1109
+							} catch (Exception $e) {
1110
+								EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1111
+								$event_name = esc_html__('Unknown Event', 'event_espresso');
1112
+							}
1113
+							$event_name .= ' - ' . $item->get('LIN_name');
1114
+							$ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1115
+							// now get all of the registrations for this transaction that use this ticket
1116
+							$registrations = $ticket->get_many_related('Registration',
1117
+								array(array('TXN_ID' => $this->_transaction->ID())));
1118
+							foreach ($registrations as $registration) {
1119
+								if ( ! $registration instanceof EE_Registration) {
1120
+									continue;
1121
+								}
1122
+								$this->_template_args['event_attendees'][$registration->ID()]['STS_ID']            = $registration->status_ID();
1123
+								$this->_template_args['event_attendees'][$registration->ID()]['att_num']           = $registration->count();
1124
+								$this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] = $event_name;
1125
+								$this->_template_args['event_attendees'][$registration->ID()]['ticket_price']      = $ticket_price;
1126
+								// attendee info
1127
+								$attendee = $registration->get_first_related('Attendee');
1128
+								if ($attendee instanceof EE_Attendee) {
1129
+									$this->_template_args['event_attendees'][$registration->ID()]['att_id']   = $attendee->ID();
1130
+									$this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name();
1131
+									$this->_template_args['event_attendees'][$registration->ID()]['email']    = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event',
1132
+											'event_espresso') . '">' . $attendee->email() . '</a>';
1133
+									$this->_template_args['event_attendees'][$registration->ID()]['address']  = EEH_Address::format($attendee,
1134
+										'inline', false, false);
1135
+								} else {
1136
+									$this->_template_args['event_attendees'][$registration->ID()]['att_id']   = '';
1137
+									$this->_template_args['event_attendees'][$registration->ID()]['attendee'] = '';
1138
+									$this->_template_args['event_attendees'][$registration->ID()]['email']    = '';
1139
+									$this->_template_args['event_attendees'][$registration->ID()]['address']  = '';
1140
+								}
1141
+							}
1142
+							break;
1143
+
1144
+					}
1145
+				}
1146
+			}
1147
+
1148
+			$this->_template_args['transaction_form_url'] = add_query_arg(array(
1149
+				'action'  => 'edit_transaction',
1150
+				'process' => 'attendees'
1151
+			), TXN_ADMIN_URL);
1152
+			echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1153
+				$this->_template_args, true);
1154
+
1155
+		} else {
1156
+			echo sprintf(
1157
+				esc_html__('%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1158
+					'event_espresso'),
1159
+				'<p class="important-notice">',
1160
+				'</p>'
1161
+			);
1162
+		}
1163
+	}
1164
+
1165
+
1166
+	/**
1167
+	 * txn_registrant_side_meta_box
1168
+	 * generates HTML for the Edit Transaction side meta box
1169
+	 *
1170
+	 * @access public
1171
+	 * @throws \EE_Error
1172
+	 * @return void
1173
+	 */
1174
+	public function txn_registrant_side_meta_box()
1175
+	{
1176
+		$primary_att = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->get_first_related('Attendee') : null;
1177
+		if ( ! $primary_att instanceof EE_Attendee) {
1178
+			$this->_template_args['no_attendee_message'] = esc_html__('There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1179
+				'event_espresso');
1180
+			$primary_att                                 = EEM_Attendee::instance()->create_default_object();
1181
+		}
1182
+		$this->_template_args['ATT_ID']            = $primary_att->ID();
1183
+		$this->_template_args['prime_reg_fname']   = $primary_att->fname();
1184
+		$this->_template_args['prime_reg_lname']   = $primary_att->lname();
1185
+		$this->_template_args['prime_reg_email']   = $primary_att->email();
1186
+		$this->_template_args['prime_reg_phone']   = $primary_att->phone();
1187
+		$this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array(
1188
+			'action' => 'edit_attendee',
1189
+			'post'   => $primary_att->ID()
1190
+		), REG_ADMIN_URL);
1191
+		// get formatted address for registrant
1192
+		$this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1193
+		echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1194
+			$this->_template_args, true);
1195
+	}
1196
+
1197
+
1198
+	/**
1199
+	 * txn_billing_info_side_meta_box
1200
+	 *    generates HTML for the Edit Transaction side meta box
1201
+	 *
1202
+	 * @access public
1203
+	 * @return void
1204
+	 */
1205
+	public function txn_billing_info_side_meta_box()
1206
+	{
1207
+
1208
+		$this->_template_args['billing_form']     = $this->_transaction->billing_info();
1209
+		$this->_template_args['billing_form_url'] = add_query_arg(
1210
+			array('action' => 'edit_transaction', 'process' => 'billing'),
1211
+			TXN_ADMIN_URL
1212
+		);
1213
+
1214
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1215
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1216
+	}
1217
+
1218
+
1219
+	/**
1220
+	 * apply_payments_or_refunds
1221
+	 *    registers a payment or refund made towards a transaction
1222
+	 *
1223
+	 * @access public
1224
+	 * @return void
1225
+	 */
1226
+	public function apply_payments_or_refunds()
1227
+	{
1228
+		$json_response_data = array('return_data' => false);
1229
+		$valid_data         = $this->_validate_payment_request_data();
1230
+		if ( ! empty($valid_data)) {
1231
+			$PAY_ID = $valid_data['PAY_ID'];
1232
+			//save  the new payment
1233
+			$payment = $this->_create_payment_from_request_data($valid_data);
1234
+			// get the TXN for this payment
1235
+			$transaction = $payment->transaction();
1236
+			// verify transaction
1237
+			if ($transaction instanceof EE_Transaction) {
1238
+				// calculate_total_payments_and_update_status
1239
+				$this->_process_transaction_payments($transaction);
1240
+				$REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1241
+				$this->_remove_existing_registration_payments($payment, $PAY_ID);
1242
+				// apply payment to registrations (if applicable)
1243
+				if ( ! empty($REG_IDs)) {
1244
+					$this->_update_registration_payments($transaction, $payment, $REG_IDs);
1245
+					$this->_maybe_send_notifications();
1246
+					// now process status changes for the same registrations
1247
+					$this->_process_registration_status_change($transaction, $REG_IDs);
1248
+				}
1249
+				$this->_maybe_send_notifications($payment);
1250
+				//prepare to render page
1251
+				$json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1252
+				do_action('AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', $transaction,
1253
+					$payment);
1254
+			} else {
1255
+				EE_Error::add_error(
1256
+					esc_html__('A valid Transaction for this payment could not be retrieved.', 'event_espresso'),
1257
+					__FILE__, __FUNCTION__, __LINE__
1258
+				);
1259
+			}
1260
+		} else {
1261
+			EE_Error::add_error(esc_html__('The payment form data could not be processed. Please try again.',
1262
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1263
+		}
1264
+
1265
+		$notices              = EE_Error::get_notices(false, false, false);
1266
+		$this->_template_args = array(
1267
+			'data'    => $json_response_data,
1268
+			'error'   => $notices['errors'],
1269
+			'success' => $notices['success']
1270
+		);
1271
+		$this->_return_json();
1272
+	}
1273
+
1274
+
1275
+	/**
1276
+	 * _validate_payment_request_data
1277
+	 *
1278
+	 * @return array
1279
+	 */
1280
+	protected function _validate_payment_request_data()
1281
+	{
1282
+		if ( ! isset($this->_req_data['txn_admin_payment'])) {
1283
+			return false;
1284
+		}
1285
+		$payment_form = $this->_generate_payment_form_section();
1286
+		try {
1287
+			if ($payment_form->was_submitted()) {
1288
+				$payment_form->receive_form_submission();
1289
+				if ( ! $payment_form->is_valid()) {
1290
+					$submission_error_messages = array();
1291
+					foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1292
+						if ($validation_error instanceof EE_Validation_Error) {
1293
+							$submission_error_messages[] = sprintf(
1294
+								_x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1295
+								$validation_error->get_form_section()->html_label_text(),
1296
+								$validation_error->getMessage()
1297
+							);
1298
+						}
1299
+					}
1300
+					EE_Error::add_error(join('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__);
1301
+
1302
+					return array();
1303
+				}
1304
+			}
1305
+		} catch (EE_Error $e) {
1306
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1307
+
1308
+			return array();
1309
+		}
1310
+
1311
+		return $payment_form->valid_data();
1312
+	}
1313
+
1314
+
1315
+	/**
1316
+	 * _generate_payment_form_section
1317
+	 *
1318
+	 * @return EE_Form_Section_Proper
1319
+	 */
1320
+	protected function _generate_payment_form_section()
1321
+	{
1322
+		return new EE_Form_Section_Proper(
1323
+			array(
1324
+				'name'        => 'txn_admin_payment',
1325
+				'subsections' => array(
1326
+					'PAY_ID'          => new EE_Text_Input(
1327
+						array(
1328
+							'default'               => 0,
1329
+							'required'              => false,
1330
+							'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1331
+							'validation_strategies' => array(new EE_Int_Normalization())
1332
+						)
1333
+					),
1334
+					'TXN_ID'          => new EE_Text_Input(
1335
+						array(
1336
+							'default'               => 0,
1337
+							'required'              => true,
1338
+							'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1339
+							'validation_strategies' => array(new EE_Int_Normalization())
1340
+						)
1341
+					),
1342
+					'type'            => new EE_Text_Input(
1343
+						array(
1344
+							'default'               => 1,
1345
+							'required'              => true,
1346
+							'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1347
+							'validation_strategies' => array(new EE_Int_Normalization())
1348
+						)
1349
+					),
1350
+					'amount'          => new EE_Text_Input(
1351
+						array(
1352
+							'default'               => 0,
1353
+							'required'              => true,
1354
+							'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1355
+							'validation_strategies' => array(new EE_Float_Normalization())
1356
+						)
1357
+					),
1358
+					'status'          => new EE_Text_Input(
1359
+						array(
1360
+							'default'         => EEM_Payment::status_id_approved,
1361
+							'required'        => true,
1362
+							'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1363
+						)
1364
+					),
1365
+					'PMD_ID'          => new EE_Text_Input(
1366
+						array(
1367
+							'default'               => 2,
1368
+							'required'              => true,
1369
+							'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1370
+							'validation_strategies' => array(new EE_Int_Normalization())
1371
+						)
1372
+					),
1373
+					'date'            => new EE_Text_Input(
1374
+						array(
1375
+							'default'         => time(),
1376
+							'required'        => true,
1377
+							'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1378
+						)
1379
+					),
1380
+					'txn_id_chq_nmbr' => new EE_Text_Input(
1381
+						array(
1382
+							'default'               => '',
1383
+							'required'              => false,
1384
+							'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1385
+							'validation_strategies' => array(
1386
+								new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'),
1387
+									100),
1388
+							)
1389
+						)
1390
+					),
1391
+					'po_number'       => new EE_Text_Input(
1392
+						array(
1393
+							'default'               => '',
1394
+							'required'              => false,
1395
+							'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1396
+							'validation_strategies' => array(
1397
+								new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'),
1398
+									100),
1399
+							)
1400
+						)
1401
+					),
1402
+					'accounting'      => new EE_Text_Input(
1403
+						array(
1404
+							'default'               => '',
1405
+							'required'              => false,
1406
+							'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1407
+							'validation_strategies' => array(
1408
+								new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'),
1409
+									100),
1410
+							)
1411
+						)
1412
+					),
1413
+				)
1414
+			)
1415
+		);
1416
+	}
1417
+
1418
+
1419
+	/**
1420
+	 * _create_payment_from_request_data
1421
+	 *
1422
+	 * @param array $valid_data
1423
+	 *
1424
+	 * @return EE_Payment
1425
+	 */
1426
+	protected function _create_payment_from_request_data($valid_data)
1427
+	{
1428
+		$PAY_ID = $valid_data['PAY_ID'];
1429
+		// get payment amount
1430
+		$amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1431
+		// payments have a type value of 1 and refunds have a type value of -1
1432
+		// so multiplying amount by type will give a positive value for payments, and negative values for refunds
1433
+		$amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1434
+		// for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1435
+		$date    = $valid_data['date'] ? preg_replace('/\s+/', ' ', $valid_data['date']) : date('Y-m-d g:i a',
1436
+			current_time('timestamp'));
1437
+		$payment = EE_Payment::new_instance(
1438
+			array(
1439
+				'TXN_ID'              => $valid_data['TXN_ID'],
1440
+				'STS_ID'              => $valid_data['status'],
1441
+				'PAY_timestamp'       => $date,
1442
+				'PAY_source'          => EEM_Payment_Method::scope_admin,
1443
+				'PMD_ID'              => $valid_data['PMD_ID'],
1444
+				'PAY_amount'          => $amount,
1445
+				'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1446
+				'PAY_po_number'       => $valid_data['po_number'],
1447
+				'PAY_extra_accntng'   => $valid_data['accounting'],
1448
+				'PAY_details'         => $valid_data,
1449
+				'PAY_ID'              => $PAY_ID
1450
+			),
1451
+			'',
1452
+			array('Y-m-d', 'g:i a')
1453
+		);
1454
+
1455
+		if ( ! $payment->save()) {
1456
+			EE_Error::add_error(
1457
+				sprintf(
1458
+					esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1459
+					$payment->ID()
1460
+				),
1461
+				__FILE__, __FUNCTION__, __LINE__
1462
+			);
1463
+		}
1464
+
1465
+		return $payment;
1466
+	}
1467
+
1468
+
1469
+	/**
1470
+	 * _process_transaction_payments
1471
+	 *
1472
+	 * @param \EE_Transaction $transaction
1473
+	 *
1474
+	 * @return array
1475
+	 */
1476
+	protected function _process_transaction_payments(EE_Transaction $transaction)
1477
+	{
1478
+		/** @type EE_Transaction_Payments $transaction_payments */
1479
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1480
+		//update the transaction with this payment
1481
+		if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1482
+			EE_Error::add_success(esc_html__('The payment has been processed successfully.', 'event_espresso'),
1483
+				__FILE__, __FUNCTION__, __LINE__);
1484
+		} else {
1485
+			EE_Error::add_error(
1486
+				esc_html__('The payment was processed successfully but the amount paid for the transaction was not updated.',
1487
+					'event_espresso')
1488
+				, __FILE__, __FUNCTION__, __LINE__
1489
+			);
1490
+		}
1491
+	}
1492
+
1493
+
1494
+	/**
1495
+	 * _get_REG_IDs_to_apply_payment_to
1496
+	 *
1497
+	 * returns a list of registration IDs that the payment will apply to
1498
+	 *
1499
+	 * @param \EE_Payment $payment
1500
+	 *
1501
+	 * @return array
1502
+	 */
1503
+	protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1504
+	{
1505
+		$REG_IDs = array();
1506
+		// grab array of IDs for specific registrations to apply changes to
1507
+		if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1508
+			$REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations'];
1509
+		}
1510
+		//nothing specified ? then get all reg IDs
1511
+		if (empty($REG_IDs)) {
1512
+			$registrations = $payment->transaction()->registrations();
1513
+			$REG_IDs       = ! empty($registrations) ? array_keys($registrations) : $this->_get_existing_reg_payment_REG_IDs($payment);
1514
+		}
1515
+
1516
+		// ensure that REG_IDs are integers and NOT strings
1517
+		return array_map('intval', $REG_IDs);
1518
+	}
1519
+
1520
+
1521
+	/**
1522
+	 * @return array
1523
+	 */
1524
+	public function existing_reg_payment_REG_IDs()
1525
+	{
1526
+		return $this->_existing_reg_payment_REG_IDs;
1527
+	}
1528
+
1529
+
1530
+	/**
1531
+	 * @param array $existing_reg_payment_REG_IDs
1532
+	 */
1533
+	public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1534
+	{
1535
+		$this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1536
+	}
1537
+
1538
+
1539
+	/**
1540
+	 * _get_existing_reg_payment_REG_IDs
1541
+	 *
1542
+	 * returns a list of registration IDs that the payment is currently related to
1543
+	 * as recorded in the database
1544
+	 *
1545
+	 * @param \EE_Payment $payment
1546
+	 *
1547
+	 * @return array
1548
+	 */
1549
+	protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1550
+	{
1551
+		if ($this->existing_reg_payment_REG_IDs() === null) {
1552
+			// let's get any existing reg payment records for this payment
1553
+			$existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
1554
+			// but we only want the REG IDs, so grab the array keys
1555
+			$existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) ? array_keys($existing_reg_payment_REG_IDs) : array();
1556
+			$this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
1557
+		}
1558
+
1559
+		return $this->existing_reg_payment_REG_IDs();
1560
+	}
1561
+
1562
+
1563
+	/**
1564
+	 * _remove_existing_registration_payments
1565
+	 *
1566
+	 * this calculates the difference between existing relations
1567
+	 * to the supplied payment and the new list registration IDs,
1568
+	 * removes any related registrations that no longer apply,
1569
+	 * and then updates the registration paid fields
1570
+	 *
1571
+	 * @param \EE_Payment $payment
1572
+	 * @param int         $PAY_ID
1573
+	 *
1574
+	 * @return bool;
1575
+	 */
1576
+	protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
1577
+	{
1578
+		// newly created payments will have nothing recorded for $PAY_ID
1579
+		if ($PAY_ID == 0) {
1580
+			return false;
1581
+		}
1582
+		$existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
1583
+		if (empty($existing_reg_payment_REG_IDs)) {
1584
+			return false;
1585
+		}
1586
+		/** @type EE_Transaction_Payments $transaction_payments */
1587
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1588
+
1589
+		return $transaction_payments->delete_registration_payments_and_update_registrations(
1590
+			$payment,
1591
+			array(
1592
+				array(
1593
+					'PAY_ID' => $payment->ID(),
1594
+					'REG_ID' => array('IN', $existing_reg_payment_REG_IDs),
1595
+				)
1596
+			)
1597
+		);
1598
+	}
1599
+
1600
+
1601
+	/**
1602
+	 * _update_registration_payments
1603
+	 *
1604
+	 * this applies the payments to the selected registrations
1605
+	 * but only if they have not already been paid for
1606
+	 *
1607
+	 * @param  EE_Transaction $transaction
1608
+	 * @param \EE_Payment     $payment
1609
+	 * @param array           $REG_IDs
1610
+	 *
1611
+	 * @return bool
1612
+	 */
1613
+	protected function _update_registration_payments(
1614
+		EE_Transaction $transaction,
1615
+		EE_Payment $payment,
1616
+		$REG_IDs = array()
1617
+	) {
1618
+		// we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
1619
+		// so let's do that using our set of REG_IDs from the form
1620
+		$registration_query_where_params = array(
1621
+			'REG_ID' => array('IN', $REG_IDs)
1622
+		);
1623
+		// but add in some conditions regarding payment,
1624
+		// so that we don't apply payments to registrations that are free or have already been paid for
1625
+		// but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
1626
+		if ( ! $payment->is_a_refund()) {
1627
+			$registration_query_where_params['REG_final_price']  = array('!=', 0);
1628
+			$registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
1629
+		}
1630
+		//EEH_Debug_Tools::printr( $registration_query_where_params, '$registration_query_where_params', __FILE__, __LINE__ );
1631
+		$registrations = $transaction->registrations(array($registration_query_where_params));
1632
+		if ( ! empty($registrations)) {
1633
+			/** @type EE_Payment_Processor $payment_processor */
1634
+			$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
1635
+			$payment_processor->process_registration_payments($transaction, $payment, $registrations);
1636
+		}
1637
+	}
1638
+
1639
+
1640
+	/**
1641
+	 * _process_registration_status_change
1642
+	 *
1643
+	 * This processes requested registration status changes for all the registrations
1644
+	 * on a given transaction and (optionally) sends out notifications for the changes.
1645
+	 *
1646
+	 * @param  EE_Transaction $transaction
1647
+	 * @param array           $REG_IDs
1648
+	 *
1649
+	 * @return bool
1650
+	 */
1651
+	protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array())
1652
+	{
1653
+		// first if there is no change in status then we get out.
1654
+		if (
1655
+			! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['reg_status'])
1656
+			|| $this->_req_data['txn_reg_status_change']['reg_status'] == 'NAN'
1657
+		) {
1658
+			//no error message, no change requested, just nothing to do man.
1659
+			return false;
1660
+		}
1661
+		/** @type EE_Transaction_Processor $transaction_processor */
1662
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
1663
+
1664
+		// made it here dude?  Oh WOW.  K, let's take care of changing the statuses
1665
+		return $transaction_processor->manually_update_registration_statuses(
1666
+			$transaction,
1667
+			sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']),
1668
+			array(array('REG_ID' => array('IN', $REG_IDs)))
1669
+		);
1670
+	}
1671
+
1672
+
1673
+	/**
1674
+	 * _build_payment_json_response
1675
+	 *
1676
+	 * @access public
1677
+	 *
1678
+	 * @param \EE_Payment $payment
1679
+	 * @param array       $REG_IDs
1680
+	 * @param bool | null $delete_txn_reg_status_change
1681
+	 *
1682
+	 * @return array
1683
+	 */
1684
+	protected function _build_payment_json_response(
1685
+		EE_Payment $payment,
1686
+		$REG_IDs = array(),
1687
+		$delete_txn_reg_status_change = null
1688
+	) {
1689
+		// was the payment deleted ?
1690
+		if (is_bool($delete_txn_reg_status_change)) {
1691
+			return array(
1692
+				'PAY_ID'                       => $payment->ID(),
1693
+				'amount'                       => $payment->amount(),
1694
+				'total_paid'                   => $payment->transaction()->paid(),
1695
+				'txn_status'                   => $payment->transaction()->status_ID(),
1696
+				'pay_status'                   => $payment->STS_ID(),
1697
+				'registrations'                => $this->_registration_payment_data_array($REG_IDs),
1698
+				'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
1699
+			);
1700
+		} else {
1701
+			$this->_get_payment_status_array();
1702
+
1703
+			return array(
1704
+				'amount'           => $payment->amount(),
1705
+				'total_paid'       => $payment->transaction()->paid(),
1706
+				'txn_status'       => $payment->transaction()->status_ID(),
1707
+				'pay_status'       => $payment->STS_ID(),
1708
+				'PAY_ID'           => $payment->ID(),
1709
+				'STS_ID'           => $payment->STS_ID(),
1710
+				'status'           => self::$_pay_status[$payment->STS_ID()],
1711
+				'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
1712
+				'method'           => strtoupper($payment->source()),
1713
+				'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
1714
+				'gateway'          => $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown",
1715
+					'event_espresso'),
1716
+				'gateway_response' => $payment->gateway_response(),
1717
+				'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
1718
+				'po_number'        => $payment->po_number(),
1719
+				'extra_accntng'    => $payment->extra_accntng(),
1720
+				'registrations'    => $this->_registration_payment_data_array($REG_IDs),
1721
+			);
1722
+		}
1723
+	}
1724
+
1725
+
1726
+	/**
1727
+	 * delete_payment
1728
+	 *    delete a payment or refund made towards a transaction
1729
+	 *
1730
+	 * @access public
1731
+	 * @return void
1732
+	 */
1733
+	public function delete_payment()
1734
+	{
1735
+		$json_response_data = array('return_data' => false);
1736
+		$PAY_ID             = isset($this->_req_data['delete_txn_admin_payment'], $this->_req_data['delete_txn_admin_payment']['PAY_ID']) ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) : 0;
1737
+		if ($PAY_ID) {
1738
+			$delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) ? $this->_req_data['delete_txn_reg_status_change'] : false;
1739
+			$payment                      = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
1740
+			if ($payment instanceof EE_Payment) {
1741
+				$REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
1742
+				/** @type EE_Transaction_Payments $transaction_payments */
1743
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1744
+				if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
1745
+					$json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs,
1746
+						$delete_txn_reg_status_change);
1747
+					if ($delete_txn_reg_status_change) {
1748
+						$this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change;
1749
+						//MAKE sure we also add the delete_txn_req_status_change to the
1750
+						//$_REQUEST global because that's how messages will be looking for it.
1751
+						$_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change;
1752
+						$this->_maybe_send_notifications();
1753
+						$this->_process_registration_status_change($payment->transaction(), $REG_IDs);
1754
+					}
1755
+				}
1756
+			} else {
1757
+				EE_Error::add_error(
1758
+					esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
1759
+					__FILE__, __FUNCTION__, __LINE__
1760
+				);
1761
+			}
1762
+		} else {
1763
+			EE_Error::add_error(
1764
+				esc_html__('A valid Payment ID was not received, therefore payment form data could not be loaded.',
1765
+					'event_espresso'),
1766
+				__FILE__, __FUNCTION__, __LINE__
1767
+			);
1768
+		}
1769
+		$notices              = EE_Error::get_notices(false, false, false);
1770
+		$this->_template_args = array(
1771
+			'data'      => $json_response_data,
1772
+			'success'   => $notices['success'],
1773
+			'error'     => $notices['errors'],
1774
+			'attention' => $notices['attention']
1775
+		);
1776
+		$this->_return_json();
1777
+	}
1778
+
1779
+
1780
+	/**
1781
+	 * _registration_payment_data_array
1782
+	 * adds info for 'owing' and 'paid' for each registration to the json response
1783
+	 *
1784
+	 * @access protected
1785
+	 *
1786
+	 * @param array $REG_IDs
1787
+	 *
1788
+	 * @return array
1789
+	 */
1790
+	protected function _registration_payment_data_array($REG_IDs)
1791
+	{
1792
+		$registration_payment_data = array();
1793
+		//if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
1794
+		if ( ! empty($REG_IDs)) {
1795
+			$registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
1796
+			foreach ($registrations as $registration) {
1797
+				if ($registration instanceof EE_Registration) {
1798
+					$registration_payment_data[$registration->ID()] = array(
1799
+						'paid'  => $registration->pretty_paid(),
1800
+						'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
1801
+					);
1802
+				}
1803
+			}
1804
+		}
1805
+
1806
+		return $registration_payment_data;
1807
+	}
1808
+
1809
+
1810
+	/**
1811
+	 * _maybe_send_notifications
1812
+	 *
1813
+	 * determines whether or not the admin has indicated that notifications should be sent.
1814
+	 * If so, will toggle a filter switch for delivering registration notices.
1815
+	 * If passed an EE_Payment object, then it will trigger payment notifications instead.
1816
+	 *
1817
+	 * @access protected
1818
+	 *
1819
+	 * @param \EE_Payment | null $payment
1820
+	 */
1821
+	protected function _maybe_send_notifications($payment = null)
1822
+	{
1823
+		switch ($payment instanceof EE_Payment) {
1824
+			// payment notifications
1825
+			case true :
1826
+				if (
1827
+					isset(
1828
+						$this->_req_data['txn_payments'],
1829
+						$this->_req_data['txn_payments']['send_notifications']
1830
+					) &&
1831
+					filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
1832
+				) {
1833
+					$this->_process_payment_notification($payment);
1834
+				}
1835
+				break;
1836
+			// registration notifications
1837
+			case false :
1838
+				if (
1839
+					isset(
1840
+						$this->_req_data['txn_reg_status_change'],
1841
+						$this->_req_data['txn_reg_status_change']['send_notifications']
1842
+					) &&
1843
+					filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
1844
+				) {
1845
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
1846
+				}
1847
+				break;
1848
+		}
1849
+	}
1850
+
1851
+
1852
+	/**
1853
+	 * _send_payment_reminder
1854
+	 *    generates HTML for the View Transaction Details Admin page
1855
+	 *
1856
+	 * @access protected
1857
+	 * @return void
1858
+	 */
1859
+	protected function _send_payment_reminder()
1860
+	{
1861
+		$TXN_ID      = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false;
1862
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
1863
+		$query_args  = isset($this->_req_data['redirect_to']) ? array(
1864
+			'action' => $this->_req_data['redirect_to'],
1865
+			'TXN_ID' => $this->_req_data['TXN_ID']
1866
+		) : array();
1867
+		do_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
1868
+			$transaction);
1869
+		$this->_redirect_after_action(false, esc_html__('payment reminder', 'event_espresso'),
1870
+			esc_html__('sent', 'event_espresso'), $query_args, true);
1871
+	}
1872
+
1873
+
1874
+	/**
1875
+	 *  get_transactions
1876
+	 *    get transactions for given parameters (used by list table)
1877
+	 *
1878
+	 * @param  int     $perpage how many transactions displayed per page
1879
+	 * @param  boolean $count   return the count or objects
1880
+	 * @param string   $view
1881
+	 *
1882
+	 * @return mixed int = count || array of transaction objects
1883
+	 */
1884
+	public function get_transactions($perpage, $count = false, $view = '')
1885
+	{
1886
+
1887
+		$TXN = EEM_Transaction::instance();
1888
+
1889
+		$start_date = isset($this->_req_data['txn-filter-start-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) : date('m/d/Y',
1890
+			strtotime('-10 year'));
1891
+		$end_date   = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y');
1892
+
1893
+		//make sure our timestamps start and end right at the boundaries for each day
1894
+		$start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1895
+		$end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1896
+
1897
+
1898
+		//convert to timestamps
1899
+		$start_date = strtotime($start_date);
1900
+		$end_date   = strtotime($end_date);
1901
+
1902
+		//makes sure start date is the lowest value and vice versa
1903
+		$start_date = min($start_date, $end_date);
1904
+		$end_date   = max($start_date, $end_date);
1905
+
1906
+		//convert to correct format for query
1907
+		$start_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp',
1908
+			date('Y-m-d H:i:s', $start_date), 'Y-m-d H:i:s');
1909
+		$end_date   = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp',
1910
+			date('Y-m-d H:i:s', $end_date), 'Y-m-d H:i:s');
1911
+
1912
+
1913
+		//set orderby
1914
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
1915
+
1916
+		switch ($this->_req_data['orderby']) {
1917
+			case 'TXN_ID':
1918
+				$orderby = 'TXN_ID';
1919
+				break;
1920
+			case 'ATT_fname':
1921
+				$orderby = 'Registration.Attendee.ATT_fname';
1922
+				break;
1923
+			case 'event_name':
1924
+				$orderby = 'Registration.Event.EVT_name';
1925
+				break;
1926
+			default: //'TXN_timestamp'
1927
+				$orderby = 'TXN_timestamp';
1928
+		}
1929
+
1930
+		$sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'DESC';
1931
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
1932
+		$per_page     = isset($perpage) && ! empty($perpage) ? $perpage : 10;
1933
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
1934
+
1935
+		$offset = ($current_page - 1) * $per_page;
1936
+		$limit  = array($offset, $per_page);
1937
+
1938
+		$_where = array(
1939
+			'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)),
1940
+			'Registration.REG_count' => 1
1941
+		);
1942
+
1943
+		if (isset($this->_req_data['EVT_ID'])) {
1944
+			$_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID'];
1945
+		}
1946
+
1947
+		if (isset($this->_req_data['s'])) {
1948
+			$search_string = '%' . $this->_req_data['s'] . '%';
1949
+			$_where['OR']  = array(
1950
+				'Registration.Event.EVT_name'         => array('LIKE', $search_string),
1951
+				'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
1952
+				'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string),
1953
+				'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string),
1954
+				'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string),
1955
+				'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string),
1956
+				'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string),
1957
+				'Registration.Attendee.ATT_email'     => array('LIKE', $search_string),
1958
+				'Registration.Attendee.ATT_address'   => array('LIKE', $search_string),
1959
+				'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string),
1960
+				'Registration.Attendee.ATT_city'      => array('LIKE', $search_string),
1961
+				'Registration.REG_final_price'        => array('LIKE', $search_string),
1962
+				'Registration.REG_code'               => array('LIKE', $search_string),
1963
+				'Registration.REG_count'              => array('LIKE', $search_string),
1964
+				'Registration.REG_group_size'         => array('LIKE', $search_string),
1965
+				'Registration.Ticket.TKT_name'        => array('LIKE', $search_string),
1966
+				'Registration.Ticket.TKT_description' => array('LIKE', $search_string),
1967
+				'Payment.PAY_source'                  => array('LIKE', $search_string),
1968
+				'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string),
1969
+				'TXN_session_data'                    => array('LIKE', $search_string),
1970
+				'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string)
1971
+			);
1972
+		}
1973
+
1974
+		//failed transactions
1975
+		$failed    = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'failed' && ! $count) || ($count && $view == 'failed') ? true : false;
1976
+		$abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'abandoned' && ! $count) || ($count && $view == 'abandoned') ? true : false;
1977
+
1978
+		if ($failed) {
1979
+			$_where['STS_ID'] = EEM_Transaction::failed_status_code;
1980
+		} else if ($abandoned) {
1981
+			$_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
1982
+		} else {
1983
+			$_where['STS_ID']  = array('!=', EEM_Transaction::failed_status_code);
1984
+			$_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code);
1985
+		}
1986
+
1987
+		$query_params = array($_where, 'order_by' => array($orderby => $sort), 'limit' => $limit);
1988
+
1989
+		$transactions = $count ? $TXN->count(array($_where), 'TXN_ID', true) : $TXN->get_all($query_params);
1990
+
1991
+
1992
+		return $transactions;
1993
+
1994
+	}
1995 1995
 
1996 1996
 
1997 1997
 }
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -338,11 +338,11 @@  discard block
 block discarded – undo
338 338
     public function load_scripts_styles()
339 339
     {
340 340
         //enqueue style
341
-        wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(),
341
+        wp_register_style('espresso_txn', TXN_ASSETS_URL.'espresso_transactions_admin.css', array(),
342 342
             EVENT_ESPRESSO_VERSION);
343 343
         wp_enqueue_style('espresso_txn');
344 344
         //scripts
345
-        wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array(
345
+        wp_register_script('espresso_txn', TXN_ASSETS_URL.'espresso_transactions_admin.js', array(
346 346
             'ee_admin_js',
347 347
             'ee-datepicker',
348 348
             'jquery-ui-datepicker',
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 
435 435
         if (empty($this->_transaction)) {
436 436
             $error_msg = esc_html__('An error occurred and the details for Transaction ID #',
437
-                    'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso');
437
+                    'event_espresso').$TXN_ID.esc_html__(' could not be retrieved.', 'event_espresso');
438 438
             EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
439 439
         }
440 440
     }
@@ -509,23 +509,23 @@  discard block
 block discarded – undo
509 509
             'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
510 510
             array(
511 511
                 'overpaid'   => array(
512
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
512
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::overpaid_status_code,
513 513
                     'desc'  => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence')
514 514
                 ),
515 515
                 'complete'   => array(
516
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
516
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::complete_status_code,
517 517
                     'desc'  => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence')
518 518
                 ),
519 519
                 'incomplete' => array(
520
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
520
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::incomplete_status_code,
521 521
                     'desc'  => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence')
522 522
                 ),
523 523
                 'abandoned'  => array(
524
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
524
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::abandoned_status_code,
525 525
                     'desc'  => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence')
526 526
                 ),
527 527
                 'failed'     => array(
528
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
528
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::failed_status_code,
529 529
                     'desc'  => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence')
530 530
                 )
531 531
             )
@@ -547,10 +547,10 @@  discard block
 block discarded – undo
547 547
         $event                                     = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null;
548 548
         $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s',
549 549
             'event_espresso'), '<h3>',
550
-            '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()),
551
-                EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event',
552
-                'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : '';
553
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
550
+            '<a href="'.EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()),
551
+                EVENTS_ADMIN_URL).'" title="'.esc_attr__('Click to Edit event',
552
+                'event_espresso').'">'.$event->get('EVT_name').'</a>', '</h3>') : '';
553
+        $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items());
554 554
         $this->display_admin_list_table_page_with_no_sidebar();
555 555
     }
556 556
 
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
 
585 585
         $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
586 586
         $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
587
-        $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
587
+        $this->_template_args['txn_status']['class'] = 'status-'.$this->_transaction->get('STS_ID');
588 588
 
589 589
         $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
590 590
         $this->_template_args['total_paid']  = $this->_transaction->get('TXN_paid');
@@ -621,9 +621,9 @@  discard block
 block discarded – undo
621 621
         $amount_due                         = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
622 622
         $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true);
623 623
         if (EE_Registry::instance()->CFG->currency->sign_b4) {
624
-            $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due'];
624
+            $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign.$this->_template_args['amount_due'];
625 625
         } else {
626
-            $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign;
626
+            $this->_template_args['amount_due'] = $this->_template_args['amount_due'].EE_Registry::instance()->CFG->currency->sign;
627 627
         }
628 628
         $this->_template_args['amount_due_class'] = '';
629 629
 
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
 
659 659
 
660 660
         // next link
661
-        $next_txn                                 = $this->_transaction->next(
661
+        $next_txn = $this->_transaction->next(
662 662
             null,
663 663
             array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
664 664
             'TXN_ID'
@@ -673,7 +673,7 @@  discard block
 block discarded – undo
673 673
             )
674 674
             : '';
675 675
         // previous link
676
-        $previous_txn                                 = $this->_transaction->previous(
676
+        $previous_txn = $this->_transaction->previous(
677 677
             null,
678 678
             array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
679 679
             'TXN_ID'
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
         // grab messages at the last second
728 728
         $this->_template_args['notices'] = EE_Error::get_notices();
729 729
         // path to template
730
-        $template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
730
+        $template_path                             = TXN_TEMPLATE_PATH.'txn_admin_details_header.template.php';
731 731
         $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path,
732 732
             $this->_template_args, true);
733 733
 
@@ -835,18 +835,18 @@  discard block
 block discarded – undo
835 835
         $reg_steps = '<ul>';
836 836
         foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
837 837
             if ($reg_step_status === true) {
838
-                $reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'),
839
-                        ucwords(str_replace('_', ' ', $reg_step))) . '</li>';
838
+                $reg_steps .= '<li style="color:#70cc50">'.sprintf(esc_html__('%1$s : Completed', 'event_espresso'),
839
+                        ucwords(str_replace('_', ' ', $reg_step))).'</li>';
840 840
             } else if (is_numeric($reg_step_status) && $reg_step_status !== false) {
841
-                $reg_steps .= '<li style="color:#2EA2CC">' . sprintf(
841
+                $reg_steps .= '<li style="color:#2EA2CC">'.sprintf(
842 842
                         esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
843 843
                         ucwords(str_replace('_', ' ', $reg_step)),
844
-                        date(get_option('date_format') . ' ' . get_option('time_format'),
844
+                        date(get_option('date_format').' '.get_option('time_format'),
845 845
                             ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)))
846
-                    ) . '</li>';
846
+                    ).'</li>';
847 847
             } else {
848
-                $reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated',
849
-                        'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>';
848
+                $reg_steps .= '<li style="color:#E76700">'.sprintf(esc_html__('%1$s : Never Initiated',
849
+                        'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))).'</li>';
850 850
             }
851 851
         }
852 852
         $reg_steps .= '</ul>';
@@ -860,11 +860,11 @@  discard block
 block discarded – undo
860 860
         $this->_get_payment_status_array();
861 861
         $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction.
862 862
 
863
-        $this->_template_args['transaction_form_url']    = add_query_arg(array(
863
+        $this->_template_args['transaction_form_url'] = add_query_arg(array(
864 864
             'action'  => 'edit_transaction',
865 865
             'process' => 'transaction'
866 866
         ), TXN_ADMIN_URL);
867
-        $this->_template_args['apply_payment_form_url']  = add_query_arg(array(
867
+        $this->_template_args['apply_payment_form_url'] = add_query_arg(array(
868 868
             'page'   => 'espresso_transactions',
869 869
             'action' => 'espresso_apply_payment'
870 870
         ), WP_AJAX_URL);
@@ -875,7 +875,7 @@  discard block
 block discarded – undo
875 875
 
876 876
         // 'espresso_delete_payment_nonce'
877 877
 
878
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
878
+        $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_txn_details.template.php';
879 879
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
880 880
 
881 881
     }
@@ -935,7 +935,7 @@  discard block
 block discarded – undo
935 935
     protected function _get_registrations_to_apply_payment_to()
936 936
     {
937 937
         // we want any registration with an active status (ie: not deleted or cancelled)
938
-        $query_params                      = array(
938
+        $query_params = array(
939 939
             array(
940 940
                 'STS_ID' => array(
941 941
                     'IN',
@@ -947,19 +947,19 @@  discard block
 block discarded – undo
947 947
                 )
948 948
             )
949 949
         );
950
-        $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div(
950
+        $registrations_to_apply_payment_to = EEH_HTML::br().EEH_HTML::div(
951 951
                 '', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;'
952 952
             );
953
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
953
+        $registrations_to_apply_payment_to .= EEH_HTML::br().EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
954 954
         $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
955 955
         $registrations_to_apply_payment_to .= EEH_HTML::thead(
956 956
             EEH_HTML::tr(
957
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
958
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
959
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
960
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
961
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
962
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
957
+                EEH_HTML::th(esc_html__('ID', 'event_espresso')).
958
+                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')).
959
+                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')).
960
+                EEH_HTML::th(esc_html__('Event', 'event_espresso')).
961
+                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr').
962
+                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr').
963 963
                 EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
964 964
             )
965 965
         );
@@ -973,28 +973,28 @@  discard block
 block discarded – undo
973 973
                     : esc_html__('Unknown Attendee', 'event_espresso');
974 974
                 $owing         = $registration->final_price() - $registration->paid();
975 975
                 $taxable       = $registration->ticket()->taxable()
976
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
976
+                    ? ' <span class="smaller-text lt-grey-text"> '.esc_html__('+ tax', 'event_espresso').'</span>'
977 977
                     : '';
978 978
                 $checked       = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
979 979
                     ? ' checked="checked"'
980 980
                     : '';
981 981
                 $disabled      = $registration->final_price() > 0 ? '' : ' disabled';
982 982
                 $registrations_to_apply_payment_to .= EEH_HTML::tr(
983
-                    EEH_HTML::td($registration->ID()) .
984
-                    EEH_HTML::td($attendee_name) .
983
+                    EEH_HTML::td($registration->ID()).
984
+                    EEH_HTML::td($attendee_name).
985 985
                     EEH_HTML::td(
986
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
987
-                    ) .
988
-                    EEH_HTML::td($registration->event_name()) .
989
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
990
-                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
986
+                        $registration->ticket()->name().' : '.$registration->ticket()->pretty_price().$taxable
987
+                    ).
988
+                    EEH_HTML::td($registration->event_name()).
989
+                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr').
990
+                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr').
991 991
                     EEH_HTML::td(
992
-                        '<input type="checkbox" value="' . $registration->ID()
992
+                        '<input type="checkbox" value="'.$registration->ID()
993 993
                         . '" name="txn_admin_payment[registrations]"'
994
-                        . $checked . $disabled . '>',
994
+                        . $checked.$disabled.'>',
995 995
                         '', 'jst-cntr'
996 996
                     ),
997
-                    'apply-payment-registration-row-' . $registration->ID()
997
+                    'apply-payment-registration-row-'.$registration->ID()
998 998
                 );
999 999
             }
1000 1000
         }
@@ -1060,12 +1060,12 @@  discard block
 block discarded – undo
1060 1060
                 array(
1061 1061
                     'OR*payment_method_for_payment' => array(
1062 1062
                         'PMD_ID'    => array('IN', $payment_methods_of_payments),
1063
-                        'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')
1063
+                        'PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%')
1064 1064
                     )
1065 1065
                 )
1066 1066
             );
1067 1067
         } else {
1068
-            $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1068
+            $query_args = array(array('PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%')));
1069 1069
         }
1070 1070
         $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1071 1071
     }
@@ -1110,7 +1110,7 @@  discard block
 block discarded – undo
1110 1110
                                 EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1111 1111
                                 $event_name = esc_html__('Unknown Event', 'event_espresso');
1112 1112
                             }
1113
-                            $event_name .= ' - ' . $item->get('LIN_name');
1113
+                            $event_name .= ' - '.$item->get('LIN_name');
1114 1114
                             $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1115 1115
                             // now get all of the registrations for this transaction that use this ticket
1116 1116
                             $registrations = $ticket->get_many_related('Registration',
@@ -1128,8 +1128,8 @@  discard block
 block discarded – undo
1128 1128
                                 if ($attendee instanceof EE_Attendee) {
1129 1129
                                     $this->_template_args['event_attendees'][$registration->ID()]['att_id']   = $attendee->ID();
1130 1130
                                     $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name();
1131
-                                    $this->_template_args['event_attendees'][$registration->ID()]['email']    = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event',
1132
-                                            'event_espresso') . '">' . $attendee->email() . '</a>';
1131
+                                    $this->_template_args['event_attendees'][$registration->ID()]['email']    = '<a href="mailto:'.$attendee->email().'?subject='.$event_name.esc_html__(' Event',
1132
+                                            'event_espresso').'">'.$attendee->email().'</a>';
1133 1133
                                     $this->_template_args['event_attendees'][$registration->ID()]['address']  = EEH_Address::format($attendee,
1134 1134
                                         'inline', false, false);
1135 1135
                                 } else {
@@ -1149,7 +1149,7 @@  discard block
 block discarded – undo
1149 1149
                 'action'  => 'edit_transaction',
1150 1150
                 'process' => 'attendees'
1151 1151
             ), TXN_ADMIN_URL);
1152
-            echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1152
+            echo EEH_Template::display_template(TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_attendees.template.php',
1153 1153
                 $this->_template_args, true);
1154 1154
 
1155 1155
         } else {
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
         ), REG_ADMIN_URL);
1191 1191
         // get formatted address for registrant
1192 1192
         $this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1193
-        echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1193
+        echo EEH_Template::display_template(TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_registrant.template.php',
1194 1194
             $this->_template_args, true);
1195 1195
     }
1196 1196
 
@@ -1211,8 +1211,8 @@  discard block
 block discarded – undo
1211 1211
             TXN_ADMIN_URL
1212 1212
         );
1213 1213
 
1214
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1215
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1214
+        $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_billing_info.template.php';
1215
+        echo EEH_Template::display_template($template_path, $this->_template_args, true); /**/
1216 1216
     }
1217 1217
 
1218 1218
 
@@ -1505,7 +1505,7 @@  discard block
 block discarded – undo
1505 1505
         $REG_IDs = array();
1506 1506
         // grab array of IDs for specific registrations to apply changes to
1507 1507
         if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1508
-            $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations'];
1508
+            $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations'];
1509 1509
         }
1510 1510
         //nothing specified ? then get all reg IDs
1511 1511
         if (empty($REG_IDs)) {
@@ -1891,8 +1891,8 @@  discard block
 block discarded – undo
1891 1891
         $end_date   = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y');
1892 1892
 
1893 1893
         //make sure our timestamps start and end right at the boundaries for each day
1894
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1895
-        $end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1894
+        $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00';
1895
+        $end_date   = date('Y-m-d', strtotime($end_date)).' 23:59:59';
1896 1896
 
1897 1897
 
1898 1898
         //convert to timestamps
@@ -1945,7 +1945,7 @@  discard block
 block discarded – undo
1945 1945
         }
1946 1946
 
1947 1947
         if (isset($this->_req_data['s'])) {
1948
-            $search_string = '%' . $this->_req_data['s'] . '%';
1948
+            $search_string = '%'.$this->_req_data['s'].'%';
1949 1949
             $_where['OR']  = array(
1950 1950
                 'Registration.Event.EVT_name'         => array('LIKE', $search_string),
1951 1951
                 'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 2 patches
Indentation   +3299 added lines, -3299 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -28,2114 +28,2114 @@  discard block
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    //set in _init_page_props()
32
-    public $page_slug;
31
+	//set in _init_page_props()
32
+	public $page_slug;
33 33
 
34
-    public $page_label;
34
+	public $page_label;
35 35
 
36
-    public $page_folder;
36
+	public $page_folder;
37 37
 
38
-    //set in define_page_props()
39
-    protected $_admin_base_url;
38
+	//set in define_page_props()
39
+	protected $_admin_base_url;
40 40
 
41
-    protected $_admin_base_path;
41
+	protected $_admin_base_path;
42 42
 
43
-    protected $_admin_page_title;
43
+	protected $_admin_page_title;
44 44
 
45
-    protected $_labels;
45
+	protected $_labels;
46 46
 
47 47
 
48
-    //set early within EE_Admin_Init
49
-    protected $_wp_page_slug;
48
+	//set early within EE_Admin_Init
49
+	protected $_wp_page_slug;
50 50
 
51
-    //navtabs
52
-    protected $_nav_tabs;
51
+	//navtabs
52
+	protected $_nav_tabs;
53 53
 
54
-    protected $_default_nav_tab_name;
54
+	protected $_default_nav_tab_name;
55 55
 
56
-    //helptourstops
57
-    protected $_help_tour = array();
56
+	//helptourstops
57
+	protected $_help_tour = array();
58 58
 
59 59
 
60
-    //template variables (used by templates)
61
-    protected $_template_path;
60
+	//template variables (used by templates)
61
+	protected $_template_path;
62 62
 
63
-    protected $_column_template_path;
63
+	protected $_column_template_path;
64 64
 
65
-    /**
66
-     * @var array $_template_args
67
-     */
68
-    protected $_template_args = array();
65
+	/**
66
+	 * @var array $_template_args
67
+	 */
68
+	protected $_template_args = array();
69 69
 
70
-    /**
71
-     * this will hold the list table object for a given view.
72
-     *
73
-     * @var EE_Admin_List_Table $_list_table_object
74
-     */
75
-    protected $_list_table_object;
70
+	/**
71
+	 * this will hold the list table object for a given view.
72
+	 *
73
+	 * @var EE_Admin_List_Table $_list_table_object
74
+	 */
75
+	protected $_list_table_object;
76 76
 
77
-    //bools
78
-    protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
77
+	//bools
78
+	protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
79 79
 
80
-    protected $_routing;
80
+	protected $_routing;
81 81
 
82
-    //list table args
83
-    protected $_view;
82
+	//list table args
83
+	protected $_view;
84 84
 
85
-    protected $_views;
85
+	protected $_views;
86 86
 
87 87
 
88
-    //action => method pairs used for routing incoming requests
89
-    protected $_page_routes;
88
+	//action => method pairs used for routing incoming requests
89
+	protected $_page_routes;
90 90
 
91
-    protected $_page_config;
91
+	protected $_page_config;
92 92
 
93
-    //the current page route and route config
94
-    protected $_route;
93
+	//the current page route and route config
94
+	protected $_route;
95 95
 
96
-    protected $_route_config;
96
+	protected $_route_config;
97 97
 
98
-    /**
99
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
100
-     * actions.
101
-     *
102
-     * @since 4.6.x
103
-     * @var array.
104
-     */
105
-    protected $_default_route_query_args;
98
+	/**
99
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
100
+	 * actions.
101
+	 *
102
+	 * @since 4.6.x
103
+	 * @var array.
104
+	 */
105
+	protected $_default_route_query_args;
106 106
 
107
-    //set via request page and action args.
108
-    protected $_current_page;
107
+	//set via request page and action args.
108
+	protected $_current_page;
109 109
 
110
-    protected $_current_view;
110
+	protected $_current_view;
111 111
 
112
-    protected $_current_page_view_url;
112
+	protected $_current_page_view_url;
113 113
 
114
-    //sanitized request action (and nonce)
115
-    /**
116
-     * @var string $_req_action
117
-     */
118
-    protected $_req_action;
114
+	//sanitized request action (and nonce)
115
+	/**
116
+	 * @var string $_req_action
117
+	 */
118
+	protected $_req_action;
119 119
 
120
-    /**
121
-     * @var string $_req_nonce
122
-     */
123
-    protected $_req_nonce;
120
+	/**
121
+	 * @var string $_req_nonce
122
+	 */
123
+	protected $_req_nonce;
124 124
 
125
-    //search related
126
-    protected $_search_btn_label;
125
+	//search related
126
+	protected $_search_btn_label;
127 127
 
128
-    protected $_search_box_callback;
128
+	protected $_search_box_callback;
129 129
 
130
-    /**
131
-     * WP Current Screen object
132
-     *
133
-     * @var WP_Screen
134
-     */
135
-    protected $_current_screen;
130
+	/**
131
+	 * WP Current Screen object
132
+	 *
133
+	 * @var WP_Screen
134
+	 */
135
+	protected $_current_screen;
136 136
 
137
-    //for holding EE_Admin_Hooks object when needed (set via set_hook_object())
138
-    protected $_hook_obj;
137
+	//for holding EE_Admin_Hooks object when needed (set via set_hook_object())
138
+	protected $_hook_obj;
139 139
 
140
-    //for holding incoming request data
141
-    protected $_req_data;
140
+	//for holding incoming request data
141
+	protected $_req_data;
142 142
 
143
-    // yes / no array for admin form fields
144
-    protected $_yes_no_values = array();
145
-
146
-    //some default things shared by all child classes
147
-    protected $_default_espresso_metaboxes;
148
-
149
-    /**
150
-     *    EE_Registry Object
151
-     *
152
-     * @var    EE_Registry
153
-     * @access    protected
154
-     */
155
-    protected $EE = null;
156
-
157
-
158
-
159
-    /**
160
-     * This is just a property that flags whether the given route is a caffeinated route or not.
161
-     *
162
-     * @var boolean
163
-     */
164
-    protected $_is_caf = false;
165
-
166
-
167
-
168
-    /**
169
-     * @Constructor
170
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
171
-     * @access public
172
-     */
173
-    public function __construct($routing = true)
174
-    {
175
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
176
-            $this->_is_caf = true;
177
-        }
178
-        $this->_yes_no_values = array(
179
-                array('id' => true, 'text' => __('Yes', 'event_espresso')),
180
-                array('id' => false, 'text' => __('No', 'event_espresso')),
181
-        );
182
-        //set the _req_data property.
183
-        $this->_req_data = array_merge($_GET, $_POST);
184
-        //routing enabled?
185
-        $this->_routing = $routing;
186
-        //set initial page props (child method)
187
-        $this->_init_page_props();
188
-        //set global defaults
189
-        $this->_set_defaults();
190
-        //set early because incoming requests could be ajax related and we need to register those hooks.
191
-        $this->_global_ajax_hooks();
192
-        $this->_ajax_hooks();
193
-        //other_page_hooks have to be early too.
194
-        $this->_do_other_page_hooks();
195
-        //This just allows us to have extending classes do something specific
196
-        // before the parent constructor runs _page_setup().
197
-        if (method_exists($this, '_before_page_setup')) {
198
-            $this->_before_page_setup();
199
-        }
200
-        //set up page dependencies
201
-        $this->_page_setup();
202
-    }
203
-
204
-
205
-
206
-    /**
207
-     * _init_page_props
208
-     * Child classes use to set at least the following properties:
209
-     * $page_slug.
210
-     * $page_label.
211
-     *
212
-     * @abstract
213
-     * @access protected
214
-     * @return void
215
-     */
216
-    abstract protected function _init_page_props();
217
-
218
-
219
-
220
-    /**
221
-     * _ajax_hooks
222
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
223
-     * Note: within the ajax callback methods.
224
-     *
225
-     * @abstract
226
-     * @access protected
227
-     * @return void
228
-     */
229
-    abstract protected function _ajax_hooks();
230
-
231
-
232
-
233
-    /**
234
-     * _define_page_props
235
-     * child classes define page properties in here.  Must include at least:
236
-     * $_admin_base_url = base_url for all admin pages
237
-     * $_admin_page_title = default admin_page_title for admin pages
238
-     * $_labels = array of default labels for various automatically generated elements:
239
-     *    array(
240
-     *        'buttons' => array(
241
-     *            'add' => __('label for add new button'),
242
-     *            'edit' => __('label for edit button'),
243
-     *            'delete' => __('label for delete button')
244
-     *            )
245
-     *        )
246
-     *
247
-     * @abstract
248
-     * @access protected
249
-     * @return void
250
-     */
251
-    abstract protected function _define_page_props();
252
-
253
-
254
-
255
-    /**
256
-     * _set_page_routes
257
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also have a 'default'
258
-     * route. Here's the format
259
-     * $this->_page_routes = array(
260
-     *        'default' => array(
261
-     *            'func' => '_default_method_handling_route',
262
-     *            'args' => array('array','of','args'),
263
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
264
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after.  The string you enter here should match the defined route reference for a headers sent route.
265
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
266
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
267
-     *        ),
268
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
269
-     *        )
270
-     * )
271
-     *
272
-     * @abstract
273
-     * @access protected
274
-     * @return void
275
-     */
276
-    abstract protected function _set_page_routes();
277
-
278
-
279
-
280
-    /**
281
-     * _set_page_config
282
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page.
283
-     * Format:
284
-     * $this->_page_config = array(
285
-     *        'default' => array(
286
-     *            'labels' => array(
287
-     *                'buttons' => array(
288
-     *                    'add' => __('label for adding item'),
289
-     *                    'edit' => __('label for editing item'),
290
-     *                    'delete' => __('label for deleting item')
291
-     *                ),
292
-     *                'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
293
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method
294
-     *            'nav' => array(
295
-     *                'label' => __('Label for Tab', 'event_espresso').
296
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
297
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
298
-     *                'order' => 10, //required to indicate tab position.
299
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
300
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
301
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
302
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added later.  We just use
303
-     *            this flag to make sure the necessary js gets enqueued on page load.
304
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
305
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The array indicates the max number of columns (4) and the default number of columns on page load (2).  There is an option
306
-     *            in the "screen_options" dropdown that is setup so users can pick what columns they want to display.
307
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
308
-     *                'tab_id' => array(
309
-     *                    'title' => 'tab_title',
310
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content.  The fallback if it isn't present is to try a the callback.  Filename should match a file in the admin
311
-     *                    folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php)
312
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class
313
-     *                    ),
314
-     *                'tab2_id' => array(
315
-     *                    'title' => 'tab2 title',
316
-     *                    'filename' => 'file_name_2'
317
-     *                    'callback' => 'callback_method_for_content',
318
-     *                 ),
319
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
320
-     *            'help_tour' => array(
321
-     *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here
322
-     *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
323
-     *            ),
324
-     *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present).  To remove the requirement for a nonce check when this route is visited just set
325
-     *            'require_nonce' to FALSE
326
-     *            )
327
-     * )
328
-     *
329
-     * @abstract
330
-     * @access protected
331
-     * @return void
332
-     */
333
-    abstract protected function _set_page_config();
334
-
335
-
336
-
337
-
338
-
339
-    /** end sample help_tour methods **/
340
-    /**
341
-     * _add_screen_options
342
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
343
-     * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
344
-     *
345
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
346
-     *         see also WP_Screen object documents...
347
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
348
-     * @abstract
349
-     * @access protected
350
-     * @return void
351
-     */
352
-    abstract protected function _add_screen_options();
353
-
354
-
355
-
356
-    /**
357
-     * _add_feature_pointers
358
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
359
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
360
-     * Note: this is just a placeholder for now.  Implementation will come down the road
361
-     * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
362
-     *
363
-     * @link   http://eamann.com/tech/wordpress-portland/
364
-     * @abstract
365
-     * @access protected
366
-     * @return void
367
-     */
368
-    abstract protected function _add_feature_pointers();
369
-
370
-
371
-
372
-    /**
373
-     * load_scripts_styles
374
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific scripts/styles
375
-     * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
376
-     *
377
-     * @abstract
378
-     * @access public
379
-     * @return void
380
-     */
381
-    abstract public function load_scripts_styles();
382
-
383
-
384
-
385
-    /**
386
-     * admin_init
387
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to all pages/views loaded by child class.
388
-     *
389
-     * @abstract
390
-     * @access public
391
-     * @return void
392
-     */
393
-    abstract public function admin_init();
394
-
395
-
396
-
397
-    /**
398
-     * admin_notices
399
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to all pages/views loaded by child class.
400
-     *
401
-     * @abstract
402
-     * @access public
403
-     * @return void
404
-     */
405
-    abstract public function admin_notices();
406
-
407
-
408
-
409
-    /**
410
-     * admin_footer_scripts
411
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class.
412
-     *
413
-     * @access public
414
-     * @return void
415
-     */
416
-    abstract public function admin_footer_scripts();
417
-
418
-
419
-
420
-    /**
421
-     * admin_footer
422
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class.
423
-     *
424
-     * @access  public
425
-     * @return void
426
-     */
427
-    public function admin_footer()
428
-    {
429
-    }
430
-
431
-
432
-
433
-    /**
434
-     * _global_ajax_hooks
435
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
436
-     * Note: within the ajax callback methods.
437
-     *
438
-     * @abstract
439
-     * @access protected
440
-     * @return void
441
-     */
442
-    protected function _global_ajax_hooks()
443
-    {
444
-        //for lazy loading of metabox content
445
-        add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
446
-    }
447
-
448
-
449
-
450
-    public function ajax_metabox_content()
451
-    {
452
-        $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
453
-        $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
454
-        self::cached_rss_display($contentid, $url);
455
-        wp_die();
456
-    }
457
-
458
-
459
-
460
-    /**
461
-     * _page_setup
462
-     * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested doesn't match the object.
463
-     *
464
-     * @final
465
-     * @access protected
466
-     * @return void
467
-     */
468
-    final protected function _page_setup()
469
-    {
470
-        //requires?
471
-        //admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
472
-        add_action('admin_init', array($this, 'admin_init_global'), 5);
473
-        //next verify if we need to load anything...
474
-        $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
475
-        $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
476
-        global $ee_menu_slugs;
477
-        $ee_menu_slugs = (array)$ee_menu_slugs;
478
-        if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
479
-            return;
480
-        }
481
-        // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
482
-        if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) {
483
-            $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
484
-        }
485
-        // then set blank or -1 action values to 'default'
486
-        $this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default';
487
-        //if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.  This covers cases where we're coming in from a list table that isn't on the default route.
488
-        $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
489
-        //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
490
-        $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
491
-        $this->_current_view = $this->_req_action;
492
-        $this->_req_nonce = $this->_req_action . '_nonce';
493
-        $this->_define_page_props();
494
-        $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
495
-        //default things
496
-        $this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box');
497
-        //set page configs
498
-        $this->_set_page_routes();
499
-        $this->_set_page_config();
500
-        //let's include any referrer data in our default_query_args for this route for "stickiness".
501
-        if (isset($this->_req_data['wp_referer'])) {
502
-            $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
503
-        }
504
-        //for caffeinated and other extended functionality.  If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays
505
-        if (method_exists($this, '_extend_page_config')) {
506
-            $this->_extend_page_config();
507
-        }
508
-        //for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays.
509
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
510
-            $this->_extend_page_config_for_cpt();
511
-        }
512
-        //filter routes and page_config so addons can add their stuff. Filtering done per class
513
-        $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
514
-        $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
515
-        //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
516
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
517
-            add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
518
-        }
519
-        //next route only if routing enabled
520
-        if ($this->_routing && ! defined('DOING_AJAX')) {
521
-            $this->_verify_routes();
522
-            //next let's just check user_access and kill if no access
523
-            $this->check_user_access();
524
-            if ($this->_is_UI_request) {
525
-                //admin_init stuff - global, all views for this page class, specific view
526
-                add_action('admin_init', array($this, 'admin_init'), 10);
527
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
528
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
529
-                }
530
-            } else {
531
-                //hijack regular WP loading and route admin request immediately
532
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
533
-                $this->route_admin_request();
534
-            }
535
-        }
536
-    }
537
-
538
-
539
-
540
-    /**
541
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
542
-     *
543
-     * @access private
544
-     * @return void
545
-     */
546
-    private function _do_other_page_hooks()
547
-    {
548
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
549
-        foreach ($registered_pages as $page) {
550
-            //now let's setup the file name and class that should be present
551
-            $classname = str_replace('.class.php', '', $page);
552
-            //autoloaders should take care of loading file
553
-            if ( ! class_exists($classname)) {
554
-                $error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
555
-                $error_msg[] = $error_msg[0]
556
-                               . "\r\n"
557
-                               . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
558
-                                'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
559
-                throw new EE_Error(implode('||', $error_msg));
560
-            }
561
-            $a = new ReflectionClass($classname);
562
-            //notice we are passing the instance of this class to the hook object.
563
-            $hookobj[] = $a->newInstance($this);
564
-        }
565
-    }
566
-
567
-
568
-
569
-    public function load_page_dependencies()
570
-    {
571
-        try {
572
-            $this->_load_page_dependencies();
573
-        } catch (EE_Error $e) {
574
-            $e->get_error();
575
-        }
576
-    }
577
-
578
-
579
-
580
-    /**
581
-     * load_page_dependencies
582
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
583
-     *
584
-     * @access public
585
-     * @return void
586
-     */
587
-    protected function _load_page_dependencies()
588
-    {
589
-        //let's set the current_screen and screen options to override what WP set
590
-        $this->_current_screen = get_current_screen();
591
-        //load admin_notices - global, page class, and view specific
592
-        add_action('admin_notices', array($this, 'admin_notices_global'), 5);
593
-        add_action('admin_notices', array($this, 'admin_notices'), 10);
594
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
595
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
596
-        }
597
-        //load network admin_notices - global, page class, and view specific
598
-        add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
599
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
600
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
601
-        }
602
-        //this will save any per_page screen options if they are present
603
-        $this->_set_per_page_screen_options();
604
-        //setup list table properties
605
-        $this->_set_list_table();
606
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.  However in some cases the metaboxes will need to be added within a route handling callback.
607
-        $this->_add_registered_meta_boxes();
608
-        $this->_add_screen_columns();
609
-        //add screen options - global, page child class, and view specific
610
-        $this->_add_global_screen_options();
611
-        $this->_add_screen_options();
612
-        if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
613
-            call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
614
-        }
615
-        //add help tab(s) and tours- set via page_config and qtips.
616
-        $this->_add_help_tour();
617
-        $this->_add_help_tabs();
618
-        $this->_add_qtips();
619
-        //add feature_pointers - global, page child class, and view specific
620
-        $this->_add_feature_pointers();
621
-        $this->_add_global_feature_pointers();
622
-        if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
623
-            call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
624
-        }
625
-        //enqueue scripts/styles - global, page class, and view specific
626
-        add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
627
-        add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
628
-        if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
629
-            add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
630
-        }
631
-        add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
632
-        //admin_print_footer_scripts - global, page child class, and view specific.  NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.  In most cases that's doing_it_wrong().  But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these
633
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
634
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
635
-        if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
636
-            add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
637
-        }
638
-        //admin footer scripts
639
-        add_action('admin_footer', array($this, 'admin_footer_global'), 99);
640
-        add_action('admin_footer', array($this, 'admin_footer'), 100);
641
-        if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
642
-            add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
643
-        }
644
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
645
-        //targeted hook
646
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
647
-    }
648
-
649
-
650
-
651
-    /**
652
-     * _set_defaults
653
-     * This sets some global defaults for class properties.
654
-     */
655
-    private function _set_defaults()
656
-    {
657
-        $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null;
658
-        $this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array();
659
-        $this->default_nav_tab_name = 'overview';
660
-        //init template args
661
-        $this->_template_args = array(
662
-                'admin_page_header'  => '',
663
-                'admin_page_content' => '',
664
-                'post_body_content'  => '',
665
-                'before_list_table'  => '',
666
-                'after_list_table'   => '',
667
-        );
668
-    }
669
-
670
-
671
-
672
-    /**
673
-     * route_admin_request
674
-     *
675
-     * @see    _route_admin_request()
676
-     * @access public
677
-     * @return void|exception error
678
-     */
679
-    public function route_admin_request()
680
-    {
681
-        try {
682
-            $this->_route_admin_request();
683
-        } catch (EE_Error $e) {
684
-            $e->get_error();
685
-        }
686
-    }
687
-
688
-
689
-
690
-    public function set_wp_page_slug($wp_page_slug)
691
-    {
692
-        $this->_wp_page_slug = $wp_page_slug;
693
-        //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
694
-        if (is_network_admin()) {
695
-            $this->_wp_page_slug .= '-network';
696
-        }
697
-    }
698
-
699
-
700
-
701
-    /**
702
-     * _verify_routes
703
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so we know if we need to drop out.
704
-     *
705
-     * @access protected
706
-     * @return void
707
-     */
708
-    protected function _verify_routes()
709
-    {
710
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
711
-        if ( ! $this->_current_page && ! defined('DOING_AJAX')) {
712
-            return false;
713
-        }
714
-        $this->_route = false;
715
-        $func = false;
716
-        $args = array();
717
-        // check that the page_routes array is not empty
718
-        if (empty($this->_page_routes)) {
719
-            // user error msg
720
-            $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
721
-            // developer error msg
722
-            $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
723
-            throw new EE_Error($error_msg);
724
-        }
725
-        // and that the requested page route exists
726
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
727
-            $this->_route = $this->_page_routes[$this->_req_action];
728
-            $this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
729
-        } else {
730
-            // user error msg
731
-            $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
732
-            // developer error msg
733
-            $error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
734
-            throw new EE_Error($error_msg);
735
-        }
736
-        // and that a default route exists
737
-        if ( ! array_key_exists('default', $this->_page_routes)) {
738
-            // user error msg
739
-            $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
740
-            // developer error msg
741
-            $error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
742
-            throw new EE_Error($error_msg);
743
-        }
744
-        //first lets' catch if the UI request has EVER been set.
745
-        if ($this->_is_UI_request === null) {
746
-            //lets set if this is a UI request or not.
747
-            $this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false;
748
-            //wait a minute... we might have a noheader in the route array
749
-            $this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request;
750
-        }
751
-        $this->_set_current_labels();
752
-    }
753
-
754
-
755
-
756
-    /**
757
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
758
-     *
759
-     * @param  string $route the route name we're verifying
760
-     * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
761
-     */
762
-    protected function _verify_route($route)
763
-    {
764
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
765
-            return true;
766
-        } else {
767
-            // user error msg
768
-            $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
769
-            // developer error msg
770
-            $error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
771
-            throw new EE_Error($error_msg);
772
-        }
773
-    }
774
-
775
-
776
-
777
-    /**
778
-     * perform nonce verification
779
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!)
780
-     *
781
-     * @param  string $nonce     The nonce sent
782
-     * @param  string $nonce_ref The nonce reference string (name0)
783
-     * @return mixed (bool|die)
784
-     */
785
-    protected function _verify_nonce($nonce, $nonce_ref)
786
-    {
787
-        // verify nonce against expected value
788
-        if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
789
-            // these are not the droids you are looking for !!!
790
-            $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
791
-            if (WP_DEBUG) {
792
-                $msg .= "\n  " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
793
-            }
794
-            if ( ! defined('DOING_AJAX')) {
795
-                wp_die($msg);
796
-            } else {
797
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
798
-                $this->_return_json();
799
-            }
800
-        }
801
-    }
802
-
803
-
804
-
805
-    /**
806
-     * _route_admin_request()
807
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
808
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
809
-     * in the page routes and then will try to load the corresponding method.
810
-     *
811
-     * @access protected
812
-     * @return void
813
-     * @throws \EE_Error
814
-     */
815
-    protected function _route_admin_request()
816
-    {
817
-        if ( ! $this->_is_UI_request) {
818
-            $this->_verify_routes();
819
-        }
820
-        $nonce_check = isset($this->_route_config['require_nonce'])
821
-            ? $this->_route_config['require_nonce']
822
-            : true;
823
-        if ($this->_req_action !== 'default' && $nonce_check) {
824
-            // set nonce from post data
825
-            $nonce = isset($this->_req_data[$this->_req_nonce])
826
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce])
827
-                : '';
828
-            $this->_verify_nonce($nonce, $this->_req_nonce);
829
-        }
830
-        //set the nav_tabs array but ONLY if this is  UI_request
831
-        if ($this->_is_UI_request) {
832
-            $this->_set_nav_tabs();
833
-        }
834
-        // grab callback function
835
-        $func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
836
-        // check if callback has args
837
-        $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
838
-        $error_msg = '';
839
-        // action right before calling route
840
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
841
-        if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
842
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
843
-        }
844
-        // right before calling the route, let's remove _wp_http_referer from the
845
-        // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
846
-        $_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI']));
847
-        if ( ! empty($func)) {
848
-            if (is_array($func)) {
849
-                list($class, $method) = $func;
850
-            } else if (strpos($func, '::') !== false) {
851
-                list($class, $method) = explode('::', $func);
852
-            } else {
853
-                $class = $this;
854
-                $method = $func;
855
-            }
856
-            if ( ! (is_object($class) && $class === $this)) {
857
-                // send along this admin page object for access by addons.
858
-                $args['admin_page_object'] = $this;
859
-            }
860
-
861
-            if (
862
-                //is it a method on a class that doesn't work?
863
-                (
864
-                    (
865
-                        method_exists($class, $method)
866
-                        && call_user_func_array(array($class, $method), $args) === false
867
-                    )
868
-                    && (
869
-                        //is it a standalone function that doesn't work?
870
-                        function_exists($method)
871
-                        && call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false
872
-                    )
873
-                )
874
-                || (
875
-                    //is it neither a class method NOR a standalone function?
876
-                    ! method_exists($class, $method)
877
-                    && ! function_exists($method)
878
-                )
879
-            ) {
880
-                // user error msg
881
-                $error_msg = __('An error occurred. The  requested page route could not be found.', 'event_espresso');
882
-                // developer error msg
883
-                $error_msg .= '||';
884
-                $error_msg .= sprintf(
885
-                    __(
886
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
887
-                        'event_espresso'
888
-                    ),
889
-                    $method
890
-                );
891
-            }
892
-            if ( ! empty($error_msg)) {
893
-                throw new EE_Error($error_msg);
894
-            }
895
-        }
896
-        //if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route.
897
-        //now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
898
-        if ($this->_is_UI_request === false
899
-            && is_array($this->_route)
900
-            && ! empty($this->_route['headers_sent_route'])
901
-        ) {
902
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
903
-        }
904
-    }
905
-
906
-
907
-
908
-    /**
909
-     * This method just allows the resetting of page properties in the case where a no headers
910
-     * route redirects to a headers route in its route config.
911
-     *
912
-     * @since   4.3.0
913
-     * @param  string $new_route New (non header) route to redirect to.
914
-     * @return   void
915
-     */
916
-    protected function _reset_routing_properties($new_route)
917
-    {
918
-        $this->_is_UI_request = true;
919
-        //now we set the current route to whatever the headers_sent_route is set at
920
-        $this->_req_data['action'] = $new_route;
921
-        //rerun page setup
922
-        $this->_page_setup();
923
-    }
924
-
925
-
926
-
927
-    /**
928
-     * _add_query_arg
929
-     * adds nonce to array of arguments then calls WP add_query_arg function
930
-     *(internally just uses EEH_URL's function with the same name)
931
-     *
932
-     * @access public
933
-     * @param array  $args
934
-     * @param string $url
935
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the generated
936
-     *                                        url in an associative array indexed by the key 'wp_referer';
937
-     *                                        Example usage:
938
-     *                                        If the current page is:
939
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
940
-     *                                        &action=default&event_id=20&month_range=March%202015
941
-     *                                        &_wpnonce=5467821
942
-     *                                        and you call:
943
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
944
-     *                                        array(
945
-     *                                        'action' => 'resend_something',
946
-     *                                        'page=>espresso_registrations'
947
-     *                                        ),
948
-     *                                        $some_url,
949
-     *                                        true
950
-     *                                        );
951
-     *                                        It will produce a url in this structure:
952
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
953
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
954
-     *                                        month_range]=March%202015
955
-     * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
956
-     * @return string
957
-     */
958
-    public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false)
959
-    {
960
-        //if there is a _wp_http_referer include the values from the request but only if sticky = true
961
-        if ($sticky) {
962
-            $request = $_REQUEST;
963
-            unset($request['_wp_http_referer']);
964
-            unset($request['wp_referer']);
965
-            foreach ($request as $key => $value) {
966
-                //do not add nonces
967
-                if (strpos($key, 'nonce') !== false) {
968
-                    continue;
969
-                }
970
-                $args['wp_referer[' . $key . ']'] = $value;
971
-            }
972
-        }
973
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
974
-    }
975
-
976
-
977
-
978
-    /**
979
-     * This returns a generated link that will load the related help tab.
980
-     *
981
-     * @param  string $help_tab_id the id for the connected help tab
982
-     * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
983
-     * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
984
-     * @uses EEH_Template::get_help_tab_link()
985
-     * @return string              generated link
986
-     */
987
-    protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false)
988
-    {
989
-        return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text);
990
-    }
991
-
992
-
993
-
994
-    /**
995
-     * _add_help_tabs
996
-     * Note child classes define their help tabs within the page_config array.
997
-     *
998
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
999
-     * @access protected
1000
-     * @return void
1001
-     */
1002
-    protected function _add_help_tabs()
1003
-    {
1004
-        $tour_buttons = '';
1005
-        if (isset($this->_page_config[$this->_req_action])) {
1006
-            $config = $this->_page_config[$this->_req_action];
1007
-            //is there a help tour for the current route?  if there is let's setup the tour buttons
1008
-            if (isset($this->_help_tour[$this->_req_action])) {
1009
-                $tb = array();
1010
-                $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1011
-                foreach ($this->_help_tour['tours'] as $tour) {
1012
-                    //if this is the end tour then we don't need to setup a button
1013
-                    if ($tour instanceof EE_Help_Tour_final_stop) {
1014
-                        continue;
1015
-                    }
1016
-                    $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1017
-                }
1018
-                $tour_buttons .= implode('<br />', $tb);
1019
-                $tour_buttons .= '</div></div>';
1020
-            }
1021
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1022
-            if (is_array($config) && isset($config['help_sidebar'])) {
1023
-                //check that the callback given is valid
1024
-                if ( ! method_exists($this, $config['help_sidebar'])) {
1025
-                    throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1026
-                            'event_espresso'), $config['help_sidebar'], get_class($this)));
1027
-                }
1028
-                $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1029
-                $content .= $tour_buttons; //add help tour buttons.
1030
-                //do we have any help tours setup?  Cause if we do we want to add the buttons
1031
-                $this->_current_screen->set_help_sidebar($content);
1032
-            }
1033
-            //if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1034
-            if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1035
-                $this->_current_screen->set_help_sidebar($tour_buttons);
1036
-            }
1037
-            //handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1038
-            if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1039
-                $_ht['id'] = $this->page_slug;
1040
-                $_ht['title'] = __('Help Tours', 'event_espresso');
1041
-                $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1042
-                $this->_current_screen->add_help_tab($_ht);
1043
-            }/**/
1044
-            if ( ! isset($config['help_tabs'])) {
1045
-                return;
1046
-            } //no help tabs for this route
1047
-            foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1048
-                //we're here so there ARE help tabs!
1049
-                //make sure we've got what we need
1050
-                if ( ! isset($cfg['title'])) {
1051
-                    throw new EE_Error(__('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso'));
1052
-                }
1053
-                if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1054
-                    throw new EE_Error(__('The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1055
-                            'event_espresso'));
1056
-                }
1057
-                //first priority goes to content.
1058
-                if ( ! empty($cfg['content'])) {
1059
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1060
-                    //second priority goes to filename
1061
-                } else if ( ! empty($cfg['filename'])) {
1062
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1063
-                    //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1064
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1065
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1066
-                    if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1067
-                        EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1068
-                                'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__);
1069
-                        return;
1070
-                    }
1071
-                    $template_args['admin_page_obj'] = $this;
1072
-                    $content = EEH_Template::display_template($file_path, $template_args, true);
1073
-                } else {
1074
-                    $content = '';
1075
-                }
1076
-                //check if callback is valid
1077
-                if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) {
1078
-                    EE_Error::add_error(sprintf(__('The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1079
-                            'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__);
1080
-                    return;
1081
-                }
1082
-                //setup config array for help tab method
1083
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1084
-                $_ht = array(
1085
-                        'id'       => $id,
1086
-                        'title'    => $cfg['title'],
1087
-                        'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1088
-                        'content'  => $content,
1089
-                );
1090
-                $this->_current_screen->add_help_tab($_ht);
1091
-            }
1092
-        }
1093
-    }
1094
-
1095
-
1096
-
1097
-    /**
1098
-     * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is an array with properties for setting up usage of the joyride plugin
1099
-     *
1100
-     * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1101
-     * @see    instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1102
-     * @access protected
1103
-     * @return void
1104
-     */
1105
-    protected function _add_help_tour()
1106
-    {
1107
-        $tours = array();
1108
-        $this->_help_tour = array();
1109
-        //exit early if help tours are turned off globally
1110
-        if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) {
1111
-            return;
1112
-        }
1113
-        //loop through _page_config to find any help_tour defined
1114
-        foreach ($this->_page_config as $route => $config) {
1115
-            //we're only going to set things up for this route
1116
-            if ($route !== $this->_req_action) {
1117
-                continue;
1118
-            }
1119
-            if (isset($config['help_tour'])) {
1120
-                foreach ($config['help_tour'] as $tour) {
1121
-                    $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1122
-                    //let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent
1123
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1124
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1125
-                    if ( ! is_readable($file_path)) {
1126
-                        EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'),
1127
-                                $file_path, $tour), __FILE__, __FUNCTION__, __LINE__);
1128
-                        return;
1129
-                    }
1130
-                    require_once $file_path;
1131
-                    if ( ! class_exists($tour)) {
1132
-                        $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1133
-                        $error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1134
-                                        'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1135
-                        throw new EE_Error(implode('||', $error_msg));
1136
-                    }
1137
-                    $a = new ReflectionClass($tour);
1138
-                    $tour_obj = $a->newInstance($this->_is_caf);
1139
-                    $tours[] = $tour_obj;
1140
-                    $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1141
-                }
1142
-                //let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1143
-                $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1144
-                $tours[] = $end_stop_tour;
1145
-                $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1146
-            }
1147
-        }
1148
-        if ( ! empty($tours)) {
1149
-            $this->_help_tour['tours'] = $tours;
1150
-        }
1151
-        //thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1152
-    }
1153
-
1154
-
1155
-
1156
-    /**
1157
-     * This simply sets up any qtips that have been defined in the page config
1158
-     *
1159
-     * @access protected
1160
-     * @return void
1161
-     */
1162
-    protected function _add_qtips()
1163
-    {
1164
-        if (isset($this->_route_config['qtips'])) {
1165
-            $qtips = (array)$this->_route_config['qtips'];
1166
-            //load qtip loader
1167
-            $path = array(
1168
-                    $this->_get_dir() . '/qtips/',
1169
-                    EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1170
-            );
1171
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1172
-        }
1173
-    }
1174
-
1175
-
1176
-
1177
-    /**
1178
-     * _set_nav_tabs
1179
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly.
1180
-     *
1181
-     * @access protected
1182
-     * @return void
1183
-     */
1184
-    protected function _set_nav_tabs()
1185
-    {
1186
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1187
-        $i = 0;
1188
-        foreach ($this->_page_config as $slug => $config) {
1189
-            if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) {
1190
-                continue;
1191
-            } //no nav tab for this config
1192
-            //check for persistent flag
1193
-            if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) {
1194
-                continue;
1195
-            } //nav tab is only to appear when route requested.
1196
-            if ( ! $this->check_user_access($slug, true)) {
1197
-                continue;
1198
-            } //no nav tab becasue current user does not have access.
1199
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1200
-            $this->_nav_tabs[$slug] = array(
1201
-                    'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1202
-                    'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1203
-                    'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1204
-                    'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1205
-            );
1206
-            $i++;
1207
-        }
1208
-        //if $this->_nav_tabs is empty then lets set the default
1209
-        if (empty($this->_nav_tabs)) {
1210
-            $this->_nav_tabs[$this->default_nav_tab_name] = array(
1211
-                    'url'       => $this->admin_base_url,
1212
-                    'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)),
1213
-                    'css_class' => 'nav-tab-active',
1214
-                    'order'     => 10,
1215
-            );
1216
-        }
1217
-        //now let's sort the tabs according to order
1218
-        usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1219
-    }
1220
-
1221
-
1222
-
1223
-    /**
1224
-     * _set_current_labels
1225
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1226
-     *
1227
-     * @access private
1228
-     * @return void
1229
-     */
1230
-    private function _set_current_labels()
1231
-    {
1232
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1233
-            foreach ($this->_route_config['labels'] as $label => $text) {
1234
-                if (is_array($text)) {
1235
-                    foreach ($text as $sublabel => $subtext) {
1236
-                        $this->_labels[$label][$sublabel] = $subtext;
1237
-                    }
1238
-                } else {
1239
-                    $this->_labels[$label] = $text;
1240
-                }
1241
-            }
1242
-        }
1243
-    }
1244
-
1245
-
1246
-
1247
-    /**
1248
-     *        verifies user access for this admin page
1249
-     *
1250
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1251
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1252
-     * @return        BOOL|wp_die()
1253
-     */
1254
-    public function check_user_access($route_to_check = '', $verify_only = false)
1255
-    {
1256
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1257
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1258
-        $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability'])
1259
-                ? $this->_page_routes[$route_to_check]['capability'] : null;
1260
-        if (empty($capability) && empty($route_to_check)) {
1261
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability'];
1262
-        } else {
1263
-            $capability = empty($capability) ? 'manage_options' : $capability;
1264
-        }
1265
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1266
-        if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1267
-            if ($verify_only) {
1268
-                return false;
1269
-            } else {
1270
-                if ( is_user_logged_in() ) {
1271
-                    wp_die(__('You do not have access to this route.', 'event_espresso'));
1272
-                } else {
1273
-                    return false;
1274
-                }
1275
-            }
1276
-        }
1277
-        return true;
1278
-    }
1279
-
1280
-
1281
-
1282
-    /**
1283
-     * admin_init_global
1284
-     * This runs all the code that we want executed within the WP admin_init hook.
1285
-     * This method executes for ALL EE Admin pages.
1286
-     *
1287
-     * @access public
1288
-     * @return void
1289
-     */
1290
-    public function admin_init_global()
1291
-    {
1292
-    }
1293
-
1294
-
1295
-
1296
-    /**
1297
-     * wp_loaded_global
1298
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an EE_Admin page and will execute on every EE Admin Page load
1299
-     *
1300
-     * @access public
1301
-     * @return void
1302
-     */
1303
-    public function wp_loaded()
1304
-    {
1305
-    }
1306
-
1307
-
1308
-
1309
-    /**
1310
-     * admin_notices
1311
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1312
-     *
1313
-     * @access public
1314
-     * @return void
1315
-     */
1316
-    public function admin_notices_global()
1317
-    {
1318
-        $this->_display_no_javascript_warning();
1319
-        $this->_display_espresso_notices();
1320
-    }
1321
-
1322
-
1323
-
1324
-    public function network_admin_notices_global()
1325
-    {
1326
-        $this->_display_no_javascript_warning();
1327
-        $this->_display_espresso_notices();
1328
-    }
1329
-
1330
-
1331
-
1332
-    /**
1333
-     * admin_footer_scripts_global
1334
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages.
1335
-     *
1336
-     * @access public
1337
-     * @return void
1338
-     */
1339
-    public function admin_footer_scripts_global()
1340
-    {
1341
-        $this->_add_admin_page_ajax_loading_img();
1342
-        $this->_add_admin_page_overlay();
1343
-        //if metaboxes are present we need to add the nonce field
1344
-        if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) {
1345
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1346
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1347
-        }
1348
-    }
1349
-
1350
-
1351
-
1352
-    /**
1353
-     * admin_footer_global
1354
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1355
-     *
1356
-     * @access  public
1357
-     * @return  void
1358
-     */
1359
-    public function admin_footer_global()
1360
-    {
1361
-        //dialog container for dialog helper
1362
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1363
-        $d_cont .= '<div class="ee-notices"></div>';
1364
-        $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1365
-        $d_cont .= '</div>';
1366
-        echo $d_cont;
1367
-        //help tour stuff?
1368
-        if (isset($this->_help_tour[$this->_req_action])) {
1369
-            echo implode('<br />', $this->_help_tour[$this->_req_action]);
1370
-        }
1371
-        //current set timezone for timezone js
1372
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1373
-    }
1374
-
1375
-
1376
-
1377
-    /**
1378
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then we'll use the retrieved array to output the content using the template.
1379
-     * For child classes:
1380
-     * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for
1381
-     * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content for the
1382
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1383
-     *    'help_trigger_id' => array(
1384
-     *        'title' => __('localized title for popup', 'event_espresso'),
1385
-     *        'content' => __('localized content for popup', 'event_espresso')
1386
-     *    )
1387
-     * );
1388
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1389
-     *
1390
-     * @access protected
1391
-     * @return string content
1392
-     */
1393
-    protected function _set_help_popup_content($help_array = array(), $display = false)
1394
-    {
1395
-        $content = '';
1396
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1397
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1398
-        //loop through the array and setup content
1399
-        foreach ($help_array as $trigger => $help) {
1400
-            //make sure the array is setup properly
1401
-            if ( ! isset($help['title']) || ! isset($help['content'])) {
1402
-                throw new EE_Error(__('Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1403
-                        'event_espresso'));
1404
-            }
1405
-            //we're good so let'd setup the template vars and then assign parsed template content to our content.
1406
-            $template_args = array(
1407
-                    'help_popup_id'      => $trigger,
1408
-                    'help_popup_title'   => $help['title'],
1409
-                    'help_popup_content' => $help['content'],
1410
-            );
1411
-            $content .= EEH_Template::display_template($template_path, $template_args, true);
1412
-        }
1413
-        if ($display) {
1414
-            echo $content;
1415
-        } else {
1416
-            return $content;
1417
-        }
1418
-    }
1419
-
1420
-
1421
-
1422
-    /**
1423
-     * All this does is retrive the help content array if set by the EE_Admin_Page child
1424
-     *
1425
-     * @access private
1426
-     * @return array properly formatted array for help popup content
1427
-     */
1428
-    private function _get_help_content()
1429
-    {
1430
-        //what is the method we're looking for?
1431
-        $method_name = '_help_popup_content_' . $this->_req_action;
1432
-        //if method doesn't exist let's get out.
1433
-        if ( ! method_exists($this, $method_name)) {
1434
-            return array();
1435
-        }
1436
-        //k we're good to go let's retrieve the help array
1437
-        $help_array = call_user_func(array($this, $method_name));
1438
-        //make sure we've got an array!
1439
-        if ( ! is_array($help_array)) {
1440
-            throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso'));
1441
-        }
1442
-        return $help_array;
1443
-    }
1444
-
1445
-
1446
-
1447
-    /**
1448
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1449
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1450
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1451
-     *
1452
-     * @access protected
1453
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1454
-     * @param boolean $display    if false then we return the trigger string
1455
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1456
-     * @return string
1457
-     */
1458
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1459
-    {
1460
-        if (defined('DOING_AJAX')) {
1461
-            return;
1462
-        }
1463
-        //let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1464
-        $help_array = $this->_get_help_content();
1465
-        $help_content = '';
1466
-        if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1467
-            $help_array[$trigger_id] = array(
1468
-                    'title'   => __('Missing Content', 'event_espresso'),
1469
-                    'content' => __('A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1470
-                            'event_espresso'),
1471
-            );
1472
-            $help_content = $this->_set_help_popup_content($help_array, false);
1473
-        }
1474
-        //let's setup the trigger
1475
-        $content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1476
-        $content = $content . $help_content;
1477
-        if ($display) {
1478
-            echo $content;
1479
-        } else {
1480
-            return $content;
1481
-        }
1482
-    }
1483
-
1484
-
1485
-
1486
-    /**
1487
-     * _add_global_screen_options
1488
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1489
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1490
-     *
1491
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1492
-     *         see also WP_Screen object documents...
1493
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1494
-     * @abstract
1495
-     * @access private
1496
-     * @return void
1497
-     */
1498
-    private function _add_global_screen_options()
1499
-    {
1500
-    }
1501
-
1502
-
1503
-
1504
-    /**
1505
-     * _add_global_feature_pointers
1506
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1507
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1508
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1509
-     *
1510
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1511
-     * @link   http://eamann.com/tech/wordpress-portland/
1512
-     * @abstract
1513
-     * @access protected
1514
-     * @return void
1515
-     */
1516
-    private function _add_global_feature_pointers()
1517
-    {
1518
-    }
1519
-
1520
-
1521
-
1522
-    /**
1523
-     * load_global_scripts_styles
1524
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1525
-     *
1526
-     * @return void
1527
-     */
1528
-    public function load_global_scripts_styles()
1529
-    {
1530
-        /** STYLES **/
1531
-        // add debugging styles
1532
-        if (WP_DEBUG) {
1533
-            add_action('admin_head', array($this, 'add_xdebug_style'));
1534
-        }
1535
-        // register all styles
1536
-        wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1537
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1538
-        //helpers styles
1539
-        wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1540
-        /** SCRIPTS **/
1541
-        //register all scripts
1542
-        wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1543
-        wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1544
-        wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1545
-        add_filter('FHEE_load_joyride', '__return_true');
1546
-        //script for sorting tables
1547
-        wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1548
-        //script for parsing uri's
1549
-        wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1550
-        //and parsing associative serialized form elements
1551
-        wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1552
-        //helpers scripts
1553
-        wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1554
-        wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1555
-        wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1556
-        wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1557
-        //google charts
1558
-        wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1559
-        // ENQUEUE ALL BASICS BY DEFAULT
1560
-        wp_enqueue_style('ee-admin-css');
1561
-        wp_enqueue_script('ee_admin_js');
1562
-        wp_enqueue_script('ee-accounting');
1563
-        wp_enqueue_script('jquery-validate');
1564
-        //taking care of metaboxes
1565
-        if (
1566
-            empty($this->_cpt_route)
1567
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1568
-        ) {
1569
-            wp_enqueue_script('dashboard');
1570
-        }
1571
-        // LOCALIZED DATA
1572
-        //localize script for ajax lazy loading
1573
-        $lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content'));
1574
-        wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1575
-        /**
1576
-         * help tour stuff
1577
-         */
1578
-        if ( ! empty($this->_help_tour)) {
1579
-            //register the js for kicking things off
1580
-            wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1581
-            //setup tours for the js tour object
1582
-            foreach ($this->_help_tour['tours'] as $tour) {
1583
-                $tours[] = array(
1584
-                        'id'      => $tour->get_slug(),
1585
-                        'options' => $tour->get_options(),
1586
-                );
1587
-            }
1588
-            wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1589
-            //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1590
-        }
1591
-    }
1592
-
1593
-
1594
-
1595
-    /**
1596
-     *        admin_footer_scripts_eei18n_js_strings
1597
-     *
1598
-     * @access        public
1599
-     * @return        void
1600
-     */
1601
-    public function admin_footer_scripts_eei18n_js_strings()
1602
-    {
1603
-        EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1604
-        EE_Registry::$i18n_js_strings['confirm_delete'] = __('Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', 'event_espresso');
1605
-        EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso');
1606
-        EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso');
1607
-        EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso');
1608
-        EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso');
1609
-        EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1610
-        EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso');
1611
-        EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso');
1612
-        EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso');
1613
-        EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso');
1614
-        EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso');
1615
-        EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso');
1616
-        EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso');
1617
-        EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso');
1618
-        EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso');
1619
-        EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso');
1620
-        EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso');
1621
-        EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1622
-        EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso');
1623
-        EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso');
1624
-        EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso');
1625
-        EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso');
1626
-        EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso');
1627
-        EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso');
1628
-        EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso');
1629
-        EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso');
1630
-        EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso');
1631
-        EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso');
1632
-        EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso');
1633
-        EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso');
1634
-        EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso');
1635
-        EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso');
1636
-        EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso');
1637
-        EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso');
1638
-        EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso');
1639
-        EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso');
1640
-        EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso');
1641
-        EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso');
1642
-        EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso');
1643
-    }
1644
-
1645
-
1646
-
1647
-    /**
1648
-     *        load enhanced xdebug styles for ppl with failing eyesight
1649
-     *
1650
-     * @access        public
1651
-     * @return        void
1652
-     */
1653
-    public function add_xdebug_style()
1654
-    {
1655
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1656
-    }
1657
-
1658
-
1659
-    /************************/
1660
-    /** LIST TABLE METHODS **/
1661
-    /************************/
1662
-    /**
1663
-     * this sets up the list table if the current view requires it.
1664
-     *
1665
-     * @access protected
1666
-     * @return void
1667
-     */
1668
-    protected function _set_list_table()
1669
-    {
1670
-        //first is this a list_table view?
1671
-        if ( ! isset($this->_route_config['list_table'])) {
1672
-            return;
1673
-        } //not a list_table view so get out.
1674
-        //list table functions are per view specific (because some admin pages might have more than one listtable!)
1675
-        if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1676
-            //user error msg
1677
-            $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1678
-            //developer error msg
1679
-            $error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'),
1680
-                            $this->_req_action, '_set_list_table_views_' . $this->_req_action);
1681
-            throw new EE_Error($error_msg);
1682
-        }
1683
-        //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1684
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1685
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1686
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1687
-        $this->_set_list_table_view();
1688
-        $this->_set_list_table_object();
1689
-    }
1690
-
1691
-
1692
-
1693
-    /**
1694
-     *        set current view for List Table
1695
-     *
1696
-     * @access public
1697
-     * @return array
1698
-     */
1699
-    protected function _set_list_table_view()
1700
-    {
1701
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1702
-        // looking at active items or dumpster diving ?
1703
-        if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
1704
-            $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1705
-        } else {
1706
-            $this->_view = sanitize_key($this->_req_data['status']);
1707
-        }
1708
-    }
1709
-
1710
-
1711
-
1712
-    /**
1713
-     * _set_list_table_object
1714
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1715
-     *
1716
-     * @throws \EE_Error
1717
-     */
1718
-    protected function _set_list_table_object()
1719
-    {
1720
-        if (isset($this->_route_config['list_table'])) {
1721
-            if ( ! class_exists($this->_route_config['list_table'])) {
1722
-                throw new EE_Error(
1723
-                        sprintf(
1724
-                                __(
1725
-                                        'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
1726
-                                        'event_espresso'
1727
-                                ),
1728
-                                $this->_route_config['list_table'],
1729
-                                get_class($this)
1730
-                        )
1731
-                );
1732
-            }
1733
-            $list_table = $this->_route_config['list_table'];
1734
-            $this->_list_table_object = new $list_table($this);
1735
-        }
1736
-    }
1737
-
1738
-
1739
-
1740
-    /**
1741
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
1742
-     *
1743
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
1744
-     *                                                    urls.  The array should be indexed by the view it is being
1745
-     *                                                    added to.
1746
-     * @return array
1747
-     */
1748
-    public function get_list_table_view_RLs($extra_query_args = array())
1749
-    {
1750
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1751
-        if (empty($this->_views)) {
1752
-            $this->_views = array();
1753
-        }
1754
-        // cycle thru views
1755
-        foreach ($this->_views as $key => $view) {
1756
-            $query_args = array();
1757
-            // check for current view
1758
-            $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1759
-            $query_args['action'] = $this->_req_action;
1760
-            $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1761
-            $query_args['status'] = $view['slug'];
1762
-            //merge any other arguments sent in.
1763
-            if (isset($extra_query_args[$view['slug']])) {
1764
-                $query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
1765
-            }
1766
-            $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1767
-        }
1768
-        return $this->_views;
1769
-    }
1770
-
1771
-
1772
-
1773
-    /**
1774
-     * _entries_per_page_dropdown
1775
-     * generates a drop down box for selecting the number of visiable rows in an admin page list table
1776
-     *
1777
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it.
1778
-     * @access protected
1779
-     * @param int $max_entries total number of rows in the table
1780
-     * @return string
1781
-     */
1782
-    protected function _entries_per_page_dropdown($max_entries = false)
1783
-    {
1784
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1785
-        $values = array(10, 25, 50, 100);
1786
-        $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
1787
-        if ($max_entries) {
1788
-            $values[] = $max_entries;
1789
-            sort($values);
1790
-        }
1791
-        $entries_per_page_dropdown = '
143
+	// yes / no array for admin form fields
144
+	protected $_yes_no_values = array();
145
+
146
+	//some default things shared by all child classes
147
+	protected $_default_espresso_metaboxes;
148
+
149
+	/**
150
+	 *    EE_Registry Object
151
+	 *
152
+	 * @var    EE_Registry
153
+	 * @access    protected
154
+	 */
155
+	protected $EE = null;
156
+
157
+
158
+
159
+	/**
160
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
161
+	 *
162
+	 * @var boolean
163
+	 */
164
+	protected $_is_caf = false;
165
+
166
+
167
+
168
+	/**
169
+	 * @Constructor
170
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
171
+	 * @access public
172
+	 */
173
+	public function __construct($routing = true)
174
+	{
175
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
176
+			$this->_is_caf = true;
177
+		}
178
+		$this->_yes_no_values = array(
179
+				array('id' => true, 'text' => __('Yes', 'event_espresso')),
180
+				array('id' => false, 'text' => __('No', 'event_espresso')),
181
+		);
182
+		//set the _req_data property.
183
+		$this->_req_data = array_merge($_GET, $_POST);
184
+		//routing enabled?
185
+		$this->_routing = $routing;
186
+		//set initial page props (child method)
187
+		$this->_init_page_props();
188
+		//set global defaults
189
+		$this->_set_defaults();
190
+		//set early because incoming requests could be ajax related and we need to register those hooks.
191
+		$this->_global_ajax_hooks();
192
+		$this->_ajax_hooks();
193
+		//other_page_hooks have to be early too.
194
+		$this->_do_other_page_hooks();
195
+		//This just allows us to have extending classes do something specific
196
+		// before the parent constructor runs _page_setup().
197
+		if (method_exists($this, '_before_page_setup')) {
198
+			$this->_before_page_setup();
199
+		}
200
+		//set up page dependencies
201
+		$this->_page_setup();
202
+	}
203
+
204
+
205
+
206
+	/**
207
+	 * _init_page_props
208
+	 * Child classes use to set at least the following properties:
209
+	 * $page_slug.
210
+	 * $page_label.
211
+	 *
212
+	 * @abstract
213
+	 * @access protected
214
+	 * @return void
215
+	 */
216
+	abstract protected function _init_page_props();
217
+
218
+
219
+
220
+	/**
221
+	 * _ajax_hooks
222
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
223
+	 * Note: within the ajax callback methods.
224
+	 *
225
+	 * @abstract
226
+	 * @access protected
227
+	 * @return void
228
+	 */
229
+	abstract protected function _ajax_hooks();
230
+
231
+
232
+
233
+	/**
234
+	 * _define_page_props
235
+	 * child classes define page properties in here.  Must include at least:
236
+	 * $_admin_base_url = base_url for all admin pages
237
+	 * $_admin_page_title = default admin_page_title for admin pages
238
+	 * $_labels = array of default labels for various automatically generated elements:
239
+	 *    array(
240
+	 *        'buttons' => array(
241
+	 *            'add' => __('label for add new button'),
242
+	 *            'edit' => __('label for edit button'),
243
+	 *            'delete' => __('label for delete button')
244
+	 *            )
245
+	 *        )
246
+	 *
247
+	 * @abstract
248
+	 * @access protected
249
+	 * @return void
250
+	 */
251
+	abstract protected function _define_page_props();
252
+
253
+
254
+
255
+	/**
256
+	 * _set_page_routes
257
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also have a 'default'
258
+	 * route. Here's the format
259
+	 * $this->_page_routes = array(
260
+	 *        'default' => array(
261
+	 *            'func' => '_default_method_handling_route',
262
+	 *            'args' => array('array','of','args'),
263
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
264
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after.  The string you enter here should match the defined route reference for a headers sent route.
265
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
266
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
267
+	 *        ),
268
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
269
+	 *        )
270
+	 * )
271
+	 *
272
+	 * @abstract
273
+	 * @access protected
274
+	 * @return void
275
+	 */
276
+	abstract protected function _set_page_routes();
277
+
278
+
279
+
280
+	/**
281
+	 * _set_page_config
282
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page.
283
+	 * Format:
284
+	 * $this->_page_config = array(
285
+	 *        'default' => array(
286
+	 *            'labels' => array(
287
+	 *                'buttons' => array(
288
+	 *                    'add' => __('label for adding item'),
289
+	 *                    'edit' => __('label for editing item'),
290
+	 *                    'delete' => __('label for deleting item')
291
+	 *                ),
292
+	 *                'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
293
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method
294
+	 *            'nav' => array(
295
+	 *                'label' => __('Label for Tab', 'event_espresso').
296
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
297
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
298
+	 *                'order' => 10, //required to indicate tab position.
299
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
300
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
301
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
302
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added later.  We just use
303
+	 *            this flag to make sure the necessary js gets enqueued on page load.
304
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
305
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The array indicates the max number of columns (4) and the default number of columns on page load (2).  There is an option
306
+	 *            in the "screen_options" dropdown that is setup so users can pick what columns they want to display.
307
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
308
+	 *                'tab_id' => array(
309
+	 *                    'title' => 'tab_title',
310
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content.  The fallback if it isn't present is to try a the callback.  Filename should match a file in the admin
311
+	 *                    folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php)
312
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class
313
+	 *                    ),
314
+	 *                'tab2_id' => array(
315
+	 *                    'title' => 'tab2 title',
316
+	 *                    'filename' => 'file_name_2'
317
+	 *                    'callback' => 'callback_method_for_content',
318
+	 *                 ),
319
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
320
+	 *            'help_tour' => array(
321
+	 *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here
322
+	 *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
323
+	 *            ),
324
+	 *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present).  To remove the requirement for a nonce check when this route is visited just set
325
+	 *            'require_nonce' to FALSE
326
+	 *            )
327
+	 * )
328
+	 *
329
+	 * @abstract
330
+	 * @access protected
331
+	 * @return void
332
+	 */
333
+	abstract protected function _set_page_config();
334
+
335
+
336
+
337
+
338
+
339
+	/** end sample help_tour methods **/
340
+	/**
341
+	 * _add_screen_options
342
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
343
+	 * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
344
+	 *
345
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
346
+	 *         see also WP_Screen object documents...
347
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
348
+	 * @abstract
349
+	 * @access protected
350
+	 * @return void
351
+	 */
352
+	abstract protected function _add_screen_options();
353
+
354
+
355
+
356
+	/**
357
+	 * _add_feature_pointers
358
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
359
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
360
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
361
+	 * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
362
+	 *
363
+	 * @link   http://eamann.com/tech/wordpress-portland/
364
+	 * @abstract
365
+	 * @access protected
366
+	 * @return void
367
+	 */
368
+	abstract protected function _add_feature_pointers();
369
+
370
+
371
+
372
+	/**
373
+	 * load_scripts_styles
374
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific scripts/styles
375
+	 * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
376
+	 *
377
+	 * @abstract
378
+	 * @access public
379
+	 * @return void
380
+	 */
381
+	abstract public function load_scripts_styles();
382
+
383
+
384
+
385
+	/**
386
+	 * admin_init
387
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to all pages/views loaded by child class.
388
+	 *
389
+	 * @abstract
390
+	 * @access public
391
+	 * @return void
392
+	 */
393
+	abstract public function admin_init();
394
+
395
+
396
+
397
+	/**
398
+	 * admin_notices
399
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to all pages/views loaded by child class.
400
+	 *
401
+	 * @abstract
402
+	 * @access public
403
+	 * @return void
404
+	 */
405
+	abstract public function admin_notices();
406
+
407
+
408
+
409
+	/**
410
+	 * admin_footer_scripts
411
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class.
412
+	 *
413
+	 * @access public
414
+	 * @return void
415
+	 */
416
+	abstract public function admin_footer_scripts();
417
+
418
+
419
+
420
+	/**
421
+	 * admin_footer
422
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class.
423
+	 *
424
+	 * @access  public
425
+	 * @return void
426
+	 */
427
+	public function admin_footer()
428
+	{
429
+	}
430
+
431
+
432
+
433
+	/**
434
+	 * _global_ajax_hooks
435
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
436
+	 * Note: within the ajax callback methods.
437
+	 *
438
+	 * @abstract
439
+	 * @access protected
440
+	 * @return void
441
+	 */
442
+	protected function _global_ajax_hooks()
443
+	{
444
+		//for lazy loading of metabox content
445
+		add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
446
+	}
447
+
448
+
449
+
450
+	public function ajax_metabox_content()
451
+	{
452
+		$contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
453
+		$url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
454
+		self::cached_rss_display($contentid, $url);
455
+		wp_die();
456
+	}
457
+
458
+
459
+
460
+	/**
461
+	 * _page_setup
462
+	 * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested doesn't match the object.
463
+	 *
464
+	 * @final
465
+	 * @access protected
466
+	 * @return void
467
+	 */
468
+	final protected function _page_setup()
469
+	{
470
+		//requires?
471
+		//admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
472
+		add_action('admin_init', array($this, 'admin_init_global'), 5);
473
+		//next verify if we need to load anything...
474
+		$this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
475
+		$this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
476
+		global $ee_menu_slugs;
477
+		$ee_menu_slugs = (array)$ee_menu_slugs;
478
+		if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
479
+			return;
480
+		}
481
+		// becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
482
+		if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) {
483
+			$this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
484
+		}
485
+		// then set blank or -1 action values to 'default'
486
+		$this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default';
487
+		//if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.  This covers cases where we're coming in from a list table that isn't on the default route.
488
+		$this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
489
+		//however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
490
+		$this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
491
+		$this->_current_view = $this->_req_action;
492
+		$this->_req_nonce = $this->_req_action . '_nonce';
493
+		$this->_define_page_props();
494
+		$this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
495
+		//default things
496
+		$this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box');
497
+		//set page configs
498
+		$this->_set_page_routes();
499
+		$this->_set_page_config();
500
+		//let's include any referrer data in our default_query_args for this route for "stickiness".
501
+		if (isset($this->_req_data['wp_referer'])) {
502
+			$this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
503
+		}
504
+		//for caffeinated and other extended functionality.  If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays
505
+		if (method_exists($this, '_extend_page_config')) {
506
+			$this->_extend_page_config();
507
+		}
508
+		//for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays.
509
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
510
+			$this->_extend_page_config_for_cpt();
511
+		}
512
+		//filter routes and page_config so addons can add their stuff. Filtering done per class
513
+		$this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
514
+		$this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
515
+		//if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
516
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
517
+			add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
518
+		}
519
+		//next route only if routing enabled
520
+		if ($this->_routing && ! defined('DOING_AJAX')) {
521
+			$this->_verify_routes();
522
+			//next let's just check user_access and kill if no access
523
+			$this->check_user_access();
524
+			if ($this->_is_UI_request) {
525
+				//admin_init stuff - global, all views for this page class, specific view
526
+				add_action('admin_init', array($this, 'admin_init'), 10);
527
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
528
+					add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
529
+				}
530
+			} else {
531
+				//hijack regular WP loading and route admin request immediately
532
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
533
+				$this->route_admin_request();
534
+			}
535
+		}
536
+	}
537
+
538
+
539
+
540
+	/**
541
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
542
+	 *
543
+	 * @access private
544
+	 * @return void
545
+	 */
546
+	private function _do_other_page_hooks()
547
+	{
548
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
549
+		foreach ($registered_pages as $page) {
550
+			//now let's setup the file name and class that should be present
551
+			$classname = str_replace('.class.php', '', $page);
552
+			//autoloaders should take care of loading file
553
+			if ( ! class_exists($classname)) {
554
+				$error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
555
+				$error_msg[] = $error_msg[0]
556
+							   . "\r\n"
557
+							   . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
558
+								'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
559
+				throw new EE_Error(implode('||', $error_msg));
560
+			}
561
+			$a = new ReflectionClass($classname);
562
+			//notice we are passing the instance of this class to the hook object.
563
+			$hookobj[] = $a->newInstance($this);
564
+		}
565
+	}
566
+
567
+
568
+
569
+	public function load_page_dependencies()
570
+	{
571
+		try {
572
+			$this->_load_page_dependencies();
573
+		} catch (EE_Error $e) {
574
+			$e->get_error();
575
+		}
576
+	}
577
+
578
+
579
+
580
+	/**
581
+	 * load_page_dependencies
582
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
583
+	 *
584
+	 * @access public
585
+	 * @return void
586
+	 */
587
+	protected function _load_page_dependencies()
588
+	{
589
+		//let's set the current_screen and screen options to override what WP set
590
+		$this->_current_screen = get_current_screen();
591
+		//load admin_notices - global, page class, and view specific
592
+		add_action('admin_notices', array($this, 'admin_notices_global'), 5);
593
+		add_action('admin_notices', array($this, 'admin_notices'), 10);
594
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
595
+			add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
596
+		}
597
+		//load network admin_notices - global, page class, and view specific
598
+		add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
599
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
600
+			add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
601
+		}
602
+		//this will save any per_page screen options if they are present
603
+		$this->_set_per_page_screen_options();
604
+		//setup list table properties
605
+		$this->_set_list_table();
606
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.  However in some cases the metaboxes will need to be added within a route handling callback.
607
+		$this->_add_registered_meta_boxes();
608
+		$this->_add_screen_columns();
609
+		//add screen options - global, page child class, and view specific
610
+		$this->_add_global_screen_options();
611
+		$this->_add_screen_options();
612
+		if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
613
+			call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
614
+		}
615
+		//add help tab(s) and tours- set via page_config and qtips.
616
+		$this->_add_help_tour();
617
+		$this->_add_help_tabs();
618
+		$this->_add_qtips();
619
+		//add feature_pointers - global, page child class, and view specific
620
+		$this->_add_feature_pointers();
621
+		$this->_add_global_feature_pointers();
622
+		if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
623
+			call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
624
+		}
625
+		//enqueue scripts/styles - global, page class, and view specific
626
+		add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
627
+		add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
628
+		if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
629
+			add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
630
+		}
631
+		add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
632
+		//admin_print_footer_scripts - global, page child class, and view specific.  NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.  In most cases that's doing_it_wrong().  But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these
633
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
634
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
635
+		if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
636
+			add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
637
+		}
638
+		//admin footer scripts
639
+		add_action('admin_footer', array($this, 'admin_footer_global'), 99);
640
+		add_action('admin_footer', array($this, 'admin_footer'), 100);
641
+		if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
642
+			add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
643
+		}
644
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
645
+		//targeted hook
646
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
647
+	}
648
+
649
+
650
+
651
+	/**
652
+	 * _set_defaults
653
+	 * This sets some global defaults for class properties.
654
+	 */
655
+	private function _set_defaults()
656
+	{
657
+		$this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null;
658
+		$this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array();
659
+		$this->default_nav_tab_name = 'overview';
660
+		//init template args
661
+		$this->_template_args = array(
662
+				'admin_page_header'  => '',
663
+				'admin_page_content' => '',
664
+				'post_body_content'  => '',
665
+				'before_list_table'  => '',
666
+				'after_list_table'   => '',
667
+		);
668
+	}
669
+
670
+
671
+
672
+	/**
673
+	 * route_admin_request
674
+	 *
675
+	 * @see    _route_admin_request()
676
+	 * @access public
677
+	 * @return void|exception error
678
+	 */
679
+	public function route_admin_request()
680
+	{
681
+		try {
682
+			$this->_route_admin_request();
683
+		} catch (EE_Error $e) {
684
+			$e->get_error();
685
+		}
686
+	}
687
+
688
+
689
+
690
+	public function set_wp_page_slug($wp_page_slug)
691
+	{
692
+		$this->_wp_page_slug = $wp_page_slug;
693
+		//if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
694
+		if (is_network_admin()) {
695
+			$this->_wp_page_slug .= '-network';
696
+		}
697
+	}
698
+
699
+
700
+
701
+	/**
702
+	 * _verify_routes
703
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so we know if we need to drop out.
704
+	 *
705
+	 * @access protected
706
+	 * @return void
707
+	 */
708
+	protected function _verify_routes()
709
+	{
710
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
711
+		if ( ! $this->_current_page && ! defined('DOING_AJAX')) {
712
+			return false;
713
+		}
714
+		$this->_route = false;
715
+		$func = false;
716
+		$args = array();
717
+		// check that the page_routes array is not empty
718
+		if (empty($this->_page_routes)) {
719
+			// user error msg
720
+			$error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
721
+			// developer error msg
722
+			$error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
723
+			throw new EE_Error($error_msg);
724
+		}
725
+		// and that the requested page route exists
726
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
727
+			$this->_route = $this->_page_routes[$this->_req_action];
728
+			$this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
729
+		} else {
730
+			// user error msg
731
+			$error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
732
+			// developer error msg
733
+			$error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
734
+			throw new EE_Error($error_msg);
735
+		}
736
+		// and that a default route exists
737
+		if ( ! array_key_exists('default', $this->_page_routes)) {
738
+			// user error msg
739
+			$error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
740
+			// developer error msg
741
+			$error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
742
+			throw new EE_Error($error_msg);
743
+		}
744
+		//first lets' catch if the UI request has EVER been set.
745
+		if ($this->_is_UI_request === null) {
746
+			//lets set if this is a UI request or not.
747
+			$this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false;
748
+			//wait a minute... we might have a noheader in the route array
749
+			$this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request;
750
+		}
751
+		$this->_set_current_labels();
752
+	}
753
+
754
+
755
+
756
+	/**
757
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
758
+	 *
759
+	 * @param  string $route the route name we're verifying
760
+	 * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
761
+	 */
762
+	protected function _verify_route($route)
763
+	{
764
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
765
+			return true;
766
+		} else {
767
+			// user error msg
768
+			$error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
769
+			// developer error msg
770
+			$error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
771
+			throw new EE_Error($error_msg);
772
+		}
773
+	}
774
+
775
+
776
+
777
+	/**
778
+	 * perform nonce verification
779
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!)
780
+	 *
781
+	 * @param  string $nonce     The nonce sent
782
+	 * @param  string $nonce_ref The nonce reference string (name0)
783
+	 * @return mixed (bool|die)
784
+	 */
785
+	protected function _verify_nonce($nonce, $nonce_ref)
786
+	{
787
+		// verify nonce against expected value
788
+		if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
789
+			// these are not the droids you are looking for !!!
790
+			$msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
791
+			if (WP_DEBUG) {
792
+				$msg .= "\n  " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
793
+			}
794
+			if ( ! defined('DOING_AJAX')) {
795
+				wp_die($msg);
796
+			} else {
797
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
798
+				$this->_return_json();
799
+			}
800
+		}
801
+	}
802
+
803
+
804
+
805
+	/**
806
+	 * _route_admin_request()
807
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
808
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
809
+	 * in the page routes and then will try to load the corresponding method.
810
+	 *
811
+	 * @access protected
812
+	 * @return void
813
+	 * @throws \EE_Error
814
+	 */
815
+	protected function _route_admin_request()
816
+	{
817
+		if ( ! $this->_is_UI_request) {
818
+			$this->_verify_routes();
819
+		}
820
+		$nonce_check = isset($this->_route_config['require_nonce'])
821
+			? $this->_route_config['require_nonce']
822
+			: true;
823
+		if ($this->_req_action !== 'default' && $nonce_check) {
824
+			// set nonce from post data
825
+			$nonce = isset($this->_req_data[$this->_req_nonce])
826
+				? sanitize_text_field($this->_req_data[$this->_req_nonce])
827
+				: '';
828
+			$this->_verify_nonce($nonce, $this->_req_nonce);
829
+		}
830
+		//set the nav_tabs array but ONLY if this is  UI_request
831
+		if ($this->_is_UI_request) {
832
+			$this->_set_nav_tabs();
833
+		}
834
+		// grab callback function
835
+		$func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
836
+		// check if callback has args
837
+		$args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
838
+		$error_msg = '';
839
+		// action right before calling route
840
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
841
+		if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
842
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
843
+		}
844
+		// right before calling the route, let's remove _wp_http_referer from the
845
+		// $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
846
+		$_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI']));
847
+		if ( ! empty($func)) {
848
+			if (is_array($func)) {
849
+				list($class, $method) = $func;
850
+			} else if (strpos($func, '::') !== false) {
851
+				list($class, $method) = explode('::', $func);
852
+			} else {
853
+				$class = $this;
854
+				$method = $func;
855
+			}
856
+			if ( ! (is_object($class) && $class === $this)) {
857
+				// send along this admin page object for access by addons.
858
+				$args['admin_page_object'] = $this;
859
+			}
860
+
861
+			if (
862
+				//is it a method on a class that doesn't work?
863
+				(
864
+					(
865
+						method_exists($class, $method)
866
+						&& call_user_func_array(array($class, $method), $args) === false
867
+					)
868
+					&& (
869
+						//is it a standalone function that doesn't work?
870
+						function_exists($method)
871
+						&& call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false
872
+					)
873
+				)
874
+				|| (
875
+					//is it neither a class method NOR a standalone function?
876
+					! method_exists($class, $method)
877
+					&& ! function_exists($method)
878
+				)
879
+			) {
880
+				// user error msg
881
+				$error_msg = __('An error occurred. The  requested page route could not be found.', 'event_espresso');
882
+				// developer error msg
883
+				$error_msg .= '||';
884
+				$error_msg .= sprintf(
885
+					__(
886
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
887
+						'event_espresso'
888
+					),
889
+					$method
890
+				);
891
+			}
892
+			if ( ! empty($error_msg)) {
893
+				throw new EE_Error($error_msg);
894
+			}
895
+		}
896
+		//if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route.
897
+		//now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
898
+		if ($this->_is_UI_request === false
899
+			&& is_array($this->_route)
900
+			&& ! empty($this->_route['headers_sent_route'])
901
+		) {
902
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
903
+		}
904
+	}
905
+
906
+
907
+
908
+	/**
909
+	 * This method just allows the resetting of page properties in the case where a no headers
910
+	 * route redirects to a headers route in its route config.
911
+	 *
912
+	 * @since   4.3.0
913
+	 * @param  string $new_route New (non header) route to redirect to.
914
+	 * @return   void
915
+	 */
916
+	protected function _reset_routing_properties($new_route)
917
+	{
918
+		$this->_is_UI_request = true;
919
+		//now we set the current route to whatever the headers_sent_route is set at
920
+		$this->_req_data['action'] = $new_route;
921
+		//rerun page setup
922
+		$this->_page_setup();
923
+	}
924
+
925
+
926
+
927
+	/**
928
+	 * _add_query_arg
929
+	 * adds nonce to array of arguments then calls WP add_query_arg function
930
+	 *(internally just uses EEH_URL's function with the same name)
931
+	 *
932
+	 * @access public
933
+	 * @param array  $args
934
+	 * @param string $url
935
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the generated
936
+	 *                                        url in an associative array indexed by the key 'wp_referer';
937
+	 *                                        Example usage:
938
+	 *                                        If the current page is:
939
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
940
+	 *                                        &action=default&event_id=20&month_range=March%202015
941
+	 *                                        &_wpnonce=5467821
942
+	 *                                        and you call:
943
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
944
+	 *                                        array(
945
+	 *                                        'action' => 'resend_something',
946
+	 *                                        'page=>espresso_registrations'
947
+	 *                                        ),
948
+	 *                                        $some_url,
949
+	 *                                        true
950
+	 *                                        );
951
+	 *                                        It will produce a url in this structure:
952
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
953
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
954
+	 *                                        month_range]=March%202015
955
+	 * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
956
+	 * @return string
957
+	 */
958
+	public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false)
959
+	{
960
+		//if there is a _wp_http_referer include the values from the request but only if sticky = true
961
+		if ($sticky) {
962
+			$request = $_REQUEST;
963
+			unset($request['_wp_http_referer']);
964
+			unset($request['wp_referer']);
965
+			foreach ($request as $key => $value) {
966
+				//do not add nonces
967
+				if (strpos($key, 'nonce') !== false) {
968
+					continue;
969
+				}
970
+				$args['wp_referer[' . $key . ']'] = $value;
971
+			}
972
+		}
973
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
974
+	}
975
+
976
+
977
+
978
+	/**
979
+	 * This returns a generated link that will load the related help tab.
980
+	 *
981
+	 * @param  string $help_tab_id the id for the connected help tab
982
+	 * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
983
+	 * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
984
+	 * @uses EEH_Template::get_help_tab_link()
985
+	 * @return string              generated link
986
+	 */
987
+	protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false)
988
+	{
989
+		return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text);
990
+	}
991
+
992
+
993
+
994
+	/**
995
+	 * _add_help_tabs
996
+	 * Note child classes define their help tabs within the page_config array.
997
+	 *
998
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
999
+	 * @access protected
1000
+	 * @return void
1001
+	 */
1002
+	protected function _add_help_tabs()
1003
+	{
1004
+		$tour_buttons = '';
1005
+		if (isset($this->_page_config[$this->_req_action])) {
1006
+			$config = $this->_page_config[$this->_req_action];
1007
+			//is there a help tour for the current route?  if there is let's setup the tour buttons
1008
+			if (isset($this->_help_tour[$this->_req_action])) {
1009
+				$tb = array();
1010
+				$tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1011
+				foreach ($this->_help_tour['tours'] as $tour) {
1012
+					//if this is the end tour then we don't need to setup a button
1013
+					if ($tour instanceof EE_Help_Tour_final_stop) {
1014
+						continue;
1015
+					}
1016
+					$tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1017
+				}
1018
+				$tour_buttons .= implode('<br />', $tb);
1019
+				$tour_buttons .= '</div></div>';
1020
+			}
1021
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1022
+			if (is_array($config) && isset($config['help_sidebar'])) {
1023
+				//check that the callback given is valid
1024
+				if ( ! method_exists($this, $config['help_sidebar'])) {
1025
+					throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1026
+							'event_espresso'), $config['help_sidebar'], get_class($this)));
1027
+				}
1028
+				$content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1029
+				$content .= $tour_buttons; //add help tour buttons.
1030
+				//do we have any help tours setup?  Cause if we do we want to add the buttons
1031
+				$this->_current_screen->set_help_sidebar($content);
1032
+			}
1033
+			//if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1034
+			if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1035
+				$this->_current_screen->set_help_sidebar($tour_buttons);
1036
+			}
1037
+			//handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1038
+			if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1039
+				$_ht['id'] = $this->page_slug;
1040
+				$_ht['title'] = __('Help Tours', 'event_espresso');
1041
+				$_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1042
+				$this->_current_screen->add_help_tab($_ht);
1043
+			}/**/
1044
+			if ( ! isset($config['help_tabs'])) {
1045
+				return;
1046
+			} //no help tabs for this route
1047
+			foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1048
+				//we're here so there ARE help tabs!
1049
+				//make sure we've got what we need
1050
+				if ( ! isset($cfg['title'])) {
1051
+					throw new EE_Error(__('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso'));
1052
+				}
1053
+				if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1054
+					throw new EE_Error(__('The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1055
+							'event_espresso'));
1056
+				}
1057
+				//first priority goes to content.
1058
+				if ( ! empty($cfg['content'])) {
1059
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1060
+					//second priority goes to filename
1061
+				} else if ( ! empty($cfg['filename'])) {
1062
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1063
+					//it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1064
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1065
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1066
+					if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1067
+						EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1068
+								'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__);
1069
+						return;
1070
+					}
1071
+					$template_args['admin_page_obj'] = $this;
1072
+					$content = EEH_Template::display_template($file_path, $template_args, true);
1073
+				} else {
1074
+					$content = '';
1075
+				}
1076
+				//check if callback is valid
1077
+				if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) {
1078
+					EE_Error::add_error(sprintf(__('The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1079
+							'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__);
1080
+					return;
1081
+				}
1082
+				//setup config array for help tab method
1083
+				$id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1084
+				$_ht = array(
1085
+						'id'       => $id,
1086
+						'title'    => $cfg['title'],
1087
+						'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1088
+						'content'  => $content,
1089
+				);
1090
+				$this->_current_screen->add_help_tab($_ht);
1091
+			}
1092
+		}
1093
+	}
1094
+
1095
+
1096
+
1097
+	/**
1098
+	 * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is an array with properties for setting up usage of the joyride plugin
1099
+	 *
1100
+	 * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1101
+	 * @see    instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1102
+	 * @access protected
1103
+	 * @return void
1104
+	 */
1105
+	protected function _add_help_tour()
1106
+	{
1107
+		$tours = array();
1108
+		$this->_help_tour = array();
1109
+		//exit early if help tours are turned off globally
1110
+		if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) {
1111
+			return;
1112
+		}
1113
+		//loop through _page_config to find any help_tour defined
1114
+		foreach ($this->_page_config as $route => $config) {
1115
+			//we're only going to set things up for this route
1116
+			if ($route !== $this->_req_action) {
1117
+				continue;
1118
+			}
1119
+			if (isset($config['help_tour'])) {
1120
+				foreach ($config['help_tour'] as $tour) {
1121
+					$file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1122
+					//let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent
1123
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1124
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1125
+					if ( ! is_readable($file_path)) {
1126
+						EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'),
1127
+								$file_path, $tour), __FILE__, __FUNCTION__, __LINE__);
1128
+						return;
1129
+					}
1130
+					require_once $file_path;
1131
+					if ( ! class_exists($tour)) {
1132
+						$error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1133
+						$error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1134
+										'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1135
+						throw new EE_Error(implode('||', $error_msg));
1136
+					}
1137
+					$a = new ReflectionClass($tour);
1138
+					$tour_obj = $a->newInstance($this->_is_caf);
1139
+					$tours[] = $tour_obj;
1140
+					$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1141
+				}
1142
+				//let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1143
+				$end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1144
+				$tours[] = $end_stop_tour;
1145
+				$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1146
+			}
1147
+		}
1148
+		if ( ! empty($tours)) {
1149
+			$this->_help_tour['tours'] = $tours;
1150
+		}
1151
+		//thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1152
+	}
1153
+
1154
+
1155
+
1156
+	/**
1157
+	 * This simply sets up any qtips that have been defined in the page config
1158
+	 *
1159
+	 * @access protected
1160
+	 * @return void
1161
+	 */
1162
+	protected function _add_qtips()
1163
+	{
1164
+		if (isset($this->_route_config['qtips'])) {
1165
+			$qtips = (array)$this->_route_config['qtips'];
1166
+			//load qtip loader
1167
+			$path = array(
1168
+					$this->_get_dir() . '/qtips/',
1169
+					EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1170
+			);
1171
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1172
+		}
1173
+	}
1174
+
1175
+
1176
+
1177
+	/**
1178
+	 * _set_nav_tabs
1179
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly.
1180
+	 *
1181
+	 * @access protected
1182
+	 * @return void
1183
+	 */
1184
+	protected function _set_nav_tabs()
1185
+	{
1186
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1187
+		$i = 0;
1188
+		foreach ($this->_page_config as $slug => $config) {
1189
+			if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) {
1190
+				continue;
1191
+			} //no nav tab for this config
1192
+			//check for persistent flag
1193
+			if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) {
1194
+				continue;
1195
+			} //nav tab is only to appear when route requested.
1196
+			if ( ! $this->check_user_access($slug, true)) {
1197
+				continue;
1198
+			} //no nav tab becasue current user does not have access.
1199
+			$css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1200
+			$this->_nav_tabs[$slug] = array(
1201
+					'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1202
+					'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1203
+					'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1204
+					'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1205
+			);
1206
+			$i++;
1207
+		}
1208
+		//if $this->_nav_tabs is empty then lets set the default
1209
+		if (empty($this->_nav_tabs)) {
1210
+			$this->_nav_tabs[$this->default_nav_tab_name] = array(
1211
+					'url'       => $this->admin_base_url,
1212
+					'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)),
1213
+					'css_class' => 'nav-tab-active',
1214
+					'order'     => 10,
1215
+			);
1216
+		}
1217
+		//now let's sort the tabs according to order
1218
+		usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1219
+	}
1220
+
1221
+
1222
+
1223
+	/**
1224
+	 * _set_current_labels
1225
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1226
+	 *
1227
+	 * @access private
1228
+	 * @return void
1229
+	 */
1230
+	private function _set_current_labels()
1231
+	{
1232
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1233
+			foreach ($this->_route_config['labels'] as $label => $text) {
1234
+				if (is_array($text)) {
1235
+					foreach ($text as $sublabel => $subtext) {
1236
+						$this->_labels[$label][$sublabel] = $subtext;
1237
+					}
1238
+				} else {
1239
+					$this->_labels[$label] = $text;
1240
+				}
1241
+			}
1242
+		}
1243
+	}
1244
+
1245
+
1246
+
1247
+	/**
1248
+	 *        verifies user access for this admin page
1249
+	 *
1250
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1251
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1252
+	 * @return        BOOL|wp_die()
1253
+	 */
1254
+	public function check_user_access($route_to_check = '', $verify_only = false)
1255
+	{
1256
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1257
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1258
+		$capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability'])
1259
+				? $this->_page_routes[$route_to_check]['capability'] : null;
1260
+		if (empty($capability) && empty($route_to_check)) {
1261
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability'];
1262
+		} else {
1263
+			$capability = empty($capability) ? 'manage_options' : $capability;
1264
+		}
1265
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1266
+		if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1267
+			if ($verify_only) {
1268
+				return false;
1269
+			} else {
1270
+				if ( is_user_logged_in() ) {
1271
+					wp_die(__('You do not have access to this route.', 'event_espresso'));
1272
+				} else {
1273
+					return false;
1274
+				}
1275
+			}
1276
+		}
1277
+		return true;
1278
+	}
1279
+
1280
+
1281
+
1282
+	/**
1283
+	 * admin_init_global
1284
+	 * This runs all the code that we want executed within the WP admin_init hook.
1285
+	 * This method executes for ALL EE Admin pages.
1286
+	 *
1287
+	 * @access public
1288
+	 * @return void
1289
+	 */
1290
+	public function admin_init_global()
1291
+	{
1292
+	}
1293
+
1294
+
1295
+
1296
+	/**
1297
+	 * wp_loaded_global
1298
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an EE_Admin page and will execute on every EE Admin Page load
1299
+	 *
1300
+	 * @access public
1301
+	 * @return void
1302
+	 */
1303
+	public function wp_loaded()
1304
+	{
1305
+	}
1306
+
1307
+
1308
+
1309
+	/**
1310
+	 * admin_notices
1311
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1312
+	 *
1313
+	 * @access public
1314
+	 * @return void
1315
+	 */
1316
+	public function admin_notices_global()
1317
+	{
1318
+		$this->_display_no_javascript_warning();
1319
+		$this->_display_espresso_notices();
1320
+	}
1321
+
1322
+
1323
+
1324
+	public function network_admin_notices_global()
1325
+	{
1326
+		$this->_display_no_javascript_warning();
1327
+		$this->_display_espresso_notices();
1328
+	}
1329
+
1330
+
1331
+
1332
+	/**
1333
+	 * admin_footer_scripts_global
1334
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages.
1335
+	 *
1336
+	 * @access public
1337
+	 * @return void
1338
+	 */
1339
+	public function admin_footer_scripts_global()
1340
+	{
1341
+		$this->_add_admin_page_ajax_loading_img();
1342
+		$this->_add_admin_page_overlay();
1343
+		//if metaboxes are present we need to add the nonce field
1344
+		if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) {
1345
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1346
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1347
+		}
1348
+	}
1349
+
1350
+
1351
+
1352
+	/**
1353
+	 * admin_footer_global
1354
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1355
+	 *
1356
+	 * @access  public
1357
+	 * @return  void
1358
+	 */
1359
+	public function admin_footer_global()
1360
+	{
1361
+		//dialog container for dialog helper
1362
+		$d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1363
+		$d_cont .= '<div class="ee-notices"></div>';
1364
+		$d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1365
+		$d_cont .= '</div>';
1366
+		echo $d_cont;
1367
+		//help tour stuff?
1368
+		if (isset($this->_help_tour[$this->_req_action])) {
1369
+			echo implode('<br />', $this->_help_tour[$this->_req_action]);
1370
+		}
1371
+		//current set timezone for timezone js
1372
+		echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1373
+	}
1374
+
1375
+
1376
+
1377
+	/**
1378
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then we'll use the retrieved array to output the content using the template.
1379
+	 * For child classes:
1380
+	 * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for
1381
+	 * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content for the
1382
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1383
+	 *    'help_trigger_id' => array(
1384
+	 *        'title' => __('localized title for popup', 'event_espresso'),
1385
+	 *        'content' => __('localized content for popup', 'event_espresso')
1386
+	 *    )
1387
+	 * );
1388
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1389
+	 *
1390
+	 * @access protected
1391
+	 * @return string content
1392
+	 */
1393
+	protected function _set_help_popup_content($help_array = array(), $display = false)
1394
+	{
1395
+		$content = '';
1396
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1397
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1398
+		//loop through the array and setup content
1399
+		foreach ($help_array as $trigger => $help) {
1400
+			//make sure the array is setup properly
1401
+			if ( ! isset($help['title']) || ! isset($help['content'])) {
1402
+				throw new EE_Error(__('Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1403
+						'event_espresso'));
1404
+			}
1405
+			//we're good so let'd setup the template vars and then assign parsed template content to our content.
1406
+			$template_args = array(
1407
+					'help_popup_id'      => $trigger,
1408
+					'help_popup_title'   => $help['title'],
1409
+					'help_popup_content' => $help['content'],
1410
+			);
1411
+			$content .= EEH_Template::display_template($template_path, $template_args, true);
1412
+		}
1413
+		if ($display) {
1414
+			echo $content;
1415
+		} else {
1416
+			return $content;
1417
+		}
1418
+	}
1419
+
1420
+
1421
+
1422
+	/**
1423
+	 * All this does is retrive the help content array if set by the EE_Admin_Page child
1424
+	 *
1425
+	 * @access private
1426
+	 * @return array properly formatted array for help popup content
1427
+	 */
1428
+	private function _get_help_content()
1429
+	{
1430
+		//what is the method we're looking for?
1431
+		$method_name = '_help_popup_content_' . $this->_req_action;
1432
+		//if method doesn't exist let's get out.
1433
+		if ( ! method_exists($this, $method_name)) {
1434
+			return array();
1435
+		}
1436
+		//k we're good to go let's retrieve the help array
1437
+		$help_array = call_user_func(array($this, $method_name));
1438
+		//make sure we've got an array!
1439
+		if ( ! is_array($help_array)) {
1440
+			throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso'));
1441
+		}
1442
+		return $help_array;
1443
+	}
1444
+
1445
+
1446
+
1447
+	/**
1448
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1449
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1450
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1451
+	 *
1452
+	 * @access protected
1453
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1454
+	 * @param boolean $display    if false then we return the trigger string
1455
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1456
+	 * @return string
1457
+	 */
1458
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1459
+	{
1460
+		if (defined('DOING_AJAX')) {
1461
+			return;
1462
+		}
1463
+		//let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1464
+		$help_array = $this->_get_help_content();
1465
+		$help_content = '';
1466
+		if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1467
+			$help_array[$trigger_id] = array(
1468
+					'title'   => __('Missing Content', 'event_espresso'),
1469
+					'content' => __('A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1470
+							'event_espresso'),
1471
+			);
1472
+			$help_content = $this->_set_help_popup_content($help_array, false);
1473
+		}
1474
+		//let's setup the trigger
1475
+		$content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1476
+		$content = $content . $help_content;
1477
+		if ($display) {
1478
+			echo $content;
1479
+		} else {
1480
+			return $content;
1481
+		}
1482
+	}
1483
+
1484
+
1485
+
1486
+	/**
1487
+	 * _add_global_screen_options
1488
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1489
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1490
+	 *
1491
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1492
+	 *         see also WP_Screen object documents...
1493
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1494
+	 * @abstract
1495
+	 * @access private
1496
+	 * @return void
1497
+	 */
1498
+	private function _add_global_screen_options()
1499
+	{
1500
+	}
1501
+
1502
+
1503
+
1504
+	/**
1505
+	 * _add_global_feature_pointers
1506
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1507
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1508
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1509
+	 *
1510
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1511
+	 * @link   http://eamann.com/tech/wordpress-portland/
1512
+	 * @abstract
1513
+	 * @access protected
1514
+	 * @return void
1515
+	 */
1516
+	private function _add_global_feature_pointers()
1517
+	{
1518
+	}
1519
+
1520
+
1521
+
1522
+	/**
1523
+	 * load_global_scripts_styles
1524
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1525
+	 *
1526
+	 * @return void
1527
+	 */
1528
+	public function load_global_scripts_styles()
1529
+	{
1530
+		/** STYLES **/
1531
+		// add debugging styles
1532
+		if (WP_DEBUG) {
1533
+			add_action('admin_head', array($this, 'add_xdebug_style'));
1534
+		}
1535
+		// register all styles
1536
+		wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1537
+		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1538
+		//helpers styles
1539
+		wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1540
+		/** SCRIPTS **/
1541
+		//register all scripts
1542
+		wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1543
+		wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1544
+		wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1545
+		add_filter('FHEE_load_joyride', '__return_true');
1546
+		//script for sorting tables
1547
+		wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1548
+		//script for parsing uri's
1549
+		wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1550
+		//and parsing associative serialized form elements
1551
+		wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1552
+		//helpers scripts
1553
+		wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1554
+		wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1555
+		wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1556
+		wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1557
+		//google charts
1558
+		wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1559
+		// ENQUEUE ALL BASICS BY DEFAULT
1560
+		wp_enqueue_style('ee-admin-css');
1561
+		wp_enqueue_script('ee_admin_js');
1562
+		wp_enqueue_script('ee-accounting');
1563
+		wp_enqueue_script('jquery-validate');
1564
+		//taking care of metaboxes
1565
+		if (
1566
+			empty($this->_cpt_route)
1567
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1568
+		) {
1569
+			wp_enqueue_script('dashboard');
1570
+		}
1571
+		// LOCALIZED DATA
1572
+		//localize script for ajax lazy loading
1573
+		$lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content'));
1574
+		wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1575
+		/**
1576
+		 * help tour stuff
1577
+		 */
1578
+		if ( ! empty($this->_help_tour)) {
1579
+			//register the js for kicking things off
1580
+			wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1581
+			//setup tours for the js tour object
1582
+			foreach ($this->_help_tour['tours'] as $tour) {
1583
+				$tours[] = array(
1584
+						'id'      => $tour->get_slug(),
1585
+						'options' => $tour->get_options(),
1586
+				);
1587
+			}
1588
+			wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1589
+			//admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1590
+		}
1591
+	}
1592
+
1593
+
1594
+
1595
+	/**
1596
+	 *        admin_footer_scripts_eei18n_js_strings
1597
+	 *
1598
+	 * @access        public
1599
+	 * @return        void
1600
+	 */
1601
+	public function admin_footer_scripts_eei18n_js_strings()
1602
+	{
1603
+		EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1604
+		EE_Registry::$i18n_js_strings['confirm_delete'] = __('Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', 'event_espresso');
1605
+		EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso');
1606
+		EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso');
1607
+		EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso');
1608
+		EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso');
1609
+		EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1610
+		EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso');
1611
+		EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso');
1612
+		EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso');
1613
+		EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso');
1614
+		EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso');
1615
+		EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso');
1616
+		EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso');
1617
+		EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso');
1618
+		EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso');
1619
+		EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso');
1620
+		EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso');
1621
+		EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1622
+		EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso');
1623
+		EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso');
1624
+		EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso');
1625
+		EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso');
1626
+		EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso');
1627
+		EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso');
1628
+		EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso');
1629
+		EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso');
1630
+		EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso');
1631
+		EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso');
1632
+		EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso');
1633
+		EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso');
1634
+		EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso');
1635
+		EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso');
1636
+		EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso');
1637
+		EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso');
1638
+		EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso');
1639
+		EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso');
1640
+		EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso');
1641
+		EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso');
1642
+		EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso');
1643
+	}
1644
+
1645
+
1646
+
1647
+	/**
1648
+	 *        load enhanced xdebug styles for ppl with failing eyesight
1649
+	 *
1650
+	 * @access        public
1651
+	 * @return        void
1652
+	 */
1653
+	public function add_xdebug_style()
1654
+	{
1655
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1656
+	}
1657
+
1658
+
1659
+	/************************/
1660
+	/** LIST TABLE METHODS **/
1661
+	/************************/
1662
+	/**
1663
+	 * this sets up the list table if the current view requires it.
1664
+	 *
1665
+	 * @access protected
1666
+	 * @return void
1667
+	 */
1668
+	protected function _set_list_table()
1669
+	{
1670
+		//first is this a list_table view?
1671
+		if ( ! isset($this->_route_config['list_table'])) {
1672
+			return;
1673
+		} //not a list_table view so get out.
1674
+		//list table functions are per view specific (because some admin pages might have more than one listtable!)
1675
+		if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1676
+			//user error msg
1677
+			$error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1678
+			//developer error msg
1679
+			$error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'),
1680
+							$this->_req_action, '_set_list_table_views_' . $this->_req_action);
1681
+			throw new EE_Error($error_msg);
1682
+		}
1683
+		//let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1684
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1685
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1686
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1687
+		$this->_set_list_table_view();
1688
+		$this->_set_list_table_object();
1689
+	}
1690
+
1691
+
1692
+
1693
+	/**
1694
+	 *        set current view for List Table
1695
+	 *
1696
+	 * @access public
1697
+	 * @return array
1698
+	 */
1699
+	protected function _set_list_table_view()
1700
+	{
1701
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1702
+		// looking at active items or dumpster diving ?
1703
+		if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
1704
+			$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1705
+		} else {
1706
+			$this->_view = sanitize_key($this->_req_data['status']);
1707
+		}
1708
+	}
1709
+
1710
+
1711
+
1712
+	/**
1713
+	 * _set_list_table_object
1714
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1715
+	 *
1716
+	 * @throws \EE_Error
1717
+	 */
1718
+	protected function _set_list_table_object()
1719
+	{
1720
+		if (isset($this->_route_config['list_table'])) {
1721
+			if ( ! class_exists($this->_route_config['list_table'])) {
1722
+				throw new EE_Error(
1723
+						sprintf(
1724
+								__(
1725
+										'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
1726
+										'event_espresso'
1727
+								),
1728
+								$this->_route_config['list_table'],
1729
+								get_class($this)
1730
+						)
1731
+				);
1732
+			}
1733
+			$list_table = $this->_route_config['list_table'];
1734
+			$this->_list_table_object = new $list_table($this);
1735
+		}
1736
+	}
1737
+
1738
+
1739
+
1740
+	/**
1741
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
1742
+	 *
1743
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
1744
+	 *                                                    urls.  The array should be indexed by the view it is being
1745
+	 *                                                    added to.
1746
+	 * @return array
1747
+	 */
1748
+	public function get_list_table_view_RLs($extra_query_args = array())
1749
+	{
1750
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1751
+		if (empty($this->_views)) {
1752
+			$this->_views = array();
1753
+		}
1754
+		// cycle thru views
1755
+		foreach ($this->_views as $key => $view) {
1756
+			$query_args = array();
1757
+			// check for current view
1758
+			$this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1759
+			$query_args['action'] = $this->_req_action;
1760
+			$query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1761
+			$query_args['status'] = $view['slug'];
1762
+			//merge any other arguments sent in.
1763
+			if (isset($extra_query_args[$view['slug']])) {
1764
+				$query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
1765
+			}
1766
+			$this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1767
+		}
1768
+		return $this->_views;
1769
+	}
1770
+
1771
+
1772
+
1773
+	/**
1774
+	 * _entries_per_page_dropdown
1775
+	 * generates a drop down box for selecting the number of visiable rows in an admin page list table
1776
+	 *
1777
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it.
1778
+	 * @access protected
1779
+	 * @param int $max_entries total number of rows in the table
1780
+	 * @return string
1781
+	 */
1782
+	protected function _entries_per_page_dropdown($max_entries = false)
1783
+	{
1784
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1785
+		$values = array(10, 25, 50, 100);
1786
+		$per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
1787
+		if ($max_entries) {
1788
+			$values[] = $max_entries;
1789
+			sort($values);
1790
+		}
1791
+		$entries_per_page_dropdown = '
1792 1792
 			<div id="entries-per-page-dv" class="alignleft actions">
1793 1793
 				<label class="hide-if-no-js">
1794 1794
 					Show
1795 1795
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
1796
-        foreach ($values as $value) {
1797
-            if ($value < $max_entries) {
1798
-                $selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1799
-                $entries_per_page_dropdown .= '
1796
+		foreach ($values as $value) {
1797
+			if ($value < $max_entries) {
1798
+				$selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1799
+				$entries_per_page_dropdown .= '
1800 1800
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
1801
-            }
1802
-        }
1803
-        $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1804
-        $entries_per_page_dropdown .= '
1801
+			}
1802
+		}
1803
+		$selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1804
+		$entries_per_page_dropdown .= '
1805 1805
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
1806
-        $entries_per_page_dropdown .= '
1806
+		$entries_per_page_dropdown .= '
1807 1807
 					</select>
1808 1808
 					entries
1809 1809
 				</label>
1810 1810
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
1811 1811
 			</div>
1812 1812
 		';
1813
-        return $entries_per_page_dropdown;
1814
-    }
1815
-
1816
-
1817
-
1818
-    /**
1819
-     *        _set_search_attributes
1820
-     *
1821
-     * @access        protected
1822
-     * @return        void
1823
-     */
1824
-    public function _set_search_attributes()
1825
-    {
1826
-        $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1827
-        $this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1828
-    }
1829
-
1830
-    /*** END LIST TABLE METHODS **/
1831
-    /*****************************/
1832
-    /**
1833
-     *        _add_registered_metaboxes
1834
-     *        this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
1835
-     *
1836
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
1837
-     * @access private
1838
-     * @return void
1839
-     */
1840
-    private function _add_registered_meta_boxes()
1841
-    {
1842
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1843
-        //we only add meta boxes if the page_route calls for it
1844
-        if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
1845
-            && is_array(
1846
-                    $this->_route_config['metaboxes']
1847
-            )
1848
-        ) {
1849
-            // this simply loops through the callbacks provided
1850
-            // and checks if there is a corresponding callback registered by the child
1851
-            // if there is then we go ahead and process the metabox loader.
1852
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
1853
-                // first check for Closures
1854
-                if ($metabox_callback instanceof Closure) {
1855
-                    $result = $metabox_callback();
1856
-                } else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
1857
-                    $result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
1858
-                } else {
1859
-                    $result = call_user_func(array($this, &$metabox_callback));
1860
-                }
1861
-                if ($result === false) {
1862
-                    // user error msg
1863
-                    $error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1864
-                    // developer error msg
1865
-                    $error_msg .= '||' . sprintf(
1866
-                                    __(
1867
-                                            'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
1868
-                                            'event_espresso'
1869
-                                    ),
1870
-                                    $metabox_callback
1871
-                            );
1872
-                    throw new EE_Error($error_msg);
1873
-                }
1874
-            }
1875
-        }
1876
-    }
1877
-
1878
-
1879
-
1880
-    /**
1881
-     * _add_screen_columns
1882
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page.
1883
-     *
1884
-     * @access private
1885
-     * @return void
1886
-     */
1887
-    private function _add_screen_columns()
1888
-    {
1889
-        if (
1890
-                is_array($this->_route_config)
1891
-                && isset($this->_route_config['columns'])
1892
-                && is_array($this->_route_config['columns'])
1893
-                && count($this->_route_config['columns']) === 2
1894
-        ) {
1895
-            add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1896
-            $this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1897
-            $screen_id = $this->_current_screen->id;
1898
-            $screen_columns = (int)get_user_option("screen_layout_$screen_id");
1899
-            $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1900
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1901
-            $this->_template_args['current_page'] = $this->_wp_page_slug;
1902
-            $this->_template_args['screen'] = $this->_current_screen;
1903
-            $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1904
-            //finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
1905
-            $this->_route_config['has_metaboxes'] = true;
1906
-        }
1907
-    }
1908
-
1909
-
1910
-
1911
-    /**********************************/
1912
-    /** GLOBALLY AVAILABLE METABOXES **/
1913
-    /**
1914
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply referencing the callback in the _page_config array property.  This way you can be very specific about what pages these get
1915
-     * loaded on.
1916
-     */
1917
-    private function _espresso_news_post_box()
1918
-    {
1919
-        $news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso'));
1920
-        add_meta_box('espresso_news_post_box', $news_box_title, array(
1921
-                $this,
1922
-                'espresso_news_post_box',
1923
-        ), $this->_wp_page_slug, 'side');
1924
-    }
1925
-
1926
-
1927
-
1928
-    /**
1929
-     * Code for setting up espresso ratings request metabox.
1930
-     */
1931
-    protected function _espresso_ratings_request()
1932
-    {
1933
-        if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
1934
-            return '';
1935
-        }
1936
-        $ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso'));
1937
-        add_meta_box('espresso_ratings_request', $ratings_box_title, array(
1938
-                $this,
1939
-                'espresso_ratings_request',
1940
-        ), $this->_wp_page_slug, 'side');
1941
-    }
1942
-
1943
-
1944
-
1945
-    /**
1946
-     * Code for setting up espresso ratings request metabox content.
1947
-     */
1948
-    public function espresso_ratings_request()
1949
-    {
1950
-        $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1951
-        EEH_Template::display_template($template_path, array());
1952
-    }
1953
-
1954
-
1955
-
1956
-    public static function cached_rss_display($rss_id, $url)
1957
-    {
1958
-        $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1959
-        $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1960
-        $pre = '<div class="espresso-rss-display">' . "\n\t";
1961
-        $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1962
-        $post = '</div>' . "\n";
1963
-        $cache_key = 'ee_rss_' . md5($rss_id);
1964
-        if (false != ($output = get_transient($cache_key))) {
1965
-            echo $pre . $output . $post;
1966
-            return true;
1967
-        }
1968
-        if ( ! $doing_ajax) {
1969
-            echo $pre . $loading . $post;
1970
-            return false;
1971
-        }
1972
-        ob_start();
1973
-        wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
1974
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
1975
-        return true;
1976
-    }
1977
-
1978
-
1979
-
1980
-    public function espresso_news_post_box()
1981
-    {
1982
-        ?>
1813
+		return $entries_per_page_dropdown;
1814
+	}
1815
+
1816
+
1817
+
1818
+	/**
1819
+	 *        _set_search_attributes
1820
+	 *
1821
+	 * @access        protected
1822
+	 * @return        void
1823
+	 */
1824
+	public function _set_search_attributes()
1825
+	{
1826
+		$this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1827
+		$this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1828
+	}
1829
+
1830
+	/*** END LIST TABLE METHODS **/
1831
+	/*****************************/
1832
+	/**
1833
+	 *        _add_registered_metaboxes
1834
+	 *        this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
1835
+	 *
1836
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
1837
+	 * @access private
1838
+	 * @return void
1839
+	 */
1840
+	private function _add_registered_meta_boxes()
1841
+	{
1842
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1843
+		//we only add meta boxes if the page_route calls for it
1844
+		if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
1845
+			&& is_array(
1846
+					$this->_route_config['metaboxes']
1847
+			)
1848
+		) {
1849
+			// this simply loops through the callbacks provided
1850
+			// and checks if there is a corresponding callback registered by the child
1851
+			// if there is then we go ahead and process the metabox loader.
1852
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
1853
+				// first check for Closures
1854
+				if ($metabox_callback instanceof Closure) {
1855
+					$result = $metabox_callback();
1856
+				} else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
1857
+					$result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
1858
+				} else {
1859
+					$result = call_user_func(array($this, &$metabox_callback));
1860
+				}
1861
+				if ($result === false) {
1862
+					// user error msg
1863
+					$error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1864
+					// developer error msg
1865
+					$error_msg .= '||' . sprintf(
1866
+									__(
1867
+											'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
1868
+											'event_espresso'
1869
+									),
1870
+									$metabox_callback
1871
+							);
1872
+					throw new EE_Error($error_msg);
1873
+				}
1874
+			}
1875
+		}
1876
+	}
1877
+
1878
+
1879
+
1880
+	/**
1881
+	 * _add_screen_columns
1882
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page.
1883
+	 *
1884
+	 * @access private
1885
+	 * @return void
1886
+	 */
1887
+	private function _add_screen_columns()
1888
+	{
1889
+		if (
1890
+				is_array($this->_route_config)
1891
+				&& isset($this->_route_config['columns'])
1892
+				&& is_array($this->_route_config['columns'])
1893
+				&& count($this->_route_config['columns']) === 2
1894
+		) {
1895
+			add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1896
+			$this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1897
+			$screen_id = $this->_current_screen->id;
1898
+			$screen_columns = (int)get_user_option("screen_layout_$screen_id");
1899
+			$total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1900
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1901
+			$this->_template_args['current_page'] = $this->_wp_page_slug;
1902
+			$this->_template_args['screen'] = $this->_current_screen;
1903
+			$this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1904
+			//finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
1905
+			$this->_route_config['has_metaboxes'] = true;
1906
+		}
1907
+	}
1908
+
1909
+
1910
+
1911
+	/**********************************/
1912
+	/** GLOBALLY AVAILABLE METABOXES **/
1913
+	/**
1914
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply referencing the callback in the _page_config array property.  This way you can be very specific about what pages these get
1915
+	 * loaded on.
1916
+	 */
1917
+	private function _espresso_news_post_box()
1918
+	{
1919
+		$news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso'));
1920
+		add_meta_box('espresso_news_post_box', $news_box_title, array(
1921
+				$this,
1922
+				'espresso_news_post_box',
1923
+		), $this->_wp_page_slug, 'side');
1924
+	}
1925
+
1926
+
1927
+
1928
+	/**
1929
+	 * Code for setting up espresso ratings request metabox.
1930
+	 */
1931
+	protected function _espresso_ratings_request()
1932
+	{
1933
+		if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
1934
+			return '';
1935
+		}
1936
+		$ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso'));
1937
+		add_meta_box('espresso_ratings_request', $ratings_box_title, array(
1938
+				$this,
1939
+				'espresso_ratings_request',
1940
+		), $this->_wp_page_slug, 'side');
1941
+	}
1942
+
1943
+
1944
+
1945
+	/**
1946
+	 * Code for setting up espresso ratings request metabox content.
1947
+	 */
1948
+	public function espresso_ratings_request()
1949
+	{
1950
+		$template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1951
+		EEH_Template::display_template($template_path, array());
1952
+	}
1953
+
1954
+
1955
+
1956
+	public static function cached_rss_display($rss_id, $url)
1957
+	{
1958
+		$loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1959
+		$doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1960
+		$pre = '<div class="espresso-rss-display">' . "\n\t";
1961
+		$pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1962
+		$post = '</div>' . "\n";
1963
+		$cache_key = 'ee_rss_' . md5($rss_id);
1964
+		if (false != ($output = get_transient($cache_key))) {
1965
+			echo $pre . $output . $post;
1966
+			return true;
1967
+		}
1968
+		if ( ! $doing_ajax) {
1969
+			echo $pre . $loading . $post;
1970
+			return false;
1971
+		}
1972
+		ob_start();
1973
+		wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
1974
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
1975
+		return true;
1976
+	}
1977
+
1978
+
1979
+
1980
+	public function espresso_news_post_box()
1981
+	{
1982
+		?>
1983 1983
         <div class="padding">
1984 1984
             <div id="espresso_news_post_box_content" class="infolinks">
1985 1985
                 <?php
1986
-                // Get RSS Feed(s)
1987
-                $feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/');
1988
-                $url = urlencode($feed_url);
1989
-                self::cached_rss_display('espresso_news_post_box_content', $url);
1990
-                ?>
1986
+				// Get RSS Feed(s)
1987
+				$feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/');
1988
+				$url = urlencode($feed_url);
1989
+				self::cached_rss_display('espresso_news_post_box_content', $url);
1990
+				?>
1991 1991
             </div>
1992 1992
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
1993 1993
         </div>
1994 1994
         <?php
1995
-    }
1996
-
1997
-
1998
-
1999
-    private function _espresso_links_post_box()
2000
-    {
2001
-        //Hiding until we actually have content to put in here...
2002
-        //add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2003
-    }
2004
-
2005
-
2006
-
2007
-    public function espresso_links_post_box()
2008
-    {
2009
-        //Hiding until we actually have content to put in here...
2010
-        //$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php';
2011
-        //EEH_Template::display_template( $templatepath );
2012
-    }
2013
-
2014
-
2015
-
2016
-    protected function _espresso_sponsors_post_box()
2017
-    {
2018
-        $show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true);
2019
-        if ($show_sponsors) {
2020
-            add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side');
2021
-        }
2022
-    }
2023
-
2024
-
2025
-
2026
-    public function espresso_sponsors_post_box()
2027
-    {
2028
-        $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2029
-        EEH_Template::display_template($templatepath);
2030
-    }
2031
-
2032
-
2033
-
2034
-    private function _publish_post_box()
2035
-    {
2036
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2037
-        //if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label.  Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2038
-        if ( ! empty($this->_labels['publishbox'])) {
2039
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
2040
-        } else {
2041
-            $box_label = __('Publish', 'event_espresso');
2042
-        }
2043
-        $box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this);
2044
-        add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high');
2045
-    }
2046
-
2047
-
2048
-
2049
-    public function editor_overview()
2050
-    {
2051
-        //if we have extra content set let's add it in if not make sure its empty
2052
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2053
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2054
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2055
-    }
2056
-
2057
-
2058
-    /** end of globally available metaboxes section **/
2059
-    /*************************************************/
2060
-    /**
2061
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2062
-     * protected method.
2063
-     *
2064
-     * @see   $this->_set_publish_post_box_vars for param details
2065
-     * @since 4.6.0
2066
-     */
2067
-    public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true)
2068
-    {
2069
-        $this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2070
-    }
2071
-
2072
-
2073
-
2074
-    /**
2075
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2076
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2077
-     * save, and save and close buttons to work properly, then you will want to include a
2078
-     * values for the name and id arguments.
2079
-     *
2080
-     * @todo  Add in validation for name/id arguments.
2081
-     * @param    string  $name                    key used for the action ID (i.e. event_id)
2082
-     * @param    int     $id                      id attached to the item published
2083
-     * @param    string  $delete                  page route callback for the delete action
2084
-     * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2085
-     * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button
2086
-     * @throws \EE_Error
2087
-     */
2088
-    protected function _set_publish_post_box_vars(
2089
-            $name = '',
2090
-            $id = 0,
2091
-            $delete = '',
2092
-            $save_close_redirect_URL = '',
2093
-            $both_btns = true
2094
-    ) {
2095
-        // if Save & Close, use a custom redirect URL or default to the main page?
2096
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url;
2097
-        // create the Save & Close and Save buttons
2098
-        $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2099
-        //if we have extra content set let's add it in if not make sure its empty
2100
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2101
-        if ($delete && ! empty($id)) {
2102
-            //make sure we have a default if just true is sent.
2103
-            $delete = ! empty($delete) ? $delete : 'delete';
2104
-            $delete_link_args = array($name => $id);
2105
-            $delete = $this->get_action_link_or_button(
2106
-                    $delete,
2107
-                    $delete,
2108
-                    $delete_link_args,
2109
-                    'submitdelete deletion',
2110
-                    '',
2111
-                    false
2112
-            );
2113
-        }
2114
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2115
-        if ( ! empty($name) && ! empty($id)) {
2116
-            $hidden_field_arr[$name] = array(
2117
-                    'type'  => 'hidden',
2118
-                    'value' => $id,
2119
-            );
2120
-            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2121
-        } else {
2122
-            $hf = '';
2123
-        }
2124
-        // add hidden field
2125
-        $this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf;
2126
-    }
2127
-
2128
-
2129
-
2130
-    /**
2131
-     *        displays an error message to ppl who have javascript disabled
2132
-     *
2133
-     * @access        private
2134
-     * @return        string
2135
-     */
2136
-    private function _display_no_javascript_warning()
2137
-    {
2138
-        ?>
1995
+	}
1996
+
1997
+
1998
+
1999
+	private function _espresso_links_post_box()
2000
+	{
2001
+		//Hiding until we actually have content to put in here...
2002
+		//add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2003
+	}
2004
+
2005
+
2006
+
2007
+	public function espresso_links_post_box()
2008
+	{
2009
+		//Hiding until we actually have content to put in here...
2010
+		//$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php';
2011
+		//EEH_Template::display_template( $templatepath );
2012
+	}
2013
+
2014
+
2015
+
2016
+	protected function _espresso_sponsors_post_box()
2017
+	{
2018
+		$show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true);
2019
+		if ($show_sponsors) {
2020
+			add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side');
2021
+		}
2022
+	}
2023
+
2024
+
2025
+
2026
+	public function espresso_sponsors_post_box()
2027
+	{
2028
+		$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2029
+		EEH_Template::display_template($templatepath);
2030
+	}
2031
+
2032
+
2033
+
2034
+	private function _publish_post_box()
2035
+	{
2036
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2037
+		//if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label.  Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2038
+		if ( ! empty($this->_labels['publishbox'])) {
2039
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
2040
+		} else {
2041
+			$box_label = __('Publish', 'event_espresso');
2042
+		}
2043
+		$box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this);
2044
+		add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high');
2045
+	}
2046
+
2047
+
2048
+
2049
+	public function editor_overview()
2050
+	{
2051
+		//if we have extra content set let's add it in if not make sure its empty
2052
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2053
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2054
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2055
+	}
2056
+
2057
+
2058
+	/** end of globally available metaboxes section **/
2059
+	/*************************************************/
2060
+	/**
2061
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2062
+	 * protected method.
2063
+	 *
2064
+	 * @see   $this->_set_publish_post_box_vars for param details
2065
+	 * @since 4.6.0
2066
+	 */
2067
+	public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true)
2068
+	{
2069
+		$this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2070
+	}
2071
+
2072
+
2073
+
2074
+	/**
2075
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2076
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2077
+	 * save, and save and close buttons to work properly, then you will want to include a
2078
+	 * values for the name and id arguments.
2079
+	 *
2080
+	 * @todo  Add in validation for name/id arguments.
2081
+	 * @param    string  $name                    key used for the action ID (i.e. event_id)
2082
+	 * @param    int     $id                      id attached to the item published
2083
+	 * @param    string  $delete                  page route callback for the delete action
2084
+	 * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2085
+	 * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button
2086
+	 * @throws \EE_Error
2087
+	 */
2088
+	protected function _set_publish_post_box_vars(
2089
+			$name = '',
2090
+			$id = 0,
2091
+			$delete = '',
2092
+			$save_close_redirect_URL = '',
2093
+			$both_btns = true
2094
+	) {
2095
+		// if Save & Close, use a custom redirect URL or default to the main page?
2096
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url;
2097
+		// create the Save & Close and Save buttons
2098
+		$this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2099
+		//if we have extra content set let's add it in if not make sure its empty
2100
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2101
+		if ($delete && ! empty($id)) {
2102
+			//make sure we have a default if just true is sent.
2103
+			$delete = ! empty($delete) ? $delete : 'delete';
2104
+			$delete_link_args = array($name => $id);
2105
+			$delete = $this->get_action_link_or_button(
2106
+					$delete,
2107
+					$delete,
2108
+					$delete_link_args,
2109
+					'submitdelete deletion',
2110
+					'',
2111
+					false
2112
+			);
2113
+		}
2114
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2115
+		if ( ! empty($name) && ! empty($id)) {
2116
+			$hidden_field_arr[$name] = array(
2117
+					'type'  => 'hidden',
2118
+					'value' => $id,
2119
+			);
2120
+			$hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2121
+		} else {
2122
+			$hf = '';
2123
+		}
2124
+		// add hidden field
2125
+		$this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf;
2126
+	}
2127
+
2128
+
2129
+
2130
+	/**
2131
+	 *        displays an error message to ppl who have javascript disabled
2132
+	 *
2133
+	 * @access        private
2134
+	 * @return        string
2135
+	 */
2136
+	private function _display_no_javascript_warning()
2137
+	{
2138
+		?>
2139 2139
         <noscript>
2140 2140
             <div id="no-js-message" class="error">
2141 2141
                 <p style="font-size:1.3em;">
@@ -2145,1267 +2145,1267 @@  discard block
 block discarded – undo
2145 2145
             </div>
2146 2146
         </noscript>
2147 2147
         <?php
2148
-    }
2148
+	}
2149 2149
 
2150 2150
 
2151 2151
 
2152
-    /**
2153
-     *        displays espresso success and/or error notices
2154
-     *
2155
-     * @access        private
2156
-     * @return        string
2157
-     */
2158
-    private function _display_espresso_notices()
2159
-    {
2160
-        $notices = $this->_get_transient(true);
2161
-        echo stripslashes($notices);
2162
-    }
2152
+	/**
2153
+	 *        displays espresso success and/or error notices
2154
+	 *
2155
+	 * @access        private
2156
+	 * @return        string
2157
+	 */
2158
+	private function _display_espresso_notices()
2159
+	{
2160
+		$notices = $this->_get_transient(true);
2161
+		echo stripslashes($notices);
2162
+	}
2163 2163
 
2164 2164
 
2165 2165
 
2166
-    /**
2167
-     *        spinny things pacify the masses
2168
-     *
2169
-     * @access private
2170
-     * @return string
2171
-     */
2172
-    protected function _add_admin_page_ajax_loading_img()
2173
-    {
2174
-        ?>
2166
+	/**
2167
+	 *        spinny things pacify the masses
2168
+	 *
2169
+	 * @access private
2170
+	 * @return string
2171
+	 */
2172
+	protected function _add_admin_page_ajax_loading_img()
2173
+	{
2174
+		?>
2175 2175
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2176 2176
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php esc_html_e('loading...', 'event_espresso'); ?></span>
2177 2177
         </div>
2178 2178
         <?php
2179
-    }
2179
+	}
2180 2180
 
2181 2181
 
2182 2182
 
2183
-    /**
2184
-     *        add admin page overlay for modal boxes
2185
-     *
2186
-     * @access private
2187
-     * @return string
2188
-     */
2189
-    protected function _add_admin_page_overlay()
2190
-    {
2191
-        ?>
2183
+	/**
2184
+	 *        add admin page overlay for modal boxes
2185
+	 *
2186
+	 * @access private
2187
+	 * @return string
2188
+	 */
2189
+	protected function _add_admin_page_overlay()
2190
+	{
2191
+		?>
2192 2192
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2193 2193
         <?php
2194
-    }
2195
-
2196
-
2197
-
2198
-    /**
2199
-     * facade for add_meta_box
2200
-     *
2201
-     * @param string  $action        where the metabox get's displayed
2202
-     * @param string  $title         Title of Metabox (output in metabox header)
2203
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here.
2204
-     * @param array   $callback_args an array of args supplied for the metabox
2205
-     * @param string  $column        what metabox column
2206
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2207
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box.
2208
-     */
2209
-    public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true)
2210
-    {
2211
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2212
-        //if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2213
-        if (empty($callback_args) && $create_func) {
2214
-            $callback_args = array(
2215
-                    'template_path' => $this->_template_path,
2216
-                    'template_args' => $this->_template_args,
2217
-            );
2218
-        }
2219
-        //if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2220
-        $call_back_func = $create_func ? create_function('$post, $metabox',
2221
-                'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2222
-        add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2223
-    }
2224
-
2225
-
2226
-
2227
-    /**
2228
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2229
-     *
2230
-     * @return [type] [description]
2231
-     */
2232
-    public function display_admin_page_with_metabox_columns()
2233
-    {
2234
-        $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2235
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true);
2236
-        //the final wrapper
2237
-        $this->admin_page_wrapper();
2238
-    }
2239
-
2240
-
2241
-
2242
-    /**
2243
-     *        generates  HTML wrapper for an admin details page
2244
-     *
2245
-     * @access public
2246
-     * @return void
2247
-     */
2248
-    public function display_admin_page_with_sidebar()
2249
-    {
2250
-        $this->_display_admin_page(true);
2251
-    }
2252
-
2253
-
2254
-
2255
-    /**
2256
-     *        generates  HTML wrapper for an admin details page (except no sidebar)
2257
-     *
2258
-     * @access public
2259
-     * @return void
2260
-     */
2261
-    public function display_admin_page_with_no_sidebar()
2262
-    {
2263
-        $this->_display_admin_page();
2264
-    }
2265
-
2266
-
2267
-
2268
-    /**
2269
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2270
-     *
2271
-     * @access public
2272
-     * @return void
2273
-     */
2274
-    public function display_about_admin_page()
2275
-    {
2276
-        $this->_display_admin_page(false, true);
2277
-    }
2278
-
2279
-
2280
-
2281
-    /**
2282
-     * display_admin_page
2283
-     * contains the code for actually displaying an admin page
2284
-     *
2285
-     * @access private
2286
-     * @param  boolean $sidebar true with sidebar, false without
2287
-     * @param  boolean $about   use the about admin wrapper instead of the default.
2288
-     * @return void
2289
-     */
2290
-    private function _display_admin_page($sidebar = false, $about = false)
2291
-    {
2292
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2293
-        //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2294
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2295
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2296
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2297
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2298
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2299
-                ? 'poststuff'
2300
-                : 'espresso-default-admin';
2301
-        $template_path = $sidebar
2302
-                ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2303
-                : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2304
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2305
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2306
-        }
2307
-        $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2308
-        $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
2309
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '';
2310
-        $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '';
2311
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2312
-        // the final template wrapper
2313
-        $this->admin_page_wrapper($about);
2314
-    }
2315
-
2316
-
2317
-
2318
-    /**
2319
-     * This is used to display caf preview pages.
2320
-     *
2321
-     * @since 4.3.2
2322
-     * @param string $utm_campaign_source what is the key used for google analytics link
2323
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2324
-     * @return void
2325
-     * @throws \EE_Error
2326
-     */
2327
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2328
-    {
2329
-        //let's generate a default preview action button if there isn't one already present.
2330
-        $this->_labels['buttons']['buy_now'] = __('Upgrade to Event Espresso 4 Right Now', 'event_espresso');
2331
-        $buy_now_url = add_query_arg(
2332
-                array(
2333
-                        'ee_ver'       => 'ee4',
2334
-                        'utm_source'   => 'ee4_plugin_admin',
2335
-                        'utm_medium'   => 'link',
2336
-                        'utm_campaign' => $utm_campaign_source,
2337
-                        'utm_content'  => 'buy_now_button',
2338
-                ),
2339
-                'http://eventespresso.com/pricing/'
2340
-        );
2341
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2342
-                ? $this->get_action_link_or_button(
2343
-                        '',
2344
-                        'buy_now',
2345
-                        array(),
2346
-                        'button-primary button-large',
2347
-                        $buy_now_url,
2348
-                        true
2349
-                )
2350
-                : $this->_template_args['preview_action_button'];
2351
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2352
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2353
-                $template_path,
2354
-                $this->_template_args,
2355
-                true
2356
-        );
2357
-        $this->_display_admin_page($display_sidebar);
2358
-    }
2359
-
2360
-
2361
-
2362
-    /**
2363
-     * display_admin_list_table_page_with_sidebar
2364
-     * generates HTML wrapper for an admin_page with list_table
2365
-     *
2366
-     * @access public
2367
-     * @return void
2368
-     */
2369
-    public function display_admin_list_table_page_with_sidebar()
2370
-    {
2371
-        $this->_display_admin_list_table_page(true);
2372
-    }
2373
-
2374
-
2375
-
2376
-    /**
2377
-     * display_admin_list_table_page_with_no_sidebar
2378
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2379
-     *
2380
-     * @access public
2381
-     * @return void
2382
-     */
2383
-    public function display_admin_list_table_page_with_no_sidebar()
2384
-    {
2385
-        $this->_display_admin_list_table_page();
2386
-    }
2387
-
2388
-
2389
-
2390
-    /**
2391
-     * generates html wrapper for an admin_list_table page
2392
-     *
2393
-     * @access private
2394
-     * @param boolean $sidebar whether to display with sidebar or not.
2395
-     * @return void
2396
-     */
2397
-    private function _display_admin_list_table_page($sidebar = false)
2398
-    {
2399
-        //setup search attributes
2400
-        $this->_set_search_attributes();
2401
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2402
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2403
-        $this->_template_args['table_url'] = defined('DOING_AJAX')
2404
-                ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2405
-                : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2406
-        $this->_template_args['list_table'] = $this->_list_table_object;
2407
-        $this->_template_args['current_route'] = $this->_req_action;
2408
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2409
-        $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2410
-        if ( ! empty($ajax_sorting_callback)) {
2411
-            $sortable_list_table_form_fields = wp_nonce_field(
2412
-                    $ajax_sorting_callback . '_nonce',
2413
-                    $ajax_sorting_callback . '_nonce',
2414
-                    false,
2415
-                    false
2416
-            );
2417
-            //			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2418
-            //			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2419
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2420
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2421
-        } else {
2422
-            $sortable_list_table_form_fields = '';
2423
-        }
2424
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2425
-        $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2426
-        $nonce_ref = $this->_req_action . '_nonce';
2427
-        $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2428
-        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2429
-        //display message about search results?
2430
-        $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
2431
-                ? '<p class="ee-search-results">' . sprintf(
2432
-                        esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2433
-                        trim($this->_req_data['s'], '%')
2434
-                ) . '</p>'
2435
-                : '';
2436
-        // filter before_list_table template arg
2437
-        $this->_template_args['before_list_table'] = apply_filters(
2438
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2439
-            $this->_template_args['before_list_table'],
2440
-            $this->page_slug,
2441
-            $this->_req_data,
2442
-            $this->_req_action
2443
-        );
2444
-        // convert to array and filter again
2445
-        // arrays are easier to inject new items in a specific location,
2446
-        // but would not be backwards compatible, so we have to add a new filter
2447
-        $this->_template_args['before_list_table'] = implode(
2448
-            " \n",
2449
-            (array) apply_filters(
2450
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2451
-                (array) $this->_template_args['before_list_table'],
2452
-                $this->page_slug,
2453
-                $this->_req_data,
2454
-                $this->_req_action
2455
-            )
2456
-        );
2457
-        // filter after_list_table template arg
2458
-        $this->_template_args['after_list_table'] = apply_filters(
2459
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2460
-            $this->_template_args['after_list_table'],
2461
-            $this->page_slug,
2462
-            $this->_req_data,
2463
-            $this->_req_action
2464
-        );
2465
-        // convert to array and filter again
2466
-        // arrays are easier to inject new items in a specific location,
2467
-        // but would not be backwards compatible, so we have to add a new filter
2468
-        $this->_template_args['after_list_table'] = implode(
2469
-            " \n",
2470
-            (array) apply_filters(
2471
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2472
-                (array) $this->_template_args['after_list_table'],
2473
-                $this->page_slug,
2474
-                $this->_req_data,
2475
-                $this->_req_action
2476
-            )
2477
-        );
2478
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2479
-                $template_path,
2480
-                $this->_template_args,
2481
-                true
2482
-        );
2483
-        // the final template wrapper
2484
-        if ($sidebar) {
2485
-            $this->display_admin_page_with_sidebar();
2486
-        } else {
2487
-            $this->display_admin_page_with_no_sidebar();
2488
-        }
2489
-    }
2490
-
2491
-
2492
-
2493
-    /**
2494
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend.
2495
-     * $items are expected in an array in the following format:
2496
-     * $legend_items = array(
2497
-     *        'item_id' => array(
2498
-     *            'icon' => 'http://url_to_icon_being_described.png',
2499
-     *            'desc' => __('localized description of item');
2500
-     *        )
2501
-     * );
2502
-     *
2503
-     * @param  array $items see above for format of array
2504
-     * @return string        html string of legend
2505
-     */
2506
-    protected function _display_legend($items)
2507
-    {
2508
-        $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2509
-        $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2510
-        return EEH_Template::display_template($legend_template, $this->_template_args, true);
2511
-    }
2512
-
2513
-
2514
-
2515
-    /**
2516
-     * this is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2517
-     *
2518
-     * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2519
-     *                             The returned json object is created from an array in the following format:
2520
-     *                             array(
2521
-     *                             'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2522
-     *                             'success' => FALSE, //(default FALSE) - contains any special success message.
2523
-     *                             'notices' => '', // - contains any EE_Error formatted notices
2524
-     *                             'content' => 'string can be html', //this is a string of formatted content (can be html)
2525
-     *                             'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any
2526
-     *                             specific template args that might be included in here)
2527
-     *                             )
2528
-     *                             The json object is populated by whatever is set in the $_template_args property.
2529
-     * @return void
2530
-     */
2531
-    protected function _return_json($sticky_notices = false)
2532
-    {
2533
-        //make sure any EE_Error notices have been handled.
2534
-        $this->_process_notices(array(), true, $sticky_notices);
2535
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
2536
-        unset($this->_template_args['data']);
2537
-        $json = array(
2538
-                'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2539
-                'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2540
-                'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2541
-                'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2542
-                'notices'   => EE_Error::get_notices(),
2543
-                'content'   => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '',
2544
-                'data'      => array_merge($data, array('template_args' => $this->_template_args)),
2545
-                'isEEajax'  => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2546
-        );
2547
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
2548
-        if (null === error_get_last() || ! headers_sent()) {
2549
-            header('Content-Type: application/json; charset=UTF-8');
2550
-        }
2551
-        echo wp_json_encode($json);
2552
-
2553
-        exit();
2554
-    }
2555
-
2556
-
2557
-
2558
-    /**
2559
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2560
-     *
2561
-     * @return void
2562
-     * @throws EE_Error
2563
-     */
2564
-    public function return_json()
2565
-    {
2566
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2567
-            $this->_return_json();
2568
-        } else {
2569
-            throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__));
2570
-        }
2571
-    }
2572
-
2573
-
2574
-
2575
-    /**
2576
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
2577
-     *
2578
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
2579
-     * @access   public
2580
-     */
2581
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
2582
-    {
2583
-        $this->_hook_obj = $hook_obj;
2584
-    }
2585
-
2586
-
2587
-
2588
-    /**
2589
-     *        generates  HTML wrapper with Tabbed nav for an admin page
2590
-     *
2591
-     * @access public
2592
-     * @param  boolean $about whether to use the special about page wrapper or default.
2593
-     * @return void
2594
-     */
2595
-    public function admin_page_wrapper($about = false)
2596
-    {
2597
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2598
-        $this->_nav_tabs = $this->_get_main_nav_tabs();
2599
-        $this->_template_args['nav_tabs'] = $this->_nav_tabs;
2600
-        $this->_template_args['admin_page_title'] = $this->_admin_page_title;
2601
-        $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2602
-                isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2603
-        $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2604
-                isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2605
-        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2606
-        // load settings page wrapper template
2607
-        $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2608
-        //about page?
2609
-        $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2610
-        if (defined('DOING_AJAX')) {
2611
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2612
-            $this->_return_json();
2613
-        } else {
2614
-            EEH_Template::display_template($template_path, $this->_template_args);
2615
-        }
2616
-    }
2617
-
2618
-
2619
-
2620
-    /**
2621
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2622
-     *
2623
-     * @return string html
2624
-     */
2625
-    protected function _get_main_nav_tabs()
2626
-    {
2627
-        //let's generate the html using the EEH_Tabbed_Content helper.  We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array)
2628
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
2629
-    }
2630
-
2631
-
2632
-
2633
-    /**
2634
-     *        sort nav tabs
2635
-     *
2636
-     * @access public
2637
-     * @param $a
2638
-     * @param $b
2639
-     * @return int
2640
-     */
2641
-    private function _sort_nav_tabs($a, $b)
2642
-    {
2643
-        if ($a['order'] == $b['order']) {
2644
-            return 0;
2645
-        }
2646
-        return ($a['order'] < $b['order']) ? -1 : 1;
2647
-    }
2648
-
2649
-
2650
-
2651
-    /**
2652
-     *    generates HTML for the forms used on admin pages
2653
-     *
2654
-     * @access protected
2655
-     * @param    array $input_vars - array of input field details
2656
-     * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to use)
2657
-     * @return string
2658
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2659
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2660
-     */
2661
-    protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
2662
-    {
2663
-        $content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2664
-        return $content;
2665
-    }
2666
-
2667
-
2668
-
2669
-    /**
2670
-     * generates the "Save" and "Save & Close" buttons for edit forms
2671
-     *
2672
-     * @access protected
2673
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save & Close" button.
2674
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2675
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button).  We can also use this to just dump default actions by submitting some other value.
2676
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling).
2677
-     */
2678
-    protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2679
-    {
2680
-        //make sure $text and $actions are in an array
2681
-        $text = (array)$text;
2682
-        $actions = (array)$actions;
2683
-        $referrer_url = empty($referrer) ? '' : $referrer;
2684
-        $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2685
-                : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2686
-        $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2687
-        $default_names = array('save', 'save_and_close');
2688
-        //add in a hidden index for the current page (so save and close redirects properly)
2689
-        $this->_template_args['save_buttons'] = $referrer_url;
2690
-        foreach ($button_text as $key => $button) {
2691
-            $ref = $default_names[$key];
2692
-            $id = $this->_current_view . '_' . $ref;
2693
-            $name = ! empty($actions) ? $actions[$key] : $ref;
2694
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2695
-            if ( ! $both) {
2696
-                break;
2697
-            }
2698
-        }
2699
-    }
2700
-
2701
-
2702
-
2703
-    /**
2704
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2705
-     *
2706
-     * @see   $this->_set_add_edit_form_tags() for details on params
2707
-     * @since 4.6.0
2708
-     * @param string $route
2709
-     * @param array  $additional_hidden_fields
2710
-     */
2711
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2712
-    {
2713
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
2714
-    }
2715
-
2716
-
2717
-
2718
-    /**
2719
-     * set form open and close tags on add/edit pages.
2720
-     *
2721
-     * @access protected
2722
-     * @param string $route                    the route you want the form to direct to
2723
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
2724
-     * @return void
2725
-     */
2726
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2727
-    {
2728
-        if (empty($route)) {
2729
-            $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2730
-            $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2731
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2732
-        }
2733
-        // open form
2734
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2735
-        // add nonce
2736
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2737
-        //		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2738
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2739
-        // add REQUIRED form action
2740
-        $hidden_fields = array(
2741
-                'action' => array('type' => 'hidden', 'value' => $route),
2742
-        );
2743
-        // merge arrays
2744
-        $hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields;
2745
-        // generate form fields
2746
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2747
-        // add fields to form
2748
-        foreach ((array)$form_fields as $field_name => $form_field) {
2749
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2750
-        }
2751
-        // close form
2752
-        $this->_template_args['after_admin_page_content'] = '</form>';
2753
-    }
2754
-
2755
-
2756
-
2757
-    /**
2758
-     * Public Wrapper for _redirect_after_action() method since its
2759
-     * discovered it would be useful for external code to have access.
2760
-     *
2761
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
2762
-     * @since 4.5.0
2763
-     */
2764
-    public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2765
-    {
2766
-        $this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite);
2767
-    }
2768
-
2769
-
2770
-
2771
-    /**
2772
-     *    _redirect_after_action
2773
-     *
2774
-     * @param int    $success            - whether success was for two or more records, or just one, or none
2775
-     * @param string $what               - what the action was performed on
2776
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
2777
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin action is completed
2778
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2779
-     * @access protected
2780
-     * @return void
2781
-     */
2782
-    protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2783
-    {
2784
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2785
-        //class name for actions/filters.
2786
-        $classname = get_class($this);
2787
-        //set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url
2788
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
2789
-        $notices = EE_Error::get_notices(false);
2790
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
2791
-        if ( ! $override_overwrite || ! empty($notices['errors'])) {
2792
-            EE_Error::overwrite_success();
2793
-        }
2794
-        if ( ! empty($what) && ! empty($action_desc)) {
2795
-            // how many records affected ? more than one record ? or just one ?
2796
-            if ($success > 1 && empty($notices['errors'])) {
2797
-                // set plural msg
2798
-                EE_Error::add_success(
2799
-                        sprintf(
2800
-                                __('The "%s" have been successfully %s.', 'event_espresso'),
2801
-                                $what,
2802
-                                $action_desc
2803
-                        ),
2804
-                        __FILE__, __FUNCTION__, __LINE__
2805
-                );
2806
-            } else if ($success == 1 && empty($notices['errors'])) {
2807
-                // set singular msg
2808
-                EE_Error::add_success(
2809
-                        sprintf(
2810
-                                __('The "%s" has been successfully %s.', 'event_espresso'),
2811
-                                $what,
2812
-                                $action_desc
2813
-                        ),
2814
-                        __FILE__, __FUNCTION__, __LINE__
2815
-                );
2816
-            }
2817
-        }
2818
-        // check that $query_args isn't something crazy
2819
-        if ( ! is_array($query_args)) {
2820
-            $query_args = array();
2821
-        }
2822
-        /**
2823
-         * Allow injecting actions before the query_args are modified for possible different
2824
-         * redirections on save and close actions
2825
-         *
2826
-         * @since 4.2.0
2827
-         * @param array $query_args       The original query_args array coming into the
2828
-         *                                method.
2829
-         */
2830
-        do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2831
-        //calculate where we're going (if we have a "save and close" button pushed)
2832
-        if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2833
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2834
-            $parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
2835
-            // regenerate query args array from referrer URL
2836
-            parse_str($parsed_url['query'], $query_args);
2837
-            // correct page and action will be in the query args now
2838
-            $redirect_url = admin_url('admin.php');
2839
-        }
2840
-        //merge any default query_args set in _default_route_query_args property
2841
-        if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
2842
-            $args_to_merge = array();
2843
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
2844
-                //is there a wp_referer array in our _default_route_query_args property?
2845
-                if ($query_param == 'wp_referer') {
2846
-                    $query_value = (array)$query_value;
2847
-                    foreach ($query_value as $reference => $value) {
2848
-                        if (strpos($reference, 'nonce') !== false) {
2849
-                            continue;
2850
-                        }
2851
-                        //finally we will override any arguments in the referer with
2852
-                        //what might be set on the _default_route_query_args array.
2853
-                        if (isset($this->_default_route_query_args[$reference])) {
2854
-                            $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
2855
-                        } else {
2856
-                            $args_to_merge[$reference] = urlencode($value);
2857
-                        }
2858
-                    }
2859
-                    continue;
2860
-                }
2861
-                $args_to_merge[$query_param] = $query_value;
2862
-            }
2863
-            //now let's merge these arguments but override with what was specifically sent in to the
2864
-            //redirect.
2865
-            $query_args = array_merge($args_to_merge, $query_args);
2866
-        }
2867
-        $this->_process_notices($query_args);
2868
-        // generate redirect url
2869
-        // if redirecting to anything other than the main page, add a nonce
2870
-        if (isset($query_args['action'])) {
2871
-            // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2872
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2873
-        }
2874
-        //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that).
2875
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2876
-        $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2877
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2878
-        if (defined('DOING_AJAX')) {
2879
-            $default_data = array(
2880
-                    'close'        => true,
2881
-                    'redirect_url' => $redirect_url,
2882
-                    'where'        => 'main',
2883
-                    'what'         => 'append',
2884
-            );
2885
-            $this->_template_args['success'] = $success;
2886
-            $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data;
2887
-            $this->_return_json();
2888
-        }
2889
-        wp_safe_redirect($redirect_url);
2890
-        exit();
2891
-    }
2892
-
2893
-
2894
-
2895
-    /**
2896
-     * process any notices before redirecting (or returning ajax request)
2897
-     * This method sets the $this->_template_args['notices'] attribute;
2898
-     *
2899
-     * @param  array $query_args        any query args that need to be used for notice transient ('action')
2900
-     * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2901
-     * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice.
2902
-     * @return void
2903
-     */
2904
-    protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
2905
-    {
2906
-        //first let's set individual error properties if doing_ajax and the properties aren't already set.
2907
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2908
-            $notices = EE_Error::get_notices(false);
2909
-            if (empty($this->_template_args['success'])) {
2910
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
2911
-            }
2912
-            if (empty($this->_template_args['errors'])) {
2913
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
2914
-            }
2915
-            if (empty($this->_template_args['attention'])) {
2916
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
2917
-            }
2918
-        }
2919
-        $this->_template_args['notices'] = EE_Error::get_notices();
2920
-        //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2921
-        if ( ! defined('DOING_AJAX') || $sticky_notices) {
2922
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
2923
-            $this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify);
2924
-        }
2925
-    }
2926
-
2927
-
2928
-
2929
-    /**
2930
-     * get_action_link_or_button
2931
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
2932
-     *
2933
-     * @param string $action        use this to indicate which action the url is generated with.
2934
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key) property.
2935
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
2936
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
2937
-     * @param string $base_url      If this is not provided
2938
-     *                              the _admin_base_url will be used as the default for the button base_url.
2939
-     *                              Otherwise this value will be used.
2940
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
2941
-     * @return string
2942
-     * @throws \EE_Error
2943
-     */
2944
-    public function get_action_link_or_button(
2945
-            $action,
2946
-            $type = 'add',
2947
-            $extra_request = array(),
2948
-            $class = 'button-primary',
2949
-            $base_url = '',
2950
-            $exclude_nonce = false
2951
-    ) {
2952
-        //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
2953
-        if (empty($base_url) && ! isset($this->_page_routes[$action])) {
2954
-            throw new EE_Error(
2955
-                    sprintf(
2956
-                            __(
2957
-                                    'There is no page route for given action for the button.  This action was given: %s',
2958
-                                    'event_espresso'
2959
-                            ),
2960
-                            $action
2961
-                    )
2962
-            );
2963
-        }
2964
-        if ( ! isset($this->_labels['buttons'][$type])) {
2965
-            throw new EE_Error(
2966
-                    sprintf(
2967
-                            __(
2968
-                                    'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
2969
-                                    'event_espresso'
2970
-                            ),
2971
-                            $type
2972
-                    )
2973
-            );
2974
-        }
2975
-        //finally check user access for this button.
2976
-        $has_access = $this->check_user_access($action, true);
2977
-        if ( ! $has_access) {
2978
-            return '';
2979
-        }
2980
-        $_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
2981
-        $query_args = array(
2982
-                'action' => $action,
2983
-        );
2984
-        //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
2985
-        if ( ! empty($extra_request)) {
2986
-            $query_args = array_merge($extra_request, $query_args);
2987
-        }
2988
-        $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
2989
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
2990
-    }
2991
-
2992
-
2993
-
2994
-    /**
2995
-     * _per_page_screen_option
2996
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
2997
-     *
2998
-     * @return void
2999
-     */
3000
-    protected function _per_page_screen_option()
3001
-    {
3002
-        $option = 'per_page';
3003
-        $args = array(
3004
-                'label'   => $this->_admin_page_title,
3005
-                'default' => 10,
3006
-                'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3007
-        );
3008
-        //ONLY add the screen option if the user has access to it.
3009
-        if ($this->check_user_access($this->_current_view, true)) {
3010
-            add_screen_option($option, $args);
3011
-        }
3012
-    }
3013
-
3014
-
3015
-
3016
-    /**
3017
-     * set_per_page_screen_option
3018
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3019
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
3020
-     *
3021
-     * @access private
3022
-     * @return void
3023
-     */
3024
-    private function _set_per_page_screen_options()
3025
-    {
3026
-        if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3027
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3028
-            if ( ! $user = wp_get_current_user()) {
3029
-                return;
3030
-            }
3031
-            $option = $_POST['wp_screen_options']['option'];
3032
-            $value = $_POST['wp_screen_options']['value'];
3033
-            if ($option != sanitize_key($option)) {
3034
-                return;
3035
-            }
3036
-            $map_option = $option;
3037
-            $option = str_replace('-', '_', $option);
3038
-            switch ($map_option) {
3039
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3040
-                    $value = (int)$value;
3041
-                    if ($value < 1 || $value > 999) {
3042
-                        return;
3043
-                    }
3044
-                    break;
3045
-                default:
3046
-                    $value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value);
3047
-                    if (false === $value) {
3048
-                        return;
3049
-                    }
3050
-                    break;
3051
-            }
3052
-            update_user_meta($user->ID, $option, $value);
3053
-            wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3054
-            exit;
3055
-        }
3056
-    }
3057
-
3058
-
3059
-
3060
-    /**
3061
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3062
-     *
3063
-     * @param array $data array that will be assigned to template args.
3064
-     */
3065
-    public function set_template_args($data)
3066
-    {
3067
-        $this->_template_args = array_merge($this->_template_args, (array)$data);
3068
-    }
3069
-
3070
-
3071
-
3072
-    /**
3073
-     * This makes available the WP transient system for temporarily moving data between routes
3074
-     *
3075
-     * @access protected
3076
-     * @param string $route             the route that should receive the transient
3077
-     * @param array  $data              the data that gets sent
3078
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3079
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used when we are adding a transient before page_routes have been defined.
3080
-     * @return void
3081
-     */
3082
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3083
-    {
3084
-        $user_id = get_current_user_id();
3085
-        if ( ! $skip_route_verify) {
3086
-            $this->_verify_route($route);
3087
-        }
3088
-        //now let's set the string for what kind of transient we're setting
3089
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3090
-        $data = $notices ? array('notices' => $data) : $data;
3091
-        //is there already a transient for this route?  If there is then let's ADD to that transient
3092
-        $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3093
-        if ($existing) {
3094
-            $data = array_merge((array)$data, (array)$existing);
3095
-        }
3096
-        if (is_multisite() && is_network_admin()) {
3097
-            set_site_transient($transient, $data, 8);
3098
-        } else {
3099
-            set_transient($transient, $data, 8);
3100
-        }
3101
-    }
3102
-
3103
-
3104
-
3105
-    /**
3106
-     * this retrieves the temporary transient that has been set for moving data between routes.
3107
-     *
3108
-     * @param bool $notices true we get notices transient. False we just return normal route transient
3109
-     * @return mixed data
3110
-     */
3111
-    protected function _get_transient($notices = false, $route = false)
3112
-    {
3113
-        $user_id = get_current_user_id();
3114
-        $route = ! $route ? $this->_req_action : $route;
3115
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3116
-        $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3117
-        //delete transient after retrieval (just in case it hasn't expired);
3118
-        if (is_multisite() && is_network_admin()) {
3119
-            delete_site_transient($transient);
3120
-        } else {
3121
-            delete_transient($transient);
3122
-        }
3123
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3124
-    }
3125
-
3126
-
3127
-
3128
-    /**
3129
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later.
3130
-     * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.)
3131
-     *
3132
-     * @return void
3133
-     */
3134
-    protected function _transient_garbage_collection()
3135
-    {
3136
-        global $wpdb;
3137
-        //retrieve all existing transients
3138
-        $query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3139
-        if ($results = $wpdb->get_results($query)) {
3140
-            foreach ($results as $result) {
3141
-                $transient = str_replace('_transient_', '', $result->option_name);
3142
-                get_transient($transient);
3143
-                if (is_multisite() && is_network_admin()) {
3144
-                    get_site_transient($transient);
3145
-                }
3146
-            }
3147
-        }
3148
-    }
3149
-
3150
-
3151
-
3152
-    /**
3153
-     * get_view
3154
-     *
3155
-     * @access public
3156
-     * @return string content of _view property
3157
-     */
3158
-    public function get_view()
3159
-    {
3160
-        return $this->_view;
3161
-    }
3162
-
3163
-
3164
-
3165
-    /**
3166
-     * getter for the protected $_views property
3167
-     *
3168
-     * @return array
3169
-     */
3170
-    public function get_views()
3171
-    {
3172
-        return $this->_views;
3173
-    }
3174
-
3175
-
3176
-
3177
-    /**
3178
-     * get_current_page
3179
-     *
3180
-     * @access public
3181
-     * @return string _current_page property value
3182
-     */
3183
-    public function get_current_page()
3184
-    {
3185
-        return $this->_current_page;
3186
-    }
3187
-
3188
-
3189
-
3190
-    /**
3191
-     * get_current_view
3192
-     *
3193
-     * @access public
3194
-     * @return string _current_view property value
3195
-     */
3196
-    public function get_current_view()
3197
-    {
3198
-        return $this->_current_view;
3199
-    }
3200
-
3201
-
3202
-
3203
-    /**
3204
-     * get_current_screen
3205
-     *
3206
-     * @access public
3207
-     * @return object The current WP_Screen object
3208
-     */
3209
-    public function get_current_screen()
3210
-    {
3211
-        return $this->_current_screen;
3212
-    }
3213
-
3214
-
3215
-
3216
-    /**
3217
-     * get_current_page_view_url
3218
-     *
3219
-     * @access public
3220
-     * @return string This returns the url for the current_page_view.
3221
-     */
3222
-    public function get_current_page_view_url()
3223
-    {
3224
-        return $this->_current_page_view_url;
3225
-    }
3226
-
3227
-
3228
-
3229
-    /**
3230
-     * just returns the _req_data property
3231
-     *
3232
-     * @return array
3233
-     */
3234
-    public function get_request_data()
3235
-    {
3236
-        return $this->_req_data;
3237
-    }
3238
-
3239
-
3240
-
3241
-    /**
3242
-     * returns the _req_data protected property
3243
-     *
3244
-     * @return string
3245
-     */
3246
-    public function get_req_action()
3247
-    {
3248
-        return $this->_req_action;
3249
-    }
3250
-
3251
-
3252
-
3253
-    /**
3254
-     * @return bool  value of $_is_caf property
3255
-     */
3256
-    public function is_caf()
3257
-    {
3258
-        return $this->_is_caf;
3259
-    }
3260
-
3261
-
3262
-
3263
-    /**
3264
-     * @return mixed
3265
-     */
3266
-    public function default_espresso_metaboxes()
3267
-    {
3268
-        return $this->_default_espresso_metaboxes;
3269
-    }
3270
-
3271
-
3272
-
3273
-    /**
3274
-     * @return mixed
3275
-     */
3276
-    public function admin_base_url()
3277
-    {
3278
-        return $this->_admin_base_url;
3279
-    }
3280
-
3281
-
3282
-
3283
-    /**
3284
-     * @return mixed
3285
-     */
3286
-    public function wp_page_slug()
3287
-    {
3288
-        return $this->_wp_page_slug;
3289
-    }
3290
-
3291
-
3292
-
3293
-    /**
3294
-     * updates  espresso configuration settings
3295
-     *
3296
-     * @access    protected
3297
-     * @param string                   $tab
3298
-     * @param EE_Config_Base|EE_Config $config
3299
-     * @param string                   $file file where error occurred
3300
-     * @param string                   $func function  where error occurred
3301
-     * @param string                   $line line no where error occurred
3302
-     * @return boolean
3303
-     */
3304
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3305
-    {
3306
-        //remove any options that are NOT going to be saved with the config settings.
3307
-        if (isset($config->core->ee_ueip_optin)) {
3308
-            $config->core->ee_ueip_has_notified = true;
3309
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
3310
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3311
-            update_option('ee_ueip_has_notified', true);
3312
-        }
3313
-        // and save it (note we're also doing the network save here)
3314
-        $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
3315
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
3316
-        if ($config_saved && $net_saved) {
3317
-            EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3318
-            return true;
3319
-        } else {
3320
-            EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3321
-            return false;
3322
-        }
3323
-    }
3324
-
3325
-
3326
-
3327
-    /**
3328
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3329
-     *
3330
-     * @return array
3331
-     */
3332
-    public function get_yes_no_values()
3333
-    {
3334
-        return $this->_yes_no_values;
3335
-    }
3336
-
3337
-
3338
-
3339
-    protected function _get_dir()
3340
-    {
3341
-        $reflector = new ReflectionClass(get_class($this));
3342
-        return dirname($reflector->getFileName());
3343
-    }
3344
-
3345
-
3346
-
3347
-    /**
3348
-     * A helper for getting a "next link".
3349
-     *
3350
-     * @param string $url   The url to link to
3351
-     * @param string $class The class to use.
3352
-     * @return string
3353
-     */
3354
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3355
-    {
3356
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3357
-    }
3358
-
3359
-
3360
-
3361
-    /**
3362
-     * A helper for getting a "previous link".
3363
-     *
3364
-     * @param string $url   The url to link to
3365
-     * @param string $class The class to use.
3366
-     * @return string
3367
-     */
3368
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3369
-    {
3370
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3371
-    }
3372
-
3373
-
3374
-
3375
-
3376
-
3377
-
3378
-
3379
-    //below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3380
-    /**
3381
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the _req_data
3382
-     * array.
3383
-     *
3384
-     * @return bool success/fail
3385
-     */
3386
-    protected function _process_resend_registration()
3387
-    {
3388
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3389
-        do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
3390
-        return $this->_template_args['success'];
3391
-    }
3392
-
3393
-
3394
-
3395
-    /**
3396
-     * This automatically processes any payment message notifications when manual payment has been applied.
3397
-     *
3398
-     * @access protected
3399
-     * @param \EE_Payment $payment
3400
-     * @return bool success/fail
3401
-     */
3402
-    protected function _process_payment_notification(EE_Payment $payment)
3403
-    {
3404
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3405
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3406
-        $this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment);
3407
-        return $this->_template_args['success'];
3408
-    }
2194
+	}
2195
+
2196
+
2197
+
2198
+	/**
2199
+	 * facade for add_meta_box
2200
+	 *
2201
+	 * @param string  $action        where the metabox get's displayed
2202
+	 * @param string  $title         Title of Metabox (output in metabox header)
2203
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here.
2204
+	 * @param array   $callback_args an array of args supplied for the metabox
2205
+	 * @param string  $column        what metabox column
2206
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2207
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box.
2208
+	 */
2209
+	public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true)
2210
+	{
2211
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2212
+		//if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2213
+		if (empty($callback_args) && $create_func) {
2214
+			$callback_args = array(
2215
+					'template_path' => $this->_template_path,
2216
+					'template_args' => $this->_template_args,
2217
+			);
2218
+		}
2219
+		//if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2220
+		$call_back_func = $create_func ? create_function('$post, $metabox',
2221
+				'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2222
+		add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2223
+	}
2224
+
2225
+
2226
+
2227
+	/**
2228
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2229
+	 *
2230
+	 * @return [type] [description]
2231
+	 */
2232
+	public function display_admin_page_with_metabox_columns()
2233
+	{
2234
+		$this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2235
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true);
2236
+		//the final wrapper
2237
+		$this->admin_page_wrapper();
2238
+	}
2239
+
2240
+
2241
+
2242
+	/**
2243
+	 *        generates  HTML wrapper for an admin details page
2244
+	 *
2245
+	 * @access public
2246
+	 * @return void
2247
+	 */
2248
+	public function display_admin_page_with_sidebar()
2249
+	{
2250
+		$this->_display_admin_page(true);
2251
+	}
2252
+
2253
+
2254
+
2255
+	/**
2256
+	 *        generates  HTML wrapper for an admin details page (except no sidebar)
2257
+	 *
2258
+	 * @access public
2259
+	 * @return void
2260
+	 */
2261
+	public function display_admin_page_with_no_sidebar()
2262
+	{
2263
+		$this->_display_admin_page();
2264
+	}
2265
+
2266
+
2267
+
2268
+	/**
2269
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2270
+	 *
2271
+	 * @access public
2272
+	 * @return void
2273
+	 */
2274
+	public function display_about_admin_page()
2275
+	{
2276
+		$this->_display_admin_page(false, true);
2277
+	}
2278
+
2279
+
2280
+
2281
+	/**
2282
+	 * display_admin_page
2283
+	 * contains the code for actually displaying an admin page
2284
+	 *
2285
+	 * @access private
2286
+	 * @param  boolean $sidebar true with sidebar, false without
2287
+	 * @param  boolean $about   use the about admin wrapper instead of the default.
2288
+	 * @return void
2289
+	 */
2290
+	private function _display_admin_page($sidebar = false, $about = false)
2291
+	{
2292
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2293
+		//custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2294
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2295
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2296
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2297
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2298
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2299
+				? 'poststuff'
2300
+				: 'espresso-default-admin';
2301
+		$template_path = $sidebar
2302
+				? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2303
+				: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2304
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2305
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2306
+		}
2307
+		$template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2308
+		$this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
2309
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '';
2310
+		$this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '';
2311
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2312
+		// the final template wrapper
2313
+		$this->admin_page_wrapper($about);
2314
+	}
2315
+
2316
+
2317
+
2318
+	/**
2319
+	 * This is used to display caf preview pages.
2320
+	 *
2321
+	 * @since 4.3.2
2322
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2323
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2324
+	 * @return void
2325
+	 * @throws \EE_Error
2326
+	 */
2327
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2328
+	{
2329
+		//let's generate a default preview action button if there isn't one already present.
2330
+		$this->_labels['buttons']['buy_now'] = __('Upgrade to Event Espresso 4 Right Now', 'event_espresso');
2331
+		$buy_now_url = add_query_arg(
2332
+				array(
2333
+						'ee_ver'       => 'ee4',
2334
+						'utm_source'   => 'ee4_plugin_admin',
2335
+						'utm_medium'   => 'link',
2336
+						'utm_campaign' => $utm_campaign_source,
2337
+						'utm_content'  => 'buy_now_button',
2338
+				),
2339
+				'http://eventespresso.com/pricing/'
2340
+		);
2341
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2342
+				? $this->get_action_link_or_button(
2343
+						'',
2344
+						'buy_now',
2345
+						array(),
2346
+						'button-primary button-large',
2347
+						$buy_now_url,
2348
+						true
2349
+				)
2350
+				: $this->_template_args['preview_action_button'];
2351
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2352
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2353
+				$template_path,
2354
+				$this->_template_args,
2355
+				true
2356
+		);
2357
+		$this->_display_admin_page($display_sidebar);
2358
+	}
2359
+
2360
+
2361
+
2362
+	/**
2363
+	 * display_admin_list_table_page_with_sidebar
2364
+	 * generates HTML wrapper for an admin_page with list_table
2365
+	 *
2366
+	 * @access public
2367
+	 * @return void
2368
+	 */
2369
+	public function display_admin_list_table_page_with_sidebar()
2370
+	{
2371
+		$this->_display_admin_list_table_page(true);
2372
+	}
2373
+
2374
+
2375
+
2376
+	/**
2377
+	 * display_admin_list_table_page_with_no_sidebar
2378
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2379
+	 *
2380
+	 * @access public
2381
+	 * @return void
2382
+	 */
2383
+	public function display_admin_list_table_page_with_no_sidebar()
2384
+	{
2385
+		$this->_display_admin_list_table_page();
2386
+	}
2387
+
2388
+
2389
+
2390
+	/**
2391
+	 * generates html wrapper for an admin_list_table page
2392
+	 *
2393
+	 * @access private
2394
+	 * @param boolean $sidebar whether to display with sidebar or not.
2395
+	 * @return void
2396
+	 */
2397
+	private function _display_admin_list_table_page($sidebar = false)
2398
+	{
2399
+		//setup search attributes
2400
+		$this->_set_search_attributes();
2401
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2402
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2403
+		$this->_template_args['table_url'] = defined('DOING_AJAX')
2404
+				? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2405
+				: add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2406
+		$this->_template_args['list_table'] = $this->_list_table_object;
2407
+		$this->_template_args['current_route'] = $this->_req_action;
2408
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2409
+		$ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2410
+		if ( ! empty($ajax_sorting_callback)) {
2411
+			$sortable_list_table_form_fields = wp_nonce_field(
2412
+					$ajax_sorting_callback . '_nonce',
2413
+					$ajax_sorting_callback . '_nonce',
2414
+					false,
2415
+					false
2416
+			);
2417
+			//			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2418
+			//			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2419
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2420
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2421
+		} else {
2422
+			$sortable_list_table_form_fields = '';
2423
+		}
2424
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2425
+		$hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2426
+		$nonce_ref = $this->_req_action . '_nonce';
2427
+		$hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2428
+		$this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2429
+		//display message about search results?
2430
+		$this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
2431
+				? '<p class="ee-search-results">' . sprintf(
2432
+						esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2433
+						trim($this->_req_data['s'], '%')
2434
+				) . '</p>'
2435
+				: '';
2436
+		// filter before_list_table template arg
2437
+		$this->_template_args['before_list_table'] = apply_filters(
2438
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2439
+			$this->_template_args['before_list_table'],
2440
+			$this->page_slug,
2441
+			$this->_req_data,
2442
+			$this->_req_action
2443
+		);
2444
+		// convert to array and filter again
2445
+		// arrays are easier to inject new items in a specific location,
2446
+		// but would not be backwards compatible, so we have to add a new filter
2447
+		$this->_template_args['before_list_table'] = implode(
2448
+			" \n",
2449
+			(array) apply_filters(
2450
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2451
+				(array) $this->_template_args['before_list_table'],
2452
+				$this->page_slug,
2453
+				$this->_req_data,
2454
+				$this->_req_action
2455
+			)
2456
+		);
2457
+		// filter after_list_table template arg
2458
+		$this->_template_args['after_list_table'] = apply_filters(
2459
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2460
+			$this->_template_args['after_list_table'],
2461
+			$this->page_slug,
2462
+			$this->_req_data,
2463
+			$this->_req_action
2464
+		);
2465
+		// convert to array and filter again
2466
+		// arrays are easier to inject new items in a specific location,
2467
+		// but would not be backwards compatible, so we have to add a new filter
2468
+		$this->_template_args['after_list_table'] = implode(
2469
+			" \n",
2470
+			(array) apply_filters(
2471
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2472
+				(array) $this->_template_args['after_list_table'],
2473
+				$this->page_slug,
2474
+				$this->_req_data,
2475
+				$this->_req_action
2476
+			)
2477
+		);
2478
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2479
+				$template_path,
2480
+				$this->_template_args,
2481
+				true
2482
+		);
2483
+		// the final template wrapper
2484
+		if ($sidebar) {
2485
+			$this->display_admin_page_with_sidebar();
2486
+		} else {
2487
+			$this->display_admin_page_with_no_sidebar();
2488
+		}
2489
+	}
2490
+
2491
+
2492
+
2493
+	/**
2494
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend.
2495
+	 * $items are expected in an array in the following format:
2496
+	 * $legend_items = array(
2497
+	 *        'item_id' => array(
2498
+	 *            'icon' => 'http://url_to_icon_being_described.png',
2499
+	 *            'desc' => __('localized description of item');
2500
+	 *        )
2501
+	 * );
2502
+	 *
2503
+	 * @param  array $items see above for format of array
2504
+	 * @return string        html string of legend
2505
+	 */
2506
+	protected function _display_legend($items)
2507
+	{
2508
+		$this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2509
+		$legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2510
+		return EEH_Template::display_template($legend_template, $this->_template_args, true);
2511
+	}
2512
+
2513
+
2514
+
2515
+	/**
2516
+	 * this is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2517
+	 *
2518
+	 * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2519
+	 *                             The returned json object is created from an array in the following format:
2520
+	 *                             array(
2521
+	 *                             'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2522
+	 *                             'success' => FALSE, //(default FALSE) - contains any special success message.
2523
+	 *                             'notices' => '', // - contains any EE_Error formatted notices
2524
+	 *                             'content' => 'string can be html', //this is a string of formatted content (can be html)
2525
+	 *                             'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any
2526
+	 *                             specific template args that might be included in here)
2527
+	 *                             )
2528
+	 *                             The json object is populated by whatever is set in the $_template_args property.
2529
+	 * @return void
2530
+	 */
2531
+	protected function _return_json($sticky_notices = false)
2532
+	{
2533
+		//make sure any EE_Error notices have been handled.
2534
+		$this->_process_notices(array(), true, $sticky_notices);
2535
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
2536
+		unset($this->_template_args['data']);
2537
+		$json = array(
2538
+				'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2539
+				'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2540
+				'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2541
+				'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2542
+				'notices'   => EE_Error::get_notices(),
2543
+				'content'   => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '',
2544
+				'data'      => array_merge($data, array('template_args' => $this->_template_args)),
2545
+				'isEEajax'  => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2546
+		);
2547
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
2548
+		if (null === error_get_last() || ! headers_sent()) {
2549
+			header('Content-Type: application/json; charset=UTF-8');
2550
+		}
2551
+		echo wp_json_encode($json);
2552
+
2553
+		exit();
2554
+	}
2555
+
2556
+
2557
+
2558
+	/**
2559
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2560
+	 *
2561
+	 * @return void
2562
+	 * @throws EE_Error
2563
+	 */
2564
+	public function return_json()
2565
+	{
2566
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2567
+			$this->_return_json();
2568
+		} else {
2569
+			throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__));
2570
+		}
2571
+	}
2572
+
2573
+
2574
+
2575
+	/**
2576
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
2577
+	 *
2578
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
2579
+	 * @access   public
2580
+	 */
2581
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
2582
+	{
2583
+		$this->_hook_obj = $hook_obj;
2584
+	}
2585
+
2586
+
2587
+
2588
+	/**
2589
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
2590
+	 *
2591
+	 * @access public
2592
+	 * @param  boolean $about whether to use the special about page wrapper or default.
2593
+	 * @return void
2594
+	 */
2595
+	public function admin_page_wrapper($about = false)
2596
+	{
2597
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2598
+		$this->_nav_tabs = $this->_get_main_nav_tabs();
2599
+		$this->_template_args['nav_tabs'] = $this->_nav_tabs;
2600
+		$this->_template_args['admin_page_title'] = $this->_admin_page_title;
2601
+		$this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2602
+				isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2603
+		$this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2604
+				isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2605
+		$this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2606
+		// load settings page wrapper template
2607
+		$template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2608
+		//about page?
2609
+		$template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2610
+		if (defined('DOING_AJAX')) {
2611
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2612
+			$this->_return_json();
2613
+		} else {
2614
+			EEH_Template::display_template($template_path, $this->_template_args);
2615
+		}
2616
+	}
2617
+
2618
+
2619
+
2620
+	/**
2621
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2622
+	 *
2623
+	 * @return string html
2624
+	 */
2625
+	protected function _get_main_nav_tabs()
2626
+	{
2627
+		//let's generate the html using the EEH_Tabbed_Content helper.  We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array)
2628
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
2629
+	}
2630
+
2631
+
2632
+
2633
+	/**
2634
+	 *        sort nav tabs
2635
+	 *
2636
+	 * @access public
2637
+	 * @param $a
2638
+	 * @param $b
2639
+	 * @return int
2640
+	 */
2641
+	private function _sort_nav_tabs($a, $b)
2642
+	{
2643
+		if ($a['order'] == $b['order']) {
2644
+			return 0;
2645
+		}
2646
+		return ($a['order'] < $b['order']) ? -1 : 1;
2647
+	}
2648
+
2649
+
2650
+
2651
+	/**
2652
+	 *    generates HTML for the forms used on admin pages
2653
+	 *
2654
+	 * @access protected
2655
+	 * @param    array $input_vars - array of input field details
2656
+	 * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to use)
2657
+	 * @return string
2658
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2659
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2660
+	 */
2661
+	protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
2662
+	{
2663
+		$content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2664
+		return $content;
2665
+	}
2666
+
2667
+
2668
+
2669
+	/**
2670
+	 * generates the "Save" and "Save & Close" buttons for edit forms
2671
+	 *
2672
+	 * @access protected
2673
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save & Close" button.
2674
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2675
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button).  We can also use this to just dump default actions by submitting some other value.
2676
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling).
2677
+	 */
2678
+	protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2679
+	{
2680
+		//make sure $text and $actions are in an array
2681
+		$text = (array)$text;
2682
+		$actions = (array)$actions;
2683
+		$referrer_url = empty($referrer) ? '' : $referrer;
2684
+		$referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2685
+				: '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2686
+		$button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2687
+		$default_names = array('save', 'save_and_close');
2688
+		//add in a hidden index for the current page (so save and close redirects properly)
2689
+		$this->_template_args['save_buttons'] = $referrer_url;
2690
+		foreach ($button_text as $key => $button) {
2691
+			$ref = $default_names[$key];
2692
+			$id = $this->_current_view . '_' . $ref;
2693
+			$name = ! empty($actions) ? $actions[$key] : $ref;
2694
+			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2695
+			if ( ! $both) {
2696
+				break;
2697
+			}
2698
+		}
2699
+	}
2700
+
2701
+
2702
+
2703
+	/**
2704
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2705
+	 *
2706
+	 * @see   $this->_set_add_edit_form_tags() for details on params
2707
+	 * @since 4.6.0
2708
+	 * @param string $route
2709
+	 * @param array  $additional_hidden_fields
2710
+	 */
2711
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2712
+	{
2713
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
2714
+	}
2715
+
2716
+
2717
+
2718
+	/**
2719
+	 * set form open and close tags on add/edit pages.
2720
+	 *
2721
+	 * @access protected
2722
+	 * @param string $route                    the route you want the form to direct to
2723
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
2724
+	 * @return void
2725
+	 */
2726
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2727
+	{
2728
+		if (empty($route)) {
2729
+			$user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2730
+			$dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2731
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2732
+		}
2733
+		// open form
2734
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2735
+		// add nonce
2736
+		$nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2737
+		//		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2738
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2739
+		// add REQUIRED form action
2740
+		$hidden_fields = array(
2741
+				'action' => array('type' => 'hidden', 'value' => $route),
2742
+		);
2743
+		// merge arrays
2744
+		$hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields;
2745
+		// generate form fields
2746
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2747
+		// add fields to form
2748
+		foreach ((array)$form_fields as $field_name => $form_field) {
2749
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2750
+		}
2751
+		// close form
2752
+		$this->_template_args['after_admin_page_content'] = '</form>';
2753
+	}
2754
+
2755
+
2756
+
2757
+	/**
2758
+	 * Public Wrapper for _redirect_after_action() method since its
2759
+	 * discovered it would be useful for external code to have access.
2760
+	 *
2761
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
2762
+	 * @since 4.5.0
2763
+	 */
2764
+	public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2765
+	{
2766
+		$this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite);
2767
+	}
2768
+
2769
+
2770
+
2771
+	/**
2772
+	 *    _redirect_after_action
2773
+	 *
2774
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
2775
+	 * @param string $what               - what the action was performed on
2776
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
2777
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin action is completed
2778
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2779
+	 * @access protected
2780
+	 * @return void
2781
+	 */
2782
+	protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2783
+	{
2784
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2785
+		//class name for actions/filters.
2786
+		$classname = get_class($this);
2787
+		//set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url
2788
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
2789
+		$notices = EE_Error::get_notices(false);
2790
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
2791
+		if ( ! $override_overwrite || ! empty($notices['errors'])) {
2792
+			EE_Error::overwrite_success();
2793
+		}
2794
+		if ( ! empty($what) && ! empty($action_desc)) {
2795
+			// how many records affected ? more than one record ? or just one ?
2796
+			if ($success > 1 && empty($notices['errors'])) {
2797
+				// set plural msg
2798
+				EE_Error::add_success(
2799
+						sprintf(
2800
+								__('The "%s" have been successfully %s.', 'event_espresso'),
2801
+								$what,
2802
+								$action_desc
2803
+						),
2804
+						__FILE__, __FUNCTION__, __LINE__
2805
+				);
2806
+			} else if ($success == 1 && empty($notices['errors'])) {
2807
+				// set singular msg
2808
+				EE_Error::add_success(
2809
+						sprintf(
2810
+								__('The "%s" has been successfully %s.', 'event_espresso'),
2811
+								$what,
2812
+								$action_desc
2813
+						),
2814
+						__FILE__, __FUNCTION__, __LINE__
2815
+				);
2816
+			}
2817
+		}
2818
+		// check that $query_args isn't something crazy
2819
+		if ( ! is_array($query_args)) {
2820
+			$query_args = array();
2821
+		}
2822
+		/**
2823
+		 * Allow injecting actions before the query_args are modified for possible different
2824
+		 * redirections on save and close actions
2825
+		 *
2826
+		 * @since 4.2.0
2827
+		 * @param array $query_args       The original query_args array coming into the
2828
+		 *                                method.
2829
+		 */
2830
+		do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2831
+		//calculate where we're going (if we have a "save and close" button pushed)
2832
+		if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2833
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2834
+			$parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
2835
+			// regenerate query args array from referrer URL
2836
+			parse_str($parsed_url['query'], $query_args);
2837
+			// correct page and action will be in the query args now
2838
+			$redirect_url = admin_url('admin.php');
2839
+		}
2840
+		//merge any default query_args set in _default_route_query_args property
2841
+		if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
2842
+			$args_to_merge = array();
2843
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
2844
+				//is there a wp_referer array in our _default_route_query_args property?
2845
+				if ($query_param == 'wp_referer') {
2846
+					$query_value = (array)$query_value;
2847
+					foreach ($query_value as $reference => $value) {
2848
+						if (strpos($reference, 'nonce') !== false) {
2849
+							continue;
2850
+						}
2851
+						//finally we will override any arguments in the referer with
2852
+						//what might be set on the _default_route_query_args array.
2853
+						if (isset($this->_default_route_query_args[$reference])) {
2854
+							$args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
2855
+						} else {
2856
+							$args_to_merge[$reference] = urlencode($value);
2857
+						}
2858
+					}
2859
+					continue;
2860
+				}
2861
+				$args_to_merge[$query_param] = $query_value;
2862
+			}
2863
+			//now let's merge these arguments but override with what was specifically sent in to the
2864
+			//redirect.
2865
+			$query_args = array_merge($args_to_merge, $query_args);
2866
+		}
2867
+		$this->_process_notices($query_args);
2868
+		// generate redirect url
2869
+		// if redirecting to anything other than the main page, add a nonce
2870
+		if (isset($query_args['action'])) {
2871
+			// manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2872
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2873
+		}
2874
+		//we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that).
2875
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2876
+		$redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2877
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2878
+		if (defined('DOING_AJAX')) {
2879
+			$default_data = array(
2880
+					'close'        => true,
2881
+					'redirect_url' => $redirect_url,
2882
+					'where'        => 'main',
2883
+					'what'         => 'append',
2884
+			);
2885
+			$this->_template_args['success'] = $success;
2886
+			$this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data;
2887
+			$this->_return_json();
2888
+		}
2889
+		wp_safe_redirect($redirect_url);
2890
+		exit();
2891
+	}
2892
+
2893
+
2894
+
2895
+	/**
2896
+	 * process any notices before redirecting (or returning ajax request)
2897
+	 * This method sets the $this->_template_args['notices'] attribute;
2898
+	 *
2899
+	 * @param  array $query_args        any query args that need to be used for notice transient ('action')
2900
+	 * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2901
+	 * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice.
2902
+	 * @return void
2903
+	 */
2904
+	protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
2905
+	{
2906
+		//first let's set individual error properties if doing_ajax and the properties aren't already set.
2907
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2908
+			$notices = EE_Error::get_notices(false);
2909
+			if (empty($this->_template_args['success'])) {
2910
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
2911
+			}
2912
+			if (empty($this->_template_args['errors'])) {
2913
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
2914
+			}
2915
+			if (empty($this->_template_args['attention'])) {
2916
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
2917
+			}
2918
+		}
2919
+		$this->_template_args['notices'] = EE_Error::get_notices();
2920
+		//IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2921
+		if ( ! defined('DOING_AJAX') || $sticky_notices) {
2922
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
2923
+			$this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify);
2924
+		}
2925
+	}
2926
+
2927
+
2928
+
2929
+	/**
2930
+	 * get_action_link_or_button
2931
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
2932
+	 *
2933
+	 * @param string $action        use this to indicate which action the url is generated with.
2934
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key) property.
2935
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
2936
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
2937
+	 * @param string $base_url      If this is not provided
2938
+	 *                              the _admin_base_url will be used as the default for the button base_url.
2939
+	 *                              Otherwise this value will be used.
2940
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
2941
+	 * @return string
2942
+	 * @throws \EE_Error
2943
+	 */
2944
+	public function get_action_link_or_button(
2945
+			$action,
2946
+			$type = 'add',
2947
+			$extra_request = array(),
2948
+			$class = 'button-primary',
2949
+			$base_url = '',
2950
+			$exclude_nonce = false
2951
+	) {
2952
+		//first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
2953
+		if (empty($base_url) && ! isset($this->_page_routes[$action])) {
2954
+			throw new EE_Error(
2955
+					sprintf(
2956
+							__(
2957
+									'There is no page route for given action for the button.  This action was given: %s',
2958
+									'event_espresso'
2959
+							),
2960
+							$action
2961
+					)
2962
+			);
2963
+		}
2964
+		if ( ! isset($this->_labels['buttons'][$type])) {
2965
+			throw new EE_Error(
2966
+					sprintf(
2967
+							__(
2968
+									'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
2969
+									'event_espresso'
2970
+							),
2971
+							$type
2972
+					)
2973
+			);
2974
+		}
2975
+		//finally check user access for this button.
2976
+		$has_access = $this->check_user_access($action, true);
2977
+		if ( ! $has_access) {
2978
+			return '';
2979
+		}
2980
+		$_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
2981
+		$query_args = array(
2982
+				'action' => $action,
2983
+		);
2984
+		//merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
2985
+		if ( ! empty($extra_request)) {
2986
+			$query_args = array_merge($extra_request, $query_args);
2987
+		}
2988
+		$url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
2989
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
2990
+	}
2991
+
2992
+
2993
+
2994
+	/**
2995
+	 * _per_page_screen_option
2996
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
2997
+	 *
2998
+	 * @return void
2999
+	 */
3000
+	protected function _per_page_screen_option()
3001
+	{
3002
+		$option = 'per_page';
3003
+		$args = array(
3004
+				'label'   => $this->_admin_page_title,
3005
+				'default' => 10,
3006
+				'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3007
+		);
3008
+		//ONLY add the screen option if the user has access to it.
3009
+		if ($this->check_user_access($this->_current_view, true)) {
3010
+			add_screen_option($option, $args);
3011
+		}
3012
+	}
3013
+
3014
+
3015
+
3016
+	/**
3017
+	 * set_per_page_screen_option
3018
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3019
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
3020
+	 *
3021
+	 * @access private
3022
+	 * @return void
3023
+	 */
3024
+	private function _set_per_page_screen_options()
3025
+	{
3026
+		if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3027
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3028
+			if ( ! $user = wp_get_current_user()) {
3029
+				return;
3030
+			}
3031
+			$option = $_POST['wp_screen_options']['option'];
3032
+			$value = $_POST['wp_screen_options']['value'];
3033
+			if ($option != sanitize_key($option)) {
3034
+				return;
3035
+			}
3036
+			$map_option = $option;
3037
+			$option = str_replace('-', '_', $option);
3038
+			switch ($map_option) {
3039
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3040
+					$value = (int)$value;
3041
+					if ($value < 1 || $value > 999) {
3042
+						return;
3043
+					}
3044
+					break;
3045
+				default:
3046
+					$value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value);
3047
+					if (false === $value) {
3048
+						return;
3049
+					}
3050
+					break;
3051
+			}
3052
+			update_user_meta($user->ID, $option, $value);
3053
+			wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3054
+			exit;
3055
+		}
3056
+	}
3057
+
3058
+
3059
+
3060
+	/**
3061
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3062
+	 *
3063
+	 * @param array $data array that will be assigned to template args.
3064
+	 */
3065
+	public function set_template_args($data)
3066
+	{
3067
+		$this->_template_args = array_merge($this->_template_args, (array)$data);
3068
+	}
3069
+
3070
+
3071
+
3072
+	/**
3073
+	 * This makes available the WP transient system for temporarily moving data between routes
3074
+	 *
3075
+	 * @access protected
3076
+	 * @param string $route             the route that should receive the transient
3077
+	 * @param array  $data              the data that gets sent
3078
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3079
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used when we are adding a transient before page_routes have been defined.
3080
+	 * @return void
3081
+	 */
3082
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3083
+	{
3084
+		$user_id = get_current_user_id();
3085
+		if ( ! $skip_route_verify) {
3086
+			$this->_verify_route($route);
3087
+		}
3088
+		//now let's set the string for what kind of transient we're setting
3089
+		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3090
+		$data = $notices ? array('notices' => $data) : $data;
3091
+		//is there already a transient for this route?  If there is then let's ADD to that transient
3092
+		$existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3093
+		if ($existing) {
3094
+			$data = array_merge((array)$data, (array)$existing);
3095
+		}
3096
+		if (is_multisite() && is_network_admin()) {
3097
+			set_site_transient($transient, $data, 8);
3098
+		} else {
3099
+			set_transient($transient, $data, 8);
3100
+		}
3101
+	}
3102
+
3103
+
3104
+
3105
+	/**
3106
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3107
+	 *
3108
+	 * @param bool $notices true we get notices transient. False we just return normal route transient
3109
+	 * @return mixed data
3110
+	 */
3111
+	protected function _get_transient($notices = false, $route = false)
3112
+	{
3113
+		$user_id = get_current_user_id();
3114
+		$route = ! $route ? $this->_req_action : $route;
3115
+		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3116
+		$data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3117
+		//delete transient after retrieval (just in case it hasn't expired);
3118
+		if (is_multisite() && is_network_admin()) {
3119
+			delete_site_transient($transient);
3120
+		} else {
3121
+			delete_transient($transient);
3122
+		}
3123
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3124
+	}
3125
+
3126
+
3127
+
3128
+	/**
3129
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later.
3130
+	 * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.)
3131
+	 *
3132
+	 * @return void
3133
+	 */
3134
+	protected function _transient_garbage_collection()
3135
+	{
3136
+		global $wpdb;
3137
+		//retrieve all existing transients
3138
+		$query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3139
+		if ($results = $wpdb->get_results($query)) {
3140
+			foreach ($results as $result) {
3141
+				$transient = str_replace('_transient_', '', $result->option_name);
3142
+				get_transient($transient);
3143
+				if (is_multisite() && is_network_admin()) {
3144
+					get_site_transient($transient);
3145
+				}
3146
+			}
3147
+		}
3148
+	}
3149
+
3150
+
3151
+
3152
+	/**
3153
+	 * get_view
3154
+	 *
3155
+	 * @access public
3156
+	 * @return string content of _view property
3157
+	 */
3158
+	public function get_view()
3159
+	{
3160
+		return $this->_view;
3161
+	}
3162
+
3163
+
3164
+
3165
+	/**
3166
+	 * getter for the protected $_views property
3167
+	 *
3168
+	 * @return array
3169
+	 */
3170
+	public function get_views()
3171
+	{
3172
+		return $this->_views;
3173
+	}
3174
+
3175
+
3176
+
3177
+	/**
3178
+	 * get_current_page
3179
+	 *
3180
+	 * @access public
3181
+	 * @return string _current_page property value
3182
+	 */
3183
+	public function get_current_page()
3184
+	{
3185
+		return $this->_current_page;
3186
+	}
3187
+
3188
+
3189
+
3190
+	/**
3191
+	 * get_current_view
3192
+	 *
3193
+	 * @access public
3194
+	 * @return string _current_view property value
3195
+	 */
3196
+	public function get_current_view()
3197
+	{
3198
+		return $this->_current_view;
3199
+	}
3200
+
3201
+
3202
+
3203
+	/**
3204
+	 * get_current_screen
3205
+	 *
3206
+	 * @access public
3207
+	 * @return object The current WP_Screen object
3208
+	 */
3209
+	public function get_current_screen()
3210
+	{
3211
+		return $this->_current_screen;
3212
+	}
3213
+
3214
+
3215
+
3216
+	/**
3217
+	 * get_current_page_view_url
3218
+	 *
3219
+	 * @access public
3220
+	 * @return string This returns the url for the current_page_view.
3221
+	 */
3222
+	public function get_current_page_view_url()
3223
+	{
3224
+		return $this->_current_page_view_url;
3225
+	}
3226
+
3227
+
3228
+
3229
+	/**
3230
+	 * just returns the _req_data property
3231
+	 *
3232
+	 * @return array
3233
+	 */
3234
+	public function get_request_data()
3235
+	{
3236
+		return $this->_req_data;
3237
+	}
3238
+
3239
+
3240
+
3241
+	/**
3242
+	 * returns the _req_data protected property
3243
+	 *
3244
+	 * @return string
3245
+	 */
3246
+	public function get_req_action()
3247
+	{
3248
+		return $this->_req_action;
3249
+	}
3250
+
3251
+
3252
+
3253
+	/**
3254
+	 * @return bool  value of $_is_caf property
3255
+	 */
3256
+	public function is_caf()
3257
+	{
3258
+		return $this->_is_caf;
3259
+	}
3260
+
3261
+
3262
+
3263
+	/**
3264
+	 * @return mixed
3265
+	 */
3266
+	public function default_espresso_metaboxes()
3267
+	{
3268
+		return $this->_default_espresso_metaboxes;
3269
+	}
3270
+
3271
+
3272
+
3273
+	/**
3274
+	 * @return mixed
3275
+	 */
3276
+	public function admin_base_url()
3277
+	{
3278
+		return $this->_admin_base_url;
3279
+	}
3280
+
3281
+
3282
+
3283
+	/**
3284
+	 * @return mixed
3285
+	 */
3286
+	public function wp_page_slug()
3287
+	{
3288
+		return $this->_wp_page_slug;
3289
+	}
3290
+
3291
+
3292
+
3293
+	/**
3294
+	 * updates  espresso configuration settings
3295
+	 *
3296
+	 * @access    protected
3297
+	 * @param string                   $tab
3298
+	 * @param EE_Config_Base|EE_Config $config
3299
+	 * @param string                   $file file where error occurred
3300
+	 * @param string                   $func function  where error occurred
3301
+	 * @param string                   $line line no where error occurred
3302
+	 * @return boolean
3303
+	 */
3304
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3305
+	{
3306
+		//remove any options that are NOT going to be saved with the config settings.
3307
+		if (isset($config->core->ee_ueip_optin)) {
3308
+			$config->core->ee_ueip_has_notified = true;
3309
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
3310
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3311
+			update_option('ee_ueip_has_notified', true);
3312
+		}
3313
+		// and save it (note we're also doing the network save here)
3314
+		$net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
3315
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
3316
+		if ($config_saved && $net_saved) {
3317
+			EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3318
+			return true;
3319
+		} else {
3320
+			EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3321
+			return false;
3322
+		}
3323
+	}
3324
+
3325
+
3326
+
3327
+	/**
3328
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3329
+	 *
3330
+	 * @return array
3331
+	 */
3332
+	public function get_yes_no_values()
3333
+	{
3334
+		return $this->_yes_no_values;
3335
+	}
3336
+
3337
+
3338
+
3339
+	protected function _get_dir()
3340
+	{
3341
+		$reflector = new ReflectionClass(get_class($this));
3342
+		return dirname($reflector->getFileName());
3343
+	}
3344
+
3345
+
3346
+
3347
+	/**
3348
+	 * A helper for getting a "next link".
3349
+	 *
3350
+	 * @param string $url   The url to link to
3351
+	 * @param string $class The class to use.
3352
+	 * @return string
3353
+	 */
3354
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3355
+	{
3356
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3357
+	}
3358
+
3359
+
3360
+
3361
+	/**
3362
+	 * A helper for getting a "previous link".
3363
+	 *
3364
+	 * @param string $url   The url to link to
3365
+	 * @param string $class The class to use.
3366
+	 * @return string
3367
+	 */
3368
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3369
+	{
3370
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3371
+	}
3372
+
3373
+
3374
+
3375
+
3376
+
3377
+
3378
+
3379
+	//below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3380
+	/**
3381
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the _req_data
3382
+	 * array.
3383
+	 *
3384
+	 * @return bool success/fail
3385
+	 */
3386
+	protected function _process_resend_registration()
3387
+	{
3388
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3389
+		do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
3390
+		return $this->_template_args['success'];
3391
+	}
3392
+
3393
+
3394
+
3395
+	/**
3396
+	 * This automatically processes any payment message notifications when manual payment has been applied.
3397
+	 *
3398
+	 * @access protected
3399
+	 * @param \EE_Payment $payment
3400
+	 * @return bool success/fail
3401
+	 */
3402
+	protected function _process_payment_notification(EE_Payment $payment)
3403
+	{
3404
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3405
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3406
+		$this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment);
3407
+		return $this->_template_args['success'];
3408
+	}
3409 3409
 
3410 3410
 
3411 3411
 }
Please login to merge, or discard this patch.
Spacing   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
         $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
475 475
         $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
476 476
         global $ee_menu_slugs;
477
-        $ee_menu_slugs = (array)$ee_menu_slugs;
477
+        $ee_menu_slugs = (array) $ee_menu_slugs;
478 478
         if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
479 479
             return;
480 480
         }
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
         //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
490 490
         $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
491 491
         $this->_current_view = $this->_req_action;
492
-        $this->_req_nonce = $this->_req_action . '_nonce';
492
+        $this->_req_nonce = $this->_req_action.'_nonce';
493 493
         $this->_define_page_props();
494 494
         $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
495 495
         //default things
@@ -510,11 +510,11 @@  discard block
 block discarded – undo
510 510
             $this->_extend_page_config_for_cpt();
511 511
         }
512 512
         //filter routes and page_config so addons can add their stuff. Filtering done per class
513
-        $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
514
-        $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
513
+        $this->_page_routes = apply_filters('FHEE__'.get_class($this).'__page_setup__page_routes', $this->_page_routes, $this);
514
+        $this->_page_config = apply_filters('FHEE__'.get_class($this).'__page_setup__page_config', $this->_page_config, $this);
515 515
         //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
516
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
517
-            add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
516
+        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) {
517
+            add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view), 10, 2);
518 518
         }
519 519
         //next route only if routing enabled
520 520
         if ($this->_routing && ! defined('DOING_AJAX')) {
@@ -524,8 +524,8 @@  discard block
 block discarded – undo
524 524
             if ($this->_is_UI_request) {
525 525
                 //admin_init stuff - global, all views for this page class, specific view
526 526
                 add_action('admin_init', array($this, 'admin_init'), 10);
527
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
528
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
527
+                if (method_exists($this, 'admin_init_'.$this->_current_view)) {
528
+                    add_action('admin_init', array($this, 'admin_init_'.$this->_current_view), 15);
529 529
                 }
530 530
             } else {
531 531
                 //hijack regular WP loading and route admin request immediately
@@ -545,17 +545,17 @@  discard block
 block discarded – undo
545 545
      */
546 546
     private function _do_other_page_hooks()
547 547
     {
548
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
548
+        $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, array());
549 549
         foreach ($registered_pages as $page) {
550 550
             //now let's setup the file name and class that should be present
551 551
             $classname = str_replace('.class.php', '', $page);
552 552
             //autoloaders should take care of loading file
553 553
             if ( ! class_exists($classname)) {
554
-                $error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
554
+                $error_msg[] = sprintf(esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
555 555
                 $error_msg[] = $error_msg[0]
556 556
                                . "\r\n"
557
-                               . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
558
-                                'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
557
+                               . sprintf(esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
558
+                                'event_espresso'), $page, '<br />', '<strong>'.$classname.'</strong>');
559 559
                 throw new EE_Error(implode('||', $error_msg));
560 560
             }
561 561
             $a = new ReflectionClass($classname);
@@ -591,13 +591,13 @@  discard block
 block discarded – undo
591 591
         //load admin_notices - global, page class, and view specific
592 592
         add_action('admin_notices', array($this, 'admin_notices_global'), 5);
593 593
         add_action('admin_notices', array($this, 'admin_notices'), 10);
594
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
595
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
594
+        if (method_exists($this, 'admin_notices_'.$this->_current_view)) {
595
+            add_action('admin_notices', array($this, 'admin_notices_'.$this->_current_view), 15);
596 596
         }
597 597
         //load network admin_notices - global, page class, and view specific
598 598
         add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
599
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
600
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
599
+        if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) {
600
+            add_action('network_admin_notices', array($this, 'network_admin_notices_'.$this->_current_view));
601 601
         }
602 602
         //this will save any per_page screen options if they are present
603 603
         $this->_set_per_page_screen_options();
@@ -609,8 +609,8 @@  discard block
 block discarded – undo
609 609
         //add screen options - global, page child class, and view specific
610 610
         $this->_add_global_screen_options();
611 611
         $this->_add_screen_options();
612
-        if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
613
-            call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
612
+        if (method_exists($this, '_add_screen_options_'.$this->_current_view)) {
613
+            call_user_func(array($this, '_add_screen_options_'.$this->_current_view));
614 614
         }
615 615
         //add help tab(s) and tours- set via page_config and qtips.
616 616
         $this->_add_help_tour();
@@ -619,31 +619,31 @@  discard block
 block discarded – undo
619 619
         //add feature_pointers - global, page child class, and view specific
620 620
         $this->_add_feature_pointers();
621 621
         $this->_add_global_feature_pointers();
622
-        if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
623
-            call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
622
+        if (method_exists($this, '_add_feature_pointer_'.$this->_current_view)) {
623
+            call_user_func(array($this, '_add_feature_pointer_'.$this->_current_view));
624 624
         }
625 625
         //enqueue scripts/styles - global, page class, and view specific
626 626
         add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
627 627
         add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
628
-        if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
629
-            add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
628
+        if (method_exists($this, 'load_scripts_styles_'.$this->_current_view)) {
629
+            add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_'.$this->_current_view), 15);
630 630
         }
631 631
         add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
632 632
         //admin_print_footer_scripts - global, page child class, and view specific.  NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.  In most cases that's doing_it_wrong().  But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these
633 633
         add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
634 634
         add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
635
-        if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
636
-            add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
635
+        if (method_exists($this, 'admin_footer_scripts_'.$this->_current_view)) {
636
+            add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_'.$this->_current_view), 101);
637 637
         }
638 638
         //admin footer scripts
639 639
         add_action('admin_footer', array($this, 'admin_footer_global'), 99);
640 640
         add_action('admin_footer', array($this, 'admin_footer'), 100);
641
-        if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
642
-            add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
641
+        if (method_exists($this, 'admin_footer_'.$this->_current_view)) {
642
+            add_action('admin_footer', array($this, 'admin_footer_'.$this->_current_view), 101);
643 643
         }
644 644
         do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
645 645
         //targeted hook
646
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
646
+        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__'.$this->page_slug.'__'.$this->_req_action);
647 647
     }
648 648
 
649 649
 
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
             // user error msg
720 720
             $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
721 721
             // developer error msg
722
-            $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
722
+            $error_msg .= '||'.$error_msg.__(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
723 723
             throw new EE_Error($error_msg);
724 724
         }
725 725
         // and that the requested page route exists
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
             // user error msg
731 731
             $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
732 732
             // developer error msg
733
-            $error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
733
+            $error_msg .= '||'.$error_msg.sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
734 734
             throw new EE_Error($error_msg);
735 735
         }
736 736
         // and that a default route exists
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
             // user error msg
739 739
             $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
740 740
             // developer error msg
741
-            $error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
741
+            $error_msg .= '||'.$error_msg.__(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
742 742
             throw new EE_Error($error_msg);
743 743
         }
744 744
         //first lets' catch if the UI request has EVER been set.
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
             // user error msg
768 768
             $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
769 769
             // developer error msg
770
-            $error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
770
+            $error_msg .= '||'.$error_msg.sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
771 771
             throw new EE_Error($error_msg);
772 772
         }
773 773
     }
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
             // these are not the droids you are looking for !!!
790 790
             $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
791 791
             if (WP_DEBUG) {
792
-                $msg .= "\n  " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
792
+                $msg .= "\n  ".sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
793 793
             }
794 794
             if ( ! defined('DOING_AJAX')) {
795 795
                 wp_die($msg);
@@ -967,7 +967,7 @@  discard block
 block discarded – undo
967 967
                 if (strpos($key, 'nonce') !== false) {
968 968
                     continue;
969 969
                 }
970
-                $args['wp_referer[' . $key . ']'] = $value;
970
+                $args['wp_referer['.$key.']'] = $value;
971 971
             }
972 972
         }
973 973
         return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
@@ -1013,7 +1013,7 @@  discard block
 block discarded – undo
1013 1013
                     if ($tour instanceof EE_Help_Tour_final_stop) {
1014 1014
                         continue;
1015 1015
                     }
1016
-                    $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1016
+                    $tb[] = '<button id="trigger-tour-'.$tour->get_slug().'" class="button-primary trigger-ee-help-tour">'.$tour->get_label().'</button>';
1017 1017
                 }
1018 1018
                 $tour_buttons .= implode('<br />', $tb);
1019 1019
                 $tour_buttons .= '</div></div>';
@@ -1025,7 +1025,7 @@  discard block
 block discarded – undo
1025 1025
                     throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1026 1026
                             'event_espresso'), $config['help_sidebar'], get_class($this)));
1027 1027
                 }
1028
-                $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1028
+                $content = apply_filters('FHEE__'.get_class($this).'__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1029 1029
                 $content .= $tour_buttons; //add help tour buttons.
1030 1030
                 //do we have any help tours setup?  Cause if we do we want to add the buttons
1031 1031
                 $this->_current_screen->set_help_sidebar($content);
@@ -1038,13 +1038,13 @@  discard block
 block discarded – undo
1038 1038
             if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1039 1039
                 $_ht['id'] = $this->page_slug;
1040 1040
                 $_ht['title'] = __('Help Tours', 'event_espresso');
1041
-                $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1041
+                $_ht['content'] = '<p>'.__('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso').'</p>';
1042 1042
                 $this->_current_screen->add_help_tab($_ht);
1043 1043
             }/**/
1044 1044
             if ( ! isset($config['help_tabs'])) {
1045 1045
                 return;
1046 1046
             } //no help tabs for this route
1047
-            foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1047
+            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1048 1048
                 //we're here so there ARE help tabs!
1049 1049
                 //make sure we've got what we need
1050 1050
                 if ( ! isset($cfg['title'])) {
@@ -1059,9 +1059,9 @@  discard block
 block discarded – undo
1059 1059
                     $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1060 1060
                     //second priority goes to filename
1061 1061
                 } else if ( ! empty($cfg['filename'])) {
1062
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1062
+                    $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php';
1063 1063
                     //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1064
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1064
+                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES.basename($this->_get_dir()).'/help_tabs/'.$cfg['filename'].'.help_tab.php' : $file_path;
1065 1065
                     //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1066 1066
                     if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1067 1067
                         EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
@@ -1080,7 +1080,7 @@  discard block
 block discarded – undo
1080 1080
                     return;
1081 1081
                 }
1082 1082
                 //setup config array for help tab method
1083
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1083
+                $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id;
1084 1084
                 $_ht = array(
1085 1085
                         'id'       => $id,
1086 1086
                         'title'    => $cfg['title'],
@@ -1118,9 +1118,9 @@  discard block
 block discarded – undo
1118 1118
             }
1119 1119
             if (isset($config['help_tour'])) {
1120 1120
                 foreach ($config['help_tour'] as $tour) {
1121
-                    $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1121
+                    $file_path = $this->_get_dir().'/help_tours/'.$tour.'.class.php';
1122 1122
                     //let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent
1123
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1123
+                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES.basename($this->_get_dir()).'/help_tours/'.$tour.'.class.php' : $file_path;
1124 1124
                     //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1125 1125
                     if ( ! is_readable($file_path)) {
1126 1126
                         EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'),
@@ -1130,7 +1130,7 @@  discard block
 block discarded – undo
1130 1130
                     require_once $file_path;
1131 1131
                     if ( ! class_exists($tour)) {
1132 1132
                         $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1133
-                        $error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1133
+                        $error_msg[] = $error_msg[0]."\r\n".sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1134 1134
                                         'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1135 1135
                         throw new EE_Error(implode('||', $error_msg));
1136 1136
                     }
@@ -1162,11 +1162,11 @@  discard block
 block discarded – undo
1162 1162
     protected function _add_qtips()
1163 1163
     {
1164 1164
         if (isset($this->_route_config['qtips'])) {
1165
-            $qtips = (array)$this->_route_config['qtips'];
1165
+            $qtips = (array) $this->_route_config['qtips'];
1166 1166
             //load qtip loader
1167 1167
             $path = array(
1168
-                    $this->_get_dir() . '/qtips/',
1169
-                    EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1168
+                    $this->_get_dir().'/qtips/',
1169
+                    EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/',
1170 1170
             );
1171 1171
             EEH_Qtip_Loader::instance()->register($qtips, $path);
1172 1172
         }
@@ -1196,11 +1196,11 @@  discard block
 block discarded – undo
1196 1196
             if ( ! $this->check_user_access($slug, true)) {
1197 1197
                 continue;
1198 1198
             } //no nav tab becasue current user does not have access.
1199
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1199
+            $css_class = isset($config['css_class']) ? $config['css_class'].' ' : '';
1200 1200
             $this->_nav_tabs[$slug] = array(
1201 1201
                     'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1202 1202
                     'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1203
-                    'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1203
+                    'css_class' => $this->_req_action == $slug ? $css_class.'nav-tab-active' : $css_class,
1204 1204
                     'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1205 1205
             );
1206 1206
             $i++;
@@ -1263,11 +1263,11 @@  discard block
 block discarded – undo
1263 1263
             $capability = empty($capability) ? 'manage_options' : $capability;
1264 1264
         }
1265 1265
         $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1266
-        if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1266
+        if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug.'_'.$route_to_check, $id)) && ! defined('DOING_AJAX')) {
1267 1267
             if ($verify_only) {
1268 1268
                 return false;
1269 1269
             } else {
1270
-                if ( is_user_logged_in() ) {
1270
+                if (is_user_logged_in()) {
1271 1271
                     wp_die(__('You do not have access to this route.', 'event_espresso'));
1272 1272
                 } else {
1273 1273
                     return false;
@@ -1359,7 +1359,7 @@  discard block
 block discarded – undo
1359 1359
     public function admin_footer_global()
1360 1360
     {
1361 1361
         //dialog container for dialog helper
1362
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1362
+        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">'."\n";
1363 1363
         $d_cont .= '<div class="ee-notices"></div>';
1364 1364
         $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1365 1365
         $d_cont .= '</div>';
@@ -1369,7 +1369,7 @@  discard block
 block discarded – undo
1369 1369
             echo implode('<br />', $this->_help_tour[$this->_req_action]);
1370 1370
         }
1371 1371
         //current set timezone for timezone js
1372
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1372
+        echo '<span id="current_timezone" class="hidden">'.EEH_DTT_Helper::get_timezone().'</span>';
1373 1373
     }
1374 1374
 
1375 1375
 
@@ -1394,7 +1394,7 @@  discard block
 block discarded – undo
1394 1394
     {
1395 1395
         $content = '';
1396 1396
         $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1397
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1397
+        $template_path = EE_ADMIN_TEMPLATE.'admin_help_popup.template.php';
1398 1398
         //loop through the array and setup content
1399 1399
         foreach ($help_array as $trigger => $help) {
1400 1400
             //make sure the array is setup properly
@@ -1428,7 +1428,7 @@  discard block
 block discarded – undo
1428 1428
     private function _get_help_content()
1429 1429
     {
1430 1430
         //what is the method we're looking for?
1431
-        $method_name = '_help_popup_content_' . $this->_req_action;
1431
+        $method_name = '_help_popup_content_'.$this->_req_action;
1432 1432
         //if method doesn't exist let's get out.
1433 1433
         if ( ! method_exists($this, $method_name)) {
1434 1434
             return array();
@@ -1472,8 +1472,8 @@  discard block
 block discarded – undo
1472 1472
             $help_content = $this->_set_help_popup_content($help_array, false);
1473 1473
         }
1474 1474
         //let's setup the trigger
1475
-        $content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1476
-        $content = $content . $help_content;
1475
+        $content = '<a class="ee-dialog" href="?height='.$dimensions[0].'&width='.$dimensions[1].'&inlineId='.$trigger_id.'" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1476
+        $content = $content.$help_content;
1477 1477
         if ($display) {
1478 1478
             echo $content;
1479 1479
         } else {
@@ -1533,27 +1533,27 @@  discard block
 block discarded – undo
1533 1533
             add_action('admin_head', array($this, 'add_xdebug_style'));
1534 1534
         }
1535 1535
         // register all styles
1536
-        wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1537
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1536
+        wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1537
+        wp_register_style('ee-admin-css', EE_ADMIN_URL.'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1538 1538
         //helpers styles
1539
-        wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1539
+        wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1540 1540
         /** SCRIPTS **/
1541 1541
         //register all scripts
1542
-        wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1543
-        wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1544
-        wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1542
+        wp_register_script('ee-dialog', EE_ADMIN_URL.'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1543
+        wp_register_script('ee_admin_js', EE_ADMIN_URL.'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1544
+        wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL.'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1545 1545
         add_filter('FHEE_load_joyride', '__return_true');
1546 1546
         //script for sorting tables
1547
-        wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1547
+        wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL."assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1548 1548
         //script for parsing uri's
1549
-        wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1549
+        wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1550 1550
         //and parsing associative serialized form elements
1551
-        wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1551
+        wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1552 1552
         //helpers scripts
1553
-        wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1554
-        wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1555
-        wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1556
-        wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1553
+        wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1554
+        wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1555
+        wp_register_script('ee-moment', EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1556
+        wp_register_script('ee-datepicker', EE_ADMIN_URL.'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1557 1557
         //google charts
1558 1558
         wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1559 1559
         // ENQUEUE ALL BASICS BY DEFAULT
@@ -1577,7 +1577,7 @@  discard block
 block discarded – undo
1577 1577
          */
1578 1578
         if ( ! empty($this->_help_tour)) {
1579 1579
             //register the js for kicking things off
1580
-            wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1580
+            wp_enqueue_script('ee-help-tour', EE_ADMIN_URL.'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1581 1581
             //setup tours for the js tour object
1582 1582
             foreach ($this->_help_tour['tours'] as $tour) {
1583 1583
                 $tours[] = array(
@@ -1672,17 +1672,17 @@  discard block
 block discarded – undo
1672 1672
             return;
1673 1673
         } //not a list_table view so get out.
1674 1674
         //list table functions are per view specific (because some admin pages might have more than one listtable!)
1675
-        if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1675
+        if (call_user_func(array($this, '_set_list_table_views_'.$this->_req_action)) === false) {
1676 1676
             //user error msg
1677 1677
             $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1678 1678
             //developer error msg
1679
-            $error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'),
1680
-                            $this->_req_action, '_set_list_table_views_' . $this->_req_action);
1679
+            $error_msg .= '||'.sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'),
1680
+                            $this->_req_action, '_set_list_table_views_'.$this->_req_action);
1681 1681
             throw new EE_Error($error_msg);
1682 1682
         }
1683 1683
         //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1684
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1685
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1684
+        $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action, $this->_views);
1685
+        $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views);
1686 1686
         $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1687 1687
         $this->_set_list_table_view();
1688 1688
         $this->_set_list_table_object();
@@ -1757,7 +1757,7 @@  discard block
 block discarded – undo
1757 1757
             // check for current view
1758 1758
             $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1759 1759
             $query_args['action'] = $this->_req_action;
1760
-            $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1760
+            $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce');
1761 1761
             $query_args['status'] = $view['slug'];
1762 1762
             //merge any other arguments sent in.
1763 1763
             if (isset($extra_query_args[$view['slug']])) {
@@ -1795,14 +1795,14 @@  discard block
 block discarded – undo
1795 1795
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
1796 1796
         foreach ($values as $value) {
1797 1797
             if ($value < $max_entries) {
1798
-                $selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1798
+                $selected = $value == $per_page ? ' selected="'.$per_page.'"' : '';
1799 1799
                 $entries_per_page_dropdown .= '
1800
-						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
1800
+						<option value="' . $value.'"'.$selected.'>'.$value.'&nbsp;&nbsp;</option>';
1801 1801
             }
1802 1802
         }
1803
-        $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1803
+        $selected = $max_entries == $per_page ? ' selected="'.$per_page.'"' : '';
1804 1804
         $entries_per_page_dropdown .= '
1805
-						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
1805
+						<option value="' . $max_entries.'"'.$selected.'>All&nbsp;&nbsp;</option>';
1806 1806
         $entries_per_page_dropdown .= '
1807 1807
 					</select>
1808 1808
 					entries
@@ -1824,7 +1824,7 @@  discard block
 block discarded – undo
1824 1824
     public function _set_search_attributes()
1825 1825
     {
1826 1826
         $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1827
-        $this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1827
+        $this->_template_args['search']['callback'] = 'search_'.$this->page_slug;
1828 1828
     }
1829 1829
 
1830 1830
     /*** END LIST TABLE METHODS **/
@@ -1862,7 +1862,7 @@  discard block
 block discarded – undo
1862 1862
                     // user error msg
1863 1863
                     $error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1864 1864
                     // developer error msg
1865
-                    $error_msg .= '||' . sprintf(
1865
+                    $error_msg .= '||'.sprintf(
1866 1866
                                     __(
1867 1867
                                             'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
1868 1868
                                             'event_espresso'
@@ -1892,15 +1892,15 @@  discard block
 block discarded – undo
1892 1892
                 && is_array($this->_route_config['columns'])
1893 1893
                 && count($this->_route_config['columns']) === 2
1894 1894
         ) {
1895
-            add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1895
+            add_screen_option('layout_columns', array('max' => (int) $this->_route_config['columns'][0], 'default' => (int) $this->_route_config['columns'][1]));
1896 1896
             $this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1897 1897
             $screen_id = $this->_current_screen->id;
1898
-            $screen_columns = (int)get_user_option("screen_layout_$screen_id");
1898
+            $screen_columns = (int) get_user_option("screen_layout_$screen_id");
1899 1899
             $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1900
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1900
+            $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns;
1901 1901
             $this->_template_args['current_page'] = $this->_wp_page_slug;
1902 1902
             $this->_template_args['screen'] = $this->_current_screen;
1903
-            $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1903
+            $this->_column_template_path = EE_ADMIN_TEMPLATE.'admin_details_metabox_column_wrapper.template.php';
1904 1904
             //finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
1905 1905
             $this->_route_config['has_metaboxes'] = true;
1906 1906
         }
@@ -1947,7 +1947,7 @@  discard block
 block discarded – undo
1947 1947
      */
1948 1948
     public function espresso_ratings_request()
1949 1949
     {
1950
-        $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1950
+        $template_path = EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php';
1951 1951
         EEH_Template::display_template($template_path, array());
1952 1952
     }
1953 1953
 
@@ -1955,18 +1955,18 @@  discard block
 block discarded – undo
1955 1955
 
1956 1956
     public static function cached_rss_display($rss_id, $url)
1957 1957
     {
1958
-        $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1958
+        $loading = '<p class="widget-loading hide-if-no-js">'.__('Loading&#8230;').'</p><p class="hide-if-js">'.__('This widget requires JavaScript.').'</p>';
1959 1959
         $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1960
-        $pre = '<div class="espresso-rss-display">' . "\n\t";
1961
-        $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1962
-        $post = '</div>' . "\n";
1963
-        $cache_key = 'ee_rss_' . md5($rss_id);
1960
+        $pre = '<div class="espresso-rss-display">'."\n\t";
1961
+        $pre .= '<span id="'.$rss_id.'_url" class="hidden">'.$url.'</span>';
1962
+        $post = '</div>'."\n";
1963
+        $cache_key = 'ee_rss_'.md5($rss_id);
1964 1964
         if (false != ($output = get_transient($cache_key))) {
1965
-            echo $pre . $output . $post;
1965
+            echo $pre.$output.$post;
1966 1966
             return true;
1967 1967
         }
1968 1968
         if ( ! $doing_ajax) {
1969
-            echo $pre . $loading . $post;
1969
+            echo $pre.$loading.$post;
1970 1970
             return false;
1971 1971
         }
1972 1972
         ob_start();
@@ -2025,7 +2025,7 @@  discard block
 block discarded – undo
2025 2025
 
2026 2026
     public function espresso_sponsors_post_box()
2027 2027
     {
2028
-        $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2028
+        $templatepath = EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php';
2029 2029
         EEH_Template::display_template($templatepath);
2030 2030
     }
2031 2031
 
@@ -2033,7 +2033,7 @@  discard block
 block discarded – undo
2033 2033
 
2034 2034
     private function _publish_post_box()
2035 2035
     {
2036
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2036
+        $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview';
2037 2037
         //if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label.  Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2038 2038
         if ( ! empty($this->_labels['publishbox'])) {
2039 2039
             $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
@@ -2050,7 +2050,7 @@  discard block
 block discarded – undo
2050 2050
     {
2051 2051
         //if we have extra content set let's add it in if not make sure its empty
2052 2052
         $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2053
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2053
+        $template_path = EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php';
2054 2054
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2055 2055
     }
2056 2056
 
@@ -2219,7 +2219,7 @@  discard block
 block discarded – undo
2219 2219
         //if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2220 2220
         $call_back_func = $create_func ? create_function('$post, $metabox',
2221 2221
                 'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2222
-        add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2222
+        add_meta_box(str_replace('_', '-', $action).'-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2223 2223
     }
2224 2224
 
2225 2225
 
@@ -2299,10 +2299,10 @@  discard block
 block discarded – undo
2299 2299
                 ? 'poststuff'
2300 2300
                 : 'espresso-default-admin';
2301 2301
         $template_path = $sidebar
2302
-                ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2303
-                : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2302
+                ? EE_ADMIN_TEMPLATE.'admin_details_wrapper.template.php'
2303
+                : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php';
2304 2304
         if (defined('DOING_AJAX') && DOING_AJAX) {
2305
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2305
+            $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php';
2306 2306
         }
2307 2307
         $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2308 2308
         $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
@@ -2348,7 +2348,7 @@  discard block
 block discarded – undo
2348 2348
                         true
2349 2349
                 )
2350 2350
                 : $this->_template_args['preview_action_button'];
2351
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2351
+        $template_path = EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php';
2352 2352
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2353 2353
                 $template_path,
2354 2354
                 $this->_template_args,
@@ -2399,7 +2399,7 @@  discard block
 block discarded – undo
2399 2399
         //setup search attributes
2400 2400
         $this->_set_search_attributes();
2401 2401
         $this->_template_args['current_page'] = $this->_wp_page_slug;
2402
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2402
+        $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php';
2403 2403
         $this->_template_args['table_url'] = defined('DOING_AJAX')
2404 2404
                 ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2405 2405
                 : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
@@ -2409,29 +2409,29 @@  discard block
 block discarded – undo
2409 2409
         $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2410 2410
         if ( ! empty($ajax_sorting_callback)) {
2411 2411
             $sortable_list_table_form_fields = wp_nonce_field(
2412
-                    $ajax_sorting_callback . '_nonce',
2413
-                    $ajax_sorting_callback . '_nonce',
2412
+                    $ajax_sorting_callback.'_nonce',
2413
+                    $ajax_sorting_callback.'_nonce',
2414 2414
                     false,
2415 2415
                     false
2416 2416
             );
2417 2417
             //			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2418 2418
             //			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2419
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2420
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2419
+            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'.$this->page_slug.'" />';
2420
+            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'.$ajax_sorting_callback.'" />';
2421 2421
         } else {
2422 2422
             $sortable_list_table_form_fields = '';
2423 2423
         }
2424 2424
         $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2425 2425
         $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2426
-        $nonce_ref = $this->_req_action . '_nonce';
2427
-        $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2426
+        $nonce_ref = $this->_req_action.'_nonce';
2427
+        $hidden_form_fields .= '<input type="hidden" name="'.$nonce_ref.'" value="'.wp_create_nonce($nonce_ref).'">';
2428 2428
         $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2429 2429
         //display message about search results?
2430 2430
         $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
2431
-                ? '<p class="ee-search-results">' . sprintf(
2431
+                ? '<p class="ee-search-results">'.sprintf(
2432 2432
                         esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2433 2433
                         trim($this->_req_data['s'], '%')
2434
-                ) . '</p>'
2434
+                ).'</p>'
2435 2435
                 : '';
2436 2436
         // filter before_list_table template arg
2437 2437
         $this->_template_args['before_list_table'] = apply_filters(
@@ -2505,8 +2505,8 @@  discard block
 block discarded – undo
2505 2505
      */
2506 2506
     protected function _display_legend($items)
2507 2507
     {
2508
-        $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2509
-        $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2508
+        $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array) $items, $this);
2509
+        $legend_template = EE_ADMIN_TEMPLATE.'admin_details_legend.template.php';
2510 2510
         return EEH_Template::display_template($legend_template, $this->_template_args, true);
2511 2511
     }
2512 2512
 
@@ -2598,15 +2598,15 @@  discard block
 block discarded – undo
2598 2598
         $this->_nav_tabs = $this->_get_main_nav_tabs();
2599 2599
         $this->_template_args['nav_tabs'] = $this->_nav_tabs;
2600 2600
         $this->_template_args['admin_page_title'] = $this->_admin_page_title;
2601
-        $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2601
+        $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content'.$this->_current_page.$this->_current_view,
2602 2602
                 isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2603
-        $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2603
+        $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content'.$this->_current_page.$this->_current_view,
2604 2604
                 isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2605 2605
         $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2606 2606
         // load settings page wrapper template
2607
-        $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2607
+        $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE.'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php';
2608 2608
         //about page?
2609
-        $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2609
+        $template_path = $about ? EE_ADMIN_TEMPLATE.'about_admin_wrapper.template.php' : $template_path;
2610 2610
         if (defined('DOING_AJAX')) {
2611 2611
             $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2612 2612
             $this->_return_json();
@@ -2678,20 +2678,20 @@  discard block
 block discarded – undo
2678 2678
     protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2679 2679
     {
2680 2680
         //make sure $text and $actions are in an array
2681
-        $text = (array)$text;
2682
-        $actions = (array)$actions;
2681
+        $text = (array) $text;
2682
+        $actions = (array) $actions;
2683 2683
         $referrer_url = empty($referrer) ? '' : $referrer;
2684
-        $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2685
-                : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2684
+        $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'.$_SERVER['REQUEST_URI'].'" />'
2685
+                : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'.$referrer.'" />';
2686 2686
         $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2687 2687
         $default_names = array('save', 'save_and_close');
2688 2688
         //add in a hidden index for the current page (so save and close redirects properly)
2689 2689
         $this->_template_args['save_buttons'] = $referrer_url;
2690 2690
         foreach ($button_text as $key => $button) {
2691 2691
             $ref = $default_names[$key];
2692
-            $id = $this->_current_view . '_' . $ref;
2692
+            $id = $this->_current_view.'_'.$ref;
2693 2693
             $name = ! empty($actions) ? $actions[$key] : $ref;
2694
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2694
+            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '.$ref.'" value="'.$button.'" name="'.$name.'" id="'.$id.'" />';
2695 2695
             if ( ! $both) {
2696 2696
                 break;
2697 2697
             }
@@ -2727,15 +2727,15 @@  discard block
 block discarded – undo
2727 2727
     {
2728 2728
         if (empty($route)) {
2729 2729
             $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2730
-            $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2731
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2730
+            $dev_msg = $user_msg."\n".sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2731
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
2732 2732
         }
2733 2733
         // open form
2734
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2734
+        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'.$this->_admin_base_url.'" id="'.$route.'_event_form" >';
2735 2735
         // add nonce
2736
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2736
+        $nonce = wp_nonce_field($route.'_nonce', $route.'_nonce', false, false);
2737 2737
         //		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2738
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2738
+        $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce;
2739 2739
         // add REQUIRED form action
2740 2740
         $hidden_fields = array(
2741 2741
                 'action' => array('type' => 'hidden', 'value' => $route),
@@ -2745,8 +2745,8 @@  discard block
 block discarded – undo
2745 2745
         // generate form fields
2746 2746
         $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2747 2747
         // add fields to form
2748
-        foreach ((array)$form_fields as $field_name => $form_field) {
2749
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2748
+        foreach ((array) $form_fields as $field_name => $form_field) {
2749
+            $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field'];
2750 2750
         }
2751 2751
         // close form
2752 2752
         $this->_template_args['after_admin_page_content'] = '</form>';
@@ -2827,7 +2827,7 @@  discard block
 block discarded – undo
2827 2827
          * @param array $query_args       The original query_args array coming into the
2828 2828
          *                                method.
2829 2829
          */
2830
-        do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2830
+        do_action('AHEE__'.$classname.'___redirect_after_action__before_redirect_modification_'.$this->_req_action, $query_args);
2831 2831
         //calculate where we're going (if we have a "save and close" button pushed)
2832 2832
         if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2833 2833
             // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
@@ -2843,7 +2843,7 @@  discard block
 block discarded – undo
2843 2843
             foreach ($this->_default_route_query_args as $query_param => $query_value) {
2844 2844
                 //is there a wp_referer array in our _default_route_query_args property?
2845 2845
                 if ($query_param == 'wp_referer') {
2846
-                    $query_value = (array)$query_value;
2846
+                    $query_value = (array) $query_value;
2847 2847
                     foreach ($query_value as $reference => $value) {
2848 2848
                         if (strpos($reference, 'nonce') !== false) {
2849 2849
                             continue;
@@ -2869,11 +2869,11 @@  discard block
 block discarded – undo
2869 2869
         // if redirecting to anything other than the main page, add a nonce
2870 2870
         if (isset($query_args['action'])) {
2871 2871
             // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2872
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2872
+            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce');
2873 2873
         }
2874 2874
         //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that).
2875
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2876
-        $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2875
+        do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args);
2876
+        $redirect_url = apply_filters('FHEE_redirect_'.$classname.$this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2877 2877
         // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2878 2878
         if (defined('DOING_AJAX')) {
2879 2879
             $default_data = array(
@@ -3003,7 +3003,7 @@  discard block
 block discarded – undo
3003 3003
         $args = array(
3004 3004
                 'label'   => $this->_admin_page_title,
3005 3005
                 'default' => 10,
3006
-                'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3006
+                'option'  => $this->_current_page.'_'.$this->_current_view.'_per_page',
3007 3007
         );
3008 3008
         //ONLY add the screen option if the user has access to it.
3009 3009
         if ($this->check_user_access($this->_current_view, true)) {
@@ -3036,8 +3036,8 @@  discard block
 block discarded – undo
3036 3036
             $map_option = $option;
3037 3037
             $option = str_replace('-', '_', $option);
3038 3038
             switch ($map_option) {
3039
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3040
-                    $value = (int)$value;
3039
+                case $this->_current_page.'_'.$this->_current_view.'_per_page':
3040
+                    $value = (int) $value;
3041 3041
                     if ($value < 1 || $value > 999) {
3042 3042
                         return;
3043 3043
                     }
@@ -3064,7 +3064,7 @@  discard block
 block discarded – undo
3064 3064
      */
3065 3065
     public function set_template_args($data)
3066 3066
     {
3067
-        $this->_template_args = array_merge($this->_template_args, (array)$data);
3067
+        $this->_template_args = array_merge($this->_template_args, (array) $data);
3068 3068
     }
3069 3069
 
3070 3070
 
@@ -3086,12 +3086,12 @@  discard block
 block discarded – undo
3086 3086
             $this->_verify_route($route);
3087 3087
         }
3088 3088
         //now let's set the string for what kind of transient we're setting
3089
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3089
+        $transient = $notices ? 'ee_rte_n_tx_'.$route.'_'.$user_id : 'rte_tx_'.$route.'_'.$user_id;
3090 3090
         $data = $notices ? array('notices' => $data) : $data;
3091 3091
         //is there already a transient for this route?  If there is then let's ADD to that transient
3092 3092
         $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3093 3093
         if ($existing) {
3094
-            $data = array_merge((array)$data, (array)$existing);
3094
+            $data = array_merge((array) $data, (array) $existing);
3095 3095
         }
3096 3096
         if (is_multisite() && is_network_admin()) {
3097 3097
             set_site_transient($transient, $data, 8);
@@ -3112,7 +3112,7 @@  discard block
 block discarded – undo
3112 3112
     {
3113 3113
         $user_id = get_current_user_id();
3114 3114
         $route = ! $route ? $this->_req_action : $route;
3115
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3115
+        $transient = $notices ? 'ee_rte_n_tx_'.$route.'_'.$user_id : 'rte_tx_'.$route.'_'.$user_id;
3116 3116
         $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3117 3117
         //delete transient after retrieval (just in case it hasn't expired);
3118 3118
         if (is_multisite() && is_network_admin()) {
@@ -3353,7 +3353,7 @@  discard block
 block discarded – undo
3353 3353
      */
3354 3354
     protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3355 3355
     {
3356
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3356
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
3357 3357
     }
3358 3358
 
3359 3359
 
@@ -3367,7 +3367,7 @@  discard block
 block discarded – undo
3367 3367
      */
3368 3368
     protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3369 3369
     {
3370
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3370
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
3371 3371
     }
3372 3372
 
3373 3373
 
Please login to merge, or discard this patch.
core/EE_Encryption.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -396,7 +396,7 @@
 block discarded – undo
396 396
 
397 397
     /**
398 398
      * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906
399
-     * @param $string
399
+     * @param string $string
400 400
      * @return bool
401 401
      */
402 402
     protected function valid_base_64($string)
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
      */
71 71
     protected function __construct()
72 72
     {
73
-        if (! defined('ESPRESSO_ENCRYPT')) {
73
+        if ( ! defined('ESPRESSO_ENCRYPT')) {
74 74
             define('ESPRESSO_ENCRYPT', true);
75 75
         }
76 76
         if (extension_loaded('openssl')) {
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
     public static function instance()
94 94
     {
95 95
         // check if class object is instantiated
96
-        if (! self::$_instance instanceof EE_Encryption) {
96
+        if ( ! self::$_instance instanceof EE_Encryption) {
97 97
             self::$_instance = new self();
98 98
         }
99 99
         return self::$_instance;
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
             $iv
288 288
         );
289 289
         // append the initialization vector
290
-        $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv;
290
+        $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER.$iv;
291 291
         // trim and maybe encode
292 292
         return $this->_use_base64_encode
293 293
             ? trim(base64_encode($encrypted_text))
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
             2
320 320
         );
321 321
         // check that iv exists, and if not, maybe text was encoded using mcrypt?
322
-        if (! isset($encrypted_components[1]) && $this->_use_mcrypt) {
322
+        if ( ! isset($encrypted_components[1]) && $this->_use_mcrypt) {
323 323
             return $this->m_decrypt($encrypted_text);
324 324
         }
325 325
         // decrypt it
@@ -402,16 +402,16 @@  discard block
 block discarded – undo
402 402
     protected function valid_base_64($string)
403 403
     {
404 404
         // ensure data is a string
405
-        if (! is_string($string) || ! $this->_use_base64_encode) {
405
+        if ( ! is_string($string) || ! $this->_use_base64_encode) {
406 406
             return false;
407 407
         }
408 408
         $decoded = base64_decode($string, true);
409 409
         // Check if there is no invalid character in string
410
-        if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
410
+        if ( ! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
411 411
             return false;
412 412
         }
413 413
         // Decode the string in strict mode and send the response
414
-        if (! base64_decode($string, true)) {
414
+        if ( ! base64_decode($string, true)) {
415 415
             return false;
416 416
         }
417 417
         // Encode and compare it to original one
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
         $iterations = ceil($length / 40);
433 433
         $random_string = '';
434 434
         for ($i = 0; $i < $iterations; $i++) {
435
-            $random_string .= sha1(microtime(true) . mt_rand(10000, 90000));
435
+            $random_string .= sha1(microtime(true).mt_rand(10000, 90000));
436 436
         }
437 437
         $random_string = substr($random_string, 0, $length);
438 438
         return $random_string;
Please login to merge, or discard this patch.
Indentation   +510 added lines, -510 removed lines patch added patch discarded remove patch
@@ -16,516 +16,516 @@
 block discarded – undo
16 16
 class EE_Encryption
17 17
 {
18 18
 
19
-    /**
20
-     * key used for saving the encryption key to the wp_options table
21
-     */
22
-    const ENCRYPTION_OPTION_KEY = 'ee_encryption_key';
23
-
24
-    /**
25
-     * the OPENSSL cipher method used
26
-     */
27
-    const OPENSSL_CIPHER_METHOD = 'aes-256-ctr';
28
-
29
-    /**
30
-     * the OPENSSL digest method used
31
-     */
32
-    const OPENSSL_DIGEST_METHOD = 'sha512';
33
-
34
-    /**
35
-     * separates the encrypted text from the initialization vector
36
-     */
37
-    const OPENSSL_IV_DELIMITER = ':iv:';
38
-
39
-    /**
40
-     * appended to text encrypted using the acme encryption
41
-     */
42
-    const ACME_ENCRYPTION_FLAG = '::ae';
43
-
44
-
45
-
46
-    /**
47
-     * instance of the EE_Encryption object
48
-     */
49
-    protected static $_instance;
50
-
51
-    /**
52
-     * @var string $_encryption_key
53
-     */
54
-    protected $_encryption_key;
55
-
56
-    /**
57
-     * @var boolean $_use_openssl_encrypt
58
-     */
59
-    protected $_use_openssl_encrypt = false;
60
-
61
-    /**
62
-     * @var boolean $_use_mcrypt
63
-     */
64
-    protected $_use_mcrypt = false;
65
-
66
-    /**
67
-     * @var boolean $_use_base64_encode
68
-     */
69
-    protected $_use_base64_encode = false;
70
-
71
-
72
-
73
-    /**
74
-     * protected constructor to prevent direct creation
75
-     */
76
-    protected function __construct()
77
-    {
78
-        if (! defined('ESPRESSO_ENCRYPT')) {
79
-            define('ESPRESSO_ENCRYPT', true);
80
-        }
81
-        if (extension_loaded('openssl')) {
82
-            $this->_use_openssl_encrypt = true;
83
-        } else if (extension_loaded('mcrypt')) {
84
-            $this->_use_mcrypt = true;
85
-        }
86
-        if (function_exists('base64_encode')) {
87
-            $this->_use_base64_encode = true;
88
-        }
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * singleton method used to instantiate class object
95
-     *
96
-     * @return EE_Encryption
97
-     */
98
-    public static function instance()
99
-    {
100
-        // check if class object is instantiated
101
-        if (! self::$_instance instanceof EE_Encryption) {
102
-            self::$_instance = new self();
103
-        }
104
-        return self::$_instance;
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * get encryption key
111
-     *
112
-     * @return string
113
-     */
114
-    public function get_encryption_key()
115
-    {
116
-        // if encryption key has not been set
117
-        if (empty($this->_encryption_key)) {
118
-            // retrieve encryption_key from db
119
-            $this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, '');
120
-            // WHAT?? No encryption_key in the db ??
121
-            if ($this->_encryption_key === '') {
122
-                // let's make one. And md5 it to make it just the right size for a key
123
-                $new_key = md5($this->generate_random_string());
124
-                // now save it to the db for later
125
-                add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key);
126
-                // here's the key - FINALLY !
127
-                $this->_encryption_key = $new_key;
128
-            }
129
-        }
130
-        return $this->_encryption_key;
131
-    }
132
-
133
-
134
-
135
-    /**
136
-     * encrypts data
137
-     *
138
-     * @param string $text_string - the text to be encrypted
139
-     * @return string
140
-     * @throws RuntimeException
141
-     */
142
-    public function encrypt($text_string = '')
143
-    {
144
-        // you give me nothing??? GET OUT !
145
-        if (empty($text_string)) {
146
-            return $text_string;
147
-        }
148
-        if ($this->_use_openssl_encrypt) {
149
-            $encrypted_text = $this->openssl_encrypt($text_string);
150
-        } else {
151
-            $encrypted_text = $this->acme_encrypt($text_string);
152
-        }
153
-        return $encrypted_text;
154
-    }
155
-
156
-
157
-
158
-    /**
159
-     * decrypts data
160
-     *
161
-     * @param string $encrypted_text - the text to be decrypted
162
-     * @return string
163
-     * @throws RuntimeException
164
-     */
165
-    public function decrypt($encrypted_text = '')
166
-    {
167
-        // you give me nothing??? GET OUT !
168
-        if (empty($encrypted_text)) {
169
-            return $encrypted_text;
170
-        }
171
-        // if PHP's mcrypt functions are installed then we'll use them
172
-        if ($this->_use_openssl_encrypt) {
173
-            $decrypted_text = $this->openssl_decrypt($encrypted_text);
174
-        } else {
175
-            $decrypted_text = $this->acme_decrypt($encrypted_text);
176
-        }
177
-        return $decrypted_text;
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     * encodes string with PHP's base64 encoding
184
-     *
185
-     * @see http://php.net/manual/en/function.base64-encode.php
186
-     * @param string $text_string the text to be encoded
187
-     * @return string
188
-     */
189
-    public function base64_string_encode($text_string = '')
190
-    {
191
-        // you give me nothing??? GET OUT !
192
-        if (empty($text_string) || ! $this->_use_base64_encode) {
193
-            return $text_string;
194
-        }
195
-        // encode
196
-        return base64_encode($text_string);
197
-    }
198
-
199
-
200
-
201
-    /**
202
-     * decodes string that has been encoded with PHP's base64 encoding
203
-     *
204
-     * @see http://php.net/manual/en/function.base64-encode.php
205
-     * @param string $encoded_string the text to be decoded
206
-     * @return string
207
-     */
208
-    public function base64_string_decode($encoded_string = '')
209
-    {
210
-        // you give me nothing??? GET OUT !
211
-        if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
212
-            return $encoded_string;
213
-        }
214
-        // decode
215
-        return base64_decode($encoded_string);
216
-    }
217
-
218
-
219
-
220
-    /**
221
-     * encodes  url string with PHP's base64 encoding
222
-     *
223
-     * @see http://php.net/manual/en/function.base64-encode.php
224
-     * @param string $text_string the text to be encoded
225
-     * @return string
226
-     */
227
-    public function base64_url_encode($text_string = '')
228
-    {
229
-        // you give me nothing??? GET OUT !
230
-        if (empty($text_string) || ! $this->_use_base64_encode) {
231
-            return $text_string;
232
-        }
233
-        // encode
234
-        $encoded_string = base64_encode($text_string);
235
-        // remove chars to make encoding more URL friendly
236
-        return strtr($encoded_string, '+/=', '-_,');
237
-    }
238
-
239
-
240
-
241
-    /**
242
-     * decodes  url string that has been encoded with PHP's base64 encoding
243
-     *
244
-     * @see http://php.net/manual/en/function.base64-encode.php
245
-     * @param string $encoded_string the text to be decoded
246
-     * @return string
247
-     */
248
-    public function base64_url_decode($encoded_string = '')
249
-    {
250
-        // you give me nothing??? GET OUT !
251
-        if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
252
-            return $encoded_string;
253
-        }
254
-        // replace previously removed characters
255
-        $encoded_string = strtr($encoded_string, '-_,', '+/=');
256
-        // decode
257
-        return base64_decode($encoded_string);
258
-    }
259
-
260
-
261
-
262
-    /**
263
-     * encrypts data using PHP's openssl functions
264
-     *
265
-     * @param string $text_string the text to be encrypted
266
-     * @return string
267
-     * @throws RuntimeException
268
-     */
269
-    protected function openssl_encrypt($text_string = '')
270
-    {
271
-        // you give me nothing??? GET OUT !
272
-        if (empty($text_string)) {
273
-            return $text_string;
274
-        }
275
-        // get initialization vector size
276
-        $iv_size = openssl_cipher_iv_length(EE_Encryption::OPENSSL_CIPHER_METHOD);
277
-        // generate initialization vector
278
-        $iv = openssl_random_pseudo_bytes($iv_size, $is_strong);
279
-        if ($iv === false || $is_strong === false) {
280
-            throw new RuntimeException(
281
-                esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso')
282
-            );
283
-        }
284
-        // encrypt it
285
-        $encrypted_text = openssl_encrypt(
286
-            $text_string,
287
-            EE_Encryption::OPENSSL_CIPHER_METHOD,
288
-            openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD),
289
-            0,
290
-            $iv
291
-        );
292
-        // append the initialization vector
293
-        $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv;
294
-        // trim and maybe encode
295
-        return $this->_use_base64_encode
296
-            ? trim(base64_encode($encrypted_text))
297
-            : trim($encrypted_text);
298
-    }
299
-
300
-
301
-
302
-    /**
303
-     * decrypts data that has been encrypted with PHP's openssl functions
304
-     *
305
-     * @param string $encrypted_text the text to be decrypted
306
-     * @return string
307
-     * @throws RuntimeException
308
-     */
309
-    protected function openssl_decrypt($encrypted_text = '')
310
-    {
311
-        // you give me nothing??? GET OUT !
312
-        if (empty($encrypted_text)) {
313
-            return $encrypted_text;
314
-        }
315
-        // decode
316
-        $encrypted_text = $this->valid_base_64($encrypted_text)
317
-            ? base64_decode($encrypted_text)
318
-            : $encrypted_text;
319
-        $encrypted_components = explode(
320
-            EE_Encryption::OPENSSL_IV_DELIMITER,
321
-            $encrypted_text,
322
-            2
323
-        );
324
-        // check that iv exists, and if not, maybe text was encoded using mcrypt?
325
-        if (! isset($encrypted_components[1]) && $this->_use_mcrypt) {
326
-            return $this->m_decrypt($encrypted_text);
327
-        }
328
-        // decrypt it
329
-        $decrypted_text = openssl_decrypt(
330
-            $encrypted_components[0],
331
-            EE_Encryption::OPENSSL_CIPHER_METHOD,
332
-            openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD),
333
-            0,
334
-            $encrypted_components[1]
335
-        );
336
-        $decrypted_text = trim($decrypted_text);
337
-        return $decrypted_text;
338
-    }
339
-
340
-
341
-
342
-    /**
343
-     * encrypts data for acme servers that didn't bother to install PHP mcrypt
344
-     *
345
-     * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
346
-     * @param string $text_string the text to be decrypted
347
-     * @return string
348
-     */
349
-    protected function acme_encrypt($text_string = '')
350
-    {
351
-        // you give me nothing??? GET OUT !
352
-        if (empty($text_string)) {
353
-            return $text_string;
354
-        }
355
-        $key_bits = str_split(
356
-            str_pad('', strlen($text_string), $this->get_encryption_key(), STR_PAD_RIGHT)
357
-        );
358
-        $string_bits = str_split($text_string);
359
-        foreach ($string_bits as $k => $v) {
360
-            $temp = ord($v) + ord($key_bits[$k]);
361
-            $string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp);
362
-        }
363
-        $encrypted_text = implode('', $string_bits);
364
-        $encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG;
365
-        return $this->_use_base64_encode
366
-            ? base64_encode($encrypted_text)
367
-            : $encrypted_text;
368
-    }
369
-
370
-
371
-
372
-    /**
373
-     * decrypts data for acme servers that didn't bother to install PHP mcrypt
374
-     *
375
-     * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
376
-     * @param string $encrypted_text the text to be decrypted
377
-     * @return string
378
-     */
379
-    protected function acme_decrypt($encrypted_text = '')
380
-    {
381
-        // you give me nothing??? GET OUT !
382
-        if (empty($encrypted_text)) {
383
-            return $encrypted_text;
384
-        }
385
-        // decode the data ?
386
-        $encrypted_text = $this->valid_base_64($encrypted_text)
387
-            ? base64_decode($encrypted_text)
388
-            : $encrypted_text;
389
-        if (strpos($encrypted_text, EE_Encryption::ACME_ENCRYPTION_FLAG) === false && $this->_use_mcrypt) {
390
-            return $this->m_decrypt($encrypted_text);
391
-        }
392
-        $encrypted_text = substr($encrypted_text, 0, -4);
393
-        $key_bits = str_split(
394
-            str_pad('', strlen($encrypted_text), $this->get_encryption_key(), STR_PAD_RIGHT)
395
-        );
396
-        $string_bits = str_split($encrypted_text);
397
-        foreach ($string_bits as $k => $v) {
398
-            $temp = ord($v) - ord($key_bits[$k]);
399
-            $string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp);
400
-        }
401
-        return implode('', $string_bits);
402
-    }
403
-
404
-
405
-
406
-    /**
407
-     * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906
408
-     * @param $string
409
-     * @return bool
410
-     */
411
-    protected function valid_base_64($string)
412
-    {
413
-        // ensure data is a string
414
-        if (! is_string($string) || ! $this->_use_base64_encode) {
415
-            return false;
416
-        }
417
-        $decoded = base64_decode($string, true);
418
-        // Check if there is no invalid character in string
419
-        if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
420
-            return false;
421
-        }
422
-        // Decode the string in strict mode and send the response
423
-        if (! base64_decode($string, true)) {
424
-            return false;
425
-        }
426
-        // Encode and compare it to original one
427
-        return base64_encode($decoded) === $string;
428
-    }
429
-
430
-
431
-
432
-    /**
433
-     * generate random string
434
-     *
435
-     * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php
436
-     * @param int $length number of characters for random string
437
-     * @return string
438
-     */
439
-    public function generate_random_string($length = 40)
440
-    {
441
-        $iterations = ceil($length / 40);
442
-        $random_string = '';
443
-        for ($i = 0; $i < $iterations; $i++) {
444
-            $random_string .= sha1(microtime(true) . mt_rand(10000, 90000));
445
-        }
446
-        $random_string = substr($random_string, 0, $length);
447
-        return $random_string;
448
-    }
449
-
450
-
451
-
452
-    /**
453
-     * encrypts data using PHP's mcrypt functions
454
-     *
455
-     * @deprecated 4.9.39
456
-     * @param string $text_string
457
-     * @internal   param $string - the text to be encrypted
458
-     * @return string
459
-     * @throws RuntimeException
460
-     */
461
-    protected function m_encrypt($text_string = '')
462
-    {
463
-        // you give me nothing??? GET OUT !
464
-        if (empty($text_string)) {
465
-            return $text_string;
466
-        }
467
-        // get the initialization vector size
468
-        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
469
-        // initialization vector
470
-        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
471
-        if ($iv === false) {
472
-            throw new RuntimeException(
473
-                esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
474
-            );
475
-        }
476
-        // encrypt it
477
-        $encrypted_text = mcrypt_encrypt(
478
-            MCRYPT_RIJNDAEL_256,
479
-            $this->get_encryption_key(),
480
-            $text_string,
481
-            MCRYPT_MODE_ECB,
482
-            $iv
483
-        );
484
-        // trim and maybe encode
485
-        return $this->_use_base64_encode
486
-            ? trim(base64_encode($encrypted_text))
487
-            : trim($encrypted_text);
488
-    }
489
-
490
-
491
-
492
-    /**
493
-     * decrypts data that has been encrypted with PHP's mcrypt functions
494
-     *
495
-     * @deprecated 4.9.39
496
-     * @param string $encrypted_text the text to be decrypted
497
-     * @return string
498
-     * @throws RuntimeException
499
-     */
500
-    protected function m_decrypt($encrypted_text = '')
501
-    {
502
-        // you give me nothing??? GET OUT !
503
-        if (empty($encrypted_text)) {
504
-            return $encrypted_text;
505
-        }
506
-        // decode
507
-        $encrypted_text = $this->valid_base_64($encrypted_text)
508
-            ? base64_decode($encrypted_text)
509
-            : $encrypted_text;
510
-        // get the initialization vector size
511
-        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
512
-        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
513
-        if ($iv === false) {
514
-            throw new RuntimeException(
515
-                esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
516
-            );
517
-        }
518
-        // decrypt it
519
-        $decrypted_text = mcrypt_decrypt(
520
-            MCRYPT_RIJNDAEL_256,
521
-            $this->get_encryption_key(),
522
-            $encrypted_text,
523
-            MCRYPT_MODE_ECB,
524
-            $iv
525
-        );
526
-        $decrypted_text = trim($decrypted_text);
527
-        return $decrypted_text;
528
-    }
19
+	/**
20
+	 * key used for saving the encryption key to the wp_options table
21
+	 */
22
+	const ENCRYPTION_OPTION_KEY = 'ee_encryption_key';
23
+
24
+	/**
25
+	 * the OPENSSL cipher method used
26
+	 */
27
+	const OPENSSL_CIPHER_METHOD = 'aes-256-ctr';
28
+
29
+	/**
30
+	 * the OPENSSL digest method used
31
+	 */
32
+	const OPENSSL_DIGEST_METHOD = 'sha512';
33
+
34
+	/**
35
+	 * separates the encrypted text from the initialization vector
36
+	 */
37
+	const OPENSSL_IV_DELIMITER = ':iv:';
38
+
39
+	/**
40
+	 * appended to text encrypted using the acme encryption
41
+	 */
42
+	const ACME_ENCRYPTION_FLAG = '::ae';
43
+
44
+
45
+
46
+	/**
47
+	 * instance of the EE_Encryption object
48
+	 */
49
+	protected static $_instance;
50
+
51
+	/**
52
+	 * @var string $_encryption_key
53
+	 */
54
+	protected $_encryption_key;
55
+
56
+	/**
57
+	 * @var boolean $_use_openssl_encrypt
58
+	 */
59
+	protected $_use_openssl_encrypt = false;
60
+
61
+	/**
62
+	 * @var boolean $_use_mcrypt
63
+	 */
64
+	protected $_use_mcrypt = false;
65
+
66
+	/**
67
+	 * @var boolean $_use_base64_encode
68
+	 */
69
+	protected $_use_base64_encode = false;
70
+
71
+
72
+
73
+	/**
74
+	 * protected constructor to prevent direct creation
75
+	 */
76
+	protected function __construct()
77
+	{
78
+		if (! defined('ESPRESSO_ENCRYPT')) {
79
+			define('ESPRESSO_ENCRYPT', true);
80
+		}
81
+		if (extension_loaded('openssl')) {
82
+			$this->_use_openssl_encrypt = true;
83
+		} else if (extension_loaded('mcrypt')) {
84
+			$this->_use_mcrypt = true;
85
+		}
86
+		if (function_exists('base64_encode')) {
87
+			$this->_use_base64_encode = true;
88
+		}
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * singleton method used to instantiate class object
95
+	 *
96
+	 * @return EE_Encryption
97
+	 */
98
+	public static function instance()
99
+	{
100
+		// check if class object is instantiated
101
+		if (! self::$_instance instanceof EE_Encryption) {
102
+			self::$_instance = new self();
103
+		}
104
+		return self::$_instance;
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * get encryption key
111
+	 *
112
+	 * @return string
113
+	 */
114
+	public function get_encryption_key()
115
+	{
116
+		// if encryption key has not been set
117
+		if (empty($this->_encryption_key)) {
118
+			// retrieve encryption_key from db
119
+			$this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, '');
120
+			// WHAT?? No encryption_key in the db ??
121
+			if ($this->_encryption_key === '') {
122
+				// let's make one. And md5 it to make it just the right size for a key
123
+				$new_key = md5($this->generate_random_string());
124
+				// now save it to the db for later
125
+				add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key);
126
+				// here's the key - FINALLY !
127
+				$this->_encryption_key = $new_key;
128
+			}
129
+		}
130
+		return $this->_encryption_key;
131
+	}
132
+
133
+
134
+
135
+	/**
136
+	 * encrypts data
137
+	 *
138
+	 * @param string $text_string - the text to be encrypted
139
+	 * @return string
140
+	 * @throws RuntimeException
141
+	 */
142
+	public function encrypt($text_string = '')
143
+	{
144
+		// you give me nothing??? GET OUT !
145
+		if (empty($text_string)) {
146
+			return $text_string;
147
+		}
148
+		if ($this->_use_openssl_encrypt) {
149
+			$encrypted_text = $this->openssl_encrypt($text_string);
150
+		} else {
151
+			$encrypted_text = $this->acme_encrypt($text_string);
152
+		}
153
+		return $encrypted_text;
154
+	}
155
+
156
+
157
+
158
+	/**
159
+	 * decrypts data
160
+	 *
161
+	 * @param string $encrypted_text - the text to be decrypted
162
+	 * @return string
163
+	 * @throws RuntimeException
164
+	 */
165
+	public function decrypt($encrypted_text = '')
166
+	{
167
+		// you give me nothing??? GET OUT !
168
+		if (empty($encrypted_text)) {
169
+			return $encrypted_text;
170
+		}
171
+		// if PHP's mcrypt functions are installed then we'll use them
172
+		if ($this->_use_openssl_encrypt) {
173
+			$decrypted_text = $this->openssl_decrypt($encrypted_text);
174
+		} else {
175
+			$decrypted_text = $this->acme_decrypt($encrypted_text);
176
+		}
177
+		return $decrypted_text;
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 * encodes string with PHP's base64 encoding
184
+	 *
185
+	 * @see http://php.net/manual/en/function.base64-encode.php
186
+	 * @param string $text_string the text to be encoded
187
+	 * @return string
188
+	 */
189
+	public function base64_string_encode($text_string = '')
190
+	{
191
+		// you give me nothing??? GET OUT !
192
+		if (empty($text_string) || ! $this->_use_base64_encode) {
193
+			return $text_string;
194
+		}
195
+		// encode
196
+		return base64_encode($text_string);
197
+	}
198
+
199
+
200
+
201
+	/**
202
+	 * decodes string that has been encoded with PHP's base64 encoding
203
+	 *
204
+	 * @see http://php.net/manual/en/function.base64-encode.php
205
+	 * @param string $encoded_string the text to be decoded
206
+	 * @return string
207
+	 */
208
+	public function base64_string_decode($encoded_string = '')
209
+	{
210
+		// you give me nothing??? GET OUT !
211
+		if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
212
+			return $encoded_string;
213
+		}
214
+		// decode
215
+		return base64_decode($encoded_string);
216
+	}
217
+
218
+
219
+
220
+	/**
221
+	 * encodes  url string with PHP's base64 encoding
222
+	 *
223
+	 * @see http://php.net/manual/en/function.base64-encode.php
224
+	 * @param string $text_string the text to be encoded
225
+	 * @return string
226
+	 */
227
+	public function base64_url_encode($text_string = '')
228
+	{
229
+		// you give me nothing??? GET OUT !
230
+		if (empty($text_string) || ! $this->_use_base64_encode) {
231
+			return $text_string;
232
+		}
233
+		// encode
234
+		$encoded_string = base64_encode($text_string);
235
+		// remove chars to make encoding more URL friendly
236
+		return strtr($encoded_string, '+/=', '-_,');
237
+	}
238
+
239
+
240
+
241
+	/**
242
+	 * decodes  url string that has been encoded with PHP's base64 encoding
243
+	 *
244
+	 * @see http://php.net/manual/en/function.base64-encode.php
245
+	 * @param string $encoded_string the text to be decoded
246
+	 * @return string
247
+	 */
248
+	public function base64_url_decode($encoded_string = '')
249
+	{
250
+		// you give me nothing??? GET OUT !
251
+		if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
252
+			return $encoded_string;
253
+		}
254
+		// replace previously removed characters
255
+		$encoded_string = strtr($encoded_string, '-_,', '+/=');
256
+		// decode
257
+		return base64_decode($encoded_string);
258
+	}
259
+
260
+
261
+
262
+	/**
263
+	 * encrypts data using PHP's openssl functions
264
+	 *
265
+	 * @param string $text_string the text to be encrypted
266
+	 * @return string
267
+	 * @throws RuntimeException
268
+	 */
269
+	protected function openssl_encrypt($text_string = '')
270
+	{
271
+		// you give me nothing??? GET OUT !
272
+		if (empty($text_string)) {
273
+			return $text_string;
274
+		}
275
+		// get initialization vector size
276
+		$iv_size = openssl_cipher_iv_length(EE_Encryption::OPENSSL_CIPHER_METHOD);
277
+		// generate initialization vector
278
+		$iv = openssl_random_pseudo_bytes($iv_size, $is_strong);
279
+		if ($iv === false || $is_strong === false) {
280
+			throw new RuntimeException(
281
+				esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso')
282
+			);
283
+		}
284
+		// encrypt it
285
+		$encrypted_text = openssl_encrypt(
286
+			$text_string,
287
+			EE_Encryption::OPENSSL_CIPHER_METHOD,
288
+			openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD),
289
+			0,
290
+			$iv
291
+		);
292
+		// append the initialization vector
293
+		$encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv;
294
+		// trim and maybe encode
295
+		return $this->_use_base64_encode
296
+			? trim(base64_encode($encrypted_text))
297
+			: trim($encrypted_text);
298
+	}
299
+
300
+
301
+
302
+	/**
303
+	 * decrypts data that has been encrypted with PHP's openssl functions
304
+	 *
305
+	 * @param string $encrypted_text the text to be decrypted
306
+	 * @return string
307
+	 * @throws RuntimeException
308
+	 */
309
+	protected function openssl_decrypt($encrypted_text = '')
310
+	{
311
+		// you give me nothing??? GET OUT !
312
+		if (empty($encrypted_text)) {
313
+			return $encrypted_text;
314
+		}
315
+		// decode
316
+		$encrypted_text = $this->valid_base_64($encrypted_text)
317
+			? base64_decode($encrypted_text)
318
+			: $encrypted_text;
319
+		$encrypted_components = explode(
320
+			EE_Encryption::OPENSSL_IV_DELIMITER,
321
+			$encrypted_text,
322
+			2
323
+		);
324
+		// check that iv exists, and if not, maybe text was encoded using mcrypt?
325
+		if (! isset($encrypted_components[1]) && $this->_use_mcrypt) {
326
+			return $this->m_decrypt($encrypted_text);
327
+		}
328
+		// decrypt it
329
+		$decrypted_text = openssl_decrypt(
330
+			$encrypted_components[0],
331
+			EE_Encryption::OPENSSL_CIPHER_METHOD,
332
+			openssl_digest($this->get_encryption_key(), EE_Encryption::OPENSSL_DIGEST_METHOD),
333
+			0,
334
+			$encrypted_components[1]
335
+		);
336
+		$decrypted_text = trim($decrypted_text);
337
+		return $decrypted_text;
338
+	}
339
+
340
+
341
+
342
+	/**
343
+	 * encrypts data for acme servers that didn't bother to install PHP mcrypt
344
+	 *
345
+	 * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
346
+	 * @param string $text_string the text to be decrypted
347
+	 * @return string
348
+	 */
349
+	protected function acme_encrypt($text_string = '')
350
+	{
351
+		// you give me nothing??? GET OUT !
352
+		if (empty($text_string)) {
353
+			return $text_string;
354
+		}
355
+		$key_bits = str_split(
356
+			str_pad('', strlen($text_string), $this->get_encryption_key(), STR_PAD_RIGHT)
357
+		);
358
+		$string_bits = str_split($text_string);
359
+		foreach ($string_bits as $k => $v) {
360
+			$temp = ord($v) + ord($key_bits[$k]);
361
+			$string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp);
362
+		}
363
+		$encrypted_text = implode('', $string_bits);
364
+		$encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG;
365
+		return $this->_use_base64_encode
366
+			? base64_encode($encrypted_text)
367
+			: $encrypted_text;
368
+	}
369
+
370
+
371
+
372
+	/**
373
+	 * decrypts data for acme servers that didn't bother to install PHP mcrypt
374
+	 *
375
+	 * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
376
+	 * @param string $encrypted_text the text to be decrypted
377
+	 * @return string
378
+	 */
379
+	protected function acme_decrypt($encrypted_text = '')
380
+	{
381
+		// you give me nothing??? GET OUT !
382
+		if (empty($encrypted_text)) {
383
+			return $encrypted_text;
384
+		}
385
+		// decode the data ?
386
+		$encrypted_text = $this->valid_base_64($encrypted_text)
387
+			? base64_decode($encrypted_text)
388
+			: $encrypted_text;
389
+		if (strpos($encrypted_text, EE_Encryption::ACME_ENCRYPTION_FLAG) === false && $this->_use_mcrypt) {
390
+			return $this->m_decrypt($encrypted_text);
391
+		}
392
+		$encrypted_text = substr($encrypted_text, 0, -4);
393
+		$key_bits = str_split(
394
+			str_pad('', strlen($encrypted_text), $this->get_encryption_key(), STR_PAD_RIGHT)
395
+		);
396
+		$string_bits = str_split($encrypted_text);
397
+		foreach ($string_bits as $k => $v) {
398
+			$temp = ord($v) - ord($key_bits[$k]);
399
+			$string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp);
400
+		}
401
+		return implode('', $string_bits);
402
+	}
403
+
404
+
405
+
406
+	/**
407
+	 * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906
408
+	 * @param $string
409
+	 * @return bool
410
+	 */
411
+	protected function valid_base_64($string)
412
+	{
413
+		// ensure data is a string
414
+		if (! is_string($string) || ! $this->_use_base64_encode) {
415
+			return false;
416
+		}
417
+		$decoded = base64_decode($string, true);
418
+		// Check if there is no invalid character in string
419
+		if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
420
+			return false;
421
+		}
422
+		// Decode the string in strict mode and send the response
423
+		if (! base64_decode($string, true)) {
424
+			return false;
425
+		}
426
+		// Encode and compare it to original one
427
+		return base64_encode($decoded) === $string;
428
+	}
429
+
430
+
431
+
432
+	/**
433
+	 * generate random string
434
+	 *
435
+	 * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php
436
+	 * @param int $length number of characters for random string
437
+	 * @return string
438
+	 */
439
+	public function generate_random_string($length = 40)
440
+	{
441
+		$iterations = ceil($length / 40);
442
+		$random_string = '';
443
+		for ($i = 0; $i < $iterations; $i++) {
444
+			$random_string .= sha1(microtime(true) . mt_rand(10000, 90000));
445
+		}
446
+		$random_string = substr($random_string, 0, $length);
447
+		return $random_string;
448
+	}
449
+
450
+
451
+
452
+	/**
453
+	 * encrypts data using PHP's mcrypt functions
454
+	 *
455
+	 * @deprecated 4.9.39
456
+	 * @param string $text_string
457
+	 * @internal   param $string - the text to be encrypted
458
+	 * @return string
459
+	 * @throws RuntimeException
460
+	 */
461
+	protected function m_encrypt($text_string = '')
462
+	{
463
+		// you give me nothing??? GET OUT !
464
+		if (empty($text_string)) {
465
+			return $text_string;
466
+		}
467
+		// get the initialization vector size
468
+		$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
469
+		// initialization vector
470
+		$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
471
+		if ($iv === false) {
472
+			throw new RuntimeException(
473
+				esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
474
+			);
475
+		}
476
+		// encrypt it
477
+		$encrypted_text = mcrypt_encrypt(
478
+			MCRYPT_RIJNDAEL_256,
479
+			$this->get_encryption_key(),
480
+			$text_string,
481
+			MCRYPT_MODE_ECB,
482
+			$iv
483
+		);
484
+		// trim and maybe encode
485
+		return $this->_use_base64_encode
486
+			? trim(base64_encode($encrypted_text))
487
+			: trim($encrypted_text);
488
+	}
489
+
490
+
491
+
492
+	/**
493
+	 * decrypts data that has been encrypted with PHP's mcrypt functions
494
+	 *
495
+	 * @deprecated 4.9.39
496
+	 * @param string $encrypted_text the text to be decrypted
497
+	 * @return string
498
+	 * @throws RuntimeException
499
+	 */
500
+	protected function m_decrypt($encrypted_text = '')
501
+	{
502
+		// you give me nothing??? GET OUT !
503
+		if (empty($encrypted_text)) {
504
+			return $encrypted_text;
505
+		}
506
+		// decode
507
+		$encrypted_text = $this->valid_base_64($encrypted_text)
508
+			? base64_decode($encrypted_text)
509
+			: $encrypted_text;
510
+		// get the initialization vector size
511
+		$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
512
+		$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
513
+		if ($iv === false) {
514
+			throw new RuntimeException(
515
+				esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
516
+			);
517
+		}
518
+		// decrypt it
519
+		$decrypted_text = mcrypt_decrypt(
520
+			MCRYPT_RIJNDAEL_256,
521
+			$this->get_encryption_key(),
522
+			$encrypted_text,
523
+			MCRYPT_MODE_ECB,
524
+			$iv
525
+		);
526
+		$decrypted_text = trim($decrypted_text);
527
+		return $decrypted_text;
528
+	}
529 529
 
530 530
 }
531 531
 /* End of file EE_Encryption.class.php */
Please login to merge, or discard this patch.
modules/ticket_selector/templates/simple_ticket_selector.template.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -11,14 +11,14 @@  discard block
 block discarded – undo
11 11
 <input type="hidden" name="tkt-slctr-ticket-id-<?php echo $EVT_ID; ?>[]" value="<?php echo $TKT_ID; ?>"/>
12 12
 <?php
13 13
 if ( $ticket instanceof EE_Ticket ) {
14
-    do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event );
15
-    $ticket_description = $ticket->description();
16
-    $ticket_description .= ! empty( $ticket_description )
17
-        ? '<br />' . $ticket_status_display
18
-        : $ticket_status_display;
19
-    if (strpos( $ticket_description, '<div' ) === false) {
20
-        $ticket_description = "<p>{$ticket_description}</p>";
21
-    }
14
+	do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event );
15
+	$ticket_description = $ticket->description();
16
+	$ticket_description .= ! empty( $ticket_description )
17
+		? '<br />' . $ticket_status_display
18
+		: $ticket_status_display;
19
+	if (strpos( $ticket_description, '<div' ) === false) {
20
+		$ticket_description = "<p>{$ticket_description}</p>";
21
+	}
22 22
 ?>
23 23
 <div id="no-tkt-slctr-ticket-dv-<?php echo $EVT_ID; ?>" class="no-tkt-slctr-ticket-dv">
24 24
     <div class="no-tkt-slctr-ticket-content-dv">
@@ -28,6 +28,6 @@  discard block
 block discarded – undo
28 28
         <?php } ?>
29 29
     </div><!-- .no-tkt-slctr-ticket-content-dv -->
30 30
 <?php
31
-    do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event );
31
+	do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event );
32 32
 }
33 33
 ?>
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -10,24 +10,24 @@
 block discarded – undo
10 10
 <input type="hidden" name="tkt-slctr-qty-<?php echo $EVT_ID; ?>[]" value="1"/>
11 11
 <input type="hidden" name="tkt-slctr-ticket-id-<?php echo $EVT_ID; ?>[]" value="<?php echo $TKT_ID; ?>"/>
12 12
 <?php
13
-if ( $ticket instanceof EE_Ticket ) {
14
-    do_action( 'AHEE__ticket_selector_chart__template__before_ticket_selector', $event );
13
+if ($ticket instanceof EE_Ticket) {
14
+    do_action('AHEE__ticket_selector_chart__template__before_ticket_selector', $event);
15 15
     $ticket_description = $ticket->description();
16
-    $ticket_description .= ! empty( $ticket_description )
17
-        ? '<br />' . $ticket_status_display
16
+    $ticket_description .= ! empty($ticket_description)
17
+        ? '<br />'.$ticket_status_display
18 18
         : $ticket_status_display;
19
-    if (strpos( $ticket_description, '<div' ) === false) {
19
+    if (strpos($ticket_description, '<div') === false) {
20 20
         $ticket_description = "<p>{$ticket_description}</p>";
21 21
     }
22 22
 ?>
23 23
 <div id="no-tkt-slctr-ticket-dv-<?php echo $EVT_ID; ?>" class="no-tkt-slctr-ticket-dv">
24 24
     <div class="no-tkt-slctr-ticket-content-dv">
25 25
         <h5><?php echo $ticket->name(); ?></h5>
26
-        <?php if ( ! empty( $ticket_description ) ) { ?>
26
+        <?php if ( ! empty($ticket_description)) { ?>
27 27
         <?php echo $ticket_description; ?>
28 28
         <?php } ?>
29 29
     </div><!-- .no-tkt-slctr-ticket-content-dv -->
30 30
 <?php
31
-    do_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event );
31
+    do_action('AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event);
32 32
 }
33 33
 ?>
Please login to merge, or discard this patch.
modules/ticket_selector/DisplayTicketSelector.php 2 patches
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 use EEM_Ticket;
16 16
 use WP_Post;
17 17
 
18
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
19
-    exit( 'No direct script access allowed' );
18
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
19
+    exit('No direct script access allowed');
20 20
 }
21 21
 
22 22
 
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
     /**
88 88
      * @param boolean $iframe
89 89
      */
90
-    public function setIframe( $iframe = true )
90
+    public function setIframe($iframe = true)
91 91
     {
92
-        $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN );
92
+        $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN);
93 93
     }
94 94
 
95 95
 
@@ -100,28 +100,28 @@  discard block
 block discarded – undo
100 100
      * @return bool
101 101
      * @throws EE_Error
102 102
      */
103
-    protected function setEvent( $event = null )
103
+    protected function setEvent($event = null)
104 104
     {
105
-        if ( $event === null ) {
105
+        if ($event === null) {
106 106
             global $post;
107 107
             $event = $post;
108 108
         }
109
-        if ( $event instanceof EE_Event ) {
109
+        if ($event instanceof EE_Event) {
110 110
             $this->event = $event;
111
-        } else if ( $event instanceof WP_Post ) {
112
-            if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) {
111
+        } else if ($event instanceof WP_Post) {
112
+            if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
113 113
                 $this->event = $event->EE_Event;
114
-            } else if ( $event->post_type === 'espresso_events' ) {
115
-                $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event );
114
+            } else if ($event->post_type === 'espresso_events') {
115
+                $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
116 116
                 $this->event = $event->EE_Event;
117 117
             }
118 118
         } else {
119
-            $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' );
120
-            $dev_msg = $user_msg . __(
119
+            $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
120
+            $dev_msg = $user_msg.__(
121 121
                     'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
122 122
                     'event_espresso'
123 123
                 );
124
-            EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ );
124
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
125 125
             return false;
126 126
         }
127 127
         return true;
@@ -162,17 +162,17 @@  discard block
 block discarded – undo
162 162
      * @return string
163 163
      * @throws EE_Error
164 164
      */
165
-    public function display( $event = null, $view_details = false )
165
+    public function display($event = null, $view_details = false)
166 166
     {
167 167
         // reset filter for displaying submit button
168
-        remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' );
168
+        remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
169 169
         // poke and prod incoming event till it tells us what it is
170
-        if ( ! $this->setEvent( $event ) ) {
170
+        if ( ! $this->setEvent($event)) {
171 171
             return false;
172 172
         }
173 173
         // begin gathering template arguments by getting event status
174
-        $template_args = array( 'event_status' => $this->event->get_active_status() );
175
-        if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) {
174
+        $template_args = array('event_status' => $this->event->get_active_status());
175
+        if ($this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details)) {
176 176
             return ! is_single() ? $this->displayViewDetailsButton() : '';
177 177
         }
178 178
         // filter the maximum qty that can appear in the Ticket Selector qty dropdowns
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
         }
183 183
         // is the event expired ?
184 184
         $template_args['event_is_expired'] = $this->event->is_expired();
185
-        if ( $template_args[ 'event_is_expired' ] ) {
185
+        if ($template_args['event_is_expired']) {
186 186
             return $this->expiredEventMessage();
187 187
         }
188 188
         // get all tickets for this event ordered by the datetime
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
         if (count($tickets) < 1) {
191 191
             return $this->noTicketAvailableMessage();
192 192
         }
193
-        if (EED_Events_Archive::is_iframe()){
193
+        if (EED_Events_Archive::is_iframe()) {
194 194
             $this->setIframe();
195 195
         }
196 196
         // redirecting to another site for registration ??
@@ -198,10 +198,10 @@  discard block
 block discarded – undo
198 198
         // if redirecting to another site for registration, then we don't load the TS
199 199
         $ticket_selector = $external_url
200 200
             ? $this->externalEventRegistration()
201
-            : $this->loadTicketSelector($tickets,$template_args);
201
+            : $this->loadTicketSelector($tickets, $template_args);
202 202
         // now set up the form (but not for the admin)
203 203
         $ticket_selector = ! is_admin()
204
-            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
204
+            ? $this->formOpen($this->event->ID(), $external_url).$ticket_selector
205 205
             : $ticket_selector;
206 206
         // submit button and form close tag
207 207
         $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : '';
@@ -251,10 +251,10 @@  discard block
 block discarded – undo
251 251
      */
252 252
     protected function expiredEventMessage()
253 253
     {
254
-        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
254
+        return '<div class="ee-event-expired-notice"><span class="important-notice">'.esc_html__(
255 255
             'We\'re sorry, but all tickets sales have ended because the event is expired.',
256 256
             'event_espresso'
257
-        ) . '</span></div><!-- .ee-event-expired-notice -->';
257
+        ).'</span></div><!-- .ee-event-expired-notice -->';
258 258
     }
259 259
 
260 260
 
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
      */
269 269
     protected function noTicketAvailableMessage()
270 270
     {
271
-        $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' );
271
+        $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso');
272 272
         if (current_user_can('edit_post', $this->event->ID())) {
273 273
             $no_ticket_available_msg .= sprintf(
274 274
                 esc_html__(
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
         }
284 284
         return '
285 285
             <div class="ee-event-expired-notice">
286
-                <span class="important-notice">' . $no_ticket_available_msg . '</span>
286
+                <span class="important-notice">' . $no_ticket_available_msg.'</span>
287 287
             </div><!-- .ee-event-expired-notice -->';
288 288
     }
289 289
 
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
                 '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
315 315
             );
316 316
         }
317
-        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
317
+        return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>';
318 318
     }
319 319
 
320 320
 
@@ -376,12 +376,12 @@  discard block
 block discarded – undo
376 376
          */
377 377
         $template_args['anchor_id'] = apply_filters(
378 378
             'FHEE__EE_Ticket_Selector__redirect_anchor_id',
379
-            '#tkt-slctr-tbl-' . $this->event->ID(),
379
+            '#tkt-slctr-tbl-'.$this->event->ID(),
380 380
             $this->event->ID()
381 381
         );
382 382
         $template_args['tickets'] = $tickets;
383 383
         $template_args['ticket_count'] = count($tickets);
384
-        $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args);
384
+        $ticket_selector = $this->simpleTicketSelector($tickets, $template_args);
385 385
         return $ticket_selector instanceof TicketSelectorSimple
386 386
             ? $ticket_selector
387 387
             : new TicketSelectorStandard(
@@ -462,11 +462,11 @@  discard block
 block discarded – undo
462 462
      * @param        string $external_url
463 463
      * @return        string
464 464
      */
465
-    public function formOpen( $ID = 0, $external_url = '' )
465
+    public function formOpen($ID = 0, $external_url = '')
466 466
     {
467 467
         // if redirecting, we don't need any anything else
468
-        if ( $external_url ) {
469
-            $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"';
468
+        if ($external_url) {
469
+            $html = '<form method="GET" action="'.EEH_URL::refactor_url($external_url).'"';
470 470
             // open link in new window ?
471 471
             $html .= apply_filters(
472 472
                 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
@@ -475,21 +475,21 @@  discard block
 block discarded – undo
475 475
                 ? ' target="_blank"'
476 476
                 : '';
477 477
             $html .= '>';
478
-            $query_args = EEH_URL::get_query_string( $external_url );
479
-            foreach ( (array)$query_args as $query_arg => $value ) {
480
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
478
+            $query_args = EEH_URL::get_query_string($external_url);
479
+            foreach ((array) $query_args as $query_arg => $value) {
480
+                $html .= '<input type="hidden" name="'.$query_arg.'" value="'.$value.'">';
481 481
             }
482 482
             return $html;
483 483
         }
484 484
         // if there is no submit button, then don't start building a form
485 485
         // because the "View Details" button will build its own form
486
-        if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) {
486
+        if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
487 487
             return '';
488 488
         }
489
-        $checkout_url = EEH_Event_View::event_link_url( $ID );
490
-        if ( ! $checkout_url ) {
489
+        $checkout_url = EEH_Event_View::event_link_url($ID);
490
+        if ( ! $checkout_url) {
491 491
             EE_Error::add_error(
492
-                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
492
+                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
493 493
                 __FILE__,
494 494
                 __FUNCTION__,
495 495
                 __LINE__
@@ -498,10 +498,10 @@  discard block
 block discarded – undo
498 498
         // set no cache headers and constants
499 499
         EE_System::do_not_cache();
500 500
         $extra_params = $this->iframe ? ' target="_blank"' : '';
501
-        $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
502
-        $html .= wp_nonce_field( 'process_ticket_selections', 'process_ticket_selections_nonce_' . $ID, true, false );
501
+        $html = '<form method="POST" action="'.$checkout_url.'"'.$extra_params.'>';
502
+        $html .= wp_nonce_field('process_ticket_selections', 'process_ticket_selections_nonce_'.$ID, true, false);
503 503
         $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
504
-        $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event );
504
+        $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event);
505 505
         return $html;
506 506
     }
507 507
 
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
                 $html .= empty($external_url)
525 525
                     ? $this->ticketSelectorEndDiv()
526 526
                     : $this->clearTicketSelector();
527
-                $html .= '<br/>' . $this->formClose();
527
+                $html .= '<br/>'.$this->formClose();
528 528
             } else if ($this->getMaxAttendees() === 1) {
529 529
                 // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
530 530
                 if ($this->event->is_sold_out()) {
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
                         $html .= $this->displayRegisterNowButton();
554 554
                     }
555 555
                     // sold out DWMTS event, no TS, no submit or view details button, but has additional content
556
-                    $html .=  $this->ticketSelectorEndDiv();
556
+                    $html .= $this->ticketSelectorEndDiv();
557 557
                 } else if (
558 558
                     apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
559 559
                     && ! is_single()
@@ -604,13 +604,13 @@  discard block
 block discarded – undo
604 604
         );
605 605
         $external_url = $this->event->external_url();
606 606
         $html = EEH_HTML::div(
607
-            '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap'
607
+            '', 'ticket-selector-submit-'.$this->event->ID().'-btn-wrap', 'ticket-selector-submit-btn-wrap'
608 608
         );
609
-        $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
609
+        $html .= '<input id="ticket-selector-submit-'.$this->event->ID().'-btn"';
610 610
         $html .= ' class="ticket-selector-submit-btn ';
611 611
         $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
612
-        $html .= ' type="submit" value="' . $btn_text . '" />';
613
-        $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
612
+        $html .= ' type="submit" value="'.$btn_text.'" />';
613
+        $html .= EEH_HTML::divx().'<!-- .ticket-selector-submit-btn-wrap -->';
614 614
         $html .= apply_filters(
615 615
             'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
616 616
             '',
@@ -630,11 +630,11 @@  discard block
 block discarded – undo
630 630
      * @return string
631 631
      * @throws EE_Error
632 632
      */
633
-    public function displayViewDetailsButton( $DWMTS = false )
633
+    public function displayViewDetailsButton($DWMTS = false)
634 634
     {
635
-        if ( ! $this->event->get_permalink() ) {
635
+        if ( ! $this->event->get_permalink()) {
636 636
             EE_Error::add_error(
637
-                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
637
+                esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
638 638
                 __FILE__, __FUNCTION__, __LINE__
639 639
             );
640 640
         }
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
         )
653 653
             ? ' target="_blank"'
654 654
             : '';
655
-        $view_details_btn .='>';
655
+        $view_details_btn .= '>';
656 656
         $btn_text = apply_filters(
657 657
             'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
658 658
             esc_html__('View Details', 'event_espresso'),
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
                              . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
664 664
                              . $btn_text
665 665
                              . '" />';
666
-        $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event );
666
+        $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event);
667 667
         if ($DWMTS) {
668 668
             $view_details_btn .= $this->formClose();
669 669
             $view_details_btn .= $this->ticketSelectorEndDiv();
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
      */
684 684
     public function ticketSelectorEndDiv()
685 685
     {
686
-        return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
686
+        return $this->clearTicketSelector().'</div><!-- ticketSelectorEndDiv -->';
687 687
     }
688 688
 
689 689
 
Please login to merge, or discard this patch.
Indentation   +676 added lines, -676 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 use WP_Post;
17 17
 
18 18
 if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
19
-    exit( 'No direct script access allowed' );
19
+	exit( 'No direct script access allowed' );
20 20
 }
21 21
 
22 22
 
@@ -33,684 +33,684 @@  discard block
 block discarded – undo
33 33
 class DisplayTicketSelector
34 34
 {
35 35
 
36
-    /**
37
-     * event that ticket selector is being generated for
38
-     *
39
-     * @access protected
40
-     * @var EE_Event $event
41
-     */
42
-    protected $event;
43
-
44
-    /**
45
-     * Used to flag when the ticket selector is being called from an external iframe.
46
-     *
47
-     * @var bool $iframe
48
-     */
49
-    protected $iframe = false;
50
-
51
-    /**
52
-     * max attendees that can register for event at one time
53
-     *
54
-     * @var int $max_attendees
55
-     */
56
-    private $max_attendees = EE_INF;
57
-
58
-    /**
59
-     *@var string $date_format
60
-     */
61
-    private $date_format;
62
-
63
-    /**
64
-     *@var string $time_format
65
-     */
66
-    private $time_format;
67
-
68
-
69
-
70
-    /**
71
-     * DisplayTicketSelector constructor.
72
-     */
73
-    public function __construct()
74
-    {
75
-        $this->date_format = apply_filters(
76
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
77
-            get_option('date_format')
78
-        );
79
-        $this->time_format = apply_filters(
80
-            'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
81
-            get_option('time_format')
82
-        );
83
-    }
84
-
85
-
86
-
87
-    /**
88
-     * @param boolean $iframe
89
-     */
90
-    public function setIframe( $iframe = true )
91
-    {
92
-        $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN );
93
-    }
94
-
95
-
96
-    /**
97
-     * finds and sets the \EE_Event object for use throughout class
98
-     *
99
-     * @param mixed $event
100
-     * @return bool
101
-     * @throws EE_Error
102
-     */
103
-    protected function setEvent( $event = null )
104
-    {
105
-        if ( $event === null ) {
106
-            global $post;
107
-            $event = $post;
108
-        }
109
-        if ( $event instanceof EE_Event ) {
110
-            $this->event = $event;
111
-        } else if ( $event instanceof WP_Post ) {
112
-            if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) {
113
-                $this->event = $event->EE_Event;
114
-            } else if ( $event->post_type === 'espresso_events' ) {
115
-                $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event );
116
-                $this->event = $event->EE_Event;
117
-            }
118
-        } else {
119
-            $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' );
120
-            $dev_msg = $user_msg . __(
121
-                    'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
122
-                    'event_espresso'
123
-                );
124
-            EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ );
125
-            return false;
126
-        }
127
-        return true;
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * @return int
134
-     */
135
-    public function getMaxAttendees()
136
-    {
137
-        return $this->max_attendees;
138
-    }
139
-
140
-
141
-
142
-    /**
143
-     * @param int $max_attendees
144
-     */
145
-    public function setMaxAttendees($max_attendees)
146
-    {
147
-        $this->max_attendees = absint(
148
-            apply_filters(
149
-                'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
150
-                $max_attendees
151
-            )
152
-        );
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     * creates buttons for selecting number of attendees for an event
159
-     *
160
-     * @param WP_Post|int $event
161
-     * @param bool         $view_details
162
-     * @return string
163
-     * @throws EE_Error
164
-     */
165
-    public function display( $event = null, $view_details = false )
166
-    {
167
-        // reset filter for displaying submit button
168
-        remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' );
169
-        // poke and prod incoming event till it tells us what it is
170
-        if ( ! $this->setEvent( $event ) ) {
171
-            return false;
172
-        }
173
-        // begin gathering template arguments by getting event status
174
-        $template_args = array( 'event_status' => $this->event->get_active_status() );
175
-        if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) {
176
-            return ! is_single() ? $this->displayViewDetailsButton() : '';
177
-        }
178
-        // filter the maximum qty that can appear in the Ticket Selector qty dropdowns
179
-        $this->setMaxAttendees($this->event->additional_limit());
180
-        if ($this->getMaxAttendees() < 1) {
181
-            return $this->ticketSalesClosedMessage();
182
-        }
183
-        // is the event expired ?
184
-        $template_args['event_is_expired'] = $this->event->is_expired();
185
-        if ( $template_args[ 'event_is_expired' ] ) {
186
-            return $this->expiredEventMessage();
187
-        }
188
-        // get all tickets for this event ordered by the datetime
189
-        $tickets = $this->getTickets();
190
-        if (count($tickets) < 1) {
191
-            return $this->noTicketAvailableMessage();
192
-        }
193
-        if (EED_Events_Archive::is_iframe()){
194
-            $this->setIframe();
195
-        }
196
-        // redirecting to another site for registration ??
197
-        $external_url = (string) $this->event->external_url();
198
-        // if redirecting to another site for registration, then we don't load the TS
199
-        $ticket_selector = $external_url
200
-            ? $this->externalEventRegistration()
201
-            : $this->loadTicketSelector($tickets,$template_args);
202
-        // now set up the form (but not for the admin)
203
-        $ticket_selector = ! is_admin()
204
-            ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
205
-            : $ticket_selector;
206
-        // submit button and form close tag
207
-        $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : '';
208
-        return $ticket_selector;
209
-    }
210
-
211
-
212
-
213
-    /**
214
-     * displayTicketSelector
215
-     * examines the event properties and determines whether a Ticket Selector should be displayed
216
-     *
217
-     * @param WP_Post|int $event
218
-     * @param string       $_event_active_status
219
-     * @param bool         $view_details
220
-     * @return bool
221
-     * @throws EE_Error
222
-     */
223
-    protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
224
-    {
225
-        $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
226
-        return ! is_admin()
227
-               && (
228
-                   ! $this->event->display_ticket_selector()
229
-                   || $view_details
230
-                   || post_password_required($event_post)
231
-                   || (
232
-                       $_event_active_status !== EE_Datetime::active
233
-                       && $_event_active_status !== EE_Datetime::upcoming
234
-                       && $_event_active_status !== EE_Datetime::sold_out
235
-                       && ! (
236
-                           $_event_active_status === EE_Datetime::inactive
237
-                           && is_user_logged_in()
238
-                       )
239
-                   )
240
-               );
241
-    }
242
-
243
-
244
-
245
-    /**
246
-     * noTicketAvailableMessage
247
-     * notice displayed if event is expired
248
-     *
249
-     * @return string
250
-     * @throws EE_Error
251
-     */
252
-    protected function expiredEventMessage()
253
-    {
254
-        return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
255
-            'We\'re sorry, but all tickets sales have ended because the event is expired.',
256
-            'event_espresso'
257
-        ) . '</span></div><!-- .ee-event-expired-notice -->';
258
-    }
259
-
260
-
261
-
262
-    /**
263
-     * noTicketAvailableMessage
264
-     * notice displayed if event has no more tickets available
265
-     *
266
-     * @return string
267
-     * @throws EE_Error
268
-     */
269
-    protected function noTicketAvailableMessage()
270
-    {
271
-        $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' );
272
-        if (current_user_can('edit_post', $this->event->ID())) {
273
-            $no_ticket_available_msg .= sprintf(
274
-                esc_html__(
275
-                    '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
276
-                    'event_espresso'
277
-                ),
278
-                '<div class="ee-attention" style="text-align: left;"><b>',
279
-                '</b><br />',
280
-                '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',
281
-                '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
282
-            );
283
-        }
284
-        return '
36
+	/**
37
+	 * event that ticket selector is being generated for
38
+	 *
39
+	 * @access protected
40
+	 * @var EE_Event $event
41
+	 */
42
+	protected $event;
43
+
44
+	/**
45
+	 * Used to flag when the ticket selector is being called from an external iframe.
46
+	 *
47
+	 * @var bool $iframe
48
+	 */
49
+	protected $iframe = false;
50
+
51
+	/**
52
+	 * max attendees that can register for event at one time
53
+	 *
54
+	 * @var int $max_attendees
55
+	 */
56
+	private $max_attendees = EE_INF;
57
+
58
+	/**
59
+	 *@var string $date_format
60
+	 */
61
+	private $date_format;
62
+
63
+	/**
64
+	 *@var string $time_format
65
+	 */
66
+	private $time_format;
67
+
68
+
69
+
70
+	/**
71
+	 * DisplayTicketSelector constructor.
72
+	 */
73
+	public function __construct()
74
+	{
75
+		$this->date_format = apply_filters(
76
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
77
+			get_option('date_format')
78
+		);
79
+		$this->time_format = apply_filters(
80
+			'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
81
+			get_option('time_format')
82
+		);
83
+	}
84
+
85
+
86
+
87
+	/**
88
+	 * @param boolean $iframe
89
+	 */
90
+	public function setIframe( $iframe = true )
91
+	{
92
+		$this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN );
93
+	}
94
+
95
+
96
+	/**
97
+	 * finds and sets the \EE_Event object for use throughout class
98
+	 *
99
+	 * @param mixed $event
100
+	 * @return bool
101
+	 * @throws EE_Error
102
+	 */
103
+	protected function setEvent( $event = null )
104
+	{
105
+		if ( $event === null ) {
106
+			global $post;
107
+			$event = $post;
108
+		}
109
+		if ( $event instanceof EE_Event ) {
110
+			$this->event = $event;
111
+		} else if ( $event instanceof WP_Post ) {
112
+			if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) {
113
+				$this->event = $event->EE_Event;
114
+			} else if ( $event->post_type === 'espresso_events' ) {
115
+				$event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event );
116
+				$this->event = $event->EE_Event;
117
+			}
118
+		} else {
119
+			$user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' );
120
+			$dev_msg = $user_msg . __(
121
+					'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
122
+					'event_espresso'
123
+				);
124
+			EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ );
125
+			return false;
126
+		}
127
+		return true;
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * @return int
134
+	 */
135
+	public function getMaxAttendees()
136
+	{
137
+		return $this->max_attendees;
138
+	}
139
+
140
+
141
+
142
+	/**
143
+	 * @param int $max_attendees
144
+	 */
145
+	public function setMaxAttendees($max_attendees)
146
+	{
147
+		$this->max_attendees = absint(
148
+			apply_filters(
149
+				'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
150
+				$max_attendees
151
+			)
152
+		);
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 * creates buttons for selecting number of attendees for an event
159
+	 *
160
+	 * @param WP_Post|int $event
161
+	 * @param bool         $view_details
162
+	 * @return string
163
+	 * @throws EE_Error
164
+	 */
165
+	public function display( $event = null, $view_details = false )
166
+	{
167
+		// reset filter for displaying submit button
168
+		remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' );
169
+		// poke and prod incoming event till it tells us what it is
170
+		if ( ! $this->setEvent( $event ) ) {
171
+			return false;
172
+		}
173
+		// begin gathering template arguments by getting event status
174
+		$template_args = array( 'event_status' => $this->event->get_active_status() );
175
+		if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) {
176
+			return ! is_single() ? $this->displayViewDetailsButton() : '';
177
+		}
178
+		// filter the maximum qty that can appear in the Ticket Selector qty dropdowns
179
+		$this->setMaxAttendees($this->event->additional_limit());
180
+		if ($this->getMaxAttendees() < 1) {
181
+			return $this->ticketSalesClosedMessage();
182
+		}
183
+		// is the event expired ?
184
+		$template_args['event_is_expired'] = $this->event->is_expired();
185
+		if ( $template_args[ 'event_is_expired' ] ) {
186
+			return $this->expiredEventMessage();
187
+		}
188
+		// get all tickets for this event ordered by the datetime
189
+		$tickets = $this->getTickets();
190
+		if (count($tickets) < 1) {
191
+			return $this->noTicketAvailableMessage();
192
+		}
193
+		if (EED_Events_Archive::is_iframe()){
194
+			$this->setIframe();
195
+		}
196
+		// redirecting to another site for registration ??
197
+		$external_url = (string) $this->event->external_url();
198
+		// if redirecting to another site for registration, then we don't load the TS
199
+		$ticket_selector = $external_url
200
+			? $this->externalEventRegistration()
201
+			: $this->loadTicketSelector($tickets,$template_args);
202
+		// now set up the form (but not for the admin)
203
+		$ticket_selector = ! is_admin()
204
+			? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector
205
+			: $ticket_selector;
206
+		// submit button and form close tag
207
+		$ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : '';
208
+		return $ticket_selector;
209
+	}
210
+
211
+
212
+
213
+	/**
214
+	 * displayTicketSelector
215
+	 * examines the event properties and determines whether a Ticket Selector should be displayed
216
+	 *
217
+	 * @param WP_Post|int $event
218
+	 * @param string       $_event_active_status
219
+	 * @param bool         $view_details
220
+	 * @return bool
221
+	 * @throws EE_Error
222
+	 */
223
+	protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details)
224
+	{
225
+		$event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event;
226
+		return ! is_admin()
227
+			   && (
228
+				   ! $this->event->display_ticket_selector()
229
+				   || $view_details
230
+				   || post_password_required($event_post)
231
+				   || (
232
+					   $_event_active_status !== EE_Datetime::active
233
+					   && $_event_active_status !== EE_Datetime::upcoming
234
+					   && $_event_active_status !== EE_Datetime::sold_out
235
+					   && ! (
236
+						   $_event_active_status === EE_Datetime::inactive
237
+						   && is_user_logged_in()
238
+					   )
239
+				   )
240
+			   );
241
+	}
242
+
243
+
244
+
245
+	/**
246
+	 * noTicketAvailableMessage
247
+	 * notice displayed if event is expired
248
+	 *
249
+	 * @return string
250
+	 * @throws EE_Error
251
+	 */
252
+	protected function expiredEventMessage()
253
+	{
254
+		return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__(
255
+			'We\'re sorry, but all tickets sales have ended because the event is expired.',
256
+			'event_espresso'
257
+		) . '</span></div><!-- .ee-event-expired-notice -->';
258
+	}
259
+
260
+
261
+
262
+	/**
263
+	 * noTicketAvailableMessage
264
+	 * notice displayed if event has no more tickets available
265
+	 *
266
+	 * @return string
267
+	 * @throws EE_Error
268
+	 */
269
+	protected function noTicketAvailableMessage()
270
+	{
271
+		$no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' );
272
+		if (current_user_can('edit_post', $this->event->ID())) {
273
+			$no_ticket_available_msg .= sprintf(
274
+				esc_html__(
275
+					'%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s',
276
+					'event_espresso'
277
+				),
278
+				'<div class="ee-attention" style="text-align: left;"><b>',
279
+				'</b><br />',
280
+				'<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',
281
+				'</a></span></div><!-- .ee-attention noTicketAvailableMessage -->'
282
+			);
283
+		}
284
+		return '
285 285
             <div class="ee-event-expired-notice">
286 286
                 <span class="important-notice">' . $no_ticket_available_msg . '</span>
287 287
             </div><!-- .ee-event-expired-notice -->';
288
-    }
289
-
290
-
291
-
292
-    /**
293
-     * ticketSalesClosed
294
-     * notice displayed if event ticket sales are turned off
295
-     *
296
-     * @return string
297
-     * @throws EE_Error
298
-     */
299
-    protected function ticketSalesClosedMessage()
300
-    {
301
-        $sales_closed_msg = esc_html__(
302
-            'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
303
-            'event_espresso'
304
-        );
305
-        if (current_user_can('edit_post', $this->event->ID())) {
306
-            $sales_closed_msg .= sprintf(
307
-                esc_html__(
308
-                    '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
309
-                    'event_espresso'
310
-                ),
311
-                '<div class="ee-attention" style="text-align: left;"><b>',
312
-                '</b><br />',
313
-                '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',
314
-                '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
315
-            );
316
-        }
317
-        return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
318
-    }
319
-
320
-
321
-
322
-    /**
323
-     * getTickets
324
-     *
325
-     * @return \EE_Base_Class[]|\EE_Ticket[]
326
-     * @throws EE_Error
327
-     */
328
-    protected function getTickets()
329
-    {
330
-        $ticket_query_args = array(
331
-            array('Datetime.EVT_ID' => $this->event->ID()),
332
-            'order_by' => array(
333
-                'TKT_order'              => 'ASC',
334
-                'TKT_required'           => 'DESC',
335
-                'TKT_start_date'         => 'ASC',
336
-                'TKT_end_date'           => 'ASC',
337
-                'Datetime.DTT_EVT_start' => 'DESC',
338
-            ),
339
-        );
340
-        if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) {
341
-            //use the correct applicable time query depending on what version of core is being run.
342
-            $current_time = method_exists('EEM_Datetime', 'current_time_for_query')
343
-                ? time()
344
-                : current_time('timestamp');
345
-            $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
346
-        }
347
-        return EEM_Ticket::instance()->get_all($ticket_query_args);
348
-    }
349
-
350
-
351
-
352
-    /**
353
-     * loadTicketSelector
354
-     * begins to assemble template arguments
355
-     * and decides whether to load a "simple" ticket selector, or the standard
356
-     *
357
-     * @param \EE_Ticket[] $tickets
358
-     * @param array $template_args
359
-     * @return string
360
-     * @throws EE_Error
361
-     */
362
-    protected function loadTicketSelector(array $tickets, array $template_args)
363
-    {
364
-        $template_args['event'] = $this->event;
365
-        $template_args['EVT_ID'] = $this->event->ID();
366
-        $template_args['event_is_expired'] = $this->event->is_expired();
367
-        $template_args['max_atndz'] = $this->getMaxAttendees();
368
-        $template_args['date_format'] = $this->date_format;
369
-        $template_args['time_format'] = $this->time_format;
370
-        /**
371
-         * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
372
-         *
373
-         * @since 4.9.13
374
-         * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
375
-         * @param int $EVT_ID The Event ID
376
-         */
377
-        $template_args['anchor_id'] = apply_filters(
378
-            'FHEE__EE_Ticket_Selector__redirect_anchor_id',
379
-            '#tkt-slctr-tbl-' . $this->event->ID(),
380
-            $this->event->ID()
381
-        );
382
-        $template_args['tickets'] = $tickets;
383
-        $template_args['ticket_count'] = count($tickets);
384
-        $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args);
385
-        return $ticket_selector instanceof TicketSelectorSimple
386
-            ? $ticket_selector
387
-            : new TicketSelectorStandard(
388
-                $this->event,
389
-                $tickets,
390
-                $this->getMaxAttendees(),
391
-                $template_args,
392
-                $this->date_format,
393
-                $this->time_format
394
-            );
395
-    }
396
-
397
-
398
-
399
-    /**
400
-     * simpleTicketSelector
401
-     * there's one ticket, and max attendees is set to one,
402
-     * so if the event is free, then this is a "simple" ticket selector
403
-     * a.k.a. "Dude Where's my Ticket Selector?"
404
-     *
405
-     * @param \EE_Ticket[] $tickets
406
-     * @param array  $template_args
407
-     * @return string
408
-     * @throws EE_Error
409
-     */
410
-    protected function simpleTicketSelector($tickets, array $template_args)
411
-    {
412
-        // if there is only ONE ticket with a max qty of ONE
413
-        if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
414
-            return '';
415
-        }
416
-        /** @var \EE_Ticket $ticket */
417
-        $ticket = reset($tickets);
418
-        // if the ticket is free... then not much need for the ticket selector
419
-        if (
420
-            apply_filters(
421
-                'FHEE__ticket_selector_chart_template__hide_ticket_selector',
422
-                $ticket->is_free(),
423
-                $this->event->ID()
424
-            )
425
-        ) {
426
-            return new TicketSelectorSimple(
427
-                $this->event,
428
-                $ticket,
429
-                $this->getMaxAttendees(),
430
-                $template_args
431
-            );
432
-        }
433
-        return '';
434
-    }
435
-
436
-
437
-
438
-    /**
439
-     * externalEventRegistration
440
-     *
441
-     * @return string
442
-     */
443
-    public function externalEventRegistration()
444
-    {
445
-        // if not we still need to trigger the display of the submit button
446
-        add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
447
-        //display notice to admin that registration is external
448
-        return is_admin()
449
-            ? esc_html__(
450
-                'Registration is at an external URL for this event.',
451
-                'event_espresso'
452
-            )
453
-            : '';
454
-    }
455
-
456
-
457
-
458
-    /**
459
-     * formOpen
460
-     *
461
-     * @param        int    $ID
462
-     * @param        string $external_url
463
-     * @return        string
464
-     */
465
-    public function formOpen( $ID = 0, $external_url = '' )
466
-    {
467
-        // if redirecting, we don't need any anything else
468
-        if ( $external_url ) {
469
-            $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"';
470
-            // open link in new window ?
471
-            $html .= apply_filters(
472
-                'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
473
-                EED_Events_Archive::is_iframe()
474
-            )
475
-                ? ' target="_blank"'
476
-                : '';
477
-            $html .= '>';
478
-            $query_args = EEH_URL::get_query_string( $external_url );
479
-            foreach ( (array)$query_args as $query_arg => $value ) {
480
-                $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
481
-            }
482
-            return $html;
483
-        }
484
-        // if there is no submit button, then don't start building a form
485
-        // because the "View Details" button will build its own form
486
-        if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) {
487
-            return '';
488
-        }
489
-        $checkout_url = EEH_Event_View::event_link_url( $ID );
490
-        if ( ! $checkout_url ) {
491
-            EE_Error::add_error(
492
-                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
493
-                __FILE__,
494
-                __FUNCTION__,
495
-                __LINE__
496
-            );
497
-        }
498
-        // set no cache headers and constants
499
-        EE_System::do_not_cache();
500
-        $extra_params = $this->iframe ? ' target="_blank"' : '';
501
-        $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
502
-        $html .= wp_nonce_field( 'process_ticket_selections', 'process_ticket_selections_nonce_' . $ID, true, false );
503
-        $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
504
-        $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event );
505
-        return $html;
506
-    }
507
-
508
-
509
-
510
-    /**
511
-     * displaySubmitButton
512
-     *
513
-     * @param  string $external_url
514
-     * @return string
515
-     * @throws EE_Error
516
-     */
517
-    public function displaySubmitButton($external_url = '')
518
-    {
519
-        $html = '';
520
-        if ( ! is_admin()) {
521
-            // standard TS displayed with submit button, ie: "Register Now"
522
-            if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
523
-                $html .= $this->displayRegisterNowButton();
524
-                $html .= empty($external_url)
525
-                    ? $this->ticketSelectorEndDiv()
526
-                    : $this->clearTicketSelector();
527
-                $html .= '<br/>' . $this->formClose();
528
-            } else if ($this->getMaxAttendees() === 1) {
529
-                // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
530
-                if ($this->event->is_sold_out()) {
531
-                    // then instead of a View Details or Submit button, just display a "Sold Out" message
532
-                    $html .= apply_filters(
533
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
534
-                        sprintf(
535
-                            __(
536
-                                '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
537
-                                'event_espresso'
538
-                            ),
539
-                            '<p class="no-ticket-selector-msg clear-float">',
540
-                            $this->event->name(),
541
-                            '</p>',
542
-                            '<br />'
543
-                        ),
544
-                        $this->event
545
-                    );
546
-                    if (
547
-                        apply_filters(
548
-                            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
549
-                            false,
550
-                            $this->event
551
-                        )
552
-                    ) {
553
-                        $html .= $this->displayRegisterNowButton();
554
-                    }
555
-                    // sold out DWMTS event, no TS, no submit or view details button, but has additional content
556
-                    $html .=  $this->ticketSelectorEndDiv();
557
-                } else if (
558
-                    apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
559
-                    && ! is_single()
560
-                ) {
561
-                    // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
562
-                    // but no tickets are available, so display event's "View Details" button.
563
-                    // it is being viewed via somewhere other than a single post
564
-                    $html .= $this->displayViewDetailsButton(true);
565
-                } else {
566
-                    $html .= $this->ticketSelectorEndDiv();
567
-                }
568
-            } else if (is_archive()) {
569
-                // event list, no tickets available so display event's "View Details" button
570
-                $html .= $this->ticketSelectorEndDiv();
571
-                $html .= $this->displayViewDetailsButton();
572
-            } else {
573
-                if (
574
-                    apply_filters(
575
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
576
-                        false,
577
-                        $this->event
578
-                    )
579
-                ) {
580
-                    $html .= $this->displayRegisterNowButton();
581
-                }
582
-                // no submit or view details button, and no additional content
583
-                $html .= $this->ticketSelectorEndDiv();
584
-            }
585
-            if ( ! $this->iframe && ! is_archive()) {
586
-                $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
587
-            }
588
-        }
589
-	    return apply_filters(
590
-		    'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
591
-		    $html,
592
-		    $this->event
593
-	    );
594
-    }
595
-
596
-
597
-
598
-    /**
599
-     * @return string
600
-     * @throws EE_Error
601
-     */
602
-    public function displayRegisterNowButton()
603
-    {
604
-        $btn_text = apply_filters(
605
-            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
606
-            __('Register Now', 'event_espresso'),
607
-            $this->event
608
-        );
609
-        $external_url = $this->event->external_url();
610
-        $html = EEH_HTML::div(
611
-            '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap'
612
-        );
613
-        $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
614
-        $html .= ' class="ticket-selector-submit-btn ';
615
-        $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
616
-        $html .= ' type="submit" value="' . $btn_text . '" />';
617
-        $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
618
-        $html .= apply_filters(
619
-            'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
620
-            '',
621
-            $this->event
622
-        );
623
-        return $html;
624
-    }
625
-
626
-
627
-    /**
628
-     * displayViewDetailsButton
629
-     *
630
-     * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
631
-     *                    (ie: $_max_atndz === 1) where there are no available tickets,
632
-     *                    either because they are sold out, expired, or not yet on sale.
633
-     *                    In this case, we need to close the form BEFORE adding any closing divs
634
-     * @return string
635
-     * @throws EE_Error
636
-     */
637
-    public function displayViewDetailsButton( $DWMTS = false )
638
-    {
639
-        if ( ! $this->event->get_permalink() ) {
640
-            EE_Error::add_error(
641
-                esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
642
-                __FILE__, __FUNCTION__, __LINE__
643
-            );
644
-        }
645
-        $view_details_btn = '<form method="POST" action="';
646
-        $view_details_btn .= apply_filters(
647
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
648
-            $this->event->get_permalink(),
649
-            $this->event
650
-        );
651
-        $view_details_btn .= '"';
652
-        // open link in new window ?
653
-        $view_details_btn .= apply_filters(
654
-            'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
655
-            EED_Events_Archive::is_iframe()
656
-        )
657
-            ? ' target="_blank"'
658
-            : '';
659
-        $view_details_btn .='>';
660
-        $btn_text = apply_filters(
661
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
662
-            esc_html__('View Details', 'event_espresso'),
663
-            $this->event
664
-        );
665
-        $view_details_btn .= '<input id="ticket-selector-submit-'
666
-                             . $this->event->ID()
667
-                             . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
668
-                             . $btn_text
669
-                             . '" />';
670
-        $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event );
671
-        if ($DWMTS) {
672
-            $view_details_btn .= $this->formClose();
673
-            $view_details_btn .= $this->ticketSelectorEndDiv();
674
-            $view_details_btn .= '<br/>';
675
-        } else {
676
-            $view_details_btn .= $this->clearTicketSelector();
677
-            $view_details_btn .= '<br/>';
678
-            $view_details_btn .= $this->formClose();
679
-        }
680
-        return $view_details_btn;
681
-    }
682
-
683
-
684
-
685
-    /**
686
-     * @return string
687
-     */
688
-    public function ticketSelectorEndDiv()
689
-    {
690
-        return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
691
-    }
692
-
693
-
694
-
695
-    /**
696
-     * @return string
697
-     */
698
-    public function clearTicketSelector()
699
-    {
700
-        // standard TS displayed, appears after a "Register Now" or "view Details" button
701
-        return '<div class="clear"></div><!-- clearTicketSelector -->';
702
-    }
703
-
704
-
705
-
706
-    /**
707
-     * @access        public
708
-     * @return        string
709
-     */
710
-    public function formClose()
711
-    {
712
-        return '</form>';
713
-    }
288
+	}
289
+
290
+
291
+
292
+	/**
293
+	 * ticketSalesClosed
294
+	 * notice displayed if event ticket sales are turned off
295
+	 *
296
+	 * @return string
297
+	 * @throws EE_Error
298
+	 */
299
+	protected function ticketSalesClosedMessage()
300
+	{
301
+		$sales_closed_msg = esc_html__(
302
+			'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
303
+			'event_espresso'
304
+		);
305
+		if (current_user_can('edit_post', $this->event->ID())) {
306
+			$sales_closed_msg .= sprintf(
307
+				esc_html__(
308
+					'%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
309
+					'event_espresso'
310
+				),
311
+				'<div class="ee-attention" style="text-align: left;"><b>',
312
+				'</b><br />',
313
+				'<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">',
314
+				'</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->'
315
+			);
316
+		}
317
+		return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
318
+	}
319
+
320
+
321
+
322
+	/**
323
+	 * getTickets
324
+	 *
325
+	 * @return \EE_Base_Class[]|\EE_Ticket[]
326
+	 * @throws EE_Error
327
+	 */
328
+	protected function getTickets()
329
+	{
330
+		$ticket_query_args = array(
331
+			array('Datetime.EVT_ID' => $this->event->ID()),
332
+			'order_by' => array(
333
+				'TKT_order'              => 'ASC',
334
+				'TKT_required'           => 'DESC',
335
+				'TKT_start_date'         => 'ASC',
336
+				'TKT_end_date'           => 'ASC',
337
+				'Datetime.DTT_EVT_start' => 'DESC',
338
+			),
339
+		);
340
+		if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) {
341
+			//use the correct applicable time query depending on what version of core is being run.
342
+			$current_time = method_exists('EEM_Datetime', 'current_time_for_query')
343
+				? time()
344
+				: current_time('timestamp');
345
+			$ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
346
+		}
347
+		return EEM_Ticket::instance()->get_all($ticket_query_args);
348
+	}
349
+
350
+
351
+
352
+	/**
353
+	 * loadTicketSelector
354
+	 * begins to assemble template arguments
355
+	 * and decides whether to load a "simple" ticket selector, or the standard
356
+	 *
357
+	 * @param \EE_Ticket[] $tickets
358
+	 * @param array $template_args
359
+	 * @return string
360
+	 * @throws EE_Error
361
+	 */
362
+	protected function loadTicketSelector(array $tickets, array $template_args)
363
+	{
364
+		$template_args['event'] = $this->event;
365
+		$template_args['EVT_ID'] = $this->event->ID();
366
+		$template_args['event_is_expired'] = $this->event->is_expired();
367
+		$template_args['max_atndz'] = $this->getMaxAttendees();
368
+		$template_args['date_format'] = $this->date_format;
369
+		$template_args['time_format'] = $this->time_format;
370
+		/**
371
+		 * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected
372
+		 *
373
+		 * @since 4.9.13
374
+		 * @param     string  '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to
375
+		 * @param int $EVT_ID The Event ID
376
+		 */
377
+		$template_args['anchor_id'] = apply_filters(
378
+			'FHEE__EE_Ticket_Selector__redirect_anchor_id',
379
+			'#tkt-slctr-tbl-' . $this->event->ID(),
380
+			$this->event->ID()
381
+		);
382
+		$template_args['tickets'] = $tickets;
383
+		$template_args['ticket_count'] = count($tickets);
384
+		$ticket_selector = $this->simpleTicketSelector( $tickets, $template_args);
385
+		return $ticket_selector instanceof TicketSelectorSimple
386
+			? $ticket_selector
387
+			: new TicketSelectorStandard(
388
+				$this->event,
389
+				$tickets,
390
+				$this->getMaxAttendees(),
391
+				$template_args,
392
+				$this->date_format,
393
+				$this->time_format
394
+			);
395
+	}
396
+
397
+
398
+
399
+	/**
400
+	 * simpleTicketSelector
401
+	 * there's one ticket, and max attendees is set to one,
402
+	 * so if the event is free, then this is a "simple" ticket selector
403
+	 * a.k.a. "Dude Where's my Ticket Selector?"
404
+	 *
405
+	 * @param \EE_Ticket[] $tickets
406
+	 * @param array  $template_args
407
+	 * @return string
408
+	 * @throws EE_Error
409
+	 */
410
+	protected function simpleTicketSelector($tickets, array $template_args)
411
+	{
412
+		// if there is only ONE ticket with a max qty of ONE
413
+		if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) {
414
+			return '';
415
+		}
416
+		/** @var \EE_Ticket $ticket */
417
+		$ticket = reset($tickets);
418
+		// if the ticket is free... then not much need for the ticket selector
419
+		if (
420
+			apply_filters(
421
+				'FHEE__ticket_selector_chart_template__hide_ticket_selector',
422
+				$ticket->is_free(),
423
+				$this->event->ID()
424
+			)
425
+		) {
426
+			return new TicketSelectorSimple(
427
+				$this->event,
428
+				$ticket,
429
+				$this->getMaxAttendees(),
430
+				$template_args
431
+			);
432
+		}
433
+		return '';
434
+	}
435
+
436
+
437
+
438
+	/**
439
+	 * externalEventRegistration
440
+	 *
441
+	 * @return string
442
+	 */
443
+	public function externalEventRegistration()
444
+	{
445
+		// if not we still need to trigger the display of the submit button
446
+		add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
447
+		//display notice to admin that registration is external
448
+		return is_admin()
449
+			? esc_html__(
450
+				'Registration is at an external URL for this event.',
451
+				'event_espresso'
452
+			)
453
+			: '';
454
+	}
455
+
456
+
457
+
458
+	/**
459
+	 * formOpen
460
+	 *
461
+	 * @param        int    $ID
462
+	 * @param        string $external_url
463
+	 * @return        string
464
+	 */
465
+	public function formOpen( $ID = 0, $external_url = '' )
466
+	{
467
+		// if redirecting, we don't need any anything else
468
+		if ( $external_url ) {
469
+			$html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"';
470
+			// open link in new window ?
471
+			$html .= apply_filters(
472
+				'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank',
473
+				EED_Events_Archive::is_iframe()
474
+			)
475
+				? ' target="_blank"'
476
+				: '';
477
+			$html .= '>';
478
+			$query_args = EEH_URL::get_query_string( $external_url );
479
+			foreach ( (array)$query_args as $query_arg => $value ) {
480
+				$html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
481
+			}
482
+			return $html;
483
+		}
484
+		// if there is no submit button, then don't start building a form
485
+		// because the "View Details" button will build its own form
486
+		if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) {
487
+			return '';
488
+		}
489
+		$checkout_url = EEH_Event_View::event_link_url( $ID );
490
+		if ( ! $checkout_url ) {
491
+			EE_Error::add_error(
492
+				esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
493
+				__FILE__,
494
+				__FUNCTION__,
495
+				__LINE__
496
+			);
497
+		}
498
+		// set no cache headers and constants
499
+		EE_System::do_not_cache();
500
+		$extra_params = $this->iframe ? ' target="_blank"' : '';
501
+		$html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
502
+		$html .= wp_nonce_field( 'process_ticket_selections', 'process_ticket_selections_nonce_' . $ID, true, false );
503
+		$html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
504
+		$html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event );
505
+		return $html;
506
+	}
507
+
508
+
509
+
510
+	/**
511
+	 * displaySubmitButton
512
+	 *
513
+	 * @param  string $external_url
514
+	 * @return string
515
+	 * @throws EE_Error
516
+	 */
517
+	public function displaySubmitButton($external_url = '')
518
+	{
519
+		$html = '';
520
+		if ( ! is_admin()) {
521
+			// standard TS displayed with submit button, ie: "Register Now"
522
+			if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
523
+				$html .= $this->displayRegisterNowButton();
524
+				$html .= empty($external_url)
525
+					? $this->ticketSelectorEndDiv()
526
+					: $this->clearTicketSelector();
527
+				$html .= '<br/>' . $this->formClose();
528
+			} else if ($this->getMaxAttendees() === 1) {
529
+				// its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
530
+				if ($this->event->is_sold_out()) {
531
+					// then instead of a View Details or Submit button, just display a "Sold Out" message
532
+					$html .= apply_filters(
533
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
534
+						sprintf(
535
+							__(
536
+								'%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
537
+								'event_espresso'
538
+							),
539
+							'<p class="no-ticket-selector-msg clear-float">',
540
+							$this->event->name(),
541
+							'</p>',
542
+							'<br />'
543
+						),
544
+						$this->event
545
+					);
546
+					if (
547
+						apply_filters(
548
+							'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
549
+							false,
550
+							$this->event
551
+						)
552
+					) {
553
+						$html .= $this->displayRegisterNowButton();
554
+					}
555
+					// sold out DWMTS event, no TS, no submit or view details button, but has additional content
556
+					$html .=  $this->ticketSelectorEndDiv();
557
+				} else if (
558
+					apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
559
+					&& ! is_single()
560
+				) {
561
+					// this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
562
+					// but no tickets are available, so display event's "View Details" button.
563
+					// it is being viewed via somewhere other than a single post
564
+					$html .= $this->displayViewDetailsButton(true);
565
+				} else {
566
+					$html .= $this->ticketSelectorEndDiv();
567
+				}
568
+			} else if (is_archive()) {
569
+				// event list, no tickets available so display event's "View Details" button
570
+				$html .= $this->ticketSelectorEndDiv();
571
+				$html .= $this->displayViewDetailsButton();
572
+			} else {
573
+				if (
574
+					apply_filters(
575
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
576
+						false,
577
+						$this->event
578
+					)
579
+				) {
580
+					$html .= $this->displayRegisterNowButton();
581
+				}
582
+				// no submit or view details button, and no additional content
583
+				$html .= $this->ticketSelectorEndDiv();
584
+			}
585
+			if ( ! $this->iframe && ! is_archive()) {
586
+				$html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
587
+			}
588
+		}
589
+		return apply_filters(
590
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html',
591
+			$html,
592
+			$this->event
593
+		);
594
+	}
595
+
596
+
597
+
598
+	/**
599
+	 * @return string
600
+	 * @throws EE_Error
601
+	 */
602
+	public function displayRegisterNowButton()
603
+	{
604
+		$btn_text = apply_filters(
605
+			'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
606
+			__('Register Now', 'event_espresso'),
607
+			$this->event
608
+		);
609
+		$external_url = $this->event->external_url();
610
+		$html = EEH_HTML::div(
611
+			'', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap'
612
+		);
613
+		$html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"';
614
+		$html .= ' class="ticket-selector-submit-btn ';
615
+		$html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
616
+		$html .= ' type="submit" value="' . $btn_text . '" />';
617
+		$html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->';
618
+		$html .= apply_filters(
619
+			'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
620
+			'',
621
+			$this->event
622
+		);
623
+		return $html;
624
+	}
625
+
626
+
627
+	/**
628
+	 * displayViewDetailsButton
629
+	 *
630
+	 * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
631
+	 *                    (ie: $_max_atndz === 1) where there are no available tickets,
632
+	 *                    either because they are sold out, expired, or not yet on sale.
633
+	 *                    In this case, we need to close the form BEFORE adding any closing divs
634
+	 * @return string
635
+	 * @throws EE_Error
636
+	 */
637
+	public function displayViewDetailsButton( $DWMTS = false )
638
+	{
639
+		if ( ! $this->event->get_permalink() ) {
640
+			EE_Error::add_error(
641
+				esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ),
642
+				__FILE__, __FUNCTION__, __LINE__
643
+			);
644
+		}
645
+		$view_details_btn = '<form method="POST" action="';
646
+		$view_details_btn .= apply_filters(
647
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
648
+			$this->event->get_permalink(),
649
+			$this->event
650
+		);
651
+		$view_details_btn .= '"';
652
+		// open link in new window ?
653
+		$view_details_btn .= apply_filters(
654
+			'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank',
655
+			EED_Events_Archive::is_iframe()
656
+		)
657
+			? ' target="_blank"'
658
+			: '';
659
+		$view_details_btn .='>';
660
+		$btn_text = apply_filters(
661
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
662
+			esc_html__('View Details', 'event_espresso'),
663
+			$this->event
664
+		);
665
+		$view_details_btn .= '<input id="ticket-selector-submit-'
666
+							 . $this->event->ID()
667
+							 . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
668
+							 . $btn_text
669
+							 . '" />';
670
+		$view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event );
671
+		if ($DWMTS) {
672
+			$view_details_btn .= $this->formClose();
673
+			$view_details_btn .= $this->ticketSelectorEndDiv();
674
+			$view_details_btn .= '<br/>';
675
+		} else {
676
+			$view_details_btn .= $this->clearTicketSelector();
677
+			$view_details_btn .= '<br/>';
678
+			$view_details_btn .= $this->formClose();
679
+		}
680
+		return $view_details_btn;
681
+	}
682
+
683
+
684
+
685
+	/**
686
+	 * @return string
687
+	 */
688
+	public function ticketSelectorEndDiv()
689
+	{
690
+		return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->';
691
+	}
692
+
693
+
694
+
695
+	/**
696
+	 * @return string
697
+	 */
698
+	public function clearTicketSelector()
699
+	{
700
+		// standard TS displayed, appears after a "Register Now" or "view Details" button
701
+		return '<div class="clear"></div><!-- clearTicketSelector -->';
702
+	}
703
+
704
+
705
+
706
+	/**
707
+	 * @access        public
708
+	 * @return        string
709
+	 */
710
+	public function formClose()
711
+	{
712
+		return '</form>';
713
+	}
714 714
 
715 715
 
716 716
 
Please login to merge, or discard this patch.
core/admin/EE_Admin.core.php 1 patch
Spacing   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 */
41 41
 	public static function instance() {
42 42
 		// check if class object is instantiated
43
-		if (  ! self::$_instance instanceof EE_Admin ) {
43
+		if ( ! self::$_instance instanceof EE_Admin) {
44 44
 			self::$_instance = new self();
45 45
 		}
46 46
 		return self::$_instance;
@@ -57,25 +57,25 @@  discard block
 block discarded – undo
57 57
 		// define global EE_Admin constants
58 58
 		$this->_define_all_constants();
59 59
 		// set autoloaders for our admin page classes based on included path information
60
-		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder( EE_ADMIN );
60
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN);
61 61
 		// admin hooks
62
-		add_filter( 'plugin_action_links', array( $this, 'filter_plugin_actions' ), 10, 2 );
62
+		add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2);
63 63
 		// load EE_Request_Handler early
64
-		add_action( 'AHEE__EE_System__core_loaded_and_ready', array( $this, 'get_request' ));
65
-		add_action( 'AHEE__EE_System__initialize_last', array( $this, 'init' ));
66
-		add_action( 'AHEE__EE_Admin_Page__route_admin_request', array( $this, 'route_admin_request' ), 100, 2 );
67
-		add_action( 'wp_loaded', array( $this, 'wp_loaded' ), 100 );
68
-		add_action( 'admin_init', array( $this, 'admin_init' ), 100 );
69
-		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ), 20 );
70
-		add_action( 'admin_notices', array( $this, 'display_admin_notices' ), 10 );
71
-		add_action( 'network_admin_notices', array( $this, 'display_admin_notices' ), 10 );
72
-		add_filter( 'pre_update_option', array( $this, 'check_for_invalid_datetime_formats' ), 100, 2 );
73
-		add_filter('admin_footer_text', array( $this, 'espresso_admin_footer' ));
64
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request'));
65
+		add_action('AHEE__EE_System__initialize_last', array($this, 'init'));
66
+		add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2);
67
+		add_action('wp_loaded', array($this, 'wp_loaded'), 100);
68
+		add_action('admin_init', array($this, 'admin_init'), 100);
69
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20);
70
+		add_action('admin_notices', array($this, 'display_admin_notices'), 10);
71
+		add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
72
+		add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
73
+		add_filter('admin_footer_text', array($this, 'espresso_admin_footer'));
74 74
 
75 75
 		//reset Environment config (we only do this on admin page loads);
76 76
 		EE_Registry::instance()->CFG->environment->recheck_values();
77 77
 
78
-		do_action( 'AHEE__EE_Admin__loaded' );
78
+		do_action('AHEE__EE_Admin__loaded');
79 79
 	}
80 80
 
81 81
 
@@ -90,11 +90,11 @@  discard block
 block discarded – undo
90 90
 	 * @return void
91 91
 	 */
92 92
 	private function _define_all_constants() {
93
-		define( 'EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/' );
94
-		define( 'EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/' );
95
-		define( 'EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS );
96
-		define( 'WP_ADMIN_PATH', ABSPATH . 'wp-admin/' );
97
-		define( 'WP_AJAX_URL', admin_url( 'admin-ajax.php' ));
93
+		define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/');
94
+		define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/');
95
+		define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates'.DS);
96
+		define('WP_ADMIN_PATH', ABSPATH.'wp-admin/');
97
+		define('WP_AJAX_URL', admin_url('admin-ajax.php'));
98 98
 	}
99 99
 
100 100
 
@@ -107,23 +107,23 @@  discard block
 block discarded – undo
107 107
 	 * @param 	string 	$plugin
108 108
 	 * @return 	array
109 109
 	 */
110
-	public function filter_plugin_actions( $links, $plugin ) {
110
+	public function filter_plugin_actions($links, $plugin) {
111 111
 		// set $main_file in stone
112 112
 		static $main_file;
113 113
 		// if $main_file is not set yet
114
-		if ( ! $main_file ) {
115
-			$main_file = plugin_basename( EVENT_ESPRESSO_MAIN_FILE );
114
+		if ( ! $main_file) {
115
+			$main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
116 116
 		}
117
-		 if ( $plugin === $main_file ) {
117
+		 if ($plugin === $main_file) {
118 118
 		 	// compare current plugin to this one
119
-			if ( EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance ) {
120
-				$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>';
121
-				array_unshift( $links, $maintenance_link );
119
+			if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
120
+				$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>';
121
+				array_unshift($links, $maintenance_link);
122 122
 			} else {
123
-				$org_settings_link = '<a href="admin.php?page=espresso_general_settings">' . __( 'Settings', 'event_espresso' ) . '</a>';
124
-				$events_link = '<a href="admin.php?page=espresso_events">' . __( 'Events', 'event_espresso' ) . '</a>';
123
+				$org_settings_link = '<a href="admin.php?page=espresso_general_settings">'.__('Settings', 'event_espresso').'</a>';
124
+				$events_link = '<a href="admin.php?page=espresso_events">'.__('Events', 'event_espresso').'</a>';
125 125
 				// add before other links
126
-				array_unshift( $links, $org_settings_link, $events_link );
126
+				array_unshift($links, $org_settings_link, $events_link);
127 127
 			}
128 128
 		}
129 129
 		return $links;
@@ -138,8 +138,8 @@  discard block
 block discarded – undo
138 138
 	 *	@return void
139 139
 	 */
140 140
 	public function get_request() {
141
-		EE_Registry::instance()->load_core( 'Request_Handler' );
142
-		EE_Registry::instance()->load_core( 'CPT_Strategy' );
141
+		EE_Registry::instance()->load_core('Request_Handler');
142
+		EE_Registry::instance()->load_core('CPT_Strategy');
143 143
 	}
144 144
 
145 145
 
@@ -151,11 +151,11 @@  discard block
 block discarded – undo
151 151
 	 * @param array $admin_page_folder_names
152 152
 	 * @return array
153 153
 	 */
154
-	public function hide_admin_pages_except_maintenance_mode( $admin_page_folder_names = array() ){
154
+	public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) {
155 155
 		return array(
156
-			'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
157
-			'about' => EE_ADMIN_PAGES . 'about' . DS,
158
-			'support' => EE_ADMIN_PAGES . 'support' . DS
156
+			'maintenance' => EE_ADMIN_PAGES.'maintenance'.DS,
157
+			'about' => EE_ADMIN_PAGES.'about'.DS,
158
+			'support' => EE_ADMIN_PAGES.'support'.DS
159 159
 		);
160 160
 	}
161 161
 
@@ -169,31 +169,31 @@  discard block
 block discarded – undo
169 169
 	*/
170 170
 	public function init() {
171 171
 		//only enable most of the EE_Admin IF we're not in full maintenance mode
172
-		if ( EE_Maintenance_Mode::instance()->models_can_query() ){
172
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
173 173
 			//ok so we want to enable the entire admin
174
-			add_action( 'wp_ajax_dismiss_ee_nag_notice', array( $this, 'dismiss_ee_nag_notice_callback' ));
175
-			add_action( 'admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 );
176
-			add_action( 'network_admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 );
174
+			add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback'));
175
+			add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9);
176
+			add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9);
177 177
 			//at a glance dashboard widget
178
-			add_filter( 'dashboard_glance_items', array( $this, 'dashboard_glance_items' ), 10 );
178
+			add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
179 179
 			//filter for get_edit_post_link used on comments for custom post types
180
-			add_filter( 'get_edit_post_link', array( $this, 'modify_edit_post_link' ), 10, 2 );
180
+			add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
181 181
 		}
182 182
 		// run the admin page factory but ONLY if we are doing an ee admin ajax request
183
-		if ( !defined('DOING_AJAX') || EE_ADMIN_AJAX ) {
183
+		if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
184 184
 			try {
185 185
 				//this loads the controller for the admin pages which will setup routing etc
186
-				EE_Registry::instance()->load_core( 'Admin_Page_Loader' );
187
-			} catch ( EE_Error $e ) {
186
+				EE_Registry::instance()->load_core('Admin_Page_Loader');
187
+			} catch (EE_Error $e) {
188 188
 				$e->get_error();
189 189
 			}
190 190
 		}
191
-		add_filter( 'content_save_pre', array( $this, 'its_eSpresso' ), 10, 1 );
191
+		add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
192 192
 		//make sure our CPTs and custom taxonomy metaboxes get shown for first time users
193
-		add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes' ), 10 );
194
-		add_action('admin_head', array( $this, 'register_custom_nav_menu_boxes' ), 10 );
193
+		add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
194
+		add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
195 195
 		//exclude EE critical pages from all nav menus and wp_list_pages
196
-		add_filter('nav_menu_meta_box_object', array( $this, 'remove_pages_from_nav_menu'), 10 );
196
+		add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
197 197
 	}
198 198
 
199 199
 
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
 	 * @param  object $post_type WP post type object
207 207
 	 * @return object            WP post type object
208 208
 	 */
209
-	public function remove_pages_from_nav_menu( $post_type ) {
209
+	public function remove_pages_from_nav_menu($post_type) {
210 210
 		//if this isn't the "pages" post type let's get out
211
-		if ( $post_type->name !== 'page' ) {
211
+		if ($post_type->name !== 'page') {
212 212
 			return $post_type;
213 213
 		}
214 214
 		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
@@ -228,28 +228,28 @@  discard block
 block discarded – undo
228 228
 	 */
229 229
 	public function enable_hidden_ee_nav_menu_metaboxes() {
230 230
 		global $wp_meta_boxes, $pagenow;
231
-		if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php' ) {
231
+		if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
232 232
 			return;
233 233
 		}
234 234
 		$user = wp_get_current_user();
235 235
 		//has this been done yet?
236
-		if ( get_user_option( 'ee_nav_menu_initialized', $user->ID ) ) {
236
+		if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
237 237
 			return;
238 238
 		}
239 239
 
240
-		$hidden_meta_boxes = get_user_option( 'metaboxhidden_nav-menus', $user->ID );
241
-		$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' ) );
240
+		$hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID);
241
+		$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'));
242 242
 
243
-		if ( is_array( $hidden_meta_boxes ) ) {
244
-			foreach ( $hidden_meta_boxes as $key => $meta_box_id ) {
245
-				if ( in_array( $meta_box_id, $initial_meta_boxes ) ) {
246
-					unset( $hidden_meta_boxes[ $key ] );
243
+		if (is_array($hidden_meta_boxes)) {
244
+			foreach ($hidden_meta_boxes as $key => $meta_box_id) {
245
+				if (in_array($meta_box_id, $initial_meta_boxes)) {
246
+					unset($hidden_meta_boxes[$key]);
247 247
 				}
248 248
 			}
249 249
 		}
250 250
 
251
-		update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true );
252
-		update_user_option( $user->ID, 'ee_nav_menu_initialized', 1, true );
251
+		update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
252
+		update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
253 253
 	}
254 254
 
255 255
 
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 	 * @return void
269 269
 	 */
270 270
 	public function register_custom_nav_menu_boxes() {
271
-		add_meta_box( 'add-extra-nav-menu-pages', __('Event Espresso Pages', 'event_espresso'), array( $this, 'ee_cpt_archive_pages' ), 'nav-menus', 'side', 'core' );
271
+		add_meta_box('add-extra-nav-menu-pages', __('Event Espresso Pages', 'event_espresso'), array($this, 'ee_cpt_archive_pages'), 'nav-menus', 'side', 'core');
272 272
 	}
273 273
 
274 274
 
@@ -284,16 +284,16 @@  discard block
 block discarded – undo
284 284
 	 *
285 285
 	 * @return string  the (maybe) modified link
286 286
 	 */
287
-	public function modify_edit_post_link( $link, $id ) {
288
-		if ( ! $post = get_post( $id ) ){
287
+	public function modify_edit_post_link($link, $id) {
288
+		if ( ! $post = get_post($id)) {
289 289
 			return $link;
290 290
 		}
291
-		if ( $post->post_type === 'espresso_attendees' ) {
291
+		if ($post->post_type === 'espresso_attendees') {
292 292
 			$query_args = array(
293 293
 				'action' => 'edit_attendee',
294 294
 				'post' => $id
295 295
 			);
296
-			return EEH_URL::add_query_args_and_nonce( $query_args, admin_url('admin.php?page=espresso_registrations') );
296
+			return EEH_URL::add_query_args_and_nonce($query_args, admin_url('admin.php?page=espresso_registrations'));
297 297
 		}
298 298
 		return $link;
299 299
 	}
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 		global $nav_menu_selected_id;
306 306
 
307 307
 		$db_fields = false;
308
-		$walker = new Walker_Nav_Menu_Checklist( $db_fields );
308
+		$walker = new Walker_Nav_Menu_Checklist($db_fields);
309 309
 		$current_tab = 'event-archives';
310 310
 
311 311
 		/*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) {
@@ -324,9 +324,9 @@  discard block
 block discarded – undo
324 324
 		?>
325 325
 		<div id="posttype-extra-nav-menu-pages" class="posttypediv">
326 326
 			<ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs">
327
-				<li <?php echo ( 'event-archives' === $current_tab ? ' class="tabs"' : '' ); ?>>
328
-					<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">
329
-						<?php _e( 'Event Archive Pages', 'event_espresso' ); ?>
327
+				<li <?php echo ('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>>
328
+					<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">
329
+						<?php _e('Event Archive Pages', 'event_espresso'); ?>
330 330
 					</a>
331 331
 				</li>
332 332
 			<?php /* // temporarily removing but leaving skeleton in place in case we ever decide to add more tabs.
@@ -344,13 +344,13 @@  discard block
 block discarded – undo
344 344
  			<?php */ ?>
345 345
 
346 346
 			<div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php
347
-			echo ( 'event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' );
347
+			echo ('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
348 348
 			?>">
349 349
 				<ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear">
350 350
 					<?php
351 351
 					$pages = $this->_get_extra_nav_menu_pages_items();
352 352
 					$args['walker'] = $walker;
353
-					echo walk_nav_menu_tree( array_map( array( $this, '_setup_extra_nav_menu_pages_items' ), $pages), 0, (object) $args );
353
+					echo walk_nav_menu_tree(array_map(array($this, '_setup_extra_nav_menu_pages_items'), $pages), 0, (object) $args);
354 354
 					?>
355 355
 				</ul>
356 356
 			</div><!-- /.tabs-panel -->
@@ -358,18 +358,18 @@  discard block
 block discarded – undo
358 358
 			<p class="button-controls">
359 359
 				<span class="list-controls">
360 360
 					<a href="<?php
361
-						echo esc_url( add_query_arg(
361
+						echo esc_url(add_query_arg(
362 362
 							array(
363 363
 								'extra-nav-menu-pages-tab' => 'event-archives',
364 364
 								'selectall' => 1,
365 365
 							),
366
-							remove_query_arg( $removed_args )
366
+							remove_query_arg($removed_args)
367 367
 						));
368 368
 					?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a>
369 369
 				</span>
370 370
 
371 371
 				<span class="add-to-menu">
372
-					<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' ); ?>" />
372
+					<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'); ?>" />
373 373
 					<span class="spinner"></span>
374 374
 				</span>
375 375
 			</p>
@@ -390,10 +390,10 @@  discard block
 block discarded – undo
390 390
 	private function _get_extra_nav_menu_pages_items() {
391 391
 		$menuitems[] = array(
392 392
 			'title' => __('Event List', 'event_espresso'),
393
-			'url' => get_post_type_archive_link( 'espresso_events' ),
393
+			'url' => get_post_type_archive_link('espresso_events'),
394 394
 			'description' => __('Archive page for all events.', 'event_espresso')
395 395
 		);
396
-		return apply_filters( 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems );
396
+		return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
397 397
 	}
398 398
 
399 399
 
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
 	 * @param $menu_item_values
406 406
 	 * @return stdClass
407 407
 	 */
408
-	private function _setup_extra_nav_menu_pages_items( $menu_item_values ) {
408
+	private function _setup_extra_nav_menu_pages_items($menu_item_values) {
409 409
 		$menu_item = new stdClass();
410 410
 		$keys = array(
411 411
 			'ID' => 0,
@@ -425,8 +425,8 @@  discard block
 block discarded – undo
425 425
 			'xfn' => ''
426 426
 		);
427 427
 
428
-		foreach ( $keys as $key => $value) {
429
-			$menu_item->{$key} = isset( $menu_item_values[ $key]) ? $menu_item_values[ $key] : $value;
428
+		foreach ($keys as $key => $value) {
429
+			$menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value;
430 430
 		}
431 431
 		return $menu_item;
432 432
 	}
@@ -465,9 +465,9 @@  discard block
 block discarded – undo
465 465
 		 * - check if doing post processing of one of EE CPTs
466 466
 		 * - instantiate the corresponding EE CPT model for the post_type being processed.
467 467
 		 */
468
-		if ( isset( $_POST['action'], $_POST['post_type'] ) && $_POST['action'] === 'editpost' ) {
469
-			EE_Registry::instance()->load_core( 'Register_CPTs' );
470
-			EE_Register_CPTs::instantiate_cpt_models( $_POST['post_type'] );
468
+		if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
469
+			EE_Registry::instance()->load_core('Register_CPTs');
470
+			EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']);
471 471
 		}
472 472
 
473 473
 
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
          * tab in the EE General Settings Admin page.
478 478
          * This is for user-proofing.
479 479
 		 */
480
-        add_filter( 'wp_dropdown_pages', array( $this, 'modify_dropdown_pages' ) );
480
+        add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
481 481
 
482 482
 	}
483 483
 
@@ -488,25 +488,25 @@  discard block
 block discarded – undo
488 488
 	 * @param string $output  Current output.
489 489
 	 * @return string
490 490
 	 */
491
-	public function modify_dropdown_pages( $output ) {
491
+	public function modify_dropdown_pages($output) {
492 492
 		//get critical pages
493 493
 		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
494 494
 
495 495
 		//split current output by line break for easier parsing.
496
-		$split_output = explode( "\n", $output );
496
+		$split_output = explode("\n", $output);
497 497
 
498 498
 		//loop through to remove any critical pages from the array.
499
-		foreach ( $critical_pages as $page_id ) {
500
-			$needle = 'value="' . $page_id . '"';
501
-			foreach( $split_output as $key => $haystack ) {
502
-				if( strpos( $haystack, $needle ) !== false ) {
503
-					unset( $split_output[$key] );
499
+		foreach ($critical_pages as $page_id) {
500
+			$needle = 'value="'.$page_id.'"';
501
+			foreach ($split_output as $key => $haystack) {
502
+				if (strpos($haystack, $needle) !== false) {
503
+					unset($split_output[$key]);
504 504
 				}
505 505
 			}
506 506
 		}
507 507
 
508 508
 		//replace output with the new contents
509
-		return implode( "\n", $split_output );
509
+		return implode("\n", $split_output);
510 510
 	}
511 511
 
512 512
 
@@ -520,17 +520,17 @@  discard block
 block discarded – undo
520 520
 	public function enqueue_admin_scripts() {
521 521
 		// this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
522 522
 		// Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script calls.
523
-		wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE);
523
+		wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE);
524 524
 		// register cookie script for future dependencies
525
-		wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', array('jquery'), '2.1', TRUE );
525
+		wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js', array('jquery'), '2.1', TRUE);
526 526
 		//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' );
527
-		if ( apply_filters( 'FHEE_load_joyride', FALSE ) ) {
527
+		if (apply_filters('FHEE_load_joyride', FALSE)) {
528 528
 			//joyride style
529
-			wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
530
-			wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', array('joyride-css'), EVENT_ESPRESSO_VERSION );
531
-			wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', array(), '2.1', TRUE );
529
+			wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1');
530
+			wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', array('joyride-css'), EVENT_ESPRESSO_VERSION);
531
+			wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', array(), '2.1', TRUE);
532 532
 			//joyride JS
533
-			wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', array('jquery-cookie', 'joyride-modernizr'), '2.1', TRUE );
533
+			wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', array('jquery-cookie', 'joyride-modernizr'), '2.1', TRUE);
534 534
 			// wanna go for a joyride?
535 535
 			wp_enqueue_style('ee-joyride-css');
536 536
 			wp_enqueue_script('jquery-joyride');
@@ -560,11 +560,11 @@  discard block
 block discarded – undo
560 560
 	public function get_persistent_admin_notices() {
561 561
 		// http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30
562 562
 		$args = array(
563
-			'page' => EE_Registry::instance()->REQ->is_set( 'page' ) ? EE_Registry::instance()->REQ->get( 'page' ) : '',
564
-			'action' => EE_Registry::instance()->REQ->is_set( 'action' ) ? EE_Registry::instance()->REQ->get( 'action' ) : '',
563
+			'page' => EE_Registry::instance()->REQ->is_set('page') ? EE_Registry::instance()->REQ->get('page') : '',
564
+			'action' => EE_Registry::instance()->REQ->is_set('action') ? EE_Registry::instance()->REQ->get('action') : '',
565 565
 		);
566
-		$return_url = EE_Admin_Page::add_query_args_and_nonce( $args, EE_ADMIN_URL );
567
-		echo EE_Error::get_persistent_admin_notices( $return_url );
566
+		$return_url = EE_Admin_Page::add_query_args_and_nonce($args, EE_ADMIN_URL);
567
+		echo EE_Error::get_persistent_admin_notices($return_url);
568 568
 	}
569 569
 
570 570
 
@@ -589,24 +589,24 @@  discard block
 block discarded – undo
589 589
 	public function dashboard_glance_items($elements) {
590 590
         $elements = is_array($elements) ? $elements : array($elements);
591 591
 		$events = EEM_Event::instance()->count();
592
-		$items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_events'), admin_url('admin.php') );
593
-		$items['events']['text'] = sprintf( _n( '%s Event', '%s Events', $events ), number_format_i18n( $events ) );
592
+		$items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_events'), admin_url('admin.php'));
593
+		$items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events));
594 594
 		$items['events']['title'] = __('Click to view all Events', 'event_espresso');
595 595
 		$registrations = EEM_Registration::instance()->count(
596 596
 			array(
597 597
 				array(
598
-					'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete )
598
+					'STS_ID' => array('!=', EEM_Registration::status_id_incomplete)
599 599
 				)
600 600
 			)
601 601
 		);
602
-		$items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_registrations' ), admin_url('admin.php') );
603
-		$items['registrations']['text'] = sprintf( _n( '%s Registration', '%s Registrations', $registrations ), number_format_i18n($registrations) );
602
+		$items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_registrations'), admin_url('admin.php'));
603
+		$items['registrations']['text'] = sprintf(_n('%s Registration', '%s Registrations', $registrations), number_format_i18n($registrations));
604 604
 		$items['registrations']['title'] = __('Click to view all registrations', 'event_espresso');
605 605
 
606
-		$items = (array) apply_filters( 'FHEE__EE_Admin__dashboard_glance_items__items', $items );
606
+		$items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
607 607
 
608
-		foreach ( $items as $type => $item_properties ) {
609
-			$elements[] = sprintf( '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', $item_properties['url'], $item_properties['title'], $item_properties['text'] );
608
+		foreach ($items as $type => $item_properties) {
609
+			$elements[] = sprintf('<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>', $item_properties['url'], $item_properties['title'], $item_properties['text']);
610 610
 		}
611 611
 		return $elements;
612 612
 	}
@@ -623,31 +623,31 @@  discard block
 block discarded – undo
623 623
 	 * @throws EE_Error
624 624
 	 * @return    string
625 625
 	 */
626
-	public function check_for_invalid_datetime_formats( $value, $option ) {
626
+	public function check_for_invalid_datetime_formats($value, $option) {
627 627
 		// check for date_format or time_format
628
-		switch ( $option ) {
628
+		switch ($option) {
629 629
 			case 'date_format' :
630
-				$date_time_format = $value . ' ' . get_option('time_format');
630
+				$date_time_format = $value.' '.get_option('time_format');
631 631
 				break;
632 632
 			case 'time_format' :
633
-				$date_time_format = get_option('date_format') . ' ' . $value;
633
+				$date_time_format = get_option('date_format').' '.$value;
634 634
 				break;
635 635
 			default :
636 636
 				$date_time_format = FALSE;
637 637
 		}
638 638
 		// do we have a date_time format to check ?
639
-		if ( $date_time_format ) {
640
-			$error_msg = EEH_DTT_Helper::validate_format_string( $date_time_format );
639
+		if ($date_time_format) {
640
+			$error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
641 641
 
642
-			if ( is_array( $error_msg ) ) {
643
-				$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>';
642
+			if (is_array($error_msg)) {
643
+				$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>';
644 644
 
645 645
 
646
-				foreach ( $error_msg as $error ) {
647
-					$msg .= '<li>' . $error . '</li>';
646
+				foreach ($error_msg as $error) {
647
+					$msg .= '<li>'.$error.'</li>';
648 648
 				}
649 649
 
650
-				$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>';
650
+				$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>';
651 651
 
652 652
 				// trigger WP settings error
653 653
 				add_settings_error(
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
657 657
 				);
658 658
 
659 659
 				// set format to something valid
660
-				switch ( $option ) {
660
+				switch ($option) {
661 661
 					case 'date_format' :
662 662
 						$value = 'F j, Y';
663 663
 						break;
@@ -679,8 +679,8 @@  discard block
 block discarded – undo
679 679
 	 * @param $content
680 680
 	 * @return    string
681 681
 	 */
682
-	public function its_eSpresso( $content ) {
683
-		return str_replace( '[EXPRESSO_', '[ESPRESSO_', $content );
682
+	public function its_eSpresso($content) {
683
+		return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
684 684
 	}
685 685
 
686 686
 
@@ -692,7 +692,7 @@  discard block
 block discarded – undo
692 692
 	 *  @return 	string
693 693
 	 */
694 694
 	public function espresso_admin_footer() {
695
-		return \EEH_Template::powered_by_event_espresso( 'aln-cntr', '', array( 'utm_content' => 'admin_footer' ));
695
+		return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
696 696
 	}
697 697
 
698 698
 
@@ -711,12 +711,12 @@  discard block
 block discarded – undo
711 711
 	 * @param array $config
712 712
 	 * @return void
713 713
 	 */
714
-	public static function register_ee_admin_page( $page_basename, $page_path, $config = array() ) {
715
-		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' );
716
-		if ( class_exists( 'EE_Register_Admin_Page' ) ) {
714
+	public static function register_ee_admin_page($page_basename, $page_path, $config = array()) {
715
+		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');
716
+		if (class_exists('EE_Register_Admin_Page')) {
717 717
 			$config['page_path'] = $page_path;
718 718
 		}
719
-		EE_Register_Admin_Page::register( $page_basename, $config );
719
+		EE_Register_Admin_Page::register($page_basename, $config);
720 720
 
721 721
 	}
722 722
 
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
 	 * @param  \WP_Post $post
730 730
 	 * @return void
731 731
 	 */
732
-	public static function parse_post_content_on_save( $post_ID, $post ) {
732
+	public static function parse_post_content_on_save($post_ID, $post) {
733 733
 		EE_Error::doing_it_wrong(
734 734
 			__METHOD__,
735 735
 			__('Usage is deprecated', 'event_espresso'),
@@ -747,7 +747,7 @@  discard block
 block discarded – undo
747 747
 	 * @param  $value
748 748
 	 * @return void
749 749
 	 */
750
-	public function reset_page_for_posts_on_change( $option, $old_value, $value ) {
750
+	public function reset_page_for_posts_on_change($option, $old_value, $value) {
751 751
 		EE_Error::doing_it_wrong(
752 752
 			__METHOD__,
753 753
 			__('Usage is deprecated', 'event_espresso'),
Please login to merge, or discard this patch.