Completed
Push — master ( fd1ed9...cc771e )
by Stephanie
02:50
created

FrmFieldsHelper::run_wpautop()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 6
nop 2
dl 0
loc 9
rs 9.2
c 0
b 0
f 0
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
		$values['field_options']['custom_html'] = self::get_default_html( $type );
23
24
		if ( isset( $setting ) && ! empty( $setting ) ) {
25
			if ( in_array( $type, array( 'data', 'lookup' ) ) ) {
26
				$values['field_options']['data_type'] = $setting;
27
			} else {
28
				$values['field_options'][ $setting ] = 1;
29
			}
30
		}
31
32
        return $values;
33
    }
34
35
	public static function get_html_id( $field, $plus = '' ) {
36
		return apply_filters( 'frm_field_html_id', 'field_' . $field['field_key'] . $plus, $field );
37
    }
38
39
    public static function setup_edit_vars( $field, $doing_ajax = false ) {
40
		$values = self::field_object_to_array( $field );
41
		return apply_filters( 'frm_setup_edit_field_vars', $values, array( 'doing_ajax' => $doing_ajax ) );
42
    }
43
44
	public static function field_object_to_array( $field ) {
45
		$values = (array) $field;
46
47
		self::fill_field_array( $field, $values );
48
49
		$values['custom_html'] = ( isset( $field->field_options['custom_html'] ) ) ? $field->field_options['custom_html'] : self::get_default_html( $field->type );
50
51
		return $values;
52
	}
53
54
	private static function fill_field_array( $field, array &$field_array ) {
55
		$field_array['options'] = $field->options;
56
		$field_array['value'] = $field->default_value;
57
58
		self::prepare_edit_front_field( $field_array, $field );
59
60
		$field_array = array_merge( $field->field_options, $field_array );
61
	}
62
63
	/**
64
	 * Prepare field while creating a new entry
65
	 * @since 3.0
66
	 */
67
	public static function prepare_new_front_field( &$field_array, $field, $args = array() ) {
68
		$args['action'] = 'new';
69
		self::prepare_front_field( $field_array, $field, $args );
70
	}
71
72
	/**
73
	 * Prepare field while editing an entry
74
	 * @since 3.0
75
	 */
76
	public static function prepare_edit_front_field( &$field_array, $field, $entry_id = 0, $args = array() ) {
77
		$args['entry_id'] = $entry_id;
78
		$args['action']   = 'edit';
79
		self::prepare_front_field( $field_array, $field, $args );
80
	}
81
82
	/**
83
	 * Prepare field while creating a new entry
84
	 * @since 3.0
85
	 */
86
	private static function prepare_front_field( &$field_array, $field, $args ) {
87
		self::fill_default_field_opts( $field, $field_array );
88
		self::fill_cleared_strings( $field, $field_array );
89
90
		// Track the original field's type
91
		$field_array['original_type'] = isset( $field->field_options['original_type'] ) ? $field->field_options['original_type'] : $field->type;
92
93
		self::prepare_field_options_for_display( $field_array, $field, $args );
94
95
		if ( $args['action'] == 'edit' ) {
96
			$field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $args['entry_id'], $args );
97
		} else {
98
			$field_array = apply_filters( 'frm_setup_new_fields_vars', $field_array, $field, $args );
99
		}
100
	}
101
102
	/**
103
	 * @since 3.0
104
	 *
105
	 * @param string $type
106
	 *
107
	 * @return array
108
	 */
109
	public static function get_default_field_options( $type ) {
110
		$field_type = FrmFieldFactory::get_field_type( $type );
111
		return $field_type->get_default_field_options();
112
	}
113
114
	/**
115
	 * @since 3.0
116
	 *
117
	 * @param object $field
118
	 * @param array $values
119
	 */
120
	private static function fill_default_field_opts( $field, array &$values ) {
121
		$check_post = FrmAppHelper::is_admin() && $_POST && isset( $_POST['field_options'] );
122
123
		$defaults = self::get_default_field_options_from_field( $field, $values );
124
		if ( ! $check_post ) {
125
			$defaults['required_indicator'] = '';
126
			$defaults['original_type']      = $field->type;
127
		}
128
129
		foreach ( $defaults as $opt => $default ) {
130
			$values[ $opt ] = isset( $field->field_options[ $opt ] ) ? $field->field_options[ $opt ] : $default;
131
132
			if ( $check_post ) {
133
				self::get_posted_field_setting( $opt . '_' . $field->id, $values[ $opt ] );
134
			}
135
136
			unset( $opt, $default );
137
		}
138
	}
139
140
	/**
141
	 * Fill the required message, invalid message,
142
	 * and refill the HTML when cleared
143
	 *
144
	 * @since 3.0
145
	 *
146
	 * @param object $field
147
	 * @param array $field_array
148
	 */
149
	private static function fill_cleared_strings( $field, array &$field_array ) {
150
		$frm_settings = FrmAppHelper::get_settings();
151
152
		if ( '' == $field_array['blank'] && '1' === $field_array['required'] ) {
153
			$field_array['blank'] = $frm_settings->blank_msg;
154
		}
155
156
		if ( '' == $field_array['invalid'] ) {
157
			if ( 'captcha' === $field->type ) {
158
				$field_array['invalid'] = $frm_settings->re_msg;
159
			} else {
160
				$field_array['invalid'] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] );
161
			}
162
		}
163
164
		if ( '' == $field_array['custom_html'] ) {
165
			$field_array['custom_html'] = FrmFieldsHelper::get_default_html( $field->type );
166
		}
167
	}
168
169
	/**
170
	 * @since 3.0
171
	 *
172
	 * @param string $setting
173
	 * @param mixed $value
174
	 */
175
	private static function get_posted_field_setting( $setting, &$value ) {
176
		if ( isset( $_POST['field_options'][ $setting ] ) ) {
177
			$value = maybe_unserialize( $_POST['field_options'][ $setting ] );
178
			if ( strpos( $setting, 'html' ) !== false ) {
179
				// strip slashes from HTML but not regex
180
				$value = stripslashes_deep( $value );
181
			}
182
		}
183
	}
184
185
	/**
186
	 * @since 3.0
187
	 *
188
	 * @param object $field
189
	 * @param array $values The field array is needed for hooks
190
	 *
191
	 * @return array
192
	 */
193
	public static function get_default_field_options_from_field( $field, $values = array() ) {
194
		$field_type = self::get_original_field( $field );
195
		$opts = $field_type->get_default_field_options();
196
197
		$opts = apply_filters( 'frm_default_field_opts', $opts, $values, $field );
198
		$opts = apply_filters( 'frm_default_' . $field->type . '_field_opts', $opts, $values, $field );
199
200
		return $opts;
201
	}
202
203
	/**
204
	 * @since 3.0
205
	 *
206
	 * @param object $field
207
	 *
208
	 * @return array
209
	 */
210
	private static function get_original_field( $field ) {
211
		$original_type = FrmField::get_option( $field, 'original_type' );
212
		if ( ! empty( $original_type ) && $field->type != $original_type ) {
213
			$field->type = $original_type;
214
		}
215
		return FrmFieldFactory::get_field_object( $field );
216
	}
217
218
	/**
219
	 * @since 3.0
220
	 *
221
	 * @param array $field_array
222
	 * @param object $field
223
	 * @param array $atts
224
	 */
225
	private static function prepare_field_options_for_display( &$field_array, $field, $atts ) {
226
		$field_obj = FrmFieldFactory::get_field_object( $field );
227
		$field_array = $field_obj->prepare_front_field( $field_array, $atts );
228
	}
229
230
	/**
231
	 * @since 3.0
232
	 *
233
	 * @param string $type
234
	 *
235
	 * @return array
236
	 */
237
	public static function get_default_field( $type ) {
238
		$field_type = FrmFieldFactory::get_field_type( $type );
239
		return $field_type->get_new_field_defaults();
240
	}
241
242
    public static function fill_field( &$values, $field, $form_id, $new_key = '' ) {
243
        global $wpdb;
244
245
		$values['field_key'] = FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_fields', 'field_key' );
246
        $values['form_id'] = $form_id;
247
        $values['options'] = maybe_serialize($field->options);
248
        $values['default_value'] = maybe_serialize($field->default_value);
249
250
        foreach ( array( 'name', 'description', 'type', 'field_order', 'field_options', 'required' ) as $col ) {
251
            $values[ $col ] = $field->{$col};
252
        }
253
    }
254
255
	/**
256
	 * @since 2.0
257
	 *
258
	 * @param $field
259
	 * @param $error
260
	 *
261
	 * @return string
262
	 */
263
	public static function get_error_msg( $field, $error ) {
264
		$frm_settings = FrmAppHelper::get_settings();
265
		$default_settings = $frm_settings->default_options();
266
		$field_name = is_array( $field ) ? $field['name'] : $field->name;
267
268
		$conf_msg = __( 'The entered values do not match', 'formidable' );
269
		$defaults = array(
270
			'unique_msg' => array(
271
				'full' => $default_settings['unique_msg'],
272
				'part' => sprintf( __('%s must be unique', 'formidable' ), $field_name ),
273
			),
274
			'invalid'  => array(
275
				'full' => __( 'This field is invalid', 'formidable' ),
276
				'part' => sprintf( __('%s is invalid', 'formidable' ), $field_name ),
277
			),
278
			'blank'    => array(
279
				'full' => $frm_settings->blank_msg,
280
				'part' => $frm_settings->blank_msg,
281
			),
282
			'conf_msg' => array(
283
				'full' => $conf_msg,
284
				'part' => $conf_msg,
285
			),
286
		);
287
288
		$msg = FrmField::get_option( $field, $error );
289
		$msg = empty( $msg ) ? $defaults[ $error ]['part'] : $msg;
290
		$msg = do_shortcode( $msg );
291
		return $msg;
292
	}
293
294
	public static function get_form_fields( $form_id, $error = array() ) {
295
		$fields = FrmField::get_all_for_form( $form_id );
296
		return apply_filters( 'frm_get_paged_fields', $fields, $form_id, $error );
297
	}
298
299
	public static function get_default_html( $type = 'text' ) {
300
		$field = FrmFieldFactory::get_field_type( $type );
301
		$default_html = $field->default_html();
302
303
		// these hooks are here for reverse compatibility since 3.0
304
		if ( ! apply_filters( 'frm_normal_field_type_html', true, $type ) ) {
305
			$default_html = apply_filters( 'frm_other_custom_html', '', $type );
306
		}
307
308
		return apply_filters('frm_custom_html', $default_html, $type);
309
	}
310
311
	/**
312
	 * @param array $fields
313
	 * @param array $errors
314
	 * @param object $form
315
	 * @param $form_action
316
	 */
317
	public static function show_fields( $fields, $errors, $form, $form_action ) {
318
		foreach ( $fields as $field ) {
319
			$field_obj = FrmFieldFactory::get_field_type( $field['type'], $field );
320
			$field_obj->show_field( compact( 'errors', 'form', 'form_action' ) );
321
		}
322
	}
323
324
	/**
325
	 * @deprecated 3.0
326
	 * @codeCoverageIgnore
327
	 *
328
	 * @param string $html
329
	 * @param array $field
330
	 * @param array $errors
331
	 * @param object $form
332
	 * @param array $args
333
	 *
334
	 * @return string
335
	 */
336
	public static function replace_shortcodes( $html, $field, $errors = array(), $form = false, $args = array() ) {
337
		_deprecated_function( __FUNCTION__, '3.0', 'FrmFieldType::prepare_field_html' );
338
		$field_obj = FrmFieldFactory::get_field_type( $field['type'], $field );
339
		return $field_obj->prepare_field_html( compact( 'errors', 'form' ) );
340
	}
341
342
	/**
343
	 * @since 3.0
344
	 *
345
	 * @param array $atts
346
	 * @param string|array $value
347
	 */
348
	public static function run_wpautop( $atts, &$value ) {
349
		$autop = isset( $atts['wpautop'] ) ? $atts['wpautop'] : true;
350
		if ( apply_filters( 'frm_use_wpautop', $autop ) ) {
351
			if ( is_array( $value ) ) {
352
				$value = implode( "\n", $value );
353
			}
354
			$value = wpautop( $value );
355
		}
356
	}
357
358
	/**
359
	 * Get the class to use for the label position
360
	 * @since 2.05
361
	 */
362
	public static function &label_position( $position, $field, $form ) {
363
		if ( $position && $position != '' ) {
364
			if ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
365
				$position = 'top';
366
			}
367
			return $position;
368
		}
369
370
		$position = FrmStylesController::get_style_val( 'position', $form );
371
		if ( $position == 'none' ) {
372
			$position = 'top';
373
		} elseif ( $position == 'no_label' ) {
374
			$position = 'none';
375
		} elseif ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) {
376
			$position = 'top';
377
		}
378
379
		$position = apply_filters( 'frm_html_label_position', $position, $field, $form );
380
		$position = ( ! empty( $position ) ) ? $position : 'top';
381
382
		return $position;
383
	}
384
385
	/**
386
	 * Check if this field type allows placeholders
387
	 * @since 2.05
388
	 */
389
	public static function is_placeholder_field_type( $type ) {
390
		return ! in_array( $type, array( 'select', 'radio', 'checkbox', 'hidden', 'file' ) );
391
	}
392
393
	/**
394
	 * @deprecated 3.0
395
	 * @codeCoverageIgnore
396
	 */
397
	public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) {
398
		_deprecated_function( __FUNCTION__, '3.0', 'FrmShortcodeHelper::remove_inline_conditions' );
399
		FrmShortcodeHelper::remove_inline_conditions( $no_vars, $code, $replace_with, $html );
400
	}
401
402
	/**
403
	 * @deprecated 3.0
404
	 * @codeCoverageIgnore
405
	 */
406
	public static function get_shortcode_tag( $shortcodes, $short_key, $args ) {
407
		_deprecated_function( __FUNCTION__, '3.0', 'FrmShortcodeHelper::get_shortcode_tag' );
408
        return FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key, $args );
409
    }
410
411
	public static function get_checkbox_id( $field, $opt_key ) {
412
		$id = $field['id'];
413
		if ( isset( $field['in_section'] ) && $field['in_section'] ) {
414
			$id .= '-' . $field['in_section'];
415
		}
416
		return 'frm_checkbox_' . $id . '-' . $opt_key;
417
	}
418
419
	/**
420
	 * @deprecated 3.0
421
	 * @codeCoverageIgnore
422
	 */
423
	public static function display_recaptcha( $field ) {
424
		_deprecated_function( __FUNCTION__, '3.0', 'FrmFieldCaptcha::field_input' );
425
    }
426
427
	public static function show_single_option( $field ) {
428
		if ( ! is_array( $field['options'] ) ) {
429
			return;
430
		}
431
432
		$field_name = isset( $field['html_name'] ) ? $field['html_name'] : $field['name'];
433
		$html_id = isset( $field['html_id'] ) ? $field['html_id'] : self::get_html_id( $field );
434
435
		foreach ( $field['options'] as $opt_key => $opt ) {
436
		    $field_val = self::get_value_from_array( $opt, $opt_key, $field );
437
		    $opt = self::get_label_from_array( $opt, $opt_key, $field );
438
439
			// Get string for Other text field, if needed
440
			$other_val = self::get_other_val( compact( 'opt_key', 'field' ) );
441
442
			$checked = ( $other_val || isset( $field['value'] ) && ( ( ! is_array( $field['value'] ) && $field['value'] == $field_val ) || ( is_array($field['value'] ) && in_array( $field_val, $field['value'] ) ) ) ) ? ' checked="checked"' : '';
443
444
		    // If this is an "Other" option, get the HTML for it
445
			if ( self::is_other_opt( $opt_key ) ) {
446
				if ( FrmAppHelper::pro_is_installed() ) {
447
					require( FrmProAppHelper::plugin_path() . '/classes/views/frmpro-fields/other-option.php' );
448
				}
449
		    } else {
450
				require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' );
451
		    }
452
453
			unset( $checked, $other_val );
454
		}
455
    }
456
457
	public static function get_value_from_array( $opt, $opt_key, $field ) {
458
		$opt = apply_filters( 'frm_field_value_saved', $opt, $opt_key, $field );
459
		return FrmFieldsController::check_value( $opt, $opt_key, $field );
460
	}
461
462
	public static function get_label_from_array( $opt, $opt_key, $field ) {
463
		$opt = apply_filters( 'frm_field_label_seen', $opt, $opt_key, $field );
464
		return FrmFieldsController::check_label( $opt );
465
	}
466
467
	/**
468
	 * @param int $tax_id
469
	 *
470
	 * @return string
471
	 */
472
	public static function get_term_link( $tax_id ) {
473
        $tax = get_taxonomy($tax_id);
474
        if ( ! $tax ) {
475
            return '';
476
        }
477
478
        $link = sprintf(
479
            __( 'Please add options from the WordPress "%1$s" page', 'formidable' ),
480
			'<a href="' . esc_url( admin_url( 'edit-tags.php?taxonomy=' . $tax->name ) ) . '" target="_blank">' . ( empty( $tax->labels->name ) ? __( 'Categories' ) : $tax->labels->name ) . '</a>'
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
481
        );
482
        unset($tax);
483
484
        return $link;
485
    }
486
487
	public static function value_meets_condition( $observed_value, $cond, $hide_opt ) {
488
		$hide_opt = self::get_value_for_comparision( $hide_opt );
489
		$observed_value = self::get_value_for_comparision( $observed_value );
490
491
        if ( is_array($observed_value) ) {
492
            return self::array_value_condition($observed_value, $cond, $hide_opt);
493
        }
494
495
        $m = false;
496
        if ( $cond == '==' ) {
497
            $m = $observed_value == $hide_opt;
498
        } else if ( $cond == '!=' ) {
499
            $m = $observed_value != $hide_opt;
500
        } else if ( $cond == '>' ) {
501
            $m = $observed_value > $hide_opt;
502
        } else if ( $cond == '<' ) {
503
            $m = $observed_value < $hide_opt;
504
        } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) {
505
            $m = stripos($observed_value, $hide_opt);
506
            if ( $cond == 'not LIKE' ) {
507
                $m = ( $m === false ) ? true : false;
508
            } else {
509
                $m = ( $m === false ) ? false : true;
510
            }
511
        }
512
        return $m;
513
    }
514
515
	/**
516
	 * Trim and sanitize the values
517
	 * @since 2.05
518
	 */
519
	private static function get_value_for_comparision( $value ) {
520
		// Remove white space from hide_opt
521
		if ( ! is_array( $value ) ) {
522
			$value = trim( $value );
523
		}
524
525
		return wp_kses_post( $value );
526
	}
527
528
	public static function array_value_condition( $observed_value, $cond, $hide_opt ) {
529
        $m = false;
530
        if ( $cond == '==' ) {
531
            if ( is_array($hide_opt) ) {
532
                $m = array_intersect($hide_opt, $observed_value);
533
                $m = empty($m) ? false : true;
534
            } else {
535
                $m = in_array($hide_opt, $observed_value);
536
            }
537
        } else if ( $cond == '!=' ) {
538
            $m = ! in_array($hide_opt, $observed_value);
539
        } else if ( $cond == '>' ) {
540
            $min = min($observed_value);
541
            $m = $min > $hide_opt;
542
        } else if ( $cond == '<' ) {
543
            $max = max($observed_value);
544
            $m = $max < $hide_opt;
545
        } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) {
546
            foreach ( $observed_value as $ob ) {
547
                $m = strpos($ob, $hide_opt);
548
                if ( $m !== false ) {
549
                    $m = true;
550
                    break;
551
                }
552
            }
553
554
            if ( $cond == 'not LIKE' ) {
555
                $m = ( $m === false ) ? true : false;
556
            }
557
        }
558
559
        return $m;
560
    }
561
562
    /**
563
     * Replace a few basic shortcodes and field ids
564
     * @since 2.0
565
     * @return string
566
     */
567
	public static function basic_replace_shortcodes( $value, $form, $entry ) {
568
        if ( strpos($value, '[sitename]') !== false ) {
569
            $new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES );
570
            $value = str_replace('[sitename]', $new_value, $value);
571
        }
572
573
        $value = apply_filters('frm_content', $value, $form, $entry);
574
        $value = do_shortcode($value);
575
576
        return $value;
577
    }
578
579
	public static function get_shortcodes( $content, $form_id ) {
580
        if ( FrmAppHelper::pro_is_installed() ) {
581
            return FrmProDisplaysHelper::get_shortcodes($content, $form_id);
582
        }
583
584
		$fields = FrmField::getAll( array(
585
			'fi.form_id'  => (int) $form_id,
586
			'fi.type not' => FrmField::no_save_fields(),
587
		) );
588
589
        $tagregexp = self::allowed_shortcodes($fields);
590
591
        preg_match_all("/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER);
592
593
        return $matches;
594
    }
595
596
	public static function allowed_shortcodes( $fields = array() ) {
597
		$tagregexp = array( 'editlink', 'id', 'key', 'ip', 'siteurl', 'sitename', 'admin_email', 'post[-|_]id', 'created[-|_]at', 'updated[-|_]at', 'updated[-|_]by', 'parent[-|_]id' );
598
599
        foreach ( $fields as $field ) {
600
            $tagregexp[] = $field->id;
601
            $tagregexp[] = $field->field_key;
602
        }
603
604
        $tagregexp = implode('|', $tagregexp);
605
        return $tagregexp;
606
    }
607
608
	public static function replace_content_shortcodes( $content, $entry, $shortcodes ) {
609
        foreach ( $shortcodes[0] as $short_key => $tag ) {
610
			if ( empty( $tag ) ) {
611
				continue;
612
			}
613
614
			$atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[3][ $short_key ] );
615
			$tag  = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key );
616
617
			$atts['entry'] = $entry;
618
			$atts['tag'] = $tag;
619
			$replace_with = self::get_value_for_shortcode( $atts );
620
621
			if ( $replace_with !== null ) {
622
				$content = str_replace( $shortcodes[0][ $short_key ], $replace_with, $content );
623
			}
624
625
			unset( $atts, $replace_with );
626
		}
627
628
		return $content;
629
    }
630
631
	/**
632
	 * @since 3.0
633
	 *
634
	 * @param $atts
635
	 *
636
	 * @return string
637
	 */
638
	private static function get_value_for_shortcode( $atts ) {
639
		$clean_tag = str_replace( '-', '_', $atts['tag'] );
640
641
		$shortcode_values = array(
642
			'id'     => $atts['entry']->id,
643
			'key'    => $atts['entry']->item_key,
644
			'ip'     => $atts['entry']->ip,
645
		);
646
647
		$dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get' );
648
649
		if ( isset( $shortcode_values[ $atts['tag'] ] ) ) {
650
			$replace_with = $shortcode_values[ $atts['tag'] ];
651
		} elseif ( in_array( $atts['tag'], $dynamic_default ) ) {
652
			$replace_with = self::dynamic_default_values( $atts['tag'], $atts );
653
		} elseif ( $clean_tag == 'user_agent' ) {
654
			$description = maybe_unserialize( $atts['entry']->description );
655
			$replace_with = FrmEntriesHelper::get_browser( $description['browser'] );
656
		} elseif ( $clean_tag == 'created_at' || $clean_tag == 'updated_at' ) {
657
			$atts['tag'] = $clean_tag;
658
			$replace_with = self::get_entry_timestamp( $atts );
659
		} elseif ( $clean_tag == 'created_by' || $clean_tag == 'updated_by' ) {
660
			$replace_with = self::get_display_value( $atts['entry']->{$clean_tag}, (object) array( 'type' => 'user_id' ), $atts );
661
		} else {
662
			$replace_with = self::get_field_shortcode_value( $atts );
663
		}
664
665
		return $replace_with;
666
	}
667
668
	/**
669
	 * @since 3.0
670
	 *
671
	 * @param $atts
672
	 *
673
	 * @return string
674
	 */
675
	private static function get_entry_timestamp( $atts ) {
676
		if ( isset( $atts['format'] ) ) {
677
			$time_format = ' ';
678
		} else {
679
			$atts['format'] = get_option('date_format');
680
			$time_format = '';
681
		}
682
683
		return FrmAppHelper::get_formatted_time( $atts['entry']->{$atts['tag']}, $atts['format'], $time_format );
684
	}
685
686
	/**
687
	 * @since 3.0
688
	 *
689
	 * @param $atts
690
	 *
691
	 * @return null|string
692
	 */
693
	private static function get_field_shortcode_value( $atts ) {
694
		$field = FrmField::getOne( $atts['tag'] );
695
		if ( empty( $field ) ) {
696
			return null;
697
		}
698
699
		if ( isset( $atts['show'] ) && $atts['show'] == 'field_label' ) {
700
			$replace_with = $field->name;
701
		} elseif ( isset( $atts['show'] ) && $atts['show'] == 'description' ) {
702
			$replace_with = $field->description;
703
		} else {
704
			$replace_with = FrmEntryMeta::get_meta_value( $atts['entry'], $field->id );
705
			$string_value = $replace_with;
706
			if ( is_array( $replace_with ) ) {
707
				$sep = isset( $atts['sep'] ) ? $atts['sep'] : ', ';
708
				$string_value = implode( $sep, $replace_with );
709
			}
710
711
			if ( empty( $string_value ) && $string_value != '0' ) {
712
				$replace_with = '';
713
			} else {
714
				$atts['entry_id']  = $atts['entry']->id;
715
				$atts['entry_key'] = $atts['entry']->item_key;
716
				$replace_with = self::get_display_value( $replace_with, $field, $atts );
717
			}
718
		}
719
720
		return $replace_with;
721
	}
722
723
    /**
724
     * Get the value to replace a few standard shortcodes
725
     *
726
     * @since 2.0
727
     * @return string
728
     */
729
    public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) {
730
        $new_value = '';
731
        switch ( $tag ) {
732
            case 'admin_email':
733
                $new_value = get_option('admin_email');
734
                break;
735
            case 'siteurl':
736
                $new_value = FrmAppHelper::site_url();
737
                break;
738
            case 'frmurl':
739
                $new_value = FrmAppHelper::plugin_url();
740
                break;
741
            case 'sitename':
742
                $new_value = FrmAppHelper::site_name();
743
                break;
744
            case 'get':
745
                $new_value = self::process_get_shortcode( $atts, $return_array );
746
        }
747
748
        return $new_value;
749
    }
750
751
    /**
752
     * Process the [get] shortcode
753
     *
754
     * @since 2.0
755
     * @return string|array
756
     */
757
    public static function process_get_shortcode( $atts, $return_array = false ) {
758
        if ( ! isset($atts['param']) ) {
759
            return '';
760
        }
761
762
        if ( strpos($atts['param'], '&#91;') ) {
763
            $atts['param'] = str_replace('&#91;', '[', $atts['param']);
764
            $atts['param'] = str_replace('&#93;', ']', $atts['param']);
765
        }
766
767
		$new_value = FrmAppHelper::get_param( $atts['param'], '', 'get', 'sanitize_text_field' );
768
        $new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] );
769
770
        if ( $new_value == '' ) {
771
            if ( ! isset($atts['prev_val']) ) {
772
                $atts['prev_val'] = '';
773
            }
774
775
            $new_value = isset($atts['default']) ? $atts['default'] : $atts['prev_val'];
776
        }
777
778
        if ( is_array($new_value) && ! $return_array ) {
779
            $new_value = implode(', ', $new_value);
780
        }
781
782
        return $new_value;
783
    }
784
785
	public static function get_display_value( $value, $field, $atts = array() ) {
786
787
		$value = apply_filters( 'frm_get_' . $field->type . '_display_value', $value, $field, $atts );
788
		$value = apply_filters( 'frm_get_display_value', $value, $field, $atts );
789
790
		return self::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) );
791
	}
792
793
	/**
794
	 * @param $atts array Includes value, field, and atts
795
	 */
796
	public static function get_unfiltered_display_value( $atts ) {
797
		$value = $atts['value'];
798
		$field = $atts['field'];
799
		$atts = isset( $atts['atts'] ) ? $atts['atts'] : $atts;
800
801
		if ( is_array( $field ) ) {
802
			$field = $field['id'];
803
		}
804
805
		$field_obj = FrmFieldFactory::get_field_object( $field );
806
		return $field_obj->get_display_value( $value, $atts );
807
	}
808
809
	/**
810
	 * Get a value from the user profile from the user ID
811
	 * @since 3.0
812
	 */
813
	public static function get_user_display_name( $user_id, $user_info = 'display_name', $args = array() ) {
814
		$defaults = array(
815
			'blank' => false,
816
			'link'  => false,
817
			'size'  => 96,
818
		);
819
820
		$args = wp_parse_args($args, $defaults);
821
822
		$user = get_userdata($user_id);
823
		$info = '';
824
825
		if ( $user ) {
826
			if ( $user_info == 'avatar' ) {
827
				$info = get_avatar( $user_id, $args['size'] );
828
			} elseif ( $user_info == 'author_link' ) {
829
				$info = get_author_posts_url( $user_id );
830
			} else {
831
				$info = isset($user->$user_info) ? $user->$user_info : '';
832
			}
833
834
			if ( 'display_name' === $user_info && empty( $info ) && ! $args['blank'] ) {
835
				$info = $user->user_login;
836
			}
837
		}
838
839
		if ( $args['link'] ) {
840
			$info = '<a href="' . esc_url( admin_url('user-edit.php?user_id=' . $user_id ) ) . '">' . $info . '</a>';
841
		}
842
843
		return $info;
844
	}
845
846
	public static function get_field_types( $type ) {
847
		$single_input = array( 'text', 'textarea', 'rte', 'number', 'email', 'url', 'file', 'date', 'phone', 'hidden', 'time', 'user_id', 'tag', 'password' );
848
		$multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' );
849
		$other_type = array( 'html', 'break' );
850
851
		$field_selection = array_merge( FrmField::pro_field_selection(), FrmField::field_selection() );
852
853
        $field_types = array();
854
        if ( in_array($type, $single_input) ) {
855
            self::field_types_for_input( $single_input, $field_selection, $field_types );
856
        } else if ( in_array($type, $multiple_input) ) {
857
            self::field_types_for_input( $multiple_input, $field_selection, $field_types );
858
        } else if ( in_array($type, $other_type) ) {
859
            self::field_types_for_input( $other_type, $field_selection, $field_types );
860
		} else if ( isset( $field_selection[ $type ] ) ) {
861
            $field_types[ $type ] = $field_selection[ $type ];
862
        }
863
864
		$field_types = apply_filters( 'frm_switch_field_types', $field_types, compact( 'type' ) );
865
        return $field_types;
866
    }
867
868
    private static function field_types_for_input( $inputs, $fields, &$field_types ) {
869
        foreach ( $inputs as $input ) {
870
            $field_types[ $input ] = $fields[ $input ];
871
            unset($input);
872
        }
873
    }
874
875
	/**
876
	 * Check if current field option is an "other" option
877
	 *
878
	 * @since 2.0.6
879
	 *
880
	 * @param string $opt_key
881
	 * @return boolean Returns true if current field option is an "Other" option
882
	 */
883
	public static function is_other_opt( $opt_key ) {
884
		return $opt_key && strpos( $opt_key, 'other_' ) === 0;
885
	}
886
887
    /**
888
    * Get value that belongs in "Other" text box
889
    *
890
    * @since 2.0.6
891
    *
892
    * @param array $args
893
    */
894
    public static function get_other_val( $args ) {
895
		$defaults = array(
896
			'opt_key' => 0,
897
			'field'   => array(),
898
			'parent'  => false,
899
			'pointer' => false,
900
		);
901
		$args = wp_parse_args( $args, $defaults );
902
903
		$opt_key = $args['opt_key'];
904
		$field = $args['field'];
905
		$parent = $args['parent'];
906
		$pointer = $args['pointer'];
907
		$other_val = '';
908
909
		// If option is an "other" option and there is a value set for this field,
910
		// check if the value belongs in the current "Other" option text field
911
		if ( ! FrmFieldsHelper::is_other_opt( $opt_key ) || ! FrmField::is_option_true( $field, 'value' ) ) {
912
			return $other_val;
913
		}
914
915
		// Check posted vals before checking saved values
916
917
		// For fields inside repeating sections - note, don't check if $pointer is true because it will often be zero
918
		if ( $parent && isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ) {
919
			if ( FrmField::is_field_with_multiple_values( $field ) ) {
920
				$other_val = isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ][ $opt_key ] ) : '';
921
			} else {
922
				$other_val = sanitize_text_field( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] );
923
			}
924
			return $other_val;
925
926
		} else if ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) {
927
			// For normal fields
928
929
			if ( FrmField::is_field_with_multiple_values( $field ) ) {
930
				$other_val = isset( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) : '';
931
			} else {
932
				$other_val = sanitize_text_field( $_POST['item_meta']['other'][ $field['id'] ] );
933
			}
934
			return $other_val;
935
		}
936
937
		// For checkboxes
938
		if ( $field['type'] == 'checkbox' && is_array( $field['value'] ) ) {
939
			// Check if there is an "other" val in saved value and make sure the
940
			// "other" val is not equal to the Other checkbox option
941
			if ( isset( $field['value'][ $opt_key ] ) && $field['options'][ $opt_key ] != $field['value'][ $opt_key ] ) {
942
				$other_val = $field['value'][ $opt_key ];
943
			}
944
		} else {
945
			/**
946
			 * For radio buttons and dropdowns
947
			 * Check if saved value equals any of the options. If not, set it as the other value.
948
			 */
949
			foreach ( $field['options'] as $opt_key => $opt_val ) {
950
				$temp_val = is_array( $opt_val ) ? $opt_val['value'] : $opt_val;
951
				// Multi-select dropdowns - key is not preserved
952
				if ( is_array( $field['value'] ) ) {
953
					$o_key = array_search( $temp_val, $field['value'] );
954
					if ( isset( $field['value'][ $o_key ] ) ) {
955
						unset( $field['value'][ $o_key ], $o_key );
956
					}
957
				} else if ( $temp_val == $field['value'] ) {
958
					// For radio and regular dropdowns
959
					return '';
960
				} else {
961
					$other_val = $field['value'];
962
				}
963
				unset( $opt_key, $opt_val, $temp_val );
964
			}
965
			// For multi-select dropdowns only
966
			if ( is_array( $field['value'] ) && ! empty( $field['value'] ) ) {
967
				$other_val = reset( $field['value'] );
968
			}
969
		}
970
971
		return $other_val;
972
    }
973
974
    /**
975
    * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val.
976
    * Intended for front-end use
977
    *
978
    * @since 2.0.6
979
    *
980
    * @param array $args should include field, opt_key and field name
981
    * @param boolean $other_opt
982
    * @param string $checked
983
    * @return array $other_args
984
    */
985
    public static function prepare_other_input( $args, &$other_opt, &$checked ) {
986
		//Check if this is an "Other" option
987
		if ( ! self::is_other_opt( $args['opt_key'] ) ) {
988
			return;
989
		}
990
991
		$other_opt = true;
992
		$other_args = array();
993
994
		self::set_other_name( $args, $other_args );
995
		self::set_other_value( $args, $other_args );
996
997
		if ( $other_args['value'] ) {
998
			$checked = 'checked="checked" ';
999
		}
1000
1001
        return $other_args;
1002
    }
1003
1004
	/**
1005
	 * @param array $args
1006
	 * @param array $other_args
1007
	 * @since 2.0.6
1008
	 */
1009
	private static function set_other_name( $args, &$other_args ) {
1010
		//Set up name for other field
1011
		$other_args['name'] = str_replace( '[]', '', $args['field_name'] );
1012
		$other_args['name'] = preg_replace('/\[' . $args['field']['id'] . '\]$/', '', $other_args['name']);
1013
		$other_args['name'] = $other_args['name'] . '[other]' . '[' . $args['field']['id'] . ']';
1014
1015
		//Converts item_meta[field_id] => item_meta[other][field_id] and
1016
		//item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id]
1017
		if ( FrmField::is_field_with_multiple_values( $args['field'] ) ) {
1018
			$other_args['name'] .= '[' . $args['opt_key'] . ']';
1019
		}
1020
	}
1021
1022
	/**
1023
	 * Find the parent and pointer, and get text for "other" text field
1024
	 * @param array $args
1025
	 * @param array $other_args
1026
	 *
1027
	 * @since 2.0.6
1028
	 */
1029
	private static function set_other_value( $args, &$other_args ) {
1030
		$parent = '';
1031
		$pointer = '';
1032
1033
		// Check for parent ID and pointer
1034
		$temp_array = explode( '[', $args['field_name'] );
1035
1036
		// Count should only be greater than 3 if inside of a repeating section
1037
		if ( count( $temp_array ) > 3 ) {
1038
			$parent = str_replace( ']', '', $temp_array[1] );
1039
			$pointer = str_replace( ']', '', $temp_array[2]);
1040
		}
1041
1042
		// Get text for "other" text field
1043
		$other_args['value'] = self::get_other_val( array(
1044
			'opt_key' => $args['opt_key'],
1045
			'field'   => $args['field'],
1046
			'parent'  => $parent,
1047
			'pointer' => $pointer,
1048
		) );
1049
	}
1050
1051
	/**
1052
	 * If this field includes an other option, show it
1053
	 * @param $args array
1054
	 * @since 2.0.6
1055
	 */
1056
	public static function include_other_input( $args ) {
1057
        if ( ! $args['other_opt'] ) {
1058
        	return;
1059
		}
1060
1061
		$classes = array( 'frm_other_input' );
1062
		if ( ! $args['checked'] || trim( $args['checked'] ) == '' ) {
1063
			// hide the field if the other option is not selected
1064
			$classes[] = 'frm_pos_none';
1065
		}
1066
		if ( $args['field']['type'] == 'select' && $args['field']['multiple'] ) {
1067
			$classes[] = 'frm_other_full';
1068
		}
1069
1070
		// Set up HTML ID for Other field
1071
		$other_id = self::get_other_field_html_id( $args['field']['type'], $args['html_id'], $args['opt_key'] );
1072
1073
		$label = isset( $args['opt_label'] ) ? $args['opt_label'] : $args['field']['name'];
1074
1075
		?><label for="<?php echo esc_attr( $other_id ) ?>" class="frm_screen_reader frm_hidden"><?php
1076
		echo esc_html( $label );
1077
		?></label><input type="text" id="<?php echo esc_attr( $other_id ) ?>" class="<?php echo sanitize_text_field( implode( ' ', $classes ) ) ?>" <?php
1078
		echo ( $args['read_only'] ? ' readonly="readonly" disabled="disabled"' : '' );
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1079
		?> name="<?php echo esc_attr( $args['name'] ) ?>" value="<?php echo esc_attr( $args['value'] ); ?>" /><?php
1080
	}
1081
1082
	/**
1083
	* Get the HTML id for an "Other" text field
1084
	* Note: This does not affect fields in repeating sections
1085
	*
1086
	* @since 2.0.08
1087
	* @param string $type - field type
1088
	* @param string $html_id
1089
	* @param string|boolean $opt_key
1090
	* @return string $other_id
1091
	*/
1092
	public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) {
1093
		$other_id = $html_id;
1094
1095
		// If hidden radio field, add an opt key of 0
1096
		if ( $type == 'radio' && $opt_key === false ) {
1097
			$opt_key = 0;
1098
		}
1099
1100
		if ( $opt_key !== false ) {
1101
			$other_id .= '-' . $opt_key;
1102
		}
1103
1104
		$other_id .= '-otext';
1105
1106
		return $other_id;
1107
	}
1108
1109
	public static function clear_on_focus_html( $field, $display, $id = '' ) {
1110
		if ( $display['clear_on_focus'] ) {
1111
			$has_default_value = ! empty( $field['default_value'] );
1112
			echo '<span id="frm_clear_on_focus_' . esc_attr( $field['id'] . $id ) . '" class="frm-show-click">';
1113
1114
			if ( $display['default_blank'] ) {
1115
				self::show_default_blank_js( $field['default_blank'], $has_default_value );
1116
				echo '<input type="hidden" name="field_options[default_blank_' . esc_attr( $field['id'] ) . ']" value="' . esc_attr( $field['default_blank'] ) . '" />';
1117
			}
1118
1119
			self::show_onfocus_js( $field['clear_on_focus'], $has_default_value );
1120
			echo '<input type="hidden" name="field_options[clear_on_focus_' . esc_attr( $field['id'] ) . ']" value="' . esc_attr( $field['clear_on_focus'] ) . '" />';
1121
1122
			echo '</span>';
1123
		}
1124
	}
1125
1126 View Code Duplication
	public static function show_onfocus_js( $is_selected, $has_default_value = true ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
1127
		$atts = array(
1128
			'icon'        => 'frm_reload_icon',
1129
			'message'     => $is_selected ? __( 'Clear default value when typing', 'formidable' ) : __( 'Do not clear default value when typing', 'formidable' ),
1130
			'is_selected' => $is_selected,
1131
			'has_default' => $has_default_value,
1132
		);
1133
		self::show_icon_link_js( $atts );
1134
	}
1135
1136 View Code Duplication
	public static function show_default_blank_js( $is_selected, $has_default_value = true ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
1137
		$atts = array(
1138
			'icon'        => 'frm_error_icon',
1139
			'message'     => $is_selected ? __( 'Default value will NOT pass form validation', 'formidable' ) : __( 'Default value will pass form validation', 'formidable' ),
1140
			'is_selected' => $is_selected,
1141
			'has_default' => $has_default_value,
1142
		);
1143
		self::show_icon_link_js( $atts );
1144
	}
1145
1146
	public static function show_icon_link_js( $atts ) {
1147
		$atts['icon'] .= $atts['is_selected'] ? ' ' : ' frm_inactive_icon ';
1148
		if ( isset( $atts['has_default'] ) && ! $atts['has_default'] ) {
1149
			$atts['icon'] .= 'frm_hidden ';
1150
		}
1151
		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>';
1152
	}
1153
1154
	public static function switch_field_ids( $val ) {
1155
        global $frm_duplicate_ids;
1156
        $replace = array();
1157
        $replace_with = array();
1158
        foreach ( (array) $frm_duplicate_ids as $old => $new ) {
1159
			$replace[] = '[if ' . $old . ']';
1160
			$replace_with[] = '[if ' . $new . ']';
1161
			$replace[] = '[if ' . $old . ' ';
1162
			$replace_with[] = '[if ' . $new . ' ';
1163
			$replace[] = '[/if ' . $old . ']';
1164
			$replace_with[] = '[/if ' . $new . ']';
1165
			$replace[] = '[foreach ' . $old . ']';
1166
			$replace_with[] = '[foreach ' . $new . ']';
1167
			$replace[] = '[/foreach ' . $old . ']';
1168
			$replace_with[] = '[/foreach ' . $new . ']';
1169
			$replace[] = '[' . $old . ']';
1170
			$replace_with[] = '[' . $new . ']';
1171
			$replace[] = '[' . $old . ' ';
1172
			$replace_with[] = '[' . $new . ' ';
1173
            unset($old, $new);
1174
        }
1175
		if ( is_array( $val ) ) {
1176
			foreach ( $val as $k => $v ) {
1177
                $val[ $k ] = str_replace( $replace, $replace_with, $v );
1178
                unset($k, $v);
1179
            }
1180
        } else {
1181
            $val = str_replace($replace, $replace_with, $val);
1182
        }
1183
1184
        return $val;
1185
    }
1186
1187
	public static function get_us_states() {
1188
		return apply_filters( 'frm_us_states', array(
1189
			'AL' => 'Alabama',
1190
			'AK' => 'Alaska',
1191
			'AR' => 'Arkansas',
1192
			'AZ' => 'Arizona',
1193
			'CA' => 'California',
1194
			'CO' => 'Colorado',
1195
			'CT' => 'Connecticut',
1196
			'DE' => 'Delaware',
1197
			'DC' => 'District of Columbia',
1198
			'FL' => 'Florida',
1199
			'GA' => 'Georgia',
1200
			'HI' => 'Hawaii',
1201
			'ID' => 'Idaho',
1202
			'IL' => 'Illinois',
1203
			'IN' => 'Indiana',
1204
			'IA' => 'Iowa',
1205
			'KS' => 'Kansas',
1206
			'KY' => 'Kentucky',
1207
			'LA' => 'Louisiana',
1208
			'ME' => 'Maine',
1209
			'MD' => 'Maryland',
1210
			'MA' => 'Massachusetts',
1211
			'MI' => 'Michigan',
1212
			'MN' => 'Minnesota',
1213
			'MS' => 'Mississippi',
1214
			'MO' => 'Missouri',
1215
			'MT' => 'Montana',
1216
			'NE' => 'Nebraska',
1217
			'NV' => 'Nevada',
1218
			'NH' => 'New Hampshire',
1219
			'NJ' => 'New Jersey',
1220
			'NM' => 'New Mexico',
1221
			'NY' => 'New York',
1222
			'NC' => 'North Carolina',
1223
			'ND' => 'North Dakota',
1224
			'OH' => 'Ohio',
1225
			'OK' => 'Oklahoma',
1226
			'OR' => 'Oregon',
1227
			'PA' => 'Pennsylvania',
1228
			'RI' => 'Rhode Island',
1229
			'SC' => 'South Carolina',
1230
			'SD' => 'South Dakota',
1231
			'TN' => 'Tennessee',
1232
			'TX' => 'Texas',
1233
			'UT' => 'Utah',
1234
			'VT' => 'Vermont',
1235
			'VA' => 'Virginia',
1236
			'WA' => 'Washington',
1237
			'WV' => 'West Virginia',
1238
			'WI' => 'Wisconsin',
1239
			'WY' => 'Wyoming',
1240
		) );
1241
	}
1242
1243
	public static function get_countries() {
1244
		return apply_filters( 'frm_countries', array( __( 'Afghanistan', 'formidable' ), __( 'Albania', 'formidable' ), __( 'Algeria', 'formidable' ), __( 'American Samoa', 'formidable' ), __( 'Andorra', 'formidable' ), __( 'Angola', 'formidable' ), __( 'Anguilla', 'formidable' ), __( 'Antarctica', 'formidable' ), __( 'Antigua and Barbuda', 'formidable' ), __( 'Argentina', 'formidable' ), __( 'Armenia', 'formidable' ), __( 'Aruba', 'formidable' ), __( 'Australia', 'formidable' ), __( 'Austria', 'formidable' ), __( 'Azerbaijan', 'formidable' ), __( 'Bahamas', 'formidable' ), __( 'Bahrain', 'formidable' ), __( 'Bangladesh', 'formidable' ), __( 'Barbados', 'formidable' ), __( 'Belarus', 'formidable' ), __( 'Belgium', 'formidable' ), __( 'Belize', 'formidable' ), __( 'Benin', 'formidable' ), __( 'Bermuda', 'formidable' ), __( 'Bhutan', 'formidable' ), __( 'Bolivia', 'formidable' ), __( 'Bosnia and Herzegovina', 'formidable' ), __( 'Botswana', 'formidable' ), __( 'Brazil', 'formidable' ), __( 'Brunei', 'formidable' ), __( 'Bulgaria', 'formidable' ), __( 'Burkina Faso', 'formidable' ), __( 'Burundi', 'formidable' ), __( 'Cambodia', 'formidable' ), __( 'Cameroon', 'formidable' ), __( 'Canada', 'formidable' ), __( 'Cape Verde', 'formidable' ), __( 'Cayman Islands', 'formidable' ), __( 'Central African Republic', 'formidable' ), __( 'Chad', 'formidable' ), __( 'Chile', 'formidable' ), __( 'China', 'formidable' ), __( 'Colombia', 'formidable' ), __( 'Comoros', 'formidable' ), __( 'Congo', 'formidable' ), __( 'Costa Rica', 'formidable' ), __( 'C&ocirc;te d\'Ivoire', 'formidable' ), __( 'Croatia', 'formidable' ), __( 'Cuba', 'formidable' ), __( 'Cyprus', 'formidable' ), __( 'Czech Republic', 'formidable' ), __( 'Denmark', 'formidable' ), __( 'Djibouti', 'formidable' ), __( 'Dominica', 'formidable' ), __( 'Dominican Republic', 'formidable' ), __( 'East Timor', 'formidable' ), __( 'Ecuador', 'formidable' ), __( 'Egypt', 'formidable' ), __( 'El Salvador', 'formidable' ), __( 'Equatorial Guinea', 'formidable' ), __( 'Eritrea', 'formidable' ), __( 'Estonia', 'formidable' ), __( 'Ethiopia', 'formidable' ), __( 'Fiji', 'formidable' ), __( 'Finland', 'formidable' ), __( 'France', 'formidable' ), __( 'French Guiana', 'formidable' ), __( 'French Polynesia', 'formidable' ), __( 'Gabon', 'formidable' ), __( 'Gambia', 'formidable' ), __( 'Georgia', 'formidable' ), __( 'Germany', 'formidable' ), __( 'Ghana', 'formidable' ), __( 'Gibraltar', 'formidable' ), __( 'Greece', 'formidable' ), __( 'Greenland', 'formidable' ), __( 'Grenada', 'formidable' ), __( 'Guam', 'formidable' ), __( 'Guatemala', 'formidable' ), __( 'Guinea', 'formidable' ), __( 'Guinea-Bissau', 'formidable' ), __( 'Guyana', 'formidable' ), __( 'Haiti', 'formidable' ), __( 'Honduras', 'formidable' ), __( 'Hong Kong', 'formidable' ), __( 'Hungary', 'formidable' ), __( 'Iceland', 'formidable' ), __( 'India', 'formidable' ), __( 'Indonesia', 'formidable' ), __( 'Iran', 'formidable' ), __( 'Iraq', 'formidable' ), __( 'Ireland', 'formidable' ), __( 'Israel', 'formidable' ), __( 'Italy', 'formidable' ), __( 'Jamaica', 'formidable' ), __( 'Japan', 'formidable' ), __( 'Jordan', 'formidable' ), __( 'Kazakhstan', 'formidable' ), __( 'Kenya', 'formidable' ), __( 'Kiribati', 'formidable' ), __( 'North Korea', 'formidable' ), __( 'South Korea', 'formidable' ), __( 'Kuwait', 'formidable' ), __( 'Kyrgyzstan', 'formidable' ), __( 'Laos', 'formidable' ), __( 'Latvia', 'formidable' ), __( 'Lebanon', 'formidable' ), __( 'Lesotho', 'formidable' ), __( 'Liberia', 'formidable' ), __( 'Libya', 'formidable' ), __( 'Liechtenstein', 'formidable' ), __( 'Lithuania', 'formidable' ), __( 'Luxembourg', 'formidable' ), __( 'Macedonia', 'formidable' ), __( 'Madagascar', 'formidable' ), __( 'Malawi', 'formidable' ), __( 'Malaysia', 'formidable' ), __( 'Maldives', 'formidable' ), __( 'Mali', 'formidable' ), __( 'Malta', 'formidable' ), __( 'Marshall Islands', 'formidable' ), __( 'Mauritania', 'formidable' ), __( 'Mauritius', 'formidable' ), __( 'Mexico', 'formidable' ), __( 'Micronesia', 'formidable' ), __( 'Moldova', 'formidable' ), __( 'Monaco', 'formidable' ), __( 'Mongolia', 'formidable' ), __( 'Montenegro', 'formidable' ), __( 'Montserrat', 'formidable' ), __( 'Morocco', 'formidable' ), __( 'Mozambique', 'formidable' ), __( 'Myanmar', 'formidable' ), __( 'Namibia', 'formidable' ), __( 'Nauru', 'formidable' ), __( 'Nepal', 'formidable' ), __( 'Netherlands', 'formidable' ), __( 'New Zealand', 'formidable' ), __( 'Nicaragua', 'formidable' ), __( 'Niger', 'formidable' ), __( 'Nigeria', 'formidable' ), __( 'Norway', 'formidable' ), __( 'Northern Mariana Islands', 'formidable' ), __( 'Oman', 'formidable' ), __( 'Pakistan', 'formidable' ), __( 'Palau', 'formidable' ), __( 'Palestine', 'formidable' ), __( 'Panama', 'formidable' ), __( 'Papua New Guinea', 'formidable' ), __( 'Paraguay', 'formidable' ), __( 'Peru', 'formidable' ), __( 'Philippines', 'formidable' ), __( 'Poland', 'formidable' ), __( 'Portugal', 'formidable' ), __( 'Puerto Rico', 'formidable' ), __( 'Qatar', 'formidable' ), __( 'Romania', 'formidable' ), __( 'Russia', 'formidable' ), __( 'Rwanda', 'formidable' ), __( 'Saint Kitts and Nevis', 'formidable' ), __( 'Saint Lucia', 'formidable' ), __( 'Saint Vincent and the Grenadines', 'formidable' ), __( 'Samoa', 'formidable' ), __( 'San Marino', 'formidable' ), __( 'Sao Tome and Principe', 'formidable' ), __( 'Saudi Arabia', 'formidable' ), __( 'Senegal', 'formidable' ), __( 'Serbia and Montenegro', 'formidable' ), __( 'Seychelles', 'formidable' ), __( 'Sierra Leone', 'formidable' ), __( 'Singapore', 'formidable' ), __( 'Slovakia', 'formidable' ), __( 'Slovenia', 'formidable' ), __( 'Solomon Islands', 'formidable' ), __( 'Somalia', 'formidable' ), __( 'South Africa', 'formidable' ), __( 'South Sudan', 'formidable' ), __( 'Spain', 'formidable' ), __( 'Sri Lanka', 'formidable' ), __( 'Sudan', 'formidable' ), __( 'Suriname', 'formidable' ), __( 'Swaziland', 'formidable' ), __( 'Sweden', 'formidable' ), __( 'Switzerland', 'formidable' ), __( 'Syria', 'formidable' ), __( 'Taiwan', 'formidable' ), __( 'Tajikistan', 'formidable' ), __( 'Tanzania', 'formidable' ), __( 'Thailand', 'formidable' ), __( 'Togo', 'formidable' ), __( 'Tonga', 'formidable' ), __( 'Trinidad and Tobago', 'formidable' ), __( 'Tunisia', 'formidable' ), __( 'Turkey', 'formidable' ), __( 'Turkmenistan', 'formidable' ), __( 'Tuvalu', 'formidable' ), __( 'Uganda', 'formidable' ), __( 'Ukraine', 'formidable' ), __( 'United Arab Emirates', 'formidable' ), __( 'United Kingdom', 'formidable' ), __( 'United States', 'formidable' ), __( 'Uruguay', 'formidable' ), __( 'Uzbekistan', 'formidable' ), __( 'Vanuatu', 'formidable' ), __( 'Vatican City', 'formidable' ), __( 'Venezuela', 'formidable' ), __( 'Vietnam', 'formidable' ), __( 'Virgin Islands, British', 'formidable' ), __( 'Virgin Islands, U.S.', 'formidable' ), __( 'Yemen', 'formidable' ), __( 'Zambia', 'formidable' ), __( 'Zimbabwe', 'formidable' ) ) );
1245
	}
1246
1247
	public static function get_bulk_prefilled_opts( array &$prepop ) {
1248
		$prepop[ __( 'Countries', 'formidable' ) ] = FrmFieldsHelper::get_countries();
1249
1250
        $states = FrmFieldsHelper::get_us_states();
1251
        $state_abv = array_keys($states);
1252
        sort($state_abv);
1253
		$prepop[ __( 'U.S. State Abbreviations', 'formidable' ) ] = $state_abv;
1254
1255
        $states = array_values($states);
1256
        sort($states);
1257
		$prepop[ __( 'U.S. States', 'formidable' ) ] = $states;
1258
        unset($state_abv, $states);
1259
1260
		$prepop[ __( 'Age', 'formidable' ) ] = array(
1261
			__( 'Under 18', 'formidable' ),
1262
			__( '18-24', 'formidable' ),
1263
			__( '25-34', 'formidable' ),
1264
			__( '35-44', 'formidable' ),
1265
			__( '45-54', 'formidable' ),
1266
			__( '55-64', 'formidable' ),
1267
			__( '65 or Above', 'formidable' ),
1268
			__( 'Prefer Not to Answer', 'formidable' ),
1269
		);
1270
1271
		$prepop[ __( 'Satisfaction', 'formidable' ) ] = array(
1272
			__( 'Very Satisfied', 'formidable' ),
1273
			__( 'Satisfied', 'formidable' ),
1274
			__( 'Neutral', 'formidable' ),
1275
			__( 'Unsatisfied', 'formidable' ),
1276
			__( 'Very Unsatisfied', 'formidable' ),
1277
			__( 'N/A', 'formidable' ),
1278
		);
1279
1280
		$prepop[ __( 'Importance', 'formidable' ) ] = array(
1281
			__( 'Very Important', 'formidable' ),
1282
			__( 'Important', 'formidable' ),
1283
			__( 'Neutral', 'formidable' ),
1284
			__( 'Somewhat Important', 'formidable' ),
1285
			__( 'Not at all Important', 'formidable' ),
1286
			__( 'N/A', 'formidable' ),
1287
		);
1288
1289
		$prepop[ __( 'Agreement', 'formidable' ) ] = array(
1290
			__( 'Strongly Agree', 'formidable' ),
1291
			__( 'Agree', 'formidable' ),
1292
			__( 'Neutral', 'formidable' ),
1293
			__( 'Disagree', 'formidable' ),
1294
			__( 'Strongly Disagree', 'formidable' ),
1295
			__( 'N/A', 'formidable' ),
1296
		);
1297
1298
		$prepop = apply_filters( 'frm_bulk_field_choices', $prepop );
1299
    }
1300
1301
	/**
1302
	 * Display a field value selector
1303
	 *
1304
	 * @since 2.03.05
1305
	 *
1306
	 * @param int $selector_field_id
1307
	 * @param array $selector_args
1308
	 */
1309
    public static function display_field_value_selector( $selector_field_id, $selector_args ) {
1310
	    $field_value_selector = FrmFieldFactory::create_field_value_selector( $selector_field_id, $selector_args );
1311
	    $field_value_selector->display();
1312
    }
1313
1314
	/**
1315
	 * Convert a field object to a flat array
1316
	 *
1317
	 * @since 2.03.05
1318
	 *
1319
	 * @param object $field
1320
	 *
1321
	 * @return array
1322
	 */
1323
	public static function convert_field_object_to_flat_array( $field ) {
1324
		$field_options = $field->field_options;
1325
		$field_array = get_object_vars( $field );
1326
		unset( $field_array['field_options'] );
1327
		return $field_array + $field_options;
1328
	}
1329
1330
	/**
1331
	 * @deprecated 3.0
1332
	 * @codeCoverageIgnore
1333
	 */
1334
	public static function get_default_field_opts( $type, $field = null, $limit = false ) {
1335
		if ( $limit ) {
1336
			_deprecated_function( __FUNCTION__, '3.0', 'FrmFieldHelper::get_default_field_options' );
1337
			$field_options = self::get_default_field_options( $type );
1338
		} else {
1339
			_deprecated_function( __FUNCTION__, '3.0', 'FrmFieldHelper::get_default_field' );
1340
			$field_options = self::get_default_field( $type );
1341
		}
1342
1343
		return $field_options;
1344
	}
1345
1346
	/**
1347
	 * @deprecated 2.02.07
1348
	 * @codeCoverageIgnore
1349
	 */
1350
	public static function dropdown_categories( $args ) {
1351
		_deprecated_function( __FUNCTION__, '2.02.07', 'FrmProPost::get_category_dropdown' );
1352
1353
		if ( FrmAppHelper::pro_is_installed() ) {
1354
			$args['location'] = 'front';
1355
			$dropdown = FrmProPost::get_category_dropdown( $args['field'], $args );
1356
		} else {
1357
			$dropdown = '';
1358
		}
1359
1360
		return $dropdown;
1361
	}
1362
}
1363