Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/22/2014 09:46:50 PM (10 years ago)
Author:
r-a-y
Message:

Activity: Support multiple scopes in bp_has_activities().

This commit:

  • Allows the 'scope' parameter to support multiple scopes. For example, scope=friends,mentions. This can be a comma-delimited string or an array.
  • Makes the 'scope' parameter available across the bp_has_activities() stack. Previously, 'scope' was only available for use in the bp_has_activities() loop.
  • Parses scopes using the BP_Activity_Query class to handle complex conditions.
  • Allows components to declare their own custom activity scopes. Components can also override existing activity arguments by setting the 'override' key in their scope callback. For an example, see how the friends component declares the 'friends' scope in bp_friends_filter_activity_scope(). Previously, it was not possible for components or third-party plugins to declare their own scopes without doing a fair bit of workarounds.

See #4988.

File:
1 edited

Legend:

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

    r9256 r9257  
    202202            'in'                => false,
    203203            'filter'            => false,
     204            'scope'             => false,
    204205            'search_terms'      => false,
    205206            'meta_query'        => false,
     
    253254                'filter_query'      => $filter_query,
    254255                'filter'            => $filter,
     256                'scope'             => $scope,
    255257                'show_hidden'       => $show_hidden,
    256258                'exclude'           => $exclude,
     
    614616    }
    615617
     618    // Search terms
    616619    if ( empty( $search_terms ) && ! empty( $_REQUEST['s'] ) )
    617620        $search_terms = $_REQUEST['s'];
    618621
    619     // If you have passed a "scope" then this will override any filters you have passed.
    620     if ( 'just-me' == $scope || 'friends' == $scope || 'groups' == $scope || 'favorites' == $scope || 'mentions' == $scope ) {
    621         if ( 'just-me' == $scope )
    622             $display_comments = 'stream';
    623 
    624         // determine which user_id applies
    625         if ( empty( $user_id ) )
     622    // Set some default arguments when using a scope
     623    if ( ! empty( $scope ) ) {
     624        // Determine which user ID applies
     625        if ( empty( $user_id ) ) {
    626626            $user_id = bp_displayed_user_id() ? bp_displayed_user_id() : bp_loggedin_user_id();
    627 
    628         // are we displaying user specific activity?
    629         if ( is_numeric( $user_id ) ) {
    630             $show_hidden = ( $user_id == bp_loggedin_user_id() && $scope != 'friends' ) ? 1 : 0;
    631 
    632             switch ( $scope ) {
    633                 case 'friends':
    634                     if ( bp_is_active( 'friends' ) )
    635                         $friends = friends_get_friend_user_ids( $user_id );
    636                         if ( empty( $friends ) )
    637                             return false;
    638 
    639                         $user_id = implode( ',', (array) $friends );
    640                     break;
    641                 case 'groups':
    642                     if ( bp_is_active( 'groups' ) ) {
    643                         $groups = groups_get_user_groups( $user_id );
    644                         if ( empty( $groups['groups'] ) )
    645                             return false;
    646 
    647                         $object = $bp->groups->id;
    648                         $primary_id = implode( ',', (array) $groups['groups'] );
    649 
    650                         $user_id = 0;
    651                     }
    652                     break;
    653                 case 'favorites':
    654                     $favs = bp_activity_get_user_favorites( $user_id );
    655                     if ( empty( $favs ) )
    656                         return false;
    657 
    658                     $in = implode( ',', (array) $favs );
    659                     $display_comments = true;
    660                     $user_id = 0;
    661                     break;
    662                 case 'mentions':
    663 
    664                     // Are mentions disabled?
    665                     if ( ! bp_activity_do_mentions() ) {
    666                         return false;
    667                     }
    668 
    669                     // Start search at @ symbol and stop search at closing tag delimiter.
    670                     $search_terms     = '@' . bp_activity_get_user_mentionname( $user_id ) . '<';
    671                     $display_comments = 'stream';
    672                     $user_id = 0;
    673                     break;
    674             }
     627        }
     628
     629        // Should we show all items regardless of sitewide visibility?
     630        if ( ! empty( $user_id ) ) {
     631            $show_hidden = ( $user_id == bp_loggedin_user_id() ) ? 1 : 0;
    675632        }
    676633    }
     
    713670        'in'                => $in,
    714671        'filter'            => $filter,
     672        'scope'             => $scope,
    715673        'search_terms'      => $search_terms,
    716674        'meta_query'        => $meta_query,
Note: See TracChangeset for help on using the changeset viewer.