Skip to:
Content

BuddyPress.org

Changeset 3317


Ignore:
Timestamp:
10/27/2010 03:48:30 PM (16 years ago)
Author:
boonebgorges
Message:

Adds default state selector for Members and Groups widgets. Fixes #1177

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-widgets.php

    r3300 r3317  
    1919        }
    2020
    21         function widget($args, $instance) {
     21        function widget( $args, $instance ) {
    2222                global $bp;
    2323
    2424                extract( $args );
     25
     26                if ( !$instance['member_default'] )
     27                        $instance['member_default'] = 'active';
    2528
    2629                echo $before_widget;
    … …  
    2932                   . $after_title; ?>
    3033
    31                 <?php if ( bp_has_members( 'user_id=0&type=newest&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
     34                <?php if ( bp_has_members( 'user_id=0&type=' . $instance['member_default'] . '&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
    3235                        <div class="item-options" id="members-list-options">
    3336                                <span class="ajax-loader" id="ajax-loader-members"></span>
    34                                 <a href="<?php echo site_url() . '/' . BP_MEMBERS_SLUG ?>" id="newest-members" class="selected"><?php _e( 'Newest', 'buddypress' ) ?></a>
    35                                 |  <a href="<?php echo site_url() . '/' . BP_MEMBERS_SLUG ?>" id="recently-active-members"><?php _e( 'Active', 'buddypress' ) ?></a>
     37                                <a href="<?php echo site_url() . '/' . $bp->members->slug ?>" id="newest-members" <?php if ( $instance['member_default'] == 'newest' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Newest', 'buddypress' ) ?></a>
     38                                |  <a href="<?php echo site_url() . '/' . $bp->members->slug ?>" id="recently-active-members" <?php if ( $instance['member_default'] == 'active' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Active', 'buddypress' ) ?></a>
    3639
    3740                                <?php if ( bp_is_active( 'friends' ) ) : ?>
    3841
    39                                         | <a href="<?php echo site_url() . '/' . BP_MEMBERS_SLUG ?>" id="popular-members"><?php _e( 'Popular', 'buddypress' ) ?></a>
     42                                        | <a href="<?php echo site_url() . '/' . $bp->members->slug ?>" id="popular-members" <?php if ( $instance['member_default'] == 'popular' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Popular', 'buddypress' ) ?></a>
    4043
    4144                                <?php endif; ?>
    … …  
    5255                                                <div class="item">
    5356                                                        <div class="item-title fn"><a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_name() ?></a></div>
    54                                                         <div class="item-meta"><span class="activity"><?php bp_member_registered() ?></span></div>
     57                                                        <div class="item-meta">
     58                                                                <span class="activity">
     59                                                                <?php
     60                                                                        if ( 'newest' == $instance['member_default'] )
     61                                                                                bp_member_registered();                                                         
     62                                                                        if ( 'active' == $instance['member_default'] )
     63                                                                                bp_member_last_active();
     64                                                                        if ( 'popular' == $instance['member_default'] )
     65                                                                                bp_member_total_friend_count();
     66                                                                ?>
     67                                                                </span>
     68                                                        </div>
    5569                                                </div>
    5670                                        </li>
    … …  
    7690                $instance = $old_instance;
    7791                $instance['max_members'] = strip_tags( $new_instance['max_members'] );
     92                $instance['member_default'] = strip_tags( $new_instance['member_default'] );
    7893
    7994                return $instance;
    … …  
    8196
    8297        function form( $instance ) {
    83                 $instance = wp_parse_args( (array) $instance, array( 'max_members' => 5 ) );
     98                $instance = wp_parse_args( (array) $instance, array( 'max_members' => 5, 'member_default' => 'active' ) );
    8499                $max_members = strip_tags( $instance['max_members'] );
     100                $member_default = strip_tags( $instance['member_default'] );
    85101                ?>
    86102
    87                 <p><label for="bp-core-widget-members-max"><?php _e('Max Members to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo esc_attr( $max_members ); ?>" style="width: 30%" /></label></p>
     103                <p><label for="bp-core-widget-members-max"><?php _e('Max members to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo esc_attr( $max_members ); ?>" style="width: 30%" /></label></p>
     104                               
     105                <p>
     106                        <label for="bp-core-widget-groups-default"><?php _e('Default members to show:', 'buddypress'); ?>
     107                        <select name="<?php echo $this->get_field_name( 'member_default' ) ?>">
     108                                <option value="newest" <?php if ( $member_default == 'newest' ) : ?>selected="selected"<?php endif; ?>><?php _e( 'Newest', 'buddypress' ) ?></option>
     109                                <option value="active" <?php if ( $member_default == 'active' ) : ?>selected="selected"<?php endif; ?>><?php _e( 'Active', 'buddypress' ) ?></option>
     110                                <option value="popular"  <?php if ( $member_default == 'popular' ) : ?>selected="selected"<?php endif; ?>><?php _e( 'Popular', 'buddypress' ) ?></option>
     111                        </select>                       
     112                        </label>
     113                </p>
     114       
    88115        <?php
    89116        }
  • trunk/bp-groups/bp-groups-widgets.php

    r3300 r3317  
    1717        }
    1818
    19         function widget($args, $instance) {
     19        function widget( $args, $instance ) {
    2020                global $bp;
    2121
    2222            extract( $args );
     23
     24                if ( !$instance['group_default'] )
     25                        $instance['group_default'] = 'popular';
    2326
    2427                echo $before_widget;
    … …  
    2730                   . $after_title; ?>
    2831
    29                 <?php if ( bp_has_groups( 'type=popular&per_page=' . $instance['max_groups'] . '&max=' . $instance['max_groups'] ) ) : ?>
     32                <?php if ( bp_has_groups( 'type=' . $instance['group_default'] . '&max=' . $instance['max_groups'] ) ) : ?>
    3033                        <div class="item-options" id="groups-list-options">
    3134                                <span class="ajax-loader" id="ajax-loader-groups"></span>
    32                                 <a href="<?php echo site_url() . '/' . $bp->groups->slug ?>" id="newest-groups"><?php _e("Newest", 'buddypress') ?></a> |
    33                                 <a href="<?php echo site_url() . '/' . $bp->groups->slug ?>" id="recently-active-groups"><?php _e("Active", 'buddypress') ?></a> |
    34                                 <a href="<?php echo site_url() . '/' . $bp->groups->slug ?>" id="popular-groups" class="selected"><?php _e("Popular", 'buddypress') ?></a>
     35                                <a href="<?php echo site_url() . '/' . $bp->groups->slug ?>" id="newest-groups"<?php if ( $instance['group_default'] == 'newest' ) : ?> class="selected"<?php endif; ?>><?php _e("Newest", 'buddypress') ?></a> |
     36                                <a href="<?php echo site_url() . '/' . $bp->groups->slug ?>" id="recently-active-groups"<?php if ( $instance['group_default'] == 'active' ) : ?> class="selected"<?php endif; ?>><?php _e("Active", 'buddypress') ?></a> |
     37                                <a href="<?php echo site_url() . '/' . $bp->groups->slug ?>" id="popular-groups" <?php if ( $instance['group_default'] == 'popular' ) : ?> class="selected"<?php endif; ?>><?php _e("Popular", 'buddypress') ?></a>
    3538                        </div>
    3639
    … …  
    4447                                                <div class="item">
    4548                                                        <div class="item-title"><a href="<?php bp_group_permalink() ?>" title="<?php bp_group_name() ?>"><?php bp_group_name() ?></a></div>
    46                                                         <div class="item-meta"><span class="activity"><?php bp_group_member_count() ?></span></div>
     49                                                        <div class="item-meta">
     50                                                                <span class="activity">
     51                                                                <?php
     52                                                                        if ( 'newest' == $instance['group_default'] )
     53                                                                                printf( __( 'created %s ago', 'buddypress' ), bp_get_group_date_created() );
     54                                                                        if ( 'active' == $instance['group_default'] )
     55                                                                                printf( __( 'active %s ago', 'buddypress' ), bp_get_group_last_active() );
     56                                                                        else if ( 'popular' == $instance['group_default'] )
     57                                                                                bp_group_member_count();
     58                                                                ?>
     59                                                                </span>
     60                                                        </div>
    4761                                                </div>
    4862                                        </li>
    … …  
    6882                $instance = $old_instance;
    6983                $instance['max_groups'] = strip_tags( $new_instance['max_groups'] );
     84                $instance['group_default'] = strip_tags( $new_instance['group_default'] );
    7085
    7186                return $instance;
    … …  
    7388
    7489        function form( $instance ) {
    75                 $instance = wp_parse_args( (array) $instance, array( 'max_groups' => 5 ) );
     90                $instance = wp_parse_args( (array) $instance, array( 'max_groups' => 5, 'group_default' => 'active' ) );
    7691                $max_groups = strip_tags( $instance['max_groups'] );
     92                $group_default = strip_tags( $instance['group_default'] );
    7793                ?>
    7894
    7995                <p><label for="bp-groups-widget-groups-max"><?php _e('Max groups to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_groups' ); ?>" name="<?php echo $this->get_field_name( 'max_groups' ); ?>" type="text" value="<?php echo esc_attr( $max_groups ); ?>" style="width: 30%" /></label></p>
     96               
     97                <p>
     98                        <label for="bp-groups-widget-groups-default"><?php _e('Default groups to show:', 'buddypress'); ?>
     99                        <select name="<?php echo $this->get_field_name( 'group_default' ); ?>">
     100                                <option value="newest" <?php if ( $group_default == 'newest' ) : ?>selected="selected"<?php endif; ?>><?php _e( 'Newest', 'buddypress' ) ?></option>
     101                                <option value="active" <?php if ( $group_default == 'active' ) : ?>selected="selected"<?php endif; ?>><?php _e( 'Active', 'buddypress' ) ?></option>
     102                                <option value="popular"  <?php if ( $group_default == 'popular' ) : ?>selected="selected"<?php endif; ?>><?php _e( 'Popular', 'buddypress' ) ?></option>
     103                        </select>                       
     104                        </label>
     105                </p>
    80106        <?php
    81107        }
Note: See TracChangeset for help on using the changeset viewer.