Advertisement
Viruthagiri

list-all.php

Feb 11th, 2012
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. Plugin Name: List-All
  4. Plugin URI: http://www.wpmudev.org/project/list-all
  5. Description: Creates a list of all blogs on a WPMU site (modified by <a href="http://atypicalhomeschool.net">Ron Rennick</a>)
  6. Author: Andrew Billits
  7. Author URI: http://wpmudev.org
  8. Version: 0.0.5
  9. */
  10.  
  11. global $name_or_url;
  12. global $begin_wrap;
  13. global $end_wrap;
  14. // determine whether using vhosts or not for both functions to use
  15. $vhosts = (defined( "VHOST" ) && constant( "VHOST" ) == 'yes' );
  16.  
  17. function echoArrayBlogList($arrayName, $name_sort) {
  18.     global $wpdb;
  19.     global $name_or_url;
  20.     global $begin_wrap;
  21.     global $end_wrap;
  22.     global $vhosts;
  23.    
  24.     $intArrayCount = 0;
  25.     $bid = '';
  26.     // if blog name requested, then get it
  27.     if ($name_or_url == "name") {
  28.         $blogs = array();
  29.         $i = 1;
  30.         foreach ($arrayName as $blog) {
  31.             $blogname = get_blog_option( $blog['blog_id'], "blogname");
  32.             $blogs[$i] = array('key' => strtolower($blogname), // give it a key to sort by
  33.                                             'blog_name' => $blogname,
  34.                                             'blog_id' => $blog['blog_id'],
  35.                                             'domain' => $blog['domain']);
  36.             $i++;
  37.         }
  38.         // now sort if requested
  39.         if($name_sort) {
  40.             asort($blogs);
  41.         }
  42.         // replace array
  43.         $arrayName = $blogs;
  44.     }
  45.     foreach ($arrayName as $blog) {
  46.         // get blog url depending on vhost or not-vhost installtion
  47.         if( $vhosts )
  48.             $tmp_domain = $blog['domain'];
  49.         else
  50.             $tmp_domain = get_blog_option( $blog['blog_id'], "siteurl");
  51.         if ($name_or_url == "name") {
  52.             $tmp_display = $blog['blog_name'];
  53.         } else {
  54.             $tmp_display = $tmp_domain;
  55.         }
  56.         // get blog url depending on vhost or not-vhost installtion
  57.         if( $vhosts )
  58.             echo $begin_wrap . "<a href='http://" . $tmp_domain . $blog['path'] . "'>" . $tmp_display . "</a>" . $end_wrap;
  59.         else
  60.             echo $begin_wrap . "<a href='" . $tmp_domain . "'>" . $tmp_display . "</a>" . $end_wrap;
  61.     }
  62. }
  63.  
  64. function list_all_wpmu_blogs($tmp_limit, $tmp_name_or_url, $tmp_begin_wrap, $tmp_end_wrap, $tmp_order) {
  65.     global $wpdb;
  66.     global $name_or_url;
  67.     global $begin_wrap;
  68.     global $end_wrap;
  69.     global $vhosts;
  70.  
  71.     if ($tmp_limit != "") {
  72.         $limit = "LIMIT " . $tmp_limit;
  73.     }
  74.     if ($tmp_name_or_url == "" || $tmp_name_or_url == "name") {
  75.         $name_or_url = "name";
  76.             // did user request sort by blog_name
  77.         $name_sort = ($tmp_order == "blog_name");
  78.     } else {
  79.         $name_or_url = "url";
  80.         $name_sort = false;
  81.     }
  82.     if (tmp_begin_wrap == "" || tmp_end_wrap == "" ) {
  83.         $begin_wrap = "<p>";
  84.         $end_wrap = "</p>";
  85.     } else {
  86.         $begin_wrap = $tmp_begin_wrap;
  87.         $end_wrap = $tmp_end_wrap;
  88.     }
  89.     if ($tmp_order == "" || $tmp_order == "updated") {
  90.         $order = "ORDER BY  last_updated DESC";
  91.     } else if ($tmp_order == "first_created") {
  92.         $order = "ORDER BY  blog_id ASC";
  93.     } else if ($tmp_order == "last_created") {
  94.         $order = "ORDER BY  blog_id DESC";
  95.     } else if ($tmp_order == "domain") {
  96.         $order = "ORDER BY  domain ASC";
  97.     }
  98.     // if vhosts retrieve all the data from global table in one query
  99.     if($vhosts) {
  100.         $extra = "domain, path, ";
  101.     }
  102.    
  103.     $blog_list = $wpdb->get_results( "SELECT " . $extra . "blog_id, last_updated FROM " . $wpdb->blogs.
  104.         " WHERE public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted ='0' " . $order . " " . $limit . "", ARRAY_A );
  105.     if (count($blog_list) < 2 ){ // we don't want to display the admin blog so we return this even if there is one blog
  106.         echo "<p>This are currently no active blogs</p>";
  107.     } else {
  108.         echoArrayBlogList($blog_list, $name_sort);
  109.     }
  110. }
  111.  
  112. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement