PluginProbe
WP-Stats / 2.31
WP-Stats v2.31
3.0.1 3.0.0 trunk 1.00 2.00 2.01 2.02 2.03 2.04 2.05 2.06 2.10 2.11 2.20 2.30 2.31 2.40 2.50 2.55 2.56 2.56.1
wp-stats / wp-stats.php

wp-stats.php in WP-Stats 2.31, at wp-stats.php

686 lines 28.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.31
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 ### Use WordPress 2.6 Constants
32 if (!defined('WP_CONTENT_DIR')) {
33 define( 'WP_CONTENT_DIR', ABSPATH.'wp-content');
34 }
35 if (!defined('WP_CONTENT_URL')) {
36 define('WP_CONTENT_URL', get_option('siteurl').'/wp-content');
37 }
38 if (!defined('WP_PLUGIN_DIR')) {
39 define('WP_PLUGIN_DIR', WP_CONTENT_DIR.'/plugins');
40 }
41 if (!defined('WP_PLUGIN_URL')) {
42 define('WP_PLUGIN_URL', WP_CONTENT_URL.'/plugins');
43 }
44
45
46 ### Create Text Domain For Translations
47 add_action('init', 'stats_textdomain');
48 function stats_textdomain() {
49 if (!function_exists('wp_print_styles')) {
50 load_plugin_textdomain('wp-stats', 'wp-content/plugins/wp-stats');
51 } else {
52 load_plugin_textdomain('wp-stats', false, 'wp-stats');
53 }
54 }
55
56
57 ### Function: WP-Stats Menu
58 add_action('admin_menu', 'stats_menu');
59 function stats_menu() {
60 if (function_exists('add_submenu_page')) {
61 add_submenu_page('index.php', __('WP-Stats', 'wp-stats'), __('WP-Stats', 'wp-stats'), 1, 'wp-stats/wp-stats.php', 'display_stats');
62 }
63 if (function_exists('add_options_page')) {
64 add_options_page(__('Stats', 'wp-stats'), __('Stats', 'wp-stats'), 'manage_options', 'wp-stats/stats-options.php');
65 }
66 }
67
68
69 ### Function: WP-Stats Manager CSS
70 add_action('wp_head', 'stats_css');
71 function stats_css() {
72 if(!function_exists('pagenavi_css')) {
73 echo "\n".'<!-- Start Of Script Generated By WP-Stats 2.31 -->'."\n";
74 if(@file_exists(TEMPLATEPATH.'/stats-css.css')) {
75 echo '<link rel="stylesheet" href="'.get_stylesheet_directory_uri().'/stats-css.css" type="text/css" media="screen" />'."\n";
76 } else {
77 echo '<link rel="stylesheet" href="'.WP_PLUGIN_URL.'/wp-stats/stats-css.css" type="text/css" media="screen" />'."\n";
78 }
79 echo '<!-- End Of Script Generated By WP-Stats 2.31 -->'."\n";
80 }
81 }
82
83
84 ### Display WP-Stats Admin Page
85 function display_stats() {
86 $stats_page = stats_page();
87 echo "<div class=\"wrap\">\n$stats_page</div>\n";
88 }
89
90
91 ### Function: Get Total Authors
92 function get_totalauthors($display = true) {
93 global $wpdb;
94 $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 = '".$wpdb->prefix."user_level' AND (meta_value+0.00) > 1");
95 if($display) {
96 echo number_format($totalauthors);
97 } else {
98 return number_format($totalauthors);
99 }
100 }
101
102
103 ### Function: Get Total Posts
104 function get_totalposts($display = true) {
105 global $wpdb;
106 $totalposts = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'");
107 if($display) {
108 echo number_format($totalposts);
109 } else {
110 return number_format($totalposts);
111 }
112 }
113
114
115 ### Function: Get Total Pages
116 function get_totalpages($display = true) {
117 global $wpdb;
118 $totalpages = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish'");
119 if($display) {
120 echo number_format($totalpages);
121 } else {
122 return number_format($totalpages);
123 }
124 }
125
126
127 ### Function: Get Total Comments
128 function get_totalcomments($display = true) {
129 global $wpdb;
130 $totalcomments = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = '1'");
131 if($display) {
132 echo number_format($totalcomments);
133 } else {
134 return number_format($totalcomments);
135 }
136 }
137
138
139 ### Function: Get Total Comments Poster
140 function get_totalcommentposters($display = true) {
141 global $wpdb;
142 $totalcommentposters = $wpdb->get_var("SELECT COUNT(DISTINCT comment_author) FROM $wpdb->comments WHERE comment_approved = '1' AND comment_type = ''");
143 if($display) {
144 echo number_format($totalcommentposters);
145 } else {
146 return number_format($totalcommentposters);
147 }
148 }
149
150
151 ### Function: Get Total Links
152 function get_totallinks($display = true) {
153 global $wpdb;
154 $totallinks = $wpdb->get_var("SELECT COUNT(link_id) FROM $wpdb->links");
155 if($display) {
156 echo number_format($totallinks);
157 } else {
158 return number_format($totallinks);
159 }
160 }
161
162
163 ### Function: Get Recent Posts
164 function get_recentposts($mode = '', $limit = 10, $display = true) {
165 global $wpdb, $post;
166 $where = '';
167 $temp = '';
168 if(!empty($mode) && $mode != 'both') {
169 $where = "post_type = '$mode'";
170 } else {
171 $where = '1=1';
172 }
173 $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");
174 if($recentposts) {
175 foreach ($recentposts as $post) {
176 $post_title = get_the_title();
177 $post_date = get_the_time(get_option('date_format').' @ '.get_option('time_format'));
178 $display_name = stripslashes($post->display_name);
179 $temp .= "<li>$post_date - <a href=\"".get_permalink()."\" title=\"".sprintf(__('View post %s', 'wp-stats'), $post_title)."\">$post_title</a> ($display_name)</li>\n";
180 }
181 } else {
182 $temp = '<li>'.__('N/A', 'wp-stats').'</li>';
183 }
184 if($display) {
185 echo $temp;
186 } else {
187 return $temp;
188 }
189 }
190
191
192 ### Function: Get Recent Comments
193 function get_recentcomments($mode = '', $limit = 10, $display = true) {
194 global $wpdb, $post;
195 $where = '';
196 $temp = '';
197 if(!empty($mode) && $mode != 'both') {
198 $where = "post_type = '$mode'";
199 } else {
200 $where = '1=1';
201 }
202 $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");
203 if($recentcomments) {
204 foreach ($recentcomments as $post) {
205 $post_title = get_the_title();
206 $comment_author = htmlspecialchars(stripslashes($post->comment_author));
207 $comment_date = mysql2date(get_option('date_format').' @ '.get_option('time_format'), $post->comment_date);
208 $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";
209 }
210 } else {
211 $temp = '<li>'.__('N/A', 'wp-stats').'</li>';
212 }
213 if($display) {
214 echo $temp;
215 } else {
216 return $temp;
217 }
218 }
219
220
221 ### Function: Get Top Commented Posts
222 function get_mostcommented($mode = '', $limit = 10, $chars = 0, $display = true) {
223 global $wpdb, $post;
224 $where = '';
225 $temp = '';
226 if(!empty($mode) && $mode != 'both') {
227 $where = "post_type = '$mode'";
228 } else {
229 $where = '1=1';
230 }
231 $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");
232 if($mostcommenteds) {
233 if($chars > 0) {
234 foreach ($mostcommenteds as $post) {
235 $post_title = get_the_title();
236 $comment_total = number_format_i18n($post->comment_total);
237 $temp .= "<li><a href=\"".get_permalink()."\" title=\"".sprintf(__('View comments in post %s', 'wp-stats'), $post_title)."\">".snippet_text($post_title, $chars)."</a> - ".sprintf(__ngettext('%s comment', '%s comments', $comment_total, 'wp-stats'), $comment_total)."</li>";
238 }
239 } else {
240 foreach ($mostcommenteds as $post) {
241 $post_title = get_the_title();
242 $comment_total = number_format_i18n($post->comment_total);
243 $temp .= "<li><a href=\"".get_permalink()."\" title=\"".sprintf(__('View comments in post %s', 'wp-stats'), $post_title)."\">$post_title</a> - ".sprintf(__ngettext('%s comment', '%s comments', $comment_total, 'wp-stats'), $comment_total)."</li>";
244 }
245 }
246 } else {
247 $temp = '<li>'.__('N/A', 'wp-stats').'</li>';
248 }
249 if($display) {
250 echo $temp;
251 } else {
252 return $temp;
253 }
254 }
255
256
257 ### Function: Get Author Stats
258 function get_authorsstats($mode = '', $display = true) {
259 global $wpdb, $wp_rewrite;
260 $where = '';
261 $temp = '';
262 if(!empty($mode) && $mode != 'both') {
263 $where = "post_type = '$mode'";
264 } else {
265 $where = '1=1';
266 }
267 $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");
268 if($posts) {
269 $using_permalink = get_option('permalink_structure');
270 $permalink = $wp_rewrite->get_author_permastruct();
271 foreach ($posts as $post) {
272 $post_author = strip_tags(stripslashes($post->user_nicename));
273 $author_link = str_replace('%author%', $post_author, $permalink);
274 $display_name = strip_tags(stripslashes($post->display_name));
275 $posts_total = number_format_i18n($post->posts_total);
276 if($using_permalink) {
277 $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";
278 } else {
279 $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";
280 }
281 }
282 } else {
283 $temp = '<li>'.__('N/A', 'wp-stats').'</li>';
284 }
285 if($display) {
286 echo $temp;
287 } else {
288 return $temp;
289 }
290 }
291
292
293 ### Function: Get Comments' Members Stats
294 // Treshhold = Number Of Posts User Must Have Before It Will Display His Name Out
295 // 5 = Default Treshhold; -1 = Disable Treshhold
296 function get_commentmembersstats($threshhold = -1, $limit = 0, $display = true) {
297 global $wpdb;
298 $temp = '';
299 $limit_sql = '';
300 if($limit > 0) {
301 $limit_sql = "LIMIT $limit";
302 }
303 $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");
304 if($comments) {
305 foreach ($comments as $comment) {
306 $comment_total = intval($comment->comment_total);
307 // If Total Comments Is Below Threshold
308 if($comment_total >= $threshhold) {
309 $comment_author = strip_tags(stripslashes($comment->comment_author));
310 $comment_author_link = urlencode($comment_author);
311 $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> (".number_format_i18n($comment_total).")</li>\n";
312 }
313 }
314 } else {
315 $temp = '<li>'.__('N/A', 'wp-stats').'</li>';
316 }
317 if($display) {
318 echo $temp;
319 } else {
320 return $temp;
321 }
322 }
323
324
325 ### Function: Get Post Categories Stats
326 function get_postcats($display = true) {
327 global $wpdb;
328 $temp = '';
329 $defaults = array('type' => 'post', 'style' => 'list', 'show_count' => 1);
330 $categories = get_categories($defaults);
331 if (empty($categories)){
332 $temp .= '<li>'.__('No categories', 'wp-stats').'</li>';
333 } else {
334 $temp .= walk_category_tree($categories, 0, $defaults);
335 }
336 if($display) {
337 echo $temp;
338 } else {
339 return $temp;
340 }
341 }
342
343
344 ### Function: Get Links Categories Stats
345 function get_linkcats($display = true) {
346 global $wpdb;
347 $temp = '';
348 $cats = get_categories('type=link');
349 if ($cats) {
350 foreach ($cats as $cat) {
351 $temp .= '<li>'.$cat->cat_name.' ('.number_format_i18n($cat->count).")</li>\n";
352 }
353 }
354 if($display) {
355 echo $temp;
356 } else {
357 return $temp;
358 }
359 }
360
361
362 ### Function: Get Tags List
363 function get_tags_list($display = true) {
364 global $wpdb;
365 $temp = '';
366 $tags = get_tags('orderby=count&order=DESC');
367 if ($tags) {
368 foreach ($tags as $tag) {
369 $temp .= '<li><a href="'.clean_url(get_tag_link($tag->term_id)).'" title="'.sprintf(__ngettext('%s topic', '%s topics', number_format_i18n($tag->count), 'wp-stats'), number_format_i18n($tag->count)).'">'.$tag->name.'</a> ('.number_format_i18n($tag->count).")</li>\n";
370 }
371 }
372 if($display) {
373 echo $temp;
374 } else {
375 return $temp;
376 }
377 }
378
379
380 ### Function: Snippet Text
381 if(!function_exists('snippet_text')) {
382 function snippet_text($text, $length = 0) {
383 $text = html_entity_decode($text, ENT_QUOTES, get_option('blog_charset'));
384 if (strlen($text) > $length) {
385 return htmlentities(substr($text,0,$length), ENT_COMPAT, get_option('blog_charset')).'...';
386 } else {
387 return htmlentities($text, ENT_COMPAT, get_option('blog_charset'));
388 }
389 }
390 }
391
392
393 ### Function: Short Code For Inserting Stats Into Page
394 add_shortcode('page_stats', 'stats_page_shortcode');
395 function stats_page_shortcode($atts) {
396 return stats_page();
397 }
398
399
400 ### Function: Stats Page
401 function stats_page_link($author, $page = 0) {
402 $stats_url = get_option('stats_url');
403 if($page > 1) {
404 $page = "&amp;stats_page=$page";
405 } else {
406 $page = '';
407 }
408 if(strpos($stats_url, '?') !== false) {
409 $stats_url = "$stats_url&amp;stats_author=$author$page";
410 } else {
411 $stats_url = "$stats_url?stats_author=$author$page";
412 }
413 return $stats_url;
414 }
415
416
417 ### Function: Statistics Page
418 function stats_page() {
419 global $wpdb, $post;
420 // Variables Variables Variables
421 $comment_author = urldecode(strip_tags(stripslashes(trim($_GET['stats_author']))));
422 $page = intval($_GET['stats_page']);
423 $temp_stats = '';
424 $temp_post = $post;
425 $stats_mostlimit = intval(get_option('stats_mostlimit'));
426 $stats_display = get_option('stats_display');
427
428 // Default wp-stats.php Page
429 if(empty($comment_author)) {
430 // General Stats
431 if($stats_display['total_stats'] == 1) {
432 $temp_stats .= '<h2 id="GeneralStats">'.__('General Stats', 'wp-stats').'</h2>'."\n";
433 $temp_stats .= '<p><strong>'.__('Total Stats', 'wp-stats').'</strong></p>'."\n";
434 $temp_stats .= '<ul>'."\n";
435 $temp_stats .= '<li>'.sprintf(__ngettext('<strong>%s</strong> author to this blog.', '<strong>%s</strong> authors to this blog.', get_totalauthors(false), 'wp-stats'), get_totalauthors(false)).'</li>'."\n";
436 $temp_stats .= '<li>'.sprintf(__ngettext('<strong>%s</strong> post was posted.', '<strong>%s</strong> posts were posted.', get_totalposts(false), 'wp-stats'), get_totalposts(false)).'</li>'."\n";
437 $temp_stats .= '<li>'.sprintf(__ngettext('<strong>%s</strong> page was created.', '<strong>%s</strong> pages were created.', get_totalpages(false), 'wp-stats'), get_totalpages(false)).'</li>'."\n";
438 $temp_stats .= '<li>'.sprintf(__ngettext('<strong>%s</strong> tag was created.', '<strong>%s</strong> tags were created.', wp_count_terms('post_tag'), 'wp-stats'), wp_count_terms('post_tag')).'</li>'."\n";
439
440 $temp_stats .= '<li>'.sprintf(__ngettext('<strong>%s</strong> comment was posted.', '<strong>%s</strong> comments were posted.', get_totalcomments(false), 'wp-stats'), get_totalcomments(false)).'</li>'."\n";
441 $temp_stats .= '<li>'.sprintf(__ngettext('<strong>%s</strong> nickname was represented in the comments.', '<strong>%s</strong> different nicknames were represented in the comments.', get_totalcommentposters(false), 'wp-stats'), get_totalcommentposters(false)).'</li>'."\n";
442
443 $temp_stats .= '<li>'.sprintf(__ngettext('<strong>%s</strong> link was added.', '<strong>%s</strong> links were added.', get_totallinks(false), 'wp-stats'), get_totallinks(false)).'</li>'."\n";
444 $temp_stats .= '<li>'.sprintf(__ngettext('<strong>%s</strong> post category was needed.', '<strong>%s</strong> post categories were needed.', wp_count_terms('category'), 'wp-stats'), wp_count_terms('category')).'</li>'."\n";
445 $temp_stats .= '<li>'.sprintf(__ngettext('<strong>%s</strong> link category was needed.', '<strong>%s</strong> link categories were needed.', wp_count_terms('link_category'), 'wp-stats'), wp_count_terms('link_category')).'</li>'."\n";
446 if(function_exists('akismet_spam_count')) {
447 $temp_stats .= '<li>'.sprintf(__ngettext('<strong>%s</strong> spam blocked.', '<strong>%s</strong> spam blocked.', number_format(get_option('akismet_spam_count')), 'wp-stats'), number_format(get_option('akismet_spam_count'))).'</li>'."\n";
448 }
449 // WP-Stats: General Stats Filter
450 $temp_stats = apply_filters('wp_stats_page_general', $temp_stats);
451 $temp_stats .= '</ul>'."\n";
452 }
453
454 // Plugin Stats
455 $temp_stats .= '<h2 id="PluginsStats">'.__('Plugins Stats', 'wp-stats').'</h2>'."\n";
456
457 // WP-Stats: Plugins Stats Filter
458 $temp_stats = apply_filters('wp_stats_page_plugins', $temp_stats);
459
460 // Top Recent Stats
461 $temp_stats .= '<h2 id="TopRecentStats">'.sprintf(__ngettext('Top %s Recent Stat', 'Top %s Recent Stats', $stats_mostlimit, 'wp-stats'), $stats_mostlimit).'</h2>'."\n";
462
463 // Recent Posts
464 if($stats_display['recent_posts'] == 1) {
465 $temp_stats .= '<p><strong>'.sprintf(__ngettext('%s Recent Post', '%s Recent Posts', $stats_mostlimit, 'wp-stats'), $stats_mostlimit).'</strong></p>'."\n";
466 $temp_stats .= '<ul>'."\n";
467 $temp_stats .= get_recentposts('post', $stats_mostlimit, false);
468 $temp_stats .= '</ul>'."\n";
469 }
470
471 // Recent Comments
472 if($stats_display['recent_commtents'] == 1) {
473 $temp_stats .= '<p><strong>'.sprintf(__ngettext('%s Recent Comment', '%s Recent Comments', $stats_mostlimit, 'wp-stats'), $stats_mostlimit).'</strong></p>'."\n";
474 $temp_stats .= '<ul>'."\n";
475 $temp_stats .= get_recentcomments('post', $stats_mostlimit, false);
476 $temp_stats .= '</ul>'."\n";
477 }
478
479 // WP-Stats: Top Recent Stats Filter
480 $temp_stats = apply_filters('wp_stats_page_recent', $temp_stats);
481
482 // Top Most Stats
483 $temp_stats .= '<h2 id="TopMostHighestStats">'.sprintf(__ngettext('%s Most/Highest Stat', '%s Most/Highest Stats', $stats_mostlimit, 'wp-stats'), $stats_mostlimit).'</h2>'."\n";
484
485 // Most Commented Post
486 if($stats_display['commented_post'] == 1) {
487 $temp_stats .= '<p><strong>'.sprintf(__ngettext('%s Most Commented Post', '%s Most Commented Posts', $stats_mostlimit, 'wp-stats'), $stats_mostlimit).'</strong></p>'."\n";
488 $temp_stats .= '<ul>'."\n";
489 $temp_stats .= get_mostcommented('post', $stats_mostlimit, 0, false);
490 $temp_stats .= '</ul>'."\n";
491 }
492
493 // WP-Stats: Top Most/Highest Stats Filter
494 $temp_stats = apply_filters('wp_stats_page_most', $temp_stats);
495
496 // Authors Stats
497 $temp_stats .= '<h2 id="AuthorsStats">'.__('Authors Stats', 'wp-stats').'</h2>'."\n";
498
499 // Authors
500 if($stats_display['authors'] == 1) {
501 $temp_stats .= '<p><strong>'.__('Authors', 'wp-stats').'</strong></p>'."\n";
502 $temp_stats .= '<ol>'."\n";
503 $temp_stats .= get_authorsstats('post', false);
504 $temp_stats .= '</ol>'."\n";
505 }
506
507 // WP-Stats: Authors Stats Filter
508 $temp_stats = apply_filters('wp_stats_page_authors', $temp_stats);
509
510 // Comments' Members Stats
511 $temp_stats .= '<h2 id="CommentsMembersStats">'.__('Comments\' Members Stats', 'wp-stats').'</h2>'."\n";
512
513 // Comments' Member
514 if($stats_display['comment_members'] == 1) {
515 $temp_stats .= '<p><strong>'.__('Comment Members', 'wp-stats').'</strong></p>'."\n";
516 $temp_stats .= '<ol>'."\n";
517 $temp_stats .= get_commentmembersstats(5, 0, false);
518 $temp_stats .= '</ol>'."\n";
519 }
520
521 // WP-Stats: Comments' Members Stats Filter
522 $temp_stats = apply_filters('wp_stats_page_comments_members', $temp_stats);
523
524 // Misc Stats
525 $temp_stats .= '<h2 id="MiscStats">'.__('Misc Stats', 'wp-stats').'</h2>'."\n";
526
527 // Post Categories
528 if($stats_display['post_cats'] == 1) {
529 $temp_stats .= '<p><strong>'.__('Post Categories', 'wp-stats').'</strong></p>'."\n";
530 $temp_stats .= '<ul>'."\n";
531 $temp_stats .= get_postcats(false);
532 $temp_stats .= '</ul>'."\n";
533 }
534
535 // Link Categories
536 if($stats_display['link_cats'] == 1) {
537 $temp_stats .= '<p><strong>'.__('Link Categories', 'wp-stats').'</strong></p>'."\n";
538 $temp_stats .= '<ul>'."\n";
539 $temp_stats .= get_linkcats(false);
540 $temp_stats .= '</ul>'."\n";
541 }
542
543 if($stats_display['tags_list'] == 1) {
544 $temp_stats .= '<p><strong>'.__('Tags List', 'wp-stats').'</strong></p>'."\n";
545 $temp_stats .= '<ul>'."\n";
546 $temp_stats .= get_tags_list(false);
547 $temp_stats .= '</ul>'."\n";
548 }
549
550 // WP-Stats: Plugin Misc Filter
551 $temp_stats = apply_filters('wp_stats_page_misc', $temp_stats);
552
553 // Displaying Comments Posted By User
554 } else {
555 // Stats URL
556 $stats_url = get_option('stats_url');
557 // Number Of Comments Per Page
558 $perpage = 10;
559 // Comment Author Link
560 $comment_author_link = urlencode($comment_author);
561 // Comment Author SQL
562 $comment_author_sql = $wpdb->escape($comment_author);
563 // Total Comments Posted By User
564 $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 = ''");
565 // Calculate Paging
566 $numposts = $totalcomments;
567 $perpage = 30;
568 $max_page = ceil($numposts/$perpage);
569 if(empty($page) || $page == 0) {
570 $page = 1;
571 }
572 $offset = ($page-1) * $perpage;
573 $pages_to_show = 10;
574 $pages_to_show_minus_1 = $pages_to_show-1;
575 $half_page_start = floor($pages_to_show_minus_1/2);
576 $half_page_end = ceil($pages_to_show_minus_1/2);
577 $start_page = $page - $half_page_start;
578 if($start_page <= 0) {
579 $start_page = 1;
580 }
581 $end_page = $page + $half_page_end;
582 if(($end_page - $start_page) != $pages_to_show_minus_1) {
583 $end_page = $start_page + $pages_to_show_minus_1;
584 }
585 if($end_page > $max_page) {
586 $start_page = $max_page - $pages_to_show_minus_1;
587 $end_page = $max_page;
588 }
589 if($start_page <= 0) {
590 $start_page = 1;
591 }
592 if(($offset + $perpage) > $numposts) {
593 $max_on_page = $numposts;
594 } else {
595 $max_on_page = ($offset + $perpage);
596 }
597 if (($offset + 1) > ($numposts)) {
598 $display_on_page = $numposts;
599 } else {
600 $display_on_page = ($offset + 1);
601 }
602
603 // Getting The Comments
604 $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");
605 $temp_stats .= '<h2>'.__('Comments Posted By', 'wp-stats').' '.$comment_author.'</h2>';
606 $temp_stats .= '<p>'.sprintf(__('Displaying <strong>%s</strong> To <strong>%s</strong> Of <strong>%s</strong> Comments', 'wp-stats'), number_format_i18n($display_on_page), number_format_i18n($max_on_page), number_format_i18n($numposts)).'</p>';
607
608
609 // Get Comments
610 if($gmz_comments) {
611 foreach($gmz_comments as $post) {
612 $comment_id = intval($post->comment_ID);
613 $comment_author2 = htmlspecialchars(stripslashes($post->comment_author));
614 $comment_date = mysql2date(sprintf(__('%s @ %s', 'wp-stats'), get_option('date_format'), get_option('time_format')), $post->comment_date);
615 $comment_content = stripslashes(strip_tags($post->comment_content));
616 $post_date = get_the_time(sprintf(__('%s @ %s', 'wp-stats'), get_option('date_format'), get_option('time_format')));
617 $post_title = get_the_title();
618
619 // Check For Password Protected Post
620 if(!empty($post->post_password) && stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password) {
621 // If New Title, Print It Out
622 if($post_title != $cache_post_title) {
623 $temp_stats .= "<p><strong><a href=\"".get_permalink()."\" title=\"".__('Posted On', 'wp-stats')." $post_date\">".__('Protected', 'wp-stats').": $post_title</a></strong></p>";
624 $temp_stats .= '<blockquote>'.__('Comments Protected', 'wp-stats').'</blockquote>';
625 }
626 } else {
627 // If New Title, Print It Out
628 if($post_title != $cache_post_title) {
629 $temp_stats .= "<p><strong><a href=\"".get_permalink()."\" title=\"".__('Posted On', 'wp-stats')." $post_date\">$post_title</a></strong></p>";
630 }
631 $temp_stats .= "<blockquote><p>$comment_content<br /><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</p></blockquote>";
632 }
633 $cache_post_title = $post_title;
634 }
635 } else {
636 $temp_stats .= "<p>$comment_author ".__('has not made any comments yet.', 'wp-stats')."</p>";
637 }
638 if($max_page > 1) {
639 $temp_stats = apply_filters('wp_stats_paging_start', $temp_stats);
640 $temp_stats .= '<div class="wp-pagenavi">'."\n";
641 $temp_stats .= '<span class="pages">Page '.$page.' of '.$max_page.'</span>';
642 if ($start_page >= 2 && $pages_to_show < $max_page) {
643 $temp_stats .= '<a href="'.stats_page_link($comment_author_link, 1).'" title="&laquo; First">&laquo; First</a>';
644 $temp_stats .= '<span class="extend">...</span>';
645 }
646 if($page > 1) {
647 $temp_stats .= '<a href="'.stats_page_link($comment_author_link, ($page-1)).'" title="&laquo;">&laquo;</a>';
648 }
649 for($i = $start_page; $i <= $end_page; $i++) {
650 if($i == $page) {
651 $temp_stats .= '<span class="current">'.$i.'</span>';
652 } else {
653 $temp_stats .= '<a href="'.stats_page_link($comment_author_link, $i).'" title="'.$i.'">'.$i.'</a>';
654 }
655 }
656 if(empty($page) || ($page+1) <= $max_page) {
657 $temp_stats .= '<a href="'.stats_page_link($comment_author_link, ($page+1)).'" title="&raquo;">&raquo;</a>';
658 }
659 if ($end_page < $max_page) {
660 $temp_stats .= '<span class="extend">...</span>';
661 $temp_stats .= '<a href="'.stats_page_link($comment_author_link, $max_page).'" title="Last &raquo;">Last &raquo;</a>';
662 }
663 $temp_stats .= '</div>';
664 $temp_stats = apply_filters('wp_stats_paging_end', $temp_stats);
665 }
666 $temp_stats .= '<strong>&laquo;&laquo;</strong> <a href="'.$stats_url.'">'.__('Back To Stats Page', 'wp-stats').' </a>';
667 } // End If
668
669 // Assign Back $post
670 $post = $temp_post;
671
672 // Output Stats Page
673 return $temp_stats;
674 }
675
676
677 ### Function: Stats Option
678 add_action('activate_wp-stats/wp-stats.php', 'stats_init');
679 function stats_init() {
680 global $wpdb;
681 $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);
682 add_option('stats_mostlimit', '10', 'Stats Most Limit');
683 add_option('stats_display', $stats_display, 'Stats To Display');
684 add_option('stats_url', get_option('siteurl').'/stats/', 'Stats URL');
685 }
686 ?>