<!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] [2698] trunk:
  Fixing up the sitewide blog posts widget to only show on multisite installations
 , and also to use the activity loop filtered on blog posts.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>2698</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2010-02-12 13:27:20 +0000 (Fri, 12 Feb 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fixing up the sitewide blog posts widget to only show on multisite installations, and also to use the activity loop filtered on blog posts.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpblogsbpblogswidgetsphp">trunk/bp-blogs/bp-blogs-widgets.php</a></li>
<li><a href="#trunkbpblogsphp">trunk/bp-blogs.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpblogsbpblogswidgetsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-blogs/bp-blogs-widgets.php (2697 => 2698)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-blogs/bp-blogs-widgets.php        2010-02-12 13:01:19 UTC (rev 2697)
+++ trunk/bp-blogs/bp-blogs-widgets.php        2010-02-12 13:27:20 UTC (rev 2698)
</span><span class="lines">@@ -1,10 +1,17 @@
</span><span class="cx"> &lt;?php
</span><span class="cx"> 
</span><del>-/* Register widgets for blogs component */
</del><ins>+/***
+ * The recent blogs widget is actually just the activity feed filtered on &quot;new_blog_post&quot;.
+ * Why not make some of your own widgets using a filtered activity stream?
+ */
+
</ins><span class="cx"> function bp_blogs_register_widgets() {
</span><del>-        add_action('widgets_init', create_function('', 'return register_widget(&quot;BP_Blogs_Recent_Posts_Widget&quot;);') );
</del><ins>+        global $current_blog, $bp;
+
+        if ( bp_is_active( 'activity' ) &amp;&amp; (int)$current_blog-&gt;blog_id == BP_ROOT_BLOG )
+                add_action('widgets_init', create_function('', 'return register_widget(&quot;BP_Blogs_Recent_Posts_Widget&quot;);') );
</ins><span class="cx"> }
</span><del>-add_action( 'template_redirect', 'bp_blogs_register_widgets' );
</del><ins>+add_action( 'bp_register_widgets', 'bp_blogs_register_widgets' );
</ins><span class="cx"> 
</span><span class="cx"> class BP_Blogs_Recent_Posts_Widget extends WP_Widget {
</span><span class="cx">         function bp_blogs_recent_posts_widget() {
</span><span class="lines">@@ -25,34 +32,35 @@
</span><span class="cx">                 if ( empty( $instance['max_posts'] ) || !$instance['max_posts'] )
</span><span class="cx">                         $instance['max_posts'] = 10; ?&gt;
</span><span class="cx"> 
</span><del>-                &lt;?php $posts = bp_blogs_get_latest_posts( null, $instance['max_posts'] ) ?&gt;
-                &lt;?php $counter = 0; ?&gt;
</del><ins>+                &lt;?php if ( bp_has_activities( 'action=new_blog_post&amp;max=' . $instance['max_posts'] . '&amp;per_page=' . $instance['max_posts'] ) ) : ?&gt;
</ins><span class="cx"> 
</span><del>-                &lt;?php if ( $posts ) : ?&gt;
-                        &lt;div class=&quot;item-options&quot; id=&quot;recent-posts-options&quot;&gt;
-                                &lt;?php _e(&quot;Site Wide&quot;, 'buddypress') ?&gt;
-                        &lt;/div&gt;
-                        &lt;ul id=&quot;recent-posts&quot; class=&quot;item-list&quot;&gt;
-                                &lt;?php foreach ( (array)$posts as $post ) : ?&gt;
</del><ins>+                        &lt;ul id=&quot;blog-post-list&quot; class=&quot;activity-list item-list&quot;&gt;
+
+                                &lt;?php while ( bp_activities() ) : bp_the_activity(); ?&gt;
+
</ins><span class="cx">                                         &lt;li&gt;
</span><del>-                                                &lt;div class=&quot;item-avatar&quot;&gt;
-                                                        &lt;a href=&quot;&lt;?php echo bp_post_get_permalink( $post, $post-&gt;blog_id ) ?&gt;&quot; title=&quot;&lt;?php echo apply_filters( 'the_title', $post-&gt;post_title ) ?&gt;&quot;&gt;&lt;?php echo bp_core_fetch_avatar( array( 'item_id' =&gt; $post-&gt;post_author, 'type' =&gt; 'thumb' ) ) ?&gt;&lt;/a&gt;
-                                                &lt;/div&gt;
</del><ins>+                                                &lt;div class=&quot;activity-content&quot; style=&quot;margin: 0&quot;&gt;
</ins><span class="cx"> 
</span><del>-                                                &lt;div class=&quot;item&quot;&gt;
-                                                        &lt;h4 class=&quot;item-title&quot;&gt;&lt;a href=&quot;&lt;?php echo bp_post_get_permalink( $post, $post-&gt;blog_id ) ?&gt;&quot; title=&quot;&lt;?php echo apply_filters( 'the_title', $post-&gt;post_title ) ?&gt;&quot;&gt;&lt;?php echo apply_filters( 'the_title', $post-&gt;post_title ) ?&gt;&lt;/a&gt;&lt;/h4&gt;
-                                                        &lt;?php if ( !$counter ) : ?&gt;
-                                                                &lt;div class=&quot;item-content&quot;&gt;&lt;?php echo bp_create_excerpt($post-&gt;post_content) ?&gt;&lt;/div&gt;
</del><ins>+                                                        &lt;div class=&quot;activity-header&quot;&gt;
+                                                                &lt;?php bp_activity_action() ?&gt;
+                                                        &lt;/div&gt;
+
+                                                        &lt;?php if ( bp_get_activity_content_body() ) : ?&gt;
+                                                                &lt;div class=&quot;activity-inner&quot;&gt;
+                                                                        &lt;?php bp_activity_content_body() ?&gt;
+                                                                &lt;/div&gt;
</ins><span class="cx">                                                         &lt;?php endif; ?&gt;
</span><del>-                                                        &lt;div class=&quot;item-meta&quot;&gt;&lt;em&gt;&lt;?php printf( __( 'by %s from the blog &lt;a href=&quot;%s&quot;&gt;%s&lt;/a&gt;', 'buddypress' ), bp_core_get_userlink( $post-&gt;post_author ), get_blog_option( $post-&gt;blog_id, 'siteurl' ), get_blog_option( $post-&gt;blog_id, 'blogname' ) ) ?&gt;&lt;/em&gt;&lt;/div&gt;
</del><ins>+
</ins><span class="cx">                                                 &lt;/div&gt;
</span><span class="cx">                                         &lt;/li&gt;
</span><del>-                                        &lt;?php $counter++; ?&gt;
-                                &lt;?php endforeach; ?&gt;
</del><ins>+
+                                &lt;?php endwhile; ?&gt;
+
</ins><span class="cx">                         &lt;/ul&gt;
</span><del>-                &lt;?php else: ?&gt;
-                        &lt;div class=&quot;widget-error&quot;&gt;
-                                &lt;?php _e('There are no recent blog posts, why not write one?', 'buddypress') ?&gt;
</del><ins>+
+                &lt;?php else : ?&gt;
+                        &lt;div id=&quot;message&quot; class=&quot;info&quot;&gt;
+                                &lt;p&gt;&lt;?php _e( 'Sorry, there were no blog posts found. Why not write one?', 'buddypress' ) ?&gt;&lt;/p&gt;
</ins><span class="cx">                         &lt;/div&gt;
</span><span class="cx">                 &lt;?php endif; ?&gt;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkbpblogsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-blogs.php (2697 => 2698)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-blogs.php        2010-02-12 13:01:19 UTC (rev 2697)
+++ trunk/bp-blogs.php        2010-02-12 13:27:20 UTC (rev 2698)
</span><span class="lines">@@ -8,8 +8,11 @@
</span><span class="cx"> 
</span><span class="cx"> require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-classes.php' );
</span><span class="cx"> require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-templatetags.php' );
</span><del>-require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-widgets.php' );
</del><span class="cx"> 
</span><ins>+/* Include the sitewide blog posts widget if this is a multisite installation */
+if ( bp_core_is_multisite() )
+        require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-widgets.php' );
+
</ins><span class="cx"> function bp_blogs_install() {
</span><span class="cx">         global $wpdb, $bp;
</span><span class="cx"> 
</span><span class="lines">@@ -436,7 +439,7 @@
</span><span class="cx"> 
</span><span class="cx">                 if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
</span><span class="cx">                         /* Now re-record the post in the activity streams */
</span><del>-                        $post_permalink = bp_post_get_permalink( $post, $blog_id );
</del><ins>+                        $post_permalink = get_permalink( $post_id );
</ins><span class="cx"> 
</span><span class="cx">                         $activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post-&gt;post_author ), '&lt;a href=&quot;' . $post_permalink . '&quot;&gt;' . $post-&gt;post_title . '&lt;/a&gt;' );
</span><span class="cx">                         $activity_content = $post-&gt;post_content;
</span><span class="lines">@@ -494,7 +497,7 @@
</span><span class="cx"> 
</span><span class="cx">         if ( (int)get_blog_option( $recorded_comment-&gt;blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
</span><span class="cx">                 /* Record in activity streams */
</span><del>-                $comment_link = bp_post_get_permalink( $comment-&gt;post, $wpdb-&gt;blogid ) . '#comment-' . $comment_id;
</del><ins>+                $comment_link = get_permalink( $comment-&gt;comment_post_ID ) . '#comment-' . $comment_id;
</ins><span class="cx">                 $activity_action = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '&lt;a href=&quot;' . $comment_link . '#comment-' . $comment-&gt;comment_ID . '&quot;&gt;' . $comment-&gt;post-&gt;post_title . '&lt;/a&gt;' );
</span><span class="cx">                 $activity_content = $comment-&gt;comment_content;
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>