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