PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.05.02
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.05.02
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.05.02, at classes/helpers/FrmFieldsHelper.php

1,851 lines 54.7 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 return self::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) );
909 }
910
911 /**
912 * @param $atts array Includes value, field, and atts
913 */
914 public static function get_unfiltered_display_value( $atts ) {
915 $value = $atts['value'];
916 $field = $atts['field'];
917 $atts = isset( $atts['atts'] ) ? $atts['atts'] : $atts;
918
919 if ( is_array( $field ) ) {
920 $field = $field['id'];
921 }
922
923 $field_obj = FrmFieldFactory::get_field_object( $field );
924
925 return $field_obj->get_display_value( $value, $atts );
926 }
927
928 /**
929 * Get a value from the user profile from the user ID
930 *
931 * @since 3.0
932 */
933 public static function get_user_display_name( $user_id, $user_info = 'display_name', $args = array() ) {
934 $defaults = array(
935 'blank' => false,
936 'link' => false,
937 'size' => 96,
938 );
939
940 $args = wp_parse_args( $args, $defaults );
941
942 $user = get_userdata( $user_id );
943 $info = '';
944
945 if ( $user ) {
946 if ( $user_info == 'avatar' ) {
947 $info = get_avatar( $user_id, $args['size'] );
948 } elseif ( $user_info == 'author_link' ) {
949 $info = get_author_posts_url( $user_id );
950 } else {
951 $info = isset( $user->$user_info ) ? $user->$user_info : '';
952 }
953
954 if ( 'display_name' === $user_info && empty( $info ) && ! $args['blank'] ) {
955 $info = $user->user_login;
956 }
957 }
958
959 if ( $args['link'] ) {
960 $info = '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $user_id ) ) . '">' . $info . '</a>';
961 }
962
963 return $info;
964 }
965
966 public static function get_field_types( $type ) {
967 $single_input = self::single_input_fields();
968 $multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' );
969
970 $field_selection = FrmField::all_field_selection();
971
972 $field_types = array();
973 if ( in_array( $type, $single_input ) ) {
974 self::field_types_for_input( $single_input, $field_selection, $field_types );
975 } elseif ( in_array( $type, $multiple_input ) ) {
976 self::field_types_for_input( $multiple_input, $field_selection, $field_types );
977 } elseif ( isset( $field_selection[ $type ] ) ) {
978 $field_types[ $type ] = $field_selection[ $type ];
979 }
980
981 $field_types = apply_filters( 'frm_switch_field_types', $field_types, compact( 'type' ) );
982
983 return $field_types;
984 }
985
986 /**
987 * Get a list of all fields that use a single value input.
988 *
989 * @since 4.0
990 */
991 public static function single_input_fields() {
992 $fields = array(
993 'text',
994 'textarea',
995 'rte',
996 'number',
997 'email',
998 'url',
999 'date',
1000 'phone',
1001 'hidden',
1002 'time',
1003 'tag',
1004 'password',
1005 );
1006 return apply_filters( 'frm_single_input_fields', $fields );
1007 }
1008
1009 private static function field_types_for_input( $inputs, $fields, &$field_types ) {
1010 foreach ( $inputs as $input ) {
1011 $field_types[ $input ] = $fields[ $input ];
1012 unset( $input );
1013 }
1014 }
1015
1016 /**
1017 * Check if current field option is an "other" option
1018 *
1019 * @since 2.0.6
1020 *
1021 * @param string $opt_key
1022 *
1023 * @return boolean Returns true if current field option is an "Other" option
1024 */
1025 public static function is_other_opt( $opt_key ) {
1026 return $opt_key && strpos( $opt_key, 'other_' ) === 0;
1027 }
1028
1029 /**
1030 * Get value that belongs in "Other" text box
1031 *
1032 * @since 2.0.6
1033 *
1034 * @param array $args
1035 */
1036 public static function get_other_val( $args ) {
1037 $defaults = array(
1038 'opt_key' => 0,
1039 'field' => array(),
1040 'parent' => false,
1041 'pointer' => false,
1042 );
1043 $args = wp_parse_args( $args, $defaults );
1044
1045 $opt_key = $args['opt_key'];
1046 $field = $args['field'];
1047 $parent = $args['parent'];
1048 $pointer = $args['pointer'];
1049 $other_val = '';
1050
1051 // If option is an "other" option and there is a value set for this field,
1052 // check if the value belongs in the current "Other" option text field
1053 if ( ! self::is_other_opt( $opt_key ) || ! FrmField::is_option_true( $field, 'value' ) ) {
1054 return $other_val;
1055 }
1056
1057 // Check posted vals before checking saved values
1058
1059 // For fields inside repeating sections - note, don't check if $pointer is true because it will often be zero
1060 if ( $parent && isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ) {
1061 if ( FrmField::is_field_with_multiple_values( $field ) ) {
1062 $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 ] ) ) : '';
1063 } else {
1064 $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) );
1065 }
1066
1067 return $other_val;
1068
1069 } elseif ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) {
1070 // For normal fields
1071
1072 if ( FrmField::is_field_with_multiple_values( $field ) ) {
1073 $other_val = isset( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ) : '';
1074 } else {
1075 $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ] ) );
1076 }
1077
1078 return $other_val;
1079 }
1080
1081 // For checkboxes
1082 if ( $field['type'] == 'checkbox' && is_array( $field['value'] ) ) {
1083 // Check if there is an "other" val in saved value and make sure the
1084 // "other" val is not equal to the Other checkbox option
1085 if ( isset( $field['value'][ $opt_key ] ) && $field['options'][ $opt_key ] != $field['value'][ $opt_key ] ) {
1086 $other_val = $field['value'][ $opt_key ];
1087 }
1088 } else {
1089 /**
1090 * For radio buttons and dropdowns
1091 * Check if saved value equals any of the options. If not, set it as the other value.
1092 */
1093 foreach ( $field['options'] as $opt_key => $opt_val ) {
1094 $temp_val = is_array( $opt_val ) ? $opt_val['value'] : $opt_val;
1095 // Multi-select dropdowns - key is not preserved
1096 if ( is_array( $field['value'] ) ) {
1097 $o_key = array_search( $temp_val, $field['value'] );
1098 if ( isset( $field['value'][ $o_key ] ) ) {
1099 unset( $field['value'][ $o_key ], $o_key );
1100 }
1101 } elseif ( $temp_val == $field['value'] ) {
1102 // For radio and regular dropdowns
1103 return '';
1104 } else {
1105 $other_val = $field['value'];
1106 }
1107 unset( $opt_key, $opt_val, $temp_val );
1108 }
1109 // For multi-select dropdowns only
1110 if ( is_array( $field['value'] ) && ! empty( $field['value'] ) ) {
1111 $other_val = reset( $field['value'] );
1112 }
1113 }
1114
1115 return $other_val;
1116 }
1117
1118 /**
1119 * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val.
1120 * Intended for front-end use
1121 *
1122 * @since 2.0.6
1123 *
1124 * @param array $args should include field, opt_key and field name
1125 * @param boolean $other_opt
1126 * @param string $checked
1127 *
1128 * @return array $other_args
1129 */
1130 public static function prepare_other_input( $args, &$other_opt, &$checked ) {
1131 $other_args = array(
1132 'name' => '',
1133 'value' => '',
1134 );
1135
1136 //Check if this is an "Other" option
1137 if ( ! self::is_other_opt( $args['opt_key'] ) ) {
1138 return $other_args;
1139 }
1140
1141 $other_opt = true;
1142
1143 self::set_other_name( $args, $other_args );
1144 self::set_other_value( $args, $other_args );
1145
1146 if ( '' !== $other_args['value'] ) {
1147 $checked = 'checked="checked" ';
1148 }
1149
1150 return $other_args;
1151 }
1152
1153 /**
1154 * @param array $args
1155 * @param array $other_args
1156 *
1157 * @since 2.0.6
1158 */
1159 private static function set_other_name( $args, &$other_args ) {
1160 //Set up name for other field
1161 $other_args['name'] = str_replace( '[]', '', $args['field_name'] );
1162 $other_args['name'] = preg_replace( '/\[' . $args['field']['id'] . '\]$/', '', $other_args['name'] );
1163 $other_args['name'] = $other_args['name'] . '[other][' . $args['field']['id'] . ']';
1164
1165 //Converts item_meta[field_id] => item_meta[other][field_id] and
1166 //item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id]
1167 if ( FrmField::is_field_with_multiple_values( $args['field'] ) ) {
1168 $other_args['name'] .= '[' . $args['opt_key'] . ']';
1169 }
1170 }
1171
1172 /**
1173 * Find the parent and pointer, and get text for "other" text field
1174 *
1175 * @param array $args
1176 * @param array $other_args
1177 *
1178 * @since 2.0.6
1179 */
1180 private static function set_other_value( $args, &$other_args ) {
1181 $parent = '';
1182 $pointer = '';
1183
1184 // Check for parent ID and pointer
1185 $temp_array = explode( '[', $args['field_name'] );
1186
1187 // Count should only be greater than 3 if inside of a repeating section
1188 if ( count( $temp_array ) > 3 ) {
1189 $parent = str_replace( ']', '', $temp_array[1] );
1190 $pointer = str_replace( ']', '', $temp_array[2] );
1191 }
1192
1193 // Get text for "other" text field
1194 $other_args['value'] = self::get_other_val(
1195 array(
1196 'opt_key' => $args['opt_key'],
1197 'field' => $args['field'],
1198 'parent' => $parent,
1199 'pointer' => $pointer,
1200 )
1201 );
1202 }
1203
1204 /**
1205 * If this field includes an other option, show it
1206 *
1207 * @param $args array
1208 *
1209 * @since 2.0.6
1210 */
1211 public static function include_other_input( $args ) {
1212 if ( ! $args['other_opt'] ) {
1213 return;
1214 }
1215
1216 $classes = array( 'frm_other_input' );
1217 if ( ! $args['checked'] || trim( $args['checked'] ) == '' ) {
1218 // hide the field if the other option is not selected
1219 $classes[] = 'frm_pos_none';
1220 }
1221 if ( $args['field']['type'] == 'select' && $args['field']['multiple'] ) {
1222 $classes[] = 'frm_other_full';
1223 }
1224
1225 // Set up HTML ID for Other field
1226 $other_id = self::get_other_field_html_id( $args['field']['type'], $args['html_id'], $args['opt_key'] );
1227
1228 $label = isset( $args['opt_label'] ) ? $args['opt_label'] : $args['field']['name'];
1229
1230 echo '<label for="' . esc_attr( $other_id ) . '" class="frm_screen_reader frm_hidden">' .
1231 esc_html( $label ) .
1232 '</label>' .
1233 '<input type="text" id="' . esc_attr( $other_id ) . '" class="' . esc_attr( implode( ' ', $classes ) ) . '" ' .
1234 ( $args['read_only'] ? ' readonly="readonly" disabled="disabled"' : '' ) .
1235 ' name="' . esc_attr( $args['name'] ) . '" value="' . esc_attr( $args['value'] ) . '" />';
1236 }
1237
1238 /**
1239 * Get the HTML id for an "Other" text field
1240 * Note: This does not affect fields in repeating sections
1241 *
1242 * @since 2.0.08
1243 *
1244 * @param string $type - field type
1245 * @param string $html_id
1246 * @param string|boolean $opt_key
1247 *
1248 * @return string $other_id
1249 */
1250 public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) {
1251 $other_id = $html_id;
1252
1253 // If hidden radio field, add an opt key of 0
1254 if ( $type == 'radio' && $opt_key === false ) {
1255 $opt_key = 0;
1256 }
1257
1258 if ( $opt_key !== false ) {
1259 $other_id .= '-' . $opt_key;
1260 }
1261
1262 $other_id .= '-otext';
1263
1264 return $other_id;
1265 }
1266
1267 public static function switch_field_ids( $val ) {
1268 global $frm_duplicate_ids;
1269 $replace = array();
1270 $replace_with = array();
1271 foreach ( (array) $frm_duplicate_ids as $old => $new ) {
1272 $replace[] = '[if ' . $old . ']';
1273 $replace_with[] = '[if ' . $new . ']';
1274 $replace[] = '[if ' . $old . ' ';
1275 $replace_with[] = '[if ' . $new . ' ';
1276 $replace[] = '[/if ' . $old . ']';
1277 $replace_with[] = '[/if ' . $new . ']';
1278 $replace[] = '[foreach ' . $old . ']';
1279 $replace_with[] = '[foreach ' . $new . ']';
1280 $replace[] = '[/foreach ' . $old . ']';
1281 $replace_with[] = '[/foreach ' . $new . ']';
1282 $replace[] = '[' . $old . ']';
1283 $replace_with[] = '[' . $new . ']';
1284 $replace[] = '[' . $old . ' ';
1285 $replace_with[] = '[' . $new . ' ';
1286 unset( $old, $new );
1287 }
1288 if ( is_array( $val ) ) {
1289 foreach ( $val as $k => $v ) {
1290 $val[ $k ] = str_replace( $replace, $replace_with, $v );
1291 unset( $k, $v );
1292 }
1293 } else {
1294 $val = str_replace( $replace, $replace_with, $val );
1295 }
1296
1297 return $val;
1298 }
1299
1300 /**
1301 * @since 4.0
1302 */
1303 public static function bulk_options_overlay() {
1304 $prepop = array();
1305 self::get_bulk_prefilled_opts( $prepop );
1306
1307 include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/bulk-options-overlay.php' );
1308 }
1309
1310 public static function get_us_states() {
1311 $states = array(
1312 'AL' => 'Alabama',
1313 'AK' => 'Alaska',
1314 'AR' => 'Arkansas',
1315 'AZ' => 'Arizona',
1316 'CA' => 'California',
1317 'CO' => 'Colorado',
1318 'CT' => 'Connecticut',
1319 'DE' => 'Delaware',
1320 'DC' => 'District of Columbia',
1321 'FL' => 'Florida',
1322 'GA' => 'Georgia',
1323 'HI' => 'Hawaii',
1324 'ID' => 'Idaho',
1325 'IL' => 'Illinois',
1326 'IN' => 'Indiana',
1327 'IA' => 'Iowa',
1328 'KS' => 'Kansas',
1329 'KY' => 'Kentucky',
1330 'LA' => 'Louisiana',
1331 'ME' => 'Maine',
1332 'MD' => 'Maryland',
1333 'MA' => 'Massachusetts',
1334 'MI' => 'Michigan',
1335 'MN' => 'Minnesota',
1336 'MS' => 'Mississippi',
1337 'MO' => 'Missouri',
1338 'MT' => 'Montana',
1339 'NE' => 'Nebraska',
1340 'NV' => 'Nevada',
1341 'NH' => 'New Hampshire',
1342 'NJ' => 'New Jersey',
1343 'NM' => 'New Mexico',
1344 'NY' => 'New York',
1345 'NC' => 'North Carolina',
1346 'ND' => 'North Dakota',
1347 'OH' => 'Ohio',
1348 'OK' => 'Oklahoma',
1349 'OR' => 'Oregon',
1350 'PA' => 'Pennsylvania',
1351 'RI' => 'Rhode Island',
1352 'SC' => 'South Carolina',
1353 'SD' => 'South Dakota',
1354 'TN' => 'Tennessee',
1355 'TX' => 'Texas',
1356 'UT' => 'Utah',
1357 'VT' => 'Vermont',
1358 'VA' => 'Virginia',
1359 'WA' => 'Washington',
1360 'WV' => 'West Virginia',
1361 'WI' => 'Wisconsin',
1362 'WY' => 'Wyoming',
1363 );
1364
1365 return apply_filters( 'frm_us_states', $states );
1366 }
1367
1368 public static function get_countries() {
1369 $countries = array(
1370 __( 'Afghanistan', 'formidable' ),
1371 __( 'Aland Islands', 'formidable' ),
1372 __( 'Albania', 'formidable' ),
1373 __( 'Algeria', 'formidable' ),
1374 __( 'American Samoa', 'formidable' ),
1375 __( 'Andorra', 'formidable' ),
1376 __( 'Angola', 'formidable' ),
1377 __( 'Anguilla', 'formidable' ),
1378 __( 'Antarctica', 'formidable' ),
1379 __( 'Antigua and Barbuda', 'formidable' ),
1380 __( 'Argentina', 'formidable' ),
1381 __( 'Armenia', 'formidable' ),
1382 __( 'Aruba', 'formidable' ),
1383 __( 'Australia', 'formidable' ),
1384 __( 'Austria', 'formidable' ),
1385 __( 'Azerbaijan', 'formidable' ),
1386 __( 'Bahamas', 'formidable' ),
1387 __( 'Bahrain', 'formidable' ),
1388 __( 'Bangladesh', 'formidable' ),
1389 __( 'Barbados', 'formidable' ),
1390 __( 'Belarus', 'formidable' ),
1391 __( 'Belgium', 'formidable' ),
1392 __( 'Belize', 'formidable' ),
1393 __( 'Benin', 'formidable' ),
1394 __( 'Bermuda', 'formidable' ),
1395 __( 'Bhutan', 'formidable' ),
1396 __( 'Bolivia', 'formidable' ),
1397 __( 'Bonaire, Sint Eustatius and Saba', 'formidable' ),
1398 __( 'Bosnia and Herzegovina', 'formidable' ),
1399 __( 'Botswana', 'formidable' ),
1400 __( 'Bouvet Island', 'formidable' ),
1401 __( 'Brazil', 'formidable' ),
1402 __( 'British Indian Ocean Territory', 'formidable' ),
1403 __( 'Brunei', 'formidable' ),
1404 __( 'Bulgaria', 'formidable' ),
1405 __( 'Burkina Faso', 'formidable' ),
1406 __( 'Burundi', 'formidable' ),
1407 __( 'Cambodia', 'formidable' ),
1408 __( 'Cameroon', 'formidable' ),
1409 __( 'Canada', 'formidable' ),
1410 __( 'Cape Verde', 'formidable' ),
1411 __( 'Cayman Islands', 'formidable' ),
1412 __( 'Central African Republic', 'formidable' ),
1413 __( 'Chad', 'formidable' ),
1414 __( 'Chile', 'formidable' ),
1415 __( 'China', 'formidable' ),
1416 __( 'Christmas Island', 'formidable' ),
1417 __( 'Cocos (Keeling) Islands', 'formidable' ),
1418 __( 'Colombia', 'formidable' ),
1419 __( 'Comoros', 'formidable' ),
1420 __( 'Congo', 'formidable' ),
1421 __( 'Cook Islands', 'formidable' ),
1422 __( 'Costa Rica', 'formidable' ),
1423 __( 'C&ocirc;te d\'Ivoire', 'formidable' ),
1424 __( 'Croatia', 'formidable' ),
1425 __( 'Cuba', 'formidable' ),
1426 __( 'Curacao', 'formidable' ),
1427 __( 'Cyprus', 'formidable' ),
1428 __( 'Czech Republic', 'formidable' ),
1429 __( 'Denmark', 'formidable' ),
1430 __( 'Djibouti', 'formidable' ),
1431 __( 'Dominica', 'formidable' ),
1432 __( 'Dominican Republic', 'formidable' ),
1433 __( 'East Timor', 'formidable' ),
1434 __( 'Ecuador', 'formidable' ),
1435 __( 'Egypt', 'formidable' ),
1436 __( 'El Salvador', 'formidable' ),
1437 __( 'Equatorial Guinea', 'formidable' ),
1438 __( 'Eritrea', 'formidable' ),
1439 __( 'Estonia', 'formidable' ),
1440 __( 'Ethiopia', 'formidable' ),
1441 __( 'Falkland Islands (Malvinas)', 'formidable' ),
1442 __( 'Faroe Islands', 'formidable' ),
1443 __( 'Fiji', 'formidable' ),
1444 __( 'Finland', 'formidable' ),
1445 __( 'France', 'formidable' ),
1446 __( 'French Guiana', 'formidable' ),
1447 __( 'French Polynesia', 'formidable' ),
1448 __( 'French Southern Territories', 'formidable' ),
1449 __( 'Gabon', 'formidable' ),
1450 __( 'Gambia', 'formidable' ),
1451 __( 'Georgia', 'formidable' ),
1452 __( 'Germany', 'formidable' ),
1453 __( 'Ghana', 'formidable' ),
1454 __( 'Gibraltar', 'formidable' ),
1455 __( 'Greece', 'formidable' ),
1456 __( 'Greenland', 'formidable' ),
1457 __( 'Grenada', 'formidable' ),
1458 __( 'Guadeloupe', 'formidable' ),
1459 __( 'Guam', 'formidable' ),
1460 __( 'Guatemala', 'formidable' ),
1461 __( 'Guernsey', 'formidable' ),
1462 __( 'Guinea', 'formidable' ),
1463 __( 'Guinea-Bissau', 'formidable' ),
1464 __( 'Guyana', 'formidable' ),
1465 __( 'Haiti', 'formidable' ),
1466 __( 'Heard Island and McDonald Islands', 'formidable' ),
1467 __( 'Holy See', 'formidable' ),
1468 __( 'Honduras', 'formidable' ),
1469 __( 'Hong Kong', 'formidable' ),
1470 __( 'Hungary', 'formidable' ),
1471 __( 'Iceland', 'formidable' ),
1472 __( 'India', 'formidable' ),
1473 __( 'Indonesia', 'formidable' ),
1474 __( 'Iran', 'formidable' ),
1475 __( 'Iraq', 'formidable' ),
1476 __( 'Ireland', 'formidable' ),
1477 __( 'Israel', 'formidable' ),
1478 __( 'Isle of Man', 'formidable' ),
1479 __( 'Italy', 'formidable' ),
1480 __( 'Jamaica', 'formidable' ),
1481 __( 'Japan', 'formidable' ),
1482 __( 'Jersey', 'formidable' ),
1483 __( 'Jordan', 'formidable' ),
1484 __( 'Kazakhstan', 'formidable' ),
1485 __( 'Kenya', 'formidable' ),
1486 __( 'Kiribati', 'formidable' ),
1487 __( 'North Korea', 'formidable' ),
1488 __( 'South Korea', 'formidable' ),
1489 __( 'Kosovo', 'formidable' ),
1490 __( 'Kuwait', 'formidable' ),
1491 __( 'Kyrgyzstan', 'formidable' ),
1492 __( 'Laos', 'formidable' ),
1493 __( 'Latvia', 'formidable' ),
1494 __( 'Lebanon', 'formidable' ),
1495 __( 'Lesotho', 'formidable' ),
1496 __( 'Liberia', 'formidable' ),
1497 __( 'Libya', 'formidable' ),
1498 __( 'Liechtenstein', 'formidable' ),
1499 __( 'Lithuania', 'formidable' ),
1500 __( 'Luxembourg', 'formidable' ),
1501 __( 'Macao', 'formidable' ),
1502 __( 'Macedonia', 'formidable' ),
1503 __( 'Madagascar', 'formidable' ),
1504 __( 'Malawi', 'formidable' ),
1505 __( 'Malaysia', 'formidable' ),
1506 __( 'Maldives', 'formidable' ),
1507 __( 'Mali', 'formidable' ),
1508 __( 'Malta', 'formidable' ),
1509 __( 'Marshall Islands', 'formidable' ),
1510 __( 'Martinique', 'formidable' ),
1511 __( 'Mauritania', 'formidable' ),
1512 __( 'Mauritius', 'formidable' ),
1513 __( 'Mayotte', 'formidable' ),
1514 __( 'Mexico', 'formidable' ),
1515 __( 'Micronesia', 'formidable' ),
1516 __( 'Moldova', 'formidable' ),
1517 __( 'Monaco', 'formidable' ),
1518 __( 'Mongolia', 'formidable' ),
1519 __( 'Montenegro', 'formidable' ),
1520 __( 'Montserrat', 'formidable' ),
1521 __( 'Morocco', 'formidable' ),
1522 __( 'Mozambique', 'formidable' ),
1523 __( 'Myanmar', 'formidable' ),
1524 __( 'Namibia', 'formidable' ),
1525 __( 'Nauru', 'formidable' ),
1526 __( 'Nepal', 'formidable' ),
1527 __( 'Netherlands', 'formidable' ),
1528 __( 'New Caledonia', 'formidable' ),
1529 __( 'New Zealand', 'formidable' ),
1530 __( 'Nicaragua', 'formidable' ),
1531 __( 'Niger', 'formidable' ),
1532 __( 'Nigeria', 'formidable' ),
1533 __( 'Niue', 'formidable' ),
1534 __( 'Norfolk Island', 'formidable' ),
1535 __( 'Northern Mariana Islands', 'formidable' ),
1536 __( 'Norway', 'formidable' ),
1537 __( 'Oman', 'formidable' ),
1538 __( 'Pakistan', 'formidable' ),
1539 __( 'Palau', 'formidable' ),
1540 __( 'Palestine', 'formidable' ),
1541 __( 'Panama', 'formidable' ),
1542 __( 'Papua New Guinea', 'formidable' ),
1543 __( 'Paraguay', 'formidable' ),
1544 __( 'Peru', 'formidable' ),
1545 __( 'Philippines', 'formidable' ),
1546 __( 'Pitcairn', 'formidable' ),
1547 __( 'Poland', 'formidable' ),
1548 __( 'Portugal', 'formidable' ),
1549 __( 'Puerto Rico', 'formidable' ),
1550 __( 'Qatar', 'formidable' ),
1551 __( 'Reunion', 'formidable' ),
1552 __( 'Romania', 'formidable' ),
1553 __( 'Russia', 'formidable' ),
1554 __( 'Rwanda', 'formidable' ),
1555 __( 'Saint Barthelemy', 'formidable' ),
1556 __( 'Saint Helena, Ascension and Tristan da Cunha', 'formidable' ),
1557 __( 'Saint Kitts and Nevis', 'formidable' ),
1558 __( 'Saint Lucia', 'formidable' ),
1559 __( 'Saint Martin (French part)', 'formidable' ),
1560 __( 'Saint Pierre and Miquelon', 'formidable' ),
1561 __( 'Saint Vincent and the Grenadines', 'formidable' ),
1562 __( 'Samoa', 'formidable' ),
1563 __( 'San Marino', 'formidable' ),
1564 __( 'Sao Tome and Principe', 'formidable' ),
1565 __( 'Saudi Arabia', 'formidable' ),
1566 __( 'Senegal', 'formidable' ),
1567 __( 'Serbia', 'formidable' ),
1568 __( 'Seychelles', 'formidable' ),
1569 __( 'Sierra Leone', 'formidable' ),
1570 __( 'Singapore', 'formidable' ),
1571 __( 'Sint Maarten (Dutch part)', 'formidable' ),
1572 __( 'Slovakia', 'formidable' ),
1573 __( 'Slovenia', 'formidable' ),
1574 __( 'Solomon Islands', 'formidable' ),
1575 __( 'Somalia', 'formidable' ),
1576 __( 'South Africa', 'formidable' ),
1577 __( 'South Georgia and the South Sandwich Islands', 'formidable' ),
1578 __( 'South Sudan', 'formidable' ),
1579 __( 'Spain', 'formidable' ),
1580 __( 'Sri Lanka', 'formidable' ),
1581 __( 'Sudan', 'formidable' ),
1582 __( 'Suriname', 'formidable' ),
1583 __( 'Svalbard and Jan Mayen', 'formidable' ),
1584 __( 'Swaziland', 'formidable' ),
1585 __( 'Sweden', 'formidable' ),
1586 __( 'Switzerland', 'formidable' ),
1587 __( 'Syria', 'formidable' ),
1588 __( 'Taiwan', 'formidable' ),
1589 __( 'Tajikistan', 'formidable' ),
1590 __( 'Tanzania', 'formidable' ),
1591 __( 'Thailand', 'formidable' ),
1592 __( 'Timor-Leste', 'formidable' ),
1593 __( 'Togo', 'formidable' ),
1594 __( 'Tokelau', 'formidable' ),
1595 __( 'Tonga', 'formidable' ),
1596 __( 'Trinidad and Tobago', 'formidable' ),
1597 __( 'Tunisia', 'formidable' ),
1598 __( 'Turkey', 'formidable' ),
1599 __( 'Turkmenistan', 'formidable' ),
1600 __( 'Turks and Caicos Islands', 'formidable' ),
1601 __( 'Tuvalu', 'formidable' ),
1602 __( 'Uganda', 'formidable' ),
1603 __( 'Ukraine', 'formidable' ),
1604 __( 'United Arab Emirates', 'formidable' ),
1605 __( 'United Kingdom', 'formidable' ),
1606 __( 'United States', 'formidable' ),
1607 __( 'United States Minor Outlying Islands', 'formidable' ),
1608 __( 'Uruguay', 'formidable' ),
1609 __( 'Uzbekistan', 'formidable' ),
1610 __( 'Vanuatu', 'formidable' ),
1611 __( 'Vatican City', 'formidable' ),
1612 __( 'Venezuela', 'formidable' ),
1613 __( 'Vietnam', 'formidable' ),
1614 __( 'Virgin Islands, British', 'formidable' ),
1615 __( 'Virgin Islands, U.S.', 'formidable' ),
1616 __( 'Wallis and Futuna', 'formidable' ),
1617 __( 'Western Sahara', 'formidable' ),
1618 __( 'Yemen', 'formidable' ),
1619 __( 'Zambia', 'formidable' ),
1620 __( 'Zimbabwe', 'formidable' ),
1621 );
1622
1623 sort( $countries, SORT_LOCALE_STRING );
1624 return apply_filters( 'frm_countries', $countries );
1625 }
1626
1627 public static function get_bulk_prefilled_opts( array &$prepop ) {
1628 $prepop[ __( 'Countries', 'formidable' ) ] = self::get_countries();
1629
1630 $states = self::get_us_states();
1631 $state_abv = array_keys( $states );
1632 sort( $state_abv );
1633 $prepop[ __( 'U.S. State Abbreviations', 'formidable' ) ] = $state_abv;
1634
1635 $states = array_values( $states );
1636 sort( $states );
1637 $prepop[ __( 'U.S. States', 'formidable' ) ] = $states;
1638 unset( $state_abv, $states );
1639
1640 $prepop[ __( 'Age', 'formidable' ) ] = array(
1641 __( 'Under 18', 'formidable' ),
1642 __( '18-24', 'formidable' ),
1643 __( '25-34', 'formidable' ),
1644 __( '35-44', 'formidable' ),
1645 __( '45-54', 'formidable' ),
1646 __( '55-64', 'formidable' ),
1647 __( '65 or Above', 'formidable' ),
1648 __( 'Prefer Not to Answer', 'formidable' ),
1649 );
1650
1651 $prepop[ __( 'Satisfaction', 'formidable' ) ] = array(
1652 __( 'Very Satisfied', 'formidable' ),
1653 __( 'Satisfied', 'formidable' ),
1654 __( 'Neutral', 'formidable' ),
1655 __( 'Unsatisfied', 'formidable' ),
1656 __( 'Very Unsatisfied', 'formidable' ),
1657 __( 'N/A', 'formidable' ),
1658 );
1659
1660 $prepop[ __( 'Importance', 'formidable' ) ] = array(
1661 __( 'Very Important', 'formidable' ),
1662 __( 'Important', 'formidable' ),
1663 __( 'Neutral', 'formidable' ),
1664 __( 'Somewhat Important', 'formidable' ),
1665 __( 'Not at all Important', 'formidable' ),
1666 __( 'N/A', 'formidable' ),
1667 );
1668
1669 $prepop[ __( 'Agreement', 'formidable' ) ] = array(
1670 __( 'Strongly Agree', 'formidable' ),
1671 __( 'Agree', 'formidable' ),
1672 __( 'Neutral', 'formidable' ),
1673 __( 'Disagree', 'formidable' ),
1674 __( 'Strongly Disagree', 'formidable' ),
1675 __( 'N/A', 'formidable' ),
1676 );
1677
1678 $prepop = apply_filters( 'frm_bulk_field_choices', $prepop );
1679 }
1680
1681 /**
1682 * Display a field value selector
1683 *
1684 * @since 2.03.05
1685 *
1686 * @param int $selector_field_id
1687 * @param array $selector_args
1688 */
1689 public static function display_field_value_selector( $selector_field_id, $selector_args ) {
1690 $field_value_selector = FrmFieldFactory::create_field_value_selector( $selector_field_id, $selector_args );
1691 $field_value_selector->display();
1692 }
1693
1694 /**
1695 * Convert a field object to a flat array
1696 *
1697 * @since 2.03.05
1698 *
1699 * @param object $field
1700 *
1701 * @return array
1702 */
1703 public static function convert_field_object_to_flat_array( $field ) {
1704 $field_options = $field->field_options;
1705 $field_array = get_object_vars( $field );
1706 unset( $field_array['field_options'] );
1707
1708 return $field_array + $field_options;
1709 }
1710
1711 /**
1712 * @since 4.04
1713 */
1714 public static function show_add_field_buttons( $args ) {
1715 $field_key = $args['field_key'];
1716 $field_type = $args['field_type'];
1717 $field_label = FrmAppHelper::icon_by_class( FrmFormsHelper::get_field_link_icon( $field_type ), array( 'echo' => false ) );
1718 $field_name = FrmFormsHelper::get_field_link_name( $field_type );
1719 $field_label .= ' <span>' . $field_name . '</span>';
1720
1721 /* translators: %s: Field name */
1722 $upgrade_label = sprintf( esc_html__( '%s fields', 'formidable' ), $field_name );
1723
1724 // If the individual field isn't allowed, disable it.
1725 $run_filter = true;
1726 $single_no_allow = ' ';
1727 $install_data = '';
1728 $requires = '';
1729 $upgrade_message = '';
1730 $link = isset( $field_type['link'] ) ? esc_url_raw( $field_type['link'] ) : '';
1731 if ( strpos( $field_type['icon'], ' frm_show_upgrade' ) ) {
1732 $single_no_allow .= 'frm_show_upgrade';
1733 $field_type['icon'] = str_replace( ' frm_show_upgrade', '', $field_type['icon'] );
1734 $run_filter = false;
1735 if ( isset( $field_type['addon'] ) ) {
1736 $upgrading = FrmAddonsController::install_link( $field_type['addon'] );
1737 if ( isset( $upgrading['url'] ) ) {
1738 $install_data = json_encode( $upgrading );
1739 }
1740 $requires = FrmFormsHelper::get_plan_required( $upgrading );
1741 } elseif ( isset( $field_type['require'] ) ) {
1742 $requires = $field_type['require'];
1743 }
1744 }
1745
1746 if ( isset( $field_type['message'] ) ) {
1747 $upgrade_message = FrmAppHelper::kses( $field_type['message'], array( 'a', 'img' ) );
1748 }
1749
1750 ?>
1751 <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 ); ?>">
1752 <?php
1753 if ( $run_filter ) {
1754 $field_label = apply_filters( 'frmpro_field_links', $field_label, $args['id'], $field_key );
1755 }
1756 echo FrmAppHelper::kses( $field_label, array( 'a', 'i', 'span', 'use', 'svg' ) ); // WPCS: XSS ok.
1757 ?>
1758 </li>
1759 <?php
1760 }
1761
1762 /**
1763 * @deprecated 4.0
1764 */
1765 public static function show_icon_link_js( $atts ) {
1766 _deprecated_function( __METHOD__, '4.0' );
1767 $atts['icon'] .= $atts['is_selected'] ? ' ' : ' frm_inactive_icon ';
1768 if ( isset( $atts['has_default'] ) && ! $atts['has_default'] ) {
1769 $atts['icon'] .= 'frm_hidden ';
1770 }
1771 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>';
1772 }
1773
1774 /**
1775 * @deprecated 4.0
1776 */
1777 public static function show_default_blank_js( $is_selected, $has_default_value = true ) {
1778 _deprecated_function( __METHOD__, '4.0' );
1779 }
1780
1781 /**
1782 * @deprecated 4.0
1783 */
1784 public static function clear_on_focus_html( $field, $display, $id = '' ) {
1785 _deprecated_function( __METHOD__, '4.0' );
1786 }
1787
1788 /**
1789 * @deprecated 4.0
1790 */
1791 public static function show_onfocus_js( $is_selected, $has_default_value = true ) {
1792 _deprecated_function( __METHOD__, '4.0' );
1793 }
1794
1795 /**
1796 * @deprecated 3.0
1797 * @codeCoverageIgnore
1798 */
1799 public static function display_recaptcha() {
1800 _deprecated_function( __FUNCTION__, '3.0', 'FrmFieldCaptcha::field_input' );
1801 }
1802
1803 /**
1804 * @deprecated 3.0
1805 * @codeCoverageIgnore
1806 */
1807 public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) {
1808 FrmDeprecated::remove_inline_conditions( $no_vars, $code, $replace_with, $html );
1809 }
1810
1811 /**
1812 * @deprecated 3.0
1813 * @codeCoverageIgnore
1814 */
1815 public static function get_shortcode_tag( $shortcodes, $short_key, $args ) {
1816 return FrmDeprecated::get_shortcode_tag( $shortcodes, $short_key, $args );
1817 }
1818
1819 /**
1820 * @deprecated 3.0
1821 * @codeCoverageIgnore
1822 *
1823 * @param string $html
1824 * @param array $field
1825 * @param array $errors
1826 * @param object $form
1827 * @param array $args
1828 *
1829 * @return string
1830 */
1831 public static function replace_shortcodes( $html, $field, $errors = array(), $form = false, $args = array() ) {
1832 return FrmDeprecated::replace_shortcodes( $html, $field, $errors, $form, $args );
1833 }
1834
1835 /**
1836 * @deprecated 3.0
1837 * @codeCoverageIgnore
1838 */
1839 public static function get_default_field_opts( $type, $field = null, $limit = false ) {
1840 return FrmDeprecated::get_default_field_opts( $type, $field, $limit );
1841 }
1842
1843 /**
1844 * @deprecated 2.02.07
1845 * @codeCoverageIgnore
1846 */
1847 public static function dropdown_categories( $args ) {
1848 return FrmDeprecated::dropdown_categories( $args );
1849 }
1850 }
1851