Completed
Branch FET-8476-powered-by-event-espr... (796ee8)
by
unknown
142:56 queued 125:38
created

EE_Admin_Config::affiliate_id()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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