Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/25/2009 08:38:56 PM (13 years ago)
Author:
apeatling
Message:

Activity stream commenting updates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-classes.php

    r2114 r2128  
    163163    }
    164164
    165     function get_activity_for_user( $user_id, $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false ) {
     165    function get_activity_for_user( $user_id, $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false ) {
    166166        global $wpdb, $bp;
    167167
     
    247247    }
    248248
    249     function get_sitewide_activity( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false ) {
    250         global $wpdb, $bp;
     249    function get_sitewide_activity( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false ) {
     250        global $wpdb, $bp;
     251
     252        $where_conditions = array();
    251253
    252254        if ( $per_page && $page )
     
    259261        if ( $search_terms ) {
    260262            $search_terms = $wpdb->escape( $search_terms );
    261             $search_sql = "AND content LIKE '%%" . like_escape( $search_terms ) . "%%'";
     263            $where_conditions['search_sql'] = "content LIKE '%%" . like_escape( $search_terms ) . "%%'";
    262264        }
    263265
    264266        /* Filtering */
    265         if ( $filter )
    266             $filter_sql = BP_Activity_Activity::get_filter_sql( $filter );
     267        if ( $filter && $filter_sql = BP_Activity_Activity::get_filter_sql( $filter ) )
     268            $where_conditions['filter_sql'] = $filter_sql;
    267269
    268270        /* Sorting */
     
    270272            $sort = 'DESC';
    271273
     274        /* Hide Hidden Items? */
     275        if ( !$show_hidden )
     276            $where_conditions['hidden_sql'] = "hide_sitewide = 0";
     277
    272278        /* Alter the query based on whether we want to show activity item comments in the stream like normal comments or threaded below the activity */
    273279        if ( !$display_comments || 'threaded' == $display_comments ) {
     280            $where_conditions[] = "component_action != 'activity_comment'";
     281            $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
     282
    274283            if ( $per_page && $page && $max )
    275                 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE hide_sitewide = 0 {$search_sql} {$filter_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$pag_sql}" ) );
     284                $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} {$where_sql} ORDER BY date_recorded {$sort} {$pag_sql}" ) );
    276285            else
    277                 $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE hide_sitewide = 0 {$search_sql} {$filter_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$pag_sql} {$max_sql}" ) );
    278 
    279             $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE hide_sitewide = 0 {$search_sql} {$filter_sql} AND component_action != 'activity_comment' ORDER BY date_recorded {$sort} {$max_sql}" ) );
     286                $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} {$where_sql} ORDER BY date_recorded {$sort} {$pag_sql} {$max_sql}" ) );
     287
     288            $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} {$where_sql} ORDER BY date_recorded {$sort} {$max_sql}" ) );
    280289
    281290            if ( $activities && $display_comments )
     
    286295             * we will need to do things slightly differently.
    287296             */
     297            if ( !empty( $where_conditions ) )
     298                $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
     299
    288300             if ( !empty( $filter_sql ) ) {
    289                 $all_activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE hide_sitewide = 0 {$search_sql} {$filter_sql} ORDER BY id {$sort}" ) );
     301                $all_activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} {$where_sql} ORDER BY id {$sort}" ) );
    290302
    291303                foreach ( (array)$all_activities as $activity ) {
     
    296308
    297309                /* Fetch the comments for the activity items */
    298                 $all_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE hide_sitewide = 0 AND item_id IN ({$activity_ids}) {$search_sql} ORDER BY id {$sort}" ) );
     310                $search_sql = $where_conditions['search_sql'];
     311                $all_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE item_id IN ({$activity_ids}) {$search_sql} ORDER BY id {$sort}" ) );
    299312
    300313                foreach ( (array)$all_comments as $comment ) {
     
    313326             } else {
    314327                if ( $per_page && $page && $max )
    315                     $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE hide_sitewide = 0 {$search_sql} {$filter_sql} ORDER BY id {$sort} {$pag_sql}" ) );
     328                    $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} {$where_sql} ORDER BY id {$sort} {$pag_sql}" ) );
    316329                else
    317                     $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE hide_sitewide = 0 {$search_sql} {$filter_sql} ORDER BY id {$sort} {$pag_sql} {$max_sql}" ) );
    318 
    319                 $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE hide_sitewide = 0 {$search_sql} {$filter_sql} ORDER BY date_recorded {$sort} {$max_sql}" ) );
     330                    $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} {$where_sql} ORDER BY id {$sort} {$pag_sql} {$max_sql}" ) );
     331
     332                $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} {$where_sql} ORDER BY date_recorded {$sort} {$max_sql}" ) );
    320333             }
    321334
     
    449462        if ( !empty( $filter_array['object'] ) ) {
    450463            $object_filter = explode( ',', $filter_array['object'] );
    451             $object_sql = ' AND ( ';
     464            $object_sql = ' ( ';
    452465
    453466            $counter = 1;
     
    462475
    463476            $object_sql .= ' )';
     477            $filter_sql[] = $object_sql;
    464478        }
    465479
    466480        if ( !empty( $filter_array['action'] ) ) {
    467481            $action_filter = explode( ',', $filter_array['action'] );
    468             $action_sql = ' AND ( ';
     482            $action_sql = ' ( ';
    469483
    470484            $counter = 1;
     
    479493
    480494            $action_sql .= ' )';
     495            $filter_sql[] = $action_sql;
    481496        }
    482497
    483498        if ( !empty( $filter_array['primary_id'] ) ) {
    484499            $pid_filter = explode( ',', $filter_array['primary_id'] );
    485             $pid_sql = ' AND ( ';
     500            $pid_sql = ' ( ';
    486501
    487502            $counter = 1;
     
    496511
    497512            $pid_sql .= ' )';
     513            $filter_sql[] = $pid_sql;
    498514        }
    499515
    500516        if ( !empty( $filter_array['secondary_id'] ) ) {
    501517            $sid_filter = explode( ',', $filter_array['secondary_id'] );
    502             $sid_sql = ' AND ( ';
     518            $sid_sql = ' ( ';
    503519
    504520            $counter = 1;
     
    513529
    514530            $sid_sql .= ' )';
    515         }
    516 
    517         return $object_sql . $action_sql . $pid_sql . $sid_sql;
     531            $filter_sql[] = $sid_sql;
     532        }
     533
     534        if ( empty($filter_sql) )
     535            return false;
     536
     537        return join( ' AND ', $filter_sql );
    518538    }
    519539
Note: See TracChangeset for help on using the changeset viewer.