Skip to:
Content

BuddyPress.org

Ticket #6485: 6485.02.patch

File 6485.02.patch, 3.6 KB (added by imath, 9 years ago)
  • src/bp-blogs/bp-blogs-activity.php

    diff --git src/bp-blogs/bp-blogs-activity.php src/bp-blogs/bp-blogs-activity.php
    index c29e56b..0395679 100644
    add_action( 'trashed_post_comments', 'bp_blogs_remove_activity_meta_for_trashed_ 
    766766 * @return array $args
    767767 */
    768768function bp_blogs_new_blog_comment_query_backpat( $args ) {
     769        global $wpdb;
     770        $bp = buddypress();
     771
    769772        // Bail if this is not a 'new_blog_comment' query
    770773        if ( 'new_blog_comment' !== $args['action'] ) {
    771774                return $args;
    772775        }
    773776
    774         // display_comments=stream is required to show new-style
    775         // 'activity_comment' items inline
    776         $args['display_comments'] = 'stream';
     777        // if activity comments are disabled for blog posts, stop now!
     778        if ( bp_disable_blogforum_comments() ) {
     779                return $args;
     780        }
    777781
    778         // For the remaining clauses, we filter the SQL query directly
    779         add_filter( 'bp_activity_paged_activities_sql', '_bp_blogs_new_blog_comment_query_backpat_filter' );
    780         add_filter( 'bp_activity_total_activities_sql', '_bp_blogs_new_blog_comment_query_backpat_filter' );
     782        // Comment synced ?
     783        $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT activity_id FROM {$bp->activity->table_name_meta} WHERE meta_key = %s", 'bp_blogs_post_comment_id' ) );
    781784
    782         // Return the original arguments
    783         return $args;
    784 }
    785 add_filter( 'bp_after_has_activities_parse_args', 'bp_blogs_new_blog_comment_query_backpat' );
     785        if ( empty( $activity_ids ) ) {
     786                return $args;
     787        }
    786788
    787 /**
    788  * Filter activity SQL to include new- and old-style 'new_blog_comment' activity items.
    789  *
    790  * @since BuddyPress (2.1.0)
    791  *
    792  * @access private
    793  * @see bp_blogs_new_blog_comment_query_backpat()
    794  *
    795  * @param string $query SQL query as assembled in BP_Activity_Activity::get().
    796  * @return string $query Modified SQL query.
    797  */
    798 function _bp_blogs_new_blog_comment_query_backpat_filter( $query ) {
    799         $bp = buddypress();
     789        // Init the filter query
     790        $filter_query = array();
     791
     792        if ( 'null' === $args['scope'] ) {
     793                $args['scope'] = '';
     794        } elseif ( 'just-me' === $args['scope'] ) {
     795                $filter_query = array(
     796                        'relation' => 'AND',
     797                        array(
     798                                'column' => 'user_id',
     799                                'value'  => bp_displayed_user_id(),
     800                        ),
     801                );
     802                $args['scope'] = '';
     803        }
     804
     805        $filter_query[] = array(
     806                'relation' => 'OR',
     807                array(
     808                        'column' => 'type',
     809                        'value'  => $args['action'],
     810                ),
     811                array(
     812                        'column'  => 'id',
     813                        'value'   =>  $activity_ids,
     814                        'compare' => 'IN'
     815                ),
     816        );
    800817
    801         // The query passed to the filter is for old-style 'new_blog_comment'
    802         // items. We include new-style 'activity_comment' items by running a
    803         // subquery inside of a large OR clause.
    804         $activity_comment_subquery = "SELECT a.id FROM {$bp->activity->table_name} a INNER JOIN {$bp->activity->table_name_meta} am ON (a.id = am.activity_id) WHERE am.meta_key = 'bp_blogs_post_comment_id' AND a.type = 'activity_comment'";
     818        $args['filter_query'] = $filter_query;
    805819
    806         // WHERE ( [original WHERE clauses] OR a.id IN (activity_comment subquery) )
    807         $query = preg_replace( '|WHERE (.*?) ORDER|', 'WHERE ( ( $1 ) OR ( a.id IN ( ' . $activity_comment_subquery . ' ) ) ) ORDER', $query );
     820        // Make sure to have comment in stream mode && avoid duplicate content
     821        $args['display_comments'] = 'stream';
    808822
    809         // Don't run this on future queries
    810         remove_filter( current_filter(), '_bp_blogs_new_blog_comment_query_backpat_filter' );
     823        // Finally reset the action
     824        $args['action'] = '';
    811825
    812         return $query;
     826        // Return the original arguments
     827        return $args;
    813828}
     829add_filter( 'bp_after_has_activities_parse_args', 'bp_blogs_new_blog_comment_query_backpat' );
    814830
    815831/**
    816832 * Utility function to set up some variables for use in the activity loop.