function render_output($wgt_miss, $wgt_count, $wgt_format, $wgt_avsize, $wgt_defav, $wgt_dt, $before_item, $after_item, $before_cont, $after_cont, $wgt_mtext, $ord, $ordb, $wgt_white, $min_post_count, $comment_age)
 {
     global $DiamondCache;
     $cachekey = 'diamond_bloglist_' . diamond_arr_to_str($wgt_miss) . '-' . $wgt_count . '-' . $wgt_format . diamond_arr_to_str($wgt_white) . '-' . $wgt_avsize . '-' . $wgt_defav . '-' . $wgt_dt . '-' . $before_item . '-' . $after_item . '-' . $before_cont . '-' . $after_cont . '-' . $wgt_mtext . '-' . $ord . '-' . $ordb . '-' . $min_post_count . '-' . $comment_age;
     $output = $DiamondCache->get($cachekey, 'bloglist');
     if ($output != false) {
         return $output;
     }
     global $switched;
     global $wpdb;
     $table_prefix = $wpdb->base_prefix;
     if (!isset($wgt_dt) || trim($wgt_dt) == '') {
         $wgt_dt = __('M. d. Y.', 'diamond');
     }
     if (!isset($wgt_avsize) || $wgt_avsize == '') {
         $wgt_avsize = 96;
     }
     if (!isset($before_item) || $before_item == '') {
         $before_item = '<li>';
     }
     if (!isset($after_item) || $after_item == '') {
         $after_item = '</li>';
     }
     if (!isset($before_cont) || $before_cont == '') {
         $before_cont = '<ul>';
     }
     if (!isset($after_cont) || $after_cont == '') {
         $after_cont = '</ul>';
     }
     if (!isset($wgt_miss) || $wgt_miss == '' || count($wgt_count) == 1 && $wgt_miss[0] == '') {
         $wgt_miss = array();
     }
     $white = 0;
     if (isset($wgt_white) && $wgt_white != '' && count($wgt_white) > 0 && $wgt_white[0] && $wgt_white[0] != '') {
         $white = 1;
     }
     $sqlstr = '';
     $felt = '';
     $sep = '';
     if ($white == 0) {
         if (count($wgt_miss) > 0) {
             $felt = ' AND blog_id NOT IN (';
             foreach ($wgt_miss as $m) {
                 $felt .= $sep . $m;
                 $sep = ', ';
             }
             $felt .= ') ';
         }
     } else {
         $felt = ' AND blog_id IN (';
         foreach ($wgt_white as $m) {
             $felt .= $sep . $m;
             $sep = ', ';
         }
         $felt .= ') ';
     }
     //print_r($wgt_miss);
     if ($ord != 4) {
         $sqlstr = "SELECT blog_id, registered, last_updated from " . $table_prefix . "blogs where public = 1 AND spam = 0 AND archived = 0 AND deleted = 0 " . $felt;
         $limit = '';
         if ((int) $wgt_count > 0) {
             $limit = ' LIMIT 0, ' . (int) $wgt_count;
         }
         if (!$ord || $ord == '') {
             $ord = 0;
         }
         $sqlstr .= " ORDER BY ";
         switch ($ord) {
             default:
                 $sqlstr .= "path ";
                 break;
             case 1:
                 $sqlstr .= "registered ";
                 break;
             case 2:
                 $sqlstr .= "last_updated ";
                 break;
         }
     } else {
         //Order by number of comments from last x days
         $sqlstr = "SELECT blog_id, registered, last_updated from " . $table_prefix . "blogs where public = 1 AND spam = 0 AND archived = 0 AND deleted = 0 " . $felt;
         $blog_list_temp = $wpdb->get_results($sqlstr, ARRAY_A);
         if (false === $blog_list_temp) {
             echo $wpdb->print_error();
         }
         $sqlstr = '';
         $age_set = '';
         if ($comment_age != '' && (int) $comment_age > 0) {
             $age_set = "where datediff(now(), comment_date)<" . $comment_age;
         }
         foreach ($blog_list_temp as $blog) {
             $tbprefix = $blog['blog_id'] == 1 ? '' : $blog['blog_id'] . '_';
             $tbprefix = $table_prefix . $tbprefix;
             if ($sqlstr != '') {
                 $sqlstr .= ' union ';
             }
             $sqlstr .= " select " . $blog['blog_id'] . " as blog_id, '" . $blog['registered'] . "' as registered, '" . $blog['last_updated'] . "' as last_updated, count(comment_ID) as comment_count from " . $tbprefix . "comments " . $age_set . " group by blog_id";
         }
         $sqlstr .= " order by comment_count ";
         $limit = '';
         if ((int) $wgt_count > 0) {
             $limit = ' LIMIT 0, ' . (int) $wgt_count;
         }
     }
     if (!$ordb || $ordb == '') {
         $ordb = 0;
     }
     switch ($ordb) {
         default:
             $sqlstr .= "asc ";
             break;
         case 1:
             $sqlstr .= "desc ";
             break;
     }
     $sqlstr .= $limit;
     //echo $sqlstr;
     $blog_list_temp = $wpdb->get_results($sqlstr, ARRAY_A);
     if (false === $blog_list_temp) {
         echo $wpdb->print_error();
     }
     //print_r($blog_list);
     $output = '';
     $output .= $before_cont;
     if ($ord == 3) {
         foreach ($blog_list_temp as $blog) {
             switch_to_blog($blog['blog_id']);
             $count = wp_count_posts()->publish;
             restore_current_blog();
             $blog_list[$count] = $blog;
             $blog_list[$count]['count'] = $count;
         }
         ksort($blog_list);
         if ($ordb == 1) {
             $blog_list = array_reverse($blog_list);
         }
     } else {
         $blog_list = $blog_list_temp;
     }
     foreach ($blog_list as $blog) {
         $wgt_format = get_format_txt($wgt_format);
         $txt = $wgt_format == '' ? '<b>{title}</b>' : $wgt_format;
         $title = '';
         $desc = '';
         $burl = '';
         $pcount = 0;
         $avatar = '';
         switch_to_blog($blog['blog_id']);
         if (strpos($txt, '{title}') !== false || strpos($txt, '{title_txt}') !== false) {
             $title = get_bloginfo('name');
         }
         if (strpos($txt, '{description}') !== false) {
             $desc = get_bloginfo('description');
         }
         $burl = get_bloginfo('url');
         if (strpos($txt, '{postcount}') !== false || (int) $min_post_count > 0) {
             $pcount = wp_count_posts()->publish;
         }
         if (strpos($txt, '{avatar}') !== false) {
             $avatar = get_avatar(get_bloginfo('admin_email'), $wgt_avsize);
         }
         restore_current_blog();
         if ((int) $min_post_count <= $pcount) {
             $output .= $before_item;
             //@TODO add trailing shash only if in subdir mode
             $txt = str_replace('{title}', '<a href="' . $burl . '/">' . $title . '</a>', $txt);
             $txt = str_replace('{more}', '<a href="' . $burl . '/">' . $wgt_mtext . '</a>', $txt);
             $txt = str_replace('{title_txt}', $title, $txt);
             $txt = str_replace('{reg}', date_i18n($wgt_dt, strtotime($blog['registered'])), $txt);
             $txt = str_replace('{last_update}', date_i18n($wgt_dt, strtotime($blog['last_updated'])), $txt);
             $txt = str_replace('{description}', $desc, $txt);
             $txt = str_replace('{postcount}', $pcount, $txt);
             $txt = str_replace('{comment_count}', $blog['comment_count'], $txt);
             $txt = str_replace('{avatar}', $avatar, $txt);
             $output .= $txt;
             $output .= $after_item;
         }
     }
     $output .= $after_cont;
     if (false === $blog_list) {
         $output .= $wpdb->print_error();
     }
     $DiamondCache->add($cachekey, 'bloglist', $output);
     return $output;
 }
 function render_output($wgt_miss, $wgt_count, $wgt_format, $wgt_avsize, $wgt_defav, $wgt_dt, $before_item, $after_item, $before_cont, $after_cont, $wgt_mtext, $wgt_white, $post_limit = 0)
 {
     global $DiamondCache;
     $cachekey = 'diamond_post_' . diamond_arr_to_str($wgt_miss) . '-' . $wgt_count . '-' . $wgt_format . diamond_arr_to_str($wgt_white) . '-' . $wgt_avsize . '-' . $wgt_defav . '-' . $wgt_dt . '-' . $before_item . '-' . $after_item . '-' . $before_cont . '-' . $after_cont . '-' . $wgt_mtext . '-' . $post_limit;
     $output = $DiamondCache->get($cachekey, 'recent-posts');
     if ($output != false) {
         return $output;
     }
     global $switched;
     global $wpdb;
     $table_prefix = $wpdb->base_prefix;
     if (!isset($wgt_dt) || trim($wgt_dt) == '') {
         $wgt_dt = 'M. d. Y.';
     }
     if (!isset($wgt_avsize) || $wgt_avsize == '') {
         $wgt_avsize = 96;
     }
     if (!isset($before_item) || $before_item == '') {
         $before_item = '<li>';
     }
     if (!isset($after_item) || $after_item == '') {
         $after_item = '</li>';
     }
     if (!isset($before_cont) || $before_cont == '') {
         $before_cont = '<ul>';
     }
     if (!isset($after_cont) || $after_cont == '') {
         $after_cont = '</ul>';
     }
     if (!isset($wgt_miss) || $wgt_miss == '') {
         $wgt_miss = array();
     }
     $white = 0;
     if (isset($wgt_white) && $wgt_white != '' && count($wgt_white) > 0 && $wgt_white[0] && $wgt_white[0] != '') {
         $white = 1;
     }
     $limitstr = '';
     if ((int) $post_limit > 0) {
         $limitstr = ' LIMIT ' . (int) $post_limit;
     }
     $sqlstr = '';
     $blog_list = get_blog_list(0, 'all');
     if ($white == 0 && !in_array(1, $wgt_miss) || $white == 1 && in_array(1, $wgt_white)) {
         $sqlstr = "(SELECT 1 as blog_id, id, post_date_gmt from " . $table_prefix . "posts where post_status = 'publish' and post_type = 'post' and post_title <> '" . __('Hello world!') . "' " . $limitstr . ")";
     }
     $uni = '';
     foreach ($blog_list as $blog) {
         if ($white == 0 && !in_array($blog['blog_id'], $wgt_miss) && $blog['blog_id'] != 1 || $white == 1 && $blog['blog_id'] != 1 && in_array($blog['blog_id'], $wgt_white)) {
             if ($sqlstr != '') {
                 $uni = ' union ';
             }
             $sqlstr .= $uni . " (SELECT " . $blog['blog_id'] . " as blog_id, id, post_date_gmt from " . $table_prefix . $blog['blog_id'] . "_posts  where post_status = 'publish' and post_type = 'post' and post_title <> '" . __('Hello world!') . "' " . $limitstr . ")";
         }
     }
     $limit = '';
     if ((int) $wgt_count > 0) {
         $limit = ' LIMIT 0, ' . (int) $wgt_count;
     }
     $sqlstr .= " ORDER BY post_date_gmt desc " . $limit;
     //echo $sqlstr;
     $post_list = $wpdb->get_results($sqlstr, ARRAY_A);
     //echo $wpdb->print_error();
     $output = '';
     $output .= $before_cont;
     foreach ($post_list as $post) {
         $output .= $before_item;
         $wgt_format = get_format_txt($wgt_format);
         $txt = $wgt_format == '' ? '<strong>{title}</strong> - {date}' : $wgt_format;
         $p = get_blog_post($post["blog_id"], $post["id"]);
         $av = get_avatar(get_userdata($p->post_author)->user_email, $wgt_avsize, $defav);
         $ex = $p->post_excerpt;
         if (!isset($ex) || trim($ex) == '') {
             $ex = mb_substr(strip_tags($p->post_content), 0, 65) . '...';
         }
         $txt = str_replace('{title}', '<a href="' . get_blog_permalink($post["blog_id"], $post["id"]) . '">' . $p->post_title . '</a>', $txt);
         $txt = str_replace('{more}', '<a href="' . get_blog_permalink($post["blog_id"], $post["id"]) . '">' . $wgt_mtext . '</a>', $txt);
         $txt = str_replace('{title_txt}', $p->post_title, $txt);
         $txt = str_replace('{date}', date_i18n($wgt_dt, strtotime($p->post_date)), $txt);
         $txt = str_replace('{excerpt}', $ex, $txt);
         $txt = str_replace('{author}', get_userdata($p->post_author)->nickname, $txt);
         $txt = str_replace('{avatar}', $av, $txt);
         $txt = str_replace('{blog}', get_blog_option($post["blog_id"], 'blogname'), $txt);
         $burl = get_blog_option($post["blog_id"], 'home');
         $txt = str_replace('{blog_link}', '<a href="' . $burl . '/">' . get_blog_option($post["blog_id"], 'blogname') . '</a>', $txt);
         $txt = str_replace('{blog_url}', $burl, $txt);
         $output .= $txt;
         $output .= $after_item;
     }
     $output .= $after_cont;
     if (false === $post_list) {
         $output .= $wpdb->print_error();
     }
     $DiamondCache->add($cachekey, 'recent-posts', $output);
     return $output;
 }
 function render_output($wgt_miss, $wgt_count, $wgt_format, $wgt_avsize, $wgt_defav, $wgt_dt, $before_item, $after_item, $before_cont, $after_cont, $wgt_white, $comment_type)
 {
     global $DiamondCache;
     $cachekey = 'diamond_comments_' . diamond_arr_to_str($wgt_miss) . '-' . $wgt_count . '-' . $wgt_format . diamond_arr_to_str($wgt_white) . '-' . $wgt_avsize . '-' . $wgt_defav . '-' . $wgt_dt . '-' . $before_item . '-' . $after_item . '-' . $before_cont . '-' . $after_cont . '-' . $wgt_mtext . '-' . $comment_type;
     $output = $DiamondCache->get($cachekey, 'recent-comments');
     if ($output != false) {
         return $output;
     }
     global $switched;
     global $wpdb;
     $table_prefix = $wpdb->base_prefix;
     if (!isset($wgt_dt) || trim($wgt_dt) == '') {
         $wgt_dt = 'M. d. Y.';
     }
     if (!isset($wgt_avsize) || $wgt_avsize == '') {
         $wgt_avsize = 96;
     }
     if (!isset($before_item) || $before_item == '') {
         $before_item = '<li>';
     }
     if (!isset($after_item) || $after_item == '') {
         $after_item = '</li>';
     }
     if (!isset($before_cont) || $before_cont == '') {
         $before_cont = '<ul>';
     }
     if (!isset($after_cont) || $after_cont == '') {
         $after_cont = '</ul>';
     }
     if (!isset($wgt_miss) || $wgt_miss == '') {
         $wgt_miss = array();
     }
     $white = 0;
     if (isset($wgt_white) && $wgt_white != '' && count($wgt_white) > 0 && $wgt_white[0] && $wgt_white[0] != '') {
         $white = 1;
     }
     $first_comment = __('Hi, this is a comment.<br />To delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.');
     $first_comment = get_site_option('first_comment', $first_comment);
     $sqlstr = '';
     $where_comment_type = " and (comment_type = '' or comment_type is null) ";
     if ($comment_type != '') {
         $where_comment_type = " AND comment_type = '" . $comment_type . "' ";
     }
     $blog_list = get_blog_list(0, 'all');
     if ($white == 0 && !in_array(1, $wgt_miss) || $white == 1 && in_array(1, $wgt_white)) {
         $sqlstr = "SELECT 1 as blog_id, comment_date, comment_id, comment_post_id, comment_content, comment_date_gmt, comment_author, comment_author_email from " . $table_prefix . "comments where comment_approved = 1 " . $where_comment_type . " and comment_content <> '" . $first_comment . "'";
     }
     $uni = '';
     foreach ($blog_list as $blog) {
         if ($white == 0 && !in_array($blog['blog_id'], $wgt_miss) && $blog['blog_id'] != 1 || $white == 1 && $blog['blog_id'] != 1 && in_array($blog['blog_id'], $wgt_white)) {
             if ($sqlstr != '') {
                 $uni = ' union ';
             }
             $sqlstr .= $uni . " SELECT " . $blog['blog_id'] . " as blog_id, comment_date, comment_id, comment_post_id, comment_content, comment_date_gmt, comment_author, comment_author_email   from " . $table_prefix . $blog['blog_id'] . "_comments where comment_approved = 1  " . $where_comment_type . " and comment_content <> '" . $first_comment . "'";
         }
     }
     $limit = '';
     if ((int) $wgt_count > 0) {
         $limit = ' LIMIT 0, ' . (int) $wgt_count;
     }
     $sqlstr .= " ORDER BY comment_date_gmt desc " . $limit;
     // echo $sqlstr;
     $output = '';
     $comm_list = $wpdb->get_results($sqlstr, ARRAY_A);
     $output .= $before_cont;
     foreach ($comm_list as $comm) {
         $output .= $before_item;
         $wgt_format = get_format_txt($wgt_format);
         $txt = $wgt_format == '' ? '<strong>{title}</strong> - {date}' : $wgt_format;
         $p = get_blog_post($comm["blog_id"], $comm["comment_post_id"]);
         $c = $comm['comment_content'];
         $av = get_avatar($comm['comment_author_email'], $wgt_avsize, $defav);
         if (strlen($c) > 50) {
             $c = mb_substr(strip_tags($c), 0, 51) . '...';
         }
         $txt = str_replace('{title}', '<a href="' . get_blog_permalink($comm["blog_id"], $comm["comment_post_id"]) . '#comment-' . $comm["comment_id"] . '">' . $c . '</a>', $txt);
         $txt = str_replace('{title_txt}', $c, $txt);
         $txt = str_replace('{author}', $comm['comment_author'], $txt);
         $txt = str_replace('{avatar}', $av, $txt);
         $txt = str_replace('{post-title}', '<a href="' . get_blog_permalink($comm["blog_id"], $comm["comment_post_id"]) . '">' . $p->post_title . '</a>', $txt);
         $txt = str_replace('{post-title_txt}', $p->post_title, $txt);
         $txt = str_replace('{date}', date_i18n($wgt_dt, strtotime($comm['comment_date'])), $txt);
         $output .= $txt;
         $output .= $after_item;
     }
     $output .= $after_cont;
     if (false === $comm_list) {
         $output .= $wpdb->print_error();
     }
     $DiamondCache->add($cachekey, 'recent-comments', $output);
     return $output;
 }