| @@ -10,9 +10,9 @@ | ||
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * @since 2.04 |
| 13 | 13 | * |
| 14 | - * @var stdClass|null | |
| 14 | + * @var false|stdClass|null | |
| 15 | 15 | */ |
| 16 | 16 | protected $entry; |
| 17 | 17 | |
| 18 | 18 | /** |
| @@ -141,14 +141,9 @@ | ||
| 141 | 141 | * @return void |
| 142 | 142 | */ |
| 143 | 143 | protected function init_entry( $atts ) { |
| 144 | 144 | if ( isset( $atts['entry'] ) && is_object( $atts['entry'] ) ) { |
| 145 | - | |
| 146 | - if ( isset( $atts['entry']->metas ) ) { | |
| 147 | - $this->entry = $atts['entry']; | |
| 148 | - } else { | |
| 149 | - $this->entry = FrmEntry::getOne( $atts['entry']->id, true ); | |
| 150 | - } | |
| 145 | + $this->entry = isset( $atts['entry']->metas ) ? $atts['entry'] : FrmEntry::getOne( $atts['entry']->id, true ); | |
| 151 | 146 | } elseif ( ! empty( $atts['id'] ) ) { |
| 152 | 147 | $this->entry = FrmEntry::getOne( $atts['id'], true ); |
| 153 | 148 | } |
| 154 | 149 | } |
| @@ -176,10 +171,9 @@ | ||
| 176 | 171 | * |
| 177 | 172 | * @return array |
| 178 | 173 | */ |
| 179 | 174 | protected function prepare_entry_attributes( $atts ) { |
| 180 | - $entry_atts = array(); | |
| 181 | - | |
| 175 | + $entry_atts = array(); | |
| 182 | 176 | $conditionally_add = array( 'include_fields', 'fields', 'exclude_fields', 'entry' ); |
| 183 | 177 | |
| 184 | 178 | foreach ( $conditionally_add as $index ) { |
| 185 | 179 | if ( isset( $atts[ $index ] ) ) { |
| @@ -204,13 +198,9 @@ | ||
| 204 | 198 | $this->format = 'array'; |
| 205 | 199 | } elseif ( $atts['format'] === 'json' ) { |
| 206 | 200 | $this->format = 'json'; |
| 207 | 201 | } elseif ( $atts['format'] === 'text' ) { |
| 208 | - if ( $this->is_plain_text === true ) { | |
| 209 | - $this->format = 'plain_text_block'; | |
| 210 | - } else { | |
| 211 | - $this->format = 'table'; | |
| 212 | - } | |
| 202 | + $this->format = $this->is_plain_text === true ? 'plain_text_block' : 'table'; | |
| 213 | 203 | } |
| 214 | 204 | |
| 215 | 205 | /** |
| 216 | 206 | * Allows modifying the format property of FrmEntryFormatter object. |
| @@ -255,9 +245,9 @@ | ||
| 255 | 245 | * |
| 256 | 246 | * @return void |
| 257 | 247 | */ |
| 258 | 248 | protected function init_is_plain_text( $atts ) { |
| 259 | - if ( isset( $atts['plain_text'] ) && $atts['plain_text'] ) { | |
| 249 | + if ( ! empty( $atts['plain_text'] ) ) { | |
| 260 | 250 | $this->is_plain_text = true; |
| 261 | 251 | } elseif ( $atts['format'] !== 'text' ) { |
| 262 | 252 | $this->is_plain_text = true; |
| 263 | 253 | } |
| @@ -272,9 +262,9 @@ | ||
| 272 | 262 | * |
| 273 | 263 | * @return void |
| 274 | 264 | */ |
| 275 | 265 | protected function init_include_blank( $atts ) { |
| 276 | - if ( isset( $atts['include_blank'] ) && $atts['include_blank'] ) { | |
| 266 | + if ( ! empty( $atts['include_blank'] ) ) { | |
| 277 | 267 | $this->include_blank = true; |
| 278 | 268 | } |
| 279 | 269 | } |
| 280 | 270 | |
| @@ -302,9 +292,9 @@ | ||
| 302 | 292 | * |
| 303 | 293 | * @return void |
| 304 | 294 | */ |
| 305 | 295 | protected function init_include_user_info( $atts ) { |
| 306 | - if ( isset( $atts['user_info'] ) && $atts['user_info'] ) { | |
| 296 | + if ( ! empty( $atts['user_info'] ) ) { | |
| 307 | 297 | $this->include_user_info = true; |
| 308 | 298 | } |
| 309 | 299 | } |
| 310 | 300 | |
| @@ -328,9 +318,9 @@ | ||
| 328 | 318 | * |
| 329 | 319 | * @return void |
| 330 | 320 | */ |
| 331 | 321 | protected function init_include_extras( $atts ) { |
| 332 | - if ( isset( $atts['include_extras'] ) && $atts['include_extras'] ) { | |
| 322 | + if ( ! empty( $atts['include_extras'] ) ) { | |
| 333 | 323 | $this->include_extras = array_map( 'strtolower', array_map( 'trim', explode( ',', $atts['include_extras'] ) ) ); |
| 334 | 324 | } |
| 335 | 325 | } |
| 336 | 326 | |
| @@ -367,9 +357,9 @@ | ||
| 367 | 357 | * |
| 368 | 358 | * @return void |
| 369 | 359 | */ |
| 370 | 360 | protected function init_is_clickable( $atts ) { |
| 371 | - if ( isset( $atts['clickable'] ) && $atts['clickable'] ) { | |
| 361 | + if ( ! empty( $atts['clickable'] ) ) { | |
| 372 | 362 | $this->is_clickable = true; |
| 373 | 363 | } |
| 374 | 364 | } |
| 375 | 365 | |
| @@ -426,18 +416,14 @@ | ||
| 426 | 416 | } |
| 427 | 417 | |
| 428 | 418 | if ( $this->format === 'json' ) { |
| 429 | 419 | $content = json_encode( $this->prepare_array() ); |
| 430 | - | |
| 431 | 420 | } elseif ( $this->format === 'array' ) { |
| 432 | 421 | $content = $this->prepare_array(); |
| 433 | - | |
| 434 | 422 | } elseif ( $this->format === 'table' ) { |
| 435 | 423 | $content = $this->prepare_html_table(); |
| 436 | - | |
| 437 | 424 | } elseif ( $this->format === 'plain_text_block' ) { |
| 438 | 425 | $content = $this->prepare_plain_text_block(); |
| 439 | - | |
| 440 | 426 | } else { |
| 441 | 427 | $content = ''; |
| 442 | 428 | } |
| 443 | 429 | |
| @@ -475,13 +461,9 @@ | ||
| 475 | 461 | $this->add_user_info_to_html_table( $content ); |
| 476 | 462 | |
| 477 | 463 | $content .= $this->table_generator->generate_table_footer(); |
| 478 | 464 | |
| 479 | - if ( $this->is_clickable ) { | |
| 480 | - $content = make_clickable( $content ); | |
| 481 | - } | |
| 482 | - | |
| 483 | - return $content; | |
| 465 | + return $this->is_clickable ? make_clickable( $content ) : $content; | |
| 484 | 466 | } |
| 485 | 467 | |
| 486 | 468 | /** |
| 487 | 469 | * Add field values to table or plain text content |
| @@ -563,19 +545,18 @@ | ||
| 563 | 545 | * |
| 564 | 546 | * @return void |
| 565 | 547 | */ |
| 566 | 548 | protected function push_single_field_to_array( $field_value, &$output ) { |
| 567 | - if ( $this->include_field_in_content( $field_value ) ) { | |
| 549 | + if ( ! $this->include_field_in_content( $field_value ) ) { | |
| 550 | + return; | |
| 551 | + } | |
| 568 | 552 | |
| 569 | - $displayed_value = $this->prepare_display_value_for_array( $field_value->get_displayed_value() ); | |
| 553 | + $displayed_value = $this->prepare_display_value_for_array( $field_value->get_displayed_value() ); | |
| 554 | + $output[ $this->get_key_or_id( $field_value ) ] = $displayed_value; | |
| 555 | + $has_separate_value = (bool) $field_value->get_field_option( 'separate_value' ); | |
| 570 | 556 | |
| 571 | - $output[ $this->get_key_or_id( $field_value ) ] = $displayed_value; | |
| 572 | - | |
| 573 | - $has_separate_value = (bool) $field_value->get_field_option( 'separate_value' ); | |
| 574 | - | |
| 575 | - if ( $has_separate_value || $displayed_value !== $field_value->get_saved_value() ) { | |
| 576 | - $output[ $this->get_key_or_id( $field_value ) . '-value' ] = $field_value->get_saved_value(); | |
| 577 | - } | |
| 557 | + if ( $has_separate_value || $displayed_value !== $field_value->get_saved_value() ) { | |
| 558 | + $output[ $this->get_key_or_id( $field_value ) . '-value' ] = $field_value->get_saved_value(); | |
| 578 | 559 | } |
| 579 | 560 | } |
| 580 | 561 | |
| 581 | 562 | /** |
| @@ -611,9 +592,8 @@ | ||
| 611 | 592 | */ |
| 612 | 593 | protected function add_field_value_to_content( $field_value, &$content ) { |
| 613 | 594 | if ( $this->is_extra_field( $field_value ) ) { |
| 614 | 595 | $this->add_row_for_extra_field( $field_value, $content ); |
| 615 | - | |
| 616 | 596 | } else { |
| 617 | 597 | $this->add_row_for_standard_field( $field_value, $content ); |
| 618 | 598 | } |
| 619 | 599 | } |
| @@ -675,9 +655,9 @@ | ||
| 675 | 655 | */ |
| 676 | 656 | protected function add_html_row_for_included_extra( $field_value, &$content ) { |
| 677 | 657 | $this->prepare_html_display_value_for_extra_fields( $field_value, $display_value ); |
| 678 | 658 | |
| 679 | - if ( in_array( $field_value->get_field_type(), $this->single_cell_fields ) ) { | |
| 659 | + if ( in_array( $field_value->get_field_type(), $this->single_cell_fields, true ) ) { | |
| 680 | 660 | $this->add_single_cell_html_row( $display_value, $content ); |
| 681 | 661 | } else { |
| 682 | 662 | $value_args = $this->package_value_args( $field_value ); |
| 683 | 663 | $this->add_html_row( $value_args, $content ); |
| @@ -696,9 +676,9 @@ | ||
| 696 | 676 | */ |
| 697 | 677 | protected function add_plain_text_row_for_included_extra( $field_value, &$content ) { |
| 698 | 678 | $this->prepare_plain_text_display_value_for_extra_fields( $field_value, $display_value ); |
| 699 | 679 | |
| 700 | - if ( in_array( $field_value->get_field_type(), $this->single_cell_fields ) ) { | |
| 680 | + if ( in_array( $field_value->get_field_type(), $this->single_cell_fields, true ) ) { | |
| 701 | 681 | $this->add_single_value_plain_text_row( $display_value, $content ); |
| 702 | 682 | } else { |
| 703 | 683 | $this->add_plain_text_row( $field_value->get_field_label(), $display_value, $content ); |
| 704 | 684 | } |
| @@ -808,18 +788,20 @@ | ||
| 808 | 788 | * |
| 809 | 789 | * @return void |
| 810 | 790 | */ |
| 811 | 791 | protected function add_user_info_to_html_table( &$content ) { |
| 812 | - if ( $this->include_user_info ) { | |
| 813 | - foreach ( $this->entry_values->get_user_info() as $user_info ) { | |
| 814 | - $value_args = array( | |
| 815 | - 'label' => $user_info['label'], | |
| 816 | - 'value' => $user_info['value'], | |
| 817 | - 'field_type' => 'none', | |
| 818 | - ); | |
| 792 | + if ( ! $this->include_user_info ) { | |
| 793 | + return; | |
| 794 | + } | |
| 819 | 795 | |
| 820 | - $this->add_html_row( $value_args, $content ); | |
| 821 | - } | |
| 796 | + foreach ( $this->entry_values->get_user_info() as $user_info ) { | |
| 797 | + $value_args = array( | |
| 798 | + 'label' => $user_info['label'], | |
| 799 | + 'value' => $user_info['value'], | |
| 800 | + 'field_type' => 'none', | |
| 801 | + ); | |
| 802 | + | |
| 803 | + $this->add_html_row( $value_args, $content ); | |
| 822 | 804 | } |
| 823 | 805 | } |
| 824 | 806 | |
| 825 | 807 | /** |
| @@ -831,13 +813,14 @@ | ||
| 831 | 813 | * |
| 832 | 814 | * @return void |
| 833 | 815 | */ |
| 834 | 816 | protected function add_user_info_to_plain_text_content( &$content ) { |
| 835 | - if ( $this->include_user_info ) { | |
| 817 | + if ( ! $this->include_user_info ) { | |
| 818 | + return; | |
| 819 | + } | |
| 836 | 820 | |
| 837 | - foreach ( $this->entry_values->get_user_info() as $user_info ) { | |
| 838 | - $this->add_plain_text_row( $user_info['label'], $user_info['value'], $content ); | |
| 839 | - } | |
| 821 | + foreach ( $this->entry_values->get_user_info() as $user_info ) { | |
| 822 | + $this->add_plain_text_row( $user_info['label'], $user_info['value'], $content ); | |
| 840 | 823 | } |
| 841 | 824 | } |
| 842 | 825 | |
| 843 | 826 | /** |
| @@ -870,9 +853,9 @@ | ||
| 870 | 853 | * |
| 871 | 854 | * @return bool |
| 872 | 855 | */ |
| 873 | 856 | protected function is_extra_field( $field_value ) { |
| 874 | - return in_array( $field_value->get_field_type(), $this->skip_fields() ); | |
| 857 | + return in_array( $field_value->get_field_type(), $this->skip_fields(), true ); | |
| 875 | 858 | } |
| 876 | 859 | |
| 877 | 860 | /** |
| 878 | 861 | * Check if an extra field is included |
| @@ -883,9 +866,9 @@ | ||
| 883 | 866 | * |
| 884 | 867 | * @return bool |
| 885 | 868 | */ |
| 886 | 869 | protected function is_extra_field_included( $field_value ) { |
| 887 | - return in_array( $field_value->get_field_type(), $this->include_extras ); | |
| 870 | + return in_array( $field_value->get_field_type(), $this->include_extras, true ); | |
| 888 | 871 | } |
| 889 | 872 | |
| 890 | 873 | /** |
| 891 | 874 | * Add a row in an HTML table |
| @@ -938,9 +921,9 @@ | ||
| 938 | 921 | protected function prepare_display_value_for_html_table( $display_value, $field_type = '' ) { |
| 939 | 922 | $display_value = $this->flatten_array( $display_value ); |
| 940 | 923 | |
| 941 | 924 | if ( ! isset( $this->atts['line_breaks'] ) || ! empty( $this->atts['line_breaks'] ) ) { |
| 942 | - $display_value = str_replace( array( "\r\n", "\n" ), '<br/>', $display_value ); | |
| 925 | + return str_replace( array( "\r\n", "\n" ), '<br/>', $display_value ); | |
| 943 | 926 | } |
| 944 | 927 | |
| 945 | 928 | return $display_value; |
| 946 | 929 | } |
| @@ -955,11 +938,9 @@ | ||
| 955 | 938 | * @return int|string |
| 956 | 939 | */ |
| 957 | 940 | protected function prepare_display_value_for_plain_text_content( $display_value ) { |
| 958 | 941 | $display_value = $this->flatten_array( $display_value ); |
| 959 | - $display_value = $this->strip_html( $display_value ); | |
| 960 | - | |
| 961 | - return $display_value; | |
| 942 | + return $this->strip_html( $display_value ); | |
| 962 | 943 | } |
| 963 | 944 | |
| 964 | 945 | /** |
| 965 | 946 | * Flatten an array |
| @@ -988,21 +969,23 @@ | ||
| 988 | 969 | * |
| 989 | 970 | * @return mixed |
| 990 | 971 | */ |
| 991 | 972 | protected function strip_html( $value ) { |
| 992 | - if ( $this->is_plain_text ) { | |
| 993 | - if ( is_array( $value ) ) { | |
| 994 | - foreach ( $value as $key => $single_value ) { | |
| 995 | - $value[ $key ] = $this->strip_html( $single_value ); | |
| 996 | - } | |
| 997 | - } elseif ( $this->is_plain_text && ! is_array( $value ) ) { | |
| 998 | - if ( strpos( $value, '<img' ) !== false ) { | |
| 999 | - $value = str_replace( array( '<img', 'src=', '/>', '"' ), '', $value ); | |
| 1000 | - $value = trim( $value ); | |
| 1001 | - } | |
| 973 | + if ( ! $this->is_plain_text ) { | |
| 974 | + return $value; | |
| 975 | + } | |
| 1002 | 976 | |
| 1003 | - $value = strip_tags( $value ); | |
| 977 | + if ( is_array( $value ) ) { | |
| 978 | + foreach ( $value as $key => $single_value ) { | |
| 979 | + $value[ $key ] = $this->strip_html( $single_value ); | |
| 1004 | 980 | } |
| 981 | + } elseif ( $this->is_plain_text && ! is_array( $value ) ) { | |
| 982 | + if ( str_contains( $value, '<img' ) ) { | |
| 983 | + $value = str_replace( array( '<img', 'src=', '/>', '"' ), '', $value ); | |
| 984 | + $value = trim( $value ); | |
| 985 | + } | |
| 986 | + | |
| 987 | + $value = strip_tags( $value ); | |
| 1005 | 988 | } |
| 1006 | 989 | |
| 1007 | 990 | return $value; |
| 1008 | 991 | } |