Skip to:
Content

bbPress.org

Ticket #1989: 1989-no-whitespace.patch

File 1989-no-whitespace.patch, 5.2 KB (added by MZAWeb, 6 years ago)
  • includes/replies/template.php

     
    661661function bbp_reply_revision_log( $reply_id = 0 ) {
    662662        echo bbp_get_reply_revision_log( $reply_id );
    663663}
     664
    664665        /**
    665666         * Return the formatted revision log of the reply
    666667         *
     
    696697                        return false;
    697698
    698699                // Get the actual revisions
    699                 $revisions = bbp_get_reply_revisions( $reply_id );
     700
     701        $total = $limit = - 1;
     702        $order = 'ASC';
     703
     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        }
     709
     710        $revisions = bbp_get_reply_revisions( $reply_id, $limit, $order );
     711
    700712                if ( empty( $revisions ) )
    701713                        return false;
    702714
     
    726738
    727739                }
    728740
     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 ) );
     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
    729750                $r .= "\n" . '</ul>' . "\n\n";
    730751
    731752                return apply_filters( 'bbp_get_reply_revision_log', $r, $reply_id );
    732753        }
     754
    733755                /**
    734756                 * Return the raw revision log of the reply
    735757                 *
     
    755777 *
    756778 * @since bbPress (r2782)
    757779 *
    758  * @param int $reply_id Optional. Reply id
     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 *
    759784 * @uses bbp_get_reply_id() To get the reply id
    760  * @uses wp_get_post_revisions() To get the reply revisions
     785 * @uses  wp_get_post_revisions() To get the topic revisions
    761786 * @uses apply_filters() Calls 'bbp_get_reply_revisions'
    762787 *                        with the revisions and reply id
    763  * @return string reply revisions
     788 *
     789 * @return string Reply revisions
    764790 */
    765 function bbp_get_reply_revisions( $reply_id = 0 ) {
     791function bbp_get_reply_revisions( $reply_id = 0, $count = -1, $order = 'ASC' ) {
    766792        $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 ) );
    768794
    769795        return apply_filters( 'bbp_get_reply_revisions', $revisions, $reply_id );
    770796}
    771797
     798
    772799/**
    773800 * Return the revision count of the reply
    774801 *
  • includes/topics/template.php

     
    885885function bbp_topic_revision_log( $topic_id = 0 ) {
    886886        echo bbp_get_topic_revision_log( $topic_id );
    887887}
     888
    888889        /**
    889890         * Return the formatted revision log of the topic
    890891         *
     
    910911                if ( empty( $topic_id ) || empty( $revision_log ) || !is_array( $revision_log ) )
    911912                        return false;
    912913
    913                 $revisions = bbp_get_topic_revisions( $topic_id );
     914        $total = $limit = - 1;
     915        $order = 'ASC';
     916
     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        }
     922
     923        $revisions = bbp_get_topic_revisions( $topic_id, $limit, $order );
     924
    914925                if ( empty( $revisions ) )
    915926                        return false;
    916927
     
    940951
    941952                }
    942953
     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 ) );
     958
     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        }
     961
    943962                $r .= "\n" . '</ul>' . "\n\n";
    944963
    945964                return apply_filters( 'bbp_get_topic_revision_log', $r, $topic_id );
    946965        }
     966
    947967                /**
    948968                 * Return the raw revision log of the topic
    949969                 *
     
    971991 * @since bbPress (r2782)
    972992 *
    973993 * @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 *
    974997 * @uses bbp_get_topic_id() To get the topic id
    975998 * @uses wp_get_post_revisions() To get the topic revisions
    976999 * @uses apply_filters() Calls 'bbp_get_topic_revisions'
    9771000 *                        with the revisions and topic id
     1001 *
    9781002 * @return string Topic revisions
    9791003 */
    980 function bbp_get_topic_revisions( $topic_id = 0 ) {
     1004function bbp_get_topic_revisions( $topic_id = 0, $count = -1, $order = 'ASC' ) {
    9811005        $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 ) );
    9831007
    9841008        return apply_filters( 'bbp_get_topic_revisions', $revisions, $topic_id );
    9851009}