| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: WP-Stats |
| 4 |
Plugin URI: http://www.lesterchan.net/portfolio/programming.php |
| 5 |
Description: Display Your WordPress Statistics. |
| 6 |
Version: 2.03 |
| 7 |
Author: GaMerZ |
| 8 |
Author URI: http://www.lesterchan.net |
| 9 |
*/ |
| 10 |
|
| 11 |
|
| 12 |
/* Copyright 2006 Lester Chan (email : gamerz84@hotmail.com) |
| 13 |
|
| 14 |
This program is free software; you can redistribute it and/or modify |
| 15 |
it under the terms of the GNU General Public License as published by |
| 16 |
the Free Software Foundation; either version 2 of the License, or |
| 17 |
(at your option) any later version. |
| 18 |
|
| 19 |
This program is distributed in the hope that it will be useful, |
| 20 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
GNU General Public License for more details. |
| 23 |
|
| 24 |
You should have received a copy of the GNU General Public License |
| 25 |
along with this program; if not, write to the Free Software |
| 26 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 27 |
*/ |
| 28 |
|
| 29 |
|
| 30 |
### Function: WP-Stats Menu |
| 31 |
add_action('admin_menu', 'stats_menu'); |
| 32 |
function stats_menu() { |
| 33 |
if (function_exists('add_submenu_page')) { |
| 34 |
add_submenu_page('index.php', __('WP-Stats'), __('WP-Stats'), 1, 'stats.php', 'display_stats'); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
### Display WP-Stats Admin Page |
| 40 |
function display_stats() { |
| 41 |
?> |
| 42 |
<!-- General Stats --> |
| 43 |
<div class="wrap"> |
| 44 |
<h2>General Stats</h2> |
| 45 |
<ul> |
| 46 |
<li><b><?php get_totalauthors(); ?></b> Authors To This Blog.</li> |
| 47 |
<li><b><?php get_totalposts(); ?></b> Posts Were Posted.</li> |
| 48 |
<li><b><?php get_totalpages(); ?></b> Pages Were Created.</li> |
| 49 |
<li><b><?php get_totalcomments(); ?></b> Comments Were Posted.</li> |
| 50 |
<li><b><?php get_totalcommentposters(); ?></b> Different Nicks Were Represented In The Comments.</li> |
| 51 |
<li><b><?php get_totallinks(); ?></b> Links Were Added.</li> |
| 52 |
</ul> |
| 53 |
</div> |
| 54 |
|
| 55 |
<!-- Plugin Stats --> |
| 56 |
<div class="wrap"> |
| 57 |
<h2>Plugins Stats</h2> |
| 58 |
<ul> |
| 59 |
<!-- WP-EMail Stats --> |
| 60 |
<?php if(function_exists('wp_email')): ?> |
| 61 |
<li><b>WP-EMail</b></li> |
| 62 |
<ul> |
| 63 |
<li><b><?php get_emails(); ?></b> Emails Were Sent.</li> |
| 64 |
<li><b><?php get_emails_success(); ?></b> Emails Were Sent Successfully.</li> |
| 65 |
<li><b><?php get_emails_failed(); ?></b> Emails Failed To Send.</li> |
| 66 |
</ul> |
| 67 |
<br /> |
| 68 |
<?php endif; ?> |
| 69 |
<!-- WP-Polls Stats --> |
| 70 |
<?php if(function_exists('get_poll')): ?> |
| 71 |
<li><b>WP-Polls</b></li> |
| 72 |
<ul> |
| 73 |
<li><b><?php get_pollquestions(); ?></b> Polls Were Created.</li> |
| 74 |
<li><b><?php get_pollanswers(); ?></b> Polls' Answers Were Given.</li> |
| 75 |
<li><b><?php get_pollvotes(); ?></b> Votes Were Casted.</li> |
| 76 |
</ul> |
| 77 |
<br /> |
| 78 |
<?php endif; ?> |
| 79 |
<!-- WP-PostRatings Stats --> |
| 80 |
<?php if(function_exists('the_ratings')): ?> |
| 81 |
<li><b>WP-PostRatings</b></li> |
| 82 |
<ul> |
| 83 |
<li><b><?php get_ratings_votes(); ?></b> Votes Were Casted.</li> |
| 84 |
<li><b><?php get_ratings_users(); ?></b> Users Casted Their Vote.</li> |
| 85 |
</ul> |
| 86 |
<br /> |
| 87 |
<?php endif; ?> |
| 88 |
<!-- WP-PostViews Stats --> |
| 89 |
<?php if(function_exists('the_views')): ?> |
| 90 |
<li><b>WP-PostViews</b></li> |
| 91 |
<ul> |
| 92 |
<li><b><?php get_totalviews(); ?></b> Views Were Generated.</li> |
| 93 |
</ul> |
| 94 |
<br /> |
| 95 |
<?php endif; ?> |
| 96 |
<!-- WP-UserOnline Stats --> |
| 97 |
<?php if(function_exists('useronline')): ?> |
| 98 |
<li><b>WP-UserOnline</b></li> |
| 99 |
<ul> |
| 100 |
<li><?php get_useronline(); ?> Now.</li> |
| 101 |
<li>Most users ever online was <b><?php get_most_useronline(); ?></b>.</li> |
| 102 |
<li>On <b><?php get_most_useronline_date(); ?></b>.</li> |
| 103 |
</ul> |
| 104 |
<br /> |
| 105 |
<?php endif; ?> |
| 106 |
</ul> |
| 107 |
</div> |
| 108 |
|
| 109 |
<!-- Top 10 Stats--> |
| 110 |
<div class="wrap"> |
| 111 |
<h2>Top 10 Stats</h2> |
| 112 |
<ul> |
| 113 |
<!-- 10 Recent Posts --> |
| 114 |
<li><b>10 Recent Posts</b></li> |
| 115 |
<ul> |
| 116 |
<?php get_recentposts(); ?> |
| 117 |
</ul> |
| 118 |
<br /> |
| 119 |
<!-- 10 Recent Comments --> |
| 120 |
<li><b>10 Recent Comments</b></li> |
| 121 |
<ul> |
| 122 |
<?php get_recentcomments(); ?> |
| 123 |
</ul> |
| 124 |
<br /> |
| 125 |
<!-- 10 Most Commented Post --> |
| 126 |
<li><b>10 Most Commented Post</b></li> |
| 127 |
<ul> |
| 128 |
<?php get_mostcommented(); ?> |
| 129 |
</ul> |
| 130 |
<br /> |
| 131 |
<!-- WP-EMail (10 Most EMailed Post) --> |
| 132 |
<?php if(function_exists('wp_email')): ?> |
| 133 |
<li><b>10 Most Emailed Post</b></li> |
| 134 |
<ul> |
| 135 |
<?php get_mostemailed(); ?> |
| 136 |
</ul> |
| 137 |
<br /> |
| 138 |
<?php endif; ?> |
| 139 |
<!-- WP-PostRatings (10 Most Rated Post) --> |
| 140 |
<?php if(function_exists('the_ratings')): ?> |
| 141 |
<li><b>10 Most Rated Post</b></li> |
| 142 |
<ul> |
| 143 |
<?php get_highest_rated(); ?> |
| 144 |
</ul> |
| 145 |
<br /> |
| 146 |
<?php endif; ?> |
| 147 |
<!-- WP-PostViews (10 Most Viewed Post) --> |
| 148 |
<?php if(function_exists('the_views')): ?> |
| 149 |
<li><b>10 Most Viewed Post</b></li> |
| 150 |
<ul><?php get_most_viewed(); ?></ul> |
| 151 |
<br /> |
| 152 |
<?php endif; ?> |
| 153 |
</ul> |
| 154 |
</div> |
| 155 |
|
| 156 |
<!-- Author Stats --> |
| 157 |
<div class="wrap"> |
| 158 |
<h2>Authors Stats</h2> |
| 159 |
<ol> |
| 160 |
<?php get_authorsstats(); ?> |
| 161 |
</ol> |
| 162 |
</div> |
| 163 |
|
| 164 |
<!-- Comments' Members Stats --> |
| 165 |
<div class="wrap"> |
| 166 |
<h2>Comments' Members Stats</h2> |
| 167 |
<ol> |
| 168 |
<?php get_commentmembersstats(); ?> |
| 169 |
</ol> |
| 170 |
</div> |
| 171 |
|
| 172 |
<!-- Misc Stats --> |
| 173 |
<div class="wrap"> |
| 174 |
<h2>Misc Stats</h2> |
| 175 |
<ul> |
| 176 |
<!-- Post Categories --> |
| 177 |
<li><b>Post Categories</b></li> |
| 178 |
<ul> |
| 179 |
<?php list_cats(1,'All','name','asc','',true,0,1,0,1,true,0,0,0,'','','',true); ?> |
| 180 |
</ul> |
| 181 |
<br /> |
| 182 |
<!-- Link Categories --> |
| 183 |
<li><b>Link Categories</b></li> |
| 184 |
<ul> |
| 185 |
<?php get_linkcats(); ?> |
| 186 |
</ul> |
| 187 |
</ul> |
| 188 |
</div> |
| 189 |
<?php |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
### Function: Get Total Authors |
| 194 |
function get_totalauthors() { |
| 195 |
global $wpdb; |
| 196 |
$totalauthors = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users WHERE user_activation_key = ''"); |
| 197 |
echo number_format($totalauthors); |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
### Function: Get Total Posts |
| 202 |
function get_totalposts() { |
| 203 |
global $wpdb; |
| 204 |
$totalposts = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_status = 'publish'"); |
| 205 |
echo number_format($totalposts); |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
### Function: Get Total Pages |
| 210 |
function get_totalpages() { |
| 211 |
global $wpdb; |
| 212 |
$totalpages = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_status = 'static'"); |
| 213 |
echo number_format($totalpages); |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
### Function: Get Total Comments |
| 218 |
function get_totalcomments() { |
| 219 |
global $wpdb; |
| 220 |
$totalcomments = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = '1'"); |
| 221 |
echo number_format($totalcomments); |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
### Function: Get Total Comments Poster |
| 226 |
function get_totalcommentposters() { |
| 227 |
global $wpdb; |
| 228 |
$totalcommentposters = $wpdb->get_var("SELECT COUNT(DISTINCT comment_author) FROM $wpdb->comments WHERE comment_approved = '1'"); |
| 229 |
echo number_format($totalcommentposters); |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
### Function: Get Total Links |
| 234 |
function get_totallinks() { |
| 235 |
global $wpdb; |
| 236 |
$totallinks = $wpdb->get_var("SELECT COUNT(link_id) FROM $wpdb->links"); |
| 237 |
echo number_format($totallinks); |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
### Function: Get Recent Posts |
| 242 |
function get_recentposts($mode = '', $limit = 10) { |
| 243 |
global $wpdb, $post; |
| 244 |
$where = ''; |
| 245 |
if($mode == 'post') { |
| 246 |
$where = 'post_status = \'publish\''; |
| 247 |
} elseif($mode == 'page') { |
| 248 |
$where = 'post_status = \'static\''; |
| 249 |
} else { |
| 250 |
$where = '(post_status = \'publish\' OR post_status = \'static\')'; |
| 251 |
} |
| 252 |
$recentposts = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_status, post_date, user_login, display_name FROM $wpdb->posts LEFT JOIN $wpdb->users ON $wpdb->users.ID = $wpdb->posts.post_author WHERE post_date < '".current_time('mysql')."' AND $where AND post_password = '' ORDER BY post_date DESC LIMIT $limit"); |
| 253 |
if($recentposts) { |
| 254 |
foreach ($recentposts as $post) { |
| 255 |
$post_title = htmlspecialchars(stripslashes($post->post_title)); |
| 256 |
$post_date = mysql2date('d.m.Y', $post->post_date); |
| 257 |
$display_name = htmlspecialchars(stripslashes($post->display_name)); |
| 258 |
echo "<li>$post_date - <a href=\"".get_permalink()."\">$post_title</a> ($display_name)</li>"; |
| 259 |
} |
| 260 |
} else { |
| 261 |
echo '<li>'.__('N/A').'</li>'; |
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
### Function: Get Recent Comments |
| 267 |
function get_recentcomments($mode = '', $limit = 10) { |
| 268 |
global $wpdb, $post; |
| 269 |
$where = ''; |
| 270 |
if($mode == 'post') { |
| 271 |
$where = 'post_status = \'publish\''; |
| 272 |
} elseif($mode == 'page') { |
| 273 |
$where = 'post_status = \'static\''; |
| 274 |
} else { |
| 275 |
$where = '(post_status = \'publish\' OR post_status = \'static\')'; |
| 276 |
} |
| 277 |
$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 $where AND post_password = '' ORDER BY comment_date DESC LIMIT $limit"); |
| 278 |
if($recentcomments) { |
| 279 |
foreach ($recentcomments as $post) { |
| 280 |
$post_title = htmlspecialchars(stripslashes($post->post_title)); |
| 281 |
$comment_author = htmlspecialchars(stripslashes($post->comment_author)); |
| 282 |
$comment_date = mysql2date('d.m.Y @ H:i', $post->comment_date); |
| 283 |
echo "<li>$comment_date - $comment_author (<a href=\"".get_permalink()."\">$post_title</a>)</li>"; |
| 284 |
} |
| 285 |
} else { |
| 286 |
echo '<li>'.__('N/A').'</li>'; |
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
### Function: Get Top Commented Posts |
| 292 |
function get_mostcommented($mode = '', $limit = 10) { |
| 293 |
global $wpdb, $post; |
| 294 |
$where = ''; |
| 295 |
if($mode == 'post') { |
| 296 |
$where = 'post_status = \'publish\''; |
| 297 |
} elseif($mode == 'page') { |
| 298 |
$where = 'post_status = \'static\''; |
| 299 |
} else { |
| 300 |
$where = '(post_status = \'publish\' OR post_status = \'static\')'; |
| 301 |
} |
| 302 |
$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 $where AND post_password = '' GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_total DESC LIMIT $limit"); |
| 303 |
if($mostcommenteds) { |
| 304 |
foreach ($mostcommenteds as $post) { |
| 305 |
$post_title = htmlspecialchars(stripslashes($post->post_title)); |
| 306 |
$comment_total = intval($post->comment_total); |
| 307 |
echo "<li><a href=\"".get_permalink()."\">$post_title</a> - $comment_total ".__('comments')."</li>"; |
| 308 |
} |
| 309 |
} else { |
| 310 |
echo '<li>'.__('N/A').'</li>'; |
| 311 |
} |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
### Function: Get Author Stats |
| 316 |
function get_authorsstats() { |
| 317 |
global $wpdb, $wp_rewrite; |
| 318 |
$where = ''; |
| 319 |
if($mode == 'post') { |
| 320 |
$where = 'post_status = \'publish\''; |
| 321 |
} elseif($mode == 'page') { |
| 322 |
$where = 'post_status = \'static\''; |
| 323 |
} else { |
| 324 |
$where = '(post_status = \'publish\' OR post_status = \'static\')'; |
| 325 |
} |
| 326 |
$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 AND user_activation_key = '' AND $where GROUP BY $wpdb->posts.post_author"); |
| 327 |
if($posts) { |
| 328 |
$using_permalink = get_settings('permalink_structure'); |
| 329 |
$permalink = $wp_rewrite->get_author_permastruct(); |
| 330 |
foreach ($posts as $post) { |
| 331 |
$author_link = str_replace('%author%', strip_tags(stripslashes($post->user_nicename)), $permalink); |
| 332 |
$display_name = urlencode($post->display_name); |
| 333 |
$posts_total = intval($post->posts_total); |
| 334 |
if($using_permalink) { |
| 335 |
echo "<li><a href=\"".get_settings('siteurl').$author_link."\">$display_name</a> ($posts_total)</li>"; |
| 336 |
} else { |
| 337 |
echo "<li><a href=\"".get_settings('siteurl')."/?author_name=$post_author\">$display_name</a> ($posts_total)</li>"; |
| 338 |
} |
| 339 |
} |
| 340 |
} else { |
| 341 |
echo '<li>'.__('N/A').'</li>'; |
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
|
| 346 |
### Function: Get Comments' Members Stats |
| 347 |
// Treshhold = Number Of Posts User Must Have Before It Will Display His Name Out |
| 348 |
// 5 = Default Treshhold; -1 = Disable Treshhold |
| 349 |
function get_commentmembersstats($threshhold = -1) { |
| 350 |
global $wpdb; |
| 351 |
$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"); |
| 352 |
if($comments) { |
| 353 |
foreach ($comments as $comment) { |
| 354 |
$comment_author = strip_tags(stripslashes($comment->comment_author)); |
| 355 |
$comment_author_link = urlencode($comment_author); |
| 356 |
$comment_total = intval($comment->comment_total); |
| 357 |
echo "<li><a href=\"".get_settings('siteurl')."/wp-stats.php?author=$comment_author_link\">$comment_author</a> ($comment_total)</li>"; |
| 358 |
// If Total Comments Is Below Threshold |
| 359 |
if($comment_total <= $threshhold && $threshhold != -1) { |
| 360 |
return; |
| 361 |
} |
| 362 |
} |
| 363 |
} else { |
| 364 |
echo '<li>'.__('N/A').'</li>'; |
| 365 |
} |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
### Function: Get Links Categories Stats |
| 370 |
function get_linkcats() { |
| 371 |
global $wpdb; |
| 372 |
$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 "); |
| 373 |
if($linkcats) { |
| 374 |
foreach ($linkcats as $linkcat) { |
| 375 |
$cat_name = htmlspecialchars(stripslashes($linkcat->cat_name)); |
| 376 |
$total_links = intval($linkcat->total_links); |
| 377 |
echo "<li>$cat_name ($total_links)</li>\n"; |
| 378 |
} |
| 379 |
} else { |
| 380 |
echo '<li>'.__('N/A').'</li>'; |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
### Function: Get Poll Total Questions |
| 386 |
if(!function_exists('get_pollquestions')) { |
| 387 |
function get_pollquestions() { |
| 388 |
global $wpdb; |
| 389 |
$totalpollq = $wpdb->get_var("SELECT COUNT(pollq_id) FROM $wpdb->pollsq"); |
| 390 |
echo number_format($totalpollq); |
| 391 |
} |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
### Function: Get Poll Total Answers |
| 396 |
if(!function_exists('get_pollanswers')) { |
| 397 |
function get_pollanswers() { |
| 398 |
global $wpdb; |
| 399 |
$totalpolla = $wpdb->get_var("SELECT COUNT(polla_aid) FROM $wpdb->pollsa"); |
| 400 |
echo number_format($totalpolla); |
| 401 |
} |
| 402 |
} |
| 403 |
|
| 404 |
|
| 405 |
### Function: Get Poll Total Votes |
| 406 |
if(!function_exists('get_pollvotes')) { |
| 407 |
function get_pollvotes() { |
| 408 |
global $wpdb; |
| 409 |
$totalpollip = $wpdb->get_var("SELECT COUNT(pollip_id) FROM $wpdb->pollsip"); |
| 410 |
echo number_format($totalpollip); |
| 411 |
} |
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
### Function: Get EMail Total Sent |
| 416 |
if(!function_exists('get_emails')) { |
| 417 |
function get_emails() { |
| 418 |
global $wpdb; |
| 419 |
$totalemails = $wpdb->get_var("SELECT COUNT(email_id) FROM $wpdb->email"); |
| 420 |
echo number_format($totalemails); |
| 421 |
} |
| 422 |
} |
| 423 |
|
| 424 |
|
| 425 |
### Function: Get EMail Total Sent Success |
| 426 |
if(!function_exists('get_emails_success')) { |
| 427 |
function get_emails_success() { |
| 428 |
global $wpdb; |
| 429 |
$totalemails_success = $wpdb->get_var("SELECT COUNT(email_id) FROM $wpdb->email WHERE email_status = '".__('Success')."'"); |
| 430 |
echo number_format($totalemails_success); |
| 431 |
} |
| 432 |
} |
| 433 |
|
| 434 |
|
| 435 |
### Function: Get EMail Total Sent Failed |
| 436 |
if(!function_exists('get_emails_failed')) { |
| 437 |
function get_emails_failed() { |
| 438 |
global $wpdb; |
| 439 |
$totalemails_failed = $wpdb->get_var("SELECT COUNT(email_id) FROM $wpdb->email WHERE email_status = '". __('Failed')."'"); |
| 440 |
echo number_format($totalemails_failed); |
| 441 |
} |
| 442 |
} |
| 443 |
|
| 444 |
|
| 445 |
### Function: Get Most Emailed Post |
| 446 |
if(!function_exists('get_mostemailed')) { |
| 447 |
function get_mostemailed($mode = '', $limit = 10) { |
| 448 |
global $wpdb, $post; |
| 449 |
$where = ''; |
| 450 |
if($mode == 'post') { |
| 451 |
$where = 'post_status = \'publish\''; |
| 452 |
} elseif($mode == 'page') { |
| 453 |
$where = 'post_status = \'static\''; |
| 454 |
} else { |
| 455 |
$where = '(post_status = \'publish\' OR post_status = \'static\')'; |
| 456 |
} |
| 457 |
$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 $where AND post_password = '' GROUP BY $wpdb->email.email_postid ORDER BY email_total DESC LIMIT $limit"); |
| 458 |
if($mostemailed) { |
| 459 |
foreach ($mostemailed as $post) { |
| 460 |
$post_title = htmlspecialchars(stripslashes($post->post_title)); |
| 461 |
$email_total = intval($post->email_total); |
| 462 |
echo "<li><a href=\"".get_permalink()."\">$post_title</a> - $email_total ".__('Emails')."</li>"; |
| 463 |
} |
| 464 |
} else { |
| 465 |
echo '<li>'.__('N/A').'</li>'; |
| 466 |
} |
| 467 |
} |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
### Function: Display Most Viewed Page/Post |
| 472 |
if(!function_exists('get_most_viewed')) { |
| 473 |
function get_most_viewed($mode = '', $limit = 10) { |
| 474 |
global $wpdb, $post; |
| 475 |
$where = ''; |
| 476 |
if($mode == 'post') { |
| 477 |
$where = 'post_status = \'publish\''; |
| 478 |
} elseif($mode == 'page') { |
| 479 |
$where = 'post_status = \'static\''; |
| 480 |
} else { |
| 481 |
$where = '(post_status = \'publish\' OR post_status = \'static\')'; |
| 482 |
} |
| 483 |
$most_viewed = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_status, post_date, CAST(meta_value AS UNSIGNED) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND $where AND meta_key = 'views' AND post_password = '' ORDER BY views DESC LIMIT $limit"); |
| 484 |
if($most_viewed) { |
| 485 |
foreach ($most_viewed as $post) { |
| 486 |
$post_title = htmlspecialchars(stripslashes($post->post_title)); |
| 487 |
$post_views = intval($post->views); |
| 488 |
echo "<li><a href=\"".get_permalink()."\">$post_title</a> ($post_views ".__('Views').")</li>"; |
| 489 |
} |
| 490 |
} else { |
| 491 |
echo '<li>'.__('N/A').'</li>'; |
| 492 |
} |
| 493 |
} |
| 494 |
} |
| 495 |
|
| 496 |
|
| 497 |
### Function: Display Total Views |
| 498 |
if(!function_exists('get_totalviews')) { |
| 499 |
function get_totalviews() { |
| 500 |
global $wpdb; |
| 501 |
$total_views = $wpdb->get_var("SELECT SUM(CAST(meta_value AS UNSIGNED)) FROM $wpdb->postmeta WHERE meta_key = 'views'"); |
| 502 |
echo number_format($total_views); |
| 503 |
} |
| 504 |
} |
| 505 |
|
| 506 |
|
| 507 |
### Function: Display Total Rating Votes |
| 508 |
if(!function_exists('get_ratings_votes')) { |
| 509 |
function get_ratings_votes() { |
| 510 |
global $wpdb; |
| 511 |
$ratings_votes = $wpdb->get_var("SELECT SUM(CAST(meta_value AS UNSIGNED)) FROM $wpdb->postmeta WHERE meta_key = 'ratings_score'"); |
| 512 |
echo number_format($ratings_votes); |
| 513 |
} |
| 514 |
} |
| 515 |
|
| 516 |
|
| 517 |
### Function: Display Total Rating Users |
| 518 |
if(!function_exists('get_ratings_users')) { |
| 519 |
function get_ratings_users() { |
| 520 |
global $wpdb; |
| 521 |
$ratings_users = $wpdb->get_var("SELECT SUM(CAST(meta_value AS UNSIGNED)) FROM $wpdb->postmeta WHERE meta_key = 'ratings_users'"); |
| 522 |
echo number_format($ratings_users); |
| 523 |
} |
| 524 |
} |
| 525 |
|
| 526 |
|
| 527 |
### Function: Display Most Rated Page/Post |
| 528 |
if(!function_exists('get_most_rated')) { |
| 529 |
function get_most_rated($mode = '', $limit = 10) { |
| 530 |
global $wpdb, $post; |
| 531 |
$where = ''; |
| 532 |
if($mode == 'post') { |
| 533 |
$where = 'post_status = \'publish\''; |
| 534 |
} elseif($mode == 'page') { |
| 535 |
$where = 'post_status = \'static\''; |
| 536 |
} else { |
| 537 |
$where = '(post_status = \'publish\' OR post_status = \'static\')'; |
| 538 |
} |
| 539 |
$most_rated = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_status, post_date, CAST(meta_value AS UNSIGNED) AS votes FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND $where AND meta_key = 'ratings_users' AND post_password = '' ORDER BY votes DESC LIMIT $limit"); |
| 540 |
if($most_rated) { |
| 541 |
foreach ($most_rated as $post) { |
| 542 |
$post_title = htmlspecialchars(stripslashes($post->post_title)); |
| 543 |
$post_views = intval($post->votes); |
| 544 |
echo "<li><a href=\"".get_permalink()."\">$post_title</a> ($post_views ".__('Votes').")</li>"; |
| 545 |
} |
| 546 |
} else { |
| 547 |
echo '<li>'.__('N/A').'</li>'; |
| 548 |
} |
| 549 |
} |
| 550 |
} |
| 551 |
|
| 552 |
|
| 553 |
### Function: Display Highest Rated Page/Post |
| 554 |
if(!function_exists('get_highest_rated')) { |
| 555 |
function get_highest_rated($mode = '', $limit = 10) { |
| 556 |
global $wpdb, $post; |
| 557 |
$where = ''; |
| 558 |
if($mode == 'post') { |
| 559 |
$where = 'post_status = \'publish\''; |
| 560 |
} elseif($mode == 'page') { |
| 561 |
$where = 'post_status = \'static\''; |
| 562 |
} else { |
| 563 |
$where = '(post_status = \'publish\' OR post_status = \'static\')'; |
| 564 |
} |
| 565 |
$most_rated = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_status, post_date, (meta_value+0.00) AS highest FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND $where AND meta_key = 'ratings_average' AND post_password = '' ORDER BY highest DESC LIMIT $limit"); |
| 566 |
if($most_rated) { |
| 567 |
foreach ($most_rated as $post) { |
| 568 |
$post_title = htmlspecialchars(stripslashes($post->post_title)); |
| 569 |
$post_views = $post->highest; |
| 570 |
echo "<li><a href=\"".get_permalink()."\">$post_title</a> ($post_views ".__('Stars').")</li>"; |
| 571 |
} |
| 572 |
} else { |
| 573 |
echo '<li>'.__('N/A').'</li>'; |
| 574 |
} |
| 575 |
} |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
### Function: Display UserOnline |
| 580 |
if(!function_exists('get_useronline')) { |
| 581 |
function get_useronline($user = 'User', $users = 'Users', $display = true) { |
| 582 |
global $useronline; |
| 583 |
// Display User Online |
| 584 |
if($display) { |
| 585 |
if($useronline > 1) { |
| 586 |
echo "<b>".number_format($useronline)."</b> $users ".__('Online'); |
| 587 |
} else { |
| 588 |
echo "<b>$useronline</b> $user ".__('Online'); |
| 589 |
} |
| 590 |
} else { |
| 591 |
return $useronline; |
| 592 |
} |
| 593 |
} |
| 594 |
} |
| 595 |
|
| 596 |
|
| 597 |
### Function: Display Max UserOnline |
| 598 |
if(!function_exists('get_most_useronline')) { |
| 599 |
function get_most_useronline($display = true) { |
| 600 |
$most_useronline_users = intval(get_settings('useronline_most_users')); |
| 601 |
if($display) { |
| 602 |
echo number_format($most_useronline_users); |
| 603 |
} else { |
| 604 |
return $most_useronline_users; |
| 605 |
} |
| 606 |
} |
| 607 |
} |
| 608 |
|
| 609 |
|
| 610 |
### Function: Display Max UserOnline Date |
| 611 |
if(!function_exists('get_most_useronline_date')) { |
| 612 |
function get_most_useronline_date($date_format = 'jS F Y, H:i', $display =true) { |
| 613 |
$most_useronline_timestamp = get_settings('useronline_most_timestamp'); |
| 614 |
$most_useronline_date = gmdate($date_format, $most_useronline_timestamp); |
| 615 |
if($display) { |
| 616 |
echo $most_useronline_date; |
| 617 |
} else { |
| 618 |
return$most_useronline_date; |
| 619 |
} |
| 620 |
} |
| 621 |
} |
| 622 |
?> |