Skip to:
Content

bbPress.org

Ticket #1989: 1989.patch

File 1989.patch, 17.8 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         /**
    665          * Return the formatted revision log of the reply
    666          *
    667          * @since bbPress (r2782)
    668          *
    669          * @param int $reply_id Optional. Reply id
    670          * @uses bbp_get_reply_id() To get the reply id
    671          * @uses bbp_get_reply_revisions() To get the reply revisions
    672          * @uses bbp_get_reply_raw_revision_log() To get the raw revision log
    673          * @uses bbp_get_reply_author_display_name() To get the reply author
    674          * @uses bbp_get_reply_author_link() To get the reply author link
    675          * @uses bbp_convert_date() To convert the date
    676          * @uses bbp_get_time_since() To get the time in since format
    677          * @uses apply_filters() Calls 'bbp_get_reply_revision_log' with the
    678          *                        log and reply id
    679          * @return string Revision log of the reply
    680          */
    681         function bbp_get_reply_revision_log( $reply_id = 0 ) {
    682664
    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 */
     682function bbp_get_reply_revision_log( $reply_id = 0 ) {
    685683
    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 );
    690686
    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        }
    693691
    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 );
    697694
    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;
    702698
    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
    704700
    705                 // Loop through revisions
    706                 foreach ( (array) $revisions as $revision ) {
     701        $total = $limit = - 1;
     702        $order = 'ASC';
    707703
    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        }
    715709
    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 );
    718711
    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;
    726714
     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'];
    727726                }
    728727
    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 ) );
    730730
    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
    732739        }
    733                 /**
    734                  * Return the raw revision log of the reply
    735                  *
    736                  * @since bbPress (r2782)
    737                  *
    738                  * @param int $reply_id Optional. Reply id
    739                  * @uses bbp_get_reply_id() To get the reply id
    740                  * @uses get_post_meta() To get the revision log meta
    741                  * @uses apply_filters() Calls 'bbp_get_reply_raw_revision_log'
    742                  *                        with the log and reply id
    743                  * @return string Raw revision log of the reply
    744                  */
    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;
    749740
    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 ) );
    752746
     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
    753755/**
    754  * Return the revisions of the reply
     756 * Return the raw revision log of the reply
    755757 *
    756758 * @since bbPress (r2782)
    757759 *
    758760 * @param int $reply_id Optional. Reply id
    759761 * @uses bbp_get_reply_id() To get the reply id
    760  * @uses wp_get_post_revisions() To get the reply revisions
    761  * @uses apply_filters() Calls 'bbp_get_reply_revisions'
    762  *                        with the revisions and reply id
    763  * @return string reply revisions
     762 * @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
    764766 */
    765 function bbp_get_reply_revisions( $reply_id = 0 ) {
     767function 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 */
     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         /**
    889          * Return the formatted revision log of the topic
    890          *
    891          * @since bbPress (r2782)
    892          *
    893          * @param int $topic_id Optional. Topic id
    894          * @uses bbp_get_topic_id() To get the topic id
    895          * @uses bbp_get_topic_revisions() To get the topic revisions
    896          * @uses bbp_get_topic_raw_revision_log() To get the raw revision log
    897          * @uses bbp_get_topic_author_display_name() To get the topic author
    898          * @uses bbp_get_author_link() To get the topic author link
    899          * @uses bbp_convert_date() To convert the date
    900          * @uses bbp_get_time_since() To get the time in since format
    901          * @uses apply_filters() Calls 'bbp_get_topic_revision_log' with the
    902          *                        log and topic id
    903          * @return string Revision log of the topic
    904          */
    905         function bbp_get_topic_revision_log( $topic_id = 0 ) {
    906                 // Create necessary variables
    907                 $topic_id     = bbp_get_topic_id( $topic_id );
    908                 $revision_log = bbp_get_topic_raw_revision_log( $topic_id );
    909888
    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 */
     906function 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 );
    912910
    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;
    916913
    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';
    918916
    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        }
    921922
    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 );
    929924
    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;
    932927
    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";
    940929
     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'];
    941939                }
    942940
    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 ) );
    944943
    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
    946952        }
    947                 /**
    948                  * Return the raw revision log of the topic
    949                  *
    950                  * @since bbPress (r2782)
    951                  *
    952                  * @param int $topic_id Optional. Topic id
    953                  * @uses bbp_get_topic_id() To get the topic id
    954                  * @uses get_post_meta() To get the revision log meta
    955                  * @uses apply_filters() Calls 'bbp_get_topic_raw_revision_log'
    956                  *                        with the log and topic id
    957                  * @return string Raw revision log of the topic
    958                  */
    959                 function bbp_get_topic_raw_revision_log( $topic_id = 0 ) {
    960                         $topic_id = bbp_get_topic_id( $topic_id );
    961953
    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 ) );
    964958
    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        }
    967961
     962        $r .= "\n" . '</ul>' . "\n\n";
     963
     964        return apply_filters( 'bbp_get_topic_revision_log', $r, $topic_id );
     965}
     966
    968967/**
    969  * Return the revisions of the topic
     968 * Return the raw revision log of the topic
    970969 *
    971970 * @since bbPress (r2782)
    972971 *
    973972 * @param int $topic_id Optional. Topic id
    974973 * @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 */
     979function 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 *
    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}