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

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