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

378 lines 15.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 +----------------------------------------------------------------+
4 | |
5 | WordPress 2.0 Plugin: WP-Stats 2.01 |
6 | Copyright (c) 2005 Lester "GaMerZ" Chan |
7 | |
8 | File Written By: |
9 | - Lester "GaMerZ" Chan |
10 | - http://www.lesterchan.net |
11 | |
12 | File Information: |
13 | - WordPress Statistics |
14 | - wp-stats.php |
15 | |
16 +----------------------------------------------------------------+
17 */
18
19
20 ### Require WordPress Header
21 require(dirname(__FILE__).'/wp-blog-header.php');
22
23 ### Variables Variables Variables
24 $comment_author = urldecode(strip_tags(stripslashes(trim($_GET['author']))));
25 $page = intval($_GET['page']);
26
27 ### Function: Get Total Posts
28 function get_totalposts() {
29 global $wpdb;
30 $totalposts = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_status = 'publish'");
31 echo $totalposts;
32 }
33
34 ### Function: Get Total Pages
35 function get_totalpages() {
36 global $wpdb;
37 $totalpages = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_status = 'static'");
38 echo $totalpages;
39 }
40
41 ### Function: Get Total Comments
42 function get_totalcomments() {
43 global $wpdb;
44 $totalcomments = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = '1'");
45 echo $totalcomments;
46 }
47
48 ### Function: Get Total Comments Poster
49 function get_totalcommentposters() {
50 global $wpdb;
51 $totalcommentposters = $wpdb->get_var("SELECT COUNT(DISTINCT comment_author) FROM $wpdb->comments WHERE comment_approved = '1'");
52 echo $totalcommentposters;
53 }
54
55 ### Function: Get Total Links
56 function get_totallinks() {
57 global $wpdb;
58 $totallinks = $wpdb->get_var("SELECT COUNT(link_id) FROM $wpdb->links");
59 echo $totallinks;
60 }
61
62 ### Function: Get Recent Posts
63 function get_recentposts($limit = 10) {
64 global $wpdb, $post;
65 $recentposts = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_status, post_date, user_login FROM $wpdb->posts LEFT JOIN $wpdb->users ON $wpdb->users.ID = $wpdb->posts.post_author WHERE post_date < '".current_time('mysql')."' AND (post_status = 'publish' OR post_status = 'static') AND post_password = '' ORDER BY post_date DESC LIMIT $limit");
66 if($recentposts) {
67 foreach ($recentposts as $post) {
68 $post_title = htmlspecialchars(stripslashes($post->post_title));
69 $post_date = mysql2date('d.m.Y', $post->post_date);
70 $user_nickname = htmlspecialchars(stripslashes($post->user_login));
71 echo "<li>$post_date - <a href=\"".get_permalink()."\">$post_title</a> ($user_nickname)</li>";
72 }
73 } else {
74 echo '<li>'.__('N/A').'</li>';
75 }
76 }
77
78 ### Function: Get Recent Comments
79 function get_recentcomments($limit = 10) {
80 global $wpdb, $post;
81 $recentcomments = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_status, comment_author, post_date, comment_date FROM $wpdb->posts INNER JOIN $wpdb->comments ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID WHERE comment_approved = '1' AND post_date < '".current_time('mysql')."' AND (post_status = 'publish' OR post_status = 'static') AND post_password = '' ORDER BY comment_date DESC LIMIT $limit");
82 if($recentcomments) {
83 foreach ($recentcomments as $post) {
84 $post_title = htmlspecialchars(stripslashes($post->post_title));
85 $comment_author = htmlspecialchars(stripslashes($post->comment_author));
86 $comment_date = mysql2date('d.m.Y @ H:i', $post->comment_date);
87 echo "<li>$comment_date - $comment_author (<a href=\"".get_permalink()."\">$post_title</a>)</li>";
88 }
89 } else {
90 echo '<li>'.__('N/A').'</li>';
91 }
92 }
93
94 ### Function: Get Top Commented Posts
95 function get_mostcommented($limit = 10) {
96 global $wpdb, $post;
97 $mostcommenteds = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_status, post_date, 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 (post_status = 'publish' OR post_status = 'static') AND post_password = '' GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_total DESC LIMIT $limit");
98 if($mostcommenteds) {
99 foreach ($mostcommenteds as $post) {
100 $post_title = htmlspecialchars(stripslashes($post->post_title));
101 $comment_total = intval($post->comment_total);
102 echo "<li><a href=\"".get_permalink()."\">$post_title</a> - $comment_total ".__('comments')."</li>";
103 }
104 } else {
105 echo '<li>'.__('N/A').'</li>';
106 }
107 }
108
109 ### Function: Get Comments' Members Stats
110 // Treshhold = Number Of Posts User Must Have Before It Will Display His Name Out
111 // 5 = Default Treshhold; -1 = Disable Treshhold
112 function get_commentmembersstats($threshhold = -1) {
113 global $wpdb;
114 $comments = $wpdb->get_results("SELECT comment_author, COUNT(comment_ID) AS 'comment_total' FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_author ORDER BY comment_total DESC");
115 if($comments) {
116 foreach ($comments as $comment) {
117 $comment_author = strip_tags(stripslashes($comment->comment_author));
118 $comment_author_link = urlencode($comment_author);
119 $comment_total = intval($comment->comment_total);
120 echo "<li><a href=\"wp-stats.php?author=$comment_author_link\">$comment_author</a> ($comment_total)</li>";
121 // If Total Comments Is Below Threshold
122 if($comment_total <= $threshhold && $threshhold != -1) {
123 return;
124 }
125 }
126 } else {
127 echo '<li>'.__('N/A').'</li>';
128 }
129 }
130
131 ### Function: Get Links Categories Stats
132 function get_linkcats() {
133 global $wpdb;
134 $linkcats = $wpdb->get_results("SELECT $wpdb->linkcategories.cat_name, COUNT(*) AS 'total_links' FROM $wpdb->links INNER JOIN $wpdb->linkcategories ON $wpdb->linkcategories.cat_id = $wpdb->links.link_category GROUP BY $wpdb->linkcategories.cat_id ORDER BY total_links DESC ");
135 if($linkcats) {
136 foreach ($linkcats as $linkcat) {
137 $cat_name = htmlspecialchars(stripslashes($linkcat->cat_name));
138 $total_links = intval($linkcat->total_links);
139 echo "<li>$cat_name ($total_links)</li>\n";
140 }
141 } else {
142 echo '<li>'.__('N/A').'</li>';
143 }
144 }
145
146 ### Function: Get Poll Total Questions
147 function get_pollquestions() {
148 global $wpdb;
149 if(function_exists('get_poll')) {
150 $totalpollq = $wpdb->get_var("SELECT COUNT(pollq_id) FROM $wpdb->pollsq");
151 echo $totalpollq;
152 }
153 }
154
155 ### Function: Get Poll Total Answers
156 function get_pollanswers() {
157 global $wpdb;
158 if(function_exists('get_poll')) {
159 $totalpolla = $wpdb->get_var("SELECT COUNT(polla_aid) FROM $wpdb->pollsa");
160 echo $totalpolla;
161 }
162 }
163
164 ### Function: Get Poll Total Votes
165 function get_pollvotes() {
166 global $wpdb;
167 if(function_exists('get_poll')) {
168 $totalpollip = $wpdb->get_var("SELECT COUNT(pollip_id) FROM $wpdb->pollsip");
169 echo $totalpollip;
170 }
171 }
172
173 ### Function: Get EMail Total Sent
174 function get_emails() {
175 global $wpdb;
176 if(function_exists('wp_email')) {
177 $totalemails = $wpdb->get_var("SELECT COUNT(email_id) FROM $wpdb->email");
178 echo $totalemails;
179 }
180 }
181
182 ### Function: Get EMail Total Sent Success
183 function get_emails_success() {
184 global $wpdb;
185 if(function_exists('wp_email')) {
186 $totalemails_success = $wpdb->get_var("SELECT COUNT(email_id) FROM $wpdb->email WHERE email_status = '".__('Success')."'");
187 echo $totalemails_success;
188 }
189 }
190
191 ### Function: Get EMail Total Sent Failed
192 function get_emails_failed() {
193 global $wpdb;
194 if(function_exists('wp_email')) {
195 $totalemails_failed = $wpdb->get_var("SELECT COUNT(email_id) FROM $wpdb->email WHERE email_status = '". __('Failed')."'");
196 echo $totalemails_failed;
197 }
198 }
199
200 ### Function: Get Most Emailed Post
201 function get_mostemailed($limit = 10) {
202 global $wpdb, $post;
203 if(function_exists('wp_email')) {
204 $mostemailed= $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_date, COUNT($wpdb->email.email_postid) AS 'email_total' FROM $wpdb->email LEFT JOIN $wpdb->posts ON $wpdb->email.email_postid = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND (post_status = 'publish' OR post_status = 'static') AND post_password = '' GROUP BY $wpdb->email.email_postid ORDER BY email_total DESC LIMIT $limit");
205 if($mostemailed) {
206 foreach ($mostemailed as $post) {
207 $post_title = htmlspecialchars(stripslashes($post->post_title));
208 $email_total = intval($post->email_total);
209 echo "<li><a href=\"".get_permalink()."\">$post_title</a> - $email_total ".__('Emails')."</li>";
210 }
211 } else {
212 echo '<li>'.__('N/A').'</li>';
213 }
214 }
215 }
216 ?>
217 <?php get_header(); ?>
218 <div id="content" class="narrowcolumn">
219 <?php
220 ### Default wp-stats.php Page
221 if(empty($comment_author)) {
222 ?>
223 <h2 class="pagetitle">General Stats</h2>
224 <ul>
225 <li><b><?php get_totalposts(); ?></b> Posts Were Posted</li>
226 <li><b><?php get_totalpages(); ?></b> Pages Were Created</li>
227 <li><b><?php get_totalcomments(); ?></b> Comments Were Posted</li>
228 <li><b><?php get_totalcommentposters(); ?></b> Different Nicks Were Represented In The Comments</li>
229 <li><b><?php get_totallinks(); ?></b> Links Were Added</li>
230 </ul>
231 <?php if(function_exists('get_poll')): ?>
232 <h2 class="pagetitle">Poll Stats</h2>
233 <ul>
234 <li><b><?php get_pollquestions(); ?></b> Polls Were Created</li>
235 <li><b><?php get_pollanswers(); ?></b> Polls' Answers Were Given</li>
236 <li><b><?php get_pollvotes(); ?></b> Votes Were Casted</li>
237 </ul>
238 <?php endif; ?>
239 <?php if(function_exists('wp_email')): ?>
240 <h2 class="pagetitle">Email Stats</h2>
241 <ul>
242 <li><b><?php get_emails(); ?></b> Emails Were Sent</li>
243 <li><b><?php get_emails_success(); ?></b> Emails Were Sent Successfully</li>
244 <li><b><?php get_emails_failed(); ?></b> Emails Failed To Send</li>
245 </ul>
246 <?php endif; ?>
247 <h2 class="pagetitle">10 Recent Posts</h2>
248 <ul><?php get_recentposts(); ?></ul>
249 <h2 class="pagetitle">10 Recent Comments</h2>
250 <ul><?php get_recentcomments(); ?></ul>
251 <h2 class="pagetitle">10 Most Commented Post</h2>
252 <ul><?php get_mostcommented(); ?></ul>
253 <?php if(function_exists('wp_email')): ?>
254 <h2 class="pagetitle">10 Most Emailed Post</h2>
255 <ul><?php get_mostemailed(); ?></ul>
256 <?php endif; ?>
257 <h2 class="pagetitle">Comments' Members Stats</h2>
258 <ol><?php get_commentmembersstats(); ?></ol>
259 <h2 class="pagetitle">Post Categories Stats</h2>
260 <ul><?php list_cats(1,'All','name','asc','',true,0,1,0,1,true,0,0,0,'','','',true); ?></ul>
261 <h2 class="pagetitle">Link Categories Stats</h2>
262 <ul><?php get_linkcats(); ?></ul>
263 <?php
264 ### Displaying Comments Posted By User
265 } else {
266 // Number Of Comments Per Page
267 $perpage = 10;
268 // Comment Author Link
269 $comment_author_link = urlencode($comment_author);
270 // Comment Author SQL
271 $comment_author_sql = $wpdb->escape($comment_author);
272 // Total Comments Posted By User
273 $totalcomments = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_author='$comment_author_sql'");
274 // Checking $page and $offset
275 if (empty($page) || $page == 0) { $page = 1; }
276 if (empty($offset)) { $offset = 0; }
277 // Determin $offset
278 $offset = ($page-1) * $perpage;
279 // Some Comments Stats
280 if(($offset + $perpage) > $totalcomments) { $maxonpage = $totalcomments ; } else { $maxonpage = ($offset+$perpage); }
281 if (($offset + 1) > ($totalcomments)) { $displayonpage = $totalcomments ; } else { $displayonpage = ($offset+1); }
282 // Count Total Pages
283 $totalpages = ceil($totalcomments/$perpage);
284 // Getting The Comments
285 $gmz_comments = $wpdb->get_results("SELECT $wpdb->posts.ID, comment_author, comment_date, comment_content, ID, comment_ID, post_date, post_title, post_name 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' OR post_status = 'static') ORDER BY comment_post_ID DESC, comment_date DESC LIMIT $offset, $perpage");
286 ?>
287 <h2 class="pagetitle">Comments Posted By <?php echo $comment_author; ?></h2>
288 <p>Displaying <b><?php echo $displayonpage; ?></b> To <b><?php echo $maxonpage; ?></b> Of <b><?php echo $totalcomments; ?></b> Comments</p>
289 <?php
290 // Get Comments
291 if($gmz_comments) {
292 foreach($gmz_comments as $post) {
293 $comment_id = intval($post-> comment_ID);
294 $comment_author2 = htmlspecialchars(stripslashes($post->comment_author));
295 $comment_date = mysql2date('d.m.Y @ H:i', $post->comment_date);
296 $comment_content = wpautop(stripslashes($post->comment_content));
297 $post_date = mysql2date('d.m.Y @ H:i', $post->post_date);
298 $post_title = htmlspecialchars(stripslashes($post->post_title));
299
300 // If New Title, Print It Out
301 if($post_title != $cache_post_title) {
302 echo "<p><b><a href=\"".get_permalink()."\" title=\"Posted On $post_date\">$post_title</a></b></p>";
303 }
304 echo "<blockquote>$comment_content <a href=\"".get_permalink()."#comment-$comment_id\">Comment</a> Posted By <b>$comment_author2</b> On $comment_date</blockquote>";
305
306 $cache_post_title = $post_title;
307 }
308 } else {
309 echo "<p>$comment_author has not made any comments yet.</p>";
310 }
311
312 // If Total Pages Is More Than 1, Display Page Navigation
313 if($totalpages > 1) {
314 ?>
315 <table width="100%" cellspacing="0" cellpadding="0" border="0">
316 <tr>
317 <td align="left" width="50%">
318 <br />
319 <?php
320 if($page > 1 && ((($page*$perpage)-($perpage-1)) < $totalcomments)) {
321 echo '<p><b>&laquo;</b> <a href="wp-stats.php?author='.$comment_author_link.'&amp;page='.($page-1).'">Previous Page</a></p>';
322 } else {
323 echo '<p>&nbsp;</p>';
324 }
325 ?>
326 </td>
327 <td align="right" width="50%">
328 <br />
329 <?php
330 if($page >= 1 && ((($page*$perpage)+1) < $totalcomments)) {
331 echo '<p><a href="wp-stats.php?author='.$comment_author_link.'&amp;page='.($page+1).'">Next page</a> <b>&raquo;</b></p>';
332 } else {
333 echo '<p>&nbsp;</p>';
334 }
335 ?>
336 </td>
337 </tr>
338 <tr>
339 <td colspan="2" align="center">
340 <br />
341 <p>Pages (<?php echo $totalpages; ?>):
342 <?php
343 if ($page >= 4) {
344 echo "<a href=\"wp-stats.php?author=$comment_author_link\">&laquo; First</a> ... ";
345 }
346 if($page > 1) {
347 echo " <a href=\"wp-stats.php?author=$comment_author_link&amp;page=".($page-1)."\">&laquo;</a> ";
348 }
349 for($i = $page - 2 ; $i <= $page +2; $i++) {
350 if ($i >= 1 && $i <= $totalpages) {
351 if($i == $page) {
352 echo " [$i] ";
353 } else {
354 echo "<a href=\"wp-stats.php?author=$comment_author_link&amp;page=$i\">$i</a> ";
355 }
356 }
357 }
358 if($page < $totalpages) {
359 echo " <a href=\"wp-stats.php?author=$comment_author_link&amp;page=".($page+1)."\">&raquo;</a> ";
360 }
361 if (($page+2) < $totalpages) {
362 echo " ... <a href=\"wp-stats.php?author=$comment_author_link&amp;page=$totalpages\">Last &raquo;</a>";
363 }
364 ?>
365 </p>
366 </td>
367 </tr>
368 </table>
369 <?php
370 }
371 ?>
372 <p><b>&laquo;&laquo;</b> <a href="<?php get_settings('home'); ?>wp-stats.php">Back To Stats Page</a></p>
373 <?php
374 } // End If
375 ?>
376 </div>
377 <?php get_sidebar(); ?>
378 <?php get_footer(); ?>