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