Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!

Untitled

By: Viruthagiri on Feb 11th, 2012  |  syntax: PHP Brief  |  size: 3.27 KB  |  views: 153  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. global $name_or_url;
  2. global $begin_wrap;
  3. global $end_wrap;
  4. // determine whether using vhosts or not for both functions to use
  5. $vhosts = (defined( "VHOST" ) && constant( "VHOST" ) == 'yes' );
  6.  
  7. function echoArrayBlogList($arrayName, $name_sort) {
  8.     global $wpdb;
  9.     global $name_or_url;
  10.     global $begin_wrap;
  11.     global $end_wrap;
  12.         global $vhosts;
  13.        
  14.     $intArrayCount = 0;
  15.     $bid = '';
  16.         // if blog name requested, then get it
  17.         if ($name_or_url == "name") {
  18.                 $blogs = array();
  19.                 $i = 1;
  20.                 foreach ($arrayName as $blog) {
  21.                         $blogname = get_blog_option( $blog['blog_id'], "blogname");
  22.                         $blogs[$i] = array('key' => strtolower($blogname), // give it a key to sort by
  23.                                                                                         'blog_name' => $blogname,
  24.                                                                                         'blog_id' => $blog['blog_id'],
  25.                                                                                         'domain' => $blog['domain']);
  26.                         $i++;
  27.                 }
  28.                 // now sort if requested
  29.                 if($name_sort) {
  30.                         asort($blogs);
  31.                 }
  32.                 // replace array
  33.                 $arrayName = $blogs;
  34.         }
  35.     foreach ($arrayName as $blog) {
  36.                 // get blog url depending on vhost or not-vhost installtion
  37.                 if( $vhosts )
  38.                         $tmp_domain = $blog['domain'];
  39.                 else
  40.                         $tmp_domain = get_blog_option( $blog['blog_id'], "siteurl");
  41.                 if ($name_or_url == "name") {
  42.                         $tmp_display = $blog['blog_name'];
  43.                 } else {
  44.                         $tmp_display = $tmp_domain;
  45.                 }
  46.                 // get blog url depending on vhost or not-vhost installtion
  47.                 if( $vhosts )
  48.                         echo $begin_wrap . "<a href='http://" . $tmp_domain . $blog['path'] . "'>" . $tmp_display . "</a>" . $end_wrap;
  49.                 else
  50.                         echo $begin_wrap . "<a href='" . $tmp_domain . "'>" . $tmp_display . "</a>" . $end_wrap;
  51.         }
  52. }
  53.  
  54. function list_all_wpmu_blogs($tmp_limit, $tmp_name_or_url, $tmp_begin_wrap, $tmp_end_wrap, $tmp_order) {
  55.     global $wpdb;
  56.     global $name_or_url;
  57.     global $begin_wrap;
  58.     global $end_wrap;
  59.         global $vhosts;
  60.  
  61.     if ($tmp_limit != "") {
  62.         $limit = "LIMIT " . $tmp_limit;
  63.     }
  64.     if ($tmp_name_or_url == "" || $tmp_name_or_url == "name") {
  65.         $name_or_url = "name";
  66.                         // did user request sort by blog_name
  67.                 $name_sort = ($tmp_order == "blog_name");
  68.     } else {
  69.         $name_or_url = "url";
  70.                 $name_sort = false;
  71.     }
  72.     if (tmp_begin_wrap == "" || tmp_end_wrap == "" ) {
  73.         $begin_wrap = "<p>";
  74.         $end_wrap = "</p>";
  75.     } else {
  76.         $begin_wrap = $tmp_begin_wrap;
  77.         $end_wrap = $tmp_end_wrap;
  78.     }
  79.     if ($tmp_order == "" || $tmp_order == "updated") {
  80.         $order = "ORDER BY  last_updated DESC";
  81.         } else if ($tmp_order == "first_created") {
  82.         $order = "ORDER BY  blog_id ASC";
  83.         } else if ($tmp_order == "last_created") {
  84.                 $order = "ORDER BY  blog_id DESC";
  85.         } else if ($tmp_order == "domain") {
  86.                 $order = "ORDER BY  domain ASC";
  87.     }
  88.         // if vhosts retrieve all the data from global table in one query
  89.         if($vhosts) {
  90.                 $extra = "domain, path, ";
  91.         }
  92.        
  93.     $blog_list = $wpdb->get_results( "SELECT " . $extra . "blog_id, last_updated FROM " . $wpdb->blogs.
  94.                 " WHERE public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted ='0' " . $order . " " . $limit . "", ARRAY_A );
  95.     if (count($blog_list) < 2 ){ // we don't want to display the admin blog so we return this even if there is one blog
  96.         echo "<p>This are currently no active blogs</p>";
  97.     } else {
  98.         echoArrayBlogList($blog_list, $name_sort);
  99.     }
  100. }