PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.07.01
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.07.01
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / helpers / FrmFieldsHelper.php

FrmFieldsHelper.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 4.07.01, at classes/helpers/FrmFieldsHelper.php

1,852 lines 54.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmFieldsHelper {
7
8 public static function setup_new_vars( $type = '', $form_id = '' ) {
9
10 if ( strpos( $type, '|' ) ) {
11 list( $type, $setting ) = explode( '|', $type );
12 }
13
14 $values = self::get_default_field( $type );
15
16 global $wpdb;
17 $field_count = FrmDb::get_var( 'frm_fields', array( 'form_id' => $form_id ), 'field_order', array( 'order_by' => 'field_order DESC' ) );
18
19 $values['field_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_fields', 'field_key' );
20 $values['form_id'] = $form_id;
21 $values['field_order'] = $field_count + 1;
22
23 $values['field_options']['custom_html'] = self::get_default_html( $type );
24
25 if ( isset( $setting ) && ! empty( $setting ) ) {
26 if ( in_array( $type, array( 'data', 'lookup' ) ) ) {
27 $values['field_options']['data_type'] = $setting;
28 } else {
29 $values['field_options'][ $setting ] = 1;
30 }
31 }
32
33 return $values;
34 }
35
36 public static function get_html_id( $field, $plus = '' ) {
37 return apply_filters( 'frm_field_html_id', 'field_' . $field['field_key'] . $plus, $field );
38 }
39
40 public static function setup_edit_vars( $field, $doing_ajax = false ) {
41 $values = self::field_object_to_array( $field );
42
43 return apply_filters( 'frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax ) );
44 }
45
46 public static function field_object_to_array( $field ) {
47 $values = (array) $field;
48
49 self::fill_field_array( $field, $values );
50
51 $values['custom_html'] = ( isset( $field->field_options['custom_html'] ) ) ? $field->field_options['custom_html'] : self::get_default_html( $field->type );
52
53 return $values;
54 }
55
56 private static function fill_field_array( $field, array &$field_array ) {
57 $field_array['options'] = $field->options;
58 $field_array['value'] = $field->default_value;
59
60 self::prepare_edit_front_field( $field_array, $field );
61
62 $field_array = array_merge( (array) $field->field_options, $field_array );
63 }
64
65 /**
66 * Prepare field while creating a new entry
67 *
68 * @since 3.0
69 */
70 public static function prepare_new_front_field( &$field_array, $field, $args = array() ) {
71 $args['action'] = 'new';
72 self::prepare_front_field( $field_array, $field, $args );
73 }
74
75 /**
76 * Prepare field while editing an entry
77 *
78 * @since 3.0
79 */
80 public static function prepare_edit_front_field( &$field_array, $field, $entry_id = 0, $args = array() ) {
81 $args['entry_id'] = $entry_id;
82 $args['action'] = 'edit';
83 self::prepare_front_field( $field_array, $field, $args );
84 }
85
86 /**
87 * Prepare field while creating a new entry
88 *
89 * @since 3.0
90 */
91 private static function prepare_front_field( &$field_array, $field, $args ) {
92 self::fill_default_field_opts( $field, $field_array );
93 self::fill_cleared_strings( $field, $field_array );
94
95 // Track the original field's type
96 $field_array['original_type'] = isset( $field->field_options['original_type'] ) ? $field->field_options['original_type'] : $field->type;
97
98 self::prepare_field_options_for_display( $field_array, $field, $args );
99
100 if ( $args['action'] == 'edit' ) {
101 $field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $args['entry_id'], $args );
102 } else {
103 $field_array = apply_filters( 'frm_setup_new_fields_vars', $field_array, $field, $args );
104 }
105 }
106
107 /**
108 * @since 3.0
109 *
110 * @param string $type
111 *
112 * @return array
113 */
114 public static function get_default_field_options( $type ) {
115 $field_type = FrmFieldFactory::get_field_type( $type );
116
117 return $field_type->get_default_field_options();
118 }
119
120 /**
121 * @since 3.0
122 *
123 * @param object $field
124 * @param array $values
125 */
126 private static function fill_default_field_opts( $field, array &$values ) {
127 $check_post = FrmAppHelper::is_admin_page() && $_POST && isset( $_POST['field_options'] );
128
129 $defaults = self::get_default_field_options_from_field( $field, $values );
130 if ( ! $check_post ) {
131 $defaults['required_indicator'] = '';
132 $defaults['original_type'] = $field->type;
133 }
134
135 foreach ( $defaults as $opt => $default ) {
136 $values[ $opt ] = isset( $field->field_options[ $opt ] ) ? $field->field_options[ $opt ] : $default;
137
138 if ( $check_post ) {
139 self::get_posted_field_setting( $opt . '_' . $field->id, $values[ $opt ] );
140 }
141
142 unset( $opt, $default );
143 }
144 }
145
146 /**
147 * Fill the required message, invalid message,
148 * and refill the HTML when cleared
149 *
150 * @since 3.0
151 *
152 * @param object $field
153 * @param array $field_array
154 */
155 private static function fill_cleared_strings( $field, array &$field_array ) {
156 $frm_settings = FrmAppHelper::get_settings();
157
158 if ( '' == $field_array['blank'] && '1' === $field_array['required'] ) {
159 $field_array['blank'] = $frm_settings->blank_msg;
160 }
161
162 if ( '' == $field_array['invalid'] ) {
163 if ( 'captcha' === $field->type ) {
164 $field_array['invalid'] = $frm_settings->re_msg;
165 } else {
166 /* translators: %s: Field name */
167 $field_array['invalid'] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] );
168 }
169 }
170
171 if ( '' == $field_array['custom_html'] ) {
172 $field_array['custom_html'] = self::get_default_html( $field->type );
173 }
174 }
175
176 /**
177 * @since 3.0
178 *
179 * @param string $setting
180 * @param mixed $value
181 */
182 private static function get_posted_field_setting( $setting, &$value ) {
183 if ( ! isset( $_POST['field_options'][ $setting ] ) ) {
184 return;
185 }
186
187 if ( strpos( $setting, 'html' ) !== false ) {
188 // Strip slashes from HTML but not regex or script tags.
189 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
190 $value = wp_unslash( $_POST['field_options'][ $setting ] );
191 } elseif ( strpos( $setting, 'format_' ) === 0 ) {
192 // TODO: Remove stripslashes on output, and use on input only.
193 $value = sanitize_text_field( $_POST['field_options'][ $setting ] ); // WPCS: sanitization ok.
194 } else {
195 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
196 $value = wp_unslash( $_POST['field_options'][ $setting ] );
197 FrmAppHelper::sanitize_value( 'wp_kses_post', $value );
198 }
199 }
200
201 /**
202 * @since 3.0
203 *
204 * @param object $field
205 * @param array $values The field array is needed for hooks
206 *
207 * @return array
208 */
209 public static function get_default_field_options_from_field( $field, $values = array() ) {
210 $field_type = self::get_original_field( $field );
211 $opts = $field_type->get_default_field_options();
212
213 $opts = apply_filters( 'frm_default_field_opts', $opts, $values, $field );
214 $opts = apply_filters( 'frm_default_' . $field->type . '_field_opts', $opts, $values, $field );
215
216 return $opts;
217 }
218
219 /**
220 * @since 3.0
221 *
222 * @param object $field
223 *
224 * @return array
225 */
226 private static function get_original_field( $field ) {
227 $original_type = FrmField::get_option( $field, 'original_type' );
228 if ( ! empty( $original_type ) && $field->type != $original_type ) {
229 $field->type = $original_type;
230 }
231
232 return FrmFieldFactory::get_field_object( $field );
233 }
234
235 /**
236 * @since 3.0
237 *
238 * @param array $field_array
239 * @param object $field
240 * @param array $atts
241 */
242 private static function prepare_field_options_for_display( &$field_array, $field, $atts ) {
243 $field_obj = FrmFieldFactory::get_field_object( $field );
244 $field_array = $field_obj->prepare_front_field( $field_array, $atts );
245 }
246
247 /**
248 * @since 3.0
249 *
250 * @param string $type
251 *
252 * @return array
253 */
254 public static function get_default_field( $type ) {
255 $field_type = FrmFieldFactory::get_field_type( $type );
256
257 return $field_type->get_new_field_defaults();
258 }
259
260 public static function fill_field( &$values, $field, $form_id, $new_key = '' ) {
261 global $wpdb;
262
263 $values['field_key'] = FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_fields', 'field_key' );
264 $values['form_id'] = $form_id;
265 $values['options'] = maybe_serialize( $field->options );
266 $values['default_value'] = FrmAppHelper::maybe_json_encode( $field->default_value );
267
268 foreach ( array( 'name', 'description', 'type', 'field_order', 'field_options', 'required' ) as $col ) {
269 $values[ $col ] = $field->{$col};
270 }
271 }
272
273 /**
274 * @since 2.0
275 *
276 * @param $field
277 * @param $error
278 *
279 * @return string
280 */
281 public static function get_error_msg( $field, $error ) {
282 $frm_settings = FrmAppHelper::get_settings();
283 $default_settings = $frm_settings->default_options();
284 $field_name = is_array( $field ) ? $field['name'] : $field->name;
285
286 $conf_msg = __( 'The entered values do not match', 'formidable' );
287 $defaults = array(
288 'unique_msg' => array(
289 'full' => $default_settings['unique_msg'],
290 /* translators: %s: Field name */
291 'part' => sprintf( __( '%s must be unique', 'formidable' ), $field_name ),
292 ),
293 'invalid' => array(
294 'full' => __( 'This field is invalid', 'formidable' ),
295 /* translators: %s: Field name */
296 'part' => sprintf( __( '%s is invalid', 'formidable' ), $field_name ),
297 ),
298 'blank' => array(
299 'full' => $frm_settings->blank_msg,
300 'part' => $frm_settings->blank_msg,
301 ),
302 'conf_msg' => array(
303 'full' => $conf_msg,
304 'part' => $conf_msg,
305 ),
306 );
307
308 $msg = FrmField::get_option( $field, $error );
309 $msg = empty( $msg ) ? $defaults[ $error ]['part'] : $msg;
310 $msg = do_shortcode( $msg );
311
312 return $msg;
313 }
314
315 public static function get_form_fields( $form_id, $error = array() ) {
316 $fields = FrmField::get_all_for_form( $form_id );
317
318 return apply_filters( 'frm_get_paged_fields', $fields, $form_id, $error );
319 }
320
321 public static function get_default_html( $type = 'text' ) {
322 $field = FrmFieldFactory::get_field_type( $type );
323 $default_html = $field->default_html();
324
325 // these hooks are here for reverse compatibility since 3.0
326 if ( ! apply_filters( 'frm_normal_field_type_html', true, $type ) ) {
327 $default_html = apply_filters( 'frm_other_custom_html', '', $type );
328 }
329
330 return apply_filters( 'frm_custom_html', $default_html, $type );
331 }
332
333 /**
334 * @param array $fields
335 * @param array $errors
336 * @param object $form
337 * @param $form_action
338 */
339 public static function show_fields( $fields, $errors, $form, $form_action ) {
340 foreach ( $fields as $field ) {
341 $field_obj = FrmFieldFactory::get_field_type( $field['type'], $field );
342 $field_obj->show_field( compact( 'errors', 'form', 'form_action' ) );
343 }
344 }
345
346 /**
347 * @since 3.0
348 *
349 * @param array $atts
350 * @param string|array $value
351 */
352 public static function run_wpautop( $atts, &$value ) {
353 $autop = isset( $atts['wpautop'] ) ? $atts['wpautop'] : true;
354 if ( apply_filters( 'frm_use_wpautop', $autop ) ) {
355 if ( is_array( $value ) ) {
356 $value = implode( "\n", $value );
357 }
358 $value = wpautop( $value );
359 }
360 }
361
362 /**
363 * Get the class to use for the label position
364 *
365 * @since 2.05
366 */
367 public static function &label_position( $position, $field, $form ) {
368 if ( $position && $position != '' ) {
369 if ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
370 $position = 'top';
371 }
372
373 return $position;
374 }
375
376 $position = FrmStylesController::get_style_val( 'position', $form );
377 if ( $position == 'none' ) {
378 $position = 'top';
379 } elseif ( $position == 'no_label' ) {
380 $position = 'none';
381 } elseif ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
382 $position = 'top';
383 }
384
385 $position = apply_filters( 'frm_html_label_position', $position, $field, $form );
386 $position = ( ! empty( $position ) ) ? $position : 'top';
387
388 return $position;
389 }
390
391 /**
392 * Check if this field type allows placeholders
393 *
394 * @since 2.05
395 */
396 public static function is_placeholder_field_type( $type ) {
397 return ! in_array( $type, array( 'radio', 'checkbox', 'hidden', 'file' ) );
398 }
399
400 public static function get_checkbox_id( $field, $opt_key, $type = 'checkbox' ) {
401 $id = $field['id'];
402 if ( isset( $field['in_section'] ) && $field['in_section'] && ! FrmAppHelper::is_admin_page( 'formidable' ) ) {
403 $id .= '-' . $field['in_section'];
404 }
405
406 return 'frm_' . $type . '_' . $id . '-' . $opt_key;
407 }
408
409 public static function show_single_option( $field ) {
410 self::hidden_field_option( $field );
411
412 if ( ! is_array( $field['options'] ) ) {
413 return;
414 }
415
416 $base_name = 'default_value_' . $field['id'];
417 $html_id = isset( $field['html_id'] ) ? $field['html_id'] : self::get_html_id( $field );
418
419 $default_type = self::get_default_value_type( $field );
420
421 foreach ( $field['options'] as $opt_key => $opt ) {
422 $field_val = self::get_value_from_array( $opt, $opt_key, $field );
423 $opt = self::get_label_from_array( $opt, $opt_key, $field );
424
425 $field_name = $base_name . ( $default_type === 'checkbox' ? '[' . $opt_key . ']' : '' );
426
427 $checked = ( isset( $field['default_value'] ) && ( ( ! is_array( $field['default_value'] ) && $field['default_value'] == $field_val ) || ( is_array( $field['default_value'] ) && in_array( $field_val, $field['default_value'] ) ) ) );
428
429 // If this is an "Other" option, get the HTML for it.
430 if ( self::is_other_opt( $opt_key ) ) {
431 if ( FrmAppHelper::pro_is_installed() ) {
432 require( FrmProAppHelper::plugin_path() . '/classes/views/frmpro-fields/other-option.php' );
433 }
434 } else {
435 require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' );
436 }
437
438 unset( $checked );
439 }
440 }
441
442 /**
443 * Include hidden row for javascript to duplicate.
444 *
445 * @since 4.0
446 * @param array $field
447 */
448 private static function hidden_field_option( $field ) {
449 // Don't duplicate during an ajax add option.
450 $ajax_action = FrmAppHelper::get_param( 'action', '', 'post', 'sanitize_text_field' );
451 if ( $ajax_action === 'frm_add_field_option' ) {
452 return;
453 }
454
455 $opt_key = '000';
456 $field_val = __( 'New Option', 'formidable' );
457 $opt = __( 'New Option', 'formidable' );
458 $checked = false;
459 $field_name = 'default_value_' . $field['id'];
460 $html_id = isset( $field['html_id'] ) ? $field['html_id'] : self::get_html_id( $field );
461
462 $default_type = self::get_default_value_type( $field );
463 $field_name .= ( $default_type === 'checkbox' ? '[' . $opt_key . ']' : '' );
464
465 require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' );
466 }
467
468 /**
469 * @since 4.0
470 *
471 * @param array $field
472 * @return string radio or checkbox
473 */
474 private static function get_default_value_type( $field ) {
475 $default_type = $field['type'];
476 if ( $field['type'] === 'select' ) {
477 $default_type = FrmField::is_multiple_select( $field ) ? 'checkbox' : 'radio';
478 }
479 return $default_type;
480 }
481
482 public static function get_value_from_array( $opt, $opt_key, $field ) {
483 $opt = apply_filters( 'frm_field_value_saved', $opt, $opt_key, $field );
484
485 return FrmFieldsController::check_value( $opt, $opt_key, $field );
486 }
487
488 public static function get_label_from_array( $opt, $opt_key, $field ) {
489 $opt = apply_filters( 'frm_field_label_seen', $opt, $opt_key, $field );
490
491 return FrmFieldsController::check_label( $opt );
492 }
493
494 /**
495 * @since 4.0
496 */
497 public static function inline_modal( $args ) {
498 $defaults = array(
499 'id' => '',
500 'class' => '',
501 'show' => 0,
502 'callback' => array(),
503 'args' => array(),
504 'title' => '',
505 );
506 $args = array_merge( $defaults, $args );
507
508 include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/inline-modal.php' );
509 }
510
511 /**
512 * @since 4.0
513 */
514 public static function smart_values() {
515 $continue = apply_filters( 'frm_smart_values_box', true );
516 if ( $continue === true ) {
517 $upgrade_link = array(
518 'medium' => 'builder',
519 'content' => 'smart-tags',
520 );
521 include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/smart-values.php' );
522 }
523 }
524
525 /**
526 * @since 4.0
527 */
528 public static function input_mask() {
529 include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/input-mask-info.php' );
530 }
531
532 /**
533 * @since 4.0
534 */
535 public static function layout_classes() {
536 include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/layout-classes.php' );
537 }
538
539 /**
540 * @param int $tax_id
541 *
542 * @return string
543 */
544 public static function get_term_link( $tax_id ) {
545 $tax = get_taxonomy( $tax_id );
546 if ( ! $tax ) {
547 return '';
548 }
549
550 $link = sprintf(
551 /* translators: %1$s: Start HTML link, %2$s: Content type label, %3$s: Content type, %4$s: End HTML link */
552 esc_html__( 'Options are dynamically created from your %1$s%2$s: %3$s%4$s', 'formidable' ),
553 '<a href="' . esc_url( admin_url( 'edit-tags.php?taxonomy=' . $tax->name ) ) . '" target="_blank">',
554 esc_html__( 'taxonomy', 'formidable' ),
555 empty( $tax->labels->name ) ? esc_html__( 'Categories', 'formidable' ) : $tax->labels->name,
556 '</a>'
557 );
558 unset( $tax );
559
560 return $link;
561 }
562
563 public static function value_meets_condition( $observed_value, $cond, $hide_opt ) {
564 $hide_opt = self::get_value_for_comparision( $hide_opt );
565 $observed_value = self::get_value_for_comparision( $observed_value );
566
567 if ( is_array( $observed_value ) ) {
568 return self::array_value_condition( $observed_value, $cond, $hide_opt );
569 }
570
571 $m = false;
572 if ( $cond == '==' ) {
573 $m = $observed_value == $hide_opt;
574 } elseif ( $cond == '!=' ) {
575 $m = $observed_value != $hide_opt;
576 } elseif ( $cond == '>' ) {
577 $m = $observed_value > $hide_opt;
578 } elseif ( $cond == '>=' ) {
579 $m = $observed_value >= $hide_opt;
580 } elseif ( $cond == '<' ) {
581 $m = $observed_value < $hide_opt;
582 } elseif ( $cond == '<=' ) {
583 $m = $observed_value <= $hide_opt;
584 } elseif ( $cond == 'LIKE' || $cond == 'not LIKE' ) {
585 $m = stripos( $observed_value, $hide_opt );
586 if ( $cond == 'not LIKE' ) {
587 $m = ( $m === false ) ? true : false;
588 } else {
589 $m = ( $m === false ) ? false : true;
590 }
591 }
592
593 return $m;
594 }
595
596 /**
597 * Trim and sanitize the values
598 *
599 * @since 2.05
600 */
601 private static function get_value_for_comparision( $value ) {
602 // Remove white space from hide_opt
603 if ( ! is_array( $value ) ) {
604 $value = trim( $value );
605 }
606
607 FrmAppHelper::sanitize_value( 'wp_kses_post', $value );
608
609 return $value;
610 }
611
612 public static function array_value_condition( $observed_value, $cond, $hide_opt ) {
613 $m = false;
614 if ( $cond == '==' ) {
615 if ( is_array( $hide_opt ) ) {
616 $m = array_intersect( $hide_opt, $observed_value );
617 $m = empty( $m ) ? false : true;
618 } else {
619 $m = in_array( $hide_opt, $observed_value );
620 }
621 } elseif ( $cond == '!=' ) {
622 $m = ! in_array( $hide_opt, $observed_value );
623 } elseif ( $cond == '>' ) {
624 $min = min( $observed_value );
625 $m = $min > $hide_opt;
626 } elseif ( $cond == '<' ) {
627 $max = max( $observed_value );
628 $m = $max < $hide_opt;
629 } elseif ( $cond == 'LIKE' || $cond == 'not LIKE' ) {
630 foreach ( $observed_value as $ob ) {
631 $m = strpos( $ob, $hide_opt );
632 if ( $m !== false ) {
633 $m = true;
634 break;
635 }
636 }
637
638 if ( $cond == 'not LIKE' ) {
639 $m = ( $m === false ) ? true : false;
640 }
641 }
642
643 return $m;
644 }
645
646 /**
647 * Replace a few basic shortcodes and field ids
648 *
649 * @since 2.0
650 * @return string
651 */
652 public static function basic_replace_shortcodes( $value, $form, $entry ) {
653 if ( strpos( $value, '[sitename]' ) !== false ) {
654 $new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
655 $value = str_replace( '[sitename]', $new_value, $value );
656 }
657
658 $value = apply_filters( 'frm_content', $value, $form, $entry );
659 $value = do_shortcode( $value );
660
661 return $value;
662 }
663
664 public static function get_shortcodes( $content, $form_id ) {
665 if ( FrmAppHelper::pro_is_installed() ) {
666 return FrmProDisplaysHelper::get_shortcodes( $content, $form_id );
667 }
668
669 $fields = FrmField::getAll(
670 array(
671 'fi.form_id' => (int) $form_id,
672 'fi.type not' => FrmField::no_save_fields(),
673 )
674 );
675
676 $tagregexp = self::allowed_shortcodes( $fields );
677
678 preg_match_all( "/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER );
679
680 return $matches;
681 }
682
683 public static function allowed_shortcodes( $fields = array() ) {
684 $tagregexp = array(
685 'editlink',
686 'id',
687 'key',
688 'ip',
689 'siteurl',
690 'sitename',
691 'admin_email',
692 'post[-|_]id',
693 'created[-|_]at',
694 'updated[-|_]at',
695 'updated[-|_]by',
696 'parent[-|_]id',
697 );
698
699 foreach ( $fields as $field ) {
700 $tagregexp[] = $field->id;
701 $tagregexp[] = $field->field_key;
702 }
703
704 $tagregexp = implode( '|', $tagregexp );
705
706 return $tagregexp;
707 }
708
709 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
710 foreach ( $shortcodes[0] as $short_key => $tag ) {
711 if ( empty( $tag ) ) {
712 continue;
713 }
714
715 $atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[3][ $short_key ] );
716 $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key );
717
718 $atts['entry'] = $entry;
719 $atts['tag'] = $tag;
720 $replace_with = self::get_value_for_shortcode( $atts );
721
722 if ( $replace_with !== null ) {
723 self::sanitize_embedded_shortcodes( compact( 'entry' ), $replace_with );
724 $content = str_replace( $shortcodes[0][ $short_key ], $replace_with, $content );
725 }
726
727 unset( $atts, $replace_with );
728 }
729
730 return $content;
731 }
732
733 /**
734 * Prevent shortcodes in fields from being processed
735 *
736 * @since 3.01.02
737 *
738 * @param array $atts - includes entry object
739 * @param string $value
740 */
741 public static function sanitize_embedded_shortcodes( $atts, &$value ) {
742 $atts['value'] = $value;
743 $should_sanitize = apply_filters( 'frm_sanitize_shortcodes', true, $atts );
744 if ( $should_sanitize ) {
745 $value = str_replace( '[', '&#91;', $value );
746 }
747 }
748
749 /**
750 * @since 3.0
751 *
752 * @param $atts
753 *
754 * @return string
755 */
756 private static function get_value_for_shortcode( $atts ) {
757 $clean_tag = str_replace( '-', '_', $atts['tag'] );
758
759 $shortcode_values = array(
760 'id' => $atts['entry']->id,
761 'key' => $atts['entry']->item_key,
762 'ip' => $atts['entry']->ip,
763 );
764
765 $dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get' );
766
767 if ( isset( $shortcode_values[ $atts['tag'] ] ) ) {
768 $replace_with = $shortcode_values[ $atts['tag'] ];
769 } elseif ( in_array( $atts['tag'], $dynamic_default ) ) {
770 $replace_with = self::dynamic_default_values( $atts['tag'], $atts );
771 } elseif ( $clean_tag == 'user_agent' ) {
772 $description = $atts['entry']->description;
773 $replace_with = FrmEntriesHelper::get_browser( $description['browser'] );
774 } elseif ( $clean_tag == 'created_at' || $clean_tag == 'updated_at' ) {
775 $atts['tag'] = $clean_tag;
776 $replace_with = self::get_entry_timestamp( $atts );
777 } elseif ( $clean_tag == 'created_by' || $clean_tag == 'updated_by' ) {
778 $replace_with = self::get_display_value( $atts['entry']->{$clean_tag}, (object) array( 'type' => 'user_id' ), $atts );
779 } else {
780 $replace_with = self::get_field_shortcode_value( $atts );
781 }
782
783 return $replace_with;
784 }
785
786 /**
787 * @since 3.0
788 *
789 * @param $atts
790 *
791 * @return string
792 */
793 private static function get_entry_timestamp( $atts ) {
794 if ( isset( $atts['format'] ) ) {
795 $time_format = ' ';
796 } else {
797 $atts['format'] = get_option( 'date_format' );
798 $time_format = '';
799 }
800
801 return FrmAppHelper::get_formatted_time( $atts['entry']->{$atts['tag']}, $atts['format'], $time_format );
802 }
803
804 /**
805 * @since 3.0
806 *
807 * @param $atts
808 *
809 * @return null|string
810 */
811 private static function get_field_shortcode_value( $atts ) {
812 $field = FrmField::getOne( $atts['tag'] );
813 if ( empty( $field ) ) {
814 return null;
815 }
816
817 if ( isset( $atts['show'] ) && $atts['show'] == 'field_label' ) {
818 $replace_with = $field->name;
819 } elseif ( isset( $atts['show'] ) && $atts['show'] == 'description' ) {
820 $replace_with = $field->description;
821 } else {
822 $replace_with = FrmEntryMeta::get_meta_value( $atts['entry'], $field->id );
823 $string_value = $replace_with;
824 if ( is_array( $replace_with ) ) {
825 $sep = isset( $atts['sep'] ) ? $atts['sep'] : ', ';
826 $string_value = implode( $sep, $replace_with );
827 }
828
829 if ( empty( $string_value ) && $string_value != '0' ) {
830 $replace_with = '';
831 } else {
832 $atts['entry_id'] = $atts['entry']->id;
833 $atts['entry_key'] = $atts['entry']->item_key;
834 $replace_with = self::get_display_value( $replace_with, $field, $atts );
835 }
836 }
837
838 return $replace_with;
839 }
840
841 /**
842 * Get the value to replace a few standard shortcodes
843 *
844 * @since 2.0
845 * @return string
846 */
847 public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) {
848 $new_value = '';
849 switch ( $tag ) {
850 case 'admin_email':
851 $new_value = get_option( 'admin_email' );
852 break;
853 case 'siteurl':
854 $new_value = FrmAppHelper::site_url();
855 break;
856 case 'frmurl':
857 $new_value = FrmAppHelper::plugin_url();
858 break;
859 case 'sitename':
860 $new_value = FrmAppHelper::site_name();
861 break;
862 case 'get':
863 $new_value = self::process_get_shortcode( $atts, $return_array );
864 }
865
866 return $new_value;
867 }
868
869 /**
870 * Process the [get] shortcode
871 *
872 * @since 2.0
873 * @return string|array
874 */
875 public static function process_get_shortcode( $atts, $return_array = false ) {
876 if ( ! isset( $atts['param'] ) ) {
877 return '';
878 }
879
880 if ( strpos( $atts['param'], '&#91;' ) ) {
881 $atts['param'] = str_replace( '&#91;', '[', $atts['param'] );
882 $atts['param'] = str_replace( '&#93;', ']', $atts['param'] );
883 }
884
885 $new_value = FrmAppHelper::get_param( $atts['param'], '', 'get', 'sanitize_text_field' );
886 $new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] );
887
888 if ( $new_value == '' ) {
889 if ( ! isset( $atts['prev_val'] ) ) {
890 $atts['prev_val'] = '';
891 }
892
893 $new_value = isset( $atts['default'] ) ? $atts['default'] : $atts['prev_val'];
894 }
895
896 if ( is_array( $new_value ) && ! $return_array ) {
897 $new_value = implode( ', ', $new_value );
898 }
899
900 return $new_value;
901 }
902
903 public static function get_display_value( $value, $field, $atts = array() ) {
904
905 $value = apply_filters( 'frm_get_' . $field->type . '_display_value', $value, $field, $atts );
906 $value = apply_filters( 'frm_get_display_value', $value, $field, $atts );
907
908 $value = self::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) );
909
910 return apply_filters( 'frm_display_value', $value, $field, $atts );
911 }
912
913 /**
914 * @param $atts array Includes value, field, and atts
915 */
916 public static function get_unfiltered_display_value( $atts ) {
917 $value = $atts['value'];
918 $field = $atts['field'];
919 $atts = isset( $atts['atts'] ) ? $atts['atts'] : $atts;
920
921 if ( is_array( $field ) ) {
922 $field = $field['id'];
923 }
924
925 $field_obj = FrmFieldFactory::get_field_object( $field );
926
927 return $field_obj->get_display_value( $value, $atts );
928 }
929
930 /**
931 * Get a value from the user profile from the user ID
932 *
933 * @since 3.0
934 */
935 public static function get_user_display_name( $user_id, $user_info = 'display_name', $args = array() ) {
936 $defaults = array(
937 'blank' => false,
938 'link' => false,
939 'size' => 96,
940 );
941
942 $args = wp_parse_args( $args, $defaults );
943
944 $user = get_userdata( $user_id );
945 $info = '';
946
947 if ( $user ) {
948 if ( $user_info == 'avatar' ) {
949 $info = get_avatar( $user_id, $args['size'] );
950 } elseif ( $user_info == 'author_link' ) {
951 $info = get_author_posts_url( $user_id );
952 } else {
953 $info = isset( $user->$user_info ) ? $user->$user_info : '';
954 }
955
956 if ( 'display_name' === $user_info && empty( $info ) && ! $args['blank'] ) {
957 $info = $user->user_login;
958 }
959 }
960
961 if ( $args['link'] ) {
962 $info = '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $user_id ) ) . '">' . $info . '</a>';
963 }
964
965 return $info;
966 }
967
968 public static function get_field_types( $type ) {
969 $single_input = self::single_input_fields();
970 $multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' );
971
972 $field_selection = FrmField::all_field_selection();
973
974 $field_types = array();
975 if ( in_array( $type, $single_input ) ) {
976 self::field_types_for_input( $single_input, $field_selection, $field_types );
977 } elseif ( in_array( $type, $multiple_input ) ) {
978 self::field_types_for_input( $multiple_input, $field_selection, $field_types );
979 } elseif ( isset( $field_selection[ $type ] ) ) {
980 $field_types[ $type ] = $field_selection[ $type ];
981 }
982
983 $field_types = apply_filters( 'frm_switch_field_types', $field_types, compact( 'type' ) );
984
985 return $field_types;
986 }
987
988 /**
989 * Get a list of all fields that use a single value input.
990 *
991 * @since 4.0
992 */
993 public static function single_input_fields() {
994 $fields = array(
995 'text',
996 'textarea',
997 'rte',
998 'number',
999 'email',
1000 'url',
1001 'date',
1002 'phone',
1003 'hidden',
1004 'time',
1005 'tag',
1006 'password',
1007 );
1008 return apply_filters( 'frm_single_input_fields', $fields );
1009 }
1010
1011 private static function field_types_for_input( $inputs, $fields, &$field_types ) {
1012 foreach ( $inputs as $input ) {
1013 $field_types[ $input ] = $fields[ $input ];
1014 unset( $input );
1015 }
1016 }
1017
1018 /**
1019 * Check if current field option is an "other" option
1020 *
1021 * @since 2.0.6
1022 *
1023 * @param string $opt_key
1024 *
1025 * @return boolean Returns true if current field option is an "Other" option
1026 */
1027 public static function is_other_opt( $opt_key ) {
1028 return $opt_key && strpos( $opt_key, 'other_' ) === 0;
1029 }
1030
1031 /**
1032 * Get value that belongs in "Other" text box
1033 *
1034 * @since 2.0.6
1035 *
1036 * @param array $args
1037 */
1038 public static function get_other_val( $args ) {
1039 $defaults = array(
1040 'opt_key' => 0,
1041 'field' => array(),
1042 'parent' => false,
1043 'pointer' => false,
1044 );
1045 $args = wp_parse_args( $args, $defaults );
1046
1047 $opt_key = $args['opt_key'];
1048 $field = $args['field'];
1049 $parent = $args['parent'];
1050 $pointer = $args['pointer'];
1051 $other_val = '';
1052
1053 // If option is an "other" option and there is a value set for this field,
1054 // check if the value belongs in the current "Other" option text field
1055 if ( ! self::is_other_opt( $opt_key ) || ! FrmField::is_option_true( $field, 'value' ) ) {
1056 return $other_val;
1057 }
1058
1059 // Check posted vals before checking saved values
1060 // For fields inside repeating sections - note, don't check if $pointer is true because it will often be zero
1061 if ( $parent && isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ) {
1062 if ( FrmField::is_field_with_multiple_values( $field ) ) {
1063 $other_val = isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) ) : '';
1064 } else {
1065 $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) );
1066 }
1067
1068 return $other_val;
1069
1070 } elseif ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) {
1071 // For normal fields
1072
1073 if ( FrmField::is_field_with_multiple_values( $field ) ) {
1074 $other_val = isset( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ) : '';
1075 } else {
1076 $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ] ) );
1077 }
1078
1079 return $other_val;
1080 }
1081
1082 // For checkboxes
1083 if ( $field['type'] == 'checkbox' && is_array( $field['value'] ) ) {
1084 // Check if there is an "other" val in saved value and make sure the
1085 // "other" val is not equal to the Other checkbox option
1086 if ( isset( $field['value'][ $opt_key ] ) && $field['options'][ $opt_key ] != $field['value'][ $opt_key ] ) {
1087 $other_val = $field['value'][ $opt_key ];
1088 }
1089 } else {
1090 /**
1091 * For radio buttons and dropdowns
1092 * Check if saved value equals any of the options. If not, set it as the other value.
1093 */
1094 foreach ( $field['options'] as $opt_key => $opt_val ) {
1095 $temp_val = is_array( $opt_val ) ? $opt_val['value'] : $opt_val;
1096 // Multi-select dropdowns - key is not preserved
1097 if ( is_array( $field['value'] ) ) {
1098 $o_key = array_search( $temp_val, $field['value'] );
1099 if ( isset( $field['value'][ $o_key ] ) ) {
1100 unset( $field['value'][ $o_key ], $o_key );
1101 }
1102 } elseif ( $temp_val == $field['value'] ) {
1103 // For radio and regular dropdowns
1104 return '';
1105 } else {
1106 $other_val = $field['value'];
1107 }
1108 unset( $opt_key, $opt_val, $temp_val );
1109 }
1110 // For multi-select dropdowns only
1111 if ( is_array( $field['value'] ) && ! empty( $field['value'] ) ) {
1112 $other_val = reset( $field['value'] );
1113 }
1114 }
1115
1116 return $other_val;
1117 }
1118
1119 /**
1120 * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val.
1121 * Intended for front-end use
1122 *
1123 * @since 2.0.6
1124 *
1125 * @param array $args should include field, opt_key and field name
1126 * @param boolean $other_opt
1127 * @param string $checked
1128 *
1129 * @return array $other_args
1130 */
1131 public static function prepare_other_input( $args, &$other_opt, &$checked ) {
1132 $other_args = array(
1133 'name' => '',
1134 'value' => '',
1135 );
1136
1137 //Check if this is an "Other" option
1138 if ( ! self::is_other_opt( $args['opt_key'] ) ) {
1139 return $other_args;
1140 }
1141
1142 $other_opt = true;
1143
1144 self::set_other_name( $args, $other_args );
1145 self::set_other_value( $args, $other_args );
1146
1147 if ( '' !== $other_args['value'] ) {
1148 $checked = 'checked="checked" ';
1149 }
1150
1151 return $other_args;
1152 }
1153
1154 /**
1155 * @param array $args
1156 * @param array $other_args
1157 *
1158 * @since 2.0.6
1159 */
1160 private static function set_other_name( $args, &$other_args ) {
1161 //Set up name for other field
1162 $other_args['name'] = str_replace( '[]', '', $args['field_name'] );
1163 $other_args['name'] = preg_replace( '/\[' . $args['field']['id'] . '\]$/', '', $other_args['name'] );
1164 $other_args['name'] = $other_args['name'] . '[other][' . $args['field']['id'] . ']';
1165
1166 //Converts item_meta[field_id] => item_meta[other][field_id] and
1167 //item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id]
1168 if ( FrmField::is_field_with_multiple_values( $args['field'] ) ) {
1169 $other_args['name'] .= '[' . $args['opt_key'] . ']';
1170 }
1171 }
1172
1173 /**
1174 * Find the parent and pointer, and get text for "other" text field
1175 *
1176 * @param array $args
1177 * @param array $other_args
1178 *
1179 * @since 2.0.6
1180 */
1181 private static function set_other_value( $args, &$other_args ) {
1182 $parent = '';
1183 $pointer = '';
1184
1185 // Check for parent ID and pointer
1186 $temp_array = explode( '[', $args['field_name'] );
1187
1188 // Count should only be greater than 3 if inside of a repeating section
1189 if ( count( $temp_array ) > 3 ) {
1190 $parent = str_replace( ']', '', $temp_array[1] );
1191 $pointer = str_replace( ']', '', $temp_array[2] );
1192 }
1193
1194 // Get text for "other" text field
1195 $other_args['value'] = self::get_other_val(
1196 array(
1197 'opt_key' => $args['opt_key'],
1198 'field' => $args['field'],
1199 'parent' => $parent,
1200 'pointer' => $pointer,
1201 )
1202 );
1203 }
1204
1205 /**
1206 * If this field includes an other option, show it
1207 *
1208 * @param $args array
1209 *
1210 * @since 2.0.6
1211 */
1212 public static function include_other_input( $args ) {
1213 if ( ! $args['other_opt'] ) {
1214 return;
1215 }
1216
1217 $classes = array( 'frm_other_input' );
1218 if ( ! $args['checked'] || trim( $args['checked'] ) == '' ) {
1219 // hide the field if the other option is not selected
1220 $classes[] = 'frm_pos_none';
1221 }
1222 if ( $args['field']['type'] == 'select' && $args['field']['multiple'] ) {
1223 $classes[] = 'frm_other_full';
1224 }
1225
1226 // Set up HTML ID for Other field
1227 $other_id = self::get_other_field_html_id( $args['field']['type'], $args['html_id'], $args['opt_key'] );
1228
1229 $label = isset( $args['opt_label'] ) ? $args['opt_label'] : $args['field']['name'];
1230
1231 echo '<label for="' . esc_attr( $other_id ) . '" class="frm_screen_reader frm_hidden">' .
1232 esc_html( $label ) .
1233 '</label>' .
1234 '<input type="text" id="' . esc_attr( $other_id ) . '" class="' . esc_attr( implode( ' ', $classes ) ) . '" ' .
1235 ( $args['read_only'] ? ' readonly="readonly" disabled="disabled"' : '' ) .
1236 ' name="' . esc_attr( $args['name'] ) . '" value="' . esc_attr( $args['value'] ) . '" />';
1237 }
1238
1239 /**
1240 * Get the HTML id for an "Other" text field
1241 * Note: This does not affect fields in repeating sections
1242 *
1243 * @since 2.0.08
1244 *
1245 * @param string $type - field type
1246 * @param string $html_id
1247 * @param string|boolean $opt_key
1248 *
1249 * @return string $other_id
1250 */
1251 public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) {
1252 $other_id = $html_id;
1253
1254 // If hidden radio field, add an opt key of 0
1255 if ( $type == 'radio' && $opt_key === false ) {
1256 $opt_key = 0;
1257 }
1258
1259 if ( $opt_key !== false ) {
1260 $other_id .= '-' . $opt_key;
1261 }
1262
1263 $other_id .= '-otext';
1264
1265 return $other_id;
1266 }
1267
1268 public static function switch_field_ids( $val ) {
1269 global $frm_duplicate_ids;
1270 $replace = array();
1271 $replace_with = array();
1272 foreach ( (array) $frm_duplicate_ids as $old => $new ) {
1273 $replace[] = '[if ' . $old . ']';
1274 $replace_with[] = '[if ' . $new . ']';
1275 $replace[] = '[if ' . $old . ' ';
1276 $replace_with[] = '[if ' . $new . ' ';
1277 $replace[] = '[/if ' . $old . ']';
1278 $replace_with[] = '[/if ' . $new . ']';
1279 $replace[] = '[foreach ' . $old . ']';
1280 $replace_with[] = '[foreach ' . $new . ']';
1281 $replace[] = '[/foreach ' . $old . ']';
1282 $replace_with[] = '[/foreach ' . $new . ']';
1283 $replace[] = '[' . $old . ']';
1284 $replace_with[] = '[' . $new . ']';
1285 $replace[] = '[' . $old . ' ';
1286 $replace_with[] = '[' . $new . ' ';
1287 unset( $old, $new );
1288 }
1289 if ( is_array( $val ) ) {
1290 foreach ( $val as $k => $v ) {
1291 $val[ $k ] = str_replace( $replace, $replace_with, $v );
1292 unset( $k, $v );
1293 }
1294 } else {
1295 $val = str_replace( $replace, $replace_with, $val );
1296 }
1297
1298 return $val;
1299 }
1300
1301 /**
1302 * @since 4.0
1303 */
1304 public static function bulk_options_overlay() {
1305 $prepop = array();
1306 self::get_bulk_prefilled_opts( $prepop );
1307
1308 include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/bulk-options-overlay.php' );
1309 }
1310
1311 public static function get_us_states() {
1312 $states = array(
1313 'AL' => 'Alabama',
1314 'AK' => 'Alaska',
1315 'AR' => 'Arkansas',
1316 'AZ' => 'Arizona',
1317 'CA' => 'California',
1318 'CO' => 'Colorado',
1319 'CT' => 'Connecticut',
1320 'DE' => 'Delaware',
1321 'DC' => 'District of Columbia',
1322 'FL' => 'Florida',
1323 'GA' => 'Georgia',
1324 'HI' => 'Hawaii',
1325 'ID' => 'Idaho',
1326 'IL' => 'Illinois',
1327 'IN' => 'Indiana',
1328 'IA' => 'Iowa',
1329 'KS' => 'Kansas',
1330 'KY' => 'Kentucky',
1331 'LA' => 'Louisiana',
1332 'ME' => 'Maine',
1333 'MD' => 'Maryland',
1334 'MA' => 'Massachusetts',
1335 'MI' => 'Michigan',
1336 'MN' => 'Minnesota',
1337 'MS' => 'Mississippi',
1338 'MO' => 'Missouri',
1339 'MT' => 'Montana',
1340 'NE' => 'Nebraska',
1341 'NV' => 'Nevada',
1342 'NH' => 'New Hampshire',
1343 'NJ' => 'New Jersey',
1344 'NM' => 'New Mexico',
1345 'NY' => 'New York',
1346 'NC' => 'North Carolina',
1347 'ND' => 'North Dakota',
1348 'OH' => 'Ohio',
1349 'OK' => 'Oklahoma',
1350 'OR' => 'Oregon',
1351 'PA' => 'Pennsylvania',
1352 'RI' => 'Rhode Island',
1353 'SC' => 'South Carolina',
1354 'SD' => 'South Dakota',
1355 'TN' => 'Tennessee',
1356 'TX' => 'Texas',
1357 'UT' => 'Utah',
1358 'VT' => 'Vermont',
1359 'VA' => 'Virginia',
1360 'WA' => 'Washington',
1361 'WV' => 'West Virginia',
1362 'WI' => 'Wisconsin',
1363 'WY' => 'Wyoming',
1364 );
1365
1366 return apply_filters( 'frm_us_states', $states );
1367 }
1368
1369 public static function get_countries() {
1370 $countries = array(
1371 __( 'Afghanistan', 'formidable' ),
1372 __( 'Aland Islands', 'formidable' ),
1373 __( 'Albania', 'formidable' ),
1374 __( 'Algeria', 'formidable' ),
1375 __( 'American Samoa', 'formidable' ),
1376 __( 'Andorra', 'formidable' ),
1377 __( 'Angola', 'formidable' ),
1378 __( 'Anguilla', 'formidable' ),
1379 __( 'Antarctica', 'formidable' ),
1380 __( 'Antigua and Barbuda', 'formidable' ),
1381 __( 'Argentina', 'formidable' ),
1382 __( 'Armenia', 'formidable' ),
1383 __( 'Aruba', 'formidable' ),
1384 __( 'Australia', 'formidable' ),
1385 __( 'Austria', 'formidable' ),
1386 __( 'Azerbaijan', 'formidable' ),
1387 __( 'Bahamas', 'formidable' ),
1388 __( 'Bahrain', 'formidable' ),
1389 __( 'Bangladesh', 'formidable' ),
1390 __( 'Barbados', 'formidable' ),
1391 __( 'Belarus', 'formidable' ),
1392 __( 'Belgium', 'formidable' ),
1393 __( 'Belize', 'formidable' ),
1394 __( 'Benin', 'formidable' ),
1395 __( 'Bermuda', 'formidable' ),
1396 __( 'Bhutan', 'formidable' ),
1397 __( 'Bolivia', 'formidable' ),
1398 __( 'Bonaire, Sint Eustatius and Saba', 'formidable' ),
1399 __( 'Bosnia and Herzegovina', 'formidable' ),
1400 __( 'Botswana', 'formidable' ),
1401 __( 'Bouvet Island', 'formidable' ),
1402 __( 'Brazil', 'formidable' ),
1403 __( 'British Indian Ocean Territory', 'formidable' ),
1404 __( 'Brunei', 'formidable' ),
1405 __( 'Bulgaria', 'formidable' ),
1406 __( 'Burkina Faso', 'formidable' ),
1407 __( 'Burundi', 'formidable' ),
1408 __( 'Cambodia', 'formidable' ),
1409 __( 'Cameroon', 'formidable' ),
1410 __( 'Canada', 'formidable' ),
1411 __( 'Cape Verde', 'formidable' ),
1412 __( 'Cayman Islands', 'formidable' ),
1413 __( 'Central African Republic', 'formidable' ),
1414 __( 'Chad', 'formidable' ),
1415 __( 'Chile', 'formidable' ),
1416 __( 'China', 'formidable' ),
1417 __( 'Christmas Island', 'formidable' ),
1418 __( 'Cocos (Keeling) Islands', 'formidable' ),
1419 __( 'Colombia', 'formidable' ),
1420 __( 'Comoros', 'formidable' ),
1421 __( 'Congo', 'formidable' ),
1422 __( 'Cook Islands', 'formidable' ),
1423 __( 'Costa Rica', 'formidable' ),
1424 __( 'C&ocirc;te d\'Ivoire', 'formidable' ),
1425 __( 'Croatia', 'formidable' ),
1426 __( 'Cuba', 'formidable' ),
1427 __( 'Curacao', 'formidable' ),
1428 __( 'Cyprus', 'formidable' ),
1429 __( 'Czech Republic', 'formidable' ),
1430 __( 'Denmark', 'formidable' ),
1431 __( 'Djibouti', 'formidable' ),
1432 __( 'Dominica', 'formidable' ),
1433 __( 'Dominican Republic', 'formidable' ),
1434 __( 'East Timor', 'formidable' ),
1435 __( 'Ecuador', 'formidable' ),
1436 __( 'Egypt', 'formidable' ),
1437 __( 'El Salvador', 'formidable' ),
1438 __( 'Equatorial Guinea', 'formidable' ),
1439 __( 'Eritrea', 'formidable' ),
1440 __( 'Estonia', 'formidable' ),
1441 __( 'Ethiopia', 'formidable' ),
1442 __( 'Falkland Islands (Malvinas)', 'formidable' ),
1443 __( 'Faroe Islands', 'formidable' ),
1444 __( 'Fiji', 'formidable' ),
1445 __( 'Finland', 'formidable' ),
1446 __( 'France', 'formidable' ),
1447 __( 'French Guiana', 'formidable' ),
1448 __( 'French Polynesia', 'formidable' ),
1449 __( 'French Southern Territories', 'formidable' ),
1450 __( 'Gabon', 'formidable' ),
1451 __( 'Gambia', 'formidable' ),
1452 __( 'Georgia', 'formidable' ),
1453 __( 'Germany', 'formidable' ),
1454 __( 'Ghana', 'formidable' ),
1455 __( 'Gibraltar', 'formidable' ),
1456 __( 'Greece', 'formidable' ),
1457 __( 'Greenland', 'formidable' ),
1458 __( 'Grenada', 'formidable' ),
1459 __( 'Guadeloupe', 'formidable' ),
1460 __( 'Guam', 'formidable' ),
1461 __( 'Guatemala', 'formidable' ),
1462 __( 'Guernsey', 'formidable' ),
1463 __( 'Guinea', 'formidable' ),
1464 __( 'Guinea-Bissau', 'formidable' ),
1465 __( 'Guyana', 'formidable' ),
1466 __( 'Haiti', 'formidable' ),
1467 __( 'Heard Island and McDonald Islands', 'formidable' ),
1468 __( 'Holy See', 'formidable' ),
1469 __( 'Honduras', 'formidable' ),
1470 __( 'Hong Kong', 'formidable' ),
1471 __( 'Hungary', 'formidable' ),
1472 __( 'Iceland', 'formidable' ),
1473 __( 'India', 'formidable' ),
1474 __( 'Indonesia', 'formidable' ),
1475 __( 'Iran', 'formidable' ),
1476 __( 'Iraq', 'formidable' ),
1477 __( 'Ireland', 'formidable' ),
1478 __( 'Israel', 'formidable' ),
1479 __( 'Isle of Man', 'formidable' ),
1480 __( 'Italy', 'formidable' ),
1481 __( 'Jamaica', 'formidable' ),
1482 __( 'Japan', 'formidable' ),
1483 __( 'Jersey', 'formidable' ),
1484 __( 'Jordan', 'formidable' ),
1485 __( 'Kazakhstan', 'formidable' ),
1486 __( 'Kenya', 'formidable' ),
1487 __( 'Kiribati', 'formidable' ),
1488 __( 'North Korea', 'formidable' ),
1489 __( 'South Korea', 'formidable' ),
1490 __( 'Kosovo', 'formidable' ),
1491 __( 'Kuwait', 'formidable' ),
1492 __( 'Kyrgyzstan', 'formidable' ),
1493 __( 'Laos', 'formidable' ),
1494 __( 'Latvia', 'formidable' ),
1495 __( 'Lebanon', 'formidable' ),
1496 __( 'Lesotho', 'formidable' ),
1497 __( 'Liberia', 'formidable' ),
1498 __( 'Libya', 'formidable' ),
1499 __( 'Liechtenstein', 'formidable' ),
1500 __( 'Lithuania', 'formidable' ),
1501 __( 'Luxembourg', 'formidable' ),
1502 __( 'Macao', 'formidable' ),
1503 __( 'Macedonia', 'formidable' ),
1504 __( 'Madagascar', 'formidable' ),
1505 __( 'Malawi', 'formidable' ),
1506 __( 'Malaysia', 'formidable' ),
1507 __( 'Maldives', 'formidable' ),
1508 __( 'Mali', 'formidable' ),
1509 __( 'Malta', 'formidable' ),
1510 __( 'Marshall Islands', 'formidable' ),
1511 __( 'Martinique', 'formidable' ),
1512 __( 'Mauritania', 'formidable' ),
1513 __( 'Mauritius', 'formidable' ),
1514 __( 'Mayotte', 'formidable' ),
1515 __( 'Mexico', 'formidable' ),
1516 __( 'Micronesia', 'formidable' ),
1517 __( 'Moldova', 'formidable' ),
1518 __( 'Monaco', 'formidable' ),
1519 __( 'Mongolia', 'formidable' ),
1520 __( 'Montenegro', 'formidable' ),
1521 __( 'Montserrat', 'formidable' ),
1522 __( 'Morocco', 'formidable' ),
1523 __( 'Mozambique', 'formidable' ),
1524 __( 'Myanmar', 'formidable' ),
1525 __( 'Namibia', 'formidable' ),
1526 __( 'Nauru', 'formidable' ),
1527 __( 'Nepal', 'formidable' ),
1528 __( 'Netherlands', 'formidable' ),
1529 __( 'New Caledonia', 'formidable' ),
1530 __( 'New Zealand', 'formidable' ),
1531 __( 'Nicaragua', 'formidable' ),
1532 __( 'Niger', 'formidable' ),
1533 __( 'Nigeria', 'formidable' ),
1534 __( 'Niue', 'formidable' ),
1535 __( 'Norfolk Island', 'formidable' ),
1536 __( 'Northern Mariana Islands', 'formidable' ),
1537 __( 'Norway', 'formidable' ),
1538 __( 'Oman', 'formidable' ),
1539 __( 'Pakistan', 'formidable' ),
1540 __( 'Palau', 'formidable' ),
1541 __( 'Palestine', 'formidable' ),
1542 __( 'Panama', 'formidable' ),
1543 __( 'Papua New Guinea', 'formidable' ),
1544 __( 'Paraguay', 'formidable' ),
1545 __( 'Peru', 'formidable' ),
1546 __( 'Philippines', 'formidable' ),
1547 __( 'Pitcairn', 'formidable' ),
1548 __( 'Poland', 'formidable' ),
1549 __( 'Portugal', 'formidable' ),
1550 __( 'Puerto Rico', 'formidable' ),
1551 __( 'Qatar', 'formidable' ),
1552 __( 'Reunion', 'formidable' ),
1553 __( 'Romania', 'formidable' ),
1554 __( 'Russia', 'formidable' ),
1555 __( 'Rwanda', 'formidable' ),
1556 __( 'Saint Barthelemy', 'formidable' ),
1557 __( 'Saint Helena, Ascension and Tristan da Cunha', 'formidable' ),
1558 __( 'Saint Kitts and Nevis', 'formidable' ),
1559 __( 'Saint Lucia', 'formidable' ),
1560 __( 'Saint Martin (French part)', 'formidable' ),
1561 __( 'Saint Pierre and Miquelon', 'formidable' ),
1562 __( 'Saint Vincent and the Grenadines', 'formidable' ),
1563 __( 'Samoa', 'formidable' ),
1564 __( 'San Marino', 'formidable' ),
1565 __( 'Sao Tome and Principe', 'formidable' ),
1566 __( 'Saudi Arabia', 'formidable' ),
1567 __( 'Senegal', 'formidable' ),
1568 __( 'Serbia', 'formidable' ),
1569 __( 'Seychelles', 'formidable' ),
1570 __( 'Sierra Leone', 'formidable' ),
1571 __( 'Singapore', 'formidable' ),
1572 __( 'Sint Maarten (Dutch part)', 'formidable' ),
1573 __( 'Slovakia', 'formidable' ),
1574 __( 'Slovenia', 'formidable' ),
1575 __( 'Solomon Islands', 'formidable' ),
1576 __( 'Somalia', 'formidable' ),
1577 __( 'South Africa', 'formidable' ),
1578 __( 'South Georgia and the South Sandwich Islands', 'formidable' ),
1579 __( 'South Sudan', 'formidable' ),
1580 __( 'Spain', 'formidable' ),
1581 __( 'Sri Lanka', 'formidable' ),
1582 __( 'Sudan', 'formidable' ),
1583 __( 'Suriname', 'formidable' ),
1584 __( 'Svalbard and Jan Mayen', 'formidable' ),
1585 __( 'Swaziland', 'formidable' ),
1586 __( 'Sweden', 'formidable' ),
1587 __( 'Switzerland', 'formidable' ),
1588 __( 'Syria', 'formidable' ),
1589 __( 'Taiwan', 'formidable' ),
1590 __( 'Tajikistan', 'formidable' ),
1591 __( 'Tanzania', 'formidable' ),
1592 __( 'Thailand', 'formidable' ),
1593 __( 'Timor-Leste', 'formidable' ),
1594 __( 'Togo', 'formidable' ),
1595 __( 'Tokelau', 'formidable' ),
1596 __( 'Tonga', 'formidable' ),
1597 __( 'Trinidad and Tobago', 'formidable' ),
1598 __( 'Tunisia', 'formidable' ),
1599 __( 'Turkey', 'formidable' ),
1600 __( 'Turkmenistan', 'formidable' ),
1601 __( 'Turks and Caicos Islands', 'formidable' ),
1602 __( 'Tuvalu', 'formidable' ),
1603 __( 'Uganda', 'formidable' ),
1604 __( 'Ukraine', 'formidable' ),
1605 __( 'United Arab Emirates', 'formidable' ),
1606 __( 'United Kingdom', 'formidable' ),
1607 __( 'United States', 'formidable' ),
1608 __( 'United States Minor Outlying Islands', 'formidable' ),
1609 __( 'Uruguay', 'formidable' ),
1610 __( 'Uzbekistan', 'formidable' ),
1611 __( 'Vanuatu', 'formidable' ),
1612 __( 'Vatican City', 'formidable' ),
1613 __( 'Venezuela', 'formidable' ),
1614 __( 'Vietnam', 'formidable' ),
1615 __( 'Virgin Islands, British', 'formidable' ),
1616 __( 'Virgin Islands, U.S.', 'formidable' ),
1617 __( 'Wallis and Futuna', 'formidable' ),
1618 __( 'Western Sahara', 'formidable' ),
1619 __( 'Yemen', 'formidable' ),
1620 __( 'Zambia', 'formidable' ),
1621 __( 'Zimbabwe', 'formidable' ),
1622 );
1623
1624 sort( $countries, SORT_LOCALE_STRING );
1625 return apply_filters( 'frm_countries', $countries );
1626 }
1627
1628 public static function get_bulk_prefilled_opts( array &$prepop ) {
1629 $prepop[ __( 'Countries', 'formidable' ) ] = self::get_countries();
1630
1631 $states = self::get_us_states();
1632 $state_abv = array_keys( $states );
1633 sort( $state_abv );
1634 $prepop[ __( 'U.S. State Abbreviations', 'formidable' ) ] = $state_abv;
1635
1636 $states = array_values( $states );
1637 sort( $states );
1638 $prepop[ __( 'U.S. States', 'formidable' ) ] = $states;
1639 unset( $state_abv, $states );
1640
1641 $prepop[ __( 'Age', 'formidable' ) ] = array(
1642 __( 'Under 18', 'formidable' ),
1643 __( '18-24', 'formidable' ),
1644 __( '25-34', 'formidable' ),
1645 __( '35-44', 'formidable' ),
1646 __( '45-54', 'formidable' ),
1647 __( '55-64', 'formidable' ),
1648 __( '65 or Above', 'formidable' ),
1649 __( 'Prefer Not to Answer', 'formidable' ),
1650 );
1651
1652 $prepop[ __( 'Satisfaction', 'formidable' ) ] = array(
1653 __( 'Very Satisfied', 'formidable' ),
1654 __( 'Satisfied', 'formidable' ),
1655 __( 'Neutral', 'formidable' ),
1656 __( 'Unsatisfied', 'formidable' ),
1657 __( 'Very Unsatisfied', 'formidable' ),
1658 __( 'N/A', 'formidable' ),
1659 );
1660
1661 $prepop[ __( 'Importance', 'formidable' ) ] = array(
1662 __( 'Very Important', 'formidable' ),
1663 __( 'Important', 'formidable' ),
1664 __( 'Neutral', 'formidable' ),
1665 __( 'Somewhat Important', 'formidable' ),
1666 __( 'Not at all Important', 'formidable' ),
1667 __( 'N/A', 'formidable' ),
1668 );
1669
1670 $prepop[ __( 'Agreement', 'formidable' ) ] = array(
1671 __( 'Strongly Agree', 'formidable' ),
1672 __( 'Agree', 'formidable' ),
1673 __( 'Neutral', 'formidable' ),
1674 __( 'Disagree', 'formidable' ),
1675 __( 'Strongly Disagree', 'formidable' ),
1676 __( 'N/A', 'formidable' ),
1677 );
1678
1679 $prepop = apply_filters( 'frm_bulk_field_choices', $prepop );
1680 }
1681
1682 /**
1683 * Display a field value selector
1684 *
1685 * @since 2.03.05
1686 *
1687 * @param int $selector_field_id
1688 * @param array $selector_args
1689 */
1690 public static function display_field_value_selector( $selector_field_id, $selector_args ) {
1691 $field_value_selector = FrmFieldFactory::create_field_value_selector( $selector_field_id, $selector_args );
1692 $field_value_selector->display();
1693 }
1694
1695 /**
1696 * Convert a field object to a flat array
1697 *
1698 * @since 2.03.05
1699 *
1700 * @param object $field
1701 *
1702 * @return array
1703 */
1704 public static function convert_field_object_to_flat_array( $field ) {
1705 $field_options = $field->field_options;
1706 $field_array = get_object_vars( $field );
1707 unset( $field_array['field_options'] );
1708
1709 return $field_array + $field_options;
1710 }
1711
1712 /**
1713 * @since 4.04
1714 */
1715 public static function show_add_field_buttons( $args ) {
1716 $field_key = $args['field_key'];
1717 $field_type = $args['field_type'];
1718 $field_label = FrmAppHelper::icon_by_class( FrmFormsHelper::get_field_link_icon( $field_type ), array( 'echo' => false ) );
1719 $field_name = FrmFormsHelper::get_field_link_name( $field_type );
1720 $field_label .= ' <span>' . $field_name . '</span>';
1721
1722 /* translators: %s: Field name */
1723 $upgrade_label = sprintf( esc_html__( '%s fields', 'formidable' ), $field_name );
1724
1725 // If the individual field isn't allowed, disable it.
1726 $run_filter = true;
1727 $single_no_allow = ' ';
1728 $install_data = '';
1729 $requires = '';
1730 $upgrade_message = '';
1731 $link = isset( $field_type['link'] ) ? esc_url_raw( $field_type['link'] ) : '';
1732 if ( strpos( $field_type['icon'], ' frm_show_upgrade' ) ) {
1733 $single_no_allow .= 'frm_show_upgrade';
1734 $field_type['icon'] = str_replace( ' frm_show_upgrade', '', $field_type['icon'] );
1735 $run_filter = false;
1736 if ( isset( $field_type['addon'] ) ) {
1737 $upgrading = FrmAddonsController::install_link( $field_type['addon'] );
1738 if ( isset( $upgrading['url'] ) ) {
1739 $install_data = json_encode( $upgrading );
1740 }
1741 $requires = FrmFormsHelper::get_plan_required( $upgrading );
1742 } elseif ( isset( $field_type['require'] ) ) {
1743 $requires = $field_type['require'];
1744 }
1745 }
1746
1747 if ( isset( $field_type['message'] ) ) {
1748 $upgrade_message = FrmAppHelper::kses( $field_type['message'], array( 'a', 'img' ) );
1749 }
1750
1751 ?>
1752 <li class="frmbutton <?php echo esc_attr( $args['no_allow_class'] . $single_no_allow . ' frm_t' . str_replace( '|', '-', $field_key ) ); ?>" id="<?php echo esc_attr( $field_key ); ?>" data-upgrade="<?php echo esc_attr( $upgrade_label ); ?>" data-message="<?php echo esc_attr( $upgrade_message ); ?>" data-link="<?php echo esc_attr( $link ); ?>" data-medium="builder" data-oneclick="<?php echo esc_attr( $install_data ); ?>" data-content="<?php echo esc_attr( $field_key ); ?>" data-requires="<?php echo esc_attr( $requires ); ?>">
1753 <?php
1754 if ( $run_filter ) {
1755 $field_label = apply_filters( 'frmpro_field_links', $field_label, $args['id'], $field_key );
1756 }
1757 echo FrmAppHelper::kses( $field_label, array( 'a', 'i', 'span', 'use', 'svg' ) ); // WPCS: XSS ok.
1758 ?>
1759 </li>
1760 <?php
1761 }
1762
1763 /**
1764 * @deprecated 4.0
1765 */
1766 public static function show_icon_link_js( $atts ) {
1767 _deprecated_function( __METHOD__, '4.0' );
1768 $atts['icon'] .= $atts['is_selected'] ? ' ' : ' frm_inactive_icon ';
1769 if ( isset( $atts['has_default'] ) && ! $atts['has_default'] ) {
1770 $atts['icon'] .= 'frm_hidden ';
1771 }
1772 echo '<a href="javascript:void(0)" class="frm_bstooltip ' . esc_attr( $atts['icon'] ) . 'frm_default_val_icons frm_action_icon frm_icon_font" title="' . esc_attr( $atts['message'] ) . '"></a>';
1773 }
1774
1775 /**
1776 * @deprecated 4.0
1777 */
1778 public static function show_default_blank_js( $is_selected, $has_default_value = true ) {
1779 _deprecated_function( __METHOD__, '4.0' );
1780 }
1781
1782 /**
1783 * @deprecated 4.0
1784 */
1785 public static function clear_on_focus_html( $field, $display, $id = '' ) {
1786 _deprecated_function( __METHOD__, '4.0' );
1787 }
1788
1789 /**
1790 * @deprecated 4.0
1791 */
1792 public static function show_onfocus_js( $is_selected, $has_default_value = true ) {
1793 _deprecated_function( __METHOD__, '4.0' );
1794 }
1795
1796 /**
1797 * @deprecated 3.0
1798 * @codeCoverageIgnore
1799 */
1800 public static function display_recaptcha() {
1801 _deprecated_function( __FUNCTION__, '3.0', 'FrmFieldCaptcha::field_input' );
1802 }
1803
1804 /**
1805 * @deprecated 3.0
1806 * @codeCoverageIgnore
1807 */
1808 public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) {
1809 FrmDeprecated::remove_inline_conditions( $no_vars, $code, $replace_with, $html );
1810 }
1811
1812 /**
1813 * @deprecated 3.0
1814 * @codeCoverageIgnore
1815 */
1816 public static function get_shortcode_tag( $shortcodes, $short_key, $args ) {
1817 return FrmDeprecated::get_shortcode_tag( $shortcodes, $short_key, $args );
1818 }
1819
1820 /**
1821 * @deprecated 3.0
1822 * @codeCoverageIgnore
1823 *
1824 * @param string $html
1825 * @param array $field
1826 * @param array $errors
1827 * @param object $form
1828 * @param array $args
1829 *
1830 * @return string
1831 */
1832 public static function replace_shortcodes( $html, $field, $errors = array(), $form = false, $args = array() ) {
1833 return FrmDeprecated::replace_shortcodes( $html, $field, $errors, $form, $args );
1834 }
1835
1836 /**
1837 * @deprecated 3.0
1838 * @codeCoverageIgnore
1839 */
1840 public static function get_default_field_opts( $type, $field = null, $limit = false ) {
1841 return FrmDeprecated::get_default_field_opts( $type, $field, $limit );
1842 }
1843
1844 /**
1845 * @deprecated 2.02.07
1846 * @codeCoverageIgnore
1847 */
1848 public static function dropdown_categories( $args ) {
1849 return FrmDeprecated::dropdown_categories( $args );
1850 }
1851 }
1852