PluginProbe
WP-Stats / 2.40
WP-Stats v2.40
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.40, at wp-stats.php

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