Skip to:
Content

bbPress.org


Ignore:
Timestamp:
09/09/2011 09:43:33 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Fix issue when topics and replies are flagged as spam/trash where they would still update last active data for ancestors. Fixes #1631.
Fix issue when trashing and deleting a topic, replies may not be properly queried and updated. Fixes #1629.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-topic-functions.php

    r3489 r3501  
    7474    $forum_id = bbp_get_topic_forum_id( $topic_id );
    7575    if ( !empty( $forum_id ) )
    76         bbp_update_forum( $forum_id );
     76        bbp_update_forum( array( 'forum_id' => $forum_id ) );
    7777
    7878    // Return new topic ID
     
    339339
    340340            // Get the topic URL
    341             $topic_url = bbp_get_topic_permalink( $topic_id, $redirect_to );
     341            $redirect_url = bbp_get_topic_permalink( $topic_id, $redirect_to );
    342342
    343343            // Add view all?
    344             if ( bbp_get_view_all() || ( current_user_can( 'moderate' ) && !empty( $view_all ) ) )
    345                 $topic_url = bbp_add_view_all( $topic_url );
     344            if ( bbp_get_view_all() || !empty( $view_all ) ) {
     345
     346                // User can moderate, so redirect to topic with view all set
     347                if ( current_user_can( 'moderate' ) ) {
     348                    $redirect_url = bbp_add_view_all( $redirect_url );
     349
     350                // User cannot moderate, so redirect to forum
     351                } else {
     352                    $redirect_url = bbp_get_forum_permalink( $forum_id );
     353                }
     354            }
    346355
    347356            // Allow to be filtered
    348             $topic_url = apply_filters( 'bbp_new_topic_redirect_to', $topic_url, $redirect_to );
     357            $redirect_url = apply_filters( 'bbp_new_topic_redirect_to', $redirect_url, $redirect_to );
    349358
    350359            /** Successful Save ***********************************************/
    351360
    352361            // Redirect back to new topic
    353             wp_safe_redirect( $topic_url );
     362            wp_safe_redirect( $redirect_url );
    354363
    355364            // For good measure
     
    709718
    710719        // Set transient for throttle check (only on new, not edit)
    711         if ( empty( $is_edit ) )
     720        if ( empty( $is_edit ) ) {
    712721            set_transient( '_bbp_' . bbp_current_author_ip() . '_last_posted', time() );
     722        }
    713723
    714724        // Website is optional
    715         if ( !empty( $bbp_anonymous_website ) )
     725        if ( !empty( $bbp_anonymous_website ) ) {
    716726            update_post_meta( $topic_id, '_bbp_anonymous_website', $bbp_anonymous_website, false );
     727        }
    717728    } else {
    718         if ( empty( $is_edit ) && !current_user_can( 'throttle' ) )
     729        if ( empty( $is_edit ) && !current_user_can( 'throttle' ) ) {
    719730            update_user_meta( $author_id, '_bbp_last_posted', time() );
     731        }
    720732    }
    721733
     
    726738
    727739        // Subscribed and unsubscribing
    728         if ( true == $subscribed && false == $subscheck )
     740        if ( true == $subscribed && false == $subscheck ) {
    729741            bbp_remove_user_subscription( $author_id, $topic_id );
    730742
    731743        // Subscribing
    732         elseif ( false == $subscribed && true == $subscheck )
     744        } elseif ( false == $subscribed && true == $subscheck ) {
    733745            bbp_add_user_subscription( $author_id, $topic_id );
     746        }
    734747    }
    735748
     
    798811    $ancestors = array_values( array_unique( array_merge( array( $forum_id ), get_post_ancestors( $topic_id ) ) ) );
    799812
     813    // Topic status
     814    $topic_status = get_post_status( $topic_id );
     815
    800816    // If we want a full refresh, unset any of the possibly passed variables
    801     if ( true == $refresh )
     817    if ( true == $refresh ) {
    802818        $forum_id = $topic_id = $reply_id = $active_id = $last_active_time = 0;
     819        $topic_status = 'publish';
     820    }
    803821
    804822    // Loop through ancestors
     
    810828            // Update the forum
    811829            bbp_update_forum( array(
    812                 'forum_id'         => $ancestor,
    813                 'last_topic_id'    => $topic_id,
    814                 'last_reply_id'    => $reply_id,
    815                 'last_active_id'   => $active_id,
    816                 'last_active_time' => 0,
     830                'forum_id'           => $ancestor,
     831                'last_topic_id'      => $topic_id,
     832                'last_reply_id'      => $reply_id,
     833                'last_active_id'     => $active_id,
     834                'last_active_time'   => 0,
     835                'last_active_status' => $topic_status
    817836            ) );
    818837        }
     
    11501169        /** Successful Merge **************************************************/
    11511170
     1171        // Update topic's last meta data
     1172        bbp_update_topic_last_reply_id   ( $destination_topic->ID );
     1173        bbp_update_topic_last_active_id  ( $destination_topic->ID );
     1174        bbp_update_topic_last_active_time( $destination_topic->ID );
     1175
    11521176        // Send the post parent of the source topic as it has been shifted
    11531177        // (possibly to a new forum) so we need to update the counts of the
     
    21482172        $active_id = $topic_id;
    21492173
    2150     update_post_meta( $topic_id, '_bbp_last_active_id', (int) $active_id );
     2174    // Update only if published
     2175    if ( 'publish' == get_post_status( $active_id ) )
     2176        update_post_meta( $topic_id, '_bbp_last_active_id', (int) $active_id );
    21512177
    21522178    return apply_filters( 'bbp_update_topic_last_active_id', (int) $active_id, $topic_id );
     
    21782204        $new_time = get_post_field( 'post_date', bbp_get_public_child_last_id( $topic_id, bbp_get_reply_post_type() ) );
    21792205
    2180     update_post_meta( $topic_id, '_bbp_last_active_time', $new_time );
     2206    // Update only if published
     2207    if ( !empty( $new_time ) )
     2208        update_post_meta( $topic_id, '_bbp_last_active_time', $new_time );
    21812209
    21822210    return apply_filters( 'bbp_update_topic_last_active_time', $new_time, $topic_id );
     
    22192247        $reply_id = 0;
    22202248
    2221     update_post_meta( $topic_id, '_bbp_last_reply_id', (int) $reply_id );
     2249    // Update if reply is published
     2250    if ( bbp_is_reply_published( $reply_id ) )
     2251        update_post_meta( $topic_id, '_bbp_last_reply_id', (int) $reply_id );
    22222252
    22232253    return apply_filters( 'bbp_update_topic_last_reply_id', (int) $reply_id, $topic_id );
     
    26672697
    26682698/**
    2669  * Called before deleting a topic
     2699 * Called before deleting a topic.
     2700 *
     2701 * This function is supplemental to the actual topic deletion which is
     2702 * handled by WordPress core API functions. It is used to clean up after
     2703 * a topic that is being deleted.
    26702704 *
    26712705 * @uses bbp_get_topic_id() To get the topic id
     
    26792713 */
    26802714function bbp_delete_topic( $topic_id = 0 ) {
     2715    global $bbp;
     2716
     2717    // Validate topic ID
    26812718    $topic_id = bbp_get_topic_id( $topic_id );
    26822719
     
    26862723    do_action( 'bbp_delete_topic', $topic_id );
    26872724
     2725    // Valid topic/reply statuses
     2726    $post_stati = join( ',', array( 'publish', $bbp->spam_status_id, 'trash' ) );
     2727
    26882728    // Topic is being permanently deleted, so its replies gotta go too
    2689     if ( bbp_has_replies( array( 'post_parent' => $topic_id, 'post_status' => 'publish', 'posts_per_page' => -1 ) ) ) {
     2729    if ( bbp_has_replies( array(
     2730        'post_type'      => bbp_get_reply_post_type(),
     2731        'post_status'    => $post_stati,
     2732        'posts_per_page' => -1,
     2733        'meta_query'     => array( array(
     2734            'key'        => '_bbp_topic_id',
     2735            'value'      => $topic_id,
     2736            'compare'    => '='
     2737        ) )
     2738    ) ) ) {
    26902739        while ( bbp_replies() ) {
    26912740            bbp_the_reply();
     
    26982747 * Called before trashing a topic
    26992748 *
     2749 * This function is supplemental to the actual topic being trashed which is
     2750 * handled by WordPress core API functions. It is used to clean up after
     2751 * a topic that is being trashed.
     2752 *
    27002753 * @uses bbp_get_topic_id() To get the topic id
    27012754 * @uses bbp_is_topic() To check if the passed id is a topic
     
    27092762 */
    27102763function bbp_trash_topic( $topic_id = 0 ) {
     2764    global $bbp;
     2765
    27112766    $topic_id = bbp_get_topic_id( $topic_id );
    27122767
     
    27172772
    27182773    // Topic is being trashed, so its replies are trashed too
    2719     if ( bbp_has_replies( array( 'post_parent' => $topic_id, 'post_status' => 'publish', 'posts_per_page' => -1 ) ) ) {
    2720         global $bbp;
     2774    if ( bbp_has_replies( array(
     2775        'post_type'      => bbp_get_reply_post_type(),
     2776        'post_status'    => 'publish',
     2777        'posts_per_page' => -1,
     2778        'meta_query'     => array( array(
     2779            'key'        => '_bbp_topic_id',
     2780            'value'      => $topic_id,
     2781            'compare'    => '='
     2782        ) )
     2783    ) ) ) {
    27212784
    27222785        // Prevent debug notices
Note: See TracChangeset for help on using the changeset viewer.