Completed
Branch BUG-10381-asset-loading (5e9d4d)
by
unknown
14:17
created

EE_Config::_verify_config()   F

Complexity

Conditions 12
Paths 2048

Size

Total Lines 59
Code Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 54
nc 2048
nop 0
dl 0
loc 59
rs 3.0929
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php use EventEspresso\core\services\shortcodes\LegacyShortcodesManager;
2
3
if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
    exit('No direct script access allowed');
5
}
6
7
8
9
/**
10
 * EE_Config
11
 *
12
 * @package     Event Espresso
13
 * @subpackage  core/
14
 * @author      Brent Christensen
15
 */
16
final class EE_Config
17
{
18
19
    const OPTION_NAME        = 'ee_config';
20
21
    const LOG_NAME           = 'ee_config_log';
22
23
    const LOG_LENGTH         = 100;
24
25
    const ADDON_OPTION_NAMES = 'ee_config_option_names';
26
27
28
    /**
29
     *    instance of the EE_Config object
30
     *
31
     * @var    EE_Config $_instance
32
     * @access    private
33
     */
34
    private static $_instance;
35
36
    /**
37
     * @var boolean $_logging_enabled
38
     */
39
    private static $_logging_enabled = false;
40
41
    /**
42
     * @var LegacyShortcodesManager $legacy_shortcodes_manager
43
     */
44
    private $legacy_shortcodes_manager;
0 ignored issues
show
Unused Code introduced by
The property $legacy_shortcodes_manager is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

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