@@ -17,627 +17,627 @@ |
||
17 | 17 | { |
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * These properties just hold the name for the Messenger and Message Type (defined by child classes). |
|
22 | - * These are used for retrieving objects etc. |
|
23 | - * |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - protected $_m_name; |
|
27 | - protected $_mt_name; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * This will hold any error messages from the validation process. |
|
32 | - * The _errors property holds an associative array of error messages |
|
33 | - * listing the field as the key and the message as the value. |
|
34 | - * |
|
35 | - * @var array() |
|
36 | - */ |
|
37 | - private $_errors = array(); |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * holds an array of fields being validated |
|
42 | - * |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - protected $_fields; |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * this will hold the incoming context |
|
50 | - * |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - protected $_context; |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * this holds an array of fields and the relevant validation information |
|
58 | - * that the incoming fields data get validated against. |
|
59 | - * This gets setup in the _set_props() method. |
|
60 | - * |
|
61 | - * @var array |
|
62 | - */ |
|
63 | - protected $_validators; |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * holds the messenger object |
|
68 | - * |
|
69 | - * @var object |
|
70 | - */ |
|
71 | - protected $_messenger; |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * holds the message type object |
|
76 | - * |
|
77 | - * @var object |
|
78 | - */ |
|
79 | - protected $_message_type; |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * will hold any valid_shortcode modifications made by the _modify_validator() method. |
|
84 | - * |
|
85 | - * @var array |
|
86 | - */ |
|
87 | - protected $_valid_shortcodes_modifier; |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * There may be times where a message type wants to include a shortcode group but exclude specific |
|
92 | - * shortcodes. If that's the case then it can set this property as an array of shortcodes to exclude and |
|
93 | - * they will not be allowed. |
|
94 | - * Array should be indexed by field and values are an array of specific shortcodes to exclude. |
|
95 | - * |
|
96 | - * @var array |
|
97 | - */ |
|
98 | - protected $_specific_shortcode_excludes = array(); |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * Runs the validator using the incoming fields array as the fields/values to check. |
|
103 | - * |
|
104 | - * @param array $fields The fields sent by the EEM object. |
|
105 | - * @param $context |
|
106 | - * @throws EE_Error |
|
107 | - * @throws ReflectionException |
|
108 | - */ |
|
109 | - public function __construct($fields, $context) |
|
110 | - { |
|
111 | - // check that _m_name and _mt_name have been set by child class otherwise we get out. |
|
112 | - if (empty($this->_m_name) || empty($this->_mt_name)) { |
|
113 | - throw new EE_Error( |
|
114 | - esc_html__( |
|
115 | - 'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property. Check that the child class is doing this', |
|
116 | - 'event_espresso' |
|
117 | - ) |
|
118 | - ); |
|
119 | - } |
|
120 | - $this->_fields = $fields; |
|
121 | - $this->_context = $context; |
|
122 | - |
|
123 | - // load messenger and message_type objects and the related shortcode objects. |
|
124 | - $this->_load_objects(); |
|
125 | - |
|
126 | - |
|
127 | - // modify any messenger/message_type specific validation instructions. This is what child classes define. |
|
128 | - $this->_modify_validator(); |
|
129 | - |
|
130 | - |
|
131 | - // let's set validators property |
|
132 | - $this->_set_validators(); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * Child classes instantiate this and use it to modify the _validator_config array property |
|
138 | - * for the messenger using messengers set_validate_config() method. |
|
139 | - * This is so we can specify specific validation instructions for a messenger/message_type combo |
|
140 | - * that aren't handled by the defaults setup in the messenger. |
|
141 | - * |
|
142 | - * @abstract |
|
143 | - * @access protected |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - abstract protected function _modify_validator(); |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * loads all objects used by validator |
|
151 | - * |
|
152 | - * @access private |
|
153 | - * @throws \EE_Error |
|
154 | - */ |
|
155 | - private function _load_objects() |
|
156 | - { |
|
157 | - // load messenger |
|
158 | - $messenger = ucwords(str_replace('_', ' ', $this->_m_name)); |
|
159 | - $messenger = str_replace(' ', '_', $messenger); |
|
160 | - $messenger = 'EE_' . $messenger . '_messenger'; |
|
161 | - |
|
162 | - if (! class_exists($messenger)) { |
|
163 | - throw new EE_Error( |
|
164 | - sprintf( |
|
165 | - esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'), |
|
166 | - $this->_m_name |
|
167 | - ) |
|
168 | - ); |
|
169 | - } |
|
170 | - |
|
171 | - $this->_messenger = new $messenger(); |
|
172 | - |
|
173 | - // load message type |
|
174 | - $message_type = ucwords(str_replace('_', ' ', $this->_mt_name)); |
|
175 | - $message_type = str_replace(' ', '_', $message_type); |
|
176 | - $message_type = 'EE_' . $message_type . '_message_type'; |
|
177 | - |
|
178 | - if (! class_exists($message_type)) { |
|
179 | - throw new EE_Error( |
|
180 | - sprintf( |
|
181 | - esc_html__('There is no message type class for the given string (%s)', 'event_espresso'), |
|
182 | - $this->_mt_name |
|
183 | - ) |
|
184 | - ); |
|
185 | - } |
|
186 | - |
|
187 | - $this->_message_type = new $message_type(); |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * used to set the $_validators property |
|
193 | - * |
|
194 | - * @access private |
|
195 | - * @return void |
|
196 | - * @throws ReflectionException |
|
197 | - */ |
|
198 | - private function _set_validators() |
|
199 | - { |
|
200 | - // let's get all valid shortcodes from mt and message type |
|
201 | - // (messenger will have its set in the _validator_config property for the messenger) |
|
202 | - $mt_codes = $this->_message_type->get_valid_shortcodes(); |
|
203 | - |
|
204 | - |
|
205 | - // get messenger validator_config |
|
206 | - $msgr_validator = $this->_messenger->get_validator_config(); |
|
207 | - |
|
208 | - |
|
209 | - // we only want the valid shortcodes for the given context! |
|
210 | - $context = $this->_context; |
|
211 | - $mt_codes = $mt_codes[ $context ]; |
|
212 | - |
|
213 | - // in this first loop we're just getting all shortcode group indexes from the msgr_validator |
|
214 | - // into a single array (so we can get the appropriate shortcode objects for the groups) |
|
215 | - $shortcode_groups = $mt_codes; |
|
216 | - $groups_per_field = array(); |
|
217 | - |
|
218 | - foreach ($msgr_validator as $field => $config) { |
|
219 | - if (empty($config) || ! isset($config['shortcodes'])) { |
|
220 | - continue; |
|
221 | - } //Nothing to see here. |
|
222 | - $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes); |
|
223 | - $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups); |
|
224 | - } |
|
225 | - |
|
226 | - $shortcode_groups = array_unique($shortcode_groups); |
|
227 | - |
|
228 | - // okay now we've got our groups. |
|
229 | - // Let's get the codes from the objects into an array indexed by group for easy retrieval later. |
|
230 | - $codes_from_objs = array(); |
|
231 | - |
|
232 | - foreach ($shortcode_groups as $group) { |
|
233 | - $ref = ucwords(str_replace('_', ' ', $group)); |
|
234 | - $ref = str_replace(' ', '_', $ref); |
|
235 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
236 | - if (class_exists($classname)) { |
|
237 | - $a = new ReflectionClass($classname); |
|
238 | - $obj = $a->newInstance(); |
|
239 | - $codes_from_objs[ $group ] = $obj->get_shortcodes(); |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique) |
|
245 | - $final_mt_codes = array(); |
|
246 | - foreach ($mt_codes as $group) { |
|
247 | - $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]); |
|
248 | - } |
|
249 | - |
|
250 | - $mt_codes = $final_mt_codes; |
|
251 | - |
|
252 | - |
|
253 | - // k now in this next loop we're going to loop through $msgr_validator again |
|
254 | - // and setup the _validators property from the data we've setup so far. |
|
255 | - foreach ($msgr_validator as $field => $config) { |
|
256 | - // if required shortcode is not in our list of codes for the given field, then we skip this field. |
|
257 | - $required = isset($config['required']) |
|
258 | - ? array_intersect($config['required'], array_keys($mt_codes)) |
|
259 | - : true; |
|
260 | - if (empty($required)) { |
|
261 | - continue; |
|
262 | - } |
|
263 | - |
|
264 | - if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) { |
|
265 | - // If we have an override then we use it to indicate the codes we want. |
|
266 | - $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
267 | - $this->_valid_shortcodes_modifier[ $context ][ $field ], |
|
268 | - $codes_from_objs |
|
269 | - ); |
|
270 | - } elseif (isset($groups_per_field[ $field ])) { |
|
271 | - // if we have specific shortcodes for a field then we need to use them |
|
272 | - $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
273 | - $groups_per_field[ $field ], |
|
274 | - $codes_from_objs |
|
275 | - ); |
|
276 | - } elseif (empty($config)) { |
|
277 | - // if empty config then we're assuming we're just going to use the shortcodes from the message type |
|
278 | - // context |
|
279 | - $this->_validators[ $field ]['shortcodes'] = $mt_codes; |
|
280 | - } elseif (isset($config['specific_shortcodes'])) { |
|
281 | - // if we have specific shortcodes then we need to use them |
|
282 | - $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes']; |
|
283 | - } else { |
|
284 | - // otherwise the shortcodes are what is set by the messenger for that field |
|
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 | - } else { |
|
373 | - // most likely the field is found in the 'extra' array. |
|
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 | - } |
|
20 | + /** |
|
21 | + * These properties just hold the name for the Messenger and Message Type (defined by child classes). |
|
22 | + * These are used for retrieving objects etc. |
|
23 | + * |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + protected $_m_name; |
|
27 | + protected $_mt_name; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * This will hold any error messages from the validation process. |
|
32 | + * The _errors property holds an associative array of error messages |
|
33 | + * listing the field as the key and the message as the value. |
|
34 | + * |
|
35 | + * @var array() |
|
36 | + */ |
|
37 | + private $_errors = array(); |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * holds an array of fields being validated |
|
42 | + * |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + protected $_fields; |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * this will hold the incoming context |
|
50 | + * |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + protected $_context; |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * this holds an array of fields and the relevant validation information |
|
58 | + * that the incoming fields data get validated against. |
|
59 | + * This gets setup in the _set_props() method. |
|
60 | + * |
|
61 | + * @var array |
|
62 | + */ |
|
63 | + protected $_validators; |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * holds the messenger object |
|
68 | + * |
|
69 | + * @var object |
|
70 | + */ |
|
71 | + protected $_messenger; |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * holds the message type object |
|
76 | + * |
|
77 | + * @var object |
|
78 | + */ |
|
79 | + protected $_message_type; |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * will hold any valid_shortcode modifications made by the _modify_validator() method. |
|
84 | + * |
|
85 | + * @var array |
|
86 | + */ |
|
87 | + protected $_valid_shortcodes_modifier; |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * There may be times where a message type wants to include a shortcode group but exclude specific |
|
92 | + * shortcodes. If that's the case then it can set this property as an array of shortcodes to exclude and |
|
93 | + * they will not be allowed. |
|
94 | + * Array should be indexed by field and values are an array of specific shortcodes to exclude. |
|
95 | + * |
|
96 | + * @var array |
|
97 | + */ |
|
98 | + protected $_specific_shortcode_excludes = array(); |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * Runs the validator using the incoming fields array as the fields/values to check. |
|
103 | + * |
|
104 | + * @param array $fields The fields sent by the EEM object. |
|
105 | + * @param $context |
|
106 | + * @throws EE_Error |
|
107 | + * @throws ReflectionException |
|
108 | + */ |
|
109 | + public function __construct($fields, $context) |
|
110 | + { |
|
111 | + // check that _m_name and _mt_name have been set by child class otherwise we get out. |
|
112 | + if (empty($this->_m_name) || empty($this->_mt_name)) { |
|
113 | + throw new EE_Error( |
|
114 | + esc_html__( |
|
115 | + 'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property. Check that the child class is doing this', |
|
116 | + 'event_espresso' |
|
117 | + ) |
|
118 | + ); |
|
119 | + } |
|
120 | + $this->_fields = $fields; |
|
121 | + $this->_context = $context; |
|
122 | + |
|
123 | + // load messenger and message_type objects and the related shortcode objects. |
|
124 | + $this->_load_objects(); |
|
125 | + |
|
126 | + |
|
127 | + // modify any messenger/message_type specific validation instructions. This is what child classes define. |
|
128 | + $this->_modify_validator(); |
|
129 | + |
|
130 | + |
|
131 | + // let's set validators property |
|
132 | + $this->_set_validators(); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * Child classes instantiate this and use it to modify the _validator_config array property |
|
138 | + * for the messenger using messengers set_validate_config() method. |
|
139 | + * This is so we can specify specific validation instructions for a messenger/message_type combo |
|
140 | + * that aren't handled by the defaults setup in the messenger. |
|
141 | + * |
|
142 | + * @abstract |
|
143 | + * @access protected |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + abstract protected function _modify_validator(); |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * loads all objects used by validator |
|
151 | + * |
|
152 | + * @access private |
|
153 | + * @throws \EE_Error |
|
154 | + */ |
|
155 | + private function _load_objects() |
|
156 | + { |
|
157 | + // load messenger |
|
158 | + $messenger = ucwords(str_replace('_', ' ', $this->_m_name)); |
|
159 | + $messenger = str_replace(' ', '_', $messenger); |
|
160 | + $messenger = 'EE_' . $messenger . '_messenger'; |
|
161 | + |
|
162 | + if (! class_exists($messenger)) { |
|
163 | + throw new EE_Error( |
|
164 | + sprintf( |
|
165 | + esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'), |
|
166 | + $this->_m_name |
|
167 | + ) |
|
168 | + ); |
|
169 | + } |
|
170 | + |
|
171 | + $this->_messenger = new $messenger(); |
|
172 | + |
|
173 | + // load message type |
|
174 | + $message_type = ucwords(str_replace('_', ' ', $this->_mt_name)); |
|
175 | + $message_type = str_replace(' ', '_', $message_type); |
|
176 | + $message_type = 'EE_' . $message_type . '_message_type'; |
|
177 | + |
|
178 | + if (! class_exists($message_type)) { |
|
179 | + throw new EE_Error( |
|
180 | + sprintf( |
|
181 | + esc_html__('There is no message type class for the given string (%s)', 'event_espresso'), |
|
182 | + $this->_mt_name |
|
183 | + ) |
|
184 | + ); |
|
185 | + } |
|
186 | + |
|
187 | + $this->_message_type = new $message_type(); |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * used to set the $_validators property |
|
193 | + * |
|
194 | + * @access private |
|
195 | + * @return void |
|
196 | + * @throws ReflectionException |
|
197 | + */ |
|
198 | + private function _set_validators() |
|
199 | + { |
|
200 | + // let's get all valid shortcodes from mt and message type |
|
201 | + // (messenger will have its set in the _validator_config property for the messenger) |
|
202 | + $mt_codes = $this->_message_type->get_valid_shortcodes(); |
|
203 | + |
|
204 | + |
|
205 | + // get messenger validator_config |
|
206 | + $msgr_validator = $this->_messenger->get_validator_config(); |
|
207 | + |
|
208 | + |
|
209 | + // we only want the valid shortcodes for the given context! |
|
210 | + $context = $this->_context; |
|
211 | + $mt_codes = $mt_codes[ $context ]; |
|
212 | + |
|
213 | + // in this first loop we're just getting all shortcode group indexes from the msgr_validator |
|
214 | + // into a single array (so we can get the appropriate shortcode objects for the groups) |
|
215 | + $shortcode_groups = $mt_codes; |
|
216 | + $groups_per_field = array(); |
|
217 | + |
|
218 | + foreach ($msgr_validator as $field => $config) { |
|
219 | + if (empty($config) || ! isset($config['shortcodes'])) { |
|
220 | + continue; |
|
221 | + } //Nothing to see here. |
|
222 | + $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes); |
|
223 | + $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups); |
|
224 | + } |
|
225 | + |
|
226 | + $shortcode_groups = array_unique($shortcode_groups); |
|
227 | + |
|
228 | + // okay now we've got our groups. |
|
229 | + // Let's get the codes from the objects into an array indexed by group for easy retrieval later. |
|
230 | + $codes_from_objs = array(); |
|
231 | + |
|
232 | + foreach ($shortcode_groups as $group) { |
|
233 | + $ref = ucwords(str_replace('_', ' ', $group)); |
|
234 | + $ref = str_replace(' ', '_', $ref); |
|
235 | + $classname = 'EE_' . $ref . '_Shortcodes'; |
|
236 | + if (class_exists($classname)) { |
|
237 | + $a = new ReflectionClass($classname); |
|
238 | + $obj = $a->newInstance(); |
|
239 | + $codes_from_objs[ $group ] = $obj->get_shortcodes(); |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique) |
|
245 | + $final_mt_codes = array(); |
|
246 | + foreach ($mt_codes as $group) { |
|
247 | + $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]); |
|
248 | + } |
|
249 | + |
|
250 | + $mt_codes = $final_mt_codes; |
|
251 | + |
|
252 | + |
|
253 | + // k now in this next loop we're going to loop through $msgr_validator again |
|
254 | + // and setup the _validators property from the data we've setup so far. |
|
255 | + foreach ($msgr_validator as $field => $config) { |
|
256 | + // if required shortcode is not in our list of codes for the given field, then we skip this field. |
|
257 | + $required = isset($config['required']) |
|
258 | + ? array_intersect($config['required'], array_keys($mt_codes)) |
|
259 | + : true; |
|
260 | + if (empty($required)) { |
|
261 | + continue; |
|
262 | + } |
|
263 | + |
|
264 | + if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) { |
|
265 | + // If we have an override then we use it to indicate the codes we want. |
|
266 | + $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
267 | + $this->_valid_shortcodes_modifier[ $context ][ $field ], |
|
268 | + $codes_from_objs |
|
269 | + ); |
|
270 | + } elseif (isset($groups_per_field[ $field ])) { |
|
271 | + // if we have specific shortcodes for a field then we need to use them |
|
272 | + $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
273 | + $groups_per_field[ $field ], |
|
274 | + $codes_from_objs |
|
275 | + ); |
|
276 | + } elseif (empty($config)) { |
|
277 | + // if empty config then we're assuming we're just going to use the shortcodes from the message type |
|
278 | + // context |
|
279 | + $this->_validators[ $field ]['shortcodes'] = $mt_codes; |
|
280 | + } elseif (isset($config['specific_shortcodes'])) { |
|
281 | + // if we have specific shortcodes then we need to use them |
|
282 | + $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes']; |
|
283 | + } else { |
|
284 | + // otherwise the shortcodes are what is set by the messenger for that field |
|
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 | + } else { |
|
373 | + // most likely the field is found in the 'extra' array. |
|
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 | } |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | // load messenger |
158 | 158 | $messenger = ucwords(str_replace('_', ' ', $this->_m_name)); |
159 | 159 | $messenger = str_replace(' ', '_', $messenger); |
160 | - $messenger = 'EE_' . $messenger . '_messenger'; |
|
160 | + $messenger = 'EE_'.$messenger.'_messenger'; |
|
161 | 161 | |
162 | - if (! class_exists($messenger)) { |
|
162 | + if ( ! class_exists($messenger)) { |
|
163 | 163 | throw new EE_Error( |
164 | 164 | sprintf( |
165 | 165 | esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'), |
@@ -173,9 +173,9 @@ discard block |
||
173 | 173 | // load message type |
174 | 174 | $message_type = ucwords(str_replace('_', ' ', $this->_mt_name)); |
175 | 175 | $message_type = str_replace(' ', '_', $message_type); |
176 | - $message_type = 'EE_' . $message_type . '_message_type'; |
|
176 | + $message_type = 'EE_'.$message_type.'_message_type'; |
|
177 | 177 | |
178 | - if (! class_exists($message_type)) { |
|
178 | + if ( ! class_exists($message_type)) { |
|
179 | 179 | throw new EE_Error( |
180 | 180 | sprintf( |
181 | 181 | esc_html__('There is no message type class for the given string (%s)', 'event_espresso'), |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | |
209 | 209 | // we only want the valid shortcodes for the given context! |
210 | 210 | $context = $this->_context; |
211 | - $mt_codes = $mt_codes[ $context ]; |
|
211 | + $mt_codes = $mt_codes[$context]; |
|
212 | 212 | |
213 | 213 | // in this first loop we're just getting all shortcode group indexes from the msgr_validator |
214 | 214 | // into a single array (so we can get the appropriate shortcode objects for the groups) |
@@ -219,8 +219,8 @@ discard block |
||
219 | 219 | if (empty($config) || ! isset($config['shortcodes'])) { |
220 | 220 | continue; |
221 | 221 | } //Nothing to see here. |
222 | - $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes); |
|
223 | - $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups); |
|
222 | + $groups_per_field[$field] = array_intersect($config['shortcodes'], $mt_codes); |
|
223 | + $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | $shortcode_groups = array_unique($shortcode_groups); |
@@ -232,11 +232,11 @@ discard block |
||
232 | 232 | foreach ($shortcode_groups as $group) { |
233 | 233 | $ref = ucwords(str_replace('_', ' ', $group)); |
234 | 234 | $ref = str_replace(' ', '_', $ref); |
235 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
235 | + $classname = 'EE_'.$ref.'_Shortcodes'; |
|
236 | 236 | if (class_exists($classname)) { |
237 | 237 | $a = new ReflectionClass($classname); |
238 | 238 | $obj = $a->newInstance(); |
239 | - $codes_from_objs[ $group ] = $obj->get_shortcodes(); |
|
239 | + $codes_from_objs[$group] = $obj->get_shortcodes(); |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique) |
245 | 245 | $final_mt_codes = array(); |
246 | 246 | foreach ($mt_codes as $group) { |
247 | - $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]); |
|
247 | + $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[$group]); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | $mt_codes = $final_mt_codes; |
@@ -261,46 +261,46 @@ discard block |
||
261 | 261 | continue; |
262 | 262 | } |
263 | 263 | |
264 | - if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) { |
|
264 | + if (isset($this->_valid_shortcodes_modifier[$context][$field])) { |
|
265 | 265 | // If we have an override then we use it to indicate the codes we want. |
266 | - $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
267 | - $this->_valid_shortcodes_modifier[ $context ][ $field ], |
|
266 | + $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
267 | + $this->_valid_shortcodes_modifier[$context][$field], |
|
268 | 268 | $codes_from_objs |
269 | 269 | ); |
270 | - } elseif (isset($groups_per_field[ $field ])) { |
|
270 | + } elseif (isset($groups_per_field[$field])) { |
|
271 | 271 | // if we have specific shortcodes for a field then we need to use them |
272 | - $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
273 | - $groups_per_field[ $field ], |
|
272 | + $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
273 | + $groups_per_field[$field], |
|
274 | 274 | $codes_from_objs |
275 | 275 | ); |
276 | 276 | } elseif (empty($config)) { |
277 | 277 | // if empty config then we're assuming we're just going to use the shortcodes from the message type |
278 | 278 | // context |
279 | - $this->_validators[ $field ]['shortcodes'] = $mt_codes; |
|
279 | + $this->_validators[$field]['shortcodes'] = $mt_codes; |
|
280 | 280 | } elseif (isset($config['specific_shortcodes'])) { |
281 | 281 | // if we have specific shortcodes then we need to use them |
282 | - $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes']; |
|
282 | + $this->_validators[$field]['shortcodes'] = $config['specific_shortcodes']; |
|
283 | 283 | } else { |
284 | 284 | // otherwise the shortcodes are what is set by the messenger for that field |
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 | } else { |
373 | 373 | // most likely the field is found in the 'extra' array. |
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( |
@@ -1,19 +1,19 @@ discard block |
||
1 | 1 | <div class="padding"> |
2 | 2 | <p> |
3 | 3 | <?php |
4 | - esc_html_e( |
|
5 | - 'Displays a list of events based on a set of criteria on a WordPress page or post. Unless otherwise specified, events are sorted by start date.', |
|
6 | - 'event_espresso' |
|
7 | - ); |
|
8 | - printf( |
|
9 | - esc_html__( |
|
10 | - 'For a full list of available shortcodes, please view the %sshortcode documentation%s on our website.', |
|
11 | - 'event_espresso' |
|
12 | - ), |
|
13 | - '<a href="https://eventespresso.com/wiki/ee4-shortcodes-template-variables/">', |
|
14 | - '</a>' |
|
15 | - ); |
|
16 | - ?> |
|
4 | + esc_html_e( |
|
5 | + 'Displays a list of events based on a set of criteria on a WordPress page or post. Unless otherwise specified, events are sorted by start date.', |
|
6 | + 'event_espresso' |
|
7 | + ); |
|
8 | + printf( |
|
9 | + esc_html__( |
|
10 | + 'For a full list of available shortcodes, please view the %sshortcode documentation%s on our website.', |
|
11 | + 'event_espresso' |
|
12 | + ), |
|
13 | + '<a href="https://eventespresso.com/wiki/ee4-shortcodes-template-variables/">', |
|
14 | + '</a>' |
|
15 | + ); |
|
16 | + ?> |
|
17 | 17 | </p> |
18 | 18 | <ul> |
19 | 19 | <li> |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | <li> |
38 | 38 | <strong> |
39 | 39 | <?php esc_html_e( |
40 | - 'Limit (paginate) the number of events that are shown in the event list on a page or post', |
|
41 | - 'event_espresso' |
|
42 | - ); ?> |
|
40 | + 'Limit (paginate) the number of events that are shown in the event list on a page or post', |
|
41 | + 'event_espresso' |
|
42 | + ); ?> |
|
43 | 43 | </strong><br/> |
44 | 44 | [ESPRESSO_EVENTS limit=5] |
45 | 45 | </li> |
@@ -76,23 +76,23 @@ discard block |
||
76 | 76 | <li> |
77 | 77 | <strong> |
78 | 78 | <?php esc_html_e( |
79 | - 'Order the event list by a specific set of parameters (refer to available options below)', |
|
80 | - 'event_espresso' |
|
81 | - ); ?> |
|
79 | + 'Order the event list by a specific set of parameters (refer to available options below)', |
|
80 | + 'event_espresso' |
|
81 | + ); ?> |
|
82 | 82 | </strong><br/> |
83 | 83 | [ESPRESSO_EVENTS order_by=start_date,id] |
84 | 84 | </li> |
85 | 85 | </ul> |
86 | 86 | <p> |
87 | 87 | <?php |
88 | - printf( |
|
89 | - esc_html__( |
|
90 | - 'These parameters (options) are available for the %s shortcode parameter above. Multiple parameters should be separated by a comma.', |
|
91 | - 'event_espresso' |
|
92 | - ), |
|
93 | - 'order_by' |
|
94 | - ); |
|
95 | - ?> |
|
88 | + printf( |
|
89 | + esc_html__( |
|
90 | + 'These parameters (options) are available for the %s shortcode parameter above. Multiple parameters should be separated by a comma.', |
|
91 | + 'event_espresso' |
|
92 | + ), |
|
93 | + 'order_by' |
|
94 | + ); |
|
95 | + ?> |
|
96 | 96 | </p> |
97 | 97 | <p> |
98 | 98 | id<br/> |
@@ -3,93 +3,93 @@ |
||
3 | 3 | |
4 | 4 | <h4> |
5 | 5 | <?php esc_html_e( |
6 | - 'You may be able to find an answer for your question or concern here:', |
|
7 | - 'event_espresso' |
|
8 | - ); ?> |
|
6 | + 'You may be able to find an answer for your question or concern here:', |
|
7 | + 'event_espresso' |
|
8 | + ); ?> |
|
9 | 9 | </h4> |
10 | 10 | <ol> |
11 | 11 | <li> |
12 | 12 | <strong><em><?php esc_html_e('A known issue.', 'event_espresso'); ?></em></strong> |
13 | 13 | <?php |
14 | - printf( |
|
15 | - esc_html__( |
|
16 | - 'Some themes and plugins have %1$sknown conflicts%2$s with Event Espresso. (You can also browse the %3$sEvent Espresso support pages%2$s or %4$sEvent Espresso support forums%2$s to see if other members have experienced and solved the problem.)', |
|
17 | - 'event_espresso' |
|
18 | - ), |
|
19 | - '<a href="https://eventespresso.com/wiki/known-third-party-plugin-theme-conflicts/" target="_blank">', |
|
20 | - '</a>', |
|
21 | - '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4" target="_blank">', |
|
22 | - '<a href="https://eventespresso.com/support/forums/" target="_blank">' |
|
23 | - ); |
|
24 | - ?> |
|
14 | + printf( |
|
15 | + esc_html__( |
|
16 | + 'Some themes and plugins have %1$sknown conflicts%2$s with Event Espresso. (You can also browse the %3$sEvent Espresso support pages%2$s or %4$sEvent Espresso support forums%2$s to see if other members have experienced and solved the problem.)', |
|
17 | + 'event_espresso' |
|
18 | + ), |
|
19 | + '<a href="https://eventespresso.com/wiki/known-third-party-plugin-theme-conflicts/" target="_blank">', |
|
20 | + '</a>', |
|
21 | + '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4" target="_blank">', |
|
22 | + '<a href="https://eventespresso.com/support/forums/" target="_blank">' |
|
23 | + ); |
|
24 | + ?> |
|
25 | 25 | </li> |
26 | 26 | <li> |
27 | 27 | <strong><em><?php esc_html_e('A plugin conflict.', 'event_espresso'); ?></em></strong> |
28 | 28 | <?php esc_html_e( |
29 | - 'You can check to see if there is a plugin conflict by temporarily deactivating all plugins except for Event Espresso. If the problem goes away, then reactivate your plugins one by one until the issue returns. This will help you pinpoint the source of the conflict.', |
|
30 | - 'event_espresso' |
|
31 | - ); ?> |
|
29 | + 'You can check to see if there is a plugin conflict by temporarily deactivating all plugins except for Event Espresso. If the problem goes away, then reactivate your plugins one by one until the issue returns. This will help you pinpoint the source of the conflict.', |
|
30 | + 'event_espresso' |
|
31 | + ); ?> |
|
32 | 32 | </li> |
33 | 33 | <li> |
34 | 34 | <strong><em><?php esc_html_e('A theme conflict.', 'event_espresso'); ?></em></strong> |
35 | 35 | <?php |
36 | - $default_theme = wp_get_theme(WP_DEFAULT_THEME); |
|
36 | + $default_theme = wp_get_theme(WP_DEFAULT_THEME); |
|
37 | 37 | |
38 | - if ($default_theme->exists()) { |
|
39 | - printf( |
|
40 | - esc_html__( |
|
41 | - 'If your problem is not a known issue or caused by a plugin, then try activating %s (the default WordPress theme).', |
|
42 | - 'event_espresso' |
|
43 | - ), |
|
44 | - $default_theme->get('Name') |
|
45 | - ); |
|
46 | - } else { |
|
47 | - esc_html_e( |
|
48 | - 'If your problem is not a known issue or caused by a plugin, then try activating the default WordPress theme.', |
|
49 | - 'event_espresso' |
|
50 | - ); |
|
51 | - } |
|
52 | - ?> |
|
38 | + if ($default_theme->exists()) { |
|
39 | + printf( |
|
40 | + esc_html__( |
|
41 | + 'If your problem is not a known issue or caused by a plugin, then try activating %s (the default WordPress theme).', |
|
42 | + 'event_espresso' |
|
43 | + ), |
|
44 | + $default_theme->get('Name') |
|
45 | + ); |
|
46 | + } else { |
|
47 | + esc_html_e( |
|
48 | + 'If your problem is not a known issue or caused by a plugin, then try activating the default WordPress theme.', |
|
49 | + 'event_espresso' |
|
50 | + ); |
|
51 | + } |
|
52 | + ?> |
|
53 | 53 | <?php esc_html_e( |
54 | - 'If this solves the problem for you, then something in your theme is causing this issue. Check to see if an update is available for your WordPress theme or reach out to the theme author.', |
|
55 | - 'event_espresso' |
|
56 | - ); ?> |
|
54 | + 'If this solves the problem for you, then something in your theme is causing this issue. Check to see if an update is available for your WordPress theme or reach out to the theme author.', |
|
55 | + 'event_espresso' |
|
56 | + ); ?> |
|
57 | 57 | </li> |
58 | 58 | </ol> |
59 | 59 | |
60 | 60 | <p> |
61 | 61 | <?php esc_html_e( |
62 | - 'If none of the suggestions above help you find a solution, then feel free to reach out to the support team at Event Espresso.', |
|
63 | - 'event_espresso' |
|
64 | - ); ?></p> |
|
62 | + 'If none of the suggestions above help you find a solution, then feel free to reach out to the support team at Event Espresso.', |
|
63 | + 'event_espresso' |
|
64 | + ); ?></p> |
|
65 | 65 | <p> |
66 | 66 | <?php |
67 | - printf( |
|
68 | - esc_html__( |
|
69 | - 'Login to your account on EventEspresso.com and %1$screate a support post in our member support forums%2$s. Use a %3$sclear and descriptive title%4$s in your support post, %3$sdescribe the issue to the best of your knowledge%4$s, and %3$snever post any sensitive information such as login details%4$s. Be sure to also include %5$simportant information in the section below%2$s about your WordPress site.', |
|
70 | - 'event_espresso' |
|
71 | - ), |
|
72 | - '<a href="https://eventespresso.com/support/forums/" target="_blank">', |
|
73 | - '</a>', |
|
74 | - '<strong>', |
|
75 | - '</strong>', |
|
76 | - '<a href="#espresso_important_information_settings">' |
|
77 | - ); |
|
78 | - ?> |
|
67 | + printf( |
|
68 | + esc_html__( |
|
69 | + 'Login to your account on EventEspresso.com and %1$screate a support post in our member support forums%2$s. Use a %3$sclear and descriptive title%4$s in your support post, %3$sdescribe the issue to the best of your knowledge%4$s, and %3$snever post any sensitive information such as login details%4$s. Be sure to also include %5$simportant information in the section below%2$s about your WordPress site.', |
|
70 | + 'event_espresso' |
|
71 | + ), |
|
72 | + '<a href="https://eventespresso.com/support/forums/" target="_blank">', |
|
73 | + '</a>', |
|
74 | + '<strong>', |
|
75 | + '</strong>', |
|
76 | + '<a href="#espresso_important_information_settings">' |
|
77 | + ); |
|
78 | + ?> |
|
79 | 79 | </p> |
80 | 80 | |
81 | 81 | <h4><?php esc_html_e('Have an emergency?', 'event_espresso'); ?></h4> |
82 | 82 | |
83 | 83 | <p> |
84 | 84 | <?php |
85 | - printf( |
|
86 | - esc_html__( |
|
87 | - 'We offer support tokens to members that need help with a time-sensitive issue. A support token will provide you with up to 30 minutes of one-on-one time with a team member at Event Espresso. If you have an emergency and need help quickly, then please %1$spurchase a support token%2$s.', |
|
88 | - 'event_espresso' |
|
89 | - ), |
|
90 | - '<a href="https://eventespresso.com/product/premium-support-token/?utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=help_support_tab&utm_content=support_token" target="_blank">', |
|
91 | - '</a>' |
|
92 | - ); |
|
93 | - ?> |
|
85 | + printf( |
|
86 | + esc_html__( |
|
87 | + 'We offer support tokens to members that need help with a time-sensitive issue. A support token will provide you with up to 30 minutes of one-on-one time with a team member at Event Espresso. If you have an emergency and need help quickly, then please %1$spurchase a support token%2$s.', |
|
88 | + 'event_espresso' |
|
89 | + ), |
|
90 | + '<a href="https://eventespresso.com/product/premium-support-token/?utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=help_support_tab&utm_content=support_token" target="_blank">', |
|
91 | + '</a>' |
|
92 | + ); |
|
93 | + ?> |
|
94 | 94 | </p> |
95 | 95 | </div> |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | <?php esc_html_e("Migration Options", "event_espresso"); ?> |
28 | 28 | <span class="tiny-text lt-grey-text"> |
29 | 29 | <?php esc_html_e( |
30 | - ' to migrate or not to migrate?', |
|
31 | - "event_espresso" |
|
32 | - ); ?></span> |
|
30 | + ' to migrate or not to migrate?', |
|
31 | + "event_espresso" |
|
32 | + ); ?></span> |
|
33 | 33 | </h2> |
34 | 34 | <div class="ee-table-wrap"> |
35 | 35 | <table> |
@@ -38,26 +38,26 @@ discard block |
||
38 | 38 | <td><h3><?php esc_html_e('1', 'event_espresso'); ?></h3></td> |
39 | 39 | <td> |
40 | 40 | <?php |
41 | - echo apply_filters( |
|
42 | - 'FHEE__ee_migration_page__option_1_main', |
|
43 | - sprintf( |
|
44 | - esc_html__( |
|
45 | - '%1$sYes. I have backed up my database%2$s, %3$sunderstand the risks involved%4$s, and am ready to migrate my existing %5$s data to %6$s.', |
|
46 | - "event_espresso" |
|
47 | - ), |
|
48 | - '<strong>', |
|
49 | - '</strong>', |
|
50 | - '<a id="migration-risks" class="" title="' |
|
51 | - . esc_attr__('click for more details', "event_espresso") |
|
52 | - . '">', |
|
53 | - '</a>', |
|
54 | - $current_db_state, |
|
55 | - $next_db_state |
|
56 | - ), |
|
57 | - $current_db_state, |
|
58 | - $next_db_state |
|
59 | - ); |
|
60 | - ?> |
|
41 | + echo apply_filters( |
|
42 | + 'FHEE__ee_migration_page__option_1_main', |
|
43 | + sprintf( |
|
44 | + esc_html__( |
|
45 | + '%1$sYes. I have backed up my database%2$s, %3$sunderstand the risks involved%4$s, and am ready to migrate my existing %5$s data to %6$s.', |
|
46 | + "event_espresso" |
|
47 | + ), |
|
48 | + '<strong>', |
|
49 | + '</strong>', |
|
50 | + '<a id="migration-risks" class="" title="' |
|
51 | + . esc_attr__('click for more details', "event_espresso") |
|
52 | + . '">', |
|
53 | + '</a>', |
|
54 | + $current_db_state, |
|
55 | + $next_db_state |
|
56 | + ), |
|
57 | + $current_db_state, |
|
58 | + $next_db_state |
|
59 | + ); |
|
60 | + ?> |
|
61 | 61 | <a id="display-migration-details" |
62 | 62 | class="display-the-hidden lt-grey-text smaller-text hide-if-no-js" |
63 | 63 | rel="migration-details"><?php esc_html_e('click for more details', "event_espresso"); ?> |
@@ -67,26 +67,26 @@ discard block |
||
67 | 67 | rel="migration-details" |
68 | 68 | style="display:none;"> |
69 | 69 | <?php echo sprintf( |
70 | - esc_html__( |
|
71 | - 'hide%1$sdetails%1$s-', |
|
72 | - 'event_espresso' |
|
73 | - ), |
|
74 | - ' ' |
|
75 | - ); ?></a> |
|
70 | + esc_html__( |
|
71 | + 'hide%1$sdetails%1$s-', |
|
72 | + 'event_espresso' |
|
73 | + ), |
|
74 | + ' ' |
|
75 | + ); ?></a> |
|
76 | 76 | </td> |
77 | 77 | <td> |
78 | 78 | <a id="db-backed-up" |
79 | 79 | class="toggle-migration-monitor button-primary"> |
80 | 80 | <?php echo apply_filters( |
81 | - 'FHEE__ee_migration_page__option_1_button_text', |
|
82 | - sprintf( |
|
83 | - esc_html__("Migrate My %s Data to %s", "event_espresso"), |
|
84 | - $current_db_state, |
|
85 | - $next_db_state |
|
86 | - ), |
|
87 | - $current_db_state, |
|
88 | - $next_db_state |
|
89 | - ); ?></a> |
|
81 | + 'FHEE__ee_migration_page__option_1_button_text', |
|
82 | + sprintf( |
|
83 | + esc_html__("Migrate My %s Data to %s", "event_espresso"), |
|
84 | + $current_db_state, |
|
85 | + $next_db_state |
|
86 | + ), |
|
87 | + $current_db_state, |
|
88 | + $next_db_state |
|
89 | + ); ?></a> |
|
90 | 90 | </td> |
91 | 91 | </tr> |
92 | 92 | <tr> |
@@ -94,37 +94,37 @@ discard block |
||
94 | 94 | <div id="migration-details-dv" style="display: none; padding: 1em;"> |
95 | 95 | <span class="reminder-spn"> |
96 | 96 | <?php |
97 | - printf( |
|
98 | - esc_html__( |
|
99 | - "%s Important: %s Before migrating, please back up your database and files.", |
|
100 | - "event_espresso" |
|
101 | - ), |
|
102 | - "<b>", |
|
103 | - "</b>" |
|
104 | - ); |
|
105 | - ?> |
|
97 | + printf( |
|
98 | + esc_html__( |
|
99 | + "%s Important: %s Before migrating, please back up your database and files.", |
|
100 | + "event_espresso" |
|
101 | + ), |
|
102 | + "<b>", |
|
103 | + "</b>" |
|
104 | + ); |
|
105 | + ?> |
|
106 | 106 | </span> |
107 | 107 | <p> |
108 | 108 | <?php |
109 | - printf( |
|
110 | - esc_html__( |
|
111 | - '%1$sNot sure how to backup your existing data?%2$s Here is %3$sWordPress\'s explanation%7$s, and here\'s %6$sour explanation%7$s.%8$sYou can also search the WordPress plugin database for %4$s database backup plugins %7$s,%8$sor have one of our dedicated support technicians help you by purchasing a %5$sPriority Support Token%7$s.', |
|
112 | - "event_espresso" |
|
113 | - ), |
|
114 | - '<b>', |
|
115 | - '</b>', |
|
116 | - "<a href='http://codex.wordpress.org/Backing_Up_Your_Database'>", |
|
117 | - "<a href='" |
|
118 | - . admin_url( |
|
119 | - 'plugin-install.php?tab=search&type=term&s=database+backup&plugin-search-input=Search+Plugins' |
|
120 | - ) |
|
121 | - . "'>", |
|
122 | - "<a href='http://eventespresso.com/product/priority-support-tokens/'>", |
|
123 | - '<a href="http://eventespresso.com/wiki/how-to-back-up-your-site/">', |
|
124 | - "</a>", |
|
125 | - '<br/>' |
|
126 | - ); |
|
127 | - ?> |
|
109 | + printf( |
|
110 | + esc_html__( |
|
111 | + '%1$sNot sure how to backup your existing data?%2$s Here is %3$sWordPress\'s explanation%7$s, and here\'s %6$sour explanation%7$s.%8$sYou can also search the WordPress plugin database for %4$s database backup plugins %7$s,%8$sor have one of our dedicated support technicians help you by purchasing a %5$sPriority Support Token%7$s.', |
|
112 | + "event_espresso" |
|
113 | + ), |
|
114 | + '<b>', |
|
115 | + '</b>', |
|
116 | + "<a href='http://codex.wordpress.org/Backing_Up_Your_Database'>", |
|
117 | + "<a href='" |
|
118 | + . admin_url( |
|
119 | + 'plugin-install.php?tab=search&type=term&s=database+backup&plugin-search-input=Search+Plugins' |
|
120 | + ) |
|
121 | + . "'>", |
|
122 | + "<a href='http://eventespresso.com/product/priority-support-tokens/'>", |
|
123 | + '<a href="http://eventespresso.com/wiki/how-to-back-up-your-site/">', |
|
124 | + "</a>", |
|
125 | + '<br/>' |
|
126 | + ); |
|
127 | + ?> |
|
128 | 128 | </p> |
129 | 129 | <?php do_action('AHEE__ee_migration_page__option_1_extra_details'); ?> |
130 | 130 | </div> |
@@ -134,25 +134,25 @@ discard block |
||
134 | 134 | <td><h3><?php esc_html_e('2', 'event_espresso'); ?></h3></td> |
135 | 135 | <td> |
136 | 136 | <?php echo apply_filters( |
137 | - 'FHEE__ee_migration_page__option_2_main', |
|
138 | - sprintf( |
|
139 | - esc_html__( |
|
140 | - 'I do NOT want to migrate my %1$s data to %2$s at this time and just want to use %3$s without migrating data.', |
|
141 | - "event_espresso" |
|
142 | - ), |
|
143 | - $current_db_state, |
|
144 | - $next_db_state, |
|
145 | - $ultimate_db_state |
|
146 | - ), |
|
147 | - $current_db_state, |
|
148 | - $next_db_state, |
|
149 | - $ultimate_db_state |
|
150 | - ); ?><br/> |
|
137 | + 'FHEE__ee_migration_page__option_2_main', |
|
138 | + sprintf( |
|
139 | + esc_html__( |
|
140 | + 'I do NOT want to migrate my %1$s data to %2$s at this time and just want to use %3$s without migrating data.', |
|
141 | + "event_espresso" |
|
142 | + ), |
|
143 | + $current_db_state, |
|
144 | + $next_db_state, |
|
145 | + $ultimate_db_state |
|
146 | + ), |
|
147 | + $current_db_state, |
|
148 | + $next_db_state, |
|
149 | + $ultimate_db_state |
|
150 | + ); ?><br/> |
|
151 | 151 | <span class="reminder-spn"> |
152 | 152 | <?php esc_html_e( |
153 | - 'Please Note: In order to avoid errors, any existing Event Espresso data (events, ticket, registrations, etc) in your db will be erased! Regular WP data will NOT be affected.', |
|
154 | - 'event_espresso' |
|
155 | - ); ?></span> |
|
153 | + 'Please Note: In order to avoid errors, any existing Event Espresso data (events, ticket, registrations, etc) in your db will be erased! Regular WP data will NOT be affected.', |
|
154 | + 'event_espresso' |
|
155 | + ); ?></span> |
|
156 | 156 | <a id="display-no-migration-details" |
157 | 157 | class="display-the-hidden lt-grey-text smaller-text hide-if-no-js" |
158 | 158 | rel="no-migration-details"><?php esc_html_e('click for more details', "event_espresso"); ?> |
@@ -162,28 +162,28 @@ discard block |
||
162 | 162 | rel="no-migration-details" |
163 | 163 | style="display:none;"> |
164 | 164 | <?php |
165 | - echo sprintf( |
|
166 | - esc_html__( |
|
167 | - 'hide%1$sdetails%1$s-', |
|
168 | - 'event_espresso' |
|
169 | - ), |
|
170 | - ' ' |
|
171 | - ); |
|
172 | - ?> |
|
165 | + echo sprintf( |
|
166 | + esc_html__( |
|
167 | + 'hide%1$sdetails%1$s-', |
|
168 | + 'event_espresso' |
|
169 | + ), |
|
170 | + ' ' |
|
171 | + ); |
|
172 | + ?> |
|
173 | 173 | </a> |
174 | 174 | </td> |
175 | 175 | <td> |
176 | 176 | <a id="do-not-migrate" class="do-not-migrate button-primary" href="<?php echo $reset_db_page_link; ?>"> |
177 | 177 | <?php |
178 | - echo apply_filters( |
|
179 | - 'FHEE__ee_migration_page__option_2_button_text', |
|
180 | - sprintf( |
|
181 | - esc_html__("Just Start %s and Delete Existing Data", "event_espresso"), |
|
182 | - $ultimate_db_state |
|
183 | - ), |
|
184 | - $ultimate_db_state |
|
185 | - ); |
|
186 | - ?> |
|
178 | + echo apply_filters( |
|
179 | + 'FHEE__ee_migration_page__option_2_button_text', |
|
180 | + sprintf( |
|
181 | + esc_html__("Just Start %s and Delete Existing Data", "event_espresso"), |
|
182 | + $ultimate_db_state |
|
183 | + ), |
|
184 | + $ultimate_db_state |
|
185 | + ); |
|
186 | + ?> |
|
187 | 187 | </a> |
188 | 188 | </td> |
189 | 189 | </tr> |
@@ -192,18 +192,18 @@ discard block |
||
192 | 192 | <div id="no-migration-details-dv" style="display: none; padding: 1em;"> |
193 | 193 | <p> |
194 | 194 | <?php |
195 | - echo apply_filters( |
|
196 | - 'FHEE__ee_migration_page__option_2_details', |
|
197 | - sprintf( |
|
198 | - esc_html__( |
|
199 | - "If your existing Event and Registration Data is no longer relevant nor required, you can just start up %s without performing a data migration.", |
|
200 | - "event_espresso" |
|
201 | - ), |
|
202 | - $ultimate_db_state |
|
203 | - ), |
|
204 | - $ultimate_db_state |
|
205 | - ); |
|
206 | - ?> |
|
195 | + echo apply_filters( |
|
196 | + 'FHEE__ee_migration_page__option_2_details', |
|
197 | + sprintf( |
|
198 | + esc_html__( |
|
199 | + "If your existing Event and Registration Data is no longer relevant nor required, you can just start up %s without performing a data migration.", |
|
200 | + "event_espresso" |
|
201 | + ), |
|
202 | + $ultimate_db_state |
|
203 | + ), |
|
204 | + $ultimate_db_state |
|
205 | + ); |
|
206 | + ?> |
|
207 | 207 | </p> |
208 | 208 | </div> |
209 | 209 | </td> |
@@ -15,652 +15,652 @@ discard block |
||
15 | 15 | class Registration_Form_Admin_Page extends EE_Admin_Page |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * _question |
|
20 | - * holds the specific question object for the question details screen |
|
21 | - * |
|
22 | - * @var EE_Question $_question |
|
23 | - */ |
|
24 | - protected $_question; |
|
25 | - |
|
26 | - /** |
|
27 | - * _question_group |
|
28 | - * holds the specific question group object for the question group details screen |
|
29 | - * |
|
30 | - * @var EE_Question_Group $_question_group |
|
31 | - */ |
|
32 | - protected $_question_group; |
|
33 | - |
|
34 | - /** |
|
35 | - *_question_model EEM_Question model instance (for queries) |
|
36 | - * |
|
37 | - * @var EEM_Question $_question_model ; |
|
38 | - */ |
|
39 | - protected $_question_model; |
|
40 | - |
|
41 | - /** |
|
42 | - * _question_group_model EEM_Question_group instance (for queries) |
|
43 | - * |
|
44 | - * @var EEM_Question_Group $_question_group_model |
|
45 | - */ |
|
46 | - protected $_question_group_model; |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * @Constructor |
|
51 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
52 | - * @access public |
|
53 | - */ |
|
54 | - public function __construct($routing = true) |
|
55 | - { |
|
56 | - require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
57 | - require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
58 | - $this->_question_model = EEM_Question::instance(); |
|
59 | - $this->_question_group_model = EEM_Question_Group::instance(); |
|
60 | - parent::__construct($routing); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - protected function _init_page_props() |
|
65 | - { |
|
66 | - $this->page_slug = REGISTRATION_FORM_PG_SLUG; |
|
67 | - $this->page_label = esc_html__('Registration Form', 'event_espresso'); |
|
68 | - $this->_admin_base_url = REGISTRATION_FORM_ADMIN_URL; |
|
69 | - $this->_admin_base_path = REGISTRATION_FORM_ADMIN; |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - protected function _ajax_hooks() |
|
74 | - { |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - protected function _define_page_props() |
|
79 | - { |
|
80 | - $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso'); |
|
81 | - $this->_labels = array( |
|
82 | - 'buttons' => array( |
|
83 | - 'edit_question' => esc_html__('Edit Question', 'event_espresso'), |
|
84 | - ), |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - *_set_page_routes |
|
91 | - */ |
|
92 | - protected function _set_page_routes() |
|
93 | - { |
|
94 | - $qst_id = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
95 | - $this->_page_routes = array( |
|
96 | - 'default' => array( |
|
97 | - 'func' => '_questions_overview_list_table', |
|
98 | - 'capability' => 'ee_read_questions', |
|
99 | - ), |
|
100 | - |
|
101 | - 'edit_question' => array( |
|
102 | - 'func' => '_edit_question', |
|
103 | - 'capability' => 'ee_edit_question', |
|
104 | - 'obj_id' => $qst_id, |
|
105 | - 'args' => array('edit'), |
|
106 | - ), |
|
107 | - |
|
108 | - 'question_groups' => array( |
|
109 | - 'func' => '_questions_groups_preview', |
|
110 | - 'capability' => 'ee_read_question_groups', |
|
111 | - ), |
|
112 | - |
|
113 | - 'update_question' => array( |
|
114 | - 'func' => '_insert_or_update_question', |
|
115 | - 'args' => array('new_question' => false), |
|
116 | - 'capability' => 'ee_edit_question', |
|
117 | - 'obj_id' => $qst_id, |
|
118 | - 'noheader' => true, |
|
119 | - ), |
|
120 | - ); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - protected function _set_page_config() |
|
125 | - { |
|
126 | - $this->_page_config = array( |
|
127 | - 'default' => array( |
|
128 | - 'nav' => array( |
|
129 | - 'label' => esc_html__('Questions', 'event_espresso'), |
|
130 | - 'order' => 10, |
|
131 | - ), |
|
132 | - 'list_table' => 'Registration_Form_Questions_Admin_List_Table', |
|
133 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
134 | - 'help_tabs' => array( |
|
135 | - 'registration_form_questions_overview_help_tab' => array( |
|
136 | - 'title' => esc_html__('Questions Overview', 'event_espresso'), |
|
137 | - 'filename' => 'registration_form_questions_overview', |
|
138 | - ), |
|
139 | - 'registration_form_questions_overview_table_column_headings_help_tab' => array( |
|
140 | - 'title' => esc_html__('Questions Overview Table Column Headings', 'event_espresso'), |
|
141 | - 'filename' => 'registration_form_questions_overview_table_column_headings', |
|
142 | - ), |
|
143 | - 'registration_form_questions_overview_views_bulk_actions_search_help_tab' => array( |
|
144 | - 'title' => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'), |
|
145 | - 'filename' => 'registration_form_questions_overview_views_bulk_actions_search', |
|
146 | - ), |
|
147 | - ), |
|
148 | - 'help_tour' => array('Registration_Form_Questions_Overview_Help_Tour'), |
|
149 | - 'require_nonce' => false, |
|
150 | - 'qtips' => array( |
|
151 | - 'EE_Registration_Form_Tips', |
|
152 | - )/**/ |
|
153 | - ), |
|
154 | - |
|
155 | - 'question_groups' => array( |
|
156 | - 'nav' => array( |
|
157 | - 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
158 | - 'order' => 20, |
|
159 | - ), |
|
160 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
161 | - 'help_tabs' => array( |
|
162 | - 'registration_form_question_groups_help_tab' => array( |
|
163 | - 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
164 | - 'filename' => 'registration_form_question_groups', |
|
165 | - ), |
|
166 | - ), |
|
167 | - 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
168 | - 'require_nonce' => false, |
|
169 | - ), |
|
170 | - |
|
171 | - 'edit_question' => array( |
|
172 | - 'nav' => array( |
|
173 | - 'label' => esc_html__('Edit Question', 'event_espresso'), |
|
174 | - 'order' => 15, |
|
175 | - 'persistent' => false, |
|
176 | - 'url' => isset($this->_req_data['question_id']) ? add_query_arg( |
|
177 | - array('question_id' => $this->_req_data['question_id']), |
|
178 | - $this->_current_page_view_url |
|
179 | - ) : $this->_admin_base_url, |
|
180 | - ), |
|
181 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
182 | - 'help_tabs' => array( |
|
183 | - 'registration_form_edit_question_group_help_tab' => array( |
|
184 | - 'title' => esc_html__('Edit Question', 'event_espresso'), |
|
185 | - 'filename' => 'registration_form_edit_question', |
|
186 | - ), |
|
187 | - ), |
|
188 | - 'help_tour' => array('Registration_Form_Edit_Question_Help_Tour'), |
|
189 | - 'require_nonce' => false, |
|
190 | - ), |
|
191 | - ); |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - protected function _add_screen_options() |
|
196 | - { |
|
197 | - // todo |
|
198 | - } |
|
199 | - |
|
200 | - protected function _add_screen_options_default() |
|
201 | - { |
|
202 | - $page_title = $this->_admin_page_title; |
|
203 | - $this->_admin_page_title = esc_html__('Questions', 'event_espresso'); |
|
204 | - $this->_per_page_screen_option(); |
|
205 | - $this->_admin_page_title = $page_title; |
|
206 | - } |
|
207 | - |
|
208 | - protected function _add_screen_options_question_groups() |
|
209 | - { |
|
210 | - $page_title = $this->_admin_page_title; |
|
211 | - $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso'); |
|
212 | - $this->_per_page_screen_option(); |
|
213 | - $this->_admin_page_title = $page_title; |
|
214 | - } |
|
215 | - |
|
216 | - // none of the below group are currently used for Event Categories |
|
217 | - protected function _add_feature_pointers() |
|
218 | - { |
|
219 | - } |
|
220 | - |
|
221 | - public function load_scripts_styles() |
|
222 | - { |
|
223 | - wp_register_style( |
|
224 | - 'espresso_registration', |
|
225 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', |
|
226 | - array(), |
|
227 | - EVENT_ESPRESSO_VERSION |
|
228 | - ); |
|
229 | - wp_enqueue_style('espresso_registration'); |
|
230 | - } |
|
231 | - |
|
232 | - public function admin_init() |
|
233 | - { |
|
234 | - } |
|
235 | - |
|
236 | - public function admin_notices() |
|
237 | - { |
|
238 | - } |
|
239 | - |
|
240 | - public function admin_footer_scripts() |
|
241 | - { |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - public function load_scripts_styles_default() |
|
246 | - { |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - public function load_scripts_styles_add_question() |
|
251 | - { |
|
252 | - $this->load_scripts_styles_question_details(); |
|
253 | - } |
|
254 | - |
|
255 | - public function load_scripts_styles_edit_question() |
|
256 | - { |
|
257 | - $this->load_scripts_styles_question_details(); |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Loads the JS required for adding or editing a question |
|
262 | - */ |
|
263 | - protected function load_scripts_styles_question_details() |
|
264 | - { |
|
265 | - $this->load_scripts_styles_forms(); |
|
266 | - wp_register_script( |
|
267 | - 'espresso_registration_form_single', |
|
268 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', |
|
269 | - array('jquery-ui-sortable'), |
|
270 | - EVENT_ESPRESSO_VERSION, |
|
271 | - true |
|
272 | - ); |
|
273 | - wp_enqueue_script('espresso_registration_form_single'); |
|
274 | - wp_localize_script( |
|
275 | - 'espresso_registration_form_single', |
|
276 | - 'ee_question_data', |
|
277 | - array( |
|
278 | - 'question_types_with_max' => EEM_Question::instance()->questionTypesWithMaxLength(), |
|
279 | - 'question_type_with_options' => EEM_Question::instance()->question_types_with_options(), |
|
280 | - ) |
|
281 | - ); |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - public function recaptcha_info_help_tab() |
|
286 | - { |
|
287 | - $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
288 | - EEH_Template::display_template($template, array()); |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - public function load_scripts_styles_forms() |
|
293 | - { |
|
294 | - // styles |
|
295 | - wp_enqueue_style('espresso-ui-theme'); |
|
296 | - // scripts |
|
297 | - wp_enqueue_script('ee_admin_js'); |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - protected function _set_list_table_views_default() |
|
302 | - { |
|
303 | - $this->_views = array( |
|
304 | - 'all' => array( |
|
305 | - 'slug' => 'all', |
|
306 | - 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
307 | - 'count' => 0, |
|
308 | - ), |
|
309 | - ); |
|
310 | - |
|
311 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
312 | - 'ee_delete_questions', |
|
313 | - 'espresso_registration_form_trash_questions' |
|
314 | - ) |
|
315 | - ) { |
|
316 | - $this->_views['trash'] = array( |
|
317 | - 'slug' => 'trash', |
|
318 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
319 | - 'count' => 0, |
|
320 | - ); |
|
321 | - } |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * This just previews the question groups tab that comes in caffeinated. |
|
326 | - * |
|
327 | - * @return string html |
|
328 | - */ |
|
329 | - protected function _questions_groups_preview() |
|
330 | - { |
|
331 | - $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
|
332 | - $this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' |
|
333 | - . esc_attr__( |
|
334 | - 'Preview Question Groups Overview List Table screenshot', |
|
335 | - 'event_espresso' |
|
336 | - ) . '" />'; |
|
337 | - $this->_template_args['preview_text'] = '<strong>' |
|
338 | - . esc_html__( |
|
339 | - 'Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
340 | - 'event_espresso' |
|
341 | - ) . '</strong>'; |
|
342 | - $this->display_admin_caf_preview_page('question_groups_tab'); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * Extracts the question field's values from the POST request to update or insert them |
|
348 | - * |
|
349 | - * @param \EEM_Base $model |
|
350 | - * @return array where each key is the name of a model's field/db column, and each value is its value. |
|
351 | - */ |
|
352 | - protected function _set_column_values_for(EEM_Base $model) |
|
353 | - { |
|
354 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
355 | - $set_column_values = array(); |
|
356 | - |
|
357 | - // some initial checks for proper values. |
|
358 | - // if QST_admin_only, then no matter what QST_required is we disable. |
|
359 | - if (! empty($this->_req_data['QST_admin_only'])) { |
|
360 | - $this->_req_data['QST_required'] = 0; |
|
361 | - } |
|
362 | - // if the question shouldn't have a max length, don't let them set one |
|
363 | - if (! isset( |
|
364 | - $this->_req_data['QST_type'], |
|
365 | - $this->_req_data['QST_max'] |
|
366 | - ) |
|
367 | - || ! in_array( |
|
368 | - $this->_req_data['QST_type'], |
|
369 | - EEM_Question::instance()->questionTypesWithMaxLength(), |
|
370 | - true |
|
371 | - ) |
|
372 | - ) { |
|
373 | - // they're not allowed to set the max |
|
374 | - $this->_req_data['QST_max'] = null; |
|
375 | - } |
|
376 | - foreach ($model->field_settings() as $fieldName => $settings) { |
|
377 | - if ( |
|
378 | - // basically if QSG_identifier is empty or not set |
|
379 | - $fieldName === 'QSG_identifier' |
|
380 | - && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier'])) |
|
381 | - ) { |
|
382 | - $QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : ''; |
|
383 | - $set_column_values[ $fieldName ] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
384 | - } elseif ( |
|
385 | - // if the admin label is blank, use a slug version of the question text |
|
386 | - $fieldName === 'QST_admin_label' |
|
387 | - && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label'])) |
|
388 | - ) { |
|
389 | - $QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : ''; |
|
390 | - $set_column_values[ $fieldName ] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
391 | - } elseif ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
392 | - $set_column_values[ $fieldName ] = 0; |
|
393 | - } elseif ($fieldName === 'QST_max') { |
|
394 | - $qst_system = EEM_Question::instance()->get_var( |
|
395 | - array( |
|
396 | - array( |
|
397 | - 'QST_ID' => isset($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0, |
|
398 | - ), |
|
399 | - ), |
|
400 | - 'QST_system' |
|
401 | - ); |
|
402 | - $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
403 | - if (empty($this->_req_data['QST_max']) || |
|
404 | - $this->_req_data['QST_max'] > $max_max |
|
405 | - ) { |
|
406 | - $set_column_values[ $fieldName ] = $max_max; |
|
407 | - } |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - // only add a property to the array if it's not null (otherwise the model should just use the default value) |
|
412 | - if (! isset($set_column_values[ $fieldName ]) && |
|
413 | - isset($this->_req_data[ $fieldName ]) |
|
414 | - ) { |
|
415 | - $set_column_values[ $fieldName ] = $this->_req_data[ $fieldName ]; |
|
416 | - } |
|
417 | - } |
|
418 | - return $set_column_values;// validation fo this data to be performed by the model before insertion. |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - *_questions_overview_list_table |
|
424 | - */ |
|
425 | - protected function _questions_overview_list_table() |
|
426 | - { |
|
427 | - $this->_search_btn_label = esc_html__('Questions', 'event_espresso'); |
|
428 | - $this->display_admin_list_table_page_with_sidebar(); |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * _edit_question |
|
434 | - */ |
|
435 | - protected function _edit_question() |
|
436 | - { |
|
437 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
438 | - $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint( |
|
439 | - $this->_req_data['QST_ID'] |
|
440 | - ) : false; |
|
441 | - |
|
442 | - switch ($this->_req_action) { |
|
443 | - case 'add_question': |
|
444 | - $this->_admin_page_title = esc_html__('Add Question', 'event_espresso'); |
|
445 | - break; |
|
446 | - case 'edit_question': |
|
447 | - $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso'); |
|
448 | - break; |
|
449 | - default: |
|
450 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
451 | - } |
|
452 | - |
|
453 | - // add PRC_ID to title if editing |
|
454 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
455 | - if ($ID) { |
|
456 | - $question = $this->_question_model->get_one_by_ID($ID); |
|
457 | - $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
458 | - $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields); |
|
459 | - } else { |
|
460 | - $question = EE_Question::new_instance(); |
|
461 | - $question->set_order_to_latest(); |
|
462 | - $this->_set_add_edit_form_tags('insert_question'); |
|
463 | - } |
|
464 | - if ($question->system_ID() === EEM_Attendee::system_question_phone) { |
|
465 | - $question_types = array_intersect_key( |
|
466 | - EEM_Question::instance()->allowed_question_types(), |
|
467 | - array_flip( |
|
468 | - array( |
|
469 | - EEM_Question::QST_type_text, |
|
470 | - EEM_Question::QST_type_us_phone, |
|
471 | - ) |
|
472 | - ) |
|
473 | - ); |
|
474 | - } else { |
|
475 | - $question_types = $question->has_answers() ? $this->_question_model->question_types_in_same_category( |
|
476 | - $question->type() |
|
477 | - ) : $this->_question_model->allowed_question_types(); |
|
478 | - } |
|
479 | - $this->_template_args['QST_ID'] = $ID; |
|
480 | - $this->_template_args['question'] = $question; |
|
481 | - $this->_template_args['question_types'] = $question_types; |
|
482 | - $this->_template_args['max_max'] = EEM_Question::instance()->absolute_max_for_system_question( |
|
483 | - $question->system_ID() |
|
484 | - ); |
|
485 | - $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
|
486 | - $this->_set_publish_post_box_vars('id', $ID); |
|
487 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
488 | - REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
489 | - $this->_template_args, |
|
490 | - true |
|
491 | - ); |
|
492 | - |
|
493 | - // the details template wrapper |
|
494 | - $this->display_admin_page_with_sidebar(); |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - /** |
|
499 | - * @return string |
|
500 | - */ |
|
501 | - protected function _get_question_type_descriptions() |
|
502 | - { |
|
503 | - EE_Registry::instance()->load_helper('HTML'); |
|
504 | - $descriptions = ''; |
|
505 | - $question_type_descriptions = EEM_Question::instance()->question_descriptions(); |
|
506 | - foreach ($question_type_descriptions as $type => $question_type_description) { |
|
507 | - if ($type == 'HTML_TEXTAREA') { |
|
508 | - $html = new EE_Simple_HTML_Validation_Strategy(); |
|
509 | - $question_type_description .= sprintf( |
|
510 | - esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'), |
|
511 | - '<br/>', |
|
512 | - $html->get_list_of_allowed_tags() |
|
513 | - ); |
|
514 | - } |
|
515 | - $descriptions .= EEH_HTML::p( |
|
516 | - $question_type_description, |
|
517 | - 'question_type_description-' . $type, |
|
518 | - 'question_type_description description', |
|
519 | - 'display:none;' |
|
520 | - ); |
|
521 | - } |
|
522 | - return $descriptions; |
|
523 | - } |
|
524 | - |
|
525 | - |
|
526 | - /** |
|
527 | - * @param bool|true $new_question |
|
528 | - * @throws \EE_Error |
|
529 | - */ |
|
530 | - protected function _insert_or_update_question($new_question = true) |
|
531 | - { |
|
532 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
533 | - $set_column_values = $this->_set_column_values_for($this->_question_model); |
|
534 | - if ($new_question) { |
|
535 | - $question = EE_Question::new_instance($set_column_values); |
|
536 | - $action_desc = 'added'; |
|
537 | - } else { |
|
538 | - $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
539 | - foreach ($set_column_values as $field => $new_value) { |
|
540 | - $question->set($field, $new_value); |
|
541 | - } |
|
542 | - $action_desc = 'updated'; |
|
543 | - } |
|
544 | - $success = $question->save(); |
|
545 | - $ID = $question->ID(); |
|
546 | - if ($ID && $question->should_have_question_options()) { |
|
547 | - // save the related options |
|
548 | - // trash removed options, save old ones |
|
549 | - // get list of all options |
|
550 | - $options = $question->options(); |
|
551 | - if (! empty($options)) { |
|
552 | - foreach ($options as $option_ID => $option) { |
|
553 | - $option_req_index = $this->_get_option_req_data_index($option_ID); |
|
554 | - if ($option_req_index !== false) { |
|
555 | - $option->save($this->_req_data['question_options'][ $option_req_index ]); |
|
556 | - } else { |
|
557 | - // not found, remove it |
|
558 | - $option->delete(); |
|
559 | - } |
|
560 | - } |
|
561 | - } |
|
562 | - // save new related options |
|
563 | - foreach ($this->_req_data['question_options'] as $index => $option_req_data) { |
|
564 | - // skip $index that is from our sample |
|
565 | - if ($index === 'xxcountxx') { |
|
566 | - continue; |
|
567 | - } |
|
568 | - // note we allow saving blank options. |
|
569 | - if (empty($option_req_data['QSO_ID']) |
|
570 | - ) {// no ID! save it! |
|
571 | - $new_option = EE_Question_Option::new_instance( |
|
572 | - array( |
|
573 | - 'QSO_value' => $option_req_data['QSO_value'], |
|
574 | - 'QSO_desc' => $option_req_data['QSO_desc'], |
|
575 | - 'QSO_order' => $option_req_data['QSO_order'], |
|
576 | - 'QST_ID' => $question->ID(), |
|
577 | - ) |
|
578 | - ); |
|
579 | - $new_option->save(); |
|
580 | - } |
|
581 | - } |
|
582 | - } |
|
583 | - $query_args = array('action' => 'edit_question', 'QST_ID' => $ID); |
|
584 | - if ($success !== false) { |
|
585 | - $msg = $new_question |
|
586 | - ? sprintf( |
|
587 | - esc_html__('The %s has been created', 'event_espresso'), |
|
588 | - $this->_question_model->item_name() |
|
589 | - ) |
|
590 | - : sprintf( |
|
591 | - esc_html__('The %s has been updated', 'event_espresso'), |
|
592 | - $this->_question_model->item_name() |
|
593 | - ); |
|
594 | - EE_Error::add_success($msg); |
|
595 | - } |
|
596 | - |
|
597 | - $this->_redirect_after_action(false, '', $action_desc, $query_args, true); |
|
598 | - } |
|
599 | - |
|
600 | - |
|
601 | - /** |
|
602 | - * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not |
|
603 | - * by ID |
|
604 | - * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously). |
|
605 | - * So, this function gets the index in that request data array called question_options. Returns FALSE if not found. |
|
606 | - * |
|
607 | - * @param int $ID of the question option to find |
|
608 | - * @return int index in question_options array if successful, FALSE if unsuccessful |
|
609 | - */ |
|
610 | - protected function _get_option_req_data_index($ID) |
|
611 | - { |
|
612 | - $req_data_for_question_options = $this->_req_data['question_options']; |
|
613 | - foreach ($req_data_for_question_options as $num => $option_data) { |
|
614 | - if (array_key_exists('QSO_ID', $option_data) && (int) $option_data['QSO_ID'] === $ID) { |
|
615 | - return $num; |
|
616 | - } |
|
617 | - } |
|
618 | - return false; |
|
619 | - } |
|
620 | - |
|
621 | - |
|
622 | - |
|
623 | - |
|
624 | - /***********/ |
|
625 | - /* QUERIES */ |
|
626 | - /** |
|
627 | - * For internal use in getting all the query parameters |
|
628 | - * (because it's pretty well the same between question, question groups, |
|
629 | - * and for both when searching for trashed and untrashed ones) |
|
630 | - * |
|
631 | - * @param EEM_Base $model either EEM_Question or EEM_Question_Group |
|
632 | - * @param int $per_page |
|
633 | - * @param int $current_page |
|
634 | - * @return array model query params, @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
635 | - */ |
|
636 | - protected function get_query_params($model, $per_page = 10, $current_page = 10) |
|
637 | - { |
|
638 | - $query_params = array(); |
|
639 | - $offset = ($current_page - 1) * $per_page; |
|
640 | - $query_params['limit'] = array($offset, $per_page); |
|
641 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
642 | - : 'ASC'; |
|
643 | - $orderby_field = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order'; |
|
644 | - $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
|
645 | - $query_params['order_by'] = array($field_to_order_by => $order); |
|
646 | - $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
|
647 | - if (! empty($search_string)) { |
|
648 | - if ($model instanceof EEM_Question_Group) { |
|
649 | - $query_params[0] = array( |
|
650 | - 'OR' => array( |
|
651 | - 'QSG_name' => array('LIKE', "%$search_string%"), |
|
652 | - 'QSG_desc' => array('LIKE', "%$search_string%"), |
|
653 | - ), |
|
654 | - ); |
|
655 | - } else { |
|
656 | - $query_params[0] = array( |
|
657 | - 'QST_display_text' => array('LIKE', "%$search_string%"), |
|
658 | - ); |
|
659 | - } |
|
660 | - } |
|
661 | - |
|
662 | - // capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented) |
|
663 | - /*if ( $model instanceof EEM_Question_Group ) { |
|
18 | + /** |
|
19 | + * _question |
|
20 | + * holds the specific question object for the question details screen |
|
21 | + * |
|
22 | + * @var EE_Question $_question |
|
23 | + */ |
|
24 | + protected $_question; |
|
25 | + |
|
26 | + /** |
|
27 | + * _question_group |
|
28 | + * holds the specific question group object for the question group details screen |
|
29 | + * |
|
30 | + * @var EE_Question_Group $_question_group |
|
31 | + */ |
|
32 | + protected $_question_group; |
|
33 | + |
|
34 | + /** |
|
35 | + *_question_model EEM_Question model instance (for queries) |
|
36 | + * |
|
37 | + * @var EEM_Question $_question_model ; |
|
38 | + */ |
|
39 | + protected $_question_model; |
|
40 | + |
|
41 | + /** |
|
42 | + * _question_group_model EEM_Question_group instance (for queries) |
|
43 | + * |
|
44 | + * @var EEM_Question_Group $_question_group_model |
|
45 | + */ |
|
46 | + protected $_question_group_model; |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * @Constructor |
|
51 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
52 | + * @access public |
|
53 | + */ |
|
54 | + public function __construct($routing = true) |
|
55 | + { |
|
56 | + require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
57 | + require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
58 | + $this->_question_model = EEM_Question::instance(); |
|
59 | + $this->_question_group_model = EEM_Question_Group::instance(); |
|
60 | + parent::__construct($routing); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + protected function _init_page_props() |
|
65 | + { |
|
66 | + $this->page_slug = REGISTRATION_FORM_PG_SLUG; |
|
67 | + $this->page_label = esc_html__('Registration Form', 'event_espresso'); |
|
68 | + $this->_admin_base_url = REGISTRATION_FORM_ADMIN_URL; |
|
69 | + $this->_admin_base_path = REGISTRATION_FORM_ADMIN; |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + protected function _ajax_hooks() |
|
74 | + { |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + protected function _define_page_props() |
|
79 | + { |
|
80 | + $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso'); |
|
81 | + $this->_labels = array( |
|
82 | + 'buttons' => array( |
|
83 | + 'edit_question' => esc_html__('Edit Question', 'event_espresso'), |
|
84 | + ), |
|
85 | + ); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + *_set_page_routes |
|
91 | + */ |
|
92 | + protected function _set_page_routes() |
|
93 | + { |
|
94 | + $qst_id = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
95 | + $this->_page_routes = array( |
|
96 | + 'default' => array( |
|
97 | + 'func' => '_questions_overview_list_table', |
|
98 | + 'capability' => 'ee_read_questions', |
|
99 | + ), |
|
100 | + |
|
101 | + 'edit_question' => array( |
|
102 | + 'func' => '_edit_question', |
|
103 | + 'capability' => 'ee_edit_question', |
|
104 | + 'obj_id' => $qst_id, |
|
105 | + 'args' => array('edit'), |
|
106 | + ), |
|
107 | + |
|
108 | + 'question_groups' => array( |
|
109 | + 'func' => '_questions_groups_preview', |
|
110 | + 'capability' => 'ee_read_question_groups', |
|
111 | + ), |
|
112 | + |
|
113 | + 'update_question' => array( |
|
114 | + 'func' => '_insert_or_update_question', |
|
115 | + 'args' => array('new_question' => false), |
|
116 | + 'capability' => 'ee_edit_question', |
|
117 | + 'obj_id' => $qst_id, |
|
118 | + 'noheader' => true, |
|
119 | + ), |
|
120 | + ); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + protected function _set_page_config() |
|
125 | + { |
|
126 | + $this->_page_config = array( |
|
127 | + 'default' => array( |
|
128 | + 'nav' => array( |
|
129 | + 'label' => esc_html__('Questions', 'event_espresso'), |
|
130 | + 'order' => 10, |
|
131 | + ), |
|
132 | + 'list_table' => 'Registration_Form_Questions_Admin_List_Table', |
|
133 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
134 | + 'help_tabs' => array( |
|
135 | + 'registration_form_questions_overview_help_tab' => array( |
|
136 | + 'title' => esc_html__('Questions Overview', 'event_espresso'), |
|
137 | + 'filename' => 'registration_form_questions_overview', |
|
138 | + ), |
|
139 | + 'registration_form_questions_overview_table_column_headings_help_tab' => array( |
|
140 | + 'title' => esc_html__('Questions Overview Table Column Headings', 'event_espresso'), |
|
141 | + 'filename' => 'registration_form_questions_overview_table_column_headings', |
|
142 | + ), |
|
143 | + 'registration_form_questions_overview_views_bulk_actions_search_help_tab' => array( |
|
144 | + 'title' => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'), |
|
145 | + 'filename' => 'registration_form_questions_overview_views_bulk_actions_search', |
|
146 | + ), |
|
147 | + ), |
|
148 | + 'help_tour' => array('Registration_Form_Questions_Overview_Help_Tour'), |
|
149 | + 'require_nonce' => false, |
|
150 | + 'qtips' => array( |
|
151 | + 'EE_Registration_Form_Tips', |
|
152 | + )/**/ |
|
153 | + ), |
|
154 | + |
|
155 | + 'question_groups' => array( |
|
156 | + 'nav' => array( |
|
157 | + 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
158 | + 'order' => 20, |
|
159 | + ), |
|
160 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
161 | + 'help_tabs' => array( |
|
162 | + 'registration_form_question_groups_help_tab' => array( |
|
163 | + 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
164 | + 'filename' => 'registration_form_question_groups', |
|
165 | + ), |
|
166 | + ), |
|
167 | + 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
168 | + 'require_nonce' => false, |
|
169 | + ), |
|
170 | + |
|
171 | + 'edit_question' => array( |
|
172 | + 'nav' => array( |
|
173 | + 'label' => esc_html__('Edit Question', 'event_espresso'), |
|
174 | + 'order' => 15, |
|
175 | + 'persistent' => false, |
|
176 | + 'url' => isset($this->_req_data['question_id']) ? add_query_arg( |
|
177 | + array('question_id' => $this->_req_data['question_id']), |
|
178 | + $this->_current_page_view_url |
|
179 | + ) : $this->_admin_base_url, |
|
180 | + ), |
|
181 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
182 | + 'help_tabs' => array( |
|
183 | + 'registration_form_edit_question_group_help_tab' => array( |
|
184 | + 'title' => esc_html__('Edit Question', 'event_espresso'), |
|
185 | + 'filename' => 'registration_form_edit_question', |
|
186 | + ), |
|
187 | + ), |
|
188 | + 'help_tour' => array('Registration_Form_Edit_Question_Help_Tour'), |
|
189 | + 'require_nonce' => false, |
|
190 | + ), |
|
191 | + ); |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + protected function _add_screen_options() |
|
196 | + { |
|
197 | + // todo |
|
198 | + } |
|
199 | + |
|
200 | + protected function _add_screen_options_default() |
|
201 | + { |
|
202 | + $page_title = $this->_admin_page_title; |
|
203 | + $this->_admin_page_title = esc_html__('Questions', 'event_espresso'); |
|
204 | + $this->_per_page_screen_option(); |
|
205 | + $this->_admin_page_title = $page_title; |
|
206 | + } |
|
207 | + |
|
208 | + protected function _add_screen_options_question_groups() |
|
209 | + { |
|
210 | + $page_title = $this->_admin_page_title; |
|
211 | + $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso'); |
|
212 | + $this->_per_page_screen_option(); |
|
213 | + $this->_admin_page_title = $page_title; |
|
214 | + } |
|
215 | + |
|
216 | + // none of the below group are currently used for Event Categories |
|
217 | + protected function _add_feature_pointers() |
|
218 | + { |
|
219 | + } |
|
220 | + |
|
221 | + public function load_scripts_styles() |
|
222 | + { |
|
223 | + wp_register_style( |
|
224 | + 'espresso_registration', |
|
225 | + REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', |
|
226 | + array(), |
|
227 | + EVENT_ESPRESSO_VERSION |
|
228 | + ); |
|
229 | + wp_enqueue_style('espresso_registration'); |
|
230 | + } |
|
231 | + |
|
232 | + public function admin_init() |
|
233 | + { |
|
234 | + } |
|
235 | + |
|
236 | + public function admin_notices() |
|
237 | + { |
|
238 | + } |
|
239 | + |
|
240 | + public function admin_footer_scripts() |
|
241 | + { |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + public function load_scripts_styles_default() |
|
246 | + { |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + public function load_scripts_styles_add_question() |
|
251 | + { |
|
252 | + $this->load_scripts_styles_question_details(); |
|
253 | + } |
|
254 | + |
|
255 | + public function load_scripts_styles_edit_question() |
|
256 | + { |
|
257 | + $this->load_scripts_styles_question_details(); |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Loads the JS required for adding or editing a question |
|
262 | + */ |
|
263 | + protected function load_scripts_styles_question_details() |
|
264 | + { |
|
265 | + $this->load_scripts_styles_forms(); |
|
266 | + wp_register_script( |
|
267 | + 'espresso_registration_form_single', |
|
268 | + REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', |
|
269 | + array('jquery-ui-sortable'), |
|
270 | + EVENT_ESPRESSO_VERSION, |
|
271 | + true |
|
272 | + ); |
|
273 | + wp_enqueue_script('espresso_registration_form_single'); |
|
274 | + wp_localize_script( |
|
275 | + 'espresso_registration_form_single', |
|
276 | + 'ee_question_data', |
|
277 | + array( |
|
278 | + 'question_types_with_max' => EEM_Question::instance()->questionTypesWithMaxLength(), |
|
279 | + 'question_type_with_options' => EEM_Question::instance()->question_types_with_options(), |
|
280 | + ) |
|
281 | + ); |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + public function recaptcha_info_help_tab() |
|
286 | + { |
|
287 | + $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
288 | + EEH_Template::display_template($template, array()); |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + public function load_scripts_styles_forms() |
|
293 | + { |
|
294 | + // styles |
|
295 | + wp_enqueue_style('espresso-ui-theme'); |
|
296 | + // scripts |
|
297 | + wp_enqueue_script('ee_admin_js'); |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + protected function _set_list_table_views_default() |
|
302 | + { |
|
303 | + $this->_views = array( |
|
304 | + 'all' => array( |
|
305 | + 'slug' => 'all', |
|
306 | + 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
307 | + 'count' => 0, |
|
308 | + ), |
|
309 | + ); |
|
310 | + |
|
311 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
312 | + 'ee_delete_questions', |
|
313 | + 'espresso_registration_form_trash_questions' |
|
314 | + ) |
|
315 | + ) { |
|
316 | + $this->_views['trash'] = array( |
|
317 | + 'slug' => 'trash', |
|
318 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
319 | + 'count' => 0, |
|
320 | + ); |
|
321 | + } |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * This just previews the question groups tab that comes in caffeinated. |
|
326 | + * |
|
327 | + * @return string html |
|
328 | + */ |
|
329 | + protected function _questions_groups_preview() |
|
330 | + { |
|
331 | + $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
|
332 | + $this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' |
|
333 | + . esc_attr__( |
|
334 | + 'Preview Question Groups Overview List Table screenshot', |
|
335 | + 'event_espresso' |
|
336 | + ) . '" />'; |
|
337 | + $this->_template_args['preview_text'] = '<strong>' |
|
338 | + . esc_html__( |
|
339 | + 'Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
340 | + 'event_espresso' |
|
341 | + ) . '</strong>'; |
|
342 | + $this->display_admin_caf_preview_page('question_groups_tab'); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * Extracts the question field's values from the POST request to update or insert them |
|
348 | + * |
|
349 | + * @param \EEM_Base $model |
|
350 | + * @return array where each key is the name of a model's field/db column, and each value is its value. |
|
351 | + */ |
|
352 | + protected function _set_column_values_for(EEM_Base $model) |
|
353 | + { |
|
354 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
355 | + $set_column_values = array(); |
|
356 | + |
|
357 | + // some initial checks for proper values. |
|
358 | + // if QST_admin_only, then no matter what QST_required is we disable. |
|
359 | + if (! empty($this->_req_data['QST_admin_only'])) { |
|
360 | + $this->_req_data['QST_required'] = 0; |
|
361 | + } |
|
362 | + // if the question shouldn't have a max length, don't let them set one |
|
363 | + if (! isset( |
|
364 | + $this->_req_data['QST_type'], |
|
365 | + $this->_req_data['QST_max'] |
|
366 | + ) |
|
367 | + || ! in_array( |
|
368 | + $this->_req_data['QST_type'], |
|
369 | + EEM_Question::instance()->questionTypesWithMaxLength(), |
|
370 | + true |
|
371 | + ) |
|
372 | + ) { |
|
373 | + // they're not allowed to set the max |
|
374 | + $this->_req_data['QST_max'] = null; |
|
375 | + } |
|
376 | + foreach ($model->field_settings() as $fieldName => $settings) { |
|
377 | + if ( |
|
378 | + // basically if QSG_identifier is empty or not set |
|
379 | + $fieldName === 'QSG_identifier' |
|
380 | + && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier'])) |
|
381 | + ) { |
|
382 | + $QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : ''; |
|
383 | + $set_column_values[ $fieldName ] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
384 | + } elseif ( |
|
385 | + // if the admin label is blank, use a slug version of the question text |
|
386 | + $fieldName === 'QST_admin_label' |
|
387 | + && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label'])) |
|
388 | + ) { |
|
389 | + $QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : ''; |
|
390 | + $set_column_values[ $fieldName ] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
391 | + } elseif ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
392 | + $set_column_values[ $fieldName ] = 0; |
|
393 | + } elseif ($fieldName === 'QST_max') { |
|
394 | + $qst_system = EEM_Question::instance()->get_var( |
|
395 | + array( |
|
396 | + array( |
|
397 | + 'QST_ID' => isset($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0, |
|
398 | + ), |
|
399 | + ), |
|
400 | + 'QST_system' |
|
401 | + ); |
|
402 | + $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
403 | + if (empty($this->_req_data['QST_max']) || |
|
404 | + $this->_req_data['QST_max'] > $max_max |
|
405 | + ) { |
|
406 | + $set_column_values[ $fieldName ] = $max_max; |
|
407 | + } |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + // only add a property to the array if it's not null (otherwise the model should just use the default value) |
|
412 | + if (! isset($set_column_values[ $fieldName ]) && |
|
413 | + isset($this->_req_data[ $fieldName ]) |
|
414 | + ) { |
|
415 | + $set_column_values[ $fieldName ] = $this->_req_data[ $fieldName ]; |
|
416 | + } |
|
417 | + } |
|
418 | + return $set_column_values;// validation fo this data to be performed by the model before insertion. |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + *_questions_overview_list_table |
|
424 | + */ |
|
425 | + protected function _questions_overview_list_table() |
|
426 | + { |
|
427 | + $this->_search_btn_label = esc_html__('Questions', 'event_espresso'); |
|
428 | + $this->display_admin_list_table_page_with_sidebar(); |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * _edit_question |
|
434 | + */ |
|
435 | + protected function _edit_question() |
|
436 | + { |
|
437 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
438 | + $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint( |
|
439 | + $this->_req_data['QST_ID'] |
|
440 | + ) : false; |
|
441 | + |
|
442 | + switch ($this->_req_action) { |
|
443 | + case 'add_question': |
|
444 | + $this->_admin_page_title = esc_html__('Add Question', 'event_espresso'); |
|
445 | + break; |
|
446 | + case 'edit_question': |
|
447 | + $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso'); |
|
448 | + break; |
|
449 | + default: |
|
450 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
451 | + } |
|
452 | + |
|
453 | + // add PRC_ID to title if editing |
|
454 | + $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
455 | + if ($ID) { |
|
456 | + $question = $this->_question_model->get_one_by_ID($ID); |
|
457 | + $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
458 | + $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields); |
|
459 | + } else { |
|
460 | + $question = EE_Question::new_instance(); |
|
461 | + $question->set_order_to_latest(); |
|
462 | + $this->_set_add_edit_form_tags('insert_question'); |
|
463 | + } |
|
464 | + if ($question->system_ID() === EEM_Attendee::system_question_phone) { |
|
465 | + $question_types = array_intersect_key( |
|
466 | + EEM_Question::instance()->allowed_question_types(), |
|
467 | + array_flip( |
|
468 | + array( |
|
469 | + EEM_Question::QST_type_text, |
|
470 | + EEM_Question::QST_type_us_phone, |
|
471 | + ) |
|
472 | + ) |
|
473 | + ); |
|
474 | + } else { |
|
475 | + $question_types = $question->has_answers() ? $this->_question_model->question_types_in_same_category( |
|
476 | + $question->type() |
|
477 | + ) : $this->_question_model->allowed_question_types(); |
|
478 | + } |
|
479 | + $this->_template_args['QST_ID'] = $ID; |
|
480 | + $this->_template_args['question'] = $question; |
|
481 | + $this->_template_args['question_types'] = $question_types; |
|
482 | + $this->_template_args['max_max'] = EEM_Question::instance()->absolute_max_for_system_question( |
|
483 | + $question->system_ID() |
|
484 | + ); |
|
485 | + $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
|
486 | + $this->_set_publish_post_box_vars('id', $ID); |
|
487 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
488 | + REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
489 | + $this->_template_args, |
|
490 | + true |
|
491 | + ); |
|
492 | + |
|
493 | + // the details template wrapper |
|
494 | + $this->display_admin_page_with_sidebar(); |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + /** |
|
499 | + * @return string |
|
500 | + */ |
|
501 | + protected function _get_question_type_descriptions() |
|
502 | + { |
|
503 | + EE_Registry::instance()->load_helper('HTML'); |
|
504 | + $descriptions = ''; |
|
505 | + $question_type_descriptions = EEM_Question::instance()->question_descriptions(); |
|
506 | + foreach ($question_type_descriptions as $type => $question_type_description) { |
|
507 | + if ($type == 'HTML_TEXTAREA') { |
|
508 | + $html = new EE_Simple_HTML_Validation_Strategy(); |
|
509 | + $question_type_description .= sprintf( |
|
510 | + esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'), |
|
511 | + '<br/>', |
|
512 | + $html->get_list_of_allowed_tags() |
|
513 | + ); |
|
514 | + } |
|
515 | + $descriptions .= EEH_HTML::p( |
|
516 | + $question_type_description, |
|
517 | + 'question_type_description-' . $type, |
|
518 | + 'question_type_description description', |
|
519 | + 'display:none;' |
|
520 | + ); |
|
521 | + } |
|
522 | + return $descriptions; |
|
523 | + } |
|
524 | + |
|
525 | + |
|
526 | + /** |
|
527 | + * @param bool|true $new_question |
|
528 | + * @throws \EE_Error |
|
529 | + */ |
|
530 | + protected function _insert_or_update_question($new_question = true) |
|
531 | + { |
|
532 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
533 | + $set_column_values = $this->_set_column_values_for($this->_question_model); |
|
534 | + if ($new_question) { |
|
535 | + $question = EE_Question::new_instance($set_column_values); |
|
536 | + $action_desc = 'added'; |
|
537 | + } else { |
|
538 | + $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
539 | + foreach ($set_column_values as $field => $new_value) { |
|
540 | + $question->set($field, $new_value); |
|
541 | + } |
|
542 | + $action_desc = 'updated'; |
|
543 | + } |
|
544 | + $success = $question->save(); |
|
545 | + $ID = $question->ID(); |
|
546 | + if ($ID && $question->should_have_question_options()) { |
|
547 | + // save the related options |
|
548 | + // trash removed options, save old ones |
|
549 | + // get list of all options |
|
550 | + $options = $question->options(); |
|
551 | + if (! empty($options)) { |
|
552 | + foreach ($options as $option_ID => $option) { |
|
553 | + $option_req_index = $this->_get_option_req_data_index($option_ID); |
|
554 | + if ($option_req_index !== false) { |
|
555 | + $option->save($this->_req_data['question_options'][ $option_req_index ]); |
|
556 | + } else { |
|
557 | + // not found, remove it |
|
558 | + $option->delete(); |
|
559 | + } |
|
560 | + } |
|
561 | + } |
|
562 | + // save new related options |
|
563 | + foreach ($this->_req_data['question_options'] as $index => $option_req_data) { |
|
564 | + // skip $index that is from our sample |
|
565 | + if ($index === 'xxcountxx') { |
|
566 | + continue; |
|
567 | + } |
|
568 | + // note we allow saving blank options. |
|
569 | + if (empty($option_req_data['QSO_ID']) |
|
570 | + ) {// no ID! save it! |
|
571 | + $new_option = EE_Question_Option::new_instance( |
|
572 | + array( |
|
573 | + 'QSO_value' => $option_req_data['QSO_value'], |
|
574 | + 'QSO_desc' => $option_req_data['QSO_desc'], |
|
575 | + 'QSO_order' => $option_req_data['QSO_order'], |
|
576 | + 'QST_ID' => $question->ID(), |
|
577 | + ) |
|
578 | + ); |
|
579 | + $new_option->save(); |
|
580 | + } |
|
581 | + } |
|
582 | + } |
|
583 | + $query_args = array('action' => 'edit_question', 'QST_ID' => $ID); |
|
584 | + if ($success !== false) { |
|
585 | + $msg = $new_question |
|
586 | + ? sprintf( |
|
587 | + esc_html__('The %s has been created', 'event_espresso'), |
|
588 | + $this->_question_model->item_name() |
|
589 | + ) |
|
590 | + : sprintf( |
|
591 | + esc_html__('The %s has been updated', 'event_espresso'), |
|
592 | + $this->_question_model->item_name() |
|
593 | + ); |
|
594 | + EE_Error::add_success($msg); |
|
595 | + } |
|
596 | + |
|
597 | + $this->_redirect_after_action(false, '', $action_desc, $query_args, true); |
|
598 | + } |
|
599 | + |
|
600 | + |
|
601 | + /** |
|
602 | + * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not |
|
603 | + * by ID |
|
604 | + * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously). |
|
605 | + * So, this function gets the index in that request data array called question_options. Returns FALSE if not found. |
|
606 | + * |
|
607 | + * @param int $ID of the question option to find |
|
608 | + * @return int index in question_options array if successful, FALSE if unsuccessful |
|
609 | + */ |
|
610 | + protected function _get_option_req_data_index($ID) |
|
611 | + { |
|
612 | + $req_data_for_question_options = $this->_req_data['question_options']; |
|
613 | + foreach ($req_data_for_question_options as $num => $option_data) { |
|
614 | + if (array_key_exists('QSO_ID', $option_data) && (int) $option_data['QSO_ID'] === $ID) { |
|
615 | + return $num; |
|
616 | + } |
|
617 | + } |
|
618 | + return false; |
|
619 | + } |
|
620 | + |
|
621 | + |
|
622 | + |
|
623 | + |
|
624 | + /***********/ |
|
625 | + /* QUERIES */ |
|
626 | + /** |
|
627 | + * For internal use in getting all the query parameters |
|
628 | + * (because it's pretty well the same between question, question groups, |
|
629 | + * and for both when searching for trashed and untrashed ones) |
|
630 | + * |
|
631 | + * @param EEM_Base $model either EEM_Question or EEM_Question_Group |
|
632 | + * @param int $per_page |
|
633 | + * @param int $current_page |
|
634 | + * @return array model query params, @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
635 | + */ |
|
636 | + protected function get_query_params($model, $per_page = 10, $current_page = 10) |
|
637 | + { |
|
638 | + $query_params = array(); |
|
639 | + $offset = ($current_page - 1) * $per_page; |
|
640 | + $query_params['limit'] = array($offset, $per_page); |
|
641 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
642 | + : 'ASC'; |
|
643 | + $orderby_field = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order'; |
|
644 | + $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
|
645 | + $query_params['order_by'] = array($field_to_order_by => $order); |
|
646 | + $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
|
647 | + if (! empty($search_string)) { |
|
648 | + if ($model instanceof EEM_Question_Group) { |
|
649 | + $query_params[0] = array( |
|
650 | + 'OR' => array( |
|
651 | + 'QSG_name' => array('LIKE', "%$search_string%"), |
|
652 | + 'QSG_desc' => array('LIKE', "%$search_string%"), |
|
653 | + ), |
|
654 | + ); |
|
655 | + } else { |
|
656 | + $query_params[0] = array( |
|
657 | + 'QST_display_text' => array('LIKE', "%$search_string%"), |
|
658 | + ); |
|
659 | + } |
|
660 | + } |
|
661 | + |
|
662 | + // capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented) |
|
663 | + /*if ( $model instanceof EEM_Question_Group ) { |
|
664 | 664 | if ( ! EE_Registry::instance()->CAP->current_user_can( 'edit_others_question_groups', 'espresso_registration_form_edit_question_group' ) ) { |
665 | 665 | $query_params[0] = array( |
666 | 666 | 'AND' => array( |
@@ -690,59 +690,59 @@ discard block |
||
690 | 690 | } |
691 | 691 | }/**/ |
692 | 692 | |
693 | - return $query_params; |
|
694 | - } |
|
695 | - |
|
696 | - |
|
697 | - /** |
|
698 | - * @param int $per_page |
|
699 | - * @param int $current_page |
|
700 | - * @param bool|false $count |
|
701 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
702 | - */ |
|
703 | - public function get_questions($per_page = 10, $current_page = 1, $count = false) |
|
704 | - { |
|
705 | - $QST = EEM_Question::instance(); |
|
706 | - $query_params = $this->get_query_params($QST, $per_page, $current_page); |
|
707 | - if ($count) { |
|
708 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
709 | - $results = $QST->count($where); |
|
710 | - } else { |
|
711 | - $results = $QST->get_all($query_params); |
|
712 | - } |
|
713 | - return $results; |
|
714 | - } |
|
715 | - |
|
716 | - |
|
717 | - /** |
|
718 | - * @param $per_page |
|
719 | - * @param int $current_page |
|
720 | - * @param bool|false $count |
|
721 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
722 | - */ |
|
723 | - public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
724 | - { |
|
725 | - $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
726 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
727 | - $questions = $count ? EEM_Question::instance()->count_deleted($where) |
|
728 | - : EEM_Question::instance()->get_all_deleted($query_params); |
|
729 | - return $questions; |
|
730 | - } |
|
731 | - |
|
732 | - |
|
733 | - /** |
|
734 | - * @param $per_page |
|
735 | - * @param int $current_page |
|
736 | - * @param bool|false $count |
|
737 | - * @return \EE_Soft_Delete_Base_Class[] |
|
738 | - */ |
|
739 | - public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
740 | - { |
|
741 | - /** @type EEM_Question_Group $questionGroupModel */ |
|
742 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
743 | - // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
744 | - return $questionGroupModel->get_all( |
|
745 | - $this->get_query_params($questionGroupModel, $per_page, $current_page) |
|
746 | - ); |
|
747 | - } |
|
693 | + return $query_params; |
|
694 | + } |
|
695 | + |
|
696 | + |
|
697 | + /** |
|
698 | + * @param int $per_page |
|
699 | + * @param int $current_page |
|
700 | + * @param bool|false $count |
|
701 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
702 | + */ |
|
703 | + public function get_questions($per_page = 10, $current_page = 1, $count = false) |
|
704 | + { |
|
705 | + $QST = EEM_Question::instance(); |
|
706 | + $query_params = $this->get_query_params($QST, $per_page, $current_page); |
|
707 | + if ($count) { |
|
708 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
709 | + $results = $QST->count($where); |
|
710 | + } else { |
|
711 | + $results = $QST->get_all($query_params); |
|
712 | + } |
|
713 | + return $results; |
|
714 | + } |
|
715 | + |
|
716 | + |
|
717 | + /** |
|
718 | + * @param $per_page |
|
719 | + * @param int $current_page |
|
720 | + * @param bool|false $count |
|
721 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
722 | + */ |
|
723 | + public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
724 | + { |
|
725 | + $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
726 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
727 | + $questions = $count ? EEM_Question::instance()->count_deleted($where) |
|
728 | + : EEM_Question::instance()->get_all_deleted($query_params); |
|
729 | + return $questions; |
|
730 | + } |
|
731 | + |
|
732 | + |
|
733 | + /** |
|
734 | + * @param $per_page |
|
735 | + * @param int $current_page |
|
736 | + * @param bool|false $count |
|
737 | + * @return \EE_Soft_Delete_Base_Class[] |
|
738 | + */ |
|
739 | + public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
740 | + { |
|
741 | + /** @type EEM_Question_Group $questionGroupModel */ |
|
742 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
743 | + // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
744 | + return $questionGroupModel->get_all( |
|
745 | + $this->get_query_params($questionGroupModel, $per_page, $current_page) |
|
746 | + ); |
|
747 | + } |
|
748 | 748 | } |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function __construct($routing = true) |
55 | 55 | { |
56 | - require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
57 | - require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
56 | + require_once(EE_MODELS.'EEM_Question.model.php'); |
|
57 | + require_once(EE_MODELS.'EEM_Question_Group.model.php'); |
|
58 | 58 | $this->_question_model = EEM_Question::instance(); |
59 | 59 | $this->_question_group_model = EEM_Question_Group::instance(); |
60 | 60 | parent::__construct($routing); |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | { |
223 | 223 | wp_register_style( |
224 | 224 | 'espresso_registration', |
225 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', |
|
225 | + REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.css', |
|
226 | 226 | array(), |
227 | 227 | EVENT_ESPRESSO_VERSION |
228 | 228 | ); |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | $this->load_scripts_styles_forms(); |
266 | 266 | wp_register_script( |
267 | 267 | 'espresso_registration_form_single', |
268 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', |
|
268 | + REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.js', |
|
269 | 269 | array('jquery-ui-sortable'), |
270 | 270 | EVENT_ESPRESSO_VERSION, |
271 | 271 | true |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | |
285 | 285 | public function recaptcha_info_help_tab() |
286 | 286 | { |
287 | - $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
287 | + $template = REGISTRATION_FORM_TEMPLATE_PATH.'recaptcha_info_help_tab.template.php'; |
|
288 | 288 | EEH_Template::display_template($template, array()); |
289 | 289 | } |
290 | 290 | |
@@ -329,16 +329,16 @@ discard block |
||
329 | 329 | protected function _questions_groups_preview() |
330 | 330 | { |
331 | 331 | $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
332 | - $this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' |
|
332 | + $this->_template_args['preview_img'] = '<img src="'.REGISTRATION_FORM_ASSETS_URL.'caf_reg_form_preview.jpg" alt="' |
|
333 | 333 | . esc_attr__( |
334 | 334 | 'Preview Question Groups Overview List Table screenshot', |
335 | 335 | 'event_espresso' |
336 | - ) . '" />'; |
|
336 | + ).'" />'; |
|
337 | 337 | $this->_template_args['preview_text'] = '<strong>' |
338 | 338 | . esc_html__( |
339 | 339 | 'Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
340 | 340 | 'event_espresso' |
341 | - ) . '</strong>'; |
|
341 | + ).'</strong>'; |
|
342 | 342 | $this->display_admin_caf_preview_page('question_groups_tab'); |
343 | 343 | } |
344 | 344 | |
@@ -356,11 +356,11 @@ discard block |
||
356 | 356 | |
357 | 357 | // some initial checks for proper values. |
358 | 358 | // if QST_admin_only, then no matter what QST_required is we disable. |
359 | - if (! empty($this->_req_data['QST_admin_only'])) { |
|
359 | + if ( ! empty($this->_req_data['QST_admin_only'])) { |
|
360 | 360 | $this->_req_data['QST_required'] = 0; |
361 | 361 | } |
362 | 362 | // if the question shouldn't have a max length, don't let them set one |
363 | - if (! isset( |
|
363 | + if ( ! isset( |
|
364 | 364 | $this->_req_data['QST_type'], |
365 | 365 | $this->_req_data['QST_max'] |
366 | 366 | ) |
@@ -380,16 +380,16 @@ discard block |
||
380 | 380 | && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier'])) |
381 | 381 | ) { |
382 | 382 | $QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : ''; |
383 | - $set_column_values[ $fieldName ] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
383 | + $set_column_values[$fieldName] = sanitize_title($QSG_name).'-'.uniqid('', true); |
|
384 | 384 | } elseif ( |
385 | 385 | // if the admin label is blank, use a slug version of the question text |
386 | 386 | $fieldName === 'QST_admin_label' |
387 | 387 | && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label'])) |
388 | 388 | ) { |
389 | 389 | $QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : ''; |
390 | - $set_column_values[ $fieldName ] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
391 | - } elseif ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
392 | - $set_column_values[ $fieldName ] = 0; |
|
390 | + $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
391 | + } elseif ($fieldName === 'QST_admin_only' && ( ! isset($this->_req_data['QST_admin_only']))) { |
|
392 | + $set_column_values[$fieldName] = 0; |
|
393 | 393 | } elseif ($fieldName === 'QST_max') { |
394 | 394 | $qst_system = EEM_Question::instance()->get_var( |
395 | 395 | array( |
@@ -403,19 +403,19 @@ discard block |
||
403 | 403 | if (empty($this->_req_data['QST_max']) || |
404 | 404 | $this->_req_data['QST_max'] > $max_max |
405 | 405 | ) { |
406 | - $set_column_values[ $fieldName ] = $max_max; |
|
406 | + $set_column_values[$fieldName] = $max_max; |
|
407 | 407 | } |
408 | 408 | } |
409 | 409 | |
410 | 410 | |
411 | 411 | // only add a property to the array if it's not null (otherwise the model should just use the default value) |
412 | - if (! isset($set_column_values[ $fieldName ]) && |
|
413 | - isset($this->_req_data[ $fieldName ]) |
|
412 | + if ( ! isset($set_column_values[$fieldName]) && |
|
413 | + isset($this->_req_data[$fieldName]) |
|
414 | 414 | ) { |
415 | - $set_column_values[ $fieldName ] = $this->_req_data[ $fieldName ]; |
|
415 | + $set_column_values[$fieldName] = $this->_req_data[$fieldName]; |
|
416 | 416 | } |
417 | 417 | } |
418 | - return $set_column_values;// validation fo this data to be performed by the model before insertion. |
|
418 | + return $set_column_values; // validation fo this data to be performed by the model before insertion. |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | } |
452 | 452 | |
453 | 453 | // add PRC_ID to title if editing |
454 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
454 | + $this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title; |
|
455 | 455 | if ($ID) { |
456 | 456 | $question = $this->_question_model->get_one_by_ID($ID); |
457 | 457 | $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID)); |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
486 | 486 | $this->_set_publish_post_box_vars('id', $ID); |
487 | 487 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
488 | - REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
488 | + REGISTRATION_FORM_TEMPLATE_PATH.'questions_main_meta_box.template.php', |
|
489 | 489 | $this->_template_args, |
490 | 490 | true |
491 | 491 | ); |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | } |
515 | 515 | $descriptions .= EEH_HTML::p( |
516 | 516 | $question_type_description, |
517 | - 'question_type_description-' . $type, |
|
517 | + 'question_type_description-'.$type, |
|
518 | 518 | 'question_type_description description', |
519 | 519 | 'display:none;' |
520 | 520 | ); |
@@ -548,11 +548,11 @@ discard block |
||
548 | 548 | // trash removed options, save old ones |
549 | 549 | // get list of all options |
550 | 550 | $options = $question->options(); |
551 | - if (! empty($options)) { |
|
551 | + if ( ! empty($options)) { |
|
552 | 552 | foreach ($options as $option_ID => $option) { |
553 | 553 | $option_req_index = $this->_get_option_req_data_index($option_ID); |
554 | 554 | if ($option_req_index !== false) { |
555 | - $option->save($this->_req_data['question_options'][ $option_req_index ]); |
|
555 | + $option->save($this->_req_data['question_options'][$option_req_index]); |
|
556 | 556 | } else { |
557 | 557 | // not found, remove it |
558 | 558 | $option->delete(); |
@@ -644,7 +644,7 @@ discard block |
||
644 | 644 | $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
645 | 645 | $query_params['order_by'] = array($field_to_order_by => $order); |
646 | 646 | $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
647 | - if (! empty($search_string)) { |
|
647 | + if ( ! empty($search_string)) { |
|
648 | 648 | if ($model instanceof EEM_Question_Group) { |
649 | 649 | $query_params[0] = array( |
650 | 650 | 'OR' => array( |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <p class="about-description"> |
2 | 2 | <?php esc_html_e( |
3 | - 'Event Espresso is created by an international team of passionate individuals with a drive to empower your events!', |
|
4 | - 'event_espresso' |
|
5 | - ); ?></p> |
|
3 | + 'Event Espresso is created by an international team of passionate individuals with a drive to empower your events!', |
|
4 | + 'event_espresso' |
|
5 | + ); ?></p> |
|
6 | 6 | <h3 class="wp-people-group"><?php esc_html_e('Founders', 'event_espresso'); ?></h3> |
7 | 7 | <ul class="wp-people-group" id="ee-people-group-owners"> |
8 | 8 | <li class="wp-person" id="ee-person-sshoultes"> |
@@ -85,15 +85,15 @@ discard block |
||
85 | 85 | <h3 class="wp-people-group"><?php esc_html_e('Contributor Recognition', 'event_espresso'); ?></h3> |
86 | 86 | <p class="description"> |
87 | 87 | <?php |
88 | - printf( |
|
89 | - esc_html__( |
|
90 | - 'For every major release we want to recognize the people who contributed to the release via a GitHub pull request. Want to see your name listed here? %sWhen you submit a pull request that gets included in a major release%s, we\'ll add your name here linked to your GitHub profile.', |
|
91 | - 'event_espresso' |
|
92 | - ), |
|
93 | - '<a href="https://github.com/eventespresso/event-espresso-core" title="Contribute to Event Espresso by making a pull request via GitHub">', |
|
94 | - '</a>' |
|
95 | - ); |
|
96 | - ?> |
|
88 | + printf( |
|
89 | + esc_html__( |
|
90 | + 'For every major release we want to recognize the people who contributed to the release via a GitHub pull request. Want to see your name listed here? %sWhen you submit a pull request that gets included in a major release%s, we\'ll add your name here linked to your GitHub profile.', |
|
91 | + 'event_espresso' |
|
92 | + ), |
|
93 | + '<a href="https://github.com/eventespresso/event-espresso-core" title="Contribute to Event Espresso by making a pull request via GitHub">', |
|
94 | + '</a>' |
|
95 | + ); |
|
96 | + ?> |
|
97 | 97 | </p> |
98 | 98 | <p class="wp-credits-list"> |
99 | 99 | <ul> |
@@ -108,15 +108,15 @@ discard block |
||
108 | 108 | <h3 class="wp-people-group"><?php esc_html_e('External Libraries', 'event_espresso'); ?></h3> |
109 | 109 | <p class="description"> |
110 | 110 | <?php |
111 | - printf( |
|
112 | - esc_html__( |
|
113 | - 'Along with the libraries %sincluded with WordPress%s, Event Espresso utilizes the following third party libraries:', |
|
114 | - 'event_espresso' |
|
115 | - ), |
|
116 | - '<a href="credits.php">', |
|
117 | - '</a>' |
|
118 | - ); |
|
119 | - ?> |
|
111 | + printf( |
|
112 | + esc_html__( |
|
113 | + 'Along with the libraries %sincluded with WordPress%s, Event Espresso utilizes the following third party libraries:', |
|
114 | + 'event_espresso' |
|
115 | + ), |
|
116 | + '<a href="credits.php">', |
|
117 | + '</a>' |
|
118 | + ); |
|
119 | + ?> |
|
120 | 120 | </p> |
121 | 121 | <p class="wp-credits-list"> |
122 | 122 | <a href="https://openexchangerates.github.io/accounting.js/">accounting.js</a>, |
@@ -133,12 +133,12 @@ discard block |
||
133 | 133 | <?php |
134 | 134 | function esp_gravatar_profile($email) |
135 | 135 | { |
136 | - echo 'https://www.gravatar.com/' . md5($email); |
|
136 | + echo 'https://www.gravatar.com/' . md5($email); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | function esp_gravatar_image($email, $name) |
140 | 140 | { |
141 | - echo '<img src="https://0.gravatar.com/avatar/' . md5($email) . '?s=60" class="gravatar" alt="' . $name . '"/>'; |
|
141 | + echo '<img src="https://0.gravatar.com/avatar/' . md5($email) . '?s=60" class="gravatar" alt="' . $name . '"/>'; |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | ?> |
@@ -1,25 +1,25 @@ |
||
1 | 1 | <p><strong><?php esc_html_e('Message Templates', 'event_espresso'); ?></strong></p> |
2 | 2 | <p> |
3 | 3 | <?php |
4 | - printf( |
|
5 | - esc_html__( |
|
6 | - 'Message Templates are the %1$sformat%2$s of the messages going out. Think of them as a “form letter”. Templates tell the Messages system how to style your messages and the content (information) they will have when they are delivered.', |
|
7 | - 'event_espresso' |
|
8 | - ), |
|
9 | - '<em>', |
|
10 | - '</em>' |
|
11 | - ); |
|
12 | - ?> |
|
4 | + printf( |
|
5 | + esc_html__( |
|
6 | + 'Message Templates are the %1$sformat%2$s of the messages going out. Think of them as a “form letter”. Templates tell the Messages system how to style your messages and the content (information) they will have when they are delivered.', |
|
7 | + 'event_espresso' |
|
8 | + ), |
|
9 | + '<em>', |
|
10 | + '</em>' |
|
11 | + ); |
|
12 | + ?> |
|
13 | 13 | </p> |
14 | 14 | <p> |
15 | 15 | <?php esc_html_e( |
16 | - 'There is a template created for each Messenger / Message Type and context combination. For example, messages that are sent for Payment Confirmation have a template for Event Administrator and a different one for Primary Registrant. Whereas, messages that are sent for the Registration confirmation have 3 templates: one for Event Administrator, one for the Primary Registrant, and another for each additional Registrant(s).', |
|
17 | - 'event_espresso' |
|
18 | - ); ?> |
|
16 | + 'There is a template created for each Messenger / Message Type and context combination. For example, messages that are sent for Payment Confirmation have a template for Event Administrator and a different one for Primary Registrant. Whereas, messages that are sent for the Registration confirmation have 3 templates: one for Event Administrator, one for the Primary Registrant, and another for each additional Registrant(s).', |
|
17 | + 'event_espresso' |
|
18 | + ); ?> |
|
19 | 19 | </p> |
20 | 20 | <p> |
21 | 21 | <?php esc_html_e( |
22 | - 'With the Event Espresso Messages system, every Messenger, Message Type, and context will have a global template created with some default content on creation. You have the ability to edit the global template that will be used for all events you create. Additionally, you have the ability to create custom templates for each event on the edit event page for the event (in a metabox labelled "Notifications").', |
|
23 | - 'event_espresso' |
|
24 | - ); ?> |
|
22 | + 'With the Event Espresso Messages system, every Messenger, Message Type, and context will have a global template created with some default content on creation. You have the ability to edit the global template that will be used for all events you create. Additionally, you have the ability to create custom templates for each event on the edit event page for the event (in a metabox labelled "Notifications").', |
|
23 | + 'event_espresso' |
|
24 | + ); ?> |
|
25 | 25 | </p> |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <p><strong><?php _e('Messengers', 'event_espresso'); ?></strong></p> |
2 | 2 | <p> |
3 | 3 | <?php |
4 | - printf( |
|
5 | - esc_html__( |
|
6 | - 'Messengers are the vehicles that deliver messages to individuals (recipients). By default, every install of Event Espresso has the %sEmail%s messenger active. The Email messenger is a vehicle for delivering messages. Other possible vehicles might be any social media applications, 3rd party API\'s etc.', |
|
7 | - 'event_espresso' |
|
8 | - ), |
|
9 | - '<strong>', |
|
10 | - '</strong>' |
|
11 | - ); |
|
12 | - ?> |
|
4 | + printf( |
|
5 | + esc_html__( |
|
6 | + 'Messengers are the vehicles that deliver messages to individuals (recipients). By default, every install of Event Espresso has the %sEmail%s messenger active. The Email messenger is a vehicle for delivering messages. Other possible vehicles might be any social media applications, 3rd party API\'s etc.', |
|
7 | + 'event_espresso' |
|
8 | + ), |
|
9 | + '<strong>', |
|
10 | + '</strong>' |
|
11 | + ); |
|
12 | + ?> |
|
13 | 13 | </p> |
14 | 14 | \ No newline at end of file |
@@ -1,15 +1,15 @@ discard block |
||
1 | 1 | <p><strong><?php esc_html_e('Message Types', 'event_espresso'); ?></strong></p> |
2 | 2 | <p> |
3 | 3 | <?php |
4 | - printf( |
|
5 | - esc_html__( |
|
6 | - 'Messages are email notifications that are sent out by Event Espresso. Message Types are the %1$skinds%2$s of messages that get delivered. They can be thought of as the "type" of package that is being delivered by the messenger. For example, Event Espresso comes with two Message Types attached to the Email Messenger:', |
|
7 | - 'event_espresso' |
|
8 | - ), |
|
9 | - '<em>', |
|
10 | - '</em>' |
|
11 | - ); |
|
12 | - ?> |
|
4 | + printf( |
|
5 | + esc_html__( |
|
6 | + 'Messages are email notifications that are sent out by Event Espresso. Message Types are the %1$skinds%2$s of messages that get delivered. They can be thought of as the "type" of package that is being delivered by the messenger. For example, Event Espresso comes with two Message Types attached to the Email Messenger:', |
|
7 | + 'event_espresso' |
|
8 | + ), |
|
9 | + '<em>', |
|
10 | + '</em>' |
|
11 | + ); |
|
12 | + ?> |
|
13 | 13 | </p> |
14 | 14 | <ul> |
15 | 15 | <li> |
@@ -24,20 +24,20 @@ discard block |
||
24 | 24 | <p><strong><?php esc_html_e('Contexts', 'event_espresso'); ?></strong></p> |
25 | 25 | <p> |
26 | 26 | <?php esc_html_e( |
27 | - 'Each Message Type (kind of message) has different contexts. Contexts are dynamic and typically represent recipients (individuals receiving email notifications). For example, when the Registration Confirmation message type is triggered, it will send out a message to the following recipients: Event Administrator, Primary Registrant, and Additional Registrants. On the other hand, the Payment Message Type has only two recipients: Event Administrator and Primary Registrant.', |
|
28 | - 'event_espresso' |
|
29 | - ); ?> |
|
27 | + 'Each Message Type (kind of message) has different contexts. Contexts are dynamic and typically represent recipients (individuals receiving email notifications). For example, when the Registration Confirmation message type is triggered, it will send out a message to the following recipients: Event Administrator, Primary Registrant, and Additional Registrants. On the other hand, the Payment Message Type has only two recipients: Event Administrator and Primary Registrant.', |
|
28 | + 'event_espresso' |
|
29 | + ); ?> |
|
30 | 30 | </p> |
31 | 31 | <p> |
32 | 32 | <?php esc_html_e( |
33 | - 'A message context can be deactivated by removing a recipient from the "TO" field. This will set the field to blank and you can save changes. Deactivated message contexts will appear in grey when viewed in the Messages Overview tab. To re-activate a message context, go to that message context and setup a recipient (using one of the available shortcodes) and save changes. This will reactivate the message context and it will appear as blue in the Messages Overview tab.', |
|
34 | - 'event_espresso' |
|
35 | - ); ?> |
|
33 | + 'A message context can be deactivated by removing a recipient from the "TO" field. This will set the field to blank and you can save changes. Deactivated message contexts will appear in grey when viewed in the Messages Overview tab. To re-activate a message context, go to that message context and setup a recipient (using one of the available shortcodes) and save changes. This will reactivate the message context and it will appear as blue in the Messages Overview tab.', |
|
34 | + 'event_espresso' |
|
35 | + ); ?> |
|
36 | 36 | </p> |
37 | 37 | <p><strong><?php esc_html_e('Activation / Deactivation of Message Types', 'event_espresso'); ?></strong></p> |
38 | 38 | <p> |
39 | 39 | <?php esc_html_e( |
40 | - 'When a new install of Event Espresso is activated, all message types will be activated except for those for Cancelled and Declined registrations. The message types for Cancelled and Declined registrations can be easily activated through the Settings tab for Messages. Deactivating and re-activating Event Espresso will keep the current settings saved.', |
|
41 | - 'event_espresso' |
|
42 | - ); ?> |
|
40 | + 'When a new install of Event Espresso is activated, all message types will be activated except for those for Cancelled and Declined registrations. The message types for Cancelled and Declined registrations can be easily activated through the Settings tab for Messages. Deactivating and re-activating Event Espresso will keep the current settings saved.', |
|
41 | + 'event_espresso' |
|
42 | + ); ?> |
|
43 | 43 | </p> |