Changeset 9958
- Timestamp:
- 06/21/2015 11:07:19 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-blogs/bp-blogs-activity.php
r9822 r9958 767 767 */ 768 768 function bp_blogs_new_blog_comment_query_backpat( $args ) { 769 global $wpdb; 770 $bp = buddypress(); 771 769 772 // Bail if this is not a 'new_blog_comment' query 770 773 if ( 'new_blog_comment' !== $args['action'] ) { … … 772 775 } 773 776 774 // display_comments=stream is required to show new-style 775 // 'activity_comment' items inline 777 // Comment synced ? 778 $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' ) ); 779 780 if ( empty( $activity_ids ) ) { 781 return $args; 782 } 783 784 // Init the filter query 785 $filter_query = array(); 786 787 if ( 'null' === $args['scope'] ) { 788 $args['scope'] = ''; 789 } elseif ( 'just-me' === $args['scope'] ) { 790 $filter_query = array( 791 'relation' => 'AND', 792 array( 793 'column' => 'user_id', 794 'value' => bp_displayed_user_id(), 795 ), 796 ); 797 $args['scope'] = ''; 798 } 799 800 $filter_query[] = array( 801 'relation' => 'OR', 802 array( 803 'column' => 'type', 804 'value' => $args['action'], 805 ), 806 array( 807 'column' => 'id', 808 'value' => $activity_ids, 809 'compare' => 'IN' 810 ), 811 ); 812 813 $args['filter_query'] = $filter_query; 814 815 // Make sure to have comment in stream mode && avoid duplicate content 776 816 $args['display_comments'] = 'stream'; 777 817 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' ); 818 // Finally reset the action 819 $args['action'] = ''; 781 820 782 821 // Return the original arguments … … 784 823 } 785 824 add_filter( 'bp_after_has_activities_parse_args', 'bp_blogs_new_blog_comment_query_backpat' ); 786 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 private793 * @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();800 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 a803 // 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'";805 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 );808 809 // Don't run this on future queries810 remove_filter( current_filter(), '_bp_blogs_new_blog_comment_query_backpat_filter' );811 812 return $query;813 }814 825 815 826 /**
Note: See TracChangeset
for help on using the changeset viewer.