| 1 |
<?php |
| 2 |
/* |
| 3 |
* Statistics Plugin For WordPress |
| 4 |
* - wp-stats.php |
| 5 |
* |
| 6 |
* Copyright � 2004-2005 Lester "GaMerZ" Chan |
| 7 |
*/ |
| 8 |
|
| 9 |
|
| 10 |
// Require WordPress Header |
| 11 |
require('wp-blog-header.php'); |
| 12 |
|
| 13 |
// Variables |
| 14 |
$comment_author = htmlspecialchars(stripslashes(trim($_GET['author']))); |
| 15 |
$page = intval($_GET['page']); |
| 16 |
|
| 17 |
// Get Total Posts |
| 18 |
function get_totalposts() { |
| 19 |
global $wpdb; |
| 20 |
$totalposts = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_status = 'publish'"); |
| 21 |
return $totalposts; |
| 22 |
} |
| 23 |
|
| 24 |
// Get Total Comments |
| 25 |
function get_totalcomments() { |
| 26 |
global $wpdb; |
| 27 |
$totalcomments = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = '1'"); |
| 28 |
return $totalcomments; |
| 29 |
} |
| 30 |
|
| 31 |
// Get Total Comments Poster |
| 32 |
function get_totalcommentposters() { |
| 33 |
global $wpdb; |
| 34 |
$totalcommentposters = $wpdb->get_var("SELECT COUNT(DISTINCT comment_author) FROM $wpdb->comments WHERE comment_approved = '1'"); |
| 35 |
|
| 36 |
return $totalcommentposters; |
| 37 |
} |
| 38 |
|
| 39 |
// Get Total Links |
| 40 |
function get_totallinks() { |
| 41 |
global $wpdb; |
| 42 |
$totallinks = $wpdb->get_var("SELECT COUNT(link_id) FROM $wpdb->links"); |
| 43 |
|
| 44 |
return $totallinks; |
| 45 |
} |
| 46 |
|
| 47 |
// Get Recent Posts |
| 48 |
function get_recentposts($limit = 10) { |
| 49 |
global $wpdb, $post; |
| 50 |
$recentposts = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_date, user_nickname FROM $wpdb->posts LEFT JOIN $wpdb->users ON $wpdb->users.ID = $wpdb->posts.post_author WHERE post_date_gmt < '".gmdate("Y-m-d H:i:s")."' AND post_status = 'publish' AND post_password = '' ORDER BY post_date DESC LIMIT $limit"); |
| 51 |
foreach ($recentposts as $post) { |
| 52 |
$post_title = htmlspecialchars(stripslashes($post->post_title)); |
| 53 |
$post_date = mysql2date('d.m.Y', $post->post_date); |
| 54 |
$user_nickname = htmlspecialchars(stripslashes($post->user_nickname)); |
| 55 |
echo "<li>$post_date - <a href=\"".get_permalink()."\">$post_title</a> ($user_nickname)</li>"; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
// Get Recent Comments |
| 60 |
function get_recentcomments($limit = 10) { |
| 61 |
global $wpdb, $post; |
| 62 |
$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_gmt < '".gmdate("Y-m-d H:i:s")."' AND post_status = 'publish' AND post_password = '' ORDER BY comment_date DESC LIMIT $limit"); |
| 63 |
foreach ($recentcomments as $post) { |
| 64 |
$post_title = htmlspecialchars(stripslashes($post->post_title)); |
| 65 |
$comment_author = htmlspecialchars(stripslashes($post->comment_author)); |
| 66 |
$comment_date = mysql2date('d.m.Y @ H:i', $post->comment_date); |
| 67 |
echo "<li>$comment_date - $comment_author (<a href=\"".get_permalink()."\">$post_title</a>)</li>"; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
// Get Top Commented Posts |
| 72 |
function get_mostcommented($limit = 10) { |
| 73 |
global $wpdb, $post; |
| 74 |
$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_gmt < '".gmdate("Y-m-d H:i:s")."' AND post_status = 'publish' AND post_password = '' GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_total DESC LIMIT $limit"); |
| 75 |
foreach ($mostcommenteds as $post) { |
| 76 |
$post_title = htmlspecialchars(stripslashes($post->post_title)); |
| 77 |
$comment_total = (int) $post->comment_total; |
| 78 |
echo "<li><a href=\"".get_permalink()."\">$post_title</a> - $comment_total comments</li>"; |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
// Get Comments' Members Stats |
| 83 |
// Treshhold = Number Of Posts User Must Have Before It Will Display His Name Out |
| 84 |
// 5 = Default Treshhold; -1 = Disable Treshhold |
| 85 |
function get_commentmembersstats($threshhold = 5) { |
| 86 |
global $wpdb; |
| 87 |
$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"); |
| 88 |
foreach ($comments as $comment) { |
| 89 |
$comment_author = htmlspecialchars(stripslashes($comment->comment_author)); |
| 90 |
$comment_total = (int) $comment->comment_total; |
| 91 |
echo "<li><a href=\"wp-stats.php?author=$comment_author\">$comment_author</a> ($comment_total)</li>"; |
| 92 |
// If Total Comments Is Below Threshold |
| 93 |
if($comment_total <= $threshhold && $threshhold != -1) { |
| 94 |
return; |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
// Get Links Categories Stats |
| 100 |
function get_linkcats() { |
| 101 |
global $wpdb; |
| 102 |
$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 "); |
| 103 |
foreach ($linkcats as $linkcat) { |
| 104 |
$cat_name = htmlspecialchars(stripslashes($linkcat->cat_name)); |
| 105 |
$total_links = intval($linkcat->total_links); |
| 106 |
echo "<li>$cat_name ($total_links)</li>\n"; |
| 107 |
} |
| 108 |
} |
| 109 |
?> |
| 110 |
<?php get_header(); ?> |
| 111 |
<div id="content" class="narrowcolumn"> |
| 112 |
<?php |
| 113 |
// If Author Is Not Specified |
| 114 |
if(empty($comment_author)) { |
| 115 |
?> |
| 116 |
<h2 class="pagetitle">General Stats</h2> |
| 117 |
<ul> |
| 118 |
<li><b><?=get_totalposts()?></b> Posts Were Posted</li> |
| 119 |
<li><b><?=get_totalcomments()?></b> Comments Were Posted</li> |
| 120 |
<li><b><?=get_totalcommentposters()?></b> Different Nicks Were Represented In The Comments</li> |
| 121 |
<li><b><?=get_totallinks()?></b> Links Where Added</li> |
| 122 |
</ul> |
| 123 |
<h2 class="pagetitle">10 Recent Posts</h2> |
| 124 |
<ul><?php get_recentposts(); ?></ul> |
| 125 |
<h2 class="pagetitle">10 Recent Comments</h2> |
| 126 |
<ul><?php get_recentcomments(); ?></ul> |
| 127 |
<h2 class="pagetitle">10 Most Commented Post</h2> |
| 128 |
<ul><?php get_mostcommented(); ?></ul> |
| 129 |
<h2 class="pagetitle">Comments' Members Stats</h2> |
| 130 |
<ol><?php get_commentmembersstats(); ?></ol> |
| 131 |
<h2 class="pagetitle">Post Categories Stats</h2> |
| 132 |
<ul><?php list_cats(1,'All','name','asc','',true,0,1,0,1,true,0,0,0,'','','',true); ?></ul> |
| 133 |
<h2 class="pagetitle">Link Categories Stats</h2> |
| 134 |
<ul><?php get_linkcats(); ?></ul> |
| 135 |
<?php |
| 136 |
// Displaying Comments Posted By User |
| 137 |
} else { |
| 138 |
// Number Of Comments Per Page |
| 139 |
$perpage = 10; |
| 140 |
// Comment Author Link |
| 141 |
$comment_author_link = urlencode($comment_author); |
| 142 |
// Total Comments Posted By User |
| 143 |
$totalcomments = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_author='$comment_author'"); |
| 144 |
// Checking $page and $offset |
| 145 |
if (empty($page) || $page == 0) { $page = 1; } |
| 146 |
if (empty($offset)) { $offset = 0; } |
| 147 |
// Determin $offset |
| 148 |
$offset = ($page-1) * $perpage; |
| 149 |
// Some Comments Stats |
| 150 |
if(($offset + $perpage) > $totalcomments) { $maxonpage = $totalcomments ; } else { $maxonpage = ($offset+$perpage); } |
| 151 |
if (($offset + 1) > ($totalcomments)) { $displayonpage = $totalcomments ; } else { $displayonpage = ($offset+1); } |
| 152 |
// Count Total Pages |
| 153 |
$totalpages = ceil($totalcomments/$perpage); |
| 154 |
// Getting The Comments |
| 155 |
$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_gmt < '".gmdate("Y-m-d H:i:s")."' AND post_status = 'publish' ORDER BY comment_post_ID DESC, comment_date DESC LIMIT $offset, $perpage"); |
| 156 |
?> |
| 157 |
<h2 class="pagetitle">Comments Posted By <?=$comment_author?></h2> |
| 158 |
<p>Displaying <b><?=$displayonpage?></b> To <b><?=$maxonpage?></b> Of <b><?=$totalcomments?></b> Comments</p> |
| 159 |
<?php |
| 160 |
foreach($gmz_comments as $post) { |
| 161 |
$comment_id = intval($post-> comment_ID); |
| 162 |
$comment_author2 = htmlspecialchars(stripslashes($post->comment_author)); |
| 163 |
$comment_date = mysql2date('d.m.Y @ H:i', $post->comment_date); |
| 164 |
$comment_content = wpautop(stripslashes($post->comment_content)); |
| 165 |
$post_date = mysql2date('d.m.Y @ H:i', $post->post_date); |
| 166 |
$post_title = htmlspecialchars(stripslashes($post->post_title)); |
| 167 |
|
| 168 |
// If New Title, Print It Out |
| 169 |
if($post_title != $cache_post_title) { |
| 170 |
echo "<p><b><a href=\"".get_permalink()."\" title=\"Posted On $post_date\">$post_title</a></b></p>"; |
| 171 |
} |
| 172 |
echo "<blockquote>$comment_content <a href=\"".get_permalink()."#comment-$comment_id\">Comment</a> Posted By <b>$comment_author2</b> On $comment_date</blockquote>"; |
| 173 |
|
| 174 |
$cache_post_title = $post_title; |
| 175 |
} |
| 176 |
?> |
| 177 |
<table width="100%" cellspacing="0" cellpadding="0" border="0"> |
| 178 |
<tr> |
| 179 |
<td align="left" width="50%"> |
| 180 |
<br /> |
| 181 |
<?php |
| 182 |
if($page > 1 && ((($page*$perpage)-($perpage-1)) < $totalcomments)) |
| 183 |
echo '<p><b>«</b> <a href="wp-stats.php?author='.$comment_author_link.'&page='.($page-1).'">Previous Page</a></p>'; |
| 184 |
else |
| 185 |
echo '<p> </p>'; |
| 186 |
?> |
| 187 |
</td> |
| 188 |
<td align="right" width="50%"> |
| 189 |
<br /> |
| 190 |
<?php |
| 191 |
if($page >= 1 && ((($page*$perpage)+1) < $totalcomments)) |
| 192 |
echo '<p><a href="wp-stats.php?author='.$comment_author_link.'&page='.($page+1).'">Next page</a> <b>»</b></p>'; |
| 193 |
else |
| 194 |
echo '<p> </p>'; |
| 195 |
?> |
| 196 |
</td> |
| 197 |
</tr> |
| 198 |
<tr> |
| 199 |
<td colspan="2" align="center"> |
| 200 |
<br /> |
| 201 |
<p>Pages (<?=$totalpages?>) : |
| 202 |
<?php |
| 203 |
if ($page >= 4) { |
| 204 |
echo "<a href=\"wp-stats.php?author=$comment_author_link\">« First</a> ... "; |
| 205 |
} |
| 206 |
if($page > 1) { |
| 207 |
echo " <a href=\"wp-stats.php?author=$comment_author_link&page=".($page-1)."\">«</a> "; |
| 208 |
} |
| 209 |
for($i = $page - 2 ; $i <= $page +2; $i++) { |
| 210 |
if ($i >= 1 && $i <= $totalpages) { |
| 211 |
if($i == $page) { |
| 212 |
echo "[$i]"; |
| 213 |
} else { |
| 214 |
echo "<a href=\"wp-stats.php?author=$comment_author_link&page=$i\">$i</a> "; |
| 215 |
} |
| 216 |
} |
| 217 |
} |
| 218 |
if($page < $totalpages) { |
| 219 |
echo " <a href=\"wp-stats.php?author=$comment_author_link&page=".($page+1)."\">»</a> "; |
| 220 |
} |
| 221 |
if (($page+2) < $totalpages) { |
| 222 |
echo " ... <a href=\"wp-stats.php?author=$comment_author_link&page=$totalpages\">Last »</a>"; |
| 223 |
} |
| 224 |
?> |
| 225 |
</p> |
| 226 |
</td> |
| 227 |
</tr> |
| 228 |
</table> |
| 229 |
<p><b>««</b> <a href="wp-stats.php">Back To Stats Page</a></p> |
| 230 |
<?php |
| 231 |
} // End If |
| 232 |
?> |
| 233 |
</div> |
| 234 |
<?php |
| 235 |
get_sidebar(); |
| 236 |
get_footer(); |
| 237 |
?> |