@@ -18,1254 +18,1254 @@ |
||
18 | 18 | class EED_Messages extends EED_Module |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * This holds the EE_messages controller |
|
23 | - * |
|
24 | - * @deprecated 4.9.0 |
|
25 | - * @var EE_messages $_EEMSG |
|
26 | - */ |
|
27 | - protected static $_EEMSG; |
|
28 | - |
|
29 | - /** |
|
30 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
31 | - */ |
|
32 | - protected static $_message_resource_manager; |
|
33 | - |
|
34 | - /** |
|
35 | - * This holds the EE_Messages_Processor business class. |
|
36 | - * |
|
37 | - * @type EE_Messages_Processor |
|
38 | - */ |
|
39 | - protected static $_MSG_PROCESSOR; |
|
40 | - |
|
41 | - /** |
|
42 | - * holds all the paths for various messages components. |
|
43 | - * Utilized by autoloader registry |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - protected static $_MSG_PATHS; |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * This will hold an array of messages template packs that are registered in the messages system. |
|
52 | - * Format is: |
|
53 | - * array( |
|
54 | - * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
55 | - * ) |
|
56 | - * |
|
57 | - * @var EE_Messages_Template_Pack[] |
|
58 | - */ |
|
59 | - protected static $_TMP_PACKS = array(); |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @return EED_Messages |
|
64 | - */ |
|
65 | - public static function instance() |
|
66 | - { |
|
67 | - return parent::get_instance(__CLASS__); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
73 | - * |
|
74 | - * @since 4.5.0 |
|
75 | - * @return void |
|
76 | - */ |
|
77 | - public static function set_hooks() |
|
78 | - { |
|
79 | - //actions |
|
80 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
81 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
82 | - array('EED_Messages', 'maybe_registration'), 10, 2); |
|
83 | - //filters |
|
84 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
85 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
86 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
87 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
88 | - //register routes |
|
89 | - self::_register_routes(); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
94 | - * |
|
95 | - * @access public |
|
96 | - * @return void |
|
97 | - */ |
|
98 | - public static function set_hooks_admin() |
|
99 | - { |
|
100 | - //actions |
|
101 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
102 | - add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
103 | - array('EED_Messages', 'payment_reminder'), 10); |
|
104 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
105 | - array('EED_Messages', 'maybe_registration'), 10, 3); |
|
106 | - add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
107 | - array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
108 | - add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
109 | - array('EED_Messages', 'cancelled_registration'), 10); |
|
110 | - add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
111 | - array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
112 | - //filters |
|
113 | - add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
114 | - array('EED_Messages', 'process_resend'), 10, 2); |
|
115 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
116 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
117 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
118 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * All the message triggers done by route go in here. |
|
124 | - * |
|
125 | - * @since 4.5.0 |
|
126 | - * @return void |
|
127 | - */ |
|
128 | - protected static function _register_routes() |
|
129 | - { |
|
130 | - EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
131 | - EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
132 | - EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
133 | - EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
134 | - do_action('AHEE__EED_Messages___register_routes'); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * This is called when a browser display trigger is executed. |
|
140 | - * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
141 | - * browser. |
|
142 | - * |
|
143 | - * @since 4.9.0 |
|
144 | - * @param WP $WP |
|
145 | - * @throws EE_Error |
|
146 | - * @throws InvalidArgumentException |
|
147 | - * @throws ReflectionException |
|
148 | - * @throws InvalidDataTypeException |
|
149 | - * @throws InvalidInterfaceException |
|
150 | - */ |
|
151 | - public function browser_trigger($WP) |
|
152 | - { |
|
153 | - //ensure controller is loaded |
|
154 | - self::_load_controller(); |
|
155 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
156 | - try { |
|
157 | - $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
158 | - self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
159 | - } catch (EE_Error $e) { |
|
160 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
161 | - 'event_espresso'); |
|
162 | - // add specific message for developers if WP_DEBUG in on |
|
163 | - $error_msg .= '||' . $e->getMessage(); |
|
164 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * This is called when a browser error trigger is executed. |
|
171 | - * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
172 | - * message and display it. |
|
173 | - * |
|
174 | - * @since 4.9.0 |
|
175 | - * @param $WP |
|
176 | - * @throws EE_Error |
|
177 | - * @throws InvalidArgumentException |
|
178 | - * @throws InvalidDataTypeException |
|
179 | - * @throws InvalidInterfaceException |
|
180 | - */ |
|
181 | - public function browser_error_trigger($WP) |
|
182 | - { |
|
183 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
184 | - if ($token) { |
|
185 | - $message = EEM_Message::instance()->get_one_by_token($token); |
|
186 | - if ($message instanceof EE_Message) { |
|
187 | - header('HTTP/1.1 200 OK'); |
|
188 | - $error_msg = nl2br($message->error_message()); |
|
189 | - ?> |
|
21 | + /** |
|
22 | + * This holds the EE_messages controller |
|
23 | + * |
|
24 | + * @deprecated 4.9.0 |
|
25 | + * @var EE_messages $_EEMSG |
|
26 | + */ |
|
27 | + protected static $_EEMSG; |
|
28 | + |
|
29 | + /** |
|
30 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
31 | + */ |
|
32 | + protected static $_message_resource_manager; |
|
33 | + |
|
34 | + /** |
|
35 | + * This holds the EE_Messages_Processor business class. |
|
36 | + * |
|
37 | + * @type EE_Messages_Processor |
|
38 | + */ |
|
39 | + protected static $_MSG_PROCESSOR; |
|
40 | + |
|
41 | + /** |
|
42 | + * holds all the paths for various messages components. |
|
43 | + * Utilized by autoloader registry |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + protected static $_MSG_PATHS; |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * This will hold an array of messages template packs that are registered in the messages system. |
|
52 | + * Format is: |
|
53 | + * array( |
|
54 | + * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
55 | + * ) |
|
56 | + * |
|
57 | + * @var EE_Messages_Template_Pack[] |
|
58 | + */ |
|
59 | + protected static $_TMP_PACKS = array(); |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @return EED_Messages |
|
64 | + */ |
|
65 | + public static function instance() |
|
66 | + { |
|
67 | + return parent::get_instance(__CLASS__); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
73 | + * |
|
74 | + * @since 4.5.0 |
|
75 | + * @return void |
|
76 | + */ |
|
77 | + public static function set_hooks() |
|
78 | + { |
|
79 | + //actions |
|
80 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
81 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
82 | + array('EED_Messages', 'maybe_registration'), 10, 2); |
|
83 | + //filters |
|
84 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
85 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
86 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
87 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
88 | + //register routes |
|
89 | + self::_register_routes(); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
94 | + * |
|
95 | + * @access public |
|
96 | + * @return void |
|
97 | + */ |
|
98 | + public static function set_hooks_admin() |
|
99 | + { |
|
100 | + //actions |
|
101 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
102 | + add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
103 | + array('EED_Messages', 'payment_reminder'), 10); |
|
104 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
105 | + array('EED_Messages', 'maybe_registration'), 10, 3); |
|
106 | + add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
107 | + array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
108 | + add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
109 | + array('EED_Messages', 'cancelled_registration'), 10); |
|
110 | + add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
111 | + array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
112 | + //filters |
|
113 | + add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
114 | + array('EED_Messages', 'process_resend'), 10, 2); |
|
115 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
116 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
117 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
118 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * All the message triggers done by route go in here. |
|
124 | + * |
|
125 | + * @since 4.5.0 |
|
126 | + * @return void |
|
127 | + */ |
|
128 | + protected static function _register_routes() |
|
129 | + { |
|
130 | + EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
131 | + EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
132 | + EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
133 | + EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
134 | + do_action('AHEE__EED_Messages___register_routes'); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * This is called when a browser display trigger is executed. |
|
140 | + * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
141 | + * browser. |
|
142 | + * |
|
143 | + * @since 4.9.0 |
|
144 | + * @param WP $WP |
|
145 | + * @throws EE_Error |
|
146 | + * @throws InvalidArgumentException |
|
147 | + * @throws ReflectionException |
|
148 | + * @throws InvalidDataTypeException |
|
149 | + * @throws InvalidInterfaceException |
|
150 | + */ |
|
151 | + public function browser_trigger($WP) |
|
152 | + { |
|
153 | + //ensure controller is loaded |
|
154 | + self::_load_controller(); |
|
155 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
156 | + try { |
|
157 | + $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
158 | + self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
159 | + } catch (EE_Error $e) { |
|
160 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
161 | + 'event_espresso'); |
|
162 | + // add specific message for developers if WP_DEBUG in on |
|
163 | + $error_msg .= '||' . $e->getMessage(); |
|
164 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * This is called when a browser error trigger is executed. |
|
171 | + * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
172 | + * message and display it. |
|
173 | + * |
|
174 | + * @since 4.9.0 |
|
175 | + * @param $WP |
|
176 | + * @throws EE_Error |
|
177 | + * @throws InvalidArgumentException |
|
178 | + * @throws InvalidDataTypeException |
|
179 | + * @throws InvalidInterfaceException |
|
180 | + */ |
|
181 | + public function browser_error_trigger($WP) |
|
182 | + { |
|
183 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
184 | + if ($token) { |
|
185 | + $message = EEM_Message::instance()->get_one_by_token($token); |
|
186 | + if ($message instanceof EE_Message) { |
|
187 | + header('HTTP/1.1 200 OK'); |
|
188 | + $error_msg = nl2br($message->error_message()); |
|
189 | + ?> |
|
190 | 190 | <!DOCTYPE html> |
191 | 191 | <html> |
192 | 192 | <head></head> |
193 | 193 | <body> |
194 | 194 | <?php echo empty($error_msg) |
195 | - ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
196 | - 'event_espresso') |
|
197 | - : wp_kses( |
|
198 | - $error_msg, |
|
199 | - array( |
|
200 | - 'a' => array( |
|
201 | - 'href' => array(), |
|
202 | - 'title' => array(), |
|
203 | - ), |
|
204 | - 'span' => array(), |
|
205 | - 'div' => array(), |
|
206 | - 'p' => array(), |
|
207 | - 'strong' => array(), |
|
208 | - 'em' => array(), |
|
209 | - 'br' => array(), |
|
210 | - ) |
|
211 | - ); ?> |
|
195 | + ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
196 | + 'event_espresso') |
|
197 | + : wp_kses( |
|
198 | + $error_msg, |
|
199 | + array( |
|
200 | + 'a' => array( |
|
201 | + 'href' => array(), |
|
202 | + 'title' => array(), |
|
203 | + ), |
|
204 | + 'span' => array(), |
|
205 | + 'div' => array(), |
|
206 | + 'p' => array(), |
|
207 | + 'strong' => array(), |
|
208 | + 'em' => array(), |
|
209 | + 'br' => array(), |
|
210 | + ) |
|
211 | + ); ?> |
|
212 | 212 | </body> |
213 | 213 | </html> |
214 | 214 | <?php |
215 | - exit; |
|
216 | - } |
|
217 | - } |
|
218 | - return; |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * This runs when the msg_url_trigger route has initiated. |
|
224 | - * |
|
225 | - * @since 4.5.0 |
|
226 | - * @param WP $WP |
|
227 | - * @throws EE_Error |
|
228 | - * @throws InvalidArgumentException |
|
229 | - * @throws ReflectionException |
|
230 | - * @throws InvalidDataTypeException |
|
231 | - * @throws InvalidInterfaceException |
|
232 | - */ |
|
233 | - public function run($WP) |
|
234 | - { |
|
235 | - //ensure controller is loaded |
|
236 | - self::_load_controller(); |
|
237 | - // attempt to process message |
|
238 | - try { |
|
239 | - /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
240 | - $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
241 | - self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
242 | - } catch (EE_Error $e) { |
|
243 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
244 | - 'event_espresso'); |
|
245 | - // add specific message for developers if WP_DEBUG in on |
|
246 | - $error_msg .= '||' . $e->getMessage(); |
|
247 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
248 | - } |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * This is triggered by the 'msg_cron_trigger' route. |
|
254 | - * |
|
255 | - * @param WP $WP |
|
256 | - */ |
|
257 | - public function execute_batch_request($WP) |
|
258 | - { |
|
259 | - $this->run_cron(); |
|
260 | - header('HTTP/1.1 200 OK'); |
|
261 | - exit(); |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
267 | - * request. |
|
268 | - */ |
|
269 | - public function run_cron() |
|
270 | - { |
|
271 | - self::_load_controller(); |
|
272 | - //get required vars |
|
273 | - $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
274 | - $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
275 | - |
|
276 | - //now let's verify transient, if not valid exit immediately |
|
277 | - if (! get_transient($transient_key)) { |
|
278 | - /** |
|
279 | - * trigger error so this gets in the error logs. This is important because it happens on a non-user |
|
280 | - * request. |
|
281 | - */ |
|
282 | - trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
283 | - } |
|
284 | - |
|
285 | - //if made it here, lets' delete the transient to keep the db clean |
|
286 | - delete_transient($transient_key); |
|
287 | - |
|
288 | - if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
289 | - |
|
290 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
291 | - if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
292 | - self::$_MSG_PROCESSOR->$method(); |
|
293 | - } else { |
|
294 | - //no matching task |
|
295 | - /** |
|
296 | - * trigger error so this gets in the error logs. This is important because it happens on a non user |
|
297 | - * request. |
|
298 | - */ |
|
299 | - trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
300 | - $cron_type))); |
|
301 | - } |
|
302 | - } |
|
303 | - |
|
304 | - do_action('FHEE__EED_Messages__run_cron__end'); |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * This is used to retrieve the template pack for the given name. |
|
310 | - * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
311 | - * the default template pack is returned. |
|
312 | - * |
|
313 | - * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
314 | - * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
315 | - * in generating the Pack class name). |
|
316 | - * @return EE_Messages_Template_Pack |
|
317 | - * @throws EE_Error |
|
318 | - * @throws InvalidArgumentException |
|
319 | - * @throws ReflectionException |
|
320 | - * @throws InvalidDataTypeException |
|
321 | - * @throws InvalidInterfaceException |
|
322 | - */ |
|
323 | - public static function get_template_pack($template_pack_name) |
|
324 | - { |
|
325 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
326 | - return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * Retrieves an array of all template packs. |
|
332 | - * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
333 | - * |
|
334 | - * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
335 | - * @return EE_Messages_Template_Pack[] |
|
336 | - * @throws EE_Error |
|
337 | - * @throws InvalidArgumentException |
|
338 | - * @throws ReflectionException |
|
339 | - * @throws InvalidDataTypeException |
|
340 | - * @throws InvalidInterfaceException |
|
341 | - */ |
|
342 | - public static function get_template_packs() |
|
343 | - { |
|
344 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
345 | - |
|
346 | - //for backward compat, let's make sure this returns in the same format as originally. |
|
347 | - $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
348 | - $template_pack_collection->rewind(); |
|
349 | - $template_packs = array(); |
|
350 | - while ($template_pack_collection->valid()) { |
|
351 | - $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
352 | - $template_pack_collection->next(); |
|
353 | - } |
|
354 | - return $template_packs; |
|
355 | - } |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
360 | - * |
|
361 | - * @since 4.5.0 |
|
362 | - * @return void |
|
363 | - * @throws EE_Error |
|
364 | - */ |
|
365 | - public static function set_autoloaders() |
|
366 | - { |
|
367 | - if (empty(self::$_MSG_PATHS)) { |
|
368 | - self::_set_messages_paths(); |
|
369 | - foreach (self::$_MSG_PATHS as $path) { |
|
370 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
371 | - } |
|
372 | - // add aliases |
|
373 | - EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
374 | - EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
375 | - } |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
381 | - * for use by the Messages Autoloaders |
|
382 | - * |
|
383 | - * @since 4.5.0 |
|
384 | - * @return void. |
|
385 | - */ |
|
386 | - protected static function _set_messages_paths() |
|
387 | - { |
|
388 | - $dir_ref = array( |
|
389 | - 'messages/message_type', |
|
390 | - 'messages/messenger', |
|
391 | - 'messages/defaults', |
|
392 | - 'messages/defaults/email', |
|
393 | - 'messages/data_class', |
|
394 | - 'messages/validators', |
|
395 | - 'messages/validators/email', |
|
396 | - 'messages/validators/html', |
|
397 | - 'shortcodes', |
|
398 | - ); |
|
399 | - $paths = array(); |
|
400 | - foreach ($dir_ref as $index => $dir) { |
|
401 | - $paths[$index] = EE_LIBRARIES . $dir; |
|
402 | - } |
|
403 | - self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * Takes care of loading dependencies |
|
409 | - * |
|
410 | - * @since 4.5.0 |
|
411 | - * @return void |
|
412 | - * @throws EE_Error |
|
413 | - * @throws InvalidArgumentException |
|
414 | - * @throws ReflectionException |
|
415 | - * @throws InvalidDataTypeException |
|
416 | - * @throws InvalidInterfaceException |
|
417 | - */ |
|
418 | - protected static function _load_controller() |
|
419 | - { |
|
420 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
421 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
422 | - self::set_autoloaders(); |
|
423 | - self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
424 | - self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
425 | - self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
426 | - } |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - /** |
|
431 | - * @param EE_Transaction $transaction |
|
432 | - * @throws EE_Error |
|
433 | - * @throws InvalidArgumentException |
|
434 | - * @throws InvalidDataTypeException |
|
435 | - * @throws InvalidInterfaceException |
|
436 | - * @throws ReflectionException |
|
437 | - */ |
|
438 | - public static function payment_reminder(EE_Transaction $transaction) |
|
439 | - { |
|
440 | - self::_load_controller(); |
|
441 | - $data = array($transaction, null); |
|
442 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * Any messages triggers for after successful gateway payments should go in here. |
|
448 | - * |
|
449 | - * @param EE_Transaction $transaction object |
|
450 | - * @param EE_Payment|null $payment object |
|
451 | - * @return void |
|
452 | - * @throws EE_Error |
|
453 | - * @throws InvalidArgumentException |
|
454 | - * @throws ReflectionException |
|
455 | - * @throws InvalidDataTypeException |
|
456 | - * @throws InvalidInterfaceException |
|
457 | - */ |
|
458 | - public static function payment(EE_Transaction $transaction, EE_Payment $payment = null) |
|
459 | - { |
|
460 | - //if there's no payment object, then we cannot do a payment type message! |
|
461 | - if (! $payment instanceof EE_Payment) { |
|
462 | - return; |
|
463 | - } |
|
464 | - self::_load_controller(); |
|
465 | - $data = array($transaction, $payment); |
|
466 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
467 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
468 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
469 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
470 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
471 | - } |
|
472 | - |
|
473 | - |
|
474 | - /** |
|
475 | - * @param EE_Transaction $transaction |
|
476 | - * @throws EE_Error |
|
477 | - * @throws InvalidArgumentException |
|
478 | - * @throws InvalidDataTypeException |
|
479 | - * @throws InvalidInterfaceException |
|
480 | - * @throws ReflectionException |
|
481 | - */ |
|
482 | - public static function cancelled_registration(EE_Transaction $transaction) |
|
483 | - { |
|
484 | - self::_load_controller(); |
|
485 | - $data = array($transaction, null); |
|
486 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
487 | - } |
|
488 | - |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * Trigger for Registration messages |
|
493 | - * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
494 | - * incoming transaction. |
|
495 | - * |
|
496 | - * @param EE_Registration $registration |
|
497 | - * @param array $extra_details |
|
498 | - * @return void |
|
499 | - * @throws EE_Error |
|
500 | - * @throws InvalidArgumentException |
|
501 | - * @throws InvalidDataTypeException |
|
502 | - * @throws InvalidInterfaceException |
|
503 | - * @throws ReflectionException |
|
504 | - * @throws EntityNotFoundException |
|
505 | - */ |
|
506 | - public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
507 | - { |
|
508 | - |
|
509 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
510 | - //no messages please |
|
511 | - return; |
|
512 | - } |
|
513 | - |
|
514 | - // get all non-trashed registrations so we make sure we send messages for the right status. |
|
515 | - $all_registrations = $registration->transaction()->registrations( |
|
516 | - array( |
|
517 | - array('REG_deleted' => false), |
|
518 | - 'order_by' => array( |
|
519 | - 'Event.EVT_name' => 'ASC', |
|
520 | - 'Attendee.ATT_lname' => 'ASC', |
|
521 | - 'Attendee.ATT_fname' => 'ASC' |
|
522 | - ) |
|
523 | - ) |
|
524 | - ); |
|
525 | - //cached array of statuses so we only trigger messages once per status. |
|
526 | - $statuses_sent = array(); |
|
527 | - self::_load_controller(); |
|
528 | - $mtgs = array(); |
|
529 | - |
|
530 | - //loop through registrations and trigger messages once per status. |
|
531 | - foreach ($all_registrations as $reg) { |
|
532 | - |
|
533 | - //already triggered? |
|
534 | - if (in_array($reg->status_ID(), $statuses_sent)) { |
|
535 | - continue; |
|
536 | - } |
|
537 | - |
|
538 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
539 | - $mtgs = array_merge( |
|
540 | - $mtgs, |
|
541 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
542 | - $message_type, |
|
543 | - array($registration->transaction(), null, $reg->status_ID()) |
|
544 | - ) |
|
545 | - ); |
|
546 | - $statuses_sent[] = $reg->status_ID(); |
|
547 | - } |
|
548 | - |
|
549 | - if (count($statuses_sent) > 1) { |
|
550 | - $mtgs = array_merge( |
|
551 | - $mtgs, |
|
552 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
553 | - 'registration_summary', |
|
554 | - array($registration->transaction(), null) |
|
555 | - ) |
|
556 | - ); |
|
557 | - } |
|
558 | - |
|
559 | - //batch queue and initiate request |
|
560 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
561 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
562 | - } |
|
563 | - |
|
564 | - |
|
565 | - /** |
|
566 | - * This is a helper method used to very whether a registration notification should be sent or |
|
567 | - * not. Prevents duplicate notifications going out for registration context notifications. |
|
568 | - * |
|
569 | - * @param EE_Registration $registration [description] |
|
570 | - * @param array $extra_details [description] |
|
571 | - * @return bool true = send away, false = nope halt the presses. |
|
572 | - */ |
|
573 | - protected static function _verify_registration_notification_send( |
|
574 | - EE_Registration $registration, |
|
575 | - $extra_details = array() |
|
576 | - ) { |
|
577 | - //self::log( |
|
578 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
579 | - // $registration->transaction(), |
|
580 | - // array( '$extra_details' => $extra_details ) |
|
581 | - //); |
|
582 | - // currently only using this to send messages for the primary registrant |
|
583 | - if (! $registration->is_primary_registrant()) { |
|
584 | - return false; |
|
585 | - } |
|
586 | - // first we check if we're in admin and not doing front ajax |
|
587 | - if (is_admin() && ! EE_FRONT_AJAX) { |
|
588 | - //make sure appropriate admin params are set for sending messages |
|
589 | - if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
590 | - //no messages sent please. |
|
591 | - return false; |
|
592 | - } |
|
593 | - } else { |
|
594 | - // frontend request (either regular or via AJAX) |
|
595 | - // TXN is NOT finalized ? |
|
596 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
597 | - return false; |
|
598 | - } |
|
599 | - // return visit but nothing changed ??? |
|
600 | - if ( |
|
601 | - isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
602 | - $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
603 | - ) { |
|
604 | - return false; |
|
605 | - } |
|
606 | - // NOT sending messages && reg status is something other than "Not-Approved" |
|
607 | - if ( |
|
608 | - ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
609 | - $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
610 | - ) { |
|
611 | - return false; |
|
612 | - } |
|
613 | - } |
|
614 | - // release the kraken |
|
615 | - return true; |
|
616 | - } |
|
617 | - |
|
618 | - |
|
619 | - /** |
|
620 | - * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
621 | - * status id. |
|
622 | - * |
|
623 | - * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
624 | - * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
625 | - * @param string $reg_status |
|
626 | - * @return array |
|
627 | - * @throws EE_Error |
|
628 | - * @throws InvalidArgumentException |
|
629 | - * @throws ReflectionException |
|
630 | - * @throws InvalidDataTypeException |
|
631 | - * @throws InvalidInterfaceException |
|
632 | - */ |
|
633 | - protected static function _get_reg_status_array($reg_status = '') |
|
634 | - { |
|
635 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
636 | - return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
637 | - ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
638 | - : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
639 | - } |
|
640 | - |
|
641 | - |
|
642 | - /** |
|
643 | - * Simply returns the payment message type for the given payment status. |
|
644 | - * |
|
645 | - * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
646 | - * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
647 | - * @param string $payment_status The payment status being matched. |
|
648 | - * @return bool|string The payment message type slug matching the status or false if no match. |
|
649 | - * @throws EE_Error |
|
650 | - * @throws InvalidArgumentException |
|
651 | - * @throws ReflectionException |
|
652 | - * @throws InvalidDataTypeException |
|
653 | - * @throws InvalidInterfaceException |
|
654 | - */ |
|
655 | - protected static function _get_payment_message_type($payment_status) |
|
656 | - { |
|
657 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
658 | - return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
659 | - ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
660 | - : false; |
|
661 | - } |
|
662 | - |
|
663 | - |
|
664 | - /** |
|
665 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
666 | - * |
|
667 | - * @access public |
|
668 | - * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
669 | - * @return bool success/fail |
|
670 | - * @throws EE_Error |
|
671 | - * @throws InvalidArgumentException |
|
672 | - * @throws InvalidDataTypeException |
|
673 | - * @throws InvalidInterfaceException |
|
674 | - * @throws ReflectionException |
|
675 | - */ |
|
676 | - public static function process_resend($req_data) |
|
677 | - { |
|
678 | - self::_load_controller(); |
|
679 | - |
|
680 | - //if $msgID in this request then skip to the new resend_message |
|
681 | - if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
682 | - return self::resend_message(); |
|
683 | - } |
|
684 | - |
|
685 | - //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
686 | - $req_data = (array)$req_data; |
|
687 | - foreach ($req_data as $request_key => $request_value) { |
|
688 | - EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
689 | - } |
|
690 | - |
|
691 | - if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
692 | - return false; |
|
693 | - } |
|
694 | - |
|
695 | - try { |
|
696 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
697 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
698 | - } catch (EE_Error $e) { |
|
699 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
700 | - return false; |
|
701 | - } |
|
702 | - EE_Error::add_success( |
|
703 | - __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
704 | - ); |
|
705 | - return true; //everything got queued. |
|
706 | - } |
|
707 | - |
|
708 | - |
|
709 | - /** |
|
710 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
711 | - * |
|
712 | - * @return bool |
|
713 | - * @throws EE_Error |
|
714 | - * @throws InvalidArgumentException |
|
715 | - * @throws InvalidDataTypeException |
|
716 | - * @throws InvalidInterfaceException |
|
717 | - * @throws ReflectionException |
|
718 | - */ |
|
719 | - public static function resend_message() |
|
720 | - { |
|
721 | - self::_load_controller(); |
|
722 | - |
|
723 | - $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
724 | - if (! $msgID) { |
|
725 | - EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
726 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
727 | - return false; |
|
728 | - } |
|
729 | - |
|
730 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
731 | - |
|
732 | - //setup success message. |
|
733 | - $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
734 | - EE_Error::add_success(sprintf( |
|
735 | - _n( |
|
736 | - 'There was %d message queued for resending.', |
|
737 | - 'There were %d messages queued for resending.', |
|
738 | - $count_ready_for_resend, |
|
739 | - 'event_espresso' |
|
740 | - ), |
|
741 | - $count_ready_for_resend |
|
742 | - )); |
|
743 | - return true; |
|
744 | - } |
|
745 | - |
|
746 | - |
|
747 | - /** |
|
748 | - * Message triggers for manual payment applied by admin |
|
749 | - * |
|
750 | - * @param EE_Payment $payment EE_payment object |
|
751 | - * @return bool success/fail |
|
752 | - * @throws EE_Error |
|
753 | - * @throws InvalidArgumentException |
|
754 | - * @throws ReflectionException |
|
755 | - * @throws InvalidDataTypeException |
|
756 | - * @throws InvalidInterfaceException |
|
757 | - */ |
|
758 | - public static function process_admin_payment(EE_Payment $payment) |
|
759 | - { |
|
760 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
761 | - //we need to get the transaction object |
|
762 | - $transaction = $payment->transaction(); |
|
763 | - if ($transaction instanceof EE_Transaction) { |
|
764 | - $data = array($transaction, $payment); |
|
765 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
766 | - |
|
767 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
768 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
769 | - |
|
770 | - //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
771 | - $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
772 | - |
|
773 | - self::_load_controller(); |
|
774 | - |
|
775 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
776 | - |
|
777 | - //get count of queued for generation |
|
778 | - $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
779 | - EEM_Message::status_incomplete, |
|
780 | - EEM_Message::status_idle, |
|
781 | - )); |
|
782 | - |
|
783 | - if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
784 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
785 | - return true; |
|
786 | - } else { |
|
787 | - $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
788 | - /** |
|
789 | - * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
790 | - * IMMEDIATE generation. |
|
791 | - */ |
|
792 | - if ($count_failed > 0) { |
|
793 | - EE_Error::add_error(sprintf( |
|
794 | - _n( |
|
795 | - 'The payment notification generation failed.', |
|
796 | - '%d payment notifications failed being sent.', |
|
797 | - $count_failed, |
|
798 | - 'event_espresso' |
|
799 | - ), |
|
800 | - $count_failed |
|
801 | - ), __FILE__, __FUNCTION__, __LINE__); |
|
802 | - |
|
803 | - return false; |
|
804 | - } else { |
|
805 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
806 | - return true; |
|
807 | - } |
|
808 | - } |
|
809 | - } else { |
|
810 | - EE_Error::add_error( |
|
811 | - 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
812 | - 'event_espresso' |
|
813 | - ); |
|
814 | - return false; |
|
815 | - } |
|
816 | - } |
|
817 | - |
|
818 | - |
|
819 | - /** |
|
820 | - * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
821 | - * |
|
822 | - * @since 4.3.0 |
|
823 | - * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
824 | - * @param int $grp_id a specific message template group id. |
|
825 | - * @return void |
|
826 | - * @throws EE_Error |
|
827 | - * @throws InvalidArgumentException |
|
828 | - * @throws InvalidDataTypeException |
|
829 | - * @throws InvalidInterfaceException |
|
830 | - * @throws ReflectionException |
|
831 | - */ |
|
832 | - public static function send_newsletter_message($registrations, $grp_id) |
|
833 | - { |
|
834 | - //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
835 | - EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
836 | - self::_load_controller(); |
|
837 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
838 | - } |
|
839 | - |
|
840 | - |
|
841 | - /** |
|
842 | - * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
843 | - * |
|
844 | - * @since 4.3.0 |
|
845 | - * @param string $registration_message_trigger_url |
|
846 | - * @param EE_Registration $registration |
|
847 | - * @param string $messenger |
|
848 | - * @param string $message_type |
|
849 | - * @return string |
|
850 | - * @throws EE_Error |
|
851 | - * @throws InvalidArgumentException |
|
852 | - * @throws InvalidDataTypeException |
|
853 | - * @throws InvalidInterfaceException |
|
854 | - */ |
|
855 | - public static function registration_message_trigger_url( |
|
856 | - $registration_message_trigger_url, |
|
857 | - EE_Registration $registration, |
|
858 | - $messenger = 'html', |
|
859 | - $message_type = 'invoice' |
|
860 | - ) { |
|
861 | - // whitelist $messenger |
|
862 | - switch ($messenger) { |
|
863 | - case 'pdf' : |
|
864 | - $sending_messenger = 'pdf'; |
|
865 | - $generating_messenger = 'html'; |
|
866 | - break; |
|
867 | - case 'html' : |
|
868 | - default : |
|
869 | - $sending_messenger = 'html'; |
|
870 | - $generating_messenger = 'html'; |
|
871 | - break; |
|
872 | - } |
|
873 | - // whitelist $message_type |
|
874 | - switch ($message_type) { |
|
875 | - case 'receipt' : |
|
876 | - $message_type = 'receipt'; |
|
877 | - break; |
|
878 | - case 'invoice' : |
|
879 | - default : |
|
880 | - $message_type = 'invoice'; |
|
881 | - break; |
|
882 | - } |
|
883 | - // verify that both the messenger AND the message type are active |
|
884 | - if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
885 | - //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
886 | - $template_query_params = array( |
|
887 | - 'MTP_is_active' => true, |
|
888 | - 'MTP_messenger' => $generating_messenger, |
|
889 | - 'MTP_message_type' => $message_type, |
|
890 | - 'Event.EVT_ID' => $registration->event_ID(), |
|
891 | - ); |
|
892 | - //get the message template group. |
|
893 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
894 | - //if we don't have an EE_Message_Template_Group then return |
|
895 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
896 | - // remove EVT_ID from query params so that global templates get picked up |
|
897 | - unset($template_query_params['Event.EVT_ID']); |
|
898 | - //get global template as the fallback |
|
899 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
900 | - } |
|
901 | - //if we don't have an EE_Message_Template_Group then return |
|
902 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
903 | - return ''; |
|
904 | - } |
|
905 | - // generate the URL |
|
906 | - $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
907 | - $sending_messenger, |
|
908 | - $generating_messenger, |
|
909 | - 'purchaser', |
|
910 | - $message_type, |
|
911 | - $registration, |
|
912 | - $msg_template_group->ID(), |
|
913 | - $registration->transaction_ID() |
|
914 | - ); |
|
915 | - |
|
916 | - } |
|
917 | - return $registration_message_trigger_url; |
|
918 | - } |
|
919 | - |
|
920 | - |
|
921 | - /** |
|
922 | - * Use to generate and return a message preview! |
|
923 | - * |
|
924 | - * @param string $type This should correspond with a valid message type |
|
925 | - * @param string $context This should correspond with a valid context for the message type |
|
926 | - * @param string $messenger This should correspond with a valid messenger. |
|
927 | - * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
928 | - * preview |
|
929 | - * @return bool|string The body of the message or if send is requested, sends. |
|
930 | - * @throws EE_Error |
|
931 | - * @throws InvalidArgumentException |
|
932 | - * @throws InvalidDataTypeException |
|
933 | - * @throws InvalidInterfaceException |
|
934 | - * @throws ReflectionException |
|
935 | - */ |
|
936 | - public static function preview_message($type, $context, $messenger, $send = false) |
|
937 | - { |
|
938 | - self::_load_controller(); |
|
939 | - $mtg = new EE_Message_To_Generate( |
|
940 | - $messenger, |
|
941 | - $type, |
|
942 | - array(), |
|
943 | - $context, |
|
944 | - true |
|
945 | - ); |
|
946 | - $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
947 | - if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
948 | - //loop through all content for the preview and remove any persisted records. |
|
949 | - $content = ''; |
|
950 | - foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
951 | - $content = $message->content(); |
|
952 | - if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
953 | - $message->delete(); |
|
954 | - } |
|
955 | - } |
|
956 | - return $content; |
|
957 | - } else { |
|
958 | - return $generated_preview_queue; |
|
959 | - } |
|
960 | - } |
|
961 | - |
|
962 | - |
|
963 | - /** |
|
964 | - * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
965 | - * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
966 | - * content found in the EE_Message objects in the queue. |
|
967 | - * |
|
968 | - * @since 4.9.0 |
|
969 | - * @param string $messenger a string matching a valid active messenger in the system |
|
970 | - * @param string $message_type Although it seems contrary to the name of the method, a message |
|
971 | - * type name is still required to send along the message type to the |
|
972 | - * messenger because this is used for determining what specific |
|
973 | - * variations might be loaded for the generated message. |
|
974 | - * @param EE_Messages_Queue $queue |
|
975 | - * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
976 | - * aggregate EE_Message object. |
|
977 | - * @return bool success or fail. |
|
978 | - * @throws EE_Error |
|
979 | - * @throws InvalidArgumentException |
|
980 | - * @throws ReflectionException |
|
981 | - * @throws InvalidDataTypeException |
|
982 | - * @throws InvalidInterfaceException |
|
983 | - */ |
|
984 | - public static function send_message_with_messenger_only( |
|
985 | - $messenger, |
|
986 | - $message_type, |
|
987 | - EE_Messages_Queue $queue, |
|
988 | - $custom_subject = '' |
|
989 | - ) { |
|
990 | - self::_load_controller(); |
|
991 | - /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
992 | - $message_to_generate = EE_Registry::instance()->load_lib( |
|
993 | - 'Message_To_Generate_From_Queue', |
|
994 | - array( |
|
995 | - $messenger, |
|
996 | - $message_type, |
|
997 | - $queue, |
|
998 | - $custom_subject, |
|
999 | - ) |
|
1000 | - ); |
|
1001 | - return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
1002 | - } |
|
1003 | - |
|
1004 | - |
|
1005 | - /** |
|
1006 | - * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
1007 | - * |
|
1008 | - * @since 4.9.0 |
|
1009 | - * @param array $message_ids An array of message ids |
|
1010 | - * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
1011 | - * messages. |
|
1012 | - * @throws EE_Error |
|
1013 | - * @throws InvalidArgumentException |
|
1014 | - * @throws InvalidDataTypeException |
|
1015 | - * @throws InvalidInterfaceException |
|
1016 | - * @throws ReflectionException |
|
1017 | - */ |
|
1018 | - public static function generate_now($message_ids) |
|
1019 | - { |
|
1020 | - self::_load_controller(); |
|
1021 | - $messages = EEM_Message::instance()->get_all( |
|
1022 | - array( |
|
1023 | - 0 => array( |
|
1024 | - 'MSG_ID' => array('IN', $message_ids), |
|
1025 | - 'STS_ID' => EEM_Message::status_incomplete, |
|
1026 | - ), |
|
1027 | - ) |
|
1028 | - ); |
|
1029 | - $generated_queue = false; |
|
1030 | - if ($messages) { |
|
1031 | - $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
1032 | - } |
|
1033 | - |
|
1034 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
1035 | - EE_Error::add_error( |
|
1036 | - __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
1037 | - 'event_espresso'), |
|
1038 | - __FILE__, __FUNCTION__, __LINE__ |
|
1039 | - ); |
|
1040 | - } |
|
1041 | - return $generated_queue; |
|
1042 | - } |
|
1043 | - |
|
1044 | - |
|
1045 | - /** |
|
1046 | - * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
1047 | - * EEM_Message::status_idle |
|
1048 | - * |
|
1049 | - * @since 4.9.0 |
|
1050 | - * @param $message_ids |
|
1051 | - * @return bool|EE_Messages_Queue false if no messages sent. |
|
1052 | - * @throws EE_Error |
|
1053 | - * @throws InvalidArgumentException |
|
1054 | - * @throws InvalidDataTypeException |
|
1055 | - * @throws InvalidInterfaceException |
|
1056 | - * @throws ReflectionException |
|
1057 | - */ |
|
1058 | - public static function send_now($message_ids) |
|
1059 | - { |
|
1060 | - self::_load_controller(); |
|
1061 | - $messages = EEM_Message::instance()->get_all( |
|
1062 | - array( |
|
1063 | - 0 => array( |
|
1064 | - 'MSG_ID' => array('IN', $message_ids), |
|
1065 | - 'STS_ID' => array( |
|
1066 | - 'IN', |
|
1067 | - array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
1068 | - ), |
|
1069 | - ), |
|
1070 | - ) |
|
1071 | - ); |
|
1072 | - $sent_queue = false; |
|
1073 | - if ($messages) { |
|
1074 | - $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
1075 | - } |
|
1076 | - |
|
1077 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
1078 | - EE_Error::add_error( |
|
1079 | - __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
1080 | - 'event_espresso'), |
|
1081 | - __FILE__, __FUNCTION__, __LINE__ |
|
1082 | - ); |
|
1083 | - } else { |
|
1084 | - //can count how many sent by using the messages in the queue |
|
1085 | - $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
1086 | - if ($sent_count > 0) { |
|
1087 | - EE_Error::add_success( |
|
1088 | - sprintf( |
|
1089 | - _n( |
|
1090 | - 'There was %d message successfully sent.', |
|
1091 | - 'There were %d messages successfully sent.', |
|
1092 | - $sent_count, |
|
1093 | - 'event_espresso' |
|
1094 | - ), |
|
1095 | - $sent_count |
|
1096 | - ) |
|
1097 | - ); |
|
1098 | - } else { |
|
1099 | - EE_Error::overwrite_errors(); |
|
1100 | - EE_Error::add_error( |
|
1101 | - __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
215 | + exit; |
|
216 | + } |
|
217 | + } |
|
218 | + return; |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * This runs when the msg_url_trigger route has initiated. |
|
224 | + * |
|
225 | + * @since 4.5.0 |
|
226 | + * @param WP $WP |
|
227 | + * @throws EE_Error |
|
228 | + * @throws InvalidArgumentException |
|
229 | + * @throws ReflectionException |
|
230 | + * @throws InvalidDataTypeException |
|
231 | + * @throws InvalidInterfaceException |
|
232 | + */ |
|
233 | + public function run($WP) |
|
234 | + { |
|
235 | + //ensure controller is loaded |
|
236 | + self::_load_controller(); |
|
237 | + // attempt to process message |
|
238 | + try { |
|
239 | + /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
240 | + $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
241 | + self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
242 | + } catch (EE_Error $e) { |
|
243 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
244 | + 'event_espresso'); |
|
245 | + // add specific message for developers if WP_DEBUG in on |
|
246 | + $error_msg .= '||' . $e->getMessage(); |
|
247 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
248 | + } |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * This is triggered by the 'msg_cron_trigger' route. |
|
254 | + * |
|
255 | + * @param WP $WP |
|
256 | + */ |
|
257 | + public function execute_batch_request($WP) |
|
258 | + { |
|
259 | + $this->run_cron(); |
|
260 | + header('HTTP/1.1 200 OK'); |
|
261 | + exit(); |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
267 | + * request. |
|
268 | + */ |
|
269 | + public function run_cron() |
|
270 | + { |
|
271 | + self::_load_controller(); |
|
272 | + //get required vars |
|
273 | + $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
274 | + $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
275 | + |
|
276 | + //now let's verify transient, if not valid exit immediately |
|
277 | + if (! get_transient($transient_key)) { |
|
278 | + /** |
|
279 | + * trigger error so this gets in the error logs. This is important because it happens on a non-user |
|
280 | + * request. |
|
281 | + */ |
|
282 | + trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
283 | + } |
|
284 | + |
|
285 | + //if made it here, lets' delete the transient to keep the db clean |
|
286 | + delete_transient($transient_key); |
|
287 | + |
|
288 | + if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
289 | + |
|
290 | + $method = 'batch_' . $cron_type . '_from_queue'; |
|
291 | + if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
292 | + self::$_MSG_PROCESSOR->$method(); |
|
293 | + } else { |
|
294 | + //no matching task |
|
295 | + /** |
|
296 | + * trigger error so this gets in the error logs. This is important because it happens on a non user |
|
297 | + * request. |
|
298 | + */ |
|
299 | + trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
300 | + $cron_type))); |
|
301 | + } |
|
302 | + } |
|
303 | + |
|
304 | + do_action('FHEE__EED_Messages__run_cron__end'); |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * This is used to retrieve the template pack for the given name. |
|
310 | + * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
311 | + * the default template pack is returned. |
|
312 | + * |
|
313 | + * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
314 | + * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
315 | + * in generating the Pack class name). |
|
316 | + * @return EE_Messages_Template_Pack |
|
317 | + * @throws EE_Error |
|
318 | + * @throws InvalidArgumentException |
|
319 | + * @throws ReflectionException |
|
320 | + * @throws InvalidDataTypeException |
|
321 | + * @throws InvalidInterfaceException |
|
322 | + */ |
|
323 | + public static function get_template_pack($template_pack_name) |
|
324 | + { |
|
325 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
326 | + return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * Retrieves an array of all template packs. |
|
332 | + * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
333 | + * |
|
334 | + * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
335 | + * @return EE_Messages_Template_Pack[] |
|
336 | + * @throws EE_Error |
|
337 | + * @throws InvalidArgumentException |
|
338 | + * @throws ReflectionException |
|
339 | + * @throws InvalidDataTypeException |
|
340 | + * @throws InvalidInterfaceException |
|
341 | + */ |
|
342 | + public static function get_template_packs() |
|
343 | + { |
|
344 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
345 | + |
|
346 | + //for backward compat, let's make sure this returns in the same format as originally. |
|
347 | + $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
348 | + $template_pack_collection->rewind(); |
|
349 | + $template_packs = array(); |
|
350 | + while ($template_pack_collection->valid()) { |
|
351 | + $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
352 | + $template_pack_collection->next(); |
|
353 | + } |
|
354 | + return $template_packs; |
|
355 | + } |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
360 | + * |
|
361 | + * @since 4.5.0 |
|
362 | + * @return void |
|
363 | + * @throws EE_Error |
|
364 | + */ |
|
365 | + public static function set_autoloaders() |
|
366 | + { |
|
367 | + if (empty(self::$_MSG_PATHS)) { |
|
368 | + self::_set_messages_paths(); |
|
369 | + foreach (self::$_MSG_PATHS as $path) { |
|
370 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
371 | + } |
|
372 | + // add aliases |
|
373 | + EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
374 | + EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
375 | + } |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
381 | + * for use by the Messages Autoloaders |
|
382 | + * |
|
383 | + * @since 4.5.0 |
|
384 | + * @return void. |
|
385 | + */ |
|
386 | + protected static function _set_messages_paths() |
|
387 | + { |
|
388 | + $dir_ref = array( |
|
389 | + 'messages/message_type', |
|
390 | + 'messages/messenger', |
|
391 | + 'messages/defaults', |
|
392 | + 'messages/defaults/email', |
|
393 | + 'messages/data_class', |
|
394 | + 'messages/validators', |
|
395 | + 'messages/validators/email', |
|
396 | + 'messages/validators/html', |
|
397 | + 'shortcodes', |
|
398 | + ); |
|
399 | + $paths = array(); |
|
400 | + foreach ($dir_ref as $index => $dir) { |
|
401 | + $paths[$index] = EE_LIBRARIES . $dir; |
|
402 | + } |
|
403 | + self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * Takes care of loading dependencies |
|
409 | + * |
|
410 | + * @since 4.5.0 |
|
411 | + * @return void |
|
412 | + * @throws EE_Error |
|
413 | + * @throws InvalidArgumentException |
|
414 | + * @throws ReflectionException |
|
415 | + * @throws InvalidDataTypeException |
|
416 | + * @throws InvalidInterfaceException |
|
417 | + */ |
|
418 | + protected static function _load_controller() |
|
419 | + { |
|
420 | + if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
421 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
422 | + self::set_autoloaders(); |
|
423 | + self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
424 | + self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
425 | + self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
426 | + } |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + /** |
|
431 | + * @param EE_Transaction $transaction |
|
432 | + * @throws EE_Error |
|
433 | + * @throws InvalidArgumentException |
|
434 | + * @throws InvalidDataTypeException |
|
435 | + * @throws InvalidInterfaceException |
|
436 | + * @throws ReflectionException |
|
437 | + */ |
|
438 | + public static function payment_reminder(EE_Transaction $transaction) |
|
439 | + { |
|
440 | + self::_load_controller(); |
|
441 | + $data = array($transaction, null); |
|
442 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * Any messages triggers for after successful gateway payments should go in here. |
|
448 | + * |
|
449 | + * @param EE_Transaction $transaction object |
|
450 | + * @param EE_Payment|null $payment object |
|
451 | + * @return void |
|
452 | + * @throws EE_Error |
|
453 | + * @throws InvalidArgumentException |
|
454 | + * @throws ReflectionException |
|
455 | + * @throws InvalidDataTypeException |
|
456 | + * @throws InvalidInterfaceException |
|
457 | + */ |
|
458 | + public static function payment(EE_Transaction $transaction, EE_Payment $payment = null) |
|
459 | + { |
|
460 | + //if there's no payment object, then we cannot do a payment type message! |
|
461 | + if (! $payment instanceof EE_Payment) { |
|
462 | + return; |
|
463 | + } |
|
464 | + self::_load_controller(); |
|
465 | + $data = array($transaction, $payment); |
|
466 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
467 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
468 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
469 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
470 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
471 | + } |
|
472 | + |
|
473 | + |
|
474 | + /** |
|
475 | + * @param EE_Transaction $transaction |
|
476 | + * @throws EE_Error |
|
477 | + * @throws InvalidArgumentException |
|
478 | + * @throws InvalidDataTypeException |
|
479 | + * @throws InvalidInterfaceException |
|
480 | + * @throws ReflectionException |
|
481 | + */ |
|
482 | + public static function cancelled_registration(EE_Transaction $transaction) |
|
483 | + { |
|
484 | + self::_load_controller(); |
|
485 | + $data = array($transaction, null); |
|
486 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
487 | + } |
|
488 | + |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * Trigger for Registration messages |
|
493 | + * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
494 | + * incoming transaction. |
|
495 | + * |
|
496 | + * @param EE_Registration $registration |
|
497 | + * @param array $extra_details |
|
498 | + * @return void |
|
499 | + * @throws EE_Error |
|
500 | + * @throws InvalidArgumentException |
|
501 | + * @throws InvalidDataTypeException |
|
502 | + * @throws InvalidInterfaceException |
|
503 | + * @throws ReflectionException |
|
504 | + * @throws EntityNotFoundException |
|
505 | + */ |
|
506 | + public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
507 | + { |
|
508 | + |
|
509 | + if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
510 | + //no messages please |
|
511 | + return; |
|
512 | + } |
|
513 | + |
|
514 | + // get all non-trashed registrations so we make sure we send messages for the right status. |
|
515 | + $all_registrations = $registration->transaction()->registrations( |
|
516 | + array( |
|
517 | + array('REG_deleted' => false), |
|
518 | + 'order_by' => array( |
|
519 | + 'Event.EVT_name' => 'ASC', |
|
520 | + 'Attendee.ATT_lname' => 'ASC', |
|
521 | + 'Attendee.ATT_fname' => 'ASC' |
|
522 | + ) |
|
523 | + ) |
|
524 | + ); |
|
525 | + //cached array of statuses so we only trigger messages once per status. |
|
526 | + $statuses_sent = array(); |
|
527 | + self::_load_controller(); |
|
528 | + $mtgs = array(); |
|
529 | + |
|
530 | + //loop through registrations and trigger messages once per status. |
|
531 | + foreach ($all_registrations as $reg) { |
|
532 | + |
|
533 | + //already triggered? |
|
534 | + if (in_array($reg->status_ID(), $statuses_sent)) { |
|
535 | + continue; |
|
536 | + } |
|
537 | + |
|
538 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
539 | + $mtgs = array_merge( |
|
540 | + $mtgs, |
|
541 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
542 | + $message_type, |
|
543 | + array($registration->transaction(), null, $reg->status_ID()) |
|
544 | + ) |
|
545 | + ); |
|
546 | + $statuses_sent[] = $reg->status_ID(); |
|
547 | + } |
|
548 | + |
|
549 | + if (count($statuses_sent) > 1) { |
|
550 | + $mtgs = array_merge( |
|
551 | + $mtgs, |
|
552 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
553 | + 'registration_summary', |
|
554 | + array($registration->transaction(), null) |
|
555 | + ) |
|
556 | + ); |
|
557 | + } |
|
558 | + |
|
559 | + //batch queue and initiate request |
|
560 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
561 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
562 | + } |
|
563 | + |
|
564 | + |
|
565 | + /** |
|
566 | + * This is a helper method used to very whether a registration notification should be sent or |
|
567 | + * not. Prevents duplicate notifications going out for registration context notifications. |
|
568 | + * |
|
569 | + * @param EE_Registration $registration [description] |
|
570 | + * @param array $extra_details [description] |
|
571 | + * @return bool true = send away, false = nope halt the presses. |
|
572 | + */ |
|
573 | + protected static function _verify_registration_notification_send( |
|
574 | + EE_Registration $registration, |
|
575 | + $extra_details = array() |
|
576 | + ) { |
|
577 | + //self::log( |
|
578 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
579 | + // $registration->transaction(), |
|
580 | + // array( '$extra_details' => $extra_details ) |
|
581 | + //); |
|
582 | + // currently only using this to send messages for the primary registrant |
|
583 | + if (! $registration->is_primary_registrant()) { |
|
584 | + return false; |
|
585 | + } |
|
586 | + // first we check if we're in admin and not doing front ajax |
|
587 | + if (is_admin() && ! EE_FRONT_AJAX) { |
|
588 | + //make sure appropriate admin params are set for sending messages |
|
589 | + if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
590 | + //no messages sent please. |
|
591 | + return false; |
|
592 | + } |
|
593 | + } else { |
|
594 | + // frontend request (either regular or via AJAX) |
|
595 | + // TXN is NOT finalized ? |
|
596 | + if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
597 | + return false; |
|
598 | + } |
|
599 | + // return visit but nothing changed ??? |
|
600 | + if ( |
|
601 | + isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
602 | + $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
603 | + ) { |
|
604 | + return false; |
|
605 | + } |
|
606 | + // NOT sending messages && reg status is something other than "Not-Approved" |
|
607 | + if ( |
|
608 | + ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
609 | + $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
610 | + ) { |
|
611 | + return false; |
|
612 | + } |
|
613 | + } |
|
614 | + // release the kraken |
|
615 | + return true; |
|
616 | + } |
|
617 | + |
|
618 | + |
|
619 | + /** |
|
620 | + * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
621 | + * status id. |
|
622 | + * |
|
623 | + * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
624 | + * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
625 | + * @param string $reg_status |
|
626 | + * @return array |
|
627 | + * @throws EE_Error |
|
628 | + * @throws InvalidArgumentException |
|
629 | + * @throws ReflectionException |
|
630 | + * @throws InvalidDataTypeException |
|
631 | + * @throws InvalidInterfaceException |
|
632 | + */ |
|
633 | + protected static function _get_reg_status_array($reg_status = '') |
|
634 | + { |
|
635 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
636 | + return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
637 | + ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
638 | + : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
639 | + } |
|
640 | + |
|
641 | + |
|
642 | + /** |
|
643 | + * Simply returns the payment message type for the given payment status. |
|
644 | + * |
|
645 | + * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
646 | + * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
647 | + * @param string $payment_status The payment status being matched. |
|
648 | + * @return bool|string The payment message type slug matching the status or false if no match. |
|
649 | + * @throws EE_Error |
|
650 | + * @throws InvalidArgumentException |
|
651 | + * @throws ReflectionException |
|
652 | + * @throws InvalidDataTypeException |
|
653 | + * @throws InvalidInterfaceException |
|
654 | + */ |
|
655 | + protected static function _get_payment_message_type($payment_status) |
|
656 | + { |
|
657 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
658 | + return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
659 | + ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
660 | + : false; |
|
661 | + } |
|
662 | + |
|
663 | + |
|
664 | + /** |
|
665 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
666 | + * |
|
667 | + * @access public |
|
668 | + * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
669 | + * @return bool success/fail |
|
670 | + * @throws EE_Error |
|
671 | + * @throws InvalidArgumentException |
|
672 | + * @throws InvalidDataTypeException |
|
673 | + * @throws InvalidInterfaceException |
|
674 | + * @throws ReflectionException |
|
675 | + */ |
|
676 | + public static function process_resend($req_data) |
|
677 | + { |
|
678 | + self::_load_controller(); |
|
679 | + |
|
680 | + //if $msgID in this request then skip to the new resend_message |
|
681 | + if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
682 | + return self::resend_message(); |
|
683 | + } |
|
684 | + |
|
685 | + //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
686 | + $req_data = (array)$req_data; |
|
687 | + foreach ($req_data as $request_key => $request_value) { |
|
688 | + EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
689 | + } |
|
690 | + |
|
691 | + if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
692 | + return false; |
|
693 | + } |
|
694 | + |
|
695 | + try { |
|
696 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
697 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
698 | + } catch (EE_Error $e) { |
|
699 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
700 | + return false; |
|
701 | + } |
|
702 | + EE_Error::add_success( |
|
703 | + __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
704 | + ); |
|
705 | + return true; //everything got queued. |
|
706 | + } |
|
707 | + |
|
708 | + |
|
709 | + /** |
|
710 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
711 | + * |
|
712 | + * @return bool |
|
713 | + * @throws EE_Error |
|
714 | + * @throws InvalidArgumentException |
|
715 | + * @throws InvalidDataTypeException |
|
716 | + * @throws InvalidInterfaceException |
|
717 | + * @throws ReflectionException |
|
718 | + */ |
|
719 | + public static function resend_message() |
|
720 | + { |
|
721 | + self::_load_controller(); |
|
722 | + |
|
723 | + $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
724 | + if (! $msgID) { |
|
725 | + EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
726 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
727 | + return false; |
|
728 | + } |
|
729 | + |
|
730 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
731 | + |
|
732 | + //setup success message. |
|
733 | + $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
734 | + EE_Error::add_success(sprintf( |
|
735 | + _n( |
|
736 | + 'There was %d message queued for resending.', |
|
737 | + 'There were %d messages queued for resending.', |
|
738 | + $count_ready_for_resend, |
|
739 | + 'event_espresso' |
|
740 | + ), |
|
741 | + $count_ready_for_resend |
|
742 | + )); |
|
743 | + return true; |
|
744 | + } |
|
745 | + |
|
746 | + |
|
747 | + /** |
|
748 | + * Message triggers for manual payment applied by admin |
|
749 | + * |
|
750 | + * @param EE_Payment $payment EE_payment object |
|
751 | + * @return bool success/fail |
|
752 | + * @throws EE_Error |
|
753 | + * @throws InvalidArgumentException |
|
754 | + * @throws ReflectionException |
|
755 | + * @throws InvalidDataTypeException |
|
756 | + * @throws InvalidInterfaceException |
|
757 | + */ |
|
758 | + public static function process_admin_payment(EE_Payment $payment) |
|
759 | + { |
|
760 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
761 | + //we need to get the transaction object |
|
762 | + $transaction = $payment->transaction(); |
|
763 | + if ($transaction instanceof EE_Transaction) { |
|
764 | + $data = array($transaction, $payment); |
|
765 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
766 | + |
|
767 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
768 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
769 | + |
|
770 | + //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
771 | + $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
772 | + |
|
773 | + self::_load_controller(); |
|
774 | + |
|
775 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
776 | + |
|
777 | + //get count of queued for generation |
|
778 | + $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
779 | + EEM_Message::status_incomplete, |
|
780 | + EEM_Message::status_idle, |
|
781 | + )); |
|
782 | + |
|
783 | + if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
784 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
785 | + return true; |
|
786 | + } else { |
|
787 | + $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
788 | + /** |
|
789 | + * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
790 | + * IMMEDIATE generation. |
|
791 | + */ |
|
792 | + if ($count_failed > 0) { |
|
793 | + EE_Error::add_error(sprintf( |
|
794 | + _n( |
|
795 | + 'The payment notification generation failed.', |
|
796 | + '%d payment notifications failed being sent.', |
|
797 | + $count_failed, |
|
798 | + 'event_espresso' |
|
799 | + ), |
|
800 | + $count_failed |
|
801 | + ), __FILE__, __FUNCTION__, __LINE__); |
|
802 | + |
|
803 | + return false; |
|
804 | + } else { |
|
805 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
806 | + return true; |
|
807 | + } |
|
808 | + } |
|
809 | + } else { |
|
810 | + EE_Error::add_error( |
|
811 | + 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
812 | + 'event_espresso' |
|
813 | + ); |
|
814 | + return false; |
|
815 | + } |
|
816 | + } |
|
817 | + |
|
818 | + |
|
819 | + /** |
|
820 | + * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
821 | + * |
|
822 | + * @since 4.3.0 |
|
823 | + * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
824 | + * @param int $grp_id a specific message template group id. |
|
825 | + * @return void |
|
826 | + * @throws EE_Error |
|
827 | + * @throws InvalidArgumentException |
|
828 | + * @throws InvalidDataTypeException |
|
829 | + * @throws InvalidInterfaceException |
|
830 | + * @throws ReflectionException |
|
831 | + */ |
|
832 | + public static function send_newsletter_message($registrations, $grp_id) |
|
833 | + { |
|
834 | + //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
835 | + EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
836 | + self::_load_controller(); |
|
837 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
838 | + } |
|
839 | + |
|
840 | + |
|
841 | + /** |
|
842 | + * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
843 | + * |
|
844 | + * @since 4.3.0 |
|
845 | + * @param string $registration_message_trigger_url |
|
846 | + * @param EE_Registration $registration |
|
847 | + * @param string $messenger |
|
848 | + * @param string $message_type |
|
849 | + * @return string |
|
850 | + * @throws EE_Error |
|
851 | + * @throws InvalidArgumentException |
|
852 | + * @throws InvalidDataTypeException |
|
853 | + * @throws InvalidInterfaceException |
|
854 | + */ |
|
855 | + public static function registration_message_trigger_url( |
|
856 | + $registration_message_trigger_url, |
|
857 | + EE_Registration $registration, |
|
858 | + $messenger = 'html', |
|
859 | + $message_type = 'invoice' |
|
860 | + ) { |
|
861 | + // whitelist $messenger |
|
862 | + switch ($messenger) { |
|
863 | + case 'pdf' : |
|
864 | + $sending_messenger = 'pdf'; |
|
865 | + $generating_messenger = 'html'; |
|
866 | + break; |
|
867 | + case 'html' : |
|
868 | + default : |
|
869 | + $sending_messenger = 'html'; |
|
870 | + $generating_messenger = 'html'; |
|
871 | + break; |
|
872 | + } |
|
873 | + // whitelist $message_type |
|
874 | + switch ($message_type) { |
|
875 | + case 'receipt' : |
|
876 | + $message_type = 'receipt'; |
|
877 | + break; |
|
878 | + case 'invoice' : |
|
879 | + default : |
|
880 | + $message_type = 'invoice'; |
|
881 | + break; |
|
882 | + } |
|
883 | + // verify that both the messenger AND the message type are active |
|
884 | + if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
885 | + //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
886 | + $template_query_params = array( |
|
887 | + 'MTP_is_active' => true, |
|
888 | + 'MTP_messenger' => $generating_messenger, |
|
889 | + 'MTP_message_type' => $message_type, |
|
890 | + 'Event.EVT_ID' => $registration->event_ID(), |
|
891 | + ); |
|
892 | + //get the message template group. |
|
893 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
894 | + //if we don't have an EE_Message_Template_Group then return |
|
895 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
896 | + // remove EVT_ID from query params so that global templates get picked up |
|
897 | + unset($template_query_params['Event.EVT_ID']); |
|
898 | + //get global template as the fallback |
|
899 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
900 | + } |
|
901 | + //if we don't have an EE_Message_Template_Group then return |
|
902 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
903 | + return ''; |
|
904 | + } |
|
905 | + // generate the URL |
|
906 | + $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
907 | + $sending_messenger, |
|
908 | + $generating_messenger, |
|
909 | + 'purchaser', |
|
910 | + $message_type, |
|
911 | + $registration, |
|
912 | + $msg_template_group->ID(), |
|
913 | + $registration->transaction_ID() |
|
914 | + ); |
|
915 | + |
|
916 | + } |
|
917 | + return $registration_message_trigger_url; |
|
918 | + } |
|
919 | + |
|
920 | + |
|
921 | + /** |
|
922 | + * Use to generate and return a message preview! |
|
923 | + * |
|
924 | + * @param string $type This should correspond with a valid message type |
|
925 | + * @param string $context This should correspond with a valid context for the message type |
|
926 | + * @param string $messenger This should correspond with a valid messenger. |
|
927 | + * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
928 | + * preview |
|
929 | + * @return bool|string The body of the message or if send is requested, sends. |
|
930 | + * @throws EE_Error |
|
931 | + * @throws InvalidArgumentException |
|
932 | + * @throws InvalidDataTypeException |
|
933 | + * @throws InvalidInterfaceException |
|
934 | + * @throws ReflectionException |
|
935 | + */ |
|
936 | + public static function preview_message($type, $context, $messenger, $send = false) |
|
937 | + { |
|
938 | + self::_load_controller(); |
|
939 | + $mtg = new EE_Message_To_Generate( |
|
940 | + $messenger, |
|
941 | + $type, |
|
942 | + array(), |
|
943 | + $context, |
|
944 | + true |
|
945 | + ); |
|
946 | + $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
947 | + if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
948 | + //loop through all content for the preview and remove any persisted records. |
|
949 | + $content = ''; |
|
950 | + foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
951 | + $content = $message->content(); |
|
952 | + if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
953 | + $message->delete(); |
|
954 | + } |
|
955 | + } |
|
956 | + return $content; |
|
957 | + } else { |
|
958 | + return $generated_preview_queue; |
|
959 | + } |
|
960 | + } |
|
961 | + |
|
962 | + |
|
963 | + /** |
|
964 | + * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
965 | + * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
966 | + * content found in the EE_Message objects in the queue. |
|
967 | + * |
|
968 | + * @since 4.9.0 |
|
969 | + * @param string $messenger a string matching a valid active messenger in the system |
|
970 | + * @param string $message_type Although it seems contrary to the name of the method, a message |
|
971 | + * type name is still required to send along the message type to the |
|
972 | + * messenger because this is used for determining what specific |
|
973 | + * variations might be loaded for the generated message. |
|
974 | + * @param EE_Messages_Queue $queue |
|
975 | + * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
976 | + * aggregate EE_Message object. |
|
977 | + * @return bool success or fail. |
|
978 | + * @throws EE_Error |
|
979 | + * @throws InvalidArgumentException |
|
980 | + * @throws ReflectionException |
|
981 | + * @throws InvalidDataTypeException |
|
982 | + * @throws InvalidInterfaceException |
|
983 | + */ |
|
984 | + public static function send_message_with_messenger_only( |
|
985 | + $messenger, |
|
986 | + $message_type, |
|
987 | + EE_Messages_Queue $queue, |
|
988 | + $custom_subject = '' |
|
989 | + ) { |
|
990 | + self::_load_controller(); |
|
991 | + /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
992 | + $message_to_generate = EE_Registry::instance()->load_lib( |
|
993 | + 'Message_To_Generate_From_Queue', |
|
994 | + array( |
|
995 | + $messenger, |
|
996 | + $message_type, |
|
997 | + $queue, |
|
998 | + $custom_subject, |
|
999 | + ) |
|
1000 | + ); |
|
1001 | + return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
1002 | + } |
|
1003 | + |
|
1004 | + |
|
1005 | + /** |
|
1006 | + * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
1007 | + * |
|
1008 | + * @since 4.9.0 |
|
1009 | + * @param array $message_ids An array of message ids |
|
1010 | + * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
1011 | + * messages. |
|
1012 | + * @throws EE_Error |
|
1013 | + * @throws InvalidArgumentException |
|
1014 | + * @throws InvalidDataTypeException |
|
1015 | + * @throws InvalidInterfaceException |
|
1016 | + * @throws ReflectionException |
|
1017 | + */ |
|
1018 | + public static function generate_now($message_ids) |
|
1019 | + { |
|
1020 | + self::_load_controller(); |
|
1021 | + $messages = EEM_Message::instance()->get_all( |
|
1022 | + array( |
|
1023 | + 0 => array( |
|
1024 | + 'MSG_ID' => array('IN', $message_ids), |
|
1025 | + 'STS_ID' => EEM_Message::status_incomplete, |
|
1026 | + ), |
|
1027 | + ) |
|
1028 | + ); |
|
1029 | + $generated_queue = false; |
|
1030 | + if ($messages) { |
|
1031 | + $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
1032 | + } |
|
1033 | + |
|
1034 | + if (! $generated_queue instanceof EE_Messages_Queue) { |
|
1035 | + EE_Error::add_error( |
|
1036 | + __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
1037 | + 'event_espresso'), |
|
1038 | + __FILE__, __FUNCTION__, __LINE__ |
|
1039 | + ); |
|
1040 | + } |
|
1041 | + return $generated_queue; |
|
1042 | + } |
|
1043 | + |
|
1044 | + |
|
1045 | + /** |
|
1046 | + * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
1047 | + * EEM_Message::status_idle |
|
1048 | + * |
|
1049 | + * @since 4.9.0 |
|
1050 | + * @param $message_ids |
|
1051 | + * @return bool|EE_Messages_Queue false if no messages sent. |
|
1052 | + * @throws EE_Error |
|
1053 | + * @throws InvalidArgumentException |
|
1054 | + * @throws InvalidDataTypeException |
|
1055 | + * @throws InvalidInterfaceException |
|
1056 | + * @throws ReflectionException |
|
1057 | + */ |
|
1058 | + public static function send_now($message_ids) |
|
1059 | + { |
|
1060 | + self::_load_controller(); |
|
1061 | + $messages = EEM_Message::instance()->get_all( |
|
1062 | + array( |
|
1063 | + 0 => array( |
|
1064 | + 'MSG_ID' => array('IN', $message_ids), |
|
1065 | + 'STS_ID' => array( |
|
1066 | + 'IN', |
|
1067 | + array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
1068 | + ), |
|
1069 | + ), |
|
1070 | + ) |
|
1071 | + ); |
|
1072 | + $sent_queue = false; |
|
1073 | + if ($messages) { |
|
1074 | + $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
1075 | + } |
|
1076 | + |
|
1077 | + if (! $sent_queue instanceof EE_Messages_Queue) { |
|
1078 | + EE_Error::add_error( |
|
1079 | + __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
1080 | + 'event_espresso'), |
|
1081 | + __FILE__, __FUNCTION__, __LINE__ |
|
1082 | + ); |
|
1083 | + } else { |
|
1084 | + //can count how many sent by using the messages in the queue |
|
1085 | + $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
1086 | + if ($sent_count > 0) { |
|
1087 | + EE_Error::add_success( |
|
1088 | + sprintf( |
|
1089 | + _n( |
|
1090 | + 'There was %d message successfully sent.', |
|
1091 | + 'There were %d messages successfully sent.', |
|
1092 | + $sent_count, |
|
1093 | + 'event_espresso' |
|
1094 | + ), |
|
1095 | + $sent_count |
|
1096 | + ) |
|
1097 | + ); |
|
1098 | + } else { |
|
1099 | + EE_Error::overwrite_errors(); |
|
1100 | + EE_Error::add_error( |
|
1101 | + __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
1102 | 1102 | If there was an error, you can look at the messages in the message activity list table for any error messages.', |
1103 | - 'event_espresso'), |
|
1104 | - __FILE__, __FUNCTION__, __LINE__ |
|
1105 | - ); |
|
1106 | - } |
|
1107 | - } |
|
1108 | - return $sent_queue; |
|
1109 | - } |
|
1110 | - |
|
1111 | - |
|
1112 | - /** |
|
1113 | - * Generate and send immediately from the given $message_ids |
|
1114 | - * |
|
1115 | - * @param array $message_ids EE_Message entity ids. |
|
1116 | - * @throws EE_Error |
|
1117 | - * @throws InvalidArgumentException |
|
1118 | - * @throws InvalidDataTypeException |
|
1119 | - * @throws InvalidInterfaceException |
|
1120 | - * @throws ReflectionException |
|
1121 | - */ |
|
1122 | - public static function generate_and_send_now(array $message_ids) |
|
1123 | - { |
|
1124 | - $generated_queue = self::generate_now($message_ids); |
|
1125 | - //now let's just trigger sending immediately from this queue. |
|
1126 | - $messages_sent = $generated_queue instanceof EE_Messages_Queue |
|
1127 | - ? $generated_queue->execute() |
|
1128 | - : 0; |
|
1129 | - if ($messages_sent) { |
|
1130 | - EE_Error::add_success( |
|
1131 | - esc_html( |
|
1132 | - sprintf( |
|
1133 | - _n( |
|
1134 | - 'There was %d message successfully generated and sent.', |
|
1135 | - 'There were %d messages successfully generated and sent.', |
|
1136 | - $messages_sent, |
|
1137 | - 'event_espresso' |
|
1138 | - ), |
|
1139 | - $messages_sent |
|
1140 | - ) |
|
1141 | - ) |
|
1142 | - ); |
|
1143 | - //errors would be added via the generate_now method. |
|
1144 | - } |
|
1145 | - } |
|
1146 | - |
|
1147 | - |
|
1148 | - /** |
|
1149 | - * This will queue the incoming message ids for resending. |
|
1150 | - * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
1151 | - * |
|
1152 | - * @since 4.9.0 |
|
1153 | - * @param array $message_ids An array of EE_Message IDs |
|
1154 | - * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
1155 | - * resending. |
|
1156 | - * @throws EE_Error |
|
1157 | - * @throws InvalidArgumentException |
|
1158 | - * @throws InvalidDataTypeException |
|
1159 | - * @throws InvalidInterfaceException |
|
1160 | - * @throws ReflectionException |
|
1161 | - */ |
|
1162 | - public static function queue_for_resending($message_ids) |
|
1163 | - { |
|
1164 | - self::_load_controller(); |
|
1165 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
1166 | - |
|
1167 | - //get queue and count |
|
1168 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
1169 | - |
|
1170 | - if ( |
|
1171 | - $queue_count > 0 |
|
1172 | - ) { |
|
1173 | - EE_Error::add_success( |
|
1174 | - sprintf( |
|
1175 | - _n( |
|
1176 | - '%d message successfully queued for resending.', |
|
1177 | - '%d messages successfully queued for resending.', |
|
1178 | - $queue_count, |
|
1179 | - 'event_espresso' |
|
1180 | - ), |
|
1181 | - $queue_count |
|
1182 | - ) |
|
1183 | - ); |
|
1184 | - /** |
|
1185 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
1186 | - */ |
|
1187 | - } elseif ( |
|
1188 | - apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
1189 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
1190 | - ) { |
|
1191 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
1192 | - if ($queue_count > 0) { |
|
1193 | - EE_Error::add_success( |
|
1194 | - sprintf( |
|
1195 | - _n( |
|
1196 | - '%d message successfully sent.', |
|
1197 | - '%d messages successfully sent.', |
|
1198 | - $queue_count, |
|
1199 | - 'event_espresso' |
|
1200 | - ), |
|
1201 | - $queue_count |
|
1202 | - ) |
|
1203 | - ); |
|
1204 | - } else { |
|
1205 | - EE_Error::add_error( |
|
1206 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1207 | - 'event_espresso'), |
|
1208 | - __FILE__, __FUNCTION__, __LINE__ |
|
1209 | - ); |
|
1210 | - } |
|
1211 | - } else { |
|
1212 | - EE_Error::add_error( |
|
1213 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1214 | - 'event_espresso'), |
|
1215 | - __FILE__, __FUNCTION__, __LINE__ |
|
1216 | - ); |
|
1217 | - } |
|
1218 | - return (bool)$queue_count; |
|
1219 | - } |
|
1220 | - |
|
1221 | - |
|
1222 | - /** |
|
1223 | - * debug |
|
1224 | - * |
|
1225 | - * @param string $class |
|
1226 | - * @param string $func |
|
1227 | - * @param string $line |
|
1228 | - * @param \EE_Transaction $transaction |
|
1229 | - * @param array $info |
|
1230 | - * @param bool $display_request |
|
1231 | - * @throws EE_Error |
|
1232 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
1233 | - */ |
|
1234 | - protected static function log( |
|
1235 | - $class = '', |
|
1236 | - $func = '', |
|
1237 | - $line = '', |
|
1238 | - EE_Transaction $transaction, |
|
1239 | - $info = array(), |
|
1240 | - $display_request = false |
|
1241 | - ) { |
|
1242 | - if (defined('EE_DEBUG') && EE_DEBUG) { |
|
1243 | - if ($transaction instanceof EE_Transaction) { |
|
1244 | - // don't serialize objects |
|
1245 | - $info = EEH_Debug_Tools::strip_objects($info); |
|
1246 | - $info['TXN_status'] = $transaction->status_ID(); |
|
1247 | - $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
1248 | - if ($transaction->ID()) { |
|
1249 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
1250 | - EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
1251 | - } |
|
1252 | - } |
|
1253 | - } |
|
1254 | - |
|
1255 | - } |
|
1256 | - |
|
1257 | - |
|
1258 | - /** |
|
1259 | - * Resets all the static properties in this class when called. |
|
1260 | - */ |
|
1261 | - public static function reset() |
|
1262 | - { |
|
1263 | - self::$_EEMSG = null; |
|
1264 | - self::$_message_resource_manager = null; |
|
1265 | - self::$_MSG_PROCESSOR = null; |
|
1266 | - self::$_MSG_PATHS = null; |
|
1267 | - self::$_TMP_PACKS = array(); |
|
1268 | - } |
|
1103 | + 'event_espresso'), |
|
1104 | + __FILE__, __FUNCTION__, __LINE__ |
|
1105 | + ); |
|
1106 | + } |
|
1107 | + } |
|
1108 | + return $sent_queue; |
|
1109 | + } |
|
1110 | + |
|
1111 | + |
|
1112 | + /** |
|
1113 | + * Generate and send immediately from the given $message_ids |
|
1114 | + * |
|
1115 | + * @param array $message_ids EE_Message entity ids. |
|
1116 | + * @throws EE_Error |
|
1117 | + * @throws InvalidArgumentException |
|
1118 | + * @throws InvalidDataTypeException |
|
1119 | + * @throws InvalidInterfaceException |
|
1120 | + * @throws ReflectionException |
|
1121 | + */ |
|
1122 | + public static function generate_and_send_now(array $message_ids) |
|
1123 | + { |
|
1124 | + $generated_queue = self::generate_now($message_ids); |
|
1125 | + //now let's just trigger sending immediately from this queue. |
|
1126 | + $messages_sent = $generated_queue instanceof EE_Messages_Queue |
|
1127 | + ? $generated_queue->execute() |
|
1128 | + : 0; |
|
1129 | + if ($messages_sent) { |
|
1130 | + EE_Error::add_success( |
|
1131 | + esc_html( |
|
1132 | + sprintf( |
|
1133 | + _n( |
|
1134 | + 'There was %d message successfully generated and sent.', |
|
1135 | + 'There were %d messages successfully generated and sent.', |
|
1136 | + $messages_sent, |
|
1137 | + 'event_espresso' |
|
1138 | + ), |
|
1139 | + $messages_sent |
|
1140 | + ) |
|
1141 | + ) |
|
1142 | + ); |
|
1143 | + //errors would be added via the generate_now method. |
|
1144 | + } |
|
1145 | + } |
|
1146 | + |
|
1147 | + |
|
1148 | + /** |
|
1149 | + * This will queue the incoming message ids for resending. |
|
1150 | + * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
1151 | + * |
|
1152 | + * @since 4.9.0 |
|
1153 | + * @param array $message_ids An array of EE_Message IDs |
|
1154 | + * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
1155 | + * resending. |
|
1156 | + * @throws EE_Error |
|
1157 | + * @throws InvalidArgumentException |
|
1158 | + * @throws InvalidDataTypeException |
|
1159 | + * @throws InvalidInterfaceException |
|
1160 | + * @throws ReflectionException |
|
1161 | + */ |
|
1162 | + public static function queue_for_resending($message_ids) |
|
1163 | + { |
|
1164 | + self::_load_controller(); |
|
1165 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
1166 | + |
|
1167 | + //get queue and count |
|
1168 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
1169 | + |
|
1170 | + if ( |
|
1171 | + $queue_count > 0 |
|
1172 | + ) { |
|
1173 | + EE_Error::add_success( |
|
1174 | + sprintf( |
|
1175 | + _n( |
|
1176 | + '%d message successfully queued for resending.', |
|
1177 | + '%d messages successfully queued for resending.', |
|
1178 | + $queue_count, |
|
1179 | + 'event_espresso' |
|
1180 | + ), |
|
1181 | + $queue_count |
|
1182 | + ) |
|
1183 | + ); |
|
1184 | + /** |
|
1185 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
1186 | + */ |
|
1187 | + } elseif ( |
|
1188 | + apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
1189 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
1190 | + ) { |
|
1191 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
1192 | + if ($queue_count > 0) { |
|
1193 | + EE_Error::add_success( |
|
1194 | + sprintf( |
|
1195 | + _n( |
|
1196 | + '%d message successfully sent.', |
|
1197 | + '%d messages successfully sent.', |
|
1198 | + $queue_count, |
|
1199 | + 'event_espresso' |
|
1200 | + ), |
|
1201 | + $queue_count |
|
1202 | + ) |
|
1203 | + ); |
|
1204 | + } else { |
|
1205 | + EE_Error::add_error( |
|
1206 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1207 | + 'event_espresso'), |
|
1208 | + __FILE__, __FUNCTION__, __LINE__ |
|
1209 | + ); |
|
1210 | + } |
|
1211 | + } else { |
|
1212 | + EE_Error::add_error( |
|
1213 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1214 | + 'event_espresso'), |
|
1215 | + __FILE__, __FUNCTION__, __LINE__ |
|
1216 | + ); |
|
1217 | + } |
|
1218 | + return (bool)$queue_count; |
|
1219 | + } |
|
1220 | + |
|
1221 | + |
|
1222 | + /** |
|
1223 | + * debug |
|
1224 | + * |
|
1225 | + * @param string $class |
|
1226 | + * @param string $func |
|
1227 | + * @param string $line |
|
1228 | + * @param \EE_Transaction $transaction |
|
1229 | + * @param array $info |
|
1230 | + * @param bool $display_request |
|
1231 | + * @throws EE_Error |
|
1232 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
1233 | + */ |
|
1234 | + protected static function log( |
|
1235 | + $class = '', |
|
1236 | + $func = '', |
|
1237 | + $line = '', |
|
1238 | + EE_Transaction $transaction, |
|
1239 | + $info = array(), |
|
1240 | + $display_request = false |
|
1241 | + ) { |
|
1242 | + if (defined('EE_DEBUG') && EE_DEBUG) { |
|
1243 | + if ($transaction instanceof EE_Transaction) { |
|
1244 | + // don't serialize objects |
|
1245 | + $info = EEH_Debug_Tools::strip_objects($info); |
|
1246 | + $info['TXN_status'] = $transaction->status_ID(); |
|
1247 | + $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
1248 | + if ($transaction->ID()) { |
|
1249 | + $index = 'EE_Transaction: ' . $transaction->ID(); |
|
1250 | + EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
1251 | + } |
|
1252 | + } |
|
1253 | + } |
|
1254 | + |
|
1255 | + } |
|
1256 | + |
|
1257 | + |
|
1258 | + /** |
|
1259 | + * Resets all the static properties in this class when called. |
|
1260 | + */ |
|
1261 | + public static function reset() |
|
1262 | + { |
|
1263 | + self::$_EEMSG = null; |
|
1264 | + self::$_message_resource_manager = null; |
|
1265 | + self::$_MSG_PROCESSOR = null; |
|
1266 | + self::$_MSG_PATHS = null; |
|
1267 | + self::$_TMP_PACKS = array(); |
|
1268 | + } |
|
1269 | 1269 | |
1270 | 1270 | } |
1271 | 1271 | // End of file EED_Messages.module.php |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
161 | 161 | 'event_espresso'); |
162 | 162 | // add specific message for developers if WP_DEBUG in on |
163 | - $error_msg .= '||' . $e->getMessage(); |
|
163 | + $error_msg .= '||'.$e->getMessage(); |
|
164 | 164 | EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
165 | 165 | } |
166 | 166 | } |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
244 | 244 | 'event_espresso'); |
245 | 245 | // add specific message for developers if WP_DEBUG in on |
246 | - $error_msg .= '||' . $e->getMessage(); |
|
246 | + $error_msg .= '||'.$e->getMessage(); |
|
247 | 247 | EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
248 | 248 | } |
249 | 249 | } |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | $transient_key = EE_Registry::instance()->REQ->get('key'); |
275 | 275 | |
276 | 276 | //now let's verify transient, if not valid exit immediately |
277 | - if (! get_transient($transient_key)) { |
|
277 | + if ( ! get_transient($transient_key)) { |
|
278 | 278 | /** |
279 | 279 | * trigger error so this gets in the error logs. This is important because it happens on a non-user |
280 | 280 | * request. |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | |
288 | 288 | if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
289 | 289 | |
290 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
290 | + $method = 'batch_'.$cron_type.'_from_queue'; |
|
291 | 291 | if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
292 | 292 | self::$_MSG_PROCESSOR->$method(); |
293 | 293 | } else { |
@@ -396,9 +396,9 @@ discard block |
||
396 | 396 | 'messages/validators/html', |
397 | 397 | 'shortcodes', |
398 | 398 | ); |
399 | - $paths = array(); |
|
399 | + $paths = array(); |
|
400 | 400 | foreach ($dir_ref as $index => $dir) { |
401 | - $paths[$index] = EE_LIBRARIES . $dir; |
|
401 | + $paths[$index] = EE_LIBRARIES.$dir; |
|
402 | 402 | } |
403 | 403 | self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
404 | 404 | } |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | */ |
418 | 418 | protected static function _load_controller() |
419 | 419 | { |
420 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
420 | + if ( ! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
421 | 421 | EE_Registry::instance()->load_core('Request_Handler'); |
422 | 422 | self::set_autoloaders(); |
423 | 423 | self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | public static function payment(EE_Transaction $transaction, EE_Payment $payment = null) |
459 | 459 | { |
460 | 460 | //if there's no payment object, then we cannot do a payment type message! |
461 | - if (! $payment instanceof EE_Payment) { |
|
461 | + if ( ! $payment instanceof EE_Payment) { |
|
462 | 462 | return; |
463 | 463 | } |
464 | 464 | self::_load_controller(); |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
507 | 507 | { |
508 | 508 | |
509 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
509 | + if ( ! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
510 | 510 | //no messages please |
511 | 511 | return; |
512 | 512 | } |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | // array( '$extra_details' => $extra_details ) |
581 | 581 | //); |
582 | 582 | // currently only using this to send messages for the primary registrant |
583 | - if (! $registration->is_primary_registrant()) { |
|
583 | + if ( ! $registration->is_primary_registrant()) { |
|
584 | 584 | return false; |
585 | 585 | } |
586 | 586 | // first we check if we're in admin and not doing front ajax |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | } else { |
594 | 594 | // frontend request (either regular or via AJAX) |
595 | 595 | // TXN is NOT finalized ? |
596 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
596 | + if ( ! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
597 | 597 | return false; |
598 | 598 | } |
599 | 599 | // return visit but nothing changed ??? |
@@ -683,12 +683,12 @@ discard block |
||
683 | 683 | } |
684 | 684 | |
685 | 685 | //make sure any incoming request data is set on the REQ so that it gets picked up later. |
686 | - $req_data = (array)$req_data; |
|
686 | + $req_data = (array) $req_data; |
|
687 | 687 | foreach ($req_data as $request_key => $request_value) { |
688 | 688 | EE_Registry::instance()->REQ->set($request_key, $request_value); |
689 | 689 | } |
690 | 690 | |
691 | - if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
691 | + if ( ! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
692 | 692 | return false; |
693 | 693 | } |
694 | 694 | |
@@ -721,13 +721,13 @@ discard block |
||
721 | 721 | self::_load_controller(); |
722 | 722 | |
723 | 723 | $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
724 | - if (! $msgID) { |
|
724 | + if ( ! $msgID) { |
|
725 | 725 | EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
726 | 726 | 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
727 | 727 | return false; |
728 | 728 | } |
729 | 729 | |
730 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
730 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID); |
|
731 | 731 | |
732 | 732 | //setup success message. |
733 | 733 | $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
@@ -832,7 +832,7 @@ discard block |
||
832 | 832 | public static function send_newsletter_message($registrations, $grp_id) |
833 | 833 | { |
834 | 834 | //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
835 | - EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
835 | + EE_Registry::instance()->REQ->set('GRP_ID', (int) $grp_id); |
|
836 | 836 | self::_load_controller(); |
837 | 837 | self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
838 | 838 | } |
@@ -892,14 +892,14 @@ discard block |
||
892 | 892 | //get the message template group. |
893 | 893 | $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
894 | 894 | //if we don't have an EE_Message_Template_Group then return |
895 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
895 | + if ( ! $msg_template_group instanceof EE_Message_Template_Group) { |
|
896 | 896 | // remove EVT_ID from query params so that global templates get picked up |
897 | 897 | unset($template_query_params['Event.EVT_ID']); |
898 | 898 | //get global template as the fallback |
899 | 899 | $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
900 | 900 | } |
901 | 901 | //if we don't have an EE_Message_Template_Group then return |
902 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
902 | + if ( ! $msg_template_group instanceof EE_Message_Template_Group) { |
|
903 | 903 | return ''; |
904 | 904 | } |
905 | 905 | // generate the URL |
@@ -936,7 +936,7 @@ discard block |
||
936 | 936 | public static function preview_message($type, $context, $messenger, $send = false) |
937 | 937 | { |
938 | 938 | self::_load_controller(); |
939 | - $mtg = new EE_Message_To_Generate( |
|
939 | + $mtg = new EE_Message_To_Generate( |
|
940 | 940 | $messenger, |
941 | 941 | $type, |
942 | 942 | array(), |
@@ -1018,7 +1018,7 @@ discard block |
||
1018 | 1018 | public static function generate_now($message_ids) |
1019 | 1019 | { |
1020 | 1020 | self::_load_controller(); |
1021 | - $messages = EEM_Message::instance()->get_all( |
|
1021 | + $messages = EEM_Message::instance()->get_all( |
|
1022 | 1022 | array( |
1023 | 1023 | 0 => array( |
1024 | 1024 | 'MSG_ID' => array('IN', $message_ids), |
@@ -1031,7 +1031,7 @@ discard block |
||
1031 | 1031 | $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
1032 | 1032 | } |
1033 | 1033 | |
1034 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
1034 | + if ( ! $generated_queue instanceof EE_Messages_Queue) { |
|
1035 | 1035 | EE_Error::add_error( |
1036 | 1036 | __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
1037 | 1037 | 'event_espresso'), |
@@ -1058,7 +1058,7 @@ discard block |
||
1058 | 1058 | public static function send_now($message_ids) |
1059 | 1059 | { |
1060 | 1060 | self::_load_controller(); |
1061 | - $messages = EEM_Message::instance()->get_all( |
|
1061 | + $messages = EEM_Message::instance()->get_all( |
|
1062 | 1062 | array( |
1063 | 1063 | 0 => array( |
1064 | 1064 | 'MSG_ID' => array('IN', $message_ids), |
@@ -1074,7 +1074,7 @@ discard block |
||
1074 | 1074 | $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
1075 | 1075 | } |
1076 | 1076 | |
1077 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
1077 | + if ( ! $sent_queue instanceof EE_Messages_Queue) { |
|
1078 | 1078 | EE_Error::add_error( |
1079 | 1079 | __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
1080 | 1080 | 'event_espresso'), |
@@ -1215,7 +1215,7 @@ discard block |
||
1215 | 1215 | __FILE__, __FUNCTION__, __LINE__ |
1216 | 1216 | ); |
1217 | 1217 | } |
1218 | - return (bool)$queue_count; |
|
1218 | + return (bool) $queue_count; |
|
1219 | 1219 | } |
1220 | 1220 | |
1221 | 1221 | |
@@ -1246,7 +1246,7 @@ discard block |
||
1246 | 1246 | $info['TXN_status'] = $transaction->status_ID(); |
1247 | 1247 | $info['TXN_reg_steps'] = $transaction->reg_steps(); |
1248 | 1248 | if ($transaction->ID()) { |
1249 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
1249 | + $index = 'EE_Transaction: '.$transaction->ID(); |
|
1250 | 1250 | EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
1251 | 1251 | } |
1252 | 1252 | } |
@@ -505,7 +505,7 @@ |
||
505 | 505 | * |
506 | 506 | * @param string $value string to evaluate |
507 | 507 | * @param array $valid_shortcodes array of shortcodes that are acceptable. |
508 | - * @return mixed (bool|string) return either a list of invalid shortcodes OR false if the shortcodes validate. |
|
508 | + * @return false|string (bool|string) return either a list of invalid shortcodes OR false if the shortcodes validate. |
|
509 | 509 | */ |
510 | 510 | protected function _invalid_shortcodes($value, $valid_shortcodes) |
511 | 511 | { |
@@ -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 | /** |
@@ -22,630 +22,630 @@ discard block |
||
22 | 22 | { |
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * These properties just hold the name for the Messenger and Message Type (defined by child classes). |
|
27 | - * These are used for retrieving objects etc. |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $_m_name; |
|
32 | - protected $_mt_name; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * This will hold any error messages from the validation process. |
|
37 | - * The _errors property holds an associative array of error messages |
|
38 | - * listing the field as the key and the message as the value. |
|
39 | - * |
|
40 | - * @var array() |
|
41 | - */ |
|
42 | - private $_errors = array(); |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * holds an array of fields being validated |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - protected $_fields; |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * this will hold the incoming context |
|
55 | - * |
|
56 | - * @var string |
|
57 | - */ |
|
58 | - protected $_context; |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * this holds an array of fields and the relevant validation information |
|
63 | - * that the incoming fields data get validated against. |
|
64 | - * This gets setup in the _set_props() method. |
|
65 | - * |
|
66 | - * @var array |
|
67 | - */ |
|
68 | - protected $_validators; |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * holds the messenger object |
|
73 | - * |
|
74 | - * @var object |
|
75 | - */ |
|
76 | - protected $_messenger; |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * holds the message type object |
|
81 | - * |
|
82 | - * @var object |
|
83 | - */ |
|
84 | - protected $_message_type; |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * will hold any valid_shortcode modifications made by the _modify_validator() method. |
|
89 | - * |
|
90 | - * @var array |
|
91 | - */ |
|
92 | - protected $_valid_shortcodes_modifier; |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * There may be times where a message type wants to include a shortcode group but exclude specific |
|
97 | - * shortcodes. If that's the case then it can set this property as an array of shortcodes to exclude and |
|
98 | - * they will not be allowed. |
|
99 | - * Array should be indexed by field and values are an array of specific shortcodes to exclude. |
|
100 | - * |
|
101 | - * @var array |
|
102 | - */ |
|
103 | - protected $_specific_shortcode_excludes = array(); |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * Runs the validator using the incoming fields array as the fields/values to check. |
|
108 | - * |
|
109 | - * @param array $fields The fields sent by the EEM object. |
|
110 | - * @param $context |
|
111 | - * @throws \EE_Error |
|
112 | - */ |
|
113 | - public function __construct($fields, $context) |
|
114 | - { |
|
115 | - //check that _m_name and _mt_name have been set by child class otherwise we get out. |
|
116 | - if (empty($this->_m_name) || empty($this->_mt_name)) { |
|
117 | - throw new EE_Error( |
|
118 | - __( |
|
119 | - 'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property. Check that the child class is doing this', |
|
120 | - 'event_espresso' |
|
121 | - ) |
|
122 | - ); |
|
123 | - } |
|
124 | - $this->_fields = $fields; |
|
125 | - $this->_context = $context; |
|
126 | - |
|
127 | - //load messenger and message_type objects and the related shortcode objects. |
|
128 | - $this->_load_objects(); |
|
129 | - |
|
130 | - |
|
131 | - //modify any messenger/message_type specific validation instructions. This is what child classes define. |
|
132 | - $this->_modify_validator(); |
|
133 | - |
|
134 | - |
|
135 | - //let's set validators property |
|
136 | - $this->_set_validators(); |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * Child classes instantiate this and use it to modify the _validator_config array property |
|
142 | - * for the messenger using messengers set_validate_config() method. |
|
143 | - * This is so we can specify specific validation instructions for a messenger/message_type combo |
|
144 | - * that aren't handled by the defaults setup in the messenger. |
|
145 | - * |
|
146 | - * @abstract |
|
147 | - * @access protected |
|
148 | - * @return void |
|
149 | - */ |
|
150 | - abstract protected function _modify_validator(); |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * loads all objects used by validator |
|
155 | - * |
|
156 | - * @access private |
|
157 | - * @throws \EE_Error |
|
158 | - */ |
|
159 | - private function _load_objects() |
|
160 | - { |
|
161 | - //load messenger |
|
162 | - $messenger = ucwords(str_replace('_', ' ', $this->_m_name)); |
|
163 | - $messenger = str_replace(' ', '_', $messenger); |
|
164 | - $messenger = 'EE_' . $messenger . '_messenger'; |
|
165 | - |
|
166 | - if (! class_exists($messenger)) { |
|
167 | - throw new EE_Error( |
|
168 | - sprintf( |
|
169 | - __('There is no messenger class for the given string (%s)', 'event_espresso'), |
|
170 | - $this->_m_name |
|
171 | - ) |
|
172 | - ); |
|
173 | - } |
|
174 | - |
|
175 | - $this->_messenger = new $messenger(); |
|
176 | - |
|
177 | - //load message type |
|
178 | - $message_type = ucwords(str_replace('_', ' ', $this->_mt_name)); |
|
179 | - $message_type = str_replace(' ', '_', $message_type); |
|
180 | - $message_type = 'EE_' . $message_type . '_message_type'; |
|
181 | - |
|
182 | - if (! class_exists($message_type)) { |
|
183 | - throw new EE_Error( |
|
184 | - sprintf( |
|
185 | - __('There is no message type class for the given string (%s)', 'event_espresso'), |
|
186 | - $this->_mt_name |
|
187 | - ) |
|
188 | - ); |
|
189 | - } |
|
190 | - |
|
191 | - $this->_message_type = new $message_type(); |
|
192 | - |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * used to set the $_validators property |
|
198 | - * |
|
199 | - * @access private |
|
200 | - * @return void |
|
201 | - */ |
|
202 | - private function _set_validators() |
|
203 | - { |
|
204 | - // let's get all valid shortcodes from mt and message type |
|
205 | - // (messenger will have its set in the _validator_config property for the messenger) |
|
206 | - $mt_codes = $this->_message_type->get_valid_shortcodes(); |
|
207 | - |
|
208 | - |
|
209 | - //get messenger validator_config |
|
210 | - $msgr_validator = $this->_messenger->get_validator_config(); |
|
211 | - |
|
212 | - |
|
213 | - //we only want the valid shortcodes for the given context! |
|
214 | - $context = $this->_context; |
|
215 | - $mt_codes = $mt_codes[$context]; |
|
216 | - |
|
217 | - // in this first loop we're just getting all shortcode group indexes from the msgr_validator |
|
218 | - // into a single array (so we can get the appropriate shortcode objects for the groups) |
|
219 | - $shortcode_groups = $mt_codes; |
|
220 | - $groups_per_field = array(); |
|
221 | - |
|
222 | - foreach ($msgr_validator as $field => $config) { |
|
223 | - if (empty($config) || ! isset($config['shortcodes'])) { |
|
224 | - continue; |
|
225 | - } //Nothing to see here. |
|
226 | - $groups_per_field[$field] = array_intersect($config['shortcodes'], $mt_codes); |
|
227 | - $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups); |
|
228 | - } |
|
229 | - |
|
230 | - $shortcode_groups = array_unique($shortcode_groups); |
|
231 | - |
|
232 | - // okay now we've got our groups. |
|
233 | - // Let's get the codes from the objects into an array indexed by group for easy retrieval later. |
|
234 | - $codes_from_objs = array(); |
|
235 | - |
|
236 | - foreach ($shortcode_groups as $group) { |
|
237 | - $ref = ucwords(str_replace('_', ' ', $group)); |
|
238 | - $ref = str_replace(' ', '_', $ref); |
|
239 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
240 | - if (class_exists($classname)) { |
|
241 | - $a = new ReflectionClass($classname); |
|
242 | - $obj = $a->newInstance(); |
|
243 | - $codes_from_objs[$group] = $obj->get_shortcodes(); |
|
244 | - } |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - //let's just replace the $mt shortcode group indexes with the actual shortcodes (unique) |
|
249 | - $final_mt_codes = array(); |
|
250 | - foreach ($mt_codes as $group) { |
|
251 | - $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[$group]); |
|
252 | - } |
|
253 | - |
|
254 | - $mt_codes = $final_mt_codes; |
|
255 | - |
|
256 | - |
|
257 | - // k now in this next loop we're going to loop through $msgr_validator again |
|
258 | - // and setup the _validators property from the data we've setup so far. |
|
259 | - foreach ($msgr_validator as $field => $config) { |
|
260 | - //if required shortcode is not in our list of codes for the given field, then we skip this field. |
|
261 | - $required = isset($config['required']) |
|
262 | - ? array_intersect($config['required'], array_keys($mt_codes)) |
|
263 | - : true; |
|
264 | - if (empty($required)) { |
|
265 | - continue; |
|
266 | - } |
|
267 | - |
|
268 | - //If we have an override then we use it to indicate the codes we want. |
|
269 | - if (isset($this->_valid_shortcodes_modifier[$context][$field])) { |
|
270 | - $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
271 | - $this->_valid_shortcodes_modifier[$context][$field], |
|
272 | - $codes_from_objs |
|
273 | - ); |
|
274 | - } //if we have specific shortcodes for a field then we need to use them |
|
275 | - else if (isset($groups_per_field[$field])) { |
|
276 | - $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
277 | - $groups_per_field[$field], |
|
278 | - $codes_from_objs |
|
279 | - ); |
|
280 | - } //if empty config then we're assuming we're just going to use the shortcodes from the message type context |
|
281 | - else if (empty($config)) { |
|
282 | - $this->_validators[$field]['shortcodes'] = $mt_codes; |
|
283 | - } //if we have specific shortcodes then we need to use them |
|
284 | - else if (isset($config['specific_shortcodes'])) { |
|
285 | - $this->_validators[$field]['shortcodes'] = $config['specific_shortcodes']; |
|
286 | - } //otherwise the shortcodes are what is set by the messenger for that field |
|
287 | - else { |
|
288 | - foreach ($config['shortcodes'] as $group) { |
|
289 | - $this->_validators[$field]['shortcodes'] = isset($this->_validators[$field]['shortcodes']) |
|
290 | - ? array_merge($this->_validators[$field]['shortcodes'], $codes_from_objs[$group]) |
|
291 | - : $codes_from_objs[$group]; |
|
292 | - } |
|
293 | - } |
|
294 | - |
|
295 | - //now let's just make sure that any excluded specific shortcodes are removed. |
|
296 | - $specific_excludes = $this->get_specific_shortcode_excludes(); |
|
297 | - if (isset($specific_excludes[$field])) { |
|
298 | - foreach ($specific_excludes[$field] as $sex) { |
|
299 | - if (isset($this->_validators[$field]['shortcodes'][$sex])) { |
|
300 | - unset($this->_validators[$field]['shortcodes'][$sex]); |
|
301 | - } |
|
302 | - } |
|
303 | - } |
|
304 | - |
|
305 | - //hey! don't forget to include the type if present! |
|
306 | - $this->_validators[$field]['type'] = isset($config['type']) ? $config['type'] : null; |
|
307 | - } |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * This just returns the validators property that contains information |
|
313 | - * about the various shortcodes and their availability with each field |
|
314 | - * |
|
315 | - * @return array |
|
316 | - */ |
|
317 | - public function get_validators() |
|
318 | - { |
|
319 | - return $this->_validators; |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * This simply returns the specific shortcode_excludes property that is set. |
|
325 | - * |
|
326 | - * @since 4.5.0 |
|
327 | - * @return array |
|
328 | - */ |
|
329 | - public function get_specific_shortcode_excludes() |
|
330 | - { |
|
331 | - //specific validator filter |
|
332 | - $shortcode_excludes = apply_filters( |
|
333 | - 'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;', |
|
334 | - $this->_specific_shortcode_excludes, |
|
335 | - $this->_context |
|
336 | - ); |
|
337 | - //global filter |
|
338 | - return apply_filters( |
|
339 | - 'FHEE__EE_Messages_Validator__get_specific_shortcode_excludes', |
|
340 | - $shortcode_excludes, |
|
341 | - $this->_context, |
|
342 | - $this |
|
343 | - ); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * This is the main method that handles validation |
|
349 | - * What it does is loop through the _fields (the ones that get validated) |
|
350 | - * and checks them against the shortcodes array for the field and the 'type' indicated by the |
|
351 | - * |
|
352 | - * @access public |
|
353 | - * @return mixed (bool|array) if errors present we return the array otherwise true |
|
354 | - */ |
|
355 | - public function validate() |
|
356 | - { |
|
357 | - //some defaults |
|
358 | - $template_fields = $this->_messenger->get_template_fields(); |
|
359 | - //loop through the fields and check! |
|
360 | - foreach ($this->_fields as $field => $value) { |
|
361 | - $this->_errors[$field] = array(); |
|
362 | - $err_msg = ''; |
|
363 | - $field_label = ''; |
|
364 | - //if field is not present in the _validators array then we continue |
|
365 | - if (! isset($this->_validators[$field])) { |
|
366 | - unset($this->_errors[$field]); |
|
367 | - continue; |
|
368 | - } |
|
369 | - |
|
370 | - //get the translated field label! |
|
371 | - //first check if it's in the main fields list |
|
372 | - if (isset($template_fields[$field])) { |
|
373 | - if (empty($template_fields[$field])) { |
|
374 | - $field_label = $field; |
|
375 | - } //most likely the field is found in the 'extra' array. |
|
376 | - else { |
|
377 | - $field_label = $template_fields[$field]['label']; |
|
378 | - } |
|
379 | - } |
|
380 | - |
|
381 | - // if field label is empty OR is equal to the current field |
|
382 | - // then we need to loop through the 'extra' fields in the template_fields config (if present) |
|
383 | - if (isset($template_fields['extra']) && (empty($field_label)) || $field_label == $field) { |
|
384 | - foreach ($template_fields['extra'] as $main_field => $secondary_field) { |
|
385 | - foreach ($secondary_field as $name => $values) { |
|
386 | - if ($name == $field) { |
|
387 | - $field_label = $values['label']; |
|
388 | - } |
|
389 | - |
|
390 | - // if we've got a 'main' secondary field, let's see if that matches what field we're on |
|
391 | - // which means it contains the label for this field. |
|
392 | - if ($name == 'main' && $main_field == $field_label) { |
|
393 | - $field_label = $values['label']; |
|
394 | - } |
|
395 | - } |
|
396 | - } |
|
397 | - } |
|
398 | - |
|
399 | - //field is present. Let's validate shortcodes first (but only if shortcodes present). |
|
400 | - if ( |
|
401 | - isset($this->_validators[$field]['shortcodes']) |
|
402 | - && ! empty($this->_validators[$field]['shortcodes']) |
|
403 | - ) { |
|
404 | - $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[$field]['shortcodes']); |
|
405 | - // if true then that means there is a returned error message |
|
406 | - // that we'll need to add to the _errors array for this field. |
|
407 | - if ($invalid_shortcodes) { |
|
408 | - $v_s = array_keys($this->_validators[$field]['shortcodes']); |
|
409 | - $err_msg = sprintf( |
|
410 | - __( |
|
411 | - '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s', |
|
412 | - 'event_espresso' |
|
413 | - ), |
|
414 | - '<strong>' . $field_label . '</strong>', |
|
415 | - $invalid_shortcodes, |
|
416 | - '<p>', |
|
417 | - '</p >' |
|
418 | - ); |
|
419 | - $err_msg .= sprintf( |
|
420 | - __('%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso'), |
|
421 | - implode(', ', $v_s), |
|
422 | - '<strong>', |
|
423 | - '</strong>' |
|
424 | - ); |
|
425 | - } |
|
426 | - } |
|
427 | - |
|
428 | - //if there's a "type" to be validated then let's do that too. |
|
429 | - if (isset($this->_validators[$field]['type']) && ! empty($this->_validators[$field]['type'])) { |
|
430 | - switch ($this->_validators[$field]['type']) { |
|
431 | - case 'number' : |
|
432 | - if (! is_numeric($value)) { |
|
433 | - $err_msg .= sprintf( |
|
434 | - __( |
|
435 | - '%3$sThe %1$s field is supposed to be a number. The value given (%2$s) is not. Please double-check and make sure the field contains a number%4$s', |
|
436 | - 'event_espresso' |
|
437 | - ), |
|
438 | - $field_label, |
|
439 | - $value, |
|
440 | - '<p>', |
|
441 | - '</p >' |
|
442 | - ); |
|
443 | - } |
|
444 | - break; |
|
445 | - case 'email' : |
|
446 | - $valid_email = $this->_validate_email($value); |
|
447 | - if (! $valid_email) { |
|
448 | - $err_msg .= htmlentities( |
|
449 | - sprintf( |
|
450 | - __( |
|
451 | - 'The %1$s field has at least one string that is not a valid email address record. Valid emails are in the format: "Name <[email protected]>" or "[email protected]" and multiple emails can be separated by a comma.' |
|
452 | - ), |
|
453 | - $field_label |
|
454 | - |
|
455 | - ) |
|
456 | - ); |
|
457 | - } |
|
458 | - break; |
|
459 | - default : |
|
460 | - break; |
|
461 | - } |
|
462 | - } |
|
463 | - |
|
464 | - //if $err_msg isn't empty let's setup the _errors array for this field. |
|
465 | - if (! empty($err_msg)) { |
|
466 | - $this->_errors[$field]['msg'] = $err_msg; |
|
467 | - } else { |
|
468 | - unset($this->_errors[$field]); |
|
469 | - } |
|
470 | - } |
|
471 | - |
|
472 | - // if we have ANY errors, then we want to make sure we return the values |
|
473 | - // for ALL the fields so the user doesn't have to retype them all. |
|
474 | - if (! empty($this->_errors)) { |
|
475 | - foreach ($this->_fields as $field => $value) { |
|
476 | - $this->_errors[$field]['value'] = stripslashes($value); |
|
477 | - } |
|
478 | - } |
|
479 | - |
|
480 | - //return any errors or just TRUE if everything validates |
|
481 | - return empty($this->_errors) ? true : $this->_errors; |
|
482 | - } |
|
483 | - |
|
484 | - |
|
485 | - /** |
|
486 | - * Reassembles and returns an array of valid shortcodes |
|
487 | - * given the array of groups and array of shortcodes indexed by group. |
|
488 | - * |
|
489 | - * @param array $groups array of shortcode groups that we want shortcodes for |
|
490 | - * @param array $codes_from_objs All the codes available. |
|
491 | - * @return array an array of actual shortcodes (that will be used for validation). |
|
492 | - */ |
|
493 | - private function _reassemble_valid_shortcodes_from_group($groups, $codes_from_objs) |
|
494 | - { |
|
495 | - $shortcodes = array(); |
|
496 | - foreach ($groups as $group) { |
|
497 | - $shortcodes = array_merge($shortcodes, $codes_from_objs[$group]); |
|
498 | - } |
|
499 | - return $shortcodes; |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - /** |
|
504 | - * Validates a string against a list of accepted shortcodes |
|
505 | - * This function takes in an array of shortcodes |
|
506 | - * and makes sure that the given string ONLY contains shortcodes in that array. |
|
507 | - * |
|
508 | - * @param string $value string to evaluate |
|
509 | - * @param array $valid_shortcodes array of shortcodes that are acceptable. |
|
510 | - * @return mixed (bool|string) return either a list of invalid shortcodes OR false if the shortcodes validate. |
|
511 | - */ |
|
512 | - protected function _invalid_shortcodes($value, $valid_shortcodes) |
|
513 | - { |
|
514 | - //first we need to go through the string and get the shortcodes in the string |
|
515 | - preg_match_all('/(\[.+?\])/', $value, $matches); |
|
516 | - $incoming_shortcodes = (array)$matches[0]; |
|
517 | - |
|
518 | - //get a diff of the shortcodes in the string vs the valid shortcodes |
|
519 | - $diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes)); |
|
520 | - |
|
521 | - //we need to account for custom codes so let's loop through the diff and remove any of those type of codes |
|
522 | - foreach ($diff as $ind => $code) { |
|
523 | - if (preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code)) { |
|
524 | - //strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] ) |
|
525 | - $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code); |
|
526 | - //does this exist in the $valid_shortcodes? If so then unset. |
|
527 | - if (isset($valid_shortcodes[$dynamic_sc])) { |
|
528 | - unset($diff[$ind]); |
|
529 | - } |
|
530 | - } |
|
531 | - } |
|
532 | - |
|
533 | - if (empty($diff)) { |
|
534 | - return false; |
|
535 | - } //there is no diff, we have no invalid shortcodes, so return |
|
536 | - |
|
537 | - //made it here? then let's assemble the error message |
|
538 | - $invalid_shortcodes = implode('</strong>,<strong>', $diff); |
|
539 | - $invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>'; |
|
540 | - return $invalid_shortcodes; |
|
541 | - } |
|
542 | - |
|
543 | - |
|
544 | - /** |
|
545 | - * Validates an incoming string and makes sure we have valid emails in the string. |
|
546 | - * |
|
547 | - * @param string $value incoming value to validate |
|
548 | - * @return bool true if the string validates, false if it doesn't |
|
549 | - */ |
|
550 | - protected function _validate_email($value) |
|
551 | - { |
|
552 | - $validate = true; |
|
553 | - $or_val = $value; |
|
554 | - |
|
555 | - // empty strings will validate because this is how a message template |
|
556 | - // for a particular context can be "turned off" (if there is no email then no message) |
|
557 | - if (empty($value)) { |
|
558 | - return $validate; |
|
559 | - } |
|
560 | - |
|
561 | - // first determine if there ARE any shortcodes. |
|
562 | - // If there are shortcodes and then later we find that there were no other valid emails |
|
563 | - // but the field isn't empty... |
|
564 | - // that means we've got extra commas that were left after stripping out shortcodes so probably still valid. |
|
565 | - $has_shortcodes = preg_match('/(\[.+?\])/', $value); |
|
566 | - |
|
567 | - //first we need to strip out all the shortcodes! |
|
568 | - $value = preg_replace('/(\[.+?\])/', '', $value); |
|
569 | - |
|
570 | - // if original value is not empty and new value is, then we've parsed out a shortcode |
|
571 | - // and we now have an empty string which DOES validate. |
|
572 | - // We also validate complete empty field for email because |
|
573 | - // its possible that this message is being "turned off" for a particular context |
|
574 | - |
|
575 | - |
|
576 | - if (! empty($or_val) && empty($value)) { |
|
577 | - return $validate; |
|
578 | - } |
|
579 | - |
|
580 | - //trim any commas from beginning and end of string ( after whitespace trimmed ); |
|
581 | - $value = trim(trim($value), ','); |
|
582 | - |
|
583 | - |
|
584 | - //next we need to split up the string if its comma delimited. |
|
585 | - $emails = explode(',', $value); |
|
586 | - $empty = false; //used to indicate that there is an empty comma. |
|
587 | - //now let's loop through the emails and do our checks |
|
588 | - foreach ($emails as $email) { |
|
589 | - if (empty($email)) { |
|
590 | - $empty = true; |
|
591 | - continue; |
|
592 | - } |
|
593 | - |
|
594 | - //trim whitespace |
|
595 | - $email = trim($email); |
|
596 | - //either its of type "[email protected]", or its of type "fname lname <[email protected]>" |
|
597 | - if (is_email($email)) { |
|
598 | - continue; |
|
599 | - } else { |
|
600 | - $matches = array(); |
|
601 | - $validate = preg_match('/(.*)<(.+)>/', $email, $matches) ? true : false; |
|
602 | - if ($validate && is_email($matches[2])) { |
|
603 | - continue; |
|
604 | - } else { |
|
605 | - return false; |
|
606 | - } |
|
607 | - } |
|
608 | - } |
|
609 | - |
|
610 | - $validate = $empty && ! $has_shortcodes ? false : $validate; |
|
611 | - |
|
612 | - return $validate; |
|
613 | - |
|
614 | - } |
|
615 | - |
|
616 | - |
|
617 | - /** |
|
618 | - * Magic getter |
|
619 | - * Using this to provide back compat with add-ons referencing deprecated properties. |
|
620 | - * |
|
621 | - * @param string $property Property being requested |
|
622 | - * @throws Exception |
|
623 | - * @return mixed |
|
624 | - */ |
|
625 | - public function __get($property) |
|
626 | - { |
|
627 | - $expected_properties_map = array( |
|
628 | - /** |
|
629 | - * @deprecated 4.9.0 |
|
630 | - */ |
|
631 | - '_MSGR' => '_messenger', |
|
632 | - /** |
|
633 | - * @deprecated 4.9.0 |
|
634 | - */ |
|
635 | - '_MSGTYP' => '_message_type', |
|
636 | - ); |
|
637 | - |
|
638 | - if (isset($expected_properties_map[$property])) { |
|
639 | - return $this->{$expected_properties_map[$property]}; |
|
640 | - } |
|
641 | - |
|
642 | - throw new Exception( |
|
643 | - sprintf( |
|
644 | - __('The property %1$s being requested on %2$s does not exist', 'event_espresso'), |
|
645 | - $property, |
|
646 | - get_class($this) |
|
647 | - ) |
|
648 | - ); |
|
649 | - } |
|
25 | + /** |
|
26 | + * These properties just hold the name for the Messenger and Message Type (defined by child classes). |
|
27 | + * These are used for retrieving objects etc. |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $_m_name; |
|
32 | + protected $_mt_name; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * This will hold any error messages from the validation process. |
|
37 | + * The _errors property holds an associative array of error messages |
|
38 | + * listing the field as the key and the message as the value. |
|
39 | + * |
|
40 | + * @var array() |
|
41 | + */ |
|
42 | + private $_errors = array(); |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * holds an array of fields being validated |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + protected $_fields; |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * this will hold the incoming context |
|
55 | + * |
|
56 | + * @var string |
|
57 | + */ |
|
58 | + protected $_context; |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * this holds an array of fields and the relevant validation information |
|
63 | + * that the incoming fields data get validated against. |
|
64 | + * This gets setup in the _set_props() method. |
|
65 | + * |
|
66 | + * @var array |
|
67 | + */ |
|
68 | + protected $_validators; |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * holds the messenger object |
|
73 | + * |
|
74 | + * @var object |
|
75 | + */ |
|
76 | + protected $_messenger; |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * holds the message type object |
|
81 | + * |
|
82 | + * @var object |
|
83 | + */ |
|
84 | + protected $_message_type; |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * will hold any valid_shortcode modifications made by the _modify_validator() method. |
|
89 | + * |
|
90 | + * @var array |
|
91 | + */ |
|
92 | + protected $_valid_shortcodes_modifier; |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * There may be times where a message type wants to include a shortcode group but exclude specific |
|
97 | + * shortcodes. If that's the case then it can set this property as an array of shortcodes to exclude and |
|
98 | + * they will not be allowed. |
|
99 | + * Array should be indexed by field and values are an array of specific shortcodes to exclude. |
|
100 | + * |
|
101 | + * @var array |
|
102 | + */ |
|
103 | + protected $_specific_shortcode_excludes = array(); |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * Runs the validator using the incoming fields array as the fields/values to check. |
|
108 | + * |
|
109 | + * @param array $fields The fields sent by the EEM object. |
|
110 | + * @param $context |
|
111 | + * @throws \EE_Error |
|
112 | + */ |
|
113 | + public function __construct($fields, $context) |
|
114 | + { |
|
115 | + //check that _m_name and _mt_name have been set by child class otherwise we get out. |
|
116 | + if (empty($this->_m_name) || empty($this->_mt_name)) { |
|
117 | + throw new EE_Error( |
|
118 | + __( |
|
119 | + 'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property. Check that the child class is doing this', |
|
120 | + 'event_espresso' |
|
121 | + ) |
|
122 | + ); |
|
123 | + } |
|
124 | + $this->_fields = $fields; |
|
125 | + $this->_context = $context; |
|
126 | + |
|
127 | + //load messenger and message_type objects and the related shortcode objects. |
|
128 | + $this->_load_objects(); |
|
129 | + |
|
130 | + |
|
131 | + //modify any messenger/message_type specific validation instructions. This is what child classes define. |
|
132 | + $this->_modify_validator(); |
|
133 | + |
|
134 | + |
|
135 | + //let's set validators property |
|
136 | + $this->_set_validators(); |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * Child classes instantiate this and use it to modify the _validator_config array property |
|
142 | + * for the messenger using messengers set_validate_config() method. |
|
143 | + * This is so we can specify specific validation instructions for a messenger/message_type combo |
|
144 | + * that aren't handled by the defaults setup in the messenger. |
|
145 | + * |
|
146 | + * @abstract |
|
147 | + * @access protected |
|
148 | + * @return void |
|
149 | + */ |
|
150 | + abstract protected function _modify_validator(); |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * loads all objects used by validator |
|
155 | + * |
|
156 | + * @access private |
|
157 | + * @throws \EE_Error |
|
158 | + */ |
|
159 | + private function _load_objects() |
|
160 | + { |
|
161 | + //load messenger |
|
162 | + $messenger = ucwords(str_replace('_', ' ', $this->_m_name)); |
|
163 | + $messenger = str_replace(' ', '_', $messenger); |
|
164 | + $messenger = 'EE_' . $messenger . '_messenger'; |
|
165 | + |
|
166 | + if (! class_exists($messenger)) { |
|
167 | + throw new EE_Error( |
|
168 | + sprintf( |
|
169 | + __('There is no messenger class for the given string (%s)', 'event_espresso'), |
|
170 | + $this->_m_name |
|
171 | + ) |
|
172 | + ); |
|
173 | + } |
|
174 | + |
|
175 | + $this->_messenger = new $messenger(); |
|
176 | + |
|
177 | + //load message type |
|
178 | + $message_type = ucwords(str_replace('_', ' ', $this->_mt_name)); |
|
179 | + $message_type = str_replace(' ', '_', $message_type); |
|
180 | + $message_type = 'EE_' . $message_type . '_message_type'; |
|
181 | + |
|
182 | + if (! class_exists($message_type)) { |
|
183 | + throw new EE_Error( |
|
184 | + sprintf( |
|
185 | + __('There is no message type class for the given string (%s)', 'event_espresso'), |
|
186 | + $this->_mt_name |
|
187 | + ) |
|
188 | + ); |
|
189 | + } |
|
190 | + |
|
191 | + $this->_message_type = new $message_type(); |
|
192 | + |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * used to set the $_validators property |
|
198 | + * |
|
199 | + * @access private |
|
200 | + * @return void |
|
201 | + */ |
|
202 | + private function _set_validators() |
|
203 | + { |
|
204 | + // let's get all valid shortcodes from mt and message type |
|
205 | + // (messenger will have its set in the _validator_config property for the messenger) |
|
206 | + $mt_codes = $this->_message_type->get_valid_shortcodes(); |
|
207 | + |
|
208 | + |
|
209 | + //get messenger validator_config |
|
210 | + $msgr_validator = $this->_messenger->get_validator_config(); |
|
211 | + |
|
212 | + |
|
213 | + //we only want the valid shortcodes for the given context! |
|
214 | + $context = $this->_context; |
|
215 | + $mt_codes = $mt_codes[$context]; |
|
216 | + |
|
217 | + // in this first loop we're just getting all shortcode group indexes from the msgr_validator |
|
218 | + // into a single array (so we can get the appropriate shortcode objects for the groups) |
|
219 | + $shortcode_groups = $mt_codes; |
|
220 | + $groups_per_field = array(); |
|
221 | + |
|
222 | + foreach ($msgr_validator as $field => $config) { |
|
223 | + if (empty($config) || ! isset($config['shortcodes'])) { |
|
224 | + continue; |
|
225 | + } //Nothing to see here. |
|
226 | + $groups_per_field[$field] = array_intersect($config['shortcodes'], $mt_codes); |
|
227 | + $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups); |
|
228 | + } |
|
229 | + |
|
230 | + $shortcode_groups = array_unique($shortcode_groups); |
|
231 | + |
|
232 | + // okay now we've got our groups. |
|
233 | + // Let's get the codes from the objects into an array indexed by group for easy retrieval later. |
|
234 | + $codes_from_objs = array(); |
|
235 | + |
|
236 | + foreach ($shortcode_groups as $group) { |
|
237 | + $ref = ucwords(str_replace('_', ' ', $group)); |
|
238 | + $ref = str_replace(' ', '_', $ref); |
|
239 | + $classname = 'EE_' . $ref . '_Shortcodes'; |
|
240 | + if (class_exists($classname)) { |
|
241 | + $a = new ReflectionClass($classname); |
|
242 | + $obj = $a->newInstance(); |
|
243 | + $codes_from_objs[$group] = $obj->get_shortcodes(); |
|
244 | + } |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + //let's just replace the $mt shortcode group indexes with the actual shortcodes (unique) |
|
249 | + $final_mt_codes = array(); |
|
250 | + foreach ($mt_codes as $group) { |
|
251 | + $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[$group]); |
|
252 | + } |
|
253 | + |
|
254 | + $mt_codes = $final_mt_codes; |
|
255 | + |
|
256 | + |
|
257 | + // k now in this next loop we're going to loop through $msgr_validator again |
|
258 | + // and setup the _validators property from the data we've setup so far. |
|
259 | + foreach ($msgr_validator as $field => $config) { |
|
260 | + //if required shortcode is not in our list of codes for the given field, then we skip this field. |
|
261 | + $required = isset($config['required']) |
|
262 | + ? array_intersect($config['required'], array_keys($mt_codes)) |
|
263 | + : true; |
|
264 | + if (empty($required)) { |
|
265 | + continue; |
|
266 | + } |
|
267 | + |
|
268 | + //If we have an override then we use it to indicate the codes we want. |
|
269 | + if (isset($this->_valid_shortcodes_modifier[$context][$field])) { |
|
270 | + $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
271 | + $this->_valid_shortcodes_modifier[$context][$field], |
|
272 | + $codes_from_objs |
|
273 | + ); |
|
274 | + } //if we have specific shortcodes for a field then we need to use them |
|
275 | + else if (isset($groups_per_field[$field])) { |
|
276 | + $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
277 | + $groups_per_field[$field], |
|
278 | + $codes_from_objs |
|
279 | + ); |
|
280 | + } //if empty config then we're assuming we're just going to use the shortcodes from the message type context |
|
281 | + else if (empty($config)) { |
|
282 | + $this->_validators[$field]['shortcodes'] = $mt_codes; |
|
283 | + } //if we have specific shortcodes then we need to use them |
|
284 | + else if (isset($config['specific_shortcodes'])) { |
|
285 | + $this->_validators[$field]['shortcodes'] = $config['specific_shortcodes']; |
|
286 | + } //otherwise the shortcodes are what is set by the messenger for that field |
|
287 | + else { |
|
288 | + foreach ($config['shortcodes'] as $group) { |
|
289 | + $this->_validators[$field]['shortcodes'] = isset($this->_validators[$field]['shortcodes']) |
|
290 | + ? array_merge($this->_validators[$field]['shortcodes'], $codes_from_objs[$group]) |
|
291 | + : $codes_from_objs[$group]; |
|
292 | + } |
|
293 | + } |
|
294 | + |
|
295 | + //now let's just make sure that any excluded specific shortcodes are removed. |
|
296 | + $specific_excludes = $this->get_specific_shortcode_excludes(); |
|
297 | + if (isset($specific_excludes[$field])) { |
|
298 | + foreach ($specific_excludes[$field] as $sex) { |
|
299 | + if (isset($this->_validators[$field]['shortcodes'][$sex])) { |
|
300 | + unset($this->_validators[$field]['shortcodes'][$sex]); |
|
301 | + } |
|
302 | + } |
|
303 | + } |
|
304 | + |
|
305 | + //hey! don't forget to include the type if present! |
|
306 | + $this->_validators[$field]['type'] = isset($config['type']) ? $config['type'] : null; |
|
307 | + } |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * This just returns the validators property that contains information |
|
313 | + * about the various shortcodes and their availability with each field |
|
314 | + * |
|
315 | + * @return array |
|
316 | + */ |
|
317 | + public function get_validators() |
|
318 | + { |
|
319 | + return $this->_validators; |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * This simply returns the specific shortcode_excludes property that is set. |
|
325 | + * |
|
326 | + * @since 4.5.0 |
|
327 | + * @return array |
|
328 | + */ |
|
329 | + public function get_specific_shortcode_excludes() |
|
330 | + { |
|
331 | + //specific validator filter |
|
332 | + $shortcode_excludes = apply_filters( |
|
333 | + 'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;', |
|
334 | + $this->_specific_shortcode_excludes, |
|
335 | + $this->_context |
|
336 | + ); |
|
337 | + //global filter |
|
338 | + return apply_filters( |
|
339 | + 'FHEE__EE_Messages_Validator__get_specific_shortcode_excludes', |
|
340 | + $shortcode_excludes, |
|
341 | + $this->_context, |
|
342 | + $this |
|
343 | + ); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * This is the main method that handles validation |
|
349 | + * What it does is loop through the _fields (the ones that get validated) |
|
350 | + * and checks them against the shortcodes array for the field and the 'type' indicated by the |
|
351 | + * |
|
352 | + * @access public |
|
353 | + * @return mixed (bool|array) if errors present we return the array otherwise true |
|
354 | + */ |
|
355 | + public function validate() |
|
356 | + { |
|
357 | + //some defaults |
|
358 | + $template_fields = $this->_messenger->get_template_fields(); |
|
359 | + //loop through the fields and check! |
|
360 | + foreach ($this->_fields as $field => $value) { |
|
361 | + $this->_errors[$field] = array(); |
|
362 | + $err_msg = ''; |
|
363 | + $field_label = ''; |
|
364 | + //if field is not present in the _validators array then we continue |
|
365 | + if (! isset($this->_validators[$field])) { |
|
366 | + unset($this->_errors[$field]); |
|
367 | + continue; |
|
368 | + } |
|
369 | + |
|
370 | + //get the translated field label! |
|
371 | + //first check if it's in the main fields list |
|
372 | + if (isset($template_fields[$field])) { |
|
373 | + if (empty($template_fields[$field])) { |
|
374 | + $field_label = $field; |
|
375 | + } //most likely the field is found in the 'extra' array. |
|
376 | + else { |
|
377 | + $field_label = $template_fields[$field]['label']; |
|
378 | + } |
|
379 | + } |
|
380 | + |
|
381 | + // if field label is empty OR is equal to the current field |
|
382 | + // then we need to loop through the 'extra' fields in the template_fields config (if present) |
|
383 | + if (isset($template_fields['extra']) && (empty($field_label)) || $field_label == $field) { |
|
384 | + foreach ($template_fields['extra'] as $main_field => $secondary_field) { |
|
385 | + foreach ($secondary_field as $name => $values) { |
|
386 | + if ($name == $field) { |
|
387 | + $field_label = $values['label']; |
|
388 | + } |
|
389 | + |
|
390 | + // if we've got a 'main' secondary field, let's see if that matches what field we're on |
|
391 | + // which means it contains the label for this field. |
|
392 | + if ($name == 'main' && $main_field == $field_label) { |
|
393 | + $field_label = $values['label']; |
|
394 | + } |
|
395 | + } |
|
396 | + } |
|
397 | + } |
|
398 | + |
|
399 | + //field is present. Let's validate shortcodes first (but only if shortcodes present). |
|
400 | + if ( |
|
401 | + isset($this->_validators[$field]['shortcodes']) |
|
402 | + && ! empty($this->_validators[$field]['shortcodes']) |
|
403 | + ) { |
|
404 | + $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[$field]['shortcodes']); |
|
405 | + // if true then that means there is a returned error message |
|
406 | + // that we'll need to add to the _errors array for this field. |
|
407 | + if ($invalid_shortcodes) { |
|
408 | + $v_s = array_keys($this->_validators[$field]['shortcodes']); |
|
409 | + $err_msg = sprintf( |
|
410 | + __( |
|
411 | + '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s', |
|
412 | + 'event_espresso' |
|
413 | + ), |
|
414 | + '<strong>' . $field_label . '</strong>', |
|
415 | + $invalid_shortcodes, |
|
416 | + '<p>', |
|
417 | + '</p >' |
|
418 | + ); |
|
419 | + $err_msg .= sprintf( |
|
420 | + __('%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso'), |
|
421 | + implode(', ', $v_s), |
|
422 | + '<strong>', |
|
423 | + '</strong>' |
|
424 | + ); |
|
425 | + } |
|
426 | + } |
|
427 | + |
|
428 | + //if there's a "type" to be validated then let's do that too. |
|
429 | + if (isset($this->_validators[$field]['type']) && ! empty($this->_validators[$field]['type'])) { |
|
430 | + switch ($this->_validators[$field]['type']) { |
|
431 | + case 'number' : |
|
432 | + if (! is_numeric($value)) { |
|
433 | + $err_msg .= sprintf( |
|
434 | + __( |
|
435 | + '%3$sThe %1$s field is supposed to be a number. The value given (%2$s) is not. Please double-check and make sure the field contains a number%4$s', |
|
436 | + 'event_espresso' |
|
437 | + ), |
|
438 | + $field_label, |
|
439 | + $value, |
|
440 | + '<p>', |
|
441 | + '</p >' |
|
442 | + ); |
|
443 | + } |
|
444 | + break; |
|
445 | + case 'email' : |
|
446 | + $valid_email = $this->_validate_email($value); |
|
447 | + if (! $valid_email) { |
|
448 | + $err_msg .= htmlentities( |
|
449 | + sprintf( |
|
450 | + __( |
|
451 | + 'The %1$s field has at least one string that is not a valid email address record. Valid emails are in the format: "Name <[email protected]>" or "[email protected]" and multiple emails can be separated by a comma.' |
|
452 | + ), |
|
453 | + $field_label |
|
454 | + |
|
455 | + ) |
|
456 | + ); |
|
457 | + } |
|
458 | + break; |
|
459 | + default : |
|
460 | + break; |
|
461 | + } |
|
462 | + } |
|
463 | + |
|
464 | + //if $err_msg isn't empty let's setup the _errors array for this field. |
|
465 | + if (! empty($err_msg)) { |
|
466 | + $this->_errors[$field]['msg'] = $err_msg; |
|
467 | + } else { |
|
468 | + unset($this->_errors[$field]); |
|
469 | + } |
|
470 | + } |
|
471 | + |
|
472 | + // if we have ANY errors, then we want to make sure we return the values |
|
473 | + // for ALL the fields so the user doesn't have to retype them all. |
|
474 | + if (! empty($this->_errors)) { |
|
475 | + foreach ($this->_fields as $field => $value) { |
|
476 | + $this->_errors[$field]['value'] = stripslashes($value); |
|
477 | + } |
|
478 | + } |
|
479 | + |
|
480 | + //return any errors or just TRUE if everything validates |
|
481 | + return empty($this->_errors) ? true : $this->_errors; |
|
482 | + } |
|
483 | + |
|
484 | + |
|
485 | + /** |
|
486 | + * Reassembles and returns an array of valid shortcodes |
|
487 | + * given the array of groups and array of shortcodes indexed by group. |
|
488 | + * |
|
489 | + * @param array $groups array of shortcode groups that we want shortcodes for |
|
490 | + * @param array $codes_from_objs All the codes available. |
|
491 | + * @return array an array of actual shortcodes (that will be used for validation). |
|
492 | + */ |
|
493 | + private function _reassemble_valid_shortcodes_from_group($groups, $codes_from_objs) |
|
494 | + { |
|
495 | + $shortcodes = array(); |
|
496 | + foreach ($groups as $group) { |
|
497 | + $shortcodes = array_merge($shortcodes, $codes_from_objs[$group]); |
|
498 | + } |
|
499 | + return $shortcodes; |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + /** |
|
504 | + * Validates a string against a list of accepted shortcodes |
|
505 | + * This function takes in an array of shortcodes |
|
506 | + * and makes sure that the given string ONLY contains shortcodes in that array. |
|
507 | + * |
|
508 | + * @param string $value string to evaluate |
|
509 | + * @param array $valid_shortcodes array of shortcodes that are acceptable. |
|
510 | + * @return mixed (bool|string) return either a list of invalid shortcodes OR false if the shortcodes validate. |
|
511 | + */ |
|
512 | + protected function _invalid_shortcodes($value, $valid_shortcodes) |
|
513 | + { |
|
514 | + //first we need to go through the string and get the shortcodes in the string |
|
515 | + preg_match_all('/(\[.+?\])/', $value, $matches); |
|
516 | + $incoming_shortcodes = (array)$matches[0]; |
|
517 | + |
|
518 | + //get a diff of the shortcodes in the string vs the valid shortcodes |
|
519 | + $diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes)); |
|
520 | + |
|
521 | + //we need to account for custom codes so let's loop through the diff and remove any of those type of codes |
|
522 | + foreach ($diff as $ind => $code) { |
|
523 | + if (preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code)) { |
|
524 | + //strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] ) |
|
525 | + $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code); |
|
526 | + //does this exist in the $valid_shortcodes? If so then unset. |
|
527 | + if (isset($valid_shortcodes[$dynamic_sc])) { |
|
528 | + unset($diff[$ind]); |
|
529 | + } |
|
530 | + } |
|
531 | + } |
|
532 | + |
|
533 | + if (empty($diff)) { |
|
534 | + return false; |
|
535 | + } //there is no diff, we have no invalid shortcodes, so return |
|
536 | + |
|
537 | + //made it here? then let's assemble the error message |
|
538 | + $invalid_shortcodes = implode('</strong>,<strong>', $diff); |
|
539 | + $invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>'; |
|
540 | + return $invalid_shortcodes; |
|
541 | + } |
|
542 | + |
|
543 | + |
|
544 | + /** |
|
545 | + * Validates an incoming string and makes sure we have valid emails in the string. |
|
546 | + * |
|
547 | + * @param string $value incoming value to validate |
|
548 | + * @return bool true if the string validates, false if it doesn't |
|
549 | + */ |
|
550 | + protected function _validate_email($value) |
|
551 | + { |
|
552 | + $validate = true; |
|
553 | + $or_val = $value; |
|
554 | + |
|
555 | + // empty strings will validate because this is how a message template |
|
556 | + // for a particular context can be "turned off" (if there is no email then no message) |
|
557 | + if (empty($value)) { |
|
558 | + return $validate; |
|
559 | + } |
|
560 | + |
|
561 | + // first determine if there ARE any shortcodes. |
|
562 | + // If there are shortcodes and then later we find that there were no other valid emails |
|
563 | + // but the field isn't empty... |
|
564 | + // that means we've got extra commas that were left after stripping out shortcodes so probably still valid. |
|
565 | + $has_shortcodes = preg_match('/(\[.+?\])/', $value); |
|
566 | + |
|
567 | + //first we need to strip out all the shortcodes! |
|
568 | + $value = preg_replace('/(\[.+?\])/', '', $value); |
|
569 | + |
|
570 | + // if original value is not empty and new value is, then we've parsed out a shortcode |
|
571 | + // and we now have an empty string which DOES validate. |
|
572 | + // We also validate complete empty field for email because |
|
573 | + // its possible that this message is being "turned off" for a particular context |
|
574 | + |
|
575 | + |
|
576 | + if (! empty($or_val) && empty($value)) { |
|
577 | + return $validate; |
|
578 | + } |
|
579 | + |
|
580 | + //trim any commas from beginning and end of string ( after whitespace trimmed ); |
|
581 | + $value = trim(trim($value), ','); |
|
582 | + |
|
583 | + |
|
584 | + //next we need to split up the string if its comma delimited. |
|
585 | + $emails = explode(',', $value); |
|
586 | + $empty = false; //used to indicate that there is an empty comma. |
|
587 | + //now let's loop through the emails and do our checks |
|
588 | + foreach ($emails as $email) { |
|
589 | + if (empty($email)) { |
|
590 | + $empty = true; |
|
591 | + continue; |
|
592 | + } |
|
593 | + |
|
594 | + //trim whitespace |
|
595 | + $email = trim($email); |
|
596 | + //either its of type "[email protected]", or its of type "fname lname <[email protected]>" |
|
597 | + if (is_email($email)) { |
|
598 | + continue; |
|
599 | + } else { |
|
600 | + $matches = array(); |
|
601 | + $validate = preg_match('/(.*)<(.+)>/', $email, $matches) ? true : false; |
|
602 | + if ($validate && is_email($matches[2])) { |
|
603 | + continue; |
|
604 | + } else { |
|
605 | + return false; |
|
606 | + } |
|
607 | + } |
|
608 | + } |
|
609 | + |
|
610 | + $validate = $empty && ! $has_shortcodes ? false : $validate; |
|
611 | + |
|
612 | + return $validate; |
|
613 | + |
|
614 | + } |
|
615 | + |
|
616 | + |
|
617 | + /** |
|
618 | + * Magic getter |
|
619 | + * Using this to provide back compat with add-ons referencing deprecated properties. |
|
620 | + * |
|
621 | + * @param string $property Property being requested |
|
622 | + * @throws Exception |
|
623 | + * @return mixed |
|
624 | + */ |
|
625 | + public function __get($property) |
|
626 | + { |
|
627 | + $expected_properties_map = array( |
|
628 | + /** |
|
629 | + * @deprecated 4.9.0 |
|
630 | + */ |
|
631 | + '_MSGR' => '_messenger', |
|
632 | + /** |
|
633 | + * @deprecated 4.9.0 |
|
634 | + */ |
|
635 | + '_MSGTYP' => '_message_type', |
|
636 | + ); |
|
637 | + |
|
638 | + if (isset($expected_properties_map[$property])) { |
|
639 | + return $this->{$expected_properties_map[$property]}; |
|
640 | + } |
|
641 | + |
|
642 | + throw new Exception( |
|
643 | + sprintf( |
|
644 | + __('The property %1$s being requested on %2$s does not exist', 'event_espresso'), |
|
645 | + $property, |
|
646 | + get_class($this) |
|
647 | + ) |
|
648 | + ); |
|
649 | + } |
|
650 | 650 | |
651 | 651 | } |
@@ -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 | |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | //load messenger |
162 | 162 | $messenger = ucwords(str_replace('_', ' ', $this->_m_name)); |
163 | 163 | $messenger = str_replace(' ', '_', $messenger); |
164 | - $messenger = 'EE_' . $messenger . '_messenger'; |
|
164 | + $messenger = 'EE_'.$messenger.'_messenger'; |
|
165 | 165 | |
166 | - if (! class_exists($messenger)) { |
|
166 | + if ( ! class_exists($messenger)) { |
|
167 | 167 | throw new EE_Error( |
168 | 168 | sprintf( |
169 | 169 | __('There is no messenger class for the given string (%s)', 'event_espresso'), |
@@ -177,9 +177,9 @@ discard block |
||
177 | 177 | //load message type |
178 | 178 | $message_type = ucwords(str_replace('_', ' ', $this->_mt_name)); |
179 | 179 | $message_type = str_replace(' ', '_', $message_type); |
180 | - $message_type = 'EE_' . $message_type . '_message_type'; |
|
180 | + $message_type = 'EE_'.$message_type.'_message_type'; |
|
181 | 181 | |
182 | - if (! class_exists($message_type)) { |
|
182 | + if ( ! class_exists($message_type)) { |
|
183 | 183 | throw new EE_Error( |
184 | 184 | sprintf( |
185 | 185 | __('There is no message type class for the given string (%s)', 'event_espresso'), |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | foreach ($shortcode_groups as $group) { |
237 | 237 | $ref = ucwords(str_replace('_', ' ', $group)); |
238 | 238 | $ref = str_replace(' ', '_', $ref); |
239 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
239 | + $classname = 'EE_'.$ref.'_Shortcodes'; |
|
240 | 240 | if (class_exists($classname)) { |
241 | 241 | $a = new ReflectionClass($classname); |
242 | 242 | $obj = $a->newInstance(); |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | { |
331 | 331 | //specific validator filter |
332 | 332 | $shortcode_excludes = apply_filters( |
333 | - 'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;', |
|
333 | + 'FHEE__'.get_class($this).'__get_specific_shortcode_excludes;', |
|
334 | 334 | $this->_specific_shortcode_excludes, |
335 | 335 | $this->_context |
336 | 336 | ); |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | $err_msg = ''; |
363 | 363 | $field_label = ''; |
364 | 364 | //if field is not present in the _validators array then we continue |
365 | - if (! isset($this->_validators[$field])) { |
|
365 | + if ( ! isset($this->_validators[$field])) { |
|
366 | 366 | unset($this->_errors[$field]); |
367 | 367 | continue; |
368 | 368 | } |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s', |
412 | 412 | 'event_espresso' |
413 | 413 | ), |
414 | - '<strong>' . $field_label . '</strong>', |
|
414 | + '<strong>'.$field_label.'</strong>', |
|
415 | 415 | $invalid_shortcodes, |
416 | 416 | '<p>', |
417 | 417 | '</p >' |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | if (isset($this->_validators[$field]['type']) && ! empty($this->_validators[$field]['type'])) { |
430 | 430 | switch ($this->_validators[$field]['type']) { |
431 | 431 | case 'number' : |
432 | - if (! is_numeric($value)) { |
|
432 | + if ( ! is_numeric($value)) { |
|
433 | 433 | $err_msg .= sprintf( |
434 | 434 | __( |
435 | 435 | '%3$sThe %1$s field is supposed to be a number. The value given (%2$s) is not. Please double-check and make sure the field contains a number%4$s', |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | break; |
445 | 445 | case 'email' : |
446 | 446 | $valid_email = $this->_validate_email($value); |
447 | - if (! $valid_email) { |
|
447 | + if ( ! $valid_email) { |
|
448 | 448 | $err_msg .= htmlentities( |
449 | 449 | sprintf( |
450 | 450 | __( |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | } |
463 | 463 | |
464 | 464 | //if $err_msg isn't empty let's setup the _errors array for this field. |
465 | - if (! empty($err_msg)) { |
|
465 | + if ( ! empty($err_msg)) { |
|
466 | 466 | $this->_errors[$field]['msg'] = $err_msg; |
467 | 467 | } else { |
468 | 468 | unset($this->_errors[$field]); |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | |
472 | 472 | // if we have ANY errors, then we want to make sure we return the values |
473 | 473 | // for ALL the fields so the user doesn't have to retype them all. |
474 | - if (! empty($this->_errors)) { |
|
474 | + if ( ! empty($this->_errors)) { |
|
475 | 475 | foreach ($this->_fields as $field => $value) { |
476 | 476 | $this->_errors[$field]['value'] = stripslashes($value); |
477 | 477 | } |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | { |
514 | 514 | //first we need to go through the string and get the shortcodes in the string |
515 | 515 | preg_match_all('/(\[.+?\])/', $value, $matches); |
516 | - $incoming_shortcodes = (array)$matches[0]; |
|
516 | + $incoming_shortcodes = (array) $matches[0]; |
|
517 | 517 | |
518 | 518 | //get a diff of the shortcodes in the string vs the valid shortcodes |
519 | 519 | $diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes)); |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | |
537 | 537 | //made it here? then let's assemble the error message |
538 | 538 | $invalid_shortcodes = implode('</strong>,<strong>', $diff); |
539 | - $invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>'; |
|
539 | + $invalid_shortcodes = '<strong>'.$invalid_shortcodes.'</strong>'; |
|
540 | 540 | return $invalid_shortcodes; |
541 | 541 | } |
542 | 542 | |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | // its possible that this message is being "turned off" for a particular context |
574 | 574 | |
575 | 575 | |
576 | - if (! empty($or_val) && empty($value)) { |
|
576 | + if ( ! empty($or_val) && empty($value)) { |
|
577 | 577 | return $validate; |
578 | 578 | } |
579 | 579 |
@@ -38,217 +38,217 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - 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 | - ); ?> |
|
52 | + 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 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | |
64 | 64 | } else { |
65 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | - /** |
|
68 | - * espresso_minimum_php_version_error |
|
69 | - * |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - function espresso_minimum_php_version_error() |
|
73 | - { |
|
74 | - ?> |
|
65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | + /** |
|
68 | + * espresso_minimum_php_version_error |
|
69 | + * |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + function espresso_minimum_php_version_error() |
|
73 | + { |
|
74 | + ?> |
|
75 | 75 | <div class="error"> |
76 | 76 | <p> |
77 | 77 | <?php |
78 | - printf( |
|
79 | - esc_html__( |
|
80 | - '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.', |
|
81 | - 'event_espresso' |
|
82 | - ), |
|
83 | - EE_MIN_PHP_VER_REQUIRED, |
|
84 | - PHP_VERSION, |
|
85 | - '<br/>', |
|
86 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
87 | - ); |
|
88 | - ?> |
|
78 | + printf( |
|
79 | + esc_html__( |
|
80 | + '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.', |
|
81 | + 'event_espresso' |
|
82 | + ), |
|
83 | + EE_MIN_PHP_VER_REQUIRED, |
|
84 | + PHP_VERSION, |
|
85 | + '<br/>', |
|
86 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
87 | + ); |
|
88 | + ?> |
|
89 | 89 | </p> |
90 | 90 | </div> |
91 | 91 | <?php |
92 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
93 | - } |
|
92 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
93 | + } |
|
94 | 94 | |
95 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
96 | - } else { |
|
97 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
98 | - /** |
|
99 | - * espresso_version |
|
100 | - * Returns the plugin version |
|
101 | - * |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - function espresso_version() |
|
105 | - { |
|
106 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.53.rc.003'); |
|
107 | - } |
|
95 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
96 | + } else { |
|
97 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
98 | + /** |
|
99 | + * espresso_version |
|
100 | + * Returns the plugin version |
|
101 | + * |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + function espresso_version() |
|
105 | + { |
|
106 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.53.rc.003'); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * espresso_plugin_activation |
|
111 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
112 | - */ |
|
113 | - function espresso_plugin_activation() |
|
114 | - { |
|
115 | - update_option('ee_espresso_activation', true); |
|
116 | - } |
|
109 | + /** |
|
110 | + * espresso_plugin_activation |
|
111 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
112 | + */ |
|
113 | + function espresso_plugin_activation() |
|
114 | + { |
|
115 | + update_option('ee_espresso_activation', true); |
|
116 | + } |
|
117 | 117 | |
118 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
119 | - /** |
|
120 | - * espresso_load_error_handling |
|
121 | - * this function loads EE's class for handling exceptions and errors |
|
122 | - */ |
|
123 | - function espresso_load_error_handling() |
|
124 | - { |
|
125 | - static $error_handling_loaded = false; |
|
126 | - if ($error_handling_loaded) { |
|
127 | - return; |
|
128 | - } |
|
129 | - // load debugging tools |
|
130 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
131 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
132 | - \EEH_Debug_Tools::instance(); |
|
133 | - } |
|
134 | - // load error handling |
|
135 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
136 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
137 | - } else { |
|
138 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
139 | - } |
|
140 | - $error_handling_loaded = true; |
|
141 | - } |
|
118 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
119 | + /** |
|
120 | + * espresso_load_error_handling |
|
121 | + * this function loads EE's class for handling exceptions and errors |
|
122 | + */ |
|
123 | + function espresso_load_error_handling() |
|
124 | + { |
|
125 | + static $error_handling_loaded = false; |
|
126 | + if ($error_handling_loaded) { |
|
127 | + return; |
|
128 | + } |
|
129 | + // load debugging tools |
|
130 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
131 | + require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
132 | + \EEH_Debug_Tools::instance(); |
|
133 | + } |
|
134 | + // load error handling |
|
135 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
136 | + require_once EE_CORE . 'EE_Error.core.php'; |
|
137 | + } else { |
|
138 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
139 | + } |
|
140 | + $error_handling_loaded = true; |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * espresso_load_required |
|
145 | - * given a class name and path, this function will load that file or throw an exception |
|
146 | - * |
|
147 | - * @param string $classname |
|
148 | - * @param string $full_path_to_file |
|
149 | - * @throws EE_Error |
|
150 | - */ |
|
151 | - function espresso_load_required($classname, $full_path_to_file) |
|
152 | - { |
|
153 | - if (is_readable($full_path_to_file)) { |
|
154 | - require_once $full_path_to_file; |
|
155 | - } else { |
|
156 | - throw new \EE_Error ( |
|
157 | - sprintf( |
|
158 | - esc_html__( |
|
159 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
160 | - 'event_espresso' |
|
161 | - ), |
|
162 | - $classname |
|
163 | - ) |
|
164 | - ); |
|
165 | - } |
|
166 | - } |
|
143 | + /** |
|
144 | + * espresso_load_required |
|
145 | + * given a class name and path, this function will load that file or throw an exception |
|
146 | + * |
|
147 | + * @param string $classname |
|
148 | + * @param string $full_path_to_file |
|
149 | + * @throws EE_Error |
|
150 | + */ |
|
151 | + function espresso_load_required($classname, $full_path_to_file) |
|
152 | + { |
|
153 | + if (is_readable($full_path_to_file)) { |
|
154 | + require_once $full_path_to_file; |
|
155 | + } else { |
|
156 | + throw new \EE_Error ( |
|
157 | + sprintf( |
|
158 | + esc_html__( |
|
159 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
160 | + 'event_espresso' |
|
161 | + ), |
|
162 | + $classname |
|
163 | + ) |
|
164 | + ); |
|
165 | + } |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * @since 4.9.27 |
|
170 | - * @throws \EE_Error |
|
171 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
172 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
173 | - * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
174 | - * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
175 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
176 | - * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException |
|
177 | - * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException |
|
178 | - * @throws \OutOfBoundsException |
|
179 | - */ |
|
180 | - function bootstrap_espresso() |
|
181 | - { |
|
182 | - require_once __DIR__ . '/core/espresso_definitions.php'; |
|
183 | - try { |
|
184 | - espresso_load_error_handling(); |
|
185 | - espresso_load_required( |
|
186 | - 'EEH_Base', |
|
187 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
188 | - ); |
|
189 | - espresso_load_required( |
|
190 | - 'EEH_File', |
|
191 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
192 | - ); |
|
193 | - espresso_load_required( |
|
194 | - 'EEH_File', |
|
195 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
196 | - ); |
|
197 | - espresso_load_required( |
|
198 | - 'EEH_Array', |
|
199 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
200 | - ); |
|
201 | - // instantiate and configure PSR4 autoloader |
|
202 | - espresso_load_required( |
|
203 | - 'Psr4Autoloader', |
|
204 | - EE_CORE . 'Psr4Autoloader.php' |
|
205 | - ); |
|
206 | - espresso_load_required( |
|
207 | - 'EE_Psr4AutoloaderInit', |
|
208 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
209 | - ); |
|
210 | - $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
211 | - $AutoloaderInit->initializeAutoloader(); |
|
212 | - espresso_load_required( |
|
213 | - 'EE_Request', |
|
214 | - EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
215 | - ); |
|
216 | - espresso_load_required( |
|
217 | - 'EE_Response', |
|
218 | - EE_CORE . 'request_stack' . DS . 'EE_Response.core.php' |
|
219 | - ); |
|
220 | - espresso_load_required( |
|
221 | - 'EE_Bootstrap', |
|
222 | - EE_CORE . 'EE_Bootstrap.core.php' |
|
223 | - ); |
|
224 | - // bootstrap EE and the request stack |
|
225 | - new EE_Bootstrap( |
|
226 | - new EE_Request($_GET, $_POST, $_COOKIE), |
|
227 | - new EE_Response() |
|
228 | - ); |
|
229 | - } catch (Exception $e) { |
|
230 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
231 | - new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
232 | - } |
|
233 | - } |
|
234 | - bootstrap_espresso(); |
|
235 | - } |
|
168 | + /** |
|
169 | + * @since 4.9.27 |
|
170 | + * @throws \EE_Error |
|
171 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
172 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
173 | + * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
174 | + * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
175 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
176 | + * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException |
|
177 | + * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException |
|
178 | + * @throws \OutOfBoundsException |
|
179 | + */ |
|
180 | + function bootstrap_espresso() |
|
181 | + { |
|
182 | + require_once __DIR__ . '/core/espresso_definitions.php'; |
|
183 | + try { |
|
184 | + espresso_load_error_handling(); |
|
185 | + espresso_load_required( |
|
186 | + 'EEH_Base', |
|
187 | + EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
188 | + ); |
|
189 | + espresso_load_required( |
|
190 | + 'EEH_File', |
|
191 | + EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
192 | + ); |
|
193 | + espresso_load_required( |
|
194 | + 'EEH_File', |
|
195 | + EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
196 | + ); |
|
197 | + espresso_load_required( |
|
198 | + 'EEH_Array', |
|
199 | + EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
200 | + ); |
|
201 | + // instantiate and configure PSR4 autoloader |
|
202 | + espresso_load_required( |
|
203 | + 'Psr4Autoloader', |
|
204 | + EE_CORE . 'Psr4Autoloader.php' |
|
205 | + ); |
|
206 | + espresso_load_required( |
|
207 | + 'EE_Psr4AutoloaderInit', |
|
208 | + EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
209 | + ); |
|
210 | + $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
211 | + $AutoloaderInit->initializeAutoloader(); |
|
212 | + espresso_load_required( |
|
213 | + 'EE_Request', |
|
214 | + EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
215 | + ); |
|
216 | + espresso_load_required( |
|
217 | + 'EE_Response', |
|
218 | + EE_CORE . 'request_stack' . DS . 'EE_Response.core.php' |
|
219 | + ); |
|
220 | + espresso_load_required( |
|
221 | + 'EE_Bootstrap', |
|
222 | + EE_CORE . 'EE_Bootstrap.core.php' |
|
223 | + ); |
|
224 | + // bootstrap EE and the request stack |
|
225 | + new EE_Bootstrap( |
|
226 | + new EE_Request($_GET, $_POST, $_COOKIE), |
|
227 | + new EE_Response() |
|
228 | + ); |
|
229 | + } catch (Exception $e) { |
|
230 | + require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
231 | + new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
232 | + } |
|
233 | + } |
|
234 | + bootstrap_espresso(); |
|
235 | + } |
|
236 | 236 | } |
237 | 237 | if (! function_exists('espresso_deactivate_plugin')) { |
238 | - /** |
|
239 | - * deactivate_plugin |
|
240 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
241 | - * |
|
242 | - * @access public |
|
243 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
244 | - * @return void |
|
245 | - */ |
|
246 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
247 | - { |
|
248 | - if (! function_exists('deactivate_plugins')) { |
|
249 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
250 | - } |
|
251 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
252 | - deactivate_plugins($plugin_basename); |
|
253 | - } |
|
238 | + /** |
|
239 | + * deactivate_plugin |
|
240 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
241 | + * |
|
242 | + * @access public |
|
243 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
244 | + * @return void |
|
245 | + */ |
|
246 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
247 | + { |
|
248 | + if (! function_exists('deactivate_plugins')) { |
|
249 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
250 | + } |
|
251 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
252 | + deactivate_plugins($plugin_basename); |
|
253 | + } |
|
254 | 254 | } |