| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: WP-Stats |
| 4 |
Plugin URI: http://lesterchan.net/portfolio/programming/php/ |
| 5 |
Description: Display your WordPress blog statistics. Ranging from general total statistics, some of my plugins statistics and top 10 statistics. |
| 6 |
Version: 2.30 |
| 7 |
Author: Lester 'GaMerZ' Chan |
| 8 |
Author URI: http://lesterchan.net |
| 9 |
*/ |
| 10 |
|
| 11 |
|
| 12 |
/* |
| 13 |
Copyright 2008 Lester Chan (email : lesterchan@gmail.com) |
| 14 |
|
| 15 |
This program is free software; you can redistribute it and/or modify |
| 16 |
it under the terms of the GNU General Public License as published by |
| 17 |
the Free Software Foundation; either version 2 of the License, or |
| 18 |
(at your option) any later version. |
| 19 |
|
| 20 |
This program is distributed in the hope that it will be useful, |
| 21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
GNU General Public License for more details. |
| 24 |
|
| 25 |
You should have received a copy of the GNU General Public License |
| 26 |
along with this program; if not, write to the Free Software |
| 27 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 28 |
*/ |
| 29 |
|
| 30 |
|
| 31 |
### Create Text Domain For Translations |
| 32 |
add_action('init', 'stats_textdomain'); |
| 33 |
function stats_textdomain() { |
| 34 |
load_plugin_textdomain('wp-stats', 'wp-content/plugins/wp-stats'); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
### Function: WP-Stats Menu |
| 39 |
add_action('admin_menu', 'stats_menu'); |
| 40 |
function stats_menu() { |
| 41 |
if (function_exists('add_submenu_page')) { |
| 42 |
add_submenu_page('index.php', __('WP-Stats', 'wp-stats'), __('WP-Stats', 'wp-stats'), 1, 'wp-stats/wp-stats.php', 'display_stats'); |
| 43 |
} |
| 44 |
if (function_exists('add_options_page')) { |
| 45 |
add_options_page(__('Stats', 'wp-stats'), __('Stats', 'wp-stats'), 'manage_options', 'wp-stats/stats-options.php'); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
### Display WP-Stats Admin Page |
| 51 |
function display_stats() { |
| 52 |
$stats_page = stats_page(); |
| 53 |
echo "<div class=\"wrap\">\n$stats_page</div>\n"; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
### Function: Get Total Authors |
| 58 |
function get_totalauthors($display = true) { |
| 59 |
global $wpdb; |
| 60 |
$totalauthors = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users LEFT JOIN $wpdb->usermeta ON $wpdb->usermeta.user_id = $wpdb->users.ID WHERE $wpdb->users.user_activation_key = '' AND $wpdb->usermeta.meta_key = 'wp_user_level' AND (meta_value+0.00) > 1"); |
| 61 |
if($display) { |
| 62 |
echo number_format($totalauthors); |
| 63 |
} else { |
| 64 |
return number_format($totalauthors); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
### Function: Get Total Posts |
| 70 |
function get_totalposts($display = true) { |
| 71 |
global $wpdb; |
| 72 |
$totalposts = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'"); |
| 73 |
if($display) { |
| 74 |
echo number_format($totalposts); |
| 75 |
} else { |
| 76 |
return number_format($totalposts); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
### Function: Get Total Pages |
| 82 |
function get_totalpages($display = true) { |
| 83 |
global $wpdb; |
| 84 |
$totalpages = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish'"); |
| 85 |
if($display) { |
| 86 |
echo number_format($totalpages); |
| 87 |
} else { |
| 88 |
return number_format($totalpages); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
### Function: Get Total Comments |
| 94 |
function get_totalcomments($display = true) { |
| 95 |
global $wpdb; |
| 96 |
$totalcomments = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = '1'"); |
| 97 |
if($display) { |
| 98 |
echo number_format($totalcomments); |
| 99 |
} else { |
| 100 |
return number_format($totalcomments); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
### Function: Get Total Comments Poster |
| 106 |
function get_totalcommentposters($display = true) { |
| 107 |
global $wpdb; |
| 108 |
$totalcommentposters = $wpdb->get_var("SELECT COUNT(DISTINCT comment_author) FROM $wpdb->comments WHERE comment_approved = '1' AND comment_type = ''"); |
| 109 |
if($display) { |
| 110 |
echo number_format($totalcommentposters); |
| 111 |
} else { |
| 112 |
return number_format($totalcommentposters); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
### Function: Get Total Links |
| 118 |
function get_totallinks($display = true) { |
| 119 |
global $wpdb; |
| 120 |
$totallinks = $wpdb->get_var("SELECT COUNT(link_id) FROM $wpdb->links"); |
| 121 |
if($display) { |
| 122 |
echo number_format($totallinks); |
| 123 |
} else { |
| 124 |
return number_format($totallinks); |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
### Function: Get Recent Posts |
| 130 |
function get_recentposts($mode = '', $limit = 10, $display = true) { |
| 131 |
global $wpdb, $post; |
| 132 |
$where = ''; |
| 133 |
$temp = ''; |
| 134 |
if(!empty($mode) && $mode != 'both') { |
| 135 |
$where = "post_type = '$mode'"; |
| 136 |
} else { |
| 137 |
$where = '1=1'; |
| 138 |
} |
| 139 |
$recentposts = $wpdb->get_results("SELECT $wpdb->posts.*, $wpdb->users.* FROM $wpdb->posts LEFT JOIN $wpdb->users ON $wpdb->users.ID = $wpdb->posts.post_author WHERE user_activation_key = '' AND post_date < '".current_time('mysql')."' AND $where AND post_status = 'publish' AND post_password = '' ORDER BY post_date DESC LIMIT $limit"); |
| 140 |
if($recentposts) { |
| 141 |
foreach ($recentposts as $post) { |
| 142 |
$post_title = get_the_title(); |
| 143 |
$post_date = get_the_time(get_option('date_format').' @ '.get_option('time_format')); |
| 144 |
$display_name = stripslashes($post->display_name); |
| 145 |
$temp .= "<li>$post_date - <a href=\"".get_permalink()."\" title=\"".sprintf(__('View post %s', 'wp-stats'), $post_title)."\">$post_title</a> ($display_name)</li>\n"; |
| 146 |
} |
| 147 |
} else { |
| 148 |
$temp = '<li>'.__('N/A', 'wp-stats').'</li>'; |
| 149 |
} |
| 150 |
if($display) { |
| 151 |
echo $temp; |
| 152 |
} else { |
| 153 |
return $temp; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
### Function: Get Recent Comments |
| 159 |
function get_recentcomments($mode = '', $limit = 10, $display = true) { |
| 160 |
global $wpdb, $post; |
| 161 |
$where = ''; |
| 162 |
$temp = ''; |
| 163 |
if(!empty($mode) && $mode != 'both') { |
| 164 |
$where = "post_type = '$mode'"; |
| 165 |
} else { |
| 166 |
$where = '1=1'; |
| 167 |
} |
| 168 |
$recentcomments = $wpdb->get_results("SELECT * FROM $wpdb->posts INNER JOIN $wpdb->comments ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID WHERE comment_approved = '1' AND comment_type = '' AND post_date < '".current_time('mysql')."' AND $where AND post_status = 'publish' AND post_password = '' ORDER BY comment_date DESC LIMIT $limit"); |
| 169 |
if($recentcomments) { |
| 170 |
foreach ($recentcomments as $post) { |
| 171 |
$post_title = get_the_title(); |
| 172 |
$comment_author = htmlspecialchars(stripslashes($post->comment_author)); |
| 173 |
$comment_date = mysql2date(get_option('date_format').' @ '.get_option('time_format'), $post->comment_date); |
| 174 |
$temp .= "<li>$comment_date - $comment_author (<a href=\"".get_permalink()."#comment-".$post->comment_ID."\" title=\"".sprintf(__('View comments in post %s', 'wp-stats'), $post_title)."\">$post_title</a>)</li>\n"; |
| 175 |
} |
| 176 |
} else { |
| 177 |
$temp = '<li>'.__('N/A', 'wp-stats').'</li>'; |
| 178 |
} |
| 179 |
if($display) { |
| 180 |
echo $temp; |
| 181 |
} else { |
| 182 |
return $temp; |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
### Function: Get Top Commented Posts |
| 188 |
function get_mostcommented($mode = '', $limit = 10, $chars = 0, $display = true) { |
| 189 |
global $wpdb, $post; |
| 190 |
$where = ''; |
| 191 |
$temp = ''; |
| 192 |
if(!empty($mode) && $mode != 'both') { |
| 193 |
$where = "post_type = '$mode'"; |
| 194 |
} else { |
| 195 |
$where = '1=1'; |
| 196 |
} |
| 197 |
$mostcommenteds = $wpdb->get_results("SELECT $wpdb->posts.*, COUNT($wpdb->comments.comment_post_ID) AS 'comment_total' FROM $wpdb->posts LEFT JOIN $wpdb->comments ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID WHERE comment_approved = '1' AND post_date < '".current_time('mysql')."' AND $where AND post_status = 'publish' AND post_password = '' GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_total DESC LIMIT $limit"); |
| 198 |
if($mostcommenteds) { |
| 199 |
if($chars > 0) { |
| 200 |
foreach ($mostcommenteds as $post) { |
| 201 |
$post_title = get_the_title(); |
| 202 |
$comment_total = intval($post->comment_total); |
| 203 |
$temp .= "<li><a href=\"".get_permalink()."\" title=\"".sprintf(__('View comments in post %s', 'wp-stats'), $post_title)."\">".snippet_text($post_title, $chars)."</a> - $comment_total ".__('comments', 'wp-stats')."</li>"; |
| 204 |
} |
| 205 |
} else { |
| 206 |
foreach ($mostcommenteds as $post) { |
| 207 |
$post_title = get_the_title(); |
| 208 |
$comment_total = intval($post->comment_total); |
| 209 |
$temp .= "<li><a href=\"".get_permalink()."\" title=\"".sprintf(__('View comments in post %s', 'wp-stats'), $post_title)."\">$post_title</a> - $comment_total ".__('comments', 'wp-stats')."</li>"; |
| 210 |
} |
| 211 |
} |
| 212 |
} else { |
| 213 |
$temp = '<li>'.__('N/A', 'wp-stats').'</li>'; |
| 214 |
} |
| 215 |
if($display) { |
| 216 |
echo $temp; |
| 217 |
} else { |
| 218 |
return $temp; |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
### Function: Get Author Stats |
| 224 |
function get_authorsstats($mode = '', $display = true) { |
| 225 |
global $wpdb, $wp_rewrite; |
| 226 |
$where = ''; |
| 227 |
$temp = ''; |
| 228 |
if(!empty($mode) && $mode != 'both') { |
| 229 |
$where = "post_type = '$mode'"; |
| 230 |
} else { |
| 231 |
$where = '1=1'; |
| 232 |
} |
| 233 |
$posts = $wpdb->get_results("SELECT COUNT($wpdb->posts.ID) AS 'posts_total', $wpdb->users.display_name, $wpdb->users.user_nicename FROM $wpdb->posts LEFT JOIN $wpdb->users ON $wpdb->users.ID = $wpdb->posts.post_author WHERE user_activation_key = '' AND $where AND post_status = 'publish' GROUP BY $wpdb->posts.post_author"); |
| 234 |
if($posts) { |
| 235 |
$using_permalink = get_option('permalink_structure'); |
| 236 |
$permalink = $wp_rewrite->get_author_permastruct(); |
| 237 |
foreach ($posts as $post) { |
| 238 |
$post_author = strip_tags(stripslashes($post->user_nicename)); |
| 239 |
$author_link = str_replace('%author%', $post_author, $permalink); |
| 240 |
$display_name = strip_tags(stripslashes($post->display_name)); |
| 241 |
$posts_total = intval($post->posts_total); |
| 242 |
if($using_permalink) { |
| 243 |
$temp .= "<li><a href=\"".get_option('home').$author_link."\" title=\"".sprintf(__('View posts posted by %s', 'wp-stats'), $display_name)."\">$display_name</a> ($posts_total)</li>\n"; |
| 244 |
} else { |
| 245 |
$temp .= "<li><a href=\"".get_option('siteurl')."/?author_name=$post_author\" title=\"".sprintf(__('View posts posted by %s', 'wp-stats'), $display_name)."\">$display_name</a> ($posts_total)</li>\n"; |
| 246 |
} |
| 247 |
} |
| 248 |
} else { |
| 249 |
$temp = '<li>'.__('N/A', 'wp-stats').'</li>'; |
| 250 |
} |
| 251 |
if($display) { |
| 252 |
echo $temp; |
| 253 |
} else { |
| 254 |
return $temp; |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
### Function: Get Comments' Members Stats |
| 260 |
// Treshhold = Number Of Posts User Must Have Before It Will Display His Name Out |
| 261 |
// 5 = Default Treshhold; -1 = Disable Treshhold |
| 262 |
function get_commentmembersstats($threshhold = -1, $limit = 0, $display = true) { |
| 263 |
global $wpdb; |
| 264 |
$temp = ''; |
| 265 |
$limit_sql = ''; |
| 266 |
if($limit > 0) { |
| 267 |
$limit_sql = "LIMIT $limit"; |
| 268 |
} |
| 269 |
$comments = $wpdb->get_results("SELECT comment_author, COUNT(comment_ID) AS 'comment_total' FROM $wpdb->comments INNER JOIN $wpdb->posts ON $wpdb->comments.comment_post_ID = $wpdb->posts.ID WHERE comment_approved = '1' AND comment_type = '' AND post_date < '".current_time('mysql')."' AND post_status = 'publish' AND post_password = '' GROUP BY comment_author ORDER BY comment_total DESC $limit_sql"); |
| 270 |
if($comments) { |
| 271 |
foreach ($comments as $comment) { |
| 272 |
$comment_author = strip_tags(stripslashes($comment->comment_author)); |
| 273 |
$comment_author_link = urlencode($comment_author); |
| 274 |
$comment_total = intval($comment->comment_total); |
| 275 |
$temp .= "<li><a href=\"".stats_page_link($comment_author_link)."\" title=\"".sprintf(__('View all comments posted by %s', 'wp-stats'), $comment_author)."\">$comment_author</a> ($comment_total)</li>\n"; |
| 276 |
// If Total Comments Is Below Threshold |
| 277 |
if($comment_total <= $threshhold && $threshhold != -1) { |
| 278 |
return; |
| 279 |
} |
| 280 |
} |
| 281 |
} else { |
| 282 |
$temp = '<li>'.__('N/A', 'wp-stats').'</li>'; |
| 283 |
} |
| 284 |
if($display) { |
| 285 |
echo $temp; |
| 286 |
} else { |
| 287 |
return $temp; |
| 288 |
} |
| 289 |
} |
| 290 |
|
| 291 |
|
| 292 |
### Function: Get Post Categories Stats |
| 293 |
function get_postcats($display = true) { |
| 294 |
global $wpdb; |
| 295 |
$temp = ''; |
| 296 |
$defaults = array('type' => 'post', 'style' => 'list', 'show_count' => 1); |
| 297 |
$categories = get_categories($defaults); |
| 298 |
if (empty($categories)){ |
| 299 |
$temp .= '<li>'.__('No categories', 'wp-stats').'</li>'; |
| 300 |
} else { |
| 301 |
$temp .= walk_category_tree($categories, 0, $defaults); |
| 302 |
} |
| 303 |
if($display) { |
| 304 |
echo $temp; |
| 305 |
} else { |
| 306 |
return $temp; |
| 307 |
} |
| 308 |
} |
| 309 |
|
| 310 |
|
| 311 |
### Function: Get Links Categories Stats |
| 312 |
function get_linkcats($display = true) { |
| 313 |
global $wpdb; |
| 314 |
$temp = ''; |
| 315 |
$cats = get_categories('type=link'); |
| 316 |
if ($cats) { |
| 317 |
foreach ($cats as $cat) { |
| 318 |
$temp .= '<li>'.$cat->cat_name.' ('.$cat->count.")</li>\n"; |
| 319 |
} |
| 320 |
} |
| 321 |
if($display) { |
| 322 |
echo $temp; |
| 323 |
} else { |
| 324 |
return $temp; |
| 325 |
} |
| 326 |
} |
| 327 |
|
| 328 |
|
| 329 |
### Function: Get Tags List |
| 330 |
function get_tags_list($display = true) { |
| 331 |
global $wpdb; |
| 332 |
$temp = ''; |
| 333 |
$tags = get_tags('orderby=count&order=DESC'); |
| 334 |
if ($tags) { |
| 335 |
foreach ($tags as $tag) { |
| 336 |
$temp .= '<li><a href="'.clean_url(get_tag_link($tag->term_id)).'" title="'.sprintf(__('%s topics', 'wp-stats'), $tag->count).'">'.$tag->name.'</a> ('.$tag->count.")</li>\n"; |
| 337 |
} |
| 338 |
} |
| 339 |
if($display) { |
| 340 |
echo $temp; |
| 341 |
} else { |
| 342 |
return $temp; |
| 343 |
} |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
### Function: Snippet Text |
| 348 |
if(!function_exists('snippet_text')) { |
| 349 |
function snippet_text($text, $length = 0) { |
| 350 |
$text = html_entity_decode($text, ENT_QUOTES, get_option('blog_charset')); |
| 351 |
if (strlen($text) > $length) { |
| 352 |
return htmlentities(substr($text,0,$length), ENT_COMPAT, get_option('blog_charset')).'...'; |
| 353 |
} else { |
| 354 |
return htmlentities($text, ENT_COMPAT, get_option('blog_charset')); |
| 355 |
} |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
|
| 360 |
### Function: Short Code For Inserting Stats Into Page |
| 361 |
add_shortcode('page_stats', 'stats_page_shortcode'); |
| 362 |
function stats_page_shortcode($atts) { |
| 363 |
return stats_page(); |
| 364 |
} |
| 365 |
|
| 366 |
|
| 367 |
### Function: Stats Page |
| 368 |
function stats_page_link($author, $page = 0) { |
| 369 |
$stats_url = get_option('stats_url'); |
| 370 |
if($page > 1) { |
| 371 |
$page = "&stats_page=$page"; |
| 372 |
} else { |
| 373 |
$page = ''; |
| 374 |
} |
| 375 |
if(strpos($stats_url, '?') !== false) { |
| 376 |
$stats_url = "$stats_url&stats_author=$author$page"; |
| 377 |
} else { |
| 378 |
$stats_url = "$stats_url?stats_author=$author$page"; |
| 379 |
} |
| 380 |
return $stats_url; |
| 381 |
} |
| 382 |
|
| 383 |
|
| 384 |
### Function: Statistics Page |
| 385 |
function stats_page() { |
| 386 |
global $wpdb, $post; |
| 387 |
// Variables Variables Variables |
| 388 |
$comment_author = urldecode(strip_tags(stripslashes(trim($_GET['stats_author'])))); |
| 389 |
$page = intval($_GET['stats_page']); |
| 390 |
$temp_stats = ''; |
| 391 |
$temp_post = $post; |
| 392 |
$stats_mostlimit = intval(get_option('stats_mostlimit')); |
| 393 |
$stats_display = get_option('stats_display'); |
| 394 |
|
| 395 |
// Default wp-stats.php Page |
| 396 |
if(empty($comment_author)) { |
| 397 |
// General Stats |
| 398 |
if($stats_display['total_stats'] == 1) { |
| 399 |
$temp_stats .= '<h2 id="GeneralStats">'.__('General Stats', 'wp-stats').'</h2>'."\n"; |
| 400 |
$temp_stats .= '<p><strong>'.__('Total Stats', 'wp-stats').'</strong></p>'."\n"; |
| 401 |
$temp_stats .= '<ul>'."\n"; |
| 402 |
$temp_stats .= '<li><strong>'.get_totalauthors(false).'</strong> '.__('authors to this blog.', 'wp-stats').'</li>'."\n"; |
| 403 |
$temp_stats .= '<li><strong>'.get_totalposts(false).'</strong> '.__('posts were posted.', 'wp-stats').'</li>'."\n"; |
| 404 |
$temp_stats .= '<li><strong>'.get_totalpages(false).'</strong> '.__('pages were created.', 'wp-stats').'</li>'."\n"; |
| 405 |
$temp_stats .= '<li><strong>'.wp_count_terms('post_tag').'</strong> '.__('tags were created.', 'wp-stats').'</li>'."\n"; |
| 406 |
$temp_stats .= '<li><strong>'.get_totalcomments(false).'</strong> '.__('comments were posted.', 'wp-stats').'</li>'."\n"; |
| 407 |
$temp_stats .= '<li><strong>'.get_totalcommentposters(false).'</strong> '.__('different nicknames were represented in the comments.', 'wp-stats').'</li>'."\n"; |
| 408 |
$temp_stats .= '<li><strong>'.get_totallinks(false).'</strong> '.__('links were added.', 'wp-stats').'</li>'."\n"; |
| 409 |
$temp_stats .= '<li><strong>'.wp_count_terms('category').'</strong> '.__('post categories were needed.', 'wp-stats').'</li>'."\n"; |
| 410 |
$temp_stats .= '<li><strong>'.wp_count_terms('link_category').'</strong> '.__('link categories were needed.', 'wp-stats').'</li>'."\n"; |
| 411 |
if(function_exists('akismet_spam_count')) { |
| 412 |
$temp_stats .= '<li><strong>'.number_format(get_option('akismet_spam_count')).'</strong> '.__('spam blocked.', 'wp-stats').'</li>'."\n"; |
| 413 |
} |
| 414 |
// WP-Stats: General Stats Filter |
| 415 |
$temp_stats = apply_filters('wp_stats_page_general', $temp_stats); |
| 416 |
$temp_stats .= '</ul>'."\n"; |
| 417 |
} |
| 418 |
|
| 419 |
// Plugin Stats |
| 420 |
$temp_stats .= '<h2 id="PluginsStats">'.__('Plugins Stats', 'wp-stats').'</h2>'."\n"; |
| 421 |
|
| 422 |
// WP-Stats: Plugins Stats Filter |
| 423 |
$temp_stats = apply_filters('wp_stats_page_plugins', $temp_stats); |
| 424 |
|
| 425 |
// Top Recent Stats |
| 426 |
$temp_stats .= '<h2 id="TopRecentStats">'.sprintf(__('Top %s Recent Stats', 'wp-stats'), $stats_mostlimit).'</h2>'."\n"; |
| 427 |
|
| 428 |
// Recent Posts |
| 429 |
if($stats_display['recent_posts'] == 1) { |
| 430 |
$temp_stats .= '<p><strong>'.$stats_mostlimit.' '.__('Recent Posts', 'wp-stats').'</strong></p>'."\n"; |
| 431 |
$temp_stats .= '<ul>'."\n"; |
| 432 |
$temp_stats .= get_recentposts('post', $stats_mostlimit, false); |
| 433 |
$temp_stats .= '</ul>'."\n"; |
| 434 |
} |
| 435 |
|
| 436 |
// Recent Comments |
| 437 |
if($stats_display['recent_commtents'] == 1) { |
| 438 |
$temp_stats .= '<p><strong>'.$stats_mostlimit.' '.__('Recent Comments', 'wp-stats').'</strong></p>'."\n"; |
| 439 |
$temp_stats .= '<ul>'."\n"; |
| 440 |
$temp_stats .= get_recentcomments('post', $stats_mostlimit, false); |
| 441 |
$temp_stats .= '</ul>'."\n"; |
| 442 |
} |
| 443 |
|
| 444 |
// WP-Stats: Top Recent Stats Filter |
| 445 |
$temp_stats = apply_filters('wp_stats_page_recent', $temp_stats); |
| 446 |
|
| 447 |
// Top Most Stats |
| 448 |
$temp_stats .= '<h2 id="TopMostHighestStats">'.sprintf(__('Top %s Most/Highest Stats', 'wp-stats'), $stats_mostlimit).'</h2>'."\n"; |
| 449 |
|
| 450 |
// Most Commented Post |
| 451 |
if($stats_display['commented_post'] == 1) { |
| 452 |
$temp_stats .= '<p><strong>'.$stats_mostlimit.' '.__('Most Commented Post', 'wp-stats').'</strong></p>'."\n"; |
| 453 |
$temp_stats .= '<ul>'."\n"; |
| 454 |
$temp_stats .= get_mostcommented('post', $stats_mostlimit, 0, false); |
| 455 |
$temp_stats .= '</ul>'."\n"; |
| 456 |
} |
| 457 |
|
| 458 |
// WP-Stats: Top Most/Highest Stats Filter |
| 459 |
$temp_stats = apply_filters('wp_stats_page_most', $temp_stats); |
| 460 |
|
| 461 |
// Authors Stats |
| 462 |
$temp_stats .= '<h2 id="AuthorsStats">'.__('Authors Stats', 'wp-stats').'</h2>'."\n"; |
| 463 |
|
| 464 |
// Authors |
| 465 |
if($stats_display['authors'] == 1) { |
| 466 |
$temp_stats .= '<p><strong>'.__('Authors', 'wp-stats').'</strong></p>'."\n"; |
| 467 |
$temp_stats .= '<ol>'."\n"; |
| 468 |
$temp_stats .= get_authorsstats('post', false); |
| 469 |
$temp_stats .= '</ol>'."\n"; |
| 470 |
} |
| 471 |
|
| 472 |
// WP-Stats: Authors Stats Filter |
| 473 |
$temp_stats = apply_filters('wp_stats_page_authors', $temp_stats); |
| 474 |
|
| 475 |
// Comments' Members Stats |
| 476 |
$temp_stats .= '<h2 id="CommentsMembersStats">'.__('Comments\' Members Stats', 'wp-stats').'</h2>'."\n"; |
| 477 |
|
| 478 |
// Comments' Member |
| 479 |
if($stats_display['comment_members'] == 1) { |
| 480 |
$temp_stats .= '<p><strong>'.__('Comment Members', 'wp-stats').'</strong></p>'."\n"; |
| 481 |
$temp_stats .= '<ol>'."\n"; |
| 482 |
$temp_stats .= get_commentmembersstats(-1, 0, false); |
| 483 |
$temp_stats .= '</ol>'."\n"; |
| 484 |
} |
| 485 |
|
| 486 |
// WP-Stats: Comments' Members Stats Filter |
| 487 |
$temp_stats = apply_filters('wp_stats_page_comments_members', $temp_stats); |
| 488 |
|
| 489 |
// Misc Stats |
| 490 |
$temp_stats .= '<h2 id="MiscStats">'.__('Misc Stats', 'wp-stats').'</h2>'."\n"; |
| 491 |
|
| 492 |
// Post Categories |
| 493 |
if($stats_display['post_cats'] == 1) { |
| 494 |
$temp_stats .= '<p><strong>'.__('Post Categories', 'wp-stats').'</strong></p>'."\n"; |
| 495 |
$temp_stats .= '<ul>'."\n"; |
| 496 |
$temp_stats .= get_postcats(false); |
| 497 |
$temp_stats .= '</ul>'."\n"; |
| 498 |
} |
| 499 |
|
| 500 |
// Link Categories |
| 501 |
if($stats_display['link_cats'] == 1) { |
| 502 |
$temp_stats .= '<p><strong>'.__('Link Categories', 'wp-stats').'</strong></p>'."\n"; |
| 503 |
$temp_stats .= '<ul>'."\n"; |
| 504 |
$temp_stats .= get_linkcats(false); |
| 505 |
$temp_stats .= '</ul>'."\n"; |
| 506 |
} |
| 507 |
|
| 508 |
if($stats_display['tags_list'] == 1) { |
| 509 |
$temp_stats .= '<p><strong>'.__('Tags List', 'wp-stats').'</strong></p>'."\n"; |
| 510 |
$temp_stats .= '<ul>'."\n"; |
| 511 |
$temp_stats .= get_tags_list(false); |
| 512 |
$temp_stats .= '</ul>'."\n"; |
| 513 |
} |
| 514 |
|
| 515 |
// WP-Stats: Plugin Misc Filter |
| 516 |
$temp_stats = apply_filters('wp_stats_page_misc', $temp_stats); |
| 517 |
|
| 518 |
// Displaying Comments Posted By User |
| 519 |
} else { |
| 520 |
// Stats URL |
| 521 |
$stats_url = get_option('stats_url'); |
| 522 |
// Number Of Comments Per Page |
| 523 |
$perpage = 10; |
| 524 |
// Comment Author Link |
| 525 |
$comment_author_link = urlencode($comment_author); |
| 526 |
// Comment Author SQL |
| 527 |
$comment_author_sql = $wpdb->escape($comment_author); |
| 528 |
// Total Comments Posted By User |
| 529 |
$totalcomments = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments INNER JOIN $wpdb->posts ON $wpdb->comments.comment_post_ID = $wpdb->posts.ID WHERE comment_author = '$comment_author_sql' AND comment_approved = '1' AND comment_type = '' AND post_date < '".current_time('mysql')."' AND post_status = 'publish' AND post_password = ''"); |
| 530 |
// Checking $page and $offset |
| 531 |
if (empty($page) || $page == 0) { $page = 1; } |
| 532 |
if (empty($offset)) { $offset = 0; } |
| 533 |
// Determin $offset |
| 534 |
$offset = ($page-1) * $perpage; |
| 535 |
// Some Comments Stats |
| 536 |
if(($offset + $perpage) > $totalcomments) { $maxonpage = $totalcomments ; } else { $maxonpage = ($offset+$perpage); } |
| 537 |
if (($offset + 1) > ($totalcomments)) { $displayonpage = $totalcomments ; } else { $displayonpage = ($offset+1); } |
| 538 |
// Count Total Pages |
| 539 |
$totalpages = ceil($totalcomments/$perpage); |
| 540 |
// Getting The Comments |
| 541 |
$gmz_comments = $wpdb->get_results("SELECT $wpdb->posts.*, $wpdb->comments.* FROM $wpdb->comments INNER JOIN $wpdb->posts ON $wpdb->comments.comment_post_ID = $wpdb->posts.ID WHERE comment_author = '$comment_author_sql' AND comment_approved = '1' AND post_date < '".current_time('mysql')."' AND post_status = 'publish' AND post_password = '' ORDER BY comment_post_ID DESC, comment_date DESC LIMIT $offset, $perpage"); |
| 542 |
$temp_stats .= '<h2>'.__('Comments Posted By', 'wp-stats').' '.$comment_author.'</h2>'; |
| 543 |
$temp_stats .= '<p>'.sprintf(__('Displaying <strong>%s</strong> To <strong>%s</strong> Of <strong>%s</strong> Comments', 'wp-stats'), $displayonpage, $maxonpage, $totalcomments).'</p>'; |
| 544 |
|
| 545 |
|
| 546 |
// Get Comments |
| 547 |
if($gmz_comments) { |
| 548 |
foreach($gmz_comments as $post) { |
| 549 |
$comment_id = intval($post->comment_ID); |
| 550 |
$comment_author2 = htmlspecialchars(stripslashes($post->comment_author)); |
| 551 |
$comment_date = mysql2date(sprintf(__('%s @ %s', 'wp-stats'), get_option('date_format'), get_option('time_format')), $post->comment_date); |
| 552 |
$comment_content = wpautop(stripslashes($post->comment_content)); |
| 553 |
$post_date = get_the_time(sprintf(__('%s @ %s', 'wp-stats'), get_option('date_format'), get_option('time_format'))); |
| 554 |
$post_title = get_the_title(); |
| 555 |
|
| 556 |
// Check For Password Protected Post |
| 557 |
if(!empty($post->post_password) && stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password) { |
| 558 |
// If New Title, Print It Out |
| 559 |
if($post_title != $cache_post_title) { |
| 560 |
$temp_stats .= "<p><strong><a href=\"".get_permalink()."\" title=\"".__('Posted On', 'wp-stats')." $post_date\">".__('Protected', 'wp-stats').": $post_title</a></strong></p>"; |
| 561 |
$temp_stats .= '<blockquote>'.__('Comments Protected', 'wp-stats').'</blockquote>'; |
| 562 |
} |
| 563 |
} else { |
| 564 |
// If New Title, Print It Out |
| 565 |
if($post_title != $cache_post_title) { |
| 566 |
$temp_stats .= "<p><strong><a href=\"".get_permalink()."\" title=\"".__('Posted On', 'wp-stats')." $post_date\">$post_title</a></strong></p>"; |
| 567 |
} |
| 568 |
$temp_stats .= "<blockquote>$comment_content <a href=\"".get_permalink()."#comment-$comment_id\" title=\"".sprintf(__('View the comment posted by %s', 'wp-stats'), $comment_author2)."\">Comment</a> ".__('Posted By', 'wp-stats')." <strong>$comment_author2</strong> ".__('On', 'wp-stats')." $comment_date</blockquote>"; |
| 569 |
} |
| 570 |
$cache_post_title = $post_title; |
| 571 |
} |
| 572 |
} else { |
| 573 |
$temp_stats .= "<p>$comment_author ".__('has not made any comments yet.', 'wp-stats')."</p>"; |
| 574 |
} |
| 575 |
|
| 576 |
// If Total Pages Is More Than 1, Display Page Navigation |
| 577 |
if($totalpages > 1) { |
| 578 |
// Previous Page |
| 579 |
$temp_stats .= '<p>'; |
| 580 |
$temp_stats .= '<span style="float: left">'; |
| 581 |
if($page > 1 && ((($page*$perpage)-($perpage-1)) < $totalcomments)) { |
| 582 |
$temp_stats .= '<strong>«</strong> <a href="'.stats_page_link($comment_author_link, $page-1).'" title="« '.__('Previous Page', 'wp-stats').'">'.__('Previous Page', 'wp-stats').'</a>'; |
| 583 |
} else { |
| 584 |
$temp_stats .= ' '; |
| 585 |
} |
| 586 |
$temp_stats .= '</span>'; |
| 587 |
// Next Page |
| 588 |
$temp_stats .= '<span style="float: right">'; |
| 589 |
if($page >= 1 && ((($page*$perpage)+1) < $totalcomments)) { |
| 590 |
$temp_stats .= '<a href="'.stats_page_link($comment_author_link, $page+1).'" title="'.__('Next Page', 'wp-stats').' »">'.__('Next Page', 'wp-stats').'</a> <strong>»</strong>'; |
| 591 |
} else { |
| 592 |
$temp_stats .= ' '; |
| 593 |
} |
| 594 |
$temp_stats .= '</span>'; |
| 595 |
$temp_stats .= '</p>'; |
| 596 |
// Pages |
| 597 |
$temp_stats .= '<br style="clear: both" />'; |
| 598 |
$temp_stats .= '<p align="center">'; |
| 599 |
$temp_stats .= sprintf(__('Pages (%s)', 'wp-stats'), $totalpages).': '; |
| 600 |
if ($page >= 4) { |
| 601 |
$temp_stats .= '<strong><a href="'.stats_page_link($comment_author_link).'" title="'.__('Go to First Page', 'wp-stats').'">« '.__('First', 'wp-stats').'</a></strong> ... '; |
| 602 |
} |
| 603 |
if($page > 1) { |
| 604 |
$temp_stats .= ' <strong><a href="'.stats_page_link($comment_author_link, $page-1).'" title="« '.__('Go to Page', 'wp-stats').' '.($page-1).'">«</a></strong> '; |
| 605 |
} |
| 606 |
for($i = $page - 2 ; $i <= $page +2; $i++) { |
| 607 |
if ($i >= 1 && $i <= $totalpages) { |
| 608 |
if($i == $page) { |
| 609 |
$temp_stats .= "<strong>[$i]</strong> "; |
| 610 |
} else { |
| 611 |
$temp_stats .= '<a href="'.stats_page_link($comment_author_link, $i).'" title="'.__('Page', 'wp-stats').' '.$i.'">'.$i.'</a> '; |
| 612 |
} |
| 613 |
} |
| 614 |
} |
| 615 |
if($page < $totalpages) { |
| 616 |
$temp_stats .= ' <strong><a href="'.stats_page_link($comment_author_link, $page+1).'" title="'.__('Go to Page', 'wp-stats').' '.($page+1).' »">»</a></strong> '; |
| 617 |
} |
| 618 |
if (($page+2) < $totalpages) { |
| 619 |
$temp_stats .= ' ... <strong><a href="'.stats_page_link($comment_author_link, $totalpages).'" title="'.__('Go to Last Page', 'wp-stats').'">'.__('Last', 'wp-stats').' »</a></strong>'; |
| 620 |
} |
| 621 |
$temp_stats .= '</p>'; |
| 622 |
} |
| 623 |
$temp_stats .= '<p><strong>««</strong> <a href="'.$stats_url.'">'.__('Back To Stats Page', 'wp-stats').' </a></p>'; |
| 624 |
} // End If |
| 625 |
|
| 626 |
// Assign Back $post |
| 627 |
$post = $temp_post; |
| 628 |
|
| 629 |
// Output Stats Page |
| 630 |
return $temp_stats; |
| 631 |
} |
| 632 |
|
| 633 |
|
| 634 |
### Function: Stats Option |
| 635 |
add_action('activate_wp-stats/wp-stats.php', 'stats_init'); |
| 636 |
function stats_init() { |
| 637 |
global $wpdb; |
| 638 |
$stats_display = array('total_stats' => 1, 'email' => 1, 'polls' => 1, 'ratings' => 1, 'views' => 1, 'useronline' => 1, 'recent_posts' => 1, 'recent_commtents' => 1, 'commented_post' => 1, 'emailed_most' => 1, 'rated_highest' => 1, 'rated_most' => 1, 'viewed_most' => 1, 'authors' => 1, 'comment_members' => 1, 'post_cats' => 1, 'link_cats' => 1); |
| 639 |
add_option('stats_mostlimit', '10', 'Stats Most Limit'); |
| 640 |
add_option('stats_display', $stats_display, 'Stats To Display'); |
| 641 |
add_option('stats_url', get_option('siteurl').'/stats/', 'Stats URL'); |
| 642 |
} |
| 643 |
?> |