Completed
Branch BUG-9951-10331-8793-pue-fixes (40e696)
by
unknown
27:52 queued 13:57
created

EE_Messages_Config   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

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