Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like FrmFieldsHelper often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FrmFieldsHelper, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
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 | public static function replace_shortcodes_before_input( $args, &$html ) { |
||
195 | $field = $args['field']; |
||
196 | |||
197 | // Remove the for attribute for captcha |
||
198 | if ( $field['type'] == 'captcha' ) { |
||
199 | $html = str_replace( ' for="field_[key]"', '', $html ); |
||
200 | } |
||
201 | |||
202 | self::replace_field_values( $field, $args, $html ); |
||
203 | self::add_class_to_divider( $field, $html ); |
||
204 | |||
205 | self::replace_required_label_shortcode( $field, $html ); |
||
206 | self::replace_required_class( $field, $html ); |
||
207 | self::replace_description_shortcode( $field, $html ); |
||
208 | self::replace_error_shortcode( $args, $html ); |
||
209 | self::add_class_to_label( $field, $html ); |
||
210 | self::add_field_div_classes( $args['field_id'], $field, $args['errors'], $html ); |
||
211 | |||
212 | self::replace_entry_key( $html ); |
||
213 | self::replace_form_shortcodes( $args['form'], $html ); |
||
214 | self::process_wp_shortcodes( $html ); |
||
215 | } |
||
216 | |||
217 | /** |
||
218 | * @since 3.0 |
||
219 | */ |
||
220 | private static function replace_field_values( $field, $args, &$html ) { |
||
221 | //replace [id] |
||
222 | $html = str_replace( '[id]', $args['field_id'], $html ); |
||
223 | |||
224 | // set the label for |
||
225 | $html = str_replace( 'field_[key]', $args['html_id'], $html ); |
||
226 | |||
227 | //replace [key] |
||
228 | $html = str_replace( '[key]', $field['field_key'], $html ); |
||
229 | |||
230 | //replace [field_name] |
||
231 | $html = str_replace('[field_name]', $field['name'], $html ); |
||
232 | } |
||
233 | |||
234 | /** |
||
235 | * If field type is section heading, add class so a bottom margin |
||
236 | * can be added to either the h3 or description |
||
237 | * |
||
238 | * @since 3.0 |
||
239 | */ |
||
240 | private static function add_class_to_divider( $field, &$html ) { |
||
241 | if ( $field['type'] == 'divider' ) { |
||
242 | if ( FrmField::is_option_true( $field, 'description' ) ) { |
||
243 | $html = str_replace( 'frm_description', 'frm_description frm_section_spacing', $html ); |
||
244 | } else { |
||
245 | $html = str_replace( '[label_position]', '[label_position] frm_section_spacing', $html ); |
||
246 | } |
||
247 | } |
||
248 | } |
||
249 | |||
250 | /** |
||
251 | * @since 3.0 |
||
252 | */ |
||
253 | private static function replace_required_label_shortcode( $field, &$html ) { |
||
254 | $required = FrmField::is_required( $field ) ? $field['required_indicator'] : ''; |
||
255 | self::remove_inline_conditions( ! empty( $required ), 'required_label', $required, $html ); |
||
256 | } |
||
257 | |||
258 | /** |
||
259 | * @since 3.0 |
||
260 | */ |
||
261 | private static function replace_description_shortcode( $field, &$html ) { |
||
262 | $description = $field['description']; |
||
263 | self::remove_inline_conditions( ( $description && $description != '' ), 'description', $description, $html ); |
||
264 | } |
||
265 | |||
266 | /** |
||
267 | * @since 3.0 |
||
268 | */ |
||
269 | private static function replace_error_shortcode( $args, &$html ) { |
||
270 | $error = isset( $args['errors'][ 'field' . $args['field_id'] ] ) ? $args['errors'][ 'field' . $args['field_id'] ] : false; |
||
271 | self::remove_inline_conditions( ! empty( $error ), 'error', $error, $html ); |
||
272 | } |
||
273 | /** |
||
274 | * replace [required_class] |
||
275 | * |
||
276 | * @since 3.0 |
||
277 | */ |
||
278 | private static function replace_required_class( $field, &$html ) { |
||
279 | $required_class = FrmField::is_required( $field ) ? ' frm_required_field' : ''; |
||
280 | $html = str_replace( '[required_class]', $required_class, $html ); |
||
281 | } |
||
282 | |||
283 | /** |
||
284 | * replace [entry_key] |
||
285 | * |
||
286 | * @since 3.0 |
||
287 | */ |
||
288 | private static function replace_entry_key( &$html ) { |
||
289 | $entry_key = FrmAppHelper::simple_get( 'entry', 'sanitize_title' ); |
||
290 | $html = str_replace( '[entry_key]', $entry_key, $html ); |
||
291 | } |
||
292 | |||
293 | /** |
||
294 | * @since 3.0 |
||
295 | */ |
||
296 | private static function replace_form_shortcodes( $form, &$html ) { |
||
297 | if ( $form ) { |
||
298 | $form = (array) $form; |
||
299 | |||
300 | //replace [form_key] |
||
301 | $html = str_replace( '[form_key]', $form['form_key'], $html ); |
||
302 | |||
303 | //replace [form_name] |
||
304 | $html = str_replace( '[form_name]', $form['name'], $html ); |
||
305 | } |
||
306 | } |
||
307 | |||
308 | /** |
||
309 | * @since 3.0 |
||
310 | */ |
||
311 | public static function replace_shortcodes_after_input( $args, &$html ) { |
||
312 | $html .= "\n"; |
||
313 | |||
314 | //Return html if conf_field to prevent loop |
||
315 | if ( isset( $args['field']['conf_field'] ) && $args['field']['conf_field'] == 'stop' ) { |
||
316 | return; |
||
317 | } |
||
318 | |||
319 | self::filter_for_more_shortcodes( $args, $args['field'], $html); |
||
320 | self::filter_html_field_shortcodes( $args['field'], $html ); |
||
321 | self::remove_collapse_shortcode( $html ); |
||
322 | } |
||
323 | |||
324 | /** |
||
325 | * @since 3.0 |
||
326 | */ |
||
327 | private static function filter_for_more_shortcodes( $args, $field, &$html) { |
||
328 | //If field is not in repeating section |
||
329 | if ( empty( $args['section_id'] ) ) { |
||
330 | $args = array( 'errors' => $args['errors'], 'form' => $args['form'] ); |
||
331 | } |
||
332 | $html = apply_filters( 'frm_replace_shortcodes', $html, $field, $args ); |
||
333 | } |
||
334 | |||
335 | private static function filter_html_field_shortcodes( $field, &$html ) { |
||
336 | if ( $field['type'] == 'html' ) { |
||
337 | self::run_wpautop( array( 'wpautop' => true ), $html ); |
||
338 | |||
339 | $html = apply_filters( 'frm_get_default_value', $html, (object) $field, false ); |
||
340 | $html = do_shortcode( $html ); |
||
341 | } |
||
342 | } |
||
343 | |||
344 | /** |
||
345 | * @since 3.0 |
||
346 | * |
||
347 | * @param array $atts |
||
348 | * @param string|array $value |
||
349 | */ |
||
350 | public static function run_wpautop( $atts, &$value ) { |
||
351 | $autop = isset( $atts['wpautop'] ) ? $atts['wpautop'] : true; |
||
352 | if ( apply_filters( 'frm_use_wpautop', $autop ) ) { |
||
353 | if ( is_array( $value ) ) { |
||
354 | $value = implode( "\n", $value ); |
||
355 | } |
||
356 | $value = wpautop( $value ); |
||
357 | } |
||
358 | } |
||
359 | /** |
||
360 | * TODO: 3.0 remove this function |
||
361 | * @since 3.0 |
||
362 | */ |
||
363 | public static function replace_shortcodes_with_atts( $args, &$html ) { |
||
364 | preg_match_all("/\[(deletelink)\b(.*?)(?:(\/))?\]/s", $html, $shortcodes, PREG_PATTERN_ORDER); |
||
365 | |||
366 | foreach ( $shortcodes[0] as $short_key => $tag ) { |
||
367 | $shortcode_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] ); |
||
368 | $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key, array( 'conditional' => false, 'conditional_check' => false ) ); |
||
369 | |||
370 | $replace_with = ''; |
||
371 | |||
372 | if ( $tag == 'deletelink' && FrmAppHelper::pro_is_installed() ) { |
||
373 | $replace_with = FrmProEntriesController::entry_delete_link( $shortcode_atts ); |
||
374 | } |
||
375 | |||
376 | $html = str_replace( $shortcodes[0][ $short_key ], $replace_with, $html ); |
||
377 | } |
||
378 | } |
||
379 | |||
380 | /** |
||
381 | * Get the class to use for the label position |
||
382 | * @since 2.05 |
||
383 | */ |
||
384 | public static function &label_position( $position, $field, $form ) { |
||
385 | if ( $position && $position != '' ) { |
||
386 | return $position; |
||
387 | } |
||
388 | |||
389 | $position = FrmStylesController::get_style_val( 'position', $form ); |
||
390 | if ( $position == 'none' ) { |
||
391 | $position = 'top'; |
||
392 | } elseif ( $position == 'no_label' ) { |
||
393 | $position = 'none'; |
||
394 | } elseif ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) { |
||
395 | $position = 'top'; |
||
396 | } |
||
397 | |||
398 | $position = apply_filters( 'frm_html_label_position', $position, $field, $form ); |
||
399 | $position = ( ! empty( $position ) ) ? $position : 'top'; |
||
400 | |||
401 | return $position; |
||
402 | } |
||
403 | |||
404 | /** |
||
405 | * Check if this field type allows placeholders |
||
406 | * @since 2.05 |
||
407 | */ |
||
408 | public static function is_placeholder_field_type( $type ) { |
||
409 | return ! in_array( $type, array( 'select', 'radio', 'checkbox', 'hidden' ) ); |
||
410 | } |
||
411 | |||
412 | /** |
||
413 | * Add the label position class into the HTML |
||
414 | * If the label position is inside, add a class to show the label if the field has a value. |
||
415 | * |
||
416 | * @since 2.05 |
||
417 | */ |
||
418 | private static function add_class_to_label( $field, &$html ) { |
||
419 | $label_class = in_array( $field['type'], array( 'divider', 'end_divider', 'break' ) ) ? $field['label'] : ' frm_primary_label'; |
||
420 | $html = str_replace( '[label_position]', $label_class, $html ); |
||
421 | if ( $field['label'] == 'inside' && $field['value'] != '' ) { |
||
422 | $html = str_replace( 'frm_primary_label', 'frm_primary_label frm_visible', $html ); |
||
423 | } |
||
424 | } |
||
425 | |||
426 | /** |
||
427 | * This filters shortcodes in the field HTML |
||
428 | * |
||
429 | * @since 2.02.11 |
||
430 | */ |
||
431 | private static function process_wp_shortcodes( &$html ) { |
||
432 | if ( apply_filters( 'frm_do_html_shortcodes', true ) ) { |
||
433 | $html = do_shortcode( $html ); |
||
434 | } |
||
435 | } |
||
436 | |||
437 | /** |
||
438 | * Add classes to a field div |
||
439 | * |
||
440 | * @since 2.02.05 |
||
441 | * |
||
442 | * @param string $field_id |
||
443 | * @param array $field |
||
444 | * @param array $errors |
||
445 | * @param string $html |
||
446 | */ |
||
447 | private static function add_field_div_classes( $field_id, $field, $errors, &$html ) { |
||
448 | $classes = self::get_field_div_classes( $field_id, $field, $errors, $html ); |
||
449 | |||
450 | if ( $field['type'] == 'html' && strpos( $html, '[error_class]' ) === false ) { |
||
451 | // there is no error_class shortcode for HTML fields |
||
452 | $html = str_replace( 'class="frm_form_field', 'class="frm_form_field ' . $classes, $html ); |
||
453 | } |
||
454 | $html = str_replace( '[error_class]', $classes, $html ); |
||
455 | } |
||
456 | |||
457 | /** |
||
458 | * Get the classes for a field div |
||
459 | * |
||
460 | * @since 2.02.05 |
||
461 | * |
||
462 | * @param string $field_id |
||
463 | * @param array $field |
||
464 | * @param array $errors |
||
465 | * @param string $html |
||
466 | * @return string $classes |
||
467 | */ |
||
468 | private static function get_field_div_classes( $field_id, $field, $errors, $html ) { |
||
469 | // Add error class |
||
470 | $classes = isset( $errors[ 'field' . $field_id ] ) ? ' frm_blank_field' : ''; |
||
471 | |||
472 | // Add label position class |
||
473 | $classes .= ' frm_' . $field['label'] . '_container'; |
||
474 | |||
475 | // Add CSS layout classes |
||
476 | if ( ! empty( $field['classes'] ) ) { |
||
477 | if ( ! strpos( $html, 'frm_form_field ') ) { |
||
478 | $classes .= ' frm_form_field'; |
||
479 | } |
||
480 | $classes .= ' ' . $field['classes']; |
||
481 | } |
||
482 | |||
483 | // Add class to HTML field |
||
484 | if ( $field['type'] == 'html' ) { |
||
485 | $classes .= ' frm_html_container'; |
||
486 | } |
||
487 | |||
488 | // Get additional classes |
||
489 | $classes = apply_filters( 'frm_field_div_classes', $classes, $field, array( 'field_id' => $field_id ) ); |
||
490 | |||
491 | return $classes; |
||
492 | } |
||
493 | |||
494 | public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) { |
||
495 | if ( $no_vars ) { |
||
496 | $html = str_replace( '[if ' . $code . ']', '', $html ); |
||
497 | $html = str_replace( '[/if ' . $code . ']', '', $html ); |
||
498 | } else { |
||
499 | $html = preg_replace( '/(\[if\s+' . $code . '\])(.*?)(\[\/if\s+' . $code . '\])/mis', '', $html ); |
||
500 | } |
||
501 | |||
502 | $html = str_replace( '[' . $code . ']', $replace_with, $html ); |
||
503 | } |
||
504 | |||
505 | public static function get_shortcode_tag( $shortcodes, $short_key, $args ) { |
||
506 | _deprecated_function( __FUNCTION__, '3.0', 'FrmShortcodesHelper::get_shortcode_tag' ); |
||
507 | return FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key, $args ); |
||
508 | } |
||
509 | |||
510 | /** |
||
511 | * Remove [collapse_this] if it's still included after all processing |
||
512 | * @since 2.0.8 |
||
513 | */ |
||
514 | private static function remove_collapse_shortcode( &$html ) { |
||
515 | if ( preg_match( '/\[(collapse_this)\]/s', $html ) ) { |
||
516 | $html = str_replace( '[collapse_this]', '', $html ); |
||
517 | } |
||
518 | } |
||
519 | |||
520 | public static function get_checkbox_id( $field, $opt_key ) { |
||
521 | $id = $field['id']; |
||
522 | if ( isset( $field['in_section'] ) && $field['in_section'] ) { |
||
523 | $id .= '-' . $field['in_section']; |
||
524 | } |
||
525 | return 'frm_checkbox_' . $id . '-' . $opt_key; |
||
526 | } |
||
527 | |||
528 | public static function display_recaptcha( $field ) { |
||
529 | _deprecated_function( __FUNCTION__, '3.0', 'FrmFieldCaptcha::field_input' ); |
||
530 | } |
||
531 | |||
532 | public static function show_single_option( $field ) { |
||
533 | if ( ! is_array( $field['options'] ) ) { |
||
534 | return; |
||
535 | } |
||
536 | |||
537 | $field_name = $field['name']; |
||
538 | $html_id = self::get_html_id($field); |
||
539 | |||
540 | foreach ( $field['options'] as $opt_key => $opt ) { |
||
541 | $field_val = self::get_value_from_array( $opt, $opt_key, $field ); |
||
542 | $opt = self::get_label_from_array( $opt, $opt_key, $field ); |
||
543 | |||
544 | // Get string for Other text field, if needed |
||
545 | $other_val = self::get_other_val( compact( 'opt_key', 'field' ) ); |
||
546 | |||
547 | $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"':''; |
||
548 | |||
549 | // If this is an "Other" option, get the HTML for it |
||
550 | if ( self::is_other_opt( $opt_key ) ) { |
||
551 | if ( FrmAppHelper::pro_is_installed() ) { |
||
552 | require( FrmProAppHelper::plugin_path() . '/classes/views/frmpro-fields/other-option.php' ); |
||
553 | } |
||
554 | } else { |
||
555 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' ); |
||
556 | } |
||
557 | |||
558 | unset( $checked, $other_val ); |
||
559 | } |
||
560 | } |
||
561 | |||
562 | public static function get_value_from_array( $opt, $opt_key, $field ) { |
||
563 | $opt = apply_filters( 'frm_field_value_saved', $opt, $opt_key, $field ); |
||
564 | return FrmFieldsController::check_value( $opt, $opt_key, $field ); |
||
565 | } |
||
566 | |||
567 | public static function get_label_from_array( $opt, $opt_key, $field ) { |
||
568 | $opt = apply_filters( 'frm_field_label_seen', $opt, $opt_key, $field ); |
||
569 | return FrmFieldsController::check_label( $opt ); |
||
570 | } |
||
571 | |||
572 | public static function get_term_link( $tax_id ) { |
||
586 | |||
587 | public static function value_meets_condition( $observed_value, $cond, $hide_opt ) { |
||
588 | $hide_opt = self::get_value_for_comparision( $hide_opt ); |
||
589 | $observed_value = self::get_value_for_comparision( $observed_value ); |
||
590 | |||
591 | if ( is_array($observed_value) ) { |
||
592 | return self::array_value_condition($observed_value, $cond, $hide_opt); |
||
593 | } |
||
594 | |||
595 | $m = false; |
||
596 | if ( $cond == '==' ) { |
||
597 | $m = $observed_value == $hide_opt; |
||
598 | } else if ( $cond == '!=' ) { |
||
599 | $m = $observed_value != $hide_opt; |
||
600 | } else if ( $cond == '>' ) { |
||
601 | $m = $observed_value > $hide_opt; |
||
602 | } else if ( $cond == '<' ) { |
||
603 | $m = $observed_value < $hide_opt; |
||
604 | } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) { |
||
605 | $m = stripos($observed_value, $hide_opt); |
||
606 | if ( $cond == 'not LIKE' ) { |
||
607 | $m = ( $m === false ) ? true : false; |
||
608 | } else { |
||
609 | $m = ( $m === false ) ? false : true; |
||
610 | } |
||
611 | } |
||
612 | return $m; |
||
613 | } |
||
614 | |||
615 | /** |
||
616 | * Trim and sanitize the values |
||
617 | * @since 2.05 |
||
618 | */ |
||
619 | private static function get_value_for_comparision( $value ) { |
||
620 | // Remove white space from hide_opt |
||
621 | if ( ! is_array( $value ) ) { |
||
622 | $value = trim( $value ); |
||
623 | } |
||
624 | |||
625 | return wp_kses_post( $value ); |
||
626 | } |
||
627 | |||
628 | public static function array_value_condition( $observed_value, $cond, $hide_opt ) { |
||
629 | $m = false; |
||
630 | if ( $cond == '==' ) { |
||
631 | if ( is_array($hide_opt) ) { |
||
632 | $m = array_intersect($hide_opt, $observed_value); |
||
633 | $m = empty($m) ? false : true; |
||
634 | } else { |
||
635 | $m = in_array($hide_opt, $observed_value); |
||
636 | } |
||
637 | } else if ( $cond == '!=' ) { |
||
638 | $m = ! in_array($hide_opt, $observed_value); |
||
639 | } else if ( $cond == '>' ) { |
||
640 | $min = min($observed_value); |
||
641 | $m = $min > $hide_opt; |
||
642 | } else if ( $cond == '<' ) { |
||
643 | $max = max($observed_value); |
||
644 | $m = $max < $hide_opt; |
||
645 | } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) { |
||
646 | foreach ( $observed_value as $ob ) { |
||
647 | $m = strpos($ob, $hide_opt); |
||
648 | if ( $m !== false ) { |
||
649 | $m = true; |
||
650 | break; |
||
651 | } |
||
652 | } |
||
653 | |||
654 | if ( $cond == 'not LIKE' ) { |
||
655 | $m = ( $m === false ) ? true : false; |
||
656 | } |
||
657 | } |
||
658 | |||
659 | return $m; |
||
660 | } |
||
661 | |||
662 | /** |
||
663 | * Replace a few basic shortcodes and field ids |
||
664 | * @since 2.0 |
||
665 | * @return string |
||
666 | */ |
||
667 | public static function basic_replace_shortcodes( $value, $form, $entry ) { |
||
668 | if ( strpos($value, '[sitename]') !== false ) { |
||
669 | $new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
||
670 | $value = str_replace('[sitename]', $new_value, $value); |
||
671 | } |
||
672 | |||
673 | $value = apply_filters('frm_content', $value, $form, $entry); |
||
674 | $value = do_shortcode($value); |
||
675 | |||
676 | return $value; |
||
677 | } |
||
678 | |||
679 | public static function get_shortcodes( $content, $form_id ) { |
||
680 | if ( FrmAppHelper::pro_is_installed() ) { |
||
681 | return FrmProDisplaysHelper::get_shortcodes($content, $form_id); |
||
682 | } |
||
683 | |||
684 | $fields = FrmField::getAll( array( 'fi.form_id' => (int) $form_id, 'fi.type not' => FrmField::no_save_fields() ) ); |
||
685 | |||
686 | $tagregexp = self::allowed_shortcodes($fields); |
||
687 | |||
688 | preg_match_all("/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER); |
||
689 | |||
690 | return $matches; |
||
691 | } |
||
692 | |||
693 | public static function allowed_shortcodes( $fields = array() ) { |
||
694 | $tagregexp = array( |
||
695 | 'editlink', 'id', 'key', 'ip', |
||
696 | 'siteurl', 'sitename', 'admin_email', |
||
697 | 'post[-|_]id', 'created[-|_]at', 'updated[-|_]at', 'updated[-|_]by', |
||
698 | 'parent[-|_]id', |
||
699 | ); |
||
700 | |||
701 | foreach ( $fields as $field ) { |
||
702 | $tagregexp[] = $field->id; |
||
703 | $tagregexp[] = $field->field_key; |
||
704 | } |
||
705 | |||
706 | $tagregexp = implode('|', $tagregexp); |
||
707 | return $tagregexp; |
||
708 | } |
||
709 | |||
710 | public static function replace_content_shortcodes( $content, $entry, $shortcodes ) { |
||
711 | $shortcode_values = array( |
||
712 | 'id' => $entry->id, |
||
713 | 'key' => $entry->item_key, |
||
714 | 'ip' => $entry->ip, |
||
715 | ); |
||
716 | |||
717 | foreach ( $shortcodes[0] as $short_key => $tag ) { |
||
718 | if ( empty( $tag ) ) { |
||
719 | continue; |
||
720 | } |
||
721 | |||
722 | $atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[3][ $short_key ] ); |
||
723 | |||
724 | if ( ! empty( $shortcodes[3][ $short_key ] ) ) { |
||
725 | $tag = str_replace( array( '[', ']' ), '', $shortcodes[0][ $short_key ] ); |
||
726 | $tags = explode(' ', $tag); |
||
727 | if ( is_array($tags) ) { |
||
728 | $tag = $tags[0]; |
||
729 | } |
||
730 | } else { |
||
731 | $tag = $shortcodes[2][ $short_key ]; |
||
732 | } |
||
733 | |||
734 | switch ( $tag ) { |
||
735 | case 'id': |
||
736 | case 'key': |
||
737 | case 'ip': |
||
738 | $replace_with = $shortcode_values[ $tag ]; |
||
739 | break; |
||
740 | |||
741 | case 'user_agent': |
||
742 | case 'user-agent': |
||
743 | $entry->description = maybe_unserialize($entry->description); |
||
744 | $replace_with = FrmEntriesHelper::get_browser( $entry->description['browser'] ); |
||
745 | break; |
||
746 | |||
747 | case 'created_at': |
||
748 | case 'created-at': |
||
749 | case 'updated_at': |
||
750 | case 'updated-at': |
||
751 | if ( isset($atts['format']) ) { |
||
752 | $time_format = ' '; |
||
753 | } else { |
||
754 | $atts['format'] = get_option('date_format'); |
||
755 | $time_format = ''; |
||
756 | } |
||
757 | |||
758 | $this_tag = str_replace('-', '_', $tag); |
||
759 | $replace_with = FrmAppHelper::get_formatted_time($entry->{$this_tag}, $atts['format'], $time_format); |
||
760 | unset($this_tag); |
||
761 | break; |
||
762 | |||
763 | case 'created_by': |
||
764 | case 'created-by': |
||
765 | case 'updated_by': |
||
766 | case 'updated-by': |
||
767 | $this_tag = str_replace('-', '_', $tag); |
||
768 | $replace_with = self::get_display_value( $entry->{$this_tag}, (object) array( 'type' => 'user_id' ), $atts ); |
||
769 | unset($this_tag); |
||
770 | break; |
||
771 | |||
772 | case 'admin_email': |
||
773 | case 'siteurl': |
||
774 | case 'frmurl': |
||
775 | case 'sitename': |
||
776 | case 'get': |
||
777 | $replace_with = self::dynamic_default_values( $tag, $atts ); |
||
778 | break; |
||
779 | |||
780 | default: |
||
781 | $field = FrmField::getOne( $tag ); |
||
782 | if ( ! $field ) { |
||
783 | break; |
||
784 | } |
||
785 | |||
786 | $sep = isset($atts['sep']) ? $atts['sep'] : ', '; |
||
787 | |||
788 | $replace_with = FrmEntryMeta::get_meta_value( $entry, $field->id ); |
||
789 | |||
790 | $atts['entry_id'] = $entry->id; |
||
791 | $atts['entry_key'] = $entry->item_key; |
||
792 | |||
793 | if ( isset($atts['show']) && $atts['show'] == 'field_label' ) { |
||
794 | $replace_with = $field->name; |
||
795 | } else if ( isset($atts['show']) && $atts['show'] == 'description' ) { |
||
796 | $replace_with = $field->description; |
||
797 | } else { |
||
798 | $string_value = $replace_with; |
||
799 | if ( is_array( $replace_with ) ) { |
||
800 | $string_value = implode( $sep, $replace_with ); |
||
801 | } |
||
802 | |||
803 | if ( empty( $string_value ) && $string_value != '0' ) { |
||
804 | $replace_with = ''; |
||
805 | } else { |
||
806 | $replace_with = self::get_display_value( $replace_with, $field, $atts ); |
||
807 | } |
||
808 | } |
||
809 | |||
810 | unset($field); |
||
811 | break; |
||
812 | } |
||
813 | |||
814 | if ( isset($replace_with) ) { |
||
815 | $content = str_replace( $shortcodes[0][ $short_key ], $replace_with, $content ); |
||
816 | } |
||
817 | |||
818 | unset($atts, $conditional, $replace_with); |
||
819 | } |
||
820 | |||
821 | return $content; |
||
822 | } |
||
823 | |||
824 | /** |
||
825 | * Get the value to replace a few standard shortcodes |
||
826 | * |
||
827 | * @since 2.0 |
||
828 | * @return string |
||
829 | */ |
||
830 | public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) { |
||
831 | $new_value = ''; |
||
832 | switch ( $tag ) { |
||
833 | case 'admin_email': |
||
834 | $new_value = get_option('admin_email'); |
||
835 | break; |
||
836 | case 'siteurl': |
||
837 | $new_value = FrmAppHelper::site_url(); |
||
838 | break; |
||
839 | case 'frmurl': |
||
840 | $new_value = FrmAppHelper::plugin_url(); |
||
841 | break; |
||
842 | case 'sitename': |
||
843 | $new_value = FrmAppHelper::site_name(); |
||
844 | break; |
||
845 | case 'get': |
||
846 | $new_value = self::process_get_shortcode( $atts, $return_array ); |
||
847 | break; |
||
848 | } |
||
849 | |||
850 | return $new_value; |
||
851 | } |
||
852 | |||
853 | /** |
||
854 | * Process the [get] shortcode |
||
855 | * |
||
856 | * @since 2.0 |
||
857 | * @return string|array |
||
858 | */ |
||
859 | public static function process_get_shortcode( $atts, $return_array = false ) { |
||
860 | if ( ! isset($atts['param']) ) { |
||
861 | return ''; |
||
862 | } |
||
863 | |||
864 | if ( strpos($atts['param'], '[') ) { |
||
865 | $atts['param'] = str_replace('[', '[', $atts['param']); |
||
866 | $atts['param'] = str_replace(']', ']', $atts['param']); |
||
867 | } |
||
868 | |||
869 | $new_value = FrmAppHelper::get_param($atts['param'], ''); |
||
870 | $new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] ); |
||
871 | |||
872 | if ( $new_value == '' ) { |
||
873 | if ( ! isset($atts['prev_val']) ) { |
||
874 | $atts['prev_val'] = ''; |
||
875 | } |
||
876 | |||
877 | $new_value = isset($atts['default']) ? $atts['default'] : $atts['prev_val']; |
||
878 | } |
||
879 | |||
880 | if ( is_array($new_value) && ! $return_array ) { |
||
881 | $new_value = implode(', ', $new_value); |
||
882 | } |
||
883 | |||
884 | return $new_value; |
||
885 | } |
||
886 | |||
887 | public static function get_display_value( $value, $field, $atts = array() ) { |
||
888 | |||
889 | $value = apply_filters( 'frm_get_' . $field->type . '_display_value', $value, $field, $atts ); |
||
890 | $value = apply_filters( 'frm_get_display_value', $value, $field, $atts ); |
||
891 | |||
892 | return self::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) ); |
||
893 | } |
||
894 | |||
895 | /** |
||
896 | * @param $atts array Includes value, field, and atts |
||
897 | */ |
||
898 | public static function get_unfiltered_display_value( $atts ) { |
||
899 | $value = $atts['value']; |
||
900 | |||
901 | if ( is_array( $atts['field'] ) ) { |
||
902 | $atts['field'] = $atts['field']['id']; |
||
903 | } |
||
904 | |||
905 | $field_obj = FrmFieldFactory::get_field_object( $atts['field'] ); |
||
906 | return $field_obj->get_display_value( $value, $atts ); |
||
907 | } |
||
908 | |||
909 | /** |
||
910 | * Get a value from the user profile from the user ID |
||
911 | * @since 3.0 |
||
912 | */ |
||
913 | public static function get_user_display_name( $user_id, $user_info = 'display_name', $args = array() ) { |
||
914 | $defaults = array( |
||
915 | 'blank' => false, 'link' => false, 'size' => 96 |
||
916 | ); |
||
917 | |||
918 | $args = wp_parse_args($args, $defaults); |
||
919 | |||
920 | $user = get_userdata($user_id); |
||
921 | $info = ''; |
||
922 | |||
923 | if ( $user ) { |
||
924 | if ( $user_info == 'avatar' ) { |
||
925 | $info = get_avatar( $user_id, $args['size'] ); |
||
926 | } elseif ( $user_info == 'author_link' ) { |
||
927 | $info = get_author_posts_url( $user_id ); |
||
928 | } else { |
||
929 | $info = isset($user->$user_info) ? $user->$user_info : ''; |
||
930 | } |
||
931 | |||
932 | if ( empty($info) && ! $args['blank'] ) { |
||
933 | $info = $user->user_login; |
||
934 | } |
||
935 | } |
||
936 | |||
937 | if ( $args['link'] ) { |
||
938 | $info = '<a href="' . esc_url( admin_url('user-edit.php?user_id=' . $user_id ) ) . '">' . $info . '</a>'; |
||
939 | } |
||
940 | |||
941 | return $info; |
||
942 | } |
||
943 | |||
944 | public static function get_field_types( $type ) { |
||
945 | $single_input = array( |
||
946 | 'text', 'textarea', 'rte', 'number', 'email', 'url', |
||
947 | 'image', 'file', 'date', 'phone', 'hidden', 'time', |
||
948 | 'user_id', 'tag', 'password', |
||
949 | ); |
||
950 | $multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'lookup' ); |
||
951 | $other_type = array( 'html', 'break' ); |
||
952 | |||
953 | $field_selection = array_merge( FrmField::pro_field_selection(), FrmField::field_selection() ); |
||
954 | |||
955 | $field_types = array(); |
||
956 | if ( in_array($type, $single_input) ) { |
||
957 | self::field_types_for_input( $single_input, $field_selection, $field_types ); |
||
958 | } else if ( in_array($type, $multiple_input) ) { |
||
959 | self::field_types_for_input( $multiple_input, $field_selection, $field_types ); |
||
960 | } else if ( in_array($type, $other_type) ) { |
||
961 | self::field_types_for_input( $other_type, $field_selection, $field_types ); |
||
962 | } else if ( isset( $field_selection[ $type ] ) ) { |
||
963 | $field_types[ $type ] = $field_selection[ $type ]; |
||
964 | } |
||
965 | |||
966 | $field_types = apply_filters( 'frm_switch_field_types', $field_types, compact( 'type' ) ); |
||
967 | return $field_types; |
||
968 | } |
||
969 | |||
970 | private static function field_types_for_input( $inputs, $fields, &$field_types ) { |
||
971 | foreach ( $inputs as $input ) { |
||
972 | $field_types[ $input ] = $fields[ $input ]; |
||
973 | unset($input); |
||
974 | } |
||
975 | } |
||
976 | |||
977 | /** |
||
978 | * Check if current field option is an "other" option |
||
979 | * |
||
980 | * @since 2.0.6 |
||
981 | * |
||
982 | * @param string $opt_key |
||
983 | * @return boolean Returns true if current field option is an "Other" option |
||
984 | */ |
||
985 | public static function is_other_opt( $opt_key ) { |
||
986 | return $opt_key && strpos( $opt_key, 'other_' ) === 0; |
||
987 | } |
||
988 | |||
989 | /** |
||
990 | * Get value that belongs in "Other" text box |
||
991 | * |
||
992 | * @since 2.0.6 |
||
993 | * |
||
994 | * @param array $args |
||
995 | */ |
||
996 | public static function get_other_val( $args ) { |
||
997 | $defaults = array( |
||
998 | 'opt_key' => 0, 'field' => array(), |
||
999 | 'parent' => false, 'pointer' => false, |
||
1000 | ); |
||
1001 | $args = wp_parse_args( $args, $defaults ); |
||
1002 | |||
1003 | $opt_key = $args['opt_key']; |
||
1004 | $field = $args['field']; |
||
1005 | $parent = $args['parent']; |
||
1006 | $pointer = $args['pointer']; |
||
1007 | $other_val = ''; |
||
1008 | |||
1009 | // If option is an "other" option and there is a value set for this field, |
||
1010 | // check if the value belongs in the current "Other" option text field |
||
1011 | if ( ! FrmFieldsHelper::is_other_opt( $opt_key ) || ! FrmField::is_option_true( $field, 'value' ) ) { |
||
1012 | return $other_val; |
||
1013 | } |
||
1014 | |||
1015 | // Check posted vals before checking saved values |
||
1016 | |||
1017 | // For fields inside repeating sections - note, don't check if $pointer is true because it will often be zero |
||
1018 | if ( $parent && isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ) { |
||
1019 | if ( FrmField::is_field_with_multiple_values( $field ) ) { |
||
1020 | $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 ] ) : ''; |
||
1021 | } else { |
||
1022 | $other_val = sanitize_text_field( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ); |
||
1023 | } |
||
1024 | return $other_val; |
||
1025 | |||
1026 | } else if ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) { |
||
1027 | // For normal fields |
||
1028 | |||
1029 | if ( FrmField::is_field_with_multiple_values( $field ) ) { |
||
1030 | $other_val = isset( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) : ''; |
||
1031 | } else { |
||
1032 | $other_val = sanitize_text_field( $_POST['item_meta']['other'][ $field['id'] ] ); |
||
1033 | } |
||
1034 | return $other_val; |
||
1035 | } |
||
1036 | |||
1037 | // For checkboxes |
||
1038 | if ( $field['type'] == 'checkbox' && is_array( $field['value'] ) ) { |
||
1039 | // Check if there is an "other" val in saved value and make sure the |
||
1040 | // "other" val is not equal to the Other checkbox option |
||
1041 | if ( isset( $field['value'][ $opt_key ] ) && $field['options'][ $opt_key ] != $field['value'][ $opt_key ] ) { |
||
1042 | $other_val = $field['value'][ $opt_key ]; |
||
1043 | } |
||
1044 | } else { |
||
1045 | /** |
||
1046 | * For radio buttons and dropdowns |
||
1047 | * Check if saved value equals any of the options. If not, set it as the other value. |
||
1048 | */ |
||
1049 | foreach ( $field['options'] as $opt_key => $opt_val ) { |
||
1050 | $temp_val = is_array( $opt_val ) ? $opt_val['value'] : $opt_val; |
||
1051 | // Multi-select dropdowns - key is not preserved |
||
1052 | if ( is_array( $field['value'] ) ) { |
||
1053 | $o_key = array_search( $temp_val, $field['value'] ); |
||
1054 | if ( isset( $field['value'][ $o_key ] ) ) { |
||
1055 | unset( $field['value'][ $o_key ], $o_key ); |
||
1056 | } |
||
1057 | } else if ( $temp_val == $field['value'] ) { |
||
1058 | // For radio and regular dropdowns |
||
1059 | return ''; |
||
1060 | } else { |
||
1061 | $other_val = $field['value']; |
||
1062 | } |
||
1063 | unset( $opt_key, $opt_val, $temp_val ); |
||
1064 | } |
||
1065 | // For multi-select dropdowns only |
||
1066 | if ( is_array( $field['value'] ) && ! empty( $field['value'] ) ) { |
||
1067 | $other_val = reset( $field['value'] ); |
||
1068 | } |
||
1069 | } |
||
1070 | |||
1071 | return $other_val; |
||
1072 | } |
||
1073 | |||
1074 | /** |
||
1075 | * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val. |
||
1076 | * Intended for front-end use |
||
1077 | * |
||
1078 | * @since 2.0.6 |
||
1079 | * |
||
1080 | * @param array $args should include field, opt_key and field name |
||
1081 | * @param boolean $other_opt |
||
1082 | * @param string $checked |
||
1083 | * @return string $other_val |
||
1084 | */ |
||
1085 | public static function prepare_other_input( $args, &$other_opt, &$checked ) { |
||
1086 | //Check if this is an "Other" option |
||
1087 | if ( ! self::is_other_opt( $args['opt_key'] ) ) { |
||
1088 | return; |
||
1089 | } |
||
1090 | |||
1091 | $other_opt = true; |
||
1092 | $other_args = array(); |
||
1093 | |||
1094 | self::set_other_name( $args, $other_args ); |
||
1095 | self::set_other_value( $args, $other_args ); |
||
1096 | |||
1097 | if ( $other_args['value'] ) { |
||
1098 | $checked = 'checked="checked" '; |
||
1099 | } |
||
1100 | |||
1101 | return $other_args; |
||
1102 | } |
||
1103 | |||
1104 | /** |
||
1105 | * @param array $args |
||
1106 | * @param array $other_args |
||
1107 | * @since 2.0.6 |
||
1108 | */ |
||
1109 | private static function set_other_name( $args, &$other_args ) { |
||
1110 | //Set up name for other field |
||
1111 | $other_args['name'] = str_replace( '[]', '', $args['field_name'] ); |
||
1112 | $other_args['name'] = preg_replace('/\[' . $args['field']['id'] . '\]$/', '', $other_args['name']); |
||
1113 | $other_args['name'] = $other_args['name'] . '[other]' . '[' . $args['field']['id'] . ']'; |
||
1114 | |||
1115 | //Converts item_meta[field_id] => item_meta[other][field_id] and |
||
1116 | //item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id] |
||
1117 | if ( FrmField::is_field_with_multiple_values( $args['field'] ) ) { |
||
1118 | $other_args['name'] .= '[' . $args['opt_key'] . ']'; |
||
1119 | } |
||
1120 | } |
||
1121 | |||
1122 | /** |
||
1123 | * Find the parent and pointer, and get text for "other" text field |
||
1124 | * @param array $args |
||
1125 | * @param array $other_args |
||
1126 | * |
||
1127 | * @since 2.0.6 |
||
1128 | */ |
||
1129 | private static function set_other_value( $args, &$other_args ) { |
||
1130 | $parent = ''; |
||
1131 | $pointer = ''; |
||
1132 | |||
1133 | // Check for parent ID and pointer |
||
1134 | $temp_array = explode( '[', $args['field_name'] ); |
||
1135 | |||
1136 | // Count should only be greater than 3 if inside of a repeating section |
||
1137 | if ( count( $temp_array ) > 3 ) { |
||
1138 | $parent = str_replace( ']', '', $temp_array[1] ); |
||
1139 | $pointer = str_replace( ']', '', $temp_array[2]); |
||
1140 | } |
||
1141 | |||
1142 | // Get text for "other" text field |
||
1143 | $other_args['value'] = self::get_other_val( array( 'opt_key' => $args['opt_key'], 'field' => $args['field'], 'parent' => $parent, 'pointer' => $pointer ) ); |
||
1144 | } |
||
1145 | |||
1146 | /** |
||
1147 | * If this field includes an other option, show it |
||
1148 | * @param $args array |
||
1149 | * @since 2.0.6 |
||
1150 | */ |
||
1151 | public static function include_other_input( $args ) { |
||
1152 | if ( ! $args['other_opt'] ) { |
||
1153 | return; |
||
1154 | } |
||
1155 | |||
1156 | $classes = array( 'frm_other_input' ); |
||
1157 | if ( ! $args['checked'] || trim( $args['checked'] ) == '' ) { |
||
1158 | // hide the field if the other option is not selected |
||
1159 | $classes[] = 'frm_pos_none'; |
||
1160 | } |
||
1161 | if ( $args['field']['type'] == 'select' && $args['field']['multiple'] ) { |
||
1162 | $classes[] = 'frm_other_full'; |
||
1163 | } |
||
1164 | |||
1165 | // Set up HTML ID for Other field |
||
1166 | $other_id = self::get_other_field_html_id( $args['field']['type'], $args['html_id'], $args['opt_key'] ); |
||
1167 | |||
1168 | ?><input type="text" id="<?php echo esc_attr( $other_id ) ?>" class="<?php echo sanitize_text_field( implode( ' ', $classes ) ) ?>" <?php |
||
1169 | echo ( $args['read_only'] ? ' readonly="readonly" disabled="disabled"' : '' ); |
||
1170 | ?> name="<?php echo esc_attr( $args['name'] ) ?>" value="<?php echo esc_attr( $args['value'] ); ?>" /><?php |
||
1171 | } |
||
1172 | |||
1173 | /** |
||
1174 | * Get the HTML id for an "Other" text field |
||
1175 | * Note: This does not affect fields in repeating sections |
||
1176 | * |
||
1177 | * @since 2.0.08 |
||
1178 | * @param string $type - field type |
||
1179 | * @param string $html_id |
||
1180 | * @param string|boolean $opt_key |
||
1181 | * @return string $other_id |
||
1182 | */ |
||
1183 | public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) { |
||
1184 | $other_id = $html_id; |
||
1185 | |||
1186 | // If hidden radio field, add an opt key of 0 |
||
1187 | if ( $type == 'radio' && $opt_key === false ) { |
||
1188 | $opt_key = 0; |
||
1189 | } |
||
1190 | |||
1191 | if ( $opt_key !== false ) { |
||
1192 | $other_id .= '-' . $opt_key; |
||
1193 | } |
||
1194 | |||
1195 | $other_id .= '-otext'; |
||
1196 | |||
1197 | return $other_id; |
||
1198 | } |
||
1199 | |||
1200 | public static function clear_on_focus_html( $field, $display, $id = '' ) { |
||
1201 | if ( $display['clear_on_focus'] ) { |
||
1202 | echo '<span id="frm_clear_on_focus_' . esc_attr( $field['id'] . $id ) . '" class="frm-show-click">'; |
||
1203 | |||
1204 | if ( $display['default_blank'] ) { |
||
1205 | self::show_default_blank_js( $field['default_blank'] ); |
||
1206 | echo '<input type="hidden" name="field_options[default_blank_' . esc_attr( $field['id'] ) . ']" value="' . esc_attr( $field['default_blank'] ) . '" />'; |
||
1207 | } |
||
1208 | |||
1209 | self::show_onfocus_js( $field['clear_on_focus'] ); |
||
1210 | echo '<input type="hidden" name="field_options[clear_on_focus_' . esc_attr( $field['id'] ) . ']" value="' . esc_attr( $field['clear_on_focus'] ) . '" />'; |
||
1211 | |||
1212 | echo '</span>'; |
||
1213 | } |
||
1214 | } |
||
1215 | |||
1216 | View Code Duplication | public static function show_onfocus_js( $is_selected ) { |
|
1217 | $atts = array( |
||
1218 | 'icon' => 'frm_reload_icon', |
||
1219 | 'message' => $is_selected ? __( 'Clear default value when typing', 'formidable' ) : __( 'Do not clear default value when typing', 'formidable' ), |
||
1220 | 'is_selected' => $is_selected, |
||
1221 | ); |
||
1222 | self::show_icon_link_js( $atts ); |
||
1223 | } |
||
1224 | |||
1225 | View Code Duplication | public static function show_default_blank_js( $is_selected ) { |
|
1226 | $atts = array( |
||
1227 | 'icon' => 'frm_error_icon', |
||
1228 | 'message' => $is_selected ? __( 'Default value will NOT pass form validation', 'formidable' ) : __( 'Default value will pass form validation', 'formidable' ), |
||
1229 | 'is_selected' => $is_selected, |
||
1230 | ); |
||
1231 | self::show_icon_link_js( $atts ); |
||
1232 | } |
||
1233 | |||
1234 | public static function show_icon_link_js( $atts ) { |
||
1235 | $atts['icon'] .= $atts['is_selected'] ? ' ' : ' frm_inactive_icon '; |
||
1236 | ?><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 |
||
1237 | } |
||
1238 | |||
1239 | public static function switch_field_ids( $val ) { |
||
1240 | global $frm_duplicate_ids; |
||
1241 | $replace = array(); |
||
1242 | $replace_with = array(); |
||
1243 | foreach ( (array) $frm_duplicate_ids as $old => $new ) { |
||
1244 | $replace[] = '[if ' . $old . ']'; |
||
1245 | $replace_with[] = '[if ' . $new . ']'; |
||
1246 | $replace[] = '[if ' . $old . ' '; |
||
1247 | $replace_with[] = '[if ' . $new . ' '; |
||
1248 | $replace[] = '[/if ' . $old . ']'; |
||
1249 | $replace_with[] = '[/if ' . $new . ']'; |
||
1250 | $replace[] = '[foreach ' . $old . ']'; |
||
1251 | $replace_with[] = '[foreach ' . $new . ']'; |
||
1252 | $replace[] = '[/foreach ' . $old . ']'; |
||
1253 | $replace_with[] = '[/foreach ' . $new . ']'; |
||
1254 | $replace[] = '[' . $old . ']'; |
||
1255 | $replace_with[] = '[' . $new . ']'; |
||
1256 | $replace[] = '[' . $old . ' '; |
||
1257 | $replace_with[] = '[' . $new . ' '; |
||
1258 | unset($old, $new); |
||
1259 | } |
||
1260 | if ( is_array( $val ) ) { |
||
1261 | foreach ( $val as $k => $v ) { |
||
1262 | $val[ $k ] = str_replace( $replace, $replace_with, $v ); |
||
1263 | unset($k, $v); |
||
1264 | } |
||
1265 | } else { |
||
1266 | $val = str_replace($replace, $replace_with, $val); |
||
1267 | } |
||
1268 | |||
1269 | return $val; |
||
1270 | } |
||
1271 | |||
1272 | public static function get_us_states() { |
||
1273 | return apply_filters( 'frm_us_states', array( |
||
1274 | 'AL' => 'Alabama', 'AK' => 'Alaska', 'AR' => 'Arkansas', 'AZ' => 'Arizona', |
||
1275 | 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware', |
||
1276 | 'DC' => 'District of Columbia', |
||
1277 | 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho', |
||
1278 | 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas', |
||
1279 | 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine','MD' => 'Maryland', |
||
1280 | 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi', |
||
1281 | 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada', |
||
1282 | 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York', |
||
1283 | 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma', |
||
1284 | 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina', |
||
1285 | 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', |
||
1286 | 'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia', |
||
1287 | 'WI' => 'Wisconsin', 'WY' => 'Wyoming', |
||
1288 | ) ); |
||
1289 | } |
||
1290 | |||
1291 | public static function get_countries() { |
||
1292 | return apply_filters( 'frm_countries', array( |
||
1293 | __( 'Afghanistan', 'formidable' ), __( 'Albania', 'formidable' ), __( 'Algeria', 'formidable' ), |
||
1294 | __( 'American Samoa', 'formidable' ), __( 'Andorra', 'formidable' ), __( 'Angola', 'formidable' ), |
||
1295 | __( 'Anguilla', 'formidable' ), __( 'Antarctica', 'formidable' ), __( 'Antigua and Barbuda', 'formidable' ), |
||
1296 | __( 'Argentina', 'formidable' ), __( 'Armenia', 'formidable' ), __( 'Aruba', 'formidable' ), |
||
1297 | __( 'Australia', 'formidable' ), __( 'Austria', 'formidable' ), __( 'Azerbaijan', 'formidable' ), |
||
1298 | __( 'Bahamas', 'formidable' ), __( 'Bahrain', 'formidable' ), __( 'Bangladesh', 'formidable' ), |
||
1299 | __( 'Barbados', 'formidable' ), __( 'Belarus', 'formidable' ), __( 'Belgium', 'formidable' ), |
||
1300 | __( 'Belize', 'formidable' ), __( 'Benin', 'formidable' ), __( 'Bermuda', 'formidable' ), |
||
1301 | __( 'Bhutan', 'formidable' ), __( 'Bolivia', 'formidable' ), __( 'Bosnia and Herzegovina', 'formidable' ), |
||
1302 | __( 'Botswana', 'formidable' ), __( 'Brazil', 'formidable' ), __( 'Brunei', 'formidable' ), |
||
1303 | __( 'Bulgaria', 'formidable' ), __( 'Burkina Faso', 'formidable' ), __( 'Burundi', 'formidable' ), |
||
1304 | __( 'Cambodia', 'formidable' ), __( 'Cameroon', 'formidable' ), __( 'Canada', 'formidable' ), |
||
1305 | __( 'Cape Verde', 'formidable' ), __( 'Cayman Islands', 'formidable' ), __( 'Central African Republic', 'formidable' ), |
||
1306 | __( 'Chad', 'formidable' ), __( 'Chile', 'formidable' ), __( 'China', 'formidable' ), |
||
1307 | __( 'Colombia', 'formidable' ), __( 'Comoros', 'formidable' ), __( 'Congo', 'formidable' ), |
||
1308 | __( 'Costa Rica', 'formidable' ), __( 'Côte d\'Ivoire', 'formidable' ), __( 'Croatia', 'formidable' ), |
||
1309 | __( 'Cuba', 'formidable' ), __( 'Cyprus', 'formidable' ), __( 'Czech Republic', 'formidable' ), |
||
1310 | __( 'Denmark', 'formidable' ), __( 'Djibouti', 'formidable' ), __( 'Dominica', 'formidable' ), |
||
1311 | __( 'Dominican Republic', 'formidable' ), __( 'East Timor', 'formidable' ), __( 'Ecuador', 'formidable' ), |
||
1312 | __( 'Egypt', 'formidable' ), __( 'El Salvador', 'formidable' ), __( 'Equatorial Guinea', 'formidable' ), |
||
1313 | __( 'Eritrea', 'formidable' ), __( 'Estonia', 'formidable' ), __( 'Ethiopia', 'formidable' ), |
||
1314 | __( 'Fiji', 'formidable' ), __( 'Finland', 'formidable' ), __( 'France', 'formidable' ), |
||
1315 | __( 'French Guiana', 'formidable' ), __( 'French Polynesia', 'formidable' ), __( 'Gabon', 'formidable' ), |
||
1316 | __( 'Gambia', 'formidable' ), __( 'Georgia', 'formidable' ), __( 'Germany', 'formidable' ), |
||
1317 | __( 'Ghana', 'formidable' ), __( 'Gibraltar', 'formidable' ), __( 'Greece', 'formidable' ), |
||
1318 | __( 'Greenland', 'formidable' ), __( 'Grenada', 'formidable' ), __( 'Guam', 'formidable' ), |
||
1319 | __( 'Guatemala', 'formidable' ), __( 'Guinea', 'formidable' ), __( 'Guinea-Bissau', 'formidable' ), |
||
1320 | __( 'Guyana', 'formidable' ), __( 'Haiti', 'formidable' ), __( 'Honduras', 'formidable' ), |
||
1321 | __( 'Hong Kong', 'formidable' ), __( 'Hungary', 'formidable' ), __( 'Iceland', 'formidable' ), |
||
1322 | __( 'India', 'formidable' ), __( 'Indonesia', 'formidable' ), __( 'Iran', 'formidable' ), |
||
1323 | __( 'Iraq', 'formidable' ), __( 'Ireland', 'formidable' ), __( 'Israel', 'formidable' ), |
||
1324 | __( 'Italy', 'formidable' ), __( 'Jamaica', 'formidable' ), __( 'Japan', 'formidable' ), |
||
1325 | __( 'Jordan', 'formidable' ), __( 'Kazakhstan', 'formidable' ), __( 'Kenya', 'formidable' ), |
||
1326 | __( 'Kiribati', 'formidable' ), __( 'North Korea', 'formidable' ), __( 'South Korea', 'formidable' ), |
||
1327 | __( 'Kuwait', 'formidable' ), __( 'Kyrgyzstan', 'formidable' ), __( 'Laos', 'formidable' ), |
||
1328 | __( 'Latvia', 'formidable' ), __( 'Lebanon', 'formidable' ), __( 'Lesotho', 'formidable' ), |
||
1329 | __( 'Liberia', 'formidable' ), __( 'Libya', 'formidable' ), __( 'Liechtenstein', 'formidable' ), |
||
1330 | __( 'Lithuania', 'formidable' ), __( 'Luxembourg', 'formidable' ), __( 'Macedonia', 'formidable' ), |
||
1331 | __( 'Madagascar', 'formidable' ), __( 'Malawi', 'formidable' ), __( 'Malaysia', 'formidable' ), |
||
1332 | __( 'Maldives', 'formidable' ), __( 'Mali', 'formidable' ), __( 'Malta', 'formidable' ), |
||
1333 | __( 'Marshall Islands', 'formidable' ), __( 'Mauritania', 'formidable' ), __( 'Mauritius', 'formidable' ), |
||
1334 | __( 'Mexico', 'formidable' ), __( 'Micronesia', 'formidable' ), __( 'Moldova', 'formidable' ), |
||
1335 | __( 'Monaco', 'formidable' ), __( 'Mongolia', 'formidable' ), __( 'Montenegro', 'formidable' ), |
||
1336 | __( 'Montserrat', 'formidable' ), __( 'Morocco', 'formidable' ), __( 'Mozambique', 'formidable' ), |
||
1337 | __( 'Myanmar', 'formidable' ), __( 'Namibia', 'formidable' ), __( 'Nauru', 'formidable' ), |
||
1338 | __( 'Nepal', 'formidable' ), __( 'Netherlands', 'formidable' ), __( 'New Zealand', 'formidable' ), |
||
1339 | __( 'Nicaragua', 'formidable' ), __( 'Niger', 'formidable' ), __( 'Nigeria', 'formidable' ), |
||
1340 | __( 'Norway', 'formidable' ), __( 'Northern Mariana Islands', 'formidable' ), __( 'Oman', 'formidable' ), |
||
1341 | __( 'Pakistan', 'formidable' ), __( 'Palau', 'formidable' ), __( 'Palestine', 'formidable' ), |
||
1342 | __( 'Panama', 'formidable' ), __( 'Papua New Guinea', 'formidable' ), __( 'Paraguay', 'formidable' ), |
||
1343 | __( 'Peru', 'formidable' ), __( 'Philippines', 'formidable' ), __( 'Poland', 'formidable' ), |
||
1344 | __( 'Portugal', 'formidable' ), __( 'Puerto Rico', 'formidable' ), __( 'Qatar', 'formidable' ), |
||
1345 | __( 'Romania', 'formidable' ), __( 'Russia', 'formidable' ), __( 'Rwanda', 'formidable' ), |
||
1346 | __( 'Saint Kitts and Nevis', 'formidable' ), __( 'Saint Lucia', 'formidable' ), |
||
1347 | __( 'Saint Vincent and the Grenadines', 'formidable' ), __( 'Samoa', 'formidable' ), |
||
1348 | __( 'San Marino', 'formidable' ), __( 'Sao Tome and Principe', 'formidable' ), __( 'Saudi Arabia', 'formidable' ), |
||
1349 | __( 'Senegal', 'formidable' ), __( 'Serbia and Montenegro', 'formidable' ), __( 'Seychelles', 'formidable' ), |
||
1350 | __( 'Sierra Leone', 'formidable' ), __( 'Singapore', 'formidable' ), __( 'Slovakia', 'formidable' ), |
||
1351 | __( 'Slovenia', 'formidable' ), __( 'Solomon Islands', 'formidable' ), __( 'Somalia', 'formidable' ), |
||
1352 | __( 'South Africa', 'formidable' ), __( 'South Sudan', 'formidable' ), |
||
1353 | __( 'Spain', 'formidable' ), __( 'Sri Lanka', 'formidable' ), |
||
1354 | __( 'Sudan', 'formidable' ), __( 'Suriname', 'formidable' ), __( 'Swaziland', 'formidable' ), |
||
1355 | __( 'Sweden', 'formidable' ), __( 'Switzerland', 'formidable' ), __( 'Syria', 'formidable' ), |
||
1356 | __( 'Taiwan', 'formidable' ), __( 'Tajikistan', 'formidable' ), __( 'Tanzania', 'formidable' ), |
||
1357 | __( 'Thailand', 'formidable' ), __( 'Togo', 'formidable' ), __( 'Tonga', 'formidable' ), |
||
1358 | __( 'Trinidad and Tobago', 'formidable' ), __( 'Tunisia', 'formidable' ), __( 'Turkey', 'formidable' ), |
||
1359 | __( 'Turkmenistan', 'formidable' ), __( 'Tuvalu', 'formidable' ), __( 'Uganda', 'formidable' ), |
||
1360 | __( 'Ukraine', 'formidable' ), __( 'United Arab Emirates', 'formidable' ), __( 'United Kingdom', 'formidable' ), |
||
1361 | __( 'United States', 'formidable' ), __( 'Uruguay', 'formidable' ), __( 'Uzbekistan', 'formidable' ), |
||
1362 | __( 'Vanuatu', 'formidable' ), __( 'Vatican City', 'formidable' ), __( 'Venezuela', 'formidable' ), |
||
1363 | __( 'Vietnam', 'formidable' ), __( 'Virgin Islands, British', 'formidable' ), |
||
1364 | __( 'Virgin Islands, U.S.', 'formidable' ), __( 'Yemen', 'formidable' ), __( 'Zambia', 'formidable' ), |
||
1365 | __( 'Zimbabwe', 'formidable' ), |
||
1366 | ) ); |
||
1367 | } |
||
1368 | |||
1369 | public static function get_bulk_prefilled_opts( array &$prepop ) { |
||
1370 | $prepop[ __( 'Countries', 'formidable' ) ] = FrmFieldsHelper::get_countries(); |
||
1371 | |||
1372 | $states = FrmFieldsHelper::get_us_states(); |
||
1373 | $state_abv = array_keys($states); |
||
1374 | sort($state_abv); |
||
1375 | $prepop[ __( 'U.S. State Abbreviations', 'formidable' ) ] = $state_abv; |
||
1376 | |||
1377 | $states = array_values($states); |
||
1378 | sort($states); |
||
1379 | $prepop[ __( 'U.S. States', 'formidable' ) ] = $states; |
||
1380 | unset($state_abv, $states); |
||
1381 | |||
1382 | $prepop[ __( 'Age', 'formidable' ) ] = array( |
||
1383 | __( 'Under 18', 'formidable' ), __( '18-24', 'formidable' ), __( '25-34', 'formidable' ), |
||
1384 | __( '35-44', 'formidable' ), __( '45-54', 'formidable' ), __( '55-64', 'formidable' ), |
||
1385 | __( '65 or Above', 'formidable' ), __( 'Prefer Not to Answer', 'formidable' ), |
||
1386 | ); |
||
1387 | |||
1388 | $prepop[ __( 'Satisfaction', 'formidable' ) ] = array( |
||
1389 | __( 'Very Satisfied', 'formidable' ), __( 'Satisfied', 'formidable' ), __( 'Neutral', 'formidable' ), |
||
1390 | __( 'Unsatisfied', 'formidable' ), __( 'Very Unsatisfied', 'formidable' ), __( 'N/A', 'formidable' ), |
||
1391 | ); |
||
1392 | |||
1393 | $prepop[ __( 'Importance', 'formidable' ) ] = array( |
||
1394 | __( 'Very Important', 'formidable' ), __( 'Important', 'formidable' ), __( 'Neutral', 'formidable' ), |
||
1395 | __( 'Somewhat Important', 'formidable' ), __( 'Not at all Important', 'formidable' ), __( 'N/A', 'formidable' ), |
||
1396 | ); |
||
1397 | |||
1398 | $prepop[ __( 'Agreement', 'formidable' ) ] = array( |
||
1399 | __( 'Strongly Agree', 'formidable' ), __( 'Agree', 'formidable' ), __( 'Neutral', 'formidable' ), |
||
1400 | __( 'Disagree', 'formidable' ), __( 'Strongly Disagree', 'formidable' ), __( 'N/A', 'formidable' ), |
||
1401 | ); |
||
1402 | |||
1403 | $prepop = apply_filters( 'frm_bulk_field_choices', $prepop ); |
||
1404 | } |
||
1405 | |||
1406 | /** |
||
1407 | * Display a field value selector |
||
1408 | * |
||
1409 | * @since 2.03.05 |
||
1410 | * |
||
1411 | * @param int $selector_field_id |
||
1412 | * @param array $selector_args |
||
1413 | */ |
||
1414 | public static function display_field_value_selector( $selector_field_id, $selector_args ) { |
||
1415 | $field_value_selector = FrmFieldFactory::create_field_value_selector( $selector_field_id, $selector_args ); |
||
1416 | $field_value_selector->display(); |
||
1417 | } |
||
1418 | |||
1419 | /** |
||
1420 | * Convert a field object to a flat array |
||
1421 | * |
||
1422 | * @since 2.03.05 |
||
1423 | * |
||
1424 | * @param object $field |
||
1425 | * |
||
1426 | * @return array |
||
1427 | */ |
||
1428 | public static function convert_field_object_to_flat_array( $field ) { |
||
1429 | $field_options = $field->field_options; |
||
1430 | $field_array = get_object_vars( $field ); |
||
1431 | unset( $field_array['field_options'] ); |
||
1432 | return $field_array + $field_options; |
||
1433 | } |
||
1434 | |||
1435 | public static function dropdown_categories( $args ) { |
||
1447 | } |
||
1448 |