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 ) { |
||
| 321 | } |
||
| 322 | } |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @param string $html |
||
| 326 | * @param array $field |
||
| 327 | * @param array $errors |
||
| 328 | * @param object $form |
||
| 329 | * @param array $args |
||
| 330 | * |
||
| 331 | * @return string |
||
| 332 | */ |
||
| 333 | public static function replace_shortcodes( $html, $field, $errors = array(), $form = false, $args = array() ) { |
||
| 334 | _deprecated_function( __FUNCTION__, '3.0', 'FrmFieldType::prepare_field_html' ); |
||
| 335 | $field_obj = FrmFieldFactory::get_field_type( $field['type'], $field ); |
||
| 336 | return $field_obj->prepare_field_html( compact( 'errors', 'form' ) ); |
||
| 337 | } |
||
| 338 | |||
| 339 | /** |
||
| 340 | * @since 3.0 |
||
| 341 | * |
||
| 342 | * @param array $atts |
||
| 343 | * @param string|array $value |
||
| 344 | */ |
||
| 345 | public static function run_wpautop( $atts, &$value ) { |
||
| 346 | $autop = isset( $atts['wpautop'] ) ? $atts['wpautop'] : true; |
||
| 347 | if ( apply_filters( 'frm_use_wpautop', $autop ) ) { |
||
| 348 | if ( is_array( $value ) ) { |
||
| 349 | $value = implode( "\n", $value ); |
||
| 350 | } |
||
| 351 | $value = wpautop( $value ); |
||
| 352 | } |
||
| 353 | } |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Get the class to use for the label position |
||
| 357 | * @since 2.05 |
||
| 358 | */ |
||
| 359 | public static function &label_position( $position, $field, $form ) { |
||
| 360 | if ( $position && $position != '' ) { |
||
| 361 | return $position; |
||
| 362 | } |
||
| 363 | |||
| 364 | $position = FrmStylesController::get_style_val( 'position', $form ); |
||
| 365 | if ( $position == 'none' ) { |
||
| 366 | $position = 'top'; |
||
| 367 | } elseif ( $position == 'no_label' ) { |
||
| 368 | $position = 'none'; |
||
| 369 | } elseif ( $position == 'inside' && ! self::is_placeholder_field_type( $field['type'] ) ) { |
||
| 370 | $position = 'top'; |
||
| 371 | } |
||
| 372 | |||
| 373 | $position = apply_filters( 'frm_html_label_position', $position, $field, $form ); |
||
| 374 | $position = ( ! empty( $position ) ) ? $position : 'top'; |
||
| 375 | |||
| 376 | return $position; |
||
| 377 | } |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Check if this field type allows placeholders |
||
| 381 | * @since 2.05 |
||
| 382 | */ |
||
| 383 | public static function is_placeholder_field_type( $type ) { |
||
| 384 | return ! in_array( $type, array( 'select', 'radio', 'checkbox', 'hidden', 'file' ) ); |
||
| 385 | } |
||
| 386 | |||
| 387 | public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) { |
||
| 388 | _deprecated_function( __FUNCTION__, '3.0', 'FrmShortcodeHelper::remove_inline_conditions' ); |
||
| 389 | FrmShortcodeHelper::remove_inline_conditions( $no_vars, $code, $replace_with, $html ); |
||
| 390 | } |
||
| 391 | |||
| 392 | public static function get_shortcode_tag( $shortcodes, $short_key, $args ) { |
||
| 393 | _deprecated_function( __FUNCTION__, '3.0', 'FrmShortcodeHelper::get_shortcode_tag' ); |
||
| 394 | return FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key, $args ); |
||
| 395 | } |
||
| 396 | |||
| 397 | public static function get_checkbox_id( $field, $opt_key ) { |
||
| 398 | $id = $field['id']; |
||
| 399 | if ( isset( $field['in_section'] ) && $field['in_section'] ) { |
||
| 400 | $id .= '-' . $field['in_section']; |
||
| 401 | } |
||
| 402 | return 'frm_checkbox_' . $id . '-' . $opt_key; |
||
| 403 | } |
||
| 404 | |||
| 405 | public static function display_recaptcha( $field ) { |
||
| 406 | _deprecated_function( __FUNCTION__, '3.0', 'FrmFieldCaptcha::field_input' ); |
||
| 407 | } |
||
| 408 | |||
| 409 | public static function show_single_option( $field ) { |
||
| 410 | if ( ! is_array( $field['options'] ) ) { |
||
| 411 | return; |
||
| 412 | } |
||
| 413 | |||
| 414 | $field_name = isset( $field['html_name'] ) ? $field['html_name'] : $field['name']; |
||
| 415 | $html_id = isset( $field['html_id'] ) ? $field['html_id'] : self::get_html_id( $field ); |
||
| 416 | |||
| 417 | foreach ( $field['options'] as $opt_key => $opt ) { |
||
| 418 | $field_val = self::get_value_from_array( $opt, $opt_key, $field ); |
||
| 419 | $opt = self::get_label_from_array( $opt, $opt_key, $field ); |
||
| 420 | |||
| 421 | // Get string for Other text field, if needed |
||
| 422 | $other_val = self::get_other_val( compact( 'opt_key', 'field' ) ); |
||
| 423 | |||
| 424 | $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"' : ''; |
||
| 425 | |||
| 426 | // If this is an "Other" option, get the HTML for it |
||
| 427 | if ( self::is_other_opt( $opt_key ) ) { |
||
| 428 | if ( FrmAppHelper::pro_is_installed() ) { |
||
| 429 | require( FrmProAppHelper::plugin_path() . '/classes/views/frmpro-fields/other-option.php' ); |
||
| 430 | } |
||
| 431 | } else { |
||
| 432 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' ); |
||
| 433 | } |
||
| 434 | |||
| 435 | unset( $checked, $other_val ); |
||
| 436 | } |
||
| 437 | } |
||
| 438 | |||
| 439 | public static function get_value_from_array( $opt, $opt_key, $field ) { |
||
| 440 | $opt = apply_filters( 'frm_field_value_saved', $opt, $opt_key, $field ); |
||
| 441 | return FrmFieldsController::check_value( $opt, $opt_key, $field ); |
||
| 442 | } |
||
| 443 | |||
| 444 | public static function get_label_from_array( $opt, $opt_key, $field ) { |
||
| 445 | $opt = apply_filters( 'frm_field_label_seen', $opt, $opt_key, $field ); |
||
| 446 | return FrmFieldsController::check_label( $opt ); |
||
| 447 | } |
||
| 448 | |||
| 449 | /** |
||
| 450 | * @param int $tax_id |
||
| 451 | * |
||
| 452 | * @return string |
||
| 453 | */ |
||
| 454 | public static function get_term_link( $tax_id ) { |
||
| 455 | $tax = get_taxonomy($tax_id); |
||
| 456 | if ( ! $tax ) { |
||
| 457 | return ''; |
||
| 458 | } |
||
| 459 | |||
| 460 | $link = sprintf( |
||
| 461 | __( 'Please add options from the WordPress "%1$s" page', 'formidable' ), |
||
| 462 | '<a href="' . esc_url( admin_url( 'edit-tags.php?taxonomy=' . $tax->name ) ) . '" target="_blank">' . ( empty( $tax->labels->name ) ? __( 'Categories' ) : $tax->labels->name ) . '</a>' |
||
| 463 | ); |
||
| 464 | unset($tax); |
||
| 465 | |||
| 466 | return $link; |
||
| 467 | } |
||
| 468 | |||
| 469 | public static function value_meets_condition( $observed_value, $cond, $hide_opt ) { |
||
| 470 | $hide_opt = self::get_value_for_comparision( $hide_opt ); |
||
| 471 | $observed_value = self::get_value_for_comparision( $observed_value ); |
||
| 472 | |||
| 473 | if ( is_array($observed_value) ) { |
||
| 474 | return self::array_value_condition($observed_value, $cond, $hide_opt); |
||
| 475 | } |
||
| 476 | |||
| 477 | $m = false; |
||
| 478 | if ( $cond == '==' ) { |
||
| 479 | $m = $observed_value == $hide_opt; |
||
| 480 | } else if ( $cond == '!=' ) { |
||
| 481 | $m = $observed_value != $hide_opt; |
||
| 482 | } else if ( $cond == '>' ) { |
||
| 483 | $m = $observed_value > $hide_opt; |
||
| 484 | } else if ( $cond == '<' ) { |
||
| 485 | $m = $observed_value < $hide_opt; |
||
| 486 | } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) { |
||
| 487 | $m = stripos($observed_value, $hide_opt); |
||
| 488 | if ( $cond == 'not LIKE' ) { |
||
| 489 | $m = ( $m === false ) ? true : false; |
||
| 490 | } else { |
||
| 491 | $m = ( $m === false ) ? false : true; |
||
| 492 | } |
||
| 493 | } |
||
| 494 | return $m; |
||
| 495 | } |
||
| 496 | |||
| 497 | /** |
||
| 498 | * Trim and sanitize the values |
||
| 499 | * @since 2.05 |
||
| 500 | */ |
||
| 501 | private static function get_value_for_comparision( $value ) { |
||
| 502 | // Remove white space from hide_opt |
||
| 503 | if ( ! is_array( $value ) ) { |
||
| 504 | $value = trim( $value ); |
||
| 505 | } |
||
| 506 | |||
| 507 | return wp_kses_post( $value ); |
||
| 508 | } |
||
| 509 | |||
| 510 | public static function array_value_condition( $observed_value, $cond, $hide_opt ) { |
||
| 511 | $m = false; |
||
| 512 | if ( $cond == '==' ) { |
||
| 513 | if ( is_array($hide_opt) ) { |
||
| 514 | $m = array_intersect($hide_opt, $observed_value); |
||
| 515 | $m = empty($m) ? false : true; |
||
| 516 | } else { |
||
| 517 | $m = in_array($hide_opt, $observed_value); |
||
| 518 | } |
||
| 519 | } else if ( $cond == '!=' ) { |
||
| 520 | $m = ! in_array($hide_opt, $observed_value); |
||
| 521 | } else if ( $cond == '>' ) { |
||
| 522 | $min = min($observed_value); |
||
| 523 | $m = $min > $hide_opt; |
||
| 524 | } else if ( $cond == '<' ) { |
||
| 525 | $max = max($observed_value); |
||
| 526 | $m = $max < $hide_opt; |
||
| 527 | } else if ( $cond == 'LIKE' || $cond == 'not LIKE' ) { |
||
| 528 | foreach ( $observed_value as $ob ) { |
||
| 529 | $m = strpos($ob, $hide_opt); |
||
| 530 | if ( $m !== false ) { |
||
| 531 | $m = true; |
||
| 532 | break; |
||
| 533 | } |
||
| 534 | } |
||
| 535 | |||
| 536 | if ( $cond == 'not LIKE' ) { |
||
| 537 | $m = ( $m === false ) ? true : false; |
||
| 538 | } |
||
| 539 | } |
||
| 540 | |||
| 541 | return $m; |
||
| 542 | } |
||
| 543 | |||
| 544 | /** |
||
| 545 | * Replace a few basic shortcodes and field ids |
||
| 546 | * @since 2.0 |
||
| 547 | * @return string |
||
| 548 | */ |
||
| 549 | public static function basic_replace_shortcodes( $value, $form, $entry ) { |
||
| 550 | if ( strpos($value, '[sitename]') !== false ) { |
||
| 551 | $new_value = wp_specialchars_decode( FrmAppHelper::site_name(), ENT_QUOTES ); |
||
| 552 | $value = str_replace('[sitename]', $new_value, $value); |
||
| 553 | } |
||
| 554 | |||
| 555 | $value = apply_filters('frm_content', $value, $form, $entry); |
||
| 556 | $value = do_shortcode($value); |
||
| 557 | |||
| 558 | return $value; |
||
| 559 | } |
||
| 560 | |||
| 561 | public static function get_shortcodes( $content, $form_id ) { |
||
| 562 | if ( FrmAppHelper::pro_is_installed() ) { |
||
| 563 | return FrmProDisplaysHelper::get_shortcodes($content, $form_id); |
||
| 564 | } |
||
| 565 | |||
| 566 | $fields = FrmField::getAll( array( |
||
| 567 | 'fi.form_id' => (int) $form_id, |
||
| 568 | 'fi.type not' => FrmField::no_save_fields(), |
||
| 569 | ) ); |
||
| 570 | |||
| 571 | $tagregexp = self::allowed_shortcodes($fields); |
||
| 572 | |||
| 573 | preg_match_all("/\[(if )?($tagregexp)\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?/s", $content, $matches, PREG_PATTERN_ORDER); |
||
| 574 | |||
| 575 | return $matches; |
||
| 576 | } |
||
| 577 | |||
| 578 | public static function allowed_shortcodes( $fields = array() ) { |
||
| 579 | $tagregexp = array( 'editlink', 'id', 'key', 'ip', 'siteurl', 'sitename', 'admin_email', 'post[-|_]id', 'created[-|_]at', 'updated[-|_]at', 'updated[-|_]by', 'parent[-|_]id' ); |
||
| 580 | |||
| 581 | foreach ( $fields as $field ) { |
||
| 582 | $tagregexp[] = $field->id; |
||
| 583 | $tagregexp[] = $field->field_key; |
||
| 584 | } |
||
| 585 | |||
| 586 | $tagregexp = implode('|', $tagregexp); |
||
| 587 | return $tagregexp; |
||
| 588 | } |
||
| 589 | |||
| 590 | public static function replace_content_shortcodes( $content, $entry, $shortcodes ) { |
||
| 591 | foreach ( $shortcodes[0] as $short_key => $tag ) { |
||
| 592 | if ( empty( $tag ) ) { |
||
| 593 | continue; |
||
| 594 | } |
||
| 595 | |||
| 596 | $atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[3][ $short_key ] ); |
||
| 597 | $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key ); |
||
| 598 | |||
| 599 | $atts['entry'] = $entry; |
||
| 600 | $atts['tag'] = $tag; |
||
| 601 | $replace_with = self::get_value_for_shortcode( $atts ); |
||
| 602 | |||
| 603 | if ( $replace_with !== null ) { |
||
| 604 | $content = str_replace( $shortcodes[0][ $short_key ], $replace_with, $content ); |
||
| 605 | } |
||
| 606 | |||
| 607 | unset( $atts, $replace_with ); |
||
| 608 | } |
||
| 609 | |||
| 610 | return $content; |
||
| 611 | } |
||
| 612 | |||
| 613 | /** |
||
| 614 | * @since 3.0 |
||
| 615 | * |
||
| 616 | * @param $atts |
||
| 617 | * |
||
| 618 | * @return string |
||
| 619 | */ |
||
| 620 | private static function get_value_for_shortcode( $atts ) { |
||
| 621 | $clean_tag = str_replace( '-', '_', $atts['tag'] ); |
||
| 622 | |||
| 623 | $shortcode_values = array( |
||
| 624 | 'id' => $atts['entry']->id, |
||
| 625 | 'key' => $atts['entry']->item_key, |
||
| 626 | 'ip' => $atts['entry']->ip, |
||
| 627 | ); |
||
| 628 | |||
| 629 | $dynamic_default = array( 'admin_email', 'siteurl', 'frmurl', 'sitename', 'get' ); |
||
| 630 | |||
| 631 | if ( isset( $shortcode_values[ $atts['tag'] ] ) ) { |
||
| 632 | $replace_with = $shortcode_values[ $atts['tag'] ]; |
||
| 633 | } elseif ( in_array( $atts['tag'], $dynamic_default ) ) { |
||
| 634 | $replace_with = self::dynamic_default_values( $atts['tag'], $atts ); |
||
| 635 | } elseif ( $clean_tag == 'user_agent' ) { |
||
| 636 | $description = maybe_unserialize( $atts['entry']->description ); |
||
| 637 | $replace_with = FrmEntriesHelper::get_browser( $description['browser'] ); |
||
| 638 | } elseif ( $clean_tag == 'created_at' || $clean_tag == 'updated_at' ) { |
||
| 639 | $atts['tag'] = $clean_tag; |
||
| 640 | $replace_with = self::get_entry_timestamp( $atts ); |
||
| 641 | } elseif ( $clean_tag == 'created_by' || $clean_tag == 'updated_by' ) { |
||
| 642 | $replace_with = self::get_display_value( $atts['entry']->{$clean_tag}, (object) array( 'type' => 'user_id' ), $atts ); |
||
| 643 | } else { |
||
| 644 | $replace_with = self::get_field_shortcode_value( $atts ); |
||
| 645 | } |
||
| 646 | |||
| 647 | return $replace_with; |
||
| 648 | } |
||
| 649 | |||
| 650 | /** |
||
| 651 | * @since 3.0 |
||
| 652 | * |
||
| 653 | * @param $atts |
||
| 654 | * |
||
| 655 | * @return string |
||
| 656 | */ |
||
| 657 | private static function get_entry_timestamp( $atts ) { |
||
| 658 | if ( isset( $atts['format'] ) ) { |
||
| 659 | $time_format = ' '; |
||
| 660 | } else { |
||
| 661 | $atts['format'] = get_option('date_format'); |
||
| 662 | $time_format = ''; |
||
| 663 | } |
||
| 664 | |||
| 665 | return FrmAppHelper::get_formatted_time( $atts['entry']->{$atts['tag']}, $atts['format'], $time_format ); |
||
| 666 | } |
||
| 667 | |||
| 668 | /** |
||
| 669 | * @since 3.0 |
||
| 670 | * |
||
| 671 | * @param $atts |
||
| 672 | * |
||
| 673 | * @return null|string |
||
| 674 | */ |
||
| 675 | private static function get_field_shortcode_value( $atts ) { |
||
| 676 | $field = FrmField::getOne( $atts['tag'] ); |
||
| 677 | if ( empty( $field ) ) { |
||
| 678 | return null; |
||
| 679 | } |
||
| 680 | |||
| 681 | if ( isset( $atts['show'] ) && $atts['show'] == 'field_label' ) { |
||
| 682 | $replace_with = $field->name; |
||
| 683 | } elseif ( isset( $atts['show'] ) && $atts['show'] == 'description' ) { |
||
| 684 | $replace_with = $field->description; |
||
| 685 | } else { |
||
| 686 | $replace_with = FrmEntryMeta::get_meta_value( $atts['entry'], $field->id ); |
||
| 687 | $string_value = $replace_with; |
||
| 688 | if ( is_array( $replace_with ) ) { |
||
| 689 | $sep = isset( $atts['sep'] ) ? $atts['sep'] : ', '; |
||
| 690 | $string_value = implode( $sep, $replace_with ); |
||
| 691 | } |
||
| 692 | |||
| 693 | if ( empty( $string_value ) && $string_value != '0' ) { |
||
| 694 | $replace_with = ''; |
||
| 695 | } else { |
||
| 696 | $atts['entry_id'] = $atts['entry']->id; |
||
| 697 | $atts['entry_key'] = $atts['entry']->item_key; |
||
| 698 | $replace_with = self::get_display_value( $replace_with, $field, $atts ); |
||
| 699 | } |
||
| 700 | } |
||
| 701 | |||
| 702 | return $replace_with; |
||
| 703 | } |
||
| 704 | |||
| 705 | /** |
||
| 706 | * Get the value to replace a few standard shortcodes |
||
| 707 | * |
||
| 708 | * @since 2.0 |
||
| 709 | * @return string |
||
| 710 | */ |
||
| 711 | public static function dynamic_default_values( $tag, $atts = array(), $return_array = false ) { |
||
| 712 | $new_value = ''; |
||
| 713 | switch ( $tag ) { |
||
| 714 | case 'admin_email': |
||
| 715 | $new_value = get_option('admin_email'); |
||
| 716 | break; |
||
| 717 | case 'siteurl': |
||
| 718 | $new_value = FrmAppHelper::site_url(); |
||
| 719 | break; |
||
| 720 | case 'frmurl': |
||
| 721 | $new_value = FrmAppHelper::plugin_url(); |
||
| 722 | break; |
||
| 723 | case 'sitename': |
||
| 724 | $new_value = FrmAppHelper::site_name(); |
||
| 725 | break; |
||
| 726 | case 'get': |
||
| 727 | $new_value = self::process_get_shortcode( $atts, $return_array ); |
||
| 728 | } |
||
| 729 | |||
| 730 | return $new_value; |
||
| 731 | } |
||
| 732 | |||
| 733 | /** |
||
| 734 | * Process the [get] shortcode |
||
| 735 | * |
||
| 736 | * @since 2.0 |
||
| 737 | * @return string|array |
||
| 738 | */ |
||
| 739 | public static function process_get_shortcode( $atts, $return_array = false ) { |
||
| 740 | if ( ! isset($atts['param']) ) { |
||
| 741 | return ''; |
||
| 742 | } |
||
| 743 | |||
| 744 | if ( strpos($atts['param'], '[') ) { |
||
| 745 | $atts['param'] = str_replace('[', '[', $atts['param']); |
||
| 746 | $atts['param'] = str_replace(']', ']', $atts['param']); |
||
| 747 | } |
||
| 748 | |||
| 749 | $new_value = FrmAppHelper::get_param( $atts['param'], '', 'get', 'sanitize_text_field' ); |
||
| 750 | $new_value = FrmAppHelper::get_query_var( $new_value, $atts['param'] ); |
||
| 751 | |||
| 752 | if ( $new_value == '' ) { |
||
| 753 | if ( ! isset($atts['prev_val']) ) { |
||
| 754 | $atts['prev_val'] = ''; |
||
| 755 | } |
||
| 756 | |||
| 757 | $new_value = isset($atts['default']) ? $atts['default'] : $atts['prev_val']; |
||
| 758 | } |
||
| 759 | |||
| 760 | if ( is_array($new_value) && ! $return_array ) { |
||
| 761 | $new_value = implode(', ', $new_value); |
||
| 762 | } |
||
| 763 | |||
| 764 | return $new_value; |
||
| 765 | } |
||
| 766 | |||
| 767 | public static function get_display_value( $value, $field, $atts = array() ) { |
||
| 768 | |||
| 769 | $value = apply_filters( 'frm_get_' . $field->type . '_display_value', $value, $field, $atts ); |
||
| 770 | $value = apply_filters( 'frm_get_display_value', $value, $field, $atts ); |
||
| 771 | |||
| 772 | return self::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) ); |
||
| 773 | } |
||
| 774 | |||
| 775 | /** |
||
| 776 | * @param $atts array Includes value, field, and atts |
||
| 777 | */ |
||
| 778 | public static function get_unfiltered_display_value( $atts ) { |
||
| 779 | $value = $atts['value']; |
||
| 780 | $field = $atts['field']; |
||
| 781 | $atts = isset( $atts['atts'] ) ? $atts['atts'] : $atts; |
||
| 782 | |||
| 783 | if ( is_array( $field ) ) { |
||
| 784 | $field = $field['id']; |
||
| 785 | } |
||
| 786 | |||
| 787 | $field_obj = FrmFieldFactory::get_field_object( $field ); |
||
| 788 | return $field_obj->get_display_value( $value, $atts ); |
||
| 789 | } |
||
| 790 | |||
| 791 | /** |
||
| 792 | * Get a value from the user profile from the user ID |
||
| 793 | * @since 3.0 |
||
| 794 | */ |
||
| 795 | public static function get_user_display_name( $user_id, $user_info = 'display_name', $args = array() ) { |
||
| 796 | $defaults = array( |
||
| 797 | 'blank' => false, |
||
| 798 | 'link' => false, |
||
| 799 | 'size' => 96, |
||
| 800 | ); |
||
| 801 | |||
| 802 | $args = wp_parse_args($args, $defaults); |
||
| 803 | |||
| 804 | $user = get_userdata($user_id); |
||
| 805 | $info = ''; |
||
| 806 | |||
| 807 | if ( $user ) { |
||
| 808 | if ( $user_info == 'avatar' ) { |
||
| 809 | $info = get_avatar( $user_id, $args['size'] ); |
||
| 810 | } elseif ( $user_info == 'author_link' ) { |
||
| 811 | $info = get_author_posts_url( $user_id ); |
||
| 812 | } else { |
||
| 813 | $info = isset($user->$user_info) ? $user->$user_info : ''; |
||
| 814 | } |
||
| 815 | |||
| 816 | if ( 'display_name' === $user_info && empty( $info ) && ! $args['blank'] ) { |
||
| 817 | $info = $user->user_login; |
||
| 818 | } |
||
| 819 | } |
||
| 820 | |||
| 821 | if ( $args['link'] ) { |
||
| 822 | $info = '<a href="' . esc_url( admin_url('user-edit.php?user_id=' . $user_id ) ) . '">' . $info . '</a>'; |
||
| 823 | } |
||
| 824 | |||
| 825 | return $info; |
||
| 826 | } |
||
| 827 | |||
| 828 | public static function get_field_types( $type ) { |
||
| 829 | $single_input = array( 'text', 'textarea', 'rte', 'number', 'email', 'url', 'file', 'date', 'phone', 'hidden', 'time', 'user_id', 'tag', 'password' ); |
||
| 830 | $multiple_input = array( 'radio', 'checkbox', 'select', 'scale', 'star', 'lookup' ); |
||
| 831 | $other_type = array( 'html', 'break' ); |
||
| 832 | |||
| 833 | $field_selection = array_merge( FrmField::pro_field_selection(), FrmField::field_selection() ); |
||
| 834 | |||
| 835 | $field_types = array(); |
||
| 836 | if ( in_array($type, $single_input) ) { |
||
| 837 | self::field_types_for_input( $single_input, $field_selection, $field_types ); |
||
| 838 | } else if ( in_array($type, $multiple_input) ) { |
||
| 839 | self::field_types_for_input( $multiple_input, $field_selection, $field_types ); |
||
| 840 | } else if ( in_array($type, $other_type) ) { |
||
| 841 | self::field_types_for_input( $other_type, $field_selection, $field_types ); |
||
| 842 | } else if ( isset( $field_selection[ $type ] ) ) { |
||
| 843 | $field_types[ $type ] = $field_selection[ $type ]; |
||
| 844 | } |
||
| 845 | |||
| 846 | $field_types = apply_filters( 'frm_switch_field_types', $field_types, compact( 'type' ) ); |
||
| 847 | return $field_types; |
||
| 848 | } |
||
| 849 | |||
| 850 | private static function field_types_for_input( $inputs, $fields, &$field_types ) { |
||
| 851 | foreach ( $inputs as $input ) { |
||
| 852 | $field_types[ $input ] = $fields[ $input ]; |
||
| 853 | unset($input); |
||
| 854 | } |
||
| 855 | } |
||
| 856 | |||
| 857 | /** |
||
| 858 | * Check if current field option is an "other" option |
||
| 859 | * |
||
| 860 | * @since 2.0.6 |
||
| 861 | * |
||
| 862 | * @param string $opt_key |
||
| 863 | * @return boolean Returns true if current field option is an "Other" option |
||
| 864 | */ |
||
| 865 | public static function is_other_opt( $opt_key ) { |
||
| 866 | return $opt_key && strpos( $opt_key, 'other_' ) === 0; |
||
| 867 | } |
||
| 868 | |||
| 869 | /** |
||
| 870 | * Get value that belongs in "Other" text box |
||
| 871 | * |
||
| 872 | * @since 2.0.6 |
||
| 873 | * |
||
| 874 | * @param array $args |
||
| 875 | */ |
||
| 876 | public static function get_other_val( $args ) { |
||
| 877 | $defaults = array( |
||
| 878 | 'opt_key' => 0, |
||
| 879 | 'field' => array(), |
||
| 880 | 'parent' => false, |
||
| 881 | 'pointer' => false, |
||
| 882 | ); |
||
| 883 | $args = wp_parse_args( $args, $defaults ); |
||
| 884 | |||
| 885 | $opt_key = $args['opt_key']; |
||
| 886 | $field = $args['field']; |
||
| 887 | $parent = $args['parent']; |
||
| 888 | $pointer = $args['pointer']; |
||
| 889 | $other_val = ''; |
||
| 890 | |||
| 891 | // If option is an "other" option and there is a value set for this field, |
||
| 892 | // check if the value belongs in the current "Other" option text field |
||
| 893 | if ( ! FrmFieldsHelper::is_other_opt( $opt_key ) || ! FrmField::is_option_true( $field, 'value' ) ) { |
||
| 894 | return $other_val; |
||
| 895 | } |
||
| 896 | |||
| 897 | // Check posted vals before checking saved values |
||
| 898 | |||
| 899 | // For fields inside repeating sections - note, don't check if $pointer is true because it will often be zero |
||
| 900 | if ( $parent && isset( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ) ) { |
||
| 901 | if ( FrmField::is_field_with_multiple_values( $field ) ) { |
||
| 902 | $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 ] ) : ''; |
||
| 903 | } else { |
||
| 904 | $other_val = sanitize_text_field( $_POST['item_meta'][ $parent ][ $pointer ]['other'][ $field['id'] ] ); |
||
| 905 | } |
||
| 906 | return $other_val; |
||
| 907 | |||
| 908 | } else if ( isset( $field['id'] ) && isset( $_POST['item_meta']['other'][ $field['id'] ] ) ) { |
||
| 909 | // For normal fields |
||
| 910 | |||
| 911 | if ( FrmField::is_field_with_multiple_values( $field ) ) { |
||
| 912 | $other_val = isset( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) ? sanitize_text_field( $_POST['item_meta']['other'][ $field['id'] ][ $opt_key ] ) : ''; |
||
| 913 | } else { |
||
| 914 | $other_val = sanitize_text_field( $_POST['item_meta']['other'][ $field['id'] ] ); |
||
| 915 | } |
||
| 916 | return $other_val; |
||
| 917 | } |
||
| 918 | |||
| 919 | // For checkboxes |
||
| 920 | if ( $field['type'] == 'checkbox' && is_array( $field['value'] ) ) { |
||
| 921 | // Check if there is an "other" val in saved value and make sure the |
||
| 922 | // "other" val is not equal to the Other checkbox option |
||
| 923 | if ( isset( $field['value'][ $opt_key ] ) && $field['options'][ $opt_key ] != $field['value'][ $opt_key ] ) { |
||
| 924 | $other_val = $field['value'][ $opt_key ]; |
||
| 925 | } |
||
| 926 | } else { |
||
| 927 | /** |
||
| 928 | * For radio buttons and dropdowns |
||
| 929 | * Check if saved value equals any of the options. If not, set it as the other value. |
||
| 930 | */ |
||
| 931 | foreach ( $field['options'] as $opt_key => $opt_val ) { |
||
| 932 | $temp_val = is_array( $opt_val ) ? $opt_val['value'] : $opt_val; |
||
| 933 | // Multi-select dropdowns - key is not preserved |
||
| 934 | if ( is_array( $field['value'] ) ) { |
||
| 935 | $o_key = array_search( $temp_val, $field['value'] ); |
||
| 936 | if ( isset( $field['value'][ $o_key ] ) ) { |
||
| 937 | unset( $field['value'][ $o_key ], $o_key ); |
||
| 938 | } |
||
| 939 | } else if ( $temp_val == $field['value'] ) { |
||
| 940 | // For radio and regular dropdowns |
||
| 941 | return ''; |
||
| 942 | } else { |
||
| 943 | $other_val = $field['value']; |
||
| 944 | } |
||
| 945 | unset( $opt_key, $opt_val, $temp_val ); |
||
| 946 | } |
||
| 947 | // For multi-select dropdowns only |
||
| 948 | if ( is_array( $field['value'] ) && ! empty( $field['value'] ) ) { |
||
| 949 | $other_val = reset( $field['value'] ); |
||
| 950 | } |
||
| 951 | } |
||
| 952 | |||
| 953 | return $other_val; |
||
| 954 | } |
||
| 955 | |||
| 956 | /** |
||
| 957 | * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val. |
||
| 958 | * Intended for front-end use |
||
| 959 | * |
||
| 960 | * @since 2.0.6 |
||
| 961 | * |
||
| 962 | * @param array $args should include field, opt_key and field name |
||
| 963 | * @param boolean $other_opt |
||
| 964 | * @param string $checked |
||
| 965 | * @return array $other_args |
||
| 966 | */ |
||
| 967 | public static function prepare_other_input( $args, &$other_opt, &$checked ) { |
||
| 968 | //Check if this is an "Other" option |
||
| 969 | if ( ! self::is_other_opt( $args['opt_key'] ) ) { |
||
| 970 | return; |
||
| 971 | } |
||
| 972 | |||
| 973 | $other_opt = true; |
||
| 974 | $other_args = array(); |
||
| 975 | |||
| 976 | self::set_other_name( $args, $other_args ); |
||
| 977 | self::set_other_value( $args, $other_args ); |
||
| 978 | |||
| 979 | if ( $other_args['value'] ) { |
||
| 980 | $checked = 'checked="checked" '; |
||
| 981 | } |
||
| 982 | |||
| 983 | return $other_args; |
||
| 984 | } |
||
| 985 | |||
| 986 | /** |
||
| 987 | * @param array $args |
||
| 988 | * @param array $other_args |
||
| 989 | * @since 2.0.6 |
||
| 990 | */ |
||
| 991 | private static function set_other_name( $args, &$other_args ) { |
||
| 992 | //Set up name for other field |
||
| 993 | $other_args['name'] = str_replace( '[]', '', $args['field_name'] ); |
||
| 994 | $other_args['name'] = preg_replace('/\[' . $args['field']['id'] . '\]$/', '', $other_args['name']); |
||
| 995 | $other_args['name'] = $other_args['name'] . '[other]' . '[' . $args['field']['id'] . ']'; |
||
| 996 | |||
| 997 | //Converts item_meta[field_id] => item_meta[other][field_id] and |
||
| 998 | //item_meta[parent][0][field_id] => item_meta[parent][0][other][field_id] |
||
| 999 | if ( FrmField::is_field_with_multiple_values( $args['field'] ) ) { |
||
| 1000 | $other_args['name'] .= '[' . $args['opt_key'] . ']'; |
||
| 1001 | } |
||
| 1002 | } |
||
| 1003 | |||
| 1004 | /** |
||
| 1005 | * Find the parent and pointer, and get text for "other" text field |
||
| 1006 | * @param array $args |
||
| 1007 | * @param array $other_args |
||
| 1008 | * |
||
| 1009 | * @since 2.0.6 |
||
| 1010 | */ |
||
| 1011 | private static function set_other_value( $args, &$other_args ) { |
||
| 1012 | $parent = ''; |
||
| 1013 | $pointer = ''; |
||
| 1014 | |||
| 1015 | // Check for parent ID and pointer |
||
| 1016 | $temp_array = explode( '[', $args['field_name'] ); |
||
| 1017 | |||
| 1018 | // Count should only be greater than 3 if inside of a repeating section |
||
| 1019 | if ( count( $temp_array ) > 3 ) { |
||
| 1020 | $parent = str_replace( ']', '', $temp_array[1] ); |
||
| 1021 | $pointer = str_replace( ']', '', $temp_array[2]); |
||
| 1022 | } |
||
| 1023 | |||
| 1024 | // Get text for "other" text field |
||
| 1025 | $other_args['value'] = self::get_other_val( array( |
||
| 1026 | 'opt_key' => $args['opt_key'], |
||
| 1027 | 'field' => $args['field'], |
||
| 1028 | 'parent' => $parent, |
||
| 1029 | 'pointer' => $pointer, |
||
| 1030 | ) ); |
||
| 1031 | } |
||
| 1032 | |||
| 1033 | /** |
||
| 1034 | * If this field includes an other option, show it |
||
| 1035 | * @param $args array |
||
| 1036 | * @since 2.0.6 |
||
| 1037 | */ |
||
| 1038 | public static function include_other_input( $args ) { |
||
| 1039 | if ( ! $args['other_opt'] ) { |
||
| 1040 | return; |
||
| 1041 | } |
||
| 1042 | |||
| 1043 | $classes = array( 'frm_other_input' ); |
||
| 1044 | if ( ! $args['checked'] || trim( $args['checked'] ) == '' ) { |
||
| 1045 | // hide the field if the other option is not selected |
||
| 1046 | $classes[] = 'frm_pos_none'; |
||
| 1047 | } |
||
| 1048 | if ( $args['field']['type'] == 'select' && $args['field']['multiple'] ) { |
||
| 1049 | $classes[] = 'frm_other_full'; |
||
| 1050 | } |
||
| 1051 | |||
| 1052 | // Set up HTML ID for Other field |
||
| 1053 | $other_id = self::get_other_field_html_id( $args['field']['type'], $args['html_id'], $args['opt_key'] ); |
||
| 1054 | |||
| 1055 | $label = isset( $args['opt_label'] ) ? $args['opt_label'] : $args['field']['name']; |
||
| 1056 | |||
| 1057 | ?><label for="<?php echo esc_attr( $other_id ) ?>" class="frm_screen_reader frm_hidden"><?php |
||
| 1058 | echo esc_html( $label ); |
||
| 1059 | ?></label><input type="text" id="<?php echo esc_attr( $other_id ) ?>" class="<?php echo sanitize_text_field( implode( ' ', $classes ) ) ?>" <?php |
||
| 1060 | echo ( $args['read_only'] ? ' readonly="readonly" disabled="disabled"' : '' ); |
||
| 1061 | ?> name="<?php echo esc_attr( $args['name'] ) ?>" value="<?php echo esc_attr( $args['value'] ); ?>" /><?php |
||
| 1062 | } |
||
| 1063 | |||
| 1064 | /** |
||
| 1065 | * Get the HTML id for an "Other" text field |
||
| 1066 | * Note: This does not affect fields in repeating sections |
||
| 1067 | * |
||
| 1068 | * @since 2.0.08 |
||
| 1069 | * @param string $type - field type |
||
| 1070 | * @param string $html_id |
||
| 1071 | * @param string|boolean $opt_key |
||
| 1072 | * @return string $other_id |
||
| 1073 | */ |
||
| 1074 | public static function get_other_field_html_id( $type, $html_id, $opt_key = false ) { |
||
| 1075 | $other_id = $html_id; |
||
| 1076 | |||
| 1077 | // If hidden radio field, add an opt key of 0 |
||
| 1078 | if ( $type == 'radio' && $opt_key === false ) { |
||
| 1079 | $opt_key = 0; |
||
| 1080 | } |
||
| 1081 | |||
| 1082 | if ( $opt_key !== false ) { |
||
| 1083 | $other_id .= '-' . $opt_key; |
||
| 1084 | } |
||
| 1085 | |||
| 1086 | $other_id .= '-otext'; |
||
| 1087 | |||
| 1088 | return $other_id; |
||
| 1089 | } |
||
| 1090 | |||
| 1091 | public static function clear_on_focus_html( $field, $display, $id = '' ) { |
||
| 1092 | if ( $display['clear_on_focus'] ) { |
||
| 1093 | $has_default_value = ! empty( $field['default_value'] ); |
||
| 1094 | echo '<span id="frm_clear_on_focus_' . esc_attr( $field['id'] . $id ) . '" class="frm-show-click">'; |
||
| 1095 | |||
| 1096 | if ( $display['default_blank'] ) { |
||
| 1097 | self::show_default_blank_js( $field['default_blank'], $has_default_value ); |
||
| 1098 | echo '<input type="hidden" name="field_options[default_blank_' . esc_attr( $field['id'] ) . ']" value="' . esc_attr( $field['default_blank'] ) . '" />'; |
||
| 1099 | } |
||
| 1100 | |||
| 1101 | self::show_onfocus_js( $field['clear_on_focus'], $has_default_value ); |
||
| 1102 | echo '<input type="hidden" name="field_options[clear_on_focus_' . esc_attr( $field['id'] ) . ']" value="' . esc_attr( $field['clear_on_focus'] ) . '" />'; |
||
| 1103 | |||
| 1104 | echo '</span>'; |
||
| 1105 | } |
||
| 1106 | } |
||
| 1107 | |||
| 1108 | public static function show_onfocus_js( $is_selected, $has_default_value = true ) { |
||
| 1109 | $atts = array( |
||
| 1110 | 'icon' => 'frm_reload_icon', |
||
| 1111 | 'message' => $is_selected ? __( 'Clear default value when typing', 'formidable' ) : __( 'Do not clear default value when typing', 'formidable' ), |
||
| 1112 | 'is_selected' => $is_selected, |
||
| 1113 | 'has_default' => $has_default_value, |
||
| 1114 | ); |
||
| 1115 | self::show_icon_link_js( $atts ); |
||
| 1116 | } |
||
| 1117 | |||
| 1118 | public static function show_default_blank_js( $is_selected, $has_default_value = true ) { |
||
| 1119 | $atts = array( |
||
| 1120 | 'icon' => 'frm_error_icon', |
||
| 1121 | 'message' => $is_selected ? __( 'Default value will NOT pass form validation', 'formidable' ) : __( 'Default value will pass form validation', 'formidable' ), |
||
| 1122 | 'is_selected' => $is_selected, |
||
| 1123 | 'has_default' => $has_default_value, |
||
| 1124 | ); |
||
| 1125 | self::show_icon_link_js( $atts ); |
||
| 1126 | } |
||
| 1127 | |||
| 1128 | public static function show_icon_link_js( $atts ) { |
||
| 1129 | $atts['icon'] .= $atts['is_selected'] ? ' ' : ' frm_inactive_icon '; |
||
| 1130 | if ( isset( $atts['has_default'] ) && ! $atts['has_default'] ) { |
||
| 1131 | $atts['icon'] .= 'frm_hidden '; |
||
| 1132 | } |
||
| 1133 | 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>'; |
||
| 1134 | } |
||
| 1135 | |||
| 1136 | public static function switch_field_ids( $val ) { |
||
| 1137 | global $frm_duplicate_ids; |
||
| 1138 | $replace = array(); |
||
| 1139 | $replace_with = array(); |
||
| 1140 | foreach ( (array) $frm_duplicate_ids as $old => $new ) { |
||
| 1141 | $replace[] = '[if ' . $old . ']'; |
||
| 1142 | $replace_with[] = '[if ' . $new . ']'; |
||
| 1143 | $replace[] = '[if ' . $old . ' '; |
||
| 1144 | $replace_with[] = '[if ' . $new . ' '; |
||
| 1145 | $replace[] = '[/if ' . $old . ']'; |
||
| 1146 | $replace_with[] = '[/if ' . $new . ']'; |
||
| 1147 | $replace[] = '[foreach ' . $old . ']'; |
||
| 1148 | $replace_with[] = '[foreach ' . $new . ']'; |
||
| 1149 | $replace[] = '[/foreach ' . $old . ']'; |
||
| 1150 | $replace_with[] = '[/foreach ' . $new . ']'; |
||
| 1151 | $replace[] = '[' . $old . ']'; |
||
| 1152 | $replace_with[] = '[' . $new . ']'; |
||
| 1153 | $replace[] = '[' . $old . ' '; |
||
| 1154 | $replace_with[] = '[' . $new . ' '; |
||
| 1155 | unset($old, $new); |
||
| 1156 | } |
||
| 1157 | if ( is_array( $val ) ) { |
||
| 1158 | foreach ( $val as $k => $v ) { |
||
| 1159 | $val[ $k ] = str_replace( $replace, $replace_with, $v ); |
||
| 1160 | unset($k, $v); |
||
| 1161 | } |
||
| 1162 | } else { |
||
| 1163 | $val = str_replace($replace, $replace_with, $val); |
||
| 1164 | } |
||
| 1165 | |||
| 1166 | return $val; |
||
| 1167 | } |
||
| 1168 | |||
| 1169 | public static function get_us_states() { |
||
| 1170 | return apply_filters( 'frm_us_states', array( |
||
| 1171 | 'AL' => 'Alabama', |
||
| 1172 | 'AK' => 'Alaska', |
||
| 1173 | 'AR' => 'Arkansas', |
||
| 1174 | 'AZ' => 'Arizona', |
||
| 1175 | 'CA' => 'California', |
||
| 1176 | 'CO' => 'Colorado', |
||
| 1177 | 'CT' => 'Connecticut', |
||
| 1178 | 'DE' => 'Delaware', |
||
| 1179 | 'DC' => 'District of Columbia', |
||
| 1180 | 'FL' => 'Florida', |
||
| 1181 | 'GA' => 'Georgia', |
||
| 1182 | 'HI' => 'Hawaii', |
||
| 1183 | 'ID' => 'Idaho', |
||
| 1184 | 'IL' => 'Illinois', |
||
| 1185 | 'IN' => 'Indiana', |
||
| 1186 | 'IA' => 'Iowa', |
||
| 1187 | 'KS' => 'Kansas', |
||
| 1188 | 'KY' => 'Kentucky', |
||
| 1189 | 'LA' => 'Louisiana', |
||
| 1190 | 'ME' => 'Maine', |
||
| 1191 | 'MD' => 'Maryland', |
||
| 1192 | 'MA' => 'Massachusetts', |
||
| 1193 | 'MI' => 'Michigan', |
||
| 1194 | 'MN' => 'Minnesota', |
||
| 1195 | 'MS' => 'Mississippi', |
||
| 1196 | 'MO' => 'Missouri', |
||
| 1197 | 'MT' => 'Montana', |
||
| 1198 | 'NE' => 'Nebraska', |
||
| 1199 | 'NV' => 'Nevada', |
||
| 1200 | 'NH' => 'New Hampshire', |
||
| 1201 | 'NJ' => 'New Jersey', |
||
| 1202 | 'NM' => 'New Mexico', |
||
| 1203 | 'NY' => 'New York', |
||
| 1204 | 'NC' => 'North Carolina', |
||
| 1205 | 'ND' => 'North Dakota', |
||
| 1206 | 'OH' => 'Ohio', |
||
| 1207 | 'OK' => 'Oklahoma', |
||
| 1208 | 'OR' => 'Oregon', |
||
| 1209 | 'PA' => 'Pennsylvania', |
||
| 1210 | 'RI' => 'Rhode Island', |
||
| 1211 | 'SC' => 'South Carolina', |
||
| 1212 | 'SD' => 'South Dakota', |
||
| 1213 | 'TN' => 'Tennessee', |
||
| 1214 | 'TX' => 'Texas', |
||
| 1215 | 'UT' => 'Utah', |
||
| 1216 | 'VT' => 'Vermont', |
||
| 1217 | 'VA' => 'Virginia', |
||
| 1218 | 'WA' => 'Washington', |
||
| 1219 | 'WV' => 'West Virginia', |
||
| 1220 | 'WI' => 'Wisconsin', |
||
| 1221 | 'WY' => 'Wyoming', |
||
| 1222 | ) ); |
||
| 1223 | } |
||
| 1224 | |||
| 1225 | public static function get_countries() { |
||
| 1226 | 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' ) ) ); |
||
| 1227 | } |
||
| 1228 | |||
| 1229 | public static function get_bulk_prefilled_opts( array &$prepop ) { |
||
| 1230 | $prepop[ __( 'Countries', 'formidable' ) ] = FrmFieldsHelper::get_countries(); |
||
| 1231 | |||
| 1232 | $states = FrmFieldsHelper::get_us_states(); |
||
| 1233 | $state_abv = array_keys($states); |
||
| 1234 | sort($state_abv); |
||
| 1235 | $prepop[ __( 'U.S. State Abbreviations', 'formidable' ) ] = $state_abv; |
||
| 1236 | |||
| 1237 | $states = array_values($states); |
||
| 1238 | sort($states); |
||
| 1239 | $prepop[ __( 'U.S. States', 'formidable' ) ] = $states; |
||
| 1240 | unset($state_abv, $states); |
||
| 1241 | |||
| 1242 | $prepop[ __( 'Age', 'formidable' ) ] = array( |
||
| 1243 | __( 'Under 18', 'formidable' ), |
||
| 1244 | __( '18-24', 'formidable' ), |
||
| 1245 | __( '25-34', 'formidable' ), |
||
| 1246 | __( '35-44', 'formidable' ), |
||
| 1247 | __( '45-54', 'formidable' ), |
||
| 1248 | __( '55-64', 'formidable' ), |
||
| 1249 | __( '65 or Above', 'formidable' ), |
||
| 1250 | __( 'Prefer Not to Answer', 'formidable' ), |
||
| 1251 | ); |
||
| 1252 | |||
| 1253 | $prepop[ __( 'Satisfaction', 'formidable' ) ] = array( |
||
| 1254 | __( 'Very Satisfied', 'formidable' ), |
||
| 1255 | __( 'Satisfied', 'formidable' ), |
||
| 1256 | __( 'Neutral', 'formidable' ), |
||
| 1257 | __( 'Unsatisfied', 'formidable' ), |
||
| 1258 | __( 'Very Unsatisfied', 'formidable' ), |
||
| 1259 | __( 'N/A', 'formidable' ), |
||
| 1260 | ); |
||
| 1261 | |||
| 1262 | $prepop[ __( 'Importance', 'formidable' ) ] = array( |
||
| 1263 | __( 'Very Important', 'formidable' ), |
||
| 1264 | __( 'Important', 'formidable' ), |
||
| 1265 | __( 'Neutral', 'formidable' ), |
||
| 1266 | __( 'Somewhat Important', 'formidable' ), |
||
| 1267 | __( 'Not at all Important', 'formidable' ), |
||
| 1268 | __( 'N/A', 'formidable' ), |
||
| 1269 | ); |
||
| 1270 | |||
| 1271 | $prepop[ __( 'Agreement', 'formidable' ) ] = array( |
||
| 1272 | __( 'Strongly Agree', 'formidable' ), |
||
| 1273 | __( 'Agree', 'formidable' ), |
||
| 1274 | __( 'Neutral', 'formidable' ), |
||
| 1275 | __( 'Disagree', 'formidable' ), |
||
| 1276 | __( 'Strongly Disagree', 'formidable' ), |
||
| 1277 | __( 'N/A', 'formidable' ), |
||
| 1278 | ); |
||
| 1279 | |||
| 1280 | $prepop = apply_filters( 'frm_bulk_field_choices', $prepop ); |
||
| 1281 | } |
||
| 1282 | |||
| 1283 | /** |
||
| 1284 | * Display a field value selector |
||
| 1285 | * |
||
| 1286 | * @since 2.03.05 |
||
| 1287 | * |
||
| 1288 | * @param int $selector_field_id |
||
| 1289 | * @param array $selector_args |
||
| 1290 | */ |
||
| 1291 | public static function display_field_value_selector( $selector_field_id, $selector_args ) { |
||
| 1292 | $field_value_selector = FrmFieldFactory::create_field_value_selector( $selector_field_id, $selector_args ); |
||
| 1293 | $field_value_selector->display(); |
||
| 1294 | } |
||
| 1295 | |||
| 1296 | /** |
||
| 1297 | * Convert a field object to a flat array |
||
| 1298 | * |
||
| 1299 | * @since 2.03.05 |
||
| 1300 | * |
||
| 1301 | * @param object $field |
||
| 1302 | * |
||
| 1303 | * @return array |
||
| 1304 | */ |
||
| 1305 | public static function convert_field_object_to_flat_array( $field ) { |
||
| 1306 | $field_options = $field->field_options; |
||
| 1307 | $field_array = get_object_vars( $field ); |
||
| 1308 | unset( $field_array['field_options'] ); |
||
| 1309 | return $field_array + $field_options; |
||
| 1310 | } |
||
| 1311 | |||
| 1312 | public static function get_default_field_opts( $type, $field = null, $limit = false ) { |
||
| 1313 | if ( $limit ) { |
||
| 1314 | _deprecated_function( __FUNCTION__, '3.0', 'FrmFieldHelper::get_default_field_options' ); |
||
| 1315 | $field_options = self::get_default_field_options( $type ); |
||
| 1316 | } else { |
||
| 1317 | _deprecated_function( __FUNCTION__, '3.0', 'FrmFieldHelper::get_default_field' ); |
||
| 1318 | $field_options = self::get_default_field( $type ); |
||
| 1319 | } |
||
| 1320 | |||
| 1321 | return $field_options; |
||
| 1322 | } |
||
| 1323 | |||
| 1324 | public static function dropdown_categories( $args ) { |
||
| 1335 | } |
||
| 1336 | } |
||
| 1337 |