| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - die( 'You are not allowed to call this page directly.' ); | |
| 4 | -} | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | 4 | * @since 2.04 |
| 8 | 5 | */ |
| @@ -125,9 +122,9 @@ | ||
| 125 | 122 | * |
| 126 | 123 | * @param array $atts |
| 127 | 124 | */ |
| 128 | 125 | protected function init_entry( $atts ) { |
| 129 | - if ( isset( $atts['entry'] ) && is_object( $atts['entry'] ) ) { | |
| 126 | + if ( is_object( $atts['entry'] ) ) { | |
| 130 | 127 | |
| 131 | 128 | if ( isset( $atts['entry']->metas ) ) { |
| 132 | 129 | $this->entry = $atts['entry']; |
| 133 | 130 | } else { |
| @@ -132,9 +129,9 @@ | ||
| 132 | 129 | $this->entry = $atts['entry']; |
| 133 | 130 | } else { |
| 134 | 131 | $this->entry = FrmEntry::getOne( $atts['entry']->id, true ); |
| 135 | 132 | } |
| 136 | - } elseif ( ! empty( $atts['id'] ) ) { | |
| 133 | + } else if ( $atts['id'] ) { | |
| 137 | 134 | $this->entry = FrmEntry::getOne( $atts['id'], true ); |
| 138 | 135 | } |
| 139 | 136 | } |
| 140 | 137 | |
| @@ -145,9 +142,9 @@ | ||
| 145 | 142 | * |
| 146 | 143 | * @param array $atts |
| 147 | 144 | */ |
| 148 | 145 | protected function init_entry_values( $atts ) { |
| 149 | - $entry_atts = $this->prepare_entry_attributes( $atts ); | |
| 146 | + $entry_atts = $this->prepare_entry_attributes( $atts ); | |
| 150 | 147 | $this->entry_values = new FrmEntryValues( $this->entry->id, $entry_atts ); |
| 151 | 148 | } |
| 152 | 149 | |
| 153 | 150 | /** |
| @@ -161,9 +158,9 @@ | ||
| 161 | 158 | */ |
| 162 | 159 | protected function prepare_entry_attributes( $atts ) { |
| 163 | 160 | $entry_atts = array(); |
| 164 | 161 | |
| 165 | - $conditionally_add = array( 'include_fields', 'fields', 'exclude_fields', 'entry' ); | |
| 162 | + $conditionally_add = array( 'include_fields', 'fields', 'exclude_fields' ); | |
| 166 | 163 | foreach ( $conditionally_add as $index ) { |
| 167 | 164 | if ( isset( $atts[ $index ] ) ) { |
| 168 | 165 | $entry_atts[ $index ] = $atts[ $index ]; |
| 169 | 166 | } |
| @@ -183,13 +180,13 @@ | ||
| 183 | 180 | if ( $atts['format'] === 'array' ) { |
| 184 | 181 | |
| 185 | 182 | $this->format = 'array'; |
| 186 | 183 | |
| 187 | - } elseif ( $atts['format'] === 'json' ) { | |
| 184 | + } else if ( $atts['format'] === 'json' ) { | |
| 188 | 185 | |
| 189 | 186 | $this->format = 'json'; |
| 190 | 187 | |
| 191 | - } elseif ( $atts['format'] === 'text' ) { | |
| 188 | + } else if ( $atts['format'] === 'text' ) { | |
| 192 | 189 | |
| 193 | 190 | if ( $this->is_plain_text === true ) { |
| 194 | 191 | $this->format = 'plain_text_block'; |
| 195 | 192 | } else { |
| @@ -195,25 +192,8 @@ | ||
| 195 | 192 | } else { |
| 196 | 193 | $this->format = 'table'; |
| 197 | 194 | } |
| 198 | 195 | } |
| 199 | - | |
| 200 | - /** | |
| 201 | - * Allows modifying the format property of FrmEntryFormatter object. | |
| 202 | - * | |
| 203 | - * @since 5.0.16 | |
| 204 | - * | |
| 205 | - * @param string $format The format. | |
| 206 | - * @param array $args Includes `atts`, `entry`. | |
| 207 | - */ | |
| 208 | - $this->format = apply_filters( | |
| 209 | - 'frm_entry_formatter_format', | |
| 210 | - $this->format, | |
| 211 | - array( | |
| 212 | - 'atts' => $atts, | |
| 213 | - 'entry' => $this->entry, | |
| 214 | - ) | |
| 215 | - ); | |
| 216 | 196 | } |
| 217 | 197 | |
| 218 | 198 | /** |
| 219 | 199 | * Set the array_key property that sets whether the keys in the |
| @@ -238,9 +218,9 @@ | ||
| 238 | 218 | */ |
| 239 | 219 | protected function init_is_plain_text( $atts ) { |
| 240 | 220 | if ( isset( $atts['plain_text'] ) && $atts['plain_text'] ) { |
| 241 | 221 | $this->is_plain_text = true; |
| 242 | - } elseif ( $atts['format'] !== 'text' ) { | |
| 222 | + } else if ( $atts['format'] !== 'text' ) { | |
| 243 | 223 | $this->is_plain_text = true; |
| 244 | 224 | } |
| 245 | 225 | } |
| 246 | 226 | |
| @@ -344,13 +324,13 @@ | ||
| 344 | 324 | * |
| 345 | 325 | * @since 3.0 |
| 346 | 326 | */ |
| 347 | 327 | protected function init_atts( $atts ) { |
| 348 | - $atts['source'] = 'entry_formatter'; | |
| 349 | - $atts['wpautop'] = false; | |
| 328 | + $atts['source'] = 'entry_formatter'; | |
| 329 | + $atts['wpautop'] = false; | |
| 350 | 330 | $atts['return_array'] = true; |
| 351 | 331 | |
| 352 | - $unset = array( 'id', 'entry', 'form_id', 'format' ); | |
| 332 | + $unset = array( 'id', 'entry', 'form_id', 'format', 'plain_text' ); | |
| 353 | 333 | foreach ( $unset as $param ) { |
| 354 | 334 | if ( isset( $atts[ $param ] ) ) { |
| 355 | 335 | unset( $atts[ $param ] ); |
| 356 | 336 | } |
| @@ -386,15 +366,15 @@ | ||
| 386 | 366 | |
| 387 | 367 | if ( $this->format === 'json' ) { |
| 388 | 368 | $content = json_encode( $this->prepare_array() ); |
| 389 | 369 | |
| 390 | - } elseif ( $this->format === 'array' ) { | |
| 370 | + } else if ( $this->format === 'array' ) { | |
| 391 | 371 | $content = $this->prepare_array(); |
| 392 | 372 | |
| 393 | - } elseif ( $this->format === 'table' ) { | |
| 373 | + } else if ( $this->format === 'table' ) { | |
| 394 | 374 | $content = $this->prepare_html_table(); |
| 395 | 375 | |
| 396 | - } elseif ( $this->format === 'plain_text_block' ) { | |
| 376 | + } else if ( $this->format === 'plain_text_block' ) { | |
| 397 | 377 | $content = $this->prepare_plain_text_block(); |
| 398 | 378 | |
| 399 | 379 | } else { |
| 400 | 380 | $content = ''; |
| @@ -399,26 +379,9 @@ | ||
| 399 | 379 | } else { |
| 400 | 380 | $content = ''; |
| 401 | 381 | } |
| 402 | 382 | |
| 403 | - /** | |
| 404 | - * Allows modifying the formatted entry values content. | |
| 405 | - * | |
| 406 | - * @since 5.0.16 | |
| 407 | - * | |
| 408 | - * @param string $content The formatted entry values content. | |
| 409 | - * @param array $args Includes `entry`, `atts`, `format`, `entry_values`. | |
| 410 | - */ | |
| 411 | - return apply_filters( | |
| 412 | - 'frm_formatted_entry_values_content', | |
| 413 | - $content, | |
| 414 | - array( | |
| 415 | - 'entry' => $this->entry, | |
| 416 | - 'atts' => $this->atts, | |
| 417 | - 'format' => $this->format, | |
| 418 | - 'entry_values' => $this->entry_values, | |
| 419 | - ) | |
| 420 | - ); | |
| 383 | + return $content; | |
| 421 | 384 | } |
| 422 | 385 | |
| 423 | 386 | /** |
| 424 | 387 | * Return the formatted HTML table with entry values |
| @@ -520,9 +483,8 @@ | ||
| 520 | 483 | protected function push_single_field_to_array( $field_value, &$output ) { |
| 521 | 484 | if ( $this->include_field_in_content( $field_value ) ) { |
| 522 | 485 | |
| 523 | 486 | $displayed_value = $this->prepare_display_value_for_array( $field_value->get_displayed_value() ); |
| 524 | - | |
| 525 | 487 | $output[ $this->get_key_or_id( $field_value ) ] = $displayed_value; |
| 526 | 488 | |
| 527 | 489 | $has_separate_value = (bool) $field_value->get_field_option( 'separate_value' ); |
| 528 | 490 | if ( $has_separate_value || $displayed_value !== $field_value->get_saved_value() ) { |
| @@ -543,11 +505,11 @@ | ||
| 543 | 505 | protected function add_plain_text_row( $label, $display_value, &$content ) { |
| 544 | 506 | $display_value = $this->prepare_display_value_for_plain_text_content( $display_value ); |
| 545 | 507 | |
| 546 | 508 | if ( 'rtl' == $this->direction ) { |
| 547 | - $content .= wp_kses_post( $display_value . ' :' . $label ) . "\r\n"; | |
| 509 | + $content .= $display_value . ' :' . $label . "\r\n"; | |
| 548 | 510 | } else { |
| 549 | - $content .= wp_kses_post( $label . ': ' . $display_value ) . "\r\n"; | |
| 511 | + $content .= $label . ': ' . $display_value . "\r\n"; | |
| 550 | 512 | } |
| 551 | 513 | } |
| 552 | 514 | |
| 553 | 515 | /** |
| @@ -581,9 +543,9 @@ | ||
| 581 | 543 | } |
| 582 | 544 | |
| 583 | 545 | if ( $this->format === 'plain_text_block' ) { |
| 584 | 546 | $this->add_plain_text_row_for_included_extra( $field_value, $content ); |
| 585 | - } elseif ( $this->format === 'table' ) { | |
| 547 | + } else if ( $this->format === 'table' ) { | |
| 586 | 548 | $this->add_html_row_for_included_extra( $field_value, $content ); |
| 587 | 549 | } |
| 588 | 550 | } |
| 589 | 551 | |
| @@ -601,9 +563,9 @@ | ||
| 601 | 563 | } |
| 602 | 564 | |
| 603 | 565 | if ( $this->format === 'plain_text_block' ) { |
| 604 | 566 | $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content ); |
| 605 | - } elseif ( $this->format === 'table' ) { | |
| 567 | + } else if ( $this->format === 'table' ) { | |
| 606 | 568 | $value_args = $this->package_value_args( $field_value ); |
| 607 | 569 | $this->add_html_row( $value_args, $content ); |
| 608 | 570 | } |
| 609 | 571 | } |
| @@ -700,15 +662,15 @@ | ||
| 700 | 662 | * Add a standard row to plain text or html table content |
| 701 | 663 | * |
| 702 | 664 | * @since 2.04 |
| 703 | 665 | * |
| 704 | - * @param FrmFieldValue $field_value | |
| 666 | + * @param FrmProFieldValue $field_value | |
| 705 | 667 | * @param string $content |
| 706 | 668 | */ |
| 707 | 669 | protected function add_standard_row( $field_value, &$content ) { |
| 708 | 670 | if ( $this->format === 'plain_text_block' ) { |
| 709 | 671 | $this->add_plain_text_row( $field_value->get_field_label(), $field_value->get_displayed_value(), $content ); |
| 710 | - } elseif ( $this->format === 'table' ) { | |
| 672 | + } else if ( $this->format === 'table' ) { | |
| 711 | 673 | $value_args = $this->package_value_args( $field_value ); |
| 712 | 674 | $this->add_html_row( $value_args, $content ); |
| 713 | 675 | } |
| 714 | 676 | } |
| @@ -723,11 +685,11 @@ | ||
| 723 | 685 | * @return array |
| 724 | 686 | */ |
| 725 | 687 | protected function package_value_args( $field_value ) { |
| 726 | 688 | return array( |
| 727 | - 'label' => $field_value->get_field_label(), | |
| 728 | - 'value' => $field_value->get_displayed_value(), | |
| 729 | - 'field_type' => $field_value->get_field_type(), | |
| 689 | + 'label' => $field_value->get_field_label(), | |
| 690 | + 'value' => $field_value->get_displayed_value(), | |
| 691 | + 'field_type' => $field_value->get_field_type(), | |
| 730 | 692 | ); |
| 731 | 693 | } |
| 732 | 694 | |
| 733 | 695 | /** |
| @@ -742,11 +704,11 @@ | ||
| 742 | 704 | |
| 743 | 705 | foreach ( $this->entry_values->get_user_info() as $user_info ) { |
| 744 | 706 | |
| 745 | 707 | $value_args = array( |
| 746 | - 'label' => $user_info['label'], | |
| 747 | - 'value' => $user_info['value'], | |
| 748 | - 'field_type' => 'none', | |
| 708 | + 'label' => $user_info['label'], | |
| 709 | + 'value' => $user_info['value'], | |
| 710 | + 'field_type' => 'none', | |
| 749 | 711 | ); |
| 750 | 712 | |
| 751 | 713 | $this->add_html_row( $value_args, $content ); |
| 752 | 714 | } |
| @@ -847,8 +809,9 @@ | ||
| 847 | 809 | protected function prepare_display_value_for_array( $value ) { |
| 848 | 810 | return $this->strip_html( $value ); |
| 849 | 811 | } |
| 850 | 812 | |
| 813 | + | |
| 851 | 814 | /** |
| 852 | 815 | * Prepare a field's display value for an HTML table |
| 853 | 816 | * |
| 854 | 817 | * @since 2.04 |
| @@ -859,11 +822,9 @@ | ||
| 859 | 822 | * @return mixed|string |
| 860 | 823 | */ |
| 861 | 824 | protected function prepare_display_value_for_html_table( $display_value, $field_type = '' ) { |
| 862 | 825 | $display_value = $this->flatten_array( $display_value ); |
| 863 | - if ( ! isset( $this->atts['line_breaks'] ) || ! empty( $this->atts['line_breaks'] ) ) { | |
| 864 | - $display_value = str_replace( array( "\r\n", "\n" ), '<br/>', $display_value ); | |
| 865 | - } | |
| 826 | + $display_value = str_replace( array( "\r\n", "\n" ), '<br/>', $display_value ); | |
| 866 | 827 | |
| 867 | 828 | return $display_value; |
| 868 | 829 | } |
| 869 | 830 | |
| @@ -893,10 +854,9 @@ | ||
| 893 | 854 | * @return string|int |
| 894 | 855 | */ |
| 895 | 856 | protected function flatten_array( $value ) { |
| 896 | 857 | if ( is_array( $value ) ) { |
| 897 | - $separator = isset( $this->atts['array_separator'] ) ? $this->atts['array_separator'] : ', '; | |
| 898 | - $value = implode( $separator, $value ); | |
| 858 | + $value = implode( ', ', $value ); | |
| 899 | 859 | } |
| 900 | 860 | |
| 901 | 861 | return $value; |
| 902 | 862 | } |
| @@ -917,9 +877,9 @@ | ||
| 917 | 877 | if ( is_array( $value ) ) { |
| 918 | 878 | foreach ( $value as $key => $single_value ) { |
| 919 | 879 | $value[ $key ] = $this->strip_html( $single_value ); |
| 920 | 880 | } |
| 921 | - } elseif ( $this->is_plain_text && ! is_array( $value ) ) { | |
| 881 | + } else if ( $this->is_plain_text && ! is_array( $value ) ) { | |
| 922 | 882 | if ( strpos( $value, '<img' ) !== false ) { |
| 923 | 883 | $value = str_replace( array( '<img', 'src=', '/>', '"' ), '', $value ); |
| 924 | 884 | $value = trim( $value ); |
| 925 | 885 | } |