get_results("SELECT ID, post_content, post_status, MID(post_date, 1, 7) AS post_date, post_title, post_author, post_type FROM $table_prefix"."posts WHERE post_status <> 'inherit' AND post_status <> 'auto-draft' AND (post_type = 'page' OR post_type = 'post') ORDER BY post_date DESC;"); foreach ($bjl_word_count_items as $items => $item) { // CALCULATE AND STORE MAIN STATS $words = word_counter($item->post_content); $arr_bjl_author_word_count[$item->post_author] = $arr_bjl_author_word_count[$item->post_author] + $words; $arr_bjl_month_word_count[$item->post_date] = $arr_bjl_month_word_count[$item->post_date] + $words; if ($item->post_type == "post") { if ($item->post_status == "publish") { $words_posts_publish += $words; $count_posts_publish++; $arr_bjl_author_posts_publish[$item->post_author] = $arr_bjl_author_posts_publish[$item->post_author] + 1; $arr_bjl_author_posts_publish_word_count[$item->post_author] = $arr_bjl_author_posts_publish_word_count[$item->post_author] + $words; $arr_bjl_month_posts_publish[$item->post_date] = $arr_bjl_month_posts_publish[$item->post_date] + 1; $arr_bjl_month_posts_publish_word_count[$item->post_date] = $arr_bjl_month_posts_publish_word_count[$item->post_date] + $words; } elseif ($item->post_status == "draft") { $words_posts_draft += $words; $count_posts_draft++; $arr_bjl_author_posts_draft[$item->post_author] = $arr_bjl_author_posts_draft[$item->post_author] + 1; $arr_bjl_author_posts_draft_word_count[$item->post_author] = $arr_bjl_author_posts_draft_word_count[$item->post_author] + $words; $arr_bjl_month_posts_draft[$item->post_date] = $arr_bjl_month_posts_draft[$item->post_date] + 1; $arr_bjl_month_posts_draft_word_count[$item->post_date] = $arr_bjl_month_posts_draft_word_count[$item->post_date] + $words; } } elseif ($item->post_type == "page") { if ($item->post_status == "publish") { $words_pages_publish += $words; $count_pages_publish++; $arr_bjl_author_pages_publish[$item->post_author] = $arr_bjl_author_pages_publish[$item->post_author] + 1; $arr_bjl_author_pages_publish_word_count[$item->post_author] = $arr_bjl_author_pages_publish_word_count[$item->post_author] + $words; $arr_bjl_month_pages_publish[$item->post_date] = $arr_bjl_month_pages_publish[$item->post_date] + 1; $arr_bjl_month_pages_publish_word_count[$item->post_date] = $arr_bjl_month_pages_publish_word_count[$item->post_date] + $words; } elseif ($item->post_status == "draft") { $words_pages_draft += $words; $count_pages_draft++; $arr_bjl_author_pages_draft[$item->post_author] = $arr_bjl_author_pages_draft[$item->post_author] + 1; $arr_bjl_author_pages_draft_word_count[$item->post_author] = $arr_bjl_author_pages_draft_word_count[$item->post_author] + $words; $arr_bjl_month_pages_draft[$item->post_date] = $arr_bjl_month_pages_draft[$item->post_date] + 1; $arr_bjl_month_pages_draft_word_count[$item->post_date] = $arr_bjl_month_pages_draft_word_count[$item->post_date] + $words; } } // ITEM STATS $arr_bjl_content_word_count[$item->ID] = $words; $arr_bjl_content_post_title[$item->ID] = $item->post_title; $arr_bjl_content_post_type[$item->ID] = $item->post_type; $arr_bjl_content_post_status[$item->ID] = $item->post_status; $arr_bjl_content_post_author[$item->ID] = $item->post_author; } // WRITE MAIN STATS TO OPTIONS TABLE $arr_bjl_word_count_main = array ( 'words_posts_publish' => $words_posts_publish, 'words_posts_draft' => $words_posts_draft, 'words_pages_publish' => $words_pages_publish, 'words_pages_draft' => $words_pages_draft, 'count_posts_publish' => $count_posts_publish, 'count_posts_draft' => $count_posts_draft, 'count_pages_publish' => $count_pages_publish, 'count_pages_draft' => $count_pages_draft ); update_option('bjl_word_count_main', $arr_bjl_word_count_main); // WRITE CACHED ITEMS TO OPTIONS TABLE $arr_bjl_word_count_cache = array ( 'bjl_content_word_count' => $arr_bjl_content_word_count, 'bjl_content_post_title' => $arr_bjl_content_post_title, 'bjl_content_post_type' => $arr_bjl_content_post_type, 'bjl_content_post_status' => $arr_bjl_content_post_status, 'bjl_content_post_author' => $arr_bjl_content_post_author ); update_option('bjl_word_count_cache', $arr_bjl_word_count_cache); // WRITE AUTHOR STATS TO OPTIONS TABLE $arr_bjl_word_count_author = array ( 'bjl_author_word_count' => $arr_bjl_author_word_count, 'bjl_author_posts_publish' => $arr_bjl_author_posts_publish, 'bjl_author_posts_publish_word_count' => $arr_bjl_author_posts_publish_word_count, 'bjl_author_posts_draft' => $arr_bjl_author_posts_draft, 'bjl_author_posts_draft_word_count' => $arr_bjl_author_posts_draft_word_count, 'bjl_author_pages_publish' => $arr_bjl_author_pages_publish, 'bjl_author_pages_publish_word_count' => $arr_bjl_author_pages_publish_word_count, 'bjl_author_pages_draft' => $arr_bjl_author_pages_draft, 'bjl_author_pages_draft_word_count' => $arr_bjl_author_pages_draft_word_count ); update_option('bjl_word_count_author', $arr_bjl_word_count_author); // WRITE MONTH STATS TO OPTIONS TABLE $arr_bjl_word_count_month = array ( 'bjl_month_word_count' => $arr_bjl_month_word_count, 'bjl_month_posts_publish' => $arr_bjl_month_posts_publish, 'bjl_month_posts_publish_word_count' => $arr_bjl_month_posts_publish_word_count, 'bjl_month_posts_draft' => $arr_bjl_month_posts_draft, 'bjl_month_posts_draft_word_count' => $arr_bjl_month_posts_draft_word_count, 'bjl_month_pages_publish' => $arr_bjl_month_pages_publish, 'bjl_month_pages_publish_word_count' => $arr_bjl_month_pages_publish_word_count, 'bjl_month_pages_draft' => $arr_bjl_month_pages_draft, 'bjl_month_pages_draft_word_count' => $arr_bjl_month_pages_draft_word_count ); update_option('bjl_word_count_month', $arr_bjl_word_count_month); } function word_counter($content) { //http://www.zhounaiming.com/entry/111 $str = strip_tags($content); $str = preg_replace('/[\x80-\xff]{1,3}/', ' ', $str,-1,$n); $n += str_word_count($str); return $n; } function bjl_word_count_admin() { if ( $_GET['ac'] == 'recount' || !get_option('bjl_word_count_main') ) { echo '

'; echo __("Counting... Please wait a few minutes and re-open this page.", 'asianwordcount'); echo '

'; word_count_calculate(); } if ( $_GET['ac'] == 'save') { echo '

'; echo __("Configuration Saved.", 'asianwordcount'); echo '

'; } // LOAD MAIN STATS $arr_bjl_word_count_main = get_option('bjl_word_count_main'); @extract($arr_bjl_word_count_main); // LOAD CACHED ITEMS $arr_bjl_word_count_cache = get_option('bjl_word_count_cache'); @extract($arr_bjl_word_count_cache); // LOAD AUTHOR STATS $arr_bjl_word_count_author = get_option('bjl_word_count_author'); @extract($arr_bjl_word_count_author); // LOAD MONTH STATS $arr_bjl_word_count_month = get_option('bjl_word_count_month'); @extract($arr_bjl_word_count_month); // OUTPUT DATA echo '
'; echo '

'.__("Asian Word Count", 'asianwordcount').''.__("Re-Count", 'asianwordcount').'

'; echo ''; echo ''; echo ''; if ($_GET["largest"] == "all") { echo '

'.__("All Posts & Pages", 'asianwordcount').'

'; } else { echo '

'.__("Largest Posts & Pages", 'asianwordcount').'

'; } $bjl_wp_posts_total = count($bjl_content_word_count); if ($bjl_wp_posts_total > 10) { $bjl_wp_posts_top = 10; } else { $bjl_wp_posts_top = $bjl_wp_posts_total; } echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; arsort($bjl_content_word_count); $bjl_largest_counter = 0; $bjl_largest_limit = 10; foreach($bjl_content_word_count as $key => $value) { $user = get_userdata($bjl_content_post_author[$key]); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $bjl_largest_counter++; if ($_GET["largest"] != "all" && $bjl_largest_counter == $bjl_largest_limit) break; } echo ''; echo '
'.__("Words", 'asianwordcount').''.__("Title", 'asianwordcount').''.__("Type", 'asianwordcount').''.__("Status", 'asianwordcount').''.__("Author", 'asianwordcount').'
'.number_format($value).''.$bjl_content_post_title[$key].''.ucwords($bjl_content_post_type[$key]).''.ucwords($bjl_content_post_status[$key]).''.$user->user_login.'
'; echo '

'.__("Author Statistics", 'asianwordcount').'

'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $bjl_author_counter = 0; foreach($bjl_author_word_count as $key => $value) { $user = get_userdata($key); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $bjl_author_counter++; } echo ''; echo '
'.__("Author", 'asianwordcount').''.__("Words", 'asianwordcount').''.__("Published Posts", 'asianwordcount').''.__("Published Pages", 'asianwordcount').''.__("Published Total", 'asianwordcount').''.__("Draft Posts", 'asianwordcount').''.__("Draft Pages", 'asianwordcount').''.__("Draft Total", 'asianwordcount').'
'.$user->user_login.''.number_format($value).''.number_format($bjl_author_posts_publish_word_count[$key]).' '.__("Words", 'asianwordcount').'
'.@number_format($bjl_author_posts_publish_word_count[$key] / $bjl_author_posts_publish[$key]).' '.__("Word Avg.", 'asianwordcount').'
'.number_format($bjl_author_pages_publish_word_count[$key]).' '.__("Words", 'asianwordcount').'
'.@number_format($bjl_author_pages_publish_word_count[$key] / $bjl_author_pages_publish[$key]).' '.__("Word Avg.", 'asianwordcount').'
'.number_format($bjl_author_posts_publish_word_count[$key] + $bjl_author_pages_publish_word_count[$key]).' '.__("Words", 'asianwordcount').'
'.@number_format(($bjl_author_posts_publish_word_count[$key] + $bjl_author_pages_publish_word_count[$key]) / ($bjl_author_posts_publish[$key] + $bjl_author_pages_publish[$key])).' '.__("Word Avg.", 'asianwordcount').'
'.number_format($bjl_author_posts_draft_word_count[$key]).' '.__("Words", 'asianwordcount').'
'.@number_format($bjl_author_posts_draft_word_count[$key] / $bjl_author_posts_draft[$key]).' '.__("Word Avg.", 'asianwordcount').'
'.number_format($bjl_author_pages_draft_word_count[$key]).' '.__("Words", 'asianwordcount').'
'.@number_format($bjl_author_pages_draft_word_count[$key] / $bjl_author_pages_draft[$key]).' '.__("Word Avg.", 'asianwordcount').'
'.number_format($bjl_author_posts_draft_word_count[$key] + $bjl_author_pages_draft_word_count[$key]).' '.__("Words", 'asianwordcount').'
'.@number_format(($bjl_author_posts_draft_word_count[$key] + $bjl_author_pages_draft_word_count[$key]) / ($bjl_author_posts_draft[$key] + $bjl_author_pages_draft[$key])).' '.__("Word Avg.", 'asianwordcount').'
'; echo '

'.__("Monthly Statistics", 'asianwordcount').'

'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $bjl_month_counter = 0; foreach($bjl_month_word_count as $key => $value) { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $bjl_month_counter++; } echo ''; echo '
'.__("Month", 'asianwordcount').''.__("Words", 'asianwordcount').''.__("Published Posts", 'asianwordcount').''.__("Published Pages", 'asianwordcount').''.__("Published Total", 'asianwordcount').''.__("Draft Posts", 'asianwordcount').''.__("Draft Pages", 'asianwordcount').''.__("Draft Total", 'asianwordcount').'
'.$key.''.number_format($value).''.number_format($bjl_month_posts_publish_word_count[$key]).' '.__("Words", 'asianwordcount').'
'.@number_format($bjl_month_posts_publish_word_count[$key] / $bjl_month_posts_publish[$key]).' '.__("Word Avg.", 'asianwordcount').'
'.number_format($bjl_month_pages_publish_word_count[$key]).' '.__("Words", 'asianwordcount').'
'.@number_format($bjl_month_pages_publish_word_count[$key] / $bjl_month_pages_publish[$key]).' '.__("Word Avg.", 'asianwordcount').'
'.number_format($bjl_month_posts_publish_word_count[$key] + $bjl_month_pages_publish_word_count[$key]).' '.__("Words", 'asianwordcount').'
'.@number_format(($bjl_month_posts_publish_word_count[$key] + $bjl_month_pages_publish_word_count[$key]) / ($bjl_month_posts_publish[$key] + $bjl_month_pages_publish[$key])).' '.__("Word Avg.", 'asianwordcount').'
'.number_format($bjl_month_posts_draft_word_count[$key]).' '.__("Words", 'asianwordcount').'
'.@number_format($bjl_month_posts_draft_word_count[$key] / $bjl_month_posts_draft[$key]).' '.__("Word Avg.", 'asianwordcount').'
'.number_format($bjl_month_pages_draft_word_count[$key]).' '.__("Words", 'asianwordcount').'
'.@number_format($bjl_month_pages_draft_word_count[$key] / $bjl_month_pages_draft[$key]).' '.__("Word Avg.", 'asianwordcount').'
'.number_format($bjl_month_posts_draft_word_count[$key] + $bjl_month_pages_draft_word_count[$key]).' '.__("Words", 'asianwordcount').'
'.@number_format(($bjl_month_posts_draft_word_count[$key] + $bjl_month_pages_draft_word_count[$key]) / ($bjl_month_posts_draft[$key] + $bjl_month_pages_draft[$key])).' '.__("Word Avg.", 'asianwordcount').'
'; echo '

'.__("Configuration", 'asianwordcount').'

'; echo '
'.__("*If you find any error on this page, please click \"recount\" on top of this page.", 'asianwordcount').'
'; ?>
Interface Language
/>

'; // END DIV.WRAP } /* // WIDGET class wpwordcount extends WP_Widget { function wpwordcount() { $widget_ops = array('classname' => 'wpwordcount', 'description' => 'Word Count Statistics for your Posts and Pages ( Support Asian characters: Chinese, Japanese, Korean ).'); $control_ops = array('id_base' => 'wpwordcount'); $this->WP_Widget('wpwordcount', 'WP Word Count', $widget_ops, $control_ops); } function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title']); $show_total = isset( $instance['show_total'] ) ? $instance['show_total'] : false; $show_posts = isset( $instance['show_posts'] ) ? $instance['show_posts'] : false; $show_pages = isset( $instance['show_pages'] ) ? $instance['show_pages'] : false; $show_link = isset( $instance['show_link'] ) ? $instance['show_link'] : false; // LOAD MAIN STATS $arr_bjl_word_count_main = get_option('bjl_word_count_main'); @extract($arr_bjl_word_count_main); echo $before_widget; echo $before_title.$title.$after_title; if ($show_total || $show_posts || $show_pages) echo '

'; if ($show_total) echo ''.__("Total").': '.number_format($words_posts_publish + $words_pages_publish).' '.__("Words").'
'; if ($show_posts) echo ''.__("Posts").': '.number_format($words_posts_publish).' '.__("Words").' ('.@number_format($words_posts_publish / $count_posts_publish).' '.__("Avg.").')
'; if ($show_pages) echo ''.__("Pages").': '.number_format($words_pages_publish).' '.__("Words").' ('.@number_format($words_pages_publish / $count_pages_publish).' '.__("Avg.").')
'; if ($show_total || $show_posts || $show_pages) echo '

'; if ($show_link) echo '

Powered by WP Word Count

'; echo $after_widget; } function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['show_total'] = $new_instance['show_total']; $instance['show_posts'] = $new_instance['show_posts']; $instance['show_pages'] = $new_instance['show_pages']; $instance['show_link'] = $new_instance['show_link']; return $instance; } function form($instance) { $defaults = array('title' => 'Word Count Statistics', 'show_total' => true, 'show_posts' => true, 'show_pages' => true, 'show_link' => true); $instance = wp_parse_args((array) $instance, $defaults); ?>

id="get_field_id('show_total'); ?>" name="get_field_name('show_total'); ?>" />
id="get_field_id('show_posts'); ?>" name="get_field_name('show_posts'); ?>" />
id="get_field_id('show_pages'); ?>" name="get_field_name('show_pages'); ?>" />
id="get_field_id('show_link'); ?>" name="get_field_name('show_link'); ?>" />

\n"; } ?>