Completed
Branch BUG/duplicate-event-categories (17a1da)
by
unknown
32:32 queued 17:08
created

gatewayLogLifespanOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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