| @@ -1,9 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - die( 'You are not allowed to call this page directly.' ); | |
| 4 | -} | |
| 5 | - | |
| 6 | 2 | /** |
| 7 | 3 | * @since 3.0 |
| 8 | 4 | */ |
| 9 | 5 | |
| @@ -13,9 +9,9 @@ | ||
| 13 | 9 | |
| 14 | 10 | private $html_id; |
| 15 | 11 | |
| 16 | 12 | /** |
| 17 | - * @var FrmFieldType | |
| 13 | + * @var FrmFieldType | |
| 18 | 14 | */ |
| 19 | 15 | private $field_obj; |
| 20 | 16 | |
| 21 | 17 | private $field_id; |
| @@ -86,10 +82,10 @@ | ||
| 86 | 82 | * @param array $atts |
| 87 | 83 | */ |
| 88 | 84 | private function set_pass_args( $atts ) { |
| 89 | 85 | $this->pass_args = $atts; |
| 86 | + $exclude = array( 'field_obj', 'html' ); | |
| 90 | 87 | |
| 91 | - $exclude = array( 'field_obj', 'html' ); | |
| 92 | 88 | foreach ( $exclude as $ex ) { |
| 93 | 89 | if ( isset( $atts[ $ex ] ) ) { |
| 94 | 90 | unset( $this->pass_args[ $ex ] ); |
| 95 | 91 | } |
| @@ -152,9 +148,9 @@ | ||
| 152 | 148 | //replace [key] |
| 153 | 149 | $this->html = str_replace( '[key]', $this->field_obj->get_field_column( 'field_key' ), $this->html ); |
| 154 | 150 | |
| 155 | 151 | //replace [field_name] |
| 156 | - $this->html = str_replace( '[field_name]', FrmAppHelper::maybe_kses( $this->field_obj->get_field_column( 'name' ) ), $this->html ); | |
| 152 | + $this->html = str_replace( '[field_name]', $this->field_obj->get_field_column( 'name' ), $this->html ); | |
| 157 | 153 | } |
| 158 | 154 | |
| 159 | 155 | /** |
| 160 | 156 | * @since 3.0 |
| @@ -170,9 +166,9 @@ | ||
| 170 | 166 | * |
| 171 | 167 | * @since 3.0 |
| 172 | 168 | */ |
| 173 | 169 | private function maybe_replace_description_shortcode( $wp_processed = false ) { |
| 174 | - $is_html = 'html' === $this->field_obj->get_field_column( 'type' ); | |
| 170 | + $is_html = 'html' === $this->field_obj->get_field_column( 'type' ); | |
| 175 | 171 | $should_replace = ( $is_html && $wp_processed ) || ( ! $is_html && ! $wp_processed ); |
| 176 | 172 | if ( $should_replace ) { |
| 177 | 173 | $this->replace_description_shortcode(); |
| 178 | 174 | } |
| @@ -182,9 +178,9 @@ | ||
| 182 | 178 | * @since 3.0 |
| 183 | 179 | */ |
| 184 | 180 | private function replace_description_shortcode() { |
| 185 | 181 | $this->maybe_add_description_id(); |
| 186 | - $description = FrmAppHelper::maybe_kses( $this->field_obj->get_field_column( 'description' ) ); | |
| 182 | + $description = $this->field_obj->get_field_column( 'description' ); | |
| 187 | 183 | FrmShortcodeHelper::remove_inline_conditions( ( $description && $description != '' ), 'description', $description, $this->html ); |
| 188 | 184 | } |
| 189 | 185 | |
| 190 | 186 | /** |
| @@ -229,42 +225,12 @@ | ||
| 229 | 225 | */ |
| 230 | 226 | private function replace_error_shortcode() { |
| 231 | 227 | $this->maybe_add_error_id(); |
| 232 | 228 | $error = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? $this->pass_args['errors'][ 'field' . $this->field_id ] : false; |
| 233 | - | |
| 234 | - if ( ! empty( $error ) && false === strpos( $this->html, 'role="alert"' ) && FrmAppHelper::should_include_alert_role_on_field_errors() ) { | |
| 235 | - $error_body = self::get_error_body( $this->html ); | |
| 236 | - if ( is_string( $error_body ) && false === strpos( $error_body, 'role=' ) ) { | |
| 237 | - $new_error_body = preg_replace( '/class="frm_error/', 'role="alert" class="frm_error', $error_body, 1 ); | |
| 238 | - $this->html = str_replace( '[if error]' . $error_body . '[/if error]', '[if error]' . $new_error_body . '[/if error]', $this->html ); | |
| 239 | - } | |
| 240 | - } | |
| 241 | - | |
| 242 | 229 | FrmShortcodeHelper::remove_inline_conditions( ! empty( $error ), 'error', $error, $this->html ); |
| 243 | 230 | } |
| 244 | 231 | |
| 245 | 232 | /** |
| 246 | - * Pull the HTML between [if error] and [/if error] shortcodes. | |
| 247 | - * | |
| 248 | - * @param string $html | |
| 249 | - * @return string|false | |
| 250 | - */ | |
| 251 | - private static function get_error_body( $html ) { | |
| 252 | - $start = strpos( $html, '[if error]' ); | |
| 253 | - if ( false === $start ) { | |
| 254 | - return false; | |
| 255 | - } | |
| 256 | - | |
| 257 | - $end = strpos( $html, '[/if error]', $start ); | |
| 258 | - if ( false === $end ) { | |
| 259 | - return false; | |
| 260 | - } | |
| 261 | - | |
| 262 | - $error_body = substr( $html, $start + 10, $end - $start - 10 ); | |
| 263 | - return $error_body; | |
| 264 | - } | |
| 265 | - | |
| 266 | - /** | |
| 267 | 233 | * Add an ID to the error message for aria-describedby. |
| 268 | 234 | * This ID was added to the HTML in v3.06.02. |
| 269 | 235 | * |
| 270 | 236 | * @since 3.06.02 |
| @@ -283,9 +249,9 @@ | ||
| 283 | 249 | * @since 3.0 |
| 284 | 250 | */ |
| 285 | 251 | private function replace_required_class() { |
| 286 | 252 | $required_class = FrmField::is_required( $this->field_obj->get_field() ) ? ' frm_required_field' : ''; |
| 287 | - $this->html = str_replace( '[required_class]', $required_class, $this->html ); | |
| 253 | + $this->html = str_replace( '[required_class]', $required_class, $this->html ); | |
| 288 | 254 | } |
| 289 | 255 | |
| 290 | 256 | /** |
| 291 | 257 | * @since 3.0 |
| @@ -350,9 +316,9 @@ | ||
| 350 | 316 | preg_match_all( "/\[(input|deletelink)\b(.*?)(?:(\/))?\]/s", $this->html, $shortcodes, PREG_PATTERN_ORDER ); |
| 351 | 317 | |
| 352 | 318 | foreach ( $shortcodes[0] as $short_key => $tag ) { |
| 353 | 319 | $shortcode_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] ); |
| 354 | - $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key ); | |
| 320 | + $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key ); | |
| 355 | 321 | |
| 356 | 322 | $replace_with = ''; |
| 357 | 323 | |
| 358 | 324 | if ( $tag == 'deletelink' && FrmAppHelper::pro_is_installed() ) { |
| @@ -371,9 +337,8 @@ | ||
| 371 | 337 | * @return string |
| 372 | 338 | */ |
| 373 | 339 | private function replace_input_shortcode( $shortcode_atts ) { |
| 374 | 340 | $shortcode_atts = $this->prepare_input_shortcode_atts( $shortcode_atts ); |
| 375 | - | |
| 376 | 341 | return $this->field_obj->include_front_field_input( $this->pass_args, $shortcode_atts ); |
| 377 | 342 | } |
| 378 | 343 | |
| 379 | 344 | /** |
| @@ -382,9 +347,9 @@ | ||
| 382 | 347 | * @return array |
| 383 | 348 | */ |
| 384 | 349 | private function prepare_input_shortcode_atts( $shortcode_atts ) { |
| 385 | 350 | if ( isset( $shortcode_atts['opt'] ) ) { |
| 386 | - $shortcode_atts['opt'] --; | |
| 351 | + $shortcode_atts['opt']--; | |
| 387 | 352 | } |
| 388 | 353 | |
| 389 | 354 | $field_class = isset( $shortcode_atts['class'] ) ? $shortcode_atts['class'] : ''; |
| 390 | 355 | $this->field_obj->set_field_column( 'input_class', $field_class ); |
| @@ -392,9 +357,11 @@ | ||
| 392 | 357 | if ( isset( $shortcode_atts['class'] ) ) { |
| 393 | 358 | unset( $shortcode_atts['class'] ); |
| 394 | 359 | } |
| 395 | 360 | |
| 396 | - $shortcode_atts['aria-invalid'] = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? 'true' : 'false'; | |
| 361 | + if ( isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ) { | |
| 362 | + $shortcode_atts['aria-invalid'] = 'true'; | |
| 363 | + } | |
| 397 | 364 | |
| 398 | 365 | $this->field_obj->set_field_column( 'shortcodes', $shortcode_atts ); |
| 399 | 366 | |
| 400 | 367 | return $shortcode_atts; |
| @@ -407,9 +374,12 @@ | ||
| 407 | 374 | * @since 3.0 |
| 408 | 375 | */ |
| 409 | 376 | private function add_class_to_label() { |
| 410 | 377 | $label_class = $this->field_obj->get_label_class(); |
| 411 | - $this->html = str_replace( '[label_position]', $label_class, $this->html ); | |
| 378 | + $this->html = str_replace( '[label_position]', $label_class, $this->html ); | |
| 379 | + if ( $this->field_obj->get_field_column( 'label' ) == 'inside' && $this->field_obj->get_field_column( 'value' ) != '' ) { | |
| 380 | + $this->html = str_replace( 'frm_primary_label', 'frm_primary_label frm_visible', $this->html ); | |
| 381 | + } | |
| 412 | 382 | } |
| 413 | 383 | |
| 414 | 384 | /** |
| 415 | 385 | * Replace [entry_key] |
| @@ -416,9 +386,9 @@ | ||
| 416 | 386 | * |
| 417 | 387 | * @since 3.0 |
| 418 | 388 | */ |
| 419 | 389 | private function replace_entry_key() { |
| 420 | - $entry_key = FrmAppHelper::simple_get( 'entry', 'sanitize_title' ); | |
| 390 | + $entry_key = FrmAppHelper::simple_get( 'entry', 'sanitize_title' ); | |
| 421 | 391 | $this->html = str_replace( '[entry_key]', $entry_key, $this->html ); |
| 422 | 392 | } |
| 423 | 393 | |
| 424 | 394 | /** |
| @@ -435,8 +405,9 @@ | ||
| 435 | 405 | } |
| 436 | 406 | $this->html = str_replace( '[error_class]', $classes, $this->html ); |
| 437 | 407 | } |
| 438 | 408 | |
| 409 | + | |
| 439 | 410 | /** |
| 440 | 411 | * Get the classes for a field div |
| 441 | 412 | * |
| 442 | 413 | * @since 3.0 |
| @@ -449,15 +420,9 @@ | ||
| 449 | 420 | |
| 450 | 421 | // Add label position class |
| 451 | 422 | $settings = $this->field_obj->display_field_settings(); |
| 452 | 423 | if ( isset( $settings['label_position'] ) && $settings['label_position'] ) { |
| 453 | - $label_position = $this->field_obj->get_field_column( 'label' ); | |
| 454 | - $classes .= ' frm_' . $label_position . '_container'; | |
| 455 | - | |
| 456 | - // Add class if field has value, to be used for floating label styling. | |
| 457 | - if ( 'inside' === $label_position && $this->field_obj->get_field_column( 'value' ) ) { | |
| 458 | - $classes .= ' frm_label_float_top'; | |
| 459 | - } | |
| 424 | + $classes .= ' frm_' . $this->field_obj->get_field_column( 'label' ) . '_container'; | |
| 460 | 425 | } |
| 461 | 426 | |
| 462 | 427 | // Add CSS layout classes |
| 463 | 428 | $extra_classes = $this->field_obj->get_field_column( 'classes' ); |