Skip to:
Content

BuddyPress.org

Changeset 11356


Ignore:
Timestamp:
12/29/2016 07:38:58 PM (8 years ago)
Author:
boonebgorges
Message:

Discard activity filter values that are invalid for the current context.

Activity filters are stored in a cookie that persists across
activity pages. But some filter values are not valid in all contexts,
such as new_member (valid in the sitewide feed, but not in a group).
This changeset ensures that filter values sent via AJAX are discarded
if they aren't valid in the current context.

Props lakrisgubben.
Fixes #4062.

Location:
trunk
Files:
1 added
3 edited

Legend:

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

    r11351 r11356  
    838838     */
    839839    return apply_filters( 'bp_activity_get_types', $actions );
     840}
     841
     842/**
     843 * Gets the current activity context.
     844 *
     845 * The "context" is the current view type, corresponding roughly to the
     846 * current component. Use this context to determine which activity actions
     847 * should be whitelisted for the filter dropdown.
     848 *
     849 * @since 2.8.0
     850 *
     851 * @return string Activity context. 'member', 'member_groups', 'group', 'activity'.
     852 */
     853function bp_activity_get_current_context() {
     854    // On member pages, default to 'member', unless this is a user's Groups activity.
     855    if ( bp_is_user() ) {
     856        if ( bp_is_active( 'groups' ) && bp_is_current_action( bp_get_groups_slug() ) ) {
     857            $context = 'member_groups';
     858        } else {
     859            $context = 'member';
     860        }
     861
     862    // On individual group pages, default to 'group'.
     863    } elseif ( bp_is_active( 'groups' ) && bp_is_group() ) {
     864        $context = 'group';
     865
     866    // 'activity' everywhere else.
     867    } else {
     868        $context = 'activity';
     869    }
     870
     871    return $context;
     872}
     873
     874/**
     875 * Gets a flat list of activity actions compatible with a given context.
     876 *
     877 * @since 2.8.0
     878 *
     879 * @param string $context Optional. Name of the context. Defaults to the current context.
     880 * @return array
     881 */
     882function bp_activity_get_actions_for_context( $context = '' ) {
     883    if ( ! $context ) {
     884        $context = bp_activity_get_current_context();
     885    }
     886
     887    $actions = array();
     888    foreach ( bp_activity_get_actions() as $component_actions ) {
     889        foreach ( $component_actions as $component_action ) {
     890            if ( in_array( $context, (array) $component_action['context'], true ) ) {
     891                $actions[] = $component_action;
     892            }
     893        }
     894    }
     895
     896    return $actions;
    840897}
    841898
  • trunk/src/bp-activity/bp-activity-template.php

    r11351 r11356  
    38013801     */
    38023802    function bp_get_activity_show_filters( $context = '' ) {
    3803         // Set default context based on current page.
    3804         if ( empty( $context ) ) {
    3805 
    3806             // On member pages, default to 'member', unless this
    3807             // is a user's Groups activity.
    3808             if ( bp_is_user() ) {
    3809                 if ( bp_is_active( 'groups' ) && bp_is_current_action( bp_get_groups_slug() ) ) {
    3810                     $context = 'member_groups';
    3811                 } else {
    3812                     $context = 'member';
    3813                 }
    3814 
    3815             // On individual group pages, default to 'group'.
    3816             } elseif ( bp_is_active( 'groups' ) && bp_is_group() ) {
    3817                 $context = 'group';
    3818 
    3819             // 'activity' everywhere else.
    3820             } else {
    3821                 $context = 'activity';
     3803        $filters = array();
     3804        $actions = bp_activity_get_actions_for_context( $context );
     3805        foreach ( $actions as $action ) {
     3806            // Friends activity collapses two filters into one.
     3807            if ( in_array( $action['key'], array( 'friendship_accepted', 'friendship_created' ) ) ) {
     3808                $action['key'] = 'friendship_accepted,friendship_created';
    38223809            }
    3823         }
    3824 
    3825         $filters = array();
    3826 
    3827         // Walk through the registered actions, and prepare an the
    3828         // select box options.
    3829         foreach ( bp_activity_get_actions() as $actions ) {
    3830             foreach ( $actions as $action ) {
    3831                 if ( ! in_array( $context, (array) $action['context'] ) ) {
    3832                     continue;
    3833                 }
    3834 
    3835                 // Friends activity collapses two filters into one.
    3836                 if ( in_array( $action['key'], array( 'friendship_accepted', 'friendship_created' ) ) ) {
    3837                     $action['key'] = 'friendship_accepted,friendship_created';
    3838                 }
    3839 
    3840                 $filters[ $action['key'] ] = $action['label'];
    3841             }
     3810
     3811            $filters[ $action['key'] ] = $action['label'];
    38423812        }
    38433813
  • trunk/src/bp-templates/bp-legacy/buddypress-functions.php

    r11351 r11356  
    688688    // Activity stream filtering on action.
    689689    if ( ! empty( $_BP_COOKIE['bp-' . $object . '-filter'] ) && '-1' != $_BP_COOKIE['bp-' . $object . '-filter'] ) {
    690         $qs[] = 'type='   . $_BP_COOKIE['bp-' . $object . '-filter'];
    691         $qs[] = 'action=' . $_BP_COOKIE['bp-' . $object . '-filter'];
     690        $actions = bp_activity_get_actions_for_context();
     691        foreach ( $actions as $action ) {
     692            if ( $action['key'] === $_BP_COOKIE['bp-' . $object . '-filter'] ) {
     693                $qs[] = 'type='   . $_BP_COOKIE['bp-' . $object . '-filter'];
     694                $qs[] = 'action=' . $_BP_COOKIE['bp-' . $object . '-filter'];
     695            }
     696        }
    692697    }
    693698
Note: See TracChangeset for help on using the changeset viewer.