Completed
Branch BUG/11288/fix-datepicker (04df7b)
by
unknown
65:36 queued 52:18
created

EE_Currency_Config::__construct()   D

Complexity

Conditions 9
Paths 48

Size

Total Lines 43
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

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