@@ -832,7 +832,7 @@ |
||
832 | 832 | * Takes care of setting up the addressee object(s) for the primary attendee. |
833 | 833 | * |
834 | 834 | * @access protected |
835 | - * @return array of EE_Addressee objects |
|
835 | + * @return EE_Messages_Addressee[] of EE_Addressee objects |
|
836 | 836 | * @throws EE_Error |
837 | 837 | */ |
838 | 838 | protected function _primary_attendee_addressees() |
@@ -20,914 +20,914 @@ |
||
20 | 20 | { |
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * message type child classes will set what contexts are associated with the message type via this array. |
|
25 | - * format: |
|
26 | - * array( |
|
27 | - * 'context' => array( |
|
28 | - * 'label' => __('Context Label', 'event_espresso'), |
|
29 | - * 'description' => __('Context description (for help popups)', 'event_espresso') |
|
30 | - * )); |
|
31 | - * |
|
32 | - * @var array |
|
33 | - */ |
|
34 | - protected $_contexts = array(); |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * This property is used to define what the display label will be for contexts (eg. "Recipients", "Themes" etc.) |
|
39 | - * Format: |
|
40 | - * array( 'label' => 'something', 'plural' => 'somethings', 'description' => 'something' ); |
|
41 | - * |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - protected $_context_label; |
|
45 | - |
|
46 | - |
|
47 | - /** MESSAGE ASSEMBLING PROPERTIES **/ |
|
48 | - /** |
|
49 | - * This parameter simply holds all the message objects for retrieval by the controller and sending to the messenger. |
|
50 | - * |
|
51 | - * @var array of message objects. |
|
52 | - */ |
|
53 | - public $messages = array(); |
|
54 | - |
|
55 | - /** |
|
56 | - * The following holds the templates that will be used to assemble the message object for the messenger. |
|
57 | - * |
|
58 | - * @var array |
|
59 | - */ |
|
60 | - protected $_templates; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * If a specific template is being parsed, this will hold the message template group GRP_ID for that template. |
|
65 | - * |
|
66 | - * @var int. |
|
67 | - */ |
|
68 | - protected $_GRP_ID; |
|
69 | - |
|
70 | - |
|
71 | - /** OTHER INFO PROPERTIES **/ |
|
72 | - /** |
|
73 | - * This will hold the count of the message objects in the messages array. This could be used for determining if |
|
74 | - * batching/queueing is needed. |
|
75 | - * |
|
76 | - * @var int |
|
77 | - */ |
|
78 | - public $count = 0; |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * This is set via the `do_messenger_hooks` method and contains the messenger being used to send the message of |
|
83 | - * this message type at time of sending. |
|
84 | - * |
|
85 | - * @var EE_messenger |
|
86 | - */ |
|
87 | - protected $_active_messenger; |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * This will hold the shortcode_replace instance for handling replacement of shortcodes in the various templates |
|
92 | - * |
|
93 | - * @var object |
|
94 | - */ |
|
95 | - protected $_shortcode_replace; |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * The purpose for this property is to simply allow message types to indicate if the message generated is intended |
|
100 | - * for only single context. Child message types should redefine this variable (if necessary) in the |
|
101 | - * _set_data_Handler() method. |
|
102 | - * |
|
103 | - * @var boolean |
|
104 | - */ |
|
105 | - protected $_single_message = false; |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * This will hold an array of specific reg_ids that are receiving messages. |
|
110 | - * |
|
111 | - * @since 4.7.x |
|
112 | - * @var array |
|
113 | - */ |
|
114 | - protected $_regs_for_sending = array(); |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * This holds the data passed to this class from the controller and also the final processed data. |
|
119 | - * |
|
120 | - * @var object |
|
121 | - */ |
|
122 | - protected $_data; |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * this is just a flag indicating whether we're in preview mode or not. |
|
127 | - * |
|
128 | - * @var bool |
|
129 | - */ |
|
130 | - protected $_preview = false; |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * This just holds defaults for addressee data that children merge with their data array setup |
|
135 | - * |
|
136 | - * @var array |
|
137 | - */ |
|
138 | - protected $_default_addressee_data; |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * Child classes declare through this property what handler they want to use for the incoming data and this string |
|
143 | - * is used to instantiate the EE_Messages_incoming_data child class for that handler. |
|
144 | - * |
|
145 | - * @var string |
|
146 | - */ |
|
147 | - protected $_data_handler; |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * This holds any specific fields for holding any settings related to a message type (if any needed) |
|
152 | - * |
|
153 | - * @var array |
|
154 | - */ |
|
155 | - protected $_admin_settings_fields = array(); |
|
156 | - |
|
157 | - /** |
|
158 | - * this property will hold any existing setting that may have been set in the admin. |
|
159 | - * |
|
160 | - * @var array |
|
161 | - */ |
|
162 | - protected $_existing_admin_settings = array(); |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * This is used to designate the generating and alternative sending messengers for a message type. It is set via |
|
167 | - * set_with_messengers() on construct. Note, generating messenger also acts as a sending messenger for this message |
|
168 | - * type. However ONLY the generating messengers are used for creating templates for this message type. Should be |
|
169 | - * in this format: |
|
170 | - * { |
|
171 | - * |
|
172 | - * @type string $generating_messenger the name of the generating messenger. Generating |
|
173 | - * messengers are used for generating templates, |
|
174 | - * doing validation and defining valid shortcodes. |
|
175 | - * { |
|
176 | - * @type string $sending_messenger values are the name(s) for the sending |
|
177 | - * messengers. sending messengers are |
|
178 | - * just valid delivery vehicles that will utilize |
|
179 | - * the templates (and generated EE_message |
|
180 | - * objects from the generating messengers). |
|
181 | - * } |
|
182 | - * } |
|
183 | - * @since 4.5.0 |
|
184 | - * @var array |
|
185 | - */ |
|
186 | - protected $_with_messengers = array(); |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * This holds the addressees in an array indexed by context for later retrieval when assembling the message objects. |
|
191 | - * |
|
192 | - * @access protected |
|
193 | - * @var array |
|
194 | - */ |
|
195 | - protected $_addressees = array(); |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * This allows each message type to set what alternate messenger&message type combination can be used for fallback |
|
200 | - * default templates if there are no specific ones defined for this messenger and message type. Should be in the |
|
201 | - * format: |
|
202 | - * array( |
|
203 | - * 'messenger' => 'message_type', |
|
204 | - * 'another_messenger' => another_message_type |
|
205 | - * ); |
|
206 | - * This is set in the message type constructor. |
|
207 | - * |
|
208 | - * @var array |
|
209 | - */ |
|
210 | - protected $_master_templates = array(); |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * This holds whatever the set template pack is for a message template group when generating messages. |
|
215 | - * |
|
216 | - * @since 4.5.0 |
|
217 | - * @var EE_Messages_Template_Pack |
|
218 | - */ |
|
219 | - protected $_template_pack; |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * This holds whatever the set variation is for a message template group when generating messages. |
|
224 | - * |
|
225 | - * @since 4.5.0 |
|
226 | - * @var string |
|
227 | - */ |
|
228 | - protected $_variation; |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * EE_message_type constructor. |
|
233 | - */ |
|
234 | - public function __construct() |
|
235 | - { |
|
236 | - $this->_messages_item_type = 'message_type'; |
|
237 | - $this->_set_contexts(); |
|
238 | - $this->_set_with_messengers(); |
|
239 | - parent::__construct(); |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * This sets the data handler for the message type. It must be used to define the _data_handler property. It is |
|
245 | - * called when messages are setup. |
|
246 | - * |
|
247 | - * @abstract |
|
248 | - * @access protected |
|
249 | - * @return void |
|
250 | - */ |
|
251 | - abstract protected function _set_data_handler(); |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * This method should return a EE_Base_Class object (or array of EE_Base_Class objects) for the given context and |
|
256 | - * ID (which should be the primary key id for the base class). Client code doesn't have to know what a message |
|
257 | - * type's data handler is. |
|
258 | - * |
|
259 | - * @since 4.5.0 |
|
260 | - * @param string $context This should be a string matching a valid context for the message type. |
|
261 | - * @param EE_Registration $registration Need a registration to ensure that the data is valid (prevents people |
|
262 | - * guessing a url). |
|
263 | - * @param int $id Optional. Integer corresponding to the value for the primary key of a |
|
264 | - * EE_Base_Class_Object |
|
265 | - * @return mixed ( EE_Base_Class||EE_Base_Class[] ) |
|
266 | - */ |
|
267 | - abstract protected function _get_data_for_context($context, EE_Registration $registration, $id); |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * _set_contexts |
|
272 | - * This sets up the contexts associated with the message_type |
|
273 | - * |
|
274 | - * @abstract |
|
275 | - * @access protected |
|
276 | - * @return void |
|
277 | - */ |
|
278 | - abstract protected function _set_contexts(); |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * This is used to get the "id" value fo the msg_trigger_url generated by get_url_trigger(). |
|
283 | - * In most cases, child classes don't need anything, (hence the default of 0), however if there is a specific |
|
284 | - * EE_Base_Class that is required in generating a message for a message type recipient then the message |
|
285 | - * type should override this method and use the given params to generate the correct ID. |
|
286 | - * |
|
287 | - * @param string $context The message type context. |
|
288 | - * @param EE_Registration $registration Registration object |
|
289 | - * @deprecated 4.9.0 |
|
290 | - * @return int |
|
291 | - */ |
|
292 | - protected function _get_id_for_msg_url($context, EE_Registration $registration) |
|
293 | - { |
|
294 | - return 0; |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * This sets up any action/filter hooks this message type puts in place for a specific messenger. Note that by |
|
300 | - * default this does nothing. Child classes will need to override if they want to add specific hooks for a |
|
301 | - * messenger. |
|
302 | - * |
|
303 | - * @since 1.0.0 |
|
304 | - * @return void |
|
305 | - */ |
|
306 | - protected function _do_messenger_hooks() |
|
307 | - { |
|
308 | - return; |
|
309 | - } |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * This is a public wrapper for the protected _do_messenger_hooks() method. |
|
314 | - * For backward compat reasons, this was done rather than making the protected method public. |
|
315 | - * |
|
316 | - * @param EE_messenger $messenger This is used to set the $_active_messenger property, so message types are able |
|
317 | - * to know what messenger is being used to send the message at the time of |
|
318 | - * sending. |
|
319 | - * @since 4.9.0 |
|
320 | - */ |
|
321 | - public function do_messenger_hooks($messenger = null) |
|
322 | - { |
|
323 | - $this->_active_messenger = $messenger; |
|
324 | - $this->_do_messenger_hooks(); |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * This method returns whether this message type should always generate a new copy |
|
330 | - * when requested, or if links can be to the already generated copy. |
|
331 | - * Note: this does NOT affect viewing/resending already generated messages in the EE_Message list table. |
|
332 | - * Child classes should override this if different from the default of false. |
|
333 | - * |
|
334 | - * @return bool false means can link to generated EE_Message. true must regenerate. |
|
335 | - */ |
|
336 | - public function always_generate() |
|
337 | - { |
|
338 | - return false; |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * Returns the priority for the message type. |
|
344 | - * Priorities are defined as constants on EEM_Message. Currently there are three priorities: |
|
345 | - * - EEM_Message::priority_high |
|
346 | - * - EEM_Message::priority_medium |
|
347 | - * - EEM_Message::priority_low |
|
348 | - * Priority is used to determine the weight the message type is given when queuing for generation and/or sending. |
|
349 | - * |
|
350 | - * @see EEM_Message for more phpdocs on priority. |
|
351 | - * The default priority for all message_types is EEM_Message::priority_low. Message Types wanting to give |
|
352 | - * a higher priority must override this method. Also note, messengers are able to override priorities |
|
353 | - * queuing instructions if their "send_now" flag is set to true. An example of this is the HTML messenger |
|
354 | - * which displays things in the browser. |
|
355 | - * @since 4.9.0 |
|
356 | - * @return int |
|
357 | - */ |
|
358 | - public function get_priority() |
|
359 | - { |
|
360 | - return EEM_Message::priority_low; |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * This runs the _set_data_handler() method for message types and then returns what got set. |
|
366 | - * |
|
367 | - * @param mixed $data This sets the data property for the message type with the incoming data used for generating. |
|
368 | - * @return string (the reference for the data handler) (will be an empty string if could not be determined). |
|
369 | - */ |
|
370 | - public function get_data_handler($data) |
|
371 | - { |
|
372 | - $this->_data = $data; |
|
373 | - $this->_set_data_handler(); |
|
374 | - return apply_filters('FHEE__EE_message_type__get_data_handler', $this->_data_handler, $this); |
|
375 | - } |
|
376 | - |
|
377 | - |
|
378 | - /** |
|
379 | - * This is called externally to reset the value of the $_data property for the message type. |
|
380 | - * Please note the value of the _data is highly volatile. It was added as an interim measure ensuring |
|
381 | - * EE_Message_To_Generate objects have any changes to the _data property when `_set_data_handler` method is called |
|
382 | - * (and for back compat reasons). This particular method is used in |
|
383 | - * EE_Messages_Generator::_reset_current_properties to ensure that the internal _data on the message type is |
|
384 | - * cleaned before subsequent EE_Message generation in the same request. |
|
385 | - * |
|
386 | - * @todo This needs refactored along with the whole _set_data_handler() method in EE_message_types. Need to |
|
387 | - * ensure that there is no manipulation of the _data property during run time so there's a clear |
|
388 | - * expectation of what it is. Likely we need to ensure that _data is not persisted IN the message type |
|
389 | - * at all. |
|
390 | - * @internal Plugin authors, do not implement this method, it is subject to change. |
|
391 | - * @since 4.9 |
|
392 | - */ |
|
393 | - public function reset_data() |
|
394 | - { |
|
395 | - $this->_data = null; |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - /** |
|
400 | - * This does some validation of incoming params gets the url trigger from the defined method in the specific child |
|
401 | - * class and then filters the results. |
|
402 | - * |
|
403 | - * @param string $context The message type context |
|
404 | - * @param string $sending_messenger The sending messenger |
|
405 | - * @param EE_Registration $registration Registration object |
|
406 | - * @throws EE_Error |
|
407 | - * @deprecated 4.9.0 Likely 4.9.10 or 4.10.0 will remove this method completely |
|
408 | - * @return string generated url |
|
409 | - */ |
|
410 | - public function get_url_trigger($context, $sending_messenger, EE_Registration $registration) |
|
411 | - { |
|
412 | - //validate context |
|
413 | - //valid context? |
|
414 | - if (! isset($this->_contexts[$context])) { |
|
415 | - throw new EE_Error( |
|
416 | - sprintf( |
|
417 | - __('The context %s is not a valid context for %s.', 'event_espresso'), |
|
418 | - $context, |
|
419 | - get_class($this) |
|
420 | - ) |
|
421 | - ); |
|
422 | - } |
|
423 | - //valid sending_messenger? |
|
424 | - $not_valid_msgr = false; |
|
425 | - foreach ($this->_with_messengers as $generating => $sendings) { |
|
426 | - if (empty($sendings) || array_search($sending_messenger, $sendings) === false) { |
|
427 | - $not_valid_msgr = true; |
|
428 | - } |
|
429 | - } |
|
430 | - if ($not_valid_msgr) { |
|
431 | - throw new EE_Error( |
|
432 | - sprintf( |
|
433 | - __( |
|
434 | - 'The given sending messenger string (%s) does not match a valid sending messenger with the %s. If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.', |
|
435 | - 'event_espresso' |
|
436 | - ), |
|
437 | - $sending_messenger, |
|
438 | - get_class($this) |
|
439 | - ) |
|
440 | - ); |
|
441 | - } |
|
442 | - return EEH_MSG_Template::generate_url_trigger( |
|
443 | - $sending_messenger, |
|
444 | - $this->_active_messenger->name, |
|
445 | - $context, |
|
446 | - $this->name, |
|
447 | - $registration, |
|
448 | - $this->_GRP_ID, |
|
449 | - $this->_get_id_for_msg_url($context, $registration) |
|
450 | - ); |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - /** |
|
455 | - * Wrapper for _get_data_for_context() that handles some validation before calling the main class and also allows |
|
456 | - * for filtering. This is (currently) called by the EED_Messages module. |
|
457 | - * |
|
458 | - * @since 4.5.0 |
|
459 | - * @throws EE_Error |
|
460 | - * @param string $context This should be a string matching a valid context for the message type. |
|
461 | - * @param EE_Registration $registration Need a registration to ensure that the data is valid (prevents people |
|
462 | - * guessing a url). |
|
463 | - * @param int $id Optional. Integer corresponding to the value for the primary key of a |
|
464 | - * EE_Base_Class_Object |
|
465 | - * @return mixed (EE_Base_Class||EE_Base_Class[]) |
|
466 | - */ |
|
467 | - public function get_data_for_context($context, EE_Registration $registration, $id = 0) |
|
468 | - { |
|
469 | - //valid context? |
|
470 | - if (! isset($this->_contexts[$context])) { |
|
471 | - throw new EE_Error( |
|
472 | - sprintf( |
|
473 | - __('The context %s is not a valid context for %s.', 'event_espresso'), |
|
474 | - $context, |
|
475 | - get_class($this) |
|
476 | - ) |
|
477 | - ); |
|
478 | - } |
|
479 | - //get data and apply global and class specific filters on it. |
|
480 | - $data = apply_filters( |
|
481 | - 'FHEE__EE_message_type__get_data_for_context__data', |
|
482 | - $this->_get_data_for_context($context, $registration, $id), |
|
483 | - $this |
|
484 | - ); |
|
485 | - $data = apply_filters('FHEE__' . get_class($this) . '__get_data_for_context__data', $data, $this); |
|
486 | - //if empty then something went wrong! |
|
487 | - if (empty($data)) { |
|
488 | - throw new EE_Error( |
|
489 | - sprintf( |
|
490 | - __( |
|
491 | - 'There is no data retrieved, it is possible that the id given (%d) does not match any value in the database for the corresponding EE_Base_Class used by the data handler for the %s message type.', |
|
492 | - 'event_espresso' |
|
493 | - ), |
|
494 | - $id, |
|
495 | - $this->name |
|
496 | - ) |
|
497 | - ); |
|
498 | - } |
|
499 | - return $data; |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - /** |
|
504 | - * This returns the contents of the _data property. |
|
505 | - * Please note the value of the _data is highly volatile. It was added as an interim measure ensuring |
|
506 | - * EE_Message_To_Generate objects have any changes to the _data property when `_set_data_handler` method is called. |
|
507 | - * |
|
508 | - * @todo This needs refactored along with the whole _set_data_handler() method in EE_message_types. Need to |
|
509 | - * ensure that there is no manipulation of the _data property during run time so there's a clear |
|
510 | - * expectation of what it is. |
|
511 | - * @internal Plugin authors, do not implement this method, it is subject to change. |
|
512 | - * @return mixed |
|
513 | - */ |
|
514 | - public function get_data() |
|
515 | - { |
|
516 | - return $this->_data; |
|
517 | - } |
|
518 | - |
|
519 | - |
|
520 | - /** |
|
521 | - * used to set the $_with_messengers property. (this is a default, child classes SHOULD override) |
|
522 | - * |
|
523 | - * @see property definition for description of setup. |
|
524 | - * @since 4.5.0 |
|
525 | - * @abstract |
|
526 | - * @return void |
|
527 | - */ |
|
528 | - protected function _set_with_messengers() |
|
529 | - { |
|
530 | - $this->_with_messengers = array( |
|
531 | - 'email' => array('html'), |
|
532 | - ); |
|
533 | - } |
|
534 | - |
|
535 | - |
|
536 | - /** |
|
537 | - * Return the value of the _with_messengers property |
|
538 | - * |
|
539 | - * @since 4.5.0 |
|
540 | - * @return array |
|
541 | - */ |
|
542 | - public function with_messengers() |
|
543 | - { |
|
544 | - return apply_filters( |
|
545 | - 'FHEE__EE_message_type__get_with_messengers__with_messengers__' . get_class($this), |
|
546 | - $this->_with_messengers |
|
547 | - ); |
|
548 | - } |
|
549 | - |
|
550 | - |
|
551 | - /** |
|
552 | - * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class |
|
553 | - * callback function if that page is registered via the `_admin_registered_page` property set by the child class. |
|
554 | - * * |
|
555 | - * |
|
556 | - * @param string $page the slug of the EE admin page |
|
557 | - * @param array $messengers an array of active messenger objects |
|
558 | - * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages) |
|
559 | - * @param array $extra This is just an extra argument that can be used to pass additional data for setting up |
|
560 | - * page content. |
|
561 | - * @access public |
|
562 | - * @return string |
|
563 | - */ |
|
564 | - public function get_message_type_admin_page_content( |
|
565 | - $page, |
|
566 | - $action = null, |
|
567 | - $extra = array(), |
|
568 | - $messengers = array() |
|
569 | - ) { |
|
570 | - //we can also further refine the context by action (if present). |
|
571 | - return $this->_get_admin_page_content($page, $action, $extra, $messengers); |
|
572 | - } |
|
573 | - |
|
574 | - |
|
575 | - /** |
|
576 | - * @return array |
|
577 | - */ |
|
578 | - public function get_contexts() |
|
579 | - { |
|
580 | - return $this->_contexts; |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - /** |
|
585 | - * This just returns the context label for a given context (as set in $_context_label property) |
|
586 | - * |
|
587 | - * @access public |
|
588 | - * @return array |
|
589 | - */ |
|
590 | - public function get_context_label() |
|
591 | - { |
|
592 | - return $this->_context_label; |
|
593 | - } |
|
594 | - |
|
595 | - |
|
596 | - /** |
|
597 | - * This just returns the (filtered) _master_templates property. |
|
598 | - * |
|
599 | - * @see property definition for documentation. |
|
600 | - * @return array |
|
601 | - */ |
|
602 | - public function get_master_templates() |
|
603 | - { |
|
604 | - //first class specific filter then filter that by the global filter. |
|
605 | - $master_templates = apply_filters( |
|
606 | - 'FHEE__' . get_class($this) . '__get_master_templates', |
|
607 | - $this->_master_templates |
|
608 | - ); |
|
609 | - return apply_filters('FHEE__EE_message_type__get_master_templates', $master_templates, $this); |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * Accepts an incoming data handler which contains data for processing, and returns an array of |
|
615 | - * EE_Messages_Addressee objects. |
|
616 | - * |
|
617 | - * @param EE_Messages_incoming_data $data |
|
618 | - * @param string $context Limit addressees to specific context. |
|
619 | - * @return array An array indexed by context where each context is an array of EE_Messages_Addressee objects for |
|
620 | - * that context |
|
621 | - * @throws EE_Error |
|
622 | - */ |
|
623 | - public function get_addressees(EE_Messages_incoming_data $data, $context = '') |
|
624 | - { |
|
625 | - //override _data |
|
626 | - $this->_data = $data; |
|
627 | - $addressees = array(); |
|
628 | - $original_contexts = $this->_contexts; |
|
629 | - //if incoming context then limit to that context |
|
630 | - if (! empty($context)) { |
|
631 | - $cntxt = ! empty($this->_contexts[$context]) ? $this->_contexts[$context] : ''; |
|
632 | - if (! empty($cntxt)) { |
|
633 | - $this->_contexts = array(); |
|
634 | - $this->_contexts[$context] = $cntxt; |
|
635 | - } |
|
636 | - } |
|
637 | - $this->_set_default_addressee_data(); |
|
638 | - if ($this->_process_data()) { |
|
639 | - $addressees = $this->_addressees; |
|
640 | - } |
|
641 | - |
|
642 | - //reset contexts and addressees |
|
643 | - $this->_contexts = $original_contexts; |
|
644 | - $this->_addressees = array(); |
|
645 | - return $addressees; |
|
646 | - } |
|
647 | - |
|
648 | - |
|
649 | - /** |
|
650 | - * processes the data object so we get |
|
651 | - * |
|
652 | - * @throws EE_Error |
|
653 | - * @return bool true means data was processed successfully, false means not. |
|
654 | - */ |
|
655 | - protected function _process_data() |
|
656 | - { |
|
657 | - //at a minimum, we NEED EE_Attendee objects. |
|
658 | - if (empty($this->_data->attendees)) { |
|
659 | - return false; //there's no data to process! |
|
660 | - } |
|
661 | - // process addressees for each context. Child classes will have to have methods for |
|
662 | - // each context defined to handle the processing of the data object within them |
|
663 | - foreach ($this->_contexts as $context => $details) { |
|
664 | - $xpctd_method = '_' . $context . '_addressees'; |
|
665 | - if (! method_exists($this, $xpctd_method)) { |
|
666 | - throw new EE_Error( |
|
667 | - sprintf( |
|
668 | - __( |
|
669 | - 'The data for %1$s message type cannot be prepared because there is no set method for doing so. The expected method name is "%2$s" please doublecheck the %1$s message type class and make sure that method is present', |
|
670 | - 'event_espresso' |
|
671 | - ), |
|
672 | - $this->label['singular'], |
|
673 | - $xpctd_method |
|
674 | - ) |
|
675 | - ); |
|
676 | - } |
|
677 | - $this->_addressees[$context] = call_user_func(array($this, $xpctd_method)); |
|
678 | - } |
|
679 | - return true; //data was processed successfully. |
|
680 | - } |
|
681 | - |
|
682 | - |
|
683 | - /** |
|
684 | - * sets the default_addressee_data property, |
|
685 | - * |
|
686 | - * @access private |
|
687 | - * @return void |
|
688 | - */ |
|
689 | - private function _set_default_addressee_data() |
|
690 | - { |
|
691 | - $this->_default_addressee_data = array( |
|
692 | - 'billing' => $this->_data->billing, |
|
693 | - 'taxes' => $this->_data->taxes, |
|
694 | - 'tax_line_items' => $this->_data->tax_line_items, |
|
695 | - 'additional_line_items' => $this->_data->additional_line_items, |
|
696 | - 'grand_total_line_item' => $this->_data->grand_total_line_item, |
|
697 | - 'txn' => $this->_data->txn, |
|
698 | - 'payments' => $this->_data->payments, |
|
699 | - 'payment' => isset($this->_data->payment) && $this->_data->payment instanceof EE_Payment |
|
700 | - ? $this->_data->payment |
|
701 | - : null, |
|
702 | - 'reg_objs' => $this->_data->reg_objs, |
|
703 | - 'registrations' => $this->_data->registrations, |
|
704 | - 'datetimes' => $this->_data->datetimes, |
|
705 | - 'tickets' => $this->_data->tickets, |
|
706 | - 'line_items_with_children' => $this->_data->line_items_with_children, |
|
707 | - 'questions' => $this->_data->questions, |
|
708 | - 'answers' => $this->_data->answers, |
|
709 | - 'txn_status' => $this->_data->txn_status, |
|
710 | - 'total_ticket_count' => $this->_data->total_ticket_count, |
|
711 | - ); |
|
712 | - if (is_array($this->_data->primary_attendee_data)) { |
|
713 | - $this->_default_addressee_data = array_merge( |
|
714 | - $this->_default_addressee_data, |
|
715 | - $this->_data->primary_attendee_data |
|
716 | - ); |
|
717 | - $this->_default_addressee_data['primary_att_obj'] = $this->_data->primary_attendee_data['att_obj']; |
|
718 | - $this->_default_addressee_data['primary_reg_obj'] = $this->_data->primary_attendee_data['reg_obj']; |
|
719 | - } |
|
720 | - } |
|
721 | - |
|
722 | - |
|
723 | - |
|
724 | - /******************** |
|
23 | + /** |
|
24 | + * message type child classes will set what contexts are associated with the message type via this array. |
|
25 | + * format: |
|
26 | + * array( |
|
27 | + * 'context' => array( |
|
28 | + * 'label' => __('Context Label', 'event_espresso'), |
|
29 | + * 'description' => __('Context description (for help popups)', 'event_espresso') |
|
30 | + * )); |
|
31 | + * |
|
32 | + * @var array |
|
33 | + */ |
|
34 | + protected $_contexts = array(); |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * This property is used to define what the display label will be for contexts (eg. "Recipients", "Themes" etc.) |
|
39 | + * Format: |
|
40 | + * array( 'label' => 'something', 'plural' => 'somethings', 'description' => 'something' ); |
|
41 | + * |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + protected $_context_label; |
|
45 | + |
|
46 | + |
|
47 | + /** MESSAGE ASSEMBLING PROPERTIES **/ |
|
48 | + /** |
|
49 | + * This parameter simply holds all the message objects for retrieval by the controller and sending to the messenger. |
|
50 | + * |
|
51 | + * @var array of message objects. |
|
52 | + */ |
|
53 | + public $messages = array(); |
|
54 | + |
|
55 | + /** |
|
56 | + * The following holds the templates that will be used to assemble the message object for the messenger. |
|
57 | + * |
|
58 | + * @var array |
|
59 | + */ |
|
60 | + protected $_templates; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * If a specific template is being parsed, this will hold the message template group GRP_ID for that template. |
|
65 | + * |
|
66 | + * @var int. |
|
67 | + */ |
|
68 | + protected $_GRP_ID; |
|
69 | + |
|
70 | + |
|
71 | + /** OTHER INFO PROPERTIES **/ |
|
72 | + /** |
|
73 | + * This will hold the count of the message objects in the messages array. This could be used for determining if |
|
74 | + * batching/queueing is needed. |
|
75 | + * |
|
76 | + * @var int |
|
77 | + */ |
|
78 | + public $count = 0; |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * This is set via the `do_messenger_hooks` method and contains the messenger being used to send the message of |
|
83 | + * this message type at time of sending. |
|
84 | + * |
|
85 | + * @var EE_messenger |
|
86 | + */ |
|
87 | + protected $_active_messenger; |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * This will hold the shortcode_replace instance for handling replacement of shortcodes in the various templates |
|
92 | + * |
|
93 | + * @var object |
|
94 | + */ |
|
95 | + protected $_shortcode_replace; |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * The purpose for this property is to simply allow message types to indicate if the message generated is intended |
|
100 | + * for only single context. Child message types should redefine this variable (if necessary) in the |
|
101 | + * _set_data_Handler() method. |
|
102 | + * |
|
103 | + * @var boolean |
|
104 | + */ |
|
105 | + protected $_single_message = false; |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * This will hold an array of specific reg_ids that are receiving messages. |
|
110 | + * |
|
111 | + * @since 4.7.x |
|
112 | + * @var array |
|
113 | + */ |
|
114 | + protected $_regs_for_sending = array(); |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * This holds the data passed to this class from the controller and also the final processed data. |
|
119 | + * |
|
120 | + * @var object |
|
121 | + */ |
|
122 | + protected $_data; |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * this is just a flag indicating whether we're in preview mode or not. |
|
127 | + * |
|
128 | + * @var bool |
|
129 | + */ |
|
130 | + protected $_preview = false; |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * This just holds defaults for addressee data that children merge with their data array setup |
|
135 | + * |
|
136 | + * @var array |
|
137 | + */ |
|
138 | + protected $_default_addressee_data; |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * Child classes declare through this property what handler they want to use for the incoming data and this string |
|
143 | + * is used to instantiate the EE_Messages_incoming_data child class for that handler. |
|
144 | + * |
|
145 | + * @var string |
|
146 | + */ |
|
147 | + protected $_data_handler; |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * This holds any specific fields for holding any settings related to a message type (if any needed) |
|
152 | + * |
|
153 | + * @var array |
|
154 | + */ |
|
155 | + protected $_admin_settings_fields = array(); |
|
156 | + |
|
157 | + /** |
|
158 | + * this property will hold any existing setting that may have been set in the admin. |
|
159 | + * |
|
160 | + * @var array |
|
161 | + */ |
|
162 | + protected $_existing_admin_settings = array(); |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * This is used to designate the generating and alternative sending messengers for a message type. It is set via |
|
167 | + * set_with_messengers() on construct. Note, generating messenger also acts as a sending messenger for this message |
|
168 | + * type. However ONLY the generating messengers are used for creating templates for this message type. Should be |
|
169 | + * in this format: |
|
170 | + * { |
|
171 | + * |
|
172 | + * @type string $generating_messenger the name of the generating messenger. Generating |
|
173 | + * messengers are used for generating templates, |
|
174 | + * doing validation and defining valid shortcodes. |
|
175 | + * { |
|
176 | + * @type string $sending_messenger values are the name(s) for the sending |
|
177 | + * messengers. sending messengers are |
|
178 | + * just valid delivery vehicles that will utilize |
|
179 | + * the templates (and generated EE_message |
|
180 | + * objects from the generating messengers). |
|
181 | + * } |
|
182 | + * } |
|
183 | + * @since 4.5.0 |
|
184 | + * @var array |
|
185 | + */ |
|
186 | + protected $_with_messengers = array(); |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * This holds the addressees in an array indexed by context for later retrieval when assembling the message objects. |
|
191 | + * |
|
192 | + * @access protected |
|
193 | + * @var array |
|
194 | + */ |
|
195 | + protected $_addressees = array(); |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * This allows each message type to set what alternate messenger&message type combination can be used for fallback |
|
200 | + * default templates if there are no specific ones defined for this messenger and message type. Should be in the |
|
201 | + * format: |
|
202 | + * array( |
|
203 | + * 'messenger' => 'message_type', |
|
204 | + * 'another_messenger' => another_message_type |
|
205 | + * ); |
|
206 | + * This is set in the message type constructor. |
|
207 | + * |
|
208 | + * @var array |
|
209 | + */ |
|
210 | + protected $_master_templates = array(); |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * This holds whatever the set template pack is for a message template group when generating messages. |
|
215 | + * |
|
216 | + * @since 4.5.0 |
|
217 | + * @var EE_Messages_Template_Pack |
|
218 | + */ |
|
219 | + protected $_template_pack; |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * This holds whatever the set variation is for a message template group when generating messages. |
|
224 | + * |
|
225 | + * @since 4.5.0 |
|
226 | + * @var string |
|
227 | + */ |
|
228 | + protected $_variation; |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * EE_message_type constructor. |
|
233 | + */ |
|
234 | + public function __construct() |
|
235 | + { |
|
236 | + $this->_messages_item_type = 'message_type'; |
|
237 | + $this->_set_contexts(); |
|
238 | + $this->_set_with_messengers(); |
|
239 | + parent::__construct(); |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * This sets the data handler for the message type. It must be used to define the _data_handler property. It is |
|
245 | + * called when messages are setup. |
|
246 | + * |
|
247 | + * @abstract |
|
248 | + * @access protected |
|
249 | + * @return void |
|
250 | + */ |
|
251 | + abstract protected function _set_data_handler(); |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * This method should return a EE_Base_Class object (or array of EE_Base_Class objects) for the given context and |
|
256 | + * ID (which should be the primary key id for the base class). Client code doesn't have to know what a message |
|
257 | + * type's data handler is. |
|
258 | + * |
|
259 | + * @since 4.5.0 |
|
260 | + * @param string $context This should be a string matching a valid context for the message type. |
|
261 | + * @param EE_Registration $registration Need a registration to ensure that the data is valid (prevents people |
|
262 | + * guessing a url). |
|
263 | + * @param int $id Optional. Integer corresponding to the value for the primary key of a |
|
264 | + * EE_Base_Class_Object |
|
265 | + * @return mixed ( EE_Base_Class||EE_Base_Class[] ) |
|
266 | + */ |
|
267 | + abstract protected function _get_data_for_context($context, EE_Registration $registration, $id); |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * _set_contexts |
|
272 | + * This sets up the contexts associated with the message_type |
|
273 | + * |
|
274 | + * @abstract |
|
275 | + * @access protected |
|
276 | + * @return void |
|
277 | + */ |
|
278 | + abstract protected function _set_contexts(); |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * This is used to get the "id" value fo the msg_trigger_url generated by get_url_trigger(). |
|
283 | + * In most cases, child classes don't need anything, (hence the default of 0), however if there is a specific |
|
284 | + * EE_Base_Class that is required in generating a message for a message type recipient then the message |
|
285 | + * type should override this method and use the given params to generate the correct ID. |
|
286 | + * |
|
287 | + * @param string $context The message type context. |
|
288 | + * @param EE_Registration $registration Registration object |
|
289 | + * @deprecated 4.9.0 |
|
290 | + * @return int |
|
291 | + */ |
|
292 | + protected function _get_id_for_msg_url($context, EE_Registration $registration) |
|
293 | + { |
|
294 | + return 0; |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * This sets up any action/filter hooks this message type puts in place for a specific messenger. Note that by |
|
300 | + * default this does nothing. Child classes will need to override if they want to add specific hooks for a |
|
301 | + * messenger. |
|
302 | + * |
|
303 | + * @since 1.0.0 |
|
304 | + * @return void |
|
305 | + */ |
|
306 | + protected function _do_messenger_hooks() |
|
307 | + { |
|
308 | + return; |
|
309 | + } |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * This is a public wrapper for the protected _do_messenger_hooks() method. |
|
314 | + * For backward compat reasons, this was done rather than making the protected method public. |
|
315 | + * |
|
316 | + * @param EE_messenger $messenger This is used to set the $_active_messenger property, so message types are able |
|
317 | + * to know what messenger is being used to send the message at the time of |
|
318 | + * sending. |
|
319 | + * @since 4.9.0 |
|
320 | + */ |
|
321 | + public function do_messenger_hooks($messenger = null) |
|
322 | + { |
|
323 | + $this->_active_messenger = $messenger; |
|
324 | + $this->_do_messenger_hooks(); |
|
325 | + } |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * This method returns whether this message type should always generate a new copy |
|
330 | + * when requested, or if links can be to the already generated copy. |
|
331 | + * Note: this does NOT affect viewing/resending already generated messages in the EE_Message list table. |
|
332 | + * Child classes should override this if different from the default of false. |
|
333 | + * |
|
334 | + * @return bool false means can link to generated EE_Message. true must regenerate. |
|
335 | + */ |
|
336 | + public function always_generate() |
|
337 | + { |
|
338 | + return false; |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * Returns the priority for the message type. |
|
344 | + * Priorities are defined as constants on EEM_Message. Currently there are three priorities: |
|
345 | + * - EEM_Message::priority_high |
|
346 | + * - EEM_Message::priority_medium |
|
347 | + * - EEM_Message::priority_low |
|
348 | + * Priority is used to determine the weight the message type is given when queuing for generation and/or sending. |
|
349 | + * |
|
350 | + * @see EEM_Message for more phpdocs on priority. |
|
351 | + * The default priority for all message_types is EEM_Message::priority_low. Message Types wanting to give |
|
352 | + * a higher priority must override this method. Also note, messengers are able to override priorities |
|
353 | + * queuing instructions if their "send_now" flag is set to true. An example of this is the HTML messenger |
|
354 | + * which displays things in the browser. |
|
355 | + * @since 4.9.0 |
|
356 | + * @return int |
|
357 | + */ |
|
358 | + public function get_priority() |
|
359 | + { |
|
360 | + return EEM_Message::priority_low; |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * This runs the _set_data_handler() method for message types and then returns what got set. |
|
366 | + * |
|
367 | + * @param mixed $data This sets the data property for the message type with the incoming data used for generating. |
|
368 | + * @return string (the reference for the data handler) (will be an empty string if could not be determined). |
|
369 | + */ |
|
370 | + public function get_data_handler($data) |
|
371 | + { |
|
372 | + $this->_data = $data; |
|
373 | + $this->_set_data_handler(); |
|
374 | + return apply_filters('FHEE__EE_message_type__get_data_handler', $this->_data_handler, $this); |
|
375 | + } |
|
376 | + |
|
377 | + |
|
378 | + /** |
|
379 | + * This is called externally to reset the value of the $_data property for the message type. |
|
380 | + * Please note the value of the _data is highly volatile. It was added as an interim measure ensuring |
|
381 | + * EE_Message_To_Generate objects have any changes to the _data property when `_set_data_handler` method is called |
|
382 | + * (and for back compat reasons). This particular method is used in |
|
383 | + * EE_Messages_Generator::_reset_current_properties to ensure that the internal _data on the message type is |
|
384 | + * cleaned before subsequent EE_Message generation in the same request. |
|
385 | + * |
|
386 | + * @todo This needs refactored along with the whole _set_data_handler() method in EE_message_types. Need to |
|
387 | + * ensure that there is no manipulation of the _data property during run time so there's a clear |
|
388 | + * expectation of what it is. Likely we need to ensure that _data is not persisted IN the message type |
|
389 | + * at all. |
|
390 | + * @internal Plugin authors, do not implement this method, it is subject to change. |
|
391 | + * @since 4.9 |
|
392 | + */ |
|
393 | + public function reset_data() |
|
394 | + { |
|
395 | + $this->_data = null; |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + /** |
|
400 | + * This does some validation of incoming params gets the url trigger from the defined method in the specific child |
|
401 | + * class and then filters the results. |
|
402 | + * |
|
403 | + * @param string $context The message type context |
|
404 | + * @param string $sending_messenger The sending messenger |
|
405 | + * @param EE_Registration $registration Registration object |
|
406 | + * @throws EE_Error |
|
407 | + * @deprecated 4.9.0 Likely 4.9.10 or 4.10.0 will remove this method completely |
|
408 | + * @return string generated url |
|
409 | + */ |
|
410 | + public function get_url_trigger($context, $sending_messenger, EE_Registration $registration) |
|
411 | + { |
|
412 | + //validate context |
|
413 | + //valid context? |
|
414 | + if (! isset($this->_contexts[$context])) { |
|
415 | + throw new EE_Error( |
|
416 | + sprintf( |
|
417 | + __('The context %s is not a valid context for %s.', 'event_espresso'), |
|
418 | + $context, |
|
419 | + get_class($this) |
|
420 | + ) |
|
421 | + ); |
|
422 | + } |
|
423 | + //valid sending_messenger? |
|
424 | + $not_valid_msgr = false; |
|
425 | + foreach ($this->_with_messengers as $generating => $sendings) { |
|
426 | + if (empty($sendings) || array_search($sending_messenger, $sendings) === false) { |
|
427 | + $not_valid_msgr = true; |
|
428 | + } |
|
429 | + } |
|
430 | + if ($not_valid_msgr) { |
|
431 | + throw new EE_Error( |
|
432 | + sprintf( |
|
433 | + __( |
|
434 | + 'The given sending messenger string (%s) does not match a valid sending messenger with the %s. If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.', |
|
435 | + 'event_espresso' |
|
436 | + ), |
|
437 | + $sending_messenger, |
|
438 | + get_class($this) |
|
439 | + ) |
|
440 | + ); |
|
441 | + } |
|
442 | + return EEH_MSG_Template::generate_url_trigger( |
|
443 | + $sending_messenger, |
|
444 | + $this->_active_messenger->name, |
|
445 | + $context, |
|
446 | + $this->name, |
|
447 | + $registration, |
|
448 | + $this->_GRP_ID, |
|
449 | + $this->_get_id_for_msg_url($context, $registration) |
|
450 | + ); |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + /** |
|
455 | + * Wrapper for _get_data_for_context() that handles some validation before calling the main class and also allows |
|
456 | + * for filtering. This is (currently) called by the EED_Messages module. |
|
457 | + * |
|
458 | + * @since 4.5.0 |
|
459 | + * @throws EE_Error |
|
460 | + * @param string $context This should be a string matching a valid context for the message type. |
|
461 | + * @param EE_Registration $registration Need a registration to ensure that the data is valid (prevents people |
|
462 | + * guessing a url). |
|
463 | + * @param int $id Optional. Integer corresponding to the value for the primary key of a |
|
464 | + * EE_Base_Class_Object |
|
465 | + * @return mixed (EE_Base_Class||EE_Base_Class[]) |
|
466 | + */ |
|
467 | + public function get_data_for_context($context, EE_Registration $registration, $id = 0) |
|
468 | + { |
|
469 | + //valid context? |
|
470 | + if (! isset($this->_contexts[$context])) { |
|
471 | + throw new EE_Error( |
|
472 | + sprintf( |
|
473 | + __('The context %s is not a valid context for %s.', 'event_espresso'), |
|
474 | + $context, |
|
475 | + get_class($this) |
|
476 | + ) |
|
477 | + ); |
|
478 | + } |
|
479 | + //get data and apply global and class specific filters on it. |
|
480 | + $data = apply_filters( |
|
481 | + 'FHEE__EE_message_type__get_data_for_context__data', |
|
482 | + $this->_get_data_for_context($context, $registration, $id), |
|
483 | + $this |
|
484 | + ); |
|
485 | + $data = apply_filters('FHEE__' . get_class($this) . '__get_data_for_context__data', $data, $this); |
|
486 | + //if empty then something went wrong! |
|
487 | + if (empty($data)) { |
|
488 | + throw new EE_Error( |
|
489 | + sprintf( |
|
490 | + __( |
|
491 | + 'There is no data retrieved, it is possible that the id given (%d) does not match any value in the database for the corresponding EE_Base_Class used by the data handler for the %s message type.', |
|
492 | + 'event_espresso' |
|
493 | + ), |
|
494 | + $id, |
|
495 | + $this->name |
|
496 | + ) |
|
497 | + ); |
|
498 | + } |
|
499 | + return $data; |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + /** |
|
504 | + * This returns the contents of the _data property. |
|
505 | + * Please note the value of the _data is highly volatile. It was added as an interim measure ensuring |
|
506 | + * EE_Message_To_Generate objects have any changes to the _data property when `_set_data_handler` method is called. |
|
507 | + * |
|
508 | + * @todo This needs refactored along with the whole _set_data_handler() method in EE_message_types. Need to |
|
509 | + * ensure that there is no manipulation of the _data property during run time so there's a clear |
|
510 | + * expectation of what it is. |
|
511 | + * @internal Plugin authors, do not implement this method, it is subject to change. |
|
512 | + * @return mixed |
|
513 | + */ |
|
514 | + public function get_data() |
|
515 | + { |
|
516 | + return $this->_data; |
|
517 | + } |
|
518 | + |
|
519 | + |
|
520 | + /** |
|
521 | + * used to set the $_with_messengers property. (this is a default, child classes SHOULD override) |
|
522 | + * |
|
523 | + * @see property definition for description of setup. |
|
524 | + * @since 4.5.0 |
|
525 | + * @abstract |
|
526 | + * @return void |
|
527 | + */ |
|
528 | + protected function _set_with_messengers() |
|
529 | + { |
|
530 | + $this->_with_messengers = array( |
|
531 | + 'email' => array('html'), |
|
532 | + ); |
|
533 | + } |
|
534 | + |
|
535 | + |
|
536 | + /** |
|
537 | + * Return the value of the _with_messengers property |
|
538 | + * |
|
539 | + * @since 4.5.0 |
|
540 | + * @return array |
|
541 | + */ |
|
542 | + public function with_messengers() |
|
543 | + { |
|
544 | + return apply_filters( |
|
545 | + 'FHEE__EE_message_type__get_with_messengers__with_messengers__' . get_class($this), |
|
546 | + $this->_with_messengers |
|
547 | + ); |
|
548 | + } |
|
549 | + |
|
550 | + |
|
551 | + /** |
|
552 | + * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class |
|
553 | + * callback function if that page is registered via the `_admin_registered_page` property set by the child class. |
|
554 | + * * |
|
555 | + * |
|
556 | + * @param string $page the slug of the EE admin page |
|
557 | + * @param array $messengers an array of active messenger objects |
|
558 | + * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages) |
|
559 | + * @param array $extra This is just an extra argument that can be used to pass additional data for setting up |
|
560 | + * page content. |
|
561 | + * @access public |
|
562 | + * @return string |
|
563 | + */ |
|
564 | + public function get_message_type_admin_page_content( |
|
565 | + $page, |
|
566 | + $action = null, |
|
567 | + $extra = array(), |
|
568 | + $messengers = array() |
|
569 | + ) { |
|
570 | + //we can also further refine the context by action (if present). |
|
571 | + return $this->_get_admin_page_content($page, $action, $extra, $messengers); |
|
572 | + } |
|
573 | + |
|
574 | + |
|
575 | + /** |
|
576 | + * @return array |
|
577 | + */ |
|
578 | + public function get_contexts() |
|
579 | + { |
|
580 | + return $this->_contexts; |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + /** |
|
585 | + * This just returns the context label for a given context (as set in $_context_label property) |
|
586 | + * |
|
587 | + * @access public |
|
588 | + * @return array |
|
589 | + */ |
|
590 | + public function get_context_label() |
|
591 | + { |
|
592 | + return $this->_context_label; |
|
593 | + } |
|
594 | + |
|
595 | + |
|
596 | + /** |
|
597 | + * This just returns the (filtered) _master_templates property. |
|
598 | + * |
|
599 | + * @see property definition for documentation. |
|
600 | + * @return array |
|
601 | + */ |
|
602 | + public function get_master_templates() |
|
603 | + { |
|
604 | + //first class specific filter then filter that by the global filter. |
|
605 | + $master_templates = apply_filters( |
|
606 | + 'FHEE__' . get_class($this) . '__get_master_templates', |
|
607 | + $this->_master_templates |
|
608 | + ); |
|
609 | + return apply_filters('FHEE__EE_message_type__get_master_templates', $master_templates, $this); |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * Accepts an incoming data handler which contains data for processing, and returns an array of |
|
615 | + * EE_Messages_Addressee objects. |
|
616 | + * |
|
617 | + * @param EE_Messages_incoming_data $data |
|
618 | + * @param string $context Limit addressees to specific context. |
|
619 | + * @return array An array indexed by context where each context is an array of EE_Messages_Addressee objects for |
|
620 | + * that context |
|
621 | + * @throws EE_Error |
|
622 | + */ |
|
623 | + public function get_addressees(EE_Messages_incoming_data $data, $context = '') |
|
624 | + { |
|
625 | + //override _data |
|
626 | + $this->_data = $data; |
|
627 | + $addressees = array(); |
|
628 | + $original_contexts = $this->_contexts; |
|
629 | + //if incoming context then limit to that context |
|
630 | + if (! empty($context)) { |
|
631 | + $cntxt = ! empty($this->_contexts[$context]) ? $this->_contexts[$context] : ''; |
|
632 | + if (! empty($cntxt)) { |
|
633 | + $this->_contexts = array(); |
|
634 | + $this->_contexts[$context] = $cntxt; |
|
635 | + } |
|
636 | + } |
|
637 | + $this->_set_default_addressee_data(); |
|
638 | + if ($this->_process_data()) { |
|
639 | + $addressees = $this->_addressees; |
|
640 | + } |
|
641 | + |
|
642 | + //reset contexts and addressees |
|
643 | + $this->_contexts = $original_contexts; |
|
644 | + $this->_addressees = array(); |
|
645 | + return $addressees; |
|
646 | + } |
|
647 | + |
|
648 | + |
|
649 | + /** |
|
650 | + * processes the data object so we get |
|
651 | + * |
|
652 | + * @throws EE_Error |
|
653 | + * @return bool true means data was processed successfully, false means not. |
|
654 | + */ |
|
655 | + protected function _process_data() |
|
656 | + { |
|
657 | + //at a minimum, we NEED EE_Attendee objects. |
|
658 | + if (empty($this->_data->attendees)) { |
|
659 | + return false; //there's no data to process! |
|
660 | + } |
|
661 | + // process addressees for each context. Child classes will have to have methods for |
|
662 | + // each context defined to handle the processing of the data object within them |
|
663 | + foreach ($this->_contexts as $context => $details) { |
|
664 | + $xpctd_method = '_' . $context . '_addressees'; |
|
665 | + if (! method_exists($this, $xpctd_method)) { |
|
666 | + throw new EE_Error( |
|
667 | + sprintf( |
|
668 | + __( |
|
669 | + 'The data for %1$s message type cannot be prepared because there is no set method for doing so. The expected method name is "%2$s" please doublecheck the %1$s message type class and make sure that method is present', |
|
670 | + 'event_espresso' |
|
671 | + ), |
|
672 | + $this->label['singular'], |
|
673 | + $xpctd_method |
|
674 | + ) |
|
675 | + ); |
|
676 | + } |
|
677 | + $this->_addressees[$context] = call_user_func(array($this, $xpctd_method)); |
|
678 | + } |
|
679 | + return true; //data was processed successfully. |
|
680 | + } |
|
681 | + |
|
682 | + |
|
683 | + /** |
|
684 | + * sets the default_addressee_data property, |
|
685 | + * |
|
686 | + * @access private |
|
687 | + * @return void |
|
688 | + */ |
|
689 | + private function _set_default_addressee_data() |
|
690 | + { |
|
691 | + $this->_default_addressee_data = array( |
|
692 | + 'billing' => $this->_data->billing, |
|
693 | + 'taxes' => $this->_data->taxes, |
|
694 | + 'tax_line_items' => $this->_data->tax_line_items, |
|
695 | + 'additional_line_items' => $this->_data->additional_line_items, |
|
696 | + 'grand_total_line_item' => $this->_data->grand_total_line_item, |
|
697 | + 'txn' => $this->_data->txn, |
|
698 | + 'payments' => $this->_data->payments, |
|
699 | + 'payment' => isset($this->_data->payment) && $this->_data->payment instanceof EE_Payment |
|
700 | + ? $this->_data->payment |
|
701 | + : null, |
|
702 | + 'reg_objs' => $this->_data->reg_objs, |
|
703 | + 'registrations' => $this->_data->registrations, |
|
704 | + 'datetimes' => $this->_data->datetimes, |
|
705 | + 'tickets' => $this->_data->tickets, |
|
706 | + 'line_items_with_children' => $this->_data->line_items_with_children, |
|
707 | + 'questions' => $this->_data->questions, |
|
708 | + 'answers' => $this->_data->answers, |
|
709 | + 'txn_status' => $this->_data->txn_status, |
|
710 | + 'total_ticket_count' => $this->_data->total_ticket_count, |
|
711 | + ); |
|
712 | + if (is_array($this->_data->primary_attendee_data)) { |
|
713 | + $this->_default_addressee_data = array_merge( |
|
714 | + $this->_default_addressee_data, |
|
715 | + $this->_data->primary_attendee_data |
|
716 | + ); |
|
717 | + $this->_default_addressee_data['primary_att_obj'] = $this->_data->primary_attendee_data['att_obj']; |
|
718 | + $this->_default_addressee_data['primary_reg_obj'] = $this->_data->primary_attendee_data['reg_obj']; |
|
719 | + } |
|
720 | + } |
|
721 | + |
|
722 | + |
|
723 | + |
|
724 | + /******************** |
|
725 | 725 | * setup default shared addressee object/contexts |
726 | 726 | * These can be utilized simply by defining the context in the child message type. |
727 | 727 | * They can also be overridden if a specific message type needs to do something different for that context. |
728 | 728 | ****************/ |
729 | - /** |
|
730 | - * see abstract declaration in parent class for details, children message types can |
|
731 | - * override these valid shortcodes if desired (we include all for all contexts by default). |
|
732 | - */ |
|
733 | - protected function _set_valid_shortcodes() |
|
734 | - { |
|
735 | - $all_shortcodes = array( |
|
736 | - 'attendee_list', |
|
737 | - 'attendee', |
|
738 | - 'datetime_list', |
|
739 | - 'datetime', |
|
740 | - 'event_list', |
|
741 | - 'event_meta', |
|
742 | - 'event', |
|
743 | - 'organization', |
|
744 | - 'recipient_details', |
|
745 | - 'recipient_list', |
|
746 | - 'ticket_list', |
|
747 | - 'ticket', |
|
748 | - 'transaction', |
|
749 | - 'venue', |
|
750 | - 'primary_registration_details', |
|
751 | - 'primary_registration_list', |
|
752 | - 'event_author', |
|
753 | - 'email', |
|
754 | - 'messenger', |
|
755 | - ); |
|
756 | - $contexts = $this->get_contexts(); |
|
757 | - foreach ($contexts as $context => $details) { |
|
758 | - $this->_valid_shortcodes[$context] = $all_shortcodes; |
|
759 | - //make sure non admin context does not include the event_author shortcodes |
|
760 | - if ($context != 'admin') { |
|
761 | - if (($key = array_search('event_author', $this->_valid_shortcodes[$context])) !== false) { |
|
762 | - unset($this->_valid_shortcodes[$context][$key]); |
|
763 | - } |
|
764 | - } |
|
765 | - } |
|
766 | - // make sure admin context does not include the recipient_details shortcodes |
|
767 | - // IF we have admin context hooked in message types might not have that context. |
|
768 | - if (! empty($this->_valid_shortcodes['admin'])) { |
|
769 | - if (($key = array_search('recipient_details', $this->_valid_shortcodes['admin'])) !== false) { |
|
770 | - unset($this->_valid_shortcodes['admin'][$key]); |
|
771 | - } |
|
772 | - //make sure admin context does not include the recipient_details shortcodes |
|
773 | - if (($key = array_search('recipient_list', $this->_valid_shortcodes['admin'])) !== false) { |
|
774 | - unset($this->_valid_shortcodes['admin'][$key]); |
|
775 | - } |
|
776 | - } |
|
777 | - } |
|
778 | - |
|
779 | - |
|
780 | - /** |
|
781 | - * Used by Validators to modify the valid shortcodes. |
|
782 | - * |
|
783 | - * @param array $new_config array of valid shortcodes (by context) |
|
784 | - * @return void sets valid_shortcodes property |
|
785 | - */ |
|
786 | - public function reset_valid_shortcodes_config($new_config) |
|
787 | - { |
|
788 | - foreach ($new_config as $context => $shortcodes) { |
|
789 | - $this->_valid_shortcodes[$context] = $shortcodes; |
|
790 | - } |
|
791 | - } |
|
792 | - |
|
793 | - |
|
794 | - /** |
|
795 | - * returns an array of addressee objects for event_admins |
|
796 | - * |
|
797 | - * @access protected |
|
798 | - * @return array array of EE_Messages_Addressee objects |
|
799 | - * @throws EE_Error |
|
800 | - * @throws InvalidArgumentException |
|
801 | - * @throws InvalidDataTypeException |
|
802 | - * @throws InvalidInterfaceException |
|
803 | - */ |
|
804 | - protected function _admin_addressees() |
|
805 | - { |
|
806 | - $admin_events = array(); |
|
807 | - $addressees = array(); |
|
808 | - // first we need to get the event admin user id for all the events |
|
809 | - // and setup an addressee object for each unique admin user. |
|
810 | - foreach ($this->_data->events as $line_ref => $event) { |
|
811 | - $admin_id = $this->_get_event_admin_id($event['ID']); |
|
812 | - //make sure we are just including the events that belong to this admin! |
|
813 | - $admin_events[$admin_id][$line_ref] = $event; |
|
814 | - } |
|
815 | - //k now we can loop through the event_admins and setup the addressee data. |
|
816 | - foreach ($admin_events as $admin_id => $event_details) { |
|
817 | - $aee = array( |
|
818 | - 'user_id' => $admin_id, |
|
819 | - 'events' => $event_details, |
|
820 | - 'attendees' => $this->_data->attendees, |
|
821 | - 'recipient_id' => $admin_id, |
|
822 | - 'recipient_type' => 'WP_User', |
|
823 | - ); |
|
824 | - $aee = array_merge($this->_default_addressee_data, $aee); |
|
825 | - $addressees[] = new EE_Messages_Addressee($aee); |
|
826 | - } |
|
827 | - return $addressees; |
|
828 | - } |
|
829 | - |
|
830 | - |
|
831 | - /** |
|
832 | - * Takes care of setting up the addressee object(s) for the primary attendee. |
|
833 | - * |
|
834 | - * @access protected |
|
835 | - * @return array of EE_Addressee objects |
|
836 | - * @throws EE_Error |
|
837 | - */ |
|
838 | - protected function _primary_attendee_addressees() |
|
839 | - { |
|
840 | - $aee = $this->_default_addressee_data; |
|
841 | - $aee['events'] = $this->_data->events; |
|
842 | - $aee['attendees'] = $this->_data->attendees; |
|
843 | - $aee['recipient_id'] = $aee['primary_att_obj'] instanceof EE_Attendee ? $aee['primary_att_obj']->ID() : 0; |
|
844 | - $aee['recipient_type'] = 'Attendee'; |
|
845 | - //great now we can instantiate the $addressee object and return (as an array); |
|
846 | - $add[] = new EE_Messages_Addressee($aee); |
|
847 | - return $add; |
|
848 | - } |
|
849 | - |
|
850 | - |
|
851 | - /** |
|
852 | - * Takes care of setting up the addressee object(s) for the registered attendees |
|
853 | - * |
|
854 | - * @access protected |
|
855 | - * @return array of EE_Addressee objects |
|
856 | - */ |
|
857 | - protected function _attendee_addressees() |
|
858 | - { |
|
859 | - $add = array(); |
|
860 | - //we just have to loop through the attendees. We'll also set the attached events for each attendee. |
|
861 | - //use to verify unique attendee emails... we don't want to sent multiple copies to the same attendee do we? |
|
862 | - $already_processed = array(); |
|
863 | - foreach ($this->_data->attendees as $att_id => $details) { |
|
864 | - //set the attendee array to blank on each loop; |
|
865 | - $aee = array(); |
|
866 | - if (isset($this->_data->reg_obj) |
|
867 | - && ($this->_data->reg_obj->attendee_ID() != $att_id) |
|
868 | - && $this->_single_message |
|
869 | - ) { |
|
870 | - continue; |
|
871 | - } |
|
872 | - // is $this->_regs_for_sending present? |
|
873 | - // If so, let's make sure we ONLY generate addressee for registrations in that array. |
|
874 | - if (! empty($this->_regs_for_sending) && is_array($this->_regs_for_sending)) { |
|
875 | - $regs_allowed = array_intersect_key(array_flip($this->_regs_for_sending), $details['reg_objs']); |
|
876 | - if (empty($regs_allowed)) { |
|
877 | - continue; |
|
878 | - } |
|
879 | - } |
|
880 | - if (apply_filters( |
|
881 | - 'FHEE__EE_message_type___attendee_addressees__prevent_duplicate_email_sends', |
|
882 | - true, |
|
883 | - $this->_data, |
|
884 | - $this |
|
885 | - ) |
|
886 | - && in_array($att_id, $already_processed, true) |
|
887 | - ) { |
|
888 | - continue; |
|
889 | - } |
|
890 | - $already_processed[] = $att_id; |
|
891 | - foreach ($details as $item => $value) { |
|
892 | - $aee[$item] = $value; |
|
893 | - if ($item === 'line_ref') { |
|
894 | - foreach ($value as $event_id) { |
|
895 | - $aee['events'][$event_id] = $this->_data->events[$event_id]; |
|
896 | - } |
|
897 | - } |
|
898 | - if ($item === 'attendee_email') { |
|
899 | - $aee['attendee_email'] = $value; |
|
900 | - } |
|
901 | - /*if ( $item == 'registration_id' ) { |
|
729 | + /** |
|
730 | + * see abstract declaration in parent class for details, children message types can |
|
731 | + * override these valid shortcodes if desired (we include all for all contexts by default). |
|
732 | + */ |
|
733 | + protected function _set_valid_shortcodes() |
|
734 | + { |
|
735 | + $all_shortcodes = array( |
|
736 | + 'attendee_list', |
|
737 | + 'attendee', |
|
738 | + 'datetime_list', |
|
739 | + 'datetime', |
|
740 | + 'event_list', |
|
741 | + 'event_meta', |
|
742 | + 'event', |
|
743 | + 'organization', |
|
744 | + 'recipient_details', |
|
745 | + 'recipient_list', |
|
746 | + 'ticket_list', |
|
747 | + 'ticket', |
|
748 | + 'transaction', |
|
749 | + 'venue', |
|
750 | + 'primary_registration_details', |
|
751 | + 'primary_registration_list', |
|
752 | + 'event_author', |
|
753 | + 'email', |
|
754 | + 'messenger', |
|
755 | + ); |
|
756 | + $contexts = $this->get_contexts(); |
|
757 | + foreach ($contexts as $context => $details) { |
|
758 | + $this->_valid_shortcodes[$context] = $all_shortcodes; |
|
759 | + //make sure non admin context does not include the event_author shortcodes |
|
760 | + if ($context != 'admin') { |
|
761 | + if (($key = array_search('event_author', $this->_valid_shortcodes[$context])) !== false) { |
|
762 | + unset($this->_valid_shortcodes[$context][$key]); |
|
763 | + } |
|
764 | + } |
|
765 | + } |
|
766 | + // make sure admin context does not include the recipient_details shortcodes |
|
767 | + // IF we have admin context hooked in message types might not have that context. |
|
768 | + if (! empty($this->_valid_shortcodes['admin'])) { |
|
769 | + if (($key = array_search('recipient_details', $this->_valid_shortcodes['admin'])) !== false) { |
|
770 | + unset($this->_valid_shortcodes['admin'][$key]); |
|
771 | + } |
|
772 | + //make sure admin context does not include the recipient_details shortcodes |
|
773 | + if (($key = array_search('recipient_list', $this->_valid_shortcodes['admin'])) !== false) { |
|
774 | + unset($this->_valid_shortcodes['admin'][$key]); |
|
775 | + } |
|
776 | + } |
|
777 | + } |
|
778 | + |
|
779 | + |
|
780 | + /** |
|
781 | + * Used by Validators to modify the valid shortcodes. |
|
782 | + * |
|
783 | + * @param array $new_config array of valid shortcodes (by context) |
|
784 | + * @return void sets valid_shortcodes property |
|
785 | + */ |
|
786 | + public function reset_valid_shortcodes_config($new_config) |
|
787 | + { |
|
788 | + foreach ($new_config as $context => $shortcodes) { |
|
789 | + $this->_valid_shortcodes[$context] = $shortcodes; |
|
790 | + } |
|
791 | + } |
|
792 | + |
|
793 | + |
|
794 | + /** |
|
795 | + * returns an array of addressee objects for event_admins |
|
796 | + * |
|
797 | + * @access protected |
|
798 | + * @return array array of EE_Messages_Addressee objects |
|
799 | + * @throws EE_Error |
|
800 | + * @throws InvalidArgumentException |
|
801 | + * @throws InvalidDataTypeException |
|
802 | + * @throws InvalidInterfaceException |
|
803 | + */ |
|
804 | + protected function _admin_addressees() |
|
805 | + { |
|
806 | + $admin_events = array(); |
|
807 | + $addressees = array(); |
|
808 | + // first we need to get the event admin user id for all the events |
|
809 | + // and setup an addressee object for each unique admin user. |
|
810 | + foreach ($this->_data->events as $line_ref => $event) { |
|
811 | + $admin_id = $this->_get_event_admin_id($event['ID']); |
|
812 | + //make sure we are just including the events that belong to this admin! |
|
813 | + $admin_events[$admin_id][$line_ref] = $event; |
|
814 | + } |
|
815 | + //k now we can loop through the event_admins and setup the addressee data. |
|
816 | + foreach ($admin_events as $admin_id => $event_details) { |
|
817 | + $aee = array( |
|
818 | + 'user_id' => $admin_id, |
|
819 | + 'events' => $event_details, |
|
820 | + 'attendees' => $this->_data->attendees, |
|
821 | + 'recipient_id' => $admin_id, |
|
822 | + 'recipient_type' => 'WP_User', |
|
823 | + ); |
|
824 | + $aee = array_merge($this->_default_addressee_data, $aee); |
|
825 | + $addressees[] = new EE_Messages_Addressee($aee); |
|
826 | + } |
|
827 | + return $addressees; |
|
828 | + } |
|
829 | + |
|
830 | + |
|
831 | + /** |
|
832 | + * Takes care of setting up the addressee object(s) for the primary attendee. |
|
833 | + * |
|
834 | + * @access protected |
|
835 | + * @return array of EE_Addressee objects |
|
836 | + * @throws EE_Error |
|
837 | + */ |
|
838 | + protected function _primary_attendee_addressees() |
|
839 | + { |
|
840 | + $aee = $this->_default_addressee_data; |
|
841 | + $aee['events'] = $this->_data->events; |
|
842 | + $aee['attendees'] = $this->_data->attendees; |
|
843 | + $aee['recipient_id'] = $aee['primary_att_obj'] instanceof EE_Attendee ? $aee['primary_att_obj']->ID() : 0; |
|
844 | + $aee['recipient_type'] = 'Attendee'; |
|
845 | + //great now we can instantiate the $addressee object and return (as an array); |
|
846 | + $add[] = new EE_Messages_Addressee($aee); |
|
847 | + return $add; |
|
848 | + } |
|
849 | + |
|
850 | + |
|
851 | + /** |
|
852 | + * Takes care of setting up the addressee object(s) for the registered attendees |
|
853 | + * |
|
854 | + * @access protected |
|
855 | + * @return array of EE_Addressee objects |
|
856 | + */ |
|
857 | + protected function _attendee_addressees() |
|
858 | + { |
|
859 | + $add = array(); |
|
860 | + //we just have to loop through the attendees. We'll also set the attached events for each attendee. |
|
861 | + //use to verify unique attendee emails... we don't want to sent multiple copies to the same attendee do we? |
|
862 | + $already_processed = array(); |
|
863 | + foreach ($this->_data->attendees as $att_id => $details) { |
|
864 | + //set the attendee array to blank on each loop; |
|
865 | + $aee = array(); |
|
866 | + if (isset($this->_data->reg_obj) |
|
867 | + && ($this->_data->reg_obj->attendee_ID() != $att_id) |
|
868 | + && $this->_single_message |
|
869 | + ) { |
|
870 | + continue; |
|
871 | + } |
|
872 | + // is $this->_regs_for_sending present? |
|
873 | + // If so, let's make sure we ONLY generate addressee for registrations in that array. |
|
874 | + if (! empty($this->_regs_for_sending) && is_array($this->_regs_for_sending)) { |
|
875 | + $regs_allowed = array_intersect_key(array_flip($this->_regs_for_sending), $details['reg_objs']); |
|
876 | + if (empty($regs_allowed)) { |
|
877 | + continue; |
|
878 | + } |
|
879 | + } |
|
880 | + if (apply_filters( |
|
881 | + 'FHEE__EE_message_type___attendee_addressees__prevent_duplicate_email_sends', |
|
882 | + true, |
|
883 | + $this->_data, |
|
884 | + $this |
|
885 | + ) |
|
886 | + && in_array($att_id, $already_processed, true) |
|
887 | + ) { |
|
888 | + continue; |
|
889 | + } |
|
890 | + $already_processed[] = $att_id; |
|
891 | + foreach ($details as $item => $value) { |
|
892 | + $aee[$item] = $value; |
|
893 | + if ($item === 'line_ref') { |
|
894 | + foreach ($value as $event_id) { |
|
895 | + $aee['events'][$event_id] = $this->_data->events[$event_id]; |
|
896 | + } |
|
897 | + } |
|
898 | + if ($item === 'attendee_email') { |
|
899 | + $aee['attendee_email'] = $value; |
|
900 | + } |
|
901 | + /*if ( $item == 'registration_id' ) { |
|
902 | 902 | $aee['attendee_registration_id'] = $value; |
903 | 903 | }/**/ |
904 | - } |
|
905 | - // note the FIRST reg object in this array is the one |
|
906 | - // we'll use for this attendee as the primary registration for this attendee. |
|
907 | - $aee['reg_obj'] = reset($this->_data->attendees[$att_id]['reg_objs']); |
|
908 | - $aee['attendees'] = $this->_data->attendees; |
|
909 | - $aee['recipient_id'] = $att_id; |
|
910 | - $aee['recipient_type'] = 'Attendee'; |
|
911 | - //merge in the primary attendee data |
|
912 | - $aee = array_merge($this->_default_addressee_data, $aee); |
|
913 | - $add[] = new EE_Messages_Addressee($aee); |
|
914 | - } |
|
915 | - return $add; |
|
916 | - } |
|
917 | - |
|
918 | - |
|
919 | - /** |
|
920 | - * @param $event_id |
|
921 | - * @return int |
|
922 | - * @throws EE_Error |
|
923 | - * @throws InvalidArgumentException |
|
924 | - * @throws InvalidDataTypeException |
|
925 | - * @throws InvalidInterfaceException |
|
926 | - */ |
|
927 | - protected function _get_event_admin_id($event_id) |
|
928 | - { |
|
929 | - $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
930 | - return $event instanceof EE_Event ? $event->wp_user() : 0; |
|
931 | - } |
|
904 | + } |
|
905 | + // note the FIRST reg object in this array is the one |
|
906 | + // we'll use for this attendee as the primary registration for this attendee. |
|
907 | + $aee['reg_obj'] = reset($this->_data->attendees[$att_id]['reg_objs']); |
|
908 | + $aee['attendees'] = $this->_data->attendees; |
|
909 | + $aee['recipient_id'] = $att_id; |
|
910 | + $aee['recipient_type'] = 'Attendee'; |
|
911 | + //merge in the primary attendee data |
|
912 | + $aee = array_merge($this->_default_addressee_data, $aee); |
|
913 | + $add[] = new EE_Messages_Addressee($aee); |
|
914 | + } |
|
915 | + return $add; |
|
916 | + } |
|
917 | + |
|
918 | + |
|
919 | + /** |
|
920 | + * @param $event_id |
|
921 | + * @return int |
|
922 | + * @throws EE_Error |
|
923 | + * @throws InvalidArgumentException |
|
924 | + * @throws InvalidDataTypeException |
|
925 | + * @throws InvalidInterfaceException |
|
926 | + */ |
|
927 | + protected function _get_event_admin_id($event_id) |
|
928 | + { |
|
929 | + $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
930 | + return $event instanceof EE_Event ? $event->wp_user() : 0; |
|
931 | + } |
|
932 | 932 | } |
933 | 933 | //end EE_message_type class |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | { |
412 | 412 | //validate context |
413 | 413 | //valid context? |
414 | - if (! isset($this->_contexts[$context])) { |
|
414 | + if ( ! isset($this->_contexts[$context])) { |
|
415 | 415 | throw new EE_Error( |
416 | 416 | sprintf( |
417 | 417 | __('The context %s is not a valid context for %s.', 'event_espresso'), |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | public function get_data_for_context($context, EE_Registration $registration, $id = 0) |
468 | 468 | { |
469 | 469 | //valid context? |
470 | - if (! isset($this->_contexts[$context])) { |
|
470 | + if ( ! isset($this->_contexts[$context])) { |
|
471 | 471 | throw new EE_Error( |
472 | 472 | sprintf( |
473 | 473 | __('The context %s is not a valid context for %s.', 'event_espresso'), |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | $this->_get_data_for_context($context, $registration, $id), |
483 | 483 | $this |
484 | 484 | ); |
485 | - $data = apply_filters('FHEE__' . get_class($this) . '__get_data_for_context__data', $data, $this); |
|
485 | + $data = apply_filters('FHEE__'.get_class($this).'__get_data_for_context__data', $data, $this); |
|
486 | 486 | //if empty then something went wrong! |
487 | 487 | if (empty($data)) { |
488 | 488 | throw new EE_Error( |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | public function with_messengers() |
543 | 543 | { |
544 | 544 | return apply_filters( |
545 | - 'FHEE__EE_message_type__get_with_messengers__with_messengers__' . get_class($this), |
|
545 | + 'FHEE__EE_message_type__get_with_messengers__with_messengers__'.get_class($this), |
|
546 | 546 | $this->_with_messengers |
547 | 547 | ); |
548 | 548 | } |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | { |
604 | 604 | //first class specific filter then filter that by the global filter. |
605 | 605 | $master_templates = apply_filters( |
606 | - 'FHEE__' . get_class($this) . '__get_master_templates', |
|
606 | + 'FHEE__'.get_class($this).'__get_master_templates', |
|
607 | 607 | $this->_master_templates |
608 | 608 | ); |
609 | 609 | return apply_filters('FHEE__EE_message_type__get_master_templates', $master_templates, $this); |
@@ -627,9 +627,9 @@ discard block |
||
627 | 627 | $addressees = array(); |
628 | 628 | $original_contexts = $this->_contexts; |
629 | 629 | //if incoming context then limit to that context |
630 | - if (! empty($context)) { |
|
630 | + if ( ! empty($context)) { |
|
631 | 631 | $cntxt = ! empty($this->_contexts[$context]) ? $this->_contexts[$context] : ''; |
632 | - if (! empty($cntxt)) { |
|
632 | + if ( ! empty($cntxt)) { |
|
633 | 633 | $this->_contexts = array(); |
634 | 634 | $this->_contexts[$context] = $cntxt; |
635 | 635 | } |
@@ -656,13 +656,13 @@ discard block |
||
656 | 656 | { |
657 | 657 | //at a minimum, we NEED EE_Attendee objects. |
658 | 658 | if (empty($this->_data->attendees)) { |
659 | - return false; //there's no data to process! |
|
659 | + return false; //there's no data to process! |
|
660 | 660 | } |
661 | 661 | // process addressees for each context. Child classes will have to have methods for |
662 | 662 | // each context defined to handle the processing of the data object within them |
663 | 663 | foreach ($this->_contexts as $context => $details) { |
664 | - $xpctd_method = '_' . $context . '_addressees'; |
|
665 | - if (! method_exists($this, $xpctd_method)) { |
|
664 | + $xpctd_method = '_'.$context.'_addressees'; |
|
665 | + if ( ! method_exists($this, $xpctd_method)) { |
|
666 | 666 | throw new EE_Error( |
667 | 667 | sprintf( |
668 | 668 | __( |
@@ -710,7 +710,7 @@ discard block |
||
710 | 710 | 'total_ticket_count' => $this->_data->total_ticket_count, |
711 | 711 | ); |
712 | 712 | if (is_array($this->_data->primary_attendee_data)) { |
713 | - $this->_default_addressee_data = array_merge( |
|
713 | + $this->_default_addressee_data = array_merge( |
|
714 | 714 | $this->_default_addressee_data, |
715 | 715 | $this->_data->primary_attendee_data |
716 | 716 | ); |
@@ -753,7 +753,7 @@ discard block |
||
753 | 753 | 'email', |
754 | 754 | 'messenger', |
755 | 755 | ); |
756 | - $contexts = $this->get_contexts(); |
|
756 | + $contexts = $this->get_contexts(); |
|
757 | 757 | foreach ($contexts as $context => $details) { |
758 | 758 | $this->_valid_shortcodes[$context] = $all_shortcodes; |
759 | 759 | //make sure non admin context does not include the event_author shortcodes |
@@ -765,7 +765,7 @@ discard block |
||
765 | 765 | } |
766 | 766 | // make sure admin context does not include the recipient_details shortcodes |
767 | 767 | // IF we have admin context hooked in message types might not have that context. |
768 | - if (! empty($this->_valid_shortcodes['admin'])) { |
|
768 | + if ( ! empty($this->_valid_shortcodes['admin'])) { |
|
769 | 769 | if (($key = array_search('recipient_details', $this->_valid_shortcodes['admin'])) !== false) { |
770 | 770 | unset($this->_valid_shortcodes['admin'][$key]); |
771 | 771 | } |
@@ -814,7 +814,7 @@ discard block |
||
814 | 814 | } |
815 | 815 | //k now we can loop through the event_admins and setup the addressee data. |
816 | 816 | foreach ($admin_events as $admin_id => $event_details) { |
817 | - $aee = array( |
|
817 | + $aee = array( |
|
818 | 818 | 'user_id' => $admin_id, |
819 | 819 | 'events' => $event_details, |
820 | 820 | 'attendees' => $this->_data->attendees, |
@@ -871,7 +871,7 @@ discard block |
||
871 | 871 | } |
872 | 872 | // is $this->_regs_for_sending present? |
873 | 873 | // If so, let's make sure we ONLY generate addressee for registrations in that array. |
874 | - if (! empty($this->_regs_for_sending) && is_array($this->_regs_for_sending)) { |
|
874 | + if ( ! empty($this->_regs_for_sending) && is_array($this->_regs_for_sending)) { |
|
875 | 875 | $regs_allowed = array_intersect_key(array_flip($this->_regs_for_sending), $details['reg_objs']); |
876 | 876 | if (empty($regs_allowed)) { |
877 | 877 | continue; |
@@ -53,7 +53,7 @@ |
||
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook |
56 | - * @param $callbacks |
|
56 | + * @param callable[] $callbacks |
|
57 | 57 | * @return array |
58 | 58 | */ |
59 | 59 | public function modify_callbacks($callbacks) |
@@ -18,207 +18,207 @@ |
||
18 | 18 | { |
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * @var EE_Event|null |
|
23 | - */ |
|
24 | - protected $_event; |
|
25 | - |
|
26 | - |
|
27 | - protected function _set_hooks_properties() |
|
28 | - { |
|
29 | - |
|
30 | - $this->_name = 'registration_form'; |
|
31 | - $this->_metaboxes = array( |
|
32 | - 0 => array( |
|
33 | - 'page_route' => array('edit', 'create_new'), |
|
34 | - 'func' => 'primary_questions', |
|
35 | - 'label' => esc_html__('Questions for Primary Registrant', 'event_espresso'), |
|
36 | - 'priority' => 'default', |
|
37 | - 'context' => 'side', |
|
38 | - ), |
|
39 | - ); |
|
40 | - |
|
41 | - //hook into the handler for saving question groups |
|
42 | - add_filter( |
|
43 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
44 | - array($this, 'modify_callbacks'), |
|
45 | - 10 |
|
46 | - ); |
|
47 | - |
|
48 | - //hook into revision restores (we're hooking into the global action because EE_Admin_Hooks classes are already |
|
49 | - //restricted by page) |
|
50 | - add_action('AHEE_EE_Admin_Page_CPT__restore_revision', array($this, 'restore_revision'), 10, 2); |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook |
|
56 | - * @param $callbacks |
|
57 | - * @return array |
|
58 | - */ |
|
59 | - public function modify_callbacks($callbacks) |
|
60 | - { |
|
61 | - //now let's add the question group callback |
|
62 | - $callbacks[] = array($this, 'primary_question_group_update'); |
|
63 | - return $callbacks; |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * Hooked into revision restores. |
|
69 | - * @param $post_id |
|
70 | - * @param $revision_id |
|
71 | - * @return EE_Base_Class |
|
72 | - * @throws EE_Error |
|
73 | - * @throws InvalidArgumentException |
|
74 | - * @throws ReflectionException |
|
75 | - * @throws InvalidDataTypeException |
|
76 | - * @throws InvalidInterfaceException |
|
77 | - */ |
|
78 | - public function restore_revision($post_id, $revision_id) |
|
79 | - { |
|
80 | - $EVT_MDL = EE_Registry::instance()->load_model('Event'); |
|
81 | - $post_evt = $EVT_MDL->get_one_by_ID($post_id); |
|
82 | - //restore revision for primary questions |
|
83 | - $post_evt->restore_revision( |
|
84 | - $revision_id, |
|
85 | - array('Question_Group'), |
|
86 | - array('Question_Group' => array('Event_Question_Group.EQG_primary' => 1)) |
|
87 | - ); |
|
88 | - return $post_evt; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * Content of metabox. |
|
94 | - * @param $post_id |
|
95 | - * @param $post |
|
96 | - * @throws EE_Error |
|
97 | - * @throws InvalidArgumentException |
|
98 | - * @throws InvalidDataTypeException |
|
99 | - * @throws InvalidInterfaceException |
|
100 | - */ |
|
101 | - public function primary_questions($post_id, $post) |
|
102 | - { |
|
103 | - $this->_event = $this->_adminpage_obj->get_event_object(); |
|
104 | - $event_id = $this->_event->ID(); |
|
105 | - ?> |
|
21 | + /** |
|
22 | + * @var EE_Event|null |
|
23 | + */ |
|
24 | + protected $_event; |
|
25 | + |
|
26 | + |
|
27 | + protected function _set_hooks_properties() |
|
28 | + { |
|
29 | + |
|
30 | + $this->_name = 'registration_form'; |
|
31 | + $this->_metaboxes = array( |
|
32 | + 0 => array( |
|
33 | + 'page_route' => array('edit', 'create_new'), |
|
34 | + 'func' => 'primary_questions', |
|
35 | + 'label' => esc_html__('Questions for Primary Registrant', 'event_espresso'), |
|
36 | + 'priority' => 'default', |
|
37 | + 'context' => 'side', |
|
38 | + ), |
|
39 | + ); |
|
40 | + |
|
41 | + //hook into the handler for saving question groups |
|
42 | + add_filter( |
|
43 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
44 | + array($this, 'modify_callbacks'), |
|
45 | + 10 |
|
46 | + ); |
|
47 | + |
|
48 | + //hook into revision restores (we're hooking into the global action because EE_Admin_Hooks classes are already |
|
49 | + //restricted by page) |
|
50 | + add_action('AHEE_EE_Admin_Page_CPT__restore_revision', array($this, 'restore_revision'), 10, 2); |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook |
|
56 | + * @param $callbacks |
|
57 | + * @return array |
|
58 | + */ |
|
59 | + public function modify_callbacks($callbacks) |
|
60 | + { |
|
61 | + //now let's add the question group callback |
|
62 | + $callbacks[] = array($this, 'primary_question_group_update'); |
|
63 | + return $callbacks; |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * Hooked into revision restores. |
|
69 | + * @param $post_id |
|
70 | + * @param $revision_id |
|
71 | + * @return EE_Base_Class |
|
72 | + * @throws EE_Error |
|
73 | + * @throws InvalidArgumentException |
|
74 | + * @throws ReflectionException |
|
75 | + * @throws InvalidDataTypeException |
|
76 | + * @throws InvalidInterfaceException |
|
77 | + */ |
|
78 | + public function restore_revision($post_id, $revision_id) |
|
79 | + { |
|
80 | + $EVT_MDL = EE_Registry::instance()->load_model('Event'); |
|
81 | + $post_evt = $EVT_MDL->get_one_by_ID($post_id); |
|
82 | + //restore revision for primary questions |
|
83 | + $post_evt->restore_revision( |
|
84 | + $revision_id, |
|
85 | + array('Question_Group'), |
|
86 | + array('Question_Group' => array('Event_Question_Group.EQG_primary' => 1)) |
|
87 | + ); |
|
88 | + return $post_evt; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * Content of metabox. |
|
94 | + * @param $post_id |
|
95 | + * @param $post |
|
96 | + * @throws EE_Error |
|
97 | + * @throws InvalidArgumentException |
|
98 | + * @throws InvalidDataTypeException |
|
99 | + * @throws InvalidInterfaceException |
|
100 | + */ |
|
101 | + public function primary_questions($post_id, $post) |
|
102 | + { |
|
103 | + $this->_event = $this->_adminpage_obj->get_event_object(); |
|
104 | + $event_id = $this->_event->ID(); |
|
105 | + ?> |
|
106 | 106 | <div class="inside"> |
107 | 107 | <p><strong> |
108 | 108 | <?php _e('Question Groups', 'event_espresso'); ?> |
109 | 109 | </strong><br/> |
110 | 110 | <?php |
111 | - printf( |
|
112 | - esc_html__( |
|
113 | - 'Add a pre-populated %1$sgroup of questions%2$s to your event. The personal information group is required for all events', |
|
114 | - 'event_espresso' |
|
115 | - ), |
|
116 | - '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
117 | - '</a>' |
|
118 | - ) |
|
119 | - ?> |
|
111 | + printf( |
|
112 | + esc_html__( |
|
113 | + 'Add a pre-populated %1$sgroup of questions%2$s to your event. The personal information group is required for all events', |
|
114 | + 'event_espresso' |
|
115 | + ), |
|
116 | + '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
117 | + '</a>' |
|
118 | + ) |
|
119 | + ?> |
|
120 | 120 | </p> |
121 | 121 | <?php |
122 | 122 | |
123 | - $qsg_where['QSG_deleted'] = false; |
|
124 | - $query_params = apply_filters( |
|
125 | - 'FHEE__espresso_events_Registration_Form_Hooks__primary_questions__question_group_query_parameters', |
|
126 | - array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
127 | - ); |
|
128 | - $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
129 | - $EQGs = ! empty($event_id) |
|
130 | - ? $this->_event->get_many_related( |
|
131 | - 'Question_Group', |
|
132 | - array(array('Event_Question_Group.EQG_primary' => 1)) |
|
133 | - ) |
|
134 | - : array(); |
|
135 | - $EQGids = array_keys($EQGs); |
|
136 | - |
|
137 | - if (! empty($QSGs)) { |
|
138 | - $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
139 | - foreach ($QSGs as $QSG) { |
|
140 | - $checked = in_array($QSG->ID(), $EQGids, true) |
|
141 | - || $QSG->get('QSG_system') === 1 |
|
142 | - ? ' checked="checked"' |
|
143 | - : ''; |
|
144 | - $visibility = $QSG->get('QSG_system') === 1 |
|
145 | - ? ' style="visibility:hidden"' |
|
146 | - : ''; |
|
147 | - $edit_query_args = $this->_adminpage_obj->is_caf() ? array( |
|
148 | - 'action' => 'edit_question_group', |
|
149 | - 'QSG_ID' => $QSG->ID(), |
|
150 | - ) : array('action' => 'question_groups'); |
|
151 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
152 | - $edit_query_args, |
|
153 | - EE_FORMS_ADMIN_URL |
|
154 | - ); |
|
155 | - |
|
156 | - $html .= ' |
|
123 | + $qsg_where['QSG_deleted'] = false; |
|
124 | + $query_params = apply_filters( |
|
125 | + 'FHEE__espresso_events_Registration_Form_Hooks__primary_questions__question_group_query_parameters', |
|
126 | + array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
127 | + ); |
|
128 | + $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
129 | + $EQGs = ! empty($event_id) |
|
130 | + ? $this->_event->get_many_related( |
|
131 | + 'Question_Group', |
|
132 | + array(array('Event_Question_Group.EQG_primary' => 1)) |
|
133 | + ) |
|
134 | + : array(); |
|
135 | + $EQGids = array_keys($EQGs); |
|
136 | + |
|
137 | + if (! empty($QSGs)) { |
|
138 | + $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
139 | + foreach ($QSGs as $QSG) { |
|
140 | + $checked = in_array($QSG->ID(), $EQGids, true) |
|
141 | + || $QSG->get('QSG_system') === 1 |
|
142 | + ? ' checked="checked"' |
|
143 | + : ''; |
|
144 | + $visibility = $QSG->get('QSG_system') === 1 |
|
145 | + ? ' style="visibility:hidden"' |
|
146 | + : ''; |
|
147 | + $edit_query_args = $this->_adminpage_obj->is_caf() ? array( |
|
148 | + 'action' => 'edit_question_group', |
|
149 | + 'QSG_ID' => $QSG->ID(), |
|
150 | + ) : array('action' => 'question_groups'); |
|
151 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
152 | + $edit_query_args, |
|
153 | + EE_FORMS_ADMIN_URL |
|
154 | + ); |
|
155 | + |
|
156 | + $html .= ' |
|
157 | 157 | <p id="event-question-group-' . $QSG->ID() . '"> |
158 | 158 | <input value="' . $QSG->ID() . '" type="checkbox"' |
159 | - . $visibility |
|
160 | - . ' name="question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
159 | + . $visibility |
|
160 | + . ' name="question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
161 | 161 | <a href="' . $edit_link . '" title="' |
162 | - . sprintf( |
|
163 | - esc_attr__('Edit %s Group', 'event_espresso'), |
|
164 | - $QSG->get('QSG_name') |
|
165 | - ) |
|
166 | - . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
162 | + . sprintf( |
|
163 | + esc_attr__('Edit %s Group', 'event_espresso'), |
|
164 | + $QSG->get('QSG_name') |
|
165 | + ) |
|
166 | + . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
167 | 167 | </p>'; |
168 | - } |
|
169 | - $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
170 | - |
|
171 | - echo $html; |
|
172 | - } else { |
|
173 | - esc_html_e( |
|
174 | - 'There seems to be a problem with your questions. Please contact [email protected]', |
|
175 | - 'event_espresso' |
|
176 | - ); |
|
177 | - } |
|
178 | - do_action('AHEE_event_editor_questions_notice'); |
|
179 | - ?> |
|
168 | + } |
|
169 | + $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
170 | + |
|
171 | + echo $html; |
|
172 | + } else { |
|
173 | + esc_html_e( |
|
174 | + 'There seems to be a problem with your questions. Please contact [email protected]', |
|
175 | + 'event_espresso' |
|
176 | + ); |
|
177 | + } |
|
178 | + do_action('AHEE_event_editor_questions_notice'); |
|
179 | + ?> |
|
180 | 180 | </div> |
181 | 181 | <?php |
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * @param EE_Event $evtobj |
|
187 | - * @param array $data |
|
188 | - * @return bool |
|
189 | - * @throws EE_Error |
|
190 | - */ |
|
191 | - public function primary_question_group_update($evtobj, $data) |
|
192 | - { |
|
193 | - $question_groups = ! empty($data['question_groups']) ? (array)$data['question_groups'] : array(); |
|
194 | - $added_qgs = array_keys($question_groups); |
|
195 | - $success = array(); |
|
196 | - |
|
197 | - //let's get all current question groups associated with this event. |
|
198 | - $current_qgs = $evtobj->get_many_related( |
|
199 | - 'Question_Group', |
|
200 | - array(array('Event_Question_Group.EQG_primary' => 1)) |
|
201 | - ); |
|
202 | - $current_qgs = array_keys($current_qgs); //we just want the ids |
|
203 | - |
|
204 | - //now let's get the groups selected in the editor and update (IF we have data) |
|
205 | - if (! empty($question_groups)) { |
|
206 | - foreach ($question_groups as $id => $val) { |
|
207 | - //add to event |
|
208 | - if ($val) { |
|
209 | - $qg = $evtobj->_add_relation_to($id, 'Question_Group', array('EQG_primary' => 1)); |
|
210 | - } |
|
211 | - $success[] = ! empty($qg) ? 1 : 0; |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - //wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
216 | - $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
217 | - |
|
218 | - foreach ($removed_qgs as $qgid) { |
|
219 | - $qg = $evtobj->_remove_relation_to($qgid, 'Question_Group', array('EQG_primary' => 1)); |
|
220 | - $success[] = ! empty($qg) ? 1 : 0; |
|
221 | - } |
|
222 | - return in_array(0, $success, true) ? false : true; |
|
223 | - } |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * @param EE_Event $evtobj |
|
187 | + * @param array $data |
|
188 | + * @return bool |
|
189 | + * @throws EE_Error |
|
190 | + */ |
|
191 | + public function primary_question_group_update($evtobj, $data) |
|
192 | + { |
|
193 | + $question_groups = ! empty($data['question_groups']) ? (array)$data['question_groups'] : array(); |
|
194 | + $added_qgs = array_keys($question_groups); |
|
195 | + $success = array(); |
|
196 | + |
|
197 | + //let's get all current question groups associated with this event. |
|
198 | + $current_qgs = $evtobj->get_many_related( |
|
199 | + 'Question_Group', |
|
200 | + array(array('Event_Question_Group.EQG_primary' => 1)) |
|
201 | + ); |
|
202 | + $current_qgs = array_keys($current_qgs); //we just want the ids |
|
203 | + |
|
204 | + //now let's get the groups selected in the editor and update (IF we have data) |
|
205 | + if (! empty($question_groups)) { |
|
206 | + foreach ($question_groups as $id => $val) { |
|
207 | + //add to event |
|
208 | + if ($val) { |
|
209 | + $qg = $evtobj->_add_relation_to($id, 'Question_Group', array('EQG_primary' => 1)); |
|
210 | + } |
|
211 | + $success[] = ! empty($qg) ? 1 : 0; |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + //wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
216 | + $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
217 | + |
|
218 | + foreach ($removed_qgs as $qgid) { |
|
219 | + $qg = $evtobj->_remove_relation_to($qgid, 'Question_Group', array('EQG_primary' => 1)); |
|
220 | + $success[] = ! empty($qg) ? 1 : 0; |
|
221 | + } |
|
222 | + return in_array(0, $success, true) ? false : true; |
|
223 | + } |
|
224 | 224 | } |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | array(array('Event_Question_Group.EQG_primary' => 1)) |
133 | 133 | ) |
134 | 134 | : array(); |
135 | - $EQGids = array_keys($EQGs); |
|
135 | + $EQGids = array_keys($EQGs); |
|
136 | 136 | |
137 | - if (! empty($QSGs)) { |
|
137 | + if ( ! empty($QSGs)) { |
|
138 | 138 | $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
139 | 139 | foreach ($QSGs as $QSG) { |
140 | - $checked = in_array($QSG->ID(), $EQGids, true) |
|
140 | + $checked = in_array($QSG->ID(), $EQGids, true) |
|
141 | 141 | || $QSG->get('QSG_system') === 1 |
142 | 142 | ? ' checked="checked"' |
143 | 143 | : ''; |
@@ -148,22 +148,22 @@ discard block |
||
148 | 148 | 'action' => 'edit_question_group', |
149 | 149 | 'QSG_ID' => $QSG->ID(), |
150 | 150 | ) : array('action' => 'question_groups'); |
151 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
151 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
152 | 152 | $edit_query_args, |
153 | 153 | EE_FORMS_ADMIN_URL |
154 | 154 | ); |
155 | 155 | |
156 | 156 | $html .= ' |
157 | - <p id="event-question-group-' . $QSG->ID() . '"> |
|
158 | - <input value="' . $QSG->ID() . '" type="checkbox"' |
|
157 | + <p id="event-question-group-' . $QSG->ID().'"> |
|
158 | + <input value="' . $QSG->ID().'" type="checkbox"' |
|
159 | 159 | . $visibility |
160 | - . ' name="question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
161 | - <a href="' . $edit_link . '" title="' |
|
160 | + . ' name="question_groups['.$QSG->ID().']"'.$checked.' /> |
|
161 | + <a href="' . $edit_link.'" title="' |
|
162 | 162 | . sprintf( |
163 | 163 | esc_attr__('Edit %s Group', 'event_espresso'), |
164 | 164 | $QSG->get('QSG_name') |
165 | 165 | ) |
166 | - . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
166 | + . '" target="_blank">'.$QSG->get('QSG_name').'</a> |
|
167 | 167 | </p>'; |
168 | 168 | } |
169 | 169 | $html .= count($QSGs) > 10 ? '</div>' : ''; |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | */ |
191 | 191 | public function primary_question_group_update($evtobj, $data) |
192 | 192 | { |
193 | - $question_groups = ! empty($data['question_groups']) ? (array)$data['question_groups'] : array(); |
|
193 | + $question_groups = ! empty($data['question_groups']) ? (array) $data['question_groups'] : array(); |
|
194 | 194 | $added_qgs = array_keys($question_groups); |
195 | 195 | $success = array(); |
196 | 196 | |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | $current_qgs = array_keys($current_qgs); //we just want the ids |
203 | 203 | |
204 | 204 | //now let's get the groups selected in the editor and update (IF we have data) |
205 | - if (! empty($question_groups)) { |
|
205 | + if ( ! empty($question_groups)) { |
|
206 | 206 | foreach ($question_groups as $id => $val) { |
207 | 207 | //add to event |
208 | 208 | if ($val) { |
@@ -17,208 +17,208 @@ |
||
17 | 17 | class espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * extending the properties set in espresso_events_Registration_From_Hooks |
|
22 | - * |
|
23 | - * @access protected |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - protected function _extend_properties() |
|
27 | - { |
|
28 | - $this->_metaboxes = array_merge( |
|
29 | - $this->_metaboxes, |
|
30 | - array( |
|
31 | - 1 => array( |
|
32 | - 'page_route' => array('create_new', 'edit'), |
|
33 | - 'func' => 'additional_questions', |
|
34 | - 'label' => esc_html__('Questions for Additional Registrants', 'event_espresso'), |
|
35 | - 'priority' => 'default', |
|
36 | - 'context' => 'side', |
|
37 | - ), |
|
38 | - ) |
|
39 | - ); |
|
40 | - $this->_scripts_styles = array( |
|
41 | - 'registers' => array( |
|
42 | - 'extended-event-editor' => array( |
|
43 | - 'url' => EE_CORE_CAF_ADMIN_EXTEND_URL |
|
44 | - . 'registration_form/assets/event-editor-question-groups.js', |
|
45 | - 'depends' => array('jquery'), |
|
46 | - ), |
|
47 | - ), |
|
48 | - 'enqueues' => array( |
|
49 | - 'extended-event-editor' => array('edit', 'create_new'), |
|
50 | - ), |
|
51 | - ); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @param Callable[] $callbacks |
|
57 | - * @return array |
|
58 | - */ |
|
59 | - public function modify_callbacks($callbacks) |
|
60 | - { |
|
61 | - $callbacks = parent::modify_callbacks($callbacks); |
|
62 | - $callbacks[] = array($this, 'additional_question_group_update'); |
|
63 | - return $callbacks; |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * Call back hooked into revision restores. |
|
69 | - * |
|
70 | - * @param $post_id |
|
71 | - * @param $revision_id |
|
72 | - * @return EE_Base_Class|void |
|
73 | - * @throws EE_Error |
|
74 | - * @throws InvalidArgumentException |
|
75 | - * @throws InvalidDataTypeException |
|
76 | - * @throws InvalidInterfaceException |
|
77 | - * @throws ReflectionException |
|
78 | - */ |
|
79 | - public function restore_revision($post_id, $revision_id) |
|
80 | - { |
|
81 | - $post_evt = parent::restore_revision($post_id, $revision_id); |
|
82 | - |
|
83 | - //restore revision for additional questions |
|
84 | - $post_evt->restore_revision( |
|
85 | - $revision_id, |
|
86 | - array('Question_Group'), |
|
87 | - array('Question_Group' => array('Event_Question_Group.EQG_primary' => 0) |
|
88 | - ) |
|
89 | - ); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * @param $post_id |
|
95 | - * @param $post |
|
96 | - * @throws EE_Error |
|
97 | - * @throws InvalidArgumentException |
|
98 | - * @throws InvalidDataTypeException |
|
99 | - * @throws InvalidInterfaceException |
|
100 | - */ |
|
101 | - public function additional_questions($post_id, $post) |
|
102 | - { |
|
103 | - $this->_event = $this->_adminpage_obj->get_event_object(); |
|
104 | - $event_id = $this->_event->ID(); |
|
105 | - ?> |
|
20 | + /** |
|
21 | + * extending the properties set in espresso_events_Registration_From_Hooks |
|
22 | + * |
|
23 | + * @access protected |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + protected function _extend_properties() |
|
27 | + { |
|
28 | + $this->_metaboxes = array_merge( |
|
29 | + $this->_metaboxes, |
|
30 | + array( |
|
31 | + 1 => array( |
|
32 | + 'page_route' => array('create_new', 'edit'), |
|
33 | + 'func' => 'additional_questions', |
|
34 | + 'label' => esc_html__('Questions for Additional Registrants', 'event_espresso'), |
|
35 | + 'priority' => 'default', |
|
36 | + 'context' => 'side', |
|
37 | + ), |
|
38 | + ) |
|
39 | + ); |
|
40 | + $this->_scripts_styles = array( |
|
41 | + 'registers' => array( |
|
42 | + 'extended-event-editor' => array( |
|
43 | + 'url' => EE_CORE_CAF_ADMIN_EXTEND_URL |
|
44 | + . 'registration_form/assets/event-editor-question-groups.js', |
|
45 | + 'depends' => array('jquery'), |
|
46 | + ), |
|
47 | + ), |
|
48 | + 'enqueues' => array( |
|
49 | + 'extended-event-editor' => array('edit', 'create_new'), |
|
50 | + ), |
|
51 | + ); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @param Callable[] $callbacks |
|
57 | + * @return array |
|
58 | + */ |
|
59 | + public function modify_callbacks($callbacks) |
|
60 | + { |
|
61 | + $callbacks = parent::modify_callbacks($callbacks); |
|
62 | + $callbacks[] = array($this, 'additional_question_group_update'); |
|
63 | + return $callbacks; |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * Call back hooked into revision restores. |
|
69 | + * |
|
70 | + * @param $post_id |
|
71 | + * @param $revision_id |
|
72 | + * @return EE_Base_Class|void |
|
73 | + * @throws EE_Error |
|
74 | + * @throws InvalidArgumentException |
|
75 | + * @throws InvalidDataTypeException |
|
76 | + * @throws InvalidInterfaceException |
|
77 | + * @throws ReflectionException |
|
78 | + */ |
|
79 | + public function restore_revision($post_id, $revision_id) |
|
80 | + { |
|
81 | + $post_evt = parent::restore_revision($post_id, $revision_id); |
|
82 | + |
|
83 | + //restore revision for additional questions |
|
84 | + $post_evt->restore_revision( |
|
85 | + $revision_id, |
|
86 | + array('Question_Group'), |
|
87 | + array('Question_Group' => array('Event_Question_Group.EQG_primary' => 0) |
|
88 | + ) |
|
89 | + ); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * @param $post_id |
|
95 | + * @param $post |
|
96 | + * @throws EE_Error |
|
97 | + * @throws InvalidArgumentException |
|
98 | + * @throws InvalidDataTypeException |
|
99 | + * @throws InvalidInterfaceException |
|
100 | + */ |
|
101 | + public function additional_questions($post_id, $post) |
|
102 | + { |
|
103 | + $this->_event = $this->_adminpage_obj->get_event_object(); |
|
104 | + $event_id = $this->_event->ID(); |
|
105 | + ?> |
|
106 | 106 | <div class="inside"> |
107 | 107 | <p><strong> |
108 | 108 | <?php _e('Question Groups', 'event_espresso'); ?> |
109 | 109 | </strong><br/> |
110 | 110 | <?php |
111 | - printf( |
|
112 | - esc_html__( |
|
113 | - 'Add a pre-populated %1$sgroup of questions%2$s to your event.', |
|
114 | - 'event_espresso' |
|
115 | - ), |
|
116 | - '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
117 | - '</a>' |
|
118 | - ); |
|
119 | - ?> |
|
111 | + printf( |
|
112 | + esc_html__( |
|
113 | + 'Add a pre-populated %1$sgroup of questions%2$s to your event.', |
|
114 | + 'event_espresso' |
|
115 | + ), |
|
116 | + '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
117 | + '</a>' |
|
118 | + ); |
|
119 | + ?> |
|
120 | 120 | </p> |
121 | 121 | <?php |
122 | 122 | |
123 | - $qsg_where['QSG_deleted'] = false; |
|
124 | - $query_params = apply_filters( |
|
125 | - 'FHEE__espresso_events_Registration_Form_Hooks_Extend__additional_questions__question_group_query_parameters', |
|
126 | - array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
127 | - ); |
|
128 | - $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
129 | - $EQGs = ! empty($event_id) |
|
130 | - ? $this->_event->get_many_related( |
|
131 | - 'Question_Group', |
|
132 | - array(array('Event_Question_Group.EQG_primary' => 0)) |
|
133 | - ) |
|
134 | - : array(); |
|
135 | - $EQGids = array_keys($EQGs); |
|
136 | - |
|
137 | - if (! empty($QSGs)) { |
|
138 | - $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
139 | - foreach ($QSGs as $QSG) { |
|
140 | - $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : ''; |
|
141 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
142 | - array( |
|
143 | - 'action' => 'edit_question_group', |
|
144 | - 'QSG_ID' => $QSG->ID(), |
|
145 | - ), |
|
146 | - EE_FORMS_ADMIN_URL |
|
147 | - ); |
|
148 | - |
|
149 | - $html .= ' |
|
123 | + $qsg_where['QSG_deleted'] = false; |
|
124 | + $query_params = apply_filters( |
|
125 | + 'FHEE__espresso_events_Registration_Form_Hooks_Extend__additional_questions__question_group_query_parameters', |
|
126 | + array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
127 | + ); |
|
128 | + $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
129 | + $EQGs = ! empty($event_id) |
|
130 | + ? $this->_event->get_many_related( |
|
131 | + 'Question_Group', |
|
132 | + array(array('Event_Question_Group.EQG_primary' => 0)) |
|
133 | + ) |
|
134 | + : array(); |
|
135 | + $EQGids = array_keys($EQGs); |
|
136 | + |
|
137 | + if (! empty($QSGs)) { |
|
138 | + $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
139 | + foreach ($QSGs as $QSG) { |
|
140 | + $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : ''; |
|
141 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
142 | + array( |
|
143 | + 'action' => 'edit_question_group', |
|
144 | + 'QSG_ID' => $QSG->ID(), |
|
145 | + ), |
|
146 | + EE_FORMS_ADMIN_URL |
|
147 | + ); |
|
148 | + |
|
149 | + $html .= ' |
|
150 | 150 | <p id="event-question-group-' . $QSG->ID() . '"> |
151 | 151 | <input value="' . $QSG->ID() . '"' |
152 | - . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
152 | + . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
153 | 153 | <a href="' . $edit_link . '" title="' |
154 | - . sprintf( |
|
155 | - esc_attr__('Edit %s Group', 'event_espresso'), |
|
156 | - $QSG->get('QSG_name') |
|
157 | - ) |
|
158 | - . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
154 | + . sprintf( |
|
155 | + esc_attr__('Edit %s Group', 'event_espresso'), |
|
156 | + $QSG->get('QSG_name') |
|
157 | + ) |
|
158 | + . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
159 | 159 | </p>'; |
160 | - if ($QSG->ID() === 2) { |
|
161 | - $html .= ' |
|
160 | + if ($QSG->ID() === 2) { |
|
161 | + $html .= ' |
|
162 | 162 | <p id="question-group-requirements-notice-pg" class="important-notice small-text" style="display: none;">' |
163 | - . esc_html__( |
|
164 | - 'The Personal Information question group is required whenever the Address Information question group is activated.', |
|
165 | - 'event_espresso' |
|
166 | - ) |
|
167 | - . '</p>'; |
|
168 | - } |
|
169 | - } |
|
170 | - $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
171 | - |
|
172 | - echo $html; |
|
173 | - |
|
174 | - } else { |
|
175 | - esc_html_e( |
|
176 | - 'There seems to be a problem with your questions. Please contact [email protected]', |
|
177 | - 'event_espresso' |
|
178 | - ); |
|
179 | - } |
|
180 | - do_action('AHEE__espresso_events_Registration_Form_Hooks__additional_questions__after_content'); |
|
181 | - ?> |
|
163 | + . esc_html__( |
|
164 | + 'The Personal Information question group is required whenever the Address Information question group is activated.', |
|
165 | + 'event_espresso' |
|
166 | + ) |
|
167 | + . '</p>'; |
|
168 | + } |
|
169 | + } |
|
170 | + $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
171 | + |
|
172 | + echo $html; |
|
173 | + |
|
174 | + } else { |
|
175 | + esc_html_e( |
|
176 | + 'There seems to be a problem with your questions. Please contact [email protected]', |
|
177 | + 'event_espresso' |
|
178 | + ); |
|
179 | + } |
|
180 | + do_action('AHEE__espresso_events_Registration_Form_Hooks__additional_questions__after_content'); |
|
181 | + ?> |
|
182 | 182 | </div> |
183 | 183 | <?php |
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - public function additional_question_group_update($evtobj, $data) |
|
188 | - { |
|
189 | - $question_groups = ! empty($data['add_attendee_question_groups']) |
|
190 | - ? (array) $data['add_attendee_question_groups'] |
|
191 | - : array(); |
|
192 | - $added_qgs = array_keys($question_groups); |
|
193 | - $success = array(); |
|
194 | - |
|
195 | - //let's get all current question groups associated with this event. |
|
196 | - $current_qgs = $evtobj->get_many_related( |
|
197 | - 'Question_Group', |
|
198 | - array(array('Event_Question_Group.EQG_primary' => 0)) |
|
199 | - ); |
|
200 | - $current_qgs = array_keys($current_qgs); //we just want the ids |
|
201 | - |
|
202 | - //now let's get the groups selected in the editor and update (IF we have data) |
|
203 | - if (! empty($question_groups)) { |
|
204 | - foreach ($question_groups as $id => $val) { |
|
205 | - //add to event |
|
206 | - if ($val) { |
|
207 | - $qg = $evtobj->_add_relation_to($id, 'Question_Group', array('EQG_primary' => 0)); |
|
208 | - } |
|
209 | - $success[] = ! empty($qg) ? 1 : 0; |
|
210 | - } |
|
211 | - } |
|
212 | - |
|
213 | - //wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
214 | - $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
215 | - |
|
216 | - foreach ($removed_qgs as $qgid) { |
|
217 | - $qg = $evtobj->_remove_relation_to($qgid, 'Question_Group', array('EQG_primary' => 0)); |
|
218 | - $success[] = ! empty($qg) ? 1 : 0; |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - return in_array(0, $success, true) ? false : true; |
|
223 | - } |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + public function additional_question_group_update($evtobj, $data) |
|
188 | + { |
|
189 | + $question_groups = ! empty($data['add_attendee_question_groups']) |
|
190 | + ? (array) $data['add_attendee_question_groups'] |
|
191 | + : array(); |
|
192 | + $added_qgs = array_keys($question_groups); |
|
193 | + $success = array(); |
|
194 | + |
|
195 | + //let's get all current question groups associated with this event. |
|
196 | + $current_qgs = $evtobj->get_many_related( |
|
197 | + 'Question_Group', |
|
198 | + array(array('Event_Question_Group.EQG_primary' => 0)) |
|
199 | + ); |
|
200 | + $current_qgs = array_keys($current_qgs); //we just want the ids |
|
201 | + |
|
202 | + //now let's get the groups selected in the editor and update (IF we have data) |
|
203 | + if (! empty($question_groups)) { |
|
204 | + foreach ($question_groups as $id => $val) { |
|
205 | + //add to event |
|
206 | + if ($val) { |
|
207 | + $qg = $evtobj->_add_relation_to($id, 'Question_Group', array('EQG_primary' => 0)); |
|
208 | + } |
|
209 | + $success[] = ! empty($qg) ? 1 : 0; |
|
210 | + } |
|
211 | + } |
|
212 | + |
|
213 | + //wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
214 | + $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
215 | + |
|
216 | + foreach ($removed_qgs as $qgid) { |
|
217 | + $qg = $evtobj->_remove_relation_to($qgid, 'Question_Group', array('EQG_primary' => 0)); |
|
218 | + $success[] = ! empty($qg) ? 1 : 0; |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + return in_array(0, $success, true) ? false : true; |
|
223 | + } |
|
224 | 224 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | protected function _extend_properties() |
27 | 27 | { |
28 | - $this->_metaboxes = array_merge( |
|
28 | + $this->_metaboxes = array_merge( |
|
29 | 29 | $this->_metaboxes, |
30 | 30 | array( |
31 | 31 | 1 => array( |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | array(array('Event_Question_Group.EQG_primary' => 0)) |
133 | 133 | ) |
134 | 134 | : array(); |
135 | - $EQGids = array_keys($EQGs); |
|
135 | + $EQGids = array_keys($EQGs); |
|
136 | 136 | |
137 | - if (! empty($QSGs)) { |
|
137 | + if ( ! empty($QSGs)) { |
|
138 | 138 | $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
139 | 139 | foreach ($QSGs as $QSG) { |
140 | 140 | $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : ''; |
@@ -147,15 +147,15 @@ discard block |
||
147 | 147 | ); |
148 | 148 | |
149 | 149 | $html .= ' |
150 | - <p id="event-question-group-' . $QSG->ID() . '"> |
|
151 | - <input value="' . $QSG->ID() . '"' |
|
152 | - . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
153 | - <a href="' . $edit_link . '" title="' |
|
150 | + <p id="event-question-group-' . $QSG->ID().'"> |
|
151 | + <input value="' . $QSG->ID().'"' |
|
152 | + . ' type="checkbox" name="add_attendee_question_groups['.$QSG->ID().']"'.$checked.' /> |
|
153 | + <a href="' . $edit_link.'" title="' |
|
154 | 154 | . sprintf( |
155 | 155 | esc_attr__('Edit %s Group', 'event_espresso'), |
156 | 156 | $QSG->get('QSG_name') |
157 | 157 | ) |
158 | - . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
158 | + . '" target="_blank">'.$QSG->get('QSG_name').'</a> |
|
159 | 159 | </p>'; |
160 | 160 | if ($QSG->ID() === 2) { |
161 | 161 | $html .= ' |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | $current_qgs = array_keys($current_qgs); //we just want the ids |
201 | 201 | |
202 | 202 | //now let's get the groups selected in the editor and update (IF we have data) |
203 | - if (! empty($question_groups)) { |
|
203 | + if ( ! empty($question_groups)) { |
|
204 | 204 | foreach ($question_groups as $id => $val) { |
205 | 205 | //add to event |
206 | 206 | if ($val) { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('NO direct script access allowed'); |
|
2 | + exit('NO direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -17,585 +17,585 @@ discard block |
||
17 | 17 | class EEG_Paypal_Express extends EE_Offsite_Gateway |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * Merchant API Username. |
|
22 | - * |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - protected $_api_username; |
|
26 | - |
|
27 | - /** |
|
28 | - * Merchant API Password. |
|
29 | - * |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - protected $_api_password; |
|
33 | - |
|
34 | - /** |
|
35 | - * API Signature. |
|
36 | - * |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - protected $_api_signature; |
|
40 | - |
|
41 | - /** |
|
42 | - * Request Shipping address on PP checkout page. |
|
43 | - * |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - protected $_request_shipping_addr; |
|
47 | - |
|
48 | - /** |
|
49 | - * Business/personal logo. |
|
50 | - * |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - protected $_image_url; |
|
54 | - |
|
55 | - /** |
|
56 | - * gateway URL variable |
|
57 | - * |
|
58 | - * @var string |
|
59 | - */ |
|
60 | - protected $_base_gateway_url = ''; |
|
61 | - |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * EEG_Paypal_Express constructor. |
|
66 | - */ |
|
67 | - public function __construct() |
|
68 | - { |
|
69 | - $this->_currencies_supported = array( |
|
70 | - 'USD', |
|
71 | - 'AUD', |
|
72 | - 'BRL', |
|
73 | - 'CAD', |
|
74 | - 'CZK', |
|
75 | - 'DKK', |
|
76 | - 'EUR', |
|
77 | - 'HKD', |
|
78 | - 'HUF', |
|
79 | - 'ILS', |
|
80 | - 'JPY', |
|
81 | - 'MYR', |
|
82 | - 'MXN', |
|
83 | - 'NOK', |
|
84 | - 'NZD', |
|
85 | - 'PHP', |
|
86 | - 'PLN', |
|
87 | - 'GBP', |
|
88 | - 'RUB', |
|
89 | - 'SGD', |
|
90 | - 'SEK', |
|
91 | - 'CHF', |
|
92 | - 'TWD', |
|
93 | - 'THB', |
|
94 | - 'TRY', |
|
95 | - ); |
|
96 | - parent::__construct(); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
103 | - * |
|
104 | - * @param array $settings_array |
|
105 | - */ |
|
106 | - public function set_settings($settings_array) |
|
107 | - { |
|
108 | - parent::set_settings($settings_array); |
|
109 | - // Redirect URL. |
|
110 | - $this->_base_gateway_url = $this->_debug_mode |
|
111 | - ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
112 | - : 'https://api-3t.paypal.com/nvp'; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @param EEI_Payment $payment |
|
119 | - * @param array $billing_info |
|
120 | - * @param string $return_url |
|
121 | - * @param string $notify_url |
|
122 | - * @param string $cancel_url |
|
123 | - * @return \EE_Payment|\EEI_Payment |
|
124 | - * @throws \EE_Error |
|
125 | - */ |
|
126 | - public function set_redirection_info( |
|
127 | - $payment, |
|
128 | - $billing_info = array(), |
|
129 | - $return_url = null, |
|
130 | - $notify_url = null, |
|
131 | - $cancel_url = null |
|
132 | - ) { |
|
133 | - if (! $payment instanceof EEI_Payment) { |
|
134 | - $payment->set_gateway_response( |
|
135 | - __( |
|
136 | - 'Error. No associated payment was found.', |
|
137 | - 'event_espresso' |
|
138 | - ) |
|
139 | - ); |
|
140 | - $payment->set_status($this->_pay_model->failed_status()); |
|
141 | - return $payment; |
|
142 | - } |
|
143 | - $transaction = $payment->transaction(); |
|
144 | - if (! $transaction instanceof EEI_Transaction) { |
|
145 | - $payment->set_gateway_response( |
|
146 | - __( |
|
147 | - 'Could not process this payment because it has no associated transaction.', |
|
148 | - 'event_espresso' |
|
149 | - ) |
|
150 | - ); |
|
151 | - $payment->set_status($this->_pay_model->failed_status()); |
|
152 | - return $payment; |
|
153 | - } |
|
154 | - $order_description = substr($this->_format_order_description($payment), 0, 127); |
|
155 | - $primary_registration = $transaction->primary_registration(); |
|
156 | - $primary_attendee = $primary_registration instanceof EE_Registration |
|
157 | - ? $primary_registration->attendee() |
|
158 | - : false; |
|
159 | - $locale = explode('-', get_bloginfo('language')); |
|
160 | - // Gather request parameters. |
|
161 | - $token_request_dtls = array( |
|
162 | - 'METHOD' => 'SetExpressCheckout', |
|
163 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
164 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
165 | - 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
166 | - 'RETURNURL' => $return_url, |
|
167 | - 'CANCELURL' => $cancel_url, |
|
168 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
169 | - // Buyer does not need to create a PayPal account to check out. |
|
170 | - // This is referred to as PayPal Account Optional. |
|
171 | - 'SOLUTIONTYPE' => 'Sole', |
|
172 | - //EE will blow up if you change this |
|
173 | - 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
174 | - // Locale of the pages displayed by PayPal during Express Checkout. |
|
175 | - 'LOCALECODE' => $locale[1] |
|
176 | - ); |
|
177 | - // Show itemized list. |
|
178 | - if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
179 | - $item_num = 0; |
|
180 | - $itemized_sum = 0; |
|
181 | - $total_line_items = $transaction->total_line_item(); |
|
182 | - // Go through each item in the list. |
|
183 | - foreach ($total_line_items->get_items() as $line_item) { |
|
184 | - if ($line_item instanceof EE_Line_Item) { |
|
185 | - // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
186 | - if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
187 | - continue; |
|
188 | - } |
|
189 | - $unit_price = $line_item->unit_price(); |
|
190 | - $line_item_quantity = $line_item->quantity(); |
|
191 | - // This is a discount. |
|
192 | - if ($line_item->is_percent()) { |
|
193 | - $unit_price = $line_item->total(); |
|
194 | - $line_item_quantity = 1; |
|
195 | - } |
|
196 | - // Item Name. |
|
197 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME' . $item_num] = substr( |
|
198 | - $this->_format_line_item_name($line_item, $payment), |
|
199 | - 0, |
|
200 | - 127 |
|
201 | - ); |
|
202 | - // Item description. |
|
203 | - $token_request_dtls['L_PAYMENTREQUEST_0_DESC' . $item_num] = substr( |
|
204 | - $this->_format_line_item_desc($line_item, $payment), |
|
205 | - 0, |
|
206 | - 127 |
|
207 | - ); |
|
208 | - // Cost of individual item. |
|
209 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency($unit_price); |
|
210 | - // Item Number. |
|
211 | - $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1; |
|
212 | - // Item quantity. |
|
213 | - $token_request_dtls['L_PAYMENTREQUEST_0_QTY' . $item_num] = $line_item_quantity; |
|
214 | - // Digital item is sold. |
|
215 | - $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical'; |
|
216 | - $itemized_sum += $line_item->total(); |
|
217 | - ++$item_num; |
|
218 | - } |
|
219 | - } |
|
220 | - // Item's sales S/H and tax amount. |
|
221 | - $token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
222 | - $token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
223 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
224 | - $token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
225 | - $itemized_sum_diff_from_txn_total = round( |
|
226 | - $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
227 | - 2 |
|
228 | - ); |
|
229 | - // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
230 | - // add the difference as an extra line item. |
|
231 | - if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
232 | - // Item Name. |
|
233 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME' . $item_num] = substr( |
|
234 | - __( |
|
235 | - 'Other (promotion/surcharge/cancellation)', |
|
236 | - 'event_espresso' |
|
237 | - ), |
|
238 | - 0, |
|
239 | - 127 |
|
240 | - ); |
|
241 | - // Item description. |
|
242 | - $token_request_dtls['L_PAYMENTREQUEST_0_DESC' . $item_num] = ''; |
|
243 | - // Cost of individual item. |
|
244 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency( |
|
245 | - $itemized_sum_diff_from_txn_total |
|
246 | - ); |
|
247 | - // Item Number. |
|
248 | - $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1; |
|
249 | - // Item quantity. |
|
250 | - $token_request_dtls['L_PAYMENTREQUEST_0_QTY' . $item_num] = 1; |
|
251 | - // Digital item is sold. |
|
252 | - $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical'; |
|
253 | - $item_num++; |
|
254 | - } |
|
255 | - } else { |
|
256 | - // Just one Item. |
|
257 | - // Item Name. |
|
258 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr( |
|
259 | - $this->_format_partial_payment_line_item_name($payment), |
|
260 | - 0, |
|
261 | - 127 |
|
262 | - ); |
|
263 | - // Item description. |
|
264 | - $token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr( |
|
265 | - $this->_format_partial_payment_line_item_desc($payment), |
|
266 | - 0, |
|
267 | - 127 |
|
268 | - ); |
|
269 | - // Cost of individual item. |
|
270 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency($payment->amount()); |
|
271 | - // Item Number. |
|
272 | - $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
273 | - // Item quantity. |
|
274 | - $token_request_dtls['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
275 | - // Digital item is sold. |
|
276 | - $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
277 | - // Item's sales S/H and tax amount. |
|
278 | - $token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency($payment->amount()); |
|
279 | - $token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
280 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
281 | - $token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
282 | - } |
|
283 | - // Automatically filling out shipping and contact information. |
|
284 | - if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
285 | - // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
286 | - $token_request_dtls['NOSHIPPING'] = '2'; |
|
287 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
288 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
289 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
290 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
291 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
292 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
293 | - $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
294 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
295 | - } elseif (! $this->_request_shipping_addr) { |
|
296 | - // Do not request shipping details on the PP Checkout page. |
|
297 | - $token_request_dtls['NOSHIPPING'] = '1'; |
|
298 | - $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
299 | - } |
|
300 | - // Used a business/personal logo on the PayPal page. |
|
301 | - if (! empty($this->_image_url)) { |
|
302 | - $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
303 | - } |
|
304 | - $token_request_dtls = apply_filters( |
|
305 | - 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
306 | - $token_request_dtls, |
|
307 | - $this |
|
308 | - ); |
|
309 | - // Request PayPal token. |
|
310 | - $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
311 | - $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
312 | - $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
313 | - ? $token_rstatus['args'] |
|
314 | - : array(); |
|
315 | - if ($token_rstatus['status']) { |
|
316 | - // We got the Token so we may continue with the payment and redirect the client. |
|
317 | - $payment->set_details($response_args); |
|
318 | - $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
319 | - $payment->set_redirect_url( |
|
320 | - $gateway_url |
|
321 | - . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
322 | - . $response_args['TOKEN'] |
|
323 | - ); |
|
324 | - } else { |
|
325 | - if (isset($response_args['L_ERRORCODE'])) { |
|
326 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
327 | - } else { |
|
328 | - $payment->set_gateway_response( |
|
329 | - esc_html__( |
|
330 | - 'Error occurred while trying to setup the Express Checkout.', |
|
331 | - 'event_espresso' |
|
332 | - ) |
|
333 | - ); |
|
334 | - } |
|
335 | - $payment->set_details($response_args); |
|
336 | - $payment->set_status($this->_pay_model->failed_status()); |
|
337 | - } |
|
338 | - return $payment; |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * @param array $update_info { |
|
345 | - * @type string $gateway_txn_id |
|
346 | - * @type string status an EEMI_Payment status |
|
347 | - * } |
|
348 | - * @param EEI_Transaction $transaction |
|
349 | - * @return EEI_Payment |
|
350 | - */ |
|
351 | - public function handle_payment_update($update_info, $transaction) |
|
352 | - { |
|
353 | - $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
354 | - if ($payment instanceof EEI_Payment) { |
|
355 | - $this->log(array('Return from Authorization' => $update_info), $payment); |
|
356 | - $transaction = $payment->transaction(); |
|
357 | - if (! $transaction instanceof EEI_Transaction) { |
|
358 | - $payment->set_gateway_response( |
|
359 | - __( |
|
360 | - 'Could not process this payment because it has no associated transaction.', |
|
361 | - 'event_espresso' |
|
362 | - ) |
|
363 | - ); |
|
364 | - $payment->set_status($this->_pay_model->failed_status()); |
|
365 | - return $payment; |
|
366 | - } |
|
367 | - $primary_registrant = $transaction->primary_registration(); |
|
368 | - $payment_details = $payment->details(); |
|
369 | - // Check if we still have the token. |
|
370 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
371 | - $payment->set_status($this->_pay_model->failed_status()); |
|
372 | - return $payment; |
|
373 | - } |
|
374 | - $cdetails_request_dtls = array( |
|
375 | - 'METHOD' => 'GetExpressCheckoutDetails', |
|
376 | - 'TOKEN' => $payment_details['TOKEN'], |
|
377 | - ); |
|
378 | - // Request Customer Details. |
|
379 | - $cdetails_request_response = $this->_ppExpress_request( |
|
380 | - $cdetails_request_dtls, |
|
381 | - 'Customer Details', |
|
382 | - $payment |
|
383 | - ); |
|
384 | - $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
385 | - $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
386 | - ? $cdetails_rstatus['args'] |
|
387 | - : array(); |
|
388 | - if ($cdetails_rstatus['status']) { |
|
389 | - // We got the PayerID so now we can Complete the transaction. |
|
390 | - $docheckout_request_dtls = array( |
|
391 | - 'METHOD' => 'DoExpressCheckoutPayment', |
|
392 | - 'PAYERID' => $cdata_response_args['PAYERID'], |
|
393 | - 'TOKEN' => $payment_details['TOKEN'], |
|
394 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
395 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
396 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
397 | - ); |
|
398 | - // Payment Checkout/Capture. |
|
399 | - $docheckout_request_response = $this->_ppExpress_request( |
|
400 | - $docheckout_request_dtls, |
|
401 | - 'Do Payment', |
|
402 | - $payment |
|
403 | - ); |
|
404 | - $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
405 | - $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
406 | - ? $docheckout_rstatus['args'] |
|
407 | - : array(); |
|
408 | - if ($docheckout_rstatus['status']) { |
|
409 | - // All is well, payment approved. |
|
410 | - $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
411 | - $primary_registrant->reg_code() |
|
412 | - : ''; |
|
413 | - $payment->set_extra_accntng($primary_registration_code); |
|
414 | - $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
415 | - ? (float)$docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
416 | - : 0); |
|
417 | - $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
418 | - ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
419 | - : null); |
|
420 | - $payment->set_details($cdata_response_args); |
|
421 | - $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
422 | - ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
423 | - : ''); |
|
424 | - $payment->set_status($this->_pay_model->approved_status()); |
|
425 | - } else { |
|
426 | - if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
427 | - $payment->set_gateway_response( |
|
428 | - $docheckout_response_args['L_ERRORCODE'] |
|
429 | - . '; ' |
|
430 | - . $docheckout_response_args['L_SHORTMESSAGE'] |
|
431 | - ); |
|
432 | - } else { |
|
433 | - $payment->set_gateway_response( |
|
434 | - __( |
|
435 | - 'Error occurred while trying to Capture the funds.', |
|
436 | - 'event_espresso' |
|
437 | - ) |
|
438 | - ); |
|
439 | - } |
|
440 | - $payment->set_details($docheckout_response_args); |
|
441 | - $payment->set_status($this->_pay_model->declined_status()); |
|
442 | - } |
|
443 | - } else { |
|
444 | - if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
445 | - $payment->set_gateway_response( |
|
446 | - $cdata_response_args['L_ERRORCODE'] |
|
447 | - . '; ' |
|
448 | - . $cdata_response_args['L_SHORTMESSAGE'] |
|
449 | - ); |
|
450 | - } else { |
|
451 | - $payment->set_gateway_response( |
|
452 | - __( |
|
453 | - 'Error occurred while trying to get payment Details from PayPal.', |
|
454 | - 'event_espresso' |
|
455 | - ) |
|
456 | - ); |
|
457 | - } |
|
458 | - $payment->set_details($cdata_response_args); |
|
459 | - $payment->set_status($this->_pay_model->failed_status()); |
|
460 | - } |
|
461 | - } else { |
|
462 | - $payment->set_gateway_response(__('Error occurred while trying to process the payment.', 'event_espresso')); |
|
463 | - $payment->set_status($this->_pay_model->failed_status()); |
|
464 | - } |
|
465 | - return $payment; |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * Make the Express checkout request. |
|
472 | - * |
|
473 | - * @param array $request_params |
|
474 | - * @param string $request_text |
|
475 | - * @param EEI_Payment $payment |
|
476 | - * @return mixed |
|
477 | - */ |
|
478 | - public function _ppExpress_request($request_params, $request_text, $payment) |
|
479 | - { |
|
480 | - $request_dtls = array( |
|
481 | - 'VERSION' => '204.0', |
|
482 | - 'USER' => urlencode($this->_api_username), |
|
483 | - 'PWD' => urlencode($this->_api_password), |
|
484 | - 'SIGNATURE' => urlencode($this->_api_signature), |
|
485 | - ); |
|
486 | - $dtls = array_merge($request_dtls, $request_params); |
|
487 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
488 | - // Request Customer Details. |
|
489 | - $request_response = wp_remote_post( |
|
490 | - $this->_base_gateway_url, |
|
491 | - array( |
|
492 | - 'method' => 'POST', |
|
493 | - 'timeout' => 45, |
|
494 | - 'httpversion' => '1.1', |
|
495 | - 'cookies' => array(), |
|
496 | - 'headers' => array(), |
|
497 | - 'body' => http_build_query($dtls), |
|
498 | - ) |
|
499 | - ); |
|
500 | - // Log the response. |
|
501 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
502 | - return $request_response; |
|
503 | - } |
|
504 | - |
|
505 | - |
|
506 | - |
|
507 | - /** |
|
508 | - * Check the response status. |
|
509 | - * |
|
510 | - * @param mixed $request_response |
|
511 | - * @return array |
|
512 | - */ |
|
513 | - public function _ppExpress_check_response($request_response) |
|
514 | - { |
|
515 | - if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
516 | - // If we got here then there was an error in this request. |
|
517 | - return array('status' => false, 'args' => $request_response); |
|
518 | - } |
|
519 | - $response_args = array(); |
|
520 | - parse_str(urldecode($request_response['body']), $response_args); |
|
521 | - if (! isset($response_args['ACK'])) { |
|
522 | - return array('status' => false, 'args' => $request_response); |
|
523 | - } |
|
524 | - if ( |
|
525 | - ( |
|
526 | - isset($response_args['PAYERID']) |
|
527 | - || isset($response_args['TOKEN']) |
|
528 | - || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
529 | - || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
530 | - ) |
|
531 | - && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
532 | - ) { |
|
533 | - // Response status OK, return response parameters for further processing. |
|
534 | - return array('status' => true, 'args' => $response_args); |
|
535 | - } |
|
536 | - $errors = $this->_get_errors($response_args); |
|
537 | - return array('status' => false, 'args' => $errors); |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - |
|
542 | - /** |
|
543 | - * Log a "Cleared" request. |
|
544 | - * |
|
545 | - * @param array $request |
|
546 | - * @param EEI_Payment $payment |
|
547 | - * @param string $info |
|
548 | - * @return void |
|
549 | - */ |
|
550 | - private function _log_clean_request($request, $payment, $info) |
|
551 | - { |
|
552 | - $cleaned_request_data = $request; |
|
553 | - unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
554 | - $this->log(array($info => $cleaned_request_data), $payment); |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * Get error from the response data. |
|
561 | - * |
|
562 | - * @param array $data_array |
|
563 | - * @return array |
|
564 | - */ |
|
565 | - private function _get_errors($data_array) |
|
566 | - { |
|
567 | - $errors = array(); |
|
568 | - $n = 0; |
|
569 | - while (isset($data_array["L_ERRORCODE{$n}"])) { |
|
570 | - $l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
|
571 | - ? $data_array["L_ERRORCODE{$n}"] |
|
572 | - : ''; |
|
573 | - $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"]) |
|
574 | - ? $data_array["L_SEVERITYCODE{$n}"] |
|
575 | - : ''; |
|
576 | - $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"]) |
|
577 | - ? $data_array["L_SHORTMESSAGE{$n}"] |
|
578 | - : ''; |
|
579 | - $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"]) |
|
580 | - ? $data_array["L_LONGMESSAGE{$n}"] |
|
581 | - : ''; |
|
582 | - if ($n === 0) { |
|
583 | - $errors = array( |
|
584 | - 'L_ERRORCODE' => $l_error_code, |
|
585 | - 'L_SHORTMESSAGE' => $l_short_message, |
|
586 | - 'L_LONGMESSAGE' => $l_long_message, |
|
587 | - 'L_SEVERITYCODE' => $l_severity_code, |
|
588 | - ); |
|
589 | - } else { |
|
590 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
591 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
592 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
593 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
594 | - } |
|
595 | - $n++; |
|
596 | - } |
|
597 | - return $errors; |
|
598 | - } |
|
20 | + /** |
|
21 | + * Merchant API Username. |
|
22 | + * |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + protected $_api_username; |
|
26 | + |
|
27 | + /** |
|
28 | + * Merchant API Password. |
|
29 | + * |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + protected $_api_password; |
|
33 | + |
|
34 | + /** |
|
35 | + * API Signature. |
|
36 | + * |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + protected $_api_signature; |
|
40 | + |
|
41 | + /** |
|
42 | + * Request Shipping address on PP checkout page. |
|
43 | + * |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + protected $_request_shipping_addr; |
|
47 | + |
|
48 | + /** |
|
49 | + * Business/personal logo. |
|
50 | + * |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + protected $_image_url; |
|
54 | + |
|
55 | + /** |
|
56 | + * gateway URL variable |
|
57 | + * |
|
58 | + * @var string |
|
59 | + */ |
|
60 | + protected $_base_gateway_url = ''; |
|
61 | + |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * EEG_Paypal_Express constructor. |
|
66 | + */ |
|
67 | + public function __construct() |
|
68 | + { |
|
69 | + $this->_currencies_supported = array( |
|
70 | + 'USD', |
|
71 | + 'AUD', |
|
72 | + 'BRL', |
|
73 | + 'CAD', |
|
74 | + 'CZK', |
|
75 | + 'DKK', |
|
76 | + 'EUR', |
|
77 | + 'HKD', |
|
78 | + 'HUF', |
|
79 | + 'ILS', |
|
80 | + 'JPY', |
|
81 | + 'MYR', |
|
82 | + 'MXN', |
|
83 | + 'NOK', |
|
84 | + 'NZD', |
|
85 | + 'PHP', |
|
86 | + 'PLN', |
|
87 | + 'GBP', |
|
88 | + 'RUB', |
|
89 | + 'SGD', |
|
90 | + 'SEK', |
|
91 | + 'CHF', |
|
92 | + 'TWD', |
|
93 | + 'THB', |
|
94 | + 'TRY', |
|
95 | + ); |
|
96 | + parent::__construct(); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
103 | + * |
|
104 | + * @param array $settings_array |
|
105 | + */ |
|
106 | + public function set_settings($settings_array) |
|
107 | + { |
|
108 | + parent::set_settings($settings_array); |
|
109 | + // Redirect URL. |
|
110 | + $this->_base_gateway_url = $this->_debug_mode |
|
111 | + ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
112 | + : 'https://api-3t.paypal.com/nvp'; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @param EEI_Payment $payment |
|
119 | + * @param array $billing_info |
|
120 | + * @param string $return_url |
|
121 | + * @param string $notify_url |
|
122 | + * @param string $cancel_url |
|
123 | + * @return \EE_Payment|\EEI_Payment |
|
124 | + * @throws \EE_Error |
|
125 | + */ |
|
126 | + public function set_redirection_info( |
|
127 | + $payment, |
|
128 | + $billing_info = array(), |
|
129 | + $return_url = null, |
|
130 | + $notify_url = null, |
|
131 | + $cancel_url = null |
|
132 | + ) { |
|
133 | + if (! $payment instanceof EEI_Payment) { |
|
134 | + $payment->set_gateway_response( |
|
135 | + __( |
|
136 | + 'Error. No associated payment was found.', |
|
137 | + 'event_espresso' |
|
138 | + ) |
|
139 | + ); |
|
140 | + $payment->set_status($this->_pay_model->failed_status()); |
|
141 | + return $payment; |
|
142 | + } |
|
143 | + $transaction = $payment->transaction(); |
|
144 | + if (! $transaction instanceof EEI_Transaction) { |
|
145 | + $payment->set_gateway_response( |
|
146 | + __( |
|
147 | + 'Could not process this payment because it has no associated transaction.', |
|
148 | + 'event_espresso' |
|
149 | + ) |
|
150 | + ); |
|
151 | + $payment->set_status($this->_pay_model->failed_status()); |
|
152 | + return $payment; |
|
153 | + } |
|
154 | + $order_description = substr($this->_format_order_description($payment), 0, 127); |
|
155 | + $primary_registration = $transaction->primary_registration(); |
|
156 | + $primary_attendee = $primary_registration instanceof EE_Registration |
|
157 | + ? $primary_registration->attendee() |
|
158 | + : false; |
|
159 | + $locale = explode('-', get_bloginfo('language')); |
|
160 | + // Gather request parameters. |
|
161 | + $token_request_dtls = array( |
|
162 | + 'METHOD' => 'SetExpressCheckout', |
|
163 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
164 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
165 | + 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
166 | + 'RETURNURL' => $return_url, |
|
167 | + 'CANCELURL' => $cancel_url, |
|
168 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
169 | + // Buyer does not need to create a PayPal account to check out. |
|
170 | + // This is referred to as PayPal Account Optional. |
|
171 | + 'SOLUTIONTYPE' => 'Sole', |
|
172 | + //EE will blow up if you change this |
|
173 | + 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
174 | + // Locale of the pages displayed by PayPal during Express Checkout. |
|
175 | + 'LOCALECODE' => $locale[1] |
|
176 | + ); |
|
177 | + // Show itemized list. |
|
178 | + if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
179 | + $item_num = 0; |
|
180 | + $itemized_sum = 0; |
|
181 | + $total_line_items = $transaction->total_line_item(); |
|
182 | + // Go through each item in the list. |
|
183 | + foreach ($total_line_items->get_items() as $line_item) { |
|
184 | + if ($line_item instanceof EE_Line_Item) { |
|
185 | + // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
186 | + if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
187 | + continue; |
|
188 | + } |
|
189 | + $unit_price = $line_item->unit_price(); |
|
190 | + $line_item_quantity = $line_item->quantity(); |
|
191 | + // This is a discount. |
|
192 | + if ($line_item->is_percent()) { |
|
193 | + $unit_price = $line_item->total(); |
|
194 | + $line_item_quantity = 1; |
|
195 | + } |
|
196 | + // Item Name. |
|
197 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME' . $item_num] = substr( |
|
198 | + $this->_format_line_item_name($line_item, $payment), |
|
199 | + 0, |
|
200 | + 127 |
|
201 | + ); |
|
202 | + // Item description. |
|
203 | + $token_request_dtls['L_PAYMENTREQUEST_0_DESC' . $item_num] = substr( |
|
204 | + $this->_format_line_item_desc($line_item, $payment), |
|
205 | + 0, |
|
206 | + 127 |
|
207 | + ); |
|
208 | + // Cost of individual item. |
|
209 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency($unit_price); |
|
210 | + // Item Number. |
|
211 | + $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1; |
|
212 | + // Item quantity. |
|
213 | + $token_request_dtls['L_PAYMENTREQUEST_0_QTY' . $item_num] = $line_item_quantity; |
|
214 | + // Digital item is sold. |
|
215 | + $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical'; |
|
216 | + $itemized_sum += $line_item->total(); |
|
217 | + ++$item_num; |
|
218 | + } |
|
219 | + } |
|
220 | + // Item's sales S/H and tax amount. |
|
221 | + $token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
222 | + $token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
223 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
224 | + $token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
225 | + $itemized_sum_diff_from_txn_total = round( |
|
226 | + $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
227 | + 2 |
|
228 | + ); |
|
229 | + // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
230 | + // add the difference as an extra line item. |
|
231 | + if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
232 | + // Item Name. |
|
233 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME' . $item_num] = substr( |
|
234 | + __( |
|
235 | + 'Other (promotion/surcharge/cancellation)', |
|
236 | + 'event_espresso' |
|
237 | + ), |
|
238 | + 0, |
|
239 | + 127 |
|
240 | + ); |
|
241 | + // Item description. |
|
242 | + $token_request_dtls['L_PAYMENTREQUEST_0_DESC' . $item_num] = ''; |
|
243 | + // Cost of individual item. |
|
244 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency( |
|
245 | + $itemized_sum_diff_from_txn_total |
|
246 | + ); |
|
247 | + // Item Number. |
|
248 | + $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1; |
|
249 | + // Item quantity. |
|
250 | + $token_request_dtls['L_PAYMENTREQUEST_0_QTY' . $item_num] = 1; |
|
251 | + // Digital item is sold. |
|
252 | + $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical'; |
|
253 | + $item_num++; |
|
254 | + } |
|
255 | + } else { |
|
256 | + // Just one Item. |
|
257 | + // Item Name. |
|
258 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr( |
|
259 | + $this->_format_partial_payment_line_item_name($payment), |
|
260 | + 0, |
|
261 | + 127 |
|
262 | + ); |
|
263 | + // Item description. |
|
264 | + $token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr( |
|
265 | + $this->_format_partial_payment_line_item_desc($payment), |
|
266 | + 0, |
|
267 | + 127 |
|
268 | + ); |
|
269 | + // Cost of individual item. |
|
270 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency($payment->amount()); |
|
271 | + // Item Number. |
|
272 | + $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
273 | + // Item quantity. |
|
274 | + $token_request_dtls['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
275 | + // Digital item is sold. |
|
276 | + $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
277 | + // Item's sales S/H and tax amount. |
|
278 | + $token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency($payment->amount()); |
|
279 | + $token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
280 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
281 | + $token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
282 | + } |
|
283 | + // Automatically filling out shipping and contact information. |
|
284 | + if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
285 | + // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
286 | + $token_request_dtls['NOSHIPPING'] = '2'; |
|
287 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
288 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
289 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
290 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
291 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
292 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
293 | + $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
294 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
295 | + } elseif (! $this->_request_shipping_addr) { |
|
296 | + // Do not request shipping details on the PP Checkout page. |
|
297 | + $token_request_dtls['NOSHIPPING'] = '1'; |
|
298 | + $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
299 | + } |
|
300 | + // Used a business/personal logo on the PayPal page. |
|
301 | + if (! empty($this->_image_url)) { |
|
302 | + $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
303 | + } |
|
304 | + $token_request_dtls = apply_filters( |
|
305 | + 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
306 | + $token_request_dtls, |
|
307 | + $this |
|
308 | + ); |
|
309 | + // Request PayPal token. |
|
310 | + $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
311 | + $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
312 | + $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
313 | + ? $token_rstatus['args'] |
|
314 | + : array(); |
|
315 | + if ($token_rstatus['status']) { |
|
316 | + // We got the Token so we may continue with the payment and redirect the client. |
|
317 | + $payment->set_details($response_args); |
|
318 | + $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
319 | + $payment->set_redirect_url( |
|
320 | + $gateway_url |
|
321 | + . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
322 | + . $response_args['TOKEN'] |
|
323 | + ); |
|
324 | + } else { |
|
325 | + if (isset($response_args['L_ERRORCODE'])) { |
|
326 | + $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
327 | + } else { |
|
328 | + $payment->set_gateway_response( |
|
329 | + esc_html__( |
|
330 | + 'Error occurred while trying to setup the Express Checkout.', |
|
331 | + 'event_espresso' |
|
332 | + ) |
|
333 | + ); |
|
334 | + } |
|
335 | + $payment->set_details($response_args); |
|
336 | + $payment->set_status($this->_pay_model->failed_status()); |
|
337 | + } |
|
338 | + return $payment; |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * @param array $update_info { |
|
345 | + * @type string $gateway_txn_id |
|
346 | + * @type string status an EEMI_Payment status |
|
347 | + * } |
|
348 | + * @param EEI_Transaction $transaction |
|
349 | + * @return EEI_Payment |
|
350 | + */ |
|
351 | + public function handle_payment_update($update_info, $transaction) |
|
352 | + { |
|
353 | + $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
354 | + if ($payment instanceof EEI_Payment) { |
|
355 | + $this->log(array('Return from Authorization' => $update_info), $payment); |
|
356 | + $transaction = $payment->transaction(); |
|
357 | + if (! $transaction instanceof EEI_Transaction) { |
|
358 | + $payment->set_gateway_response( |
|
359 | + __( |
|
360 | + 'Could not process this payment because it has no associated transaction.', |
|
361 | + 'event_espresso' |
|
362 | + ) |
|
363 | + ); |
|
364 | + $payment->set_status($this->_pay_model->failed_status()); |
|
365 | + return $payment; |
|
366 | + } |
|
367 | + $primary_registrant = $transaction->primary_registration(); |
|
368 | + $payment_details = $payment->details(); |
|
369 | + // Check if we still have the token. |
|
370 | + if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
371 | + $payment->set_status($this->_pay_model->failed_status()); |
|
372 | + return $payment; |
|
373 | + } |
|
374 | + $cdetails_request_dtls = array( |
|
375 | + 'METHOD' => 'GetExpressCheckoutDetails', |
|
376 | + 'TOKEN' => $payment_details['TOKEN'], |
|
377 | + ); |
|
378 | + // Request Customer Details. |
|
379 | + $cdetails_request_response = $this->_ppExpress_request( |
|
380 | + $cdetails_request_dtls, |
|
381 | + 'Customer Details', |
|
382 | + $payment |
|
383 | + ); |
|
384 | + $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
385 | + $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
386 | + ? $cdetails_rstatus['args'] |
|
387 | + : array(); |
|
388 | + if ($cdetails_rstatus['status']) { |
|
389 | + // We got the PayerID so now we can Complete the transaction. |
|
390 | + $docheckout_request_dtls = array( |
|
391 | + 'METHOD' => 'DoExpressCheckoutPayment', |
|
392 | + 'PAYERID' => $cdata_response_args['PAYERID'], |
|
393 | + 'TOKEN' => $payment_details['TOKEN'], |
|
394 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
395 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
396 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
397 | + ); |
|
398 | + // Payment Checkout/Capture. |
|
399 | + $docheckout_request_response = $this->_ppExpress_request( |
|
400 | + $docheckout_request_dtls, |
|
401 | + 'Do Payment', |
|
402 | + $payment |
|
403 | + ); |
|
404 | + $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
405 | + $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
406 | + ? $docheckout_rstatus['args'] |
|
407 | + : array(); |
|
408 | + if ($docheckout_rstatus['status']) { |
|
409 | + // All is well, payment approved. |
|
410 | + $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
411 | + $primary_registrant->reg_code() |
|
412 | + : ''; |
|
413 | + $payment->set_extra_accntng($primary_registration_code); |
|
414 | + $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
415 | + ? (float)$docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
416 | + : 0); |
|
417 | + $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
418 | + ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
419 | + : null); |
|
420 | + $payment->set_details($cdata_response_args); |
|
421 | + $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
422 | + ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
423 | + : ''); |
|
424 | + $payment->set_status($this->_pay_model->approved_status()); |
|
425 | + } else { |
|
426 | + if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
427 | + $payment->set_gateway_response( |
|
428 | + $docheckout_response_args['L_ERRORCODE'] |
|
429 | + . '; ' |
|
430 | + . $docheckout_response_args['L_SHORTMESSAGE'] |
|
431 | + ); |
|
432 | + } else { |
|
433 | + $payment->set_gateway_response( |
|
434 | + __( |
|
435 | + 'Error occurred while trying to Capture the funds.', |
|
436 | + 'event_espresso' |
|
437 | + ) |
|
438 | + ); |
|
439 | + } |
|
440 | + $payment->set_details($docheckout_response_args); |
|
441 | + $payment->set_status($this->_pay_model->declined_status()); |
|
442 | + } |
|
443 | + } else { |
|
444 | + if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
445 | + $payment->set_gateway_response( |
|
446 | + $cdata_response_args['L_ERRORCODE'] |
|
447 | + . '; ' |
|
448 | + . $cdata_response_args['L_SHORTMESSAGE'] |
|
449 | + ); |
|
450 | + } else { |
|
451 | + $payment->set_gateway_response( |
|
452 | + __( |
|
453 | + 'Error occurred while trying to get payment Details from PayPal.', |
|
454 | + 'event_espresso' |
|
455 | + ) |
|
456 | + ); |
|
457 | + } |
|
458 | + $payment->set_details($cdata_response_args); |
|
459 | + $payment->set_status($this->_pay_model->failed_status()); |
|
460 | + } |
|
461 | + } else { |
|
462 | + $payment->set_gateway_response(__('Error occurred while trying to process the payment.', 'event_espresso')); |
|
463 | + $payment->set_status($this->_pay_model->failed_status()); |
|
464 | + } |
|
465 | + return $payment; |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * Make the Express checkout request. |
|
472 | + * |
|
473 | + * @param array $request_params |
|
474 | + * @param string $request_text |
|
475 | + * @param EEI_Payment $payment |
|
476 | + * @return mixed |
|
477 | + */ |
|
478 | + public function _ppExpress_request($request_params, $request_text, $payment) |
|
479 | + { |
|
480 | + $request_dtls = array( |
|
481 | + 'VERSION' => '204.0', |
|
482 | + 'USER' => urlencode($this->_api_username), |
|
483 | + 'PWD' => urlencode($this->_api_password), |
|
484 | + 'SIGNATURE' => urlencode($this->_api_signature), |
|
485 | + ); |
|
486 | + $dtls = array_merge($request_dtls, $request_params); |
|
487 | + $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
488 | + // Request Customer Details. |
|
489 | + $request_response = wp_remote_post( |
|
490 | + $this->_base_gateway_url, |
|
491 | + array( |
|
492 | + 'method' => 'POST', |
|
493 | + 'timeout' => 45, |
|
494 | + 'httpversion' => '1.1', |
|
495 | + 'cookies' => array(), |
|
496 | + 'headers' => array(), |
|
497 | + 'body' => http_build_query($dtls), |
|
498 | + ) |
|
499 | + ); |
|
500 | + // Log the response. |
|
501 | + $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
502 | + return $request_response; |
|
503 | + } |
|
504 | + |
|
505 | + |
|
506 | + |
|
507 | + /** |
|
508 | + * Check the response status. |
|
509 | + * |
|
510 | + * @param mixed $request_response |
|
511 | + * @return array |
|
512 | + */ |
|
513 | + public function _ppExpress_check_response($request_response) |
|
514 | + { |
|
515 | + if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
516 | + // If we got here then there was an error in this request. |
|
517 | + return array('status' => false, 'args' => $request_response); |
|
518 | + } |
|
519 | + $response_args = array(); |
|
520 | + parse_str(urldecode($request_response['body']), $response_args); |
|
521 | + if (! isset($response_args['ACK'])) { |
|
522 | + return array('status' => false, 'args' => $request_response); |
|
523 | + } |
|
524 | + if ( |
|
525 | + ( |
|
526 | + isset($response_args['PAYERID']) |
|
527 | + || isset($response_args['TOKEN']) |
|
528 | + || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
529 | + || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
530 | + ) |
|
531 | + && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
532 | + ) { |
|
533 | + // Response status OK, return response parameters for further processing. |
|
534 | + return array('status' => true, 'args' => $response_args); |
|
535 | + } |
|
536 | + $errors = $this->_get_errors($response_args); |
|
537 | + return array('status' => false, 'args' => $errors); |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + |
|
542 | + /** |
|
543 | + * Log a "Cleared" request. |
|
544 | + * |
|
545 | + * @param array $request |
|
546 | + * @param EEI_Payment $payment |
|
547 | + * @param string $info |
|
548 | + * @return void |
|
549 | + */ |
|
550 | + private function _log_clean_request($request, $payment, $info) |
|
551 | + { |
|
552 | + $cleaned_request_data = $request; |
|
553 | + unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
554 | + $this->log(array($info => $cleaned_request_data), $payment); |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * Get error from the response data. |
|
561 | + * |
|
562 | + * @param array $data_array |
|
563 | + * @return array |
|
564 | + */ |
|
565 | + private function _get_errors($data_array) |
|
566 | + { |
|
567 | + $errors = array(); |
|
568 | + $n = 0; |
|
569 | + while (isset($data_array["L_ERRORCODE{$n}"])) { |
|
570 | + $l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
|
571 | + ? $data_array["L_ERRORCODE{$n}"] |
|
572 | + : ''; |
|
573 | + $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"]) |
|
574 | + ? $data_array["L_SEVERITYCODE{$n}"] |
|
575 | + : ''; |
|
576 | + $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"]) |
|
577 | + ? $data_array["L_SHORTMESSAGE{$n}"] |
|
578 | + : ''; |
|
579 | + $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"]) |
|
580 | + ? $data_array["L_LONGMESSAGE{$n}"] |
|
581 | + : ''; |
|
582 | + if ($n === 0) { |
|
583 | + $errors = array( |
|
584 | + 'L_ERRORCODE' => $l_error_code, |
|
585 | + 'L_SHORTMESSAGE' => $l_short_message, |
|
586 | + 'L_LONGMESSAGE' => $l_long_message, |
|
587 | + 'L_SEVERITYCODE' => $l_severity_code, |
|
588 | + ); |
|
589 | + } else { |
|
590 | + $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
591 | + $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
592 | + $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
593 | + $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
594 | + } |
|
595 | + $n++; |
|
596 | + } |
|
597 | + return $errors; |
|
598 | + } |
|
599 | 599 | |
600 | 600 | } |
601 | 601 | // End of file EEG_Paypal_Express.gateway.php |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('NO direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | $notify_url = null, |
131 | 131 | $cancel_url = null |
132 | 132 | ) { |
133 | - if (! $payment instanceof EEI_Payment) { |
|
133 | + if ( ! $payment instanceof EEI_Payment) { |
|
134 | 134 | $payment->set_gateway_response( |
135 | 135 | __( |
136 | 136 | 'Error. No associated payment was found.', |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | return $payment; |
142 | 142 | } |
143 | 143 | $transaction = $payment->transaction(); |
144 | - if (! $transaction instanceof EEI_Transaction) { |
|
144 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
145 | 145 | $payment->set_gateway_response( |
146 | 146 | __( |
147 | 147 | 'Could not process this payment because it has no associated transaction.', |
@@ -194,25 +194,25 @@ discard block |
||
194 | 194 | $line_item_quantity = 1; |
195 | 195 | } |
196 | 196 | // Item Name. |
197 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME' . $item_num] = substr( |
|
197 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr( |
|
198 | 198 | $this->_format_line_item_name($line_item, $payment), |
199 | 199 | 0, |
200 | 200 | 127 |
201 | 201 | ); |
202 | 202 | // Item description. |
203 | - $token_request_dtls['L_PAYMENTREQUEST_0_DESC' . $item_num] = substr( |
|
203 | + $token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = substr( |
|
204 | 204 | $this->_format_line_item_desc($line_item, $payment), |
205 | 205 | 0, |
206 | 206 | 127 |
207 | 207 | ); |
208 | 208 | // Cost of individual item. |
209 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency($unit_price); |
|
209 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency($unit_price); |
|
210 | 210 | // Item Number. |
211 | - $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1; |
|
211 | + $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
|
212 | 212 | // Item quantity. |
213 | - $token_request_dtls['L_PAYMENTREQUEST_0_QTY' . $item_num] = $line_item_quantity; |
|
213 | + $token_request_dtls['L_PAYMENTREQUEST_0_QTY'.$item_num] = $line_item_quantity; |
|
214 | 214 | // Digital item is sold. |
215 | - $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical'; |
|
215 | + $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
216 | 216 | $itemized_sum += $line_item->total(); |
217 | 217 | ++$item_num; |
218 | 218 | } |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | // add the difference as an extra line item. |
231 | 231 | if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
232 | 232 | // Item Name. |
233 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME' . $item_num] = substr( |
|
233 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr( |
|
234 | 234 | __( |
235 | 235 | 'Other (promotion/surcharge/cancellation)', |
236 | 236 | 'event_espresso' |
@@ -239,17 +239,17 @@ discard block |
||
239 | 239 | 127 |
240 | 240 | ); |
241 | 241 | // Item description. |
242 | - $token_request_dtls['L_PAYMENTREQUEST_0_DESC' . $item_num] = ''; |
|
242 | + $token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = ''; |
|
243 | 243 | // Cost of individual item. |
244 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT' . $item_num] = $this->format_currency( |
|
244 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( |
|
245 | 245 | $itemized_sum_diff_from_txn_total |
246 | 246 | ); |
247 | 247 | // Item Number. |
248 | - $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER' . $item_num] = $item_num + 1; |
|
248 | + $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
|
249 | 249 | // Item quantity. |
250 | - $token_request_dtls['L_PAYMENTREQUEST_0_QTY' . $item_num] = 1; |
|
250 | + $token_request_dtls['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1; |
|
251 | 251 | // Digital item is sold. |
252 | - $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num] = 'Physical'; |
|
252 | + $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
253 | 253 | $item_num++; |
254 | 254 | } |
255 | 255 | } else { |
@@ -292,13 +292,13 @@ discard block |
||
292 | 292 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
293 | 293 | $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
294 | 294 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
295 | - } elseif (! $this->_request_shipping_addr) { |
|
295 | + } elseif ( ! $this->_request_shipping_addr) { |
|
296 | 296 | // Do not request shipping details on the PP Checkout page. |
297 | 297 | $token_request_dtls['NOSHIPPING'] = '1'; |
298 | 298 | $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
299 | 299 | } |
300 | 300 | // Used a business/personal logo on the PayPal page. |
301 | - if (! empty($this->_image_url)) { |
|
301 | + if ( ! empty($this->_image_url)) { |
|
302 | 302 | $token_request_dtls['LOGOIMG'] = $this->_image_url; |
303 | 303 | } |
304 | 304 | $token_request_dtls = apply_filters( |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | ); |
324 | 324 | } else { |
325 | 325 | if (isset($response_args['L_ERRORCODE'])) { |
326 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
326 | + $payment->set_gateway_response($response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE']); |
|
327 | 327 | } else { |
328 | 328 | $payment->set_gateway_response( |
329 | 329 | esc_html__( |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | if ($payment instanceof EEI_Payment) { |
355 | 355 | $this->log(array('Return from Authorization' => $update_info), $payment); |
356 | 356 | $transaction = $payment->transaction(); |
357 | - if (! $transaction instanceof EEI_Transaction) { |
|
357 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
358 | 358 | $payment->set_gateway_response( |
359 | 359 | __( |
360 | 360 | 'Could not process this payment because it has no associated transaction.', |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | $primary_registrant = $transaction->primary_registration(); |
368 | 368 | $payment_details = $payment->details(); |
369 | 369 | // Check if we still have the token. |
370 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
370 | + if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
371 | 371 | $payment->set_status($this->_pay_model->failed_status()); |
372 | 372 | return $payment; |
373 | 373 | } |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | : ''; |
413 | 413 | $payment->set_extra_accntng($primary_registration_code); |
414 | 414 | $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
415 | - ? (float)$docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
415 | + ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
416 | 416 | : 0); |
417 | 417 | $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
418 | 418 | ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
@@ -484,7 +484,7 @@ discard block |
||
484 | 484 | 'SIGNATURE' => urlencode($this->_api_signature), |
485 | 485 | ); |
486 | 486 | $dtls = array_merge($request_dtls, $request_params); |
487 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
487 | + $this->_log_clean_request($dtls, $payment, $request_text.' Request'); |
|
488 | 488 | // Request Customer Details. |
489 | 489 | $request_response = wp_remote_post( |
490 | 490 | $this->_base_gateway_url, |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | ) |
499 | 499 | ); |
500 | 500 | // Log the response. |
501 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
501 | + $this->log(array($request_text.' Response' => $request_response), $payment); |
|
502 | 502 | return $request_response; |
503 | 503 | } |
504 | 504 | |
@@ -518,7 +518,7 @@ discard block |
||
518 | 518 | } |
519 | 519 | $response_args = array(); |
520 | 520 | parse_str(urldecode($request_response['body']), $response_args); |
521 | - if (! isset($response_args['ACK'])) { |
|
521 | + if ( ! isset($response_args['ACK'])) { |
|
522 | 522 | return array('status' => false, 'args' => $request_response); |
523 | 523 | } |
524 | 524 | if ( |
@@ -587,10 +587,10 @@ discard block |
||
587 | 587 | 'L_SEVERITYCODE' => $l_severity_code, |
588 | 588 | ); |
589 | 589 | } else { |
590 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
591 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
592 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
593 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
590 | + $errors['L_ERRORCODE'] .= ', '.$l_error_code; |
|
591 | + $errors['L_SHORTMESSAGE'] .= ', '.$l_short_message; |
|
592 | + $errors['L_LONGMESSAGE'] .= ', '.$l_long_message; |
|
593 | + $errors['L_SEVERITYCODE'] .= ', '.$l_severity_code; |
|
594 | 594 | } |
595 | 595 | $n++; |
596 | 596 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php echo esc_html__( |
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.47.rc.043'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.47.rc.043'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |