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

2,135 lines 63.0 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'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
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 ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
184 return;
185 }
186
187 if ( strpos( $setting, 'html' ) !== false ) {
188 // Strip slashes from HTML but not regex or script tags.
189 $value = wp_unslash( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
190 } elseif ( strpos( $setting, 'format_' ) === 0 ) {
191 // TODO: Remove stripslashes on output, and use on input only.
192 $value = sanitize_text_field( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing
193 } else {
194 $value = wp_unslash( $_POST['field_options'][ $setting ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
195 FrmAppHelper::sanitize_value( 'wp_kses_post', $value );
196 }
197 }
198
199 /**
200 * @since 3.0
201 *
202 * @param object $field
203 * @param array $values The field array is needed for hooks
204 *
205 * @return array
206 */
207 public static function get_default_field_options_from_field( $field, $values = array() ) {
208 $field_type = self::get_original_field( $field );
209 $opts = $field_type->get_default_field_options();
210
211 $opts = apply_filters( 'frm_default_field_opts', $opts, $values, $field );
212 $opts = apply_filters( 'frm_default_' . $field->type . '_field_opts', $opts, $values, $field );
213
214 return $opts;
215 }
216
217 /**
218 * @since 3.0
219 *
220 * @param object $field
221 *
222 * @return array
223 */
224 private static function get_original_field( $field ) {
225 $original_type = FrmField::get_option( $field, 'original_type' );
226 if ( ! empty( $original_type ) && $field->type != $original_type ) {
227 $field->type = $original_type;
228 }
229
230 return FrmFieldFactory::get_field_object( $field );
231 }
232
233 /**
234 * @since 3.0
235 *
236 * @param array $field_array
237 * @param object $field
238 * @param array $atts
239 */
240 private static function prepare_field_options_for_display( &$field_array, $field, $atts ) {
241 $field_obj = FrmFieldFactory::get_field_object( $field );
242 $field_array = $field_obj->prepare_front_field( $field_array, $atts );
243 }
244
245 /**
246 * @since 3.0
247 *
248 * @param string $type
249 *
250 * @return array
251 */
252 public static function get_default_field( $type ) {
253 $field_type = FrmFieldFactory::get_field_type( $type );
254
255 return $field_type->get_new_field_defaults();
256 }
257
258 public static function fill_field( &$values, $field, $form_id, $new_key = '' ) {
259 global $wpdb;
260
261 $values['field_key'] = FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_fields', 'field_key' );
262 $values['form_id'] = $form_id;
263 $values['options'] = maybe_serialize( $field->options );
264 $values['default_value'] = FrmAppHelper::maybe_json_encode( $field->default_value );
265
266 foreach ( array( 'name', 'description', 'type', 'field_order', 'field_options', 'required' ) as $col ) {
267 $values[ $col ] = $field->{$col};
268 }
269 }
270
271 /**
272 * @since 2.0
273 *
274 * @param $field
275 * @param $error
276 *
277 * @return string
278 */
279 public static function get_error_msg( $field, $error ) {
280 $frm_settings = FrmAppHelper::get_settings();
281 $default_settings = $frm_settings->default_options();
282 $field_name = is_array( $field ) ? $field['name'] : $field->name;
283
284 $conf_msg = __( 'The entered values do not match', 'formidable' );
285 $defaults = array(
286 'unique_msg' => array(
287 'full' => $default_settings['unique_msg'],
288 /* translators: %s: Field name */
289 'part' => sprintf( __( '%s must be unique', 'formidable' ), $field_name ),
290 ),
291 'invalid' => array(
292 'full' => __( 'This field is invalid', 'formidable' ),
293 /* translators: %s: Field name */
294 'part' => sprintf( __( '%s is invalid', 'formidable' ), $field_name ),
295 ),
296 'blank' => array(
297 'full' => $frm_settings->blank_msg,
298 'part' => $frm_settings->blank_msg,
299 ),
300 'conf_msg' => array(
301 'full' => $conf_msg,
302 'part' => $conf_msg,
303 ),
304 );
305
306 $msg = FrmField::get_option( $field, $error );
307 $msg = empty( $msg ) ? $defaults[ $error ]['part'] : $msg;
308 $msg = do_shortcode( $msg );
309
310 return $msg;
311 }
312
313 public static function get_form_fields( $form_id, $error = array() ) {
314 $fields = FrmField::get_all_for_form( $form_id );
315
316 return apply_filters( 'frm_get_paged_fields', $fields, $form_id, $error );
317 }
318
319 public static function get_default_html( $type = 'text' ) {
320 $field = FrmFieldFactory::get_field_type( $type );
321 $default_html = $field->default_html();
322
323 // these hooks are here for reverse compatibility since 3.0
324 if ( ! apply_filters( 'frm_normal_field_type_html', true, $type ) ) {
325 $default_html = apply_filters( 'frm_other_custom_html', '', $type );
326 }
327
328 return apply_filters( 'frm_custom_html', $default_html, $type );
329 }
330
331 /**
332 * @param array $fields
333 * @param array $errors
334 * @param object $form
335 * @param $form_action
336 */
337 public static function show_fields( $fields, $errors, $form, $form_action ) {
338 foreach ( $fields as $field ) {
339 $field_obj = FrmFieldFactory::get_field_type( $field['type'], $field );
340 $field_obj->show_field( compact( 'errors', 'form', 'form_action' ) );
341 }
342 }
343
344 /**
345 * @since 3.0
346 *
347 * @param array $atts
348 * @param string|array $value
349 */
350 public static function run_wpautop( $atts, &$value ) {
351 $autop = isset( $atts['wpautop'] ) ? $atts['wpautop'] : true;
352 if ( apply_filters( 'frm_use_wpautop', $autop ) ) {
353 if ( is_array( $value ) ) {
354 $value = implode( "\n", $value );
355 }
356 $value = wpautop( $value );
357 }
358 }
359
360 /**
361 * Get the class to use for the label position
362 *
363 * @since 2.05
364 */
365 public static function &label_position( $position, $field, $form ) {
366 if ( $position && $position != '' ) {
367 if ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
368 $position = 'top';
369 }
370
371 return $position;
372 }
373
374 $position = FrmStylesController::get_style_val( 'position', $form );
375 if ( $position == 'none' ) {
376 $position = 'top';
377 } elseif ( $position == 'no_label' ) {
378 $position = 'none';
379 } elseif ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
380 $position = 'top';
381 }
382
383 $position = apply_filters( 'frm_html_label_position', $position, $field, $form );
384 $position = ( ! empty( $position ) ) ? $position : 'top';
385
386 return $position;
387 }
388
389 /**
390 * Check if this field type allows placeholders
391 *
392 * @since 2.05
393 * @param string $type
394 * @return bool
395 */
396 public static function is_placeholder_field_type( $type ) {
397 return ! in_array( $type, array( 'radio', 'checkbox', 'hidden', 'file' ), true );
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 } elseif ( $cond === '%LIKE' ) {
592 // ends with
593 $length = strlen( $hide_opt );
594 $substr = substr( $observed_value, strlen( $observed_value ) - $length );
595 $m = 0 === strcasecmp( $substr, $hide_opt );
596 } elseif ( 'LIKE%' === $cond ) {
597 // starts with
598 $length = strlen( $hide_opt );
599 $substr = substr( $observed_value, 0, $length );
600 $m = 0 === strcasecmp( $substr, $hide_opt );
601 }
602
603 return $m;
604 }
605
606 /**
607 * Trim and sanitize the values
608 *
609 * @since 2.05
610 */
611 private static function get_value_for_comparision( $value ) {
612 // Remove white space from hide_opt
613 if ( ! is_array( $value ) ) {
614 $value = trim( $value );
615 }
616
617 FrmAppHelper::sanitize_value( 'wp_kses_post', $value );
618
619 return $value;
620 }
621
622 public static function array_value_condition( $observed_value, $cond, $hide_opt ) {
623 $m = false;
624 if ( $cond === '==' ) {
625 if ( is_array( $hide_opt ) ) {
626 $m = array_intersect( $hide_opt, $observed_value );
627 $m = empty( $m ) ? false : true;
628 } else {
629 $m = in_array( $hide_opt, $observed_value );
630 }
631 } elseif ( $cond === '!=' ) {
632 $m = ! in_array( $hide_opt, $observed_value );
633 } elseif ( $cond === '>' ) {
634 $min = min( $observed_value );
635 $m = $min > $hide_opt;
636 } elseif ( $cond === '<' ) {
637 $max = max( $observed_value );
638 $m = $max < $hide_opt;
639 } elseif ( $cond === 'LIKE' || $cond === 'not LIKE' ) {
640 foreach ( $observed_value as $ob ) {
641 $m = strpos( $ob, $hide_opt );
642 if ( $m !== false ) {
643 $m = true;
644 break;
645 }
646 }
647
648 if ( $cond === 'not LIKE' ) {
649 $m = ( $m === false ) ? true : false;
650 }
651 } elseif ( $cond === '%LIKE' ) {
652 // ends with
653 foreach ( $observed_value as $ob ) {
654 if ( $hide_opt === substr( $ob, strlen( $ob ) - strlen( $hide_opt ) ) ) {
655 $m = true;
656 break;
657 }
658 }
659 } elseif ( $cond === 'LIKE%' ) {
660 // starts with
661 foreach ( $observed_value as $ob ) {
662 if ( $hide_opt === substr( $ob, 0, strlen( $hide_opt ) ) ) {
663 $m = true;
664 break;
665 }
666 }
667 }
668
669 return $m;
670 }
671
672 /**
673 * Replace a few basic shortcodes and field ids
674 *
675 * @since 2.0
676 * @return string
677 */
678 public static function basic_replace_shortcodes( $value, $form, $entry ) {
679 if ( strpos( $value, '[sitename]' ) !== false ) {
680 $new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
681 $value = str_replace( '[sitename]', $new_value, $value );
682 }
683
684 $value = apply_filters( 'frm_content', $value, $form, $entry );
685 $value = do_shortcode( $value );
686
687 return $value;
688 }
689
690 public static function get_shortcodes( $content, $form_id ) {
691 if ( FrmAppHelper::pro_is_installed() ) {
692 return FrmProDisplaysHelper::get_shortcodes( $content, $form_id );
693 }
694
695 $fields = FrmField::getAll(
696 array(
697 'fi.form_id' => (int) $form_id,
698 'fi.type not' => FrmField::no_save_fields(),
699 )
700 );
701
702 $tagregexp = self::allowed_shortcodes( $fields );
703
704 preg_match_all( "/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER );
705
706 return $matches;
707 }
708
709 public static function allowed_shortcodes( $fields = array() ) {
710 $tagregexp = array(
711 'editlink',
712 'id',
713 'key',
714 'ip',
715 'siteurl',
716 'sitename',
717 'admin_email',
718 'post[-|_]id',
719 'created[-|_]at',
720 'updated[-|_]at',
721 'updated[-|_]by',
722 'parent[-|_]id',
723 );
724
725 foreach ( $fields as $field ) {
726 $tagregexp[] = $field->id;
727 $tagregexp[] = $field->field_key;
728 }
729
730 $tagregexp = implode( '|', $tagregexp );
731
732 return $tagregexp;
733 }
734
735 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
736 foreach ( $shortcodes[0] as $short_key => $tag ) {
737 if ( empty( $tag ) ) {
738 continue;
739 }
740
741 $atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[3][ $short_key ] );
742 $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key );
743
744 $atts['entry'] = $entry;
745 $atts['tag'] = $tag;
746 $replace_with = self::get_value_for_shortcode( $atts );
747
748 if ( $replace_with !== null ) {
749 $replace_with = self::trigger_shortcode_atts( $replace_with, $atts );
750 self::sanitize_embedded_shortcodes( compact( 'entry' ), $replace_with );
751 $content = str_replace( $shortcodes[0][ $short_key ], $replace_with, $content );
752 }
753
754 unset( $atts, $replace_with );
755 }
756
757 return $content;
758 }
759
760 /**
761 * @param string $replace_with
762 * @param array $atts
763 */
764 private static function trigger_shortcode_atts( $replace_with, $atts ) {
765 $supported_atts = array( 'sanitize', 'sanitize_url' );
766 $included_atts = array_intersect( $supported_atts, array_keys( $atts ) );
767 foreach ( $included_atts as $included_att ) {
768 $function = 'atts_' . $included_att;
769 $replace_with = self::$function( $replace_with, $atts );
770 }
771 return $replace_with;
772 }
773
774 /**
775 * @param string $replace_with
776 * @return string
777 */
778 private static function atts_sanitize( $replace_with ) {
779 return sanitize_title_with_dashes( $replace_with );
780 }
781
782 /**
783 * @param string $replace_with
784 * @return string
785 */
786 private static function atts_sanitize_url( $replace_with ) {
787 return urlencode( $replace_with );
788 }
789
790 /**
791 * Prevent shortcodes in fields from being processed
792 *
793 * @since 3.01.02
794 *
795 * @param array $atts - includes entry object
796 * @param string $value
797 */
798 public static function sanitize_embedded_shortcodes( $atts, &$value ) {
799 $atts['value'] = $value;
800 $should_sanitize = apply_filters( 'frm_sanitize_shortcodes', true, $atts );
801 if ( $should_sanitize ) {
802 $value = str_replace( '[', '&#91;', $value );
803 }
804 }
805
806 /**
807 * @since 3.0
808 *
809 * @param $atts
810 *
811 * @return string
812 */
813 private static function get_value_for_shortcode( $atts ) {
814 $clean_tag = str_replace( '-', '_', $atts['tag'] );
815
816 $shortcode_values = array(
817 'id' => $atts['entry']->id,
818 'key' => $atts['entry']->item_key,
819 'ip' => $atts['entry']->ip,
820 );
821
822 $dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get' );
823
824 if ( isset( $shortcode_values[ $atts['tag'] ] ) ) {
825 $replace_with = $shortcode_values[ $atts['tag'] ];
826 } elseif ( in_array( $atts['tag'], $dynamic_default ) ) {
827 $replace_with = self::dynamic_default_values( $atts['tag'], $atts );
828 } elseif ( $clean_tag == 'user_agent' ) {
829 $description = $atts['entry']->description;
830 $replace_with = FrmEntriesHelper::get_browser( $description['browser'] );
831 } elseif ( $clean_tag == 'created_at' || $clean_tag == 'updated_at' ) {
832 $atts['tag'] = $clean_tag;
833 $replace_with = self::get_entry_timestamp( $atts );
834 } elseif ( $clean_tag == 'created_by' || $clean_tag == 'updated_by' ) {
835 $replace_with = self::get_display_value( $atts['entry']->{$clean_tag}, (object) array( 'type' => 'user_id' ), $atts );
836 } else {
837 $replace_with = self::get_field_shortcode_value( $atts );
838 }
839
840 return $replace_with;
841 }
842
843 /**
844 * @since 3.0
845 *
846 * @param $atts
847 *
848 * @return string
849 */
850 private static function get_entry_timestamp( $atts ) {
851 if ( isset( $atts['format'] ) ) {
852 $time_format = ' ';
853 } else {
854 $atts['format'] = get_option( 'date_format' );
855 $time_format = '';
856 }
857
858 return FrmAppHelper::get_formatted_time( $atts['entry']->{$atts['tag']}, $atts['format'], $time_format );
859 }
860
861 /**
862 * @since 3.0
863 *
864 * @param $atts
865 *
866 * @return null|string
867 */
868 private static function get_field_shortcode_value( $atts ) {
869 $field = FrmField::getOne( $atts['tag'] );
870 if ( empty( $field ) ) {
871 return null;
872 }
873
874 if ( isset( $atts['show'] ) && $atts['show'] === 'field_label' ) {
875 $replace_with = $field->name;
876 } elseif ( isset( $atts['show'] ) && $atts['show'] === 'description' ) {
877 $replace_with = $field->description;
878 } else {
879 $replace_with = FrmEntryMeta::get_meta_value( $atts['entry'], $field->id );
880 $string_value = $replace_with;
881 if ( is_array( $replace_with ) ) {
882 $sep = isset( $atts['sep'] ) ? $atts['sep'] : ', ';
883 $string_value = implode( $sep, $replace_with );
884 }
885
886 if ( empty( $string_value ) && $string_value != '0' ) {
887 $replace_with = '';
888 } else {
889 $atts['entry_id'] = $atts['entry']->id;
890 $atts['entry_key'] = $atts['entry']->item_key;
891 $replace_with = self::get_display_value( $replace_with, $field, $atts );
892 }
893 }
894
895 return $replace_with;
896 }
897
898 /**
899 * Get the value to replace a few standard shortcodes
900 *
901 * @since 2.0
902 * @return string
903 */
904 public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) {
905 $new_value = '';
906 switch ( $tag ) {
907 case 'admin_email':
908 $new_value = get_option( 'admin_email' );
909 break;
910 case 'siteurl':
911 $new_value = FrmAppHelper::site_url();
912 break;
913 case 'frmurl':
914 $new_value = FrmAppHelper::plugin_url();
915 break;
916 case 'sitename':
917 $new_value = FrmAppHelper::site_name();
918 break;
919 case 'get':
920 $new_value = self::process_get_shortcode( $atts, $return_array );
921 }
922
923 return $new_value;
924 }
925
926 /**
927 * Process the [get] shortcode
928 *
929 * @since 2.0
930 * @return string|array
931 */
932 public static function process_get_shortcode( $atts, $return_array = false ) {
933 if ( ! isset( $atts['param'] ) ) {
934 return '';
935 }
936
937 if ( strpos( $atts['param'], '&#91;' ) ) {
938 $atts['param'] = str_replace( '&#91;', '[', $atts['param'] );
939 $atts['param'] = str_replace( '&#93;', ']', $atts['param'] );
940 }
941
942 $new_value = FrmAppHelper::get_param( $atts['param'], '', 'get', 'sanitize_text_field' );
943 $new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] );
944
945 if ( $new_value == '' ) {
946 if ( ! isset( $atts['prev_val'] ) ) {
947 $atts['prev_val'] = '';
948 }
949
950 $new_value = isset( $atts['default'] ) ? $atts['default'] : $atts['prev_val'];
951 }
952
953 if ( is_array( $new_value ) && ! $return_array ) {
954 $new_value = implode( ', ', $new_value );
955 }
956
957 return $new_value;
958 }
959
960 public static function get_display_value( $value, $field, $atts = array() ) {
961
962 $value = apply_filters( 'frm_get_' . $field->type . '_display_value', $value, $field, $atts );
963 $value = apply_filters( 'frm_get_display_value', $value, $field, $atts );
964
965 $value = self::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) );
966
967 return apply_filters( 'frm_display_value', $value, $field, $atts );
968 }
969
970 /**
971 * @param $atts array Includes value, field, and atts
972 */
973 public static function get_unfiltered_display_value( $atts ) {
974 $value = $atts['value'];
975 $field = $atts['field'];
976 $atts = isset( $atts['atts'] ) ? $atts['atts'] : $atts;
977
978 if ( is_array( $field ) ) {
979 $field = $field['id'];
980 }
981
982 $field_obj = FrmFieldFactory::get_field_object( $field );
983
984 return $field_obj->get_display_value( $value, $atts );
985 }
986
987 /**
988 * Get a value from the user profile from the user ID
989 *
990 * @since 3.0
991 */
992 public static function get_user_display_name( $user_id, $user_info = 'display_name', $args = array() ) {
993 $defaults = array(
994 'blank' => false,
995 'link' => false,
996 'size' => 96,
997 );
998
999 $args = wp_parse_args( $args, $defaults );
1000
1001 $user = get_userdata( $user_id );
1002 $info = '';
1003
1004 if ( $user ) {
1005 if ( $user_info == 'avatar' ) {
1006 $info = get_avatar( $user_id, $args['size'] );
1007 } elseif ( $user_info == 'author_link' ) {
1008 $info = get_author_posts_url( $user_id );
1009 } else {
1010 $info = isset( $user->$user_info ) ? $user->$user_info : '';
1011 }
1012
1013 if ( 'display_name' === $user_info && empty( $info ) && ! $args['blank'] ) {
1014 $info = $user->user_login;
1015 }
1016 }
1017
1018 if ( $args['link'] ) {
1019 $info = '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $user_id ) ) . '">' . $info . '</a>';
1020 }
1021
1022 return $info;
1023 }
1024
1025 public static function get_field_types( $type ) {
1026 $single_input = self::single_input_fields();
1027 $multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' );
1028
1029 $field_selection = FrmField::all_field_selection();
1030
1031 $field_types = array();
1032 if ( in_array( $type, $single_input ) ) {
1033 self::field_types_for_input( $single_input, $field_selection, $field_types );
1034 } elseif ( in_array( $type, $multiple_input ) ) {
1035 self::field_types_for_input( $multiple_input, $field_selection, $field_types );
1036 } elseif ( isset( $field_selection[ $type ] ) ) {
1037 $field_types[ $type ] = $field_selection[ $type ];
1038 }
1039
1040 $field_types = apply_filters( 'frm_switch_field_types', $field_types, compact( 'type', 'field_selection' ) );
1041
1042 return $field_types;
1043 }
1044
1045 /**
1046 * Get a list of all fields that use a single value input.
1047 *
1048 * @since 4.0
1049 */
1050 public static function single_input_fields() {
1051 $fields = array(
1052 'text',
1053 'textarea',
1054 'rte',
1055 'number',
1056 'email',
1057 'url',
1058 'date',
1059 'phone',
1060 'hidden',
1061 'time',
1062 'tag',
1063 'password',
1064 );
1065 return apply_filters( 'frm_single_input_fields', $fields );
1066 }
1067
1068 private static function field_types_for_input( $inputs, $fields, &$field_types ) {
1069 foreach ( $inputs as $input ) {
1070 $field_types[ $input ] = $fields[ $input ];
1071 unset( $input );
1072 }
1073 }
1074
1075 /**
1076 * Check if current field option is an "other" option
1077 *
1078 * @since 2.0.6
1079 *
1080 * @param string $opt_key
1081 *
1082 * @return boolean Returns true if current field option is an "Other" option
1083 */
1084 public static function is_other_opt( $opt_key ) {
1085 return $opt_key && strpos( $opt_key, 'other_' ) === 0;
1086 }
1087
1088 /**
1089 * Get value that belongs in "Other" text box
1090 *
1091 * @since 2.0.6
1092 *
1093 * @param array $args
1094 */
1095 public static function get_other_val( $args ) {
1096 $defaults = array(
1097 'opt_key' => 0,
1098 'field' => array(),
1099 'parent' => false,
1100 'pointer' => false,
1101 );
1102 $args = wp_parse_args( $args, $defaults );
1103
1104 $opt_key = $args['opt_key'];
1105 $field = $args['field'];
1106 $parent = $args['parent'];
1107 $pointer = $args['pointer'];
1108 $other_val = '';
1109
1110 // If option is an "other" option and there is a value set for this field,
1111 // check if the value belongs in the current "Other" option text field
1112 if ( ! self::is_other_opt( $opt_key ) || ! FrmField::is_option_true( $field, 'value' ) ) {
1113 return $other_val;
1114 }
1115
1116 // Check posted vals before checking saved values
1117 // For fields inside repeating sections - note, don't check if $pointer is true because it will often be zero
1118 if ( $parent && isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
1119 if ( FrmField::is_field_with_multiple_values( $field ) ) {
1120 // phpcs:ignore WordPress.Security.NonceVerification.Missing
1121 $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 ] ) ) : '';
1122 } else {
1123 $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
1124 }
1125
1126 return $other_val;
1127
1128 } elseif ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
1129 // For normal fields
1130
1131 if ( FrmField::is_field_with_multiple_values( $field ) ) {
1132 // phpcs:ignore WordPress.Security.NonceVerification.Missing
1133 $other_val = isset( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ) : '';
1134 } else {
1135 $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
1136 }
1137
1138 return $other_val;
1139 }
1140
1141 // For checkboxes
1142 if ( $field['type'] === 'checkbox' && is_array( $field['value'] ) ) {
1143 // Check if there is an "other" val in saved value and make sure the
1144 // "other" val is not equal to the Other checkbox option
1145 if ( isset( $field['value'][ $opt_key ] ) && $field['options'][ $opt_key ] != $field['value'][ $opt_key ] ) {
1146 $other_val = $field['value'][ $opt_key ];
1147 }
1148 } else {
1149 /**
1150 * For radio buttons and dropdowns
1151 * Check if saved value equals any of the options. If not, set it as the other value.
1152 */
1153 foreach ( $field['options'] as $opt_key => $opt_val ) {
1154 $temp_val = is_array( $opt_val ) ? $opt_val['value'] : $opt_val;
1155 // Multi-select dropdowns - key is not preserved
1156 if ( is_array( $field['value'] ) ) {
1157 $o_key = array_search( $temp_val, $field['value'] );
1158 if ( isset( $field['value'][ $o_key ] ) ) {
1159 unset( $field['value'][ $o_key ], $o_key );
1160 }
1161 } elseif ( $temp_val == $field['value'] ) {
1162 // For radio and regular dropdowns
1163 return '';
1164 } else {
1165 $other_val = $field['value'];
1166 }
1167 unset( $opt_key, $opt_val, $temp_val );
1168 }
1169 // For multi-select dropdowns only
1170 if ( is_array( $field['value'] ) && ! empty( $field['value'] ) ) {
1171 $other_val = reset( $field['value'] );
1172 }
1173 }
1174
1175 return $other_val;
1176 }
1177
1178 /**
1179 * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val.
1180 * Intended for front-end use
1181 *
1182 * @since 2.0.6
1183 *
1184 * @param array $args should include field, opt_key and field name
1185 * @param boolean $other_opt
1186 * @param string $checked
1187 *
1188 * @return array $other_args
1189 */
1190 public static function prepare_other_input( $args, &$other_opt, &$checked ) {
1191 $other_args = array(
1192 'name' => '',
1193 'value' => '',
1194 );
1195
1196 //Check if this is an "Other" option
1197 if ( ! self::is_other_opt( $args['opt_key'] ) ) {
1198 return $other_args;
1199 }
1200
1201 $other_opt = true;
1202
1203 self::set_other_name( $args, $other_args );
1204 self::set_other_value( $args, $other_args );
1205
1206 if ( '' !== $other_args['value'] ) {
1207 $checked = 'checked="checked" ';
1208 }
1209
1210 return $other_args;
1211 }
1212
1213 /**
1214 * @param array $args
1215 * @param array $other_args
1216 *
1217 * @since 2.0.6
1218 */
1219 private static function set_other_name( $args, &$other_args ) {
1220 //Set up name for other field
1221 $other_args['name'] = str_replace( '[]', '', $args['field_name'] );
1222 $other_args['name'] = preg_replace( '/\[' . $args['field']['id'] . '\]$/', '', $other_args['name'] );
1223 $other_args['name'] = $other_args['name'] . '[other][' . $args['field']['id'] . ']';
1224
1225 //Converts item_meta[field_id] => item_meta[other][field_id] and
1226 //item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id]
1227 if ( FrmField::is_field_with_multiple_values( $args['field'] ) ) {
1228 $other_args['name'] .= '[' . $args['opt_key'] . ']';
1229 }
1230 }
1231
1232 /**
1233 * Find the parent and pointer, and get text for "other" text field
1234 *
1235 * @param array $args
1236 * @param array $other_args
1237 *
1238 * @since 2.0.6
1239 */
1240 private static function set_other_value( $args, &$other_args ) {
1241 $parent = '';
1242 $pointer = '';
1243
1244 // Check for parent ID and pointer
1245 $temp_array = explode( '[', $args['field_name'] );
1246
1247 // Count should only be greater than 3 if inside of a repeating section
1248 if ( count( $temp_array ) > 3 ) {
1249 $parent = str_replace( ']', '', $temp_array[1] );
1250 $pointer = str_replace( ']', '', $temp_array[2] );
1251 }
1252
1253 // Get text for "other" text field
1254 $other_args['value'] = self::get_other_val(
1255 array(
1256 'opt_key' => $args['opt_key'],
1257 'field' => $args['field'],
1258 'parent' => $parent,
1259 'pointer' => $pointer,
1260 )
1261 );
1262 }
1263
1264 /**
1265 * If this field includes an other option, show it
1266 *
1267 * @param $args array
1268 *
1269 * @since 2.0.6
1270 */
1271 public static function include_other_input( $args ) {
1272 if ( ! $args['other_opt'] ) {
1273 return;
1274 }
1275
1276 $classes = array( 'frm_other_input' );
1277 if ( ! $args['checked'] || trim( $args['checked'] ) == '' ) {
1278 // hide the field if the other option is not selected
1279 $classes[] = 'frm_pos_none';
1280 }
1281 if ( $args['field']['type'] == 'select' && $args['field']['multiple'] ) {
1282 $classes[] = 'frm_other_full';
1283 }
1284
1285 // Set up HTML ID for Other field
1286 $other_id = self::get_other_field_html_id( $args['field']['type'], $args['html_id'], $args['opt_key'] );
1287
1288 $label = isset( $args['opt_label'] ) ? $args['opt_label'] : $args['field']['name'];
1289
1290 echo '<label for="' . esc_attr( $other_id ) . '" class="frm_screen_reader frm_hidden">' .
1291 esc_html( $label ) .
1292 '</label>' .
1293 '<input type="text" id="' . esc_attr( $other_id ) . '" class="' . esc_attr( implode( ' ', $classes ) ) . '" ' .
1294 ( $args['read_only'] ? ' readonly="readonly" disabled="disabled"' : '' ) .
1295 ' name="' . esc_attr( $args['name'] ) . '" value="' . esc_attr( $args['value'] ) . '" />';
1296 }
1297
1298 /**
1299 * Get the HTML id for an "Other" text field
1300 * Note: This does not affect fields in repeating sections
1301 *
1302 * @since 2.0.08
1303 *
1304 * @param string $type - field type
1305 * @param string $html_id
1306 * @param string|boolean $opt_key
1307 *
1308 * @return string $other_id
1309 */
1310 public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) {
1311 $other_id = $html_id;
1312
1313 // If hidden radio field, add an opt key of 0
1314 if ( $type == 'radio' && $opt_key === false ) {
1315 $opt_key = 0;
1316 }
1317
1318 if ( $opt_key !== false ) {
1319 $other_id .= '-' . $opt_key;
1320 }
1321
1322 $other_id .= '-otext';
1323
1324 return $other_id;
1325 }
1326
1327 public static function switch_field_ids( $val ) {
1328 global $frm_duplicate_ids;
1329 $replace = array();
1330 $replace_with = array();
1331 foreach ( (array) $frm_duplicate_ids as $old => $new ) {
1332 $replace[] = '[if ' . $old . ']';
1333 $replace_with[] = '[if ' . $new . ']';
1334 $replace[] = '[if ' . $old . ' ';
1335 $replace_with[] = '[if ' . $new . ' ';
1336 $replace[] = '[/if ' . $old . ']';
1337 $replace_with[] = '[/if ' . $new . ']';
1338 $replace[] = '[\/if ' . $old . ']';
1339 $replace_with[] = '[\/if ' . $new . ']';
1340 $replace[] = '[foreach ' . $old . ']';
1341 $replace_with[] = '[foreach ' . $new . ']';
1342 $replace[] = '[/foreach ' . $old . ']';
1343 $replace_with[] = '[/foreach ' . $new . ']';
1344 $replace[] = '[\/foreach ' . $old . ']';
1345 $replace_with[] = '[\/foreach ' . $new . ']';
1346 $replace[] = '[' . $old . ']';
1347 $replace_with[] = '[' . $new . ']';
1348 $replace[] = '[' . $old . ' ';
1349 $replace_with[] = '[' . $new . ' ';
1350 unset( $old, $new );
1351 }
1352 if ( is_array( $val ) ) {
1353 foreach ( $val as $k => $v ) {
1354 if ( is_string( $v ) ) {
1355 $val[ $k ] = str_replace( $replace, $replace_with, $v );
1356 unset( $k, $v );
1357 }
1358 }
1359 } else {
1360 $val = str_replace( $replace, $replace_with, $val );
1361 }
1362
1363 return $val;
1364 }
1365
1366 /**
1367 * @since 4.0
1368 */
1369 public static function bulk_options_overlay() {
1370 $prepop = array();
1371 self::get_bulk_prefilled_opts( $prepop, true );
1372
1373 include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/bulk-options-overlay.php' );
1374 }
1375
1376 public static function get_us_states() {
1377 $states = array(
1378 'AL' => 'Alabama',
1379 'AK' => 'Alaska',
1380 'AR' => 'Arkansas',
1381 'AZ' => 'Arizona',
1382 'CA' => 'California',
1383 'CO' => 'Colorado',
1384 'CT' => 'Connecticut',
1385 'DE' => 'Delaware',
1386 'DC' => 'District of Columbia',
1387 'FL' => 'Florida',
1388 'GA' => 'Georgia',
1389 'HI' => 'Hawaii',
1390 'ID' => 'Idaho',
1391 'IL' => 'Illinois',
1392 'IN' => 'Indiana',
1393 'IA' => 'Iowa',
1394 'KS' => 'Kansas',
1395 'KY' => 'Kentucky',
1396 'LA' => 'Louisiana',
1397 'ME' => 'Maine',
1398 'MD' => 'Maryland',
1399 'MA' => 'Massachusetts',
1400 'MI' => 'Michigan',
1401 'MN' => 'Minnesota',
1402 'MS' => 'Mississippi',
1403 'MO' => 'Missouri',
1404 'MT' => 'Montana',
1405 'NE' => 'Nebraska',
1406 'NV' => 'Nevada',
1407 'NH' => 'New Hampshire',
1408 'NJ' => 'New Jersey',
1409 'NM' => 'New Mexico',
1410 'NY' => 'New York',
1411 'NC' => 'North Carolina',
1412 'ND' => 'North Dakota',
1413 'OH' => 'Ohio',
1414 'OK' => 'Oklahoma',
1415 'OR' => 'Oregon',
1416 'PA' => 'Pennsylvania',
1417 'RI' => 'Rhode Island',
1418 'SC' => 'South Carolina',
1419 'SD' => 'South Dakota',
1420 'TN' => 'Tennessee',
1421 'TX' => 'Texas',
1422 'UT' => 'Utah',
1423 'VT' => 'Vermont',
1424 'VA' => 'Virginia',
1425 'WA' => 'Washington',
1426 'WV' => 'West Virginia',
1427 'WI' => 'Wisconsin',
1428 'WY' => 'Wyoming',
1429 );
1430
1431 return apply_filters( 'frm_us_states', $states );
1432 }
1433
1434 public static function get_countries() {
1435 $countries = array(
1436 __( 'Afghanistan', 'formidable' ),
1437 __( 'Aland Islands', 'formidable' ),
1438 __( 'Albania', 'formidable' ),
1439 __( 'Algeria', 'formidable' ),
1440 __( 'American Samoa', 'formidable' ),
1441 __( 'Andorra', 'formidable' ),
1442 __( 'Angola', 'formidable' ),
1443 __( 'Anguilla', 'formidable' ),
1444 __( 'Antarctica', 'formidable' ),
1445 __( 'Antigua and Barbuda', 'formidable' ),
1446 __( 'Argentina', 'formidable' ),
1447 __( 'Armenia', 'formidable' ),
1448 __( 'Aruba', 'formidable' ),
1449 __( 'Australia', 'formidable' ),
1450 __( 'Austria', 'formidable' ),
1451 __( 'Azerbaijan', 'formidable' ),
1452 __( 'Bahamas', 'formidable' ),
1453 __( 'Bahrain', 'formidable' ),
1454 __( 'Bangladesh', 'formidable' ),
1455 __( 'Barbados', 'formidable' ),
1456 __( 'Belarus', 'formidable' ),
1457 __( 'Belgium', 'formidable' ),
1458 __( 'Belize', 'formidable' ),
1459 __( 'Benin', 'formidable' ),
1460 __( 'Bermuda', 'formidable' ),
1461 __( 'Bhutan', 'formidable' ),
1462 __( 'Bolivia', 'formidable' ),
1463 __( 'Bonaire, Sint Eustatius and Saba', 'formidable' ),
1464 __( 'Bosnia and Herzegovina', 'formidable' ),
1465 __( 'Botswana', 'formidable' ),
1466 __( 'Bouvet Island', 'formidable' ),
1467 __( 'Brazil', 'formidable' ),
1468 __( 'British Indian Ocean Territory', 'formidable' ),
1469 __( 'Brunei', 'formidable' ),
1470 __( 'Bulgaria', 'formidable' ),
1471 __( 'Burkina Faso', 'formidable' ),
1472 __( 'Burundi', 'formidable' ),
1473 __( 'Cambodia', 'formidable' ),
1474 __( 'Cameroon', 'formidable' ),
1475 __( 'Canada', 'formidable' ),
1476 __( 'Cape Verde', 'formidable' ),
1477 __( 'Cayman Islands', 'formidable' ),
1478 __( 'Central African Republic', 'formidable' ),
1479 __( 'Chad', 'formidable' ),
1480 __( 'Chile', 'formidable' ),
1481 __( 'China', 'formidable' ),
1482 __( 'Christmas Island', 'formidable' ),
1483 __( 'Cocos (Keeling) Islands', 'formidable' ),
1484 __( 'Colombia', 'formidable' ),
1485 __( 'Comoros', 'formidable' ),
1486 __( 'Congo', 'formidable' ),
1487 __( 'Cook Islands', 'formidable' ),
1488 __( 'Costa Rica', 'formidable' ),
1489 __( 'C&ocirc;te d\'Ivoire', 'formidable' ),
1490 __( 'Croatia', 'formidable' ),
1491 __( 'Cuba', 'formidable' ),
1492 __( 'Curacao', 'formidable' ),
1493 __( 'Cyprus', 'formidable' ),
1494 __( 'Czech Republic', 'formidable' ),
1495 __( 'Denmark', 'formidable' ),
1496 __( 'Djibouti', 'formidable' ),
1497 __( 'Dominica', 'formidable' ),
1498 __( 'Dominican Republic', 'formidable' ),
1499 __( 'East Timor', 'formidable' ),
1500 __( 'Ecuador', 'formidable' ),
1501 __( 'Egypt', 'formidable' ),
1502 __( 'El Salvador', 'formidable' ),
1503 __( 'Equatorial Guinea', 'formidable' ),
1504 __( 'Eritrea', 'formidable' ),
1505 __( 'Estonia', 'formidable' ),
1506 __( 'Ethiopia', 'formidable' ),
1507 __( 'Falkland Islands (Malvinas)', 'formidable' ),
1508 __( 'Faroe Islands', 'formidable' ),
1509 __( 'Fiji', 'formidable' ),
1510 __( 'Finland', 'formidable' ),
1511 __( 'France', 'formidable' ),
1512 __( 'French Guiana', 'formidable' ),
1513 __( 'French Polynesia', 'formidable' ),
1514 __( 'French Southern Territories', 'formidable' ),
1515 __( 'Gabon', 'formidable' ),
1516 __( 'Gambia', 'formidable' ),
1517 __( 'Georgia', 'formidable' ),
1518 __( 'Germany', 'formidable' ),
1519 __( 'Ghana', 'formidable' ),
1520 __( 'Gibraltar', 'formidable' ),
1521 __( 'Greece', 'formidable' ),
1522 __( 'Greenland', 'formidable' ),
1523 __( 'Grenada', 'formidable' ),
1524 __( 'Guadeloupe', 'formidable' ),
1525 __( 'Guam', 'formidable' ),
1526 __( 'Guatemala', 'formidable' ),
1527 __( 'Guernsey', 'formidable' ),
1528 __( 'Guinea', 'formidable' ),
1529 __( 'Guinea-Bissau', 'formidable' ),
1530 __( 'Guyana', 'formidable' ),
1531 __( 'Haiti', 'formidable' ),
1532 __( 'Heard Island and McDonald Islands', 'formidable' ),
1533 __( 'Holy See', 'formidable' ),
1534 __( 'Honduras', 'formidable' ),
1535 __( 'Hong Kong', 'formidable' ),
1536 __( 'Hungary', 'formidable' ),
1537 __( 'Iceland', 'formidable' ),
1538 __( 'India', 'formidable' ),
1539 __( 'Indonesia', 'formidable' ),
1540 __( 'Iran', 'formidable' ),
1541 __( 'Iraq', 'formidable' ),
1542 __( 'Ireland', 'formidable' ),
1543 __( 'Israel', 'formidable' ),
1544 __( 'Isle of Man', 'formidable' ),
1545 __( 'Italy', 'formidable' ),
1546 __( 'Jamaica', 'formidable' ),
1547 __( 'Japan', 'formidable' ),
1548 __( 'Jersey', 'formidable' ),
1549 __( 'Jordan', 'formidable' ),
1550 __( 'Kazakhstan', 'formidable' ),
1551 __( 'Kenya', 'formidable' ),
1552 __( 'Kiribati', 'formidable' ),
1553 __( 'North Korea', 'formidable' ),
1554 __( 'South Korea', 'formidable' ),
1555 __( 'Kosovo', 'formidable' ),
1556 __( 'Kuwait', 'formidable' ),
1557 __( 'Kyrgyzstan', 'formidable' ),
1558 __( 'Laos', 'formidable' ),
1559 __( 'Latvia', 'formidable' ),
1560 __( 'Lebanon', 'formidable' ),
1561 __( 'Lesotho', 'formidable' ),
1562 __( 'Liberia', 'formidable' ),
1563 __( 'Libya', 'formidable' ),
1564 __( 'Liechtenstein', 'formidable' ),
1565 __( 'Lithuania', 'formidable' ),
1566 __( 'Luxembourg', 'formidable' ),
1567 __( 'Macao', 'formidable' ),
1568 __( 'Macedonia', 'formidable' ),
1569 __( 'Madagascar', 'formidable' ),
1570 __( 'Malawi', 'formidable' ),
1571 __( 'Malaysia', 'formidable' ),
1572 __( 'Maldives', 'formidable' ),
1573 __( 'Mali', 'formidable' ),
1574 __( 'Malta', 'formidable' ),
1575 __( 'Marshall Islands', 'formidable' ),
1576 __( 'Martinique', 'formidable' ),
1577 __( 'Mauritania', 'formidable' ),
1578 __( 'Mauritius', 'formidable' ),
1579 __( 'Mayotte', 'formidable' ),
1580 __( 'Mexico', 'formidable' ),
1581 __( 'Micronesia', 'formidable' ),
1582 __( 'Moldova', 'formidable' ),
1583 __( 'Monaco', 'formidable' ),
1584 __( 'Mongolia', 'formidable' ),
1585 __( 'Montenegro', 'formidable' ),
1586 __( 'Montserrat', 'formidable' ),
1587 __( 'Morocco', 'formidable' ),
1588 __( 'Mozambique', 'formidable' ),
1589 __( 'Myanmar', 'formidable' ),
1590 __( 'Namibia', 'formidable' ),
1591 __( 'Nauru', 'formidable' ),
1592 __( 'Nepal', 'formidable' ),
1593 __( 'Netherlands', 'formidable' ),
1594 __( 'New Caledonia', 'formidable' ),
1595 __( 'New Zealand', 'formidable' ),
1596 __( 'Nicaragua', 'formidable' ),
1597 __( 'Niger', 'formidable' ),
1598 __( 'Nigeria', 'formidable' ),
1599 __( 'Niue', 'formidable' ),
1600 __( 'Norfolk Island', 'formidable' ),
1601 __( 'Northern Mariana Islands', 'formidable' ),
1602 __( 'Norway', 'formidable' ),
1603 __( 'Oman', 'formidable' ),
1604 __( 'Pakistan', 'formidable' ),
1605 __( 'Palau', 'formidable' ),
1606 __( 'Palestine', 'formidable' ),
1607 __( 'Panama', 'formidable' ),
1608 __( 'Papua New Guinea', 'formidable' ),
1609 __( 'Paraguay', 'formidable' ),
1610 __( 'Peru', 'formidable' ),
1611 __( 'Philippines', 'formidable' ),
1612 __( 'Pitcairn', 'formidable' ),
1613 __( 'Poland', 'formidable' ),
1614 __( 'Portugal', 'formidable' ),
1615 __( 'Puerto Rico', 'formidable' ),
1616 __( 'Qatar', 'formidable' ),
1617 __( 'Reunion', 'formidable' ),
1618 __( 'Romania', 'formidable' ),
1619 __( 'Russia', 'formidable' ),
1620 __( 'Rwanda', 'formidable' ),
1621 __( 'Saint Barthelemy', 'formidable' ),
1622 __( 'Saint Helena, Ascension and Tristan da Cunha', 'formidable' ),
1623 __( 'Saint Kitts and Nevis', 'formidable' ),
1624 __( 'Saint Lucia', 'formidable' ),
1625 __( 'Saint Martin (French part)', 'formidable' ),
1626 __( 'Saint Pierre and Miquelon', 'formidable' ),
1627 __( 'Saint Vincent and the Grenadines', 'formidable' ),
1628 __( 'Samoa', 'formidable' ),
1629 __( 'San Marino', 'formidable' ),
1630 __( 'Sao Tome and Principe', 'formidable' ),
1631 __( 'Saudi Arabia', 'formidable' ),
1632 __( 'Senegal', 'formidable' ),
1633 __( 'Serbia', 'formidable' ),
1634 __( 'Seychelles', 'formidable' ),
1635 __( 'Sierra Leone', 'formidable' ),
1636 __( 'Singapore', 'formidable' ),
1637 __( 'Sint Maarten (Dutch part)', 'formidable' ),
1638 __( 'Slovakia', 'formidable' ),
1639 __( 'Slovenia', 'formidable' ),
1640 __( 'Solomon Islands', 'formidable' ),
1641 __( 'Somalia', 'formidable' ),
1642 __( 'South Africa', 'formidable' ),
1643 __( 'South Georgia and the South Sandwich Islands', 'formidable' ),
1644 __( 'South Sudan', 'formidable' ),
1645 __( 'Spain', 'formidable' ),
1646 __( 'Sri Lanka', 'formidable' ),
1647 __( 'Sudan', 'formidable' ),
1648 __( 'Suriname', 'formidable' ),
1649 __( 'Svalbard and Jan Mayen', 'formidable' ),
1650 __( 'Swaziland', 'formidable' ),
1651 __( 'Sweden', 'formidable' ),
1652 __( 'Switzerland', 'formidable' ),
1653 __( 'Syria', 'formidable' ),
1654 __( 'Taiwan', 'formidable' ),
1655 __( 'Tajikistan', 'formidable' ),
1656 __( 'Tanzania', 'formidable' ),
1657 __( 'Thailand', 'formidable' ),
1658 __( 'Timor-Leste', 'formidable' ),
1659 __( 'Togo', 'formidable' ),
1660 __( 'Tokelau', 'formidable' ),
1661 __( 'Tonga', 'formidable' ),
1662 __( 'Trinidad and Tobago', 'formidable' ),
1663 __( 'Tunisia', 'formidable' ),
1664 __( 'Turkey', 'formidable' ),
1665 __( 'Turkmenistan', 'formidable' ),
1666 __( 'Turks and Caicos Islands', 'formidable' ),
1667 __( 'Tuvalu', 'formidable' ),
1668 __( 'Uganda', 'formidable' ),
1669 __( 'Ukraine', 'formidable' ),
1670 __( 'United Arab Emirates', 'formidable' ),
1671 __( 'United Kingdom', 'formidable' ),
1672 __( 'United States', 'formidable' ),
1673 __( 'United States Minor Outlying Islands', 'formidable' ),
1674 __( 'Uruguay', 'formidable' ),
1675 __( 'Uzbekistan', 'formidable' ),
1676 __( 'Vanuatu', 'formidable' ),
1677 __( 'Vatican City', 'formidable' ),
1678 __( 'Venezuela', 'formidable' ),
1679 __( 'Vietnam', 'formidable' ),
1680 __( 'Virgin Islands, British', 'formidable' ),
1681 __( 'Virgin Islands, U.S.', 'formidable' ),
1682 __( 'Wallis and Futuna', 'formidable' ),
1683 __( 'Western Sahara', 'formidable' ),
1684 __( 'Yemen', 'formidable' ),
1685 __( 'Zambia', 'formidable' ),
1686 __( 'Zimbabwe', 'formidable' ),
1687 );
1688
1689 sort( $countries, SORT_LOCALE_STRING );
1690 return apply_filters( 'frm_countries', $countries );
1691 }
1692
1693 /**
1694 * Gets bulk prefilled options.
1695 *
1696 * @since 5.0.04 Add `$include_class` param.
1697 *
1698 * @param array $prepop Bulk options.
1699 * @param array|false $include_class Include the class in the bulk options.
1700 */
1701 public static function get_bulk_prefilled_opts( array &$prepop, $include_class = false ) {
1702 // Countries.
1703 $countries = self::get_countries();
1704 if ( $include_class ) {
1705 $countries['class'] = 'frm-countries-opts';
1706 }
1707
1708 $prepop[ __( 'Countries', 'formidable' ) ] = $countries;
1709
1710 // State abv.
1711 $states = self::get_us_states();
1712 $state_abv = array_keys( $states );
1713 sort( $state_abv );
1714 if ( $include_class ) {
1715 $state_abv['class'] = 'frm-state-abv-opts';
1716 }
1717
1718 $prepop[ __( 'U.S. State Abbreviations', 'formidable' ) ] = $state_abv;
1719
1720 // States.
1721 $states = array_values( $states );
1722 sort( $states );
1723 if ( $include_class ) {
1724 $states['class'] = 'frm-states-opts';
1725 }
1726
1727 $prepop[ __( 'U.S. States', 'formidable' ) ] = $states;
1728 unset( $state_abv, $states );
1729
1730 // Age.
1731 $ages = array(
1732 __( 'Under 18', 'formidable' ),
1733 __( '18-24', 'formidable' ),
1734 __( '25-34', 'formidable' ),
1735 __( '35-44', 'formidable' ),
1736 __( '45-54', 'formidable' ),
1737 __( '55-64', 'formidable' ),
1738 __( '65 or Above', 'formidable' ),
1739 __( 'Prefer Not to Answer', 'formidable' ),
1740 );
1741 if ( $include_class ) {
1742 $ages['class'] = 'frm-age-opts';
1743 }
1744
1745 $prepop[ __( 'Age', 'formidable' ) ] = $ages;
1746
1747 // Satisfaction.
1748 $satisfaction = array(
1749 __( 'Very Unsatisfied', 'formidable' ),
1750 __( 'Unsatisfied', 'formidable' ),
1751 __( 'Neutral', 'formidable' ),
1752 __( 'Satisfied', 'formidable' ),
1753 __( 'Very Satisfied', 'formidable' ),
1754 __( 'N/A', 'formidable' ),
1755 );
1756 if ( $include_class ) {
1757 $satisfaction['class'] = 'frm-satisfaction-opts';
1758 }
1759
1760 $prepop[ __( 'Satisfaction', 'formidable' ) ] = $satisfaction;
1761
1762 // Importance.
1763 $importance = array(
1764 __( 'Not at all Important', 'formidable' ),
1765 __( 'Somewhat Important', 'formidable' ),
1766 __( 'Neutral', 'formidable' ),
1767 __( 'Important', 'formidable' ),
1768 __( 'Very Important', 'formidable' ),
1769 __( 'N/A', 'formidable' ),
1770 );
1771 if ( $include_class ) {
1772 $importance['class'] = 'frm-importance-opts';
1773 }
1774
1775 $prepop[ __( 'Importance', 'formidable' ) ] = $importance;
1776
1777 // Agreement.
1778 $agreement = array(
1779 __( 'Strongly Disagree', 'formidable' ),
1780 __( 'Disagree', 'formidable' ),
1781 __( 'Neutral', 'formidable' ),
1782 __( 'Agree', 'formidable' ),
1783 __( 'Strongly Agree', 'formidable' ),
1784 __( 'N/A', 'formidable' ),
1785 );
1786 if ( $include_class ) {
1787 $agreement['class'] = 'frm-agreement-opts';
1788 }
1789
1790 $prepop[ __( 'Agreement', 'formidable' ) ] = $agreement;
1791
1792 // Likely.
1793 $likely = array(
1794 __( 'Extremely Unlikely', 'formidable' ),
1795 __( 'Unlikely', 'formidable' ),
1796 __( 'Neutral', 'formidable' ),
1797 __( 'Likely', 'formidable' ),
1798 __( 'Extremely Likely', 'formidable' ),
1799 __( 'N/A', 'formidable' ),
1800 );
1801 if ( $include_class ) {
1802 $likely['class'] = 'frm-likely-opts';
1803 }
1804
1805 $prepop[ __( 'Likely', 'formidable' ) ] = $likely;
1806
1807 $prepop = apply_filters( 'frm_bulk_field_choices', $prepop );
1808 }
1809
1810 /**
1811 * Display a field value selector
1812 *
1813 * @since 2.03.05
1814 *
1815 * @param int $selector_field_id
1816 * @param array $selector_args
1817 */
1818 public static function display_field_value_selector( $selector_field_id, $selector_args ) {
1819 $field_value_selector = FrmFieldFactory::create_field_value_selector( $selector_field_id, $selector_args );
1820 $field_value_selector->display();
1821 }
1822
1823 /**
1824 * Convert a field object to a flat array
1825 *
1826 * @since 2.03.05
1827 *
1828 * @param object $field
1829 *
1830 * @return array
1831 */
1832 public static function convert_field_object_to_flat_array( $field ) {
1833 $field_options = $field->field_options;
1834 $field_array = get_object_vars( $field );
1835 unset( $field_array['field_options'] );
1836
1837 return $field_array + $field_options;
1838 }
1839
1840 /**
1841 * @since 4.04
1842 * @param array $args
1843 */
1844 public static function show_add_field_buttons( $args ) {
1845 $field_key = $args['field_key'];
1846 $field_type = $args['field_type'];
1847 $field_label = FrmAppHelper::icon_by_class( FrmFormsHelper::get_field_link_icon( $field_type ), array( 'echo' => false ) );
1848 $field_name = FrmFormsHelper::get_field_link_name( $field_type );
1849 $field_label .= ' <span>' . $field_name . '</span>';
1850
1851 // If the individual field isn't allowed, disable it.
1852 $run_filter = true;
1853 $single_no_allow = ' ';
1854 $install_data = '';
1855 $requires = '';
1856 $link = isset( $field_type['link'] ) ? esc_url_raw( $field_type['link'] ) : '';
1857 $has_show_upgrade_class = strpos( $field_type['icon'], ' frm_show_upgrade' );
1858 $show_upgrade = $has_show_upgrade_class || false !== strpos( $args['no_allow_class'], 'frm_show_upgrade' );
1859
1860 if ( $has_show_upgrade_class ) {
1861 $single_no_allow .= 'frm_show_upgrade';
1862 $field_type['icon'] = str_replace( ' frm_show_upgrade', '', $field_type['icon'] );
1863 $run_filter = false;
1864 if ( isset( $field_type['addon'] ) ) {
1865 $upgrading = FrmAddonsController::install_link( $field_type['addon'] );
1866 if ( isset( $upgrading['url'] ) ) {
1867 $install_data = json_encode( $upgrading );
1868 }
1869 $requires = FrmFormsHelper::get_plan_required( $upgrading );
1870 } elseif ( isset( $field_type['require'] ) ) {
1871 $requires = $field_type['require'];
1872 }
1873 }
1874
1875 $upgrade_label = '';
1876 $upgrade_message = '';
1877 if ( $show_upgrade ) {
1878 /* translators: %s: Field name */
1879 $upgrade_label = sprintf( esc_html__( '%s fields', 'formidable' ), $field_name );
1880
1881 if ( isset( $field_type['message'] ) ) {
1882 $upgrade_message = FrmAppHelper::kses( $field_type['message'], array( 'a', 'img' ) );
1883 }
1884 }
1885
1886 $li_params = array(
1887 'class' => 'frmbutton frm6 ' . $args['no_allow_class'] . $single_no_allow . ' frm_t' . str_replace( '|', '-', $field_key ),
1888 'id' => $field_key,
1889 'data-upgrade' => $upgrade_label,
1890 'data-link' => $link,
1891 'data-medium' => 'builder',
1892 'data-oneclick' => $install_data,
1893 'data-content' => $field_key,
1894 'data-requires' => $requires,
1895 );
1896
1897 if ( $upgrade_message ) {
1898 $li_params['data-message'] = $upgrade_message;
1899 }
1900 ?>
1901 <li <?php FrmAppHelper::array_to_html_params( $li_params, true ); ?>>
1902 <?php
1903 if ( $run_filter ) {
1904 $field_label = apply_filters( 'frmpro_field_links', $field_label, $args['id'], $field_key );
1905 }
1906 echo FrmAppHelper::kses( $field_label, array( 'a', 'i', 'span', 'use', 'svg' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1907 ?>
1908 </li>
1909 <?php
1910 }
1911
1912 /**
1913 * Shows Display format option.
1914 *
1915 * @since 5.0.04
1916 *
1917 * @param array $field Field data.
1918 */
1919 public static function show_radio_display_format( $field ) {
1920 $options = array(
1921 '0' => array(
1922 'text' => __( 'Simple', 'formidable' ),
1923 'svg' => 'frm_simple_radio',
1924 ),
1925 '1' => array(
1926 'text' => __( 'Images', 'formidable' ),
1927 'svg' => 'frm_image_as_option',
1928 'addon' => 'pro',
1929 'upgrade' => __( 'Image Options', 'formidable' ),
1930 'message' => __( 'Show images instead of radio buttons or check boxes. This is ideal for polls, surveys, segmenting questionnaires and more.', 'formidable' ) . '<img src="' . esc_url( FrmAppHelper::plugin_url() ) . '/images/image-options.png" />',
1931 'content' => 'image-options',
1932 ),
1933 'buttons' => array(
1934 'text' => __( 'Buttons', 'formidable' ),
1935 'svg' => 'frm_button_as_option',
1936 'addon' => 'surveys',
1937 'upgrade' => __( 'Button Options', 'formidable' ),
1938 'message' => __( 'Show buttons for radio buttons or check boxes. This is ideal for polls, surveys, segmenting questionnaires and more.', 'formidable' ),
1939 'content' => 'button-options',
1940 ),
1941 );
1942
1943 /**
1944 * Allows modifying the options of Display format setting of Radio field.
1945 *
1946 * @since 5.0.04
1947 *
1948 * @param array $options Options.
1949 */
1950 $options = apply_filters( 'frm_radio_display_format_options', $options );
1951
1952 $args = self::get_display_format_args( $field, $options );
1953
1954 include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/radio-display-format.php';
1955 }
1956
1957 /**
1958 * Gets display format arguments to pass to the images_dropdown() method.
1959 *
1960 * @since 5.0.04
1961 *
1962 * @param array $field Field data.
1963 * @param array $options Options array.
1964 * @return array
1965 */
1966 private static function get_display_format_args( $field, $options ) {
1967 $args = array(
1968 'selected' => '0',
1969 'options' => array(),
1970 'name' => 'field_options[image_options_' . $field['id'] . ']',
1971 'input_attrs' => array(
1972 'class' => 'frm_toggle_image_options',
1973 ),
1974 );
1975
1976 self::fill_image_setting_options( $options, $args );
1977
1978 /**
1979 * Allows modifying the arguments of Display format setting of Radio field.
1980 *
1981 * @since 5.0.04
1982 *
1983 * @param array $args Arguments.
1984 * @param array $method_args The arguments from the method. Contains `field`, `options`.
1985 */
1986 return apply_filters( 'frm_radio_display_format_args', $args, compact( 'field', 'options' ) );
1987 }
1988
1989 /**
1990 * @since 5.0.04
1991 */
1992 private static function fill_image_setting_options( $options, &$args ) {
1993 foreach ( $options as $key => $option ) {
1994 $args['options'][ $key ] = $option;
1995
1996 if ( ! empty( $option['addon'] ) ) {
1997 $args['options'][ $key ]['custom_attrs'] = self::fill_image_setting_addon_link( $option );
1998 }
1999
2000 unset( $args['options'][ $key ]['addon'] );
2001 $fill = array( 'upgrade', 'message', 'content' );
2002 foreach ( $fill as $f ) {
2003 unset( $args['options'][ $key ][ $f ], $f );
2004 }
2005 }
2006 }
2007
2008 /**
2009 * @since 5.0.04
2010 *
2011 * @return array
2012 */
2013 private static function fill_image_setting_addon_link( $option ) {
2014 $custom_attrs = array(
2015 'class' => 'frm_noallow frm_show_upgrade',
2016 'data-medium' => 'builder',
2017 );
2018
2019 // translators: Add-on name.
2020 $custom_attrs['data-upgrade'] = sprintf( __( 'Formidable %s', 'formidable' ), ucwords( $option['addon'] ) );
2021
2022 $fill = array( 'upgrade', 'message', 'content' );
2023 foreach ( $fill as $f ) {
2024 if ( isset( $option[ $f ] ) ) {
2025 $custom_attrs[ 'data-' . $f ] = $option[ $f ];
2026 }
2027 }
2028
2029 if ( 'pro' === $option['addon'] ) {
2030 return $custom_attrs;
2031 }
2032
2033 $upgrading = FrmAddonsController::install_link( $option['addon'] );
2034 if ( isset( $upgrading['url'] ) ) {
2035 $install_data = wp_json_encode( $upgrading );
2036 } else {
2037 $install_data = '';
2038 }
2039
2040 $custom_attrs['data-oneclick'] = $install_data;
2041 $custom_attrs['data-requires'] = FrmFormsHelper::get_plan_required( $upgrading );
2042
2043 return $custom_attrs;
2044 }
2045
2046 /**
2047 * @deprecated 4.0
2048 */
2049 public static function show_icon_link_js( $atts ) {
2050 _deprecated_function( __METHOD__, '4.0' );
2051 $atts['icon'] .= $atts['is_selected'] ? ' ' : ' frm_inactive_icon ';
2052 if ( isset( $atts['has_default'] ) && ! $atts['has_default'] ) {
2053 $atts['icon'] .= 'frm_hidden ';
2054 }
2055 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>';
2056 }
2057
2058 /**
2059 * @deprecated 4.0
2060 */
2061 public static function show_default_blank_js( $is_selected, $has_default_value = true ) {
2062 _deprecated_function( __METHOD__, '4.0' );
2063 }
2064
2065 /**
2066 * @deprecated 4.0
2067 */
2068 public static function clear_on_focus_html( $field, $display, $id = '' ) {
2069 _deprecated_function( __METHOD__, '4.0' );
2070 }
2071
2072 /**
2073 * @deprecated 4.0
2074 */
2075 public static function show_onfocus_js( $is_selected, $has_default_value = true ) {
2076 _deprecated_function( __METHOD__, '4.0' );
2077 }
2078
2079 /**
2080 * @deprecated 3.0
2081 * @codeCoverageIgnore
2082 */
2083 public static function display_recaptcha() {
2084 _deprecated_function( __FUNCTION__, '3.0', 'FrmFieldCaptcha::field_input' );
2085 }
2086
2087 /**
2088 * @deprecated 3.0
2089 * @codeCoverageIgnore
2090 */
2091 public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) {
2092 FrmDeprecated::remove_inline_conditions( $no_vars, $code, $replace_with, $html );
2093 }
2094
2095 /**
2096 * @deprecated 3.0
2097 * @codeCoverageIgnore
2098 */
2099 public static function get_shortcode_tag( $shortcodes, $short_key, $args ) {
2100 return FrmDeprecated::get_shortcode_tag( $shortcodes, $short_key, $args );
2101 }
2102
2103 /**
2104 * @deprecated 3.0
2105 * @codeCoverageIgnore
2106 *
2107 * @param string $html
2108 * @param array $field
2109 * @param array $errors
2110 * @param object|false $form
2111 * @param array $args
2112 *
2113 * @return string
2114 */
2115 public static function replace_shortcodes( $html, $field, $errors = array(), $form = false, $args = array() ) {
2116 return FrmDeprecated::replace_shortcodes( $html, $field, $errors, $form, $args );
2117 }
2118
2119 /**
2120 * @deprecated 3.0
2121 * @codeCoverageIgnore
2122 */
2123 public static function get_default_field_opts( $type, $field = null, $limit = false ) {
2124 return FrmDeprecated::get_default_field_opts( $type, $field, $limit );
2125 }
2126
2127 /**
2128 * @deprecated 2.02.07
2129 * @codeCoverageIgnore
2130 */
2131 public static function dropdown_categories( $args ) {
2132 return FrmDeprecated::dropdown_categories( $args );
2133 }
2134 }
2135