Skip to:
Content

BuddyPress.org

Changeset 3373


Ignore:
Timestamp:
11/07/2010 11:33:21 AM (15 years ago)
Author:
boonebgorges
Message:

Adds exclude parameter to bp_has_activities. Fixes #2646

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r3369 r3373  
    504504        'search_terms' => false, // Pass search terms as a string
    505505        'show_hidden' => false, // Show activity items that are hidden site-wide?
     506        'exclude' => false, // Comma-separated list of activity IDs to exclude
    506507
    507508        /**
     
    522523
    523524    /* Attempt to return a cached copy of the first page of sitewide activity. */
    524     if ( 1 == (int)$page && empty( $max ) && empty( $search_terms ) && empty( $filter ) && 'DESC' == $sort ) {
     525    if ( 1 == (int)$page && empty( $max ) && empty( $search_terms ) && empty( $filter ) && 'DESC' == $sort && empty( $exclude ) ) {
    525526        if ( !$activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' ) ) {
    526527            $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
     
    528529        }
    529530    } else
    530         $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
     531        $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden, $exclude );
    531532
    532533    return apply_filters( 'bp_activity_get', $activity, &$r );
  • trunk/bp-activity/bp-activity-classes.php

    r3369 r3373  
    7171            $this->primary_link = $bp->loggedin_user->domain;
    7272
    73         /* If we have an existing ID, update the activity item, otherwise insert it. */
     73        // If we have an existing ID, update the activity item, otherwise insert it.
    7474        if ( $this->id )
    7575            $q = $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET user_id = %d, component = %s, type = %s, action = %s, content = %s, primary_link = %s, date_recorded = %s, item_id = %s, secondary_item_id = %s, hide_sitewide = %d WHERE id = %d", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->id );
     
    8787    }
    8888
    89     /* Static Functions */
    90 
    91     function get( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false ) {
    92         global $wpdb, $bp;
    93 
    94         /* Select conditions */
     89    // Static Functions
     90
     91    function get( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false, $exclude = false ) {
     92        global $wpdb, $bp;
     93
     94        // Select conditions
    9595        $select_sql = "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name";
    9696
    9797        $from_sql = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID";
    9898
    99         /* Where conditions */
     99        // Where conditions
    100100        $where_conditions = array();
    101101
    102         /* Searching */
     102        // Searching
    103103        if ( $search_terms ) {
    104104            $search_terms = $wpdb->escape( $search_terms );
     
    106106        }
    107107
    108         /* Filtering */
     108        // Filtering
    109109        if ( $filter && $filter_sql = BP_Activity_Activity::get_filter_sql( $filter ) )
    110110            $where_conditions['filter_sql'] = $filter_sql;
    111111
    112         /* Sorting */
     112        // Sorting
    113113        if ( $sort != 'ASC' && $sort != 'DESC' )
    114114            $sort = 'DESC';
    115115
    116         /* Hide Hidden Items? */
     116        // Hide Hidden Items?
    117117        if ( !$show_hidden )
    118118            $where_conditions['hidden_sql'] = "a.hide_sitewide = 0";
    119119
    120         /* Alter the query based on whether we want to show activity item comments in the stream like normal comments or threaded below the activity */
     120        // Exclude specified items
     121        if ( $exclude )
     122            $where_conditions['exclude'] = "a.id NOT IN ({$exclude})";
     123
     124        // Alter the query based on whether we want to show activity item comments in the stream like normal comments or threaded below the activity
    121125        if ( !$display_comments || 'threaded' == $display_comments ) {
    122126            $where_conditions[] = "a.type != 'activity_comment'";
     
    134138        $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(a.id) FROM {$bp->activity->table_name} a {$where_sql} ORDER BY a.date_recorded {$sort}" ) );
    135139
    136         /* Get the fullnames of users so we don't have to query in the loop */
     140        // Get the fullnames of users so we don't have to query in the loop
    137141        if ( bp_is_active( 'xprofile' ) && $activities ) {
    138142            foreach ( (array)$activities as $activity ) {
     
    161165            $activities = BP_Activity_Activity::append_comments( &$activities );
    162166
    163         /* If $max is set, only return up to the max results */
     167        // If $max is set, only return up to the max results
    164168        if ( !empty( $max ) ) {
    165169            if ( (int)$total_activities > (int)$max )
     
    194198            $activities = BP_Activity_Activity::append_comments( $activities );
    195199
    196         /* If $max is set, only return up to the max results */
     200        // If $max is set, only return up to the max results
    197201        if ( !empty( $max ) ) {
    198202            if ( (int)$total_activities > (int)$max )
  • trunk/bp-activity/bp-activity-templatetags.php

    r3369 r3373  
    1616    var $full_name;
    1717
    18     function bp_activity_template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden ) {
     18    function bp_activity_template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden, $exclude ) {
    1919        global $bp;
    2020
     
    3333        // Fetch all activity items
    3434        else
    35             $this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden ) );
     35            $this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden, 'exclude' => $exclude ) );
    3636
    3737        if ( !$max || $max >= (int)$this->activities['total'] )
     
    143143    $user_id = false;
    144144    $include = false;
     145    $exclude = false;
    145146    $show_hidden = false;
    146147    $object = false;
     
    167168    $defaults = array(
    168169        'display_comments' => 'threaded', // false for none, stream/threaded - show comments in the stream or threaded under items
    169         'include' => $include, // pass an activity_id or string of ID's comma separated
     170        'include' => $include, // pass an activity_id or string of IDs comma-separated
     171        'exclude' => $exclude, // pass an activity_id or string of IDs comma-separated
    170172        'sort' => 'DESC', // sort DESC or ASC
    171173        'page' => 1, // which page to load
     
    255257        $filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id );
    256258
    257     $activities_template = new BP_Activity_Template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden );
     259    $activities_template = new BP_Activity_Template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden, $exclude );
    258260
    259261    return apply_filters( 'bp_has_activities', $activities_template->has_activities(), &$activities_template );
Note: See TracChangeset for help on using the changeset viewer.