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

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