Completed
Branch FET-10586-integer-input (ef3884)
by
unknown
14:05
created
help_tours/Registration_Form_Questions_Overview_Help_Tour.class.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (!defined('EVENT_ESPRESSO_VERSION') )
2
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
3 3
 	exit('NO direct script access allowed');
4 4
 
5 5
 /**
@@ -116,42 +116,42 @@  discard block
 block discarded – undo
116 116
 
117 117
 
118 118
 	protected function _start() {
119
-		$content = '<h3>' . __('Questions Overview', 'event_espresso') . '</h3>';
120
-		$content .= '<p>' . __('This tour of the Questions Overview page will go over different areas of the screen to help you understand what they are used for.', 'event_espresso') . '</p>';
119
+		$content = '<h3>'.__('Questions Overview', 'event_espresso').'</h3>';
120
+		$content .= '<p>'.__('This tour of the Questions Overview page will go over different areas of the screen to help you understand what they are used for.', 'event_espresso').'</p>';
121 121
 
122 122
 		return $content;
123 123
 	}
124 124
 
125 125
 	protected function _display_text_stop() {
126
-		return '<p>' . __('View available questions.', 'event_espresso') . '</p>';
126
+		return '<p>'.__('View available questions.', 'event_espresso').'</p>';
127 127
 	}
128 128
 
129 129
 	protected function _admin_label_stop() {
130
-		return '<p>' . __('View the admin label for your questions.', 'event_espresso') . '</p>';
130
+		return '<p>'.__('View the admin label for your questions.', 'event_espresso').'</p>';
131 131
 	}
132 132
 
133 133
 	protected function _type_stop() {
134
-		return '<p>' . __('View the type of question. Available options are Text, Textarea, Checkboxes, Radio Buttons, Dropdown, State/Province Dropdown, Country Dropdown, and Date Picker.', 'event_espresso') . '</p>';
134
+		return '<p>'.__('View the type of question. Available options are Text, Textarea, Checkboxes, Radio Buttons, Dropdown, State/Province Dropdown, Country Dropdown, and Date Picker.', 'event_espresso').'</p>';
135 135
 	}
136 136
 
137 137
 	protected function _values_stop() {
138
-		return '<p>' . __('View stored values for checkboxes, radio buttons, and select boxes.', 'event_espresso') . '</p>';
138
+		return '<p>'.__('View stored values for checkboxes, radio buttons, and select boxes.', 'event_espresso').'</p>';
139 139
 	}
140 140
 
141 141
 	protected function _required_stop() {
142
-		return '<p>' . __('View if a question is required.', 'event_espresso') . '</p>';
142
+		return '<p>'.__('View if a question is required.', 'event_espresso').'</p>';
143 143
 	}
144 144
 
145 145
 	protected function _bulk_actions_stop() {
146
-		return '<p>' . __('Perform bulk actions to multiple questions.', 'event_espresso') . '</p>';
146
+		return '<p>'.__('Perform bulk actions to multiple questions.', 'event_espresso').'</p>';
147 147
 	}
148 148
 
149 149
 	protected function _search_stop() {
150
-		return '<p>' . __('Search through questions. The following sources will be searched: Name of Question (display text).', 'event_espresso') . '</p>';
150
+		return '<p>'.__('Search through questions. The following sources will be searched: Name of Question (display text).', 'event_espresso').'</p>';
151 151
 	}
152 152
 
153 153
 	protected function _add_new_question_stop() {
154
-		return '<p>' . __('Click here to add a new question.', 'event_espresso') . '</p>';
154
+		return '<p>'.__('Click here to add a new question.', 'event_espresso').'</p>';
155 155
 	}
156 156
 
157 157
 }
158 158
\ No newline at end of file
Please login to merge, or discard this patch.
help_tours/Registration_Form_Questions_Overview_Help_Tour.class.php 2 patches
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 /**
@@ -18,64 +18,64 @@  discard block
 block discarded – undo
18 18
 class Registration_Form_Questions_Overview_Help_Tour extends EE_Help_Tour
19 19
 {
20 20
     
21
-    protected function _set_tour_properties()
22
-    {
23
-        $this->_label = __('Questions Overview Tour', 'event_espresso');
24
-        $this->_slug  = $this->_is_caf ? 'questions-overview-caf-joyride' : 'questions-overview-joyride';
25
-    }
21
+	protected function _set_tour_properties()
22
+	{
23
+		$this->_label = __('Questions Overview Tour', 'event_espresso');
24
+		$this->_slug  = $this->_is_caf ? 'questions-overview-caf-joyride' : 'questions-overview-joyride';
25
+	}
26 26
     
27
-    protected function _set_tour_stops()
28
-    {
29
-        $this->_stops = array(
30
-            10  => array(
31
-                'content' => $this->_start(),
32
-            ),
33
-            30  => array(
34
-                'id'      => 'display_text',
35
-                'content' => $this->_display_text_stop(),
36
-                'options' => array(
37
-                    'tipLocation'    => 'top',
38
-                    'tipAdjustmentX' => -5,
39
-                    'tipAdjustmentY' => -25
40
-                )
41
-            ),
42
-            40  => array(
43
-                'id'      => 'admin_label',
44
-                'content' => $this->_admin_label_stop(),
45
-                'options' => array(
46
-                    'tipLocation'    => 'top',
47
-                    'tipAdjustmentX' => 20,
48
-                    'tipAdjustmentY' => -25
49
-                )
50
-            ),
51
-            50  => array(
52
-                'id'      => 'type',
53
-                'content' => $this->_type_stop(),
54
-                'options' => array(
55
-                    'tipLocation'    => 'top',
56
-                    'tipAdjustmentX' => -5,
57
-                    'tipAdjustmentY' => -25
58
-                )
59
-            ),
60
-            60  => array(
61
-                'id'      => 'values',
62
-                'content' => $this->_values_stop(),
63
-                'options' => array(
64
-                    'tipLocation'    => 'top',
65
-                    'tipAdjustmentX' => -5,
66
-                    'tipAdjustmentY' => -25
67
-                )
68
-            ),
69
-            70  => array(
70
-                'id'      => 'required',
71
-                'content' => $this->_required_stop(),
72
-                'options' => array(
73
-                    'tipLocation'    => 'top',
74
-                    'tipAdjustmentY' => -20,
75
-                    'tipAdjustmentX' => -15
76
-                )
77
-            ),
78
-            /*80 => array(
27
+	protected function _set_tour_stops()
28
+	{
29
+		$this->_stops = array(
30
+			10  => array(
31
+				'content' => $this->_start(),
32
+			),
33
+			30  => array(
34
+				'id'      => 'display_text',
35
+				'content' => $this->_display_text_stop(),
36
+				'options' => array(
37
+					'tipLocation'    => 'top',
38
+					'tipAdjustmentX' => -5,
39
+					'tipAdjustmentY' => -25
40
+				)
41
+			),
42
+			40  => array(
43
+				'id'      => 'admin_label',
44
+				'content' => $this->_admin_label_stop(),
45
+				'options' => array(
46
+					'tipLocation'    => 'top',
47
+					'tipAdjustmentX' => 20,
48
+					'tipAdjustmentY' => -25
49
+				)
50
+			),
51
+			50  => array(
52
+				'id'      => 'type',
53
+				'content' => $this->_type_stop(),
54
+				'options' => array(
55
+					'tipLocation'    => 'top',
56
+					'tipAdjustmentX' => -5,
57
+					'tipAdjustmentY' => -25
58
+				)
59
+			),
60
+			60  => array(
61
+				'id'      => 'values',
62
+				'content' => $this->_values_stop(),
63
+				'options' => array(
64
+					'tipLocation'    => 'top',
65
+					'tipAdjustmentX' => -5,
66
+					'tipAdjustmentY' => -25
67
+				)
68
+			),
69
+			70  => array(
70
+				'id'      => 'required',
71
+				'content' => $this->_required_stop(),
72
+				'options' => array(
73
+					'tipLocation'    => 'top',
74
+					'tipAdjustmentY' => -20,
75
+					'tipAdjustmentX' => -15
76
+				)
77
+			),
78
+			/*80 => array(
79 79
                 'class' => 'bulkactions',
80 80
                 'content' => $this->_bulk_actions_stop(),
81 81
                 'options' => array(
@@ -84,77 +84,77 @@  discard block
 block discarded – undo
84 84
                     'tipAdjustmentX' => -15
85 85
                     )
86 86
                 ),*/
87
-            90  => array(
88
-                'id'      => 'event-espresso_page_espresso_registration_form-search-input',
89
-                'content' => $this->_search_stop(),
90
-                'options' => array(
91
-                    'tipLocation'    => 'left',
92
-                    'tipAdjustmentY' => -50,
93
-                    'tipAdjustmentX' => -15
94
-                )
95
-            ),
96
-            100 => array(
97
-                'id'      => 'add-new-question',
98
-                'content' => $this->_add_new_question_stop(),
99
-                'options' => array(
100
-                    'tipLocation'    => 'right',
101
-                    'tipAdjustmentY' => -50,
102
-                    'tipAdjustmentX' => 15
103
-                )
104
-            ),
105
-        );
106
-    }
87
+			90  => array(
88
+				'id'      => 'event-espresso_page_espresso_registration_form-search-input',
89
+				'content' => $this->_search_stop(),
90
+				'options' => array(
91
+					'tipLocation'    => 'left',
92
+					'tipAdjustmentY' => -50,
93
+					'tipAdjustmentX' => -15
94
+				)
95
+			),
96
+			100 => array(
97
+				'id'      => 'add-new-question',
98
+				'content' => $this->_add_new_question_stop(),
99
+				'options' => array(
100
+					'tipLocation'    => 'right',
101
+					'tipAdjustmentY' => -50,
102
+					'tipAdjustmentX' => 15
103
+				)
104
+			),
105
+		);
106
+	}
107 107
     
108 108
     
109
-    protected function _start()
110
-    {
111
-        $content = '<h3>' . __('Questions Overview', 'event_espresso') . '</h3>';
112
-        $content .= '<p>' . __('This tour of the Questions Overview page will go over different areas of the screen to help you understand what they are used for.',
113
-                'event_espresso') . '</p>';
109
+	protected function _start()
110
+	{
111
+		$content = '<h3>' . __('Questions Overview', 'event_espresso') . '</h3>';
112
+		$content .= '<p>' . __('This tour of the Questions Overview page will go over different areas of the screen to help you understand what they are used for.',
113
+				'event_espresso') . '</p>';
114 114
         
115
-        return $content;
116
-    }
115
+		return $content;
116
+	}
117 117
     
118
-    protected function _display_text_stop()
119
-    {
120
-        return '<p>' . __('View available questions.', 'event_espresso') . '</p>';
121
-    }
118
+	protected function _display_text_stop()
119
+	{
120
+		return '<p>' . __('View available questions.', 'event_espresso') . '</p>';
121
+	}
122 122
     
123
-    protected function _admin_label_stop()
124
-    {
125
-        return '<p>' . __('View the admin label for your questions.', 'event_espresso') . '</p>';
126
-    }
123
+	protected function _admin_label_stop()
124
+	{
125
+		return '<p>' . __('View the admin label for your questions.', 'event_espresso') . '</p>';
126
+	}
127 127
     
128
-    protected function _type_stop()
129
-    {
130
-        return '<p>' . __('View the type of question. Available options are Text, Textarea, Checkboxes, Radio Buttons, Dropdown, State/Province Dropdown, Country Dropdown, and Date Picker.',
131
-            'event_espresso') . '</p>';
132
-    }
128
+	protected function _type_stop()
129
+	{
130
+		return '<p>' . __('View the type of question. Available options are Text, Textarea, Checkboxes, Radio Buttons, Dropdown, State/Province Dropdown, Country Dropdown, and Date Picker.',
131
+			'event_espresso') . '</p>';
132
+	}
133 133
     
134
-    protected function _values_stop()
135
-    {
136
-        return '<p>' . __('View stored values for checkboxes, radio buttons, and select boxes.',
137
-            'event_espresso') . '</p>';
138
-    }
134
+	protected function _values_stop()
135
+	{
136
+		return '<p>' . __('View stored values for checkboxes, radio buttons, and select boxes.',
137
+			'event_espresso') . '</p>';
138
+	}
139 139
     
140
-    protected function _required_stop()
141
-    {
142
-        return '<p>' . __('View if a question is required.', 'event_espresso') . '</p>';
143
-    }
140
+	protected function _required_stop()
141
+	{
142
+		return '<p>' . __('View if a question is required.', 'event_espresso') . '</p>';
143
+	}
144 144
     
145
-    /* protected function _bulk_actions_stop() {
145
+	/* protected function _bulk_actions_stop() {
146 146
         return '<p>' . __('Perform bulk actions to multiple questions.', 'event_espresso') . '</p>';
147 147
     } */
148 148
     
149
-    protected function _search_stop()
150
-    {
151
-        return '<p>' . __('Search through questions. The following sources will be searched: Name of Question (display text).',
152
-            'event_espresso') . '</p>';
153
-    }
149
+	protected function _search_stop()
150
+	{
151
+		return '<p>' . __('Search through questions. The following sources will be searched: Name of Question (display text).',
152
+			'event_espresso') . '</p>';
153
+	}
154 154
     
155
-    protected function _add_new_question_stop()
156
-    {
157
-        return '<p>' . __('Click here to add a new question.', 'event_espresso') . '</p>';
158
-    }
155
+	protected function _add_new_question_stop()
156
+	{
157
+		return '<p>' . __('Click here to add a new question.', 'event_espresso') . '</p>';
158
+	}
159 159
     
160 160
 }
161 161
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -108,38 +108,38 @@  discard block
 block discarded – undo
108 108
     
109 109
     protected function _start()
110 110
     {
111
-        $content = '<h3>' . __('Questions Overview', 'event_espresso') . '</h3>';
112
-        $content .= '<p>' . __('This tour of the Questions Overview page will go over different areas of the screen to help you understand what they are used for.',
113
-                'event_espresso') . '</p>';
111
+        $content = '<h3>'.__('Questions Overview', 'event_espresso').'</h3>';
112
+        $content .= '<p>'.__('This tour of the Questions Overview page will go over different areas of the screen to help you understand what they are used for.',
113
+                'event_espresso').'</p>';
114 114
         
115 115
         return $content;
116 116
     }
117 117
     
118 118
     protected function _display_text_stop()
119 119
     {
120
-        return '<p>' . __('View available questions.', 'event_espresso') . '</p>';
120
+        return '<p>'.__('View available questions.', 'event_espresso').'</p>';
121 121
     }
122 122
     
123 123
     protected function _admin_label_stop()
124 124
     {
125
-        return '<p>' . __('View the admin label for your questions.', 'event_espresso') . '</p>';
125
+        return '<p>'.__('View the admin label for your questions.', 'event_espresso').'</p>';
126 126
     }
127 127
     
128 128
     protected function _type_stop()
129 129
     {
130
-        return '<p>' . __('View the type of question. Available options are Text, Textarea, Checkboxes, Radio Buttons, Dropdown, State/Province Dropdown, Country Dropdown, and Date Picker.',
131
-            'event_espresso') . '</p>';
130
+        return '<p>'.__('View the type of question. Available options are Text, Textarea, Checkboxes, Radio Buttons, Dropdown, State/Province Dropdown, Country Dropdown, and Date Picker.',
131
+            'event_espresso').'</p>';
132 132
     }
133 133
     
134 134
     protected function _values_stop()
135 135
     {
136
-        return '<p>' . __('View stored values for checkboxes, radio buttons, and select boxes.',
137
-            'event_espresso') . '</p>';
136
+        return '<p>'.__('View stored values for checkboxes, radio buttons, and select boxes.',
137
+            'event_espresso').'</p>';
138 138
     }
139 139
     
140 140
     protected function _required_stop()
141 141
     {
142
-        return '<p>' . __('View if a question is required.', 'event_espresso') . '</p>';
142
+        return '<p>'.__('View if a question is required.', 'event_espresso').'</p>';
143 143
     }
144 144
     
145 145
     /* protected function _bulk_actions_stop() {
@@ -148,13 +148,13 @@  discard block
 block discarded – undo
148 148
     
149 149
     protected function _search_stop()
150 150
     {
151
-        return '<p>' . __('Search through questions. The following sources will be searched: Name of Question (display text).',
152
-            'event_espresso') . '</p>';
151
+        return '<p>'.__('Search through questions. The following sources will be searched: Name of Question (display text).',
152
+            'event_espresso').'</p>';
153 153
     }
154 154
     
155 155
     protected function _add_new_question_stop()
156 156
     {
157
-        return '<p>' . __('Click here to add a new question.', 'event_espresso') . '</p>';
157
+        return '<p>'.__('Click here to add a new question.', 'event_espresso').'</p>';
158 158
     }
159 159
     
160 160
 }
161 161
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_models/EEM_Event.model.php 2 patches
Indentation   +745 added lines, -745 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 require_once(EE_MODELS . 'EEM_CPT_Base.model.php');
5 5
 
@@ -16,750 +16,750 @@  discard block
 block discarded – undo
16 16
 class EEM_Event extends EEM_CPT_Base
17 17
 {
18 18
 
19
-    /**
20
-     * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
21
-     * event
22
-     */
23
-    const sold_out = 'sold_out';
24
-
25
-    /**
26
-     * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
27
-     * date)
28
-     */
29
-    const postponed = 'postponed';
30
-
31
-    /**
32
-     * constant used by status(), indicating that the event will no longer occur
33
-     */
34
-    const cancelled = 'cancelled';
35
-
36
-
37
-    /**
38
-     * @var string
39
-     */
40
-    protected static $_default_reg_status;
41
-
42
-
43
-    /**
44
-     * private instance of the Event object
45
-     *
46
-     * @var EEM_Event
47
-     */
48
-    protected static $_instance;
49
-
50
-
51
-
52
-    /**
53
-     *  This function is a singleton method used to instantiate the EEM_Event object
54
-     *
55
-     * @param string $timezone
56
-     * @return EEM_Event
57
-     * @throws \EE_Error
58
-     */
59
-    public static function instance($timezone = null)
60
-    {
61
-        // check if instance of EEM_Event already exists
62
-        if (! self::$_instance instanceof EEM_Event) {
63
-            // instantiate Espresso_model
64
-            self::$_instance = new self($timezone);
65
-        }
66
-        //we might have a timezone set, let set_timezone decide what to do with it
67
-        self::$_instance->set_timezone($timezone);
68
-        // EEM_Event object
69
-        return self::$_instance;
70
-    }
71
-
72
-
73
-
74
-    /**
75
-     * Adds a relationship to Term_Taxonomy for each CPT_Base
76
-     *
77
-     * @param string $timezone
78
-     * @throws \EE_Error
79
-     */
80
-    protected function __construct($timezone = null)
81
-    {
82
-        EE_Registry::instance()->load_model('Registration');
83
-        $this->singular_item = esc_html__('Event', 'event_espresso');
84
-        $this->plural_item = esc_html__('Events', 'event_espresso');
85
-        // to remove Cancelled events from the frontend, copy the following filter to your functions.php file
86
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
87
-        // to remove Postponed events from the frontend, copy the following filter to your functions.php file
88
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
89
-        // to remove Sold Out events from the frontend, copy the following filter to your functions.php file
90
-        //	add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
91
-        $this->_custom_stati = apply_filters(
92
-            'AFEE__EEM_Event__construct___custom_stati',
93
-            array(
94
-                EEM_Event::cancelled => array(
95
-                    'label'  => esc_html__('Cancelled', 'event_espresso'),
96
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
97
-                ),
98
-                EEM_Event::postponed => array(
99
-                    'label'  => esc_html__('Postponed', 'event_espresso'),
100
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
101
-                ),
102
-                EEM_Event::sold_out  => array(
103
-                    'label'  => esc_html__('Sold Out', 'event_espresso'),
104
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
105
-                ),
106
-            )
107
-        );
108
-        self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
109
-            : self::$_default_reg_status;
110
-        $this->_tables = array(
111
-            'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
112
-            'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
113
-        );
114
-        $this->_fields = array(
115
-            'Event_CPT'  => array(
116
-                'EVT_ID'         => new EE_Primary_Key_Int_Field('ID',
117
-                    esc_html__('Post ID for Event', 'event_espresso')),
118
-                'EVT_name'       => new EE_Plain_Text_Field('post_title', esc_html__('Event Name', 'event_espresso'),
119
-                    false,
120
-                    ''),
121
-                'EVT_desc'       => new EE_Post_Content_Field('post_content',
122
-                    esc_html__('Event Description', 'event_espresso'),
123
-                    false, ''),
124
-                'EVT_slug'       => new EE_Slug_Field('post_name', esc_html__('Event Slug', 'event_espresso'), false,
125
-                    ''),
126
-                'EVT_created'    => new EE_Datetime_Field('post_date',
127
-                    esc_html__('Date/Time Event Created', 'event_espresso'),
128
-                    false, EE_Datetime_Field::now),
129
-                'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt',
130
-                    esc_html__('Event Short Description', 'event_espresso'), false, ''),
131
-                'EVT_modified'   => new EE_Datetime_Field('post_modified',
132
-                    esc_html__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now),
133
-                'EVT_wp_user'    => new EE_WP_User_Field('post_author',
134
-                    esc_html__('Event Creator ID', 'event_espresso'),
135
-                    false),
136
-                'parent'         => new EE_Integer_Field('post_parent', esc_html__('Event Parent ID', 'event_espresso'),
137
-                    false,
138
-                    0),
139
-                'EVT_order'      => new EE_Integer_Field('menu_order', esc_html__('Event Menu Order', 'event_espresso'),
140
-                    false,
141
-                    1),
142
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
143
-                // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
144
-                'status'         => new EE_WP_Post_Status_Field('post_status',
145
-                    esc_html__('Event Status', 'event_espresso'),
146
-                    false, 'draft', $this->_custom_stati),
147
-            ),
148
-            'Event_Meta' => array(
149
-                'EVTM_ID'                         => new EE_DB_Only_Float_Field('EVTM_ID',
150
-                    esc_html__('Event Meta Row ID', 'event_espresso'), false),
151
-                'EVT_ID_fk'                       => new EE_DB_Only_Int_Field('EVT_ID',
152
-                    esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false),
153
-                'EVT_display_desc'                => new EE_Boolean_Field('EVT_display_desc',
154
-                    esc_html__('Display Description Flag', 'event_espresso'), false, 1),
155
-                'EVT_display_ticket_selector'     => new EE_Boolean_Field('EVT_display_ticket_selector',
156
-                    esc_html__('Display Ticket Selector Flag', 'event_espresso'), false, 1),
157
-                'EVT_visible_on'                  => new EE_Datetime_Field('EVT_visible_on',
158
-                    esc_html__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now),
159
-                'EVT_additional_limit'            => new EE_Integer_Field('EVT_additional_limit',
160
-                    esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), true, 10),
161
-                'EVT_default_registration_status' => new EE_Enum_Text_Field(
162
-                    'EVT_default_registration_status',
163
-                    esc_html__('Default Registration Status on this Event', 'event_espresso'), false,
164
-                    EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array()
165
-                ),
166
-                'EVT_member_only'                 => new EE_Boolean_Field('EVT_member_only',
167
-                    esc_html__('Member-Only Event Flag', 'event_espresso'), false, false),
168
-                'EVT_phone'                       => new EE_Plain_Text_Field('EVT_phone',
169
-                    esc_html__('Event Phone Number', 'event_espresso'), false),
170
-                'EVT_allow_overflow'              => new EE_Boolean_Field('EVT_allow_overflow',
171
-                    esc_html__('Allow Overflow on Event', 'event_espresso'), false, false),
172
-                'EVT_timezone_string'             => new EE_Plain_Text_Field('EVT_timezone_string',
173
-                    esc_html__('Timezone (name) for Event times', 'event_espresso'), false),
174
-                'EVT_external_URL'                => new EE_Plain_Text_Field('EVT_external_URL',
175
-                    esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true),
176
-                'EVT_donations'                   => new EE_Boolean_Field('EVT_donations',
177
-                    esc_html__('Accept Donations?', 'event_espresso'), false, false),
178
-            ),
179
-        );
180
-        $this->_model_relations = array(
181
-            'Registration'           => new EE_Has_Many_Relation(),
182
-            'Datetime'               => new EE_Has_Many_Relation(),
183
-            'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
184
-            'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
185
-            'Term_Relationship'      => new EE_Has_Many_Relation(),
186
-            'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
187
-            'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
188
-            'Attendee'               => new EE_HABTM_Relation('Registration'),
189
-            'WP_User'                => new EE_Belongs_To_Relation(),
190
-        );
191
-        //this model is generally available for reading
192
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
193
-        parent::__construct($timezone);
194
-    }
195
-
196
-
197
-
198
-    /**
199
-     * @param string $default_reg_status
200
-     */
201
-    public static function set_default_reg_status($default_reg_status)
202
-    {
203
-        self::$_default_reg_status = $default_reg_status;
204
-        // if EEM_Event has already been instantiated,
205
-        // then we need to reset the `EVT_default_reg_status` field to use the new default.
206
-        if (self::$_instance instanceof EEM_Event) {
207
-            $default_reg_status = new EE_Enum_Text_Field(
208
-                'EVT_default_registration_status',
209
-                esc_html__('Default Registration Status on this Event', 'event_espresso'),
210
-                false,
211
-                $default_reg_status,
212
-                EEM_Registration::reg_status_array()
213
-            );
214
-            $default_reg_status->_construct_finalize(
215
-                'Event_Meta',
216
-                'EVT_default_registration_status',
217
-                'EEM_Event'
218
-            );
219
-            self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
220
-        }
221
-    }
222
-
223
-
224
-
225
-    /**
226
-     * get_question_groups
227
-     *
228
-     * @return array
229
-     * @throws \EE_Error
230
-     */
231
-    public function get_all_question_groups()
232
-    {
233
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
234
-            array(
235
-                array('QSG_deleted' => false),
236
-                'order_by' => array('QSG_order' => 'ASC'),
237
-            )
238
-        );
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * get_question_groups
245
-     *
246
-     * @param int $EVT_ID
247
-     * @return array|bool
248
-     * @throws \EE_Error
249
-     */
250
-    public function get_all_event_question_groups($EVT_ID = 0)
251
-    {
252
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
253
-            EE_Error::add_error(
254
-                esc_html__(
255
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
256
-                    'event_espresso'
257
-                ),
258
-                __FILE__, __FUNCTION__, __LINE__
259
-            );
260
-            return false;
261
-        }
262
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
263
-            array(
264
-                array('EVT_ID' => $EVT_ID),
265
-            )
266
-        );
267
-    }
268
-
269
-
270
-
271
-    /**
272
-     * get_question_groups
273
-     *
274
-     * @param int     $EVT_ID
275
-     * @param boolean $for_primary_attendee
276
-     * @return array|bool
277
-     * @throws \EE_Error
278
-     */
279
-    public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
280
-    {
281
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
282
-            EE_Error::add_error(
283
-                esc_html__(
284
-                    'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
285
-                    'event_espresso'
286
-                ),
287
-                __FILE__, __FUNCTION__, __LINE__
288
-            );
289
-            return false;
290
-        }
291
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
292
-            array(
293
-                array(
294
-                    'EVT_ID'      => $EVT_ID,
295
-                    'EQG_primary' => $for_primary_attendee,
296
-                ),
297
-            )
298
-        );
299
-    }
300
-
301
-
302
-
303
-    /**
304
-     * get_question_groups
305
-     *
306
-     * @param int             $EVT_ID
307
-     * @param EE_Registration $registration
308
-     * @return array|bool
309
-     * @throws \EE_Error
310
-     */
311
-    public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
312
-    {
313
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
314
-            EE_Error::add_error(
315
-                esc_html__(
316
-                    'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
317
-                    'event_espresso'
318
-                ),
319
-                __FILE__, __FUNCTION__, __LINE__
320
-            );
321
-            return false;
322
-        }
323
-        $where_params = array(
324
-            'Event_Question_Group.EVT_ID'      => $EVT_ID,
325
-            'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false,
326
-            'QSG_deleted'                      => false,
327
-        );
328
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(
329
-            array(
330
-                $where_params,
331
-                'order_by' => array('QSG_order' => 'ASC'),
332
-            )
333
-        );
334
-    }
335
-
336
-
337
-
338
-    /**
339
-     * get_question_target_db_column
340
-     *
341
-     * @param string $QSG_IDs csv list of $QSG IDs
342
-     * @return array|bool
343
-     * @throws \EE_Error
344
-     */
345
-    public function get_questions_in_groups($QSG_IDs = '')
346
-    {
347
-        if (empty($QSG_IDs)) {
348
-            EE_Error::add_error(
349
-                esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
350
-                __FILE__, __FUNCTION__, __LINE__
351
-            );
352
-            return false;
353
-        }
354
-        return EE_Registry::instance()->load_model('Question')->get_all(
355
-            array(
356
-                array(
357
-                    'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
358
-                    'QST_deleted'           => false,
359
-                    'QST_admin_only'        => is_admin(),
360
-                ),
361
-                'order_by' => 'QST_order',
362
-            )
363
-        );
364
-    }
365
-
366
-
367
-
368
-    /**
369
-     * get_options_for_question
370
-     *
371
-     * @param string $QST_IDs csv list of $QST IDs
372
-     * @return array|bool
373
-     * @throws \EE_Error
374
-     */
375
-    public function get_options_for_question($QST_IDs)
376
-    {
377
-        if (empty($QST_IDs)) {
378
-            EE_Error::add_error(
379
-                esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
380
-                __FILE__, __FUNCTION__, __LINE__
381
-            );
382
-            return false;
383
-        }
384
-        return EE_Registry::instance()->load_model('Question_Option')->get_all(
385
-            array(
386
-                array(
387
-                    'Question.QST_ID' => array('IN', $QST_IDs),
388
-                    'QSO_deleted'     => false,
389
-                ),
390
-                'order_by' => 'QSO_ID',
391
-            )
392
-        );
393
-    }
394
-
395
-
396
-
397
-
398
-
399
-
400
-
401
-    /**
402
-     * Gets all events that are published
403
-     * and have event start time earlier than now and an event end time later than now
404
-     *
405
-     * @param  array $query_params An array of query params to further filter on
406
-     *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
407
-     * @param bool   $count        whether to return the count or not (default FALSE)
408
-     * @return EE_Event[]|int
409
-     * @throws \EE_Error
410
-     */
411
-    public function get_active_events($query_params, $count = false)
412
-    {
413
-        if (array_key_exists(0, $query_params)) {
414
-            $where_params = $query_params[0];
415
-            unset($query_params[0]);
416
-        } else {
417
-            $where_params = array();
418
-        }
419
-        // if we have count make sure we don't include group by
420
-        if ($count && isset($query_params['group_by'])) {
421
-            unset($query_params['group_by']);
422
-        }
423
-        // let's add specific query_params for active_events
424
-        // keep in mind this will override any sent status in the query AND any date queries.
425
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
426
-        //if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
427
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
428
-            $where_params['Datetime.DTT_EVT_start******'] = array(
429
-                '<',
430
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
431
-            );
432
-        } else {
433
-            $where_params['Datetime.DTT_EVT_start'] = array(
434
-                '<',
435
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
436
-            );
437
-        }
438
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
439
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
440
-                '>',
441
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
442
-            );
443
-        } else {
444
-            $where_params['Datetime.DTT_EVT_end'] = array(
445
-                '>',
446
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
447
-            );
448
-        }
449
-        $query_params[0] = $where_params;
450
-        // don't use $query_params with count()
451
-        // because we don't want to include additional query clauses like "GROUP BY"
452
-        return $count
453
-            ? $this->count(array($where_params), 'EVT_ID', true)
454
-            : $this->get_all($query_params);
455
-    }
456
-
457
-
458
-
459
-    /**
460
-     * get all events that are published and have an event start time later than now
461
-     *
462
-     * @param  array $query_params An array of query params to further filter on
463
-     *                             (Note that status and DTT_EVT_start will be overridden)
464
-     * @param bool   $count        whether to return the count or not (default FALSE)
465
-     * @return EE_Event[]|int
466
-     * @throws \EE_Error
467
-     */
468
-    public function get_upcoming_events($query_params, $count = false)
469
-    {
470
-        if (array_key_exists(0, $query_params)) {
471
-            $where_params = $query_params[0];
472
-            unset($query_params[0]);
473
-        } else {
474
-            $where_params = array();
475
-        }
476
-        // if we have count make sure we don't include group by
477
-        if ($count && isset($query_params['group_by'])) {
478
-            unset($query_params['group_by']);
479
-        }
480
-        // let's add specific query_params for active_events
481
-        // keep in mind this will override any sent status in the query AND any date queries.
482
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
483
-        // if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
484
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
485
-            $where_params['Datetime.DTT_EVT_start*****'] = array(
486
-                '>',
487
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
488
-            );
489
-        } else {
490
-            $where_params['Datetime.DTT_EVT_start'] = array(
491
-                '>',
492
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
493
-            );
494
-        }
495
-        $query_params[0] = $where_params;
496
-        // don't use $query_params with count()
497
-        // because we don't want to include additional query clauses like "GROUP BY"
498
-        return $count
499
-            ? $this->count(array($where_params), 'EVT_ID', true)
500
-            : $this->get_all($query_params);
501
-    }
502
-
503
-
504
-
505
-    /**
506
-     * Gets all events that are published
507
-     * and have an event end time later than now
508
-     *
509
-     * @param  array $query_params An array of query params to further filter on
510
-     *                             (note that status and DTT_EVT_end will be overridden)
511
-     * @param bool   $count        whether to return the count or not (default FALSE)
512
-     * @return EE_Event[]|int
513
-     * @throws \EE_Error
514
-     */
515
-    public function get_active_and_upcoming_events($query_params, $count = false)
516
-    {
517
-        if (array_key_exists(0, $query_params)) {
518
-            $where_params = $query_params[0];
519
-            unset($query_params[0]);
520
-        } else {
521
-            $where_params = array();
522
-        }
523
-        // if we have count make sure we don't include group by
524
-        if ($count && isset($query_params['group_by'])) {
525
-            unset($query_params['group_by']);
526
-        }
527
-        // let's add specific query_params for active_events
528
-        // keep in mind this will override any sent status in the query AND any date queries.
529
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
530
-        // add where params for DTT_EVT_end
531
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
532
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
533
-                '>',
534
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
535
-            );
536
-        } else {
537
-            $where_params['Datetime.DTT_EVT_end'] = array(
538
-                '>',
539
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
540
-            );
541
-        }
542
-        $query_params[0] = $where_params;
543
-        // don't use $query_params with count()
544
-        // because we don't want to include additional query clauses like "GROUP BY"
545
-        return $count
546
-            ? $this->count(array($where_params), 'EVT_ID', true)
547
-            : $this->get_all($query_params);
548
-    }
549
-
550
-
551
-
552
-    /**
553
-     * This only returns events that are expired.
554
-     * They may still be published but all their datetimes have expired.
555
-     *
556
-     * @param  array $query_params An array of query params to further filter on
557
-     *                             (note that status and DTT_EVT_end will be overridden)
558
-     * @param bool   $count        whether to return the count or not (default FALSE)
559
-     * @return EE_Event[]|int
560
-     * @throws \EE_Error
561
-     */
562
-    public function get_expired_events($query_params, $count = false)
563
-    {
564
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
565
-        // if we have count make sure we don't include group by
566
-        if ($count && isset($query_params['group_by'])) {
567
-            unset($query_params['group_by']);
568
-        }
569
-        // let's add specific query_params for active_events
570
-        // keep in mind this will override any sent status in the query AND any date queries.
571
-        if (isset($where_params['status'])) {
572
-            unset($where_params['status']);
573
-        }
574
-        $exclude_query = $query_params;
575
-        if (isset($exclude_query[0])) {
576
-            unset($exclude_query[0]);
577
-        }
578
-        $exclude_query[0] = array(
579
-            'Datetime.DTT_EVT_end' => array(
580
-                '>',
581
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
582
-            ),
583
-        );
584
-        // first get all events that have datetimes where its not expired.
585
-        $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
586
-        $event_ids = array_keys($event_ids);
587
-        // if we have any additional query_params, let's add them to the 'AND' condition
588
-        $and_condition = array(
589
-            'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
590
-            'EVT_ID'               => array('NOT IN', $event_ids),
591
-        );
592
-        if (isset($where_params['OR'])) {
593
-            $and_condition['OR'] = $where_params['OR'];
594
-            unset($where_params['OR']);
595
-        }
596
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
597
-            $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
598
-            unset($where_params['Datetime.DTT_EVT_end']);
599
-        }
600
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
601
-            $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
602
-            unset($where_params['Datetime.DTT_EVT_start']);
603
-        }
604
-        // merge remaining $where params with the and conditions.
605
-        $where_params['AND'] = array_merge($and_condition, $where_params);
606
-        $query_params[0] = $where_params;
607
-        // don't use $query_params with count()
608
-        // because we don't want to include additional query clauses like "GROUP BY"
609
-        return $count
610
-            ? $this->count(array($where_params), 'EVT_ID', true)
611
-            : $this->get_all($query_params);
612
-    }
613
-
614
-
615
-
616
-    /**
617
-     * This basically just returns the events that do not have the publish status.
618
-     *
619
-     * @param  array   $query_params An array of query params to further filter on
620
-     *                               (note that status will be overwritten)
621
-     * @param  boolean $count        whether to return the count or not (default FALSE)
622
-     * @return EE_Event[]|int
623
-     * @throws \EE_Error
624
-     */
625
-    public function get_inactive_events($query_params, $count = false)
626
-    {
627
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
628
-        // let's add in specific query_params for inactive events.
629
-        if (isset($where_params['status'])) {
630
-            unset($where_params['status']);
631
-        }
632
-        // if we have count make sure we don't include group by
633
-        if ($count && isset($query_params['group_by'])) {
634
-            unset($query_params['group_by']);
635
-        }
636
-        // if we have any additional query_params, let's add them to the 'AND' condition
637
-        $where_params['AND']['status'] = array('!=', 'publish');
638
-        if (isset($where_params['OR'])) {
639
-            $where_params['AND']['OR'] = $where_params['OR'];
640
-            unset($where_params['OR']);
641
-        }
642
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
643
-            $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
644
-            unset($where_params['Datetime.DTT_EVT_end']);
645
-        }
646
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
647
-            $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
648
-            unset($where_params['Datetime.DTT_EVT_start']);
649
-        }
650
-        $query_params[0] = $where_params;
651
-        // don't use $query_params with count()
652
-        // because we don't want to include additional query clauses like "GROUP BY"
653
-        return $count
654
-            ? $this->count(array($where_params), 'EVT_ID', true)
655
-            : $this->get_all($query_params);
656
-    }
657
-
658
-
659
-
660
-    /**
661
-     * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
662
-     * because we don't want to override any existing global default prices but instead insert NEW prices that get
663
-     * attached to the event. See parent for param descriptions
664
-     *
665
-     * @param        $id_or_obj
666
-     * @param        $other_model_id_or_obj
667
-     * @param string $relationName
668
-     * @param array  $where_query
669
-     * @return EE_Base_Class
670
-     * @throws EE_Error
671
-     */
672
-    public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
673
-    {
674
-        if ($relationName === 'Price') {
675
-            //let's get the PRC object for the given ID to make sure that we aren't dealing with a default
676
-            $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
677
-            //if EVT_ID = 0, then this is a default
678
-            if ((int) $prc_chk->get('EVT_ID') === 0) {
679
-                //let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
680
-                $prc_chk->set('PRC_ID', 0);
681
-            }
682
-            //run parent
683
-            return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
684
-        }
685
-        //otherwise carry on as normal
686
-        return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
687
-    }
688
-
689
-
690
-
691
-    /******************** DEPRECATED METHODS ********************/
692
-
693
-
694
-
695
-    /**
696
-     * _get_question_target_db_column
697
-     *
698
-     * @deprecated as of 4.8.32.rc.001. Instead consider using
699
-     *             EE_Registration_Custom_Questions_Form located in
700
-     *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
701
-     * @access     public
702
-     * @param    EE_Registration $registration (so existing answers for registration are included)
703
-     * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
704
-     *                                         registration).
705
-     * @throws EE_Error
706
-     * @return    array
707
-     */
708
-    public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
709
-    {
710
-        if (empty($EVT_ID)) {
711
-            throw new EE_Error(__('An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
712
-                'event_espresso'));
713
-        }
714
-        $questions = array();
715
-        // get all question groups for event
716
-        $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
717
-        if (! empty($qgs)) {
718
-            foreach ($qgs as $qg) {
719
-                $qsts = $qg->questions();
720
-                $questions[$qg->ID()] = $qg->model_field_array();
721
-                $questions[$qg->ID()]['QSG_questions'] = array();
722
-                foreach ($qsts as $qst) {
723
-                    if ($qst->is_system_question()) {
724
-                        continue;
725
-                    }
726
-                    $answer = EEM_Answer::instance()->get_one(array(
727
-                        array(
728
-                            'QST_ID' => $qst->ID(),
729
-                            'REG_ID' => $registration->ID(),
730
-                        ),
731
-                    ));
732
-                    $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
733
-                    $qst_name = $qstn_id = $qst->ID();
734
-                    $ans_id = $answer->ID();
735
-                    $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
736
-                    $input_name = '';
737
-                    $input_id = sanitize_key($qst->display_text());
738
-                    $input_class = '';
739
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array();
740
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'
741
-                                                                                           . $input_name
742
-                                                                                           . $qst_name;
743
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id;
744
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
745
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array();
746
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst;
747
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer;
748
-                    //leave responses as-is, don't convert stuff into html entities please!
749
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false;
750
-                    if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
751
-                        $QSOs = $qst->options(true, $answer->value());
752
-                        if (is_array($QSOs)) {
753
-                            foreach ($QSOs as $QSO_ID => $QSO) {
754
-                                $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array();
755
-                            }
756
-                        }
757
-                    }
758
-                }
759
-            }
760
-        }
761
-        return $questions;
762
-    }
19
+	/**
20
+	 * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
21
+	 * event
22
+	 */
23
+	const sold_out = 'sold_out';
24
+
25
+	/**
26
+	 * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
27
+	 * date)
28
+	 */
29
+	const postponed = 'postponed';
30
+
31
+	/**
32
+	 * constant used by status(), indicating that the event will no longer occur
33
+	 */
34
+	const cancelled = 'cancelled';
35
+
36
+
37
+	/**
38
+	 * @var string
39
+	 */
40
+	protected static $_default_reg_status;
41
+
42
+
43
+	/**
44
+	 * private instance of the Event object
45
+	 *
46
+	 * @var EEM_Event
47
+	 */
48
+	protected static $_instance;
49
+
50
+
51
+
52
+	/**
53
+	 *  This function is a singleton method used to instantiate the EEM_Event object
54
+	 *
55
+	 * @param string $timezone
56
+	 * @return EEM_Event
57
+	 * @throws \EE_Error
58
+	 */
59
+	public static function instance($timezone = null)
60
+	{
61
+		// check if instance of EEM_Event already exists
62
+		if (! self::$_instance instanceof EEM_Event) {
63
+			// instantiate Espresso_model
64
+			self::$_instance = new self($timezone);
65
+		}
66
+		//we might have a timezone set, let set_timezone decide what to do with it
67
+		self::$_instance->set_timezone($timezone);
68
+		// EEM_Event object
69
+		return self::$_instance;
70
+	}
71
+
72
+
73
+
74
+	/**
75
+	 * Adds a relationship to Term_Taxonomy for each CPT_Base
76
+	 *
77
+	 * @param string $timezone
78
+	 * @throws \EE_Error
79
+	 */
80
+	protected function __construct($timezone = null)
81
+	{
82
+		EE_Registry::instance()->load_model('Registration');
83
+		$this->singular_item = esc_html__('Event', 'event_espresso');
84
+		$this->plural_item = esc_html__('Events', 'event_espresso');
85
+		// to remove Cancelled events from the frontend, copy the following filter to your functions.php file
86
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
87
+		// to remove Postponed events from the frontend, copy the following filter to your functions.php file
88
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
89
+		// to remove Sold Out events from the frontend, copy the following filter to your functions.php file
90
+		//	add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
91
+		$this->_custom_stati = apply_filters(
92
+			'AFEE__EEM_Event__construct___custom_stati',
93
+			array(
94
+				EEM_Event::cancelled => array(
95
+					'label'  => esc_html__('Cancelled', 'event_espresso'),
96
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
97
+				),
98
+				EEM_Event::postponed => array(
99
+					'label'  => esc_html__('Postponed', 'event_espresso'),
100
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
101
+				),
102
+				EEM_Event::sold_out  => array(
103
+					'label'  => esc_html__('Sold Out', 'event_espresso'),
104
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
105
+				),
106
+			)
107
+		);
108
+		self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
109
+			: self::$_default_reg_status;
110
+		$this->_tables = array(
111
+			'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
112
+			'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
113
+		);
114
+		$this->_fields = array(
115
+			'Event_CPT'  => array(
116
+				'EVT_ID'         => new EE_Primary_Key_Int_Field('ID',
117
+					esc_html__('Post ID for Event', 'event_espresso')),
118
+				'EVT_name'       => new EE_Plain_Text_Field('post_title', esc_html__('Event Name', 'event_espresso'),
119
+					false,
120
+					''),
121
+				'EVT_desc'       => new EE_Post_Content_Field('post_content',
122
+					esc_html__('Event Description', 'event_espresso'),
123
+					false, ''),
124
+				'EVT_slug'       => new EE_Slug_Field('post_name', esc_html__('Event Slug', 'event_espresso'), false,
125
+					''),
126
+				'EVT_created'    => new EE_Datetime_Field('post_date',
127
+					esc_html__('Date/Time Event Created', 'event_espresso'),
128
+					false, EE_Datetime_Field::now),
129
+				'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt',
130
+					esc_html__('Event Short Description', 'event_espresso'), false, ''),
131
+				'EVT_modified'   => new EE_Datetime_Field('post_modified',
132
+					esc_html__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now),
133
+				'EVT_wp_user'    => new EE_WP_User_Field('post_author',
134
+					esc_html__('Event Creator ID', 'event_espresso'),
135
+					false),
136
+				'parent'         => new EE_Integer_Field('post_parent', esc_html__('Event Parent ID', 'event_espresso'),
137
+					false,
138
+					0),
139
+				'EVT_order'      => new EE_Integer_Field('menu_order', esc_html__('Event Menu Order', 'event_espresso'),
140
+					false,
141
+					1),
142
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
143
+				// EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
144
+				'status'         => new EE_WP_Post_Status_Field('post_status',
145
+					esc_html__('Event Status', 'event_espresso'),
146
+					false, 'draft', $this->_custom_stati),
147
+			),
148
+			'Event_Meta' => array(
149
+				'EVTM_ID'                         => new EE_DB_Only_Float_Field('EVTM_ID',
150
+					esc_html__('Event Meta Row ID', 'event_espresso'), false),
151
+				'EVT_ID_fk'                       => new EE_DB_Only_Int_Field('EVT_ID',
152
+					esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false),
153
+				'EVT_display_desc'                => new EE_Boolean_Field('EVT_display_desc',
154
+					esc_html__('Display Description Flag', 'event_espresso'), false, 1),
155
+				'EVT_display_ticket_selector'     => new EE_Boolean_Field('EVT_display_ticket_selector',
156
+					esc_html__('Display Ticket Selector Flag', 'event_espresso'), false, 1),
157
+				'EVT_visible_on'                  => new EE_Datetime_Field('EVT_visible_on',
158
+					esc_html__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now),
159
+				'EVT_additional_limit'            => new EE_Integer_Field('EVT_additional_limit',
160
+					esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), true, 10),
161
+				'EVT_default_registration_status' => new EE_Enum_Text_Field(
162
+					'EVT_default_registration_status',
163
+					esc_html__('Default Registration Status on this Event', 'event_espresso'), false,
164
+					EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array()
165
+				),
166
+				'EVT_member_only'                 => new EE_Boolean_Field('EVT_member_only',
167
+					esc_html__('Member-Only Event Flag', 'event_espresso'), false, false),
168
+				'EVT_phone'                       => new EE_Plain_Text_Field('EVT_phone',
169
+					esc_html__('Event Phone Number', 'event_espresso'), false),
170
+				'EVT_allow_overflow'              => new EE_Boolean_Field('EVT_allow_overflow',
171
+					esc_html__('Allow Overflow on Event', 'event_espresso'), false, false),
172
+				'EVT_timezone_string'             => new EE_Plain_Text_Field('EVT_timezone_string',
173
+					esc_html__('Timezone (name) for Event times', 'event_espresso'), false),
174
+				'EVT_external_URL'                => new EE_Plain_Text_Field('EVT_external_URL',
175
+					esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true),
176
+				'EVT_donations'                   => new EE_Boolean_Field('EVT_donations',
177
+					esc_html__('Accept Donations?', 'event_espresso'), false, false),
178
+			),
179
+		);
180
+		$this->_model_relations = array(
181
+			'Registration'           => new EE_Has_Many_Relation(),
182
+			'Datetime'               => new EE_Has_Many_Relation(),
183
+			'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
184
+			'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
185
+			'Term_Relationship'      => new EE_Has_Many_Relation(),
186
+			'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
187
+			'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
188
+			'Attendee'               => new EE_HABTM_Relation('Registration'),
189
+			'WP_User'                => new EE_Belongs_To_Relation(),
190
+		);
191
+		//this model is generally available for reading
192
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
193
+		parent::__construct($timezone);
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 * @param string $default_reg_status
200
+	 */
201
+	public static function set_default_reg_status($default_reg_status)
202
+	{
203
+		self::$_default_reg_status = $default_reg_status;
204
+		// if EEM_Event has already been instantiated,
205
+		// then we need to reset the `EVT_default_reg_status` field to use the new default.
206
+		if (self::$_instance instanceof EEM_Event) {
207
+			$default_reg_status = new EE_Enum_Text_Field(
208
+				'EVT_default_registration_status',
209
+				esc_html__('Default Registration Status on this Event', 'event_espresso'),
210
+				false,
211
+				$default_reg_status,
212
+				EEM_Registration::reg_status_array()
213
+			);
214
+			$default_reg_status->_construct_finalize(
215
+				'Event_Meta',
216
+				'EVT_default_registration_status',
217
+				'EEM_Event'
218
+			);
219
+			self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status;
220
+		}
221
+	}
222
+
223
+
224
+
225
+	/**
226
+	 * get_question_groups
227
+	 *
228
+	 * @return array
229
+	 * @throws \EE_Error
230
+	 */
231
+	public function get_all_question_groups()
232
+	{
233
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
234
+			array(
235
+				array('QSG_deleted' => false),
236
+				'order_by' => array('QSG_order' => 'ASC'),
237
+			)
238
+		);
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * get_question_groups
245
+	 *
246
+	 * @param int $EVT_ID
247
+	 * @return array|bool
248
+	 * @throws \EE_Error
249
+	 */
250
+	public function get_all_event_question_groups($EVT_ID = 0)
251
+	{
252
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
253
+			EE_Error::add_error(
254
+				esc_html__(
255
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
256
+					'event_espresso'
257
+				),
258
+				__FILE__, __FUNCTION__, __LINE__
259
+			);
260
+			return false;
261
+		}
262
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
263
+			array(
264
+				array('EVT_ID' => $EVT_ID),
265
+			)
266
+		);
267
+	}
268
+
269
+
270
+
271
+	/**
272
+	 * get_question_groups
273
+	 *
274
+	 * @param int     $EVT_ID
275
+	 * @param boolean $for_primary_attendee
276
+	 * @return array|bool
277
+	 * @throws \EE_Error
278
+	 */
279
+	public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
280
+	{
281
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
282
+			EE_Error::add_error(
283
+				esc_html__(
284
+					'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
285
+					'event_espresso'
286
+				),
287
+				__FILE__, __FUNCTION__, __LINE__
288
+			);
289
+			return false;
290
+		}
291
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(
292
+			array(
293
+				array(
294
+					'EVT_ID'      => $EVT_ID,
295
+					'EQG_primary' => $for_primary_attendee,
296
+				),
297
+			)
298
+		);
299
+	}
300
+
301
+
302
+
303
+	/**
304
+	 * get_question_groups
305
+	 *
306
+	 * @param int             $EVT_ID
307
+	 * @param EE_Registration $registration
308
+	 * @return array|bool
309
+	 * @throws \EE_Error
310
+	 */
311
+	public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
312
+	{
313
+		if (! isset($EVT_ID) || ! absint($EVT_ID)) {
314
+			EE_Error::add_error(
315
+				esc_html__(
316
+					'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
317
+					'event_espresso'
318
+				),
319
+				__FILE__, __FUNCTION__, __LINE__
320
+			);
321
+			return false;
322
+		}
323
+		$where_params = array(
324
+			'Event_Question_Group.EVT_ID'      => $EVT_ID,
325
+			'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false,
326
+			'QSG_deleted'                      => false,
327
+		);
328
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(
329
+			array(
330
+				$where_params,
331
+				'order_by' => array('QSG_order' => 'ASC'),
332
+			)
333
+		);
334
+	}
335
+
336
+
337
+
338
+	/**
339
+	 * get_question_target_db_column
340
+	 *
341
+	 * @param string $QSG_IDs csv list of $QSG IDs
342
+	 * @return array|bool
343
+	 * @throws \EE_Error
344
+	 */
345
+	public function get_questions_in_groups($QSG_IDs = '')
346
+	{
347
+		if (empty($QSG_IDs)) {
348
+			EE_Error::add_error(
349
+				esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
350
+				__FILE__, __FUNCTION__, __LINE__
351
+			);
352
+			return false;
353
+		}
354
+		return EE_Registry::instance()->load_model('Question')->get_all(
355
+			array(
356
+				array(
357
+					'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
358
+					'QST_deleted'           => false,
359
+					'QST_admin_only'        => is_admin(),
360
+				),
361
+				'order_by' => 'QST_order',
362
+			)
363
+		);
364
+	}
365
+
366
+
367
+
368
+	/**
369
+	 * get_options_for_question
370
+	 *
371
+	 * @param string $QST_IDs csv list of $QST IDs
372
+	 * @return array|bool
373
+	 * @throws \EE_Error
374
+	 */
375
+	public function get_options_for_question($QST_IDs)
376
+	{
377
+		if (empty($QST_IDs)) {
378
+			EE_Error::add_error(
379
+				esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'),
380
+				__FILE__, __FUNCTION__, __LINE__
381
+			);
382
+			return false;
383
+		}
384
+		return EE_Registry::instance()->load_model('Question_Option')->get_all(
385
+			array(
386
+				array(
387
+					'Question.QST_ID' => array('IN', $QST_IDs),
388
+					'QSO_deleted'     => false,
389
+				),
390
+				'order_by' => 'QSO_ID',
391
+			)
392
+		);
393
+	}
394
+
395
+
396
+
397
+
398
+
399
+
400
+
401
+	/**
402
+	 * Gets all events that are published
403
+	 * and have event start time earlier than now and an event end time later than now
404
+	 *
405
+	 * @param  array $query_params An array of query params to further filter on
406
+	 *                             (note that status and DTT_EVT_start and DTT_EVT_end will be overridden)
407
+	 * @param bool   $count        whether to return the count or not (default FALSE)
408
+	 * @return EE_Event[]|int
409
+	 * @throws \EE_Error
410
+	 */
411
+	public function get_active_events($query_params, $count = false)
412
+	{
413
+		if (array_key_exists(0, $query_params)) {
414
+			$where_params = $query_params[0];
415
+			unset($query_params[0]);
416
+		} else {
417
+			$where_params = array();
418
+		}
419
+		// if we have count make sure we don't include group by
420
+		if ($count && isset($query_params['group_by'])) {
421
+			unset($query_params['group_by']);
422
+		}
423
+		// let's add specific query_params for active_events
424
+		// keep in mind this will override any sent status in the query AND any date queries.
425
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
426
+		//if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
427
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
428
+			$where_params['Datetime.DTT_EVT_start******'] = array(
429
+				'<',
430
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
431
+			);
432
+		} else {
433
+			$where_params['Datetime.DTT_EVT_start'] = array(
434
+				'<',
435
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
436
+			);
437
+		}
438
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
439
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
440
+				'>',
441
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
442
+			);
443
+		} else {
444
+			$where_params['Datetime.DTT_EVT_end'] = array(
445
+				'>',
446
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
447
+			);
448
+		}
449
+		$query_params[0] = $where_params;
450
+		// don't use $query_params with count()
451
+		// because we don't want to include additional query clauses like "GROUP BY"
452
+		return $count
453
+			? $this->count(array($where_params), 'EVT_ID', true)
454
+			: $this->get_all($query_params);
455
+	}
456
+
457
+
458
+
459
+	/**
460
+	 * get all events that are published and have an event start time later than now
461
+	 *
462
+	 * @param  array $query_params An array of query params to further filter on
463
+	 *                             (Note that status and DTT_EVT_start will be overridden)
464
+	 * @param bool   $count        whether to return the count or not (default FALSE)
465
+	 * @return EE_Event[]|int
466
+	 * @throws \EE_Error
467
+	 */
468
+	public function get_upcoming_events($query_params, $count = false)
469
+	{
470
+		if (array_key_exists(0, $query_params)) {
471
+			$where_params = $query_params[0];
472
+			unset($query_params[0]);
473
+		} else {
474
+			$where_params = array();
475
+		}
476
+		// if we have count make sure we don't include group by
477
+		if ($count && isset($query_params['group_by'])) {
478
+			unset($query_params['group_by']);
479
+		}
480
+		// let's add specific query_params for active_events
481
+		// keep in mind this will override any sent status in the query AND any date queries.
482
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
483
+		// if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
484
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
485
+			$where_params['Datetime.DTT_EVT_start*****'] = array(
486
+				'>',
487
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
488
+			);
489
+		} else {
490
+			$where_params['Datetime.DTT_EVT_start'] = array(
491
+				'>',
492
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
493
+			);
494
+		}
495
+		$query_params[0] = $where_params;
496
+		// don't use $query_params with count()
497
+		// because we don't want to include additional query clauses like "GROUP BY"
498
+		return $count
499
+			? $this->count(array($where_params), 'EVT_ID', true)
500
+			: $this->get_all($query_params);
501
+	}
502
+
503
+
504
+
505
+	/**
506
+	 * Gets all events that are published
507
+	 * and have an event end time later than now
508
+	 *
509
+	 * @param  array $query_params An array of query params to further filter on
510
+	 *                             (note that status and DTT_EVT_end will be overridden)
511
+	 * @param bool   $count        whether to return the count or not (default FALSE)
512
+	 * @return EE_Event[]|int
513
+	 * @throws \EE_Error
514
+	 */
515
+	public function get_active_and_upcoming_events($query_params, $count = false)
516
+	{
517
+		if (array_key_exists(0, $query_params)) {
518
+			$where_params = $query_params[0];
519
+			unset($query_params[0]);
520
+		} else {
521
+			$where_params = array();
522
+		}
523
+		// if we have count make sure we don't include group by
524
+		if ($count && isset($query_params['group_by'])) {
525
+			unset($query_params['group_by']);
526
+		}
527
+		// let's add specific query_params for active_events
528
+		// keep in mind this will override any sent status in the query AND any date queries.
529
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
530
+		// add where params for DTT_EVT_end
531
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
532
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
533
+				'>',
534
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
535
+			);
536
+		} else {
537
+			$where_params['Datetime.DTT_EVT_end'] = array(
538
+				'>',
539
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
540
+			);
541
+		}
542
+		$query_params[0] = $where_params;
543
+		// don't use $query_params with count()
544
+		// because we don't want to include additional query clauses like "GROUP BY"
545
+		return $count
546
+			? $this->count(array($where_params), 'EVT_ID', true)
547
+			: $this->get_all($query_params);
548
+	}
549
+
550
+
551
+
552
+	/**
553
+	 * This only returns events that are expired.
554
+	 * They may still be published but all their datetimes have expired.
555
+	 *
556
+	 * @param  array $query_params An array of query params to further filter on
557
+	 *                             (note that status and DTT_EVT_end will be overridden)
558
+	 * @param bool   $count        whether to return the count or not (default FALSE)
559
+	 * @return EE_Event[]|int
560
+	 * @throws \EE_Error
561
+	 */
562
+	public function get_expired_events($query_params, $count = false)
563
+	{
564
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
565
+		// if we have count make sure we don't include group by
566
+		if ($count && isset($query_params['group_by'])) {
567
+			unset($query_params['group_by']);
568
+		}
569
+		// let's add specific query_params for active_events
570
+		// keep in mind this will override any sent status in the query AND any date queries.
571
+		if (isset($where_params['status'])) {
572
+			unset($where_params['status']);
573
+		}
574
+		$exclude_query = $query_params;
575
+		if (isset($exclude_query[0])) {
576
+			unset($exclude_query[0]);
577
+		}
578
+		$exclude_query[0] = array(
579
+			'Datetime.DTT_EVT_end' => array(
580
+				'>',
581
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
582
+			),
583
+		);
584
+		// first get all events that have datetimes where its not expired.
585
+		$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
586
+		$event_ids = array_keys($event_ids);
587
+		// if we have any additional query_params, let's add them to the 'AND' condition
588
+		$and_condition = array(
589
+			'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
590
+			'EVT_ID'               => array('NOT IN', $event_ids),
591
+		);
592
+		if (isset($where_params['OR'])) {
593
+			$and_condition['OR'] = $where_params['OR'];
594
+			unset($where_params['OR']);
595
+		}
596
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
597
+			$and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
598
+			unset($where_params['Datetime.DTT_EVT_end']);
599
+		}
600
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
601
+			$and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
602
+			unset($where_params['Datetime.DTT_EVT_start']);
603
+		}
604
+		// merge remaining $where params with the and conditions.
605
+		$where_params['AND'] = array_merge($and_condition, $where_params);
606
+		$query_params[0] = $where_params;
607
+		// don't use $query_params with count()
608
+		// because we don't want to include additional query clauses like "GROUP BY"
609
+		return $count
610
+			? $this->count(array($where_params), 'EVT_ID', true)
611
+			: $this->get_all($query_params);
612
+	}
613
+
614
+
615
+
616
+	/**
617
+	 * This basically just returns the events that do not have the publish status.
618
+	 *
619
+	 * @param  array   $query_params An array of query params to further filter on
620
+	 *                               (note that status will be overwritten)
621
+	 * @param  boolean $count        whether to return the count or not (default FALSE)
622
+	 * @return EE_Event[]|int
623
+	 * @throws \EE_Error
624
+	 */
625
+	public function get_inactive_events($query_params, $count = false)
626
+	{
627
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
628
+		// let's add in specific query_params for inactive events.
629
+		if (isset($where_params['status'])) {
630
+			unset($where_params['status']);
631
+		}
632
+		// if we have count make sure we don't include group by
633
+		if ($count && isset($query_params['group_by'])) {
634
+			unset($query_params['group_by']);
635
+		}
636
+		// if we have any additional query_params, let's add them to the 'AND' condition
637
+		$where_params['AND']['status'] = array('!=', 'publish');
638
+		if (isset($where_params['OR'])) {
639
+			$where_params['AND']['OR'] = $where_params['OR'];
640
+			unset($where_params['OR']);
641
+		}
642
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
643
+			$where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
644
+			unset($where_params['Datetime.DTT_EVT_end']);
645
+		}
646
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
647
+			$where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
648
+			unset($where_params['Datetime.DTT_EVT_start']);
649
+		}
650
+		$query_params[0] = $where_params;
651
+		// don't use $query_params with count()
652
+		// because we don't want to include additional query clauses like "GROUP BY"
653
+		return $count
654
+			? $this->count(array($where_params), 'EVT_ID', true)
655
+			: $this->get_all($query_params);
656
+	}
657
+
658
+
659
+
660
+	/**
661
+	 * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
662
+	 * because we don't want to override any existing global default prices but instead insert NEW prices that get
663
+	 * attached to the event. See parent for param descriptions
664
+	 *
665
+	 * @param        $id_or_obj
666
+	 * @param        $other_model_id_or_obj
667
+	 * @param string $relationName
668
+	 * @param array  $where_query
669
+	 * @return EE_Base_Class
670
+	 * @throws EE_Error
671
+	 */
672
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
673
+	{
674
+		if ($relationName === 'Price') {
675
+			//let's get the PRC object for the given ID to make sure that we aren't dealing with a default
676
+			$prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
677
+			//if EVT_ID = 0, then this is a default
678
+			if ((int) $prc_chk->get('EVT_ID') === 0) {
679
+				//let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
680
+				$prc_chk->set('PRC_ID', 0);
681
+			}
682
+			//run parent
683
+			return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
684
+		}
685
+		//otherwise carry on as normal
686
+		return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
687
+	}
688
+
689
+
690
+
691
+	/******************** DEPRECATED METHODS ********************/
692
+
693
+
694
+
695
+	/**
696
+	 * _get_question_target_db_column
697
+	 *
698
+	 * @deprecated as of 4.8.32.rc.001. Instead consider using
699
+	 *             EE_Registration_Custom_Questions_Form located in
700
+	 *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
701
+	 * @access     public
702
+	 * @param    EE_Registration $registration (so existing answers for registration are included)
703
+	 * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
704
+	 *                                         registration).
705
+	 * @throws EE_Error
706
+	 * @return    array
707
+	 */
708
+	public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
709
+	{
710
+		if (empty($EVT_ID)) {
711
+			throw new EE_Error(__('An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
712
+				'event_espresso'));
713
+		}
714
+		$questions = array();
715
+		// get all question groups for event
716
+		$qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
717
+		if (! empty($qgs)) {
718
+			foreach ($qgs as $qg) {
719
+				$qsts = $qg->questions();
720
+				$questions[$qg->ID()] = $qg->model_field_array();
721
+				$questions[$qg->ID()]['QSG_questions'] = array();
722
+				foreach ($qsts as $qst) {
723
+					if ($qst->is_system_question()) {
724
+						continue;
725
+					}
726
+					$answer = EEM_Answer::instance()->get_one(array(
727
+						array(
728
+							'QST_ID' => $qst->ID(),
729
+							'REG_ID' => $registration->ID(),
730
+						),
731
+					));
732
+					$answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
733
+					$qst_name = $qstn_id = $qst->ID();
734
+					$ans_id = $answer->ID();
735
+					$qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
736
+					$input_name = '';
737
+					$input_id = sanitize_key($qst->display_text());
738
+					$input_class = '';
739
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array();
740
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'
741
+																						   . $input_name
742
+																						   . $qst_name;
743
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id;
744
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
745
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array();
746
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst;
747
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer;
748
+					//leave responses as-is, don't convert stuff into html entities please!
749
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false;
750
+					if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
751
+						$QSOs = $qst->options(true, $answer->value());
752
+						if (is_array($QSOs)) {
753
+							foreach ($QSOs as $QSO_ID => $QSO) {
754
+								$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array();
755
+							}
756
+						}
757
+					}
758
+				}
759
+			}
760
+		}
761
+		return $questions;
762
+	}
763 763
 
764 764
 
765 765
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4
-require_once(EE_MODELS . 'EEM_CPT_Base.model.php');
4
+require_once(EE_MODELS.'EEM_CPT_Base.model.php');
5 5
 
6 6
 
7 7
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
     public static function instance($timezone = null)
60 60
     {
61 61
         // check if instance of EEM_Event already exists
62
-        if (! self::$_instance instanceof EEM_Event) {
62
+        if ( ! self::$_instance instanceof EEM_Event) {
63 63
             // instantiate Espresso_model
64 64
             self::$_instance = new self($timezone);
65 65
         }
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
      */
250 250
     public function get_all_event_question_groups($EVT_ID = 0)
251 251
     {
252
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
252
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
253 253
             EE_Error::add_error(
254 254
                 esc_html__(
255 255
                     'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
      */
279 279
     public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
280 280
     {
281
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
281
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
282 282
             EE_Error::add_error(
283 283
                 esc_html__(
284 284
                     'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
      */
311 311
     public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
312 312
     {
313
-        if (! isset($EVT_ID) || ! absint($EVT_ID)) {
313
+        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
314 314
             EE_Error::add_error(
315 315
                 esc_html__(
316 316
                     'An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
@@ -714,7 +714,7 @@  discard block
 block discarded – undo
714 714
         $questions = array();
715 715
         // get all question groups for event
716 716
         $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
717
-        if (! empty($qgs)) {
717
+        if ( ! empty($qgs)) {
718 718
             foreach ($qgs as $qg) {
719 719
                 $qsts = $qg->questions();
720 720
                 $questions[$qg->ID()] = $qg->model_field_array();
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
                     $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
733 733
                     $qst_name = $qstn_id = $qst->ID();
734 734
                     $ans_id = $answer->ID();
735
-                    $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
735
+                    $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']';
736 736
                     $input_name = '';
737 737
                     $input_id = sanitize_key($qst->display_text());
738 738
                     $input_class = '';
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
                     $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'
741 741
                                                                                            . $input_name
742 742
                                                                                            . $qst_name;
743
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id;
743
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id;
744 744
                     $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
745 745
                     $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array();
746 746
                     $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst;
Please login to merge, or discard this patch.
admin_pages/maintenance/Maintenance_Admin_Page.core.php 2 patches
Indentation   +616 added lines, -616 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -28,636 +28,636 @@  discard block
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    public function __construct($routing = true)
32
-    {
33
-        parent::__construct($routing);
34
-    }
35
-
36
-
37
-
38
-    protected function _init_page_props()
39
-    {
40
-        $this->page_slug = EE_MAINTENANCE_PG_SLUG;
41
-        $this->page_label = EE_MAINTENANCE_LABEL;
42
-        $this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL;
43
-        $this->_admin_base_path = EE_MAINTENANCE_ADMIN;
44
-    }
45
-
46
-
47
-
48
-    protected function _ajax_hooks()
49
-    {
50
-        add_action('wp_ajax_migration_step', array($this, 'migration_step'));
51
-        add_action('wp_ajax_add_error_to_migrations_ran', array($this, 'add_error_to_migrations_ran'));
52
-    }
53
-
54
-
55
-
56
-    protected function _define_page_props()
57
-    {
58
-        $this->_admin_page_title = EE_MAINTENANCE_LABEL;
59
-        $this->_labels = array(
60
-            'buttons' => array(
61
-                'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'),
62
-                'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'),
63
-            ),
64
-        );
65
-    }
66
-
67
-
68
-
69
-    protected function _set_page_routes()
70
-    {
71
-        $this->_page_routes = array(
72
-            'default'                             => array(
73
-                'func'       => '_maintenance',
74
-                'capability' => 'manage_options',
75
-            ),
76
-            'change_maintenance_level'            => array(
77
-                'func'       => '_change_maintenance_level',
78
-                'capability' => 'manage_options',
79
-                'noheader'   => true,
80
-            ),
81
-            'system_status'                       => array(
82
-                'func'       => '_system_status',
83
-                'capability' => 'manage_options',
84
-            ),
85
-            'download_system_status' => array(
86
-                'func'       => '_download_system_status',
87
-                'capability' => 'manage_options',
88
-                'noheader'   => true,
89
-            ),
90
-            'send_migration_crash_report'         => array(
91
-                'func'       => '_send_migration_crash_report',
92
-                'capability' => 'manage_options',
93
-                'noheader'   => true,
94
-            ),
95
-            'confirm_migration_crash_report_sent' => array(
96
-                'func'       => '_confirm_migration_crash_report_sent',
97
-                'capability' => 'manage_options',
98
-            ),
99
-            'data_reset'                          => array(
100
-                'func'       => '_data_reset_and_delete',
101
-                'capability' => 'manage_options',
102
-            ),
103
-            'reset_db'                            => array(
104
-                'func'       => '_reset_db',
105
-                'capability' => 'manage_options',
106
-                'noheader'   => true,
107
-                'args'       => array('nuke_old_ee4_data' => true),
108
-            ),
109
-            'start_with_fresh_ee4_db'             => array(
110
-                'func'       => '_reset_db',
111
-                'capability' => 'manage_options',
112
-                'noheader'   => true,
113
-                'args'       => array('nuke_old_ee4_data' => false),
114
-            ),
115
-            'delete_db'                           => array(
116
-                'func'       => '_delete_db',
117
-                'capability' => 'manage_options',
118
-                'noheader'   => true,
119
-            ),
120
-            'rerun_migration_from_ee3'            => array(
121
-                'func'       => '_rerun_migration_from_ee3',
122
-                'capability' => 'manage_options',
123
-                'noheader'   => true,
124
-            ),
125
-            'reset_reservations'                  => array(
126
-                'func'       => '_reset_reservations',
127
-                'capability' => 'manage_options',
128
-                'noheader'   => true,
129
-            ),
130
-            'reset_capabilities'                  => array(
131
-                'func'       => '_reset_capabilities',
132
-                'capability' => 'manage_options',
133
-                'noheader'   => true,
134
-            ),
135
-            'reattempt_migration'                 => array(
136
-                'func'       => '_reattempt_migration',
137
-                'capability' => 'manage_options',
138
-                'noheader'   => true,
139
-            ),
140
-        );
141
-    }
142
-
143
-
144
-
145
-    protected function _set_page_config()
146
-    {
147
-        $this->_page_config = array(
148
-            'default'       => array(
149
-                'nav'           => array(
150
-                    'label' => esc_html__('Maintenance', 'event_espresso'),
151
-                    'order' => 10,
152
-                ),
153
-                'require_nonce' => false,
154
-            ),
155
-            'data_reset'    => array(
156
-                'nav'           => array(
157
-                    'label' => esc_html__('Reset/Delete Data', 'event_espresso'),
158
-                    'order' => 20,
159
-                ),
160
-                'require_nonce' => false,
161
-            ),
162
-            'system_status' => array(
163
-                'nav'           => array(
164
-                    'label' => esc_html__("System Information", "event_espresso"),
165
-                    'order' => 30,
166
-                ),
167
-                'require_nonce' => false,
168
-            ),
169
-        );
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     * default maintenance page. If we're in maintenance mode level 2, then we need to show
176
-     * the migration scripts and all that UI.
177
-     */
178
-    public function _maintenance()
179
-    {
180
-        //it all depends if we're in maintenance model level 1 (frontend-only) or
181
-        //level 2 (everything except maintenance page)
182
-        try {
183
-            //get the current maintenance level and check if
184
-            //we are removed
185
-            $mm = EE_Maintenance_Mode::instance()->level();
186
-            $placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
187
-            if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) {
188
-                //we just took the site out of maintenance mode, so notify the user.
189
-                //unfortunately this message appears to be echoed on the NEXT page load...
190
-                //oh well, we should really be checking for this on addon deactivation anyways
191
-                EE_Error::add_attention(__('Site taken out of maintenance mode because no data migration scripts are required',
192
-                    'event_espresso'));
193
-                $this->_process_notices(array('page' => 'espresso_maintenance_settings'), false);
194
-            }
195
-            //in case an exception is thrown while trying to handle migrations
196
-            switch (EE_Maintenance_Mode::instance()->level()) {
197
-                case EE_Maintenance_Mode::level_0_not_in_maintenance:
198
-                case EE_Maintenance_Mode::level_1_frontend_only_maintenance:
199
-                    $show_maintenance_switch = true;
200
-                    $show_backup_db_text = false;
201
-                    $show_migration_progress = false;
202
-                    $script_names = array();
203
-                    $addons_should_be_upgraded_first = false;
204
-                    break;
205
-                case EE_Maintenance_Mode::level_2_complete_maintenance:
206
-                    $show_maintenance_switch = false;
207
-                    $show_migration_progress = true;
208
-                    if (isset($this->_req_data['continue_migration'])) {
209
-                        $show_backup_db_text = false;
210
-                    } else {
211
-                        $show_backup_db_text = true;
212
-                    }
213
-                    $scripts_needing_to_run = EE_Data_Migration_Manager::instance()
214
-                                                                       ->check_for_applicable_data_migration_scripts();
215
-                    $addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating();
216
-                    $script_names = array();
217
-                    $current_script = null;
218
-                    foreach ($scripts_needing_to_run as $script) {
219
-                        if ($script instanceof EE_Data_Migration_Script_Base) {
220
-                            if ( ! $current_script) {
221
-                                $current_script = $script;
222
-                                $current_script->migration_page_hooks();
223
-                            }
224
-                            $script_names[] = $script->pretty_name();
225
-                        }
226
-                    }
227
-                    break;
228
-            }
229
-            $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
230
-            $exception_thrown = false;
231
-        } catch (EE_Error $e) {
232
-            EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
233
-            //now, just so we can display the page correctly, make a error migration script stage object
234
-            //and also put the error on it. It only persists for the duration of this request
235
-            $most_recent_migration = new EE_DMS_Unknown_1_0_0();
236
-            $most_recent_migration->add_error($e->getMessage());
237
-            $exception_thrown = true;
238
-        }
239
-        $current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set();
240
-        $current_db_state = str_replace('.decaf', '', $current_db_state);
241
-        if ($exception_thrown
242
-            || ($most_recent_migration
243
-                && $most_recent_migration instanceof EE_Data_Migration_Script_Base
244
-                && $most_recent_migration->is_broken()
245
-            )
246
-        ) {
247
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
248
-            $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/';
249
-            $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action'  => 'confirm_migration_crash_report_sent',
250
-                                                                                        'success' => '0',
251
-            ), EE_MAINTENANCE_ADMIN_URL);
252
-        } elseif ($addons_should_be_upgraded_first) {
253
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
254
-        } else {
255
-            if ($most_recent_migration
256
-                && $most_recent_migration instanceof EE_Data_Migration_Script_Base
257
-                && $most_recent_migration->can_continue()
258
-            ) {
259
-                $show_backup_db_text = false;
260
-                $show_continue_current_migration_script = true;
261
-                $show_most_recent_migration = true;
262
-            } elseif (isset($this->_req_data['continue_migration'])) {
263
-                $show_most_recent_migration = true;
264
-                $show_continue_current_migration_script = false;
265
-            } else {
266
-                $show_most_recent_migration = false;
267
-                $show_continue_current_migration_script = false;
268
-            }
269
-            if (isset($current_script)) {
270
-                $migrates_to = $current_script->migrates_to_version();
271
-                $plugin_slug = $migrates_to['slug'];
272
-                $new_version = $migrates_to['version'];
273
-                $this->_template_args = array_merge($this->_template_args, array(
274
-                    'current_db_state' => sprintf(__("EE%s (%s)", "event_espresso"),
275
-                        isset($current_db_state[$plugin_slug]) ? $current_db_state[$plugin_slug] : 3, $plugin_slug),
276
-                    'next_db_state'    => isset($current_script) ? sprintf(__("EE%s (%s)", 'event_espresso'),
277
-                        $new_version, $plugin_slug) : null,
278
-                ));
279
-            } else {
280
-                $this->_template_args['current_db_state'] = null;
281
-                $this->_template_args['next_db_state'] = null;
282
-            }
283
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
284
-            $this->_template_args = array_merge(
285
-                $this->_template_args,
286
-                array(
287
-                    'show_most_recent_migration'             => $show_most_recent_migration,
288
-                    //flag for showing the most recent migration's status and/or errors
289
-                    'show_migration_progress'                => $show_migration_progress,
290
-                    //flag for showing the option to run migrations and see their progress
291
-                    'show_backup_db_text'                    => $show_backup_db_text,
292
-                    //flag for showing text telling the user to backup their DB
293
-                    'show_maintenance_switch'                => $show_maintenance_switch,
294
-                    //flag for showing the option to change maintenance mode between levels 0 and 1
295
-                    'script_names'                           => $script_names,
296
-                    //array of names of scripts that have run
297
-                    'show_continue_current_migration_script' => $show_continue_current_migration_script,
298
-                    //flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
299
-                    'reset_db_page_link'                     => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
300
-                        EE_MAINTENANCE_ADMIN_URL),
301
-                    'data_reset_page'                        => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
302
-                        EE_MAINTENANCE_ADMIN_URL),
303
-                    'update_migration_script_page_link'      => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'change_maintenance_level'),
304
-                        EE_MAINTENANCE_ADMIN_URL),
305
-                    'ultimate_db_state'                      => sprintf(__("EE%s", 'event_espresso'),
306
-                        espresso_version()),
307
-                )
308
-            );
309
-            //make sure we have the form fields helper available. It usually is, but sometimes it isn't
310
-            //localize script stuff
311
-            wp_localize_script('ee-maintenance', 'ee_maintenance', array(
312
-                'migrating'                        => esc_html__("Updating Database...", "event_espresso"),
313
-                'next'                             => esc_html__("Next", "event_espresso"),
314
-                'fatal_error'                      => esc_html__("A Fatal Error Has Occurred", "event_espresso"),
315
-                'click_next_when_ready'            => esc_html__("The current Database Update has ended. Click 'next' when ready to proceed",
316
-                    "event_espresso"),
317
-                'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts,
318
-                'status_fatal_error'               => EE_Data_Migration_Manager::status_fatal_error,
319
-                'status_completed'                 => EE_Data_Migration_Manager::status_completed,
320
-            ));
321
-        }
322
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration
323
-        //now render the migration options part, and put it in a variable
324
-        $migration_options_template_file = apply_filters(
325
-            'FHEE__ee_migration_page__migration_options_template',
326
-            EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
327
-        );
328
-        $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true);
329
-        $this->_template_args['migration_options_html'] = $migration_options_html;
330
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
331
-            $this->_template_args, true);
332
-        $this->display_admin_page_with_sidebar();
333
-    }
334
-
335
-
336
-
337
-    /**
338
-     * returns JSON and executes another step of the currently-executing data migration (called via ajax)
339
-     */
340
-    public function migration_step()
341
-    {
342
-        $this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request();
343
-        $this->_return_json();
344
-    }
345
-
346
-
347
-
348
-    /**
349
-     * Can be used by js when it notices a response with HTML in it in order
350
-     * to log the malformed response
351
-     */
352
-    public function add_error_to_migrations_ran()
353
-    {
354
-        EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']);
355
-        $this->_template_args['data'] = array('ok' => true);
356
-        $this->_return_json();
357
-    }
358
-
359
-
360
-
361
-    /**
362
-     * changes the maintenance level, provided there are still no migration scripts that should run
363
-     */
364
-    public function _change_maintenance_level()
365
-    {
366
-        $new_level = absint($this->_req_data['maintenance_mode_level']);
367
-        if ( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
368
-            EE_Maintenance_Mode::instance()->set_maintenance_level($new_level);
369
-            $success = true;
370
-        } else {
371
-            EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
372
-            $success = false;
373
-        }
374
-        $this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso"));
375
-    }
376
-
377
-
378
-
379
-    /**
380
-     * a tab with options for resetting and/or deleting EE data
381
-     *
382
-     * @throws \EE_Error
383
-     * @throws \DomainException
384
-     */
385
-    public function _data_reset_and_delete()
386
-    {
387
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
388
-        $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
389
-            'reset_reservations',
390
-            'reset_reservations',
391
-            array(),
392
-            'button button-primary',
393
-            '',
394
-            false
395
-        );
396
-        $this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button(
397
-            'reset_capabilities',
398
-            'reset_capabilities',
399
-            array(),
400
-            'button button-primary',
401
-            '',
402
-            false
403
-        );
404
-        $this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
405
-            array('action' => 'delete_db'),
406
-            EE_MAINTENANCE_ADMIN_URL
407
-        );
408
-        $this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
409
-            array('action' => 'reset_db'),
410
-            EE_MAINTENANCE_ADMIN_URL
411
-        );
412
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
413
-            $this->_template_path,
414
-            $this->_template_args,
415
-            true
416
-        );
417
-        $this->display_admin_page_with_sidebar();
418
-    }
419
-
420
-
421
-
422
-    protected function _reset_reservations()
423
-    {
424
-        if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
425
-            EE_Error::add_success(
426
-                __(
427
-                    'Ticket and datetime reserved counts have been successfully reset.',
428
-                    'event_espresso'
429
-                )
430
-            );
431
-        } else {
432
-            EE_Error::add_success(
433
-                __(
434
-                    'Ticket and datetime reserved counts were correct and did not need resetting.',
435
-                    'event_espresso'
436
-                )
437
-            );
438
-        }
439
-        $this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true);
440
-    }
441
-
442
-
443
-
444
-    protected function _reset_capabilities()
445
-    {
446
-        EE_Registry::instance()->CAP->init_caps(true);
447
-        EE_Error::add_success(__('Default Event Espresso capabilities have been restored for all current roles.',
448
-            'event_espresso'));
449
-        $this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true);
450
-    }
451
-
452
-
453
-
454
-    /**
455
-     * resets the DMSs so we can attempt to continue migrating after a fatal error
456
-     * (only a good idea when someone has somehow tried ot fix whatever caused
457
-     * the fatal error in teh first place)
458
-     */
459
-    protected function _reattempt_migration()
460
-    {
461
-        EE_Data_Migration_Manager::instance()->reattempt();
462
-        $this->_redirect_after_action(false, '', '', array('action' => 'default'), true);
463
-    }
464
-
465
-
466
-
467
-    /**
468
-     * shows the big ol' System Information page
469
-     */
470
-    public function _system_status()
471
-    {
472
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
473
-        $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
474
-        $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
475
-            array(
476
-                'action' => 'download_system_status',
477
-            ),
478
-            EE_MAINTENANCE_ADMIN_URL
479
-        );
480
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
481
-            $this->_template_args, true);
482
-        $this->display_admin_page_with_sidebar();
483
-    }
484
-
485
-    /**
486
-     * Downloads an HTML file of the system status that can be easily stored or emailed
487
-     */
488
-    public function _download_system_status()
489
-    {
490
-        $status_info = EEM_System_Status::instance()->get_system_stati();
491
-        header( 'Content-Disposition: attachment' );
492
-        header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" );
493
-        echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>";
494
-        echo "<h1>System Information for " . site_url() . "</h1>";
495
-        echo EEH_Template::layout_array_as_table( $status_info );
496
-        die;
497
-    }
498
-
499
-
500
-
501
-    public function _send_migration_crash_report()
502
-    {
503
-        $from = $this->_req_data['from'];
504
-        $from_name = $this->_req_data['from_name'];
505
-        $body = $this->_req_data['body'];
506
-        try {
507
-            $success = wp_mail(EE_SUPPORT_EMAIL,
508
-                'Migration Crash Report',
509
-                $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
510
-                array(
511
-                    "from:$from_name<$from>",
512
-                    //					'content-type:text/html charset=UTF-8'
513
-                ));
514
-        } catch (Exception $e) {
515
-            $success = false;
516
-        }
517
-        $this->_redirect_after_action($success, esc_html__("Migration Crash Report", "event_espresso"),
518
-            esc_html__("sent", "event_espresso"),
519
-            array('success' => $success, 'action' => 'confirm_migration_crash_report_sent'));
520
-    }
521
-
522
-
523
-
524
-    public function _confirm_migration_crash_report_sent()
525
-    {
526
-        try {
527
-            $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
528
-        } catch (EE_Error $e) {
529
-            EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
530
-            //now, just so we can display the page correctly, make a error migration script stage object
531
-            //and also put the error on it. It only persists for the duration of this request
532
-            $most_recent_migration = new EE_DMS_Unknown_1_0_0();
533
-            $most_recent_migration->add_error($e->getMessage());
534
-        }
535
-        $success = $this->_req_data['success'] == '1' ? true : false;
536
-        $this->_template_args['success'] = $success;
537
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;
538
-        $this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
539
-            EE_MAINTENANCE_ADMIN_URL);
540
-        $this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
541
-            EE_MAINTENANCE_ADMIN_URL);
542
-        $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'),
543
-            EE_MAINTENANCE_ADMIN_URL);
544
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
545
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
546
-            $this->_template_args, true);
547
-        $this->display_admin_page_with_sidebar();
548
-    }
549
-
550
-
551
-
552
-    /**
553
-     * Resets the entire EE4 database.
554
-     * Currently basically only sets up ee4 database for a fresh install- doesn't
555
-     * actually clean out the old wp options, or cpts (although does erase old ee table data)
556
-     *
557
-     * @param boolean $nuke_old_ee4_data controls whether or not we
558
-     *                                   destroy the old ee4 data, or just try initializing ee4 default data
559
-     */
560
-    public function _reset_db($nuke_old_ee4_data = true)
561
-    {
562
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
563
-        if ($nuke_old_ee4_data) {
564
-            EEH_Activation::delete_all_espresso_cpt_data();
565
-            EEH_Activation::delete_all_espresso_tables_and_data(false);
566
-            EEH_Activation::remove_cron_tasks();
567
-        }
568
-        //make sure when we reset the registry's config that it
569
-        //switches to using the new singleton
570
-        EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true);
571
-        EE_System::instance()->initialize_db_if_no_migrations_required(true);
572
-        EE_System::instance()->redirect_to_about_ee();
573
-    }
574
-
575
-
576
-
577
-    /**
578
-     * Deletes ALL EE tables, Records, and Options from the database.
579
-     */
580
-    public function _delete_db()
581
-    {
582
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
583
-        EEH_Activation::delete_all_espresso_cpt_data();
584
-        EEH_Activation::delete_all_espresso_tables_and_data();
585
-        EEH_Activation::remove_cron_tasks();
586
-        EEH_Activation::deactivate_event_espresso();
587
-        wp_safe_redirect(admin_url('plugins.php'));
588
-        exit;
589
-    }
590
-
591
-
592
-
593
-    /**
594
-     * sets up EE4 to rerun the migrations from ee3 to ee4
595
-     */
596
-    public function _rerun_migration_from_ee3()
597
-    {
598
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
599
-        EEH_Activation::delete_all_espresso_cpt_data();
600
-        EEH_Activation::delete_all_espresso_tables_and_data(false);
601
-        //set the db state to something that will require migrations
602
-        update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
603
-        EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
604
-        $this->_redirect_after_action(true, esc_html__("Database", 'event_espresso'), esc_html__("reset", 'event_espresso'));
605
-    }
606
-
607
-
608
-
609
-    //none of the below group are currently used for Gateway Settings
610
-    protected function _add_screen_options()
611
-    {
612
-    }
613
-
614
-
615
-
616
-    protected function _add_feature_pointers()
617
-    {
618
-    }
619
-
31
+	public function __construct($routing = true)
32
+	{
33
+		parent::__construct($routing);
34
+	}
35
+
36
+
37
+
38
+	protected function _init_page_props()
39
+	{
40
+		$this->page_slug = EE_MAINTENANCE_PG_SLUG;
41
+		$this->page_label = EE_MAINTENANCE_LABEL;
42
+		$this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL;
43
+		$this->_admin_base_path = EE_MAINTENANCE_ADMIN;
44
+	}
45
+
46
+
47
+
48
+	protected function _ajax_hooks()
49
+	{
50
+		add_action('wp_ajax_migration_step', array($this, 'migration_step'));
51
+		add_action('wp_ajax_add_error_to_migrations_ran', array($this, 'add_error_to_migrations_ran'));
52
+	}
53
+
54
+
55
+
56
+	protected function _define_page_props()
57
+	{
58
+		$this->_admin_page_title = EE_MAINTENANCE_LABEL;
59
+		$this->_labels = array(
60
+			'buttons' => array(
61
+				'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'),
62
+				'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'),
63
+			),
64
+		);
65
+	}
66
+
67
+
68
+
69
+	protected function _set_page_routes()
70
+	{
71
+		$this->_page_routes = array(
72
+			'default'                             => array(
73
+				'func'       => '_maintenance',
74
+				'capability' => 'manage_options',
75
+			),
76
+			'change_maintenance_level'            => array(
77
+				'func'       => '_change_maintenance_level',
78
+				'capability' => 'manage_options',
79
+				'noheader'   => true,
80
+			),
81
+			'system_status'                       => array(
82
+				'func'       => '_system_status',
83
+				'capability' => 'manage_options',
84
+			),
85
+			'download_system_status' => array(
86
+				'func'       => '_download_system_status',
87
+				'capability' => 'manage_options',
88
+				'noheader'   => true,
89
+			),
90
+			'send_migration_crash_report'         => array(
91
+				'func'       => '_send_migration_crash_report',
92
+				'capability' => 'manage_options',
93
+				'noheader'   => true,
94
+			),
95
+			'confirm_migration_crash_report_sent' => array(
96
+				'func'       => '_confirm_migration_crash_report_sent',
97
+				'capability' => 'manage_options',
98
+			),
99
+			'data_reset'                          => array(
100
+				'func'       => '_data_reset_and_delete',
101
+				'capability' => 'manage_options',
102
+			),
103
+			'reset_db'                            => array(
104
+				'func'       => '_reset_db',
105
+				'capability' => 'manage_options',
106
+				'noheader'   => true,
107
+				'args'       => array('nuke_old_ee4_data' => true),
108
+			),
109
+			'start_with_fresh_ee4_db'             => array(
110
+				'func'       => '_reset_db',
111
+				'capability' => 'manage_options',
112
+				'noheader'   => true,
113
+				'args'       => array('nuke_old_ee4_data' => false),
114
+			),
115
+			'delete_db'                           => array(
116
+				'func'       => '_delete_db',
117
+				'capability' => 'manage_options',
118
+				'noheader'   => true,
119
+			),
120
+			'rerun_migration_from_ee3'            => array(
121
+				'func'       => '_rerun_migration_from_ee3',
122
+				'capability' => 'manage_options',
123
+				'noheader'   => true,
124
+			),
125
+			'reset_reservations'                  => array(
126
+				'func'       => '_reset_reservations',
127
+				'capability' => 'manage_options',
128
+				'noheader'   => true,
129
+			),
130
+			'reset_capabilities'                  => array(
131
+				'func'       => '_reset_capabilities',
132
+				'capability' => 'manage_options',
133
+				'noheader'   => true,
134
+			),
135
+			'reattempt_migration'                 => array(
136
+				'func'       => '_reattempt_migration',
137
+				'capability' => 'manage_options',
138
+				'noheader'   => true,
139
+			),
140
+		);
141
+	}
142
+
143
+
144
+
145
+	protected function _set_page_config()
146
+	{
147
+		$this->_page_config = array(
148
+			'default'       => array(
149
+				'nav'           => array(
150
+					'label' => esc_html__('Maintenance', 'event_espresso'),
151
+					'order' => 10,
152
+				),
153
+				'require_nonce' => false,
154
+			),
155
+			'data_reset'    => array(
156
+				'nav'           => array(
157
+					'label' => esc_html__('Reset/Delete Data', 'event_espresso'),
158
+					'order' => 20,
159
+				),
160
+				'require_nonce' => false,
161
+			),
162
+			'system_status' => array(
163
+				'nav'           => array(
164
+					'label' => esc_html__("System Information", "event_espresso"),
165
+					'order' => 30,
166
+				),
167
+				'require_nonce' => false,
168
+			),
169
+		);
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 * default maintenance page. If we're in maintenance mode level 2, then we need to show
176
+	 * the migration scripts and all that UI.
177
+	 */
178
+	public function _maintenance()
179
+	{
180
+		//it all depends if we're in maintenance model level 1 (frontend-only) or
181
+		//level 2 (everything except maintenance page)
182
+		try {
183
+			//get the current maintenance level and check if
184
+			//we are removed
185
+			$mm = EE_Maintenance_Mode::instance()->level();
186
+			$placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
187
+			if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) {
188
+				//we just took the site out of maintenance mode, so notify the user.
189
+				//unfortunately this message appears to be echoed on the NEXT page load...
190
+				//oh well, we should really be checking for this on addon deactivation anyways
191
+				EE_Error::add_attention(__('Site taken out of maintenance mode because no data migration scripts are required',
192
+					'event_espresso'));
193
+				$this->_process_notices(array('page' => 'espresso_maintenance_settings'), false);
194
+			}
195
+			//in case an exception is thrown while trying to handle migrations
196
+			switch (EE_Maintenance_Mode::instance()->level()) {
197
+				case EE_Maintenance_Mode::level_0_not_in_maintenance:
198
+				case EE_Maintenance_Mode::level_1_frontend_only_maintenance:
199
+					$show_maintenance_switch = true;
200
+					$show_backup_db_text = false;
201
+					$show_migration_progress = false;
202
+					$script_names = array();
203
+					$addons_should_be_upgraded_first = false;
204
+					break;
205
+				case EE_Maintenance_Mode::level_2_complete_maintenance:
206
+					$show_maintenance_switch = false;
207
+					$show_migration_progress = true;
208
+					if (isset($this->_req_data['continue_migration'])) {
209
+						$show_backup_db_text = false;
210
+					} else {
211
+						$show_backup_db_text = true;
212
+					}
213
+					$scripts_needing_to_run = EE_Data_Migration_Manager::instance()
214
+																	   ->check_for_applicable_data_migration_scripts();
215
+					$addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating();
216
+					$script_names = array();
217
+					$current_script = null;
218
+					foreach ($scripts_needing_to_run as $script) {
219
+						if ($script instanceof EE_Data_Migration_Script_Base) {
220
+							if ( ! $current_script) {
221
+								$current_script = $script;
222
+								$current_script->migration_page_hooks();
223
+							}
224
+							$script_names[] = $script->pretty_name();
225
+						}
226
+					}
227
+					break;
228
+			}
229
+			$most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
230
+			$exception_thrown = false;
231
+		} catch (EE_Error $e) {
232
+			EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
233
+			//now, just so we can display the page correctly, make a error migration script stage object
234
+			//and also put the error on it. It only persists for the duration of this request
235
+			$most_recent_migration = new EE_DMS_Unknown_1_0_0();
236
+			$most_recent_migration->add_error($e->getMessage());
237
+			$exception_thrown = true;
238
+		}
239
+		$current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set();
240
+		$current_db_state = str_replace('.decaf', '', $current_db_state);
241
+		if ($exception_thrown
242
+			|| ($most_recent_migration
243
+				&& $most_recent_migration instanceof EE_Data_Migration_Script_Base
244
+				&& $most_recent_migration->is_broken()
245
+			)
246
+		) {
247
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
248
+			$this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/';
249
+			$this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action'  => 'confirm_migration_crash_report_sent',
250
+																						'success' => '0',
251
+			), EE_MAINTENANCE_ADMIN_URL);
252
+		} elseif ($addons_should_be_upgraded_first) {
253
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
254
+		} else {
255
+			if ($most_recent_migration
256
+				&& $most_recent_migration instanceof EE_Data_Migration_Script_Base
257
+				&& $most_recent_migration->can_continue()
258
+			) {
259
+				$show_backup_db_text = false;
260
+				$show_continue_current_migration_script = true;
261
+				$show_most_recent_migration = true;
262
+			} elseif (isset($this->_req_data['continue_migration'])) {
263
+				$show_most_recent_migration = true;
264
+				$show_continue_current_migration_script = false;
265
+			} else {
266
+				$show_most_recent_migration = false;
267
+				$show_continue_current_migration_script = false;
268
+			}
269
+			if (isset($current_script)) {
270
+				$migrates_to = $current_script->migrates_to_version();
271
+				$plugin_slug = $migrates_to['slug'];
272
+				$new_version = $migrates_to['version'];
273
+				$this->_template_args = array_merge($this->_template_args, array(
274
+					'current_db_state' => sprintf(__("EE%s (%s)", "event_espresso"),
275
+						isset($current_db_state[$plugin_slug]) ? $current_db_state[$plugin_slug] : 3, $plugin_slug),
276
+					'next_db_state'    => isset($current_script) ? sprintf(__("EE%s (%s)", 'event_espresso'),
277
+						$new_version, $plugin_slug) : null,
278
+				));
279
+			} else {
280
+				$this->_template_args['current_db_state'] = null;
281
+				$this->_template_args['next_db_state'] = null;
282
+			}
283
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
284
+			$this->_template_args = array_merge(
285
+				$this->_template_args,
286
+				array(
287
+					'show_most_recent_migration'             => $show_most_recent_migration,
288
+					//flag for showing the most recent migration's status and/or errors
289
+					'show_migration_progress'                => $show_migration_progress,
290
+					//flag for showing the option to run migrations and see their progress
291
+					'show_backup_db_text'                    => $show_backup_db_text,
292
+					//flag for showing text telling the user to backup their DB
293
+					'show_maintenance_switch'                => $show_maintenance_switch,
294
+					//flag for showing the option to change maintenance mode between levels 0 and 1
295
+					'script_names'                           => $script_names,
296
+					//array of names of scripts that have run
297
+					'show_continue_current_migration_script' => $show_continue_current_migration_script,
298
+					//flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
299
+					'reset_db_page_link'                     => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
300
+						EE_MAINTENANCE_ADMIN_URL),
301
+					'data_reset_page'                        => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
302
+						EE_MAINTENANCE_ADMIN_URL),
303
+					'update_migration_script_page_link'      => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'change_maintenance_level'),
304
+						EE_MAINTENANCE_ADMIN_URL),
305
+					'ultimate_db_state'                      => sprintf(__("EE%s", 'event_espresso'),
306
+						espresso_version()),
307
+				)
308
+			);
309
+			//make sure we have the form fields helper available. It usually is, but sometimes it isn't
310
+			//localize script stuff
311
+			wp_localize_script('ee-maintenance', 'ee_maintenance', array(
312
+				'migrating'                        => esc_html__("Updating Database...", "event_espresso"),
313
+				'next'                             => esc_html__("Next", "event_espresso"),
314
+				'fatal_error'                      => esc_html__("A Fatal Error Has Occurred", "event_espresso"),
315
+				'click_next_when_ready'            => esc_html__("The current Database Update has ended. Click 'next' when ready to proceed",
316
+					"event_espresso"),
317
+				'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts,
318
+				'status_fatal_error'               => EE_Data_Migration_Manager::status_fatal_error,
319
+				'status_completed'                 => EE_Data_Migration_Manager::status_completed,
320
+			));
321
+		}
322
+		$this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration
323
+		//now render the migration options part, and put it in a variable
324
+		$migration_options_template_file = apply_filters(
325
+			'FHEE__ee_migration_page__migration_options_template',
326
+			EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
327
+		);
328
+		$migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true);
329
+		$this->_template_args['migration_options_html'] = $migration_options_html;
330
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
331
+			$this->_template_args, true);
332
+		$this->display_admin_page_with_sidebar();
333
+	}
334
+
335
+
336
+
337
+	/**
338
+	 * returns JSON and executes another step of the currently-executing data migration (called via ajax)
339
+	 */
340
+	public function migration_step()
341
+	{
342
+		$this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request();
343
+		$this->_return_json();
344
+	}
345
+
346
+
347
+
348
+	/**
349
+	 * Can be used by js when it notices a response with HTML in it in order
350
+	 * to log the malformed response
351
+	 */
352
+	public function add_error_to_migrations_ran()
353
+	{
354
+		EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']);
355
+		$this->_template_args['data'] = array('ok' => true);
356
+		$this->_return_json();
357
+	}
358
+
359
+
360
+
361
+	/**
362
+	 * changes the maintenance level, provided there are still no migration scripts that should run
363
+	 */
364
+	public function _change_maintenance_level()
365
+	{
366
+		$new_level = absint($this->_req_data['maintenance_mode_level']);
367
+		if ( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
368
+			EE_Maintenance_Mode::instance()->set_maintenance_level($new_level);
369
+			$success = true;
370
+		} else {
371
+			EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
372
+			$success = false;
373
+		}
374
+		$this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso"));
375
+	}
376
+
377
+
378
+
379
+	/**
380
+	 * a tab with options for resetting and/or deleting EE data
381
+	 *
382
+	 * @throws \EE_Error
383
+	 * @throws \DomainException
384
+	 */
385
+	public function _data_reset_and_delete()
386
+	{
387
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
388
+		$this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
389
+			'reset_reservations',
390
+			'reset_reservations',
391
+			array(),
392
+			'button button-primary',
393
+			'',
394
+			false
395
+		);
396
+		$this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button(
397
+			'reset_capabilities',
398
+			'reset_capabilities',
399
+			array(),
400
+			'button button-primary',
401
+			'',
402
+			false
403
+		);
404
+		$this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
405
+			array('action' => 'delete_db'),
406
+			EE_MAINTENANCE_ADMIN_URL
407
+		);
408
+		$this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce(
409
+			array('action' => 'reset_db'),
410
+			EE_MAINTENANCE_ADMIN_URL
411
+		);
412
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
413
+			$this->_template_path,
414
+			$this->_template_args,
415
+			true
416
+		);
417
+		$this->display_admin_page_with_sidebar();
418
+	}
419
+
420
+
421
+
422
+	protected function _reset_reservations()
423
+	{
424
+		if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
425
+			EE_Error::add_success(
426
+				__(
427
+					'Ticket and datetime reserved counts have been successfully reset.',
428
+					'event_espresso'
429
+				)
430
+			);
431
+		} else {
432
+			EE_Error::add_success(
433
+				__(
434
+					'Ticket and datetime reserved counts were correct and did not need resetting.',
435
+					'event_espresso'
436
+				)
437
+			);
438
+		}
439
+		$this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true);
440
+	}
441
+
442
+
443
+
444
+	protected function _reset_capabilities()
445
+	{
446
+		EE_Registry::instance()->CAP->init_caps(true);
447
+		EE_Error::add_success(__('Default Event Espresso capabilities have been restored for all current roles.',
448
+			'event_espresso'));
449
+		$this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true);
450
+	}
451
+
452
+
453
+
454
+	/**
455
+	 * resets the DMSs so we can attempt to continue migrating after a fatal error
456
+	 * (only a good idea when someone has somehow tried ot fix whatever caused
457
+	 * the fatal error in teh first place)
458
+	 */
459
+	protected function _reattempt_migration()
460
+	{
461
+		EE_Data_Migration_Manager::instance()->reattempt();
462
+		$this->_redirect_after_action(false, '', '', array('action' => 'default'), true);
463
+	}
464
+
465
+
466
+
467
+	/**
468
+	 * shows the big ol' System Information page
469
+	 */
470
+	public function _system_status()
471
+	{
472
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
473
+		$this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
474
+		$this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
475
+			array(
476
+				'action' => 'download_system_status',
477
+			),
478
+			EE_MAINTENANCE_ADMIN_URL
479
+		);
480
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
481
+			$this->_template_args, true);
482
+		$this->display_admin_page_with_sidebar();
483
+	}
484
+
485
+	/**
486
+	 * Downloads an HTML file of the system status that can be easily stored or emailed
487
+	 */
488
+	public function _download_system_status()
489
+	{
490
+		$status_info = EEM_System_Status::instance()->get_system_stati();
491
+		header( 'Content-Disposition: attachment' );
492
+		header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" );
493
+		echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>";
494
+		echo "<h1>System Information for " . site_url() . "</h1>";
495
+		echo EEH_Template::layout_array_as_table( $status_info );
496
+		die;
497
+	}
498
+
499
+
500
+
501
+	public function _send_migration_crash_report()
502
+	{
503
+		$from = $this->_req_data['from'];
504
+		$from_name = $this->_req_data['from_name'];
505
+		$body = $this->_req_data['body'];
506
+		try {
507
+			$success = wp_mail(EE_SUPPORT_EMAIL,
508
+				'Migration Crash Report',
509
+				$body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
510
+				array(
511
+					"from:$from_name<$from>",
512
+					//					'content-type:text/html charset=UTF-8'
513
+				));
514
+		} catch (Exception $e) {
515
+			$success = false;
516
+		}
517
+		$this->_redirect_after_action($success, esc_html__("Migration Crash Report", "event_espresso"),
518
+			esc_html__("sent", "event_espresso"),
519
+			array('success' => $success, 'action' => 'confirm_migration_crash_report_sent'));
520
+	}
521
+
522
+
523
+
524
+	public function _confirm_migration_crash_report_sent()
525
+	{
526
+		try {
527
+			$most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
528
+		} catch (EE_Error $e) {
529
+			EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
530
+			//now, just so we can display the page correctly, make a error migration script stage object
531
+			//and also put the error on it. It only persists for the duration of this request
532
+			$most_recent_migration = new EE_DMS_Unknown_1_0_0();
533
+			$most_recent_migration->add_error($e->getMessage());
534
+		}
535
+		$success = $this->_req_data['success'] == '1' ? true : false;
536
+		$this->_template_args['success'] = $success;
537
+		$this->_template_args['most_recent_migration'] = $most_recent_migration;
538
+		$this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'),
539
+			EE_MAINTENANCE_ADMIN_URL);
540
+		$this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'),
541
+			EE_MAINTENANCE_ADMIN_URL);
542
+		$this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'),
543
+			EE_MAINTENANCE_ADMIN_URL);
544
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
545
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
546
+			$this->_template_args, true);
547
+		$this->display_admin_page_with_sidebar();
548
+	}
549
+
550
+
551
+
552
+	/**
553
+	 * Resets the entire EE4 database.
554
+	 * Currently basically only sets up ee4 database for a fresh install- doesn't
555
+	 * actually clean out the old wp options, or cpts (although does erase old ee table data)
556
+	 *
557
+	 * @param boolean $nuke_old_ee4_data controls whether or not we
558
+	 *                                   destroy the old ee4 data, or just try initializing ee4 default data
559
+	 */
560
+	public function _reset_db($nuke_old_ee4_data = true)
561
+	{
562
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
563
+		if ($nuke_old_ee4_data) {
564
+			EEH_Activation::delete_all_espresso_cpt_data();
565
+			EEH_Activation::delete_all_espresso_tables_and_data(false);
566
+			EEH_Activation::remove_cron_tasks();
567
+		}
568
+		//make sure when we reset the registry's config that it
569
+		//switches to using the new singleton
570
+		EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true);
571
+		EE_System::instance()->initialize_db_if_no_migrations_required(true);
572
+		EE_System::instance()->redirect_to_about_ee();
573
+	}
574
+
575
+
576
+
577
+	/**
578
+	 * Deletes ALL EE tables, Records, and Options from the database.
579
+	 */
580
+	public function _delete_db()
581
+	{
582
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
583
+		EEH_Activation::delete_all_espresso_cpt_data();
584
+		EEH_Activation::delete_all_espresso_tables_and_data();
585
+		EEH_Activation::remove_cron_tasks();
586
+		EEH_Activation::deactivate_event_espresso();
587
+		wp_safe_redirect(admin_url('plugins.php'));
588
+		exit;
589
+	}
590
+
591
+
592
+
593
+	/**
594
+	 * sets up EE4 to rerun the migrations from ee3 to ee4
595
+	 */
596
+	public function _rerun_migration_from_ee3()
597
+	{
598
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
599
+		EEH_Activation::delete_all_espresso_cpt_data();
600
+		EEH_Activation::delete_all_espresso_tables_and_data(false);
601
+		//set the db state to something that will require migrations
602
+		update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
603
+		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
604
+		$this->_redirect_after_action(true, esc_html__("Database", 'event_espresso'), esc_html__("reset", 'event_espresso'));
605
+	}
606
+
607
+
608
+
609
+	//none of the below group are currently used for Gateway Settings
610
+	protected function _add_screen_options()
611
+	{
612
+	}
613
+
614
+
615
+
616
+	protected function _add_feature_pointers()
617
+	{
618
+	}
619
+
620 620
 
621 621
 
622
-    public function admin_init()
623
-    {
624
-    }
625
-
626
-
627
-
628
-    public function admin_notices()
629
-    {
630
-    }
631
-
622
+	public function admin_init()
623
+	{
624
+	}
625
+
626
+
627
+
628
+	public function admin_notices()
629
+	{
630
+	}
631
+
632 632
 
633 633
 
634
-    public function admin_footer_scripts()
635
-    {
636
-    }
634
+	public function admin_footer_scripts()
635
+	{
636
+	}
637 637
 
638 638
 
639 639
 
640
-    public function load_scripts_styles()
641
-    {
642
-        wp_enqueue_script('ee_admin_js');
640
+	public function load_scripts_styles()
641
+	{
642
+		wp_enqueue_script('ee_admin_js');
643 643
 //		wp_enqueue_media();
644 644
 //		wp_enqueue_script('media-upload');
645
-        wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'),
646
-            EVENT_ESPRESSO_VERSION, true);
647
-        wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(),
648
-            EVENT_ESPRESSO_VERSION);
649
-        wp_enqueue_style('espresso_maintenance');
650
-    }
645
+		wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'),
646
+			EVENT_ESPRESSO_VERSION, true);
647
+		wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(),
648
+			EVENT_ESPRESSO_VERSION);
649
+		wp_enqueue_style('espresso_maintenance');
650
+	}
651 651
 
652 652
 
653 653
 
654
-    public function load_scripts_styles_default()
655
-    {
656
-        //styles
654
+	public function load_scripts_styles_default()
655
+	{
656
+		//styles
657 657
 //		wp_enqueue_style('ee-text-links');
658 658
 //		//scripts
659 659
 //		wp_enqueue_script('ee-text-links');
660
-    }
660
+	}
661 661
 
662 662
 
663 663
 
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -244,13 +244,13 @@  discard block
 block discarded – undo
244 244
                 && $most_recent_migration->is_broken()
245 245
             )
246 246
         ) {
247
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
247
+            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_was_borked_page.template.php';
248 248
             $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/';
249 249
             $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action'  => 'confirm_migration_crash_report_sent',
250 250
                                                                                         'success' => '0',
251 251
             ), EE_MAINTENANCE_ADMIN_URL);
252 252
         } elseif ($addons_should_be_upgraded_first) {
253
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
253
+            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_upgrade_addons_before_migrating.template.php';
254 254
         } else {
255 255
             if ($most_recent_migration
256 256
                 && $most_recent_migration instanceof EE_Data_Migration_Script_Base
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
                 $this->_template_args['current_db_state'] = null;
281 281
                 $this->_template_args['next_db_state'] = null;
282 282
             }
283
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
283
+            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_page.template.php';
284 284
             $this->_template_args = array_merge(
285 285
                 $this->_template_args,
286 286
                 array(
@@ -319,13 +319,13 @@  discard block
 block discarded – undo
319 319
                 'status_completed'                 => EE_Data_Migration_Manager::status_completed,
320 320
             ));
321 321
         }
322
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration
322
+        $this->_template_args['most_recent_migration'] = $most_recent_migration; //the actual most recently ran migration
323 323
         //now render the migration options part, and put it in a variable
324 324
         $migration_options_template_file = apply_filters(
325 325
             'FHEE__ee_migration_page__migration_options_template',
326
-            EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
326
+            EE_MAINTENANCE_TEMPLATE_PATH.'migration_options_from_ee4.template.php'
327 327
         );
328
-        $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true);
328
+        $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args, true);
329 329
         $this->_template_args['migration_options_html'] = $migration_options_html;
330 330
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
331 331
             $this->_template_args, true);
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
      */
385 385
     public function _data_reset_and_delete()
386 386
     {
387
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
387
+        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_data_reset_and_delete.template.php';
388 388
         $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
389 389
             'reset_reservations',
390 390
             'reset_reservations',
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 
422 422
     protected function _reset_reservations()
423 423
     {
424
-        if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
424
+        if (\EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
425 425
             EE_Error::add_success(
426 426
                 __(
427 427
                     'Ticket and datetime reserved counts have been successfully reset.',
@@ -469,7 +469,7 @@  discard block
 block discarded – undo
469 469
      */
470 470
     public function _system_status()
471 471
     {
472
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
472
+        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_system_stati_page.template.php';
473 473
         $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
474 474
         $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
475 475
             array(
@@ -488,11 +488,11 @@  discard block
 block discarded – undo
488 488
     public function _download_system_status()
489 489
     {
490 490
         $status_info = EEM_System_Status::instance()->get_system_stati();
491
-        header( 'Content-Disposition: attachment' );
492
-        header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" );
491
+        header('Content-Disposition: attachment');
492
+        header("Content-Disposition: attachment; filename=system_status_".sanitize_key(site_url()).".html");
493 493
         echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>";
494
-        echo "<h1>System Information for " . site_url() . "</h1>";
495
-        echo EEH_Template::layout_array_as_table( $status_info );
494
+        echo "<h1>System Information for ".site_url()."</h1>";
495
+        echo EEH_Template::layout_array_as_table($status_info);
496 496
         die;
497 497
     }
498 498
 
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
         try {
507 507
             $success = wp_mail(EE_SUPPORT_EMAIL,
508 508
                 'Migration Crash Report',
509
-                $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
509
+                $body."/r/n<br>".print_r(EEM_System_Status::instance()->get_system_stati(), true),
510 510
                 array(
511 511
                     "from:$from_name<$from>",
512 512
                     //					'content-type:text/html charset=UTF-8'
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
             EE_MAINTENANCE_ADMIN_URL);
542 542
         $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'),
543 543
             EE_MAINTENANCE_ADMIN_URL);
544
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
544
+        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_confirm_migration_crash_report_sent.template.php';
545 545
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
546 546
             $this->_template_args, true);
547 547
         $this->display_admin_page_with_sidebar();
@@ -642,9 +642,9 @@  discard block
 block discarded – undo
642 642
         wp_enqueue_script('ee_admin_js');
643 643
 //		wp_enqueue_media();
644 644
 //		wp_enqueue_script('media-upload');
645
-        wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'),
645
+        wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL.'/ee-maintenance.js', array('jquery'),
646 646
             EVENT_ESPRESSO_VERSION, true);
647
-        wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(),
647
+        wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL.'ee-maintenance.css', array(),
648 648
             EVENT_ESPRESSO_VERSION);
649 649
         wp_enqueue_style('espresso_maintenance');
650 650
     }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Message_Resource_Manager.lib.php 2 patches
Indentation   +1016 added lines, -1016 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 
@@ -17,1021 +17,1021 @@  discard block
 block discarded – undo
17 17
 class EE_Message_Resource_Manager
18 18
 {
19 19
 
20
-    /**
21
-     * @type boolean $_initialized
22
-     */
23
-    protected $_initialized = false;
24
-
25
-    /**
26
-     * @type EE_Messenger_Collection $_messenger_collection_loader
27
-     */
28
-    protected $_messenger_collection_loader;
29
-
30
-    /**
31
-     * @type EE_Message_Type_Collection $_message_type_collection_loader
32
-     */
33
-    protected $_message_type_collection_loader;
34
-
35
-    /**
36
-     * @type EEM_Message_Template_Group $_message_template_group_model
37
-     */
38
-    protected $_message_template_group_model;
39
-
40
-    /**
41
-     * @type EE_messenger[]
42
-     */
43
-    protected $_installed_messengers = array();
44
-
45
-    /**
46
-     * @type EE_message_type[]
47
-     */
48
-    protected $_installed_message_types = array();
49
-
50
-    /**
51
-     * Array of active messengers.
52
-     * Format is this:
53
-     * array(
54
-     *      'messenger_name' => EE_messenger
55
-     * )
56
-     *
57
-     * @type EE_messenger[]
58
-     */
59
-    protected $_active_messengers = array();
60
-
61
-    /**
62
-     * Formatted array of active message types grouped per messenger.
63
-     * Format is this:
64
-     * array(
65
-     *      'messenger_name' => array(
66
-     *          'settings' => array(
67
-     *              '{messenger_name}-message_types' => array(
68
-     *                  'message_type_name' => array() //variable array of settings corresponding to message type.
69
-     *              )
70
-     *          )
71
-     *      )
72
-     * )
73
-     *
74
-     * @type array
75
-     */
76
-    protected $_active_message_types = array();
77
-
78
-
79
-    /**
80
-     * This holds the array of messengers and their corresponding message types that have
81
-     * been activated on a site at some point.  This is an important record that helps the messages system
82
-     * not accidentally reactivate something that was intentionally deactivated by a user.
83
-     *
84
-     * @type array
85
-     */
86
-    protected $_has_activated_messengers_and_message_types = array();
87
-
88
-    /**
89
-     * An array of unique message type contexts across all active message types.
90
-     * The array will be indexed by either 'slugs' or 'all'.
91
-     * The slugs index contains an array indexed by unique context slugs with the latest label representation for that
92
-     * slug. array(
93
-     *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
94
-     * );
95
-     * The all index returns an array in this format:
96
-     * array(
97
-     *      'message_type_name' => array(
98
-     *          'context_slug' => array(
99
-     *              'label' => 'localized label for context',
100
-     *              'description' => 'localized description for context'
101
-     *          )
102
-     *      )
103
-     * );
104
-     *
105
-     * @type array
106
-     */
107
-    protected $_contexts = array();
108
-
109
-
110
-    /**
111
-     * EE_Message_Resource_Manager constructor.
112
-     *
113
-     * @param \EE_Messenger_Collection_Loader    $Messenger_Collection_Loader
114
-     * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader
115
-     * @param \EEM_Message_Template_Group        $Message_Template_Group_Model
116
-     */
117
-    function __construct(
118
-        EE_Messenger_Collection_Loader $Messenger_Collection_Loader,
119
-        EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader,
120
-        EEM_Message_Template_Group $Message_Template_Group_Model
121
-    ) {
122
-        $this->_messenger_collection_loader    = $Messenger_Collection_Loader;
123
-        $this->_message_type_collection_loader = $Message_Type_Collection_Loader;
124
-        $this->_message_template_group_model   = $Message_Template_Group_Model;
125
-    }
126
-
127
-
128
-    /**
129
-     * @return void
130
-     */
131
-    protected function _initialize_collections()
132
-    {
133
-        if ($this->_initialized) {
134
-            return;
135
-        }
136
-        $this->_initialized = true;
137
-        $this->_messenger_collection_loader->load_messengers_from_folder();
138
-        $this->_message_type_collection_loader->load_message_types_from_folder();
139
-        $this->get_has_activated_messengers_option(true);
140
-        $this->_set_active_messengers_and_message_types();
141
-    }
142
-
143
-
144
-    /**
145
-     * @return EE_Messenger_Collection
146
-     */
147
-    public function messenger_collection()
148
-    {
149
-        $this->_initialize_collections();
150
-        return $this->_messenger_collection_loader->messenger_collection();
151
-    }
152
-
153
-
154
-    /**
155
-     * @return EE_messenger[]
156
-     */
157
-    public function active_messengers()
158
-    {
159
-        $this->_initialize_collections();
160
-        return $this->_active_messengers;
161
-    }
162
-
163
-
164
-    /**
165
-     * @param string $messenger_name
166
-     * @return \EE_messenger
167
-     */
168
-    public function get_messenger($messenger_name)
169
-    {
170
-        return $this->messenger_collection()->get_by_info($messenger_name);
171
-    }
172
-
173
-
174
-    /**
175
-     * This returns the corresponding EE_messenger object for the given string if it is active.
176
-     *
177
-     * @param string $messenger
178
-     * @return EE_messenger | null
179
-     */
180
-    public function get_active_messenger($messenger)
181
-    {
182
-        $this->_initialize_collections();
183
-        return ! empty($this->_active_messengers[$messenger]) ? $this->_active_messengers[$messenger] : null;
184
-    }
185
-
186
-
187
-    /**
188
-     * @return \EE_messenger[]
189
-     */
190
-    public function installed_messengers()
191
-    {
192
-        if (empty($this->_installed_messengers)) {
193
-            $this->_installed_messengers = array();
194
-            $this->messenger_collection()->rewind();
195
-            while ($this->messenger_collection()->valid()) {
196
-                $this->_installed_messengers[$this->messenger_collection()->current()->name] = $this->messenger_collection()->current();
197
-                $this->messenger_collection()->next();
198
-            }
199
-        }
200
-        return $this->_installed_messengers;
201
-    }
202
-
203
-
204
-    /**
205
-     * @param string $messenger_name
206
-     * @return \EE_messenger
207
-     * @throws \EE_Error
208
-     */
209
-    public function valid_messenger($messenger_name)
210
-    {
211
-        $messenger = $this->get_messenger($messenger_name);
212
-        if ($messenger instanceof EE_messenger) {
213
-            return $messenger;
214
-        }
215
-        throw new EE_Error(
216
-            sprintf(
217
-                __('The "%1$s" messenger is either invalid or not installed', 'event_espresso'),
218
-                $messenger_name
219
-            )
220
-        );
221
-    }
222
-
223
-
224
-    /**
225
-     * @return EE_Message_Type_Collection
226
-     */
227
-    public function message_type_collection()
228
-    {
229
-        $this->_initialize_collections();
230
-        return $this->_message_type_collection_loader->message_type_collection();
231
-    }
232
-
233
-
234
-    /**
235
-     * @return array
236
-     */
237
-    public function active_message_types()
238
-    {
239
-        $this->_initialize_collections();
240
-        return $this->_active_message_types;
241
-    }
242
-
243
-
244
-    /**
245
-     * @param string $message_type_name
246
-     * @return \EE_message_type
247
-     */
248
-    public function get_message_type($message_type_name)
249
-    {
250
-        return $this->message_type_collection()->get_by_info($message_type_name);
251
-    }
252
-
253
-
254
-    /**
255
-     * This returns the EE_message_type from the active message types array ( if present );
256
-     *
257
-     * @param string $messenger_name
258
-     * @param string $message_type_name
259
-     * @return \EE_message_type|null
260
-     */
261
-    public function get_active_message_type_for_messenger($messenger_name, $message_type_name)
262
-    {
263
-        return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
264
-            ? $this->get_message_type($message_type_name)
265
-            : null;
266
-    }
267
-
268
-
269
-    /**
270
-     * Returns whether the given message type is active for the given messenger.
271
-     *
272
-     * @param string $messenger_name
273
-     * @param string $message_type_name
274
-     * @return bool
275
-     */
276
-    public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
277
-    {
278
-        $this->_initialize_collections();
279
-        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
280
-    }
281
-
282
-
283
-    /**
284
-     * Returns whether the given messenger is active.
285
-     *
286
-     * @param string $messenger_name the name of the messenger to check if active.
287
-     * @return bool
288
-     */
289
-    public function is_messenger_active($messenger_name)
290
-    {
291
-        $this->_initialize_collections();
292
-        return ! empty($this->_active_message_types[$messenger_name]);
293
-    }
294
-
295
-
296
-    /**
297
-     * This returns any settings that might be on a message type for a messenger
298
-     *
299
-     * @param string $messenger_name    The slug of the messenger
300
-     * @param string $message_type_name The slug of the message type getting the settings for.
301
-     * @return array
302
-     */
303
-    public function get_message_type_settings_for_messenger($messenger_name, $message_type_name)
304
-    {
305
-        $settings = array();
306
-        if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
307
-            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'])
308
-                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']
309
-                : array();
310
-        }
311
-        return $settings;
312
-    }
313
-
314
-
315
-    /**
316
-     * Returns whether the given messenger name has active message types on it.
317
-     * Infers whether the messenger is active or not as well.
318
-     *
319
-     * @param string $messenger_name
320
-     * @return bool
321
-     */
322
-    public function messenger_has_active_message_types($messenger_name)
323
-    {
324
-        $this->_initialize_collections();
325
-        return
326
-            ! empty($this->_active_message_types[$messenger_name])
327
-            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']);
328
-    }
329
-
330
-
331
-    /**
332
-     * This checks the _active_message_types property for any active message types
333
-     * that are present for the given messenger and returns them.
334
-     *
335
-     * @since 4.9.0
336
-     * @param string $messenger_name The messenger being checked
337
-     * @return EE_message_type[]|array    (empty array if no active_message_types)
338
-     */
339
-    public function get_active_message_types_for_messenger($messenger_name)
340
-    {
341
-        $message_types = array();
342
-        if (! $this->messenger_has_active_message_types($messenger_name)) {
343
-            return $message_types;
344
-        }
345
-        $installed_message_types = $this->installed_message_types();
346
-        foreach ($installed_message_types as $message_type_name => $message_type) {
347
-            if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
348
-                $message_types[$message_type_name] = $message_type;
349
-            }
350
-        }
351
-        return $message_types;
352
-    }
353
-
354
-
355
-    /**
356
-     * This does NOT return the _active_message_types property but
357
-     * simply returns an array of active message type names from that property.
358
-     * (The _active_message_types property is indexed by messenger and active message_types per messenger).
359
-     *
360
-     * @return array message_type references (string)
361
-     */
362
-    public function list_of_active_message_types()
363
-    {
364
-        $active_message_type_names = array();
365
-        $this->_initialize_collections();
366
-        foreach ($this->_active_message_types as $messenger => $messenger_settings) {
367
-            if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) {
368
-                continue;
369
-            }
370
-            foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) {
371
-                if (! in_array($message_type_name, $active_message_type_names)) {
372
-                    $active_message_type_names[] = $message_type_name;
373
-                }
374
-            }
375
-        }
376
-        return $active_message_type_names;
377
-    }
378
-
379
-
380
-    /**
381
-     * Same as list_of_active_message_types() except this returns actual EE_message_type objects
382
-     *
383
-     * @since 4.9.0
384
-     * @return \EE_message_type[]
385
-     */
386
-    public function get_active_message_type_objects()
387
-    {
388
-        $active_message_types      = array();
389
-        $installed_message_types   = $this->installed_message_types();
390
-        $active_message_type_names = $this->list_of_active_message_types();
391
-        foreach ($active_message_type_names as $active_message_type_name) {
392
-            if (isset($installed_message_types[$active_message_type_name])) {
393
-                $active_message_types[$active_message_type_name] = $installed_message_types[$active_message_type_name];
394
-            }
395
-        }
396
-        return $active_message_types;
397
-    }
398
-
399
-
400
-    /**
401
-     * @return \EE_message_type[]
402
-     */
403
-    public function installed_message_types()
404
-    {
405
-        if (empty($this->_installed_message_types)) {
406
-            $this->message_type_collection()->rewind();
407
-            while ($this->message_type_collection()->valid()) {
408
-                $this->_installed_message_types[$this->message_type_collection()->current()->name] = $this->message_type_collection()->current();
409
-                $this->message_type_collection()->next();
410
-            }
411
-        }
412
-        return $this->_installed_message_types;
413
-    }
414
-
415
-
416
-    /**
417
-     * @param string $message_type_name
418
-     * @return \EE_message_type
419
-     * @throws \EE_Error
420
-     */
421
-    public function valid_message_type($message_type_name)
422
-    {
423
-        $message_type = $this->get_message_type($message_type_name);
424
-        if ($message_type instanceof EE_message_type) {
425
-            return $message_type;
426
-        }
427
-        throw new EE_Error(
428
-            sprintf(
429
-                __('The "%1$s" message type is either invalid or not installed', 'event_espresso'),
430
-                $message_type_name
431
-            )
432
-        );
433
-    }
434
-
435
-
436
-    /**
437
-     * valid_message_type_for_messenger
438
-     *
439
-     * @param EE_messenger $messenger
440
-     * @param string       $message_type_name
441
-     * @return boolean
442
-     * @throws \EE_Error
443
-     */
444
-    public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
445
-    {
446
-        $valid_message_types = $messenger->get_valid_message_types();
447
-        if (! in_array($message_type_name, $valid_message_types)) {
448
-            throw new EE_Error(
449
-                sprintf(
450
-                    __(
451
-                        'The message type (%1$s) sent to "%2$s" is not valid for the "%3$s" messenger.  Double-check the spelling and verify that message type has been registered as a valid type with the messenger.',
452
-                        'event_espresso'
453
-                    ),
454
-                    $message_type_name,
455
-                    __METHOD__,
456
-                    $messenger->name
457
-                )
458
-            );
459
-        }
460
-        return true;
461
-    }
462
-
463
-
464
-    /**
465
-     * Used to return active messengers array stored in the wp options table.
466
-     * If no value is present in the option then an empty array is returned.
467
-     *
468
-     * @param   bool $reset     If true then we ignore whether the option is cached on the _active_message_types
469
-     *                          property and pull directly from the db.  Otherwise whatever is currently on the
470
-     *                          $_active_message_types property is pulled.
471
-     * @return array
472
-     */
473
-    public function get_active_messengers_option($reset = false)
474
-    {
475
-        if ($reset) {
476
-            $this->_active_message_types = get_option('ee_active_messengers', array());
477
-        }
478
-        return $this->_active_message_types;
479
-    }
480
-
481
-
482
-    /**
483
-     * Used to update the active messengers array stored in the wp options table.
484
-     *
485
-     * @param array $active_messenger_settings Incoming data to save.  If empty, then the internal cached property
486
-     *                                         representing this data is used.
487
-     * @return bool FALSE if not updated, TRUE if updated.
488
-     */
489
-    public function update_active_messengers_option($active_messenger_settings = array())
490
-    {
491
-        $active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings;
492
-        //make sure _active_message_types is updated (this is the internal cache for the settings).
493
-        $this->_active_message_types = $active_messenger_settings;
494
-        return update_option('ee_active_messengers', $active_messenger_settings);
495
-    }
496
-
497
-
498
-    /**
499
-     * Used to return active messengers array stored in the wp options table.
500
-     * If no value is present in the option then an empty array is returned.
501
-     * The value is cached on the $_has_activated_messengers_and_message_types property for future calls.
502
-     *
503
-     * @param   bool $reset Used to indicate that any cached value should be ignored.
504
-     * @return array
505
-     */
506
-    public function get_has_activated_messengers_option($reset = false)
507
-    {
508
-        if ($reset || empty($this->_has_activated_messengers_and_message_types)) {
509
-            $this->_has_activated_messengers_and_message_types = get_option('ee_has_activated_messenger', array());
510
-        }
511
-        return $this->_has_activated_messengers_and_message_types;
512
-    }
513
-
514
-
515
-    /**
516
-     * Used to update the active messengers array stored in the wp options table.
517
-     *
518
-     * @param array $has_activated_messengers Incoming data to save.  If empty, then the internal cached property
519
-     *                                        representing this data is used.
520
-     * @return bool FALSE if not updated, TRUE if updated.
521
-     */
522
-    public function update_has_activated_messengers_option($has_activated_messengers = array())
523
-    {
524
-        //make sure the option has been retrieved from first so we don't overwrite it accidentally.
525
-        if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) {
526
-            $this->get_has_activated_messengers_option();
527
-        }
528
-        $has_activated_messengers = empty($has_activated_messengers)
529
-            ? $this->_has_activated_messengers_and_message_types
530
-            : $has_activated_messengers;
531
-        return update_option('ee_has_activated_messenger', $has_activated_messengers);
532
-    }
533
-
534
-
535
-    /**
536
-     * wrapper for _set_active_messengers_and_message_types()
537
-     */
538
-    public function reset_active_messengers_and_message_types()
539
-    {
540
-        $this->_set_active_messengers_and_message_types();
541
-    }
542
-
543
-
544
-    /**
545
-     * Generate list of active messengers and message types from collection.
546
-     * This sets up the active messengers from what is present in the database.
547
-     */
548
-    protected function _set_active_messengers_and_message_types()
549
-    {
550
-        //echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n";
551
-        // list of activated messengers as set via the admin
552
-        // note calling `get_active_messengers_options` also initializes the _active_message_types property.
553
-        $this->get_active_messengers_option(true);
554
-        $this->ensure_messengers_are_active(array(), false, true);
555
-        $this->update_active_messengers_option();
556
-        $this->update_has_activated_messengers_option();
557
-    }
558
-
559
-
560
-    /**
561
-     * Ensures that the specified messenger is currently active.
562
-     * If not, activates it and its default message types.
563
-     *
564
-     * @param string $messenger_name
565
-     * @param bool   $update_option Whether to update the option in the db or not.
566
-     * @return boolean true if either already active or successfully activated.
567
-     */
568
-    public function ensure_messenger_is_active($messenger_name, $update_option = true)
569
-    {
570
-        if (! isset($this->_active_messengers[$messenger_name])) {
571
-            try {
572
-                $this->activate_messenger($messenger_name, array(), $update_option);
573
-            } catch (EE_Error $e) {
574
-                EE_Error::add_error(
575
-                    $e->getMessage(),
576
-                    __FILE__,
577
-                    __FUNCTION__,
578
-                    __LINE__
579
-                );
580
-                return false;
581
-            }
582
-        }
583
-        return true;
584
-    }
585
-
586
-
587
-    /**
588
-     * This ensures the given array of messenger names is active in the system.
589
-     * Note, this method will not activate any NEW message types for the messenger when it is called. Instead,
590
-     * it will automatically activate the default message types for the messenger if its not active.
591
-     *
592
-     * @param array $messenger_names  Array of messenger names for messengers to be activated.  If an empty array
593
-     *                                (default) then will attempt to set the active messengers from the
594
-     *                                activated_messengers option
595
-     *                                (stored in $_active_message_types property).
596
-     * @param bool  $update_option    Whether to update the related active messengers option.
597
-     * @param bool  $verify           Whether to verify the messengers are installed before activating. Note if this is
598
-     *                                set to true and a messenger is indicated as active, but is NOT installed, then it
599
-     *                                will automatically be deactivated.
600
-     */
601
-    public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false)
602
-    {
603
-        $messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names;
604
-
605
-        $not_installed = array();
606
-        foreach ($messenger_names as $messenger_name) {
607
-            if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) {
608
-                $not_installed[] = $messenger_name;
609
-                $this->deactivate_messenger($messenger_name);
610
-                continue;
611
-            }
612
-            $this->ensure_messenger_is_active($messenger_name, $update_option);
613
-        }
614
-
615
-        if (! empty($not_installed_messenger)) {
616
-            EE_Error::add_error(
617
-                sprintf(
618
-                    __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
619
-                    '<br />',
620
-                    implode(', ', $not_installed_messenger)
621
-                ),
622
-                __FILE__, __FUNCTION__, __LINE__
623
-            );
624
-        }
625
-    }
626
-
627
-
628
-    /**
629
-     * Ensures that the specified message type for the given messenger is currently active, if not activates it.
630
-     * This ALSO ensures that the given messenger is active as well!
631
-     *
632
-     * @param string $message_type_name message type name.
633
-     * @param        $messenger_name
634
-     * @param bool   $update_option     Whether to update the option in the db or not.
635
-     * @return bool  Returns true if already is active or if was activated successfully.
636
-     * @throws \EE_Error
637
-     */
638
-    public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true)
639
-    {
640
-        // grab the messenger to work with.
641
-        $messenger = $this->valid_messenger($messenger_name);
642
-        if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) {
643
-            //ensure messenger is active (that's an inherent coupling between active message types and the
644
-            //messenger they are being activated for.
645
-            try {
646
-                if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
647
-                    //all is good so let's just get it active
648
-                    $this->activate_messenger($messenger_name, array($message_type_name), $update_option);
649
-                }
650
-            } catch (EE_Error $e) {
651
-                EE_Error::add_error(
652
-                    $e->getMessage(),
653
-                    __FILE__,
654
-                    __FUNCTION__,
655
-                    __LINE__
656
-                );
657
-                return false;
658
-            }
659
-        }
660
-        return true;
661
-    }
662
-
663
-
664
-    /**
665
-     * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a
666
-     * messenger are active in one go.
667
-     *
668
-     * @param array  $message_type_names Array of message type names to ensure are active.
669
-     * @param string $messenger_name     The name of the messenger that the message types are to be activated on.
670
-     * @param bool   $update_option      Whether to persist the activation to the database or not (default true).
671
-     */
672
-    public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
673
-    {
674
-        $message_type_names = (array)$message_type_names;
675
-        foreach ($message_type_names as $message_type_name) {
676
-            // note, intentionally not updating option here because we're in a loop.
677
-            // We'll follow the instructions of the incoming $update_option argument after the loop.
678
-            $this->ensure_message_type_is_active($message_type_name, $messenger_name, false);
679
-        }
680
-        if ($update_option) {
681
-            $this->update_active_messengers_option();
682
-            $this->update_has_activated_messengers_option();
683
-        }
684
-    }
685
-
686
-
687
-    /**
688
-     * Activates the specified messenger.
689
-     *
690
-     * @param string $messenger_name
691
-     * @param array  $message_type_names        An array of message type names to activate with this messenger.
692
-     *                                          If included we do NOT setup the default message types
693
-     *                                          (assuming they are already setup.)
694
-     * @param bool   $update_active_messengers_option
695
-     * @return array of generated templates
696
-     * @throws \EE_Error
697
-     */
698
-    public function activate_messenger(
699
-        $messenger_name,
700
-        $message_type_names = array(),
701
-        $update_active_messengers_option = true
702
-    ) {
703
-        $templates = array();
704
-        // grab the messenger to work with.
705
-        $messenger = $this->messenger_collection()->get_by_info($messenger_name);
706
-        // it's inactive. Activate it.
707
-        if ($messenger instanceof EE_messenger) {
708
-            $this->_active_messengers[$messenger->name] = $messenger;
709
-            //activate incoming message types set to be activated with messenger.
710
-            $message_type_names = $this->_activate_message_types($messenger, $message_type_names);
711
-            // setup any initial settings for the messenger if necessary.
712
-            $this->add_settings_for_messenger($messenger->name);
713
-            if ($update_active_messengers_option) {
714
-                $this->update_active_messengers_option();
715
-                $this->update_has_activated_messengers_option();
716
-            }
717
-            //generate new templates if necessary and ensure all related templates that are already in the database are
718
-            //marked active.  Note, this will also deactivate a message type for a messenger if the template
719
-            //cannot be successfully created during its attempt (only happens for global template attempts).
720
-            if (! empty($message_type_names)) {
721
-                $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
722
-                EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
723
-            }
724
-        }
725
-        return $templates;
726
-    }
727
-
728
-
729
-    /**
730
-     * Activates given message types for the given EE_messenger object.
731
-     * Note: (very important) This method does not persist the activation to the database.
732
-     * See code implementing this method in this class for examples of how to persist.
733
-     *
734
-     * @param \EE_messenger $messenger
735
-     * @param  array        $message_type_names
736
-     * @return array
737
-     */
738
-    protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array())
739
-    {
740
-        //If $message_type_names is empty, AND $this->_active_message_types is empty, then that means
741
-        //things have never been initialized (which should happen on EEH_Activation::generate_message_templates).
742
-        //So ONLY then do we need to actually grab defaults and cycle through them.  Otherwise we
743
-        //only override _active_message_types when an explicit array of $message_type_names has been provided.
744
-        $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
745
-            ? $messenger->get_default_message_types()
746
-            : (array)$message_type_names;
747
-
748
-        //now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
749
-        if (! isset($this->_active_message_types[$messenger->name])) {
750
-            $this->_active_message_types[$messenger->name]['settings'] = array();
751
-        }
752
-
753
-        if ($message_type_names) {
754
-            // cycle thru message types
755
-            foreach ($message_type_names as $message_type_name) {
756
-                //only register the message type as active IF it isn't already active
757
-                //and if its actually installed.
758
-                if (
759
-                ! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name)
760
-                ) {
761
-                    $this->add_settings_for_message_type($messenger->name, $message_type_name);
762
-                    $this->_set_messenger_has_activated_message_type(
763
-                        $messenger,
764
-                        $message_type_name
765
-                    );
766
-                }
767
-            }
768
-        }
769
-        return $message_type_names;
770
-    }
771
-
772
-
773
-    /**
774
-     * add_settings_for_message_type
775
-     * NOTE This does NOT automatically persist any settings to the db.  Client code should call
776
-     * $this->update_active_messengers_option to persist.
777
-     *
778
-     * @param  string $messenger_name    The name of the messenger adding the settings for
779
-     * @param  string $message_type_name The name of the message type adding the settings for
780
-     * @param  array  $new_settings      Any new settings being set for the message type and messenger
781
-     */
782
-    public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array())
783
-    {
784
-        // get installed message type from collection
785
-        $message_type      = $this->message_type_collection()->get_by_info($message_type_name);
786
-        $existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name);
787
-        //we need to setup any initial settings for message types
788
-        if ($message_type instanceof EE_message_type) {
789
-            $default_settings = $message_type->get_admin_settings_fields();
790
-            foreach ($default_settings as $field => $values) {
791
-                if (isset($new_settings[$field])) {
792
-                    $existing_settings[$field] = $new_settings[$field];
793
-                    continue;
794
-                }
795
-                if (! isset($existing_settings[$field])) {
796
-                    $existing_settings[$field] = $values['default'];
797
-                }
798
-            }
799
-        }
800
-        $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings;
801
-    }
802
-
803
-
804
-    /**
805
-     * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger
806
-     * and message type.
807
-     *
808
-     * @access protected
809
-     * @param \EE_messenger $messenger
810
-     * @param string        $message_type_name
811
-     */
812
-    protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name)
813
-    {
814
-
815
-        //if _has_activated_messengers_and_message_types is empty then lets ensure its initialized
816
-        if (empty($this->_has_activated_messengers_and_message_types)) {
817
-            $this->get_has_activated_messengers_option();
818
-        }
819
-
820
-        // make sure this messenger has a record in the has_activated array
821
-        if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
822
-            $this->_has_activated_messengers_and_message_types[$messenger->name] = array();
823
-        }
824
-        // check if message type has already been added
825
-        if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
826
-            $this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
827
-        }
828
-    }
829
-
830
-
831
-    /**
832
-     * add_settings_for_messenger
833
-     * NOTE This does NOT automatically persist any settings to the db.  Client code should call
834
-     * $this->update_active_messengers_option to persist.
835
-     *
836
-     * @param string $messenger_name The name of the messenger the settings is being added for.
837
-     * @param array  $new_settings   An array of settings to update the existing settings.
838
-     */
839
-    public function add_settings_for_messenger($messenger_name, $new_settings = array())
840
-    {
841
-        $messenger = $this->get_messenger($messenger_name);
842
-        if ($messenger instanceof EE_messenger) {
843
-            $msgr_settings = $messenger->get_admin_settings_fields();
844
-            if (! empty($msgr_settings)) {
845
-                foreach ($msgr_settings as $field => $value) {
846
-                    //is there a new setting for this?
847
-                    if (isset($new_settings[$field])) {
848
-                        $this->_active_message_types[$messenger->name]['settings'][$field] = $new_settings[$field];
849
-                        continue;
850
-                    }
851
-                    //only set the default if it isn't already set.
852
-                    if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
853
-                        $this->_active_message_types[$messenger->name]['settings'][$field] = $value;
854
-                    }
855
-                }
856
-            }
857
-        }
858
-    }
859
-
860
-
861
-    /**
862
-     * deactivate_messenger
863
-     *
864
-     * @param  string|EE_messenger $messenger_name name of messenger
865
-     * @return void
866
-     */
867
-    public function deactivate_messenger($messenger_name)
868
-    {
869
-        $this->_initialize_collections();
870
-        if ($messenger_name instanceof EE_messenger) {
871
-            $messenger_name = $messenger_name->name;
872
-        }
873
-        unset($this->_active_messengers[$messenger_name]);
874
-        unset($this->_active_message_types[$messenger_name]);
875
-        $this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name);
876
-        $this->update_active_messengers_option();
877
-    }
878
-
879
-
880
-    /**
881
-     * Deactivates a message type (note this will deactivate across all messenger's it is active on.
882
-     *
883
-     * @param  string $message_type_name name of message type being deactivated
884
-     */
885
-    public function deactivate_message_type($message_type_name)
886
-    {
887
-        $this->_initialize_collections();
888
-        if ($message_type_name instanceof EE_message_type) {
889
-            $message_type_name = $message_type_name->name;
890
-        }
891
-        foreach ($this->_active_message_types as $messenger_name => $settings) {
892
-            unset(
893
-                $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]
894
-            );
895
-
896
-            //we always record (even on deactivation) that a message type has been activated because there should at
897
-            //least be a record in the "has_activated" option that it WAS active at one point.
898
-            $messenger = $this->get_messenger($messenger_name);
899
-            $this->_set_messenger_has_activated_message_type($messenger, $message_type_name);
900
-        }
901
-        $this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name);
902
-        $this->update_active_messengers_option();
903
-        $this->update_has_activated_messengers_option();
904
-    }
905
-
906
-
907
-    /**
908
-     * Deactivates a message type for a specific messenger as opposed to all messengers.
909
-     *
910
-     * @param string $message_type_name Name of message type being deactivated.
911
-     * @param string $messenger_name    Name of messenger the message type is being deactivated for.
912
-     */
913
-    public function deactivate_message_type_for_messenger($message_type_name, $messenger_name)
914
-    {
915
-        $this->_initialize_collections();
916
-        if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
917
-            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
918
-        }
919
-        $this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name),
920
-            array($message_type_name));
921
-        $this->update_active_messengers_option();
922
-    }
923
-
924
-
925
-    /**
926
-     * Used to verify if a message can be sent for the given messenger and message type
927
-     * and that it is a generating messenger (used for generating message templates).
928
-     *
929
-     * @param EE_messenger    $messenger    messenger used in trigger
930
-     * @param EE_message_type $message_type message type used in trigger
931
-     * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
932
-     */
933
-    public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
934
-    {
935
-        //get the $messengers the message type says it can be used with.
936
-        foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) {
937
-            if (
938
-                $messenger->name === $generating_messenger
939
-                && $this->is_message_type_active_for_messenger($messenger->name, $message_type->name)
940
-            ) {
941
-                return true;
942
-            }
943
-        }
944
-        return false;
945
-    }
946
-
947
-
948
-    /**
949
-     * This returns all the contexts that are registered by all message types.
950
-     * If $slugs_only is true,
951
-     * then just an array indexed by unique context slugs with the latest label representation for that slug.
952
-     * array(
953
-     *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
954
-     * );
955
-     * If $slugs_only is false, then the format is:
956
-     * array(
957
-     *      'message_type_name' => array(
958
-     *          'context_slug' => array(
959
-     *              'label' => 'localized label for context',
960
-     *              'description' => 'localized description for context'
961
-     *          )
962
-     *      )
963
-     * );
964
-     * Keep in mind that although different message types may share the same context slugs,
965
-     * it is possible that the context is described differently by the message type.
966
-     *
967
-     * @since 4.9.0
968
-     * @param   bool $slugs_only Whether to return an array of just slugs and labels (true)
969
-     *                           or all contexts indexed by message type.
970
-     * @return array
971
-     */
972
-    public function get_all_contexts($slugs_only = true)
973
-    {
974
-        $key = $slugs_only ? 'slugs' : 'all';
975
-        // check if contexts has been setup yet.
976
-        if (empty($this->_contexts[$key])) {
977
-            // So let's get all active message type objects and loop through to get all unique contexts
978
-            foreach ($this->get_active_message_type_objects() as $message_type) {
979
-                if ($message_type instanceof EE_message_type) {
980
-                    $message_type_contexts = $message_type->get_contexts();
981
-                    if ($slugs_only) {
982
-                        foreach ($message_type_contexts as $context => $context_details) {
983
-                            $this->_contexts[$key][$context] = $context_details['label'];
984
-                        }
985
-                    } else {
986
-                        $this->_contexts[$key][$message_type->name] = $message_type_contexts;
987
-                    }
988
-                }
989
-            }
990
-        }
991
-        return ! empty($this->_contexts[$key]) ? $this->_contexts[$key] : array();
992
-    }
993
-
994
-
995
-    /**
996
-     * This checks the internal record of what message types are considered "active" and verifies that
997
-     * there is an installed class definition for that message type.  If the active message type does not have a
998
-     * corresponding accessible message type class then it will be deactivated from all messengers it is active on and
999
-     * any related message templates will be inactivated as well.
1000
-     *
1001
-     * @return bool   true means all active message types are valid, false means at least one message type was
1002
-     *                deactivated.
1003
-     */
1004
-    public function validate_active_message_types_are_installed()
1005
-    {
1006
-        $list_of_active_message_type_names = $this->list_of_active_message_types();
1007
-        $installed_message_types           = $this->installed_message_types();
1008
-        $all_message_types_valid           = true;
1009
-        //loop through list of active message types and verify they are installed.
1010
-        foreach ($list_of_active_message_type_names as $message_type_name) {
1011
-            if (! isset($installed_message_types[$message_type_name])) {
1012
-                $this->deactivate_message_type($message_type_name);
1013
-                $all_message_types_valid = false;
1014
-            }
1015
-        }
1016
-        return $all_message_types_valid;
1017
-    }
1018
-
1019
-
1020
-    /**
1021
-     * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been
1022
-     * activated for the given messenger.  This can be called by client code on plugin updates etc to determine whether
1023
-     * to attempt automatically reactivating message types that should be activated by default or not.
1024
-     *
1025
-     * @param $message_type_name
1026
-     * @param $messenger_name
1027
-     * @return bool
1028
-     */
1029
-    public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name)
1030
-    {
1031
-        $has_activated = $this->get_has_activated_messengers_option();
1032
-        return isset($has_activated[$messenger_name])
1033
-               && in_array($message_type_name, $has_activated[$messenger_name]);
1034
-    }
20
+	/**
21
+	 * @type boolean $_initialized
22
+	 */
23
+	protected $_initialized = false;
24
+
25
+	/**
26
+	 * @type EE_Messenger_Collection $_messenger_collection_loader
27
+	 */
28
+	protected $_messenger_collection_loader;
29
+
30
+	/**
31
+	 * @type EE_Message_Type_Collection $_message_type_collection_loader
32
+	 */
33
+	protected $_message_type_collection_loader;
34
+
35
+	/**
36
+	 * @type EEM_Message_Template_Group $_message_template_group_model
37
+	 */
38
+	protected $_message_template_group_model;
39
+
40
+	/**
41
+	 * @type EE_messenger[]
42
+	 */
43
+	protected $_installed_messengers = array();
44
+
45
+	/**
46
+	 * @type EE_message_type[]
47
+	 */
48
+	protected $_installed_message_types = array();
49
+
50
+	/**
51
+	 * Array of active messengers.
52
+	 * Format is this:
53
+	 * array(
54
+	 *      'messenger_name' => EE_messenger
55
+	 * )
56
+	 *
57
+	 * @type EE_messenger[]
58
+	 */
59
+	protected $_active_messengers = array();
60
+
61
+	/**
62
+	 * Formatted array of active message types grouped per messenger.
63
+	 * Format is this:
64
+	 * array(
65
+	 *      'messenger_name' => array(
66
+	 *          'settings' => array(
67
+	 *              '{messenger_name}-message_types' => array(
68
+	 *                  'message_type_name' => array() //variable array of settings corresponding to message type.
69
+	 *              )
70
+	 *          )
71
+	 *      )
72
+	 * )
73
+	 *
74
+	 * @type array
75
+	 */
76
+	protected $_active_message_types = array();
77
+
78
+
79
+	/**
80
+	 * This holds the array of messengers and their corresponding message types that have
81
+	 * been activated on a site at some point.  This is an important record that helps the messages system
82
+	 * not accidentally reactivate something that was intentionally deactivated by a user.
83
+	 *
84
+	 * @type array
85
+	 */
86
+	protected $_has_activated_messengers_and_message_types = array();
87
+
88
+	/**
89
+	 * An array of unique message type contexts across all active message types.
90
+	 * The array will be indexed by either 'slugs' or 'all'.
91
+	 * The slugs index contains an array indexed by unique context slugs with the latest label representation for that
92
+	 * slug. array(
93
+	 *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
94
+	 * );
95
+	 * The all index returns an array in this format:
96
+	 * array(
97
+	 *      'message_type_name' => array(
98
+	 *          'context_slug' => array(
99
+	 *              'label' => 'localized label for context',
100
+	 *              'description' => 'localized description for context'
101
+	 *          )
102
+	 *      )
103
+	 * );
104
+	 *
105
+	 * @type array
106
+	 */
107
+	protected $_contexts = array();
108
+
109
+
110
+	/**
111
+	 * EE_Message_Resource_Manager constructor.
112
+	 *
113
+	 * @param \EE_Messenger_Collection_Loader    $Messenger_Collection_Loader
114
+	 * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader
115
+	 * @param \EEM_Message_Template_Group        $Message_Template_Group_Model
116
+	 */
117
+	function __construct(
118
+		EE_Messenger_Collection_Loader $Messenger_Collection_Loader,
119
+		EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader,
120
+		EEM_Message_Template_Group $Message_Template_Group_Model
121
+	) {
122
+		$this->_messenger_collection_loader    = $Messenger_Collection_Loader;
123
+		$this->_message_type_collection_loader = $Message_Type_Collection_Loader;
124
+		$this->_message_template_group_model   = $Message_Template_Group_Model;
125
+	}
126
+
127
+
128
+	/**
129
+	 * @return void
130
+	 */
131
+	protected function _initialize_collections()
132
+	{
133
+		if ($this->_initialized) {
134
+			return;
135
+		}
136
+		$this->_initialized = true;
137
+		$this->_messenger_collection_loader->load_messengers_from_folder();
138
+		$this->_message_type_collection_loader->load_message_types_from_folder();
139
+		$this->get_has_activated_messengers_option(true);
140
+		$this->_set_active_messengers_and_message_types();
141
+	}
142
+
143
+
144
+	/**
145
+	 * @return EE_Messenger_Collection
146
+	 */
147
+	public function messenger_collection()
148
+	{
149
+		$this->_initialize_collections();
150
+		return $this->_messenger_collection_loader->messenger_collection();
151
+	}
152
+
153
+
154
+	/**
155
+	 * @return EE_messenger[]
156
+	 */
157
+	public function active_messengers()
158
+	{
159
+		$this->_initialize_collections();
160
+		return $this->_active_messengers;
161
+	}
162
+
163
+
164
+	/**
165
+	 * @param string $messenger_name
166
+	 * @return \EE_messenger
167
+	 */
168
+	public function get_messenger($messenger_name)
169
+	{
170
+		return $this->messenger_collection()->get_by_info($messenger_name);
171
+	}
172
+
173
+
174
+	/**
175
+	 * This returns the corresponding EE_messenger object for the given string if it is active.
176
+	 *
177
+	 * @param string $messenger
178
+	 * @return EE_messenger | null
179
+	 */
180
+	public function get_active_messenger($messenger)
181
+	{
182
+		$this->_initialize_collections();
183
+		return ! empty($this->_active_messengers[$messenger]) ? $this->_active_messengers[$messenger] : null;
184
+	}
185
+
186
+
187
+	/**
188
+	 * @return \EE_messenger[]
189
+	 */
190
+	public function installed_messengers()
191
+	{
192
+		if (empty($this->_installed_messengers)) {
193
+			$this->_installed_messengers = array();
194
+			$this->messenger_collection()->rewind();
195
+			while ($this->messenger_collection()->valid()) {
196
+				$this->_installed_messengers[$this->messenger_collection()->current()->name] = $this->messenger_collection()->current();
197
+				$this->messenger_collection()->next();
198
+			}
199
+		}
200
+		return $this->_installed_messengers;
201
+	}
202
+
203
+
204
+	/**
205
+	 * @param string $messenger_name
206
+	 * @return \EE_messenger
207
+	 * @throws \EE_Error
208
+	 */
209
+	public function valid_messenger($messenger_name)
210
+	{
211
+		$messenger = $this->get_messenger($messenger_name);
212
+		if ($messenger instanceof EE_messenger) {
213
+			return $messenger;
214
+		}
215
+		throw new EE_Error(
216
+			sprintf(
217
+				__('The "%1$s" messenger is either invalid or not installed', 'event_espresso'),
218
+				$messenger_name
219
+			)
220
+		);
221
+	}
222
+
223
+
224
+	/**
225
+	 * @return EE_Message_Type_Collection
226
+	 */
227
+	public function message_type_collection()
228
+	{
229
+		$this->_initialize_collections();
230
+		return $this->_message_type_collection_loader->message_type_collection();
231
+	}
232
+
233
+
234
+	/**
235
+	 * @return array
236
+	 */
237
+	public function active_message_types()
238
+	{
239
+		$this->_initialize_collections();
240
+		return $this->_active_message_types;
241
+	}
242
+
243
+
244
+	/**
245
+	 * @param string $message_type_name
246
+	 * @return \EE_message_type
247
+	 */
248
+	public function get_message_type($message_type_name)
249
+	{
250
+		return $this->message_type_collection()->get_by_info($message_type_name);
251
+	}
252
+
253
+
254
+	/**
255
+	 * This returns the EE_message_type from the active message types array ( if present );
256
+	 *
257
+	 * @param string $messenger_name
258
+	 * @param string $message_type_name
259
+	 * @return \EE_message_type|null
260
+	 */
261
+	public function get_active_message_type_for_messenger($messenger_name, $message_type_name)
262
+	{
263
+		return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
264
+			? $this->get_message_type($message_type_name)
265
+			: null;
266
+	}
267
+
268
+
269
+	/**
270
+	 * Returns whether the given message type is active for the given messenger.
271
+	 *
272
+	 * @param string $messenger_name
273
+	 * @param string $message_type_name
274
+	 * @return bool
275
+	 */
276
+	public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
277
+	{
278
+		$this->_initialize_collections();
279
+		return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
280
+	}
281
+
282
+
283
+	/**
284
+	 * Returns whether the given messenger is active.
285
+	 *
286
+	 * @param string $messenger_name the name of the messenger to check if active.
287
+	 * @return bool
288
+	 */
289
+	public function is_messenger_active($messenger_name)
290
+	{
291
+		$this->_initialize_collections();
292
+		return ! empty($this->_active_message_types[$messenger_name]);
293
+	}
294
+
295
+
296
+	/**
297
+	 * This returns any settings that might be on a message type for a messenger
298
+	 *
299
+	 * @param string $messenger_name    The slug of the messenger
300
+	 * @param string $message_type_name The slug of the message type getting the settings for.
301
+	 * @return array
302
+	 */
303
+	public function get_message_type_settings_for_messenger($messenger_name, $message_type_name)
304
+	{
305
+		$settings = array();
306
+		if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
307
+			$settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'])
308
+				? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']
309
+				: array();
310
+		}
311
+		return $settings;
312
+	}
313
+
314
+
315
+	/**
316
+	 * Returns whether the given messenger name has active message types on it.
317
+	 * Infers whether the messenger is active or not as well.
318
+	 *
319
+	 * @param string $messenger_name
320
+	 * @return bool
321
+	 */
322
+	public function messenger_has_active_message_types($messenger_name)
323
+	{
324
+		$this->_initialize_collections();
325
+		return
326
+			! empty($this->_active_message_types[$messenger_name])
327
+			&& ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']);
328
+	}
329
+
330
+
331
+	/**
332
+	 * This checks the _active_message_types property for any active message types
333
+	 * that are present for the given messenger and returns them.
334
+	 *
335
+	 * @since 4.9.0
336
+	 * @param string $messenger_name The messenger being checked
337
+	 * @return EE_message_type[]|array    (empty array if no active_message_types)
338
+	 */
339
+	public function get_active_message_types_for_messenger($messenger_name)
340
+	{
341
+		$message_types = array();
342
+		if (! $this->messenger_has_active_message_types($messenger_name)) {
343
+			return $message_types;
344
+		}
345
+		$installed_message_types = $this->installed_message_types();
346
+		foreach ($installed_message_types as $message_type_name => $message_type) {
347
+			if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
348
+				$message_types[$message_type_name] = $message_type;
349
+			}
350
+		}
351
+		return $message_types;
352
+	}
353
+
354
+
355
+	/**
356
+	 * This does NOT return the _active_message_types property but
357
+	 * simply returns an array of active message type names from that property.
358
+	 * (The _active_message_types property is indexed by messenger and active message_types per messenger).
359
+	 *
360
+	 * @return array message_type references (string)
361
+	 */
362
+	public function list_of_active_message_types()
363
+	{
364
+		$active_message_type_names = array();
365
+		$this->_initialize_collections();
366
+		foreach ($this->_active_message_types as $messenger => $messenger_settings) {
367
+			if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) {
368
+				continue;
369
+			}
370
+			foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) {
371
+				if (! in_array($message_type_name, $active_message_type_names)) {
372
+					$active_message_type_names[] = $message_type_name;
373
+				}
374
+			}
375
+		}
376
+		return $active_message_type_names;
377
+	}
378
+
379
+
380
+	/**
381
+	 * Same as list_of_active_message_types() except this returns actual EE_message_type objects
382
+	 *
383
+	 * @since 4.9.0
384
+	 * @return \EE_message_type[]
385
+	 */
386
+	public function get_active_message_type_objects()
387
+	{
388
+		$active_message_types      = array();
389
+		$installed_message_types   = $this->installed_message_types();
390
+		$active_message_type_names = $this->list_of_active_message_types();
391
+		foreach ($active_message_type_names as $active_message_type_name) {
392
+			if (isset($installed_message_types[$active_message_type_name])) {
393
+				$active_message_types[$active_message_type_name] = $installed_message_types[$active_message_type_name];
394
+			}
395
+		}
396
+		return $active_message_types;
397
+	}
398
+
399
+
400
+	/**
401
+	 * @return \EE_message_type[]
402
+	 */
403
+	public function installed_message_types()
404
+	{
405
+		if (empty($this->_installed_message_types)) {
406
+			$this->message_type_collection()->rewind();
407
+			while ($this->message_type_collection()->valid()) {
408
+				$this->_installed_message_types[$this->message_type_collection()->current()->name] = $this->message_type_collection()->current();
409
+				$this->message_type_collection()->next();
410
+			}
411
+		}
412
+		return $this->_installed_message_types;
413
+	}
414
+
415
+
416
+	/**
417
+	 * @param string $message_type_name
418
+	 * @return \EE_message_type
419
+	 * @throws \EE_Error
420
+	 */
421
+	public function valid_message_type($message_type_name)
422
+	{
423
+		$message_type = $this->get_message_type($message_type_name);
424
+		if ($message_type instanceof EE_message_type) {
425
+			return $message_type;
426
+		}
427
+		throw new EE_Error(
428
+			sprintf(
429
+				__('The "%1$s" message type is either invalid or not installed', 'event_espresso'),
430
+				$message_type_name
431
+			)
432
+		);
433
+	}
434
+
435
+
436
+	/**
437
+	 * valid_message_type_for_messenger
438
+	 *
439
+	 * @param EE_messenger $messenger
440
+	 * @param string       $message_type_name
441
+	 * @return boolean
442
+	 * @throws \EE_Error
443
+	 */
444
+	public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
445
+	{
446
+		$valid_message_types = $messenger->get_valid_message_types();
447
+		if (! in_array($message_type_name, $valid_message_types)) {
448
+			throw new EE_Error(
449
+				sprintf(
450
+					__(
451
+						'The message type (%1$s) sent to "%2$s" is not valid for the "%3$s" messenger.  Double-check the spelling and verify that message type has been registered as a valid type with the messenger.',
452
+						'event_espresso'
453
+					),
454
+					$message_type_name,
455
+					__METHOD__,
456
+					$messenger->name
457
+				)
458
+			);
459
+		}
460
+		return true;
461
+	}
462
+
463
+
464
+	/**
465
+	 * Used to return active messengers array stored in the wp options table.
466
+	 * If no value is present in the option then an empty array is returned.
467
+	 *
468
+	 * @param   bool $reset     If true then we ignore whether the option is cached on the _active_message_types
469
+	 *                          property and pull directly from the db.  Otherwise whatever is currently on the
470
+	 *                          $_active_message_types property is pulled.
471
+	 * @return array
472
+	 */
473
+	public function get_active_messengers_option($reset = false)
474
+	{
475
+		if ($reset) {
476
+			$this->_active_message_types = get_option('ee_active_messengers', array());
477
+		}
478
+		return $this->_active_message_types;
479
+	}
480
+
481
+
482
+	/**
483
+	 * Used to update the active messengers array stored in the wp options table.
484
+	 *
485
+	 * @param array $active_messenger_settings Incoming data to save.  If empty, then the internal cached property
486
+	 *                                         representing this data is used.
487
+	 * @return bool FALSE if not updated, TRUE if updated.
488
+	 */
489
+	public function update_active_messengers_option($active_messenger_settings = array())
490
+	{
491
+		$active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings;
492
+		//make sure _active_message_types is updated (this is the internal cache for the settings).
493
+		$this->_active_message_types = $active_messenger_settings;
494
+		return update_option('ee_active_messengers', $active_messenger_settings);
495
+	}
496
+
497
+
498
+	/**
499
+	 * Used to return active messengers array stored in the wp options table.
500
+	 * If no value is present in the option then an empty array is returned.
501
+	 * The value is cached on the $_has_activated_messengers_and_message_types property for future calls.
502
+	 *
503
+	 * @param   bool $reset Used to indicate that any cached value should be ignored.
504
+	 * @return array
505
+	 */
506
+	public function get_has_activated_messengers_option($reset = false)
507
+	{
508
+		if ($reset || empty($this->_has_activated_messengers_and_message_types)) {
509
+			$this->_has_activated_messengers_and_message_types = get_option('ee_has_activated_messenger', array());
510
+		}
511
+		return $this->_has_activated_messengers_and_message_types;
512
+	}
513
+
514
+
515
+	/**
516
+	 * Used to update the active messengers array stored in the wp options table.
517
+	 *
518
+	 * @param array $has_activated_messengers Incoming data to save.  If empty, then the internal cached property
519
+	 *                                        representing this data is used.
520
+	 * @return bool FALSE if not updated, TRUE if updated.
521
+	 */
522
+	public function update_has_activated_messengers_option($has_activated_messengers = array())
523
+	{
524
+		//make sure the option has been retrieved from first so we don't overwrite it accidentally.
525
+		if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) {
526
+			$this->get_has_activated_messengers_option();
527
+		}
528
+		$has_activated_messengers = empty($has_activated_messengers)
529
+			? $this->_has_activated_messengers_and_message_types
530
+			: $has_activated_messengers;
531
+		return update_option('ee_has_activated_messenger', $has_activated_messengers);
532
+	}
533
+
534
+
535
+	/**
536
+	 * wrapper for _set_active_messengers_and_message_types()
537
+	 */
538
+	public function reset_active_messengers_and_message_types()
539
+	{
540
+		$this->_set_active_messengers_and_message_types();
541
+	}
542
+
543
+
544
+	/**
545
+	 * Generate list of active messengers and message types from collection.
546
+	 * This sets up the active messengers from what is present in the database.
547
+	 */
548
+	protected function _set_active_messengers_and_message_types()
549
+	{
550
+		//echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n";
551
+		// list of activated messengers as set via the admin
552
+		// note calling `get_active_messengers_options` also initializes the _active_message_types property.
553
+		$this->get_active_messengers_option(true);
554
+		$this->ensure_messengers_are_active(array(), false, true);
555
+		$this->update_active_messengers_option();
556
+		$this->update_has_activated_messengers_option();
557
+	}
558
+
559
+
560
+	/**
561
+	 * Ensures that the specified messenger is currently active.
562
+	 * If not, activates it and its default message types.
563
+	 *
564
+	 * @param string $messenger_name
565
+	 * @param bool   $update_option Whether to update the option in the db or not.
566
+	 * @return boolean true if either already active or successfully activated.
567
+	 */
568
+	public function ensure_messenger_is_active($messenger_name, $update_option = true)
569
+	{
570
+		if (! isset($this->_active_messengers[$messenger_name])) {
571
+			try {
572
+				$this->activate_messenger($messenger_name, array(), $update_option);
573
+			} catch (EE_Error $e) {
574
+				EE_Error::add_error(
575
+					$e->getMessage(),
576
+					__FILE__,
577
+					__FUNCTION__,
578
+					__LINE__
579
+				);
580
+				return false;
581
+			}
582
+		}
583
+		return true;
584
+	}
585
+
586
+
587
+	/**
588
+	 * This ensures the given array of messenger names is active in the system.
589
+	 * Note, this method will not activate any NEW message types for the messenger when it is called. Instead,
590
+	 * it will automatically activate the default message types for the messenger if its not active.
591
+	 *
592
+	 * @param array $messenger_names  Array of messenger names for messengers to be activated.  If an empty array
593
+	 *                                (default) then will attempt to set the active messengers from the
594
+	 *                                activated_messengers option
595
+	 *                                (stored in $_active_message_types property).
596
+	 * @param bool  $update_option    Whether to update the related active messengers option.
597
+	 * @param bool  $verify           Whether to verify the messengers are installed before activating. Note if this is
598
+	 *                                set to true and a messenger is indicated as active, but is NOT installed, then it
599
+	 *                                will automatically be deactivated.
600
+	 */
601
+	public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false)
602
+	{
603
+		$messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names;
604
+
605
+		$not_installed = array();
606
+		foreach ($messenger_names as $messenger_name) {
607
+			if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) {
608
+				$not_installed[] = $messenger_name;
609
+				$this->deactivate_messenger($messenger_name);
610
+				continue;
611
+			}
612
+			$this->ensure_messenger_is_active($messenger_name, $update_option);
613
+		}
614
+
615
+		if (! empty($not_installed_messenger)) {
616
+			EE_Error::add_error(
617
+				sprintf(
618
+					__('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
619
+					'<br />',
620
+					implode(', ', $not_installed_messenger)
621
+				),
622
+				__FILE__, __FUNCTION__, __LINE__
623
+			);
624
+		}
625
+	}
626
+
627
+
628
+	/**
629
+	 * Ensures that the specified message type for the given messenger is currently active, if not activates it.
630
+	 * This ALSO ensures that the given messenger is active as well!
631
+	 *
632
+	 * @param string $message_type_name message type name.
633
+	 * @param        $messenger_name
634
+	 * @param bool   $update_option     Whether to update the option in the db or not.
635
+	 * @return bool  Returns true if already is active or if was activated successfully.
636
+	 * @throws \EE_Error
637
+	 */
638
+	public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true)
639
+	{
640
+		// grab the messenger to work with.
641
+		$messenger = $this->valid_messenger($messenger_name);
642
+		if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) {
643
+			//ensure messenger is active (that's an inherent coupling between active message types and the
644
+			//messenger they are being activated for.
645
+			try {
646
+				if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
647
+					//all is good so let's just get it active
648
+					$this->activate_messenger($messenger_name, array($message_type_name), $update_option);
649
+				}
650
+			} catch (EE_Error $e) {
651
+				EE_Error::add_error(
652
+					$e->getMessage(),
653
+					__FILE__,
654
+					__FUNCTION__,
655
+					__LINE__
656
+				);
657
+				return false;
658
+			}
659
+		}
660
+		return true;
661
+	}
662
+
663
+
664
+	/**
665
+	 * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a
666
+	 * messenger are active in one go.
667
+	 *
668
+	 * @param array  $message_type_names Array of message type names to ensure are active.
669
+	 * @param string $messenger_name     The name of the messenger that the message types are to be activated on.
670
+	 * @param bool   $update_option      Whether to persist the activation to the database or not (default true).
671
+	 */
672
+	public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
673
+	{
674
+		$message_type_names = (array)$message_type_names;
675
+		foreach ($message_type_names as $message_type_name) {
676
+			// note, intentionally not updating option here because we're in a loop.
677
+			// We'll follow the instructions of the incoming $update_option argument after the loop.
678
+			$this->ensure_message_type_is_active($message_type_name, $messenger_name, false);
679
+		}
680
+		if ($update_option) {
681
+			$this->update_active_messengers_option();
682
+			$this->update_has_activated_messengers_option();
683
+		}
684
+	}
685
+
686
+
687
+	/**
688
+	 * Activates the specified messenger.
689
+	 *
690
+	 * @param string $messenger_name
691
+	 * @param array  $message_type_names        An array of message type names to activate with this messenger.
692
+	 *                                          If included we do NOT setup the default message types
693
+	 *                                          (assuming they are already setup.)
694
+	 * @param bool   $update_active_messengers_option
695
+	 * @return array of generated templates
696
+	 * @throws \EE_Error
697
+	 */
698
+	public function activate_messenger(
699
+		$messenger_name,
700
+		$message_type_names = array(),
701
+		$update_active_messengers_option = true
702
+	) {
703
+		$templates = array();
704
+		// grab the messenger to work with.
705
+		$messenger = $this->messenger_collection()->get_by_info($messenger_name);
706
+		// it's inactive. Activate it.
707
+		if ($messenger instanceof EE_messenger) {
708
+			$this->_active_messengers[$messenger->name] = $messenger;
709
+			//activate incoming message types set to be activated with messenger.
710
+			$message_type_names = $this->_activate_message_types($messenger, $message_type_names);
711
+			// setup any initial settings for the messenger if necessary.
712
+			$this->add_settings_for_messenger($messenger->name);
713
+			if ($update_active_messengers_option) {
714
+				$this->update_active_messengers_option();
715
+				$this->update_has_activated_messengers_option();
716
+			}
717
+			//generate new templates if necessary and ensure all related templates that are already in the database are
718
+			//marked active.  Note, this will also deactivate a message type for a messenger if the template
719
+			//cannot be successfully created during its attempt (only happens for global template attempts).
720
+			if (! empty($message_type_names)) {
721
+				$templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
722
+				EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
723
+			}
724
+		}
725
+		return $templates;
726
+	}
727
+
728
+
729
+	/**
730
+	 * Activates given message types for the given EE_messenger object.
731
+	 * Note: (very important) This method does not persist the activation to the database.
732
+	 * See code implementing this method in this class for examples of how to persist.
733
+	 *
734
+	 * @param \EE_messenger $messenger
735
+	 * @param  array        $message_type_names
736
+	 * @return array
737
+	 */
738
+	protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array())
739
+	{
740
+		//If $message_type_names is empty, AND $this->_active_message_types is empty, then that means
741
+		//things have never been initialized (which should happen on EEH_Activation::generate_message_templates).
742
+		//So ONLY then do we need to actually grab defaults and cycle through them.  Otherwise we
743
+		//only override _active_message_types when an explicit array of $message_type_names has been provided.
744
+		$message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
745
+			? $messenger->get_default_message_types()
746
+			: (array)$message_type_names;
747
+
748
+		//now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
749
+		if (! isset($this->_active_message_types[$messenger->name])) {
750
+			$this->_active_message_types[$messenger->name]['settings'] = array();
751
+		}
752
+
753
+		if ($message_type_names) {
754
+			// cycle thru message types
755
+			foreach ($message_type_names as $message_type_name) {
756
+				//only register the message type as active IF it isn't already active
757
+				//and if its actually installed.
758
+				if (
759
+				! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name)
760
+				) {
761
+					$this->add_settings_for_message_type($messenger->name, $message_type_name);
762
+					$this->_set_messenger_has_activated_message_type(
763
+						$messenger,
764
+						$message_type_name
765
+					);
766
+				}
767
+			}
768
+		}
769
+		return $message_type_names;
770
+	}
771
+
772
+
773
+	/**
774
+	 * add_settings_for_message_type
775
+	 * NOTE This does NOT automatically persist any settings to the db.  Client code should call
776
+	 * $this->update_active_messengers_option to persist.
777
+	 *
778
+	 * @param  string $messenger_name    The name of the messenger adding the settings for
779
+	 * @param  string $message_type_name The name of the message type adding the settings for
780
+	 * @param  array  $new_settings      Any new settings being set for the message type and messenger
781
+	 */
782
+	public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array())
783
+	{
784
+		// get installed message type from collection
785
+		$message_type      = $this->message_type_collection()->get_by_info($message_type_name);
786
+		$existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name);
787
+		//we need to setup any initial settings for message types
788
+		if ($message_type instanceof EE_message_type) {
789
+			$default_settings = $message_type->get_admin_settings_fields();
790
+			foreach ($default_settings as $field => $values) {
791
+				if (isset($new_settings[$field])) {
792
+					$existing_settings[$field] = $new_settings[$field];
793
+					continue;
794
+				}
795
+				if (! isset($existing_settings[$field])) {
796
+					$existing_settings[$field] = $values['default'];
797
+				}
798
+			}
799
+		}
800
+		$this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings;
801
+	}
802
+
803
+
804
+	/**
805
+	 * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger
806
+	 * and message type.
807
+	 *
808
+	 * @access protected
809
+	 * @param \EE_messenger $messenger
810
+	 * @param string        $message_type_name
811
+	 */
812
+	protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name)
813
+	{
814
+
815
+		//if _has_activated_messengers_and_message_types is empty then lets ensure its initialized
816
+		if (empty($this->_has_activated_messengers_and_message_types)) {
817
+			$this->get_has_activated_messengers_option();
818
+		}
819
+
820
+		// make sure this messenger has a record in the has_activated array
821
+		if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
822
+			$this->_has_activated_messengers_and_message_types[$messenger->name] = array();
823
+		}
824
+		// check if message type has already been added
825
+		if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
826
+			$this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
827
+		}
828
+	}
829
+
830
+
831
+	/**
832
+	 * add_settings_for_messenger
833
+	 * NOTE This does NOT automatically persist any settings to the db.  Client code should call
834
+	 * $this->update_active_messengers_option to persist.
835
+	 *
836
+	 * @param string $messenger_name The name of the messenger the settings is being added for.
837
+	 * @param array  $new_settings   An array of settings to update the existing settings.
838
+	 */
839
+	public function add_settings_for_messenger($messenger_name, $new_settings = array())
840
+	{
841
+		$messenger = $this->get_messenger($messenger_name);
842
+		if ($messenger instanceof EE_messenger) {
843
+			$msgr_settings = $messenger->get_admin_settings_fields();
844
+			if (! empty($msgr_settings)) {
845
+				foreach ($msgr_settings as $field => $value) {
846
+					//is there a new setting for this?
847
+					if (isset($new_settings[$field])) {
848
+						$this->_active_message_types[$messenger->name]['settings'][$field] = $new_settings[$field];
849
+						continue;
850
+					}
851
+					//only set the default if it isn't already set.
852
+					if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
853
+						$this->_active_message_types[$messenger->name]['settings'][$field] = $value;
854
+					}
855
+				}
856
+			}
857
+		}
858
+	}
859
+
860
+
861
+	/**
862
+	 * deactivate_messenger
863
+	 *
864
+	 * @param  string|EE_messenger $messenger_name name of messenger
865
+	 * @return void
866
+	 */
867
+	public function deactivate_messenger($messenger_name)
868
+	{
869
+		$this->_initialize_collections();
870
+		if ($messenger_name instanceof EE_messenger) {
871
+			$messenger_name = $messenger_name->name;
872
+		}
873
+		unset($this->_active_messengers[$messenger_name]);
874
+		unset($this->_active_message_types[$messenger_name]);
875
+		$this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name);
876
+		$this->update_active_messengers_option();
877
+	}
878
+
879
+
880
+	/**
881
+	 * Deactivates a message type (note this will deactivate across all messenger's it is active on.
882
+	 *
883
+	 * @param  string $message_type_name name of message type being deactivated
884
+	 */
885
+	public function deactivate_message_type($message_type_name)
886
+	{
887
+		$this->_initialize_collections();
888
+		if ($message_type_name instanceof EE_message_type) {
889
+			$message_type_name = $message_type_name->name;
890
+		}
891
+		foreach ($this->_active_message_types as $messenger_name => $settings) {
892
+			unset(
893
+				$this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]
894
+			);
895
+
896
+			//we always record (even on deactivation) that a message type has been activated because there should at
897
+			//least be a record in the "has_activated" option that it WAS active at one point.
898
+			$messenger = $this->get_messenger($messenger_name);
899
+			$this->_set_messenger_has_activated_message_type($messenger, $message_type_name);
900
+		}
901
+		$this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name);
902
+		$this->update_active_messengers_option();
903
+		$this->update_has_activated_messengers_option();
904
+	}
905
+
906
+
907
+	/**
908
+	 * Deactivates a message type for a specific messenger as opposed to all messengers.
909
+	 *
910
+	 * @param string $message_type_name Name of message type being deactivated.
911
+	 * @param string $messenger_name    Name of messenger the message type is being deactivated for.
912
+	 */
913
+	public function deactivate_message_type_for_messenger($message_type_name, $messenger_name)
914
+	{
915
+		$this->_initialize_collections();
916
+		if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
917
+			unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
918
+		}
919
+		$this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name),
920
+			array($message_type_name));
921
+		$this->update_active_messengers_option();
922
+	}
923
+
924
+
925
+	/**
926
+	 * Used to verify if a message can be sent for the given messenger and message type
927
+	 * and that it is a generating messenger (used for generating message templates).
928
+	 *
929
+	 * @param EE_messenger    $messenger    messenger used in trigger
930
+	 * @param EE_message_type $message_type message type used in trigger
931
+	 * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
932
+	 */
933
+	public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
934
+	{
935
+		//get the $messengers the message type says it can be used with.
936
+		foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) {
937
+			if (
938
+				$messenger->name === $generating_messenger
939
+				&& $this->is_message_type_active_for_messenger($messenger->name, $message_type->name)
940
+			) {
941
+				return true;
942
+			}
943
+		}
944
+		return false;
945
+	}
946
+
947
+
948
+	/**
949
+	 * This returns all the contexts that are registered by all message types.
950
+	 * If $slugs_only is true,
951
+	 * then just an array indexed by unique context slugs with the latest label representation for that slug.
952
+	 * array(
953
+	 *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
954
+	 * );
955
+	 * If $slugs_only is false, then the format is:
956
+	 * array(
957
+	 *      'message_type_name' => array(
958
+	 *          'context_slug' => array(
959
+	 *              'label' => 'localized label for context',
960
+	 *              'description' => 'localized description for context'
961
+	 *          )
962
+	 *      )
963
+	 * );
964
+	 * Keep in mind that although different message types may share the same context slugs,
965
+	 * it is possible that the context is described differently by the message type.
966
+	 *
967
+	 * @since 4.9.0
968
+	 * @param   bool $slugs_only Whether to return an array of just slugs and labels (true)
969
+	 *                           or all contexts indexed by message type.
970
+	 * @return array
971
+	 */
972
+	public function get_all_contexts($slugs_only = true)
973
+	{
974
+		$key = $slugs_only ? 'slugs' : 'all';
975
+		// check if contexts has been setup yet.
976
+		if (empty($this->_contexts[$key])) {
977
+			// So let's get all active message type objects and loop through to get all unique contexts
978
+			foreach ($this->get_active_message_type_objects() as $message_type) {
979
+				if ($message_type instanceof EE_message_type) {
980
+					$message_type_contexts = $message_type->get_contexts();
981
+					if ($slugs_only) {
982
+						foreach ($message_type_contexts as $context => $context_details) {
983
+							$this->_contexts[$key][$context] = $context_details['label'];
984
+						}
985
+					} else {
986
+						$this->_contexts[$key][$message_type->name] = $message_type_contexts;
987
+					}
988
+				}
989
+			}
990
+		}
991
+		return ! empty($this->_contexts[$key]) ? $this->_contexts[$key] : array();
992
+	}
993
+
994
+
995
+	/**
996
+	 * This checks the internal record of what message types are considered "active" and verifies that
997
+	 * there is an installed class definition for that message type.  If the active message type does not have a
998
+	 * corresponding accessible message type class then it will be deactivated from all messengers it is active on and
999
+	 * any related message templates will be inactivated as well.
1000
+	 *
1001
+	 * @return bool   true means all active message types are valid, false means at least one message type was
1002
+	 *                deactivated.
1003
+	 */
1004
+	public function validate_active_message_types_are_installed()
1005
+	{
1006
+		$list_of_active_message_type_names = $this->list_of_active_message_types();
1007
+		$installed_message_types           = $this->installed_message_types();
1008
+		$all_message_types_valid           = true;
1009
+		//loop through list of active message types and verify they are installed.
1010
+		foreach ($list_of_active_message_type_names as $message_type_name) {
1011
+			if (! isset($installed_message_types[$message_type_name])) {
1012
+				$this->deactivate_message_type($message_type_name);
1013
+				$all_message_types_valid = false;
1014
+			}
1015
+		}
1016
+		return $all_message_types_valid;
1017
+	}
1018
+
1019
+
1020
+	/**
1021
+	 * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been
1022
+	 * activated for the given messenger.  This can be called by client code on plugin updates etc to determine whether
1023
+	 * to attempt automatically reactivating message types that should be activated by default or not.
1024
+	 *
1025
+	 * @param $message_type_name
1026
+	 * @param $messenger_name
1027
+	 * @return bool
1028
+	 */
1029
+	public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name)
1030
+	{
1031
+		$has_activated = $this->get_has_activated_messengers_option();
1032
+		return isset($has_activated[$messenger_name])
1033
+			   && in_array($message_type_name, $has_activated[$messenger_name]);
1034
+	}
1035 1035
 }
1036 1036
 // End of file EE_Message_Resource_Manager.lib.php
1037 1037
 // Location: /EE_Message_Resource_Manager.lib.php
1038 1038
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (! defined('EVENT_ESPRESSO_VERSION')) {
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('No direct script access allowed');
5 5
 }
6 6
 
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
     public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
277 277
     {
278 278
         $this->_initialize_collections();
279
-        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
279
+        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]);
280 280
     }
281 281
 
282 282
 
@@ -304,8 +304,8 @@  discard block
 block discarded – undo
304 304
     {
305 305
         $settings = array();
306 306
         if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
307
-            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'])
308
-                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']
307
+            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'])
308
+                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings']
309 309
                 : array();
310 310
         }
311 311
         return $settings;
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
         $this->_initialize_collections();
325 325
         return
326 326
             ! empty($this->_active_message_types[$messenger_name])
327
-            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']);
327
+            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types']);
328 328
     }
329 329
 
330 330
 
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
     public function get_active_message_types_for_messenger($messenger_name)
340 340
     {
341 341
         $message_types = array();
342
-        if (! $this->messenger_has_active_message_types($messenger_name)) {
342
+        if ( ! $this->messenger_has_active_message_types($messenger_name)) {
343 343
             return $message_types;
344 344
         }
345 345
         $installed_message_types = $this->installed_message_types();
@@ -364,11 +364,11 @@  discard block
 block discarded – undo
364 364
         $active_message_type_names = array();
365 365
         $this->_initialize_collections();
366 366
         foreach ($this->_active_message_types as $messenger => $messenger_settings) {
367
-            if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) {
367
+            if ( ! isset($messenger_settings['settings'][$messenger.'-message_types'])) {
368 368
                 continue;
369 369
             }
370
-            foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) {
371
-                if (! in_array($message_type_name, $active_message_type_names)) {
370
+            foreach ($messenger_settings['settings'][$messenger.'-message_types'] as $message_type_name => $message_type_config) {
371
+                if ( ! in_array($message_type_name, $active_message_type_names)) {
372 372
                     $active_message_type_names[] = $message_type_name;
373 373
                 }
374 374
             }
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
     public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
445 445
     {
446 446
         $valid_message_types = $messenger->get_valid_message_types();
447
-        if (! in_array($message_type_name, $valid_message_types)) {
447
+        if ( ! in_array($message_type_name, $valid_message_types)) {
448 448
             throw new EE_Error(
449 449
                 sprintf(
450 450
                     __(
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
      */
568 568
     public function ensure_messenger_is_active($messenger_name, $update_option = true)
569 569
     {
570
-        if (! isset($this->_active_messengers[$messenger_name])) {
570
+        if ( ! isset($this->_active_messengers[$messenger_name])) {
571 571
             try {
572 572
                 $this->activate_messenger($messenger_name, array(), $update_option);
573 573
             } catch (EE_Error $e) {
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
             $this->ensure_messenger_is_active($messenger_name, $update_option);
613 613
         }
614 614
 
615
-        if (! empty($not_installed_messenger)) {
615
+        if ( ! empty($not_installed_messenger)) {
616 616
             EE_Error::add_error(
617 617
                 sprintf(
618 618
                     __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
             //ensure messenger is active (that's an inherent coupling between active message types and the
644 644
             //messenger they are being activated for.
645 645
             try {
646
-                if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
646
+                if ( ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
647 647
                     //all is good so let's just get it active
648 648
                     $this->activate_messenger($messenger_name, array($message_type_name), $update_option);
649 649
                 }
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
      */
672 672
     public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
673 673
     {
674
-        $message_type_names = (array)$message_type_names;
674
+        $message_type_names = (array) $message_type_names;
675 675
         foreach ($message_type_names as $message_type_name) {
676 676
             // note, intentionally not updating option here because we're in a loop.
677 677
             // We'll follow the instructions of the incoming $update_option argument after the loop.
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
             //generate new templates if necessary and ensure all related templates that are already in the database are
718 718
             //marked active.  Note, this will also deactivate a message type for a messenger if the template
719 719
             //cannot be successfully created during its attempt (only happens for global template attempts).
720
-            if (! empty($message_type_names)) {
720
+            if ( ! empty($message_type_names)) {
721 721
                 $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
722 722
                 EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
723 723
             }
@@ -743,10 +743,10 @@  discard block
 block discarded – undo
743 743
         //only override _active_message_types when an explicit array of $message_type_names has been provided.
744 744
         $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
745 745
             ? $messenger->get_default_message_types()
746
-            : (array)$message_type_names;
746
+            : (array) $message_type_names;
747 747
 
748 748
         //now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
749
-        if (! isset($this->_active_message_types[$messenger->name])) {
749
+        if ( ! isset($this->_active_message_types[$messenger->name])) {
750 750
             $this->_active_message_types[$messenger->name]['settings'] = array();
751 751
         }
752 752
 
@@ -792,12 +792,12 @@  discard block
 block discarded – undo
792 792
                     $existing_settings[$field] = $new_settings[$field];
793 793
                     continue;
794 794
                 }
795
-                if (! isset($existing_settings[$field])) {
795
+                if ( ! isset($existing_settings[$field])) {
796 796
                     $existing_settings[$field] = $values['default'];
797 797
                 }
798 798
             }
799 799
         }
800
-        $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings;
800
+        $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'] = $existing_settings;
801 801
     }
802 802
 
803 803
 
@@ -818,11 +818,11 @@  discard block
 block discarded – undo
818 818
         }
819 819
 
820 820
         // make sure this messenger has a record in the has_activated array
821
-        if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
821
+        if ( ! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
822 822
             $this->_has_activated_messengers_and_message_types[$messenger->name] = array();
823 823
         }
824 824
         // check if message type has already been added
825
-        if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
825
+        if ( ! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
826 826
             $this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
827 827
         }
828 828
     }
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
         $messenger = $this->get_messenger($messenger_name);
842 842
         if ($messenger instanceof EE_messenger) {
843 843
             $msgr_settings = $messenger->get_admin_settings_fields();
844
-            if (! empty($msgr_settings)) {
844
+            if ( ! empty($msgr_settings)) {
845 845
                 foreach ($msgr_settings as $field => $value) {
846 846
                     //is there a new setting for this?
847 847
                     if (isset($new_settings[$field])) {
@@ -849,7 +849,7 @@  discard block
 block discarded – undo
849 849
                         continue;
850 850
                     }
851 851
                     //only set the default if it isn't already set.
852
-                    if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
852
+                    if ( ! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
853 853
                         $this->_active_message_types[$messenger->name]['settings'][$field] = $value;
854 854
                     }
855 855
                 }
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
         }
891 891
         foreach ($this->_active_message_types as $messenger_name => $settings) {
892 892
             unset(
893
-                $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]
893
+                $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]
894 894
             );
895 895
 
896 896
             //we always record (even on deactivation) that a message type has been activated because there should at
@@ -914,7 +914,7 @@  discard block
 block discarded – undo
914 914
     {
915 915
         $this->_initialize_collections();
916 916
         if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
917
-            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
917
+            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]);
918 918
         }
919 919
         $this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name),
920 920
             array($message_type_name));
@@ -1008,7 +1008,7 @@  discard block
 block discarded – undo
1008 1008
         $all_message_types_valid           = true;
1009 1009
         //loop through list of active message types and verify they are installed.
1010 1010
         foreach ($list_of_active_message_type_names as $message_type_name) {
1011
-            if (! isset($installed_message_types[$message_type_name])) {
1011
+            if ( ! isset($installed_message_types[$message_type_name])) {
1012 1012
                 $this->deactivate_message_type($message_type_name);
1013 1013
                 $all_message_types_valid = false;
1014 1014
             }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,243 +40,243 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                ); ?>
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+				); ?>
56 56
             </p>
57 57
         </div>
58 58
         <?php
59
-        espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
-    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
+	if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                            esc_html__(
79
-                                    'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                                    'event_espresso'
81
-                            ),
82
-                            EE_MIN_PHP_VER_REQUIRED,
83
-                            PHP_VERSION,
84
-                            '<br/>',
85
-                            '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+							esc_html__(
79
+									'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+									'event_espresso'
81
+							),
82
+							EE_MIN_PHP_VER_REQUIRED,
83
+							PHP_VERSION,
84
+							'<br/>',
85
+							'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.38.rc.002');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.38.rc.002');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        // for older WP versions
197
-        if ( ! defined('MONTH_IN_SECONDS')) {
198
-            define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
-        }
200
-        /**
201
-         *    espresso_plugin_activation
202
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
-         */
204
-        function espresso_plugin_activation()
205
-        {
206
-            update_option('ee_espresso_activation', true);
207
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		// for older WP versions
197
+		if ( ! defined('MONTH_IN_SECONDS')) {
198
+			define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
+		}
200
+		/**
201
+		 *    espresso_plugin_activation
202
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
+		 */
204
+		function espresso_plugin_activation()
205
+		{
206
+			update_option('ee_espresso_activation', true);
207
+		}
208 208
 
209
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
-        /**
211
-         *    espresso_load_error_handling
212
-         *    this function loads EE's class for handling exceptions and errors
213
-         */
214
-        function espresso_load_error_handling()
215
-        {
216
-            // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
-                EEH_Debug_Tools::instance();
220
-            }
221
-            // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
224
-            } else {
225
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
-            }
227
-        }
209
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
+		/**
211
+		 *    espresso_load_error_handling
212
+		 *    this function loads EE's class for handling exceptions and errors
213
+		 */
214
+		function espresso_load_error_handling()
215
+		{
216
+			// load debugging tools
217
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
+				EEH_Debug_Tools::instance();
220
+			}
221
+			// load error handling
222
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
+				require_once(EE_CORE . 'EE_Error.core.php');
224
+			} else {
225
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
+			}
227
+		}
228 228
 
229
-        /**
230
-         *    espresso_load_required
231
-         *    given a class name and path, this function will load that file or throw an exception
232
-         *
233
-         * @param    string $classname
234
-         * @param    string $full_path_to_file
235
-         * @throws    EE_Error
236
-         */
237
-        function espresso_load_required($classname, $full_path_to_file)
238
-        {
239
-            static $error_handling_loaded = false;
240
-            if ( ! $error_handling_loaded) {
241
-                espresso_load_error_handling();
242
-                $error_handling_loaded = true;
243
-            }
244
-            if (is_readable($full_path_to_file)) {
245
-                require_once($full_path_to_file);
246
-            } else {
247
-                throw new EE_Error (
248
-                        sprintf(
249
-                                esc_html__(
250
-                                        'The %s class file could not be located or is not readable due to file permissions.',
251
-                                        'event_espresso'
252
-                                ),
253
-                                $classname
254
-                        )
255
-                );
256
-            }
257
-        }
229
+		/**
230
+		 *    espresso_load_required
231
+		 *    given a class name and path, this function will load that file or throw an exception
232
+		 *
233
+		 * @param    string $classname
234
+		 * @param    string $full_path_to_file
235
+		 * @throws    EE_Error
236
+		 */
237
+		function espresso_load_required($classname, $full_path_to_file)
238
+		{
239
+			static $error_handling_loaded = false;
240
+			if ( ! $error_handling_loaded) {
241
+				espresso_load_error_handling();
242
+				$error_handling_loaded = true;
243
+			}
244
+			if (is_readable($full_path_to_file)) {
245
+				require_once($full_path_to_file);
246
+			} else {
247
+				throw new EE_Error (
248
+						sprintf(
249
+								esc_html__(
250
+										'The %s class file could not be located or is not readable due to file permissions.',
251
+										'event_espresso'
252
+								),
253
+								$classname
254
+						)
255
+				);
256
+			}
257
+		}
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
-        new EE_Bootstrap();
263
-    }
259
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
+		new EE_Bootstrap();
263
+	}
264 264
 }
265 265
 if ( ! function_exists('espresso_deactivate_plugin')) {
266
-    /**
267
-     *    deactivate_plugin
268
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
-     *
270
-     * @access public
271
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
-     * @return    void
273
-     */
274
-    function espresso_deactivate_plugin($plugin_basename = '')
275
-    {
276
-        if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
-        }
279
-        unset($_GET['activate'], $_REQUEST['activate']);
280
-        deactivate_plugins($plugin_basename);
281
-    }
266
+	/**
267
+	 *    deactivate_plugin
268
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
+	 *
270
+	 * @access public
271
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
+	 * @return    void
273
+	 */
274
+	function espresso_deactivate_plugin($plugin_basename = '')
275
+	{
276
+		if ( ! function_exists('deactivate_plugins')) {
277
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
+		}
279
+		unset($_GET['activate'], $_REQUEST['activate']);
280
+		deactivate_plugins($plugin_basename);
281
+	}
282 282
 }
283 283
\ No newline at end of file
Please login to merge, or discard this patch.
form_sections/strategies/normalization/EE_Int_Normalization.strategy.php 2 patches
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -15,89 +15,89 @@  discard block
 block discarded – undo
15 15
 class EE_Int_Normalization extends EE_Normalization_Strategy_Base
16 16
 {
17 17
 
18
-    /*
18
+	/*
19 19
      * regex pattern that matches for the following:
20 20
      *      * optional negative sign
21 21
      *      * one or more digits
22 22
      */
23
-    const REGEX = '/^(-?)(\d+)(?:\.0+)?$/';
23
+	const REGEX = '/^(-?)(\d+)(?:\.0+)?$/';
24 24
 
25 25
 
26
-    /**
27
-     * @param string $value_to_normalize
28
-     * @return int|mixed|string
29
-     * @throws \EE_Validation_Error
30
-     */
31
-    public function normalize($value_to_normalize)
32
-    {
33
-        if ($value_to_normalize === null) {
34
-            return null;
35
-        }
36
-        if (is_int($value_to_normalize) || is_float($value_to_normalize)) {
37
-            return (int)$value_to_normalize;
38
-        }
39
-        if (! is_string($value_to_normalize)) {
40
-            throw new EE_Validation_Error(
41
-                sprintf(
42
-                    __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'),
43
-                    print_r($value_to_normalize, true),
44
-                    gettype($value_to_normalize)
45
-                )
46
-            );
47
-        }
48
-        $value_to_normalize = filter_var(
49
-            $value_to_normalize,
50
-            FILTER_SANITIZE_NUMBER_FLOAT,
51
-            FILTER_FLAG_ALLOW_FRACTION
52
-        );
53
-        if ($value_to_normalize === '') {
54
-            return null;
55
-        }
56
-        $matches = array();
57
-        if (preg_match(EE_Int_Normalization::REGEX, $value_to_normalize, $matches)) {
58
-            if (count($matches) === 3) {
59
-                // if first match is the negative sign,
60
-                // then the number needs to be multiplied by -1 to remain negative
61
-                return $matches[1] === '-'
62
-                    ? (int)$matches[2] * -1
63
-                    : (int)$matches[2];
64
-            }
65
-        }
66
-        //find if this input has a int validation strategy
67
-        //in which case, use its message
68
-        $validation_error_message = null;
69
-        foreach ($this->_input->get_validation_strategies() as $validation_strategy) {
70
-            if ($validation_strategy instanceof EE_Int_Validation_Strategy) {
71
-                $validation_error_message = $validation_strategy->get_validation_error_message();
72
-            }
73
-        }
74
-        //this really shouldn't ever happen because fields with a int normalization strategy
75
-        //should also have a int validation strategy, but in case it doesn't use the default
76
-        if (! $validation_error_message) {
77
-            $default_validation_strategy = new EE_Int_Validation_Strategy();
78
-            $validation_error_message = $default_validation_strategy->get_validation_error_message();
79
-        }
80
-        throw new EE_Validation_Error($validation_error_message, 'numeric_only');
81
-    }
26
+	/**
27
+	 * @param string $value_to_normalize
28
+	 * @return int|mixed|string
29
+	 * @throws \EE_Validation_Error
30
+	 */
31
+	public function normalize($value_to_normalize)
32
+	{
33
+		if ($value_to_normalize === null) {
34
+			return null;
35
+		}
36
+		if (is_int($value_to_normalize) || is_float($value_to_normalize)) {
37
+			return (int)$value_to_normalize;
38
+		}
39
+		if (! is_string($value_to_normalize)) {
40
+			throw new EE_Validation_Error(
41
+				sprintf(
42
+					__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'),
43
+					print_r($value_to_normalize, true),
44
+					gettype($value_to_normalize)
45
+				)
46
+			);
47
+		}
48
+		$value_to_normalize = filter_var(
49
+			$value_to_normalize,
50
+			FILTER_SANITIZE_NUMBER_FLOAT,
51
+			FILTER_FLAG_ALLOW_FRACTION
52
+		);
53
+		if ($value_to_normalize === '') {
54
+			return null;
55
+		}
56
+		$matches = array();
57
+		if (preg_match(EE_Int_Normalization::REGEX, $value_to_normalize, $matches)) {
58
+			if (count($matches) === 3) {
59
+				// if first match is the negative sign,
60
+				// then the number needs to be multiplied by -1 to remain negative
61
+				return $matches[1] === '-'
62
+					? (int)$matches[2] * -1
63
+					: (int)$matches[2];
64
+			}
65
+		}
66
+		//find if this input has a int validation strategy
67
+		//in which case, use its message
68
+		$validation_error_message = null;
69
+		foreach ($this->_input->get_validation_strategies() as $validation_strategy) {
70
+			if ($validation_strategy instanceof EE_Int_Validation_Strategy) {
71
+				$validation_error_message = $validation_strategy->get_validation_error_message();
72
+			}
73
+		}
74
+		//this really shouldn't ever happen because fields with a int normalization strategy
75
+		//should also have a int validation strategy, but in case it doesn't use the default
76
+		if (! $validation_error_message) {
77
+			$default_validation_strategy = new EE_Int_Validation_Strategy();
78
+			$validation_error_message = $default_validation_strategy->get_validation_error_message();
79
+		}
80
+		throw new EE_Validation_Error($validation_error_message, 'numeric_only');
81
+	}
82 82
 
83 83
 
84 84
 
85
-    /**
86
-     * Converts the int into a string for use in teh html form
87
-     *
88
-     * @param int $normalized_value
89
-     * @return string
90
-     */
91
-    public function unnormalize($normalized_value)
92
-    {
93
-        if ($normalized_value === null || $normalized_value === '') {
94
-            return '';
95
-        }
96
-        if (empty($normalized_value)) {
97
-            return '0';
98
-        }
99
-        return "$normalized_value";
100
-    }
85
+	/**
86
+	 * Converts the int into a string for use in teh html form
87
+	 *
88
+	 * @param int $normalized_value
89
+	 * @return string
90
+	 */
91
+	public function unnormalize($normalized_value)
92
+	{
93
+		if ($normalized_value === null || $normalized_value === '') {
94
+			return '';
95
+		}
96
+		if (empty($normalized_value)) {
97
+			return '0';
98
+		}
99
+		return "$normalized_value";
100
+	}
101 101
 }
102 102
 
103 103
 // End of file EE_Int_Normalization.strategy.php
104 104
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
@@ -34,9 +34,9 @@  discard block
 block discarded – undo
34 34
             return null;
35 35
         }
36 36
         if (is_int($value_to_normalize) || is_float($value_to_normalize)) {
37
-            return (int)$value_to_normalize;
37
+            return (int) $value_to_normalize;
38 38
         }
39
-        if (! is_string($value_to_normalize)) {
39
+        if ( ! is_string($value_to_normalize)) {
40 40
             throw new EE_Validation_Error(
41 41
                 sprintf(
42 42
                     __('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'),
@@ -59,8 +59,8 @@  discard block
 block discarded – undo
59 59
                 // if first match is the negative sign,
60 60
                 // then the number needs to be multiplied by -1 to remain negative
61 61
                 return $matches[1] === '-'
62
-                    ? (int)$matches[2] * -1
63
-                    : (int)$matches[2];
62
+                    ? (int) $matches[2] * -1
63
+                    : (int) $matches[2];
64 64
             }
65 65
         }
66 66
         //find if this input has a int validation strategy
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
         }
74 74
         //this really shouldn't ever happen because fields with a int normalization strategy
75 75
         //should also have a int validation strategy, but in case it doesn't use the default
76
-        if (! $validation_error_message) {
76
+        if ( ! $validation_error_message) {
77 77
             $default_validation_strategy = new EE_Int_Validation_Strategy();
78 78
             $validation_error_message = $default_validation_strategy->get_validation_error_message();
79 79
         }
Please login to merge, or discard this patch.