<!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"> <?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 "new_blog_post".
+ * 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("BP_Blogs_Recent_Posts_Widget");') );
</del><ins>+        global $current_blog, $bp;
+
+        if ( bp_is_active( 'activity' ) && (int)$current_blog->blog_id == BP_ROOT_BLOG )
+                add_action('widgets_init', create_function('', 'return register_widget("BP_Blogs_Recent_Posts_Widget");') );
</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; ?>
</span><span class="cx">
</span><del>-                <?php $posts = bp_blogs_get_latest_posts( null, $instance['max_posts'] ) ?>
-                <?php $counter = 0; ?>
</del><ins>+                <?php if ( bp_has_activities( 'action=new_blog_post&max=' . $instance['max_posts'] . '&per_page=' . $instance['max_posts'] ) ) : ?>
</ins><span class="cx">
</span><del>-                <?php if ( $posts ) : ?>
-                        <div class="item-options" id="recent-posts-options">
-                                <?php _e("Site Wide", 'buddypress') ?>
-                        </div>
-                        <ul id="recent-posts" class="item-list">
-                                <?php foreach ( (array)$posts as $post ) : ?>
</del><ins>+                        <ul id="blog-post-list" class="activity-list item-list">
+
+                                <?php while ( bp_activities() ) : bp_the_activity(); ?>
+
</ins><span class="cx">                                         <li>
</span><del>-                                                <div class="item-avatar">
-                                                        <a href="<?php echo bp_post_get_permalink( $post, $post->blog_id ) ?>" title="<?php echo apply_filters( 'the_title', $post->post_title ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $post->post_author, 'type' => 'thumb' ) ) ?></a>
-                                                </div>
</del><ins>+                                                <div class="activity-content" style="margin: 0">
</ins><span class="cx">
</span><del>-                                                <div class="item">
-                                                        <h4 class="item-title"><a href="<?php echo bp_post_get_permalink( $post, $post->blog_id ) ?>" title="<?php echo apply_filters( 'the_title', $post->post_title ) ?>"><?php echo apply_filters( 'the_title', $post->post_title ) ?></a></h4>
-                                                        <?php if ( !$counter ) : ?>
-                                                                <div class="item-content"><?php echo bp_create_excerpt($post->post_content) ?></div>
</del><ins>+                                                        <div class="activity-header">
+                                                                <?php bp_activity_action() ?>
+                                                        </div>
+
+                                                        <?php if ( bp_get_activity_content_body() ) : ?>
+                                                                <div class="activity-inner">
+                                                                        <?php bp_activity_content_body() ?>
+                                                                </div>
</ins><span class="cx">                                                         <?php endif; ?>
</span><del>-                                                        <div class="item-meta"><em><?php printf( __( 'by %s from the blog <a href="%s">%s</a>', 'buddypress' ), bp_core_get_userlink( $post->post_author ), get_blog_option( $post->blog_id, 'siteurl' ), get_blog_option( $post->blog_id, 'blogname' ) ) ?></em></div>
</del><ins>+
</ins><span class="cx">                                                 </div>
</span><span class="cx">                                         </li>
</span><del>-                                        <?php $counter++; ?>
-                                <?php endforeach; ?>
</del><ins>+
+                                <?php endwhile; ?>
+
</ins><span class="cx">                         </ul>
</span><del>-                <?php else: ?>
-                        <div class="widget-error">
-                                <?php _e('There are no recent blog posts, why not write one?', 'buddypress') ?>
</del><ins>+
+                <?php else : ?>
+                        <div id="message" class="info">
+                                <p><?php _e( 'Sorry, there were no blog posts found. Why not write one?', 'buddypress' ) ?></p>
</ins><span class="cx">                         </div>
</span><span class="cx">                 <?php endif; ?>
</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->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
</span><span class="cx">                         $activity_content = $post->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->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->post, $wpdb->blogid ) . '#comment-' . $comment_id;
</del><ins>+                $comment_link = get_permalink( $comment->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 ), '<a href="' . $comment_link . '#comment-' . $comment->comment_ID . '">' . $comment->post->post_title . '</a>' );
</span><span class="cx">                 $activity_content = $comment->comment_content;
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>