PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0.07
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0.07
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / helpers / FrmFieldsHelper.php

FrmFieldsHelper.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 5.0.07, at classes/helpers/FrmFieldsHelper.php

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