get('post');
//Pages
$stats[] = '页面数:' . $y->get('page');
//Categories
$stats[] = '分类数:' . $y->get('categorie');
//Links
$stats[] = '链接数:' . $y->get('links');
//Tags
if (function_exists('UTW_ShowRelatedPostsForCurrentPost'))
$stats[] = 'Tag 数:' . $y->get('tag');
//Comments
$stats[] = '评论数:' . $y->get('comment');
//Comments by guest/Comments by author
$stats[] = '来宾/作者:' . $y->get('comment_guest') . '/' . $y->get('comment_author');
//Trackback&Pingback
$stats[] = 'TBPB数:' . $y->get('pingback');
//Word counts
$stats[] = '总字数:' . $y->get('word');
//Blog建立时间
$createdate = strtotime('2006-4-1');
$stats[] = '建站日期:' . date('Y年n月j日', $createdate) . '';
//First post date
//$stats[] = '最早文章日期:
' . $y->get('firstpost');
//Last Update
$stats[] = '最后更新日期:
' . $y->get('lastupdate');
//Cache stat
if ( defined('ENABLE_CACHE') ) {
global $wp_object_cache;
// No cache this item
$stats[] = 'Cold/Warm/Miss:' . $wp_object_cache->cold_cache_hits . '/' . $wp_object_cache->warm_cache_hits . '/' . $wp_object_cache->cache_misses;
}
unset($stats_result);
if ($style) {
$stats_result = implode("
\n", $stats);
} else {
foreach($stats as $s2)
$stats_result .= "
" . $s2 . "\n";
}
$y->close(); //析构对象
echo $stats_result;
}
// mb_strlen1
if ( !function_exists('mb_strlen1') ):
function mb_strlen1($str) {
$num = 0;
for ($i=0; $icache[$str])) return $this->cache[$str];
switch ($str) {
case 'post':
$result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE (post_status = 'publish' OR post_status = 'private') AND post_date_gmt < '{$this->now}'");
break;
case 'page':
$result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'static' AND post_date_gmt < '{$this->now}'");
break;
case 'categorie':
$result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->categories");
break;
case 'links':
$result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = 'Y'");
break;
case 'tag':
global $tabletags;
$result = $wpdb->get_var("SELECT COUNT(*) FROM $tabletags");
break;
case 'comment':
$result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1' AND comment_type != 'trackback' AND comment_type != 'pingback'");
break;
case 'comment_guest':
$result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1' AND comment_type != 'trackback' AND comment_type != 'pingback' AND user_id = 0");
break;
case 'comment_author':
$result = $this->get('comment') - $this->get('comment_guest');
break;
case 'pingback':
$result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1' AND (comment_type = 'trackback' OR comment_type = 'pingback')");
break;
case 'word':
$words = $wpdb->get_results("SELECT post_content FROM $wpdb->posts WHERE (post_status = 'publish' OR post_status = 'private' OR post_status = 'static') AND post_date_gmt < '{$this->now}'");
$result = 0;
if ( function_exists('mb_strlen') ) {
foreach ($words as $word)
$result += mb_strlen(preg_replace('/\s/', '', html_entity_decode( strip_tags($word->post_content) ) ), 'UTF-8');
} else {
foreach ($words as $word)
$result += mb_strlen1(preg_replace('/\s/', '', html_entity_decode( strip_tags($word->post_content) ) ), 'UTF-8');
}
break;
case 'firstpost':
$result = $wpdb->get_results("SELECT MIN(post_modified) AS MIN_m FROM $wpdb->posts WHERE (post_status = 'publish' OR post_status = 'static')");
$result = date('Y-n-j', strtotime($result[0]->MIN_m));
break;
case 'lastupdate':
$result = $wpdb->get_results("SELECT MAX(post_modified) AS MAX_m FROM $wpdb->posts WHERE (post_status = 'publish' OR post_status = 'static') AND post_date_gmt < '{$this->now}'");
$result = date('Y-n-j g:ia', strtotime($result[0]->MAX_m));
break;
default:
break;
}
$this->cache[$str] = $result;
return $result;
}
function Ystat() {
$this->cache = wp_cache_get('ystat', 'plugins');
if ($this->cache == false) $this->cache = array();
$this->cachelen = count($this->cache);
$this->now = current_time('mysql', 1);
}
function close() {
if ($this->cachelen <> count($this->cache)) wp_cache_set('ystat', $this->cache, 'plugins');
}
}
function widget_Ystat_init() {
if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') )
return;
function statistics_sidebar_module($args) {
extract($args);
echo($before_widget . $before_title . $title . $after_title . "");
ShowStatistics();
echo("
" . $after_widget);
}
register_sidebar_widget('Statistics module', 'statistics_sidebar_module', 'sb-stat');
}
add_action('plugins_loaded', 'widget_Ystat_init');
?>