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

1,863 lines 55.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmFieldsHelper {
7
8 public static function setup_new_vars( $type = '', $form_id = '' ) {
9
10 if ( strpos( $type, '|' ) ) {
11 list( $type, $setting ) = explode( '|', $type );
12 }
13
14 $values = self::get_default_field( $type );
15
16 global $wpdb;
17 $field_count = FrmDb::get_var( 'frm_fields', array( 'form_id' => $form_id ), 'field_order', array( 'order_by' => 'field_order DESC' ) );
18
19 $values['field_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_fields', 'field_key' );
20 $values['form_id'] = $form_id;
21 $values['field_order'] = $field_count + 1;
22
23 $values['field_options']['custom_html'] = self::get_default_html( $type );
24
25 if ( isset( $setting ) && ! empty( $setting ) ) {
26 if ( in_array( $type, array( 'data', 'lookup' ) ) ) {
27 $values['field_options']['data_type'] = $setting;
28 } else {
29 $values['field_options'][ $setting ] = 1;
30 }
31 }
32
33 return $values;
34 }
35
36 public static function get_html_id( $field, $plus = '' ) {
37 return apply_filters( 'frm_field_html_id', 'field_' . $field['field_key'] . $plus, $field );
38 }
39
40 public static function setup_edit_vars( $field, $doing_ajax = false ) {
41 $values = self::field_object_to_array( $field );
42
43 return apply_filters( 'frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax ) );
44 }
45
46 public static function field_object_to_array( $field ) {
47 $values = (array) $field;
48
49 self::fill_field_array( $field, $values );
50
51 $values['custom_html'] = ( isset( $field->field_options['custom_html'] ) ) ? $field->field_options['custom_html'] : self::get_default_html( $field->type );
52
53 return $values;
54 }
55
56 private static function fill_field_array( $field, array &$field_array ) {
57 $field_array['options'] = $field->options;
58 $field_array['value'] = $field->default_value;
59
60 self::prepare_edit_front_field( $field_array, $field );
61
62 $field_array = array_merge( (array) $field->field_options, $field_array );
63 }
64
65 /**
66 * Prepare field while creating a new entry
67 *
68 * @since 3.0
69 */
70 public static function prepare_new_front_field( &$field_array, $field, $args = array() ) {
71 $args['action'] = 'new';
72 self::prepare_front_field( $field_array, $field, $args );
73 }
74
75 /**
76 * Prepare field while editing an entry
77 *
78 * @since 3.0
79 */
80 public static function prepare_edit_front_field( &$field_array, $field, $entry_id = 0, $args = array() ) {
81 $args['entry_id'] = $entry_id;
82 $args['action'] = 'edit';
83 self::prepare_front_field( $field_array, $field, $args );
84 }
85
86 /**
87 * Prepare field while creating a new entry
88 *
89 * @since 3.0
90 */
91 private static function prepare_front_field( &$field_array, $field, $args ) {
92 self::fill_default_field_opts( $field, $field_array );
93 self::fill_cleared_strings( $field, $field_array );
94
95 // Track the original field's type
96 $field_array['original_type'] = isset( $field->field_options['original_type'] ) ? $field->field_options['original_type'] : $field->type;
97
98 self::prepare_field_options_for_display( $field_array, $field, $args );
99
100 if ( $args['action'] == 'edit' ) {
101 $field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $args['entry_id'], $args );
102 } else {
103 $field_array = apply_filters( 'frm_setup_new_fields_vars', $field_array, $field, $args );
104 }
105 }
106
107 /**
108 * @since 3.0
109 *
110 * @param string $type
111 *
112 * @return array
113 */
114 public static function get_default_field_options( $type ) {
115 $field_type = FrmFieldFactory::get_field_type( $type );
116
117 return $field_type->get_default_field_options();
118 }
119
120 /**
121 * @since 3.0
122 *
123 * @param object $field
124 * @param array $values
125 */
126 private static function fill_default_field_opts( $field, array &$values ) {
127 $check_post = FrmAppHelper::is_admin_page() && $_POST && isset( $_POST['field_options'] );
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 }
594
595 return $m;
596 }
597
598 /**
599 * Trim and sanitize the values
600 *
601 * @since 2.05
602 */
603 private static function get_value_for_comparision( $value ) {
604 // Remove white space from hide_opt
605 if ( ! is_array( $value ) ) {
606 $value = trim( $value );
607 }
608
609 FrmAppHelper::sanitize_value( 'wp_kses_post', $value );
610
611 return $value;
612 }
613
614 public static function array_value_condition( $observed_value, $cond, $hide_opt ) {
615 $m = false;
616 if ( $cond == '==' ) {
617 if ( is_array( $hide_opt ) ) {
618 $m = array_intersect( $hide_opt, $observed_value );
619 $m = empty( $m ) ? false : true;
620 } else {
621 $m = in_array( $hide_opt, $observed_value );
622 }
623 } elseif ( $cond == '!=' ) {
624 $m = ! in_array( $hide_opt, $observed_value );
625 } elseif ( $cond == '>' ) {
626 $min = min( $observed_value );
627 $m = $min > $hide_opt;
628 } elseif ( $cond == '<' ) {
629 $max = max( $observed_value );
630 $m = $max < $hide_opt;
631 } elseif ( $cond == 'LIKE' || $cond == 'not LIKE' ) {
632 foreach ( $observed_value as $ob ) {
633 $m = strpos( $ob, $hide_opt );
634 if ( $m !== false ) {
635 $m = true;
636 break;
637 }
638 }
639
640 if ( $cond == 'not LIKE' ) {
641 $m = ( $m === false ) ? true : false;
642 }
643 }
644
645 return $m;
646 }
647
648 /**
649 * Replace a few basic shortcodes and field ids
650 *
651 * @since 2.0
652 * @return string
653 */
654 public static function basic_replace_shortcodes( $value, $form, $entry ) {
655 if ( strpos( $value, '[sitename]' ) !== false ) {
656 $new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
657 $value = str_replace( '[sitename]', $new_value, $value );
658 }
659
660 $value = apply_filters( 'frm_content', $value, $form, $entry );
661 $value = do_shortcode( $value );
662
663 return $value;
664 }
665
666 public static function get_shortcodes( $content, $form_id ) {
667 if ( FrmAppHelper::pro_is_installed() ) {
668 return FrmProDisplaysHelper::get_shortcodes( $content, $form_id );
669 }
670
671 $fields = FrmField::getAll(
672 array(
673 'fi.form_id' => (int) $form_id,
674 'fi.type not' => FrmField::no_save_fields(),
675 )
676 );
677
678 $tagregexp = self::allowed_shortcodes( $fields );
679
680 preg_match_all( "/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER );
681
682 return $matches;
683 }
684
685 public static function allowed_shortcodes( $fields = array() ) {
686 $tagregexp = array(
687 'editlink',
688 'id',
689 'key',
690 'ip',
691 'siteurl',
692 'sitename',
693 'admin_email',
694 'post[-|_]id',
695 'created[-|_]at',
696 'updated[-|_]at',
697 'updated[-|_]by',
698 'parent[-|_]id',
699 );
700
701 foreach ( $fields as $field ) {
702 $tagregexp[] = $field->id;
703 $tagregexp[] = $field->field_key;
704 }
705
706 $tagregexp = implode( '|', $tagregexp );
707
708 return $tagregexp;
709 }
710
711 public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
712 foreach ( $shortcodes[0] as $short_key => $tag ) {
713 if ( empty( $tag ) ) {
714 continue;
715 }
716
717 $atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[3][ $short_key ] );
718 $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key );
719
720 $atts['entry'] = $entry;
721 $atts['tag'] = $tag;
722 $replace_with = self::get_value_for_shortcode( $atts );
723
724 if ( $replace_with !== null ) {
725 self::sanitize_embedded_shortcodes( compact( 'entry' ), $replace_with );
726 $content = str_replace( $shortcodes[0][ $short_key ], $replace_with, $content );
727 }
728
729 unset( $atts, $replace_with );
730 }
731
732 return $content;
733 }
734
735 /**
736 * Prevent shortcodes in fields from being processed
737 *
738 * @since 3.01.02
739 *
740 * @param array $atts - includes entry object
741 * @param string $value
742 */
743 public static function sanitize_embedded_shortcodes( $atts, &$value ) {
744 $atts['value'] = $value;
745 $should_sanitize = apply_filters( 'frm_sanitize_shortcodes', true, $atts );
746 if ( $should_sanitize ) {
747 $value = str_replace( '[', '&#91;', $value );
748 }
749 }
750
751 /**
752 * @since 3.0
753 *
754 * @param $atts
755 *
756 * @return string
757 */
758 private static function get_value_for_shortcode( $atts ) {
759 $clean_tag = str_replace( '-', '_', $atts['tag'] );
760
761 $shortcode_values = array(
762 'id' => $atts['entry']->id,
763 'key' => $atts['entry']->item_key,
764 'ip' => $atts['entry']->ip,
765 );
766
767 $dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get' );
768
769 if ( isset( $shortcode_values[ $atts['tag'] ] ) ) {
770 $replace_with = $shortcode_values[ $atts['tag'] ];
771 } elseif ( in_array( $atts['tag'], $dynamic_default ) ) {
772 $replace_with = self::dynamic_default_values( $atts['tag'], $atts );
773 } elseif ( $clean_tag == 'user_agent' ) {
774 $description = $atts['entry']->description;
775 $replace_with = FrmEntriesHelper::get_browser( $description['browser'] );
776 } elseif ( $clean_tag == 'created_at' || $clean_tag == 'updated_at' ) {
777 $atts['tag'] = $clean_tag;
778 $replace_with = self::get_entry_timestamp( $atts );
779 } elseif ( $clean_tag == 'created_by' || $clean_tag == 'updated_by' ) {
780 $replace_with = self::get_display_value( $atts['entry']->{$clean_tag}, (object) array( 'type' => 'user_id' ), $atts );
781 } else {
782 $replace_with = self::get_field_shortcode_value( $atts );
783 }
784
785 return $replace_with;
786 }
787
788 /**
789 * @since 3.0
790 *
791 * @param $atts
792 *
793 * @return string
794 */
795 private static function get_entry_timestamp( $atts ) {
796 if ( isset( $atts['format'] ) ) {
797 $time_format = ' ';
798 } else {
799 $atts['format'] = get_option( 'date_format' );
800 $time_format = '';
801 }
802
803 return FrmAppHelper::get_formatted_time( $atts['entry']->{$atts['tag']}, $atts['format'], $time_format );
804 }
805
806 /**
807 * @since 3.0
808 *
809 * @param $atts
810 *
811 * @return null|string
812 */
813 private static function get_field_shortcode_value( $atts ) {
814 $field = FrmField::getOne( $atts['tag'] );
815 if ( empty( $field ) ) {
816 return null;
817 }
818
819 if ( isset( $atts['show'] ) && $atts['show'] == 'field_label' ) {
820 $replace_with = $field->name;
821 } elseif ( isset( $atts['show'] ) && $atts['show'] == 'description' ) {
822 $replace_with = $field->description;
823 } else {
824 $replace_with = FrmEntryMeta::get_meta_value( $atts['entry'], $field->id );
825 $string_value = $replace_with;
826 if ( is_array( $replace_with ) ) {
827 $sep = isset( $atts['sep'] ) ? $atts['sep'] : ', ';
828 $string_value = implode( $sep, $replace_with );
829 }
830
831 if ( empty( $string_value ) && $string_value != '0' ) {
832 $replace_with = '';
833 } else {
834 $atts['entry_id'] = $atts['entry']->id;
835 $atts['entry_key'] = $atts['entry']->item_key;
836 $replace_with = self::get_display_value( $replace_with, $field, $atts );
837 }
838 }
839
840 return $replace_with;
841 }
842
843 /**
844 * Get the value to replace a few standard shortcodes
845 *
846 * @since 2.0
847 * @return string
848 */
849 public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) {
850 $new_value = '';
851 switch ( $tag ) {
852 case 'admin_email':
853 $new_value = get_option( 'admin_email' );
854 break;
855 case 'siteurl':
856 $new_value = FrmAppHelper::site_url();
857 break;
858 case 'frmurl':
859 $new_value = FrmAppHelper::plugin_url();
860 break;
861 case 'sitename':
862 $new_value = FrmAppHelper::site_name();
863 break;
864 case 'get':
865 $new_value = self::process_get_shortcode( $atts, $return_array );
866 }
867
868 return $new_value;
869 }
870
871 /**
872 * Process the [get] shortcode
873 *
874 * @since 2.0
875 * @return string|array
876 */
877 public static function process_get_shortcode( $atts, $return_array = false ) {
878 if ( ! isset( $atts['param'] ) ) {
879 return '';
880 }
881
882 if ( strpos( $atts['param'], '&#91;' ) ) {
883 $atts['param'] = str_replace( '&#91;', '[', $atts['param'] );
884 $atts['param'] = str_replace( '&#93;', ']', $atts['param'] );
885 }
886
887 $new_value = FrmAppHelper::get_param( $atts['param'], '', 'get', 'sanitize_text_field' );
888 $new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] );
889
890 if ( $new_value == '' ) {
891 if ( ! isset( $atts['prev_val'] ) ) {
892 $atts['prev_val'] = '';
893 }
894
895 $new_value = isset( $atts['default'] ) ? $atts['default'] : $atts['prev_val'];
896 }
897
898 if ( is_array( $new_value ) && ! $return_array ) {
899 $new_value = implode( ', ', $new_value );
900 }
901
902 return $new_value;
903 }
904
905 public static function get_display_value( $value, $field, $atts = array() ) {
906
907 $value = apply_filters( 'frm_get_' . $field->type . '_display_value', $value, $field, $atts );
908 $value = apply_filters( 'frm_get_display_value', $value, $field, $atts );
909
910 $value = self::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) );
911
912 return apply_filters( 'frm_display_value', $value, $field, $atts );
913 }
914
915 /**
916 * @param $atts array Includes value, field, and atts
917 */
918 public static function get_unfiltered_display_value( $atts ) {
919 $value = $atts['value'];
920 $field = $atts['field'];
921 $atts = isset( $atts['atts'] ) ? $atts['atts'] : $atts;
922
923 if ( is_array( $field ) ) {
924 $field = $field['id'];
925 }
926
927 $field_obj = FrmFieldFactory::get_field_object( $field );
928
929 return $field_obj->get_display_value( $value, $atts );
930 }
931
932 /**
933 * Get a value from the user profile from the user ID
934 *
935 * @since 3.0
936 */
937 public static function get_user_display_name( $user_id, $user_info = 'display_name', $args = array() ) {
938 $defaults = array(
939 'blank' => false,
940 'link' => false,
941 'size' => 96,
942 );
943
944 $args = wp_parse_args( $args, $defaults );
945
946 $user = get_userdata( $user_id );
947 $info = '';
948
949 if ( $user ) {
950 if ( $user_info == 'avatar' ) {
951 $info = get_avatar( $user_id, $args['size'] );
952 } elseif ( $user_info == 'author_link' ) {
953 $info = get_author_posts_url( $user_id );
954 } else {
955 $info = isset( $user->$user_info ) ? $user->$user_info : '';
956 }
957
958 if ( 'display_name' === $user_info && empty( $info ) && ! $args['blank'] ) {
959 $info = $user->user_login;
960 }
961 }
962
963 if ( $args['link'] ) {
964 $info = '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $user_id ) ) . '">' . $info . '</a>';
965 }
966
967 return $info;
968 }
969
970 public static function get_field_types( $type ) {
971 $single_input = self::single_input_fields();
972 $multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' );
973
974 $field_selection = FrmField::all_field_selection();
975
976 $field_types = array();
977 if ( in_array( $type, $single_input ) ) {
978 self::field_types_for_input( $single_input, $field_selection, $field_types );
979 } elseif ( in_array( $type, $multiple_input ) ) {
980 self::field_types_for_input( $multiple_input, $field_selection, $field_types );
981 } elseif ( isset( $field_selection[ $type ] ) ) {
982 $field_types[ $type ] = $field_selection[ $type ];
983 }
984
985 $field_types = apply_filters( 'frm_switch_field_types', $field_types, compact( 'type' ) );
986
987 return $field_types;
988 }
989
990 /**
991 * Get a list of all fields that use a single value input.
992 *
993 * @since 4.0
994 */
995 public static function single_input_fields() {
996 $fields = array(
997 'text',
998 'textarea',
999 'rte',
1000 'number',
1001 'email',
1002 'url',
1003 'date',
1004 'phone',
1005 'hidden',
1006 'time',
1007 'tag',
1008 'password',
1009 );
1010 return apply_filters( 'frm_single_input_fields', $fields );
1011 }
1012
1013 private static function field_types_for_input( $inputs, $fields, &$field_types ) {
1014 foreach ( $inputs as $input ) {
1015 $field_types[ $input ] = $fields[ $input ];
1016 unset( $input );
1017 }
1018 }
1019
1020 /**
1021 * Check if current field option is an "other" option
1022 *
1023 * @since 2.0.6
1024 *
1025 * @param string $opt_key
1026 *
1027 * @return boolean Returns true if current field option is an "Other" option
1028 */
1029 public static function is_other_opt( $opt_key ) {
1030 return $opt_key && strpos( $opt_key, 'other_' ) === 0;
1031 }
1032
1033 /**
1034 * Get value that belongs in "Other" text box
1035 *
1036 * @since 2.0.6
1037 *
1038 * @param array $args
1039 */
1040 public static function get_other_val( $args ) {
1041 $defaults = array(
1042 'opt_key' => 0,
1043 'field' => array(),
1044 'parent' => false,
1045 'pointer' => false,
1046 );
1047 $args = wp_parse_args( $args, $defaults );
1048
1049 $opt_key = $args['opt_key'];
1050 $field = $args['field'];
1051 $parent = $args['parent'];
1052 $pointer = $args['pointer'];
1053 $other_val = '';
1054
1055 // If option is an "other" option and there is a value set for this field,
1056 // check if the value belongs in the current "Other" option text field
1057 if ( ! self::is_other_opt( $opt_key ) || ! FrmField::is_option_true( $field, 'value' ) ) {
1058 return $other_val;
1059 }
1060
1061 // Check posted vals before checking saved values
1062 // For fields inside repeating sections - note, don't check if $pointer is true because it will often be zero
1063 if ( $parent && isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ) {
1064 if ( FrmField::is_field_with_multiple_values( $field ) ) {
1065 $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 ] ) ) : '';
1066 } else {
1067 $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) );
1068 }
1069
1070 return $other_val;
1071
1072 } elseif ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) {
1073 // For normal fields
1074
1075 if ( FrmField::is_field_with_multiple_values( $field ) ) {
1076 $other_val = isset( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ) : '';
1077 } else {
1078 $other_val = sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ] ) );
1079 }
1080
1081 return $other_val;
1082 }
1083
1084 // For checkboxes
1085 if ( $field['type'] == 'checkbox' && is_array( $field['value'] ) ) {
1086 // Check if there is an "other" val in saved value and make sure the
1087 // "other" val is not equal to the Other checkbox option
1088 if ( isset( $field['value'][ $opt_key ] ) && $field['options'][ $opt_key ] != $field['value'][ $opt_key ] ) {
1089 $other_val = $field['value'][ $opt_key ];
1090 }
1091 } else {
1092 /**
1093 * For radio buttons and dropdowns
1094 * Check if saved value equals any of the options. If not, set it as the other value.
1095 */
1096 foreach ( $field['options'] as $opt_key => $opt_val ) {
1097 $temp_val = is_array( $opt_val ) ? $opt_val['value'] : $opt_val;
1098 // Multi-select dropdowns - key is not preserved
1099 if ( is_array( $field['value'] ) ) {
1100 $o_key = array_search( $temp_val, $field['value'] );
1101 if ( isset( $field['value'][ $o_key ] ) ) {
1102 unset( $field['value'][ $o_key ], $o_key );
1103 }
1104 } elseif ( $temp_val == $field['value'] ) {
1105 // For radio and regular dropdowns
1106 return '';
1107 } else {
1108 $other_val = $field['value'];
1109 }
1110 unset( $opt_key, $opt_val, $temp_val );
1111 }
1112 // For multi-select dropdowns only
1113 if ( is_array( $field['value'] ) && ! empty( $field['value'] ) ) {
1114 $other_val = reset( $field['value'] );
1115 }
1116 }
1117
1118 return $other_val;
1119 }
1120
1121 /**
1122 * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val.
1123 * Intended for front-end use
1124 *
1125 * @since 2.0.6
1126 *
1127 * @param array $args should include field, opt_key and field name
1128 * @param boolean $other_opt
1129 * @param string $checked
1130 *
1131 * @return array $other_args
1132 */
1133 public static function prepare_other_input( $args, &$other_opt, &$checked ) {
1134 $other_args = array(
1135 'name' => '',
1136 'value' => '',
1137 );
1138
1139 //Check if this is an "Other" option
1140 if ( ! self::is_other_opt( $args['opt_key'] ) ) {
1141 return $other_args;
1142 }
1143
1144 $other_opt = true;
1145
1146 self::set_other_name( $args, $other_args );
1147 self::set_other_value( $args, $other_args );
1148
1149 if ( '' !== $other_args['value'] ) {
1150 $checked = 'checked="checked" ';
1151 }
1152
1153 return $other_args;
1154 }
1155
1156 /**
1157 * @param array $args
1158 * @param array $other_args
1159 *
1160 * @since 2.0.6
1161 */
1162 private static function set_other_name( $args, &$other_args ) {
1163 //Set up name for other field
1164 $other_args['name'] = str_replace( '[]', '', $args['field_name'] );
1165 $other_args['name'] = preg_replace( '/\[' . $args['field']['id'] . '\]$/', '', $other_args['name'] );
1166 $other_args['name'] = $other_args['name'] . '[other][' . $args['field']['id'] . ']';
1167
1168 //Converts item_meta[field_id] => item_meta[other][field_id] and
1169 //item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id]
1170 if ( FrmField::is_field_with_multiple_values( $args['field'] ) ) {
1171 $other_args['name'] .= '[' . $args['opt_key'] . ']';
1172 }
1173 }
1174
1175 /**
1176 * Find the parent and pointer, and get text for "other" text field
1177 *
1178 * @param array $args
1179 * @param array $other_args
1180 *
1181 * @since 2.0.6
1182 */
1183 private static function set_other_value( $args, &$other_args ) {
1184 $parent = '';
1185 $pointer = '';
1186
1187 // Check for parent ID and pointer
1188 $temp_array = explode( '[', $args['field_name'] );
1189
1190 // Count should only be greater than 3 if inside of a repeating section
1191 if ( count( $temp_array ) > 3 ) {
1192 $parent = str_replace( ']', '', $temp_array[1] );
1193 $pointer = str_replace( ']', '', $temp_array[2] );
1194 }
1195
1196 // Get text for "other" text field
1197 $other_args['value'] = self::get_other_val(
1198 array(
1199 'opt_key' => $args['opt_key'],
1200 'field' => $args['field'],
1201 'parent' => $parent,
1202 'pointer' => $pointer,
1203 )
1204 );
1205 }
1206
1207 /**
1208 * If this field includes an other option, show it
1209 *
1210 * @param $args array
1211 *
1212 * @since 2.0.6
1213 */
1214 public static function include_other_input( $args ) {
1215 if ( ! $args['other_opt'] ) {
1216 return;
1217 }
1218
1219 $classes = array( 'frm_other_input' );
1220 if ( ! $args['checked'] || trim( $args['checked'] ) == '' ) {
1221 // hide the field if the other option is not selected
1222 $classes[] = 'frm_pos_none';
1223 }
1224 if ( $args['field']['type'] == 'select' && $args['field']['multiple'] ) {
1225 $classes[] = 'frm_other_full';
1226 }
1227
1228 // Set up HTML ID for Other field
1229 $other_id = self::get_other_field_html_id( $args['field']['type'], $args['html_id'], $args['opt_key'] );
1230
1231 $label = isset( $args['opt_label'] ) ? $args['opt_label'] : $args['field']['name'];
1232
1233 echo '<label for="' . esc_attr( $other_id ) . '" class="frm_screen_reader frm_hidden">' .
1234 esc_html( $label ) .
1235 '</label>' .
1236 '<input type="text" id="' . esc_attr( $other_id ) . '" class="' . esc_attr( implode( ' ', $classes ) ) . '" ' .
1237 ( $args['read_only'] ? ' readonly="readonly" disabled="disabled"' : '' ) .
1238 ' name="' . esc_attr( $args['name'] ) . '" value="' . esc_attr( $args['value'] ) . '" />';
1239 }
1240
1241 /**
1242 * Get the HTML id for an "Other" text field
1243 * Note: This does not affect fields in repeating sections
1244 *
1245 * @since 2.0.08
1246 *
1247 * @param string $type - field type
1248 * @param string $html_id
1249 * @param string|boolean $opt_key
1250 *
1251 * @return string $other_id
1252 */
1253 public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) {
1254 $other_id = $html_id;
1255
1256 // If hidden radio field, add an opt key of 0
1257 if ( $type == 'radio' && $opt_key === false ) {
1258 $opt_key = 0;
1259 }
1260
1261 if ( $opt_key !== false ) {
1262 $other_id .= '-' . $opt_key;
1263 }
1264
1265 $other_id .= '-otext';
1266
1267 return $other_id;
1268 }
1269
1270 public static function switch_field_ids( $val ) {
1271 global $frm_duplicate_ids;
1272 $replace = array();
1273 $replace_with = array();
1274 foreach ( (array) $frm_duplicate_ids as $old => $new ) {
1275 $replace[] = '[if ' . $old . ']';
1276 $replace_with[] = '[if ' . $new . ']';
1277 $replace[] = '[if ' . $old . ' ';
1278 $replace_with[] = '[if ' . $new . ' ';
1279 $replace[] = '[/if ' . $old . ']';
1280 $replace_with[] = '[/if ' . $new . ']';
1281 $replace[] = '[foreach ' . $old . ']';
1282 $replace_with[] = '[foreach ' . $new . ']';
1283 $replace[] = '[/foreach ' . $old . ']';
1284 $replace_with[] = '[/foreach ' . $new . ']';
1285 $replace[] = '[' . $old . ']';
1286 $replace_with[] = '[' . $new . ']';
1287 $replace[] = '[' . $old . ' ';
1288 $replace_with[] = '[' . $new . ' ';
1289 unset( $old, $new );
1290 }
1291 if ( is_array( $val ) ) {
1292 foreach ( $val as $k => $v ) {
1293 if ( is_string( $v ) ) {
1294 $val[ $k ] = str_replace( $replace, $replace_with, $v );
1295 unset( $k, $v );
1296 }
1297 }
1298 } else {
1299 $val = str_replace( $replace, $replace_with, $val );
1300 }
1301
1302 return $val;
1303 }
1304
1305 /**
1306 * @since 4.0
1307 */
1308 public static function bulk_options_overlay() {
1309 $prepop = array();
1310 self::get_bulk_prefilled_opts( $prepop );
1311
1312 include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/bulk-options-overlay.php' );
1313 }
1314
1315 public static function get_us_states() {
1316 $states = array(
1317 'AL' => 'Alabama',
1318 'AK' => 'Alaska',
1319 'AR' => 'Arkansas',
1320 'AZ' => 'Arizona',
1321 'CA' => 'California',
1322 'CO' => 'Colorado',
1323 'CT' => 'Connecticut',
1324 'DE' => 'Delaware',
1325 'DC' => 'District of Columbia',
1326 'FL' => 'Florida',
1327 'GA' => 'Georgia',
1328 'HI' => 'Hawaii',
1329 'ID' => 'Idaho',
1330 'IL' => 'Illinois',
1331 'IN' => 'Indiana',
1332 'IA' => 'Iowa',
1333 'KS' => 'Kansas',
1334 'KY' => 'Kentucky',
1335 'LA' => 'Louisiana',
1336 'ME' => 'Maine',
1337 'MD' => 'Maryland',
1338 'MA' => 'Massachusetts',
1339 'MI' => 'Michigan',
1340 'MN' => 'Minnesota',
1341 'MS' => 'Mississippi',
1342 'MO' => 'Missouri',
1343 'MT' => 'Montana',
1344 'NE' => 'Nebraska',
1345 'NV' => 'Nevada',
1346 'NH' => 'New Hampshire',
1347 'NJ' => 'New Jersey',
1348 'NM' => 'New Mexico',
1349 'NY' => 'New York',
1350 'NC' => 'North Carolina',
1351 'ND' => 'North Dakota',
1352 'OH' => 'Ohio',
1353 'OK' => 'Oklahoma',
1354 'OR' => 'Oregon',
1355 'PA' => 'Pennsylvania',
1356 'RI' => 'Rhode Island',
1357 'SC' => 'South Carolina',
1358 'SD' => 'South Dakota',
1359 'TN' => 'Tennessee',
1360 'TX' => 'Texas',
1361 'UT' => 'Utah',
1362 'VT' => 'Vermont',
1363 'VA' => 'Virginia',
1364 'WA' => 'Washington',
1365 'WV' => 'West Virginia',
1366 'WI' => 'Wisconsin',
1367 'WY' => 'Wyoming',
1368 );
1369
1370 return apply_filters( 'frm_us_states', $states );
1371 }
1372
1373 public static function get_countries() {
1374 $countries = array(
1375 __( 'Afghanistan', 'formidable' ),
1376 __( 'Aland Islands', 'formidable' ),
1377 __( 'Albania', 'formidable' ),
1378 __( 'Algeria', 'formidable' ),
1379 __( 'American Samoa', 'formidable' ),
1380 __( 'Andorra', 'formidable' ),
1381 __( 'Angola', 'formidable' ),
1382 __( 'Anguilla', 'formidable' ),
1383 __( 'Antarctica', 'formidable' ),
1384 __( 'Antigua and Barbuda', 'formidable' ),
1385 __( 'Argentina', 'formidable' ),
1386 __( 'Armenia', 'formidable' ),
1387 __( 'Aruba', 'formidable' ),
1388 __( 'Australia', 'formidable' ),
1389 __( 'Austria', 'formidable' ),
1390 __( 'Azerbaijan', 'formidable' ),
1391 __( 'Bahamas', 'formidable' ),
1392 __( 'Bahrain', 'formidable' ),
1393 __( 'Bangladesh', 'formidable' ),
1394 __( 'Barbados', 'formidable' ),
1395 __( 'Belarus', 'formidable' ),
1396 __( 'Belgium', 'formidable' ),
1397 __( 'Belize', 'formidable' ),
1398 __( 'Benin', 'formidable' ),
1399 __( 'Bermuda', 'formidable' ),
1400 __( 'Bhutan', 'formidable' ),
1401 __( 'Bolivia', 'formidable' ),
1402 __( 'Bonaire, Sint Eustatius and Saba', 'formidable' ),
1403 __( 'Bosnia and Herzegovina', 'formidable' ),
1404 __( 'Botswana', 'formidable' ),
1405 __( 'Bouvet Island', 'formidable' ),
1406 __( 'Brazil', 'formidable' ),
1407 __( 'British Indian Ocean Territory', 'formidable' ),
1408 __( 'Brunei', 'formidable' ),
1409 __( 'Bulgaria', 'formidable' ),
1410 __( 'Burkina Faso', 'formidable' ),
1411 __( 'Burundi', 'formidable' ),
1412 __( 'Cambodia', 'formidable' ),
1413 __( 'Cameroon', 'formidable' ),
1414 __( 'Canada', 'formidable' ),
1415 __( 'Cape Verde', 'formidable' ),
1416 __( 'Cayman Islands', 'formidable' ),
1417 __( 'Central African Republic', 'formidable' ),
1418 __( 'Chad', 'formidable' ),
1419 __( 'Chile', 'formidable' ),
1420 __( 'China', 'formidable' ),
1421 __( 'Christmas Island', 'formidable' ),
1422 __( 'Cocos (Keeling) Islands', 'formidable' ),
1423 __( 'Colombia', 'formidable' ),
1424 __( 'Comoros', 'formidable' ),
1425 __( 'Congo', 'formidable' ),
1426 __( 'Cook Islands', 'formidable' ),
1427 __( 'Costa Rica', 'formidable' ),
1428 __( 'C&ocirc;te d\'Ivoire', 'formidable' ),
1429 __( 'Croatia', 'formidable' ),
1430 __( 'Cuba', 'formidable' ),
1431 __( 'Curacao', 'formidable' ),
1432 __( 'Cyprus', 'formidable' ),
1433 __( 'Czech Republic', 'formidable' ),
1434 __( 'Denmark', 'formidable' ),
1435 __( 'Djibouti', 'formidable' ),
1436 __( 'Dominica', 'formidable' ),
1437 __( 'Dominican Republic', 'formidable' ),
1438 __( 'East Timor', 'formidable' ),
1439 __( 'Ecuador', 'formidable' ),
1440 __( 'Egypt', 'formidable' ),
1441 __( 'El Salvador', 'formidable' ),
1442 __( 'Equatorial Guinea', 'formidable' ),
1443 __( 'Eritrea', 'formidable' ),
1444 __( 'Estonia', 'formidable' ),
1445 __( 'Ethiopia', 'formidable' ),
1446 __( 'Falkland Islands (Malvinas)', 'formidable' ),
1447 __( 'Faroe Islands', 'formidable' ),
1448 __( 'Fiji', 'formidable' ),
1449 __( 'Finland', 'formidable' ),
1450 __( 'France', 'formidable' ),
1451 __( 'French Guiana', 'formidable' ),
1452 __( 'French Polynesia', 'formidable' ),
1453 __( 'French Southern Territories', 'formidable' ),
1454 __( 'Gabon', 'formidable' ),
1455 __( 'Gambia', 'formidable' ),
1456 __( 'Georgia', 'formidable' ),
1457 __( 'Germany', 'formidable' ),
1458 __( 'Ghana', 'formidable' ),
1459 __( 'Gibraltar', 'formidable' ),
1460 __( 'Greece', 'formidable' ),
1461 __( 'Greenland', 'formidable' ),
1462 __( 'Grenada', 'formidable' ),
1463 __( 'Guadeloupe', 'formidable' ),
1464 __( 'Guam', 'formidable' ),
1465 __( 'Guatemala', 'formidable' ),
1466 __( 'Guernsey', 'formidable' ),
1467 __( 'Guinea', 'formidable' ),
1468 __( 'Guinea-Bissau', 'formidable' ),
1469 __( 'Guyana', 'formidable' ),
1470 __( 'Haiti', 'formidable' ),
1471 __( 'Heard Island and McDonald Islands', 'formidable' ),
1472 __( 'Holy See', 'formidable' ),
1473 __( 'Honduras', 'formidable' ),
1474 __( 'Hong Kong', 'formidable' ),
1475 __( 'Hungary', 'formidable' ),
1476 __( 'Iceland', 'formidable' ),
1477 __( 'India', 'formidable' ),
1478 __( 'Indonesia', 'formidable' ),
1479 __( 'Iran', 'formidable' ),
1480 __( 'Iraq', 'formidable' ),
1481 __( 'Ireland', 'formidable' ),
1482 __( 'Israel', 'formidable' ),
1483 __( 'Isle of Man', 'formidable' ),
1484 __( 'Italy', 'formidable' ),
1485 __( 'Jamaica', 'formidable' ),
1486 __( 'Japan', 'formidable' ),
1487 __( 'Jersey', 'formidable' ),
1488 __( 'Jordan', 'formidable' ),
1489 __( 'Kazakhstan', 'formidable' ),
1490 __( 'Kenya', 'formidable' ),
1491 __( 'Kiribati', 'formidable' ),
1492 __( 'North Korea', 'formidable' ),
1493 __( 'South Korea', 'formidable' ),
1494 __( 'Kosovo', 'formidable' ),
1495 __( 'Kuwait', 'formidable' ),
1496 __( 'Kyrgyzstan', 'formidable' ),
1497 __( 'Laos', 'formidable' ),
1498 __( 'Latvia', 'formidable' ),
1499 __( 'Lebanon', 'formidable' ),
1500 __( 'Lesotho', 'formidable' ),
1501 __( 'Liberia', 'formidable' ),
1502 __( 'Libya', 'formidable' ),
1503 __( 'Liechtenstein', 'formidable' ),
1504 __( 'Lithuania', 'formidable' ),
1505 __( 'Luxembourg', 'formidable' ),
1506 __( 'Macao', 'formidable' ),
1507 __( 'Macedonia', 'formidable' ),
1508 __( 'Madagascar', 'formidable' ),
1509 __( 'Malawi', 'formidable' ),
1510 __( 'Malaysia', 'formidable' ),
1511 __( 'Maldives', 'formidable' ),
1512 __( 'Mali', 'formidable' ),
1513 __( 'Malta', 'formidable' ),
1514 __( 'Marshall Islands', 'formidable' ),
1515 __( 'Martinique', 'formidable' ),
1516 __( 'Mauritania', 'formidable' ),
1517 __( 'Mauritius', 'formidable' ),
1518 __( 'Mayotte', 'formidable' ),
1519 __( 'Mexico', 'formidable' ),
1520 __( 'Micronesia', 'formidable' ),
1521 __( 'Moldova', 'formidable' ),
1522 __( 'Monaco', 'formidable' ),
1523 __( 'Mongolia', 'formidable' ),
1524 __( 'Montenegro', 'formidable' ),
1525 __( 'Montserrat', 'formidable' ),
1526 __( 'Morocco', 'formidable' ),
1527 __( 'Mozambique', 'formidable' ),
1528 __( 'Myanmar', 'formidable' ),
1529 __( 'Namibia', 'formidable' ),
1530 __( 'Nauru', 'formidable' ),
1531 __( 'Nepal', 'formidable' ),
1532 __( 'Netherlands', 'formidable' ),
1533 __( 'New Caledonia', 'formidable' ),
1534 __( 'New Zealand', 'formidable' ),
1535 __( 'Nicaragua', 'formidable' ),
1536 __( 'Niger', 'formidable' ),
1537 __( 'Nigeria', 'formidable' ),
1538 __( 'Niue', 'formidable' ),
1539 __( 'Norfolk Island', 'formidable' ),
1540 __( 'Northern Mariana Islands', 'formidable' ),
1541 __( 'Norway', 'formidable' ),
1542 __( 'Oman', 'formidable' ),
1543 __( 'Pakistan', 'formidable' ),
1544 __( 'Palau', 'formidable' ),
1545 __( 'Palestine', 'formidable' ),
1546 __( 'Panama', 'formidable' ),
1547 __( 'Papua New Guinea', 'formidable' ),
1548 __( 'Paraguay', 'formidable' ),
1549 __( 'Peru', 'formidable' ),
1550 __( 'Philippines', 'formidable' ),
1551 __( 'Pitcairn', 'formidable' ),
1552 __( 'Poland', 'formidable' ),
1553 __( 'Portugal', 'formidable' ),
1554 __( 'Puerto Rico', 'formidable' ),
1555 __( 'Qatar', 'formidable' ),
1556 __( 'Reunion', 'formidable' ),
1557 __( 'Romania', 'formidable' ),
1558 __( 'Russia', 'formidable' ),
1559 __( 'Rwanda', 'formidable' ),
1560 __( 'Saint Barthelemy', 'formidable' ),
1561 __( 'Saint Helena, Ascension and Tristan da Cunha', 'formidable' ),
1562 __( 'Saint Kitts and Nevis', 'formidable' ),
1563 __( 'Saint Lucia', 'formidable' ),
1564 __( 'Saint Martin (French part)', 'formidable' ),
1565 __( 'Saint Pierre and Miquelon', 'formidable' ),
1566 __( 'Saint Vincent and the Grenadines', 'formidable' ),
1567 __( 'Samoa', 'formidable' ),
1568 __( 'San Marino', 'formidable' ),
1569 __( 'Sao Tome and Principe', 'formidable' ),
1570 __( 'Saudi Arabia', 'formidable' ),
1571 __( 'Senegal', 'formidable' ),
1572 __( 'Serbia', 'formidable' ),
1573 __( 'Seychelles', 'formidable' ),
1574 __( 'Sierra Leone', 'formidable' ),
1575 __( 'Singapore', 'formidable' ),
1576 __( 'Sint Maarten (Dutch part)', 'formidable' ),
1577 __( 'Slovakia', 'formidable' ),
1578 __( 'Slovenia', 'formidable' ),
1579 __( 'Solomon Islands', 'formidable' ),
1580 __( 'Somalia', 'formidable' ),
1581 __( 'South Africa', 'formidable' ),
1582 __( 'South Georgia and the South Sandwich Islands', 'formidable' ),
1583 __( 'South Sudan', 'formidable' ),
1584 __( 'Spain', 'formidable' ),
1585 __( 'Sri Lanka', 'formidable' ),
1586 __( 'Sudan', 'formidable' ),
1587 __( 'Suriname', 'formidable' ),
1588 __( 'Svalbard and Jan Mayen', 'formidable' ),
1589 __( 'Swaziland', 'formidable' ),
1590 __( 'Sweden', 'formidable' ),
1591 __( 'Switzerland', 'formidable' ),
1592 __( 'Syria', 'formidable' ),
1593 __( 'Taiwan', 'formidable' ),
1594 __( 'Tajikistan', 'formidable' ),
1595 __( 'Tanzania', 'formidable' ),
1596 __( 'Thailand', 'formidable' ),
1597 __( 'Timor-Leste', 'formidable' ),
1598 __( 'Togo', 'formidable' ),
1599 __( 'Tokelau', 'formidable' ),
1600 __( 'Tonga', 'formidable' ),
1601 __( 'Trinidad and Tobago', 'formidable' ),
1602 __( 'Tunisia', 'formidable' ),
1603 __( 'Turkey', 'formidable' ),
1604 __( 'Turkmenistan', 'formidable' ),
1605 __( 'Turks and Caicos Islands', 'formidable' ),
1606 __( 'Tuvalu', 'formidable' ),
1607 __( 'Uganda', 'formidable' ),
1608 __( 'Ukraine', 'formidable' ),
1609 __( 'United Arab Emirates', 'formidable' ),
1610 __( 'United Kingdom', 'formidable' ),
1611 __( 'United States', 'formidable' ),
1612 __( 'United States Minor Outlying Islands', 'formidable' ),
1613 __( 'Uruguay', 'formidable' ),
1614 __( 'Uzbekistan', 'formidable' ),
1615 __( 'Vanuatu', 'formidable' ),
1616 __( 'Vatican City', 'formidable' ),
1617 __( 'Venezuela', 'formidable' ),
1618 __( 'Vietnam', 'formidable' ),
1619 __( 'Virgin Islands, British', 'formidable' ),
1620 __( 'Virgin Islands, U.S.', 'formidable' ),
1621 __( 'Wallis and Futuna', 'formidable' ),
1622 __( 'Western Sahara', 'formidable' ),
1623 __( 'Yemen', 'formidable' ),
1624 __( 'Zambia', 'formidable' ),
1625 __( 'Zimbabwe', 'formidable' ),
1626 );
1627
1628 sort( $countries, SORT_LOCALE_STRING );
1629 return apply_filters( 'frm_countries', $countries );
1630 }
1631
1632 public static function get_bulk_prefilled_opts( array &$prepop ) {
1633 $prepop[ __( 'Countries', 'formidable' ) ] = self::get_countries();
1634
1635 $states = self::get_us_states();
1636 $state_abv = array_keys( $states );
1637 sort( $state_abv );
1638 $prepop[ __( 'U.S. State Abbreviations', 'formidable' ) ] = $state_abv;
1639
1640 $states = array_values( $states );
1641 sort( $states );
1642 $prepop[ __( 'U.S. States', 'formidable' ) ] = $states;
1643 unset( $state_abv, $states );
1644
1645 $prepop[ __( 'Age', 'formidable' ) ] = array(
1646 __( 'Under 18', 'formidable' ),
1647 __( '18-24', 'formidable' ),
1648 __( '25-34', 'formidable' ),
1649 __( '35-44', 'formidable' ),
1650 __( '45-54', 'formidable' ),
1651 __( '55-64', 'formidable' ),
1652 __( '65 or Above', 'formidable' ),
1653 __( 'Prefer Not to Answer', 'formidable' ),
1654 );
1655
1656 $prepop[ __( 'Satisfaction', 'formidable' ) ] = array(
1657 __( 'Very Satisfied', 'formidable' ),
1658 __( 'Satisfied', 'formidable' ),
1659 __( 'Neutral', 'formidable' ),
1660 __( 'Unsatisfied', 'formidable' ),
1661 __( 'Very Unsatisfied', 'formidable' ),
1662 __( 'N/A', 'formidable' ),
1663 );
1664
1665 $prepop[ __( 'Importance', 'formidable' ) ] = array(
1666 __( 'Very Important', 'formidable' ),
1667 __( 'Important', 'formidable' ),
1668 __( 'Neutral', 'formidable' ),
1669 __( 'Somewhat Important', 'formidable' ),
1670 __( 'Not at all Important', 'formidable' ),
1671 __( 'N/A', 'formidable' ),
1672 );
1673
1674 $prepop[ __( 'Agreement', 'formidable' ) ] = array(
1675 __( 'Strongly Agree', 'formidable' ),
1676 __( 'Agree', 'formidable' ),
1677 __( 'Neutral', 'formidable' ),
1678 __( 'Disagree', 'formidable' ),
1679 __( 'Strongly Disagree', 'formidable' ),
1680 __( 'N/A', 'formidable' ),
1681 );
1682
1683 $prepop = apply_filters( 'frm_bulk_field_choices', $prepop );
1684 }
1685
1686 /**
1687 * Display a field value selector
1688 *
1689 * @since 2.03.05
1690 *
1691 * @param int $selector_field_id
1692 * @param array $selector_args
1693 */
1694 public static function display_field_value_selector( $selector_field_id, $selector_args ) {
1695 $field_value_selector = FrmFieldFactory::create_field_value_selector( $selector_field_id, $selector_args );
1696 $field_value_selector->display();
1697 }
1698
1699 /**
1700 * Convert a field object to a flat array
1701 *
1702 * @since 2.03.05
1703 *
1704 * @param object $field
1705 *
1706 * @return array
1707 */
1708 public static function convert_field_object_to_flat_array( $field ) {
1709 $field_options = $field->field_options;
1710 $field_array = get_object_vars( $field );
1711 unset( $field_array['field_options'] );
1712
1713 return $field_array + $field_options;
1714 }
1715
1716 /**
1717 * @since 4.04
1718 * @param array $args
1719 */
1720 public static function show_add_field_buttons( $args ) {
1721 $field_key = $args['field_key'];
1722 $field_type = $args['field_type'];
1723 $field_label = FrmAppHelper::icon_by_class( FrmFormsHelper::get_field_link_icon( $field_type ), array( 'echo' => false ) );
1724 $field_name = FrmFormsHelper::get_field_link_name( $field_type );
1725 $field_label .= ' <span>' . $field_name . '</span>';
1726
1727 // If the individual field isn't allowed, disable it.
1728 $run_filter = true;
1729 $single_no_allow = ' ';
1730 $install_data = '';
1731 $requires = '';
1732 $link = isset( $field_type['link'] ) ? esc_url_raw( $field_type['link'] ) : '';
1733 $has_show_upgrade_class = strpos( $field_type['icon'], ' frm_show_upgrade' );
1734 $show_upgrade = $has_show_upgrade_class || false !== strpos( $args['no_allow_class'], 'frm_show_upgrade' );
1735
1736 if ( $has_show_upgrade_class ) {
1737 $single_no_allow .= 'frm_show_upgrade';
1738 $field_type['icon'] = str_replace( ' frm_show_upgrade', '', $field_type['icon'] );
1739 $run_filter = false;
1740 if ( isset( $field_type['addon'] ) ) {
1741 $upgrading = FrmAddonsController::install_link( $field_type['addon'] );
1742 if ( isset( $upgrading['url'] ) ) {
1743 $install_data = json_encode( $upgrading );
1744 }
1745 $requires = FrmFormsHelper::get_plan_required( $upgrading );
1746 } elseif ( isset( $field_type['require'] ) ) {
1747 $requires = $field_type['require'];
1748 }
1749 }
1750
1751 $upgrade_label = '';
1752 $upgrade_message = '';
1753 if ( $show_upgrade ) {
1754 /* translators: %s: Field name */
1755 $upgrade_label = sprintf( esc_html__( '%s fields', 'formidable' ), $field_name );
1756
1757 if ( isset( $field_type['message'] ) ) {
1758 $upgrade_message = FrmAppHelper::kses( $field_type['message'], array( 'a', 'img' ) );
1759 }
1760 }
1761
1762 ?>
1763 <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 ); ?>">
1764 <?php
1765 if ( $run_filter ) {
1766 $field_label = apply_filters( 'frmpro_field_links', $field_label, $args['id'], $field_key );
1767 }
1768 echo FrmAppHelper::kses( $field_label, array( 'a', 'i', 'span', 'use', 'svg' ) ); // WPCS: XSS ok.
1769 ?>
1770 </li>
1771 <?php
1772 }
1773
1774 /**
1775 * @deprecated 4.0
1776 */
1777 public static function show_icon_link_js( $atts ) {
1778 _deprecated_function( __METHOD__, '4.0' );
1779 $atts['icon'] .= $atts['is_selected'] ? ' ' : ' frm_inactive_icon ';
1780 if ( isset( $atts['has_default'] ) && ! $atts['has_default'] ) {
1781 $atts['icon'] .= 'frm_hidden ';
1782 }
1783 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>';
1784 }
1785
1786 /**
1787 * @deprecated 4.0
1788 */
1789 public static function show_default_blank_js( $is_selected, $has_default_value = true ) {
1790 _deprecated_function( __METHOD__, '4.0' );
1791 }
1792
1793 /**
1794 * @deprecated 4.0
1795 */
1796 public static function clear_on_focus_html( $field, $display, $id = '' ) {
1797 _deprecated_function( __METHOD__, '4.0' );
1798 }
1799
1800 /**
1801 * @deprecated 4.0
1802 */
1803 public static function show_onfocus_js( $is_selected, $has_default_value = true ) {
1804 _deprecated_function( __METHOD__, '4.0' );
1805 }
1806
1807 /**
1808 * @deprecated 3.0
1809 * @codeCoverageIgnore
1810 */
1811 public static function display_recaptcha() {
1812 _deprecated_function( __FUNCTION__, '3.0', 'FrmFieldCaptcha::field_input' );
1813 }
1814
1815 /**
1816 * @deprecated 3.0
1817 * @codeCoverageIgnore
1818 */
1819 public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) {
1820 FrmDeprecated::remove_inline_conditions( $no_vars, $code, $replace_with, $html );
1821 }
1822
1823 /**
1824 * @deprecated 3.0
1825 * @codeCoverageIgnore
1826 */
1827 public static function get_shortcode_tag( $shortcodes, $short_key, $args ) {
1828 return FrmDeprecated::get_shortcode_tag( $shortcodes, $short_key, $args );
1829 }
1830
1831 /**
1832 * @deprecated 3.0
1833 * @codeCoverageIgnore
1834 *
1835 * @param string $html
1836 * @param array $field
1837 * @param array $errors
1838 * @param object $form
1839 * @param array $args
1840 *
1841 * @return string
1842 */
1843 public static function replace_shortcodes( $html, $field, $errors = array(), $form = false, $args = array() ) {
1844 return FrmDeprecated::replace_shortcodes( $html, $field, $errors, $form, $args );
1845 }
1846
1847 /**
1848 * @deprecated 3.0
1849 * @codeCoverageIgnore
1850 */
1851 public static function get_default_field_opts( $type, $field = null, $limit = false ) {
1852 return FrmDeprecated::get_default_field_opts( $type, $field, $limit );
1853 }
1854
1855 /**
1856 * @deprecated 2.02.07
1857 * @codeCoverageIgnore
1858 */
1859 public static function dropdown_categories( $args ) {
1860 return FrmDeprecated::dropdown_categories( $args );
1861 }
1862 }
1863