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

289 lines 12.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.00 |
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_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' AND post_password = '' ORDER BY post_date DESC LIMIT $limit");
66 foreach ($recentposts as $post) {
67 $post_title = htmlspecialchars(stripslashes($post->post_title));
68 $post_date = mysql2date('d.m.Y', $post->post_date);
69 $user_nickname = htmlspecialchars(stripslashes($post->user_login));
70 echo "<li>$post_date - <a href=\"".get_permalink()."\">$post_title</a> ($user_nickname)</li>";
71 }
72 }
73
74 ### Function: Get Recent Comments
75 function get_recentcomments($limit = 10) {
76 global $wpdb, $post;
77 $recentcomments = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, 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");
78 foreach ($recentcomments as $post) {
79 $post_title = htmlspecialchars(stripslashes($post->post_title));
80 $comment_author = htmlspecialchars(stripslashes($post->comment_author));
81 $comment_date = mysql2date('d.m.Y @ H:i', $post->comment_date);
82 echo "<li>$comment_date - $comment_author (<a href=\"".get_permalink()."\">$post_title</a>)</li>";
83 }
84 }
85
86 ### Function: Get Top Commented Posts
87 function get_mostcommented($limit = 10) {
88 global $wpdb, $post;
89 $mostcommenteds = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, 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' AND post_password = '' GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_total DESC LIMIT $limit");
90 foreach ($mostcommenteds as $post) {
91 $post_title = htmlspecialchars(stripslashes($post->post_title));
92 $comment_total = (int) $post->comment_total;
93 echo "<li><a href=\"".get_permalink()."\">$post_title</a> - $comment_total comments</li>";
94 }
95 }
96
97 ### Function: Get Comments' Members Stats
98 // Treshhold = Number Of Posts User Must Have Before It Will Display His Name Out
99 // 5 = Default Treshhold; -1 = Disable Treshhold
100 function get_commentmembersstats($threshhold = -1) {
101 global $wpdb;
102 $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");
103 foreach ($comments as $comment) {
104 $comment_author = strip_tags(stripslashes($comment->comment_author));
105 $comment_author_link = urlencode($comment_author);
106 $comment_total = intval($comment->comment_total);
107 echo "<li><a href=\"wp-stats.php?author=$comment_author_link\">$comment_author</a> ($comment_total)</li>";
108 // If Total Comments Is Below Threshold
109 if($comment_total <= $threshhold && $threshhold != -1) {
110 return;
111 }
112 }
113 }
114
115 ### Function: Get Links Categories Stats
116 function get_linkcats() {
117 global $wpdb;
118 $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 ");
119 foreach ($linkcats as $linkcat) {
120 $cat_name = htmlspecialchars(stripslashes($linkcat->cat_name));
121 $total_links = intval($linkcat->total_links);
122 echo "<li>$cat_name ($total_links)</li>\n";
123 }
124 }
125
126 ### Function: Get Poll Total Questions
127 function get_pollquestions() {
128 global $wpdb;
129 if(function_exists('get_poll')) {
130 $totalpollq = $wpdb->get_var("SELECT COUNT(pollq_id) FROM $wpdb->pollsq");
131 echo $totalpollq;
132 }
133 }
134
135 ### Function: Get Poll Total Answers
136 function get_pollanswers() {
137 global $wpdb;
138 if(function_exists('get_poll')) {
139 $totalpolla = $wpdb->get_var("SELECT COUNT(polla_aid) FROM $wpdb->pollsa");
140 echo $totalpolla;
141 }
142 }
143
144 ### Function: Get Poll Total Votes
145 function get_pollvotes() {
146 global $wpdb;
147 if(function_exists('get_poll')) {
148 $totalpollip = $wpdb->get_var("SELECT COUNT(pollip_id) FROM $wpdb->pollsip");
149 echo $totalpollip;
150 }
151 }
152 ?>
153 <?php get_header(); ?>
154 <div id="content" class="narrowcolumn">
155 <?php
156 ### Default wp-stats.php Page
157 if(empty($comment_author)) {
158 ?>
159 <h2 class="pagetitle">General Stats</h2>
160 <ul>
161 <li><b><?php get_totalposts(); ?></b> Posts Were Posted</li>
162 <li><b><?php get_totalpages(); ?></b> Pages Were Created</li>
163 <li><b><?php get_totalcomments(); ?></b> Comments Were Posted</li>
164 <li><b><?php get_totalcommentposters(); ?></b> Different Nicks Were Represented In The Comments</li>
165 <li><b><?php get_totallinks(); ?></b> Links Were Added</li>
166 </ul>
167 <h2 class="pagetitle">10 Recent Posts</h2>
168 <ul><?php get_recentposts(); ?></ul>
169 <h2 class="pagetitle">10 Recent Comments</h2>
170 <ul><?php get_recentcomments(); ?></ul>
171 <h2 class="pagetitle">10 Most Commented Post</h2>
172 <ul><?php get_mostcommented(); ?></ul>
173 <h2 class="pagetitle">Comments' Members Stats</h2>
174 <ol><?php get_commentmembersstats(); ?></ol>
175 <h2 class="pagetitle">Post Categories Stats</h2>
176 <ul><?php list_cats(1,'All','name','asc','',true,0,1,0,1,true,0,0,0,'','','',true); ?></ul>
177 <h2 class="pagetitle">Link Categories Stats</h2>
178 <ul><?php get_linkcats(); ?></ul>
179 <?php if(function_exists('get_poll')): ?>
180 <h2 class="pagetitle">Poll Stats</h2>
181 <ul>
182 <li><b><?php get_pollquestions(); ?></b> Polls Were Created</li>
183 <li><b><?php get_pollanswers(); ?></b> Polls' Answers Were Given</li>
184 <li><b><?php get_pollvotes(); ?></b> Votes Were Casted</li>
185 </ul>
186 <?php endif; ?>
187 <?php
188 ### Displaying Comments Posted By User
189 } else {
190 // Number Of Comments Per Page
191 $perpage = 10;
192 // Comment Author Link
193 $comment_author_link = urlencode($comment_author);
194 // Total Comments Posted By User
195 $totalcomments = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_author='$comment_author'");
196 // Checking $page and $offset
197 if (empty($page) || $page == 0) { $page = 1; }
198 if (empty($offset)) { $offset = 0; }
199 // Determin $offset
200 $offset = ($page-1) * $perpage;
201 // Some Comments Stats
202 if(($offset + $perpage) > $totalcomments) { $maxonpage = $totalcomments ; } else { $maxonpage = ($offset+$perpage); }
203 if (($offset + 1) > ($totalcomments)) { $displayonpage = $totalcomments ; } else { $displayonpage = ($offset+1); }
204 // Count Total Pages
205 $totalpages = ceil($totalcomments/$perpage);
206 // Getting The Comments
207 $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' 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");
208 ?>
209 <h2 class="pagetitle">Comments Posted By <?php echo $comment_author; ?></h2>
210 <p>Displaying <b><?php echo $displayonpage; ?></b> To <b><?php echo $maxonpage; ?></b> Of <b><?php echo $totalcomments; ?></b> Comments</p>
211 <?php
212 foreach($gmz_comments as $post) {
213 $comment_id = intval($post-> comment_ID);
214 $comment_author2 = htmlspecialchars(stripslashes($post->comment_author));
215 $comment_date = mysql2date('d.m.Y @ H:i', $post->comment_date);
216 $comment_content = wpautop(stripslashes($post->comment_content));
217 $post_date = mysql2date('d.m.Y @ H:i', $post->post_date);
218 $post_title = htmlspecialchars(stripslashes($post->post_title));
219
220 // If New Title, Print It Out
221 if($post_title != $cache_post_title) {
222 echo "<p><b><a href=\"".get_permalink()."\" title=\"Posted On $post_date\">$post_title</a></b></p>";
223 }
224 echo "<blockquote>$comment_content <a href=\"".get_permalink()."#comment-$comment_id\">Comment</a> Posted By <b>$comment_author2</b> On $comment_date</blockquote>";
225
226 $cache_post_title = $post_title;
227 }
228 ?>
229 <table width="100%" cellspacing="0" cellpadding="0" border="0">
230 <tr>
231 <td align="left" width="50%">
232 <br />
233 <?php
234 if($page > 1 && ((($page*$perpage)-($perpage-1)) < $totalcomments)) {
235 echo '<p><b>&laquo;</b> <a href="wp-stats.php?author='.$comment_author_link.'&amp;page='.($page-1).'">Previous Page</a></p>';
236 } else {
237 echo '<p>&nbsp;</p>';
238 }
239 ?>
240 </td>
241 <td align="right" width="50%">
242 <br />
243 <?php
244 if($page >= 1 && ((($page*$perpage)+1) < $totalcomments)) {
245 echo '<p><a href="wp-stats.php?author='.$comment_author_link.'&amp;page='.($page+1).'">Next page</a> <b>&raquo;</b></p>';
246 } else {
247 echo '<p>&nbsp;</p>';
248 }
249 ?>
250 </td>
251 </tr>
252 <tr>
253 <td colspan="2" align="center">
254 <br />
255 <p>Pages (<?php echo $totalpages; ?>):
256 <?php
257 if ($page >= 4) {
258 echo "<a href=\"wp-stats.php?author=$comment_author_link\">&laquo; First</a> ... ";
259 }
260 if($page > 1) {
261 echo " <a href=\"wp-stats.php?author=$comment_author_link&amp;page=".($page-1)."\">&laquo;</a> ";
262 }
263 for($i = $page - 2 ; $i <= $page +2; $i++) {
264 if ($i >= 1 && $i <= $totalpages) {
265 if($i == $page) {
266 echo "[$i]";
267 } else {
268 echo "<a href=\"wp-stats.php?author=$comment_author_link&amp;page=$i\">$i</a> ";
269 }
270 }
271 }
272 if($page < $totalpages) {
273 echo " <a href=\"wp-stats.php?author=$comment_author_link&amp;page=".($page+1)."\">&raquo;</a> ";
274 }
275 if (($page+2) < $totalpages) {
276 echo " ... <a href=\"wp-stats.php?author=$comment_author_link&amp;page=$totalpages\">Last &raquo;</a>";
277 }
278 ?>
279 </p>
280 </td>
281 </tr>
282 </table>
283 <p><b>&laquo;&laquo;</b> <a href="<?php get_settings('home'); ?>wp-stats.php">Back To Stats Page</a></p>
284 <?php
285 } // End If
286 ?>
287 </div>
288 <?php get_sidebar(); ?>
289 <?php get_footer(); ?>