Completed
Pull Request — master (#132)
by Stephanie
02:31
created

FrmFieldsHelper   F

Complexity

Total Complexity 264

Size/Duplication

Total Lines 1840
Duplicated Lines 0.33 %

Coupling/Cohesion

Components 4
Dependencies 14

Importance

Changes 0
Metric Value
dl 6
loc 1840
rs 0.8
c 0
b 0
f 0
wmc 264
lcom 4
cbo 14

79 Methods

Rating   Name   Duplication   Size   Complexity  
A setup_new_vars() 0 27 5
A get_html_id() 0 3 1
A setup_edit_vars() 0 5 1
A field_object_to_array() 0 9 2
A fill_field_array() 0 8 1
A prepare_new_front_field() 0 4 1
A prepare_edit_front_field() 0 5 1
A prepare_front_field() 0 15 3
A get_default_field_options() 0 5 1
B fill_default_field_opts() 0 19 7
B fill_cleared_strings() 0 20 6
A get_posted_field_setting() 0 18 4
A get_default_field_options_from_field() 0 9 1
A get_original_field() 0 8 3
A prepare_field_options_for_display() 0 4 1
A get_default_field() 0 5 1
A fill_field() 0 12 2
A get_error_msg() 0 33 3
A get_form_fields() 0 5 1
A get_default_html() 0 11 2
A show_fields() 0 6 2
A run_wpautop() 0 9 4
B label_position() 0 23 10
A is_placeholder_field_type() 0 3 1
A get_checkbox_id() 0 8 4
B show_single_option() 0 32 11
A hidden_field_option() 0 19 4
A get_default_value_type() 0 7 3
A get_value_from_array() 0 5 1
A get_label_from_array() 0 5 1
A inline_modal() 0 13 1
A smart_values() 0 10 2
A input_mask() 0 3 1
A layout_classes() 0 3 1
A get_term_link() 0 18 3
C value_meets_condition() 0 32 13
A get_value_for_comparision() 0 10 2
C array_value_condition() 0 33 13
A basic_replace_shortcodes() 0 11 2
A get_shortcodes() 0 18 2
A allowed_shortcodes() 0 25 2
A replace_content_shortcodes() 0 23 4
A sanitize_embedded_shortcodes() 0 7 2
B get_value_for_shortcode() 0 29 8
A get_entry_timestamp() 0 10 2
B get_field_shortcode_value() 0 29 10
B dynamic_default_values() 0 21 6
B process_get_shortcode() 0 27 8
A get_display_value() 0 7 1
A get_unfiltered_display_value() 0 13 3
B get_user_display_name() 0 32 9
A get_field_types() 0 19 4
A single_input_fields() 0 17 1
A field_types_for_input() 0 6 2
A is_other_opt() 0 3 2
D get_other_val() 6 81 22
A prepare_other_input() 0 18 3
A set_other_name() 0 12 2
A set_other_value() 0 23 2
B include_other_input() 0 26 8
A get_other_field_html_id() 0 16 4
A switch_field_ids() 0 32 4
A bulk_options_overlay() 0 6 1
B get_us_states() 0 57 1
B get_countries() 0 257 1
A get_bulk_prefilled_opts() 0 53 1
A display_field_value_selector() 0 4 1
A convert_field_object_to_flat_array() 0 7 1
B show_add_field_buttons() 0 47 8
A show_icon_link_js() 0 8 4
A show_default_blank_js() 0 3 1
A clear_on_focus_html() 0 3 1
A show_onfocus_js() 0 3 1
A display_recaptcha() 0 3 1
A remove_inline_conditions() 0 3 1
A get_shortcode_tag() 0 3 1
A replace_shortcodes() 0 3 1
A get_default_field_opts() 0 3 1
A dropdown_categories() 0 3 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like FrmFieldsHelper often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use FrmFieldsHelper, and based on these observations, apply Extract Interface, too.

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
	 */
396
	public static function is_placeholder_field_type( $type ) {
397
		return ! in_array( $type, array( 'radio', 'checkbox', 'hidden', 'file' ) );
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
		}
592
593
		return $m;
594
	}
595
596
	/**
597
	 * Trim and sanitize the values
598
	 *
599
	 * @since 2.05
600
	 */
601
	private static function get_value_for_comparision( $value ) {
602
		// Remove white space from hide_opt
603
		if ( ! is_array( $value ) ) {
604
			$value = trim( $value );
605
		}
606
607
		FrmAppHelper::sanitize_value( 'wp_kses_post', $value );
608
609
		return $value;
610
	}
611
612
	public static function array_value_condition( $observed_value, $cond, $hide_opt ) {
613
		$m = false;
614
		if ( $cond == '==' ) {
615
			if ( is_array( $hide_opt ) ) {
616
				$m = array_intersect( $hide_opt, $observed_value );
617
				$m = empty( $m ) ? false : true;
618
			} else {
619
				$m = in_array( $hide_opt, $observed_value );
620
			}
621
		} elseif ( $cond == '!=' ) {
622
			$m = ! in_array( $hide_opt, $observed_value );
623
		} elseif ( $cond == '>' ) {
624
			$min = min( $observed_value );
625
			$m   = $min > $hide_opt;
626
		} elseif ( $cond == '<' ) {
627
			$max = max( $observed_value );
628
			$m   = $max < $hide_opt;
629
		} elseif ( $cond == 'LIKE' || $cond == 'not LIKE' ) {
630
			foreach ( $observed_value as $ob ) {
631
				$m = strpos( $ob, $hide_opt );
632
				if ( $m !== false ) {
633
					$m = true;
634
					break;
635
				}
636
			}
637
638
			if ( $cond == 'not LIKE' ) {
639
				$m = ( $m === false ) ? true : false;
640
			}
641
		}
642
643
		return $m;
644
	}
645
646
	/**
647
	 * Replace a few basic shortcodes and field ids
648
	 *
649
	 * @since 2.0
650
	 * @return string
651
	 */
652
	public static function basic_replace_shortcodes( $value, $form, $entry ) {
653
		if ( strpos( $value, '[sitename]' ) !== false ) {
654
			$new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
655
			$value     = str_replace( '[sitename]', $new_value, $value );
656
		}
657
658
		$value = apply_filters( 'frm_content', $value, $form, $entry );
659
		$value = do_shortcode( $value );
660
661
		return $value;
662
	}
663
664
	public static function get_shortcodes( $content, $form_id ) {
665
		if ( FrmAppHelper::pro_is_installed() ) {
666
			return FrmProDisplaysHelper::get_shortcodes( $content, $form_id );
667
		}
668
669
		$fields = FrmField::getAll(
670
			array(
671
				'fi.form_id'  => (int) $form_id,
672
				'fi.type not' => FrmField::no_save_fields(),
673
			)
674
		);
675
676
		$tagregexp = self::allowed_shortcodes( $fields );
677
678
		preg_match_all( "/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER );
679
680
		return $matches;
681
	}
682
683
	public static function allowed_shortcodes( $fields = array() ) {
684
		$tagregexp = array(
685
			'editlink',
686
			'id',
687
			'key',
688
			'ip',
689
			'siteurl',
690
			'sitename',
691
			'admin_email',
692
			'post[-|_]id',
693
			'created[-|_]at',
694
			'updated[-|_]at',
695
			'updated[-|_]by',
696
			'parent[-|_]id',
697
		);
698
699
		foreach ( $fields as $field ) {
700
			$tagregexp[] = $field->id;
701
			$tagregexp[] = $field->field_key;
702
		}
703
704
		$tagregexp = implode( '|', $tagregexp );
705
706
		return $tagregexp;
707
	}
708
709
	public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
710
		foreach ( $shortcodes[0] as $short_key => $tag ) {
711
			if ( empty( $tag ) ) {
712
				continue;
713
			}
714
715
			$atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[3][ $short_key ] );
716
			$tag  = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key );
717
718
			$atts['entry'] = $entry;
719
			$atts['tag']   = $tag;
720
			$replace_with  = self::get_value_for_shortcode( $atts );
721
722
			if ( $replace_with !== null ) {
723
				self::sanitize_embedded_shortcodes( compact( 'entry' ), $replace_with );
724
				$content = str_replace( $shortcodes[0][ $short_key ], $replace_with, $content );
725
			}
726
727
			unset( $atts, $replace_with );
728
		}
729
730
		return $content;
731
	}
732
733
	/**
734
	 * Prevent shortcodes in fields from being processed
735
	 *
736
	 * @since 3.01.02
737
	 *
738
	 * @param array $atts - includes entry object
739
	 * @param string $value
740
	 */
741
	public static function sanitize_embedded_shortcodes( $atts, &$value ) {
742
		$atts['value']   = $value;
743
		$should_sanitize = apply_filters( 'frm_sanitize_shortcodes', true, $atts );
744
		if ( $should_sanitize ) {
745
			$value = str_replace( '[', '&#91;', $value );
746
		}
747
	}
748
749
	/**
750
	 * @since 3.0
751
	 *
752
	 * @param $atts
753
	 *
754
	 * @return string
755
	 */
756
	private static function get_value_for_shortcode( $atts ) {
757
		$clean_tag = str_replace( '-', '_', $atts['tag'] );
758
759
		$shortcode_values = array(
760
			'id'  => $atts['entry']->id,
761
			'key' => $atts['entry']->item_key,
762
			'ip'  => $atts['entry']->ip,
763
		);
764
765
		$dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get' );
766
767
		if ( isset( $shortcode_values[ $atts['tag'] ] ) ) {
768
			$replace_with = $shortcode_values[ $atts['tag'] ];
769
		} elseif ( in_array( $atts['tag'], $dynamic_default ) ) {
770
			$replace_with = self::dynamic_default_values( $atts['tag'], $atts );
771
		} elseif ( $clean_tag == 'user_agent' ) {
772
			$description  = $atts['entry']->description;
773
			$replace_with = FrmEntriesHelper::get_browser( $description['browser'] );
774
		} elseif ( $clean_tag == 'created_at' || $clean_tag == 'updated_at' ) {
775
			$atts['tag']  = $clean_tag;
776
			$replace_with = self::get_entry_timestamp( $atts );
777
		} elseif ( $clean_tag == 'created_by' || $clean_tag == 'updated_by' ) {
778
			$replace_with = self::get_display_value( $atts['entry']->{$clean_tag}, (object) array( 'type' => 'user_id' ), $atts );
779
		} else {
780
			$replace_with = self::get_field_shortcode_value( $atts );
781
		}
782
783
		return $replace_with;
784
	}
785
786
	/**
787
	 * @since 3.0
788
	 *
789
	 * @param $atts
790
	 *
791
	 * @return string
792
	 */
793
	private static function get_entry_timestamp( $atts ) {
794
		if ( isset( $atts['format'] ) ) {
795
			$time_format = ' ';
796
		} else {
797
			$atts['format'] = get_option( 'date_format' );
798
			$time_format    = '';
799
		}
800
801
		return FrmAppHelper::get_formatted_time( $atts['entry']->{$atts['tag']}, $atts['format'], $time_format );
802
	}
803
804
	/**
805
	 * @since 3.0
806
	 *
807
	 * @param $atts
808
	 *
809
	 * @return null|string
810
	 */
811
	private static function get_field_shortcode_value( $atts ) {
812
		$field = FrmField::getOne( $atts['tag'] );
813
		if ( empty( $field ) ) {
814
			return null;
815
		}
816
817
		if ( isset( $atts['show'] ) && $atts['show'] == 'field_label' ) {
818
			$replace_with = $field->name;
819
		} elseif ( isset( $atts['show'] ) && $atts['show'] == 'description' ) {
820
			$replace_with = $field->description;
821
		} else {
822
			$replace_with = FrmEntryMeta::get_meta_value( $atts['entry'], $field->id );
823
			$string_value = $replace_with;
824
			if ( is_array( $replace_with ) ) {
825
				$sep          = isset( $atts['sep'] ) ? $atts['sep'] : ', ';
826
				$string_value = implode( $sep, $replace_with );
827
			}
828
829
			if ( empty( $string_value ) && $string_value != '0' ) {
830
				$replace_with = '';
831
			} else {
832
				$atts['entry_id']  = $atts['entry']->id;
833
				$atts['entry_key'] = $atts['entry']->item_key;
834
				$replace_with      = self::get_display_value( $replace_with, $field, $atts );
835
			}
836
		}
837
838
		return $replace_with;
839
	}
840
841
	/**
842
	 * Get the value to replace a few standard shortcodes
843
	 *
844
	 * @since 2.0
845
	 * @return string
846
	 */
847
	public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) {
848
		$new_value = '';
849
		switch ( $tag ) {
850
			case 'admin_email':
851
				$new_value = get_option( 'admin_email' );
852
				break;
853
			case 'siteurl':
854
				$new_value = FrmAppHelper::site_url();
855
				break;
856
			case 'frmurl':
857
				$new_value = FrmAppHelper::plugin_url();
858
				break;
859
			case 'sitename':
860
				$new_value = FrmAppHelper::site_name();
861
				break;
862
			case 'get':
863
				$new_value = self::process_get_shortcode( $atts, $return_array );
864
		}
865
866
		return $new_value;
867
	}
868
869
	/**
870
	 * Process the [get] shortcode
871
	 *
872
	 * @since 2.0
873
	 * @return string|array
874
	 */
875
	public static function process_get_shortcode( $atts, $return_array = false ) {
876
		if ( ! isset( $atts['param'] ) ) {
877
			return '';
878
		}
879
880
		if ( strpos( $atts['param'], '&#91;' ) ) {
881
			$atts['param'] = str_replace( '&#91;', '[', $atts['param'] );
882
			$atts['param'] = str_replace( '&#93;', ']', $atts['param'] );
883
		}
884
885
		$new_value = FrmAppHelper::get_param( $atts['param'], '', 'get', 'sanitize_text_field' );
886
		$new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] );
887
888
		if ( $new_value == '' ) {
889
			if ( ! isset( $atts['prev_val'] ) ) {
890
				$atts['prev_val'] = '';
891
			}
892
893
			$new_value = isset( $atts['default'] ) ? $atts['default'] : $atts['prev_val'];
894
		}
895
896
		if ( is_array( $new_value ) && ! $return_array ) {
897
			$new_value = implode( ', ', $new_value );
898
		}
899
900
		return $new_value;
901
	}
902
903
	public static function get_display_value( $value, $field, $atts = array() ) {
904
905
		$value = apply_filters( 'frm_get_' . $field->type . '_display_value', $value, $field, $atts );
906
		$value = apply_filters( 'frm_get_display_value', $value, $field, $atts );
907
908
		return self::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) );
909
	}
910
911
	/**
912
	 * @param $atts array Includes value, field, and atts
913
	 */
914
	public static function get_unfiltered_display_value( $atts ) {
915
		$value = $atts['value'];
916
		$field = $atts['field'];
917
		$atts  = isset( $atts['atts'] ) ? $atts['atts'] : $atts;
918
919
		if ( is_array( $field ) ) {
920
			$field = $field['id'];
921
		}
922
923
		$field_obj = FrmFieldFactory::get_field_object( $field );
924
925
		return $field_obj->get_display_value( $value, $atts );
926
	}
927
928
	/**
929
	 * Get a value from the user profile from the user ID
930
	 *
931
	 * @since 3.0
932
	 */
933
	public static function get_user_display_name( $user_id, $user_info = 'display_name', $args = array() ) {
934
		$defaults = array(
935
			'blank' => false,
936
			'link'  => false,
937
			'size'  => 96,
938
		);
939
940
		$args = wp_parse_args( $args, $defaults );
941
942
		$user = get_userdata( $user_id );
943
		$info = '';
944
945
		if ( $user ) {
946
			if ( $user_info == 'avatar' ) {
947
				$info = get_avatar( $user_id, $args['size'] );
948
			} elseif ( $user_info == 'author_link' ) {
949
				$info = get_author_posts_url( $user_id );
950
			} else {
951
				$info = isset( $user->$user_info ) ? $user->$user_info : '';
952
			}
953
954
			if ( 'display_name' === $user_info && empty( $info ) && ! $args['blank'] ) {
955
				$info = $user->user_login;
956
			}
957
		}
958
959
		if ( $args['link'] ) {
960
			$info = '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $user_id ) ) . '">' . $info . '</a>';
961
		}
962
963
		return $info;
964
	}
965
966
	public static function get_field_types( $type ) {
967
		$single_input   = self::single_input_fields();
968
		$multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' );
969
970
		$field_selection = FrmField::all_field_selection();
971
972
		$field_types = array();
973
		if ( in_array( $type, $single_input ) ) {
974
			self::field_types_for_input( $single_input, $field_selection, $field_types );
975
		} elseif ( in_array( $type, $multiple_input ) ) {
976
			self::field_types_for_input( $multiple_input, $field_selection, $field_types );
977
		} elseif ( isset( $field_selection[ $type ] ) ) {
978
			$field_types[ $type ] = $field_selection[ $type ];
979
		}
980
981
		$field_types = apply_filters( 'frm_switch_field_types', $field_types, compact( 'type' ) );
982
983
		return $field_types;
984
	}
985
986
	/**
987
	 * Get a list of all fields that use a single value input.
988
	 *
989
	 * @since 4.0
990
	 */
991
	public static function single_input_fields() {
992
		$fields = array(
993
			'text',
994
			'textarea',
995
			'rte',
996
			'number',
997
			'email',
998
			'url',
999
			'date',
1000
			'phone',
1001
			'hidden',
1002
			'time',
1003
			'tag',
1004
			'password',
1005
		);
1006
		return apply_filters( 'frm_single_input_fields', $fields );
1007
	}
1008
1009
	private static function field_types_for_input( $inputs, $fields, &$field_types ) {
1010
		foreach ( $inputs as $input ) {
1011
			$field_types[ $input ] = $fields[ $input ];
1012
			unset( $input );
1013
		}
1014
	}
1015
1016
	/**
1017
	 * Check if current field option is an "other" option
1018
	 *
1019
	 * @since 2.0.6
1020
	 *
1021
	 * @param string $opt_key
1022
	 *
1023
	 * @return boolean Returns true if current field option is an "Other" option
1024
	 */
1025
	public static function is_other_opt( $opt_key ) {
1026
		return $opt_key && strpos( $opt_key, 'other_' ) === 0;
1027
	}
1028
1029
	/**
1030
	 * Get value that belongs in "Other" text box
1031
	 *
1032
	 * @since 2.0.6
1033
	 *
1034
	 * @param array $args
1035
	 */
1036
	public static function get_other_val( $args ) {
1037
		$defaults = array(
1038
			'opt_key' => 0,
1039
			'field'   => array(),
1040
			'parent'  => false,
1041
			'pointer' => false,
1042
		);
1043
		$args     = wp_parse_args( $args, $defaults );
1044
1045
		$opt_key   = $args['opt_key'];
1046
		$field     = $args['field'];
1047
		$parent    = $args['parent'];
1048
		$pointer   = $args['pointer'];
1049
		$other_val = '';
1050
1051
		// If option is an "other" option and there is a value set for this field,
1052
		// check if the value belongs in the current "Other" option text field
1053
		if ( ! self::is_other_opt( $opt_key ) || ! FrmField::is_option_true( $field, 'value' ) ) {
1054
			return $other_val;
1055
		}
1056
1057
		// Check posted vals before checking saved values
1058
1059
		// For fields inside repeating sections - note, don't check if $pointer is true because it will often be zero
1060
		if ( $parent && isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ) {
1061
			if ( FrmField::is_field_with_multiple_values( $field ) ) {
1062
				$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 ] ) ) : '';
1063 View Code Duplication
			} else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1064
				$other_val = sanitize_text_field( wp_unslash( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) );
1065
			}
1066
1067
			return $other_val;
1068
1069
		} elseif ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) {
1070
			// For normal fields
1071
1072
			if ( FrmField::is_field_with_multiple_values( $field ) ) {
1073
				$other_val = isset( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ) : '';
1074 View Code Duplication
			} else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1075
				$other_val = sanitize_text_field( wp_unslash( $_POST['item_meta']['other'][ $field['id'] ] ) );
1076
			}
1077
1078
			return $other_val;
1079
		}
1080
1081
		// For checkboxes
1082
		if ( $field['type'] == 'checkbox' && is_array( $field['value'] ) ) {
1083
			// Check if there is an "other" val in saved value and make sure the
1084
			// "other" val is not equal to the Other checkbox option
1085
			if ( isset( $field['value'][ $opt_key ] ) && $field['options'][ $opt_key ] != $field['value'][ $opt_key ] ) {
1086
				$other_val = $field['value'][ $opt_key ];
1087
			}
1088
		} else {
1089
			/**
1090
			 * For radio buttons and dropdowns
1091
			 * Check if saved value equals any of the options. If not, set it as the other value.
1092
			 */
1093
			foreach ( $field['options'] as $opt_key => $opt_val ) {
1094
				$temp_val = is_array( $opt_val ) ? $opt_val['value'] : $opt_val;
1095
				// Multi-select dropdowns - key is not preserved
1096
				if ( is_array( $field['value'] ) ) {
1097
					$o_key = array_search( $temp_val, $field['value'] );
1098
					if ( isset( $field['value'][ $o_key ] ) ) {
1099
						unset( $field['value'][ $o_key ], $o_key );
1100
					}
1101
				} elseif ( $temp_val == $field['value'] ) {
1102
					// For radio and regular dropdowns
1103
					return '';
1104
				} else {
1105
					$other_val = $field['value'];
1106
				}
1107
				unset( $opt_key, $opt_val, $temp_val );
1108
			}
1109
			// For multi-select dropdowns only
1110
			if ( is_array( $field['value'] ) && ! empty( $field['value'] ) ) {
1111
				$other_val = reset( $field['value'] );
1112
			}
1113
		}
1114
1115
		return $other_val;
1116
	}
1117
1118
	/**
1119
	 * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val.
1120
	 * Intended for front-end use
1121
	 *
1122
	 * @since 2.0.6
1123
	 *
1124
	 * @param array $args should include field, opt_key and field name
1125
	 * @param boolean $other_opt
1126
	 * @param string $checked
1127
	 *
1128
	 * @return array $other_args
1129
	 */
1130
	public static function prepare_other_input( $args, &$other_opt, &$checked ) {
1131
		//Check if this is an "Other" option
1132
		if ( ! self::is_other_opt( $args['opt_key'] ) ) {
1133
			return;
1134
		}
1135
1136
		$other_opt  = true;
1137
		$other_args = array();
1138
1139
		self::set_other_name( $args, $other_args );
1140
		self::set_other_value( $args, $other_args );
1141
1142
		if ( '' !== $other_args['value'] ) {
1143
			$checked = 'checked="checked" ';
1144
		}
1145
1146
		return $other_args;
1147
	}
1148
1149
	/**
1150
	 * @param array $args
1151
	 * @param array $other_args
1152
	 *
1153
	 * @since 2.0.6
1154
	 */
1155
	private static function set_other_name( $args, &$other_args ) {
1156
		//Set up name for other field
1157
		$other_args['name'] = str_replace( '[]', '', $args['field_name'] );
1158
		$other_args['name'] = preg_replace( '/\[' . $args['field']['id'] . '\]$/', '', $other_args['name'] );
1159
		$other_args['name'] = $other_args['name'] . '[other][' . $args['field']['id'] . ']';
1160
1161
		//Converts item_meta[field_id] => item_meta[other][field_id] and
1162
		//item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id]
1163
		if ( FrmField::is_field_with_multiple_values( $args['field'] ) ) {
1164
			$other_args['name'] .= '[' . $args['opt_key'] . ']';
1165
		}
1166
	}
1167
1168
	/**
1169
	 * Find the parent and pointer, and get text for "other" text field
1170
	 *
1171
	 * @param array $args
1172
	 * @param array $other_args
1173
	 *
1174
	 * @since 2.0.6
1175
	 */
1176
	private static function set_other_value( $args, &$other_args ) {
1177
		$parent  = '';
1178
		$pointer = '';
1179
1180
		// Check for parent ID and pointer
1181
		$temp_array = explode( '[', $args['field_name'] );
1182
1183
		// Count should only be greater than 3 if inside of a repeating section
1184
		if ( count( $temp_array ) > 3 ) {
1185
			$parent  = str_replace( ']', '', $temp_array[1] );
1186
			$pointer = str_replace( ']', '', $temp_array[2] );
1187
		}
1188
1189
		// Get text for "other" text field
1190
		$other_args['value'] = self::get_other_val(
1191
			array(
1192
				'opt_key' => $args['opt_key'],
1193
				'field'   => $args['field'],
1194
				'parent'  => $parent,
1195
				'pointer' => $pointer,
1196
			)
1197
		);
1198
	}
1199
1200
	/**
1201
	 * If this field includes an other option, show it
1202
	 *
1203
	 * @param $args array
1204
	 *
1205
	 * @since 2.0.6
1206
	 */
1207
	public static function include_other_input( $args ) {
1208
		if ( ! $args['other_opt'] ) {
1209
			return;
1210
		}
1211
1212
		$classes = array( 'frm_other_input' );
1213
		if ( ! $args['checked'] || trim( $args['checked'] ) == '' ) {
1214
			// hide the field if the other option is not selected
1215
			$classes[] = 'frm_pos_none';
1216
		}
1217
		if ( $args['field']['type'] == 'select' && $args['field']['multiple'] ) {
1218
			$classes[] = 'frm_other_full';
1219
		}
1220
1221
		// Set up HTML ID for Other field
1222
		$other_id = self::get_other_field_html_id( $args['field']['type'], $args['html_id'], $args['opt_key'] );
1223
1224
		$label = isset( $args['opt_label'] ) ? $args['opt_label'] : $args['field']['name'];
1225
1226
		echo '<label for="' . esc_attr( $other_id ) . '" class="frm_screen_reader frm_hidden">' .
1227
			esc_html( $label ) .
1228
			'</label>' .
1229
			'<input type="text" id="' . esc_attr( $other_id ) . '" class="' . esc_attr( implode( ' ', $classes ) ) . '" ' .
1230
			( $args['read_only'] ? ' readonly="readonly" disabled="disabled"' : '' ) .
1231
			' name="' . esc_attr( $args['name'] ) . '" value="' . esc_attr( $args['value'] ) . '" />';
1232
	}
1233
1234
	/**
1235
	 * Get the HTML id for an "Other" text field
1236
	 * Note: This does not affect fields in repeating sections
1237
	 *
1238
	 * @since 2.0.08
1239
	 *
1240
	 * @param string $type - field type
1241
	 * @param string $html_id
1242
	 * @param string|boolean $opt_key
1243
	 *
1244
	 * @return string $other_id
1245
	 */
1246
	public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) {
1247
		$other_id = $html_id;
1248
1249
		// If hidden radio field, add an opt key of 0
1250
		if ( $type == 'radio' && $opt_key === false ) {
1251
			$opt_key = 0;
1252
		}
1253
1254
		if ( $opt_key !== false ) {
1255
			$other_id .= '-' . $opt_key;
1256
		}
1257
1258
		$other_id .= '-otext';
1259
1260
		return $other_id;
1261
	}
1262
1263
	public static function switch_field_ids( $val ) {
1264
		global $frm_duplicate_ids;
1265
		$replace      = array();
1266
		$replace_with = array();
1267
		foreach ( (array) $frm_duplicate_ids as $old => $new ) {
1268
			$replace[]      = '[if ' . $old . ']';
1269
			$replace_with[] = '[if ' . $new . ']';
1270
			$replace[]      = '[if ' . $old . ' ';
1271
			$replace_with[] = '[if ' . $new . ' ';
1272
			$replace[]      = '[/if ' . $old . ']';
1273
			$replace_with[] = '[/if ' . $new . ']';
1274
			$replace[]      = '[foreach ' . $old . ']';
1275
			$replace_with[] = '[foreach ' . $new . ']';
1276
			$replace[]      = '[/foreach ' . $old . ']';
1277
			$replace_with[] = '[/foreach ' . $new . ']';
1278
			$replace[]      = '[' . $old . ']';
1279
			$replace_with[] = '[' . $new . ']';
1280
			$replace[]      = '[' . $old . ' ';
1281
			$replace_with[] = '[' . $new . ' ';
1282
			unset( $old, $new );
1283
		}
1284
		if ( is_array( $val ) ) {
1285
			foreach ( $val as $k => $v ) {
1286
				$val[ $k ] = str_replace( $replace, $replace_with, $v );
1287
				unset( $k, $v );
1288
			}
1289
		} else {
1290
			$val = str_replace( $replace, $replace_with, $val );
1291
		}
1292
1293
		return $val;
1294
	}
1295
1296
	/**
1297
	 * @since 4.0
1298
	 */
1299
	public static function bulk_options_overlay() {
1300
		$prepop = array();
1301
		self::get_bulk_prefilled_opts( $prepop );
1302
1303
		include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/bulk-options-overlay.php' );
1304
	}
1305
1306
	public static function get_us_states() {
1307
		$states = array(
1308
			'AL' => 'Alabama',
1309
			'AK' => 'Alaska',
1310
			'AR' => 'Arkansas',
1311
			'AZ' => 'Arizona',
1312
			'CA' => 'California',
1313
			'CO' => 'Colorado',
1314
			'CT' => 'Connecticut',
1315
			'DE' => 'Delaware',
1316
			'DC' => 'District of Columbia',
1317
			'FL' => 'Florida',
1318
			'GA' => 'Georgia',
1319
			'HI' => 'Hawaii',
1320
			'ID' => 'Idaho',
1321
			'IL' => 'Illinois',
1322
			'IN' => 'Indiana',
1323
			'IA' => 'Iowa',
1324
			'KS' => 'Kansas',
1325
			'KY' => 'Kentucky',
1326
			'LA' => 'Louisiana',
1327
			'ME' => 'Maine',
1328
			'MD' => 'Maryland',
1329
			'MA' => 'Massachusetts',
1330
			'MI' => 'Michigan',
1331
			'MN' => 'Minnesota',
1332
			'MS' => 'Mississippi',
1333
			'MO' => 'Missouri',
1334
			'MT' => 'Montana',
1335
			'NE' => 'Nebraska',
1336
			'NV' => 'Nevada',
1337
			'NH' => 'New Hampshire',
1338
			'NJ' => 'New Jersey',
1339
			'NM' => 'New Mexico',
1340
			'NY' => 'New York',
1341
			'NC' => 'North Carolina',
1342
			'ND' => 'North Dakota',
1343
			'OH' => 'Ohio',
1344
			'OK' => 'Oklahoma',
1345
			'OR' => 'Oregon',
1346
			'PA' => 'Pennsylvania',
1347
			'RI' => 'Rhode Island',
1348
			'SC' => 'South Carolina',
1349
			'SD' => 'South Dakota',
1350
			'TN' => 'Tennessee',
1351
			'TX' => 'Texas',
1352
			'UT' => 'Utah',
1353
			'VT' => 'Vermont',
1354
			'VA' => 'Virginia',
1355
			'WA' => 'Washington',
1356
			'WV' => 'West Virginia',
1357
			'WI' => 'Wisconsin',
1358
			'WY' => 'Wyoming',
1359
		);
1360
1361
		return apply_filters( 'frm_us_states', $states );
1362
	}
1363
1364
	public static function get_countries() {
1365
		$countries = array(
1366
			__( 'Afghanistan', 'formidable' ),
1367
			__( 'Aland Islands', 'formidable' ),
1368
			__( 'Albania', 'formidable' ),
1369
			__( 'Algeria', 'formidable' ),
1370
			__( 'American Samoa', 'formidable' ),
1371
			__( 'Andorra', 'formidable' ),
1372
			__( 'Angola', 'formidable' ),
1373
			__( 'Anguilla', 'formidable' ),
1374
			__( 'Antarctica', 'formidable' ),
1375
			__( 'Antigua and Barbuda', 'formidable' ),
1376
			__( 'Argentina', 'formidable' ),
1377
			__( 'Armenia', 'formidable' ),
1378
			__( 'Aruba', 'formidable' ),
1379
			__( 'Australia', 'formidable' ),
1380
			__( 'Austria', 'formidable' ),
1381
			__( 'Azerbaijan', 'formidable' ),
1382
			__( 'Bahamas', 'formidable' ),
1383
			__( 'Bahrain', 'formidable' ),
1384
			__( 'Bangladesh', 'formidable' ),
1385
			__( 'Barbados', 'formidable' ),
1386
			__( 'Belarus', 'formidable' ),
1387
			__( 'Belgium', 'formidable' ),
1388
			__( 'Belize', 'formidable' ),
1389
			__( 'Benin', 'formidable' ),
1390
			__( 'Bermuda', 'formidable' ),
1391
			__( 'Bhutan', 'formidable' ),
1392
			__( 'Bolivia', 'formidable' ),
1393
			__( 'Bonaire, Sint Eustatius and Saba', 'formidable' ),
1394
			__( 'Bosnia and Herzegovina', 'formidable' ),
1395
			__( 'Botswana', 'formidable' ),
1396
			__( 'Bouvet Island', 'formidable' ),
1397
			__( 'Brazil', 'formidable' ),
1398
			__( 'British Indian Ocean Territory', 'formidable' ),
1399
			__( 'Brunei', 'formidable' ),
1400
			__( 'Bulgaria', 'formidable' ),
1401
			__( 'Burkina Faso', 'formidable' ),
1402
			__( 'Burundi', 'formidable' ),
1403
			__( 'Cambodia', 'formidable' ),
1404
			__( 'Cameroon', 'formidable' ),
1405
			__( 'Canada', 'formidable' ),
1406
			__( 'Cape Verde', 'formidable' ),
1407
			__( 'Cayman Islands', 'formidable' ),
1408
			__( 'Central African Republic', 'formidable' ),
1409
			__( 'Chad', 'formidable' ),
1410
			__( 'Chile', 'formidable' ),
1411
			__( 'China', 'formidable' ),
1412
			__( 'Christmas Island', 'formidable' ),
1413
			__( 'Cocos (Keeling) Islands', 'formidable' ),
1414
			__( 'Colombia', 'formidable' ),
1415
			__( 'Comoros', 'formidable' ),
1416
			__( 'Congo', 'formidable' ),
1417
			__( 'Cook Islands', 'formidable' ),
1418
			__( 'Costa Rica', 'formidable' ),
1419
			__( 'C&ocirc;te d\'Ivoire', 'formidable' ),
1420
			__( 'Croatia', 'formidable' ),
1421
			__( 'Cuba', 'formidable' ),
1422
			__( 'Curacao', 'formidable' ),
1423
			__( 'Cyprus', 'formidable' ),
1424
			__( 'Czech Republic', 'formidable' ),
1425
			__( 'Denmark', 'formidable' ),
1426
			__( 'Djibouti', 'formidable' ),
1427
			__( 'Dominica', 'formidable' ),
1428
			__( 'Dominican Republic', 'formidable' ),
1429
			__( 'East Timor', 'formidable' ),
1430
			__( 'Ecuador', 'formidable' ),
1431
			__( 'Egypt', 'formidable' ),
1432
			__( 'El Salvador', 'formidable' ),
1433
			__( 'Equatorial Guinea', 'formidable' ),
1434
			__( 'Eritrea', 'formidable' ),
1435
			__( 'Estonia', 'formidable' ),
1436
			__( 'Ethiopia', 'formidable' ),
1437
			__( 'Falkland Islands (Malvinas)', 'formidable' ),
1438
			__( 'Faroe Islands', 'formidable' ),
1439
			__( 'Fiji', 'formidable' ),
1440
			__( 'Finland', 'formidable' ),
1441
			__( 'France', 'formidable' ),
1442
			__( 'French Guiana', 'formidable' ),
1443
			__( 'French Polynesia', 'formidable' ),
1444
			__( 'French Southern Territories', 'formidable' ),
1445
			__( 'Gabon', 'formidable' ),
1446
			__( 'Gambia', 'formidable' ),
1447
			__( 'Georgia', 'formidable' ),
1448
			__( 'Germany', 'formidable' ),
1449
			__( 'Ghana', 'formidable' ),
1450
			__( 'Gibraltar', 'formidable' ),
1451
			__( 'Greece', 'formidable' ),
1452
			__( 'Greenland', 'formidable' ),
1453
			__( 'Grenada', 'formidable' ),
1454
			__( 'Guadeloupe', 'formidable' ),
1455
			__( 'Guam', 'formidable' ),
1456
			__( 'Guatemala', 'formidable' ),
1457
			__( 'Guernsey', 'formidable' ),
1458
			__( 'Guinea', 'formidable' ),
1459
			__( 'Guinea-Bissau', 'formidable' ),
1460
			__( 'Guyana', 'formidable' ),
1461
			__( 'Haiti', 'formidable' ),
1462
			__( 'Heard Island and McDonald Islands', 'formidable' ),
1463
			__( 'Holy See', 'formidable' ),
1464
			__( 'Honduras', 'formidable' ),
1465
			__( 'Hong Kong', 'formidable' ),
1466
			__( 'Hungary', 'formidable' ),
1467
			__( 'Iceland', 'formidable' ),
1468
			__( 'India', 'formidable' ),
1469
			__( 'Indonesia', 'formidable' ),
1470
			__( 'Iran', 'formidable' ),
1471
			__( 'Iraq', 'formidable' ),
1472
			__( 'Ireland', 'formidable' ),
1473
			__( 'Israel', 'formidable' ),
1474
			__( 'Isle of Man', 'formidable' ),
1475
			__( 'Italy', 'formidable' ),
1476
			__( 'Jamaica', 'formidable' ),
1477
			__( 'Japan', 'formidable' ),
1478
			__( 'Jersey', 'formidable' ),
1479
			__( 'Jordan', 'formidable' ),
1480
			__( 'Kazakhstan', 'formidable' ),
1481
			__( 'Kenya', 'formidable' ),
1482
			__( 'Kiribati', 'formidable' ),
1483
			__( 'North Korea', 'formidable' ),
1484
			__( 'South Korea', 'formidable' ),
1485
			__( 'Kosovo', 'formidable' ),
1486
			__( 'Kuwait', 'formidable' ),
1487
			__( 'Kyrgyzstan', 'formidable' ),
1488
			__( 'Laos', 'formidable' ),
1489
			__( 'Latvia', 'formidable' ),
1490
			__( 'Lebanon', 'formidable' ),
1491
			__( 'Lesotho', 'formidable' ),
1492
			__( 'Liberia', 'formidable' ),
1493
			__( 'Libya', 'formidable' ),
1494
			__( 'Liechtenstein', 'formidable' ),
1495
			__( 'Lithuania', 'formidable' ),
1496
			__( 'Luxembourg', 'formidable' ),
1497
			__( 'Macao', 'formidable' ),
1498
			__( 'Macedonia', 'formidable' ),
1499
			__( 'Madagascar', 'formidable' ),
1500
			__( 'Malawi', 'formidable' ),
1501
			__( 'Malaysia', 'formidable' ),
1502
			__( 'Maldives', 'formidable' ),
1503
			__( 'Mali', 'formidable' ),
1504
			__( 'Malta', 'formidable' ),
1505
			__( 'Marshall Islands', 'formidable' ),
1506
			__( 'Martinique', 'formidable' ),
1507
			__( 'Mauritania', 'formidable' ),
1508
			__( 'Mauritius', 'formidable' ),
1509
			__( 'Mayotte', 'formidable' ),
1510
			__( 'Mexico', 'formidable' ),
1511
			__( 'Micronesia', 'formidable' ),
1512
			__( 'Moldova', 'formidable' ),
1513
			__( 'Monaco', 'formidable' ),
1514
			__( 'Mongolia', 'formidable' ),
1515
			__( 'Montenegro', 'formidable' ),
1516
			__( 'Montserrat', 'formidable' ),
1517
			__( 'Morocco', 'formidable' ),
1518
			__( 'Mozambique', 'formidable' ),
1519
			__( 'Myanmar', 'formidable' ),
1520
			__( 'Namibia', 'formidable' ),
1521
			__( 'Nauru', 'formidable' ),
1522
			__( 'Nepal', 'formidable' ),
1523
			__( 'Netherlands', 'formidable' ),
1524
			__( 'New Caledonia', 'formidable' ),
1525
			__( 'New Zealand', 'formidable' ),
1526
			__( 'Nicaragua', 'formidable' ),
1527
			__( 'Niger', 'formidable' ),
1528
			__( 'Nigeria', 'formidable' ),
1529
			__( 'Niue', 'formidable' ),
1530
			__( 'Norfolk Island', 'formidable' ),
1531
			__( 'Northern Mariana Islands', 'formidable' ),
1532
			__( 'Norway', 'formidable' ),
1533
			__( 'Oman', 'formidable' ),
1534
			__( 'Pakistan', 'formidable' ),
1535
			__( 'Palau', 'formidable' ),
1536
			__( 'Palestine', 'formidable' ),
1537
			__( 'Panama', 'formidable' ),
1538
			__( 'Papua New Guinea', 'formidable' ),
1539
			__( 'Paraguay', 'formidable' ),
1540
			__( 'Peru', 'formidable' ),
1541
			__( 'Philippines', 'formidable' ),
1542
			__( 'Pitcairn', 'formidable' ),
1543
			__( 'Poland', 'formidable' ),
1544
			__( 'Portugal', 'formidable' ),
1545
			__( 'Puerto Rico', 'formidable' ),
1546
			__( 'Qatar', 'formidable' ),
1547
			__( 'Reunion', 'formidable' ),
1548
			__( 'Romania', 'formidable' ),
1549
			__( 'Russia', 'formidable' ),
1550
			__( 'Rwanda', 'formidable' ),
1551
			__( 'Saint Barthelemy', 'formidable' ),
1552
			__( 'Saint Helena, Ascension and Tristan da Cunha', 'formidable' ),
1553
			__( 'Saint Kitts and Nevis', 'formidable' ),
1554
			__( 'Saint Lucia', 'formidable' ),
1555
			__( 'Saint Martin (French part)', 'formidable' ),
1556
			__( 'Saint Pierre and Miquelon', 'formidable' ),
1557
			__( 'Saint Vincent and the Grenadines', 'formidable' ),
1558
			__( 'Samoa', 'formidable' ),
1559
			__( 'San Marino', 'formidable' ),
1560
			__( 'Sao Tome and Principe', 'formidable' ),
1561
			__( 'Saudi Arabia', 'formidable' ),
1562
			__( 'Senegal', 'formidable' ),
1563
			__( 'Serbia', 'formidable' ),
1564
			__( 'Seychelles', 'formidable' ),
1565
			__( 'Sierra Leone', 'formidable' ),
1566
			__( 'Singapore', 'formidable' ),
1567
			__( 'Sint Maarten (Dutch part)', 'formidable' ),
1568
			__( 'Slovakia', 'formidable' ),
1569
			__( 'Slovenia', 'formidable' ),
1570
			__( 'Solomon Islands', 'formidable' ),
1571
			__( 'Somalia', 'formidable' ),
1572
			__( 'South Africa', 'formidable' ),
1573
			__( 'South Georgia and the South Sandwich Islands', 'formidable' ),
1574
			__( 'South Sudan', 'formidable' ),
1575
			__( 'Spain', 'formidable' ),
1576
			__( 'Sri Lanka', 'formidable' ),
1577
			__( 'Sudan', 'formidable' ),
1578
			__( 'Suriname', 'formidable' ),
1579
			__( 'Svalbard and Jan Mayen', 'formidable' ),
1580
			__( 'Swaziland', 'formidable' ),
1581
			__( 'Sweden', 'formidable' ),
1582
			__( 'Switzerland', 'formidable' ),
1583
			__( 'Syria', 'formidable' ),
1584
			__( 'Taiwan', 'formidable' ),
1585
			__( 'Tajikistan', 'formidable' ),
1586
			__( 'Tanzania', 'formidable' ),
1587
			__( 'Thailand', 'formidable' ),
1588
			__( 'Timor-Leste', 'formidable' ),
1589
			__( 'Togo', 'formidable' ),
1590
			__( 'Tokelau', 'formidable' ),
1591
			__( 'Tonga', 'formidable' ),
1592
			__( 'Trinidad and Tobago', 'formidable' ),
1593
			__( 'Tunisia', 'formidable' ),
1594
			__( 'Turkey', 'formidable' ),
1595
			__( 'Turkmenistan', 'formidable' ),
1596
			__( 'Turks and Caicos Islands', 'formidable' ),
1597
			__( 'Tuvalu', 'formidable' ),
1598
			__( 'Uganda', 'formidable' ),
1599
			__( 'Ukraine', 'formidable' ),
1600
			__( 'United Arab Emirates', 'formidable' ),
1601
			__( 'United Kingdom', 'formidable' ),
1602
			__( 'United States', 'formidable' ),
1603
			__( 'United States Minor Outlying Islands', 'formidable' ),
1604
			__( 'Uruguay', 'formidable' ),
1605
			__( 'Uzbekistan', 'formidable' ),
1606
			__( 'Vanuatu', 'formidable' ),
1607
			__( 'Vatican City', 'formidable' ),
1608
			__( 'Venezuela', 'formidable' ),
1609
			__( 'Vietnam', 'formidable' ),
1610
			__( 'Virgin Islands, British', 'formidable' ),
1611
			__( 'Virgin Islands, U.S.', 'formidable' ),
1612
			__( 'Wallis and Futuna', 'formidable' ),
1613
			__( 'Western Sahara', 'formidable' ),
1614
			__( 'Yemen', 'formidable' ),
1615
			__( 'Zambia', 'formidable' ),
1616
			__( 'Zimbabwe', 'formidable' ),
1617
		);
1618
1619
		return apply_filters( 'frm_countries', $countries );
1620
	}
1621
1622
	public static function get_bulk_prefilled_opts( array &$prepop ) {
1623
		$prepop[ __( 'Countries', 'formidable' ) ] = self::get_countries();
1624
1625
		$states    = self::get_us_states();
1626
		$state_abv = array_keys( $states );
1627
		sort( $state_abv );
1628
		$prepop[ __( 'U.S. State Abbreviations', 'formidable' ) ] = $state_abv;
1629
1630
		$states = array_values( $states );
1631
		sort( $states );
1632
		$prepop[ __( 'U.S. States', 'formidable' ) ] = $states;
1633
		unset( $state_abv, $states );
1634
1635
		$prepop[ __( 'Age', 'formidable' ) ] = array(
1636
			__( 'Under 18', 'formidable' ),
1637
			__( '18-24', 'formidable' ),
1638
			__( '25-34', 'formidable' ),
1639
			__( '35-44', 'formidable' ),
1640
			__( '45-54', 'formidable' ),
1641
			__( '55-64', 'formidable' ),
1642
			__( '65 or Above', 'formidable' ),
1643
			__( 'Prefer Not to Answer', 'formidable' ),
1644
		);
1645
1646
		$prepop[ __( 'Satisfaction', 'formidable' ) ] = array(
1647
			__( 'Very Satisfied', 'formidable' ),
1648
			__( 'Satisfied', 'formidable' ),
1649
			__( 'Neutral', 'formidable' ),
1650
			__( 'Unsatisfied', 'formidable' ),
1651
			__( 'Very Unsatisfied', 'formidable' ),
1652
			__( 'N/A', 'formidable' ),
1653
		);
1654
1655
		$prepop[ __( 'Importance', 'formidable' ) ] = array(
1656
			__( 'Very Important', 'formidable' ),
1657
			__( 'Important', 'formidable' ),
1658
			__( 'Neutral', 'formidable' ),
1659
			__( 'Somewhat Important', 'formidable' ),
1660
			__( 'Not at all Important', 'formidable' ),
1661
			__( 'N/A', 'formidable' ),
1662
		);
1663
1664
		$prepop[ __( 'Agreement', 'formidable' ) ] = array(
1665
			__( 'Strongly Agree', 'formidable' ),
1666
			__( 'Agree', 'formidable' ),
1667
			__( 'Neutral', 'formidable' ),
1668
			__( 'Disagree', 'formidable' ),
1669
			__( 'Strongly Disagree', 'formidable' ),
1670
			__( 'N/A', 'formidable' ),
1671
		);
1672
1673
		$prepop = apply_filters( 'frm_bulk_field_choices', $prepop );
1674
	}
1675
1676
	/**
1677
	 * Display a field value selector
1678
	 *
1679
	 * @since 2.03.05
1680
	 *
1681
	 * @param int $selector_field_id
1682
	 * @param array $selector_args
1683
	 */
1684
	public static function display_field_value_selector( $selector_field_id, $selector_args ) {
1685
		$field_value_selector = FrmFieldFactory::create_field_value_selector( $selector_field_id, $selector_args );
1686
		$field_value_selector->display();
1687
	}
1688
1689
	/**
1690
	 * Convert a field object to a flat array
1691
	 *
1692
	 * @since 2.03.05
1693
	 *
1694
	 * @param object $field
1695
	 *
1696
	 * @return array
1697
	 */
1698
	public static function convert_field_object_to_flat_array( $field ) {
1699
		$field_options = $field->field_options;
1700
		$field_array   = get_object_vars( $field );
1701
		unset( $field_array['field_options'] );
1702
1703
		return $field_array + $field_options;
1704
	}
1705
1706
	/**
1707
	 * @since 4.04
1708
	 */
1709
	public static function show_add_field_buttons( $args ) {
1710
		$field_key      = $args['field_key'];
1711
		$field_type     = $args['field_type'];
1712
		$field_label    = FrmAppHelper::icon_by_class( FrmFormsHelper::get_field_link_icon( $field_type ), array( 'echo' => false ) );
1713
		$field_name     = FrmFormsHelper::get_field_link_name( $field_type );
1714
		$field_label   .= ' <span>' . $field_name . '</span>';
1715
1716
		/* translators: %s: Field name */
1717
		$upgrade_label = sprintf( esc_html__( '%s fields', 'formidable' ), $field_name );
1718
1719
		// If the individual field isn't allowed, disable it.
1720
		$run_filter      = true;
1721
		$single_no_allow = ' ';
1722
		$install_data    = '';
1723
		$requires        = '';
1724
		$upgrade_message = '';
1725
		$link            = isset( $field_type['link'] ) ? esc_url_raw( $field_type['link'] ) : '';
1726
		if ( strpos( $field_type['icon'], ' frm_show_upgrade' ) ) {
1727
			$single_no_allow   .= 'frm_show_upgrade';
1728
			$field_type['icon'] = str_replace( ' frm_show_upgrade', '', $field_type['icon'] );
1729
			$run_filter         = false;
1730
			if ( isset( $field_type['addon'] ) ) {
1731
				$upgrading = FrmAddonsController::install_link( $field_type['addon'] );
1732
				if ( isset( $upgrading['url'] ) ) {
1733
					$install_data = json_encode( $upgrading );
1734
				}
1735
				$requires = FrmFormsHelper::get_plan_required( $upgrading );
1736
			} elseif ( isset( $field_type['require'] ) ) {
1737
				$requires = $field_type['require'];
1738
			}
1739
		}
1740
1741
		if ( isset( $field_type['message'] ) ) {
1742
			$upgrade_message = FrmAppHelper::kses( $field_type['message'], array( 'a', 'img' ) );
1743
		}
1744
1745
		?>
1746
		<li class="frmbutton <?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 ); ?>">
1747
		<?php
1748
		if ( $run_filter ) {
1749
			$field_label = apply_filters( 'frmpro_field_links', $field_label, $args['id'], $field_key );
1750
		}
1751
		echo FrmAppHelper::kses( $field_label, array( 'a', 'i', 'span', 'use', 'svg' ) ); // WPCS: XSS ok.
1752
		?>
1753
		</li>
1754
		<?php
1755
	}
1756
1757
	/**
1758
	 * @deprecated 4.0
1759
	 */
1760
	public static function show_icon_link_js( $atts ) {
1761
		_deprecated_function( __METHOD__, '4.0' );
1762
		$atts['icon'] .= $atts['is_selected'] ? ' ' : ' frm_inactive_icon ';
1763
		if ( isset( $atts['has_default'] ) && ! $atts['has_default'] ) {
1764
			$atts['icon'] .= 'frm_hidden ';
1765
		}
1766
		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>';
1767
	}
1768
1769
	/**
1770
	 * @deprecated 4.0
1771
	 */
1772
	public static function show_default_blank_js( $is_selected, $has_default_value = true ) {
1773
		_deprecated_function( __METHOD__, '4.0' );
1774
	}
1775
1776
	/**
1777
	 * @deprecated 4.0
1778
	 */
1779
	public static function clear_on_focus_html( $field, $display, $id = '' ) {
1780
		_deprecated_function( __METHOD__, '4.0' );
1781
	}
1782
1783
	/**
1784
	 * @deprecated 4.0
1785
	 */
1786
	public static function show_onfocus_js( $is_selected, $has_default_value = true ) {
1787
		_deprecated_function( __METHOD__, '4.0' );
1788
	}
1789
1790
	/**
1791
	 * @deprecated 3.0
1792
	 * @codeCoverageIgnore
1793
	 */
1794
	public static function display_recaptcha() {
1795
		_deprecated_function( __FUNCTION__, '3.0', 'FrmFieldCaptcha::field_input' );
1796
	}
1797
1798
	/**
1799
	 * @deprecated 3.0
1800
	 * @codeCoverageIgnore
1801
	 */
1802
	public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) {
1803
		FrmDeprecated::remove_inline_conditions( $no_vars, $code, $replace_with, $html );
1804
	}
1805
1806
	/**
1807
	 * @deprecated 3.0
1808
	 * @codeCoverageIgnore
1809
	 */
1810
	public static function get_shortcode_tag( $shortcodes, $short_key, $args ) {
1811
		return FrmDeprecated::get_shortcode_tag( $shortcodes, $short_key, $args );
1812
	}
1813
1814
	/**
1815
	 * @deprecated 3.0
1816
	 * @codeCoverageIgnore
1817
	 *
1818
	 * @param string $html
1819
	 * @param array $field
1820
	 * @param array $errors
1821
	 * @param object $form
1822
	 * @param array $args
1823
	 *
1824
	 * @return string
1825
	 */
1826
	public static function replace_shortcodes( $html, $field, $errors = array(), $form = false, $args = array() ) {
1827
		return FrmDeprecated::replace_shortcodes( $html, $field, $errors, $form, $args );
1828
	}
1829
1830
	/**
1831
	 * @deprecated 3.0
1832
	 * @codeCoverageIgnore
1833
	 */
1834
	public static function get_default_field_opts( $type, $field = null, $limit = false ) {
1835
		return FrmDeprecated::get_default_field_opts( $type, $field, $limit );
1836
	}
1837
1838
	/**
1839
	 * @deprecated 2.02.07
1840
	 * @codeCoverageIgnore
1841
	 */
1842
	public static function dropdown_categories( $args ) {
1843
		return FrmDeprecated::dropdown_categories( $args );
1844
	}
1845
}
1846