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

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