Completed
Branch FET-9795-new-interfaces (ea072c)
by
unknown
51:56 queued 35:16
created

EE_Config::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

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