<!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] [2147] trunk: Updated site wide activity widget.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd>2147</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2009-11-27 15:58:51 +0000 (Fri, 27 Nov 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>Updated site wide activity widget. Added new AJAX functionality along with more powerful filtering</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpactivitybpactivityclassesphp">trunk/bp-activity/bp-activity-classes.php</a></li>
<li><a href="#trunkbpactivitybpactivitytemplatetagsphp">trunk/bp-activity/bp-activity-templatetags.php</a></li>
<li><a href="#trunkbpactivitybpactivitywidgetsphp">trunk/bp-activity/bp-activity-widgets.php</a></li>
<li><a href="#trunkbpgroupsphp">trunk/bp-groups.php</a></li>
<li><a href="#trunkbpthemesbpdefault_inccssscreencss">trunk/bp-themes/bp-default/_inc/css/screen.css</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpactivitybpactivityclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-classes.php (2146 => 2147)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-classes.php        2009-11-27 14:11:08 UTC (rev 2146)
+++ trunk/bp-activity/bp-activity-classes.php        2009-11-27 15:58:51 UTC (rev 2147)
</span><span class="lines">@@ -459,6 +459,24 @@
</span><span class="cx">         function get_filter_sql( $filter_array ) {
</span><span class="cx">                 global $wpdb;
</span><span class="cx">
</span><ins>+                if ( !empty( $filter_array['user_id'] ) ) {
+                        $user_filter = explode( ',', $filter_array['user_id'] );
+                        $user_sql = ' ( ';
+
+                        $counter = 1;
+                        foreach( (array) $user_filter as $user ) {
+                                $user_sql .= $wpdb->prepare( "user_id = %d", trim( $user ) );
+
+                                if ( $counter != count( $user_filter ) )
+                                        $user_sql .= ' || ';
+
+                                $counter++;
+                        }
+
+                        $user_sql .= ' )';
+                        $filter_sql[] = $user_sql;
+                }
+
</ins><span class="cx">                 if ( !empty( $filter_array['object'] ) ) {
</span><span class="cx">                         $object_filter = explode( ',', $filter_array['object'] );
</span><span class="cx">                         $object_sql = ' ( ';
</span></span></pre></div>
<a id="trunkbpactivitybpactivitytemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-templatetags.php (2146 => 2147)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-templatetags.php        2009-11-27 14:11:08 UTC (rev 2146)
+++ trunk/bp-activity/bp-activity-templatetags.php        2009-11-27 15:58:51 UTC (rev 2147)
</span><span class="lines">@@ -155,7 +155,7 @@
</span><span class="cx">         if ( isset( $_GET['afilter'] ) )
</span><span class="cx">                 $filter = array( 'object' => $_GET['afilter'] );
</span><span class="cx">         else
</span><del>-                $filter = array( 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id );
</del><ins>+                $filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id );
</ins><span class="cx">
</span><span class="cx">         $activities_template = new BP_Activity_Template( $type, $user_id, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden );
</span><span class="cx">
</span></span></pre></div>
<a id="trunkbpactivitybpactivitywidgetsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-widgets.php (2146 => 2147)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-widgets.php        2009-11-27 14:11:08 UTC (rev 2146)
+++ trunk/bp-activity/bp-activity-widgets.php        2009-11-27 15:58:51 UTC (rev 2147)
</span><span class="lines">@@ -9,6 +9,9 @@
</span><span class="cx"> class BP_Activity_Widget extends WP_Widget {
</span><span class="cx">         function bp_activity_widget() {
</span><span class="cx">                 parent::WP_Widget( false, $name = __( 'Site Wide Activity', 'buddypress' ) );
</span><ins>+
+                if ( is_active_widget( false, false, $this->id_base ) )
+                        wp_enqueue_script( 'activity_widget_js', BP_PLUGIN_URL . '/bp-activity/js/widget-activity.js' );
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         function widget($args, $instance) {
</span><span class="lines">@@ -19,27 +22,91 @@
</span><span class="cx">                 echo $before_widget;
</span><span class="cx">                 echo $before_title
</span><span class="cx">                  . $widget_name .
</span><del>-                         ' <a class="rss-image" href="' . bp_get_sitewide_activity_feed_link() . '" title="' . __( 'Site Wide Activity RSS Feed', 'buddypress' ) . '">' . __( '[RSS]', 'buddypress' ) . '</a>'
</del><ins>+                         ' &nbsp;<span class="ajax-loader"></span>
+                         <a class="rss-image" href="' . bp_get_sitewide_activity_feed_link() . '" title="' . __( 'Site Wide Activity RSS Feed', 'buddypress' ) . '">' . __( '[RSS]', 'buddypress' ) . '</a>'
</ins><span class="cx">                  . $after_title; ?>
</span><span class="cx">
</span><del>-        <?php if ( bp_has_activities( 'type=sitewide&max=' . $instance['max_items'] . '&per_page=' . $instance['per_page'] . '&display_comments=threaded' ) ) : ?>
</del><ins>+        <?php if ( is_user_logged_in() ) : ?>
+        <div class="item-list-tabs">
+                <ul>
+                        <li class="selected" id="activity-all"><a href="<?php bp_root_domain() ?>"><?php _e( 'All Members', 'buddypress' ) ?></a></li>
+                        <li id="activity-friends"><a href="<?php echo bp_loggedin_user_domain() . BP_ACTIVITY_SLUG . '/my-friends/' ?>"><?php _e( 'My Friends', 'buddypress') ?></a></li>
+                        <li id="activity-groups"><a href="<?php echo bp_loggedin_user_domain() . BP_ACTIVITY_SLUG . '/my-groups/' ?>"><?php _e( 'My Groups', 'buddypress') ?></a></li>
</ins><span class="cx">
</span><del>-                <?php if ( !file_exists( WP_CONTENT_DIR . '/bp-themes' ) ) : ?>
-                        <div class="pagination">
-                                <div class="pag-count" id="activity-count">
-                                        <?php bp_activity_pagination_count() ?>
-                                </div>
</del><ins>+                        <?php do_action( 'bp_activity_types' ) ?>
</ins><span class="cx">
</span><del>-                                <div class="pagination-links" id="activity-pag">
-                                        &nbsp; <?php bp_activity_pagination_links() ?>
-                                </div>
-                        </div>
</del><ins>+                        <li id="activity-filter-select">
+                                <select>
+                                        <option value="-1"><?php _e( 'No Filter', 'buddypress' ) ?></option>
+                                        <option value="new_wire_post"><?php _e( 'Updates Only', 'buddypress' ) ?></option>
+                                        <option value="new_forum_post,new_forum_topic"><?php _e( 'Group Forum Activity Only', 'buddypress' ) ?></option>
+                                        <option value="new_blog_post,new_blog_comment"><?php _e( 'Blog Activity Only', 'buddypress' ) ?></option>
</ins><span class="cx">
</span><del>-                        <ul id="activity-filter-links">
-                                <?php bp_activity_filter_links() ?>
-                        </ul>
-                <?php endif; ?>
</del><ins>+                                        <?php do_action( 'bp_activity_filter_options' ) ?>
+                                </select>
+                        </li>
+                </ul>
+        </div>
+        <?php endif; ?>
</ins><span class="cx">
</span><ins>+        <div class="astream">
+                <?php // The loop will be loaded here via AJAX on page load to retain settings. ?>
+        </div>
+
+        <?php echo $after_widget; ?>
+        <?php
+        }
+
+        function update( $new_instance, $old_instance ) {
+                $instance = $old_instance;
+                $instance['max_items'] = strip_tags( $new_instance['max_items'] );
+                $instance['per_page'] = strip_tags( $new_instance['per_page'] );
+
+                return $instance;
+        }
+
+        function form( $instance ) {
+                $instance = wp_parse_args( (array) $instance, array( 'max_items' => 200, 'per_page' => 25 ) );
+                $per_page = strip_tags( $instance['per_page'] );
+                $max_items = strip_tags( $instance['max_items'] );
+                ?>
+
+                <p><label for="bp-activity-widget-sitewide-per-page"><?php _e('Number of Items Per Page:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'per_page' ); ?>" name="<?php echo $this->get_field_name( 'per_page' ); ?>" type="text" value="<?php echo attribute_escape( $per_page ); ?>" style="width: 30%" /></label></p>
+                <p><label for="bp-core-widget-members-max"><?php _e('Max items to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_items' ); ?>" name="<?php echo $this->get_field_name( 'max_items' ); ?>" type="text" value="<?php echo attribute_escape( $max_items ); ?>" style="width: 30%" /></label></p>
+        <?php
+        }
+}
+
+function bp_activity_widget_loop( $type = 'all', $filter = false, $per_page = 20 ) {
+        global $bp;
+
+        /* Set a valid type */
+        if ( !$type || ( 'all' != $type && 'friends' != $type && 'groups' != $type ) )
+                $type = 'all';
+
+        if ( ( 'friends' == $type || 'groups' == $type ) && !is_user_logged_in() )
+                $type = 'all';
+
+        switch( $type ) {
+                case 'friends':
+                        $friend_ids = implode( ',', friends_get_friend_user_ids( $bp->loggedin_user->id ) );
+                        $query_string = 'user_id=' . $friend_ids;
+                        break;
+                case 'groups':
+                        $groups = groups_get_user_groups( $bp->loggedin_user->id );
+                        $group_ids = implode( ',', $groups['groups'] );
+                        $query_string = 'object=groups&primary_id=' . $group_ids;
+                        break;
+        }
+
+        /* Build the filter */
+        if ( $filter && $filter != '-1' )
+                $query_string .= '&action=' . $filter;
+
+        /* Add the per_page param */
+        $query_string .= '&per_page=' . $per_page;
+
+        if ( bp_has_activities( $query_string . '&display_comments=threaded' ) ) : ?>
</ins><span class="cx">                 <ul id="site-wide-stream" class="activity-list">
</span><span class="cx">                 <?php while ( bp_activities() ) : bp_the_activity(); ?>
</span><span class="cx">                         <li class="<?php bp_activity_css_class() ?>" id="activity-<?php bp_activity_id() ?>">
</span><span class="lines">@@ -77,33 +144,16 @@
</span><span class="cx">                 </ul>
</span><span class="cx">
</span><span class="cx">         <?php else: ?>
</span><ins>+<?php echo "-1<div id='message' class='info'><p>" . __( 'No activity found', 'buddypress' ) . '</p></div>'; ?>
+        <?php endif;
+}
</ins><span class="cx">
</span><del>-                <div class="widget-error">
-                        <?php _e('There has been no recent site activity.', 'buddypress') ?>
-                </div>
-        <?php endif;?>
</del><ins>+/* The ajax function to reload the activity widget. In here because this is a self contained widget. */
+function bp_activity_ajax_widget_filter() {
+        bp_activity_widget_loop( $_POST['type'], $_POST['filter'] );
+}
+add_action( 'wp_ajax_activity_widget_filter', 'bp_activity_ajax_widget_filter' );
</ins><span class="cx">
</span><del>-        <?php echo $after_widget; ?>
-        <?php
-        }
</del><span class="cx">
</span><del>-        function update( $new_instance, $old_instance ) {
-                $instance = $old_instance;
-                $instance['max_items'] = strip_tags( $new_instance['max_items'] );
-                $instance['per_page'] = strip_tags( $new_instance['per_page'] );
</del><span class="cx">
</span><del>-                return $instance;
-        }
-
-        function form( $instance ) {
-                $instance = wp_parse_args( (array) $instance, array( 'max_items' => 200, 'per_page' => 25 ) );
-                $per_page = strip_tags( $instance['per_page'] );
-                $max_items = strip_tags( $instance['max_items'] );
-                ?>
-
-                <p><label for="bp-activity-widget-sitewide-per-page"><?php _e('Number of Items Per Page:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'per_page' ); ?>" name="<?php echo $this->get_field_name( 'per_page' ); ?>" type="text" value="<?php echo attribute_escape( $per_page ); ?>" style="width: 30%" /></label></p>
-                <p><label for="bp-core-widget-members-max"><?php _e('Max items to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_items' ); ?>" name="<?php echo $this->get_field_name( 'max_items' ); ?>" type="text" value="<?php echo attribute_escape( $max_items ); ?>" style="width: 30%" /></label></p>
-        <?php
-        }
-}
-?>
</del><span class="cx">\ No newline at end of file
</span><ins>+?>
</ins></span></pre></div>
<a id="trunkbpgroupsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups.php (2146 => 2147)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups.php        2009-11-27 14:11:08 UTC (rev 2146)
+++ trunk/bp-groups.php        2009-11-27 15:58:51 UTC (rev 2147)
</span><span class="lines">@@ -1917,6 +1917,8 @@
</span><span class="cx">         return BP_Groups_Group::get_by_most_forum_posts( $limit, $page );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+/* TODO: These user group functions could be merged with the above with an optional user ID param */
+
</ins><span class="cx"> function groups_get_user_groups( $user_id = false, $pag_num = false, $pag_page = false ) {
</span><span class="cx">         global $bp;
</span><span class="cx">
</span><span class="lines">@@ -1926,8 +1928,6 @@
</span><span class="cx">         return BP_Groups_Member::get_group_ids( $user_id, $pag_num, $pag_page );
</span><span class="cx"> }
</span><span class="cx">
</span><del>-/* TODO: These user group functions could be merged with the above with an optional user ID param */
-
</del><span class="cx"> function groups_get_recently_joined_for_user( $user_id = false, $pag_num = false, $pag_page = false, $filter = false ) {
</span><span class="cx">         global $bp;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkbpthemesbpdefault_inccssscreencss"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/_inc/css/screen.css (2146 => 2147)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/_inc/css/screen.css        2009-11-27 14:11:08 UTC (rev 2146)
+++ trunk/bp-themes/bp-default/_inc/css/screen.css        2009-11-27 15:58:51 UTC (rev 2147)
</span><span class="lines">@@ -1262,30 +1262,6 @@
</span><span class="cx">         background: none !important;
</span><span class="cx">         border-bottom: 1px solid #eee;
</span><span class="cx"> }
</span><del>-        ul#activity-filter-links li#afilter-blogs a {
-                background: url(../images/blog_bullet.gif) 20px 4px no-repeat;
-        }
-
-        ul#activity-filter-links li#afilter-profile a {
-                background: url(../images/profile_bullet.gif) 0 4px no-repeat;
-        }
-
-        ul#activity-filter-links li#afilter-friends a {
-                background: url(../images/friends_bullet.gif) 0 4px no-repeat;
-        }
-
-        ul#activity-filter-links li#afilter-groups a {
-                background: url(../images/groups_bullet.gif) 0 4px no-repeat;
-        }
-
-        ul#activity-filter-links li#afilter-wire a {
-                background: url(../images/wire_bullet.gif) 0 4px no-repeat;
-        }
-
-        ul#activity-filter-links li#afilter-status a {
-                background: url(../images/status_bullet.gif) 0 4px no-repeat;
-        }
-
</del><span class="cx">         .activity-list li.mini {
</span><span class="cx">                 font-size: 0.9em;
</span><span class="cx">                 min-height: 35px;
</span><span class="lines">@@ -1390,26 +1366,21 @@
</span><span class="cx">                 margin: 0;
</span><span class="cx">         }
</span><span class="cx">
</span><del>-ul#activity-filter-links {
</del><ins>+div.item-list-tabs ul {
</ins><span class="cx">         margin: 0;
</span><span class="cx">         padding: 0;
</span><span class="cx">         list-style: none;
</span><span class="cx">         background: url(../images/item_list_back.gif) top left repeat-x;
</span><span class="cx">         padding: 15px;
</span><del>-        min-height: 22px;
</del><span class="cx">         overflow: hidden;
</span><span class="cx"> }
</span><del>-        .activity ul#activity-filter-links {
-                margin-top: 35px;
-        }
</del><span class="cx">
</span><del>-ul#activity-filter-links li {
</del><ins>+div.item-list-tabs ul li {
</ins><span class="cx">         float: left;
</span><del>-        margin-bottom: 5px;
</del><span class="cx"> }
</span><del>-        ul#activity-filter-links li a {
</del><ins>+        div.item-list-tabs ul li a {
</ins><span class="cx">                 display: block;
</span><del>-                padding: 2px 8px 2px 30px;
</del><ins>+                padding: 2px 8px;
</ins><span class="cx">                 background-color: #fff !important;
</span><span class="cx">                 background-position: 8px 6px !important;
</span><span class="cx">                 border-radius: 5px;
</span><span class="lines">@@ -1419,17 +1390,25 @@
</span><span class="cx">                 border: 1px solid #eee;
</span><span class="cx">                 text-decoration: none;
</span><span class="cx">         }
</span><del>-                ul#activity-filter-links li.selected a {
</del><ins>+                div.item-list-tabs ul li.selected a {
</ins><span class="cx">                         border: 1px solid #ccc;
</span><ins>+                        color: #555;
</ins><span class="cx">                         font-weight: bold;
</span><span class="cx">                 }
</span><span class="cx">
</span><del>-                ul#activity-filter-links li#afilter-clear a {
</del><ins>+                div.item-list-tabs ul li.afilter-clear a {
</ins><span class="cx">                         background: url(../images/error_icon.gif) 0 4px no-repeat;
</span><span class="cx">                         border-color: #ffa6ac;
</span><span class="cx">                         color: #ff5560;
</span><span class="cx">                 }
</span><span class="cx">
</span><ins>+                div.item-list-tabs li#activity-filter-select {
+                        float: right;
+                }
+                        div.item-list-tabs li#activity-filter-select select {
+                                max-width: 120px;
+                        }
+
</ins><span class="cx"> a.rss-image {
</span><span class="cx">         background: url( ../images/rss.png ) top left no-repeat;
</span><span class="cx">         width: 10px;
</span></span></pre>
</div>
</div>
</body>
</html>