@@ -505,7 +505,7 @@ |
||
505 | 505 | * |
506 | 506 | * @param string $value string to evaluate |
507 | 507 | * @param array $valid_shortcodes array of shortcodes that are acceptable. |
508 | - * @return mixed (bool|string) return either a list of invalid shortcodes OR false if the shortcodes validate. |
|
508 | + * @return false|string (bool|string) return either a list of invalid shortcodes OR false if the shortcodes validate. |
|
509 | 509 | */ |
510 | 510 | protected function _invalid_shortcodes($value, $valid_shortcodes) |
511 | 511 | { |
@@ -18,626 +18,626 @@ |
||
18 | 18 | { |
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * These properties just hold the name for the Messenger and Message Type (defined by child classes). |
|
23 | - * These are used for retrieving objects etc. |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - protected $_m_name; |
|
28 | - protected $_mt_name; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * This will hold any error messages from the validation process. |
|
33 | - * The _errors property holds an associative array of error messages |
|
34 | - * listing the field as the key and the message as the value. |
|
35 | - * |
|
36 | - * @var array() |
|
37 | - */ |
|
38 | - private $_errors = array(); |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * holds an array of fields being validated |
|
43 | - * |
|
44 | - * @var array |
|
45 | - */ |
|
46 | - protected $_fields; |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * this will hold the incoming context |
|
51 | - * |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $_context; |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * this holds an array of fields and the relevant validation information |
|
59 | - * that the incoming fields data get validated against. |
|
60 | - * This gets setup in the _set_props() method. |
|
61 | - * |
|
62 | - * @var array |
|
63 | - */ |
|
64 | - protected $_validators; |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * holds the messenger object |
|
69 | - * |
|
70 | - * @var object |
|
71 | - */ |
|
72 | - protected $_messenger; |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * holds the message type object |
|
77 | - * |
|
78 | - * @var object |
|
79 | - */ |
|
80 | - protected $_message_type; |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * will hold any valid_shortcode modifications made by the _modify_validator() method. |
|
85 | - * |
|
86 | - * @var array |
|
87 | - */ |
|
88 | - protected $_valid_shortcodes_modifier; |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * There may be times where a message type wants to include a shortcode group but exclude specific |
|
93 | - * shortcodes. If that's the case then it can set this property as an array of shortcodes to exclude and |
|
94 | - * they will not be allowed. |
|
95 | - * Array should be indexed by field and values are an array of specific shortcodes to exclude. |
|
96 | - * |
|
97 | - * @var array |
|
98 | - */ |
|
99 | - protected $_specific_shortcode_excludes = array(); |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * Runs the validator using the incoming fields array as the fields/values to check. |
|
104 | - * |
|
105 | - * @param array $fields The fields sent by the EEM object. |
|
106 | - * @param $context |
|
107 | - * @throws EE_Error |
|
108 | - * @throws ReflectionException |
|
109 | - */ |
|
110 | - public function __construct($fields, $context) |
|
111 | - { |
|
112 | - // check that _m_name and _mt_name have been set by child class otherwise we get out. |
|
113 | - if (empty($this->_m_name) || empty($this->_mt_name)) { |
|
114 | - throw new EE_Error( |
|
115 | - esc_html__( |
|
116 | - 'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property. Check that the child class is doing this', |
|
117 | - 'event_espresso' |
|
118 | - ) |
|
119 | - ); |
|
120 | - } |
|
121 | - $this->_fields = $fields; |
|
122 | - $this->_context = $context; |
|
123 | - |
|
124 | - // load messenger and message_type objects and the related shortcode objects. |
|
125 | - $this->_load_objects(); |
|
126 | - |
|
127 | - |
|
128 | - // modify any messenger/message_type specific validation instructions. This is what child classes define. |
|
129 | - $this->_modify_validator(); |
|
130 | - |
|
131 | - |
|
132 | - // let's set validators property |
|
133 | - $this->_set_validators(); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * Child classes instantiate this and use it to modify the _validator_config array property |
|
139 | - * for the messenger using messengers set_validate_config() method. |
|
140 | - * This is so we can specify specific validation instructions for a messenger/message_type combo |
|
141 | - * that aren't handled by the defaults setup in the messenger. |
|
142 | - * |
|
143 | - * @abstract |
|
144 | - * @access protected |
|
145 | - * @return void |
|
146 | - */ |
|
147 | - abstract protected function _modify_validator(); |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * loads all objects used by validator |
|
152 | - * |
|
153 | - * @access private |
|
154 | - * @throws \EE_Error |
|
155 | - */ |
|
156 | - private function _load_objects() |
|
157 | - { |
|
158 | - // load messenger |
|
159 | - $messenger = ucwords(str_replace('_', ' ', $this->_m_name)); |
|
160 | - $messenger = str_replace(' ', '_', $messenger); |
|
161 | - $messenger = 'EE_' . $messenger . '_messenger'; |
|
162 | - |
|
163 | - if (! class_exists($messenger)) { |
|
164 | - throw new EE_Error( |
|
165 | - sprintf( |
|
166 | - esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'), |
|
167 | - $this->_m_name |
|
168 | - ) |
|
169 | - ); |
|
170 | - } |
|
171 | - |
|
172 | - $this->_messenger = new $messenger(); |
|
173 | - |
|
174 | - // load message type |
|
175 | - $message_type = ucwords(str_replace('_', ' ', $this->_mt_name)); |
|
176 | - $message_type = str_replace(' ', '_', $message_type); |
|
177 | - $message_type = 'EE_' . $message_type . '_message_type'; |
|
178 | - |
|
179 | - if (! class_exists($message_type)) { |
|
180 | - throw new EE_Error( |
|
181 | - sprintf( |
|
182 | - esc_html__('There is no message type class for the given string (%s)', 'event_espresso'), |
|
183 | - $this->_mt_name |
|
184 | - ) |
|
185 | - ); |
|
186 | - } |
|
187 | - |
|
188 | - $this->_message_type = new $message_type(); |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * used to set the $_validators property |
|
194 | - * |
|
195 | - * @access private |
|
196 | - * @return void |
|
197 | - * @throws ReflectionException |
|
198 | - */ |
|
199 | - private function _set_validators() |
|
200 | - { |
|
201 | - // let's get all valid shortcodes from mt and message type |
|
202 | - // (messenger will have its set in the _validator_config property for the messenger) |
|
203 | - $mt_codes = $this->_message_type->get_valid_shortcodes(); |
|
204 | - |
|
205 | - |
|
206 | - // get messenger validator_config |
|
207 | - $msgr_validator = $this->_messenger->get_validator_config(); |
|
208 | - |
|
209 | - |
|
210 | - // we only want the valid shortcodes for the given context! |
|
211 | - $context = $this->_context; |
|
212 | - $mt_codes = $mt_codes[ $context ]; |
|
213 | - |
|
214 | - // in this first loop we're just getting all shortcode group indexes from the msgr_validator |
|
215 | - // into a single array (so we can get the appropriate shortcode objects for the groups) |
|
216 | - $shortcode_groups = $mt_codes; |
|
217 | - $groups_per_field = array(); |
|
218 | - |
|
219 | - foreach ($msgr_validator as $field => $config) { |
|
220 | - if (empty($config) || ! isset($config['shortcodes'])) { |
|
221 | - continue; |
|
222 | - } //Nothing to see here. |
|
223 | - $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes); |
|
224 | - $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups); |
|
225 | - } |
|
226 | - |
|
227 | - $shortcode_groups = array_unique($shortcode_groups); |
|
228 | - |
|
229 | - // okay now we've got our groups. |
|
230 | - // Let's get the codes from the objects into an array indexed by group for easy retrieval later. |
|
231 | - $codes_from_objs = array(); |
|
232 | - |
|
233 | - foreach ($shortcode_groups as $group) { |
|
234 | - $ref = ucwords(str_replace('_', ' ', $group)); |
|
235 | - $ref = str_replace(' ', '_', $ref); |
|
236 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
237 | - if (class_exists($classname)) { |
|
238 | - $a = new ReflectionClass($classname); |
|
239 | - $obj = $a->newInstance(); |
|
240 | - $codes_from_objs[ $group ] = $obj->get_shortcodes(); |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique) |
|
246 | - $final_mt_codes = array(); |
|
247 | - foreach ($mt_codes as $group) { |
|
248 | - $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]); |
|
249 | - } |
|
250 | - |
|
251 | - $mt_codes = $final_mt_codes; |
|
252 | - |
|
253 | - |
|
254 | - // k now in this next loop we're going to loop through $msgr_validator again |
|
255 | - // and setup the _validators property from the data we've setup so far. |
|
256 | - foreach ($msgr_validator as $field => $config) { |
|
257 | - // if required shortcode is not in our list of codes for the given field, then we skip this field. |
|
258 | - $required = isset($config['required']) |
|
259 | - ? array_intersect($config['required'], array_keys($mt_codes)) |
|
260 | - : true; |
|
261 | - if (empty($required)) { |
|
262 | - continue; |
|
263 | - } |
|
264 | - |
|
265 | - // If we have an override then we use it to indicate the codes we want. |
|
266 | - if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) { |
|
267 | - $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
268 | - $this->_valid_shortcodes_modifier[ $context ][ $field ], |
|
269 | - $codes_from_objs |
|
270 | - ); |
|
271 | - } //if we have specific shortcodes for a field then we need to use them |
|
272 | - elseif (isset($groups_per_field[ $field ])) { |
|
273 | - $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
274 | - $groups_per_field[ $field ], |
|
275 | - $codes_from_objs |
|
276 | - ); |
|
277 | - } //if empty config then we're assuming we're just going to use the shortcodes from the message type context |
|
278 | - elseif (empty($config)) { |
|
279 | - $this->_validators[ $field ]['shortcodes'] = $mt_codes; |
|
280 | - } //if we have specific shortcodes then we need to use them |
|
281 | - elseif (isset($config['specific_shortcodes'])) { |
|
282 | - $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes']; |
|
283 | - } //otherwise the shortcodes are what is set by the messenger for that field |
|
284 | - else { |
|
285 | - foreach ($config['shortcodes'] as $group) { |
|
286 | - $this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes']) |
|
287 | - ? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ]) |
|
288 | - : $codes_from_objs[ $group ]; |
|
289 | - } |
|
290 | - } |
|
291 | - |
|
292 | - // now let's just make sure that any excluded specific shortcodes are removed. |
|
293 | - $specific_excludes = $this->get_specific_shortcode_excludes(); |
|
294 | - if (isset($specific_excludes[ $field ])) { |
|
295 | - foreach ($specific_excludes[ $field ] as $sex) { |
|
296 | - if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) { |
|
297 | - unset($this->_validators[ $field ]['shortcodes'][ $sex ]); |
|
298 | - } |
|
299 | - } |
|
300 | - } |
|
301 | - |
|
302 | - // hey! don't forget to include the type if present! |
|
303 | - $this->_validators[ $field ]['type'] = isset($config['type']) ? $config['type'] : null; |
|
304 | - } |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * This just returns the validators property that contains information |
|
310 | - * about the various shortcodes and their availability with each field |
|
311 | - * |
|
312 | - * @return array |
|
313 | - */ |
|
314 | - public function get_validators() |
|
315 | - { |
|
316 | - return $this->_validators; |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * This simply returns the specific shortcode_excludes property that is set. |
|
322 | - * |
|
323 | - * @since 4.5.0 |
|
324 | - * @return array |
|
325 | - */ |
|
326 | - public function get_specific_shortcode_excludes() |
|
327 | - { |
|
328 | - // specific validator filter |
|
329 | - $shortcode_excludes = apply_filters( |
|
330 | - 'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;', |
|
331 | - $this->_specific_shortcode_excludes, |
|
332 | - $this->_context |
|
333 | - ); |
|
334 | - // global filter |
|
335 | - return apply_filters( |
|
336 | - 'FHEE__EE_Messages_Validator__get_specific_shortcode_excludes', |
|
337 | - $shortcode_excludes, |
|
338 | - $this->_context, |
|
339 | - $this |
|
340 | - ); |
|
341 | - } |
|
342 | - |
|
343 | - |
|
344 | - /** |
|
345 | - * This is the main method that handles validation |
|
346 | - * What it does is loop through the _fields (the ones that get validated) |
|
347 | - * and checks them against the shortcodes array for the field and the 'type' indicated by the |
|
348 | - * |
|
349 | - * @access public |
|
350 | - * @return mixed (bool|array) if errors present we return the array otherwise true |
|
351 | - */ |
|
352 | - public function validate() |
|
353 | - { |
|
354 | - // some defaults |
|
355 | - $template_fields = $this->_messenger->get_template_fields(); |
|
356 | - // loop through the fields and check! |
|
357 | - foreach ($this->_fields as $field => $value) { |
|
358 | - $this->_errors[ $field ] = array(); |
|
359 | - $err_msg = ''; |
|
360 | - $field_label = ''; |
|
361 | - // if field is not present in the _validators array then we continue |
|
362 | - if (! isset($this->_validators[ $field ])) { |
|
363 | - unset($this->_errors[ $field ]); |
|
364 | - continue; |
|
365 | - } |
|
366 | - |
|
367 | - // get the translated field label! |
|
368 | - // first check if it's in the main fields list |
|
369 | - if (isset($template_fields[ $field ])) { |
|
370 | - if (empty($template_fields[ $field ])) { |
|
371 | - $field_label = $field; |
|
372 | - } //most likely the field is found in the 'extra' array. |
|
373 | - else { |
|
374 | - $field_label = $template_fields[ $field ]['label']; |
|
375 | - } |
|
376 | - } |
|
377 | - |
|
378 | - // if field label is empty OR is equal to the current field |
|
379 | - // then we need to loop through the 'extra' fields in the template_fields config (if present) |
|
380 | - if (isset($template_fields['extra']) && (empty($field_label) || $field_label === $field)) { |
|
381 | - foreach ($template_fields['extra'] as $main_field => $secondary_field) { |
|
382 | - foreach ($secondary_field as $name => $values) { |
|
383 | - if ($name === $field) { |
|
384 | - $field_label = $values['label']; |
|
385 | - } |
|
386 | - |
|
387 | - // if we've got a 'main' secondary field, let's see if that matches what field we're on |
|
388 | - // which means it contains the label for this field. |
|
389 | - if ($name === 'main' && $main_field === $field_label) { |
|
390 | - $field_label = $values['label']; |
|
391 | - } |
|
392 | - } |
|
393 | - } |
|
394 | - } |
|
395 | - |
|
396 | - // field is present. Let's validate shortcodes first (but only if shortcodes present). |
|
397 | - if (isset($this->_validators[ $field ]['shortcodes']) |
|
398 | - && ! empty($this->_validators[ $field ]['shortcodes']) |
|
399 | - ) { |
|
400 | - $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']); |
|
401 | - // if true then that means there is a returned error message |
|
402 | - // that we'll need to add to the _errors array for this field. |
|
403 | - if ($invalid_shortcodes) { |
|
404 | - $v_s = array_keys($this->_validators[ $field ]['shortcodes']); |
|
405 | - $err_msg = sprintf( |
|
406 | - esc_html__( |
|
407 | - '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s', |
|
408 | - 'event_espresso' |
|
409 | - ), |
|
410 | - '<strong>' . $field_label . '</strong>', |
|
411 | - $invalid_shortcodes, |
|
412 | - '<p>', |
|
413 | - '</p >' |
|
414 | - ); |
|
415 | - $err_msg .= sprintf( |
|
416 | - esc_html__('%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso'), |
|
417 | - implode(', ', $v_s), |
|
418 | - '<strong>', |
|
419 | - '</strong>' |
|
420 | - ); |
|
421 | - } |
|
422 | - } |
|
423 | - |
|
424 | - // if there's a "type" to be validated then let's do that too. |
|
425 | - if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) { |
|
426 | - switch ($this->_validators[ $field ]['type']) { |
|
427 | - case 'number': |
|
428 | - if (! is_numeric($value)) { |
|
429 | - $err_msg .= sprintf( |
|
430 | - esc_html__( |
|
431 | - '%3$sThe %1$s field is supposed to be a number. The value given (%2$s) is not. Please double-check and make sure the field contains a number%4$s', |
|
432 | - 'event_espresso' |
|
433 | - ), |
|
434 | - $field_label, |
|
435 | - $value, |
|
436 | - '<p>', |
|
437 | - '</p >' |
|
438 | - ); |
|
439 | - } |
|
440 | - break; |
|
441 | - case 'email': |
|
442 | - $valid_email = $this->_validate_email($value); |
|
443 | - if (! $valid_email) { |
|
444 | - $err_msg .= htmlentities( |
|
445 | - sprintf( |
|
446 | - esc_html__( |
|
447 | - 'The %1$s field has at least one string that is not a valid email address record. Valid emails are in the format: "Name <[email protected]>" or "[email protected]" and multiple emails can be separated by a comma.', |
|
448 | - 'event_espresso' |
|
449 | - ), |
|
450 | - $field_label |
|
451 | - ) |
|
452 | - ); |
|
453 | - } |
|
454 | - break; |
|
455 | - default: |
|
456 | - break; |
|
457 | - } |
|
458 | - } |
|
459 | - |
|
460 | - // if $err_msg isn't empty let's setup the _errors array for this field. |
|
461 | - if (! empty($err_msg)) { |
|
462 | - $this->_errors[ $field ]['msg'] = $err_msg; |
|
463 | - } else { |
|
464 | - unset($this->_errors[ $field ]); |
|
465 | - } |
|
466 | - } |
|
467 | - |
|
468 | - // if we have ANY errors, then we want to make sure we return the values |
|
469 | - // for ALL the fields so the user doesn't have to retype them all. |
|
470 | - if (! empty($this->_errors)) { |
|
471 | - foreach ($this->_fields as $field => $value) { |
|
472 | - $this->_errors[ $field ]['value'] = stripslashes($value); |
|
473 | - } |
|
474 | - } |
|
475 | - |
|
476 | - // return any errors or just TRUE if everything validates |
|
477 | - return empty($this->_errors) ? true : $this->_errors; |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * Reassembles and returns an array of valid shortcodes |
|
483 | - * given the array of groups and array of shortcodes indexed by group. |
|
484 | - * |
|
485 | - * @param array $groups array of shortcode groups that we want shortcodes for |
|
486 | - * @param array $codes_from_objs All the codes available. |
|
487 | - * @return array an array of actual shortcodes (that will be used for validation). |
|
488 | - */ |
|
489 | - private function _reassemble_valid_shortcodes_from_group($groups, $codes_from_objs) |
|
490 | - { |
|
491 | - $shortcodes = array(); |
|
492 | - foreach ($groups as $group) { |
|
493 | - $shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]); |
|
494 | - } |
|
495 | - return $shortcodes; |
|
496 | - } |
|
497 | - |
|
498 | - |
|
499 | - /** |
|
500 | - * Validates a string against a list of accepted shortcodes |
|
501 | - * This function takes in an array of shortcodes |
|
502 | - * and makes sure that the given string ONLY contains shortcodes in that array. |
|
503 | - * |
|
504 | - * @param string $value string to evaluate |
|
505 | - * @param array $valid_shortcodes array of shortcodes that are acceptable. |
|
506 | - * @return mixed (bool|string) return either a list of invalid shortcodes OR false if the shortcodes validate. |
|
507 | - */ |
|
508 | - protected function _invalid_shortcodes($value, $valid_shortcodes) |
|
509 | - { |
|
510 | - // first we need to go through the string and get the shortcodes in the string |
|
511 | - preg_match_all('/(\[.+?\])/', $value, $matches); |
|
512 | - $incoming_shortcodes = (array) $matches[0]; |
|
513 | - |
|
514 | - // get a diff of the shortcodes in the string vs the valid shortcodes |
|
515 | - $diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes)); |
|
516 | - |
|
517 | - // we need to account for custom codes so let's loop through the diff and remove any of those type of codes |
|
518 | - foreach ($diff as $ind => $code) { |
|
519 | - if (preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code)) { |
|
520 | - // strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] ) |
|
521 | - $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code); |
|
522 | - // does this exist in the $valid_shortcodes? If so then unset. |
|
523 | - if (isset($valid_shortcodes[ $dynamic_sc ])) { |
|
524 | - unset($diff[ $ind ]); |
|
525 | - } |
|
526 | - } |
|
527 | - } |
|
528 | - |
|
529 | - if (empty($diff)) { |
|
530 | - return false; |
|
531 | - } //there is no diff, we have no invalid shortcodes, so return |
|
532 | - |
|
533 | - // made it here? then let's assemble the error message |
|
534 | - $invalid_shortcodes = implode('</strong>,<strong>', $diff); |
|
535 | - $invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>'; |
|
536 | - return $invalid_shortcodes; |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * Validates an incoming string and makes sure we have valid emails in the string. |
|
542 | - * |
|
543 | - * @param string $value incoming value to validate |
|
544 | - * @return bool true if the string validates, false if it doesn't |
|
545 | - */ |
|
546 | - protected function _validate_email($value) |
|
547 | - { |
|
548 | - $validate = true; |
|
549 | - $or_val = $value; |
|
550 | - |
|
551 | - // empty strings will validate because this is how a message template |
|
552 | - // for a particular context can be "turned off" (if there is no email then no message) |
|
553 | - if (empty($value)) { |
|
554 | - return $validate; |
|
555 | - } |
|
556 | - |
|
557 | - // first determine if there ARE any shortcodes. |
|
558 | - // If there are shortcodes and then later we find that there were no other valid emails |
|
559 | - // but the field isn't empty... |
|
560 | - // that means we've got extra commas that were left after stripping out shortcodes so probably still valid. |
|
561 | - $has_shortcodes = preg_match('/(\[.+?\])/', $value); |
|
562 | - |
|
563 | - // first we need to strip out all the shortcodes! |
|
564 | - $value = preg_replace('/(\[.+?\])/', '', $value); |
|
565 | - |
|
566 | - // if original value is not empty and new value is, then we've parsed out a shortcode |
|
567 | - // and we now have an empty string which DOES validate. |
|
568 | - // We also validate complete empty field for email because |
|
569 | - // its possible that this message is being "turned off" for a particular context |
|
570 | - |
|
571 | - |
|
572 | - if (! empty($or_val) && empty($value)) { |
|
573 | - return $validate; |
|
574 | - } |
|
575 | - |
|
576 | - // trim any commas from beginning and end of string ( after whitespace trimmed ); |
|
577 | - $value = trim(trim($value), ','); |
|
578 | - |
|
579 | - |
|
580 | - // next we need to split up the string if its comma delimited. |
|
581 | - $emails = explode(',', $value); |
|
582 | - $empty = false; // used to indicate that there is an empty comma. |
|
583 | - // now let's loop through the emails and do our checks |
|
584 | - foreach ($emails as $email) { |
|
585 | - if (empty($email)) { |
|
586 | - $empty = true; |
|
587 | - continue; |
|
588 | - } |
|
589 | - |
|
590 | - // trim whitespace |
|
591 | - $email = trim($email); |
|
592 | - // either its of type "[email protected]", or its of type "fname lname <[email protected]>" |
|
593 | - if (is_email($email)) { |
|
594 | - continue; |
|
595 | - } |
|
596 | - $matches = array(); |
|
597 | - $validate = preg_match('/(.*)<(.+)>/', $email, $matches) ? true : false; |
|
598 | - if ($validate && is_email($matches[2])) { |
|
599 | - continue; |
|
600 | - } |
|
601 | - return false; |
|
602 | - } |
|
603 | - |
|
604 | - $validate = $empty && ! $has_shortcodes ? false : $validate; |
|
605 | - |
|
606 | - return $validate; |
|
607 | - } |
|
608 | - |
|
609 | - |
|
610 | - /** |
|
611 | - * Magic getter |
|
612 | - * Using this to provide back compat with add-ons referencing deprecated properties. |
|
613 | - * |
|
614 | - * @param string $property Property being requested |
|
615 | - * @throws Exception |
|
616 | - * @return mixed |
|
617 | - */ |
|
618 | - public function __get($property) |
|
619 | - { |
|
620 | - $expected_properties_map = array( |
|
621 | - /** |
|
622 | - * @deprecated 4.9.0 |
|
623 | - */ |
|
624 | - '_MSGR' => '_messenger', |
|
625 | - /** |
|
626 | - * @deprecated 4.9.0 |
|
627 | - */ |
|
628 | - '_MSGTYP' => '_message_type', |
|
629 | - ); |
|
630 | - |
|
631 | - if (isset($expected_properties_map[ $property ])) { |
|
632 | - return $this->{$expected_properties_map[ $property ]}; |
|
633 | - } |
|
634 | - |
|
635 | - throw new Exception( |
|
636 | - sprintf( |
|
637 | - esc_html__('The property %1$s being requested on %2$s does not exist', 'event_espresso'), |
|
638 | - $property, |
|
639 | - get_class($this) |
|
640 | - ) |
|
641 | - ); |
|
642 | - } |
|
21 | + /** |
|
22 | + * These properties just hold the name for the Messenger and Message Type (defined by child classes). |
|
23 | + * These are used for retrieving objects etc. |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + protected $_m_name; |
|
28 | + protected $_mt_name; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * This will hold any error messages from the validation process. |
|
33 | + * The _errors property holds an associative array of error messages |
|
34 | + * listing the field as the key and the message as the value. |
|
35 | + * |
|
36 | + * @var array() |
|
37 | + */ |
|
38 | + private $_errors = array(); |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * holds an array of fields being validated |
|
43 | + * |
|
44 | + * @var array |
|
45 | + */ |
|
46 | + protected $_fields; |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * this will hold the incoming context |
|
51 | + * |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $_context; |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * this holds an array of fields and the relevant validation information |
|
59 | + * that the incoming fields data get validated against. |
|
60 | + * This gets setup in the _set_props() method. |
|
61 | + * |
|
62 | + * @var array |
|
63 | + */ |
|
64 | + protected $_validators; |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * holds the messenger object |
|
69 | + * |
|
70 | + * @var object |
|
71 | + */ |
|
72 | + protected $_messenger; |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * holds the message type object |
|
77 | + * |
|
78 | + * @var object |
|
79 | + */ |
|
80 | + protected $_message_type; |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * will hold any valid_shortcode modifications made by the _modify_validator() method. |
|
85 | + * |
|
86 | + * @var array |
|
87 | + */ |
|
88 | + protected $_valid_shortcodes_modifier; |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * There may be times where a message type wants to include a shortcode group but exclude specific |
|
93 | + * shortcodes. If that's the case then it can set this property as an array of shortcodes to exclude and |
|
94 | + * they will not be allowed. |
|
95 | + * Array should be indexed by field and values are an array of specific shortcodes to exclude. |
|
96 | + * |
|
97 | + * @var array |
|
98 | + */ |
|
99 | + protected $_specific_shortcode_excludes = array(); |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * Runs the validator using the incoming fields array as the fields/values to check. |
|
104 | + * |
|
105 | + * @param array $fields The fields sent by the EEM object. |
|
106 | + * @param $context |
|
107 | + * @throws EE_Error |
|
108 | + * @throws ReflectionException |
|
109 | + */ |
|
110 | + public function __construct($fields, $context) |
|
111 | + { |
|
112 | + // check that _m_name and _mt_name have been set by child class otherwise we get out. |
|
113 | + if (empty($this->_m_name) || empty($this->_mt_name)) { |
|
114 | + throw new EE_Error( |
|
115 | + esc_html__( |
|
116 | + 'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property. Check that the child class is doing this', |
|
117 | + 'event_espresso' |
|
118 | + ) |
|
119 | + ); |
|
120 | + } |
|
121 | + $this->_fields = $fields; |
|
122 | + $this->_context = $context; |
|
123 | + |
|
124 | + // load messenger and message_type objects and the related shortcode objects. |
|
125 | + $this->_load_objects(); |
|
126 | + |
|
127 | + |
|
128 | + // modify any messenger/message_type specific validation instructions. This is what child classes define. |
|
129 | + $this->_modify_validator(); |
|
130 | + |
|
131 | + |
|
132 | + // let's set validators property |
|
133 | + $this->_set_validators(); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * Child classes instantiate this and use it to modify the _validator_config array property |
|
139 | + * for the messenger using messengers set_validate_config() method. |
|
140 | + * This is so we can specify specific validation instructions for a messenger/message_type combo |
|
141 | + * that aren't handled by the defaults setup in the messenger. |
|
142 | + * |
|
143 | + * @abstract |
|
144 | + * @access protected |
|
145 | + * @return void |
|
146 | + */ |
|
147 | + abstract protected function _modify_validator(); |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * loads all objects used by validator |
|
152 | + * |
|
153 | + * @access private |
|
154 | + * @throws \EE_Error |
|
155 | + */ |
|
156 | + private function _load_objects() |
|
157 | + { |
|
158 | + // load messenger |
|
159 | + $messenger = ucwords(str_replace('_', ' ', $this->_m_name)); |
|
160 | + $messenger = str_replace(' ', '_', $messenger); |
|
161 | + $messenger = 'EE_' . $messenger . '_messenger'; |
|
162 | + |
|
163 | + if (! class_exists($messenger)) { |
|
164 | + throw new EE_Error( |
|
165 | + sprintf( |
|
166 | + esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'), |
|
167 | + $this->_m_name |
|
168 | + ) |
|
169 | + ); |
|
170 | + } |
|
171 | + |
|
172 | + $this->_messenger = new $messenger(); |
|
173 | + |
|
174 | + // load message type |
|
175 | + $message_type = ucwords(str_replace('_', ' ', $this->_mt_name)); |
|
176 | + $message_type = str_replace(' ', '_', $message_type); |
|
177 | + $message_type = 'EE_' . $message_type . '_message_type'; |
|
178 | + |
|
179 | + if (! class_exists($message_type)) { |
|
180 | + throw new EE_Error( |
|
181 | + sprintf( |
|
182 | + esc_html__('There is no message type class for the given string (%s)', 'event_espresso'), |
|
183 | + $this->_mt_name |
|
184 | + ) |
|
185 | + ); |
|
186 | + } |
|
187 | + |
|
188 | + $this->_message_type = new $message_type(); |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * used to set the $_validators property |
|
194 | + * |
|
195 | + * @access private |
|
196 | + * @return void |
|
197 | + * @throws ReflectionException |
|
198 | + */ |
|
199 | + private function _set_validators() |
|
200 | + { |
|
201 | + // let's get all valid shortcodes from mt and message type |
|
202 | + // (messenger will have its set in the _validator_config property for the messenger) |
|
203 | + $mt_codes = $this->_message_type->get_valid_shortcodes(); |
|
204 | + |
|
205 | + |
|
206 | + // get messenger validator_config |
|
207 | + $msgr_validator = $this->_messenger->get_validator_config(); |
|
208 | + |
|
209 | + |
|
210 | + // we only want the valid shortcodes for the given context! |
|
211 | + $context = $this->_context; |
|
212 | + $mt_codes = $mt_codes[ $context ]; |
|
213 | + |
|
214 | + // in this first loop we're just getting all shortcode group indexes from the msgr_validator |
|
215 | + // into a single array (so we can get the appropriate shortcode objects for the groups) |
|
216 | + $shortcode_groups = $mt_codes; |
|
217 | + $groups_per_field = array(); |
|
218 | + |
|
219 | + foreach ($msgr_validator as $field => $config) { |
|
220 | + if (empty($config) || ! isset($config['shortcodes'])) { |
|
221 | + continue; |
|
222 | + } //Nothing to see here. |
|
223 | + $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes); |
|
224 | + $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups); |
|
225 | + } |
|
226 | + |
|
227 | + $shortcode_groups = array_unique($shortcode_groups); |
|
228 | + |
|
229 | + // okay now we've got our groups. |
|
230 | + // Let's get the codes from the objects into an array indexed by group for easy retrieval later. |
|
231 | + $codes_from_objs = array(); |
|
232 | + |
|
233 | + foreach ($shortcode_groups as $group) { |
|
234 | + $ref = ucwords(str_replace('_', ' ', $group)); |
|
235 | + $ref = str_replace(' ', '_', $ref); |
|
236 | + $classname = 'EE_' . $ref . '_Shortcodes'; |
|
237 | + if (class_exists($classname)) { |
|
238 | + $a = new ReflectionClass($classname); |
|
239 | + $obj = $a->newInstance(); |
|
240 | + $codes_from_objs[ $group ] = $obj->get_shortcodes(); |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique) |
|
246 | + $final_mt_codes = array(); |
|
247 | + foreach ($mt_codes as $group) { |
|
248 | + $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]); |
|
249 | + } |
|
250 | + |
|
251 | + $mt_codes = $final_mt_codes; |
|
252 | + |
|
253 | + |
|
254 | + // k now in this next loop we're going to loop through $msgr_validator again |
|
255 | + // and setup the _validators property from the data we've setup so far. |
|
256 | + foreach ($msgr_validator as $field => $config) { |
|
257 | + // if required shortcode is not in our list of codes for the given field, then we skip this field. |
|
258 | + $required = isset($config['required']) |
|
259 | + ? array_intersect($config['required'], array_keys($mt_codes)) |
|
260 | + : true; |
|
261 | + if (empty($required)) { |
|
262 | + continue; |
|
263 | + } |
|
264 | + |
|
265 | + // If we have an override then we use it to indicate the codes we want. |
|
266 | + if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) { |
|
267 | + $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
268 | + $this->_valid_shortcodes_modifier[ $context ][ $field ], |
|
269 | + $codes_from_objs |
|
270 | + ); |
|
271 | + } //if we have specific shortcodes for a field then we need to use them |
|
272 | + elseif (isset($groups_per_field[ $field ])) { |
|
273 | + $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
274 | + $groups_per_field[ $field ], |
|
275 | + $codes_from_objs |
|
276 | + ); |
|
277 | + } //if empty config then we're assuming we're just going to use the shortcodes from the message type context |
|
278 | + elseif (empty($config)) { |
|
279 | + $this->_validators[ $field ]['shortcodes'] = $mt_codes; |
|
280 | + } //if we have specific shortcodes then we need to use them |
|
281 | + elseif (isset($config['specific_shortcodes'])) { |
|
282 | + $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes']; |
|
283 | + } //otherwise the shortcodes are what is set by the messenger for that field |
|
284 | + else { |
|
285 | + foreach ($config['shortcodes'] as $group) { |
|
286 | + $this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes']) |
|
287 | + ? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ]) |
|
288 | + : $codes_from_objs[ $group ]; |
|
289 | + } |
|
290 | + } |
|
291 | + |
|
292 | + // now let's just make sure that any excluded specific shortcodes are removed. |
|
293 | + $specific_excludes = $this->get_specific_shortcode_excludes(); |
|
294 | + if (isset($specific_excludes[ $field ])) { |
|
295 | + foreach ($specific_excludes[ $field ] as $sex) { |
|
296 | + if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) { |
|
297 | + unset($this->_validators[ $field ]['shortcodes'][ $sex ]); |
|
298 | + } |
|
299 | + } |
|
300 | + } |
|
301 | + |
|
302 | + // hey! don't forget to include the type if present! |
|
303 | + $this->_validators[ $field ]['type'] = isset($config['type']) ? $config['type'] : null; |
|
304 | + } |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * This just returns the validators property that contains information |
|
310 | + * about the various shortcodes and their availability with each field |
|
311 | + * |
|
312 | + * @return array |
|
313 | + */ |
|
314 | + public function get_validators() |
|
315 | + { |
|
316 | + return $this->_validators; |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * This simply returns the specific shortcode_excludes property that is set. |
|
322 | + * |
|
323 | + * @since 4.5.0 |
|
324 | + * @return array |
|
325 | + */ |
|
326 | + public function get_specific_shortcode_excludes() |
|
327 | + { |
|
328 | + // specific validator filter |
|
329 | + $shortcode_excludes = apply_filters( |
|
330 | + 'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;', |
|
331 | + $this->_specific_shortcode_excludes, |
|
332 | + $this->_context |
|
333 | + ); |
|
334 | + // global filter |
|
335 | + return apply_filters( |
|
336 | + 'FHEE__EE_Messages_Validator__get_specific_shortcode_excludes', |
|
337 | + $shortcode_excludes, |
|
338 | + $this->_context, |
|
339 | + $this |
|
340 | + ); |
|
341 | + } |
|
342 | + |
|
343 | + |
|
344 | + /** |
|
345 | + * This is the main method that handles validation |
|
346 | + * What it does is loop through the _fields (the ones that get validated) |
|
347 | + * and checks them against the shortcodes array for the field and the 'type' indicated by the |
|
348 | + * |
|
349 | + * @access public |
|
350 | + * @return mixed (bool|array) if errors present we return the array otherwise true |
|
351 | + */ |
|
352 | + public function validate() |
|
353 | + { |
|
354 | + // some defaults |
|
355 | + $template_fields = $this->_messenger->get_template_fields(); |
|
356 | + // loop through the fields and check! |
|
357 | + foreach ($this->_fields as $field => $value) { |
|
358 | + $this->_errors[ $field ] = array(); |
|
359 | + $err_msg = ''; |
|
360 | + $field_label = ''; |
|
361 | + // if field is not present in the _validators array then we continue |
|
362 | + if (! isset($this->_validators[ $field ])) { |
|
363 | + unset($this->_errors[ $field ]); |
|
364 | + continue; |
|
365 | + } |
|
366 | + |
|
367 | + // get the translated field label! |
|
368 | + // first check if it's in the main fields list |
|
369 | + if (isset($template_fields[ $field ])) { |
|
370 | + if (empty($template_fields[ $field ])) { |
|
371 | + $field_label = $field; |
|
372 | + } //most likely the field is found in the 'extra' array. |
|
373 | + else { |
|
374 | + $field_label = $template_fields[ $field ]['label']; |
|
375 | + } |
|
376 | + } |
|
377 | + |
|
378 | + // if field label is empty OR is equal to the current field |
|
379 | + // then we need to loop through the 'extra' fields in the template_fields config (if present) |
|
380 | + if (isset($template_fields['extra']) && (empty($field_label) || $field_label === $field)) { |
|
381 | + foreach ($template_fields['extra'] as $main_field => $secondary_field) { |
|
382 | + foreach ($secondary_field as $name => $values) { |
|
383 | + if ($name === $field) { |
|
384 | + $field_label = $values['label']; |
|
385 | + } |
|
386 | + |
|
387 | + // if we've got a 'main' secondary field, let's see if that matches what field we're on |
|
388 | + // which means it contains the label for this field. |
|
389 | + if ($name === 'main' && $main_field === $field_label) { |
|
390 | + $field_label = $values['label']; |
|
391 | + } |
|
392 | + } |
|
393 | + } |
|
394 | + } |
|
395 | + |
|
396 | + // field is present. Let's validate shortcodes first (but only if shortcodes present). |
|
397 | + if (isset($this->_validators[ $field ]['shortcodes']) |
|
398 | + && ! empty($this->_validators[ $field ]['shortcodes']) |
|
399 | + ) { |
|
400 | + $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']); |
|
401 | + // if true then that means there is a returned error message |
|
402 | + // that we'll need to add to the _errors array for this field. |
|
403 | + if ($invalid_shortcodes) { |
|
404 | + $v_s = array_keys($this->_validators[ $field ]['shortcodes']); |
|
405 | + $err_msg = sprintf( |
|
406 | + esc_html__( |
|
407 | + '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s', |
|
408 | + 'event_espresso' |
|
409 | + ), |
|
410 | + '<strong>' . $field_label . '</strong>', |
|
411 | + $invalid_shortcodes, |
|
412 | + '<p>', |
|
413 | + '</p >' |
|
414 | + ); |
|
415 | + $err_msg .= sprintf( |
|
416 | + esc_html__('%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso'), |
|
417 | + implode(', ', $v_s), |
|
418 | + '<strong>', |
|
419 | + '</strong>' |
|
420 | + ); |
|
421 | + } |
|
422 | + } |
|
423 | + |
|
424 | + // if there's a "type" to be validated then let's do that too. |
|
425 | + if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) { |
|
426 | + switch ($this->_validators[ $field ]['type']) { |
|
427 | + case 'number': |
|
428 | + if (! is_numeric($value)) { |
|
429 | + $err_msg .= sprintf( |
|
430 | + esc_html__( |
|
431 | + '%3$sThe %1$s field is supposed to be a number. The value given (%2$s) is not. Please double-check and make sure the field contains a number%4$s', |
|
432 | + 'event_espresso' |
|
433 | + ), |
|
434 | + $field_label, |
|
435 | + $value, |
|
436 | + '<p>', |
|
437 | + '</p >' |
|
438 | + ); |
|
439 | + } |
|
440 | + break; |
|
441 | + case 'email': |
|
442 | + $valid_email = $this->_validate_email($value); |
|
443 | + if (! $valid_email) { |
|
444 | + $err_msg .= htmlentities( |
|
445 | + sprintf( |
|
446 | + esc_html__( |
|
447 | + 'The %1$s field has at least one string that is not a valid email address record. Valid emails are in the format: "Name <[email protected]>" or "[email protected]" and multiple emails can be separated by a comma.', |
|
448 | + 'event_espresso' |
|
449 | + ), |
|
450 | + $field_label |
|
451 | + ) |
|
452 | + ); |
|
453 | + } |
|
454 | + break; |
|
455 | + default: |
|
456 | + break; |
|
457 | + } |
|
458 | + } |
|
459 | + |
|
460 | + // if $err_msg isn't empty let's setup the _errors array for this field. |
|
461 | + if (! empty($err_msg)) { |
|
462 | + $this->_errors[ $field ]['msg'] = $err_msg; |
|
463 | + } else { |
|
464 | + unset($this->_errors[ $field ]); |
|
465 | + } |
|
466 | + } |
|
467 | + |
|
468 | + // if we have ANY errors, then we want to make sure we return the values |
|
469 | + // for ALL the fields so the user doesn't have to retype them all. |
|
470 | + if (! empty($this->_errors)) { |
|
471 | + foreach ($this->_fields as $field => $value) { |
|
472 | + $this->_errors[ $field ]['value'] = stripslashes($value); |
|
473 | + } |
|
474 | + } |
|
475 | + |
|
476 | + // return any errors or just TRUE if everything validates |
|
477 | + return empty($this->_errors) ? true : $this->_errors; |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * Reassembles and returns an array of valid shortcodes |
|
483 | + * given the array of groups and array of shortcodes indexed by group. |
|
484 | + * |
|
485 | + * @param array $groups array of shortcode groups that we want shortcodes for |
|
486 | + * @param array $codes_from_objs All the codes available. |
|
487 | + * @return array an array of actual shortcodes (that will be used for validation). |
|
488 | + */ |
|
489 | + private function _reassemble_valid_shortcodes_from_group($groups, $codes_from_objs) |
|
490 | + { |
|
491 | + $shortcodes = array(); |
|
492 | + foreach ($groups as $group) { |
|
493 | + $shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]); |
|
494 | + } |
|
495 | + return $shortcodes; |
|
496 | + } |
|
497 | + |
|
498 | + |
|
499 | + /** |
|
500 | + * Validates a string against a list of accepted shortcodes |
|
501 | + * This function takes in an array of shortcodes |
|
502 | + * and makes sure that the given string ONLY contains shortcodes in that array. |
|
503 | + * |
|
504 | + * @param string $value string to evaluate |
|
505 | + * @param array $valid_shortcodes array of shortcodes that are acceptable. |
|
506 | + * @return mixed (bool|string) return either a list of invalid shortcodes OR false if the shortcodes validate. |
|
507 | + */ |
|
508 | + protected function _invalid_shortcodes($value, $valid_shortcodes) |
|
509 | + { |
|
510 | + // first we need to go through the string and get the shortcodes in the string |
|
511 | + preg_match_all('/(\[.+?\])/', $value, $matches); |
|
512 | + $incoming_shortcodes = (array) $matches[0]; |
|
513 | + |
|
514 | + // get a diff of the shortcodes in the string vs the valid shortcodes |
|
515 | + $diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes)); |
|
516 | + |
|
517 | + // we need to account for custom codes so let's loop through the diff and remove any of those type of codes |
|
518 | + foreach ($diff as $ind => $code) { |
|
519 | + if (preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code)) { |
|
520 | + // strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] ) |
|
521 | + $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code); |
|
522 | + // does this exist in the $valid_shortcodes? If so then unset. |
|
523 | + if (isset($valid_shortcodes[ $dynamic_sc ])) { |
|
524 | + unset($diff[ $ind ]); |
|
525 | + } |
|
526 | + } |
|
527 | + } |
|
528 | + |
|
529 | + if (empty($diff)) { |
|
530 | + return false; |
|
531 | + } //there is no diff, we have no invalid shortcodes, so return |
|
532 | + |
|
533 | + // made it here? then let's assemble the error message |
|
534 | + $invalid_shortcodes = implode('</strong>,<strong>', $diff); |
|
535 | + $invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>'; |
|
536 | + return $invalid_shortcodes; |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * Validates an incoming string and makes sure we have valid emails in the string. |
|
542 | + * |
|
543 | + * @param string $value incoming value to validate |
|
544 | + * @return bool true if the string validates, false if it doesn't |
|
545 | + */ |
|
546 | + protected function _validate_email($value) |
|
547 | + { |
|
548 | + $validate = true; |
|
549 | + $or_val = $value; |
|
550 | + |
|
551 | + // empty strings will validate because this is how a message template |
|
552 | + // for a particular context can be "turned off" (if there is no email then no message) |
|
553 | + if (empty($value)) { |
|
554 | + return $validate; |
|
555 | + } |
|
556 | + |
|
557 | + // first determine if there ARE any shortcodes. |
|
558 | + // If there are shortcodes and then later we find that there were no other valid emails |
|
559 | + // but the field isn't empty... |
|
560 | + // that means we've got extra commas that were left after stripping out shortcodes so probably still valid. |
|
561 | + $has_shortcodes = preg_match('/(\[.+?\])/', $value); |
|
562 | + |
|
563 | + // first we need to strip out all the shortcodes! |
|
564 | + $value = preg_replace('/(\[.+?\])/', '', $value); |
|
565 | + |
|
566 | + // if original value is not empty and new value is, then we've parsed out a shortcode |
|
567 | + // and we now have an empty string which DOES validate. |
|
568 | + // We also validate complete empty field for email because |
|
569 | + // its possible that this message is being "turned off" for a particular context |
|
570 | + |
|
571 | + |
|
572 | + if (! empty($or_val) && empty($value)) { |
|
573 | + return $validate; |
|
574 | + } |
|
575 | + |
|
576 | + // trim any commas from beginning and end of string ( after whitespace trimmed ); |
|
577 | + $value = trim(trim($value), ','); |
|
578 | + |
|
579 | + |
|
580 | + // next we need to split up the string if its comma delimited. |
|
581 | + $emails = explode(',', $value); |
|
582 | + $empty = false; // used to indicate that there is an empty comma. |
|
583 | + // now let's loop through the emails and do our checks |
|
584 | + foreach ($emails as $email) { |
|
585 | + if (empty($email)) { |
|
586 | + $empty = true; |
|
587 | + continue; |
|
588 | + } |
|
589 | + |
|
590 | + // trim whitespace |
|
591 | + $email = trim($email); |
|
592 | + // either its of type "[email protected]", or its of type "fname lname <[email protected]>" |
|
593 | + if (is_email($email)) { |
|
594 | + continue; |
|
595 | + } |
|
596 | + $matches = array(); |
|
597 | + $validate = preg_match('/(.*)<(.+)>/', $email, $matches) ? true : false; |
|
598 | + if ($validate && is_email($matches[2])) { |
|
599 | + continue; |
|
600 | + } |
|
601 | + return false; |
|
602 | + } |
|
603 | + |
|
604 | + $validate = $empty && ! $has_shortcodes ? false : $validate; |
|
605 | + |
|
606 | + return $validate; |
|
607 | + } |
|
608 | + |
|
609 | + |
|
610 | + /** |
|
611 | + * Magic getter |
|
612 | + * Using this to provide back compat with add-ons referencing deprecated properties. |
|
613 | + * |
|
614 | + * @param string $property Property being requested |
|
615 | + * @throws Exception |
|
616 | + * @return mixed |
|
617 | + */ |
|
618 | + public function __get($property) |
|
619 | + { |
|
620 | + $expected_properties_map = array( |
|
621 | + /** |
|
622 | + * @deprecated 4.9.0 |
|
623 | + */ |
|
624 | + '_MSGR' => '_messenger', |
|
625 | + /** |
|
626 | + * @deprecated 4.9.0 |
|
627 | + */ |
|
628 | + '_MSGTYP' => '_message_type', |
|
629 | + ); |
|
630 | + |
|
631 | + if (isset($expected_properties_map[ $property ])) { |
|
632 | + return $this->{$expected_properties_map[ $property ]}; |
|
633 | + } |
|
634 | + |
|
635 | + throw new Exception( |
|
636 | + sprintf( |
|
637 | + esc_html__('The property %1$s being requested on %2$s does not exist', 'event_espresso'), |
|
638 | + $property, |
|
639 | + get_class($this) |
|
640 | + ) |
|
641 | + ); |
|
642 | + } |
|
643 | 643 | } |
@@ -158,9 +158,9 @@ discard block |
||
158 | 158 | // load messenger |
159 | 159 | $messenger = ucwords(str_replace('_', ' ', $this->_m_name)); |
160 | 160 | $messenger = str_replace(' ', '_', $messenger); |
161 | - $messenger = 'EE_' . $messenger . '_messenger'; |
|
161 | + $messenger = 'EE_'.$messenger.'_messenger'; |
|
162 | 162 | |
163 | - if (! class_exists($messenger)) { |
|
163 | + if ( ! class_exists($messenger)) { |
|
164 | 164 | throw new EE_Error( |
165 | 165 | sprintf( |
166 | 166 | esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'), |
@@ -174,9 +174,9 @@ discard block |
||
174 | 174 | // load message type |
175 | 175 | $message_type = ucwords(str_replace('_', ' ', $this->_mt_name)); |
176 | 176 | $message_type = str_replace(' ', '_', $message_type); |
177 | - $message_type = 'EE_' . $message_type . '_message_type'; |
|
177 | + $message_type = 'EE_'.$message_type.'_message_type'; |
|
178 | 178 | |
179 | - if (! class_exists($message_type)) { |
|
179 | + if ( ! class_exists($message_type)) { |
|
180 | 180 | throw new EE_Error( |
181 | 181 | sprintf( |
182 | 182 | esc_html__('There is no message type class for the given string (%s)', 'event_espresso'), |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | |
210 | 210 | // we only want the valid shortcodes for the given context! |
211 | 211 | $context = $this->_context; |
212 | - $mt_codes = $mt_codes[ $context ]; |
|
212 | + $mt_codes = $mt_codes[$context]; |
|
213 | 213 | |
214 | 214 | // in this first loop we're just getting all shortcode group indexes from the msgr_validator |
215 | 215 | // into a single array (so we can get the appropriate shortcode objects for the groups) |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | if (empty($config) || ! isset($config['shortcodes'])) { |
221 | 221 | continue; |
222 | 222 | } //Nothing to see here. |
223 | - $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes); |
|
224 | - $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups); |
|
223 | + $groups_per_field[$field] = array_intersect($config['shortcodes'], $mt_codes); |
|
224 | + $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | $shortcode_groups = array_unique($shortcode_groups); |
@@ -233,11 +233,11 @@ discard block |
||
233 | 233 | foreach ($shortcode_groups as $group) { |
234 | 234 | $ref = ucwords(str_replace('_', ' ', $group)); |
235 | 235 | $ref = str_replace(' ', '_', $ref); |
236 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
236 | + $classname = 'EE_'.$ref.'_Shortcodes'; |
|
237 | 237 | if (class_exists($classname)) { |
238 | 238 | $a = new ReflectionClass($classname); |
239 | 239 | $obj = $a->newInstance(); |
240 | - $codes_from_objs[ $group ] = $obj->get_shortcodes(); |
|
240 | + $codes_from_objs[$group] = $obj->get_shortcodes(); |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique) |
246 | 246 | $final_mt_codes = array(); |
247 | 247 | foreach ($mt_codes as $group) { |
248 | - $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]); |
|
248 | + $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[$group]); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | $mt_codes = $final_mt_codes; |
@@ -263,44 +263,44 @@ discard block |
||
263 | 263 | } |
264 | 264 | |
265 | 265 | // If we have an override then we use it to indicate the codes we want. |
266 | - if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) { |
|
267 | - $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
268 | - $this->_valid_shortcodes_modifier[ $context ][ $field ], |
|
266 | + if (isset($this->_valid_shortcodes_modifier[$context][$field])) { |
|
267 | + $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
268 | + $this->_valid_shortcodes_modifier[$context][$field], |
|
269 | 269 | $codes_from_objs |
270 | 270 | ); |
271 | 271 | } //if we have specific shortcodes for a field then we need to use them |
272 | - elseif (isset($groups_per_field[ $field ])) { |
|
273 | - $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
274 | - $groups_per_field[ $field ], |
|
272 | + elseif (isset($groups_per_field[$field])) { |
|
273 | + $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
274 | + $groups_per_field[$field], |
|
275 | 275 | $codes_from_objs |
276 | 276 | ); |
277 | 277 | } //if empty config then we're assuming we're just going to use the shortcodes from the message type context |
278 | 278 | elseif (empty($config)) { |
279 | - $this->_validators[ $field ]['shortcodes'] = $mt_codes; |
|
279 | + $this->_validators[$field]['shortcodes'] = $mt_codes; |
|
280 | 280 | } //if we have specific shortcodes then we need to use them |
281 | 281 | elseif (isset($config['specific_shortcodes'])) { |
282 | - $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes']; |
|
282 | + $this->_validators[$field]['shortcodes'] = $config['specific_shortcodes']; |
|
283 | 283 | } //otherwise the shortcodes are what is set by the messenger for that field |
284 | 284 | else { |
285 | 285 | foreach ($config['shortcodes'] as $group) { |
286 | - $this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes']) |
|
287 | - ? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ]) |
|
288 | - : $codes_from_objs[ $group ]; |
|
286 | + $this->_validators[$field]['shortcodes'] = isset($this->_validators[$field]['shortcodes']) |
|
287 | + ? array_merge($this->_validators[$field]['shortcodes'], $codes_from_objs[$group]) |
|
288 | + : $codes_from_objs[$group]; |
|
289 | 289 | } |
290 | 290 | } |
291 | 291 | |
292 | 292 | // now let's just make sure that any excluded specific shortcodes are removed. |
293 | 293 | $specific_excludes = $this->get_specific_shortcode_excludes(); |
294 | - if (isset($specific_excludes[ $field ])) { |
|
295 | - foreach ($specific_excludes[ $field ] as $sex) { |
|
296 | - if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) { |
|
297 | - unset($this->_validators[ $field ]['shortcodes'][ $sex ]); |
|
294 | + if (isset($specific_excludes[$field])) { |
|
295 | + foreach ($specific_excludes[$field] as $sex) { |
|
296 | + if (isset($this->_validators[$field]['shortcodes'][$sex])) { |
|
297 | + unset($this->_validators[$field]['shortcodes'][$sex]); |
|
298 | 298 | } |
299 | 299 | } |
300 | 300 | } |
301 | 301 | |
302 | 302 | // hey! don't forget to include the type if present! |
303 | - $this->_validators[ $field ]['type'] = isset($config['type']) ? $config['type'] : null; |
|
303 | + $this->_validators[$field]['type'] = isset($config['type']) ? $config['type'] : null; |
|
304 | 304 | } |
305 | 305 | } |
306 | 306 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | { |
328 | 328 | // specific validator filter |
329 | 329 | $shortcode_excludes = apply_filters( |
330 | - 'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;', |
|
330 | + 'FHEE__'.get_class($this).'__get_specific_shortcode_excludes;', |
|
331 | 331 | $this->_specific_shortcode_excludes, |
332 | 332 | $this->_context |
333 | 333 | ); |
@@ -355,23 +355,23 @@ discard block |
||
355 | 355 | $template_fields = $this->_messenger->get_template_fields(); |
356 | 356 | // loop through the fields and check! |
357 | 357 | foreach ($this->_fields as $field => $value) { |
358 | - $this->_errors[ $field ] = array(); |
|
358 | + $this->_errors[$field] = array(); |
|
359 | 359 | $err_msg = ''; |
360 | 360 | $field_label = ''; |
361 | 361 | // if field is not present in the _validators array then we continue |
362 | - if (! isset($this->_validators[ $field ])) { |
|
363 | - unset($this->_errors[ $field ]); |
|
362 | + if ( ! isset($this->_validators[$field])) { |
|
363 | + unset($this->_errors[$field]); |
|
364 | 364 | continue; |
365 | 365 | } |
366 | 366 | |
367 | 367 | // get the translated field label! |
368 | 368 | // first check if it's in the main fields list |
369 | - if (isset($template_fields[ $field ])) { |
|
370 | - if (empty($template_fields[ $field ])) { |
|
369 | + if (isset($template_fields[$field])) { |
|
370 | + if (empty($template_fields[$field])) { |
|
371 | 371 | $field_label = $field; |
372 | 372 | } //most likely the field is found in the 'extra' array. |
373 | 373 | else { |
374 | - $field_label = $template_fields[ $field ]['label']; |
|
374 | + $field_label = $template_fields[$field]['label']; |
|
375 | 375 | } |
376 | 376 | } |
377 | 377 | |
@@ -394,20 +394,20 @@ discard block |
||
394 | 394 | } |
395 | 395 | |
396 | 396 | // field is present. Let's validate shortcodes first (but only if shortcodes present). |
397 | - if (isset($this->_validators[ $field ]['shortcodes']) |
|
398 | - && ! empty($this->_validators[ $field ]['shortcodes']) |
|
397 | + if (isset($this->_validators[$field]['shortcodes']) |
|
398 | + && ! empty($this->_validators[$field]['shortcodes']) |
|
399 | 399 | ) { |
400 | - $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']); |
|
400 | + $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[$field]['shortcodes']); |
|
401 | 401 | // if true then that means there is a returned error message |
402 | 402 | // that we'll need to add to the _errors array for this field. |
403 | 403 | if ($invalid_shortcodes) { |
404 | - $v_s = array_keys($this->_validators[ $field ]['shortcodes']); |
|
404 | + $v_s = array_keys($this->_validators[$field]['shortcodes']); |
|
405 | 405 | $err_msg = sprintf( |
406 | 406 | esc_html__( |
407 | 407 | '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s', |
408 | 408 | 'event_espresso' |
409 | 409 | ), |
410 | - '<strong>' . $field_label . '</strong>', |
|
410 | + '<strong>'.$field_label.'</strong>', |
|
411 | 411 | $invalid_shortcodes, |
412 | 412 | '<p>', |
413 | 413 | '</p >' |
@@ -422,10 +422,10 @@ discard block |
||
422 | 422 | } |
423 | 423 | |
424 | 424 | // if there's a "type" to be validated then let's do that too. |
425 | - if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) { |
|
426 | - switch ($this->_validators[ $field ]['type']) { |
|
425 | + if (isset($this->_validators[$field]['type']) && ! empty($this->_validators[$field]['type'])) { |
|
426 | + switch ($this->_validators[$field]['type']) { |
|
427 | 427 | case 'number': |
428 | - if (! is_numeric($value)) { |
|
428 | + if ( ! is_numeric($value)) { |
|
429 | 429 | $err_msg .= sprintf( |
430 | 430 | esc_html__( |
431 | 431 | '%3$sThe %1$s field is supposed to be a number. The value given (%2$s) is not. Please double-check and make sure the field contains a number%4$s', |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | break; |
441 | 441 | case 'email': |
442 | 442 | $valid_email = $this->_validate_email($value); |
443 | - if (! $valid_email) { |
|
443 | + if ( ! $valid_email) { |
|
444 | 444 | $err_msg .= htmlentities( |
445 | 445 | sprintf( |
446 | 446 | esc_html__( |
@@ -458,18 +458,18 @@ discard block |
||
458 | 458 | } |
459 | 459 | |
460 | 460 | // if $err_msg isn't empty let's setup the _errors array for this field. |
461 | - if (! empty($err_msg)) { |
|
462 | - $this->_errors[ $field ]['msg'] = $err_msg; |
|
461 | + if ( ! empty($err_msg)) { |
|
462 | + $this->_errors[$field]['msg'] = $err_msg; |
|
463 | 463 | } else { |
464 | - unset($this->_errors[ $field ]); |
|
464 | + unset($this->_errors[$field]); |
|
465 | 465 | } |
466 | 466 | } |
467 | 467 | |
468 | 468 | // if we have ANY errors, then we want to make sure we return the values |
469 | 469 | // for ALL the fields so the user doesn't have to retype them all. |
470 | - if (! empty($this->_errors)) { |
|
470 | + if ( ! empty($this->_errors)) { |
|
471 | 471 | foreach ($this->_fields as $field => $value) { |
472 | - $this->_errors[ $field ]['value'] = stripslashes($value); |
|
472 | + $this->_errors[$field]['value'] = stripslashes($value); |
|
473 | 473 | } |
474 | 474 | } |
475 | 475 | |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | { |
491 | 491 | $shortcodes = array(); |
492 | 492 | foreach ($groups as $group) { |
493 | - $shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]); |
|
493 | + $shortcodes = array_merge($shortcodes, $codes_from_objs[$group]); |
|
494 | 494 | } |
495 | 495 | return $shortcodes; |
496 | 496 | } |
@@ -520,8 +520,8 @@ discard block |
||
520 | 520 | // strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] ) |
521 | 521 | $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code); |
522 | 522 | // does this exist in the $valid_shortcodes? If so then unset. |
523 | - if (isset($valid_shortcodes[ $dynamic_sc ])) { |
|
524 | - unset($diff[ $ind ]); |
|
523 | + if (isset($valid_shortcodes[$dynamic_sc])) { |
|
524 | + unset($diff[$ind]); |
|
525 | 525 | } |
526 | 526 | } |
527 | 527 | } |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | |
533 | 533 | // made it here? then let's assemble the error message |
534 | 534 | $invalid_shortcodes = implode('</strong>,<strong>', $diff); |
535 | - $invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>'; |
|
535 | + $invalid_shortcodes = '<strong>'.$invalid_shortcodes.'</strong>'; |
|
536 | 536 | return $invalid_shortcodes; |
537 | 537 | } |
538 | 538 | |
@@ -569,7 +569,7 @@ discard block |
||
569 | 569 | // its possible that this message is being "turned off" for a particular context |
570 | 570 | |
571 | 571 | |
572 | - if (! empty($or_val) && empty($value)) { |
|
572 | + if ( ! empty($or_val) && empty($value)) { |
|
573 | 573 | return $validate; |
574 | 574 | } |
575 | 575 | |
@@ -628,8 +628,8 @@ discard block |
||
628 | 628 | '_MSGTYP' => '_message_type', |
629 | 629 | ); |
630 | 630 | |
631 | - if (isset($expected_properties_map[ $property ])) { |
|
632 | - return $this->{$expected_properties_map[ $property ]}; |
|
631 | + if (isset($expected_properties_map[$property])) { |
|
632 | + return $this->{$expected_properties_map[$property]}; |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | throw new Exception( |
@@ -11,14 +11,14 @@ |
||
11 | 11 | |
12 | 12 | |
13 | 13 | |
14 | - /** |
|
15 | - * removes all tags which a WP Post wouldn't allow in its content normally |
|
16 | - * |
|
17 | - * @param string $value |
|
18 | - * @return string |
|
19 | - */ |
|
20 | - public function prepare_for_set($value) |
|
21 | - { |
|
22 | - return parent::prepare_for_set(wp_kses("$value", EEH_HTML::get_simple_tags())); |
|
23 | - } |
|
14 | + /** |
|
15 | + * removes all tags which a WP Post wouldn't allow in its content normally |
|
16 | + * |
|
17 | + * @param string $value |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public function prepare_for_set($value) |
|
21 | + { |
|
22 | + return parent::prepare_for_set(wp_kses("$value", EEH_HTML::get_simple_tags())); |
|
23 | + } |
|
24 | 24 | } |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | /** |
604 | 604 | * returns any events attached to this attendee ($_Event property); |
605 | 605 | * |
606 | - * @return array |
|
606 | + * @return EE_Base_Class[] |
|
607 | 607 | * @throws EE_Error |
608 | 608 | */ |
609 | 609 | public function events() |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | * used to save the billing info |
619 | 619 | * |
620 | 620 | * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
621 | - * @return EE_Form_Section_Proper|null |
|
621 | + * @return null|EE_Billing_Info_Form |
|
622 | 622 | * @throws EE_Error |
623 | 623 | */ |
624 | 624 | public function billing_info_for_payment_method($payment_method) |
@@ -25,746 +25,746 @@ |
||
25 | 25 | class EE_Attendee extends EE_CPT_Base implements EEI_Contact, EEI_Address, EEI_Admin_Links, EEI_Attendee |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Sets some dynamic defaults |
|
30 | - * |
|
31 | - * @param array $fieldValues |
|
32 | - * @param bool $bydb |
|
33 | - * @param string $timezone |
|
34 | - * @param array $date_formats |
|
35 | - * @throws EE_Error |
|
36 | - */ |
|
37 | - protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
38 | - { |
|
39 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
40 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
41 | - $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
42 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
43 | - } |
|
44 | - if (! isset($fieldValues['ATT_slug'])) { |
|
45 | - // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
46 | - $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
47 | - } |
|
48 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
49 | - $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
50 | - } |
|
51 | - parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @param array $props_n_values incoming values |
|
57 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
58 | - * used.) |
|
59 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
60 | - * date_format and the second value is the time format |
|
61 | - * @return EE_Attendee |
|
62 | - * @throws EE_Error |
|
63 | - */ |
|
64 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
65 | - { |
|
66 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
67 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @param array $props_n_values incoming values from the database |
|
73 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
74 | - * the website will be used. |
|
75 | - * @return EE_Attendee |
|
76 | - */ |
|
77 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
78 | - { |
|
79 | - return new self($props_n_values, true, $timezone); |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * Set Attendee First Name |
|
85 | - * |
|
86 | - * @access public |
|
87 | - * @param string $fname |
|
88 | - * @throws EE_Error |
|
89 | - */ |
|
90 | - public function set_fname($fname = '') |
|
91 | - { |
|
92 | - $this->set('ATT_fname', $fname); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * Set Attendee Last Name |
|
98 | - * |
|
99 | - * @access public |
|
100 | - * @param string $lname |
|
101 | - * @throws EE_Error |
|
102 | - */ |
|
103 | - public function set_lname($lname = '') |
|
104 | - { |
|
105 | - $this->set('ATT_lname', $lname); |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * Set Attendee Address |
|
111 | - * |
|
112 | - * @access public |
|
113 | - * @param string $address |
|
114 | - * @throws EE_Error |
|
115 | - */ |
|
116 | - public function set_address($address = '') |
|
117 | - { |
|
118 | - $this->set('ATT_address', $address); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * Set Attendee Address2 |
|
124 | - * |
|
125 | - * @access public |
|
126 | - * @param string $address2 |
|
127 | - * @throws EE_Error |
|
128 | - */ |
|
129 | - public function set_address2($address2 = '') |
|
130 | - { |
|
131 | - $this->set('ATT_address2', $address2); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * Set Attendee City |
|
137 | - * |
|
138 | - * @access public |
|
139 | - * @param string $city |
|
140 | - * @throws EE_Error |
|
141 | - */ |
|
142 | - public function set_city($city = '') |
|
143 | - { |
|
144 | - $this->set('ATT_city', $city); |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * Set Attendee State ID |
|
150 | - * |
|
151 | - * @access public |
|
152 | - * @param int $STA_ID |
|
153 | - * @throws EE_Error |
|
154 | - */ |
|
155 | - public function set_state($STA_ID = 0) |
|
156 | - { |
|
157 | - $this->set('STA_ID', $STA_ID); |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * Set Attendee Country ISO Code |
|
163 | - * |
|
164 | - * @access public |
|
165 | - * @param string $CNT_ISO |
|
166 | - * @throws EE_Error |
|
167 | - */ |
|
168 | - public function set_country($CNT_ISO = '') |
|
169 | - { |
|
170 | - $this->set('CNT_ISO', $CNT_ISO); |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * Set Attendee Zip/Postal Code |
|
176 | - * |
|
177 | - * @access public |
|
178 | - * @param string $zip |
|
179 | - * @throws EE_Error |
|
180 | - */ |
|
181 | - public function set_zip($zip = '') |
|
182 | - { |
|
183 | - $this->set('ATT_zip', $zip); |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * Set Attendee Email Address |
|
189 | - * |
|
190 | - * @access public |
|
191 | - * @param string $email |
|
192 | - * @throws EE_Error |
|
193 | - */ |
|
194 | - public function set_email($email = '') |
|
195 | - { |
|
196 | - $this->set('ATT_email', $email); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * Set Attendee Phone |
|
202 | - * |
|
203 | - * @access public |
|
204 | - * @param string $phone |
|
205 | - * @throws EE_Error |
|
206 | - */ |
|
207 | - public function set_phone($phone = '') |
|
208 | - { |
|
209 | - $this->set('ATT_phone', $phone); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * set deleted |
|
215 | - * |
|
216 | - * @access public |
|
217 | - * @param bool $ATT_deleted |
|
218 | - * @throws EE_Error |
|
219 | - */ |
|
220 | - public function set_deleted($ATT_deleted = false) |
|
221 | - { |
|
222 | - $this->set('ATT_deleted', $ATT_deleted); |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * Returns the value for the post_author id saved with the cpt |
|
228 | - * |
|
229 | - * @since 4.5.0 |
|
230 | - * @return int |
|
231 | - * @throws EE_Error |
|
232 | - */ |
|
233 | - public function wp_user() |
|
234 | - { |
|
235 | - return $this->get('ATT_author'); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * get Attendee First Name |
|
241 | - * |
|
242 | - * @access public |
|
243 | - * @return string |
|
244 | - * @throws EE_Error |
|
245 | - */ |
|
246 | - public function fname() |
|
247 | - { |
|
248 | - return $this->get('ATT_fname'); |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * echoes out the attendee's first name |
|
254 | - * |
|
255 | - * @return void |
|
256 | - * @throws EE_Error |
|
257 | - */ |
|
258 | - public function e_full_name() |
|
259 | - { |
|
260 | - echo $this->full_name(); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * Returns the first and last name concatenated together with a space. |
|
266 | - * |
|
267 | - * @param bool $apply_html_entities |
|
268 | - * @return string |
|
269 | - * @throws EE_Error |
|
270 | - */ |
|
271 | - public function full_name($apply_html_entities = false) |
|
272 | - { |
|
273 | - $full_name = array( |
|
274 | - $this->fname(), |
|
275 | - $this->lname(), |
|
276 | - ); |
|
277 | - $full_name = array_filter($full_name); |
|
278 | - $full_name = implode(' ', $full_name); |
|
279 | - return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
285 | - * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
286 | - * attendee. |
|
287 | - * |
|
288 | - * @param bool $apply_html_entities |
|
289 | - * @return string |
|
290 | - * @throws EE_Error |
|
291 | - */ |
|
292 | - public function ATT_full_name($apply_html_entities = false) |
|
293 | - { |
|
294 | - return $apply_html_entities |
|
295 | - ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
296 | - : $this->get('ATT_full_name'); |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * get Attendee Last Name |
|
302 | - * |
|
303 | - * @access public |
|
304 | - * @return string |
|
305 | - * @throws EE_Error |
|
306 | - */ |
|
307 | - public function lname() |
|
308 | - { |
|
309 | - return $this->get('ATT_lname'); |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
315 | - * |
|
316 | - * @return array numerically indexed, with each part of the address that is known. |
|
317 | - * Eg, if the user only responded to state and country, |
|
318 | - * it would be array(0=>'Alabama',1=>'USA') |
|
319 | - * @return array |
|
320 | - * @throws EE_Error |
|
321 | - */ |
|
322 | - public function full_address_as_array() |
|
323 | - { |
|
324 | - $full_address_array = array(); |
|
325 | - $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
326 | - foreach ($initial_address_fields as $address_field_name) { |
|
327 | - $address_fields_value = $this->get($address_field_name); |
|
328 | - if (! empty($address_fields_value)) { |
|
329 | - $full_address_array[] = $address_fields_value; |
|
330 | - } |
|
331 | - } |
|
332 | - // now handle state and country |
|
333 | - $state_obj = $this->state_obj(); |
|
334 | - if ($state_obj instanceof EE_State) { |
|
335 | - $full_address_array[] = $state_obj->name(); |
|
336 | - } |
|
337 | - $country_obj = $this->country_obj(); |
|
338 | - if ($country_obj instanceof EE_Country) { |
|
339 | - $full_address_array[] = $country_obj->name(); |
|
340 | - } |
|
341 | - // lastly get the xip |
|
342 | - $zip_value = $this->zip(); |
|
343 | - if (! empty($zip_value)) { |
|
344 | - $full_address_array[] = $zip_value; |
|
345 | - } |
|
346 | - return $full_address_array; |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * get Attendee Address |
|
352 | - * |
|
353 | - * @return string |
|
354 | - * @throws EE_Error |
|
355 | - */ |
|
356 | - public function address() |
|
357 | - { |
|
358 | - return $this->get('ATT_address'); |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * get Attendee Address2 |
|
364 | - * |
|
365 | - * @return string |
|
366 | - * @throws EE_Error |
|
367 | - */ |
|
368 | - public function address2() |
|
369 | - { |
|
370 | - return $this->get('ATT_address2'); |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * get Attendee City |
|
376 | - * |
|
377 | - * @return string |
|
378 | - * @throws EE_Error |
|
379 | - */ |
|
380 | - public function city() |
|
381 | - { |
|
382 | - return $this->get('ATT_city'); |
|
383 | - } |
|
384 | - |
|
385 | - |
|
386 | - /** |
|
387 | - * get Attendee State ID |
|
388 | - * |
|
389 | - * @return string |
|
390 | - * @throws EE_Error |
|
391 | - */ |
|
392 | - public function state_ID() |
|
393 | - { |
|
394 | - return $this->get('STA_ID'); |
|
395 | - } |
|
396 | - |
|
397 | - |
|
398 | - /** |
|
399 | - * @return string |
|
400 | - * @throws EE_Error |
|
401 | - */ |
|
402 | - public function state_abbrev() |
|
403 | - { |
|
404 | - return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * Gets the state set to this attendee |
|
410 | - * |
|
411 | - * @return EE_State |
|
412 | - * @throws EE_Error |
|
413 | - */ |
|
414 | - public function state_obj() |
|
415 | - { |
|
416 | - return $this->get_first_related('State'); |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - /** |
|
421 | - * Returns the state's name, otherwise 'Unknown' |
|
422 | - * |
|
423 | - * @return string |
|
424 | - * @throws EE_Error |
|
425 | - */ |
|
426 | - public function state_name() |
|
427 | - { |
|
428 | - if ($this->state_obj()) { |
|
429 | - return $this->state_obj()->name(); |
|
430 | - } else { |
|
431 | - return ''; |
|
432 | - } |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * either displays the state abbreviation or the state name, as determined |
|
438 | - * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
439 | - * defaults to abbreviation |
|
440 | - * |
|
441 | - * @return string |
|
442 | - * @throws EE_Error |
|
443 | - */ |
|
444 | - public function state() |
|
445 | - { |
|
446 | - if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
447 | - return $this->state_abbrev(); |
|
448 | - } |
|
449 | - return $this->state_name(); |
|
450 | - } |
|
451 | - |
|
452 | - |
|
453 | - /** |
|
454 | - * get Attendee Country ISO Code |
|
455 | - * |
|
456 | - * @return string |
|
457 | - * @throws EE_Error |
|
458 | - */ |
|
459 | - public function country_ID() |
|
460 | - { |
|
461 | - return $this->get('CNT_ISO'); |
|
462 | - } |
|
463 | - |
|
464 | - |
|
465 | - /** |
|
466 | - * Gets country set for this attendee |
|
467 | - * |
|
468 | - * @return EE_Country |
|
469 | - * @throws EE_Error |
|
470 | - */ |
|
471 | - public function country_obj() |
|
472 | - { |
|
473 | - return $this->get_first_related('Country'); |
|
474 | - } |
|
475 | - |
|
476 | - |
|
477 | - /** |
|
478 | - * Returns the country's name if known, otherwise 'Unknown' |
|
479 | - * |
|
480 | - * @return string |
|
481 | - * @throws EE_Error |
|
482 | - */ |
|
483 | - public function country_name() |
|
484 | - { |
|
485 | - if ($this->country_obj()) { |
|
486 | - return $this->country_obj()->name(); |
|
487 | - } |
|
488 | - return ''; |
|
489 | - } |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * either displays the country ISO2 code or the country name, as determined |
|
494 | - * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
495 | - * defaults to abbreviation |
|
496 | - * |
|
497 | - * @return string |
|
498 | - * @throws EE_Error |
|
499 | - */ |
|
500 | - public function country() |
|
501 | - { |
|
502 | - if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
503 | - return $this->country_ID(); |
|
504 | - } |
|
505 | - return $this->country_name(); |
|
506 | - } |
|
507 | - |
|
508 | - |
|
509 | - /** |
|
510 | - * get Attendee Zip/Postal Code |
|
511 | - * |
|
512 | - * @return string |
|
513 | - * @throws EE_Error |
|
514 | - */ |
|
515 | - public function zip() |
|
516 | - { |
|
517 | - return $this->get('ATT_zip'); |
|
518 | - } |
|
519 | - |
|
520 | - |
|
521 | - /** |
|
522 | - * get Attendee Email Address |
|
523 | - * |
|
524 | - * @return string |
|
525 | - * @throws EE_Error |
|
526 | - */ |
|
527 | - public function email() |
|
528 | - { |
|
529 | - return $this->get('ATT_email'); |
|
530 | - } |
|
531 | - |
|
532 | - |
|
533 | - /** |
|
534 | - * get Attendee Phone # |
|
535 | - * |
|
536 | - * @return string |
|
537 | - * @throws EE_Error |
|
538 | - */ |
|
539 | - public function phone() |
|
540 | - { |
|
541 | - return $this->get('ATT_phone'); |
|
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * get deleted |
|
547 | - * |
|
548 | - * @return bool |
|
549 | - * @throws EE_Error |
|
550 | - */ |
|
551 | - public function deleted() |
|
552 | - { |
|
553 | - return $this->get('ATT_deleted'); |
|
554 | - } |
|
555 | - |
|
556 | - |
|
557 | - /** |
|
558 | - * Gets registrations of this attendee |
|
559 | - * |
|
560 | - * @param array $query_params |
|
561 | - * @return EE_Registration[] |
|
562 | - * @throws EE_Error |
|
563 | - */ |
|
564 | - public function get_registrations($query_params = array()) |
|
565 | - { |
|
566 | - return $this->get_many_related('Registration', $query_params); |
|
567 | - } |
|
568 | - |
|
569 | - |
|
570 | - /** |
|
571 | - * Gets the most recent registration of this attendee |
|
572 | - * |
|
573 | - * @return EE_Registration |
|
574 | - * @throws EE_Error |
|
575 | - */ |
|
576 | - public function get_most_recent_registration() |
|
577 | - { |
|
578 | - return $this->get_first_related( |
|
579 | - 'Registration', |
|
580 | - array('order_by' => array('REG_date' => 'DESC')) |
|
581 | - ); // null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
582 | - } |
|
583 | - |
|
584 | - |
|
585 | - /** |
|
586 | - * Gets the most recent registration for this attend at this event |
|
587 | - * |
|
588 | - * @param int $event_id |
|
589 | - * @return EE_Registration |
|
590 | - * @throws EE_Error |
|
591 | - */ |
|
592 | - public function get_most_recent_registration_for_event($event_id) |
|
593 | - { |
|
594 | - return $this->get_first_related( |
|
595 | - 'Registration', |
|
596 | - array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')) |
|
597 | - ); |
|
598 | - } |
|
599 | - |
|
600 | - |
|
601 | - /** |
|
602 | - * returns any events attached to this attendee ($_Event property); |
|
603 | - * |
|
604 | - * @return array |
|
605 | - * @throws EE_Error |
|
606 | - */ |
|
607 | - public function events() |
|
608 | - { |
|
609 | - return $this->get_many_related('Event'); |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
615 | - * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
616 | - * used to save the billing info |
|
617 | - * |
|
618 | - * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
619 | - * @return EE_Form_Section_Proper|null |
|
620 | - * @throws EE_Error |
|
621 | - */ |
|
622 | - public function billing_info_for_payment_method($payment_method) |
|
623 | - { |
|
624 | - $pm_type = $payment_method->type_obj(); |
|
625 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
626 | - return null; |
|
627 | - } |
|
628 | - $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
629 | - if (! $billing_info) { |
|
630 | - return null; |
|
631 | - } |
|
632 | - $billing_form = $pm_type->billing_form(); |
|
633 | - // double-check the form isn't totally hidden, in which case pretend there is no form |
|
634 | - $form_totally_hidden = true; |
|
635 | - foreach ($billing_form->inputs_in_subsections() as $input) { |
|
636 | - if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
637 | - $form_totally_hidden = false; |
|
638 | - break; |
|
639 | - } |
|
640 | - } |
|
641 | - if ($form_totally_hidden) { |
|
642 | - return null; |
|
643 | - } |
|
644 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
645 | - $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
646 | - } |
|
647 | - |
|
648 | - return $billing_form; |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - /** |
|
653 | - * Gets the postmeta key that holds this attendee's billing info for the |
|
654 | - * specified payment method |
|
655 | - * |
|
656 | - * @param EE_Payment_Method $payment_method |
|
657 | - * @return string |
|
658 | - * @throws EE_Error |
|
659 | - */ |
|
660 | - public function get_billing_info_postmeta_name($payment_method) |
|
661 | - { |
|
662 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
663 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
664 | - } |
|
665 | - return null; |
|
666 | - } |
|
667 | - |
|
668 | - |
|
669 | - /** |
|
670 | - * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
671 | - * retrieve it |
|
672 | - * |
|
673 | - * @param EE_Billing_Attendee_Info_Form $billing_form |
|
674 | - * @param EE_Payment_Method $payment_method |
|
675 | - * @return boolean |
|
676 | - * @throws EE_Error |
|
677 | - */ |
|
678 | - public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
679 | - { |
|
680 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
681 | - EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
|
682 | - return false; |
|
683 | - } |
|
684 | - $billing_form->clean_sensitive_data(); |
|
685 | - return update_post_meta( |
|
686 | - $this->ID(), |
|
687 | - $this->get_billing_info_postmeta_name($payment_method), |
|
688 | - $billing_form->input_values(true) |
|
689 | - ); |
|
690 | - } |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * Return the link to the admin details for the object. |
|
695 | - * |
|
696 | - * @return string |
|
697 | - * @throws EE_Error |
|
698 | - * @throws InvalidArgumentException |
|
699 | - * @throws InvalidDataTypeException |
|
700 | - * @throws InvalidInterfaceException |
|
701 | - * @throws ReflectionException |
|
702 | - */ |
|
703 | - public function get_admin_details_link() |
|
704 | - { |
|
705 | - return $this->get_admin_edit_link(); |
|
706 | - } |
|
707 | - |
|
708 | - |
|
709 | - /** |
|
710 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
711 | - * |
|
712 | - * @return string |
|
713 | - * @throws EE_Error |
|
714 | - * @throws InvalidArgumentException |
|
715 | - * @throws ReflectionException |
|
716 | - * @throws InvalidDataTypeException |
|
717 | - * @throws InvalidInterfaceException |
|
718 | - */ |
|
719 | - public function get_admin_edit_link() |
|
720 | - { |
|
721 | - EE_Registry::instance()->load_helper('URL'); |
|
722 | - return EEH_URL::add_query_args_and_nonce( |
|
723 | - array( |
|
724 | - 'page' => 'espresso_registrations', |
|
725 | - 'action' => 'edit_attendee', |
|
726 | - 'post' => $this->ID(), |
|
727 | - ), |
|
728 | - admin_url('admin.php') |
|
729 | - ); |
|
730 | - } |
|
731 | - |
|
732 | - |
|
733 | - /** |
|
734 | - * Returns the link to a settings page for the object. |
|
735 | - * |
|
736 | - * @return string |
|
737 | - * @throws EE_Error |
|
738 | - * @throws InvalidArgumentException |
|
739 | - * @throws InvalidDataTypeException |
|
740 | - * @throws InvalidInterfaceException |
|
741 | - * @throws ReflectionException |
|
742 | - */ |
|
743 | - public function get_admin_settings_link() |
|
744 | - { |
|
745 | - return $this->get_admin_edit_link(); |
|
746 | - } |
|
747 | - |
|
748 | - |
|
749 | - /** |
|
750 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
751 | - * |
|
752 | - * @return string |
|
753 | - * @throws EE_Error |
|
754 | - * @throws InvalidArgumentException |
|
755 | - * @throws ReflectionException |
|
756 | - * @throws InvalidDataTypeException |
|
757 | - * @throws InvalidInterfaceException |
|
758 | - */ |
|
759 | - public function get_admin_overview_link() |
|
760 | - { |
|
761 | - EE_Registry::instance()->load_helper('URL'); |
|
762 | - return EEH_URL::add_query_args_and_nonce( |
|
763 | - array( |
|
764 | - 'page' => 'espresso_registrations', |
|
765 | - 'action' => 'contact_list', |
|
766 | - ), |
|
767 | - admin_url('admin.php') |
|
768 | - ); |
|
769 | - } |
|
28 | + /** |
|
29 | + * Sets some dynamic defaults |
|
30 | + * |
|
31 | + * @param array $fieldValues |
|
32 | + * @param bool $bydb |
|
33 | + * @param string $timezone |
|
34 | + * @param array $date_formats |
|
35 | + * @throws EE_Error |
|
36 | + */ |
|
37 | + protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
38 | + { |
|
39 | + if (! isset($fieldValues['ATT_full_name'])) { |
|
40 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
41 | + $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
42 | + $fieldValues['ATT_full_name'] = $fname . $lname; |
|
43 | + } |
|
44 | + if (! isset($fieldValues['ATT_slug'])) { |
|
45 | + // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
46 | + $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
47 | + } |
|
48 | + if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
49 | + $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
50 | + } |
|
51 | + parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @param array $props_n_values incoming values |
|
57 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
58 | + * used.) |
|
59 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
60 | + * date_format and the second value is the time format |
|
61 | + * @return EE_Attendee |
|
62 | + * @throws EE_Error |
|
63 | + */ |
|
64 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
65 | + { |
|
66 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
67 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @param array $props_n_values incoming values from the database |
|
73 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
74 | + * the website will be used. |
|
75 | + * @return EE_Attendee |
|
76 | + */ |
|
77 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
78 | + { |
|
79 | + return new self($props_n_values, true, $timezone); |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * Set Attendee First Name |
|
85 | + * |
|
86 | + * @access public |
|
87 | + * @param string $fname |
|
88 | + * @throws EE_Error |
|
89 | + */ |
|
90 | + public function set_fname($fname = '') |
|
91 | + { |
|
92 | + $this->set('ATT_fname', $fname); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * Set Attendee Last Name |
|
98 | + * |
|
99 | + * @access public |
|
100 | + * @param string $lname |
|
101 | + * @throws EE_Error |
|
102 | + */ |
|
103 | + public function set_lname($lname = '') |
|
104 | + { |
|
105 | + $this->set('ATT_lname', $lname); |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * Set Attendee Address |
|
111 | + * |
|
112 | + * @access public |
|
113 | + * @param string $address |
|
114 | + * @throws EE_Error |
|
115 | + */ |
|
116 | + public function set_address($address = '') |
|
117 | + { |
|
118 | + $this->set('ATT_address', $address); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * Set Attendee Address2 |
|
124 | + * |
|
125 | + * @access public |
|
126 | + * @param string $address2 |
|
127 | + * @throws EE_Error |
|
128 | + */ |
|
129 | + public function set_address2($address2 = '') |
|
130 | + { |
|
131 | + $this->set('ATT_address2', $address2); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * Set Attendee City |
|
137 | + * |
|
138 | + * @access public |
|
139 | + * @param string $city |
|
140 | + * @throws EE_Error |
|
141 | + */ |
|
142 | + public function set_city($city = '') |
|
143 | + { |
|
144 | + $this->set('ATT_city', $city); |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * Set Attendee State ID |
|
150 | + * |
|
151 | + * @access public |
|
152 | + * @param int $STA_ID |
|
153 | + * @throws EE_Error |
|
154 | + */ |
|
155 | + public function set_state($STA_ID = 0) |
|
156 | + { |
|
157 | + $this->set('STA_ID', $STA_ID); |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * Set Attendee Country ISO Code |
|
163 | + * |
|
164 | + * @access public |
|
165 | + * @param string $CNT_ISO |
|
166 | + * @throws EE_Error |
|
167 | + */ |
|
168 | + public function set_country($CNT_ISO = '') |
|
169 | + { |
|
170 | + $this->set('CNT_ISO', $CNT_ISO); |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * Set Attendee Zip/Postal Code |
|
176 | + * |
|
177 | + * @access public |
|
178 | + * @param string $zip |
|
179 | + * @throws EE_Error |
|
180 | + */ |
|
181 | + public function set_zip($zip = '') |
|
182 | + { |
|
183 | + $this->set('ATT_zip', $zip); |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * Set Attendee Email Address |
|
189 | + * |
|
190 | + * @access public |
|
191 | + * @param string $email |
|
192 | + * @throws EE_Error |
|
193 | + */ |
|
194 | + public function set_email($email = '') |
|
195 | + { |
|
196 | + $this->set('ATT_email', $email); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * Set Attendee Phone |
|
202 | + * |
|
203 | + * @access public |
|
204 | + * @param string $phone |
|
205 | + * @throws EE_Error |
|
206 | + */ |
|
207 | + public function set_phone($phone = '') |
|
208 | + { |
|
209 | + $this->set('ATT_phone', $phone); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * set deleted |
|
215 | + * |
|
216 | + * @access public |
|
217 | + * @param bool $ATT_deleted |
|
218 | + * @throws EE_Error |
|
219 | + */ |
|
220 | + public function set_deleted($ATT_deleted = false) |
|
221 | + { |
|
222 | + $this->set('ATT_deleted', $ATT_deleted); |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * Returns the value for the post_author id saved with the cpt |
|
228 | + * |
|
229 | + * @since 4.5.0 |
|
230 | + * @return int |
|
231 | + * @throws EE_Error |
|
232 | + */ |
|
233 | + public function wp_user() |
|
234 | + { |
|
235 | + return $this->get('ATT_author'); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * get Attendee First Name |
|
241 | + * |
|
242 | + * @access public |
|
243 | + * @return string |
|
244 | + * @throws EE_Error |
|
245 | + */ |
|
246 | + public function fname() |
|
247 | + { |
|
248 | + return $this->get('ATT_fname'); |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * echoes out the attendee's first name |
|
254 | + * |
|
255 | + * @return void |
|
256 | + * @throws EE_Error |
|
257 | + */ |
|
258 | + public function e_full_name() |
|
259 | + { |
|
260 | + echo $this->full_name(); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * Returns the first and last name concatenated together with a space. |
|
266 | + * |
|
267 | + * @param bool $apply_html_entities |
|
268 | + * @return string |
|
269 | + * @throws EE_Error |
|
270 | + */ |
|
271 | + public function full_name($apply_html_entities = false) |
|
272 | + { |
|
273 | + $full_name = array( |
|
274 | + $this->fname(), |
|
275 | + $this->lname(), |
|
276 | + ); |
|
277 | + $full_name = array_filter($full_name); |
|
278 | + $full_name = implode(' ', $full_name); |
|
279 | + return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
285 | + * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
286 | + * attendee. |
|
287 | + * |
|
288 | + * @param bool $apply_html_entities |
|
289 | + * @return string |
|
290 | + * @throws EE_Error |
|
291 | + */ |
|
292 | + public function ATT_full_name($apply_html_entities = false) |
|
293 | + { |
|
294 | + return $apply_html_entities |
|
295 | + ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
296 | + : $this->get('ATT_full_name'); |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * get Attendee Last Name |
|
302 | + * |
|
303 | + * @access public |
|
304 | + * @return string |
|
305 | + * @throws EE_Error |
|
306 | + */ |
|
307 | + public function lname() |
|
308 | + { |
|
309 | + return $this->get('ATT_lname'); |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
315 | + * |
|
316 | + * @return array numerically indexed, with each part of the address that is known. |
|
317 | + * Eg, if the user only responded to state and country, |
|
318 | + * it would be array(0=>'Alabama',1=>'USA') |
|
319 | + * @return array |
|
320 | + * @throws EE_Error |
|
321 | + */ |
|
322 | + public function full_address_as_array() |
|
323 | + { |
|
324 | + $full_address_array = array(); |
|
325 | + $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
326 | + foreach ($initial_address_fields as $address_field_name) { |
|
327 | + $address_fields_value = $this->get($address_field_name); |
|
328 | + if (! empty($address_fields_value)) { |
|
329 | + $full_address_array[] = $address_fields_value; |
|
330 | + } |
|
331 | + } |
|
332 | + // now handle state and country |
|
333 | + $state_obj = $this->state_obj(); |
|
334 | + if ($state_obj instanceof EE_State) { |
|
335 | + $full_address_array[] = $state_obj->name(); |
|
336 | + } |
|
337 | + $country_obj = $this->country_obj(); |
|
338 | + if ($country_obj instanceof EE_Country) { |
|
339 | + $full_address_array[] = $country_obj->name(); |
|
340 | + } |
|
341 | + // lastly get the xip |
|
342 | + $zip_value = $this->zip(); |
|
343 | + if (! empty($zip_value)) { |
|
344 | + $full_address_array[] = $zip_value; |
|
345 | + } |
|
346 | + return $full_address_array; |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * get Attendee Address |
|
352 | + * |
|
353 | + * @return string |
|
354 | + * @throws EE_Error |
|
355 | + */ |
|
356 | + public function address() |
|
357 | + { |
|
358 | + return $this->get('ATT_address'); |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * get Attendee Address2 |
|
364 | + * |
|
365 | + * @return string |
|
366 | + * @throws EE_Error |
|
367 | + */ |
|
368 | + public function address2() |
|
369 | + { |
|
370 | + return $this->get('ATT_address2'); |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * get Attendee City |
|
376 | + * |
|
377 | + * @return string |
|
378 | + * @throws EE_Error |
|
379 | + */ |
|
380 | + public function city() |
|
381 | + { |
|
382 | + return $this->get('ATT_city'); |
|
383 | + } |
|
384 | + |
|
385 | + |
|
386 | + /** |
|
387 | + * get Attendee State ID |
|
388 | + * |
|
389 | + * @return string |
|
390 | + * @throws EE_Error |
|
391 | + */ |
|
392 | + public function state_ID() |
|
393 | + { |
|
394 | + return $this->get('STA_ID'); |
|
395 | + } |
|
396 | + |
|
397 | + |
|
398 | + /** |
|
399 | + * @return string |
|
400 | + * @throws EE_Error |
|
401 | + */ |
|
402 | + public function state_abbrev() |
|
403 | + { |
|
404 | + return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * Gets the state set to this attendee |
|
410 | + * |
|
411 | + * @return EE_State |
|
412 | + * @throws EE_Error |
|
413 | + */ |
|
414 | + public function state_obj() |
|
415 | + { |
|
416 | + return $this->get_first_related('State'); |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + /** |
|
421 | + * Returns the state's name, otherwise 'Unknown' |
|
422 | + * |
|
423 | + * @return string |
|
424 | + * @throws EE_Error |
|
425 | + */ |
|
426 | + public function state_name() |
|
427 | + { |
|
428 | + if ($this->state_obj()) { |
|
429 | + return $this->state_obj()->name(); |
|
430 | + } else { |
|
431 | + return ''; |
|
432 | + } |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * either displays the state abbreviation or the state name, as determined |
|
438 | + * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
439 | + * defaults to abbreviation |
|
440 | + * |
|
441 | + * @return string |
|
442 | + * @throws EE_Error |
|
443 | + */ |
|
444 | + public function state() |
|
445 | + { |
|
446 | + if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
447 | + return $this->state_abbrev(); |
|
448 | + } |
|
449 | + return $this->state_name(); |
|
450 | + } |
|
451 | + |
|
452 | + |
|
453 | + /** |
|
454 | + * get Attendee Country ISO Code |
|
455 | + * |
|
456 | + * @return string |
|
457 | + * @throws EE_Error |
|
458 | + */ |
|
459 | + public function country_ID() |
|
460 | + { |
|
461 | + return $this->get('CNT_ISO'); |
|
462 | + } |
|
463 | + |
|
464 | + |
|
465 | + /** |
|
466 | + * Gets country set for this attendee |
|
467 | + * |
|
468 | + * @return EE_Country |
|
469 | + * @throws EE_Error |
|
470 | + */ |
|
471 | + public function country_obj() |
|
472 | + { |
|
473 | + return $this->get_first_related('Country'); |
|
474 | + } |
|
475 | + |
|
476 | + |
|
477 | + /** |
|
478 | + * Returns the country's name if known, otherwise 'Unknown' |
|
479 | + * |
|
480 | + * @return string |
|
481 | + * @throws EE_Error |
|
482 | + */ |
|
483 | + public function country_name() |
|
484 | + { |
|
485 | + if ($this->country_obj()) { |
|
486 | + return $this->country_obj()->name(); |
|
487 | + } |
|
488 | + return ''; |
|
489 | + } |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * either displays the country ISO2 code or the country name, as determined |
|
494 | + * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
495 | + * defaults to abbreviation |
|
496 | + * |
|
497 | + * @return string |
|
498 | + * @throws EE_Error |
|
499 | + */ |
|
500 | + public function country() |
|
501 | + { |
|
502 | + if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
503 | + return $this->country_ID(); |
|
504 | + } |
|
505 | + return $this->country_name(); |
|
506 | + } |
|
507 | + |
|
508 | + |
|
509 | + /** |
|
510 | + * get Attendee Zip/Postal Code |
|
511 | + * |
|
512 | + * @return string |
|
513 | + * @throws EE_Error |
|
514 | + */ |
|
515 | + public function zip() |
|
516 | + { |
|
517 | + return $this->get('ATT_zip'); |
|
518 | + } |
|
519 | + |
|
520 | + |
|
521 | + /** |
|
522 | + * get Attendee Email Address |
|
523 | + * |
|
524 | + * @return string |
|
525 | + * @throws EE_Error |
|
526 | + */ |
|
527 | + public function email() |
|
528 | + { |
|
529 | + return $this->get('ATT_email'); |
|
530 | + } |
|
531 | + |
|
532 | + |
|
533 | + /** |
|
534 | + * get Attendee Phone # |
|
535 | + * |
|
536 | + * @return string |
|
537 | + * @throws EE_Error |
|
538 | + */ |
|
539 | + public function phone() |
|
540 | + { |
|
541 | + return $this->get('ATT_phone'); |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * get deleted |
|
547 | + * |
|
548 | + * @return bool |
|
549 | + * @throws EE_Error |
|
550 | + */ |
|
551 | + public function deleted() |
|
552 | + { |
|
553 | + return $this->get('ATT_deleted'); |
|
554 | + } |
|
555 | + |
|
556 | + |
|
557 | + /** |
|
558 | + * Gets registrations of this attendee |
|
559 | + * |
|
560 | + * @param array $query_params |
|
561 | + * @return EE_Registration[] |
|
562 | + * @throws EE_Error |
|
563 | + */ |
|
564 | + public function get_registrations($query_params = array()) |
|
565 | + { |
|
566 | + return $this->get_many_related('Registration', $query_params); |
|
567 | + } |
|
568 | + |
|
569 | + |
|
570 | + /** |
|
571 | + * Gets the most recent registration of this attendee |
|
572 | + * |
|
573 | + * @return EE_Registration |
|
574 | + * @throws EE_Error |
|
575 | + */ |
|
576 | + public function get_most_recent_registration() |
|
577 | + { |
|
578 | + return $this->get_first_related( |
|
579 | + 'Registration', |
|
580 | + array('order_by' => array('REG_date' => 'DESC')) |
|
581 | + ); // null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
582 | + } |
|
583 | + |
|
584 | + |
|
585 | + /** |
|
586 | + * Gets the most recent registration for this attend at this event |
|
587 | + * |
|
588 | + * @param int $event_id |
|
589 | + * @return EE_Registration |
|
590 | + * @throws EE_Error |
|
591 | + */ |
|
592 | + public function get_most_recent_registration_for_event($event_id) |
|
593 | + { |
|
594 | + return $this->get_first_related( |
|
595 | + 'Registration', |
|
596 | + array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')) |
|
597 | + ); |
|
598 | + } |
|
599 | + |
|
600 | + |
|
601 | + /** |
|
602 | + * returns any events attached to this attendee ($_Event property); |
|
603 | + * |
|
604 | + * @return array |
|
605 | + * @throws EE_Error |
|
606 | + */ |
|
607 | + public function events() |
|
608 | + { |
|
609 | + return $this->get_many_related('Event'); |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
615 | + * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
616 | + * used to save the billing info |
|
617 | + * |
|
618 | + * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
619 | + * @return EE_Form_Section_Proper|null |
|
620 | + * @throws EE_Error |
|
621 | + */ |
|
622 | + public function billing_info_for_payment_method($payment_method) |
|
623 | + { |
|
624 | + $pm_type = $payment_method->type_obj(); |
|
625 | + if (! $pm_type instanceof EE_PMT_Base) { |
|
626 | + return null; |
|
627 | + } |
|
628 | + $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
629 | + if (! $billing_info) { |
|
630 | + return null; |
|
631 | + } |
|
632 | + $billing_form = $pm_type->billing_form(); |
|
633 | + // double-check the form isn't totally hidden, in which case pretend there is no form |
|
634 | + $form_totally_hidden = true; |
|
635 | + foreach ($billing_form->inputs_in_subsections() as $input) { |
|
636 | + if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
637 | + $form_totally_hidden = false; |
|
638 | + break; |
|
639 | + } |
|
640 | + } |
|
641 | + if ($form_totally_hidden) { |
|
642 | + return null; |
|
643 | + } |
|
644 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
645 | + $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
646 | + } |
|
647 | + |
|
648 | + return $billing_form; |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + /** |
|
653 | + * Gets the postmeta key that holds this attendee's billing info for the |
|
654 | + * specified payment method |
|
655 | + * |
|
656 | + * @param EE_Payment_Method $payment_method |
|
657 | + * @return string |
|
658 | + * @throws EE_Error |
|
659 | + */ |
|
660 | + public function get_billing_info_postmeta_name($payment_method) |
|
661 | + { |
|
662 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
663 | + return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
664 | + } |
|
665 | + return null; |
|
666 | + } |
|
667 | + |
|
668 | + |
|
669 | + /** |
|
670 | + * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
671 | + * retrieve it |
|
672 | + * |
|
673 | + * @param EE_Billing_Attendee_Info_Form $billing_form |
|
674 | + * @param EE_Payment_Method $payment_method |
|
675 | + * @return boolean |
|
676 | + * @throws EE_Error |
|
677 | + */ |
|
678 | + public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
679 | + { |
|
680 | + if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
681 | + EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
|
682 | + return false; |
|
683 | + } |
|
684 | + $billing_form->clean_sensitive_data(); |
|
685 | + return update_post_meta( |
|
686 | + $this->ID(), |
|
687 | + $this->get_billing_info_postmeta_name($payment_method), |
|
688 | + $billing_form->input_values(true) |
|
689 | + ); |
|
690 | + } |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * Return the link to the admin details for the object. |
|
695 | + * |
|
696 | + * @return string |
|
697 | + * @throws EE_Error |
|
698 | + * @throws InvalidArgumentException |
|
699 | + * @throws InvalidDataTypeException |
|
700 | + * @throws InvalidInterfaceException |
|
701 | + * @throws ReflectionException |
|
702 | + */ |
|
703 | + public function get_admin_details_link() |
|
704 | + { |
|
705 | + return $this->get_admin_edit_link(); |
|
706 | + } |
|
707 | + |
|
708 | + |
|
709 | + /** |
|
710 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
711 | + * |
|
712 | + * @return string |
|
713 | + * @throws EE_Error |
|
714 | + * @throws InvalidArgumentException |
|
715 | + * @throws ReflectionException |
|
716 | + * @throws InvalidDataTypeException |
|
717 | + * @throws InvalidInterfaceException |
|
718 | + */ |
|
719 | + public function get_admin_edit_link() |
|
720 | + { |
|
721 | + EE_Registry::instance()->load_helper('URL'); |
|
722 | + return EEH_URL::add_query_args_and_nonce( |
|
723 | + array( |
|
724 | + 'page' => 'espresso_registrations', |
|
725 | + 'action' => 'edit_attendee', |
|
726 | + 'post' => $this->ID(), |
|
727 | + ), |
|
728 | + admin_url('admin.php') |
|
729 | + ); |
|
730 | + } |
|
731 | + |
|
732 | + |
|
733 | + /** |
|
734 | + * Returns the link to a settings page for the object. |
|
735 | + * |
|
736 | + * @return string |
|
737 | + * @throws EE_Error |
|
738 | + * @throws InvalidArgumentException |
|
739 | + * @throws InvalidDataTypeException |
|
740 | + * @throws InvalidInterfaceException |
|
741 | + * @throws ReflectionException |
|
742 | + */ |
|
743 | + public function get_admin_settings_link() |
|
744 | + { |
|
745 | + return $this->get_admin_edit_link(); |
|
746 | + } |
|
747 | + |
|
748 | + |
|
749 | + /** |
|
750 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
751 | + * |
|
752 | + * @return string |
|
753 | + * @throws EE_Error |
|
754 | + * @throws InvalidArgumentException |
|
755 | + * @throws ReflectionException |
|
756 | + * @throws InvalidDataTypeException |
|
757 | + * @throws InvalidInterfaceException |
|
758 | + */ |
|
759 | + public function get_admin_overview_link() |
|
760 | + { |
|
761 | + EE_Registry::instance()->load_helper('URL'); |
|
762 | + return EEH_URL::add_query_args_and_nonce( |
|
763 | + array( |
|
764 | + 'page' => 'espresso_registrations', |
|
765 | + 'action' => 'contact_list', |
|
766 | + ), |
|
767 | + admin_url('admin.php') |
|
768 | + ); |
|
769 | + } |
|
770 | 770 | } |
@@ -36,16 +36,16 @@ discard block |
||
36 | 36 | */ |
37 | 37 | protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
38 | 38 | { |
39 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
40 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
39 | + if ( ! isset($fieldValues['ATT_full_name'])) { |
|
40 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'].' ' : ''; |
|
41 | 41 | $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
42 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
42 | + $fieldValues['ATT_full_name'] = $fname.$lname; |
|
43 | 43 | } |
44 | - if (! isset($fieldValues['ATT_slug'])) { |
|
44 | + if ( ! isset($fieldValues['ATT_slug'])) { |
|
45 | 45 | // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
46 | 46 | $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
47 | 47 | } |
48 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
48 | + if ( ! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
49 | 49 | $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
50 | 50 | } |
51 | 51 | parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
326 | 326 | foreach ($initial_address_fields as $address_field_name) { |
327 | 327 | $address_fields_value = $this->get($address_field_name); |
328 | - if (! empty($address_fields_value)) { |
|
328 | + if ( ! empty($address_fields_value)) { |
|
329 | 329 | $full_address_array[] = $address_fields_value; |
330 | 330 | } |
331 | 331 | } |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | } |
341 | 341 | // lastly get the xip |
342 | 342 | $zip_value = $this->zip(); |
343 | - if (! empty($zip_value)) { |
|
343 | + if ( ! empty($zip_value)) { |
|
344 | 344 | $full_address_array[] = $zip_value; |
345 | 345 | } |
346 | 346 | return $full_address_array; |
@@ -622,18 +622,18 @@ discard block |
||
622 | 622 | public function billing_info_for_payment_method($payment_method) |
623 | 623 | { |
624 | 624 | $pm_type = $payment_method->type_obj(); |
625 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
625 | + if ( ! $pm_type instanceof EE_PMT_Base) { |
|
626 | 626 | return null; |
627 | 627 | } |
628 | 628 | $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
629 | - if (! $billing_info) { |
|
629 | + if ( ! $billing_info) { |
|
630 | 630 | return null; |
631 | 631 | } |
632 | 632 | $billing_form = $pm_type->billing_form(); |
633 | 633 | // double-check the form isn't totally hidden, in which case pretend there is no form |
634 | 634 | $form_totally_hidden = true; |
635 | 635 | foreach ($billing_form->inputs_in_subsections() as $input) { |
636 | - if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
636 | + if ( ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
637 | 637 | $form_totally_hidden = false; |
638 | 638 | break; |
639 | 639 | } |
@@ -660,7 +660,7 @@ discard block |
||
660 | 660 | public function get_billing_info_postmeta_name($payment_method) |
661 | 661 | { |
662 | 662 | if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
663 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
663 | + return 'billing_info_'.$payment_method->type_obj()->system_name(); |
|
664 | 664 | } |
665 | 665 | return null; |
666 | 666 | } |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | */ |
678 | 678 | public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
679 | 679 | { |
680 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
680 | + if ( ! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
681 | 681 | EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
682 | 682 | return false; |
683 | 683 | } |
@@ -51,7 +51,7 @@ |
||
51 | 51 | */ |
52 | 52 | public function wp_user_obj() |
53 | 53 | { |
54 | - if (! $this->_wp_user_obj) { |
|
54 | + if ( ! $this->_wp_user_obj) { |
|
55 | 55 | $this->_wp_user_obj = get_user_by('ID', $this->ID()); |
56 | 56 | } |
57 | 57 | return $this->_wp_user_obj; |
@@ -11,91 +11,91 @@ |
||
11 | 11 | class EE_WP_User extends EE_Base_Class implements EEI_Admin_Links |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @var WP_User |
|
16 | - */ |
|
17 | - protected $_wp_user_obj; |
|
14 | + /** |
|
15 | + * @var WP_User |
|
16 | + */ |
|
17 | + protected $_wp_user_obj; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @param array $props_n_values |
|
21 | - * @return EE_WP_User|mixed |
|
22 | - */ |
|
23 | - public static function new_instance($props_n_values = array()) |
|
24 | - { |
|
25 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
26 | - return $has_object ? $has_object : new self($props_n_values); |
|
27 | - } |
|
19 | + /** |
|
20 | + * @param array $props_n_values |
|
21 | + * @return EE_WP_User|mixed |
|
22 | + */ |
|
23 | + public static function new_instance($props_n_values = array()) |
|
24 | + { |
|
25 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
26 | + return $has_object ? $has_object : new self($props_n_values); |
|
27 | + } |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * @param array $props_n_values |
|
32 | - * @return EE_WP_User |
|
33 | - */ |
|
34 | - public static function new_instance_from_db($props_n_values = array()) |
|
35 | - { |
|
36 | - return new self($props_n_values, true); |
|
37 | - } |
|
30 | + /** |
|
31 | + * @param array $props_n_values |
|
32 | + * @return EE_WP_User |
|
33 | + */ |
|
34 | + public static function new_instance_from_db($props_n_values = array()) |
|
35 | + { |
|
36 | + return new self($props_n_values, true); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Return a normal WP_User object (caches the object for future calls) |
|
41 | - * |
|
42 | - * @return WP_User |
|
43 | - */ |
|
44 | - public function wp_user_obj() |
|
45 | - { |
|
46 | - if (! $this->_wp_user_obj) { |
|
47 | - $this->_wp_user_obj = get_user_by('ID', $this->ID()); |
|
48 | - } |
|
49 | - return $this->_wp_user_obj; |
|
50 | - } |
|
39 | + /** |
|
40 | + * Return a normal WP_User object (caches the object for future calls) |
|
41 | + * |
|
42 | + * @return WP_User |
|
43 | + */ |
|
44 | + public function wp_user_obj() |
|
45 | + { |
|
46 | + if (! $this->_wp_user_obj) { |
|
47 | + $this->_wp_user_obj = get_user_by('ID', $this->ID()); |
|
48 | + } |
|
49 | + return $this->_wp_user_obj; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Return the link to the admin details for the object. |
|
54 | - * |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - public function get_admin_details_link() |
|
58 | - { |
|
59 | - return $this->get_admin_edit_link(); |
|
60 | - } |
|
52 | + /** |
|
53 | + * Return the link to the admin details for the object. |
|
54 | + * |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + public function get_admin_details_link() |
|
58 | + { |
|
59 | + return $this->get_admin_edit_link(); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
64 | - * |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function get_admin_edit_link() |
|
68 | - { |
|
69 | - return esc_url( |
|
70 | - add_query_arg( |
|
71 | - 'wp_http_referer', |
|
72 | - urlencode( |
|
73 | - wp_unslash( |
|
74 | - $_SERVER['REQUEST_URI'] |
|
75 | - ) |
|
76 | - ), |
|
77 | - get_edit_user_link($this->ID()) |
|
78 | - ) |
|
79 | - ); |
|
80 | - } |
|
62 | + /** |
|
63 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
64 | + * |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function get_admin_edit_link() |
|
68 | + { |
|
69 | + return esc_url( |
|
70 | + add_query_arg( |
|
71 | + 'wp_http_referer', |
|
72 | + urlencode( |
|
73 | + wp_unslash( |
|
74 | + $_SERVER['REQUEST_URI'] |
|
75 | + ) |
|
76 | + ), |
|
77 | + get_edit_user_link($this->ID()) |
|
78 | + ) |
|
79 | + ); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Returns the link to a settings page for the object. |
|
84 | - * |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - public function get_admin_settings_link() |
|
88 | - { |
|
89 | - return $this->get_admin_edit_link(); |
|
90 | - } |
|
82 | + /** |
|
83 | + * Returns the link to a settings page for the object. |
|
84 | + * |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + public function get_admin_settings_link() |
|
88 | + { |
|
89 | + return $this->get_admin_edit_link(); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
94 | - * |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public function get_admin_overview_link() |
|
98 | - { |
|
99 | - return admin_url('users.php'); |
|
100 | - } |
|
92 | + /** |
|
93 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
94 | + * |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public function get_admin_overview_link() |
|
98 | + { |
|
99 | + return admin_url('users.php'); |
|
100 | + } |
|
101 | 101 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * this method instantiates modules and calls the method that was defined when the route was registered |
183 | 183 | * |
184 | 184 | * @param string $module_name |
185 | - * @return EED_Module|object|null |
|
185 | + * @return null|EED_Module |
|
186 | 186 | * @throws ReflectionException |
187 | 187 | */ |
188 | 188 | public static function module_factory($module_name) |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | |
253 | 253 | |
254 | 254 | /** |
255 | - * @param $current_route |
|
255 | + * @param string $current_route |
|
256 | 256 | * @return string |
257 | 257 | */ |
258 | 258 | public function get_view($current_route) |
@@ -15,255 +15,255 @@ |
||
15 | 15 | final class EE_Module_Request_Router implements InterminableInterface |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var EE_Request $request |
|
20 | - */ |
|
21 | - private $request; |
|
18 | + /** |
|
19 | + * @var EE_Request $request |
|
20 | + */ |
|
21 | + private $request; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @var array $_previous_routes |
|
25 | - */ |
|
26 | - private static $_previous_routes = array(); |
|
23 | + /** |
|
24 | + * @var array $_previous_routes |
|
25 | + */ |
|
26 | + private static $_previous_routes = array(); |
|
27 | 27 | |
28 | - /** |
|
29 | - * @var WP_Query $WP_Query |
|
30 | - */ |
|
31 | - public $WP_Query; |
|
28 | + /** |
|
29 | + * @var WP_Query $WP_Query |
|
30 | + */ |
|
31 | + public $WP_Query; |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * EE_Module_Request_Router constructor. |
|
36 | - * |
|
37 | - * @param EE_Request $request |
|
38 | - */ |
|
39 | - public function __construct(EE_Request $request) |
|
40 | - { |
|
41 | - $this->request = $request; |
|
42 | - } |
|
34 | + /** |
|
35 | + * EE_Module_Request_Router constructor. |
|
36 | + * |
|
37 | + * @param EE_Request $request |
|
38 | + */ |
|
39 | + public function __construct(EE_Request $request) |
|
40 | + { |
|
41 | + $this->request = $request; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
47 | - * on subsequent calls to this method, |
|
48 | - * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
49 | - * and checks if the last called route has any forwarding routes registered for it |
|
50 | - * |
|
51 | - * @param WP_Query $WP_Query |
|
52 | - * @return NULL|string |
|
53 | - * @throws EE_Error |
|
54 | - * @throws ReflectionException |
|
55 | - */ |
|
56 | - public function get_route(WP_Query $WP_Query) |
|
57 | - { |
|
58 | - $this->WP_Query = $WP_Query; |
|
59 | - // assume this if first route being called |
|
60 | - $previous_route = false; |
|
61 | - // but is it really ??? |
|
62 | - if (! empty(self::$_previous_routes)) { |
|
63 | - // get last run route |
|
64 | - $previous_routes = array_values(self::$_previous_routes); |
|
65 | - $previous_route = array_pop($previous_routes); |
|
66 | - } |
|
67 | - // has another route already been run ? |
|
68 | - if ($previous_route) { |
|
69 | - // check if forwarding has been set |
|
70 | - $current_route = $this->get_forward($previous_route); |
|
71 | - try { |
|
72 | - // check for recursive forwarding |
|
73 | - if (isset(self::$_previous_routes[ $current_route ])) { |
|
74 | - throw new EE_Error( |
|
75 | - sprintf( |
|
76 | - __( |
|
77 | - 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
78 | - 'event_espresso' |
|
79 | - ), |
|
80 | - $current_route |
|
81 | - ) |
|
82 | - ); |
|
83 | - } |
|
84 | - } catch (EE_Error $e) { |
|
85 | - $e->get_error(); |
|
86 | - return null; |
|
87 | - } |
|
88 | - } else { |
|
89 | - // first route called |
|
90 | - $current_route = null; |
|
91 | - // grab all routes |
|
92 | - $routes = EE_Config::get_routes(); |
|
93 | - foreach ($routes as $key => $route) { |
|
94 | - // first determine if route key uses w?ldc*rds |
|
95 | - $uses_wildcards = strpos($key, '?') !== false |
|
96 | - || strpos($key, '*') !== false; |
|
97 | - // check request for module route |
|
98 | - $route_found = $uses_wildcards |
|
99 | - ? $this->request->matches($key) |
|
100 | - : $this->request->is_set($key); |
|
101 | - if ($route_found) { |
|
102 | - $current_route = $uses_wildcards |
|
103 | - ? $this->request->getMatch($key) |
|
104 | - : $this->request->get($key); |
|
105 | - $current_route = sanitize_text_field($current_route); |
|
106 | - if ($current_route) { |
|
107 | - $current_route = array($key, $current_route); |
|
108 | - break; |
|
109 | - } |
|
110 | - } |
|
111 | - } |
|
112 | - } |
|
113 | - // sorry, but I can't read what you route ! |
|
114 | - if (empty($current_route)) { |
|
115 | - return null; |
|
116 | - } |
|
117 | - // add route to previous routes array |
|
118 | - self::$_previous_routes[] = $current_route; |
|
119 | - return $current_route; |
|
120 | - } |
|
45 | + /** |
|
46 | + * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
47 | + * on subsequent calls to this method, |
|
48 | + * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
49 | + * and checks if the last called route has any forwarding routes registered for it |
|
50 | + * |
|
51 | + * @param WP_Query $WP_Query |
|
52 | + * @return NULL|string |
|
53 | + * @throws EE_Error |
|
54 | + * @throws ReflectionException |
|
55 | + */ |
|
56 | + public function get_route(WP_Query $WP_Query) |
|
57 | + { |
|
58 | + $this->WP_Query = $WP_Query; |
|
59 | + // assume this if first route being called |
|
60 | + $previous_route = false; |
|
61 | + // but is it really ??? |
|
62 | + if (! empty(self::$_previous_routes)) { |
|
63 | + // get last run route |
|
64 | + $previous_routes = array_values(self::$_previous_routes); |
|
65 | + $previous_route = array_pop($previous_routes); |
|
66 | + } |
|
67 | + // has another route already been run ? |
|
68 | + if ($previous_route) { |
|
69 | + // check if forwarding has been set |
|
70 | + $current_route = $this->get_forward($previous_route); |
|
71 | + try { |
|
72 | + // check for recursive forwarding |
|
73 | + if (isset(self::$_previous_routes[ $current_route ])) { |
|
74 | + throw new EE_Error( |
|
75 | + sprintf( |
|
76 | + __( |
|
77 | + 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
78 | + 'event_espresso' |
|
79 | + ), |
|
80 | + $current_route |
|
81 | + ) |
|
82 | + ); |
|
83 | + } |
|
84 | + } catch (EE_Error $e) { |
|
85 | + $e->get_error(); |
|
86 | + return null; |
|
87 | + } |
|
88 | + } else { |
|
89 | + // first route called |
|
90 | + $current_route = null; |
|
91 | + // grab all routes |
|
92 | + $routes = EE_Config::get_routes(); |
|
93 | + foreach ($routes as $key => $route) { |
|
94 | + // first determine if route key uses w?ldc*rds |
|
95 | + $uses_wildcards = strpos($key, '?') !== false |
|
96 | + || strpos($key, '*') !== false; |
|
97 | + // check request for module route |
|
98 | + $route_found = $uses_wildcards |
|
99 | + ? $this->request->matches($key) |
|
100 | + : $this->request->is_set($key); |
|
101 | + if ($route_found) { |
|
102 | + $current_route = $uses_wildcards |
|
103 | + ? $this->request->getMatch($key) |
|
104 | + : $this->request->get($key); |
|
105 | + $current_route = sanitize_text_field($current_route); |
|
106 | + if ($current_route) { |
|
107 | + $current_route = array($key, $current_route); |
|
108 | + break; |
|
109 | + } |
|
110 | + } |
|
111 | + } |
|
112 | + } |
|
113 | + // sorry, but I can't read what you route ! |
|
114 | + if (empty($current_route)) { |
|
115 | + return null; |
|
116 | + } |
|
117 | + // add route to previous routes array |
|
118 | + self::$_previous_routes[] = $current_route; |
|
119 | + return $current_route; |
|
120 | + } |
|
121 | 121 | |
122 | 122 | |
123 | - /** |
|
124 | - * this method simply takes a valid route, and resolves what module class method the route points to |
|
125 | - * |
|
126 | - * @param string $key |
|
127 | - * @param string $current_route |
|
128 | - * @return mixed EED_Module | boolean |
|
129 | - * @throws EE_Error |
|
130 | - * @throws ReflectionException |
|
131 | - */ |
|
132 | - public function resolve_route($key, $current_route) |
|
133 | - { |
|
134 | - // get module method that route has been mapped to |
|
135 | - $module_method = EE_Config::get_route($current_route, $key); |
|
136 | - // verify result was returned |
|
137 | - if (empty($module_method)) { |
|
138 | - $msg = sprintf( |
|
139 | - __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
140 | - $current_route |
|
141 | - ); |
|
142 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
143 | - return false; |
|
144 | - } |
|
145 | - // verify that result is an array |
|
146 | - if (! is_array($module_method)) { |
|
147 | - $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
148 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
149 | - return false; |
|
150 | - } |
|
151 | - // grab module name |
|
152 | - $module_name = $module_method[0]; |
|
153 | - // verify that a class method was registered properly |
|
154 | - if (! isset($module_method[1])) { |
|
155 | - $msg = sprintf( |
|
156 | - __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
157 | - $current_route |
|
158 | - ); |
|
159 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
160 | - return false; |
|
161 | - } |
|
162 | - // grab method |
|
163 | - $method = $module_method[1]; |
|
164 | - // verify that class exists |
|
165 | - if (! class_exists($module_name)) { |
|
166 | - $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
167 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
168 | - return false; |
|
169 | - } |
|
170 | - // verify that method exists |
|
171 | - if (! method_exists($module_name, $method)) { |
|
172 | - $msg = sprintf( |
|
173 | - __('The class method %s for the %s route is in invalid.', 'event_espresso'), |
|
174 | - $method, |
|
175 | - $current_route |
|
176 | - ); |
|
177 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
178 | - return false; |
|
179 | - } |
|
180 | - // instantiate module and call route method |
|
181 | - return $this->_module_router($module_name, $method); |
|
182 | - } |
|
123 | + /** |
|
124 | + * this method simply takes a valid route, and resolves what module class method the route points to |
|
125 | + * |
|
126 | + * @param string $key |
|
127 | + * @param string $current_route |
|
128 | + * @return mixed EED_Module | boolean |
|
129 | + * @throws EE_Error |
|
130 | + * @throws ReflectionException |
|
131 | + */ |
|
132 | + public function resolve_route($key, $current_route) |
|
133 | + { |
|
134 | + // get module method that route has been mapped to |
|
135 | + $module_method = EE_Config::get_route($current_route, $key); |
|
136 | + // verify result was returned |
|
137 | + if (empty($module_method)) { |
|
138 | + $msg = sprintf( |
|
139 | + __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
140 | + $current_route |
|
141 | + ); |
|
142 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
143 | + return false; |
|
144 | + } |
|
145 | + // verify that result is an array |
|
146 | + if (! is_array($module_method)) { |
|
147 | + $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
148 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
149 | + return false; |
|
150 | + } |
|
151 | + // grab module name |
|
152 | + $module_name = $module_method[0]; |
|
153 | + // verify that a class method was registered properly |
|
154 | + if (! isset($module_method[1])) { |
|
155 | + $msg = sprintf( |
|
156 | + __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
157 | + $current_route |
|
158 | + ); |
|
159 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
160 | + return false; |
|
161 | + } |
|
162 | + // grab method |
|
163 | + $method = $module_method[1]; |
|
164 | + // verify that class exists |
|
165 | + if (! class_exists($module_name)) { |
|
166 | + $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
167 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
168 | + return false; |
|
169 | + } |
|
170 | + // verify that method exists |
|
171 | + if (! method_exists($module_name, $method)) { |
|
172 | + $msg = sprintf( |
|
173 | + __('The class method %s for the %s route is in invalid.', 'event_espresso'), |
|
174 | + $method, |
|
175 | + $current_route |
|
176 | + ); |
|
177 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
178 | + return false; |
|
179 | + } |
|
180 | + // instantiate module and call route method |
|
181 | + return $this->_module_router($module_name, $method); |
|
182 | + } |
|
183 | 183 | |
184 | 184 | |
185 | - /** |
|
186 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
187 | - * |
|
188 | - * @param string $module_name |
|
189 | - * @return EED_Module|object|null |
|
190 | - * @throws ReflectionException |
|
191 | - */ |
|
192 | - public static function module_factory($module_name) |
|
193 | - { |
|
194 | - if ($module_name === 'EED_Module') { |
|
195 | - EE_Error::add_error( |
|
196 | - sprintf( |
|
197 | - __( |
|
198 | - 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
199 | - 'event_espresso' |
|
200 | - ), |
|
201 | - $module_name |
|
202 | - ), |
|
203 | - __FILE__, |
|
204 | - __FUNCTION__, |
|
205 | - __LINE__ |
|
206 | - ); |
|
207 | - return null; |
|
208 | - } |
|
209 | - // instantiate module class |
|
210 | - $module = new $module_name(); |
|
211 | - // ensure that class is actually a module |
|
212 | - if (! $module instanceof EED_Module) { |
|
213 | - EE_Error::add_error( |
|
214 | - sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
215 | - __FILE__, |
|
216 | - __FUNCTION__, |
|
217 | - __LINE__ |
|
218 | - ); |
|
219 | - return null; |
|
220 | - } |
|
221 | - return $module; |
|
222 | - } |
|
185 | + /** |
|
186 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
187 | + * |
|
188 | + * @param string $module_name |
|
189 | + * @return EED_Module|object|null |
|
190 | + * @throws ReflectionException |
|
191 | + */ |
|
192 | + public static function module_factory($module_name) |
|
193 | + { |
|
194 | + if ($module_name === 'EED_Module') { |
|
195 | + EE_Error::add_error( |
|
196 | + sprintf( |
|
197 | + __( |
|
198 | + 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
199 | + 'event_espresso' |
|
200 | + ), |
|
201 | + $module_name |
|
202 | + ), |
|
203 | + __FILE__, |
|
204 | + __FUNCTION__, |
|
205 | + __LINE__ |
|
206 | + ); |
|
207 | + return null; |
|
208 | + } |
|
209 | + // instantiate module class |
|
210 | + $module = new $module_name(); |
|
211 | + // ensure that class is actually a module |
|
212 | + if (! $module instanceof EED_Module) { |
|
213 | + EE_Error::add_error( |
|
214 | + sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
215 | + __FILE__, |
|
216 | + __FUNCTION__, |
|
217 | + __LINE__ |
|
218 | + ); |
|
219 | + return null; |
|
220 | + } |
|
221 | + return $module; |
|
222 | + } |
|
223 | 223 | |
224 | 224 | |
225 | - /** |
|
226 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
227 | - * |
|
228 | - * @param string $module_name |
|
229 | - * @param string $method |
|
230 | - * @return EED_Module|null |
|
231 | - * @throws EE_Error |
|
232 | - * @throws ReflectionException |
|
233 | - */ |
|
234 | - private function _module_router($module_name, $method) |
|
235 | - { |
|
236 | - // instantiate module class |
|
237 | - $module = EE_Module_Request_Router::module_factory($module_name); |
|
238 | - if ($module instanceof EED_Module) { |
|
239 | - // and call whatever action the route was for |
|
240 | - try { |
|
241 | - call_user_func(array($module, $method), $this->WP_Query); |
|
242 | - } catch (EE_Error $e) { |
|
243 | - $e->get_error(); |
|
244 | - return null; |
|
245 | - } |
|
246 | - } |
|
247 | - return $module; |
|
248 | - } |
|
225 | + /** |
|
226 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
227 | + * |
|
228 | + * @param string $module_name |
|
229 | + * @param string $method |
|
230 | + * @return EED_Module|null |
|
231 | + * @throws EE_Error |
|
232 | + * @throws ReflectionException |
|
233 | + */ |
|
234 | + private function _module_router($module_name, $method) |
|
235 | + { |
|
236 | + // instantiate module class |
|
237 | + $module = EE_Module_Request_Router::module_factory($module_name); |
|
238 | + if ($module instanceof EED_Module) { |
|
239 | + // and call whatever action the route was for |
|
240 | + try { |
|
241 | + call_user_func(array($module, $method), $this->WP_Query); |
|
242 | + } catch (EE_Error $e) { |
|
243 | + $e->get_error(); |
|
244 | + return null; |
|
245 | + } |
|
246 | + } |
|
247 | + return $module; |
|
248 | + } |
|
249 | 249 | |
250 | 250 | |
251 | - /** |
|
252 | - * @param $current_route |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - public function get_forward($current_route) |
|
256 | - { |
|
257 | - return EE_Config::get_forward($current_route); |
|
258 | - } |
|
251 | + /** |
|
252 | + * @param $current_route |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + public function get_forward($current_route) |
|
256 | + { |
|
257 | + return EE_Config::get_forward($current_route); |
|
258 | + } |
|
259 | 259 | |
260 | 260 | |
261 | - /** |
|
262 | - * @param $current_route |
|
263 | - * @return string |
|
264 | - */ |
|
265 | - public function get_view($current_route) |
|
266 | - { |
|
267 | - return EE_Config::get_view($current_route); |
|
268 | - } |
|
261 | + /** |
|
262 | + * @param $current_route |
|
263 | + * @return string |
|
264 | + */ |
|
265 | + public function get_view($current_route) |
|
266 | + { |
|
267 | + return EE_Config::get_view($current_route); |
|
268 | + } |
|
269 | 269 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | // assume this if first route being called |
60 | 60 | $previous_route = false; |
61 | 61 | // but is it really ??? |
62 | - if (! empty(self::$_previous_routes)) { |
|
62 | + if ( ! empty(self::$_previous_routes)) { |
|
63 | 63 | // get last run route |
64 | 64 | $previous_routes = array_values(self::$_previous_routes); |
65 | 65 | $previous_route = array_pop($previous_routes); |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $current_route = $this->get_forward($previous_route); |
71 | 71 | try { |
72 | 72 | // check for recursive forwarding |
73 | - if (isset(self::$_previous_routes[ $current_route ])) { |
|
73 | + if (isset(self::$_previous_routes[$current_route])) { |
|
74 | 74 | throw new EE_Error( |
75 | 75 | sprintf( |
76 | 76 | __( |
@@ -143,38 +143,38 @@ discard block |
||
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | // verify that result is an array |
146 | - if (! is_array($module_method)) { |
|
146 | + if ( ! is_array($module_method)) { |
|
147 | 147 | $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
148 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
148 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
149 | 149 | return false; |
150 | 150 | } |
151 | 151 | // grab module name |
152 | 152 | $module_name = $module_method[0]; |
153 | 153 | // verify that a class method was registered properly |
154 | - if (! isset($module_method[1])) { |
|
154 | + if ( ! isset($module_method[1])) { |
|
155 | 155 | $msg = sprintf( |
156 | 156 | __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
157 | 157 | $current_route |
158 | 158 | ); |
159 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
159 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
160 | 160 | return false; |
161 | 161 | } |
162 | 162 | // grab method |
163 | 163 | $method = $module_method[1]; |
164 | 164 | // verify that class exists |
165 | - if (! class_exists($module_name)) { |
|
165 | + if ( ! class_exists($module_name)) { |
|
166 | 166 | $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
167 | 167 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
168 | 168 | return false; |
169 | 169 | } |
170 | 170 | // verify that method exists |
171 | - if (! method_exists($module_name, $method)) { |
|
171 | + if ( ! method_exists($module_name, $method)) { |
|
172 | 172 | $msg = sprintf( |
173 | 173 | __('The class method %s for the %s route is in invalid.', 'event_espresso'), |
174 | 174 | $method, |
175 | 175 | $current_route |
176 | 176 | ); |
177 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
177 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
178 | 178 | return false; |
179 | 179 | } |
180 | 180 | // instantiate module and call route method |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | // instantiate module class |
210 | 210 | $module = new $module_name(); |
211 | 211 | // ensure that class is actually a module |
212 | - if (! $module instanceof EED_Module) { |
|
212 | + if ( ! $module instanceof EED_Module) { |
|
213 | 213 | EE_Error::add_error( |
214 | 214 | sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
215 | 215 | __FILE__, |
@@ -9,24 +9,24 @@ |
||
9 | 9 | interface EEI_Request_Decorator |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * converts a Request to a Response |
|
14 | - * can perform their logic either before or after the core application has run like so: |
|
15 | - * public function handle_request( EE_Request $request, EE_Response $response ) { |
|
16 | - * $this->request = $request; |
|
17 | - * $this->response = $response; |
|
18 | - * // logic performed BEFORE core app has run |
|
19 | - * $this->process_request_stack( $this->request, $this->response ); |
|
20 | - * // logic performed AFTER core app has run |
|
21 | - * return $response; |
|
22 | - * } |
|
23 | - * |
|
24 | - * @deprecated 4.9.53 |
|
25 | - * @param EE_Request $request |
|
26 | - * @param EE_Response $response |
|
27 | - * @return EE_Response |
|
28 | - */ |
|
29 | - public function handle_request(EE_Request $request, EE_Response $response); |
|
12 | + /** |
|
13 | + * converts a Request to a Response |
|
14 | + * can perform their logic either before or after the core application has run like so: |
|
15 | + * public function handle_request( EE_Request $request, EE_Response $response ) { |
|
16 | + * $this->request = $request; |
|
17 | + * $this->response = $response; |
|
18 | + * // logic performed BEFORE core app has run |
|
19 | + * $this->process_request_stack( $this->request, $this->response ); |
|
20 | + * // logic performed AFTER core app has run |
|
21 | + * return $response; |
|
22 | + * } |
|
23 | + * |
|
24 | + * @deprecated 4.9.53 |
|
25 | + * @param EE_Request $request |
|
26 | + * @param EE_Response $response |
|
27 | + * @return EE_Response |
|
28 | + */ |
|
29 | + public function handle_request(EE_Request $request, EE_Response $response); |
|
30 | 30 | |
31 | 31 | |
32 | 32 | } |
@@ -15,125 +15,125 @@ |
||
15 | 15 | interface LegacyRequestInterface |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @return array |
|
20 | - */ |
|
21 | - public function get_params(); |
|
18 | + /** |
|
19 | + * @return array |
|
20 | + */ |
|
21 | + public function get_params(); |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * @return array |
|
26 | - */ |
|
27 | - public function post_params(); |
|
24 | + /** |
|
25 | + * @return array |
|
26 | + */ |
|
27 | + public function post_params(); |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * @return array |
|
32 | - */ |
|
33 | - public function cookie_params(); |
|
30 | + /** |
|
31 | + * @return array |
|
32 | + */ |
|
33 | + public function cookie_params(); |
|
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * @return array |
|
38 | - */ |
|
39 | - public function server_params(); |
|
36 | + /** |
|
37 | + * @return array |
|
38 | + */ |
|
39 | + public function server_params(); |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * returns contents of $_REQUEST |
|
44 | - * |
|
45 | - * @return array |
|
46 | - */ |
|
47 | - public function params(); |
|
42 | + /** |
|
43 | + * returns contents of $_REQUEST |
|
44 | + * |
|
45 | + * @return array |
|
46 | + */ |
|
47 | + public function params(); |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @param $key |
|
52 | - * @param $value |
|
53 | - * @param bool $override_ee |
|
54 | - * @return void |
|
55 | - */ |
|
56 | - public function set($key, $value, $override_ee = false); |
|
50 | + /** |
|
51 | + * @param $key |
|
52 | + * @param $value |
|
53 | + * @param bool $override_ee |
|
54 | + * @return void |
|
55 | + */ |
|
56 | + public function set($key, $value, $override_ee = false); |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * returns the value for a request param if the given key exists |
|
61 | - * |
|
62 | - * @param $key |
|
63 | - * @param null $default |
|
64 | - * @return mixed |
|
65 | - */ |
|
66 | - public function get($key, $default = null); |
|
59 | + /** |
|
60 | + * returns the value for a request param if the given key exists |
|
61 | + * |
|
62 | + * @param $key |
|
63 | + * @param null $default |
|
64 | + * @return mixed |
|
65 | + */ |
|
66 | + public function get($key, $default = null); |
|
67 | 67 | |
68 | 68 | |
69 | - /** |
|
70 | - * check if param exists |
|
71 | - * |
|
72 | - * @param $key |
|
73 | - * @return bool |
|
74 | - */ |
|
75 | - public function is_set($key); |
|
69 | + /** |
|
70 | + * check if param exists |
|
71 | + * |
|
72 | + * @param $key |
|
73 | + * @return bool |
|
74 | + */ |
|
75 | + public function is_set($key); |
|
76 | 76 | |
77 | 77 | |
78 | - /** |
|
79 | - * remove param |
|
80 | - * |
|
81 | - * @param $key |
|
82 | - * @param bool $unset_from_global_too |
|
83 | - */ |
|
84 | - public function un_set($key, $unset_from_global_too = false); |
|
78 | + /** |
|
79 | + * remove param |
|
80 | + * |
|
81 | + * @param $key |
|
82 | + * @param bool $unset_from_global_too |
|
83 | + */ |
|
84 | + public function un_set($key, $unset_from_global_too = false); |
|
85 | 85 | |
86 | 86 | |
87 | - /** |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function ip_address(); |
|
87 | + /** |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function ip_address(); |
|
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * @return bool |
|
95 | - */ |
|
96 | - public function isAdmin(); |
|
93 | + /** |
|
94 | + * @return bool |
|
95 | + */ |
|
96 | + public function isAdmin(); |
|
97 | 97 | |
98 | 98 | |
99 | - /** |
|
100 | - * @return mixed |
|
101 | - */ |
|
102 | - public function isAjax(); |
|
99 | + /** |
|
100 | + * @return mixed |
|
101 | + */ |
|
102 | + public function isAjax(); |
|
103 | 103 | |
104 | 104 | |
105 | - /** |
|
106 | - * @return mixed |
|
107 | - */ |
|
108 | - public function isFrontAjax(); |
|
105 | + /** |
|
106 | + * @return mixed |
|
107 | + */ |
|
108 | + public function isFrontAjax(); |
|
109 | 109 | |
110 | 110 | |
111 | - /** |
|
112 | - * @return mixed|string |
|
113 | - */ |
|
114 | - public function requestUri(); |
|
111 | + /** |
|
112 | + * @return mixed|string |
|
113 | + */ |
|
114 | + public function requestUri(); |
|
115 | 115 | |
116 | 116 | |
117 | - /** |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - public function userAgent(); |
|
117 | + /** |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + public function userAgent(); |
|
121 | 121 | |
122 | 122 | |
123 | - /** |
|
124 | - * @param string $user_agent |
|
125 | - */ |
|
126 | - public function setUserAgent($user_agent = ''); |
|
123 | + /** |
|
124 | + * @param string $user_agent |
|
125 | + */ |
|
126 | + public function setUserAgent($user_agent = ''); |
|
127 | 127 | |
128 | 128 | |
129 | - /** |
|
130 | - * @return bool |
|
131 | - */ |
|
132 | - public function isBot(); |
|
129 | + /** |
|
130 | + * @return bool |
|
131 | + */ |
|
132 | + public function isBot(); |
|
133 | 133 | |
134 | 134 | |
135 | - /** |
|
136 | - * @param bool $is_bot |
|
137 | - */ |
|
138 | - public function setIsBot($is_bot); |
|
135 | + /** |
|
136 | + * @param bool $is_bot |
|
137 | + */ |
|
138 | + public function setIsBot($is_bot); |
|
139 | 139 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function setNotice($key, $value) |
60 | 60 | { |
61 | - $this->notice[ $key ] = $value; |
|
61 | + $this->notice[$key] = $value; |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function getNotice($key) |
71 | 71 | { |
72 | - return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null; |
|
72 | + return isset($this->notice[$key]) ? $this->notice[$key] : null; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function addOutput($string, $append = true) |
92 | 92 | { |
93 | - $this->output = $append ? $this->output . $string : $string . $this->output; |
|
93 | + $this->output = $append ? $this->output.$string : $string.$this->output; |
|
94 | 94 | } |
95 | 95 | |
96 | 96 |
@@ -16,119 +16,119 @@ |
||
16 | 16 | class Response implements ResponseInterface, ReservedInstanceInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var array $notice |
|
21 | - */ |
|
22 | - protected $notice = array(); |
|
23 | - |
|
24 | - /** |
|
25 | - * rendered output to be returned to WP |
|
26 | - * |
|
27 | - * @var string $output |
|
28 | - */ |
|
29 | - protected $output = ''; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var bool |
|
33 | - */ |
|
34 | - protected $request_terminated = false; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var bool $deactivate_plugin |
|
38 | - */ |
|
39 | - protected $deactivate_plugin = false; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * EE_Response constructor. |
|
44 | - */ |
|
45 | - public function __construct() |
|
46 | - { |
|
47 | - $this->terminateRequest(false); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * @param $key |
|
53 | - * @param $value |
|
54 | - * @return void |
|
55 | - */ |
|
56 | - public function setNotice($key, $value) |
|
57 | - { |
|
58 | - $this->notice[ $key ] = $value; |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @param $key |
|
64 | - * @return mixed |
|
65 | - */ |
|
66 | - public function getNotice($key) |
|
67 | - { |
|
68 | - return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @return array |
|
74 | - */ |
|
75 | - public function getNotices() |
|
76 | - { |
|
77 | - return $this->notice; |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * @param string $string |
|
83 | - * @param bool $append |
|
84 | - */ |
|
85 | - public function addOutput($string, $append = true) |
|
86 | - { |
|
87 | - $this->output = $append ? $this->output . $string : $string . $this->output; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function getOutput() |
|
95 | - { |
|
96 | - return $this->output; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @return boolean |
|
102 | - */ |
|
103 | - public function requestTerminated() |
|
104 | - { |
|
105 | - return $this->request_terminated; |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @param boolean $request_terminated |
|
111 | - */ |
|
112 | - public function terminateRequest($request_terminated = true) |
|
113 | - { |
|
114 | - $this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @return boolean |
|
120 | - */ |
|
121 | - public function pluginDeactivated() |
|
122 | - { |
|
123 | - return $this->deactivate_plugin; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * sets $deactivate_plugin to true |
|
129 | - */ |
|
130 | - public function deactivatePlugin() |
|
131 | - { |
|
132 | - $this->deactivate_plugin = true; |
|
133 | - } |
|
19 | + /** |
|
20 | + * @var array $notice |
|
21 | + */ |
|
22 | + protected $notice = array(); |
|
23 | + |
|
24 | + /** |
|
25 | + * rendered output to be returned to WP |
|
26 | + * |
|
27 | + * @var string $output |
|
28 | + */ |
|
29 | + protected $output = ''; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var bool |
|
33 | + */ |
|
34 | + protected $request_terminated = false; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var bool $deactivate_plugin |
|
38 | + */ |
|
39 | + protected $deactivate_plugin = false; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * EE_Response constructor. |
|
44 | + */ |
|
45 | + public function __construct() |
|
46 | + { |
|
47 | + $this->terminateRequest(false); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * @param $key |
|
53 | + * @param $value |
|
54 | + * @return void |
|
55 | + */ |
|
56 | + public function setNotice($key, $value) |
|
57 | + { |
|
58 | + $this->notice[ $key ] = $value; |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @param $key |
|
64 | + * @return mixed |
|
65 | + */ |
|
66 | + public function getNotice($key) |
|
67 | + { |
|
68 | + return isset($this->notice[ $key ]) ? $this->notice[ $key ] : null; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @return array |
|
74 | + */ |
|
75 | + public function getNotices() |
|
76 | + { |
|
77 | + return $this->notice; |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * @param string $string |
|
83 | + * @param bool $append |
|
84 | + */ |
|
85 | + public function addOutput($string, $append = true) |
|
86 | + { |
|
87 | + $this->output = $append ? $this->output . $string : $string . $this->output; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function getOutput() |
|
95 | + { |
|
96 | + return $this->output; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @return boolean |
|
102 | + */ |
|
103 | + public function requestTerminated() |
|
104 | + { |
|
105 | + return $this->request_terminated; |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @param boolean $request_terminated |
|
111 | + */ |
|
112 | + public function terminateRequest($request_terminated = true) |
|
113 | + { |
|
114 | + $this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @return boolean |
|
120 | + */ |
|
121 | + public function pluginDeactivated() |
|
122 | + { |
|
123 | + return $this->deactivate_plugin; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * sets $deactivate_plugin to true |
|
129 | + */ |
|
130 | + public function deactivatePlugin() |
|
131 | + { |
|
132 | + $this->deactivate_plugin = true; |
|
133 | + } |
|
134 | 134 | } |
@@ -78,7 +78,7 @@ |
||
78 | 78 | public function preProductionVersionAdminNotice() |
79 | 79 | { |
80 | 80 | new PersistentAdminNotice( |
81 | - 'preProductionVersionAdminNotice_' . EVENT_ESPRESSO_VERSION, |
|
81 | + 'preProductionVersionAdminNotice_'.EVENT_ESPRESSO_VERSION, |
|
82 | 82 | $this->warningNotice() |
83 | 83 | ); |
84 | 84 | } |
@@ -18,91 +18,91 @@ |
||
18 | 18 | class PreProductionVersionWarning extends Middleware |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * converts a Request to a Response |
|
23 | - * |
|
24 | - * @param RequestInterface $request |
|
25 | - * @param ResponseInterface $response |
|
26 | - * @return ResponseInterface |
|
27 | - */ |
|
28 | - public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
29 | - { |
|
30 | - $this->request = $request; |
|
31 | - $this->response = $response; |
|
32 | - $this->displayPreProductionVersionWarning(); |
|
33 | - $this->response = $this->processRequestStack($this->request, $this->response); |
|
34 | - return $this->response; |
|
35 | - } |
|
21 | + /** |
|
22 | + * converts a Request to a Response |
|
23 | + * |
|
24 | + * @param RequestInterface $request |
|
25 | + * @param ResponseInterface $response |
|
26 | + * @return ResponseInterface |
|
27 | + */ |
|
28 | + public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
29 | + { |
|
30 | + $this->request = $request; |
|
31 | + $this->response = $response; |
|
32 | + $this->displayPreProductionVersionWarning(); |
|
33 | + $this->response = $this->processRequestStack($this->request, $this->response); |
|
34 | + return $this->response; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
40 | - * |
|
41 | - * @return void |
|
42 | - */ |
|
43 | - public function displayPreProductionVersionWarning() |
|
44 | - { |
|
45 | - // skip AJAX requests |
|
46 | - if ($this->request->isAjax()) { |
|
47 | - return; |
|
48 | - } |
|
49 | - // skip stable releases |
|
50 | - if (substr(EVENT_ESPRESSO_VERSION, -5) !== '.beta') { |
|
51 | - return; |
|
52 | - } |
|
53 | - // site admin has authorized use of non-stable release candidate for production |
|
54 | - if (defined('ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE') && ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE) { |
|
55 | - return; |
|
56 | - } |
|
57 | - // post release candidate warning |
|
58 | - if ($this->request->isAdmin()) { |
|
59 | - add_action('admin_notices', array($this, 'preProductionVersionAdminNotice'), -999); |
|
60 | - } else { |
|
61 | - add_action('shutdown', array($this, 'preProductionVersionWarningNotice'), 10); |
|
62 | - } |
|
63 | - } |
|
38 | + /** |
|
39 | + * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
40 | + * |
|
41 | + * @return void |
|
42 | + */ |
|
43 | + public function displayPreProductionVersionWarning() |
|
44 | + { |
|
45 | + // skip AJAX requests |
|
46 | + if ($this->request->isAjax()) { |
|
47 | + return; |
|
48 | + } |
|
49 | + // skip stable releases |
|
50 | + if (substr(EVENT_ESPRESSO_VERSION, -5) !== '.beta') { |
|
51 | + return; |
|
52 | + } |
|
53 | + // site admin has authorized use of non-stable release candidate for production |
|
54 | + if (defined('ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE') && ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE) { |
|
55 | + return; |
|
56 | + } |
|
57 | + // post release candidate warning |
|
58 | + if ($this->request->isAdmin()) { |
|
59 | + add_action('admin_notices', array($this, 'preProductionVersionAdminNotice'), -999); |
|
60 | + } else { |
|
61 | + add_action('shutdown', array($this, 'preProductionVersionWarningNotice'), 10); |
|
62 | + } |
|
63 | + } |
|
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * displays admin notice that current version of EE is not a stable release |
|
68 | - * |
|
69 | - * @return void |
|
70 | - * @throws InvalidDataTypeException |
|
71 | - */ |
|
72 | - public function preProductionVersionAdminNotice() |
|
73 | - { |
|
74 | - new PersistentAdminNotice( |
|
75 | - 'preProductionVersionAdminNotice_' . EVENT_ESPRESSO_VERSION, |
|
76 | - $this->warningNotice() |
|
77 | - ); |
|
78 | - } |
|
66 | + /** |
|
67 | + * displays admin notice that current version of EE is not a stable release |
|
68 | + * |
|
69 | + * @return void |
|
70 | + * @throws InvalidDataTypeException |
|
71 | + */ |
|
72 | + public function preProductionVersionAdminNotice() |
|
73 | + { |
|
74 | + new PersistentAdminNotice( |
|
75 | + 'preProductionVersionAdminNotice_' . EVENT_ESPRESSO_VERSION, |
|
76 | + $this->warningNotice() |
|
77 | + ); |
|
78 | + } |
|
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * displays message on frontend of site notifying admin that current version of EE is not a stable release |
|
83 | - * |
|
84 | - * @return void |
|
85 | - */ |
|
86 | - public function preProductionVersionWarningNotice() |
|
87 | - { |
|
88 | - echo '<div id="ee-release-candidate-notice-dv" class="ee-really-important-notice-dv"><p>'; |
|
89 | - echo $this->warningNotice(); |
|
90 | - echo '</p></div>'; |
|
91 | - } |
|
81 | + /** |
|
82 | + * displays message on frontend of site notifying admin that current version of EE is not a stable release |
|
83 | + * |
|
84 | + * @return void |
|
85 | + */ |
|
86 | + public function preProductionVersionWarningNotice() |
|
87 | + { |
|
88 | + echo '<div id="ee-release-candidate-notice-dv" class="ee-really-important-notice-dv"><p>'; |
|
89 | + echo $this->warningNotice(); |
|
90 | + echo '</p></div>'; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - private function warningNotice() |
|
98 | - { |
|
99 | - return sprintf( |
|
100 | - esc_html__( |
|
101 | - 'This version of Event Espresso is for testing and/or evaluation purposes only. It is %1$snot%2$s considered a stable release and should therefore %1$snot%2$s be activated on a live or production website.', |
|
102 | - 'event_espresso' |
|
103 | - ), |
|
104 | - '<strong>', |
|
105 | - '</strong>' |
|
106 | - ); |
|
107 | - } |
|
94 | + /** |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + private function warningNotice() |
|
98 | + { |
|
99 | + return sprintf( |
|
100 | + esc_html__( |
|
101 | + 'This version of Event Espresso is for testing and/or evaluation purposes only. It is %1$snot%2$s considered a stable release and should therefore %1$snot%2$s be activated on a live or production website.', |
|
102 | + 'event_espresso' |
|
103 | + ), |
|
104 | + '<strong>', |
|
105 | + '</strong>' |
|
106 | + ); |
|
107 | + } |
|
108 | 108 | } |