Completed
Branch BUG-8957-add-countries (49f36b)
by
unknown
33:27 queued 16:54
created

EE_Tax_Config   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
1
<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
	exit( 'No direct script access allowed' );
3
}
4
5
6
7
/**
8
 * EE_Config
9
 *
10
 * @package     Event Espresso
11
 * @subpackage  core/
12
 * @author      Brent Christensen
13
 */
14
final class EE_Config {
15
16
	const OPTION_NAME        = 'ee_config';
17
18
	const LOG_NAME           = 'ee_config_log';
19
20
	const LOG_LENGTH         = 100;
21
22
	const ADDON_OPTION_NAMES = 'ee_config_option_names';
23
24
25
	/**
26
	 *    instance of the EE_Config object
27
	 *
28
	 * @var    EE_Config $_instance
29
	 * @access    private
30
	 */
31
	private static $_instance;
32
33
	/**
34
	 * An StdClass whose property names are addon slugs,
35
	 * and values are their config classes
36
	 *
37
	 * @var StdClass
38
	 */
39
	public $addons;
40
41
	/**
42
	 * @var EE_Admin_Config
43
	 */
44
	public $admin;
45
46
	/**
47
	 * @var EE_Core_Config
48
	 */
49
	public $core;
50
51
	/**
52
	 * @var EE_Currency_Config
53
	 */
54
	public $currency;
55
56
	/**
57
	 * @var EE_Organization_Config
58
	 */
59
	public $organization;
60
61
	/**
62
	 * @var EE_Registration_Config
63
	 */
64
	public $registration;
65
66
	/**
67
	 * @var EE_Template_Config
68
	 */
69
	public $template_settings;
70
71
	/**
72
	 * Holds EE environment values.
73
	 *
74
	 * @var EE_Environment_Config
75
	 */
76
	public $environment;
77
78
	/**
79
	 * settings pertaining to Google maps
80
	 *
81
	 * @var EE_Map_Config
82
	 */
83
	public $map_settings;
84
85
	/**
86
	 * settings pertaining to Taxes
87
	 *
88
	 * @var EE_Tax_Config
89
	 */
90
	public $tax_settings;
91
92
	/**
93
	 * @deprecated
94
	 * @var EE_Gateway_Config
95
	 */
96
	public $gateway;
97
98
	/**
99
	 * @var    array $_addon_option_names
100
	 * @access    private
101
	 */
102
	private $_addon_option_names = array();
103
104
	/**
105
	 * @var    array $_module_route_map
106
	 * @access    private
107
	 */
108
	private static $_module_route_map = array();
109
110
	/**
111
	 * @var    array $_module_forward_map
112
	 * @access    private
113
	 */
114
	private static $_module_forward_map = array();
115
116
	/**
117
	 * @var    array $_module_view_map
118
	 * @access    private
119
	 */
120
	private static $_module_view_map = array();
121
122
123
124
	/**
125
	 * @singleton method used to instantiate class object
126
	 * @access    public
127
	 * @return EE_Config instance
128
	 */
129
	public static function instance() {
130
		// check if class object is instantiated, and instantiated properly
131
		if ( ! self::$_instance instanceof EE_Config ) {
132
			self::$_instance = new self();
133
		}
134
		return self::$_instance;
135
	}
136
137
138
139
	/**
140
	 * Resets the config
141
	 *
142
	 * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
143
	 *                               (default) leaves the database alone, and merely resets the EE_Config object to
144
	 *                               reflect its state in the database
145
	 * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
146
	 *                               $_instance as NULL. Useful in case you want to forget about the old instance on
147
	 *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
148
	 *                               site was put into maintenance mode)
149
	 * @return EE_Config
150
	 */
151
	public static function reset( $hard_reset = false, $reinstantiate = true ) {
152
		if ( $hard_reset ) {
153
			self::$_instance->_addon_option_names = array();
154
			self::$_instance->_initialize_config();
155
			self::$_instance->update_espresso_config();
156
		}
157
		if ( self::$_instance instanceof EE_Config ) {
158
			self::$_instance->update_addon_option_names();
159
		}
160
		self::$_instance = null;
161
		//we don't need to reset the static properties imo because those should
162
		//only change when a module is added or removed. Currently we don't
163
		//support removing a module during a request when it previously existed
164
		if ( $reinstantiate ) {
165
			return self::instance();
166
		} else {
167
			return null;
168
		}
169
	}
170
171
172
173
	/**
174
	 *    class constructor
175
	 *
176
	 * @access    private
177
	 */
178
	private function __construct() {
179
		do_action( 'AHEE__EE_Config__construct__begin', $this );
180
		// setup empty config classes
181
		$this->_initialize_config();
182
		// load existing EE site settings
183
		$this->_load_core_config();
184
		// confirm everything loaded correctly and set filtered defaults if not
185
		$this->_verify_config();
186
		//  register shortcodes and modules
187
		add_action(
188
			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
189
			array( $this, 'register_shortcodes_and_modules' ),
190
			999
191
		);
192
		//  initialize shortcodes and modules
193
		add_action( 'AHEE__EE_System__core_loaded_and_ready', array( $this, 'initialize_shortcodes_and_modules' ) );
194
		// register widgets
195
		add_action( 'widgets_init', array( $this, 'widgets_init' ), 10 );
196
		// shutdown
197
		add_action( 'shutdown', array( $this, 'shutdown' ), 10 );
198
		// construct__end hook
199
		do_action( 'AHEE__EE_Config__construct__end', $this );
200
		// hardcoded hack
201
		$this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
202
	}
203
204
205
206
	/**
207
	 * use to get the current theme if needed from static context
208
	 *
209
	 * @return string current theme set.
210
	 */
211
	public static function get_current_theme() {
212
		return isset( self::$_instance->template_settings->current_espresso_theme )
213
			? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
214
	}
215
216
217
218
	/**
219
	 *        _initialize_config
220
	 *
221
	 * @access private
222
	 * @return void
223
	 */
224
	private function _initialize_config() {
225
		EE_Config::trim_log();
226
		//set defaults
227
		$this->_addon_option_names = get_option( EE_Config::ADDON_OPTION_NAMES, array() );
228
		$this->addons = new stdClass();
229
		// set _module_route_map
230
		EE_Config::$_module_route_map = array();
231
		// set _module_forward_map
232
		EE_Config::$_module_forward_map = array();
233
		// set _module_view_map
234
		EE_Config::$_module_view_map = array();
235
	}
236
237
238
239
	/**
240
	 *        load core plugin configuration
241
	 *
242
	 * @access private
243
	 * @return void
244
	 */
245
	private function _load_core_config() {
246
		// load_core_config__start hook
247
		do_action( 'AHEE__EE_Config___load_core_config__start', $this );
248
		$espresso_config = $this->get_espresso_config();
249
		foreach ( $espresso_config as $config => $settings ) {
250
			// load_core_config__start hook
251
			$settings = apply_filters(
252
				'FHEE__EE_Config___load_core_config__config_settings',
253
				$settings,
254
				$config,
255
				$this
256
			);
257 View Code Duplication
			if ( is_object( $settings ) && property_exists( $this, $config ) ) {
258
				$this->{$config} = apply_filters( 'FHEE__EE_Config___load_core_config__' . $config, $settings );
259
				//call configs populate method to ensure any defaults are set for empty values.
260
				if ( method_exists( $settings, 'populate' ) ) {
261
					$this->{$config}->populate();
262
				}
263
				if ( method_exists( $settings, 'do_hooks' ) ) {
264
					$this->{$config}->do_hooks();
265
				}
266
			}
267
		}
268
		if ( apply_filters( 'FHEE__EE_Config___load_core_config__update_espresso_config', false ) ) {
269
			$this->update_espresso_config();
270
		}
271
		// load_core_config__end hook
272
		do_action( 'AHEE__EE_Config___load_core_config__end', $this );
273
	}
274
275
276
277
	/**
278
	 *    _verify_config
279
	 *
280
	 * @access    protected
281
	 * @return    void
282
	 */
283
	protected function _verify_config() {
284
		$this->core = $this->core instanceof EE_Core_Config
285
			? $this->core
286
			: new EE_Core_Config();
287
		$this->core = apply_filters( 'FHEE__EE_Config___initialize_config__core', $this->core );
288
		$this->organization = $this->organization instanceof EE_Organization_Config
289
			? $this->organization
290
			: new EE_Organization_Config();
291
		$this->organization = apply_filters( 'FHEE__EE_Config___initialize_config__organization', $this->organization );
292
		$this->currency = $this->currency instanceof EE_Currency_Config
293
			? $this->currency
294
			: new EE_Currency_Config();
295
		$this->currency = apply_filters( 'FHEE__EE_Config___initialize_config__currency', $this->currency );
296
		$this->registration = $this->registration instanceof EE_Registration_Config
297
			? $this->registration
298
			: new EE_Registration_Config();
299
		$this->registration = apply_filters( 'FHEE__EE_Config___initialize_config__registration', $this->registration );
300
		$this->admin = $this->admin instanceof EE_Admin_Config
301
			? $this->admin
302
			: new EE_Admin_Config();
303
		$this->admin = apply_filters( 'FHEE__EE_Config___initialize_config__admin', $this->admin );
304
		$this->template_settings = $this->template_settings instanceof EE_Template_Config
305
			? $this->template_settings
306
			: new EE_Template_Config();
307
		$this->template_settings = apply_filters(
308
			'FHEE__EE_Config___initialize_config__template_settings',
309
			$this->template_settings
310
		);
311
		$this->map_settings = $this->map_settings instanceof EE_Map_Config
312
			? $this->map_settings
313
			: new EE_Map_Config();
314
		$this->map_settings = apply_filters( 'FHEE__EE_Config___initialize_config__map_settings', $this->map_settings );
315
		$this->environment = $this->environment instanceof EE_Environment_Config
316
			? $this->environment
317
			: new EE_Environment_Config();
318
		$this->environment = apply_filters( 'FHEE__EE_Config___initialize_config__environment', $this->environment );
319
		$this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
320
			? $this->tax_settings
321
			: new EE_Tax_Config();
322
		$this->tax_settings = apply_filters( 'FHEE__EE_Config___initialize_config__tax_settings', $this->tax_settings );
323
		$this->gateway = $this->gateway instanceof EE_Gateway_Config
0 ignored issues
show
Deprecated Code introduced by
The property EE_Config::$gateway has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
324
			? $this->gateway
0 ignored issues
show
Deprecated Code introduced by
The property EE_Config::$gateway has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
325
			: new EE_Gateway_Config();
0 ignored issues
show
Deprecated Code introduced by
The class EE_Gateway_Config has been deprecated.

This class, trait or interface has been deprecated.

Loading history...
326
		$this->gateway = apply_filters( 'FHEE__EE_Config___initialize_config__gateway', $this->gateway );
0 ignored issues
show
Deprecated Code introduced by
The property EE_Config::$gateway has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
327
	}
328
329
330
331
	/**
332
	 *    get_espresso_config
333
	 *
334
	 * @access    public
335
	 * @return    array of espresso config stuff
336
	 */
337
	public function get_espresso_config() {
338
		// grab espresso configuration
339
		return apply_filters(
340
			'FHEE__EE_Config__get_espresso_config__CFG',
341
			get_option( EE_Config::OPTION_NAME, array() )
342
		);
343
	}
344
345
346
347
	/**
348
	 *    double_check_config_comparison
349
	 *
350
	 * @access    public
351
	 * @param string $option
352
	 * @param        $old_value
353
	 * @param        $value
354
	 */
355
	public function double_check_config_comparison( $option = '', $old_value, $value ) {
356
		// make sure we're checking the ee config
357
		if ( $option === EE_Config::OPTION_NAME ) {
358
			// run a loose comparison of the old value against the new value for type and properties,
359
			// but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
360
			if ( $value != $old_value ) {
361
				// if they are NOT the same, then remove the hook,
362
				// which means the subsequent update results will be based solely on the update query results
363
				// the reason we do this is because, as stated above,
364
				// WP update_option performs an exact instance comparison (===) on any update values passed to it
365
				// this happens PRIOR to serialization and any subsequent update.
366
				// If values are found to match their previous old value,
367
				// then WP bails before performing any update.
368
				// Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
369
				// it just pulled from the db, with the one being passed to it (which will not match).
370
				// HOWEVER, once the object is serialized and passed off to MySQL to update,
371
				// MySQL MAY ALSO NOT perform the update because
372
				// the string it sees in the db looks the same as the new one it has been passed!!!
373
				// This results in the query returning an "affected rows" value of ZERO,
374
				// which gets returned immediately by WP update_option and looks like an error.
375
				remove_action( 'update_option', array( $this, 'check_config_updated' ) );
376
			}
377
		}
378
	}
379
380
381
382
	/**
383
	 *    update_espresso_config
384
	 *
385
	 * @access   public
386
	 */
387
	protected function _reset_espresso_addon_config() {
388
		$this->_addon_option_names = array();
389
		foreach ( $this->addons as $addon_name => $addon_config_obj ) {
0 ignored issues
show
Bug introduced by
The expression $this->addons of type object<stdClass> is not traversable.
Loading history...
390
			$addon_config_obj = maybe_unserialize( $addon_config_obj );
391
			$config_class = get_class( $addon_config_obj );
392
			if ( $addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class ) {
393
				$this->update_config( 'addons', $addon_name, $addon_config_obj, false );
394
			}
395
			$this->addons->{$addon_name} = null;
396
		}
397
	}
398
399
400
401
	/**
402
	 *    update_espresso_config
403
	 *
404
	 * @access   public
405
	 * @param   bool $add_success
406
	 * @param   bool $add_error
407
	 * @return   bool
408
	 */
409
	public function update_espresso_config( $add_success = false, $add_error = true ) {
410
		// don't allow config updates during WP heartbeats
411
		if ( \EE_Registry::instance()->REQ->get( 'action', '' ) === 'heartbeat' ) {
412
			return false;
413
		}
414
		// commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
415
		//$clone = clone( self::$_instance );
416
		//self::$_instance = NULL;
417
		do_action( 'AHEE__EE_Config__update_espresso_config__begin', $this );
418
		$this->_reset_espresso_addon_config();
419
		// hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
420
		// but BEFORE the actual update occurs
421
		add_action( 'update_option', array( $this, 'double_check_config_comparison' ), 1, 3 );
422
		// now update "ee_config"
423
		$saved = update_option( EE_Config::OPTION_NAME, $this );
424
		EE_Config::log( EE_Config::OPTION_NAME );
425
		// if not saved... check if the hook we just added still exists;
426
		// if it does, it means one of two things:
427
		// 		that update_option bailed at the ( $value === $old_value ) conditional,
428
		//		 or...
429
		// 		the db update query returned 0 rows affected
430
		// 		(probably because the data  value was the same from it's perspective)
431
		// so the existence of the hook means that a negative result from update_option is NOT an error,
432
		// but just means no update occurred, so don't display an error to the user.
433
		// BUT... if update_option returns FALSE, AND the hook is missing,
434
		// then it means that something truly went wrong
435
		$saved = ! $saved ? has_action( 'update_option', array( $this, 'double_check_config_comparison' ) ) : $saved;
436
		// remove our action since we don't want it in the system anymore
437
		remove_action( 'update_option', array( $this, 'double_check_config_comparison' ), 1 );
438
		do_action( 'AHEE__EE_Config__update_espresso_config__end', $this, $saved );
439
		//self::$_instance = $clone;
440
		//unset( $clone );
441
		// if config remains the same or was updated successfully
442
		if ( $saved ) {
443
			if ( $add_success ) {
444
				EE_Error::add_success(
445
					__( 'The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso' ),
446
					__FILE__,
447
					__FUNCTION__,
448
					__LINE__
449
				);
450
			}
451
			return true;
452
		} else {
453
			if ( $add_error ) {
454
				EE_Error::add_error(
455
					__( 'The Event Espresso Configuration Settings were not updated.', 'event_espresso' ),
456
					__FILE__,
457
					__FUNCTION__,
458
					__LINE__
459
				);
460
			}
461
			return false;
462
		}
463
	}
464
465
466
467
	/**
468
	 *    _verify_config_params
469
	 *
470
	 * @access    private
471
	 * @param    string         $section
472
	 * @param    string         $name
473
	 * @param    string         $config_class
474
	 * @param    EE_Config_Base $config_obj
475
	 * @param    array          $tests_to_run
476
	 * @param    bool           $display_errors
477
	 * @return    bool    TRUE on success, FALSE on fail
478
	 */
479
	private function _verify_config_params(
480
		$section = '',
481
		$name = '',
482
		$config_class = '',
483
		$config_obj = null,
484
		$tests_to_run = array( 1, 2, 3, 4, 5, 6, 7, 8 ),
485
		$display_errors = true
486
	) {
487
		try {
488
			foreach ( $tests_to_run as $test ) {
489
				switch ( $test ) {
490
					// TEST #1 : check that section was set
491 View Code Duplication
					case 1 :
492
						if ( empty( $section ) ) {
493
							if ( $display_errors ) {
494
								throw new EE_Error(
495
									sprintf(
496
										__(
497
											'No configuration section has been provided while attempting to save "%s".',
498
											'event_espresso'
499
										),
500
										$config_class
501
									)
502
								);
503
							}
504
							return false;
505
						}
506
						break;
507
					// TEST #2 : check that settings section exists
508 View Code Duplication
					case 2 :
509
						if ( ! isset( $this->{$section} ) ) {
510
							if ( $display_errors ) {
511
								throw new EE_Error(
512
									sprintf(
513
										__( 'The "%s" configuration section does not exist.', 'event_espresso' ),
514
										$section
515
									)
516
								);
517
							}
518
							return false;
519
						}
520
						break;
521
					// TEST #3 : check that section is the proper format
522
					case 3 :
523
						if (
524
						! ( $this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass )
525
						) {
526
							if ( $display_errors ) {
527
								throw new EE_Error(
528
									sprintf(
529
										__(
530
											'The "%s" configuration settings have not been formatted correctly.',
531
											'event_espresso'
532
										),
533
										$section
534
									)
535
								);
536
							}
537
							return false;
538
						}
539
						break;
540
					// TEST #4 : check that config section name has been set
541 View Code Duplication
					case 4 :
542
						if ( empty( $name ) ) {
543
							if ( $display_errors ) {
544
								throw new EE_Error(
545
									__(
546
										'No name has been provided for the specific configuration section.',
547
										'event_espresso'
548
									)
549
								);
550
							}
551
							return false;
552
						}
553
						break;
554
					// TEST #5 : check that a config class name has been set
555 View Code Duplication
					case 5 :
556
						if ( empty( $config_class ) ) {
557
							if ( $display_errors ) {
558
								throw new EE_Error(
559
									__(
560
										'No class name has been provided for the specific configuration section.',
561
										'event_espresso'
562
									)
563
								);
564
							}
565
							return false;
566
						}
567
						break;
568
					// TEST #6 : verify config class is accessible
569 View Code Duplication
					case 6 :
570
						if ( ! class_exists( $config_class ) ) {
571
							if ( $display_errors ) {
572
								throw new EE_Error(
573
									sprintf(
574
										__(
575
											'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
576
											'event_espresso'
577
										),
578
										$config_class
579
									)
580
								);
581
							}
582
							return false;
583
						}
584
						break;
585
					// TEST #7 : check that config has even been set
586
					case 7 :
587
						if ( ! isset( $this->{$section}->{$name} ) ) {
588
							if ( $display_errors ) {
589
								throw new EE_Error(
590
									sprintf(
591
										__( 'No configuration has been set for "%1$s->%2$s".', 'event_espresso' ),
592
										$section,
593
										$name
594
									)
595
								);
596
							}
597
							return false;
598
						} else {
599
							// and make sure it's not serialized
600
							$this->{$section}->{$name} = maybe_unserialize( $this->{$section}->{$name} );
601
						}
602
						break;
603
					// TEST #8 : check that config is the requested type
604
					case 8 :
605
						if ( ! $this->{$section}->{$name} instanceof $config_class ) {
606
							if ( $display_errors ) {
607
								throw new EE_Error(
608
									sprintf(
609
										__(
610
											'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
611
											'event_espresso'
612
										),
613
										$section,
614
										$name,
615
										$config_class
616
									)
617
								);
618
							}
619
							return false;
620
						}
621
						break;
622
					// TEST #9 : verify config object
623 View Code Duplication
					case 9 :
624
						if ( ! $config_obj instanceof EE_Config_Base ) {
625
							if ( $display_errors ) {
626
								throw new EE_Error(
627
									sprintf(
628
										__( 'The "%s" class is not an instance of EE_Config_Base.', 'event_espresso' ),
629
										print_r( $config_obj, true )
630
									)
631
								);
632
							}
633
							return false;
634
						}
635
						break;
636
				}
637
			}
638
		} catch ( EE_Error $e ) {
639
			$e->get_error();
640
		}
641
		// you have successfully run the gauntlet
642
		return true;
643
	}
644
645
646
647
	/**
648
	 *    _generate_config_option_name
649
	 *
650
	 * @access        protected
651
	 * @param        string $section
652
	 * @param        string $name
653
	 * @return        string
654
	 */
655
	private function _generate_config_option_name( $section = '', $name = '' ) {
656
		return 'ee_config-' . strtolower( $section . '-' . str_replace( array( 'EE_', 'EED_' ), '', $name ) );
657
	}
658
659
660
661
	/**
662
	 *    _set_config_class
663
	 * ensures that a config class is set, either from a passed config class or one generated from the config name
664
	 *
665
	 * @access    private
666
	 * @param    string $config_class
667
	 * @param    string $name
668
	 * @return    string
669
	 */
670
	private function _set_config_class( $config_class = '', $name = '' ) {
671
		return ! empty( $config_class )
672
			? $config_class
673
			: str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $name ) ) ) . '_Config';
674
	}
675
676
677
678
	/**
679
	 *    set_config
680
	 *
681
	 * @access    protected
682
	 * @param    string         $section
683
	 * @param    string         $name
684
	 * @param    string         $config_class
685
	 * @param    EE_Config_Base $config_obj
686
	 * @return    EE_Config_Base
687
	 */
688
	public function set_config( $section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null ) {
689
		// ensure config class is set to something
690
		$config_class = $this->_set_config_class( $config_class, $name );
691
		// run tests 1-4, 6, and 7 to verify all config params are set and valid
692 View Code Duplication
		if ( ! $this->_verify_config_params( $section, $name, $config_class, null, array( 1, 2, 3, 4, 5, 6 ) ) ) {
693
			return null;
694
		}
695
		$config_option_name = $this->_generate_config_option_name( $section, $name );
696
		// if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
697
		if ( ! isset( $this->_addon_option_names[ $config_option_name ] ) ) {
698
			$this->_addon_option_names[ $config_option_name ] = $config_class;
699
			$this->update_addon_option_names();
700
		}
701
		// verify the incoming config object but suppress errors
702
		if ( ! $this->_verify_config_params( $section, $name, $config_class, $config_obj, array( 9 ), false ) ) {
703
			$config_obj = new $config_class();
704
		}
705
		if ( get_option( $config_option_name ) ) {
706
			EE_Config::log( $config_option_name );
707
			update_option( $config_option_name, $config_obj );
708
			$this->{$section}->{$name} = $config_obj;
709
			return $this->{$section}->{$name};
710
		} else {
711
			// create a wp-option for this config
712
			if ( add_option( $config_option_name, $config_obj, '', 'no' ) ) {
713
				$this->{$section}->{$name} = maybe_unserialize( $config_obj );
714
				return $this->{$section}->{$name};
715
			} else {
716
				EE_Error::add_error(
717
					sprintf( __( 'The "%s" could not be saved to the database.', 'event_espresso' ), $config_class ),
718
					__FILE__,
719
					__FUNCTION__,
720
					__LINE__
721
				);
722
				return null;
723
			}
724
		}
725
	}
726
727
728
729
	/**
730
	 *    update_config
731
	 * Important: the config object must ALREADY be set, otherwise this will produce an error.
732
	 *
733
	 * @access    public
734
	 * @param    string                $section
735
	 * @param    string                $name
736
	 * @param    EE_Config_Base|string $config_obj
737
	 * @param    bool                  $throw_errors
738
	 * @return    bool
739
	 */
740
	public function update_config( $section = '', $name = '', $config_obj = '', $throw_errors = true ) {
741
		// don't allow config updates during WP heartbeats
742
		if ( \EE_Registry::instance()->REQ->get( 'action', '' ) === 'heartbeat' ) {
743
			return false;
744
		}
745
		$config_obj = maybe_unserialize( $config_obj );
746
		// get class name of the incoming object
747
		$config_class = get_class( $config_obj );
748
		// run tests 1-5 and 9 to verify config
749 View Code Duplication
		if ( ! $this->_verify_config_params(
750
			$section,
751
			$name,
752
			$config_class,
753
			$config_obj,
754
			array( 1, 2, 3, 4, 7, 9 )
755
		)
756
		) {
757
			return false;
758
		}
759
		$config_option_name = $this->_generate_config_option_name( $section, $name );
760
		// check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
761
		if ( ! isset( $this->_addon_option_names[ $config_option_name ] ) ) {
762
			// save new config to db
763
			if( $this->set_config( $section, $name, $config_class, $config_obj ) ) {
764
				return true;
765
			}
766
		} else {
767
			// first check if the record already exists
768
			$existing_config = get_option( $config_option_name );
769
			$config_obj = serialize( $config_obj );
770
			// just return if db record is already up to date (NOT type safe comparison)
771
			if ( $existing_config == $config_obj ) {
772
				$this->{$section}->{$name} = $config_obj;
773
				return true;
774
			} else if ( update_option( $config_option_name, $config_obj ) ) {
775
				EE_Config::log( $config_option_name );
776
				// update wp-option for this config class
777
				$this->{$section}->{$name} = $config_obj;
778
				return true;
779
			} elseif ( $throw_errors ) {
780
				EE_Error::add_error(
781
					sprintf(
782
						__(
783
							'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
784
							'event_espresso'
785
						),
786
						$config_class,
787
						'EE_Config->' . $section . '->' . $name
788
					),
789
					__FILE__,
790
					__FUNCTION__,
791
					__LINE__
792
				);
793
			}
794
		}
795
		return false;
796
	}
797
798
799
800
	/**
801
	 *    get_config
802
	 *
803
	 * @access    public
804
	 * @param    string $section
805
	 * @param    string $name
806
	 * @param    string $config_class
807
	 * @return    mixed EE_Config_Base | NULL
808
	 */
809
	public function get_config( $section = '', $name = '', $config_class = '' ) {
810
		// ensure config class is set to something
811
		$config_class = $this->_set_config_class( $config_class, $name );
812
		// run tests 1-4, 6 and 7 to verify that all params have been set
813 View Code Duplication
		if ( ! $this->_verify_config_params( $section, $name, $config_class, null, array( 1, 2, 3, 4, 5, 6 ) ) ) {
814
			return null;
815
		}
816
		// now test if the requested config object exists, but suppress errors
817
		if ( $this->_verify_config_params( $section, $name, $config_class, null, array( 7, 8 ), false ) ) {
818
			// config already exists, so pass it back
819
			return $this->{$section}->{$name};
820
		}
821
		// load config option from db if it exists
822
		$config_obj = $this->get_config_option( $this->_generate_config_option_name( $section, $name ) );
823
		// verify the newly retrieved config object, but suppress errors
824
		if ( $this->_verify_config_params( $section, $name, $config_class, $config_obj, array( 9 ), false ) ) {
825
			// config is good, so set it and pass it back
826
			$this->{$section}->{$name} = $config_obj;
827
			return $this->{$section}->{$name};
828
		}
829
		// oops! $config_obj is not already set and does not exist in the db, so create a new one
830
		$config_obj = $this->set_config( $section, $name, $config_class );
831
		// verify the newly created config object
832
		if ( $this->_verify_config_params( $section, $name, $config_class, $config_obj, array( 9 ) ) ) {
833
			return $this->{$section}->{$name};
834
		} else {
835
			EE_Error::add_error(
836
				sprintf( __( 'The "%s" could not be retrieved from the database.', 'event_espresso' ), $config_class ),
837
				__FILE__,
838
				__FUNCTION__,
839
				__LINE__
840
			);
841
		}
842
		return null;
843
	}
844
845
846
847
	/**
848
	 *    get_config_option
849
	 *
850
	 * @access    public
851
	 * @param    string $config_option_name
852
	 * @return    mixed EE_Config_Base | FALSE
853
	 */
854
	public function get_config_option( $config_option_name = '' ) {
855
		// retrieve the wp-option for this config class.
856
		$config_option = maybe_unserialize( get_option( $config_option_name, array() ) );
857
		if ( empty( $config_option ) ) {
858
			EE_Config::log( $config_option_name . '-NOT-FOUND' );
859
		}
860
		return $config_option;
861
	}
862
863
864
865
	/**
866
	 * log
867
	 *
868
	 * @param string $config_option_name
869
	 */
870
	public static function log( $config_option_name = '' ) {
871
		if ( ! empty( $config_option_name ) ) {
872
			$config_log = get_option( EE_Config::LOG_NAME, array() );
873
			//copy incoming $_REQUEST and sanitize it so we can save it
874
			$_request = $_REQUEST;
875
			array_walk_recursive( $_request, 'sanitize_text_field' );
876
			$config_log[ (string) microtime( true ) ] = array(
877
				'config_name' => $config_option_name,
878
				'request'     => $_request,
879
			);
880
			update_option( EE_Config::LOG_NAME, $config_log );
881
		}
882
	}
883
884
885
886
	/**
887
	 * trim_log
888
	 * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
889
	 */
890
	public static function trim_log() {
891
		$config_log = get_option( EE_Config::LOG_NAME, array() );
892
		$log_length = count( $config_log );
893
		if ( $log_length > EE_Config::LOG_LENGTH ) {
894
			ksort( $config_log );
895
			$config_log = array_slice( $config_log, $log_length - EE_Config::LOG_LENGTH, null, true );
896
			update_option( EE_Config::LOG_NAME, $config_log );
897
		}
898
	}
899
900
901
902
	/**
903
	 *    get_page_for_posts
904
	 *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
905
	 *    wp-option "page_for_posts", or "posts" if no page is selected
906
	 *
907
	 * @access    public
908
	 * @return    string
909
	 */
910 View Code Duplication
	public static function get_page_for_posts() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
911
		$page_for_posts = get_option( 'page_for_posts' );
912
		if ( ! $page_for_posts ) {
913
			return 'posts';
914
		}
915
		/** @type WPDB $wpdb */
916
		global $wpdb;
917
		$SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
918
		return $wpdb->get_var( $wpdb->prepare( $SQL, $page_for_posts ) );
919
	}
920
921
922
923
	/**
924
	 *    register_shortcodes_and_modules.
925
	 *    At this point, it's too early to tell if we're maintenance mode or not.
926
	 *    In fact, this is where we give modules a chance to let core know they exist
927
	 *    so they can help trigger maintenance mode if it's needed
928
	 *
929
	 * @access    public
930
	 * @return    void
931
	 */
932
	public function register_shortcodes_and_modules() {
933
		// allow shortcodes to register with WP and to set hooks for the rest of the system
934
		EE_Registry::instance()->shortcodes = $this->_register_shortcodes();
935
		// allow modules to set hooks for the rest of the system
936
		EE_Registry::instance()->modules = $this->_register_modules();
937
	}
938
939
940
941
	/**
942
	 *    initialize_shortcodes_and_modules
943
	 *    meaning they can start adding their hooks to get stuff done
944
	 *
945
	 * @access    public
946
	 * @return    void
947
	 */
948
	public function initialize_shortcodes_and_modules() {
949
		// allow shortcodes to set hooks for the rest of the system
950
		$this->_initialize_shortcodes();
951
		// allow modules to set hooks for the rest of the system
952
		$this->_initialize_modules();
953
	}
954
955
956
957
	/**
958
	 *    widgets_init
959
	 *
960
	 * @access private
961
	 * @return void
962
	 */
963
	public function widgets_init() {
964
		//only init widgets on admin pages when not in complete maintenance, and
965
		//on frontend when not in any maintenance mode
966
		if (
967
			! EE_Maintenance_Mode::instance()->level()
968
			|| (
969
				is_admin()
970
				&& EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
971
			)
972
		) {
973
			// grab list of installed widgets
974
			$widgets_to_register = glob( EE_WIDGETS . '*', GLOB_ONLYDIR );
975
			// filter list of modules to register
976
			$widgets_to_register = apply_filters(
977
				'FHEE__EE_Config__register_widgets__widgets_to_register',
978
				$widgets_to_register
979
			);
980
			if ( ! empty( $widgets_to_register ) ) {
981
				// cycle thru widget folders
982
				foreach ( $widgets_to_register as $widget_path ) {
983
					// add to list of installed widget modules
984
					EE_Config::register_ee_widget( $widget_path );
985
				}
986
			}
987
			// filter list of installed modules
988
			EE_Registry::instance()->widgets = apply_filters(
989
				'FHEE__EE_Config__register_widgets__installed_widgets',
990
				EE_Registry::instance()->widgets
991
			);
992
		}
993
	}
994
995
996
997
	/**
998
	 *    register_ee_widget - makes core aware of this widget
999
	 *
1000
	 * @access    public
1001
	 * @param    string $widget_path - full path up to and including widget folder
1002
	 * @return    void
1003
	 */
1004
	public static function register_ee_widget( $widget_path = null ) {
1005
		do_action( 'AHEE__EE_Config__register_widget__begin', $widget_path );
1006
		$widget_ext = '.widget.php';
1007
		// make all separators match
1008
		$widget_path = rtrim( str_replace( '/\\', DS, $widget_path ), DS );
1009
		// does the file path INCLUDE the actual file name as part of the path ?
1010
		if ( strpos( $widget_path, $widget_ext ) !== false ) {
1011
			// grab and shortcode file name from directory name and break apart at dots
1012
			$file_name = explode( '.', basename( $widget_path ) );
1013
			// take first segment from file name pieces and remove class prefix if it exists
1014
			$widget = strpos( $file_name[0], 'EEW_' ) === 0 ? substr( $file_name[0], 4 ) : $file_name[0];
1015
			// sanitize shortcode directory name
1016
			$widget = sanitize_key( $widget );
1017
			// now we need to rebuild the shortcode path
1018
			$widget_path = explode( DS, $widget_path );
1019
			// remove last segment
1020
			array_pop( $widget_path );
1021
			// glue it back together
1022
			$widget_path = implode( DS, $widget_path );
1023
		} else {
1024
			// grab and sanitize widget directory name
1025
			$widget = sanitize_key( basename( $widget_path ) );
1026
		}
1027
		// create classname from widget directory name
1028
		$widget = str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $widget ) ) );
1029
		// add class prefix
1030
		$widget_class = 'EEW_' . $widget;
1031
		// does the widget exist ?
1032 View Code Duplication
		if ( ! is_readable( $widget_path . DS . $widget_class . $widget_ext ) ) {
1033
			$msg = sprintf(
1034
				__(
1035
					'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1036
					'event_espresso'
1037
				),
1038
				$widget_class,
1039
				$widget_path . DS . $widget_class . $widget_ext
1040
			);
1041
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1042
			return;
1043
		}
1044
		// load the widget class file
1045
		require_once( $widget_path . DS . $widget_class . $widget_ext );
1046
		// verify that class exists
1047
		if ( ! class_exists( $widget_class ) ) {
1048
			$msg = sprintf( __( 'The requested %s widget class does not exist.', 'event_espresso' ), $widget_class );
1049
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1050
			return;
1051
		}
1052
		register_widget( $widget_class );
1053
		// add to array of registered widgets
1054
		EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1055
	}
1056
1057
1058
1059
	/**
1060
	 *        _register_shortcodes
1061
	 *
1062
	 * @access private
1063
	 * @return array
1064
	 */
1065
	private function _register_shortcodes() {
1066
		// grab list of installed shortcodes
1067
		$shortcodes_to_register = glob( EE_SHORTCODES . '*', GLOB_ONLYDIR );
1068
		// filter list of modules to register
1069
		$shortcodes_to_register = apply_filters(
1070
			'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
1071
			$shortcodes_to_register
1072
		);
1073
		if ( ! empty( $shortcodes_to_register ) ) {
1074
			// cycle thru shortcode folders
1075
			foreach ( $shortcodes_to_register as $shortcode_path ) {
1076
				// add to list of installed shortcode modules
1077
				EE_Config::register_shortcode( $shortcode_path );
1078
			}
1079
		}
1080
		// filter list of installed modules
1081
		return apply_filters(
1082
			'FHEE__EE_Config___register_shortcodes__installed_shortcodes',
1083
			EE_Registry::instance()->shortcodes
1084
		);
1085
	}
1086
1087
1088
1089
	/**
1090
	 *    register_shortcode - makes core aware of this shortcode
1091
	 *
1092
	 * @access    public
1093
	 * @param    string $shortcode_path - full path up to and including shortcode folder
1094
	 * @return    bool
1095
	 */
1096
	public static function register_shortcode( $shortcode_path = null ) {
1097
		do_action( 'AHEE__EE_Config__register_shortcode__begin', $shortcode_path );
1098
		$shortcode_ext = '.shortcode.php';
1099
		// make all separators match
1100
		$shortcode_path = str_replace( array( '\\', '/' ), DS, $shortcode_path );
1101
		// does the file path INCLUDE the actual file name as part of the path ?
1102
		if ( strpos( $shortcode_path, $shortcode_ext ) !== false ) {
1103
			// grab shortcode file name from directory name and break apart at dots
1104
			$shortcode_file = explode( '.', basename( $shortcode_path ) );
1105
			// take first segment from file name pieces and remove class prefix if it exists
1106
			$shortcode = strpos( $shortcode_file[0], 'EES_' ) === 0
1107
				? substr( $shortcode_file[0], 4 )
1108
				: $shortcode_file[0];
1109
			// sanitize shortcode directory name
1110
			$shortcode = sanitize_key( $shortcode );
1111
			// now we need to rebuild the shortcode path
1112
			$shortcode_path = explode( DS, $shortcode_path );
1113
			// remove last segment
1114
			array_pop( $shortcode_path );
1115
			// glue it back together
1116
			$shortcode_path = implode( DS, $shortcode_path ) . DS;
1117
		} else {
1118
			// we need to generate the filename based off of the folder name
1119
			// grab and sanitize shortcode directory name
1120
			$shortcode = sanitize_key( basename( $shortcode_path ) );
1121
			$shortcode_path = rtrim( $shortcode_path, DS ) . DS;
1122
		}
1123
		// create classname from shortcode directory or file name
1124
		$shortcode = str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $shortcode ) ) );
1125
		// add class prefix
1126
		$shortcode_class = 'EES_' . $shortcode;
1127
		// does the shortcode exist ?
1128 View Code Duplication
		if ( ! is_readable( $shortcode_path . DS . $shortcode_class . $shortcode_ext ) ) {
1129
			$msg = sprintf(
1130
				__(
1131
					'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s',
1132
					'event_espresso'
1133
				),
1134
				$shortcode_class,
1135
				$shortcode_path . DS . $shortcode_class . $shortcode_ext
1136
			);
1137
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1138
			return false;
1139
		}
1140
		// load the shortcode class file
1141
		require_once( $shortcode_path . $shortcode_class . $shortcode_ext );
1142
		// verify that class exists
1143
		if ( ! class_exists( $shortcode_class ) ) {
1144
			$msg = sprintf(
1145
				__( 'The requested %s shortcode class does not exist.', 'event_espresso' ),
1146
				$shortcode_class
1147
			);
1148
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1149
			return false;
1150
		}
1151
		$shortcode = strtoupper( $shortcode );
1152
		// add to array of registered shortcodes
1153
		EE_Registry::instance()->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext;
1154
		return true;
1155
	}
1156
1157
1158
1159
	/**
1160
	 *        _register_modules
1161
	 *
1162
	 * @access private
1163
	 * @return array
1164
	 */
1165
	private function _register_modules() {
1166
		// grab list of installed modules
1167
		$modules_to_register = glob( EE_MODULES . '*', GLOB_ONLYDIR );
1168
		// filter list of modules to register
1169
		$modules_to_register = apply_filters(
1170
			'FHEE__EE_Config__register_modules__modules_to_register',
1171
			$modules_to_register
1172
		);
1173
		if ( ! empty( $modules_to_register ) ) {
1174
			// loop through folders
1175
			foreach ( $modules_to_register as $module_path ) {
1176
				/**TEMPORARILY EXCLUDE gateways from modules for time being**/
1177
				if (
1178
					$module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1179
					&& $module_path !== EE_MODULES . 'gateways'
1180
				) {
1181
					// add to list of installed modules
1182
					EE_Config::register_module( $module_path );
1183
				}
1184
			}
1185
		}
1186
		// filter list of installed modules
1187
		return apply_filters(
1188
			'FHEE__EE_Config___register_modules__installed_modules',
1189
			EE_Registry::instance()->modules
1190
		);
1191
	}
1192
1193
1194
1195
	/**
1196
	 *    register_module - makes core aware of this module
1197
	 *
1198
	 * @access    public
1199
	 * @param    string $module_path - full path up to and including module folder
1200
	 * @return    bool
1201
	 */
1202
	public static function register_module( $module_path = null ) {
1203
		do_action( 'AHEE__EE_Config__register_module__begin', $module_path );
1204
		$module_ext = '.module.php';
1205
		// make all separators match
1206
		$module_path = str_replace( array( '\\', '/' ), DS, $module_path );
1207
		// does the file path INCLUDE the actual file name as part of the path ?
1208
		if ( strpos( $module_path, $module_ext ) !== false ) {
1209
			// grab and shortcode file name from directory name and break apart at dots
1210
			$module_file = explode( '.', basename( $module_path ) );
1211
			// now we need to rebuild the shortcode path
1212
			$module_path = explode( DS, $module_path );
1213
			// remove last segment
1214
			array_pop( $module_path );
1215
			// glue it back together
1216
			$module_path = implode( DS, $module_path ) . DS;
1217
			// take first segment from file name pieces and sanitize it
1218
			$module = preg_replace( '/[^a-zA-Z0-9_\-]/', '', $module_file[0] );
1219
			// ensure class prefix is added
1220
			$module_class = strpos( $module, 'EED_' ) !== 0 ? 'EED_' . $module : $module;
1221
		} else {
1222
			// we need to generate the filename based off of the folder name
1223
			// grab and sanitize module name
1224
			$module = strtolower( basename( $module_path ) );
1225
			$module = preg_replace( '/[^a-z0-9_\-]/', '', $module );
1226
			// like trailingslashit()
1227
			$module_path = rtrim( $module_path, DS ) . DS;
1228
			// create classname from module directory name
1229
			$module = str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $module ) ) );
1230
			// add class prefix
1231
			$module_class = 'EED_' . $module;
1232
		}
1233
		// does the module exist ?
1234 View Code Duplication
		if ( ! is_readable( $module_path . DS . $module_class . $module_ext ) ) {
1235
			$msg = sprintf(
1236
				__(
1237
					'The requested %s module file could not be found or is not readable due to file permissions.',
1238
					'event_espresso'
1239
				),
1240
				$module
1241
			);
1242
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1243
			return false;
1244
		}
1245
		// load the module class file
1246
		require_once( $module_path . $module_class . $module_ext );
1247
		// verify that class exists
1248
		if ( ! class_exists( $module_class ) ) {
1249
			$msg = sprintf( __( 'The requested %s module class does not exist.', 'event_espresso' ), $module_class );
1250
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1251
			return false;
1252
		}
1253
		// add to array of registered modules
1254
		EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1255
		do_action(
1256
			'AHEE__EE_Config__register_module__complete',
1257
			$module_class,
1258
			EE_Registry::instance()->modules->{$module_class}
1259
		);
1260
		return true;
1261
	}
1262
1263
1264
1265
	/**
1266
	 *    _initialize_shortcodes
1267
	 *    allow shortcodes to set hooks for the rest of the system
1268
	 *
1269
	 * @access private
1270
	 * @return void
1271
	 */
1272
	private function _initialize_shortcodes() {
1273
		// cycle thru shortcode folders
1274
		foreach ( EE_Registry::instance()->shortcodes as $shortcode => $shortcode_path ) {
1275
			// add class prefix
1276
			$shortcode_class = 'EES_' . $shortcode;
1277
			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1278
			// which set hooks ?
1279
			if ( is_admin() ) {
1280
				// fire immediately
1281
				call_user_func( array( $shortcode_class, 'set_hooks_admin' ) );
1282
			} else {
1283
				// delay until other systems are online
1284
				add_action(
1285
					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1286
					array( $shortcode_class, 'set_hooks' )
1287
				);
1288
				// convert classname to UPPERCASE and create WP shortcode.
1289
				$shortcode_tag = strtoupper( $shortcode );
1290
				// but first check if the shortcode has already been added before assigning 'fallback_shortcode_processor'
1291
				if ( ! shortcode_exists( $shortcode_tag ) ) {
1292
					// NOTE: this shortcode declaration will get overridden if the shortcode is successfully detected in the post content in EE_Front_Controller->_initialize_shortcodes()
1293
					add_shortcode( $shortcode_tag, array( $shortcode_class, 'fallback_shortcode_processor' ) );
1294
				}
1295
			}
1296
		}
1297
	}
1298
1299
1300
1301
	/**
1302
	 *    _initialize_modules
1303
	 *    allow modules to set hooks for the rest of the system
1304
	 *
1305
	 * @access private
1306
	 * @return void
1307
	 */
1308
	private function _initialize_modules() {
1309
		// cycle thru shortcode folders
1310
		foreach ( EE_Registry::instance()->modules as $module_class => $module_path ) {
1311
			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1312
			// which set hooks ?
1313
			if ( is_admin() ) {
1314
				// fire immediately
1315
				call_user_func( array( $module_class, 'set_hooks_admin' ) );
1316
			} else {
1317
				// delay until other systems are online
1318
				add_action(
1319
					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1320
					array( $module_class, 'set_hooks' )
1321
				);
1322
			}
1323
		}
1324
	}
1325
1326
1327
1328
	/**
1329
	 *    register_route - adds module method routes to route_map
1330
	 *
1331
	 * @access    public
1332
	 * @param    string $route       - "pretty" public alias for module method
1333
	 * @param    string $module      - module name (classname without EED_ prefix)
1334
	 * @param    string $method_name - the actual module method to be routed to
1335
	 * @param    string $key         - url param key indicating a route is being called
1336
	 * @return    bool
1337
	 */
1338
	public static function register_route( $route = null, $module = null, $method_name = null, $key = 'ee' ) {
1339
		do_action( 'AHEE__EE_Config__register_route__begin', $route, $module, $method_name );
1340
		$module = str_replace( 'EED_', '', $module );
1341
		$module_class = 'EED_' . $module;
1342
		if ( ! isset( EE_Registry::instance()->modules->{$module_class} ) ) {
1343
			$msg = sprintf( __( 'The module %s has not been registered.', 'event_espresso' ), $module );
1344
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1345
			return false;
1346
		}
1347 View Code Duplication
		if ( empty( $route ) ) {
1348
			$msg = sprintf( __( 'No route has been supplied.', 'event_espresso' ), $route );
1349
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1350
			return false;
1351
		}
1352 View Code Duplication
		if ( ! method_exists( 'EED_' . $module, $method_name ) ) {
1353
			$msg = sprintf(
1354
				__( 'A valid class method for the %s route has not been supplied.', 'event_espresso' ),
1355
				$route
1356
			);
1357
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1358
			return false;
1359
		}
1360
		EE_Config::$_module_route_map[ $key ][ $route ] = array( 'EED_' . $module, $method_name );
1361
		return true;
1362
	}
1363
1364
1365
1366
	/**
1367
	 *    get_route - get module method route
1368
	 *
1369
	 * @access    public
1370
	 * @param    string $route - "pretty" public alias for module method
1371
	 * @param    string $key   - url param key indicating a route is being called
1372
	 * @return    string
1373
	 */
1374
	public static function get_route( $route = null, $key = 'ee' ) {
1375
		do_action( 'AHEE__EE_Config__get_route__begin', $route );
1376
		$route = (string) apply_filters( 'FHEE__EE_Config__get_route', $route );
1377
		if ( isset( EE_Config::$_module_route_map[ $key ][ $route ] ) ) {
1378
			return EE_Config::$_module_route_map[ $key ][ $route ];
1379
		}
1380
		return null;
1381
	}
1382
1383
1384
1385
	/**
1386
	 *    get_routes - get ALL module method routes
1387
	 *
1388
	 * @access    public
1389
	 * @return    array
1390
	 */
1391
	public static function get_routes() {
1392
		return EE_Config::$_module_route_map;
1393
	}
1394
1395
1396
1397
	/**
1398
	 *    register_forward - allows modules to forward request to another module for further processing
1399
	 *
1400
	 * @access    public
1401
	 * @param    string       $route   - "pretty" public alias for module method
1402
	 * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1403
	 *                                 class, allows different forwards to be served based on status
1404
	 * @param    array|string $forward - function name or array( class, method )
1405
	 * @param    string       $key     - url param key indicating a route is being called
1406
	 * @return    bool
1407
	 */
1408
	public static function register_forward( $route = null, $status = 0, $forward = null, $key = 'ee' ) {
1409
		do_action( 'AHEE__EE_Config__register_forward', $route, $status, $forward );
1410 View Code Duplication
		if ( ! isset( EE_Config::$_module_route_map[ $key ][ $route ] ) || empty( $route ) ) {
1411
			$msg = sprintf(
1412
				__( 'The module route %s for this forward has not been registered.', 'event_espresso' ),
1413
				$route
1414
			);
1415
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1416
			return false;
1417
		}
1418 View Code Duplication
		if ( empty( $forward ) ) {
1419
			$msg = sprintf( __( 'No forwarding route has been supplied.', 'event_espresso' ), $route );
1420
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1421
			return false;
1422
		}
1423
		if ( is_array( $forward ) ) {
1424 View Code Duplication
			if ( ! isset( $forward[1] ) ) {
1425
				$msg = sprintf(
1426
					__( 'A class method for the %s forwarding route has not been supplied.', 'event_espresso' ),
1427
					$route
1428
				);
1429
				EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1430
				return false;
1431
			}
1432
			if ( ! method_exists( $forward[0], $forward[1] ) ) {
1433
				$msg = sprintf(
1434
					__( 'The class method %s for the %s forwarding route is in invalid.', 'event_espresso' ),
1435
					$forward[1],
1436
					$route
1437
				);
1438
				EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1439
				return false;
1440
			}
1441
		} else if ( ! function_exists( $forward ) ) {
1442
			$msg = sprintf(
1443
				__( 'The function %s for the %s forwarding route is in invalid.', 'event_espresso' ),
1444
				$forward,
1445
				$route
1446
			);
1447
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1448
			return false;
1449
		}
1450
		EE_Config::$_module_forward_map[ $key ][ $route ][ absint( $status ) ] = $forward;
1451
		return true;
1452
	}
1453
1454
1455
1456
	/**
1457
	 *    get_forward - get forwarding route
1458
	 *
1459
	 * @access    public
1460
	 * @param    string  $route  - "pretty" public alias for module method
1461
	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1462
	 *                           allows different forwards to be served based on status
1463
	 * @param    string  $key    - url param key indicating a route is being called
1464
	 * @return    string
1465
	 */
1466 View Code Duplication
	public static function get_forward( $route = null, $status = 0, $key = 'ee' ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1467
		do_action( 'AHEE__EE_Config__get_forward__begin', $route, $status );
1468
		if ( isset( EE_Config::$_module_forward_map[ $key ][ $route ][ $status ] ) ) {
1469
			return apply_filters(
1470
				'FHEE__EE_Config__get_forward',
1471
				EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1472
				$route,
1473
				$status
1474
			);
1475
		}
1476
		return null;
1477
	}
1478
1479
1480
1481
	/**
1482
	 *    register_forward - allows modules to specify different view templates for different method routes and status
1483
	 *    results
1484
	 *
1485
	 * @access    public
1486
	 * @param    string  $route  - "pretty" public alias for module method
1487
	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1488
	 *                           allows different views to be served based on status
1489
	 * @param    string  $view
1490
	 * @param    string  $key    - url param key indicating a route is being called
1491
	 * @return    bool
1492
	 */
1493
	public static function register_view( $route = null, $status = 0, $view = null, $key = 'ee' ) {
1494
		do_action( 'AHEE__EE_Config__register_view__begin', $route, $status, $view );
1495 View Code Duplication
		if ( ! isset( EE_Config::$_module_route_map[ $key ][ $route ] ) || empty( $route ) ) {
1496
			$msg = sprintf(
1497
				__( 'The module route %s for this view has not been registered.', 'event_espresso' ),
1498
				$route
1499
			);
1500
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1501
			return false;
1502
		}
1503
		if ( ! is_readable( $view ) ) {
1504
			$msg = sprintf(
1505
				__(
1506
					'The %s view file could not be found or is not readable due to file permissions.',
1507
					'event_espresso'
1508
				),
1509
				$view
1510
			);
1511
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1512
			return false;
1513
		}
1514
		EE_Config::$_module_view_map[ $key ][ $route ][ absint( $status ) ] = $view;
1515
		return true;
1516
	}
1517
1518
1519
1520
	/**
1521
	 *    get_view - get view for route and status
1522
	 *
1523
	 * @access    public
1524
	 * @param    string  $route  - "pretty" public alias for module method
1525
	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1526
	 *                           allows different views to be served based on status
1527
	 * @param    string  $key    - url param key indicating a route is being called
1528
	 * @return    string
1529
	 */
1530 View Code Duplication
	public static function get_view( $route = null, $status = 0, $key = 'ee' ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1531
		do_action( 'AHEE__EE_Config__get_view__begin', $route, $status );
1532
		if ( isset( EE_Config::$_module_view_map[ $key ][ $route ][ $status ] ) ) {
1533
			return apply_filters(
1534
				'FHEE__EE_Config__get_view',
1535
				EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1536
				$route,
1537
				$status
1538
			);
1539
		}
1540
		return null;
1541
	}
1542
1543
1544
1545
	public function update_addon_option_names() {
1546
		update_option( EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names );
1547
	}
1548
1549
1550
1551
	public function shutdown() {
1552
		$this->update_addon_option_names();
1553
	}
1554
1555
1556
}
1557
1558
1559
1560
/**
1561
 * Base class used for config classes. These classes should generally not have
1562
 * magic functions in use, except we'll allow them to magically set and get stuff...
1563
 * basically, they should just be well-defined stdClasses
1564
 */
1565
class EE_Config_Base {
1566
1567
	/**
1568
	 * Utility function for escaping the value of a property and returning.
1569
	 *
1570
	 * @param string $property property name (checks to see if exists).
1571
	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1572
	 * @throws \EE_Error
1573
	 */
1574
	public function get_pretty( $property ) {
1575
		if ( ! property_exists( $this, $property ) ) {
1576
			throw new EE_Error(
1577
				sprintf(
1578
					__(
1579
						'%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1580
						'event_espresso'
1581
					),
1582
					get_class( $this ),
1583
					$property
1584
				)
1585
			);
1586
		}
1587
		//just handling escaping of strings for now.
1588
		if ( is_string( $this->{$property} ) ) {
1589
			return stripslashes( $this->{$property} );
1590
		}
1591
		return $this->{$property};
1592
	}
1593
1594
1595
1596
	public function populate() {
1597
		//grab defaults via a new instance of this class.
1598
		$class_name = get_class( $this );
1599
		$defaults = new $class_name;
1600
		//loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1601
		//default from our $defaults object.
1602
		foreach ( get_object_vars( $defaults ) as $property => $value ) {
1603
			if ( $this->{$property} === null ) {
1604
				$this->{$property} = $value;
1605
			}
1606
		}
1607
		//cleanup
1608
		unset( $defaults );
1609
	}
1610
1611
1612
	/**
1613
	 *        @ override magic methods
1614
	 *        @ return void
1615
	 */
1616
//	public function __get($a) { return apply_filters('FHEE__'.get_class($this).'__get__'.$a,$this->{$a}); }
1617
//	public function __set($a,$b) { return apply_filters('FHEE__'.get_class($this).'__set__'.$a, $this->{$a} = $b ); }
1618
	/**
1619
	 *        __isset
1620
	 *
1621
	 * @param $a
1622
	 * @return bool
1623
	 */
1624
	public function __isset( $a ) {
1625
		return false;
1626
	}
1627
1628
1629
1630
	/**
1631
	 *        __unset
1632
	 *
1633
	 * @param $a
1634
	 * @return bool
1635
	 */
1636
	public function __unset( $a ) {
1637
		return false;
1638
	}
1639
1640
1641
1642
	/**
1643
	 *        __clone
1644
	 */
1645
	public function __clone() {
1646
	}
1647
1648
1649
1650
	/**
1651
	 *        __wakeup
1652
	 */
1653
	public function __wakeup() {
1654
	}
1655
1656
1657
1658
	/**
1659
	 *        __destruct
1660
	 */
1661
	public function __destruct() {
1662
	}
1663
}
1664
1665
1666
1667
/**
1668
 * Class for defining what's in the EE_Config relating to registration settings
1669
 */
1670
class EE_Core_Config extends EE_Config_Base {
1671
1672
	public $current_blog_id;
1673
1674
	public $ee_ueip_optin;
1675
1676
	public $ee_ueip_has_notified;
1677
1678
	/**
1679
	 * Not to be confused with the 4 critical page variables (See
1680
	 * get_critical_pages_array()), this is just an array of wp posts that have EE
1681
	 * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1682
	 * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1683
	 *
1684
	 * @var array
1685
	 */
1686
	public $post_shortcodes;
1687
1688
	public $module_route_map;
1689
1690
	public $module_forward_map;
1691
1692
	public $module_view_map;
1693
1694
	/**
1695
	 * The next 4 vars are the IDs of critical EE pages.
1696
	 *
1697
	 * @var int
1698
	 */
1699
	public $reg_page_id;
1700
1701
	public $txn_page_id;
1702
1703
	public $thank_you_page_id;
1704
1705
	public $cancel_page_id;
1706
1707
	/**
1708
	 * The next 4 vars are the URLs of critical EE pages.
1709
	 *
1710
	 * @var int
1711
	 */
1712
	public $reg_page_url;
1713
1714
	public $txn_page_url;
1715
1716
	public $thank_you_page_url;
1717
1718
	public $cancel_page_url;
1719
1720
	/**
1721
	 * The next vars relate to the custom slugs for EE CPT routes
1722
	 */
1723
	public $event_cpt_slug;
1724
1725
1726
1727
	/**
1728
	 * This caches the _ee_ueip_option in case this config is reset in the same
1729
	 * request across blog switches in a multisite context.
1730
	 * Avoids extra queries to the db for this option.
1731
	 * @var bool
1732
	 */
1733
	public static $ee_ueip_option;
1734
1735
1736
	/**
1737
	 *    class constructor
1738
	 *
1739
	 * @access    public
1740
	 */
1741
	public function __construct() {
1742
		// set default organization settings
1743
		$this->current_blog_id = get_current_blog_id();
1744
		$this->current_blog_id = $this->current_blog_id === NULL ? 1 : $this->current_blog_id;
1745
		$this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1746
		$this->ee_ueip_has_notified = is_main_site() ? get_option( 'ee_ueip_has_notified', false ) : true;
1747
		$this->post_shortcodes = array();
1748
		$this->module_route_map = array();
1749
		$this->module_forward_map = array();
1750
		$this->module_view_map = array();
1751
		// critical EE page IDs
1752
		$this->reg_page_id = 0;
1753
		$this->txn_page_id = 0;
1754
		$this->thank_you_page_id = 0;
1755
		$this->cancel_page_id = 0;
1756
		// critical EE page URLs
1757
		$this->reg_page_url = '';
0 ignored issues
show
Documentation Bug introduced by
The property $reg_page_url was declared of type integer, but '' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
1758
		$this->txn_page_url = '';
1759
		$this->thank_you_page_url = '';
1760
		$this->cancel_page_url = '';
1761
		//cpt slugs
1762
		$this->event_cpt_slug = __( 'events', 'event_espresso' );
1763
		//ueip constant check
1764
		if ( defined( 'EE_DISABLE_UXIP' ) && EE_DISABLE_UXIP ) {
1765
			$this->ee_ueip_optin = false;
1766
			$this->ee_ueip_has_notified = true;
1767
		}
1768
	}
1769
1770
1771
1772
	/**
1773
	 * @return array
1774
	 */
1775
	public function get_critical_pages_array() {
1776
		return array(
1777
			$this->reg_page_id,
1778
			$this->txn_page_id,
1779
			$this->thank_you_page_id,
1780
			$this->cancel_page_id,
1781
		);
1782
	}
1783
1784
1785
1786
	/**
1787
	 * @return array
1788
	 */
1789
	public function get_critical_pages_shortcodes_array() {
1790
		return array(
1791
			$this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1792
			$this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1793
			$this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1794
			$this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1795
		);
1796
	}
1797
1798
1799
1800
	/**
1801
	 *  gets/returns URL for EE reg_page
1802
	 *
1803
	 * @access    public
1804
	 * @return    string
1805
	 */
1806
	public function reg_page_url() {
1807
		if ( ! $this->reg_page_url ) {
1808
			$this->reg_page_url = add_query_arg(
0 ignored issues
show
Documentation Bug introduced by
The property $reg_page_url was declared of type integer, but add_query_arg(array('uts...page_id)) . '#checkout' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
1809
				array( 'uts' => time() ),
1810
				get_permalink( $this->reg_page_id )
1811
			) . '#checkout';
1812
		}
1813
		return $this->reg_page_url;
1814
	}
1815
1816
1817
1818
	/**
1819
	 *  gets/returns URL for EE txn_page
1820
	 *
1821
	 * @param array $query_args like what gets passed to
1822
	 *                          add_query_arg() as the first argument
1823
	 * @access    public
1824
	 * @return    string
1825
	 */
1826 View Code Duplication
	public function txn_page_url( $query_args = array() ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1827
		if ( ! $this->txn_page_url ) {
1828
			$this->txn_page_url = get_permalink( $this->txn_page_id );
1829
		}
1830
		if ( $query_args ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $query_args of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1831
			return add_query_arg( $query_args, $this->txn_page_url );
1832
		} else {
1833
			return $this->txn_page_url;
1834
		}
1835
	}
1836
1837
1838
1839
	/**
1840
	 *  gets/returns URL for EE thank_you_page
1841
	 *
1842
	 * @param array $query_args like what gets passed to
1843
	 *                          add_query_arg() as the first argument
1844
	 * @access    public
1845
	 * @return    string
1846
	 */
1847 View Code Duplication
	public function thank_you_page_url( $query_args = array() ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1848
		if ( ! $this->thank_you_page_url ) {
1849
			$this->thank_you_page_url = get_permalink( $this->thank_you_page_id );
1850
		}
1851
		if ( $query_args ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $query_args of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1852
			return add_query_arg( $query_args, $this->thank_you_page_url );
1853
		} else {
1854
			return $this->thank_you_page_url;
1855
		}
1856
	}
1857
1858
1859
1860
	/**
1861
	 *  gets/returns URL for EE cancel_page
1862
	 *
1863
	 * @access    public
1864
	 * @return    string
1865
	 */
1866
	public function cancel_page_url() {
1867
		if ( ! $this->cancel_page_url ) {
1868
			$this->cancel_page_url = get_permalink( $this->cancel_page_id );
1869
		}
1870
		return $this->cancel_page_url;
1871
	}
1872
1873
1874
1875
	/**
1876
	 * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1877
	 *
1878
	 * @since 4.7.5
1879
	 */
1880
	protected function _reset_urls() {
1881
		$this->reg_page_url = '';
0 ignored issues
show
Documentation Bug introduced by
The property $reg_page_url was declared of type integer, but '' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
1882
		$this->txn_page_url = '';
1883
		$this->cancel_page_url = '';
1884
		$this->thank_you_page_url = '';
1885
	}
1886
1887
1888
	/**
1889
	 * Used to return what the optin value is set for the EE User Experience Program.
1890
	 * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1891
	 * on the main site only.
1892
	 *
1893
	 * @return mixed|void
1894
	 */
1895
	protected function _get_main_ee_ueip_optin() {
1896
		//if this is the main site then we can just bypass our direct query.
1897
		if ( is_main_site() ) {
1898
			return get_option( 'ee_ueip_optin', false );
1899
		}
1900
1901
		//is this already cached for this request?  If so use it.
1902
		if ( ! empty( EE_Core_Config::$ee_ueip_option ) ) {
1903
			return EE_Core_Config::$ee_ueip_option;
1904
		}
1905
1906
		global $wpdb;
1907
		$current_network_main_site = is_multisite() ? get_current_site() : null;
1908
		$current_main_site_id = ! empty( $current_network_main_site ) ? $current_network_main_site->blog_id : 1;
1909
		$option = 'ee_ueip_optin';
1910
1911
		//set correct table for query
1912
		$table_name = $wpdb->get_blog_prefix( $current_main_site_id ) . 'options';
1913
1914
1915
		//rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1916
		//get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1917
		//re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1918
		//this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1919
		//for the purpose of caching.
1920
		$pre = apply_filters( 'pre_option_' . $option, false, $option );
1921
		if ( false !== $pre ) {
1922
			EE_Core_Config::$ee_ueip_option = $pre;
1923
			return EE_Core_Config::$ee_ueip_option;
1924
		}
1925
1926
		$row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", $option ) );
1927
		if ( is_object( $row ) ) {
1928
			$value = $row->option_value;
1929
		} else { //option does not exist so use default.
1930
			return apply_filters( 'default_option_' . $option, false, $option );
1931
		}
1932
1933
		EE_Core_Config::$ee_ueip_option = apply_filters( 'option_' . $option, maybe_unserialize( $value ), $option );
1934
		return EE_Core_Config::$ee_ueip_option;
1935
	}
1936
1937
1938
1939
	/**
1940
	 * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1941
	 * on the object.
1942
	 *
1943
	 * @return array
1944
	 */
1945
	public function __sleep() {
1946
		//reset all url properties
1947
		$this->_reset_urls();
1948
		//return what to save to db
1949
		return array_keys( get_object_vars( $this ) );
1950
	}
1951
1952
}
1953
1954
1955
1956
/**
1957
 * Config class for storing info on the Organization
1958
 */
1959
class EE_Organization_Config extends EE_Config_Base {
1960
1961
	/**
1962
	 * @var string $name
1963
	 * eg EE4.1
1964
	 */
1965
	public $name;
1966
1967
	/**
1968
	 * @var string $address_1
1969
	 * eg 123 Onna Road
1970
	 */
1971
	public $address_1;
1972
1973
	/**
1974
	 * @var string $address_2
1975
	 * eg PO Box 123
1976
	 */
1977
	public $address_2;
1978
1979
	/**
1980
	 * @var string $city
1981
	 * eg Inna City
1982
	 */
1983
	public $city;
1984
1985
	/**
1986
	 * @var int $STA_ID
1987
	 * eg 4
1988
	 */
1989
	public $STA_ID;
1990
1991
	/**
1992
	 * @var string $CNT_ISO
1993
	 * eg US
1994
	 */
1995
	public $CNT_ISO;
1996
1997
	/**
1998
	 * @var string $zip
1999
	 * eg 12345  or V1A 2B3
2000
	 */
2001
	public $zip;
2002
2003
	/**
2004
	 * @var string $email
2005
	 * eg [email protected]
2006
	 */
2007
	public $email;
2008
2009
2010
2011
	/**
2012
	 * @var string $phone
2013
	 * eg. 111-111-1111
2014
	 */
2015
	public $phone;
2016
2017
2018
	/**
2019
	 * @var string $vat
2020
	 * VAT/Tax Number
2021
	 */
2022
	public $vat;
2023
2024
	/**
2025
	 * @var string $logo_url
2026
	 * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
2027
	 */
2028
	public $logo_url;
2029
2030
2031
	/**
2032
	 * The below are all various properties for holding links to organization social network profiles
2033
	 *
2034
	 * @var string
2035
	 */
2036
	/**
2037
	 * facebook (facebook.com/profile.name)
2038
	 *
2039
	 * @var string
2040
	 */
2041
	public $facebook;
2042
2043
2044
	/**
2045
	 * twitter (twitter.com/twitter_handle)
2046
	 *
2047
	 * @var string
2048
	 */
2049
	public $twitter;
2050
2051
2052
2053
	/**
2054
	 * linkedin (linkedin.com/in/profile_name)
2055
	 *
2056
	 * @var string
2057
	 */
2058
	public $linkedin;
2059
2060
2061
2062
	/**
2063
	 * pinterest (www.pinterest.com/profile_name)
2064
	 *
2065
	 * @var string
2066
	 */
2067
	public $pinterest;
2068
2069
2070
2071
	/**
2072
	 * google+ (google.com/+profileName)
2073
	 *
2074
	 * @var string
2075
	 */
2076
	public $google;
2077
2078
2079
2080
	/**
2081
	 * instagram (instagram.com/handle)
2082
	 *
2083
	 * @var string
2084
	 */
2085
	public $instagram;
2086
2087
2088
2089
	/**
2090
	 *    class constructor
2091
	 *
2092
	 * @access    public
2093
	 */
2094
	public function __construct() {
2095
		// set default organization settings
2096
		$this->name = get_bloginfo( 'name' );
2097
		$this->address_1 = '123 Onna Road';
2098
		$this->address_2 = 'PO Box 123';
2099
		$this->city = 'Inna City';
2100
		$this->STA_ID = 4;
2101
		$this->CNT_ISO = 'US';
2102
		$this->zip = '12345';
2103
		$this->email = get_bloginfo( 'admin_email' );
2104
		$this->phone = '';
2105
		$this->vat = '123456789';
2106
		$this->logo_url = '';
2107
		$this->facebook = '';
2108
		$this->twitter = '';
2109
		$this->linkedin = '';
2110
		$this->pinterest = '';
2111
		$this->google = '';
2112
		$this->instagram = '';
2113
	}
2114
2115
}
2116
2117
2118
2119
/**
2120
 * Class for defining what's in the EE_Config relating to currency
2121
 */
2122
class EE_Currency_Config extends EE_Config_Base {
2123
2124
	/**
2125
	 * @var string $code
2126
	 * eg 'US'
2127
	 */
2128
	public $code;
2129
2130
	/**
2131
	 * @var string $name
2132
	 * eg 'Dollar'
2133
	 */
2134
	public $name;
2135
2136
	/**
2137
	 * plural name
2138
	 *
2139
	 * @var string $plural
2140
	 * eg 'Dollars'
2141
	 */
2142
	public $plural;
2143
2144
	/**
2145
	 * currency sign
2146
	 *
2147
	 * @var string $sign
2148
	 * eg '$'
2149
	 */
2150
	public $sign;
2151
2152
	/**
2153
	 * Whether the currency sign should come before the number or not
2154
	 *
2155
	 * @var boolean $sign_b4
2156
	 */
2157
	public $sign_b4;
2158
2159
	/**
2160
	 * How many digits should come after the decimal place
2161
	 *
2162
	 * @var int $dec_plc
2163
	 */
2164
	public $dec_plc;
2165
2166
	/**
2167
	 * Symbol to use for decimal mark
2168
	 *
2169
	 * @var string $dec_mrk
2170
	 * eg '.'
2171
	 */
2172
	public $dec_mrk;
2173
2174
	/**
2175
	 * Symbol to use for thousands
2176
	 *
2177
	 * @var string $thsnds
2178
	 * eg ','
2179
	 */
2180
	public $thsnds;
2181
2182
2183
2184
	/**
2185
	 *    class constructor
2186
	 *
2187
	 * @access    public
2188
	 * @param string $CNT_ISO
2189
	 * @throws \EE_Error
2190
	 */
2191
	public function __construct( $CNT_ISO = '' ) {
2192
		/** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2193
		$table_analysis = EE_Registry::instance()->create( 'TableAnalysis', array(), true );
2194
		// get country code from organization settings or use default
2195
		$ORG_CNT = isset( EE_Registry::instance()->CFG->organization )
2196
		           && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2197
			? EE_Registry::instance()->CFG->organization->CNT_ISO
2198
			: '';
2199
		// but override if requested
2200
		$CNT_ISO = ! empty( $CNT_ISO ) ? $CNT_ISO : $ORG_CNT;
2201
		// so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2202
		if (
2203
			! empty( $CNT_ISO )
2204
			&& EE_Maintenance_Mode::instance()->models_can_query()
2205
			&& $table_analysis->tableExists( EE_Registry::instance()->load_model( 'Country' )->table() )
2206
		) {
2207
			// retrieve the country settings from the db, just in case they have been customized
2208
			$country = EE_Registry::instance()->load_model( 'Country' )->get_one_by_ID( $CNT_ISO );
2209
			if ( $country instanceof EE_Country ) {
2210
				$this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2211
				$this->name = $country->currency_name_single();    // Dollar
2212
				$this->plural = $country->currency_name_plural();    // Dollars
2213
				$this->sign = $country->currency_sign();            // currency sign: $
2214
				$this->sign_b4 = $country->currency_sign_before();        // currency sign before or after: $TRUE  or  FALSE$
2215
				$this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2216
				$this->dec_mrk = $country->currency_decimal_mark();    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2217
				$this->thsnds = $country->currency_thousands_separator();    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2218
			}
2219
		}
2220
		// fallback to hardcoded defaults, in case the above failed
2221
		if ( empty( $this->code ) ) {
2222
			// set default currency settings
2223
			$this->code = 'USD';    // currency code: USD, CAD, EUR
2224
			$this->name = __( 'Dollar', 'event_espresso' );    // Dollar
2225
			$this->plural = __( 'Dollars', 'event_espresso' );    // Dollars
2226
			$this->sign = '$';    // currency sign: $
2227
			$this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2228
			$this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2229
			$this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2230
			$this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2231
		}
2232
	}
2233
}
2234
2235
2236
2237
/**
2238
 * Class for defining what's in the EE_Config relating to registration settings
2239
 */
2240
class EE_Registration_Config extends EE_Config_Base {
2241
2242
	/**
2243
	 * Default registration status
2244
	 *
2245
	 * @var string $default_STS_ID
2246
	 * eg 'RPP'
2247
	 */
2248
	public $default_STS_ID;
2249
2250
	/**
2251
	 * level of validation to apply to email addresses
2252
	 *
2253
	 * @var string $email_validation_level
2254
	 * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2255
	 */
2256
	public $email_validation_level;
2257
2258
	/**
2259
	 *    whether or not to show alternate payment options during the reg process if payment status is pending
2260
	 *
2261
	 * @var boolean $show_pending_payment_options
2262
	 */
2263
	public $show_pending_payment_options;
2264
2265
	/**
2266
	 * Whether to skip the registration confirmation page
2267
	 *
2268
	 * @var boolean $skip_reg_confirmation
2269
	 */
2270
	public $skip_reg_confirmation;
2271
2272
	/**
2273
	 * an array of SPCO reg steps where:
2274
	 *        the keys denotes the reg step order
2275
	 *        each element consists of an array with the following elements:
2276
	 *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2277
	 *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2278
	 *            "slug" => the URL param used to trigger the reg step
2279
	 *
2280
	 * @var array $reg_steps
2281
	 */
2282
	public $reg_steps;
2283
2284
	/**
2285
	 * Whether registration confirmation should be the last page of SPCO
2286
	 *
2287
	 * @var boolean $reg_confirmation_last
2288
	 */
2289
	public $reg_confirmation_last;
2290
2291
	/**
2292
	 * Whether or not to enable the EE Bot Trap
2293
	 *
2294
	 * @var boolean $use_bot_trap
2295
	 */
2296
	public $use_bot_trap;
2297
2298
	/**
2299
	 * Whether or not to encrypt some data sent by the EE Bot Trap
2300
	 *
2301
	 * @var boolean $use_encryption
2302
	 */
2303
	public $use_encryption;
2304
2305
	/**
2306
	 * Whether or not to use ReCaptcha
2307
	 *
2308
	 * @var boolean $use_captcha
2309
	 */
2310
	public $use_captcha;
2311
2312
	/**
2313
	 * ReCaptcha Theme
2314
	 *
2315
	 * @var string $recaptcha_theme
2316
	 *    options: 'dark    ', 'light'
2317
	 */
2318
	public $recaptcha_theme;
2319
2320
	/**
2321
	 * ReCaptcha Type
2322
	 *
2323
	 * @var string $recaptcha_type
2324
	 *    options: 'audio', 'image'
2325
	 */
2326
	public $recaptcha_type;
2327
2328
	/**
2329
	 * ReCaptcha language
2330
	 *
2331
	 * @var string $recaptcha_language
2332
	 * eg 'en'
2333
	 */
2334
	public $recaptcha_language;
2335
2336
	/**
2337
	 * ReCaptcha public key
2338
	 *
2339
	 * @var string $recaptcha_publickey
2340
	 */
2341
	public $recaptcha_publickey;
2342
2343
	/**
2344
	 * ReCaptcha private key
2345
	 *
2346
	 * @var string $recaptcha_privatekey
2347
	 */
2348
	public $recaptcha_privatekey;
2349
2350
	/**
2351
	 * ReCaptcha width
2352
	 *
2353
	 * @var int $recaptcha_width
2354
	 * @deprecated
2355
	 */
2356
	public $recaptcha_width;
2357
2358
2359
2360
	/**
2361
	 *    class constructor
2362
	 *
2363
	 * @access    public
2364
	 */
2365
	public function __construct() {
2366
		// set default registration settings
2367
		$this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2368
		$this->email_validation_level = 'wp_default';
2369
		$this->show_pending_payment_options = true;
2370
		$this->skip_reg_confirmation = false;
2371
		$this->reg_steps = array();
2372
		$this->reg_confirmation_last = false;
2373
		$this->use_bot_trap = true;
2374
		$this->use_encryption = true;
2375
		$this->use_captcha = false;
2376
		$this->recaptcha_theme = 'light';
2377
		$this->recaptcha_type = 'image';
2378
		$this->recaptcha_language = 'en';
2379
		$this->recaptcha_publickey = null;
2380
		$this->recaptcha_privatekey = null;
2381
		$this->recaptcha_width = 500;
0 ignored issues
show
Deprecated Code introduced by
The property EE_Registration_Config::$recaptcha_width has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
2382
	}
2383
2384
2385
2386
	/**
2387
	 * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2388
	 *
2389
	 * @since 4.8.8.rc.019
2390
	 */
2391
	public function do_hooks() {
2392
		add_action( 'AHEE__EE_Config___load_core_config__end', array( $this, 'set_default_reg_status_on_EEM_Event' ) );
2393
	}
2394
2395
2396
2397
	/**
2398
	 * @return void
2399
	 */
2400
	public function set_default_reg_status_on_EEM_Event() {
2401
		EEM_Event::set_default_reg_status( $this->default_STS_ID );
2402
	}
2403
2404
2405
2406
}
2407
2408
2409
2410
/**
2411
 * Class for defining what's in the EE_Config relating to admin settings
2412
 */
2413
class EE_Admin_Config extends EE_Config_Base {
2414
2415
	/**
2416
	 * @var boolean $use_personnel_manager
2417
	 */
2418
	public $use_personnel_manager;
2419
2420
	/**
2421
	 * @var boolean $use_dashboard_widget
2422
	 */
2423
	public $use_dashboard_widget;
2424
2425
	/**
2426
	 * @var int $events_in_dashboard
2427
	 */
2428
	public $events_in_dashboard;
2429
2430
	/**
2431
	 * @var boolean $use_event_timezones
2432
	 */
2433
	public $use_event_timezones;
2434
2435
	/**
2436
	 * @var boolean $use_full_logging
2437
	 */
2438
	public $use_full_logging;
2439
2440
	/**
2441
	 * @var string $log_file_name
2442
	 */
2443
	public $log_file_name;
2444
2445
	/**
2446
	 * @var string $debug_file_name
2447
	 */
2448
	public $debug_file_name;
2449
2450
	/**
2451
	 * @var boolean $use_remote_logging
2452
	 */
2453
	public $use_remote_logging;
2454
2455
	/**
2456
	 * @var string $remote_logging_url
2457
	 */
2458
	public $remote_logging_url;
2459
2460
	/**
2461
	 * @var boolean $show_reg_footer
2462
	 */
2463
	public $show_reg_footer;
2464
2465
	/**
2466
	 * @var string $affiliate_id
2467
	 */
2468
	public $affiliate_id;
2469
2470
2471
	/**
2472
	 * help tours on or off (global setting)
2473
	 *
2474
	 * @var boolean
2475
	 */
2476
	public $help_tour_activation;
2477
2478
2479
2480
	/**
2481
	 *    class constructor
2482
	 *
2483
	 * @access    public
2484
	 */
2485
	public function __construct() {
2486
		// set default general admin settings
2487
		$this->use_personnel_manager = true;
2488
		$this->use_dashboard_widget = true;
2489
		$this->events_in_dashboard = 30;
2490
		$this->use_event_timezones = false;
2491
		$this->use_full_logging = false;
2492
		$this->use_remote_logging = false;
2493
		$this->remote_logging_url = null;
2494
		$this->show_reg_footer = true;
2495
		$this->affiliate_id = 'default';
2496
		$this->help_tour_activation = true;
2497
	}
2498
2499
2500
2501
	/**
2502
	 * @param bool $reset
2503
	 * @return string
2504
	 */
2505 View Code Duplication
	public function log_file_name( $reset = false ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2506
		if ( empty( $this->log_file_name ) || $reset ) {
2507
			$this->log_file_name = sanitize_key( 'espresso_log_' . md5( uniqid( '', true ) ) ) . '.txt';
2508
			EE_Config::instance()->update_espresso_config( false, false );
2509
		}
2510
		return $this->log_file_name;
2511
	}
2512
2513
2514
2515
	/**
2516
	 * @param bool $reset
2517
	 * @return string
2518
	 */
2519 View Code Duplication
	public function debug_file_name( $reset = false ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2520
		if ( empty( $this->debug_file_name ) || $reset ) {
2521
			$this->debug_file_name = sanitize_key( 'espresso_debug_' . md5( uniqid( '', true ) ) ) . '.txt';
2522
			EE_Config::instance()->update_espresso_config( false, false );
2523
		}
2524
		return $this->debug_file_name;
2525
	}
2526
2527
2528
2529
	/**
2530
	 * @return string
2531
	 */
2532
	public function affiliate_id() {
2533
		return ! empty( $this->affiliate_id ) ? $this->affiliate_id : 'default';
2534
	}
2535
2536
2537
2538
}
2539
2540
2541
2542
/**
2543
 * Class for defining what's in the EE_Config relating to template settings
2544
 */
2545
class EE_Template_Config extends EE_Config_Base {
2546
2547
	/**
2548
	 * @var boolean $enable_default_style
2549
	 */
2550
	public $enable_default_style;
2551
2552
	/**
2553
	 * @var string $custom_style_sheet
2554
	 */
2555
	public $custom_style_sheet;
2556
2557
	/**
2558
	 * @var boolean $display_address_in_regform
2559
	 */
2560
	public $display_address_in_regform;
2561
2562
	/**
2563
	 * @var int $display_description_on_multi_reg_page
2564
	 */
2565
	public $display_description_on_multi_reg_page;
2566
2567
	/**
2568
	 * @var boolean $use_custom_templates
2569
	 */
2570
	public $use_custom_templates;
2571
2572
	/**
2573
	 * @var string $current_espresso_theme
2574
	 */
2575
	public $current_espresso_theme;
2576
2577
	/**
2578
	 * @var EE_Event_Single_Config $EED_Event_Single
2579
	 */
2580
	public $EED_Event_Single;
2581
2582
	/**
2583
	 * @var EE_Events_Archive_Config $EED_Events_Archive
2584
	 */
2585
	public $EED_Events_Archive;
2586
2587
	/**
2588
	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2589
	 */
2590
	public $EED_Ticket_Selector;
2591
2592
2593
2594
	/**
2595
	 *    class constructor
2596
	 *
2597
	 * @access    public
2598
	 */
2599
	public function __construct() {
2600
		// set default template settings
2601
		$this->enable_default_style = true;
2602
		$this->custom_style_sheet = null;
2603
		$this->display_address_in_regform = true;
2604
		$this->display_description_on_multi_reg_page = false;
0 ignored issues
show
Documentation Bug introduced by
The property $display_description_on_multi_reg_page was declared of type integer, but false is of type false. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
2605
		$this->use_custom_templates = false;
2606
		$this->current_espresso_theme = 'Espresso_Arabica_2014';
2607
		$this->EED_Event_Single = null;
2608
		$this->EED_Events_Archive = null;
2609
		$this->EED_Ticket_Selector = null;
2610
	}
2611
2612
}
2613
2614
2615
2616
/**
2617
 * Class for defining what's in the EE_Config relating to map settings
2618
 */
2619
class EE_Map_Config extends EE_Config_Base {
2620
2621
	/**
2622
	 * @var boolean $use_google_maps
2623
	 */
2624
	public $use_google_maps;
2625
2626
	/**
2627
	 * @var string $api_key
2628
	 */
2629
	public $google_map_api_key;
2630
2631
	/**
2632
	 * @var int $event_details_map_width
2633
	 */
2634
	public $event_details_map_width;
2635
2636
	/**
2637
	 * @var int $event_details_map_height
2638
	 */
2639
	public $event_details_map_height;
2640
2641
	/**
2642
	 * @var int $event_details_map_zoom
2643
	 */
2644
	public $event_details_map_zoom;
2645
2646
	/**
2647
	 * @var boolean $event_details_display_nav
2648
	 */
2649
	public $event_details_display_nav;
2650
2651
	/**
2652
	 * @var boolean $event_details_nav_size
2653
	 */
2654
	public $event_details_nav_size;
2655
2656
	/**
2657
	 * @var string $event_details_control_type
2658
	 */
2659
	public $event_details_control_type;
2660
2661
	/**
2662
	 * @var string $event_details_map_align
2663
	 */
2664
	public $event_details_map_align;
2665
2666
	/**
2667
	 * @var int $event_list_map_width
2668
	 */
2669
	public $event_list_map_width;
2670
2671
	/**
2672
	 * @var int $event_list_map_height
2673
	 */
2674
	public $event_list_map_height;
2675
2676
	/**
2677
	 * @var int $event_list_map_zoom
2678
	 */
2679
	public $event_list_map_zoom;
2680
2681
	/**
2682
	 * @var boolean $event_list_display_nav
2683
	 */
2684
	public $event_list_display_nav;
2685
2686
	/**
2687
	 * @var boolean $event_list_nav_size
2688
	 */
2689
	public $event_list_nav_size;
2690
2691
	/**
2692
	 * @var string $event_list_control_type
2693
	 */
2694
	public $event_list_control_type;
2695
2696
	/**
2697
	 * @var string $event_list_map_align
2698
	 */
2699
	public $event_list_map_align;
2700
2701
2702
2703
	/**
2704
	 *    class constructor
2705
	 *
2706
	 * @access    public
2707
	 */
2708
	public function __construct() {
2709
		// set default map settings
2710
		$this->use_google_maps = true;
2711
		$this->google_map_api_key = '';
2712
		// for event details pages (reg page)
2713
		$this->event_details_map_width = 585;            // ee_map_width_single
2714
		$this->event_details_map_height = 362;            // ee_map_height_single
2715
		$this->event_details_map_zoom = 14;            // ee_map_zoom_single
2716
		$this->event_details_display_nav = true;            // ee_map_nav_display_single
2717
		$this->event_details_nav_size = false;            // ee_map_nav_size_single
2718
		$this->event_details_control_type = 'default';        // ee_map_type_control_single
2719
		$this->event_details_map_align = 'center';            // ee_map_align_single
2720
		// for event list pages
2721
		$this->event_list_map_width = 300;            // ee_map_width
2722
		$this->event_list_map_height = 185;        // ee_map_height
2723
		$this->event_list_map_zoom = 12;            // ee_map_zoom
2724
		$this->event_list_display_nav = false;        // ee_map_nav_display
2725
		$this->event_list_nav_size = true;            // ee_map_nav_size
2726
		$this->event_list_control_type = 'dropdown';        // ee_map_type_control
2727
		$this->event_list_map_align = 'center';            // ee_map_align
2728
	}
2729
2730
}
2731
2732
2733
2734
/**
2735
 * stores Events_Archive settings
2736
 */
2737
class EE_Events_Archive_Config extends EE_Config_Base {
2738
2739
	public $display_status_banner;
2740
2741
	public $display_description;
2742
2743
	public $display_ticket_selector;
2744
2745
	public $display_datetimes;
2746
2747
	public $display_venue;
2748
2749
	public $display_expired_events;
2750
2751
	public $use_sortable_display_order;
2752
2753
	public $display_order_tickets;
2754
2755
	public $display_order_datetimes;
2756
2757
	public $display_order_event;
2758
2759
	public $display_order_venue;
2760
2761
2762
2763
	/**
2764
	 *    class constructor
2765
	 */
2766
	public function __construct() {
2767
		$this->display_status_banner = 0;
2768
		$this->display_description = 1;
2769
		$this->display_ticket_selector = 0;
2770
		$this->display_datetimes = 1;
2771
		$this->display_venue = 0;
2772
		$this->display_expired_events = 0;
2773
		$this->use_sortable_display_order = false;
2774
		$this->display_order_tickets = 100;
2775
		$this->display_order_datetimes = 110;
2776
		$this->display_order_event = 120;
2777
		$this->display_order_venue = 130;
2778
	}
2779
}
2780
2781
2782
2783
/**
2784
 * Stores Event_Single_Config settings
2785
 */
2786
class EE_Event_Single_Config extends EE_Config_Base {
2787
2788
	public $display_status_banner_single;
2789
2790
	public $display_venue;
2791
2792
	public $use_sortable_display_order;
2793
2794
	public $display_order_tickets;
2795
2796
	public $display_order_datetimes;
2797
2798
	public $display_order_event;
2799
2800
	public $display_order_venue;
2801
2802
2803
2804
	/**
2805
	 *    class constructor
2806
	 */
2807
	public function __construct() {
2808
		$this->display_status_banner_single = 0;
2809
		$this->display_venue = 1;
2810
		$this->use_sortable_display_order = false;
2811
		$this->display_order_tickets = 100;
2812
		$this->display_order_datetimes = 110;
2813
		$this->display_order_event = 120;
2814
		$this->display_order_venue = 130;
2815
	}
2816
}
2817
2818
2819
2820
/**
2821
 * Stores Ticket_Selector_Config settings
2822
 */
2823
class EE_Ticket_Selector_Config extends EE_Config_Base {
2824
2825
	/*
2826
	 * @var boolean $show_ticket_sale_columns
2827
	 */
2828
	public $show_ticket_sale_columns;
2829
2830
	/*
2831
	 * @var boolean $show_ticket_details
2832
	 */
2833
	public $show_ticket_details;
2834
2835
	/*
2836
	 * @var boolean $show_expired_tickets
2837
	 */
2838
	public $show_expired_tickets;
2839
2840
2841
2842
	/**
2843
	 *    class constructor
2844
	 */
2845
	public function __construct() {
2846
		$this->show_ticket_sale_columns = true;
2847
		$this->show_ticket_details = true;
2848
		$this->show_expired_tickets = true;
2849
	}
2850
}
2851
2852
2853
2854
/**
2855
 * Stores any EE Environment values that are referenced through the code.
2856
 *
2857
 * @since       4.4.0
2858
 * @package     Event Espresso
2859
 * @subpackage  config
2860
 */
2861
class EE_Environment_Config extends EE_Config_Base {
2862
2863
	/**
2864
	 * Hold any php environment variables that we want to track.
2865
	 *
2866
	 * @var stdClass;
2867
	 */
2868
	public $php;
2869
2870
2871
2872
	/**
2873
	 *    constructor
2874
	 */
2875
	public function __construct() {
2876
		$this->php = new stdClass();
2877
		$this->_set_php_values();
2878
	}
2879
2880
2881
2882
	/**
2883
	 * This sets the php environment variables.
2884
	 *
2885
	 * @since 4.4.0
2886
	 * @return void
2887
	 */
2888
	protected function _set_php_values() {
2889
		$this->php->max_input_vars = ini_get( 'max_input_vars' );
2890
		$this->php->version = phpversion();
2891
	}
2892
2893
2894
2895
	/**
2896
	 * helper method for determining whether input_count is
2897
	 * reaching the potential maximum the server can handle
2898
	 * according to max_input_vars
2899
	 *
2900
	 * @param int   $input_count the count of input vars.
2901
	 * @return array {
2902
	 *                           An array that represents whether available space and if no available space the error
2903
	 *                           message.
2904
	 * @type bool   $has_space   whether more inputs can be added.
2905
	 * @type string $msg         Any message to be displayed.
2906
	 *                           }
2907
	 */
2908
	public function max_input_vars_limit_check( $input_count = 0 ) {
2909
		if ( ! empty( $this->php->max_input_vars )
2910
		     && ( $input_count >= $this->php->max_input_vars )
2911
		     && ( PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9 )
2912
		) {
2913
			return sprintf(
2914
				__(
2915
					'The maximum number of inputs on this page has been exceeded.  You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.',
2916
					'event_espresso'
2917
				),
2918
				'<br>',
2919
				$input_count,
2920
				$this->php->max_input_vars
2921
			);
2922
		} else {
2923
			return '';
2924
		}
2925
	}
2926
2927
2928
2929
	/**
2930
	 * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
2931
	 *
2932
	 * @since 4.4.1
2933
	 * @return void
2934
	 */
2935
	public function recheck_values() {
2936
		$this->_set_php_values();
2937
	}
2938
2939
2940
2941
}
2942
2943
2944
2945
/**
2946
 * Stores any options pertaining to taxes
2947
 *
2948
 * @since       4.9.13
2949
 * @package     Event Espresso
2950
 * @subpackage  config
2951
 */
2952
class EE_Tax_Config extends EE_Config_Base
2953
{
2954
2955
    /*
2956
     * flag to indicate whether or not to display ticket prices with the taxes included
2957
     *
2958
     * @var boolean $prices_displayed_including_taxes
2959
     */
2960
    public $prices_displayed_including_taxes;
2961
2962
2963
2964
    /**
2965
     *    class constructor
2966
     */
2967
    public function __construct()
2968
    {
2969
        $this->prices_displayed_including_taxes = true;
2970
    }
2971
}
2972
2973
2974
2975
/**
2976
 * stores payment gateway info
2977
 *
2978
 * @deprecated
2979
 */
2980
class EE_Gateway_Config extends EE_Config_Base {
2981
2982
	/**
2983
	 * Array with keys that are payment gateways slugs, and values are arrays
2984
	 * with any config info the gateway wants to store
2985
	 *
2986
	 * @var array
2987
	 */
2988
	public $payment_settings;
2989
2990
	/**
2991
	 * Where keys are gateway slugs, and values are booleans indicating whether or not
2992
	 * the gateway is stored in the uploads directory
2993
	 *
2994
	 * @var array
2995
	 */
2996
	public $active_gateways;
2997
2998
2999
3000
	/**
3001
	 *    class constructor
3002
	 *
3003
	 * @deprecated
3004
	 */
3005
	public function __construct() {
3006
		$this->payment_settings = array();
3007
		$this->active_gateways = array( 'Invoice' => false );
3008
	}
3009
}
3010
3011
// End of file EE_Config.core.php
3012
// Location: /core/EE_Config.core.php
3013