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

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