@@ -1,6 +1,6 @@ discard block |
||
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 | |
@@ -19,263 +19,263 @@ discard block |
||
19 | 19 | |
20 | 20 | |
21 | 21 | |
22 | - protected function _init_page_props() |
|
23 | - { |
|
24 | - $this->page_slug = EE_SUPPORT_PG_SLUG; |
|
25 | - $this->page_label = esc_html__('Help & Support', 'event_espresso'); |
|
26 | - $this->_admin_base_url = EE_SUPPORT_ADMIN_URL; |
|
27 | - $this->_admin_base_path = EE_SUPPORT_ADMIN; |
|
28 | - } |
|
22 | + protected function _init_page_props() |
|
23 | + { |
|
24 | + $this->page_slug = EE_SUPPORT_PG_SLUG; |
|
25 | + $this->page_label = esc_html__('Help & Support', 'event_espresso'); |
|
26 | + $this->_admin_base_url = EE_SUPPORT_ADMIN_URL; |
|
27 | + $this->_admin_base_path = EE_SUPPORT_ADMIN; |
|
28 | + } |
|
29 | 29 | |
30 | 30 | |
31 | 31 | |
32 | - protected function _ajax_hooks() |
|
33 | - { |
|
34 | - } |
|
32 | + protected function _ajax_hooks() |
|
33 | + { |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | 37 | |
38 | - protected function _define_page_props() |
|
39 | - { |
|
40 | - $this->_labels = array(); |
|
41 | - $this->_admin_page_title = $this->page_label; |
|
42 | - } |
|
38 | + protected function _define_page_props() |
|
39 | + { |
|
40 | + $this->_labels = array(); |
|
41 | + $this->_admin_page_title = $this->page_label; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | 45 | |
46 | - protected function _set_page_routes() |
|
47 | - { |
|
48 | - $this->_page_routes = array( |
|
49 | - 'default' => array( |
|
50 | - 'func' => '_contact_support', |
|
51 | - 'capability' => 'ee_read_ee', |
|
52 | - ), |
|
53 | - 'developers' => array( |
|
54 | - 'func' => '_developers', |
|
55 | - 'capability' => 'ee_read_ee', |
|
56 | - ), |
|
57 | - 'shortcodes' => array( |
|
58 | - 'func' => '_shortcodes', |
|
59 | - 'capability' => 'ee_read_ee', |
|
60 | - ), |
|
61 | - ); |
|
62 | - } |
|
46 | + protected function _set_page_routes() |
|
47 | + { |
|
48 | + $this->_page_routes = array( |
|
49 | + 'default' => array( |
|
50 | + 'func' => '_contact_support', |
|
51 | + 'capability' => 'ee_read_ee', |
|
52 | + ), |
|
53 | + 'developers' => array( |
|
54 | + 'func' => '_developers', |
|
55 | + 'capability' => 'ee_read_ee', |
|
56 | + ), |
|
57 | + 'shortcodes' => array( |
|
58 | + 'func' => '_shortcodes', |
|
59 | + 'capability' => 'ee_read_ee', |
|
60 | + ), |
|
61 | + ); |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | 65 | |
66 | - protected function _set_page_config() |
|
67 | - { |
|
68 | - $this->_page_config = array( |
|
69 | - 'default' => array( |
|
70 | - 'nav' => array( |
|
71 | - 'label' => esc_html__('Support', 'event_espresso'), |
|
72 | - 'order' => 30, |
|
73 | - ), |
|
74 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_support_boxes')), |
|
75 | - 'require_nonce' => false, |
|
76 | - ), |
|
77 | - 'developers' => array( |
|
78 | - 'nav' => array( |
|
79 | - 'label' => esc_html__('Developers', 'event_espresso'), |
|
80 | - 'order' => 50, |
|
81 | - ), |
|
82 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
83 | - 'require_nonce' => false, |
|
84 | - ), |
|
85 | - 'shortcodes' => array( |
|
86 | - 'nav' => array( |
|
87 | - 'label' => esc_html__('Shortcodes', 'event_espresso'), |
|
88 | - 'order' => 60, |
|
89 | - ), |
|
90 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_shortcodes_boxes')), |
|
91 | - 'require_nonce' => false, |
|
92 | - ), |
|
93 | - ); |
|
94 | - } |
|
66 | + protected function _set_page_config() |
|
67 | + { |
|
68 | + $this->_page_config = array( |
|
69 | + 'default' => array( |
|
70 | + 'nav' => array( |
|
71 | + 'label' => esc_html__('Support', 'event_espresso'), |
|
72 | + 'order' => 30, |
|
73 | + ), |
|
74 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_support_boxes')), |
|
75 | + 'require_nonce' => false, |
|
76 | + ), |
|
77 | + 'developers' => array( |
|
78 | + 'nav' => array( |
|
79 | + 'label' => esc_html__('Developers', 'event_espresso'), |
|
80 | + 'order' => 50, |
|
81 | + ), |
|
82 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
83 | + 'require_nonce' => false, |
|
84 | + ), |
|
85 | + 'shortcodes' => array( |
|
86 | + 'nav' => array( |
|
87 | + 'label' => esc_html__('Shortcodes', 'event_espresso'), |
|
88 | + 'order' => 60, |
|
89 | + ), |
|
90 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_shortcodes_boxes')), |
|
91 | + 'require_nonce' => false, |
|
92 | + ), |
|
93 | + ); |
|
94 | + } |
|
95 | 95 | |
96 | 96 | |
97 | 97 | |
98 | - //none of the below group are currently used for Support pages |
|
99 | - protected function _add_screen_options() |
|
100 | - { |
|
101 | - } |
|
102 | - |
|
98 | + //none of the below group are currently used for Support pages |
|
99 | + protected function _add_screen_options() |
|
100 | + { |
|
101 | + } |
|
102 | + |
|
103 | 103 | |
104 | 104 | |
105 | - protected function _add_feature_pointers() |
|
106 | - { |
|
107 | - } |
|
105 | + protected function _add_feature_pointers() |
|
106 | + { |
|
107 | + } |
|
108 | 108 | |
109 | 109 | |
110 | 110 | |
111 | - public function admin_init() |
|
112 | - { |
|
113 | - } |
|
111 | + public function admin_init() |
|
112 | + { |
|
113 | + } |
|
114 | 114 | |
115 | 115 | |
116 | 116 | |
117 | - public function admin_notices() |
|
118 | - { |
|
119 | - } |
|
117 | + public function admin_notices() |
|
118 | + { |
|
119 | + } |
|
120 | 120 | |
121 | - |
|
122 | - |
|
123 | - public function admin_footer_scripts() |
|
124 | - { |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - public function load_scripts_styles() |
|
130 | - { |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - protected function _installation() |
|
136 | - { |
|
137 | - $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'support_admin_details_installation.template.php'; |
|
138 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
139 | - $template_path, |
|
140 | - '', |
|
141 | - true |
|
142 | - ); |
|
143 | - $this->display_admin_page_with_sidebar(); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - protected function _resources() |
|
149 | - { |
|
150 | - $this->display_admin_page_with_sidebar(); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - protected function _add_settings_metabox($box, $label, array $args) |
|
156 | - { |
|
157 | - add_meta_box( |
|
158 | - "espresso_{$box}_settings", |
|
159 | - $label, |
|
160 | - function ($post, $metabox) { |
|
161 | - echo EEH_Template::display_template( |
|
162 | - $metabox['args']['template_path'], |
|
163 | - $metabox['args']['template_args'], |
|
164 | - true |
|
165 | - ); |
|
166 | - }, |
|
167 | - $this->_current_screen->id, |
|
168 | - 'normal', |
|
169 | - 'high', |
|
170 | - apply_filters( |
|
171 | - "FHEE__Support_Admin_Page___add_settings_metabox__{$box}_args_array", |
|
172 | - $args |
|
173 | - ) |
|
174 | - ); |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - |
|
179 | - protected function _resources_boxes() |
|
180 | - { |
|
181 | - $boxes = apply_filters( |
|
182 | - 'FHEE__Support_Admin_Page___resources_boxes__boxes_array', |
|
183 | - array( |
|
184 | - 'favorite_theme_developers' => esc_html__('Favorite Theme Developers', 'event_espresso'), |
|
185 | - 'highly_recommended_themes' => esc_html__('Highly Recommended Themes', 'event_espresso'), |
|
186 | - 'hire_developer' => esc_html__('Hire a Developer', 'event_espresso'), |
|
187 | - 'partners' => esc_html__('Partners', 'event_espresso'), |
|
188 | - 'recommended_plugins' => esc_html__('Recommended Plugins', 'event_espresso'), |
|
189 | - 'other_resources' => esc_html__('Other Resources', 'event_espresso'), |
|
190 | - ) |
|
191 | - ); |
|
192 | - foreach ($boxes as $box => $label) { |
|
193 | - $this->_add_settings_metabox( |
|
194 | - $box, |
|
195 | - $label, |
|
196 | - array( |
|
197 | - 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php", |
|
198 | - 'template_args' => $this->_template_args, |
|
199 | - ) |
|
200 | - ); |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - |
|
206 | - protected function _shortcodes() |
|
207 | - { |
|
208 | - $this->display_admin_page_with_sidebar(); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - |
|
213 | - protected function _shortcodes_boxes() |
|
214 | - { |
|
215 | - $boxes = apply_filters( |
|
216 | - 'FHEE__Support_Admin_Page___shortcodes_boxes__boxes_array', |
|
217 | - array( |
|
218 | - 'shortcodes_event_listings' => esc_html__('Event Listings', 'event_espresso'), |
|
219 | - 'shortcodes_ticket_selector' => esc_html__('Event Ticket Selector', 'event_espresso'), |
|
220 | - 'shortcodes_category' => esc_html__('Event Categories', 'event_espresso'), |
|
221 | - 'shortcodes_attendee' => esc_html__('Event Attendees', 'event_espresso') |
|
222 | - /*'shortcodes_single_events' => esc_html__('Single Events', 'event_espresso'),*/ |
|
223 | - /*'shortcodes_attendee_listings' => esc_html__('Attendee Listings', 'event_espresso'),*/ |
|
224 | - ) |
|
225 | - ); |
|
226 | - foreach ($boxes as $box => $label) { |
|
227 | - $this->_add_settings_metabox( |
|
228 | - $box, |
|
229 | - $label, |
|
230 | - array( |
|
231 | - 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php", |
|
232 | - 'template_args' => $this->_template_args, |
|
233 | - ) |
|
234 | - ); |
|
235 | - } |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - |
|
240 | - protected function _contact_support() |
|
241 | - { |
|
242 | - $this->display_admin_page_with_sidebar(); |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - |
|
247 | - protected function _support_boxes() |
|
248 | - { |
|
249 | - $boxes = apply_filters( |
|
250 | - 'FHEE__Support_Admin_Page___support_boxes__boxes_array', |
|
251 | - array( |
|
252 | - 'contact_support' => esc_html__('Contact Support', 'event_espresso'), |
|
253 | - 'important_information' => esc_html__('Important Information', 'event_espresso'), |
|
254 | - ) |
|
255 | - ); |
|
256 | - foreach ($boxes as $box => $label) { |
|
257 | - $this->_add_settings_metabox( |
|
258 | - $box, |
|
259 | - $label, |
|
260 | - array( |
|
261 | - 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php", |
|
262 | - 'template_args' => $this->_template_args, |
|
263 | - ) |
|
264 | - ); |
|
265 | - } |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - |
|
270 | - protected function _developers() |
|
271 | - { |
|
272 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
273 | - EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'developers_admin_details.template.php', |
|
274 | - array(), |
|
275 | - true |
|
276 | - ); |
|
277 | - $this->display_admin_page_with_sidebar(); |
|
278 | - } |
|
121 | + |
|
122 | + |
|
123 | + public function admin_footer_scripts() |
|
124 | + { |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + public function load_scripts_styles() |
|
130 | + { |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + protected function _installation() |
|
136 | + { |
|
137 | + $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'support_admin_details_installation.template.php'; |
|
138 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
139 | + $template_path, |
|
140 | + '', |
|
141 | + true |
|
142 | + ); |
|
143 | + $this->display_admin_page_with_sidebar(); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + protected function _resources() |
|
149 | + { |
|
150 | + $this->display_admin_page_with_sidebar(); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + protected function _add_settings_metabox($box, $label, array $args) |
|
156 | + { |
|
157 | + add_meta_box( |
|
158 | + "espresso_{$box}_settings", |
|
159 | + $label, |
|
160 | + function ($post, $metabox) { |
|
161 | + echo EEH_Template::display_template( |
|
162 | + $metabox['args']['template_path'], |
|
163 | + $metabox['args']['template_args'], |
|
164 | + true |
|
165 | + ); |
|
166 | + }, |
|
167 | + $this->_current_screen->id, |
|
168 | + 'normal', |
|
169 | + 'high', |
|
170 | + apply_filters( |
|
171 | + "FHEE__Support_Admin_Page___add_settings_metabox__{$box}_args_array", |
|
172 | + $args |
|
173 | + ) |
|
174 | + ); |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + |
|
179 | + protected function _resources_boxes() |
|
180 | + { |
|
181 | + $boxes = apply_filters( |
|
182 | + 'FHEE__Support_Admin_Page___resources_boxes__boxes_array', |
|
183 | + array( |
|
184 | + 'favorite_theme_developers' => esc_html__('Favorite Theme Developers', 'event_espresso'), |
|
185 | + 'highly_recommended_themes' => esc_html__('Highly Recommended Themes', 'event_espresso'), |
|
186 | + 'hire_developer' => esc_html__('Hire a Developer', 'event_espresso'), |
|
187 | + 'partners' => esc_html__('Partners', 'event_espresso'), |
|
188 | + 'recommended_plugins' => esc_html__('Recommended Plugins', 'event_espresso'), |
|
189 | + 'other_resources' => esc_html__('Other Resources', 'event_espresso'), |
|
190 | + ) |
|
191 | + ); |
|
192 | + foreach ($boxes as $box => $label) { |
|
193 | + $this->_add_settings_metabox( |
|
194 | + $box, |
|
195 | + $label, |
|
196 | + array( |
|
197 | + 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php", |
|
198 | + 'template_args' => $this->_template_args, |
|
199 | + ) |
|
200 | + ); |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + |
|
206 | + protected function _shortcodes() |
|
207 | + { |
|
208 | + $this->display_admin_page_with_sidebar(); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + |
|
213 | + protected function _shortcodes_boxes() |
|
214 | + { |
|
215 | + $boxes = apply_filters( |
|
216 | + 'FHEE__Support_Admin_Page___shortcodes_boxes__boxes_array', |
|
217 | + array( |
|
218 | + 'shortcodes_event_listings' => esc_html__('Event Listings', 'event_espresso'), |
|
219 | + 'shortcodes_ticket_selector' => esc_html__('Event Ticket Selector', 'event_espresso'), |
|
220 | + 'shortcodes_category' => esc_html__('Event Categories', 'event_espresso'), |
|
221 | + 'shortcodes_attendee' => esc_html__('Event Attendees', 'event_espresso') |
|
222 | + /*'shortcodes_single_events' => esc_html__('Single Events', 'event_espresso'),*/ |
|
223 | + /*'shortcodes_attendee_listings' => esc_html__('Attendee Listings', 'event_espresso'),*/ |
|
224 | + ) |
|
225 | + ); |
|
226 | + foreach ($boxes as $box => $label) { |
|
227 | + $this->_add_settings_metabox( |
|
228 | + $box, |
|
229 | + $label, |
|
230 | + array( |
|
231 | + 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php", |
|
232 | + 'template_args' => $this->_template_args, |
|
233 | + ) |
|
234 | + ); |
|
235 | + } |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + |
|
240 | + protected function _contact_support() |
|
241 | + { |
|
242 | + $this->display_admin_page_with_sidebar(); |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + |
|
247 | + protected function _support_boxes() |
|
248 | + { |
|
249 | + $boxes = apply_filters( |
|
250 | + 'FHEE__Support_Admin_Page___support_boxes__boxes_array', |
|
251 | + array( |
|
252 | + 'contact_support' => esc_html__('Contact Support', 'event_espresso'), |
|
253 | + 'important_information' => esc_html__('Important Information', 'event_espresso'), |
|
254 | + ) |
|
255 | + ); |
|
256 | + foreach ($boxes as $box => $label) { |
|
257 | + $this->_add_settings_metabox( |
|
258 | + $box, |
|
259 | + $label, |
|
260 | + array( |
|
261 | + 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php", |
|
262 | + 'template_args' => $this->_template_args, |
|
263 | + ) |
|
264 | + ); |
|
265 | + } |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + |
|
270 | + protected function _developers() |
|
271 | + { |
|
272 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
273 | + EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'developers_admin_details.template.php', |
|
274 | + array(), |
|
275 | + true |
|
276 | + ); |
|
277 | + $this->display_admin_page_with_sidebar(); |
|
278 | + } |
|
279 | 279 | |
280 | 280 | |
281 | 281 |
@@ -1,5 +1,5 @@ discard block |
||
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 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | |
135 | 135 | protected function _installation() |
136 | 136 | { |
137 | - $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'support_admin_details_installation.template.php'; |
|
137 | + $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH.'support_admin_details_installation.template.php'; |
|
138 | 138 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
139 | 139 | $template_path, |
140 | 140 | '', |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | add_meta_box( |
158 | 158 | "espresso_{$box}_settings", |
159 | 159 | $label, |
160 | - function ($post, $metabox) { |
|
160 | + function($post, $metabox) { |
|
161 | 161 | echo EEH_Template::display_template( |
162 | 162 | $metabox['args']['template_path'], |
163 | 163 | $metabox['args']['template_args'], |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | $box, |
195 | 195 | $label, |
196 | 196 | array( |
197 | - 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php", |
|
197 | + 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH."support_admin_details_{$box}.template.php", |
|
198 | 198 | 'template_args' => $this->_template_args, |
199 | 199 | ) |
200 | 200 | ); |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | $box, |
229 | 229 | $label, |
230 | 230 | array( |
231 | - 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php", |
|
231 | + 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH."support_admin_details_{$box}.template.php", |
|
232 | 232 | 'template_args' => $this->_template_args, |
233 | 233 | ) |
234 | 234 | ); |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | $box, |
259 | 259 | $label, |
260 | 260 | array( |
261 | - 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php", |
|
261 | + 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH."support_admin_details_{$box}.template.php", |
|
262 | 262 | 'template_args' => $this->_template_args, |
263 | 263 | ) |
264 | 264 | ); |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | protected function _developers() |
271 | 271 | { |
272 | 272 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
273 | - EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'developers_admin_details.template.php', |
|
273 | + EE_SUPPORT_ADMIN_TEMPLATE_PATH.'developers_admin_details.template.php', |
|
274 | 274 | array(), |
275 | 275 | true |
276 | 276 | ); |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | } |
21 | 21 | |
22 | 22 | if ( is_null( $value_to_normalize ) || $value_to_normalize === '' ) { |
23 | - return null; |
|
24 | - } |
|
23 | + return null; |
|
24 | + } |
|
25 | 25 | |
26 | 26 | if( ! is_string( $value_to_normalize )){ |
27 | 27 | throw new EE_Validation_Error( sprintf( __( 'The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso' ), print_r( $value_to_normalize, TRUE), gettype( $value_to_normalize ) ) ); |
@@ -56,9 +56,9 @@ discard block |
||
56 | 56 | * @return string |
57 | 57 | */ |
58 | 58 | public function unnormalize( $normalized_value ) { |
59 | - if ($normalized_value === null || $normalized_value === '') { |
|
60 | - return ''; |
|
61 | - }elseif( empty( $normalized_value ) ){ |
|
59 | + if ($normalized_value === null || $normalized_value === '') { |
|
60 | + return ''; |
|
61 | + }elseif( empty( $normalized_value ) ){ |
|
62 | 62 | return '0'; |
63 | 63 | }else{ |
64 | 64 | return "$normalized_value"; |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @subpackage |
8 | 8 | * @author Mike Nelson |
9 | 9 | */ |
10 | -class EE_Int_Normalization extends EE_Normalization_Strategy_Base{ |
|
10 | +class EE_Int_Normalization extends EE_Normalization_Strategy_Base { |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * @param string $value_to_normalize |
@@ -15,38 +15,38 @@ discard block |
||
15 | 15 | * @throws \EE_Validation_Error |
16 | 16 | */ |
17 | 17 | public function normalize($value_to_normalize) { |
18 | - if( is_int( $value_to_normalize ) ){ |
|
18 | + if (is_int($value_to_normalize)) { |
|
19 | 19 | return $value_to_normalize; |
20 | 20 | } |
21 | 21 | |
22 | - if ( is_null( $value_to_normalize ) || $value_to_normalize === '' ) { |
|
22 | + if (is_null($value_to_normalize) || $value_to_normalize === '') { |
|
23 | 23 | return null; |
24 | 24 | } |
25 | 25 | |
26 | - if( ! is_string( $value_to_normalize )){ |
|
27 | - throw new EE_Validation_Error( sprintf( __( 'The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso' ), print_r( $value_to_normalize, TRUE), gettype( $value_to_normalize ) ) ); |
|
26 | + if ( ! is_string($value_to_normalize)) { |
|
27 | + throw new EE_Validation_Error(sprintf(__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), print_r($value_to_normalize, TRUE), gettype($value_to_normalize))); |
|
28 | 28 | } |
29 | 29 | $thousands_separator = EE_Config::instance()->currency->thsnds; |
30 | - $value_to_normalize = str_replace( $thousands_separator, "", $value_to_normalize ); |
|
31 | - $value_to_normalize = str_replace( array(" ","\t"), '', $value_to_normalize ); |
|
32 | - if ( preg_match( '/^\d+$/', $value_to_normalize )) { |
|
33 | - return intval( $value_to_normalize ); |
|
30 | + $value_to_normalize = str_replace($thousands_separator, "", $value_to_normalize); |
|
31 | + $value_to_normalize = str_replace(array(" ", "\t"), '', $value_to_normalize); |
|
32 | + if (preg_match('/^\d+$/', $value_to_normalize)) { |
|
33 | + return intval($value_to_normalize); |
|
34 | 34 | } else { |
35 | 35 | //find if this input has a int validation strategy |
36 | 36 | //in which case, use its message |
37 | 37 | $validation_error_message = NULL; |
38 | - foreach( $this->_input->get_validation_strategies() as $validation_strategy ){ |
|
39 | - if( $validation_strategy instanceof EE_Int_Validation_Strategy ){ |
|
38 | + foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
39 | + if ($validation_strategy instanceof EE_Int_Validation_Strategy) { |
|
40 | 40 | $validation_error_message = $validation_strategy->get_validation_error_message(); |
41 | 41 | } |
42 | 42 | } |
43 | 43 | //this really shouldn't ever happen because fields with a int normalization strategy |
44 | 44 | //should also have a int validation strategy, but in case it doesnt use the default |
45 | - if( ! $validation_error_message ){ |
|
45 | + if ( ! $validation_error_message) { |
|
46 | 46 | $default_validation_strategy = new EE_Int_Validation_Strategy(); |
47 | 47 | $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
48 | 48 | } |
49 | - throw new EE_Validation_Error( $validation_error_message, 'numeric_only' ); |
|
49 | + throw new EE_Validation_Error($validation_error_message, 'numeric_only'); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
@@ -55,12 +55,12 @@ discard block |
||
55 | 55 | * @param int $normalized_value |
56 | 56 | * @return string |
57 | 57 | */ |
58 | - public function unnormalize( $normalized_value ) { |
|
58 | + public function unnormalize($normalized_value) { |
|
59 | 59 | if ($normalized_value === null || $normalized_value === '') { |
60 | 60 | return ''; |
61 | - }elseif( empty( $normalized_value ) ){ |
|
61 | + }elseif (empty($normalized_value)) { |
|
62 | 62 | return '0'; |
63 | - }else{ |
|
63 | + } else { |
|
64 | 64 | return "$normalized_value"; |
65 | 65 | } |
66 | 66 | } |
@@ -58,9 +58,9 @@ |
||
58 | 58 | public function unnormalize( $normalized_value ) { |
59 | 59 | if ($normalized_value === null || $normalized_value === '') { |
60 | 60 | return ''; |
61 | - }elseif( empty( $normalized_value ) ){ |
|
61 | + } elseif( empty( $normalized_value ) ){ |
|
62 | 62 | return '0'; |
63 | - }else{ |
|
63 | + } else{ |
|
64 | 64 | return "$normalized_value"; |
65 | 65 | } |
66 | 66 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * @since $VID:$ |
14 | 14 | */ |
15 | 15 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
16 | - exit('No direct script access allowed'); |
|
16 | + exit('No direct script access allowed'); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | |
@@ -21,58 +21,58 @@ discard block |
||
21 | 21 | class Registration extends Calculations_Base |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * Calculates the checkin status for each datetime this registration has access to |
|
26 | - * |
|
27 | - * @param array $wpdb_row |
|
28 | - * @param \WP_REST_Request $request |
|
29 | - * @param Base $controller |
|
30 | - * @return int |
|
31 | - * @throws \EE_Error |
|
32 | - */ |
|
33 | - public static function datetime_checkin_stati($wpdb_row, $request, $controller) |
|
34 | - { |
|
35 | - if (is_array($wpdb_row) && isset($wpdb_row['Registration.REG_ID'])) { |
|
36 | - $reg = \EEM_Registration::instance()->get_one_by_ID($wpdb_row['Registration.REG_ID']); |
|
37 | - } else { |
|
38 | - $reg = null; |
|
39 | - } |
|
40 | - if (! $reg instanceof \EE_Registration |
|
41 | - ) { |
|
42 | - throw new \EE_Error( |
|
43 | - sprintf( |
|
44 | - __('Cannot calculate datetime_checkin_stati because the registration with ID %1$s (from database row %2$s) was not found', |
|
45 | - 'event_espresso'), |
|
46 | - $wpdb_row['Registration.REG_ID'], |
|
47 | - print_r($wpdb_row, true) |
|
48 | - ) |
|
49 | - ); |
|
50 | - } |
|
51 | - $datetime_ids = \EEM_Datetime::instance()->get_col( |
|
52 | - array( |
|
53 | - array( |
|
54 | - 'Ticket.TKT_ID' => $reg->ticket_ID(), |
|
55 | - ), |
|
56 | - 'default_where_conditions' => \EEM_Base::default_where_conditions_minimum_all |
|
57 | - ) |
|
58 | - ); |
|
59 | - $checkin_stati = array(); |
|
60 | - foreach ($datetime_ids as $datetime_id) { |
|
61 | - $status = $reg->check_in_status_for_datetime($datetime_id); |
|
62 | - switch ($status) { |
|
63 | - case \EE_Registration::checkin_status_out: |
|
64 | - $status_pretty = 'OUT'; |
|
65 | - break; |
|
66 | - case \EE_Registration::checkin_status_in: |
|
67 | - $status_pretty = 'IN'; |
|
68 | - break; |
|
69 | - case \EE_Registration::checkin_status_never: |
|
70 | - default: |
|
71 | - $status_pretty = 'NEVER'; |
|
72 | - break; |
|
73 | - } |
|
74 | - $checkin_stati[$datetime_id] = $status_pretty; |
|
75 | - } |
|
76 | - return $checkin_stati; |
|
77 | - } |
|
24 | + /** |
|
25 | + * Calculates the checkin status for each datetime this registration has access to |
|
26 | + * |
|
27 | + * @param array $wpdb_row |
|
28 | + * @param \WP_REST_Request $request |
|
29 | + * @param Base $controller |
|
30 | + * @return int |
|
31 | + * @throws \EE_Error |
|
32 | + */ |
|
33 | + public static function datetime_checkin_stati($wpdb_row, $request, $controller) |
|
34 | + { |
|
35 | + if (is_array($wpdb_row) && isset($wpdb_row['Registration.REG_ID'])) { |
|
36 | + $reg = \EEM_Registration::instance()->get_one_by_ID($wpdb_row['Registration.REG_ID']); |
|
37 | + } else { |
|
38 | + $reg = null; |
|
39 | + } |
|
40 | + if (! $reg instanceof \EE_Registration |
|
41 | + ) { |
|
42 | + throw new \EE_Error( |
|
43 | + sprintf( |
|
44 | + __('Cannot calculate datetime_checkin_stati because the registration with ID %1$s (from database row %2$s) was not found', |
|
45 | + 'event_espresso'), |
|
46 | + $wpdb_row['Registration.REG_ID'], |
|
47 | + print_r($wpdb_row, true) |
|
48 | + ) |
|
49 | + ); |
|
50 | + } |
|
51 | + $datetime_ids = \EEM_Datetime::instance()->get_col( |
|
52 | + array( |
|
53 | + array( |
|
54 | + 'Ticket.TKT_ID' => $reg->ticket_ID(), |
|
55 | + ), |
|
56 | + 'default_where_conditions' => \EEM_Base::default_where_conditions_minimum_all |
|
57 | + ) |
|
58 | + ); |
|
59 | + $checkin_stati = array(); |
|
60 | + foreach ($datetime_ids as $datetime_id) { |
|
61 | + $status = $reg->check_in_status_for_datetime($datetime_id); |
|
62 | + switch ($status) { |
|
63 | + case \EE_Registration::checkin_status_out: |
|
64 | + $status_pretty = 'OUT'; |
|
65 | + break; |
|
66 | + case \EE_Registration::checkin_status_in: |
|
67 | + $status_pretty = 'IN'; |
|
68 | + break; |
|
69 | + case \EE_Registration::checkin_status_never: |
|
70 | + default: |
|
71 | + $status_pretty = 'NEVER'; |
|
72 | + break; |
|
73 | + } |
|
74 | + $checkin_stati[$datetime_id] = $status_pretty; |
|
75 | + } |
|
76 | + return $checkin_stati; |
|
77 | + } |
|
78 | 78 | } |
@@ -1,6 +1,6 @@ discard block |
||
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 |
||
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 |
@@ -244,13 +244,13 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -1,7 +1,7 @@ discard block |
||
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 |
||
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 |
@@ -1,6 +1,6 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -1,5 +1,5 @@ discard block |
||
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 |
||
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.37.rc.011'); |
|
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.37.rc.011'); |
|
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 |