1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| <?php include('wp-config.php') ?>
<?php
//What blogs where last updated, lets grab a bunch at first.
$blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE domain!='dubblogs.com' AND public = 1 AND last_updated!='0000-00-00 00:00:00' ORDER BY last_updated DESC LIMIT 10");
$tables = array();
foreach ($blogs as $blog) {
// we need _posts and _options tables for this to work
$blogOptionsTable = "wp_".$blog."_options";
$blogPostsTable = "wp_".$blog."_posts";
$blogCatTable = "wp_".$blog."_post2cat";
//add to array for later use
$table = array ($blog, $blogPostsTable, $blogOptionsTable, $blogCatTable );
$tables[] = $table; //push into tables
}
//now lets pull out 5 recent posts from each blog
$postresults = array();
foreach ($tables as $t) {
$postitems = $wpdb->get_results("SELECT ID,post_title,guid,post_content,comment_count,post_date_gmt FROM $t[1] WHERE post_status = 'publish' AND guid != '' ORDER BY id DESC LIMIT 0,10");
//push into array, had $postresults[] = $postitems;, but didn't work?
if ($postitems) {
foreach ($postitems as $postitem) {
$col = array($postitem->ID,$postitem->post_title,$postitem->guid,$postitem->post_content,$postitem->comment_count,$postitem->post_date_gmt,$t[0]);
$postresults[] = $col;
}
}
}
function cutpost($text) { // Fakes an excerpt if needed
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
$excerpt_length = 30;
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
array_push($words, '[...]');
$text = implode(' ', $words);
}
return $text;
}
function cmp($a,$b) {
$at = strtotime($a[5]);
$bt = strtotime($b[5]);
if($at == $bt)
return(0);
if($at < $bt)
return(1);
else
return(-1);
}
usort($postresults, 'cmp');
$postresults = array_slice($postresults, 0,10); //limit number of results
foreach ($postresults as $postresult) {
$siteurl = $wpdb->get_col("SELECT option_value FROM wp_". $postresult[6] ."_options WHERE option_name='siteurl'");
$blogname = $wpdb->get_col("SELECT option_value FROM wp_". $postresult[6] ."_options WHERE option_name='blogname'");
//todo - this is an array, need to sort and pull out
//$catitems = $wpdb->get_col("SELECT category_id FROM wp_".$postresult[6]."_post2cat WHERE $postitems->ID ORDER BY category_id");
?>
<a href="<?php echo $postresult[2]; ?>" rel="bookmark" title=' du blog F1 : "<?php echo $postresult[1]; ?>"' target="_blank"> - <?php echo $postresult[1]; ?></a>
<?php } ?> |
Partager