Ticket #1989: 1989.patch
File 1989.patch, 17.8 KB (added by , 11 years ago) |
---|
-
includes/replies/template.php
661 661 function bbp_reply_revision_log( $reply_id = 0 ) { 662 662 echo bbp_get_reply_revision_log( $reply_id ); 663 663 } 664 /**665 * Return the formatted revision log of the reply666 *667 * @since bbPress (r2782)668 *669 * @param int $reply_id Optional. Reply id670 * @uses bbp_get_reply_id() To get the reply id671 * @uses bbp_get_reply_revisions() To get the reply revisions672 * @uses bbp_get_reply_raw_revision_log() To get the raw revision log673 * @uses bbp_get_reply_author_display_name() To get the reply author674 * @uses bbp_get_reply_author_link() To get the reply author link675 * @uses bbp_convert_date() To convert the date676 * @uses bbp_get_time_since() To get the time in since format677 * @uses apply_filters() Calls 'bbp_get_reply_revision_log' with the678 * log and reply id679 * @return string Revision log of the reply680 */681 function bbp_get_reply_revision_log( $reply_id = 0 ) {682 664 683 // Create necessary variables 684 $reply_id = bbp_get_reply_id( $reply_id ); 665 /** 666 * Return the formatted revision log of the reply 667 * 668 * @since bbPress (r2782) 669 * 670 * @param int $reply_id Optional. Reply id 671 * @uses bbp_get_reply_id() To get the reply id 672 * @uses bbp_get_reply_revisions() To get the reply revisions 673 * @uses bbp_get_reply_raw_revision_log() To get the raw revision log 674 * @uses bbp_get_reply_author_display_name() To get the reply author 675 * @uses bbp_get_reply_author_link() To get the reply author link 676 * @uses bbp_convert_date() To convert the date 677 * @uses bbp_get_time_since() To get the time in since format 678 * @uses apply_filters() Calls 'bbp_get_reply_revision_log' with the 679 * log and reply id 680 * @return string Revision log of the reply 681 */ 682 function bbp_get_reply_revision_log( $reply_id = 0 ) { 685 683 686 // Show the topic reply log if this is a topic in a reply loop 687 if ( bbp_is_topic( $reply_id ) ) { 688 return bbp_get_topic_revision_log( $reply_id ); 689 } 684 // Create necessary variables 685 $reply_id = bbp_get_reply_id( $reply_id ); 690 686 691 // Get the reply revision log (out of post meta 692 $revision_log = bbp_get_reply_raw_revision_log( $reply_id ); 687 // Show the topic reply log if this is a topic in a reply loop 688 if ( bbp_is_topic( $reply_id ) ) { 689 return bbp_get_topic_revision_log( $reply_id ); 690 } 693 691 694 // Check reply and revision log exist 695 if ( empty( $reply_id ) || empty( $revision_log ) || !is_array( $revision_log ) ) 696 return false; 692 // Get the reply revision log (out of post meta 693 $revision_log = bbp_get_reply_raw_revision_log( $reply_id ); 697 694 698 // Get the actual revisions 699 $revisions = bbp_get_reply_revisions( $reply_id ); 700 if ( empty( $revisions ) ) 701 return false; 695 // Check reply and revision log exist 696 if ( empty( $reply_id ) || empty( $revision_log ) || !is_array( $revision_log ) ) 697 return false; 702 698 703 $r = "\n\n" . '<ul id="bbp-reply-revision-log-' . esc_attr( $reply_id ) . '" class="bbp-reply-revision-log">' . "\n\n";699 // Get the actual revisions 704 700 705 // Loop through revisions706 foreach ( (array) $revisions as $revision ) {701 $total = $limit = - 1; 702 $order = 'ASC'; 707 703 708 if ( empty( $revision_log[$revision->ID] ) ) { 709 $author_id = $revision->post_author; 710 $reason = ''; 711 } else { 712 $author_id = $revision_log[$revision->ID]['author']; 713 $reason = $revision_log[$revision->ID]['reason']; 714 } 704 if ( empty( $_GET['bbp_reply_revisions_all'] ) || intval( $_GET['bbp_reply_revisions_all'] ) != $reply_id ) { 705 $total = bbp_get_reply_revision_count( $reply_id ); 706 $limit = (int) apply_filters( 'bbp_reply_revision_log_limit', 1 ); 707 $order = 'DESC'; 708 } 715 709 716 $author = bbp_get_author_link( array( 'size' => 14, 'link_text' => bbp_get_reply_author_display_name( $revision->ID ), 'post_id' => $revision->ID ) ); 717 $since = bbp_get_time_since( bbp_convert_date( $revision->post_modified ) ); 710 $revisions = bbp_get_reply_revisions( $reply_id, $limit, $order ); 718 711 719 $r .= "\t" . '<li id="bbp-reply-revision-log-' . esc_attr( $reply_id ) . '-item-' . esc_attr( $revision->ID ) . '" class="bbp-reply-revision-log-item">' . "\n"; 720 if ( !empty( $reason ) ) { 721 $r .= "\t\t" . sprintf( esc_html__( 'This reply was modified %1$s by %2$s. Reason: %3$s', 'bbpress' ), esc_html( $since ), $author, esc_html( $reason ) ) . "\n"; 722 } else { 723 $r .= "\t\t" . sprintf( esc_html__( 'This reply was modified %1$s by %2$s.', 'bbpress' ), esc_html( $since ), $author ) . "\n"; 724 } 725 $r .= "\t" . '</li>' . "\n"; 712 if ( empty( $revisions ) ) 713 return false; 726 714 715 $r = "\n\n" . '<ul id="bbp-reply-revision-log-' . esc_attr( $reply_id ) . '" class="bbp-reply-revision-log">' . "\n\n"; 716 717 // Loop through revisions 718 foreach ( (array) $revisions as $revision ) { 719 720 if ( empty( $revision_log[$revision->ID] ) ) { 721 $author_id = $revision->post_author; 722 $reason = ''; 723 } else { 724 $author_id = $revision_log[$revision->ID]['author']; 725 $reason = $revision_log[$revision->ID]['reason']; 727 726 } 728 727 729 $r .= "\n" . '</ul>' . "\n\n"; 728 $author = bbp_get_author_link( array( 'size' => 14, 'link_text' => bbp_get_reply_author_display_name( $revision->ID ), 'post_id' => $revision->ID ) ); 729 $since = bbp_get_time_since( bbp_convert_date( $revision->post_modified ) ); 730 730 731 return apply_filters( 'bbp_get_reply_revision_log', $r, $reply_id ); 731 $r .= "\t" . '<li id="bbp-reply-revision-log-' . esc_attr( $reply_id ) . '-item-' . esc_attr( $revision->ID ) . '" class="bbp-reply-revision-log-item">' . "\n"; 732 if ( !empty( $reason ) ) { 733 $r .= "\t\t" . sprintf( esc_html__( 'This reply was modified %1$s by %2$s. Reason: %3$s', 'bbpress' ), esc_html( $since ), $author, esc_html( $reason ) ) . "\n"; 734 } else { 735 $r .= "\t\t" . sprintf( esc_html__( 'This reply was modified %1$s by %2$s.', 'bbpress' ), esc_html( $since ), $author ) . "\n"; 736 } 737 $r .= "\t" . '</li>' . "\n"; 738 732 739 } 733 /**734 * Return the raw revision log of the reply735 *736 * @since bbPress (r2782)737 *738 * @param int $reply_id Optional. Reply id739 * @uses bbp_get_reply_id() To get the reply id740 * @uses get_post_meta() To get the revision log meta741 * @uses apply_filters() Calls 'bbp_get_reply_raw_revision_log'742 * with the log and reply id743 * @return string Raw revision log of the reply744 */745 function bbp_get_reply_raw_revision_log( $reply_id = 0 ) {746 $reply_id = bbp_get_reply_id( $reply_id );747 $revision_log = get_post_meta( $reply_id, '_bbp_revision_log', true );748 $revision_log = empty( $revision_log ) ? array() : $revision_log;749 740 750 return apply_filters( 'bbp_get_reply_raw_revision_log', $revision_log, $reply_id ); 751 } 741 // If there are more revisions to show 742 if ( $total > $limit ) { 743 $topic_id = bbp_get_reply_topic_id( $reply_id ); 744 $link_url = add_query_arg( 'bbp_reply_revisions_all', $reply_id, bbp_get_topic_permalink( $topic_id ) . '/#post-' . $reply_id ); 745 $link_text = esc_html__( sprintf( 'Show %d more', $total - $limit ) ); 752 746 747 $r .= sprintf( "<li class='bbp-reply-revision-log-more' data-id='%d'><a href='%s'>%s</a></li>", $reply_id, $link_url, $link_text ); 748 } 749 750 $r .= "\n" . '</ul>' . "\n\n"; 751 752 return apply_filters( 'bbp_get_reply_revision_log', $r, $reply_id ); 753 } 754 753 755 /** 754 * Return the r evisionsof the reply756 * Return the raw revision log of the reply 755 757 * 756 758 * @since bbPress (r2782) 757 759 * 758 760 * @param int $reply_id Optional. Reply id 759 761 * @uses bbp_get_reply_id() To get the reply id 760 * @uses wp_get_post_revisions() To get the reply revisions761 * @uses apply_filters() Calls 'bbp_get_reply_r evisions'762 * with the revisionsand reply id763 * @return string reply revisions762 * @uses get_post_meta() To get the revision log meta 763 * @uses apply_filters() Calls 'bbp_get_reply_raw_revision_log' 764 * with the log and reply id 765 * @return string Raw revision log of the reply 764 766 */ 765 function bbp_get_reply_revisions( $reply_id = 0 ) { 767 function bbp_get_reply_raw_revision_log( $reply_id = 0 ) { 768 $reply_id = bbp_get_reply_id( $reply_id ); 769 $revision_log = get_post_meta( $reply_id, '_bbp_revision_log', true ); 770 $revision_log = empty( $revision_log ) ? array() : $revision_log; 771 772 return apply_filters( 'bbp_get_reply_raw_revision_log', $revision_log, $reply_id ); 773 } 774 775 /** 776 * Return the revisions of the reply 777 * 778 * @since bbPress (r2782) 779 * 780 * @param int $reply_id Optional. Topic id 781 * @param int $count Optional. Amout of revisions to grab. 782 * @param string $order Optional. ASC/DESC Order of the results. 783 * 784 * @uses bbp_get_reply_id() To get the reply id 785 * @uses wp_get_post_revisions() To get the topic revisions 786 * @uses apply_filters() Calls 'bbp_get_reply_revisions' 787 * with the revisions and reply id 788 * 789 * @return string Reply revisions 790 */ 791 function bbp_get_reply_revisions( $reply_id = 0, $count = -1, $order = 'ASC' ) { 766 792 $reply_id = bbp_get_reply_id( $reply_id ); 767 $revisions = wp_get_post_revisions( $reply_id, array( 'order' => 'ASC') );793 $revisions = wp_get_post_revisions( $reply_id, array( 'order' => $order, 'posts_per_page' => $count ) ); 768 794 769 795 return apply_filters( 'bbp_get_reply_revisions', $revisions, $reply_id ); 770 796 } 771 797 798 772 799 /** 773 800 * Return the revision count of the reply 774 801 * -
includes/topics/template.php
885 885 function bbp_topic_revision_log( $topic_id = 0 ) { 886 886 echo bbp_get_topic_revision_log( $topic_id ); 887 887 } 888 /**889 * Return the formatted revision log of the topic890 *891 * @since bbPress (r2782)892 *893 * @param int $topic_id Optional. Topic id894 * @uses bbp_get_topic_id() To get the topic id895 * @uses bbp_get_topic_revisions() To get the topic revisions896 * @uses bbp_get_topic_raw_revision_log() To get the raw revision log897 * @uses bbp_get_topic_author_display_name() To get the topic author898 * @uses bbp_get_author_link() To get the topic author link899 * @uses bbp_convert_date() To convert the date900 * @uses bbp_get_time_since() To get the time in since format901 * @uses apply_filters() Calls 'bbp_get_topic_revision_log' with the902 * log and topic id903 * @return string Revision log of the topic904 */905 function bbp_get_topic_revision_log( $topic_id = 0 ) {906 // Create necessary variables907 $topic_id = bbp_get_topic_id( $topic_id );908 $revision_log = bbp_get_topic_raw_revision_log( $topic_id );909 888 910 if ( empty( $topic_id ) || empty( $revision_log ) || !is_array( $revision_log ) ) 911 return false; 889 /** 890 * Return the formatted revision log of the topic 891 * 892 * @since bbPress (r2782) 893 * 894 * @param int $topic_id Optional. Topic id 895 * @uses bbp_get_topic_id() To get the topic id 896 * @uses bbp_get_topic_revisions() To get the topic revisions 897 * @uses bbp_get_topic_raw_revision_log() To get the raw revision log 898 * @uses bbp_get_topic_author_display_name() To get the topic author 899 * @uses bbp_get_author_link() To get the topic author link 900 * @uses bbp_convert_date() To convert the date 901 * @uses bbp_get_time_since() To get the time in since format 902 * @uses apply_filters() Calls 'bbp_get_topic_revision_log' with the 903 * log and topic id 904 * @return string Revision log of the topic 905 */ 906 function bbp_get_topic_revision_log( $topic_id = 0 ) { 907 // Create necessary variables 908 $topic_id = bbp_get_topic_id( $topic_id ); 909 $revision_log = bbp_get_topic_raw_revision_log( $topic_id ); 912 910 913 $revisions = bbp_get_topic_revisions( $topic_id ); 914 if ( empty( $revisions ) ) 915 return false; 911 if ( empty( $topic_id ) || empty( $revision_log ) || !is_array( $revision_log ) ) 912 return false; 916 913 917 $r = "\n\n" . '<ul id="bbp-topic-revision-log-' . esc_attr( $topic_id ) . '" class="bbp-topic-revision-log">' . "\n\n"; 914 $total = $limit = - 1; 915 $order = 'ASC'; 918 916 919 // Loop through revisions 920 foreach ( (array) $revisions as $revision ) { 917 if ( empty( $_GET['bbp_topic_revisions_all'] ) || intval( $_GET['bbp_topic_revisions_all'] ) != $topic_id ) { 918 $total = bbp_get_topic_revision_count( $topic_id ); 919 $limit = (int) apply_filters( 'bbp_topic_revision_log_limit', 1 ); 920 $order = 'DESC'; 921 } 921 922 922 if ( empty( $revision_log[$revision->ID] ) ) { 923 $author_id = $revision->post_author; 924 $reason = ''; 925 } else { 926 $author_id = $revision_log[$revision->ID]['author']; 927 $reason = $revision_log[$revision->ID]['reason']; 928 } 923 $revisions = bbp_get_topic_revisions( $topic_id, $limit, $order ); 929 924 930 $author = bbp_get_author_link( array( 'size' => 14, 'link_text' => bbp_get_topic_author_display_name( $revision->ID ), 'post_id' => $revision->ID ) );931 $since = bbp_get_time_since( bbp_convert_date( $revision->post_modified ) );925 if ( empty( $revisions ) ) 926 return false; 932 927 933 $r .= "\t" . '<li id="bbp-topic-revision-log-' . esc_attr( $topic_id ) . '-item-' . esc_attr( $revision->ID ) . '" class="bbp-topic-revision-log-item">' . "\n"; 934 if ( !empty( $reason ) ) { 935 $r .= "\t\t" . sprintf( __( 'This topic was modified %1$s by %2$s. Reason: %3$s', 'bbpress' ), esc_html( $since ), $author, esc_html( $reason ) ) . "\n"; 936 } else { 937 $r .= "\t\t" . sprintf( __( 'This topic was modified %1$s by %2$s.', 'bbpress' ), esc_html( $since ), $author ) . "\n"; 938 } 939 $r .= "\t" . '</li>' . "\n"; 928 $r = "\n\n" . '<ul id="bbp-topic-revision-log-' . esc_attr( $topic_id ) . '" class="bbp-topic-revision-log">' . "\n\n"; 940 929 930 // Loop through revisions 931 foreach ( (array) $revisions as $revision ) { 932 933 if ( empty( $revision_log[$revision->ID] ) ) { 934 $author_id = $revision->post_author; 935 $reason = ''; 936 } else { 937 $author_id = $revision_log[$revision->ID]['author']; 938 $reason = $revision_log[$revision->ID]['reason']; 941 939 } 942 940 943 $r .= "\n" . '</ul>' . "\n\n"; 941 $author = bbp_get_author_link( array( 'size' => 14, 'link_text' => bbp_get_topic_author_display_name( $revision->ID ), 'post_id' => $revision->ID ) ); 942 $since = bbp_get_time_since( bbp_convert_date( $revision->post_modified ) ); 944 943 945 return apply_filters( 'bbp_get_topic_revision_log', $r, $topic_id ); 944 $r .= "\t" . '<li id="bbp-topic-revision-log-' . esc_attr( $topic_id ) . '-item-' . esc_attr( $revision->ID ) . '" class="bbp-topic-revision-log-item">' . "\n"; 945 if ( !empty( $reason ) ) { 946 $r .= "\t\t" . sprintf( __( 'This topic was modified %1$s by %2$s. Reason: %3$s', 'bbpress' ), esc_html( $since ), $author, esc_html( $reason ) ) . "\n"; 947 } else { 948 $r .= "\t\t" . sprintf( __( 'This topic was modified %1$s by %2$s.', 'bbpress' ), esc_html( $since ), $author ) . "\n"; 949 } 950 $r .= "\t" . '</li>' . "\n"; 951 946 952 } 947 /**948 * Return the raw revision log of the topic949 *950 * @since bbPress (r2782)951 *952 * @param int $topic_id Optional. Topic id953 * @uses bbp_get_topic_id() To get the topic id954 * @uses get_post_meta() To get the revision log meta955 * @uses apply_filters() Calls 'bbp_get_topic_raw_revision_log'956 * with the log and topic id957 * @return string Raw revision log of the topic958 */959 function bbp_get_topic_raw_revision_log( $topic_id = 0 ) {960 $topic_id = bbp_get_topic_id( $topic_id );961 953 962 $revision_log = get_post_meta( $topic_id, '_bbp_revision_log', true ); 963 $revision_log = empty( $revision_log ) ? array() : $revision_log; 954 // If there are more revisions to show 955 if ( $total > $limit ) { 956 $link_url = add_query_arg( 'bbp_topic_revisions_all', $topic_id, bbp_get_topic_permalink( $topic_id ) . '/#post-' . $topic_id ); 957 $link_text = esc_html__( sprintf( 'Show %d more', $total - $limit ) ); 964 958 965 return apply_filters( 'bbp_get_topic_raw_revision_log', $revision_log, $topic_id);966 959 $r .= sprintf( "<li class='bbp-topic-revision-log-more' data-id='%d'><a href='%s'>%s</a></li>", $topic_id, $link_url, $link_text ); 960 } 967 961 962 $r .= "\n" . '</ul>' . "\n\n"; 963 964 return apply_filters( 'bbp_get_topic_revision_log', $r, $topic_id ); 965 } 966 968 967 /** 969 * Return the r evisionsof the topic968 * Return the raw revision log of the topic 970 969 * 971 970 * @since bbPress (r2782) 972 971 * 973 972 * @param int $topic_id Optional. Topic id 974 973 * @uses bbp_get_topic_id() To get the topic id 975 * @uses wp_get_post_revisions() To get the topic revisions 976 * @uses apply_filters() Calls 'bbp_get_topic_revisions' 977 * with the revisions and topic id 974 * @uses get_post_meta() To get the revision log meta 975 * @uses apply_filters() Calls 'bbp_get_topic_raw_revision_log' 976 * with the log and topic id 977 * @return string Raw revision log of the topic 978 */ 979 function bbp_get_topic_raw_revision_log( $topic_id = 0 ) { 980 $topic_id = bbp_get_topic_id( $topic_id ); 981 982 $revision_log = get_post_meta( $topic_id, '_bbp_revision_log', true ); 983 $revision_log = empty( $revision_log ) ? array() : $revision_log; 984 985 return apply_filters( 'bbp_get_topic_raw_revision_log', $revision_log, $topic_id ); 986 } 987 988 /** 989 * Return the revisions of the topic 990 * 991 * @since bbPress (r2782) 992 * 993 * @param int $topic_id Optional. Topic id 994 * @param int $count Optional. Amout of revisions to grab. 995 * @param string $order Optional. ASC/DESC Order of the results. 996 * 997 * @uses bbp_get_topic_id() To get the topic id 998 * @uses wp_get_post_revisions() To get the topic revisions 999 * @uses apply_filters() Calls 'bbp_get_topic_revisions' 1000 * with the revisions and topic id 1001 * 978 1002 * @return string Topic revisions 979 1003 */ 980 function bbp_get_topic_revisions( $topic_id = 0 ) {1004 function bbp_get_topic_revisions( $topic_id = 0, $count = -1, $order = 'ASC' ) { 981 1005 $topic_id = bbp_get_topic_id( $topic_id ); 982 $revisions = wp_get_post_revisions( $topic_id, array( 'order' => 'ASC') );1006 $revisions = wp_get_post_revisions( $topic_id, array( 'order' => $order, 'posts_per_page' => $count ) ); 983 1007 984 1008 return apply_filters( 'bbp_get_topic_revisions', $revisions, $topic_id ); 985 1009 }