<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[BuddyPress] [3317] trunk:
Adds default state selector for Members and Groups widgets.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd>3317</dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2010-10-27 15:48:30 +0000 (Wed, 27 Oct 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Adds default state selector for Members and Groups widgets. Fixes #1177</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpcorebpcorewidgetsphp">trunk/bp-core/bp-core-widgets.php</a></li>
<li><a href="#trunkbpgroupsbpgroupswidgetsphp">trunk/bp-groups/bp-groups-widgets.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpcorebpcorewidgetsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-widgets.php (3316 => 3317)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-widgets.php        2010-10-27 13:13:35 UTC (rev 3316)
+++ trunk/bp-core/bp-core-widgets.php        2010-10-27 15:48:30 UTC (rev 3317)
</span><span class="lines">@@ -18,25 +18,28 @@
</span><span class="cx">                         wp_enqueue_script( 'bp_core_widget_members-js', BP_PLUGIN_URL . '/bp-core/js/widget-members.js', array('jquery') );
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        function widget($args, $instance) {
</del><ins>+        function widget( $args, $instance ) {
</ins><span class="cx">                 global $bp;
</span><span class="cx">
</span><span class="cx">                 extract( $args );
</span><span class="cx">
</span><ins>+                if ( !$instance['member_default'] )
+                        $instance['member_default'] = 'active';
+
</ins><span class="cx">                 echo $before_widget;
</span><span class="cx">                 echo $before_title
</span><span class="cx">                  . $widget_name
</span><span class="cx">                  . $after_title; ?>
</span><span class="cx">
</span><del>-                <?php if ( bp_has_members( 'user_id=0&type=newest&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
</del><ins>+                <?php if ( bp_has_members( 'user_id=0&type=' . $instance['member_default'] . '&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
</ins><span class="cx">                         <div class="item-options" id="members-list-options">
</span><span class="cx">                                 <span class="ajax-loader" id="ajax-loader-members"></span>
</span><del>-                                <a href="<?php echo site_url() . '/' . BP_MEMBERS_SLUG ?>" id="newest-members" class="selected"><?php _e( 'Newest', 'buddypress' ) ?></a>
-                                | <a href="<?php echo site_url() . '/' . BP_MEMBERS_SLUG ?>" id="recently-active-members"><?php _e( 'Active', 'buddypress' ) ?></a>
</del><ins>+                                <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>
+                                | <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>
</ins><span class="cx">
</span><span class="cx">                                 <?php if ( bp_is_active( 'friends' ) ) : ?>
</span><span class="cx">
</span><del>-                                        | <a href="<?php echo site_url() . '/' . BP_MEMBERS_SLUG ?>" id="popular-members"><?php _e( 'Popular', 'buddypress' ) ?></a>
</del><ins>+                                        | <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>
</ins><span class="cx">
</span><span class="cx">                                 <?php endif; ?>
</span><span class="cx">
</span><span class="lines">@@ -51,7 +54,18 @@
</span><span class="cx">
</span><span class="cx">                                                 <div class="item">
</span><span class="cx">                                                         <div class="item-title fn"><a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_name() ?></a></div>
</span><del>-                                                        <div class="item-meta"><span class="activity"><?php bp_member_registered() ?></span></div>
</del><ins>+                                                        <div class="item-meta">
+                                                                <span class="activity">
+                                                                <?php
+                                                                        if ( 'newest' == $instance['member_default'] )
+                                                                                bp_member_registered();                                                                
+                                                                        if ( 'active' == $instance['member_default'] )
+                                                                                bp_member_last_active();
+                                                                        if ( 'popular' == $instance['member_default'] )
+                                                                                bp_member_total_friend_count();
+                                                                ?>
+                                                                </span>
+                                                        </div>
</ins><span class="cx">                                                 </div>
</span><span class="cx">                                         </li>
</span><span class="cx">
</span><span class="lines">@@ -75,16 +89,29 @@
</span><span class="cx">         function update( $new_instance, $old_instance ) {
</span><span class="cx">                 $instance = $old_instance;
</span><span class="cx">                 $instance['max_members'] = strip_tags( $new_instance['max_members'] );
</span><ins>+                $instance['member_default'] = strip_tags( $new_instance['member_default'] );
</ins><span class="cx">
</span><span class="cx">                 return $instance;
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function form( $instance ) {
</span><del>-                $instance = wp_parse_args( (array) $instance, array( 'max_members' => 5 ) );
</del><ins>+                $instance = wp_parse_args( (array) $instance, array( 'max_members' => 5, 'member_default' => 'active' ) );
</ins><span class="cx">                 $max_members = strip_tags( $instance['max_members'] );
</span><ins>+                $member_default = strip_tags( $instance['member_default'] );
</ins><span class="cx">                 ?>
</span><span class="cx">
</span><del>-                <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>
</del><ins>+                <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>
+                                
+                <p>
+                        <label for="bp-core-widget-groups-default"><?php _e('Default members to show:', 'buddypress'); ?>
+                        <select name="<?php echo $this->get_field_name( 'member_default' ) ?>">
+                                <option value="newest" <?php if ( $member_default == 'newest' ) : ?>selected="selected"<?php endif; ?>><?php _e( 'Newest', 'buddypress' ) ?></option>
+                                <option value="active" <?php if ( $member_default == 'active' ) : ?>selected="selected"<?php endif; ?>><?php _e( 'Active', 'buddypress' ) ?></option>
+                                <option value="popular" <?php if ( $member_default == 'popular' ) : ?>selected="selected"<?php endif; ?>><?php _e( 'Popular', 'buddypress' ) ?></option>
+                        </select>                        
+                        </label>
+                </p>
+        
</ins><span class="cx">         <?php
</span><span class="cx">         }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkbpgroupsbpgroupswidgetsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-widgets.php (3316 => 3317)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-widgets.php        2010-10-27 13:13:35 UTC (rev 3316)
+++ trunk/bp-groups/bp-groups-widgets.php        2010-10-27 15:48:30 UTC (rev 3317)
</span><span class="lines">@@ -16,22 +16,25 @@
</span><span class="cx">                         wp_enqueue_script( 'groups_widget_groups_list-js', BP_PLUGIN_URL . '/bp-groups/js/widget-groups.js', array('jquery') );
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        function widget($args, $instance) {
</del><ins>+        function widget( $args, $instance ) {
</ins><span class="cx">                 global $bp;
</span><span class="cx">
</span><span class="cx">          extract( $args );
</span><span class="cx">
</span><ins>+                if ( !$instance['group_default'] )
+                        $instance['group_default'] = 'popular';
+
</ins><span class="cx">                 echo $before_widget;
</span><span class="cx">                 echo $before_title
</span><span class="cx">                  . $widget_name
</span><span class="cx">                  . $after_title; ?>
</span><span class="cx">
</span><del>-                <?php if ( bp_has_groups( 'type=popular&per_page=' . $instance['max_groups'] . '&max=' . $instance['max_groups'] ) ) : ?>
</del><ins>+                <?php if ( bp_has_groups( 'type=' . $instance['group_default'] . '&max=' . $instance['max_groups'] ) ) : ?>
</ins><span class="cx">                         <div class="item-options" id="groups-list-options">
</span><span class="cx">                                 <span class="ajax-loader" id="ajax-loader-groups"></span>
</span><del>-                                <a href="<?php echo site_url() . '/' . $bp->groups->slug ?>" id="newest-groups"><?php _e("Newest", 'buddypress') ?></a> |
-                                <a href="<?php echo site_url() . '/' . $bp->groups->slug ?>" id="recently-active-groups"><?php _e("Active", 'buddypress') ?></a> |
-                                <a href="<?php echo site_url() . '/' . $bp->groups->slug ?>" id="popular-groups" class="selected"><?php _e("Popular", 'buddypress') ?></a>
</del><ins>+                                <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> |
+                                <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> |
+                                <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>
</ins><span class="cx">                         </div>
</span><span class="cx">
</span><span class="cx">                         <ul id="groups-list" class="item-list">
</span><span class="lines">@@ -43,7 +46,18 @@
</span><span class="cx">
</span><span class="cx">                                                 <div class="item">
</span><span class="cx">                                                         <div class="item-title"><a href="<?php bp_group_permalink() ?>" title="<?php bp_group_name() ?>"><?php bp_group_name() ?></a></div>
</span><del>-                                                        <div class="item-meta"><span class="activity"><?php bp_group_member_count() ?></span></div>
</del><ins>+                                                        <div class="item-meta">
+                                                                <span class="activity">
+                                                                <?php
+                                                                        if ( 'newest' == $instance['group_default'] )
+                                                                                printf( __( 'created %s ago', 'buddypress' ), bp_get_group_date_created() );
+                                                                        if ( 'active' == $instance['group_default'] )
+                                                                                printf( __( 'active %s ago', 'buddypress' ), bp_get_group_last_active() );
+                                                                        else if ( 'popular' == $instance['group_default'] )
+                                                                                bp_group_member_count();
+                                                                ?>
+                                                                </span>
+                                                        </div>
</ins><span class="cx">                                                 </div>
</span><span class="cx">                                         </li>
</span><span class="cx">
</span><span class="lines">@@ -67,16 +81,28 @@
</span><span class="cx">         function update( $new_instance, $old_instance ) {
</span><span class="cx">                 $instance = $old_instance;
</span><span class="cx">                 $instance['max_groups'] = strip_tags( $new_instance['max_groups'] );
</span><ins>+                $instance['group_default'] = strip_tags( $new_instance['group_default'] );
</ins><span class="cx">
</span><span class="cx">                 return $instance;
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function form( $instance ) {
</span><del>-                $instance = wp_parse_args( (array) $instance, array( 'max_groups' => 5 ) );
</del><ins>+                $instance = wp_parse_args( (array) $instance, array( 'max_groups' => 5, 'group_default' => 'active' ) );
</ins><span class="cx">                 $max_groups = strip_tags( $instance['max_groups'] );
</span><ins>+                $group_default = strip_tags( $instance['group_default'] );
</ins><span class="cx">                 ?>
</span><span class="cx">
</span><span class="cx">                 <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>
</span><ins>+                
+                <p>
+                        <label for="bp-groups-widget-groups-default"><?php _e('Default groups to show:', 'buddypress'); ?>
+                        <select name="<?php echo $this->get_field_name( 'group_default' ); ?>">
+                                <option value="newest" <?php if ( $group_default == 'newest' ) : ?>selected="selected"<?php endif; ?>><?php _e( 'Newest', 'buddypress' ) ?></option>
+                                <option value="active" <?php if ( $group_default == 'active' ) : ?>selected="selected"<?php endif; ?>><?php _e( 'Active', 'buddypress' ) ?></option>
+                                <option value="popular" <?php if ( $group_default == 'popular' ) : ?>selected="selected"<?php endif; ?>><?php _e( 'Popular', 'buddypress' ) ?></option>
+                        </select>                        
+                        </label>
+                </p>
</ins><span class="cx">         <?php
</span><span class="cx">         }
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>