Guest User

bobthemonster

a guest
Feb 25th, 2009
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.10 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: List-All-Recent-Posts
  4. Plugin URI: http://www.wpmudev.org/project/list-all-Posts-multi
  5. Description: Creates a list of most recent posts across all active blogs.
  6. Author: Eric Estabrooks, derived from the work of Andrew Billits
  7. Author URI: http://wpmudev.org
  8. Version: 0.0.2
  9. Note: Derived from http://www.wpmudev.org/project/list-all-Posts
  10. */
  11.  
  12. global $word_limit;
  13. global $title_begin_wrap;
  14. global $title_end_wrap;
  15. global $begin_wrap;
  16. global $end_wrap;
  17. global $table_prefix;
  18. global $read_more;
  19. global $show_author;
  20. global $show_blog;
  21.  
  22. function list_all_posts_summary_multi($content, $limit){
  23.  
  24. $content = explode(' ',$content);
  25. for($i=0; $i<$limit; $i++){
  26. $summary[$i] = $content[$i];
  27. }
  28. $summary = implode(' ', $summary).'..';
  29.  
  30. return $summary;
  31. }
  32.  
  33.  
  34. function echoAllRecentPosts($arrayName, $limit) {
  35.     global $wpdb;
  36.     global $table_prefix;
  37.     global $word_limit;
  38.     global $title_begin_wrap;
  39.     global $title_end_wrap;
  40.     global $begin_wrap;
  41.     global $end_wrap;
  42.     global $read_more;
  43.     global $show_author;
  44.     global $show_blog;
  45.    
  46.     $intArrayCount = 0;
  47.     $bid = '';
  48.    
  49.     $sqlGetPosts = "";
  50.     foreach ($arrayName as $arrayElement) {
  51.         $bid = $arrayElement->blog_id;
  52.         $tmp_SQL = "SELECT post_content, post_title, post_author, post_date_gmt, $bid as blog_id  FROM wp_".$bid."_posts WHERE post_type = 'post'";
  53.         if ( strlen( $sqlGetPosts) > 0){
  54.             $sqlGetPosts .= "UNION ";
  55.         }          
  56.         $sqlGetPosts .= $tmp_SQL;
  57.     }
  58.    
  59.     $sqlGetPosts .= " ORDER BY post_date_gmt DESC " . $limit;
  60.     $post_list = $wpdb->get_results( $sqlGetPosts, ARRAY_A );
  61.    
  62.     foreach ($post_list as $post) {
  63.        
  64.         $tmp_post_content = $post["post_content"];
  65.         $tmp_post_title = $post["post_title"];
  66.        
  67.         $tmp_post_author = $wpdb->get_var("SELECT display_name FROM $wpdb->users WHERE ID = '" . $post["post_author"] . "'");
  68.        
  69.         $bid = $post["blog_id"];
  70.         $tmp_blog_name = $wpdb->get_var("SELECT option_value FROM " . "wp_" . $bid . "_options" . " WHERE option_name = 'blogname'");
  71.        
  72.         $tmp_domain = $wpdb->get_row("SELECT domain FROM $wpdb->blogs WHERE blog_id = '" . $bid . "'");
  73.         $tmp_path = $wpdb->get_row("SELECT path FROM $wpdb->blogs WHERE blog_id = '" . $bid . "'");
  74.         $tmp_siteurl = $wpdb->get_var("SELECT option_value FROM " . "wp_" . $bid . "_options" . " WHERE option_name = 'siteurl'");
  75.  
  76.         $info = ' - Posted ';
  77.         if ($show_blog == "show"){
  78.             $info = $info .'to ' . $tmp_blog_name . ' ';               
  79.         }
  80.         if ($show_author == "show"){
  81.             $info = $info .'by ' . ucfirst($tmp_post_author);              
  82.         }
  83.         if ($show_author && $show_blog == 'hide'){
  84.             $info = '';            
  85.         }
  86.        
  87.         $info = stripslashes($info);
  88.  
  89.         if ($bid == 1) {
  90.             //skip if main blog
  91.         } else {
  92.             if( constant( 'VHOST' ) == 'yes' ) {
  93.                 echo $title_begin_wrap . "<a href='" . $tmp_siteurl . "'>" . $tmp_post_title . "</a>" . $info . $title_end_wrap;
  94.                 if ($word_limit == '') {
  95.                     echo $begin_wrap . $tmp_post_content . $end_wrap;
  96.                 } else {
  97.                     if ($read_more == 'show') {
  98.                         echo $begin_wrap . list_all_posts_summary_multi($tmp_post_content, $word_limit) . " <a href='" . $tmp_siteurl . "'>(Read More)</a>" . $end_wrap;                       
  99.                     } else {
  100.                         echo $begin_wrap . list_all_posts_summary_multi($tmp_post_content, $word_limit) . $end_wrap;
  101.                     }
  102.                 }
  103.             } else {
  104.                 echo $title_begin_wrap . "<a href='" . $tmp_siteurl . "'>" . $tmp_post_title . "</a>" . $info . $title_end_wrap;
  105.                 if ($word_limit == '') {
  106.                     echo $begin_wrap . strip_tags($tmp_post_content) . $end_wrap;                  
  107.                 } else {
  108.                     if ($read_more == 'show') {
  109.                         echo $begin_wrap . strip_tags(list_all_posts_summary_multi($tmp_post_content, $word_limit)) . " <a href='" . $tmp_siteurl . "'>(Read More)</a>" . $end_wrap;                       
  110.                     } else {
  111.                         echo $begin_wrap . strip_tags(list_all_posts_summary_multi($tmp_post_content, $word_limit)) . $end_wrap;
  112.                     }
  113.                 }
  114.             }
  115.         }      
  116.     }
  117. }
  118.  
  119. function list_all_wpmu_recent_posts($tmp_limit, $tmp_word_limit, $tmp_begin_wrap, $tmp_end_wrap, $tmp_title_begin_wrap, $tmp_title_end_wrap, $tmp_read_more,$tmp_show_author,$tmp_show_blog) {
  120.     global $wpdb;
  121.     global $word_limit;
  122.     global $title_begin_wrap;
  123.     global $title_end_wrap;
  124.     global $begin_wrap;
  125.     global $end_wrap;
  126.     global $read_more;
  127.     global $show_author;
  128.     global $show_blog;
  129.     if ($tmp_show_blog == "show") {
  130.         $show_blog = "show";
  131.     } else {
  132.         $show_blog = "hide";
  133.     }
  134.     if ($tmp_read_more == "show") {
  135.         $read_more = "show";
  136.     } else {
  137.         $read_more = "hide";
  138.     }
  139.     if ($tmp_show_author == "show") {
  140.         $show_author = "show";
  141.     } else {
  142.         $show_author = "hide";
  143.     }      
  144.     if ($tmp_word_limit == "") {
  145.         //no limit
  146.     } else {
  147.         $word_limit = $tmp_word_limit;
  148.     }
  149.     if ($tmp_limit == "") {
  150.         //no limit
  151.     } else {
  152.         $limit = "LIMIT " . $tmp_limit;
  153.     }
  154.     if (tmp_begin_wrap == "" || tmp_end_wrap == "" ) {
  155.         $begin_wrap = "<p>";
  156.         $end_wrap = "</p>";
  157.     } else {
  158.         $begin_wrap = $tmp_begin_wrap;
  159.         $end_wrap = $tmp_end_wrap;
  160.     }
  161.     if (tmp_title_begin_wrap == "" || tmp_title_end_wrap == "" ) {
  162.         $title_begin_wrap = "<p>";
  163.         $title_end_wrap = "</p>";
  164.     } else {
  165.         $title_begin_wrap = $tmp_title_begin_wrap;
  166.         $title_end_wrap = $tmp_title_end_wrap;
  167.     }
  168.     if ($tmp_order == "") {
  169.         $order = "ORDER BY  last_updated DESC";
  170.     } else {
  171.         if ($tmp_order == "updated") {
  172.             $order = "ORDER BY  last_updated DESC";
  173.         }
  174.         if ($tmp_order == "first_created") {
  175.             $order = "ORDER BY  blog_id ASC";
  176.         }
  177.         if ($tmp_order == "last_created") {
  178.             $order = "ORDER BY  blog_id DESC";
  179.         }
  180.     }
  181.    
  182.     $blog_list = $wpdb->get_results( "SELECT blog_id from wp_blogs where public = 1" );
  183.     $check_blogs = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->blogs . "");
  184.     if ($check_blogs == 0 || $check_blogs == 1 ){ // we don't want to display the admin blog so we return this even if there is one blog
  185.         echo "<p>This are currently no active blogs</p>";
  186.     } else {
  187.         echoAllRecentPosts($blog_list, $limit);
  188.     }
  189. }
  190. ?>
Advertisement
Add Comment
Please, Sign In to add comment