Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/01/2014 07:58:47 PM (9 years ago)
Author:
boonebgorges
Message:

Ensure that the 'Comments' dropdown filter on the activity directory includes new- and old-style comment activity

The change in BuddyPress 2.0 to storing blog comment activity in
activity_comment items resulted in the 'Comments' dropdown filter breaking: it
continued to return only 'new_blog_comment' items. This changeset introduces
a number of filters to ensure that both the appropriate 'activity_comment'
and 'new_blog_comment' items are included when passing 'action=new_blog_comment'
to bp_has_activities().

See #5608

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-activity.php

    r8715 r8747  
    658658
    659659/**
     660 * Filter 'new_blog_comment' bp_has_activities() loop to include new- and old-style blog activity comment items.
     661 *
     662 * In BuddyPress 2.0, the schema for storing activity items related to blog
     663 * posts changed. Instead creating new top-level 'new_blog_comment' activity
     664 * items, blog comments are recorded in the activity stream as comments on the
     665 * 'new_blog_post' activity items corresponding to the parent post. This filter
     666 * ensures that the 'new_blog_comment' filter in bp_has_activities() (which
     667 * powers the 'Comments' filter in the activity directory dropdown) includes
     668 * both old-style and new-style activity comments.
     669 *
     670 * This implementation involves filtering the activity queries directly, and
     671 * should be considered a stopgap. The proper solution would involve enabling
     672 * multiple query condition clauses, connected by an OR, in the bp_has_activities()
     673 * API.
     674 *
     675 * @since BuddyPress (2.1.0)
     676 *
     677 * @param array $args Arguments passed from bp_parse_args() in bp_has_activities().
     678 * @return array $args
     679 */
     680function bp_blogs_new_blog_comment_query_backpat( $args ) {
     681    // Bail if this is not a 'new_blog_comment' query
     682    if ( 'new_blog_comment' !== $args['action'] ) {
     683        return $args;
     684    }
     685
     686    // display_comments=stream is required to show new-style
     687    // 'activity_comment' items inline
     688    $args['display_comments'] = 'stream';
     689
     690    // For the remaining clauses, we filter the SQL query directly
     691    add_filter( 'bp_activity_paged_activities_sql', '_bp_blogs_new_blog_comment_query_backpat_filter' );
     692    add_filter( 'bp_activity_total_activities_sql', '_bp_blogs_new_blog_comment_query_backpat_filter' );
     693
     694    // Return the original arguments
     695    return $args;
     696}
     697add_filter( 'bp_after_has_activities_parse_args', 'bp_blogs_new_blog_comment_query_backpat' );
     698
     699/**
     700 * Filter activity SQL to include new- and old-style 'new_blog_comment' activity items.
     701 *
     702 * @since BuddyPress (2.1.0)
     703 *
     704 * @access private
     705 * @see bp_blogs_new_blog_comment_query_backpat()
     706 *
     707 * @param string $query SQL query as assembled in BP_Activity_Activity::get().
     708 * @return string $query Modified SQL query.
     709 */
     710function _bp_blogs_new_blog_comment_query_backpat_filter( $query ) {
     711    $bp = buddypress();
     712
     713    // The query passed to the filter is for old-style 'new_blog_comment'
     714    // items. We include new-style 'activity_comment' items by running a
     715    // subquery inside of a large OR clause.
     716    $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'";
     717
     718    // WHERE ( [original WHERE clauses] OR a.id IN (activity_comment subquery) )
     719    $query = preg_replace( '|WHERE (.*?) ORDER|', 'WHERE ( ( $1 ) OR ( a.id IN ( ' . $activity_comment_subquery . ' ) ) ) ORDER', $query );
     720
     721    // Don't run this on future queries
     722    remove_filter( current_filter(), '_bp_blogs_new_blog_comment_query_backpat_filter' );
     723
     724    return $query;
     725}
     726
     727/**
    660728 * Utility function to set up some variables for use in the activity loop.
    661729 *
Note: See TracChangeset for help on using the changeset viewer.