Skip to:
Content

BuddyPress.org

Changeset 9406


Ignore:
Timestamp:
01/28/2015 10:50:33 PM (11 years ago)
Author:
johnjamesjacoby
Message:

Move $user_id abstraction out of bp_get_activities() and into their respective scope filters.

This fixes a regression from Activity Query scope improvements causing private and hidden group activity queries to intersect with user ID's, resulting in unexpected activity stream items being displayed.

Tests included in r9405.

Props r-a-y. Fixes #6169.

Location:
trunk/src
Files:
4 edited

Legend:

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

    r9372 r9406  
    640640add_filter( 'bp_core_get_js_strings', 'bp_activity_heartbeat_strings', 10, 1 );
    641641
    642 /** SCOPES **************************************************************/
     642/** Scopes ********************************************************************/
    643643
    644644/**
     
    651651 * @return array
    652652 */
    653 function bp_activity_filter_just_me_scope( $retval, $filter ) {
     653function bp_activity_filter_just_me_scope( $retval = array(), $filter = array() ) {
     654
     655    // Determine the user_id
     656    if ( ! empty( $filter['user_id'] ) ) {
     657        $user_id = $filter['user_id'];
     658    } else {
     659        $user_id = bp_displayed_user_id()
     660            ? bp_displayed_user_id()
     661            : bp_loggedin_user_id();
     662    }
     663
     664    // Should we show all items regardless of sitewide visibility?
     665    $show_hidden = array();
     666    if ( ! empty( $user_id ) && $user_id !== bp_loggedin_user_id() ) {
     667        $show_hidden = array(
     668            'column' => 'hide_sitewide',
     669            'value'  => 0
     670        );
     671    }
     672
    654673    $retval = array(
    655         'column' => 'user_id',
    656         'value'  => $filter['user_id']
     674        'relation' => 'AND',
     675        array(
     676            'column' => 'user_id',
     677            'value'  => $filter['user_id']
     678        ),
     679        $show_hidden,
     680
     681        // overrides
     682        'override' => array(
     683            'display_comments' => 'stream',
     684            'filter'           => array( 'user_id' => 0 ),
     685            'show_hidden'      => true
     686        ),
    657687    );
    658 
    659     $retval['override']['display_comments'] = 'stream';
    660 
    661     // wipe out the user ID
    662     $retval['override']['filter']['user_id'] = 0;
    663688
    664689    return $retval;
     
    675700 * @return array
    676701 */
    677 function bp_activity_filter_favorites_scope( $retval, $filter ) {
    678     $favs = bp_activity_get_user_favorites( $filter['user_id'] );
     702function bp_activity_filter_favorites_scope( $retval = array(), $filter = array() ) {
     703
     704    // Determine the user_id
     705    if ( ! empty( $filter['user_id'] ) ) {
     706        $user_id = $filter['user_id'];
     707    } else {
     708        $user_id = bp_displayed_user_id()
     709            ? bp_displayed_user_id()
     710            : bp_loggedin_user_id();
     711    }
     712
     713    // Determine the favorites
     714    $favs = bp_activity_get_user_favorites( $user_id );
    679715    if ( empty( $favs ) ) {
    680716        $favs = array( 0 );
    681717    }
    682718
     719    // Should we show all items regardless of sitewide visibility?
     720    $show_hidden = array();
     721    if ( ! empty( $user_id ) && ( $user_id !== bp_loggedin_user_id() ) ) {
     722        $show_hidden = array(
     723            'column' => 'hide_sitewide',
     724            'value'  => 0
     725        );
     726    }
     727
    683728    $retval = array(
    684         'column'  => 'id',
    685         'compare' => 'IN',
    686         'value'   => (array) $favs
     729        'relation' => 'AND',
     730        array(
     731            'column'  => 'id',
     732            'compare' => 'IN',
     733            'value'   => (array) $favs
     734        ),
     735        $show_hidden,
     736
     737        // overrides
     738        'override' => array(
     739            'display_comments' => true,
     740            'filter'           => array( 'user_id' => 0 ),
     741            'show_hidden'      => true
     742        ),
    687743    );
    688     $retval['override']['display_comments']  = true;
    689 
    690     // wipe out the user ID
    691     $retval['override']['filter']['user_id'] = 0;
    692744
    693745    return $retval;
     
    705757 * @return array
    706758 */
    707 function bp_activity_filter_mentions_scope( $retval, $filter ) {
     759function bp_activity_filter_mentions_scope( $retval = array(), $filter = array() ) {
     760
    708761    // Are mentions disabled?
    709762    if ( ! bp_activity_do_mentions() ) {
     
    711764    }
    712765
     766    // Determine the user_id
     767    if ( ! empty( $filter['user_id'] ) ) {
     768        $user_id = $filter['user_id'];
     769    } else {
     770        $user_id = bp_displayed_user_id()
     771            ? bp_displayed_user_id()
     772            : bp_loggedin_user_id();
     773    }
     774
     775    // Should we show all items regardless of sitewide visibility?
     776    $show_hidden = array();
     777    if ( ! empty( $user_id ) && $user_id !== bp_loggedin_user_id() ) {
     778        $show_hidden = array(
     779            'column' => 'hide_sitewide',
     780            'value'  => 0
     781        );
     782    }
     783
    713784    $retval = array(
    714         'column'  => 'content',
    715         'compare' => 'LIKE',
    716 
    717         // Start search at @ symbol and stop search at closing tag delimiter.
    718         'value'   => '@' . bp_activity_get_user_mentionname( $filter['user_id'] ) . '<'
     785        'relation' => 'AND',
     786        array(
     787            'column'  => 'content',
     788            'compare' => 'LIKE',
     789
     790            // Start search at @ symbol and stop search at closing tag delimiter.
     791            'value'   => '@' . bp_activity_get_user_mentionname( $user_id ) . '<'
     792        ),
     793        $show_hidden,
     794
     795        // overrides
     796        'override' => array(
     797
     798            // clear search terms so 'mentions' scope works with other scopes
     799            'search_terms' => false,
     800
     801            'display_comments' => 'stream',
     802            'filter'           => array( 'user_id' => 0 ),
     803            'show_hidden'      => true
     804        ),
    719805    );
    720806
    721     // wipe out current search terms if any
    722     // this is so the 'mentions' scope can be combined with other scopes
    723     $retval['override']['search_terms'] = false;
    724 
    725     $retval['override']['display_comments'] = 'stream';
    726     $retval['override']['filter']['user_id'] = 0;
    727 
    728807    return $retval;
    729808}
  • trunk/src/bp-activity/bp-activity-template.php

    r9351 r9406  
    623623        $search_terms = $_REQUEST['s'];
    624624
    625     // Set some default arguments when using a scope
    626     if ( ! empty( $scope ) ) {
    627         // Determine which user ID applies
    628         if ( empty( $user_id ) ) {
    629             $user_id = bp_displayed_user_id() ? bp_displayed_user_id() : bp_loggedin_user_id();
    630         }
    631 
    632         // Should we show all items regardless of sitewide visibility?
    633         if ( ! empty( $user_id ) ) {
    634             $show_hidden = ( $user_id == bp_loggedin_user_id() ) ? 1 : 0;
    635         }
    636     }
    637 
    638625    // Do not exceed the maximum per page
    639626    if ( !empty( $max ) && ( (int) $per_page > (int) $max ) )
  • trunk/src/bp-friends/bp-friends-activity.php

    r9372 r9406  
    239239 * @return array
    240240 */
    241 function bp_friends_filter_activity_scope( $retval, $filter ) {
    242     $friends = friends_get_friend_user_ids( $filter['user_id'] );
    243 
     241function bp_friends_filter_activity_scope( $retval = array(), $filter = array() ) {
     242
     243    // Determine the user_id
     244    if ( ! empty( $filter['user_id'] ) ) {
     245        $user_id = $filter['user_id'];
     246    } else {
     247        $user_id = bp_displayed_user_id()
     248            ? bp_displayed_user_id()
     249            : bp_loggedin_user_id();
     250    }
     251
     252    // Determine friends of user
     253    $friends = friends_get_friend_user_ids( $user_id );
    244254    if ( empty( $friends ) ) {
    245255        $friends = array( 0 );
    246256    }
    247257
    248     $retval= array(
     258    $retval = array(
    249259        'relation' => 'AND',
    250260        array(
     
    253263            'value'   => (array) $friends
    254264        ),
     265
    255266        // we should only be able to view sitewide activity content for friends
    256267        array(
     
    258269            'value'  => 0
    259270        ),
     271
     272        // overrides
     273        'override' => array(
     274            'filter'      => array( 'user_id' => 0 ),
     275            'show_hidden' => true
     276        ),
    260277    );
    261 
    262     // wipe out the user ID
    263     $retval['override']['filter']['user_id'] = 0;
    264 
    265     // make sure we aren't limiting items by 'hide_sitewide' since we're already
    266     // limiting it above
    267     $retval['override']['show_hidden'] = true;
    268278
    269279    return $retval;
     
    282292 * @return array
    283293 */
    284 function bp_friends_filter_activity_just_me_scope( $retval, $filter ) {
     294function bp_friends_filter_activity_just_me_scope( $retval = array(), $filter = array() ) {
     295
     296    // Determine the user_id
     297    if ( ! empty( $filter['user_id'] ) ) {
     298        $user_id = $filter['user_id'];
     299    } else {
     300        $user_id = bp_displayed_user_id()
     301            ? bp_displayed_user_id()
     302            : bp_loggedin_user_id();
     303    }
     304
    285305    // Get the requested action
    286306    $action = $filter['filter']['action'];
     
    294314
    295315    /**
    296      * If filtering activities for something other than the friendship_created action
    297      * return without changing anything
     316     * If filtering activities for something other than the friendship_created
     317     * action return without changing anything
    298318     */
    299319    if ( ! empty( $action ) && ! isset( $action['friendship_created'] ) ) {
    300320        return $retval;
     321    }
     322
     323    // Juggle existing override value
     324    $override = array();
     325    if ( ! empty( $retval['override'] ) ) {
     326        $override = $retval['override'];
     327        unset( $retval['override'] );
    301328    }
    302329
     
    306333     * - user has been requested a friendship
    307334     */
    308     return array(
     335    $retval = array(
    309336        'relation' => 'OR',
    310         array(
    311             'column' => 'user_id',
    312             'value'  => $filter['user_id']
    313         ),
     337        $retval,
    314338        array(
    315339            'relation' => 'AND',
     
    320344            array(
    321345                'column' => 'secondary_item_id',
    322                 'value'  => $filter['user_id'],
     346                'value'  => $user_id,
    323347            ),
    324         ),
    325         'override' => array(
    326             'display_comments' => 'stream',
    327             'filter'           => array( 'user_id' => 0 ),
    328         ),
     348        )
    329349    );
     350
     351    // Juggle back override value
     352    if ( ! empty( $override ) ) {
     353        $retval['override'] = $override;
     354    }
     355
     356    return $retval;
    330357}
    331358add_filter( 'bp_activity_set_just-me_scope_args', 'bp_friends_filter_activity_just_me_scope', 20, 2 );
  • trunk/src/bp-groups/bp-groups-activity.php

    r9372 r9406  
    243243 * @return array
    244244 */
    245 function bp_groups_filter_activity_scope( $retval, $filter ) {
    246     $groups = groups_get_user_groups( $filter['user_id'] );
    247 
     245function bp_groups_filter_activity_scope( $retval = array(), $filter = array() ) {
     246
     247    // Determine the user_id
     248    if ( ! empty( $filter['user_id'] ) ) {
     249        $user_id = $filter['user_id'];
     250    } else {
     251        $user_id = bp_displayed_user_id()
     252            ? bp_displayed_user_id()
     253            : bp_loggedin_user_id();
     254    }
     255
     256    // Determine groups of user
     257    $groups = groups_get_user_groups( $user_id );
    248258    if ( empty( $groups['groups'] ) ) {
    249259        $groups = array( 'groups' => 0 );
    250260    }
    251261
    252     $retval= array(
     262    // Should we show all items regardless of sitewide visibility?
     263    $show_hidden = array();
     264    if ( ! empty( $user_id ) && ( $user_id !== bp_loggedin_user_id() ) ) {
     265        $show_hidden = array(
     266            'column' => 'hide_sitewide',
     267            'value'  => 0
     268        );
     269    }
     270
     271    $retval = array(
    253272        'relation' => 'AND',
    254273        array(
    255             'column' => 'component',
    256             'value'  => buddypress()->groups->id
     274            'relation' => 'AND',
     275            array(
     276                'column' => 'component',
     277                'value'  => buddypress()->groups->id
     278            ),
     279            array(
     280                'column'  => 'item_id',
     281                'compare' => 'IN',
     282                'value'   => (array) $groups['groups']
     283            ),
    257284        ),
    258         array(
    259             'column'  => 'item_id',
    260             'compare' => 'IN',
    261             'value'   => (array) $groups['groups']
     285        $show_hidden,
     286
     287        // overrides
     288        'override' => array(
     289            'filter'      => array( 'user_id' => 0 ),
     290            'show_hidden' => true
    262291        ),
    263292    );
    264 
    265     // wipe out the user ID
    266     $retval['override']['filter']['user_id'] = 0;
    267293
    268294    return $retval;
Note: See TracChangeset for help on using the changeset viewer.