| @@ -8,19 +8,18 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | class FrmEntryFormatter { |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | + * @var stdClass | |
| 12 | 13 | * @since 2.04 |
| 13 | - * | |
| 14 | - * @var stdClass|null | |
| 15 | 14 | */ |
| 16 | - protected $entry; | |
| 15 | + protected $entry = null; | |
| 17 | 16 | |
| 18 | 17 | /** |
| 19 | - * @var FrmEntryValues|null | |
| 18 | + * @var FrmEntryValues | |
| 20 | 19 | * @since 2.04 |
| 21 | 20 | */ |
| 22 | - protected $entry_values; | |
| 21 | + protected $entry_values = null; | |
| 23 | 22 | |
| 24 | 23 | /** |
| 25 | 24 | * @var bool |
| 26 | 25 | * @since 2.04 |
| @@ -57,12 +56,12 @@ | ||
| 57 | 56 | */ |
| 58 | 57 | protected $direction = 'ltr'; |
| 59 | 58 | |
| 60 | 59 | /** |
| 61 | - * @var FrmTableHTMLGenerator|null | |
| 60 | + * @var FrmTableHTMLGenerator | |
| 62 | 61 | * @since 2.04 |
| 63 | 62 | */ |
| 64 | - protected $table_generator; | |
| 63 | + protected $table_generator = null; | |
| 65 | 64 | |
| 66 | 65 | /** |
| 67 | 66 | * @var bool |
| 68 | 67 | * @since 2.04 |
| @@ -91,9 +90,9 @@ | ||
| 91 | 90 | * FrmEntryFormat constructor |
| 92 | 91 | * |
| 93 | 92 | * @since 2.04 |
| 94 | 93 | * |
| 95 | - * @param array $atts | |
| 94 | + * @param $atts | |
| 96 | 95 | */ |
| 97 | 96 | public function __construct( $atts ) { |
| 98 | 97 | $this->init_entry( $atts ); |
| 99 | 98 | |
| @@ -196,25 +195,8 @@ | ||
| 196 | 195 | } else { |
| 197 | 196 | $this->format = 'table'; |
| 198 | 197 | } |
| 199 | 198 | } |
| 200 | - | |
| 201 | - /** | |
| 202 | - * Allows modifying the format property of FrmEntryFormatter object. | |
| 203 | - * | |
| 204 | - * @since 5.0.16 | |
| 205 | - * | |
| 206 | - * @param string $format The format. | |
| 207 | - * @param array $args Includes `atts`, `entry`. | |
| 208 | - */ | |
| 209 | - $this->format = apply_filters( | |
| 210 | - 'frm_entry_formatter_format', | |
| 211 | - $this->format, | |
| 212 | - array( | |
| 213 | - 'atts' => $atts, | |
| 214 | - 'entry' => $this->entry, | |
| 215 | - ) | |
| 216 | - ); | |
| 217 | 199 | } |
| 218 | 200 | |
| 219 | 201 | /** |
| 220 | 202 | * Set the array_key property that sets whether the keys in the |
| @@ -224,9 +206,9 @@ | ||
| 224 | 206 | * |
| 225 | 207 | * @param array $atts |
| 226 | 208 | */ |
| 227 | 209 | protected function init_array_key( $atts ) { |
| 228 | - if ( isset( $atts['array_key'] ) && $atts['array_key'] === 'id' ) { | |
| 210 | + if ( isset( $atts['array_key'] ) && $atts['array_key'] == 'id' ) { | |
| 229 | 211 | $this->array_key = 'id'; |
| 230 | 212 | } |
| 231 | 213 | } |
| 232 | 214 | |
| @@ -289,9 +271,9 @@ | ||
| 289 | 271 | * |
| 290 | 272 | * @since 3.0 |
| 291 | 273 | */ |
| 292 | 274 | protected function skip_fields() { |
| 293 | - return array( 'captcha', 'html', FrmSubmitHelper::FIELD_TYPE ); | |
| 275 | + return array( 'captcha', 'html' ); | |
| 294 | 276 | } |
| 295 | 277 | |
| 296 | 278 | /** |
| 297 | 279 | * Set the include_extras property |
| @@ -349,9 +331,9 @@ | ||
| 349 | 331 | $atts['source'] = 'entry_formatter'; |
| 350 | 332 | $atts['wpautop'] = false; |
| 351 | 333 | $atts['return_array'] = true; |
| 352 | 334 | |
| 353 | - $unset = array( 'id', 'form_id', 'format' ); | |
| 335 | + $unset = array( 'id', 'entry', 'form_id', 'format' ); | |
| 354 | 336 | foreach ( $unset as $param ) { |
| 355 | 337 | if ( isset( $atts[ $param ] ) ) { |
| 356 | 338 | unset( $atts[ $param ] ); |
| 357 | 339 | } |
| @@ -356,10 +338,9 @@ | ||
| 356 | 338 | unset( $atts[ $param ] ); |
| 357 | 339 | } |
| 358 | 340 | } |
| 359 | 341 | |
| 360 | - $this->atts = $atts; | |
| 361 | - $this->atts['entry'] = $this->entry; | |
| 342 | + $this->atts = $atts; | |
| 362 | 343 | } |
| 363 | 344 | |
| 364 | 345 | /** |
| 365 | 346 | * Get the field key or ID, depending on array_key property |
| @@ -367,12 +348,12 @@ | ||
| 367 | 348 | * @since 2.05 |
| 368 | 349 | * |
| 369 | 350 | * @param FrmFieldValue $field_value |
| 370 | 351 | * |
| 371 | - * @return int|string | |
| 352 | + * @return string|int | |
| 372 | 353 | */ |
| 373 | 354 | protected function get_key_or_id( $field_value ) { |
| 374 | - return $this->array_key === 'key' ? $field_value->get_field_key() : $field_value->get_field_id(); | |
| 355 | + return $this->array_key == 'key' ? $field_value->get_field_key() : $field_value->get_field_id(); | |
| 375 | 356 | } |
| 376 | 357 | |
| 377 | 358 | /** |
| 378 | 359 | * Package and return the formatted entry values |
| @@ -401,26 +382,9 @@ | ||
| 401 | 382 | } else { |
| 402 | 383 | $content = ''; |
| 403 | 384 | } |
| 404 | 385 | |
| 405 | - /** | |
| 406 | - * Allows modifying the formatted entry values content. | |
| 407 | - * | |
| 408 | - * @since 5.0.16 | |
| 409 | - * | |
| 410 | - * @param string $content The formatted entry values content. | |
| 411 | - * @param array $args Includes `entry`, `atts`, `format`, `entry_values`. | |
| 412 | - */ | |
| 413 | - return apply_filters( | |
| 414 | - 'frm_formatted_entry_values_content', | |
| 415 | - $content, | |
| 416 | - array( | |
| 417 | - 'entry' => $this->entry, | |
| 418 | - 'atts' => $this->atts, | |
| 419 | - 'format' => $this->format, | |
| 420 | - 'entry_values' => $this->entry_values, | |
| 421 | - ) | |
| 422 | - ); | |
| 386 | + return $content; | |
| 423 | 387 | } |
| 424 | 388 | |
| 425 | 389 | /** |
| 426 | 390 | * Return the formatted HTML table with entry values |
| @@ -451,9 +415,9 @@ | ||
| 451 | 415 | * |
| 452 | 416 | * @param string $content |
| 453 | 417 | */ |
| 454 | 418 | protected function add_field_values_to_content( &$content ) { |
| 455 | - foreach ( $this->entry_values->get_field_values() as $field_value ) { | |
| 419 | + foreach ( $this->entry_values->get_field_values() as $field_id => $field_value ) { | |
| 456 | 420 | |
| 457 | 421 | /** |
| 458 | 422 | * @var FrmFieldValue $field_value |
| 459 | 423 | */ |
| @@ -516,9 +480,9 @@ | ||
| 516 | 480 | * |
| 517 | 481 | * @since 2.04 |
| 518 | 482 | * |
| 519 | 483 | * @param FrmFieldValue $field_value |
| 520 | - * @param array $output | |
| 484 | + * @param array $output | |
| 521 | 485 | */ |
| 522 | 486 | protected function push_single_field_to_array( $field_value, &$output ) { |
| 523 | 487 | if ( $this->include_field_in_content( $field_value ) ) { |
| 524 | 488 | |
| @@ -538,9 +502,9 @@ | ||
| 538 | 502 | * |
| 539 | 503 | * @since 2.04 |
| 540 | 504 | * |
| 541 | 505 | * @param string $label |
| 542 | - * @param mixed $display_value | |
| 506 | + * @param mixed $display_value | |
| 543 | 507 | * @param string $content |
| 544 | 508 | */ |
| 545 | 509 | protected function add_plain_text_row( $label, $display_value, &$content ) { |
| 546 | 510 | $display_value = $this->prepare_display_value_for_plain_text_content( $display_value ); |
| @@ -557,9 +521,9 @@ | ||
| 557 | 521 | * |
| 558 | 522 | * @since 2.04 |
| 559 | 523 | * |
| 560 | 524 | * @param FrmFieldValue $field_value |
| 561 | - * @param string $content | |
| 525 | + * @param string $content | |
| 562 | 526 | */ |
| 563 | 527 | protected function add_field_value_to_content( $field_value, &$content ) { |
| 564 | 528 | if ( $this->is_extra_field( $field_value ) ) { |
| 565 | 529 | $this->add_row_for_extra_field( $field_value, $content ); |
| @@ -574,9 +538,9 @@ | ||
| 574 | 538 | * |
| 575 | 539 | * @since 3.0 |
| 576 | 540 | * |
| 577 | 541 | * @param FrmFieldValue $field_value |
| 578 | - * @param string $content | |
| 542 | + * @param string $content | |
| 579 | 543 | */ |
| 580 | 544 | protected function add_row_for_extra_field( $field_value, &$content ) { |
| 581 | 545 | if ( ! $this->include_field_in_content( $field_value ) ) { |
| 582 | 546 | return; |
| @@ -594,9 +558,9 @@ | ||
| 594 | 558 | * |
| 595 | 559 | * @since 3.0 |
| 596 | 560 | * |
| 597 | 561 | * @param FrmFieldValue $field_value |
| 598 | - * @param string $content | |
| 562 | + * @param string $content | |
| 599 | 563 | */ |
| 600 | 564 | protected function add_row_for_standard_field( $field_value, &$content ) { |
| 601 | 565 | if ( ! $this->include_field_in_content( $field_value ) ) { |
| 602 | 566 | return; |
| @@ -615,9 +579,9 @@ | ||
| 615 | 579 | * |
| 616 | 580 | * @since 3.0 |
| 617 | 581 | * |
| 618 | 582 | * @param FrmFieldValue $field_value |
| 619 | - * @param string $content | |
| 583 | + * @param string $content | |
| 620 | 584 | */ |
| 621 | 585 | protected function add_html_row_for_included_extra( $field_value, &$content ) { |
| 622 | 586 | $this->prepare_html_display_value_for_extra_fields( $field_value, $display_value ); |
| 623 | 587 | |
| @@ -634,9 +598,9 @@ | ||
| 634 | 598 | * |
| 635 | 599 | * @since 3.0 |
| 636 | 600 | * |
| 637 | 601 | * @param FrmFieldValue $field_value |
| 638 | - * @param string $content | |
| 602 | + * @param string $content | |
| 639 | 603 | */ |
| 640 | 604 | protected function add_plain_text_row_for_included_extra( $field_value, &$content ) { |
| 641 | 605 | $this->prepare_plain_text_display_value_for_extra_fields( $field_value, $display_value ); |
| 642 | 606 | |
| @@ -679,9 +643,9 @@ | ||
| 679 | 643 | * |
| 680 | 644 | * @since 3.0 |
| 681 | 645 | * |
| 682 | 646 | * @param FrmFieldValue $field_value |
| 683 | - * @param mixed $display_value | |
| 647 | + * @param mixed $display_value | |
| 684 | 648 | */ |
| 685 | 649 | protected function prepare_html_display_value_for_extra_fields( $field_value, &$display_value ) { |
| 686 | 650 | $display_value = $field_value->get_displayed_value(); |
| 687 | 651 | } |
| @@ -691,9 +655,9 @@ | ||
| 691 | 655 | * |
| 692 | 656 | * @since 3.0 |
| 693 | 657 | * |
| 694 | 658 | * @param FrmFieldValue $field_value |
| 695 | - * @param mixed $display_value | |
| 659 | + * @param mixed $display_value | |
| 696 | 660 | */ |
| 697 | 661 | protected function prepare_plain_text_display_value_for_extra_fields( $field_value, &$display_value ) { |
| 698 | 662 | $display_value = $field_value->get_displayed_value() . "\r\n"; |
| 699 | 663 | } |
| @@ -702,10 +666,10 @@ | ||
| 702 | 666 | * Add a standard row to plain text or html table content |
| 703 | 667 | * |
| 704 | 668 | * @since 2.04 |
| 705 | 669 | * |
| 706 | - * @param FrmFieldValue $field_value | |
| 707 | - * @param string $content | |
| 670 | + * @param FrmProFieldValue $field_value | |
| 671 | + * @param string $content | |
| 708 | 672 | */ |
| 709 | 673 | protected function add_standard_row( $field_value, &$content ) { |
| 710 | 674 | if ( $this->format === 'plain_text_block' ) { |
| 711 | 675 | $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content ); |
| @@ -822,9 +786,9 @@ | ||
| 822 | 786 | * Add a row in an HTML table |
| 823 | 787 | * |
| 824 | 788 | * @since 2.04 |
| 825 | 789 | * |
| 826 | - * @param array $value_args | |
| 790 | + * @param array $value_args | |
| 827 | 791 | * $value_args = [ |
| 828 | 792 | * 'label' => (string) The label. Required |
| 829 | 793 | * 'value' => (mixed) The value to add. Required |
| 830 | 794 | * 'field_type' => (string) The field type. Blank string if not a field. |
| @@ -854,9 +818,9 @@ | ||
| 854 | 818 | * Prepare a field's display value for an HTML table |
| 855 | 819 | * |
| 856 | 820 | * @since 2.04 |
| 857 | 821 | * |
| 858 | - * @param mixed $display_value | |
| 822 | + * @param mixed $display_value | |
| 859 | 823 | * @param string $field_type |
| 860 | 824 | * |
| 861 | 825 | * @return mixed|string |
| 862 | 826 | */ |
| @@ -875,9 +839,9 @@ | ||
| 875 | 839 | * @since 2.04 |
| 876 | 840 | * |
| 877 | 841 | * @param mixed $display_value |
| 878 | 842 | * |
| 879 | - * @return int|string | |
| 843 | + * @return string|int | |
| 880 | 844 | */ |
| 881 | 845 | protected function prepare_display_value_for_plain_text_content( $display_value ) { |
| 882 | 846 | $display_value = $this->flatten_array( $display_value ); |
| 883 | 847 | $display_value = $this->strip_html( $display_value ); |
| @@ -889,16 +853,15 @@ | ||
| 889 | 853 | * Flatten an array |
| 890 | 854 | * |
| 891 | 855 | * @since 2.04 |
| 892 | 856 | * |
| 893 | - * @param array|int|string $value | |
| 857 | + * @param array|string|int $value | |
| 894 | 858 | * |
| 895 | - * @return int|string | |
| 859 | + * @return string|int | |
| 896 | 860 | */ |
| 897 | 861 | protected function flatten_array( $value ) { |
| 898 | 862 | if ( is_array( $value ) ) { |
| 899 | - $separator = $this->atts['array_separator'] ?? ', '; | |
| 900 | - $value = implode( $separator, $value ); | |
| 863 | + $value = implode( ', ', $value ); | |
| 901 | 864 | } |
| 902 | 865 | |
| 903 | 866 | return $value; |
| 904 | 867 | } |