Completed
Branch FET-10025-refresh-help-support... (658f11)
by
unknown
100:36 queued 83:14
created

EE_Config::logging_enabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
	 * @var boolean $_logging_enabled
35
	 */
36
	private static $_logging_enabled = false;
37
38
	/**
39
	 * An StdClass whose property names are addon slugs,
40
	 * and values are their config classes
41
	 *
42
	 * @var StdClass
43
	 */
44
	public $addons;
45
46
	/**
47
	 * @var EE_Admin_Config
48
	 */
49
	public $admin;
50
51
	/**
52
	 * @var EE_Core_Config
53
	 */
54
	public $core;
55
56
	/**
57
	 * @var EE_Currency_Config
58
	 */
59
	public $currency;
60
61
	/**
62
	 * @var EE_Organization_Config
63
	 */
64
	public $organization;
65
66
	/**
67
	 * @var EE_Registration_Config
68
	 */
69
	public $registration;
70
71
	/**
72
	 * @var EE_Template_Config
73
	 */
74
	public $template_settings;
75
76
	/**
77
	 * Holds EE environment values.
78
	 *
79
	 * @var EE_Environment_Config
80
	 */
81
	public $environment;
82
83
	/**
84
	 * settings pertaining to Google maps
85
	 *
86
	 * @var EE_Map_Config
87
	 */
88
	public $map_settings;
89
90
	/**
91
	 * settings pertaining to Taxes
92
	 *
93
	 * @var EE_Tax_Config
94
	 */
95
	public $tax_settings;
96
97
	/**
98
	 * @deprecated
99
	 * @var EE_Gateway_Config
100
	 */
101
	public $gateway;
102
103
	/**
104
	 * @var    array $_addon_option_names
105
	 * @access    private
106
	 */
107
	private $_addon_option_names = array();
108
109
	/**
110
	 * @var    array $_module_route_map
111
	 * @access    private
112
	 */
113
	private static $_module_route_map = array();
114
115
	/**
116
	 * @var    array $_module_forward_map
117
	 * @access    private
118
	 */
119
	private static $_module_forward_map = array();
120
121
	/**
122
	 * @var    array $_module_view_map
123
	 * @access    private
124
	 */
125
	private static $_module_view_map = array();
126
127
128
129
	/**
130
	 * @singleton method used to instantiate class object
131
	 * @access    public
132
	 * @return EE_Config instance
133
	 */
134
	public static function instance() {
135
		// check if class object is instantiated, and instantiated properly
136
		if ( ! self::$_instance instanceof EE_Config ) {
137
			self::$_instance = new self();
138
		}
139
		return self::$_instance;
140
	}
141
142
143
144
	/**
145
	 * Resets the config
146
	 *
147
	 * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
148
	 *                               (default) leaves the database alone, and merely resets the EE_Config object to
149
	 *                               reflect its state in the database
150
	 * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
151
	 *                               $_instance as NULL. Useful in case you want to forget about the old instance on
152
	 *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
153
	 *                               site was put into maintenance mode)
154
	 * @return EE_Config
155
	 */
156
	public static function reset( $hard_reset = false, $reinstantiate = true ) {
157
		if ( $hard_reset ) {
158
			self::$_instance->_addon_option_names = array();
159
			self::$_instance->_initialize_config();
160
			self::$_instance->update_espresso_config();
161
		}
162
		if ( self::$_instance instanceof EE_Config ) {
163
			self::$_instance->update_addon_option_names();
164
		}
165
		self::$_instance = null;
166
		//we don't need to reset the static properties imo because those should
167
		//only change when a module is added or removed. Currently we don't
168
		//support removing a module during a request when it previously existed
169
		if ( $reinstantiate ) {
170
			return self::instance();
171
		} else {
172
			return null;
173
		}
174
	}
175
176
177
178
	/**
179
	 *    class constructor
180
	 *
181
	 * @access    private
182
	 */
183
	private function __construct() {
184
		do_action( 'AHEE__EE_Config__construct__begin', $this );
185
		EE_Config::$_logging_enabled = apply_filters( 'FHEE__EE_Config___construct__logging_enabled', false );
186
		// setup empty config classes
187
		$this->_initialize_config();
188
		// load existing EE site settings
189
		$this->_load_core_config();
190
		// confirm everything loaded correctly and set filtered defaults if not
191
		$this->_verify_config();
192
		//  register shortcodes and modules
193
		add_action(
194
			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
195
			array( $this, 'register_shortcodes_and_modules' ),
196
			999
197
		);
198
		//  initialize shortcodes and modules
199
		add_action( 'AHEE__EE_System__core_loaded_and_ready', array( $this, 'initialize_shortcodes_and_modules' ) );
200
		// register widgets
201
		add_action( 'widgets_init', array( $this, 'widgets_init' ), 10 );
202
		// shutdown
203
		add_action( 'shutdown', array( $this, 'shutdown' ), 10 );
204
		// construct__end hook
205
		do_action( 'AHEE__EE_Config__construct__end', $this );
206
		// hardcoded hack
207
		$this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
208
	}
209
210
211
212
	/**
213
	 * @return boolean
214
	 */
215
	public static function logging_enabled() {
216
		return self::$_logging_enabled;
217
	}
218
219
220
221
	/**
222
	 * use to get the current theme if needed from static context
223
	 *
224
	 * @return string current theme set.
225
	 */
226
	public static function get_current_theme() {
227
		return isset( self::$_instance->template_settings->current_espresso_theme )
228
			? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
229
	}
230
231
232
233
	/**
234
	 *        _initialize_config
235
	 *
236
	 * @access private
237
	 * @return void
238
	 */
239
	private function _initialize_config() {
240
		EE_Config::trim_log();
241
		//set defaults
242
		$this->_addon_option_names = get_option( EE_Config::ADDON_OPTION_NAMES, array() );
243
		$this->addons = new stdClass();
244
		// set _module_route_map
245
		EE_Config::$_module_route_map = array();
246
		// set _module_forward_map
247
		EE_Config::$_module_forward_map = array();
248
		// set _module_view_map
249
		EE_Config::$_module_view_map = array();
250
	}
251
252
253
254
	/**
255
	 *        load core plugin configuration
256
	 *
257
	 * @access private
258
	 * @return void
259
	 */
260
	private function _load_core_config() {
261
		// load_core_config__start hook
262
		do_action( 'AHEE__EE_Config___load_core_config__start', $this );
263
		$espresso_config = $this->get_espresso_config();
264
		foreach ( $espresso_config as $config => $settings ) {
265
			// load_core_config__start hook
266
			$settings = apply_filters(
267
				'FHEE__EE_Config___load_core_config__config_settings',
268
				$settings,
269
				$config,
270
				$this
271
			);
272 View Code Duplication
			if ( is_object( $settings ) && property_exists( $this, $config ) ) {
273
				$this->{$config} = apply_filters( 'FHEE__EE_Config___load_core_config__' . $config, $settings );
274
				//call configs populate method to ensure any defaults are set for empty values.
275
				if ( method_exists( $settings, 'populate' ) ) {
276
					$this->{$config}->populate();
277
				}
278
				if ( method_exists( $settings, 'do_hooks' ) ) {
279
					$this->{$config}->do_hooks();
280
				}
281
			}
282
		}
283
		if ( apply_filters( 'FHEE__EE_Config___load_core_config__update_espresso_config', false ) ) {
284
			$this->update_espresso_config();
285
		}
286
		// load_core_config__end hook
287
		do_action( 'AHEE__EE_Config___load_core_config__end', $this );
288
	}
289
290
291
292
	/**
293
	 *    _verify_config
294
	 *
295
	 * @access    protected
296
	 * @return    void
297
	 */
298
	protected function _verify_config() {
299
		$this->core = $this->core instanceof EE_Core_Config
300
			? $this->core
301
			: new EE_Core_Config();
302
		$this->core = apply_filters( 'FHEE__EE_Config___initialize_config__core', $this->core );
303
		$this->organization = $this->organization instanceof EE_Organization_Config
304
			? $this->organization
305
			: new EE_Organization_Config();
306
		$this->organization = apply_filters( 'FHEE__EE_Config___initialize_config__organization', $this->organization );
307
		$this->currency = $this->currency instanceof EE_Currency_Config
308
			? $this->currency
309
			: new EE_Currency_Config();
310
		$this->currency = apply_filters( 'FHEE__EE_Config___initialize_config__currency', $this->currency );
311
		$this->registration = $this->registration instanceof EE_Registration_Config
312
			? $this->registration
313
			: new EE_Registration_Config();
314
		$this->registration = apply_filters( 'FHEE__EE_Config___initialize_config__registration', $this->registration );
315
		$this->admin = $this->admin instanceof EE_Admin_Config
316
			? $this->admin
317
			: new EE_Admin_Config();
318
		$this->admin = apply_filters( 'FHEE__EE_Config___initialize_config__admin', $this->admin );
319
		$this->template_settings = $this->template_settings instanceof EE_Template_Config
320
			? $this->template_settings
321
			: new EE_Template_Config();
322
		$this->template_settings = apply_filters(
323
			'FHEE__EE_Config___initialize_config__template_settings',
324
			$this->template_settings
325
		);
326
		$this->map_settings = $this->map_settings instanceof EE_Map_Config
327
			? $this->map_settings
328
			: new EE_Map_Config();
329
		$this->map_settings = apply_filters( 'FHEE__EE_Config___initialize_config__map_settings', $this->map_settings );
330
		$this->environment = $this->environment instanceof EE_Environment_Config
331
			? $this->environment
332
			: new EE_Environment_Config();
333
		$this->environment = apply_filters( 'FHEE__EE_Config___initialize_config__environment', $this->environment );
334
		$this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
335
			? $this->tax_settings
336
			: new EE_Tax_Config();
337
		$this->tax_settings = apply_filters( 'FHEE__EE_Config___initialize_config__tax_settings', $this->tax_settings );
338
		$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...
339
			? $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...
340
			: 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...
341
		$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...
342
	}
343
344
345
346
	/**
347
	 *    get_espresso_config
348
	 *
349
	 * @access    public
350
	 * @return    array of espresso config stuff
351
	 */
352
	public function get_espresso_config() {
353
		// grab espresso configuration
354
		return apply_filters(
355
			'FHEE__EE_Config__get_espresso_config__CFG',
356
			get_option( EE_Config::OPTION_NAME, array() )
357
		);
358
	}
359
360
361
362
	/**
363
	 *    double_check_config_comparison
364
	 *
365
	 * @access    public
366
	 * @param string $option
367
	 * @param        $old_value
368
	 * @param        $value
369
	 */
370
	public function double_check_config_comparison( $option = '', $old_value, $value ) {
371
		// make sure we're checking the ee config
372
		if ( $option === EE_Config::OPTION_NAME ) {
373
			// run a loose comparison of the old value against the new value for type and properties,
374
			// but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
375
			if ( $value != $old_value ) {
376
				// if they are NOT the same, then remove the hook,
377
				// which means the subsequent update results will be based solely on the update query results
378
				// the reason we do this is because, as stated above,
379
				// WP update_option performs an exact instance comparison (===) on any update values passed to it
380
				// this happens PRIOR to serialization and any subsequent update.
381
				// If values are found to match their previous old value,
382
				// then WP bails before performing any update.
383
				// Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
384
				// it just pulled from the db, with the one being passed to it (which will not match).
385
				// HOWEVER, once the object is serialized and passed off to MySQL to update,
386
				// MySQL MAY ALSO NOT perform the update because
387
				// the string it sees in the db looks the same as the new one it has been passed!!!
388
				// This results in the query returning an "affected rows" value of ZERO,
389
				// which gets returned immediately by WP update_option and looks like an error.
390
				remove_action( 'update_option', array( $this, 'check_config_updated' ) );
391
			}
392
		}
393
	}
394
395
396
397
	/**
398
	 *    update_espresso_config
399
	 *
400
	 * @access   public
401
	 */
402
	protected function _reset_espresso_addon_config() {
403
		$this->_addon_option_names = array();
404
		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...
405
			$addon_config_obj = maybe_unserialize( $addon_config_obj );
406
			$config_class = get_class( $addon_config_obj );
407
			if ( $addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class ) {
408
				$this->update_config( 'addons', $addon_name, $addon_config_obj, false );
409
			}
410
			$this->addons->{$addon_name} = null;
411
		}
412
	}
413
414
415
416
	/**
417
	 *    update_espresso_config
418
	 *
419
	 * @access   public
420
	 * @param   bool $add_success
421
	 * @param   bool $add_error
422
	 * @return   bool
423
	 */
424
	public function update_espresso_config( $add_success = false, $add_error = true ) {
425
		// don't allow config updates during WP heartbeats
426
		if ( \EE_Registry::instance()->REQ->get( 'action', '' ) === 'heartbeat' ) {
427
			return false;
428
		}
429
		// commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
430
		//$clone = clone( self::$_instance );
431
		//self::$_instance = NULL;
432
		do_action( 'AHEE__EE_Config__update_espresso_config__begin', $this );
433
		$this->_reset_espresso_addon_config();
434
		// hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
435
		// but BEFORE the actual update occurs
436
		add_action( 'update_option', array( $this, 'double_check_config_comparison' ), 1, 3 );
437
		// now update "ee_config"
438
		$saved = update_option( EE_Config::OPTION_NAME, $this );
439
		EE_Config::log( EE_Config::OPTION_NAME );
440
		// if not saved... check if the hook we just added still exists;
441
		// if it does, it means one of two things:
442
		// 		that update_option bailed at the ( $value === $old_value ) conditional,
443
		//		 or...
444
		// 		the db update query returned 0 rows affected
445
		// 		(probably because the data  value was the same from it's perspective)
446
		// so the existence of the hook means that a negative result from update_option is NOT an error,
447
		// but just means no update occurred, so don't display an error to the user.
448
		// BUT... if update_option returns FALSE, AND the hook is missing,
449
		// then it means that something truly went wrong
450
		$saved = ! $saved ? has_action( 'update_option', array( $this, 'double_check_config_comparison' ) ) : $saved;
451
		// remove our action since we don't want it in the system anymore
452
		remove_action( 'update_option', array( $this, 'double_check_config_comparison' ), 1 );
453
		do_action( 'AHEE__EE_Config__update_espresso_config__end', $this, $saved );
454
		//self::$_instance = $clone;
455
		//unset( $clone );
456
		// if config remains the same or was updated successfully
457
		if ( $saved ) {
458
			if ( $add_success ) {
459
				EE_Error::add_success(
460
					__( 'The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso' ),
461
					__FILE__,
462
					__FUNCTION__,
463
					__LINE__
464
				);
465
			}
466
			return true;
467
		} else {
468
			if ( $add_error ) {
469
				EE_Error::add_error(
470
					__( 'The Event Espresso Configuration Settings were not updated.', 'event_espresso' ),
471
					__FILE__,
472
					__FUNCTION__,
473
					__LINE__
474
				);
475
			}
476
			return false;
477
		}
478
	}
479
480
481
482
	/**
483
	 *    _verify_config_params
484
	 *
485
	 * @access    private
486
	 * @param    string         $section
487
	 * @param    string         $name
488
	 * @param    string         $config_class
489
	 * @param    EE_Config_Base $config_obj
490
	 * @param    array          $tests_to_run
491
	 * @param    bool           $display_errors
492
	 * @return    bool    TRUE on success, FALSE on fail
493
	 */
494
	private function _verify_config_params(
495
		$section = '',
496
		$name = '',
497
		$config_class = '',
498
		$config_obj = null,
499
		$tests_to_run = array( 1, 2, 3, 4, 5, 6, 7, 8 ),
500
		$display_errors = true
501
	) {
502
		try {
503
			foreach ( $tests_to_run as $test ) {
504
				switch ( $test ) {
505
					// TEST #1 : check that section was set
506 View Code Duplication
					case 1 :
507
						if ( empty( $section ) ) {
508
							if ( $display_errors ) {
509
								throw new EE_Error(
510
									sprintf(
511
										__(
512
											'No configuration section has been provided while attempting to save "%s".',
513
											'event_espresso'
514
										),
515
										$config_class
516
									)
517
								);
518
							}
519
							return false;
520
						}
521
						break;
522
					// TEST #2 : check that settings section exists
523 View Code Duplication
					case 2 :
524
						if ( ! isset( $this->{$section} ) ) {
525
							if ( $display_errors ) {
526
								throw new EE_Error(
527
									sprintf(
528
										__( 'The "%s" configuration section does not exist.', 'event_espresso' ),
529
										$section
530
									)
531
								);
532
							}
533
							return false;
534
						}
535
						break;
536
					// TEST #3 : check that section is the proper format
537
					case 3 :
538
						if (
539
						! ( $this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass )
540
						) {
541
							if ( $display_errors ) {
542
								throw new EE_Error(
543
									sprintf(
544
										__(
545
											'The "%s" configuration settings have not been formatted correctly.',
546
											'event_espresso'
547
										),
548
										$section
549
									)
550
								);
551
							}
552
							return false;
553
						}
554
						break;
555
					// TEST #4 : check that config section name has been set
556 View Code Duplication
					case 4 :
557
						if ( empty( $name ) ) {
558
							if ( $display_errors ) {
559
								throw new EE_Error(
560
									__(
561
										'No name has been provided for the specific configuration section.',
562
										'event_espresso'
563
									)
564
								);
565
							}
566
							return false;
567
						}
568
						break;
569
					// TEST #5 : check that a config class name has been set
570 View Code Duplication
					case 5 :
571
						if ( empty( $config_class ) ) {
572
							if ( $display_errors ) {
573
								throw new EE_Error(
574
									__(
575
										'No class name has been provided for the specific configuration section.',
576
										'event_espresso'
577
									)
578
								);
579
							}
580
							return false;
581
						}
582
						break;
583
					// TEST #6 : verify config class is accessible
584 View Code Duplication
					case 6 :
585
						if ( ! class_exists( $config_class ) ) {
586
							if ( $display_errors ) {
587
								throw new EE_Error(
588
									sprintf(
589
										__(
590
											'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
591
											'event_espresso'
592
										),
593
										$config_class
594
									)
595
								);
596
							}
597
							return false;
598
						}
599
						break;
600
					// TEST #7 : check that config has even been set
601
					case 7 :
602
						if ( ! isset( $this->{$section}->{$name} ) ) {
603
							if ( $display_errors ) {
604
								throw new EE_Error(
605
									sprintf(
606
										__( 'No configuration has been set for "%1$s->%2$s".', 'event_espresso' ),
607
										$section,
608
										$name
609
									)
610
								);
611
							}
612
							return false;
613
						} else {
614
							// and make sure it's not serialized
615
							$this->{$section}->{$name} = maybe_unserialize( $this->{$section}->{$name} );
616
						}
617
						break;
618
					// TEST #8 : check that config is the requested type
619
					case 8 :
620
						if ( ! $this->{$section}->{$name} instanceof $config_class ) {
621
							if ( $display_errors ) {
622
								throw new EE_Error(
623
									sprintf(
624
										__(
625
											'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
626
											'event_espresso'
627
										),
628
										$section,
629
										$name,
630
										$config_class
631
									)
632
								);
633
							}
634
							return false;
635
						}
636
						break;
637
					// TEST #9 : verify config object
638 View Code Duplication
					case 9 :
639
						if ( ! $config_obj instanceof EE_Config_Base ) {
640
							if ( $display_errors ) {
641
								throw new EE_Error(
642
									sprintf(
643
										__( 'The "%s" class is not an instance of EE_Config_Base.', 'event_espresso' ),
644
										print_r( $config_obj, true )
645
									)
646
								);
647
							}
648
							return false;
649
						}
650
						break;
651
				}
652
			}
653
		} catch ( EE_Error $e ) {
654
			$e->get_error();
655
		}
656
		// you have successfully run the gauntlet
657
		return true;
658
	}
659
660
661
662
	/**
663
	 *    _generate_config_option_name
664
	 *
665
	 * @access        protected
666
	 * @param        string $section
667
	 * @param        string $name
668
	 * @return        string
669
	 */
670
	private function _generate_config_option_name( $section = '', $name = '' ) {
671
		return 'ee_config-' . strtolower( $section . '-' . str_replace( array( 'EE_', 'EED_' ), '', $name ) );
672
	}
673
674
675
676
	/**
677
	 *    _set_config_class
678
	 * ensures that a config class is set, either from a passed config class or one generated from the config name
679
	 *
680
	 * @access    private
681
	 * @param    string $config_class
682
	 * @param    string $name
683
	 * @return    string
684
	 */
685
	private function _set_config_class( $config_class = '', $name = '' ) {
686
		return ! empty( $config_class )
687
			? $config_class
688
			: str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $name ) ) ) . '_Config';
689
	}
690
691
692
693
	/**
694
	 *    set_config
695
	 *
696
	 * @access    protected
697
	 * @param    string         $section
698
	 * @param    string         $name
699
	 * @param    string         $config_class
700
	 * @param    EE_Config_Base $config_obj
701
	 * @return    EE_Config_Base
702
	 */
703
	public function set_config( $section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null ) {
704
		// ensure config class is set to something
705
		$config_class = $this->_set_config_class( $config_class, $name );
706
		// run tests 1-4, 6, and 7 to verify all config params are set and valid
707 View Code Duplication
		if ( ! $this->_verify_config_params( $section, $name, $config_class, null, array( 1, 2, 3, 4, 5, 6 ) ) ) {
708
			return null;
709
		}
710
		$config_option_name = $this->_generate_config_option_name( $section, $name );
711
		// if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
712
		if ( ! isset( $this->_addon_option_names[ $config_option_name ] ) ) {
713
			$this->_addon_option_names[ $config_option_name ] = $config_class;
714
			$this->update_addon_option_names();
715
		}
716
		// verify the incoming config object but suppress errors
717
		if ( ! $this->_verify_config_params( $section, $name, $config_class, $config_obj, array( 9 ), false ) ) {
718
			$config_obj = new $config_class();
719
		}
720
		if ( get_option( $config_option_name ) ) {
721
			EE_Config::log( $config_option_name );
722
			update_option( $config_option_name, $config_obj );
723
			$this->{$section}->{$name} = $config_obj;
724
			return $this->{$section}->{$name};
725
		} else {
726
			// create a wp-option for this config
727
			if ( add_option( $config_option_name, $config_obj, '', 'no' ) ) {
728
				$this->{$section}->{$name} = maybe_unserialize( $config_obj );
729
				return $this->{$section}->{$name};
730
			} else {
731
				EE_Error::add_error(
732
					sprintf( __( 'The "%s" could not be saved to the database.', 'event_espresso' ), $config_class ),
733
					__FILE__,
734
					__FUNCTION__,
735
					__LINE__
736
				);
737
				return null;
738
			}
739
		}
740
	}
741
742
743
744
	/**
745
	 *    update_config
746
	 * Important: the config object must ALREADY be set, otherwise this will produce an error.
747
	 *
748
	 * @access    public
749
	 * @param    string                $section
750
	 * @param    string                $name
751
	 * @param    EE_Config_Base|string $config_obj
752
	 * @param    bool                  $throw_errors
753
	 * @return    bool
754
	 */
755
	public function update_config( $section = '', $name = '', $config_obj = '', $throw_errors = true ) {
756
		// don't allow config updates during WP heartbeats
757
		if ( \EE_Registry::instance()->REQ->get( 'action', '' ) === 'heartbeat' ) {
758
			return false;
759
		}
760
		$config_obj = maybe_unserialize( $config_obj );
761
		// get class name of the incoming object
762
		$config_class = get_class( $config_obj );
763
		// run tests 1-5 and 9 to verify config
764 View Code Duplication
		if ( ! $this->_verify_config_params(
765
			$section,
766
			$name,
767
			$config_class,
768
			$config_obj,
769
			array( 1, 2, 3, 4, 7, 9 )
770
		)
771
		) {
772
			return false;
773
		}
774
		$config_option_name = $this->_generate_config_option_name( $section, $name );
775
		// check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
776
		if ( ! isset( $this->_addon_option_names[ $config_option_name ] ) ) {
777
			// save new config to db
778
			if( $this->set_config( $section, $name, $config_class, $config_obj ) ) {
779
				return true;
780
			}
781
		} else {
782
			// first check if the record already exists
783
			$existing_config = get_option( $config_option_name );
784
			$config_obj = serialize( $config_obj );
785
			// just return if db record is already up to date (NOT type safe comparison)
786
			if ( $existing_config == $config_obj ) {
787
				$this->{$section}->{$name} = $config_obj;
788
				return true;
789
			} else if ( update_option( $config_option_name, $config_obj ) ) {
790
				EE_Config::log( $config_option_name );
791
				// update wp-option for this config class
792
				$this->{$section}->{$name} = $config_obj;
793
				return true;
794
			} elseif ( $throw_errors ) {
795
				EE_Error::add_error(
796
					sprintf(
797
						__(
798
							'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
799
							'event_espresso'
800
						),
801
						$config_class,
802
						'EE_Config->' . $section . '->' . $name
803
					),
804
					__FILE__,
805
					__FUNCTION__,
806
					__LINE__
807
				);
808
			}
809
		}
810
		return false;
811
	}
812
813
814
815
	/**
816
	 *    get_config
817
	 *
818
	 * @access    public
819
	 * @param    string $section
820
	 * @param    string $name
821
	 * @param    string $config_class
822
	 * @return    mixed EE_Config_Base | NULL
823
	 */
824
	public function get_config( $section = '', $name = '', $config_class = '' ) {
825
		// ensure config class is set to something
826
		$config_class = $this->_set_config_class( $config_class, $name );
827
		// run tests 1-4, 6 and 7 to verify that all params have been set
828 View Code Duplication
		if ( ! $this->_verify_config_params( $section, $name, $config_class, null, array( 1, 2, 3, 4, 5, 6 ) ) ) {
829
			return null;
830
		}
831
		// now test if the requested config object exists, but suppress errors
832
		if ( $this->_verify_config_params( $section, $name, $config_class, null, array( 7, 8 ), false ) ) {
833
			// config already exists, so pass it back
834
			return $this->{$section}->{$name};
835
		}
836
		// load config option from db if it exists
837
		$config_obj = $this->get_config_option( $this->_generate_config_option_name( $section, $name ) );
838
		// verify the newly retrieved config object, but suppress errors
839
		if ( $this->_verify_config_params( $section, $name, $config_class, $config_obj, array( 9 ), false ) ) {
840
			// config is good, so set it and pass it back
841
			$this->{$section}->{$name} = $config_obj;
842
			return $this->{$section}->{$name};
843
		}
844
		// oops! $config_obj is not already set and does not exist in the db, so create a new one
845
		$config_obj = $this->set_config( $section, $name, $config_class );
846
		// verify the newly created config object
847
		if ( $this->_verify_config_params( $section, $name, $config_class, $config_obj, array( 9 ) ) ) {
848
			return $this->{$section}->{$name};
849
		} else {
850
			EE_Error::add_error(
851
				sprintf( __( 'The "%s" could not be retrieved from the database.', 'event_espresso' ), $config_class ),
852
				__FILE__,
853
				__FUNCTION__,
854
				__LINE__
855
			);
856
		}
857
		return null;
858
	}
859
860
861
862
	/**
863
	 *    get_config_option
864
	 *
865
	 * @access    public
866
	 * @param    string $config_option_name
867
	 * @return    mixed EE_Config_Base | FALSE
868
	 */
869
	public function get_config_option( $config_option_name = '' ) {
870
		// retrieve the wp-option for this config class.
871
		$config_option = maybe_unserialize( get_option( $config_option_name, array() ) );
872
		if ( empty( $config_option ) ) {
873
			EE_Config::log( $config_option_name . '-NOT-FOUND' );
874
		}
875
		return $config_option;
876
	}
877
878
879
880
	/**
881
	 * log
882
	 *
883
	 * @param string $config_option_name
884
	 */
885
	public static function log( $config_option_name = '' ) {
886
		if ( EE_Config::logging_enabled() && ! empty( $config_option_name ) ) {
887
			$config_log = get_option( EE_Config::LOG_NAME, array() );
888
			//copy incoming $_REQUEST and sanitize it so we can save it
889
			$_request = $_REQUEST;
890
			array_walk_recursive( $_request, 'sanitize_text_field' );
891
			$config_log[ (string) microtime( true ) ] = array(
892
				'config_name' => $config_option_name,
893
				'request'     => $_request,
894
			);
895
			update_option( EE_Config::LOG_NAME, $config_log );
896
		}
897
	}
898
899
900
901
	/**
902
	 * trim_log
903
	 * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
904
	 */
905
	public static function trim_log() {
906
		if ( ! EE_Config::logging_enabled() ) {
907
			return;
908
		}
909
		$config_log = maybe_unserialize( get_option( EE_Config::LOG_NAME, array() ) );
910
		$log_length = count( $config_log );
911
		if ( $log_length > EE_Config::LOG_LENGTH ) {
912
			ksort( $config_log );
913
			$config_log = array_slice( $config_log, $log_length - EE_Config::LOG_LENGTH, null, true );
914
			update_option( EE_Config::LOG_NAME, $config_log );
915
		}
916
	}
917
918
919
920
	/**
921
	 *    get_page_for_posts
922
	 *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
923
	 *    wp-option "page_for_posts", or "posts" if no page is selected
924
	 *
925
	 * @access    public
926
	 * @return    string
927
	 */
928 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...
929
		$page_for_posts = get_option( 'page_for_posts' );
930
		if ( ! $page_for_posts ) {
931
			return 'posts';
932
		}
933
		/** @type WPDB $wpdb */
934
		global $wpdb;
935
		$SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
936
		return $wpdb->get_var( $wpdb->prepare( $SQL, $page_for_posts ) );
937
	}
938
939
940
941
	/**
942
	 *    register_shortcodes_and_modules.
943
	 *    At this point, it's too early to tell if we're maintenance mode or not.
944
	 *    In fact, this is where we give modules a chance to let core know they exist
945
	 *    so they can help trigger maintenance mode if it's needed
946
	 *
947
	 * @access    public
948
	 * @return    void
949
	 */
950
	public function register_shortcodes_and_modules() {
951
		// allow shortcodes to register with WP and to set hooks for the rest of the system
952
		EE_Registry::instance()->shortcodes = $this->_register_shortcodes();
953
		// allow modules to set hooks for the rest of the system
954
		EE_Registry::instance()->modules = $this->_register_modules();
955
	}
956
957
958
959
	/**
960
	 *    initialize_shortcodes_and_modules
961
	 *    meaning they can start adding their hooks to get stuff done
962
	 *
963
	 * @access    public
964
	 * @return    void
965
	 */
966
	public function initialize_shortcodes_and_modules() {
967
		// allow shortcodes to set hooks for the rest of the system
968
		$this->_initialize_shortcodes();
969
		// allow modules to set hooks for the rest of the system
970
		$this->_initialize_modules();
971
	}
972
973
974
975
	/**
976
	 *    widgets_init
977
	 *
978
	 * @access private
979
	 * @return void
980
	 */
981
	public function widgets_init() {
982
		//only init widgets on admin pages when not in complete maintenance, and
983
		//on frontend when not in any maintenance mode
984
		if (
985
			! EE_Maintenance_Mode::instance()->level()
986
			|| (
987
				is_admin()
988
				&& EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
989
			)
990
		) {
991
			// grab list of installed widgets
992
			$widgets_to_register = glob( EE_WIDGETS . '*', GLOB_ONLYDIR );
993
			// filter list of modules to register
994
			$widgets_to_register = apply_filters(
995
				'FHEE__EE_Config__register_widgets__widgets_to_register',
996
				$widgets_to_register
997
			);
998
			if ( ! empty( $widgets_to_register ) ) {
999
				// cycle thru widget folders
1000
				foreach ( $widgets_to_register as $widget_path ) {
1001
					// add to list of installed widget modules
1002
					EE_Config::register_ee_widget( $widget_path );
1003
				}
1004
			}
1005
			// filter list of installed modules
1006
			EE_Registry::instance()->widgets = apply_filters(
1007
				'FHEE__EE_Config__register_widgets__installed_widgets',
1008
				EE_Registry::instance()->widgets
1009
			);
1010
		}
1011
	}
1012
1013
1014
1015
	/**
1016
	 *    register_ee_widget - makes core aware of this widget
1017
	 *
1018
	 * @access    public
1019
	 * @param    string $widget_path - full path up to and including widget folder
1020
	 * @return    void
1021
	 */
1022
	public static function register_ee_widget( $widget_path = null ) {
1023
		do_action( 'AHEE__EE_Config__register_widget__begin', $widget_path );
1024
		$widget_ext = '.widget.php';
1025
		// make all separators match
1026
		$widget_path = rtrim( str_replace( '/\\', DS, $widget_path ), DS );
1027
		// does the file path INCLUDE the actual file name as part of the path ?
1028
		if ( strpos( $widget_path, $widget_ext ) !== false ) {
1029
			// grab and shortcode file name from directory name and break apart at dots
1030
			$file_name = explode( '.', basename( $widget_path ) );
1031
			// take first segment from file name pieces and remove class prefix if it exists
1032
			$widget = strpos( $file_name[0], 'EEW_' ) === 0 ? substr( $file_name[0], 4 ) : $file_name[0];
1033
			// sanitize shortcode directory name
1034
			$widget = sanitize_key( $widget );
1035
			// now we need to rebuild the shortcode path
1036
			$widget_path = explode( DS, $widget_path );
1037
			// remove last segment
1038
			array_pop( $widget_path );
1039
			// glue it back together
1040
			$widget_path = implode( DS, $widget_path );
1041
		} else {
1042
			// grab and sanitize widget directory name
1043
			$widget = sanitize_key( basename( $widget_path ) );
1044
		}
1045
		// create classname from widget directory name
1046
		$widget = str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $widget ) ) );
1047
		// add class prefix
1048
		$widget_class = 'EEW_' . $widget;
1049
		// does the widget exist ?
1050 View Code Duplication
		if ( ! is_readable( $widget_path . DS . $widget_class . $widget_ext ) ) {
1051
			$msg = sprintf(
1052
				__(
1053
					'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',
1054
					'event_espresso'
1055
				),
1056
				$widget_class,
1057
				$widget_path . DS . $widget_class . $widget_ext
1058
			);
1059
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1060
			return;
1061
		}
1062
		// load the widget class file
1063
		require_once( $widget_path . DS . $widget_class . $widget_ext );
1064
		// verify that class exists
1065
		if ( ! class_exists( $widget_class ) ) {
1066
			$msg = sprintf( __( 'The requested %s widget class does not exist.', 'event_espresso' ), $widget_class );
1067
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1068
			return;
1069
		}
1070
		register_widget( $widget_class );
1071
		// add to array of registered widgets
1072
		EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1073
	}
1074
1075
1076
1077
	/**
1078
	 *        _register_shortcodes
1079
	 *
1080
	 * @access private
1081
	 * @return array
1082
	 */
1083
	private function _register_shortcodes() {
1084
		// grab list of installed shortcodes
1085
		$shortcodes_to_register = glob( EE_SHORTCODES . '*', GLOB_ONLYDIR );
1086
		// filter list of modules to register
1087
		$shortcodes_to_register = apply_filters(
1088
			'FHEE__EE_Config__register_shortcodes__shortcodes_to_register',
1089
			$shortcodes_to_register
1090
		);
1091
		if ( ! empty( $shortcodes_to_register ) ) {
1092
			// cycle thru shortcode folders
1093
			foreach ( $shortcodes_to_register as $shortcode_path ) {
1094
				// add to list of installed shortcode modules
1095
				EE_Config::register_shortcode( $shortcode_path );
1096
			}
1097
		}
1098
		// filter list of installed modules
1099
		return apply_filters(
1100
			'FHEE__EE_Config___register_shortcodes__installed_shortcodes',
1101
			EE_Registry::instance()->shortcodes
1102
		);
1103
	}
1104
1105
1106
1107
	/**
1108
	 *    register_shortcode - makes core aware of this shortcode
1109
	 *
1110
	 * @access    public
1111
	 * @param    string $shortcode_path - full path up to and including shortcode folder
1112
	 * @return    bool
1113
	 */
1114
	public static function register_shortcode( $shortcode_path = null ) {
1115
		do_action( 'AHEE__EE_Config__register_shortcode__begin', $shortcode_path );
1116
		$shortcode_ext = '.shortcode.php';
1117
		// make all separators match
1118
		$shortcode_path = str_replace( array( '\\', '/' ), DS, $shortcode_path );
1119
		// does the file path INCLUDE the actual file name as part of the path ?
1120
		if ( strpos( $shortcode_path, $shortcode_ext ) !== false ) {
1121
			// grab shortcode file name from directory name and break apart at dots
1122
			$shortcode_file = explode( '.', basename( $shortcode_path ) );
1123
			// take first segment from file name pieces and remove class prefix if it exists
1124
			$shortcode = strpos( $shortcode_file[0], 'EES_' ) === 0
1125
				? substr( $shortcode_file[0], 4 )
1126
				: $shortcode_file[0];
1127
			// sanitize shortcode directory name
1128
			$shortcode = sanitize_key( $shortcode );
1129
			// now we need to rebuild the shortcode path
1130
			$shortcode_path = explode( DS, $shortcode_path );
1131
			// remove last segment
1132
			array_pop( $shortcode_path );
1133
			// glue it back together
1134
			$shortcode_path = implode( DS, $shortcode_path ) . DS;
1135
		} else {
1136
			// we need to generate the filename based off of the folder name
1137
			// grab and sanitize shortcode directory name
1138
			$shortcode = sanitize_key( basename( $shortcode_path ) );
1139
			$shortcode_path = rtrim( $shortcode_path, DS ) . DS;
1140
		}
1141
		// create classname from shortcode directory or file name
1142
		$shortcode = str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $shortcode ) ) );
1143
		// add class prefix
1144
		$shortcode_class = 'EES_' . $shortcode;
1145
		// does the shortcode exist ?
1146 View Code Duplication
		if ( ! is_readable( $shortcode_path . DS . $shortcode_class . $shortcode_ext ) ) {
1147
			$msg = sprintf(
1148
				__(
1149
					'The requested %s shortcode file could not be found or is not readable due to file permissions. It should be in %s',
1150
					'event_espresso'
1151
				),
1152
				$shortcode_class,
1153
				$shortcode_path . DS . $shortcode_class . $shortcode_ext
1154
			);
1155
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1156
			return false;
1157
		}
1158
		// load the shortcode class file
1159
		require_once( $shortcode_path . $shortcode_class . $shortcode_ext );
1160
		// verify that class exists
1161
		if ( ! class_exists( $shortcode_class ) ) {
1162
			$msg = sprintf(
1163
				__( 'The requested %s shortcode class does not exist.', 'event_espresso' ),
1164
				$shortcode_class
1165
			);
1166
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1167
			return false;
1168
		}
1169
		$shortcode = strtoupper( $shortcode );
1170
		// add to array of registered shortcodes
1171
		EE_Registry::instance()->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext;
1172
		return true;
1173
	}
1174
1175
1176
1177
	/**
1178
	 *        _register_modules
1179
	 *
1180
	 * @access private
1181
	 * @return array
1182
	 */
1183
	private function _register_modules() {
1184
		// grab list of installed modules
1185
		$modules_to_register = glob( EE_MODULES . '*', GLOB_ONLYDIR );
1186
		// filter list of modules to register
1187
		$modules_to_register = apply_filters(
1188
			'FHEE__EE_Config__register_modules__modules_to_register',
1189
			$modules_to_register
1190
		);
1191
		if ( ! empty( $modules_to_register ) ) {
1192
			// loop through folders
1193
			foreach ( $modules_to_register as $module_path ) {
1194
				/**TEMPORARILY EXCLUDE gateways from modules for time being**/
1195
				if (
1196
					$module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1197
					&& $module_path !== EE_MODULES . 'gateways'
1198
				) {
1199
					// add to list of installed modules
1200
					EE_Config::register_module( $module_path );
1201
				}
1202
			}
1203
		}
1204
		// filter list of installed modules
1205
		return apply_filters(
1206
			'FHEE__EE_Config___register_modules__installed_modules',
1207
			EE_Registry::instance()->modules
1208
		);
1209
	}
1210
1211
1212
1213
	/**
1214
	 *    register_module - makes core aware of this module
1215
	 *
1216
	 * @access    public
1217
	 * @param    string $module_path - full path up to and including module folder
1218
	 * @return    bool
1219
	 */
1220
	public static function register_module( $module_path = null ) {
1221
		do_action( 'AHEE__EE_Config__register_module__begin', $module_path );
1222
		$module_ext = '.module.php';
1223
		// make all separators match
1224
		$module_path = str_replace( array( '\\', '/' ), DS, $module_path );
1225
		// does the file path INCLUDE the actual file name as part of the path ?
1226
		if ( strpos( $module_path, $module_ext ) !== false ) {
1227
			// grab and shortcode file name from directory name and break apart at dots
1228
			$module_file = explode( '.', basename( $module_path ) );
1229
			// now we need to rebuild the shortcode path
1230
			$module_path = explode( DS, $module_path );
1231
			// remove last segment
1232
			array_pop( $module_path );
1233
			// glue it back together
1234
			$module_path = implode( DS, $module_path ) . DS;
1235
			// take first segment from file name pieces and sanitize it
1236
			$module = preg_replace( '/[^a-zA-Z0-9_\-]/', '', $module_file[0] );
1237
			// ensure class prefix is added
1238
			$module_class = strpos( $module, 'EED_' ) !== 0 ? 'EED_' . $module : $module;
1239
		} else {
1240
			// we need to generate the filename based off of the folder name
1241
			// grab and sanitize module name
1242
			$module = strtolower( basename( $module_path ) );
1243
			$module = preg_replace( '/[^a-z0-9_\-]/', '', $module );
1244
			// like trailingslashit()
1245
			$module_path = rtrim( $module_path, DS ) . DS;
1246
			// create classname from module directory name
1247
			$module = str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $module ) ) );
1248
			// add class prefix
1249
			$module_class = 'EED_' . $module;
1250
		}
1251
		// does the module exist ?
1252 View Code Duplication
		if ( ! is_readable( $module_path . DS . $module_class . $module_ext ) ) {
1253
			$msg = sprintf(
1254
				__(
1255
					'The requested %s module file could not be found or is not readable due to file permissions.',
1256
					'event_espresso'
1257
				),
1258
				$module
1259
			);
1260
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1261
			return false;
1262
		}
1263
		// load the module class file
1264
		require_once( $module_path . $module_class . $module_ext );
1265
		// verify that class exists
1266
		if ( ! class_exists( $module_class ) ) {
1267
			$msg = sprintf( __( 'The requested %s module class does not exist.', 'event_espresso' ), $module_class );
1268
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1269
			return false;
1270
		}
1271
		// add to array of registered modules
1272
		EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1273
		do_action(
1274
			'AHEE__EE_Config__register_module__complete',
1275
			$module_class,
1276
			EE_Registry::instance()->modules->{$module_class}
1277
		);
1278
		return true;
1279
	}
1280
1281
1282
1283
	/**
1284
	 *    _initialize_shortcodes
1285
	 *    allow shortcodes to set hooks for the rest of the system
1286
	 *
1287
	 * @access private
1288
	 * @return void
1289
	 */
1290
	private function _initialize_shortcodes() {
1291
		// cycle thru shortcode folders
1292
		foreach ( EE_Registry::instance()->shortcodes as $shortcode => $shortcode_path ) {
1293
			// add class prefix
1294
			$shortcode_class = 'EES_' . $shortcode;
1295
			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1296
			// which set hooks ?
1297
			if ( is_admin() ) {
1298
				// fire immediately
1299
				call_user_func( array( $shortcode_class, 'set_hooks_admin' ) );
1300
			} else {
1301
				// delay until other systems are online
1302
				add_action(
1303
					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1304
					array( $shortcode_class, 'set_hooks' )
1305
				);
1306
				// convert classname to UPPERCASE and create WP shortcode.
1307
				$shortcode_tag = strtoupper( $shortcode );
1308
				// but first check if the shortcode has already been added before assigning 'fallback_shortcode_processor'
1309
				if ( ! shortcode_exists( $shortcode_tag ) ) {
1310
					// NOTE: this shortcode declaration will get overridden if the shortcode is successfully detected in the post content in EE_Front_Controller->_initialize_shortcodes()
1311
					add_shortcode( $shortcode_tag, array( $shortcode_class, 'fallback_shortcode_processor' ) );
1312
				}
1313
			}
1314
		}
1315
	}
1316
1317
1318
1319
	/**
1320
	 *    _initialize_modules
1321
	 *    allow modules to set hooks for the rest of the system
1322
	 *
1323
	 * @access private
1324
	 * @return void
1325
	 */
1326
	private function _initialize_modules() {
1327
		// cycle thru shortcode folders
1328
		foreach ( EE_Registry::instance()->modules as $module_class => $module_path ) {
1329
			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1330
			// which set hooks ?
1331
			if ( is_admin() ) {
1332
				// fire immediately
1333
				call_user_func( array( $module_class, 'set_hooks_admin' ) );
1334
			} else {
1335
				// delay until other systems are online
1336
				add_action(
1337
					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1338
					array( $module_class, 'set_hooks' )
1339
				);
1340
			}
1341
		}
1342
	}
1343
1344
1345
1346
	/**
1347
	 *    register_route - adds module method routes to route_map
1348
	 *
1349
	 * @access    public
1350
	 * @param    string $route       - "pretty" public alias for module method
1351
	 * @param    string $module      - module name (classname without EED_ prefix)
1352
	 * @param    string $method_name - the actual module method to be routed to
1353
	 * @param    string $key         - url param key indicating a route is being called
1354
	 * @return    bool
1355
	 */
1356
	public static function register_route( $route = null, $module = null, $method_name = null, $key = 'ee' ) {
1357
		do_action( 'AHEE__EE_Config__register_route__begin', $route, $module, $method_name );
1358
		$module = str_replace( 'EED_', '', $module );
1359
		$module_class = 'EED_' . $module;
1360
		if ( ! isset( EE_Registry::instance()->modules->{$module_class} ) ) {
1361
			$msg = sprintf( __( 'The module %s has not been registered.', 'event_espresso' ), $module );
1362
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1363
			return false;
1364
		}
1365 View Code Duplication
		if ( empty( $route ) ) {
1366
			$msg = sprintf( __( 'No route has been supplied.', 'event_espresso' ), $route );
1367
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1368
			return false;
1369
		}
1370 View Code Duplication
		if ( ! method_exists( 'EED_' . $module, $method_name ) ) {
1371
			$msg = sprintf(
1372
				__( 'A valid class method for the %s route has not been supplied.', 'event_espresso' ),
1373
				$route
1374
			);
1375
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1376
			return false;
1377
		}
1378
		EE_Config::$_module_route_map[ $key ][ $route ] = array( 'EED_' . $module, $method_name );
1379
		return true;
1380
	}
1381
1382
1383
1384
	/**
1385
	 *    get_route - get module method route
1386
	 *
1387
	 * @access    public
1388
	 * @param    string $route - "pretty" public alias for module method
1389
	 * @param    string $key   - url param key indicating a route is being called
1390
	 * @return    string
1391
	 */
1392
	public static function get_route( $route = null, $key = 'ee' ) {
1393
		do_action( 'AHEE__EE_Config__get_route__begin', $route );
1394
		$route = (string) apply_filters( 'FHEE__EE_Config__get_route', $route );
1395
		if ( isset( EE_Config::$_module_route_map[ $key ][ $route ] ) ) {
1396
			return EE_Config::$_module_route_map[ $key ][ $route ];
1397
		}
1398
		return null;
1399
	}
1400
1401
1402
1403
	/**
1404
	 *    get_routes - get ALL module method routes
1405
	 *
1406
	 * @access    public
1407
	 * @return    array
1408
	 */
1409
	public static function get_routes() {
1410
		return EE_Config::$_module_route_map;
1411
	}
1412
1413
1414
1415
	/**
1416
	 *    register_forward - allows modules to forward request to another module for further processing
1417
	 *
1418
	 * @access    public
1419
	 * @param    string       $route   - "pretty" public alias for module method
1420
	 * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1421
	 *                                 class, allows different forwards to be served based on status
1422
	 * @param    array|string $forward - function name or array( class, method )
1423
	 * @param    string       $key     - url param key indicating a route is being called
1424
	 * @return    bool
1425
	 */
1426
	public static function register_forward( $route = null, $status = 0, $forward = null, $key = 'ee' ) {
1427
		do_action( 'AHEE__EE_Config__register_forward', $route, $status, $forward );
1428 View Code Duplication
		if ( ! isset( EE_Config::$_module_route_map[ $key ][ $route ] ) || empty( $route ) ) {
1429
			$msg = sprintf(
1430
				__( 'The module route %s for this forward has not been registered.', 'event_espresso' ),
1431
				$route
1432
			);
1433
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1434
			return false;
1435
		}
1436 View Code Duplication
		if ( empty( $forward ) ) {
1437
			$msg = sprintf( __( 'No forwarding route has been supplied.', 'event_espresso' ), $route );
1438
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1439
			return false;
1440
		}
1441
		if ( is_array( $forward ) ) {
1442 View Code Duplication
			if ( ! isset( $forward[1] ) ) {
1443
				$msg = sprintf(
1444
					__( 'A class method for the %s forwarding route has not been supplied.', 'event_espresso' ),
1445
					$route
1446
				);
1447
				EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1448
				return false;
1449
			}
1450
			if ( ! method_exists( $forward[0], $forward[1] ) ) {
1451
				$msg = sprintf(
1452
					__( 'The class method %s for the %s forwarding route is in invalid.', 'event_espresso' ),
1453
					$forward[1],
1454
					$route
1455
				);
1456
				EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1457
				return false;
1458
			}
1459
		} else if ( ! function_exists( $forward ) ) {
1460
			$msg = sprintf(
1461
				__( 'The function %s for the %s forwarding route is in invalid.', 'event_espresso' ),
1462
				$forward,
1463
				$route
1464
			);
1465
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1466
			return false;
1467
		}
1468
		EE_Config::$_module_forward_map[ $key ][ $route ][ absint( $status ) ] = $forward;
1469
		return true;
1470
	}
1471
1472
1473
1474
	/**
1475
	 *    get_forward - get forwarding route
1476
	 *
1477
	 * @access    public
1478
	 * @param    string  $route  - "pretty" public alias for module method
1479
	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1480
	 *                           allows different forwards to be served based on status
1481
	 * @param    string  $key    - url param key indicating a route is being called
1482
	 * @return    string
1483
	 */
1484 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...
1485
		do_action( 'AHEE__EE_Config__get_forward__begin', $route, $status );
1486
		if ( isset( EE_Config::$_module_forward_map[ $key ][ $route ][ $status ] ) ) {
1487
			return apply_filters(
1488
				'FHEE__EE_Config__get_forward',
1489
				EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1490
				$route,
1491
				$status
1492
			);
1493
		}
1494
		return null;
1495
	}
1496
1497
1498
1499
	/**
1500
	 *    register_forward - allows modules to specify different view templates for different method routes and status
1501
	 *    results
1502
	 *
1503
	 * @access    public
1504
	 * @param    string  $route  - "pretty" public alias for module method
1505
	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1506
	 *                           allows different views to be served based on status
1507
	 * @param    string  $view
1508
	 * @param    string  $key    - url param key indicating a route is being called
1509
	 * @return    bool
1510
	 */
1511
	public static function register_view( $route = null, $status = 0, $view = null, $key = 'ee' ) {
1512
		do_action( 'AHEE__EE_Config__register_view__begin', $route, $status, $view );
1513 View Code Duplication
		if ( ! isset( EE_Config::$_module_route_map[ $key ][ $route ] ) || empty( $route ) ) {
1514
			$msg = sprintf(
1515
				__( 'The module route %s for this view has not been registered.', 'event_espresso' ),
1516
				$route
1517
			);
1518
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1519
			return false;
1520
		}
1521
		if ( ! is_readable( $view ) ) {
1522
			$msg = sprintf(
1523
				__(
1524
					'The %s view file could not be found or is not readable due to file permissions.',
1525
					'event_espresso'
1526
				),
1527
				$view
1528
			);
1529
			EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ );
1530
			return false;
1531
		}
1532
		EE_Config::$_module_view_map[ $key ][ $route ][ absint( $status ) ] = $view;
1533
		return true;
1534
	}
1535
1536
1537
1538
	/**
1539
	 *    get_view - get view for route and status
1540
	 *
1541
	 * @access    public
1542
	 * @param    string  $route  - "pretty" public alias for module method
1543
	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1544
	 *                           allows different views to be served based on status
1545
	 * @param    string  $key    - url param key indicating a route is being called
1546
	 * @return    string
1547
	 */
1548 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...
1549
		do_action( 'AHEE__EE_Config__get_view__begin', $route, $status );
1550
		if ( isset( EE_Config::$_module_view_map[ $key ][ $route ][ $status ] ) ) {
1551
			return apply_filters(
1552
				'FHEE__EE_Config__get_view',
1553
				EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1554
				$route,
1555
				$status
1556
			);
1557
		}
1558
		return null;
1559
	}
1560
1561
1562
1563
	public function update_addon_option_names() {
1564
		update_option( EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names );
1565
	}
1566
1567
1568
1569
	public function shutdown() {
1570
		$this->update_addon_option_names();
1571
	}
1572
1573
1574
}
1575
1576
1577
1578
/**
1579
 * Base class used for config classes. These classes should generally not have
1580
 * magic functions in use, except we'll allow them to magically set and get stuff...
1581
 * basically, they should just be well-defined stdClasses
1582
 */
1583
class EE_Config_Base {
1584
1585
	/**
1586
	 * Utility function for escaping the value of a property and returning.
1587
	 *
1588
	 * @param string $property property name (checks to see if exists).
1589
	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1590
	 * @throws \EE_Error
1591
	 */
1592
	public function get_pretty( $property ) {
1593
		if ( ! property_exists( $this, $property ) ) {
1594
			throw new EE_Error(
1595
				sprintf(
1596
					__(
1597
						'%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1598
						'event_espresso'
1599
					),
1600
					get_class( $this ),
1601
					$property
1602
				)
1603
			);
1604
		}
1605
		//just handling escaping of strings for now.
1606
		if ( is_string( $this->{$property} ) ) {
1607
			return stripslashes( $this->{$property} );
1608
		}
1609
		return $this->{$property};
1610
	}
1611
1612
1613
1614
	public function populate() {
1615
		//grab defaults via a new instance of this class.
1616
		$class_name = get_class( $this );
1617
		$defaults = new $class_name;
1618
		//loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1619
		//default from our $defaults object.
1620
		foreach ( get_object_vars( $defaults ) as $property => $value ) {
1621
			if ( $this->{$property} === null ) {
1622
				$this->{$property} = $value;
1623
			}
1624
		}
1625
		//cleanup
1626
		unset( $defaults );
1627
	}
1628
1629
1630
	/**
1631
	 *        @ override magic methods
1632
	 *        @ return void
1633
	 */
1634
//	public function __get($a) { return apply_filters('FHEE__'.get_class($this).'__get__'.$a,$this->{$a}); }
1635
//	public function __set($a,$b) { return apply_filters('FHEE__'.get_class($this).'__set__'.$a, $this->{$a} = $b ); }
1636
	/**
1637
	 *        __isset
1638
	 *
1639
	 * @param $a
1640
	 * @return bool
1641
	 */
1642
	public function __isset( $a ) {
1643
		return false;
1644
	}
1645
1646
1647
1648
	/**
1649
	 *        __unset
1650
	 *
1651
	 * @param $a
1652
	 * @return bool
1653
	 */
1654
	public function __unset( $a ) {
1655
		return false;
1656
	}
1657
1658
1659
1660
	/**
1661
	 *        __clone
1662
	 */
1663
	public function __clone() {
1664
	}
1665
1666
1667
1668
	/**
1669
	 *        __wakeup
1670
	 */
1671
	public function __wakeup() {
1672
	}
1673
1674
1675
1676
	/**
1677
	 *        __destruct
1678
	 */
1679
	public function __destruct() {
1680
	}
1681
}
1682
1683
1684
1685
/**
1686
 * Class for defining what's in the EE_Config relating to registration settings
1687
 */
1688
class EE_Core_Config extends EE_Config_Base {
1689
1690
	public $current_blog_id;
1691
1692
	public $ee_ueip_optin;
1693
1694
	public $ee_ueip_has_notified;
1695
1696
	/**
1697
	 * Not to be confused with the 4 critical page variables (See
1698
	 * get_critical_pages_array()), this is just an array of wp posts that have EE
1699
	 * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1700
	 * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1701
	 *
1702
	 * @var array
1703
	 */
1704
	public $post_shortcodes;
1705
1706
	public $module_route_map;
1707
1708
	public $module_forward_map;
1709
1710
	public $module_view_map;
1711
1712
	/**
1713
	 * The next 4 vars are the IDs of critical EE pages.
1714
	 *
1715
	 * @var int
1716
	 */
1717
	public $reg_page_id;
1718
1719
	public $txn_page_id;
1720
1721
	public $thank_you_page_id;
1722
1723
	public $cancel_page_id;
1724
1725
	/**
1726
	 * The next 4 vars are the URLs of critical EE pages.
1727
	 *
1728
	 * @var int
1729
	 */
1730
	public $reg_page_url;
1731
1732
	public $txn_page_url;
1733
1734
	public $thank_you_page_url;
1735
1736
	public $cancel_page_url;
1737
1738
	/**
1739
	 * The next vars relate to the custom slugs for EE CPT routes
1740
	 */
1741
	public $event_cpt_slug;
1742
1743
1744
1745
	/**
1746
	 * This caches the _ee_ueip_option in case this config is reset in the same
1747
	 * request across blog switches in a multisite context.
1748
	 * Avoids extra queries to the db for this option.
1749
	 * @var bool
1750
	 */
1751
	public static $ee_ueip_option;
1752
1753
1754
	/**
1755
	 *    class constructor
1756
	 *
1757
	 * @access    public
1758
	 */
1759
	public function __construct() {
1760
		// set default organization settings
1761
		$this->current_blog_id = get_current_blog_id();
1762
		$this->current_blog_id = $this->current_blog_id === NULL ? 1 : $this->current_blog_id;
1763
		$this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1764
		$this->ee_ueip_has_notified = is_main_site() ? get_option( 'ee_ueip_has_notified', false ) : true;
1765
		$this->post_shortcodes = array();
1766
		$this->module_route_map = array();
1767
		$this->module_forward_map = array();
1768
		$this->module_view_map = array();
1769
		// critical EE page IDs
1770
		$this->reg_page_id = 0;
1771
		$this->txn_page_id = 0;
1772
		$this->thank_you_page_id = 0;
1773
		$this->cancel_page_id = 0;
1774
		// critical EE page URLs
1775
		$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...
1776
		$this->txn_page_url = '';
1777
		$this->thank_you_page_url = '';
1778
		$this->cancel_page_url = '';
1779
		//cpt slugs
1780
		$this->event_cpt_slug = __( 'events', 'event_espresso' );
1781
		//ueip constant check
1782
		if ( defined( 'EE_DISABLE_UXIP' ) && EE_DISABLE_UXIP ) {
1783
			$this->ee_ueip_optin = false;
1784
			$this->ee_ueip_has_notified = true;
1785
		}
1786
	}
1787
1788
1789
1790
	/**
1791
	 * @return array
1792
	 */
1793
	public function get_critical_pages_array() {
1794
		return array(
1795
			$this->reg_page_id,
1796
			$this->txn_page_id,
1797
			$this->thank_you_page_id,
1798
			$this->cancel_page_id,
1799
		);
1800
	}
1801
1802
1803
1804
	/**
1805
	 * @return array
1806
	 */
1807
	public function get_critical_pages_shortcodes_array() {
1808
		return array(
1809
			$this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1810
			$this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1811
			$this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1812
			$this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1813
		);
1814
	}
1815
1816
1817
1818
	/**
1819
	 *  gets/returns URL for EE reg_page
1820
	 *
1821
	 * @access    public
1822
	 * @return    string
1823
	 */
1824
	public function reg_page_url() {
1825
		if ( ! $this->reg_page_url ) {
1826
			$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...
1827
				array( 'uts' => time() ),
1828
				get_permalink( $this->reg_page_id )
1829
			) . '#checkout';
1830
		}
1831
		return $this->reg_page_url;
1832
	}
1833
1834
1835
1836
	/**
1837
	 *  gets/returns URL for EE txn_page
1838
	 *
1839
	 * @param array $query_args like what gets passed to
1840
	 *                          add_query_arg() as the first argument
1841
	 * @access    public
1842
	 * @return    string
1843
	 */
1844 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...
1845
		if ( ! $this->txn_page_url ) {
1846
			$this->txn_page_url = get_permalink( $this->txn_page_id );
1847
		}
1848
		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...
1849
			return add_query_arg( $query_args, $this->txn_page_url );
1850
		} else {
1851
			return $this->txn_page_url;
1852
		}
1853
	}
1854
1855
1856
1857
	/**
1858
	 *  gets/returns URL for EE thank_you_page
1859
	 *
1860
	 * @param array $query_args like what gets passed to
1861
	 *                          add_query_arg() as the first argument
1862
	 * @access    public
1863
	 * @return    string
1864
	 */
1865 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...
1866
		if ( ! $this->thank_you_page_url ) {
1867
			$this->thank_you_page_url = get_permalink( $this->thank_you_page_id );
1868
		}
1869
		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...
1870
			return add_query_arg( $query_args, $this->thank_you_page_url );
1871
		} else {
1872
			return $this->thank_you_page_url;
1873
		}
1874
	}
1875
1876
1877
1878
	/**
1879
	 *  gets/returns URL for EE cancel_page
1880
	 *
1881
	 * @access    public
1882
	 * @return    string
1883
	 */
1884
	public function cancel_page_url() {
1885
		if ( ! $this->cancel_page_url ) {
1886
			$this->cancel_page_url = get_permalink( $this->cancel_page_id );
1887
		}
1888
		return $this->cancel_page_url;
1889
	}
1890
1891
1892
1893
	/**
1894
	 * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1895
	 *
1896
	 * @since 4.7.5
1897
	 */
1898
	protected function _reset_urls() {
1899
		$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...
1900
		$this->txn_page_url = '';
1901
		$this->cancel_page_url = '';
1902
		$this->thank_you_page_url = '';
1903
	}
1904
1905
1906
	/**
1907
	 * Used to return what the optin value is set for the EE User Experience Program.
1908
	 * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1909
	 * on the main site only.
1910
	 *
1911
	 * @return mixed|void
1912
	 */
1913
	protected function _get_main_ee_ueip_optin() {
1914
		//if this is the main site then we can just bypass our direct query.
1915
		if ( is_main_site() ) {
1916
			return get_option( 'ee_ueip_optin', false );
1917
		}
1918
1919
		//is this already cached for this request?  If so use it.
1920
		if ( ! empty( EE_Core_Config::$ee_ueip_option ) ) {
1921
			return EE_Core_Config::$ee_ueip_option;
1922
		}
1923
1924
		global $wpdb;
1925
		$current_network_main_site = is_multisite() ? get_current_site() : null;
1926
		$current_main_site_id = ! empty( $current_network_main_site ) ? $current_network_main_site->blog_id : 1;
1927
		$option = 'ee_ueip_optin';
1928
1929
		//set correct table for query
1930
		$table_name = $wpdb->get_blog_prefix( $current_main_site_id ) . 'options';
1931
1932
1933
		//rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1934
		//get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1935
		//re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1936
		//this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1937
		//for the purpose of caching.
1938
		$pre = apply_filters( 'pre_option_' . $option, false, $option );
1939
		if ( false !== $pre ) {
1940
			EE_Core_Config::$ee_ueip_option = $pre;
1941
			return EE_Core_Config::$ee_ueip_option;
1942
		}
1943
1944
		$row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", $option ) );
1945
		if ( is_object( $row ) ) {
1946
			$value = $row->option_value;
1947
		} else { //option does not exist so use default.
1948
			return apply_filters( 'default_option_' . $option, false, $option );
1949
		}
1950
1951
		EE_Core_Config::$ee_ueip_option = apply_filters( 'option_' . $option, maybe_unserialize( $value ), $option );
1952
		return EE_Core_Config::$ee_ueip_option;
1953
	}
1954
1955
1956
1957
	/**
1958
	 * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1959
	 * on the object.
1960
	 *
1961
	 * @return array
1962
	 */
1963
	public function __sleep() {
1964
		//reset all url properties
1965
		$this->_reset_urls();
1966
		//return what to save to db
1967
		return array_keys( get_object_vars( $this ) );
1968
	}
1969
1970
}
1971
1972
1973
1974
/**
1975
 * Config class for storing info on the Organization
1976
 */
1977
class EE_Organization_Config extends EE_Config_Base {
1978
1979
	/**
1980
	 * @var string $name
1981
	 * eg EE4.1
1982
	 */
1983
	public $name;
1984
1985
	/**
1986
	 * @var string $address_1
1987
	 * eg 123 Onna Road
1988
	 */
1989
	public $address_1;
1990
1991
	/**
1992
	 * @var string $address_2
1993
	 * eg PO Box 123
1994
	 */
1995
	public $address_2;
1996
1997
	/**
1998
	 * @var string $city
1999
	 * eg Inna City
2000
	 */
2001
	public $city;
2002
2003
	/**
2004
	 * @var int $STA_ID
2005
	 * eg 4
2006
	 */
2007
	public $STA_ID;
2008
2009
	/**
2010
	 * @var string $CNT_ISO
2011
	 * eg US
2012
	 */
2013
	public $CNT_ISO;
2014
2015
	/**
2016
	 * @var string $zip
2017
	 * eg 12345  or V1A 2B3
2018
	 */
2019
	public $zip;
2020
2021
	/**
2022
	 * @var string $email
2023
	 * eg [email protected]
2024
	 */
2025
	public $email;
2026
2027
2028
2029
	/**
2030
	 * @var string $phone
2031
	 * eg. 111-111-1111
2032
	 */
2033
	public $phone;
2034
2035
2036
	/**
2037
	 * @var string $vat
2038
	 * VAT/Tax Number
2039
	 */
2040
	public $vat;
2041
2042
	/**
2043
	 * @var string $logo_url
2044
	 * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
2045
	 */
2046
	public $logo_url;
2047
2048
2049
	/**
2050
	 * The below are all various properties for holding links to organization social network profiles
2051
	 *
2052
	 * @var string
2053
	 */
2054
	/**
2055
	 * facebook (facebook.com/profile.name)
2056
	 *
2057
	 * @var string
2058
	 */
2059
	public $facebook;
2060
2061
2062
	/**
2063
	 * twitter (twitter.com/twitter_handle)
2064
	 *
2065
	 * @var string
2066
	 */
2067
	public $twitter;
2068
2069
2070
2071
	/**
2072
	 * linkedin (linkedin.com/in/profile_name)
2073
	 *
2074
	 * @var string
2075
	 */
2076
	public $linkedin;
2077
2078
2079
2080
	/**
2081
	 * pinterest (www.pinterest.com/profile_name)
2082
	 *
2083
	 * @var string
2084
	 */
2085
	public $pinterest;
2086
2087
2088
2089
	/**
2090
	 * google+ (google.com/+profileName)
2091
	 *
2092
	 * @var string
2093
	 */
2094
	public $google;
2095
2096
2097
2098
	/**
2099
	 * instagram (instagram.com/handle)
2100
	 *
2101
	 * @var string
2102
	 */
2103
	public $instagram;
2104
2105
2106
2107
	/**
2108
	 *    class constructor
2109
	 *
2110
	 * @access    public
2111
	 */
2112
	public function __construct() {
2113
		// set default organization settings
2114
		$this->name = get_bloginfo( 'name' );
2115
		$this->address_1 = '123 Onna Road';
2116
		$this->address_2 = 'PO Box 123';
2117
		$this->city = 'Inna City';
2118
		$this->STA_ID = 4;
2119
		$this->CNT_ISO = 'US';
2120
		$this->zip = '12345';
2121
		$this->email = get_bloginfo( 'admin_email' );
2122
		$this->phone = '';
2123
		$this->vat = '123456789';
2124
		$this->logo_url = '';
2125
		$this->facebook = '';
2126
		$this->twitter = '';
2127
		$this->linkedin = '';
2128
		$this->pinterest = '';
2129
		$this->google = '';
2130
		$this->instagram = '';
2131
	}
2132
2133
}
2134
2135
2136
2137
/**
2138
 * Class for defining what's in the EE_Config relating to currency
2139
 */
2140
class EE_Currency_Config extends EE_Config_Base {
2141
2142
	/**
2143
	 * @var string $code
2144
	 * eg 'US'
2145
	 */
2146
	public $code;
2147
2148
	/**
2149
	 * @var string $name
2150
	 * eg 'Dollar'
2151
	 */
2152
	public $name;
2153
2154
	/**
2155
	 * plural name
2156
	 *
2157
	 * @var string $plural
2158
	 * eg 'Dollars'
2159
	 */
2160
	public $plural;
2161
2162
	/**
2163
	 * currency sign
2164
	 *
2165
	 * @var string $sign
2166
	 * eg '$'
2167
	 */
2168
	public $sign;
2169
2170
	/**
2171
	 * Whether the currency sign should come before the number or not
2172
	 *
2173
	 * @var boolean $sign_b4
2174
	 */
2175
	public $sign_b4;
2176
2177
	/**
2178
	 * How many digits should come after the decimal place
2179
	 *
2180
	 * @var int $dec_plc
2181
	 */
2182
	public $dec_plc;
2183
2184
	/**
2185
	 * Symbol to use for decimal mark
2186
	 *
2187
	 * @var string $dec_mrk
2188
	 * eg '.'
2189
	 */
2190
	public $dec_mrk;
2191
2192
	/**
2193
	 * Symbol to use for thousands
2194
	 *
2195
	 * @var string $thsnds
2196
	 * eg ','
2197
	 */
2198
	public $thsnds;
2199
2200
2201
2202
	/**
2203
	 *    class constructor
2204
	 *
2205
	 * @access    public
2206
	 * @param string $CNT_ISO
2207
	 * @throws \EE_Error
2208
	 */
2209
	public function __construct( $CNT_ISO = '' ) {
2210
		/** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2211
		$table_analysis = EE_Registry::instance()->create( 'TableAnalysis', array(), true );
2212
		// get country code from organization settings or use default
2213
		$ORG_CNT = isset( EE_Registry::instance()->CFG->organization )
2214
		           && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2215
			? EE_Registry::instance()->CFG->organization->CNT_ISO
2216
			: '';
2217
		// but override if requested
2218
		$CNT_ISO = ! empty( $CNT_ISO ) ? $CNT_ISO : $ORG_CNT;
2219
		// 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
2220
		if (
2221
			! empty( $CNT_ISO )
2222
			&& EE_Maintenance_Mode::instance()->models_can_query()
2223
			&& $table_analysis->tableExists( EE_Registry::instance()->load_model( 'Country' )->table() )
2224
		) {
2225
			// retrieve the country settings from the db, just in case they have been customized
2226
			$country = EE_Registry::instance()->load_model( 'Country' )->get_one_by_ID( $CNT_ISO );
2227
			if ( $country instanceof EE_Country ) {
2228
				$this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2229
				$this->name = $country->currency_name_single();    // Dollar
2230
				$this->plural = $country->currency_name_plural();    // Dollars
2231
				$this->sign = $country->currency_sign();            // currency sign: $
2232
				$this->sign_b4 = $country->currency_sign_before();        // currency sign before or after: $TRUE  or  FALSE$
2233
				$this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2234
				$this->dec_mrk = $country->currency_decimal_mark();    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2235
				$this->thsnds = $country->currency_thousands_separator();    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2236
			}
2237
		}
2238
		// fallback to hardcoded defaults, in case the above failed
2239
		if ( empty( $this->code ) ) {
2240
			// set default currency settings
2241
			$this->code = 'USD';    // currency code: USD, CAD, EUR
2242
			$this->name = __( 'Dollar', 'event_espresso' );    // Dollar
2243
			$this->plural = __( 'Dollars', 'event_espresso' );    // Dollars
2244
			$this->sign = '$';    // currency sign: $
2245
			$this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2246
			$this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2247
			$this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2248
			$this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2249
		}
2250
	}
2251
}
2252
2253
2254
2255
/**
2256
 * Class for defining what's in the EE_Config relating to registration settings
2257
 */
2258
class EE_Registration_Config extends EE_Config_Base {
2259
2260
	/**
2261
	 * Default registration status
2262
	 *
2263
	 * @var string $default_STS_ID
2264
	 * eg 'RPP'
2265
	 */
2266
	public $default_STS_ID;
2267
2268
	/**
2269
	 * level of validation to apply to email addresses
2270
	 *
2271
	 * @var string $email_validation_level
2272
	 * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2273
	 */
2274
	public $email_validation_level;
2275
2276
	/**
2277
	 *    whether or not to show alternate payment options during the reg process if payment status is pending
2278
	 *
2279
	 * @var boolean $show_pending_payment_options
2280
	 */
2281
	public $show_pending_payment_options;
2282
2283
	/**
2284
	 * Whether to skip the registration confirmation page
2285
	 *
2286
	 * @var boolean $skip_reg_confirmation
2287
	 */
2288
	public $skip_reg_confirmation;
2289
2290
	/**
2291
	 * an array of SPCO reg steps where:
2292
	 *        the keys denotes the reg step order
2293
	 *        each element consists of an array with the following elements:
2294
	 *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2295
	 *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2296
	 *            "slug" => the URL param used to trigger the reg step
2297
	 *
2298
	 * @var array $reg_steps
2299
	 */
2300
	public $reg_steps;
2301
2302
	/**
2303
	 * Whether registration confirmation should be the last page of SPCO
2304
	 *
2305
	 * @var boolean $reg_confirmation_last
2306
	 */
2307
	public $reg_confirmation_last;
2308
2309
	/**
2310
	 * Whether or not to enable the EE Bot Trap
2311
	 *
2312
	 * @var boolean $use_bot_trap
2313
	 */
2314
	public $use_bot_trap;
2315
2316
	/**
2317
	 * Whether or not to encrypt some data sent by the EE Bot Trap
2318
	 *
2319
	 * @var boolean $use_encryption
2320
	 */
2321
	public $use_encryption;
2322
2323
	/**
2324
	 * Whether or not to use ReCaptcha
2325
	 *
2326
	 * @var boolean $use_captcha
2327
	 */
2328
	public $use_captcha;
2329
2330
	/**
2331
	 * ReCaptcha Theme
2332
	 *
2333
	 * @var string $recaptcha_theme
2334
	 *    options: 'dark    ', 'light'
2335
	 */
2336
	public $recaptcha_theme;
2337
2338
	/**
2339
	 * ReCaptcha Type
2340
	 *
2341
	 * @var string $recaptcha_type
2342
	 *    options: 'audio', 'image'
2343
	 */
2344
	public $recaptcha_type;
2345
2346
	/**
2347
	 * ReCaptcha language
2348
	 *
2349
	 * @var string $recaptcha_language
2350
	 * eg 'en'
2351
	 */
2352
	public $recaptcha_language;
2353
2354
	/**
2355
	 * ReCaptcha public key
2356
	 *
2357
	 * @var string $recaptcha_publickey
2358
	 */
2359
	public $recaptcha_publickey;
2360
2361
	/**
2362
	 * ReCaptcha private key
2363
	 *
2364
	 * @var string $recaptcha_privatekey
2365
	 */
2366
	public $recaptcha_privatekey;
2367
2368
	/**
2369
	 * ReCaptcha width
2370
	 *
2371
	 * @var int $recaptcha_width
2372
	 * @deprecated
2373
	 */
2374
	public $recaptcha_width;
2375
2376
2377
2378
	/**
2379
	 *    class constructor
2380
	 *
2381
	 * @access    public
2382
	 */
2383
	public function __construct() {
2384
		// set default registration settings
2385
		$this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2386
		$this->email_validation_level = 'wp_default';
2387
		$this->show_pending_payment_options = true;
2388
		$this->skip_reg_confirmation = false;
2389
		$this->reg_steps = array();
2390
		$this->reg_confirmation_last = false;
2391
		$this->use_bot_trap = true;
2392
		$this->use_encryption = true;
2393
		$this->use_captcha = false;
2394
		$this->recaptcha_theme = 'light';
2395
		$this->recaptcha_type = 'image';
2396
		$this->recaptcha_language = 'en';
2397
		$this->recaptcha_publickey = null;
2398
		$this->recaptcha_privatekey = null;
2399
		$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...
2400
	}
2401
2402
2403
2404
	/**
2405
	 * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2406
	 *
2407
	 * @since 4.8.8.rc.019
2408
	 */
2409
	public function do_hooks() {
2410
		add_action( 'AHEE__EE_Config___load_core_config__end', array( $this, 'set_default_reg_status_on_EEM_Event' ) );
2411
	}
2412
2413
2414
2415
	/**
2416
	 * @return void
2417
	 */
2418
	public function set_default_reg_status_on_EEM_Event() {
2419
		EEM_Event::set_default_reg_status( $this->default_STS_ID );
2420
	}
2421
2422
2423
2424
}
2425
2426
2427
2428
/**
2429
 * Class for defining what's in the EE_Config relating to admin settings
2430
 */
2431
class EE_Admin_Config extends EE_Config_Base {
2432
2433
	/**
2434
	 * @var boolean $use_personnel_manager
2435
	 */
2436
	public $use_personnel_manager;
2437
2438
	/**
2439
	 * @var boolean $use_dashboard_widget
2440
	 */
2441
	public $use_dashboard_widget;
2442
2443
	/**
2444
	 * @var int $events_in_dashboard
2445
	 */
2446
	public $events_in_dashboard;
2447
2448
	/**
2449
	 * @var boolean $use_event_timezones
2450
	 */
2451
	public $use_event_timezones;
2452
2453
	/**
2454
	 * @var boolean $use_full_logging
2455
	 */
2456
	public $use_full_logging;
2457
2458
	/**
2459
	 * @var string $log_file_name
2460
	 */
2461
	public $log_file_name;
2462
2463
	/**
2464
	 * @var string $debug_file_name
2465
	 */
2466
	public $debug_file_name;
2467
2468
	/**
2469
	 * @var boolean $use_remote_logging
2470
	 */
2471
	public $use_remote_logging;
2472
2473
	/**
2474
	 * @var string $remote_logging_url
2475
	 */
2476
	public $remote_logging_url;
2477
2478
	/**
2479
	 * @var boolean $show_reg_footer
2480
	 */
2481
	public $show_reg_footer;
2482
2483
	/**
2484
	 * @var string $affiliate_id
2485
	 */
2486
	public $affiliate_id;
2487
2488
2489
	/**
2490
	 * help tours on or off (global setting)
2491
	 *
2492
	 * @var boolean
2493
	 */
2494
	public $help_tour_activation;
2495
2496
2497
2498
	/**
2499
	 *    class constructor
2500
	 *
2501
	 * @access    public
2502
	 */
2503
	public function __construct() {
2504
		// set default general admin settings
2505
		$this->use_personnel_manager = true;
2506
		$this->use_dashboard_widget = true;
2507
		$this->events_in_dashboard = 30;
2508
		$this->use_event_timezones = false;
2509
		$this->use_full_logging = false;
2510
		$this->use_remote_logging = false;
2511
		$this->remote_logging_url = null;
2512
		$this->show_reg_footer = true;
2513
		$this->affiliate_id = 'default';
2514
		$this->help_tour_activation = true;
2515
	}
2516
2517
2518
2519
	/**
2520
	 * @param bool $reset
2521
	 * @return string
2522
	 */
2523 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...
2524
		if ( empty( $this->log_file_name ) || $reset ) {
2525
			$this->log_file_name = sanitize_key( 'espresso_log_' . md5( uniqid( '', true ) ) ) . '.txt';
2526
			EE_Config::instance()->update_espresso_config( false, false );
2527
		}
2528
		return $this->log_file_name;
2529
	}
2530
2531
2532
2533
	/**
2534
	 * @param bool $reset
2535
	 * @return string
2536
	 */
2537 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...
2538
		if ( empty( $this->debug_file_name ) || $reset ) {
2539
			$this->debug_file_name = sanitize_key( 'espresso_debug_' . md5( uniqid( '', true ) ) ) . '.txt';
2540
			EE_Config::instance()->update_espresso_config( false, false );
2541
		}
2542
		return $this->debug_file_name;
2543
	}
2544
2545
2546
2547
	/**
2548
	 * @return string
2549
	 */
2550
	public function affiliate_id() {
2551
		return ! empty( $this->affiliate_id ) ? $this->affiliate_id : 'default';
2552
	}
2553
2554
2555
2556
}
2557
2558
2559
2560
/**
2561
 * Class for defining what's in the EE_Config relating to template settings
2562
 */
2563
class EE_Template_Config extends EE_Config_Base {
2564
2565
	/**
2566
	 * @var boolean $enable_default_style
2567
	 */
2568
	public $enable_default_style;
2569
2570
	/**
2571
	 * @var string $custom_style_sheet
2572
	 */
2573
	public $custom_style_sheet;
2574
2575
	/**
2576
	 * @var boolean $display_address_in_regform
2577
	 */
2578
	public $display_address_in_regform;
2579
2580
	/**
2581
	 * @var int $display_description_on_multi_reg_page
2582
	 */
2583
	public $display_description_on_multi_reg_page;
2584
2585
	/**
2586
	 * @var boolean $use_custom_templates
2587
	 */
2588
	public $use_custom_templates;
2589
2590
	/**
2591
	 * @var string $current_espresso_theme
2592
	 */
2593
	public $current_espresso_theme;
2594
2595
	/**
2596
	 * @var EE_Event_Single_Config $EED_Event_Single
2597
	 */
2598
	public $EED_Event_Single;
2599
2600
	/**
2601
	 * @var EE_Events_Archive_Config $EED_Events_Archive
2602
	 */
2603
	public $EED_Events_Archive;
2604
2605
	/**
2606
	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2607
	 */
2608
	public $EED_Ticket_Selector;
2609
2610
2611
2612
	/**
2613
	 *    class constructor
2614
	 *
2615
	 * @access    public
2616
	 */
2617
	public function __construct() {
2618
		// set default template settings
2619
		$this->enable_default_style = true;
2620
		$this->custom_style_sheet = null;
2621
		$this->display_address_in_regform = true;
2622
		$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...
2623
		$this->use_custom_templates = false;
2624
		$this->current_espresso_theme = 'Espresso_Arabica_2014';
2625
		$this->EED_Event_Single = null;
2626
		$this->EED_Events_Archive = null;
2627
		$this->EED_Ticket_Selector = null;
2628
	}
2629
2630
}
2631
2632
2633
2634
/**
2635
 * Class for defining what's in the EE_Config relating to map settings
2636
 */
2637
class EE_Map_Config extends EE_Config_Base {
2638
2639
	/**
2640
	 * @var boolean $use_google_maps
2641
	 */
2642
	public $use_google_maps;
2643
2644
	/**
2645
	 * @var string $api_key
2646
	 */
2647
	public $google_map_api_key;
2648
2649
	/**
2650
	 * @var int $event_details_map_width
2651
	 */
2652
	public $event_details_map_width;
2653
2654
	/**
2655
	 * @var int $event_details_map_height
2656
	 */
2657
	public $event_details_map_height;
2658
2659
	/**
2660
	 * @var int $event_details_map_zoom
2661
	 */
2662
	public $event_details_map_zoom;
2663
2664
	/**
2665
	 * @var boolean $event_details_display_nav
2666
	 */
2667
	public $event_details_display_nav;
2668
2669
	/**
2670
	 * @var boolean $event_details_nav_size
2671
	 */
2672
	public $event_details_nav_size;
2673
2674
	/**
2675
	 * @var string $event_details_control_type
2676
	 */
2677
	public $event_details_control_type;
2678
2679
	/**
2680
	 * @var string $event_details_map_align
2681
	 */
2682
	public $event_details_map_align;
2683
2684
	/**
2685
	 * @var int $event_list_map_width
2686
	 */
2687
	public $event_list_map_width;
2688
2689
	/**
2690
	 * @var int $event_list_map_height
2691
	 */
2692
	public $event_list_map_height;
2693
2694
	/**
2695
	 * @var int $event_list_map_zoom
2696
	 */
2697
	public $event_list_map_zoom;
2698
2699
	/**
2700
	 * @var boolean $event_list_display_nav
2701
	 */
2702
	public $event_list_display_nav;
2703
2704
	/**
2705
	 * @var boolean $event_list_nav_size
2706
	 */
2707
	public $event_list_nav_size;
2708
2709
	/**
2710
	 * @var string $event_list_control_type
2711
	 */
2712
	public $event_list_control_type;
2713
2714
	/**
2715
	 * @var string $event_list_map_align
2716
	 */
2717
	public $event_list_map_align;
2718
2719
2720
2721
	/**
2722
	 *    class constructor
2723
	 *
2724
	 * @access    public
2725
	 */
2726
	public function __construct() {
2727
		// set default map settings
2728
		$this->use_google_maps = true;
2729
		$this->google_map_api_key = '';
2730
		// for event details pages (reg page)
2731
		$this->event_details_map_width = 585;            // ee_map_width_single
2732
		$this->event_details_map_height = 362;            // ee_map_height_single
2733
		$this->event_details_map_zoom = 14;            // ee_map_zoom_single
2734
		$this->event_details_display_nav = true;            // ee_map_nav_display_single
2735
		$this->event_details_nav_size = false;            // ee_map_nav_size_single
2736
		$this->event_details_control_type = 'default';        // ee_map_type_control_single
2737
		$this->event_details_map_align = 'center';            // ee_map_align_single
2738
		// for event list pages
2739
		$this->event_list_map_width = 300;            // ee_map_width
2740
		$this->event_list_map_height = 185;        // ee_map_height
2741
		$this->event_list_map_zoom = 12;            // ee_map_zoom
2742
		$this->event_list_display_nav = false;        // ee_map_nav_display
2743
		$this->event_list_nav_size = true;            // ee_map_nav_size
2744
		$this->event_list_control_type = 'dropdown';        // ee_map_type_control
2745
		$this->event_list_map_align = 'center';            // ee_map_align
2746
	}
2747
2748
}
2749
2750
2751
2752
/**
2753
 * stores Events_Archive settings
2754
 */
2755
class EE_Events_Archive_Config extends EE_Config_Base {
2756
2757
	public $display_status_banner;
2758
2759
	public $display_description;
2760
2761
	public $display_ticket_selector;
2762
2763
	public $display_datetimes;
2764
2765
	public $display_venue;
2766
2767
	public $display_expired_events;
2768
2769
	public $use_sortable_display_order;
2770
2771
	public $display_order_tickets;
2772
2773
	public $display_order_datetimes;
2774
2775
	public $display_order_event;
2776
2777
	public $display_order_venue;
2778
2779
2780
2781
	/**
2782
	 *    class constructor
2783
	 */
2784
	public function __construct() {
2785
		$this->display_status_banner = 0;
2786
		$this->display_description = 1;
2787
		$this->display_ticket_selector = 0;
2788
		$this->display_datetimes = 1;
2789
		$this->display_venue = 0;
2790
		$this->display_expired_events = 0;
2791
		$this->use_sortable_display_order = false;
2792
		$this->display_order_tickets = 100;
2793
		$this->display_order_datetimes = 110;
2794
		$this->display_order_event = 120;
2795
		$this->display_order_venue = 130;
2796
	}
2797
}
2798
2799
2800
2801
/**
2802
 * Stores Event_Single_Config settings
2803
 */
2804
class EE_Event_Single_Config extends EE_Config_Base {
2805
2806
	public $display_status_banner_single;
2807
2808
	public $display_venue;
2809
2810
	public $use_sortable_display_order;
2811
2812
	public $display_order_tickets;
2813
2814
	public $display_order_datetimes;
2815
2816
	public $display_order_event;
2817
2818
	public $display_order_venue;
2819
2820
2821
2822
	/**
2823
	 *    class constructor
2824
	 */
2825
	public function __construct() {
2826
		$this->display_status_banner_single = 0;
2827
		$this->display_venue = 1;
2828
		$this->use_sortable_display_order = false;
2829
		$this->display_order_tickets = 100;
2830
		$this->display_order_datetimes = 110;
2831
		$this->display_order_event = 120;
2832
		$this->display_order_venue = 130;
2833
	}
2834
}
2835
2836
2837
2838
/**
2839
 * Stores Ticket_Selector_Config settings
2840
 */
2841
class EE_Ticket_Selector_Config extends EE_Config_Base {
2842
2843
	/*
2844
	 * @var boolean $show_ticket_sale_columns
2845
	 */
2846
	public $show_ticket_sale_columns;
2847
2848
	/*
2849
	 * @var boolean $show_ticket_details
2850
	 */
2851
	public $show_ticket_details;
2852
2853
	/*
2854
	 * @var boolean $show_expired_tickets
2855
	 */
2856
	public $show_expired_tickets;
2857
2858
2859
2860
	/**
2861
	 *    class constructor
2862
	 */
2863
	public function __construct() {
2864
		$this->show_ticket_sale_columns = true;
2865
		$this->show_ticket_details = true;
2866
		$this->show_expired_tickets = true;
2867
	}
2868
}
2869
2870
2871
2872
/**
2873
 * Stores any EE Environment values that are referenced through the code.
2874
 *
2875
 * @since       4.4.0
2876
 * @package     Event Espresso
2877
 * @subpackage  config
2878
 */
2879
class EE_Environment_Config extends EE_Config_Base {
2880
2881
	/**
2882
	 * Hold any php environment variables that we want to track.
2883
	 *
2884
	 * @var stdClass;
2885
	 */
2886
	public $php;
2887
2888
2889
2890
	/**
2891
	 *    constructor
2892
	 */
2893
	public function __construct() {
2894
		$this->php = new stdClass();
2895
		$this->_set_php_values();
2896
	}
2897
2898
2899
2900
	/**
2901
	 * This sets the php environment variables.
2902
	 *
2903
	 * @since 4.4.0
2904
	 * @return void
2905
	 */
2906
	protected function _set_php_values() {
2907
		$this->php->max_input_vars = ini_get( 'max_input_vars' );
2908
		$this->php->version = phpversion();
2909
	}
2910
2911
2912
2913
	/**
2914
	 * helper method for determining whether input_count is
2915
	 * reaching the potential maximum the server can handle
2916
	 * according to max_input_vars
2917
	 *
2918
	 * @param int   $input_count the count of input vars.
2919
	 * @return array {
2920
	 *                           An array that represents whether available space and if no available space the error
2921
	 *                           message.
2922
	 * @type bool   $has_space   whether more inputs can be added.
2923
	 * @type string $msg         Any message to be displayed.
2924
	 *                           }
2925
	 */
2926
	public function max_input_vars_limit_check( $input_count = 0 ) {
2927
		if ( ! empty( $this->php->max_input_vars )
2928
		     && ( $input_count >= $this->php->max_input_vars )
2929
		     && ( PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9 )
2930
		) {
2931
			return sprintf(
2932
				__(
2933
					'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.',
2934
					'event_espresso'
2935
				),
2936
				'<br>',
2937
				$input_count,
2938
				$this->php->max_input_vars
2939
			);
2940
		} else {
2941
			return '';
2942
		}
2943
	}
2944
2945
2946
2947
	/**
2948
	 * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
2949
	 *
2950
	 * @since 4.4.1
2951
	 * @return void
2952
	 */
2953
	public function recheck_values() {
2954
		$this->_set_php_values();
2955
	}
2956
2957
2958
2959
}
2960
2961
2962
2963
/**
2964
 * Stores any options pertaining to taxes
2965
 *
2966
 * @since       4.9.13
2967
 * @package     Event Espresso
2968
 * @subpackage  config
2969
 */
2970
class EE_Tax_Config extends EE_Config_Base
2971
{
2972
2973
    /*
2974
     * flag to indicate whether or not to display ticket prices with the taxes included
2975
     *
2976
     * @var boolean $prices_displayed_including_taxes
2977
     */
2978
    public $prices_displayed_including_taxes;
2979
2980
2981
2982
    /**
2983
     *    class constructor
2984
     */
2985
    public function __construct()
2986
    {
2987
        $this->prices_displayed_including_taxes = true;
2988
    }
2989
}
2990
2991
2992
2993
/**
2994
 * stores payment gateway info
2995
 *
2996
 * @deprecated
2997
 */
2998
class EE_Gateway_Config extends EE_Config_Base {
2999
3000
	/**
3001
	 * Array with keys that are payment gateways slugs, and values are arrays
3002
	 * with any config info the gateway wants to store
3003
	 *
3004
	 * @var array
3005
	 */
3006
	public $payment_settings;
3007
3008
	/**
3009
	 * Where keys are gateway slugs, and values are booleans indicating whether or not
3010
	 * the gateway is stored in the uploads directory
3011
	 *
3012
	 * @var array
3013
	 */
3014
	public $active_gateways;
3015
3016
3017
3018
	/**
3019
	 *    class constructor
3020
	 *
3021
	 * @deprecated
3022
	 */
3023
	public function __construct() {
3024
		$this->payment_settings = array();
3025
		$this->active_gateways = array( 'Invoice' => false );
3026
	}
3027
}
3028
3029
// End of file EE_Config.core.php
3030
// Location: /core/EE_Config.core.php
3031