Skip to:
Content

BuddyPress.org

Changeset 8428


Ignore:
Timestamp:
05/16/2014 01:05:35 PM (10 years ago)
Author:
boonebgorges
Message:

Introduce bp_activity_show_filters(), and use it for generating dynamic activity filter dropdowns

Activity filter dropdowns were previously hardcoded into templates, with
template-specific hooks for plugins to add their own filter values. This
resulted in an inconsistent and awkward process of maintaining filter lists
between components. The new method introduces new parameters to bp_activity_set_action():
$context (an array of the contexts in which the filter should appear) and
$label (the text that should be used when generating the <option> markup). The
new function bp_activity_show_filter() is then used in the templates to
generate a dynamic list of <option> markup, based on the values registered by
the activity types.

Fixes #5637

Props imath

Location:
trunk/src
Files:
9 edited

Legend:

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

    r8237 r8428  
    276276 * @param string $description The action description.
    277277 * @param callable $format_callback Callback for formatting the action string.
     278 * @param string $label String to describe this action in the activity stream
     279 *        filter dropdown.
     280 * @param array $context Activity stream contexts where the filter should appear.
     281 *        'activity', 'member', 'member_groups', 'group'
    278282 * @return bool False if any param is empty, otherwise true.
    279283 */
    280 function bp_activity_set_action( $component_id, $type, $description, $format_callback = false ) {
     284function bp_activity_set_action( $component_id, $type, $description, $format_callback = false, $label = false, $context = array() ) {
    281285    $bp = buddypress();
    282286
     
    304308        'value'           => $description,
    305309        'format_callback' => $format_callback,
    306     ), $component_id, $type, $description, $format_callback );
     310        'label'           => $label,
     311        'context'         => $context,
     312    ), $component_id, $type, $description, $format_callback, $label, $context );
    307313
    308314    return true;
     
    836842        'activity_update',
    837843        __( 'Posted a status update', 'buddypress' ),
    838         'bp_activity_format_activity_action_activity_update'
     844        'bp_activity_format_activity_action_activity_update',
     845        __( 'Updates', 'buddypress' ),
     846        array( 'activity', 'group', 'member', 'member_groups' )
    839847    );
    840848
     
    843851        'activity_comment',
    844852        __( 'Replied to a status update', 'buddypress' ),
    845         'bp_activity_format_activity_action_activity_comment'
     853        'bp_activity_format_activity_action_activity_comment',
     854        __( 'Activity Comments', 'buddypress' )
    846855    );
    847856
  • trunk/src/bp-activity/bp-activity-template.php

    r8404 r8428  
    33723372}
    33733373add_action( 'bp_head', 'bp_activity_sitewide_feed' );
     3374
     3375/**
     3376 * Display available filters depending on the scope.
     3377 *
     3378 * @since BuddyPress (2.1.0)
     3379 *
     3380 * @param string $context The current context. 'activity', 'member',
     3381 *    'member_groups', 'group'.
     3382 * @uses bp_get_activity_show_filters()
     3383 */
     3384function bp_activity_show_filters( $context = '' ) {
     3385    echo bp_get_activity_show_filters( $context );
     3386}
     3387    /**
     3388     * Get available filters depending on the scope.
     3389     *
     3390     * @since BuddyPress (2.1.0)
     3391     *
     3392     * @param string $context The current context. 'activity', 'member',
     3393     *    'member_groups', 'group'
     3394     * @return string HTML for <option> values.
     3395     */
     3396    function bp_get_activity_show_filters( $context = '' ) {
     3397        // Set default context based on current page
     3398        if ( empty( $context ) ) {
     3399            if ( bp_is_user() ) {
     3400                switch ( bp_current_action() ) {
     3401                    case bp_get_groups_slug() :
     3402                        $context = 'member_groups';
     3403                        break;
     3404
     3405                    default :
     3406                        $context = 'member';
     3407                        break;
     3408                }
     3409            } else if ( bp_is_active( 'groups' ) && bp_is_group() ) {
     3410                $context = 'group';
     3411            } else {
     3412                $context = 'activity';
     3413            }
     3414        }
     3415
     3416        $filters = array();
     3417
     3418        // Walk through the registered actions, and prepare an the
     3419        // select box options.
     3420        foreach ( buddypress()->activity->actions as $actions ) {
     3421            foreach ( $actions as $action ) {
     3422                if ( ! in_array( $context, (array) $action['context'] ) ) {
     3423                    continue;
     3424                }
     3425
     3426                // Friends activity collapses two filters into one
     3427                if ( in_array( $action['key'], array( 'friendship_accepted', 'friendship_created' ) ) ) {
     3428                    $action['key'] = 'friendship_accepted,friendship_created';
     3429                }
     3430
     3431                $filters[ $action['key'] ] = $action['label'];
     3432            }
     3433        }
     3434
     3435        /**
     3436         * Modify the filter options available in the activity filter dropdown.
     3437         *
     3438         * @since BuddyPress (2.1.0)
     3439         *
     3440         * @param array $filters Array of filter options for the given
     3441         *        context, in the following format:
     3442         *            $option_value => $option_name
     3443         * @param string $context Context for the filter. 'activity'
     3444         *        'member', 'member_groups', 'group'.
     3445         */
     3446        $filters = apply_filters( 'bp_get_activity_show_filters', $filters, $context );
     3447
     3448        // Build the options output
     3449        $output = '';
     3450
     3451        if ( ! empty( $filters ) ) {
     3452            foreach ( $filters as $value => $filter ) {
     3453                $output .= '<option value="' . esc_attr( $value ) . '">' . esc_html( $filter ) . '</option>' . "\n";
     3454            }
     3455        }
     3456
     3457        return apply_filters( 'bp_get_activity_show_filters', $output, $filters, $context );
     3458    }
  • trunk/src/bp-blogs/bp-blogs-activity.php

    r8345 r8428  
    3333            'new_blog',
    3434            __( 'New site created', 'buddypress' ),
    35             'bp_blogs_format_activity_action_new_blog'
     35            'bp_blogs_format_activity_action_new_blog',
     36            __( 'New Sites', 'buddypress' )
    3637        );
    3738    }
     
    4142        'new_blog_post',
    4243        __( 'New post published', 'buddypress' ),
    43         'bp_blogs_format_activity_action_new_blog_post'
     44        'bp_blogs_format_activity_action_new_blog_post',
     45        __( 'Posts', 'buddypress' ),
     46        array( 'activity', 'member' )
    4447    );
    4548
     
    4851        'new_blog_comment',
    4952        __( 'New post comment posted', 'buddypress' ),
    50         'bp_blogs_format_activity_action_new_blog_comment'
     53        'bp_blogs_format_activity_action_new_blog_comment',
     54        __( 'Comments', 'buddypress' ),
     55        array( 'activity', 'member' )
    5156    );
    5257
  • trunk/src/bp-friends/bp-friends-activity.php

    r8259 r8428  
    9797        'friendship_accepted',
    9898        __( 'Friendships accepted', 'buddypress' ),
    99         'bp_friends_format_activity_action_friendship_accepted'
     99        'bp_friends_format_activity_action_friendship_accepted',
     100        __( 'Friendships', 'buddypress' ),
     101        array( 'activity', 'member' )
    100102    );
    101103
     
    104106        'friendship_created',
    105107        __( 'New friendships', 'buddypress' ),
    106         'bp_friends_format_activity_action_friendship_created'
     108        'bp_friends_format_activity_action_friendship_created',
     109        __( 'Friendships', 'buddypress' ),
     110        array( 'activity', 'member' )
    107111    );
    108112
  • trunk/src/bp-groups/bp-groups-activity.php

    r8259 r8428  
    2828        'created_group',
    2929        __( 'Created a group', 'buddypress' ),
    30         'bp_groups_format_activity_action_created_group'
     30        'bp_groups_format_activity_action_created_group',
     31        __( 'New Groups', 'buddypress' ),
     32        array( 'activity', 'member', 'member_groups' )
    3133    );
    3234
     
    3537        'joined_group',
    3638        __( 'Joined a group', 'buddypress' ),
    37         'bp_groups_format_activity_action_joined_group'
     39        'bp_groups_format_activity_action_joined_group',
     40        __( 'Group Memberships', 'buddypress' ),
     41        array( 'activity', 'group', 'member', 'member_groups' )
    3842    );
    3943
     
    4246    // check for the legacy forums loader class to be extra cautious
    4347    if ( bp_is_active( 'forums' ) && class_exists( 'BP_Forums_Component' ) ) {
    44         bp_activity_set_action( $bp->groups->id, 'new_forum_topic', __( 'New group forum topic', 'buddypress' ) );
    45         bp_activity_set_action( $bp->groups->id, 'new_forum_post',  __( 'New group forum post',  'buddypress' ) );
     48        bp_activity_set_action(
     49            $bp->groups->id,
     50            'new_forum_topic',
     51            __( 'New group forum topic', 'buddypress' ),
     52            false,
     53            __( 'Forum Topics', 'buddypress' ),
     54            array( 'activity', 'group', 'member', 'member_groups' )
     55        );
     56
     57        bp_activity_set_action(
     58            $bp->groups->id,
     59            'new_forum_post',
     60            __( 'New group forum post',  'buddypress' ),
     61            false,
     62            __( 'Forum Replies', 'buddypress' ),
     63            array( 'activity', 'group', 'member', 'member_groups' )
     64        );
    4665    }
    4766
  • trunk/src/bp-templates/bp-legacy/buddypress/activity/index.php

    r7965 r8428  
    7777                <select id="activity-filter-by">
    7878                    <option value="-1"><?php _e( 'Everything', 'buddypress' ); ?></option>
    79                     <option value="activity_update"><?php _e( 'Updates', 'buddypress' ); ?></option>
    8079
    81                     <?php if ( bp_is_active( 'blogs' ) ) : ?>
    82 
    83                         <option value="new_blog_post"><?php _e( 'Posts', 'buddypress' ); ?></option>
    84                         <option value="new_blog_comment"><?php _e( 'Comments', 'buddypress' ); ?></option>
    85 
    86                     <?php endif; ?>
    87 
    88                     <?php if ( bp_is_active( 'forums' ) ) : ?>
    89 
    90                         <option value="new_forum_topic"><?php _e( 'Forum Topics', 'buddypress' ); ?></option>
    91                         <option value="new_forum_post"><?php _e( 'Forum Replies', 'buddypress' ); ?></option>
    92 
    93                     <?php endif; ?>
    94 
    95                     <?php if ( bp_is_active( 'groups' ) ) : ?>
    96 
    97                         <option value="created_group"><?php _e( 'New Groups', 'buddypress' ); ?></option>
    98                         <option value="joined_group"><?php _e( 'Group Memberships', 'buddypress' ); ?></option>
    99 
    100                     <?php endif; ?>
    101 
    102                     <?php if ( bp_is_active( 'friends' ) ) : ?>
    103 
    104                         <option value="friendship_accepted,friendship_created"><?php _e( 'Friendships', 'buddypress' ); ?></option>
    105 
    106                     <?php endif; ?>
    107 
    108                     <option value="new_member"><?php _e( 'New Members', 'buddypress' ); ?></option>
     80                    <?php bp_activity_show_filters(); ?>
    10981
    11082                    <?php do_action( 'bp_activity_filter_options' ); ?>
  • trunk/src/bp-templates/bp-legacy/buddypress/groups/single/activity.php

    r7965 r8428  
    66
    77        <li id="activity-filter-select" class="last">
    8             <label for="activity-filter-by"><?php _e( 'Show:', 'buddypress' ); ?></label> 
     8            <label for="activity-filter-by"><?php _e( 'Show:', 'buddypress' ); ?></label>
    99            <select id="activity-filter-by">
    1010                <option value="-1"><?php _e( 'Everything', 'buddypress' ); ?></option>
    11                 <option value="activity_update"><?php _e( 'Updates', 'buddypress' ); ?></option>
    1211
    13                 <?php if ( bp_is_active( 'forums' ) ) : ?>
    14                     <option value="new_forum_topic"><?php _e( 'Forum Topics', 'buddypress' ); ?></option>
    15                     <option value="new_forum_post"><?php _e( 'Forum Replies', 'buddypress' ); ?></option>
    16                 <?php endif; ?>
    17 
    18                 <option value="joined_group"><?php _e( 'Group Memberships', 'buddypress' ); ?></option>
     12                <?php bp_activity_show_filters( 'group' ); ?>
    1913
    2014                <?php do_action( 'bp_group_activity_filter_options' ); ?>
  • trunk/src/bp-templates/bp-legacy/buddypress/members/single/activity.php

    r6284 r8428  
    1919            <select id="activity-filter-by">
    2020                <option value="-1"><?php _e( 'Everything', 'buddypress' ); ?></option>
    21                 <option value="activity_update"><?php _e( 'Updates', 'buddypress' ); ?></option>
    2221
    23                 <?php
    24                 if ( !bp_is_current_action( 'groups' ) ) :
    25                     if ( bp_is_active( 'blogs' ) ) : ?>
     22                <?php bp_activity_show_filters(); ?>
    2623
    27                         <option value="new_blog_post"><?php _e( 'Posts', 'buddypress' ); ?></option>
    28                         <option value="new_blog_comment"><?php _e( 'Comments', 'buddypress' ); ?></option>
    29 
    30                     <?php
    31                     endif;
    32 
    33                     if ( bp_is_active( 'friends' ) ) : ?>
    34 
    35                         <option value="friendship_accepted,friendship_created"><?php _e( 'Friendships', 'buddypress' ); ?></option>
    36 
    37                     <?php endif;
    38 
    39                 endif;
    40 
    41                 if ( bp_is_active( 'forums' ) ) : ?>
    42 
    43                     <option value="new_forum_topic"><?php _e( 'Forum Topics', 'buddypress' ); ?></option>
    44                     <option value="new_forum_post"><?php _e( 'Forum Replies', 'buddypress' ); ?></option>
    45 
    46                 <?php endif;
    47 
    48                 if ( bp_is_active( 'groups' ) ) : ?>
    49 
    50                     <option value="created_group"><?php _e( 'New Groups', 'buddypress' ); ?></option>
    51                     <option value="joined_group"><?php _e( 'Group Memberships', 'buddypress' ); ?></option>
    52 
    53                 <?php endif;
    54 
    55                 do_action( 'bp_member_activity_filter_options' ); ?>
     24                <?php do_action( 'bp_member_activity_filter_options' ); ?>
    5625
    5726            </select>
  • trunk/src/bp-xprofile/bp-xprofile-activity.php

    r8306 r8428  
    2222        // see r4273
    2323        'profile',
    24 
    2524        'new_avatar',
    2625        __( 'Member changed profile picture', 'buddypress' ),
    27         'bp_xprofile_format_activity_action_new_avatar'
     26        'bp_xprofile_format_activity_action_new_avatar',
     27        __( 'Updated Avatars', 'buddypress' )
    2828    );
    2929
     
    3232        'new_member',
    3333        __( 'New member registered', 'buddypress' ),
    34         'bp_xprofile_format_activity_action_new_member'
     34        'bp_xprofile_format_activity_action_new_member',
     35        __( 'New Members', 'buddypress' ),
     36        array( 'activity' )
    3537    );
    3638
     
    3941        'updated_profile',
    4042        __( 'Updated Profile', 'buddypress' ),
    41         'bp_xprofile_format_activity_action_updated_profile'
     43        'bp_xprofile_format_activity_action_updated_profile',
     44        __( 'Profile Updates', 'buddypress' ),
     45        array( 'activity' )
    4246    );
    4347
     
    310314 *
    311315 * @since BuddyPress (2.0.0)
     316 * @todo Mark as deprecated
    312317 */
    313318function xprofile_activity_filter_options() {
     
    318323    <?php
    319324}
    320 add_action( 'bp_activity_filter_options', 'xprofile_activity_filter_options' );
Note: See TracChangeset for help on using the changeset viewer.