Skip to:
Content

BuddyPress.org

Ticket #4062: 4062.2.diff

File 4062.2.diff, 4.9 KB (added by boonebgorges, 8 years ago)
  • src/bp-activity/bp-activity-functions.php

    diff --git src/bp-activity/bp-activity-functions.php src/bp-activity/bp-activity-functions.php
    index e52c6d476..1e8615db7 100644
    function bp_activity_get_types() { 
    839839        return apply_filters( 'bp_activity_get_types', $actions );
    840840}
    841841
     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;
     897}
     898
    842899/** Favorites ****************************************************************/
    843900
    844901/**
  • src/bp-activity/bp-activity-template.php

    diff --git src/bp-activity/bp-activity-template.php src/bp-activity/bp-activity-template.php
    index cef887221..373677815 100644
    function bp_activity_show_filters( $context = '' ) { 
    38003800         * @return string HTML for <option> values.
    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';
    3822                         }
    3823                 }
    3824 
    38253803                $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'];
     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';
    38413809                        }
     3810
     3811                        $filters[ $action['key'] ] = $action['label'];
    38423812                }
    38433813
    38443814                /**
  • src/bp-templates/bp-legacy/buddypress-functions.php

    diff --git src/bp-templates/bp-legacy/buddypress-functions.php src/bp-templates/bp-legacy/buddypress-functions.php
    index 0ea62de07..1be372368 100644
    function bp_legacy_theme_ajax_querystring( $query_string, $object ) { 
    687687
    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
    694699        if ( ! empty( $_BP_COOKIE['bp-' . $object . '-scope'] ) ) {