Completed
Branch 3.0 (991649)
by Stephanie
02:44
created

FrmFieldsHelper::get_field_div_classes()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 25
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

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