I have no place to link this, but here is the code we use to accomplish this which was developed by someone within my company (and some other stuff). Hope that helps.
<?php
/*
Plugin Name: Feedbag
Description: Creates a condensed view of recent posts from all blogs.
Author: Steven L. Eddins
*/
function wpmu_feedbag_get_blogs() {
global $wpdb, $wpmuBaseTablePrefix;
$blogs = $wpdb->get_col("SELECT blog_id
FROM $wpdb->blogs
WHERE public
= '1' AND archived
= '0' AND
last_updated
!= '0000-00-00 00:00:00' ");
return($blogs);
}
function wpmu_feedbag_get_post_ids() {
global $wpdb, $wpmuBaseTablePrefix;
$post_limit_per_blog = 100;
$blogs = wpmu_feedbag_get_blogs();
foreach ($blogs as $blogid) {
$results = $wpdb->get_results("SELECT ID
,post_date_gmt
FROM ".$wpmuBaseTablePrefix.$blogid."_posts
WHERE post_status
= 'publish' AND
(post_type
= 'post' OR post_type
= '')
AND post_date_gmt
< '".gmdate("Y-m-d H:i:s")."'
ORDER BY post_date_gmt
DESC LIMIT ". $post_limit_per_blog);
foreach ($results as $result) {
$map[] = array($blogid,$result->ID,$result->post_date_gmt);
$ID[] = $result->ID;
$date_gmt[] = $result->post_date_gmt;
}
}
array_multisort($date_gmt, SORT_DESC, $ID, SORT_ASC, $map);
return($map);
}
function wpmu_feedbag_get_post_info($max_posts) {
global $wpdb, $wpmuBaseTablePrefix;
$untitled = "Untitled";
$post_ids = wpmu_feedbag_get_post_ids();
$counter = 0;
foreach ($post_ids as $post_id) {
$row = $wpdb->get_row(
"SELECT * FROM ".$wpmuBaseTablePrefix.intval($post_id[0])."_posts
WHERE ID
= '".intval($post_id[1])."'");
if ($row->ID) {
if (!$row->post_title) {
$row->post_title = $untitled;
}
$row->blogid = intval($post_id[0]);
$rows[] = $row;
$counter++;
if ($counter >= $max_posts) {
break;
}
}
}
return($rows);
}
function wpmu_feedbag_get_comment_ids() {
global $wpdb, $wpmuBaseTablePrefix;
$limit = 500;
$blogs = wpmu_feedbag_get_blogs();
foreach ($blogs as $blogid) {
$results = $wpdb->get_results("SELECT comment_ID, comment_date_gmt, comment_post_ID,
".$wpmuBaseTablePrefix.$blogid."_posts.ID, ".$wpmuBaseTablePrefix.$blogid."_posts.post_password
FROM ".$wpmuBaseTablePrefix.$blogid."_comments
LEFT JOIN ".$wpmuBaseTablePrefix.$blogid."_posts ON comment_post_id = id
WHERE ".$wpmuBaseTablePrefix.$blogid."_posts.post_status IN ('publish', 'static', 'object')
AND ".$wpmuBaseTablePrefix.$blogid."_comments.comment_approved = '1' AND post_date_gmt < '" . gmdate("Y-m-d H:i:s") . "'
ORDER BY comment_date_gmt DESC LIMIT " . $limit);
foreach ($results as $result) {
$map[] = array($blogid,$result->comment_ID,$result->comment_date_gmt);
$ID[] = $result->comment_ID;
$date_gmt[] = $result->comment_date_gmt;
}
}
array_multisort($date_gmt, SORT_DESC, $ID, SORT_ASC, $map);
return($map);
}
function wpmu_feedbag_get_comment_info($max_comments) {
global $wpdb, $wpmuBaseTablePrefix;
$comment_ids = wpmu_feedbag_get_comment_ids();
$counter = 0;
foreach ($comment_ids as $comment_id) {
$row = $wpdb->get_row("SELECT * FROM `" .
$wpmuBaseTablePrefix.intval($comment_id[0]) .
"_commentsWHERE
comment_ID` = '" .
intval($comment_id[1])."'");
if ($row->comment_ID) {
$row->blogid = intval($comment_id[0]);
$row->comment_gmt_date = $comment_id[2];
$rows[] = $row;
}
$counter++;
if ($counter >= $max_comments) {
break;
}
}
return($rows);
}
function wpmu_feedbag_condense_content_string($content, $max_words) {
$content = strip_tags($content);
$content = str_replace(array("\r\n", "\n", "\r"), " ", $content);
$content = explode(' ', $content);
for ($i = 0; $i < $max_words; $i++) {
$summary[$i] = $content[$i];
}
$summary = implode(' ', $summary) . '...';
return($summary);
}
function wpmu_feedbag_elapsed_time($date_gmt) {
$elapsed_time = strtotime(gmdate("Y-m-d H:i:s")) -
strtotime($date_gmt);
return($elapsed_time);
}
function wpmu_feedbag_ago_string($time_ago) {
if ($time_ago < 60) {
$str = "seconds ago";
} else if ($time_ago < 120) {
$str = "1 minute ago";
} else if ($time_ago < 3600) {
$str = strval(floor($time_ago / 60)) . " minutes ago";
} else if ($time_ago < 7200) {
$str = strval("1 hour ago");
} else if ($time_ago < 86400) {
$str = strval(floor($time_ago / 3600)) . " hours ago";
} else if ($time_ago < 172800) {
$str = "yesterday";
} else {
$str = strval(floor($time_ago / 86400)) . " days ago";
}
return($str);
}
function wpmu_feedbag_recent_posts_condensed($max_posts) {
global $wpdb, $wpmuBaseTablePrefix;
$post_info = wpmu_feedbag_get_post_info($max_posts);
foreach ($post_info as $post) {
$blog_name = $wpdb->get_var("SELECT option_value FROM " .
$wpmuBaseTablePrefix . $post->blogid . "_options" .
" WHERE option_name = 'blogname'");
$blog_url = $wpdb->get_var("SELECT option_value FROM " .
$wpmuBaseTablePrefix . $post->blogid . "_options" .
" WHERE option_name = 'siteurl'");
$post_author_name = get_author_name($post->post_author);
print "<p style=\"margin-bottom: 0;\"> ";
print "guid\">";
print $post->post_title;
print "";
print " </p>";
print "<p style=\"padding-left: 2em; margin-top: 0;\">";
$summary = wpmu_feedbag_condense_content_string($post->post_content, 25);
print "$summary\n";
print "";
$time_ago = wpmu_feedbag_elapsed_time($post->post_date_gmt);
$time_ago_str = wpmu_feedbag_ago_string($time_ago);
print "
Posted $time_ago_str";
print " on $blog_name";
print " by $post_author_name\n";
if ($post->comment_count > 0) {
if ($post->comment_count == 1) {
print "
1 comment\n";
} else {
print "
$post->comment_count comments\n";
}
}
print "\n";
print "</p>\n";
}
}
function wpmu_feedbag_recent_comments($max_comments) {
global $wpdb, $wpmuBaseTablePrefix;
$comment_info = wpmu_feedbag_get_comment_info($max_comments);
foreach ($comment_info as $comment) {
$blog_name = $wpdb->get_var("SELECT option_value FROM " .
$wpmuBaseTablePrefix . intval($comment->blogid) . "_options" .
" WHERE option_name = 'blogname'");
$blog_url = $wpdb->get_var("SELECT option_value FROM " .
$wpmuBaseTablePrefix . intval($comment->blogid) . "_options" .
" WHERE option_name = 'siteurl'");
$post = $wpdb->get_row(
"SELECT * FROM ".$wpmuBaseTablePrefix.intval($comment->blogid)."_posts
WHERE ID
= '".intval($comment->comment_post_ID)."'");
$time_ago_str = wpmu_feedbag_ago_string(wpmu_feedbag_elapsed_time($comment->comment_gmt_date));
print "<p style=\"margin-bottom: 0;\">\n";
print $comment->comment_author . " commented " . $time_ago_str . " on " .
"guid\">\"$post->post_title\"" .
" on $blog_name";
print "</p>";
print "<p style=\"padding-left: 2em; margin-top: 1em;\">";
print $comment->comment_content;
print "</p>";
}
}
function wpmu_feedbag_recent_posts($max_posts) {
global $wpdb, $wpmuBaseTablePrefix;
$post_info = wpmu_feedbag_get_post_info($max_posts);
foreach ($post_info as $post) {
$blog_name = $wpdb->get_var("SELECT option_value FROM " .
$wpmuBaseTablePrefix . $post->blogid . "_options" .
" WHERE option_name = 'blogname'");
$blog_url = $wpdb->get_var("SELECT option_value FROM " .
$wpmuBaseTablePrefix . $post->blogid . "_options" .
" WHERE option_name = 'siteurl'");
$post_author_name = get_author_name($post->post_author);
print "<h2 style=\"margin-top: 2em;\">";
print "guid\">";
print $post->post_title;
print "";
print "</h2>";
print "<p>";
print "";
$time_ago = wpmu_feedbag_elapsed_time($post->post_date_gmt);
$time_ago_str = wpmu_feedbag_ago_string($time_ago);
print "
Posted $time_ago_str\n";
print " on $blog_name";
print " by $post_author_name\n";
if ($post->comment_count > 0) {
if ($post->comment_count == 1) {
print "
1 comment\n";
} else {
print "
$post->comment_count comments\n";
}
}
print "";
print "</p>\n";
print "<p>";
echo preg_replace('@<pre(.*?)@si',"
Code removed from this feed. See actual post for code.
",$post->post_content);
print "</p>\n";
}
}
?>