| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: WP-Stats |
| 4 |
Plugin URI: https://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.56 |
| 7 |
Author: Lester 'GaMerZ' Chan |
| 8 |
Author URI: https://lesterchan.net |
| 9 |
Text Domain: wp-stats |
| 10 |
*/ |
| 11 |
|
| 12 |
|
| 13 |
/* |
| 14 |
Copyright 2020 Lester Chan (email : lesterchan@gmail.com) |
| 15 |
|
| 16 |
This program is free software; you can redistribute it and/or modify |
| 17 |
it under the terms of the GNU General Public License as published by |
| 18 |
the Free Software Foundation; either version 2 of the License, or |
| 19 |
(at your option) any later version. |
| 20 |
|
| 21 |
This program is distributed in the hope that it will be useful, |
| 22 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 |
GNU General Public License for more details. |
| 25 |
|
| 26 |
You should have received a copy of the GNU General Public License |
| 27 |
along with this program; if not, write to the Free Software |
| 28 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 29 |
*/ |
| 30 |
|
| 31 |
|
| 32 |
### Create Text Domain For Translations |
| 33 |
add_action( 'plugins_loaded', 'stats_textdomain' ); |
| 34 |
function stats_textdomain() { |
| 35 |
load_plugin_textdomain( 'wp-stats', false, dirname( plugin_basename( __FILE__ ) ) ); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
### Function: WP-Stats Menu |
| 40 |
add_action('admin_menu', 'stats_menu'); |
| 41 |
function stats_menu() { |
| 42 |
add_submenu_page('index.php', __('WP-Stats', 'wp-stats'), __('WP-Stats', 'wp-stats'), 'manage_options', 'wp-stats/wp-stats.php', 'display_stats'); |
| 43 |
add_options_page(__('Stats', 'wp-stats'), __('Stats', 'wp-stats'), 'manage_options', 'wp-stats/stats-options.php'); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
### Function: Enqueue Stats Stylesheets |
| 48 |
add_action('wp_enqueue_script', 'stats_stylesheets'); |
| 49 |
function stats_stylesheets() { |
| 50 |
if(!function_exists('pagenavi_stylesheets')) { |
| 51 |
if(@file_exists(TEMPLATEPATH.'/stats-css.css')) { |
| 52 |
wp_enqueue_style('wp-stats', plugins_url(get_stylesheet_directory_uri().'/stats-css.css'), false, '2.50', 'all'); |
| 53 |
} else { |
| 54 |
wp_enqueue_style('wp-stats', plugins_url('wp-stats/stats-css.css'), false, '2.50', 'all'); |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
### Display WP-Stats Admin Page |
| 61 |
function display_stats() { |
| 62 |
$stats_page = stats_page(); |
| 63 |
echo '<div class="wrap">'; |
| 64 |
echo $stats_page; |
| 65 |
echo '</div>'; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
### Function: Get Total Authors |
| 70 |
function get_totalauthors($display = true) { |
| 71 |
global $wpdb; |
| 72 |
$totalauthors = (int) $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"); |
| 73 |
if($display) { |
| 74 |
echo $totalauthors; |
| 75 |
} else { |
| 76 |
return $totalauthors; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
### Function: Get Total Posts |
| 82 |
function get_totalposts($display = true) { |
| 83 |
global $wpdb; |
| 84 |
$totalposts = (int) $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'"); |
| 85 |
if($display) { |
| 86 |
echo $totalposts; |
| 87 |
} else { |
| 88 |
return $totalposts; |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
### Function: Get Total Pages |
| 94 |
function get_totalpages($display = true) { |
| 95 |
global $wpdb; |
| 96 |
$totalpages = (int) $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish'"); |
| 97 |
if($display) { |
| 98 |
echo $totalpages; |
| 99 |
} else { |
| 100 |
return $totalpages; |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
### Function: Get Total Comments |
| 106 |
function get_totalcomments($display = true) { |
| 107 |
global $wpdb; |
| 108 |
$totalcomments = (int) $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = '1'"); |
| 109 |
if($display) { |
| 110 |
echo $totalcomments; |
| 111 |
} else { |
| 112 |
return $totalcomments; |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
### Function: Get Total Comments Poster |
| 118 |
function get_totalcommentposters($display = true) { |
| 119 |
global $wpdb; |
| 120 |
$totalcommentposters = (int) $wpdb->get_var("SELECT COUNT(DISTINCT comment_author) FROM $wpdb->comments WHERE comment_approved = '1' AND comment_type = 'comment'"); |
| 121 |
if($display) { |
| 122 |
echo $totalcommentposters; |
| 123 |
} else { |
| 124 |
return $totalcommentposters; |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
### Function: Get Total Links |
| 130 |
function get_totallinks($display = true) { |
| 131 |
global $wpdb; |
| 132 |
$totallinks = (int) $wpdb->get_var("SELECT COUNT(link_id) FROM $wpdb->links"); |
| 133 |
if($display) { |
| 134 |
echo $totallinks; |
| 135 |
} else { |
| 136 |
return $totallinks; |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
### Function: Get Recent Posts |
| 142 |
function get_recentposts($mode = '', $limit = 10, $display = true) { |
| 143 |
global $wpdb, $post; |
| 144 |
$temp = ''; |
| 145 |
if(!empty($mode) && $mode !== 'both') { |
| 146 |
$where = "post_type = '$mode'"; |
| 147 |
} else { |
| 148 |
$where = '1=1'; |
| 149 |
} |
| 150 |
$recentposts = $wpdb->get_results("SELECT $wpdb->users.*, $wpdb->posts.* 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"); |
| 151 |
if($recentposts) { |
| 152 |
foreach ($recentposts as $post) { |
| 153 |
$post_title = get_the_title(); |
| 154 |
$post_date = get_the_time(sprintf(__('%s @ %s', 'wp-stats'), get_option('date_format'), get_option('time_format'))); |
| 155 |
$display_name = stripslashes($post->display_name); |
| 156 |
$temp .= "<li>$post_date - <a href=\"".get_permalink()."\" title=\"".sprintf(__('View post %s', 'wp-stats'), $post_title)."\">$post_title</a> ($display_name)</li>\n"; |
| 157 |
} |
| 158 |
} else { |
| 159 |
$temp = '<li>'.__('N/A', 'wp-stats').'</li>'; |
| 160 |
} |
| 161 |
if($display) { |
| 162 |
echo $temp; |
| 163 |
} else { |
| 164 |
return $temp; |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
### Function: Get Recent Comments |
| 170 |
function get_recentcomments($mode = '', $limit = 10, $display = true) { |
| 171 |
global $wpdb, $post; |
| 172 |
$temp = ''; |
| 173 |
if(!empty($mode) && $mode !== 'both') { |
| 174 |
$where = "post_type = '$mode'"; |
| 175 |
} else { |
| 176 |
$where = '1=1'; |
| 177 |
} |
| 178 |
$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 = 'comment' AND post_date < '".current_time('mysql')."' AND $where AND post_status = 'publish' AND post_password = '' ORDER BY comment_date DESC LIMIT $limit"); |
| 179 |
if($recentcomments) { |
| 180 |
foreach ($recentcomments as $post) { |
| 181 |
$post_title = get_the_title(); |
| 182 |
$comment_author = htmlspecialchars(stripslashes($post->comment_author)); |
| 183 |
$comment_date = mysql2date(sprintf(__('%s @ %s', 'wp-stats'), get_option('date_format'), get_option('time_format')), $post->comment_date); |
| 184 |
$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"; |
| 185 |
} |
| 186 |
} else { |
| 187 |
$temp = '<li>'.__('N/A', 'wp-stats').'</li>'; |
| 188 |
} |
| 189 |
if($display) { |
| 190 |
echo $temp; |
| 191 |
} else { |
| 192 |
return $temp; |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
### Function: Get Top Commented Posts |
| 198 |
function get_mostcommented($mode = '', $limit = 10, $chars = 0, $display = true) { |
| 199 |
global $wpdb, $post; |
| 200 |
$temp = ''; |
| 201 |
if(!empty($mode) && $mode !== 'both') { |
| 202 |
$where = "post_type = '$mode'"; |
| 203 |
} else { |
| 204 |
$where = '1=1'; |
| 205 |
} |
| 206 |
$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"); |
| 207 |
if($mostcommenteds) { |
| 208 |
if($chars > 0) { |
| 209 |
foreach ($mostcommenteds as $post) { |
| 210 |
$post_title = get_the_title(); |
| 211 |
$comment_total = $post->comment_total; |
| 212 |
$temp .= "<li><a href=\"".get_permalink()."\" title=\"".sprintf(__('View comments in post %s', 'wp-stats'), $post_title)."\">".snippet_text($post_title, $chars)."</a> - ".sprintf(_n('%s comment', '%s comments', $comment_total, 'wp-stats'), number_format_i18n($comment_total))."</li>"; |
| 213 |
} |
| 214 |
} else { |
| 215 |
foreach ($mostcommenteds as $post) { |
| 216 |
$post_title = get_the_title(); |
| 217 |
$comment_total = $post->comment_total; |
| 218 |
$temp .= "<li><a href=\"".get_permalink()."\" title=\"".sprintf(__('View comments in post %s', 'wp-stats'), $post_title)."\">$post_title</a> - ".sprintf(_n('%s comment', '%s comments', $comment_total, 'wp-stats'), number_format_i18n($comment_total))."</li>"; |
| 219 |
} |
| 220 |
} |
| 221 |
} else { |
| 222 |
$temp = '<li>'.__('N/A', 'wp-stats').'</li>'; |
| 223 |
} |
| 224 |
if($display) { |
| 225 |
echo $temp; |
| 226 |
} else { |
| 227 |
return $temp; |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
### Function: Get Author Stats |
| 233 |
function get_authorsstats($mode = '', $display = true) { |
| 234 |
global $wpdb, $wp_rewrite; |
| 235 |
$temp = ''; |
| 236 |
if(!empty($mode) && $mode !== 'both') { |
| 237 |
$where = "post_type = '$mode'"; |
| 238 |
} else { |
| 239 |
$where = '1=1'; |
| 240 |
} |
| 241 |
$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"); |
| 242 |
if($posts) { |
| 243 |
$using_permalink = get_option('permalink_structure'); |
| 244 |
$permalink = $wp_rewrite->get_author_permastruct(); |
| 245 |
foreach ($posts as $post) { |
| 246 |
$post_author = strip_tags(stripslashes($post->user_nicename)); |
| 247 |
$author_link = str_replace('%author%', $post_author, $permalink); |
| 248 |
$display_name = strip_tags(stripslashes($post->display_name)); |
| 249 |
$posts_total = number_format_i18n($post->posts_total); |
| 250 |
if($using_permalink) { |
| 251 |
$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"; |
| 252 |
} else { |
| 253 |
$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"; |
| 254 |
} |
| 255 |
} |
| 256 |
} else { |
| 257 |
$temp = '<li>'.__('N/A', 'wp-stats').'</li>'; |
| 258 |
} |
| 259 |
if($display) { |
| 260 |
echo $temp; |
| 261 |
} else { |
| 262 |
return $temp; |
| 263 |
} |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
### Function: Get Comments' Members Stats |
| 268 |
// Treshhold = Number Of Posts User Must Have Before It Will Display His Name Out |
| 269 |
// 5 = Default Treshhold; -1 = Disable Treshhold |
| 270 |
function get_commentmembersstats($threshhold = -1, $limit = 0, $display = true) { |
| 271 |
global $wpdb; |
| 272 |
$temp = ''; |
| 273 |
$limit_sql = ''; |
| 274 |
if($limit > 0) { |
| 275 |
$limit_sql = "LIMIT $limit"; |
| 276 |
} |
| 277 |
$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 = 'comment' AND post_date < '".current_time('mysql')."' AND post_status = 'publish' AND post_password = '' GROUP BY comment_author ORDER BY comment_total DESC $limit_sql"); |
| 278 |
if($comments) { |
| 279 |
foreach ($comments as $comment) { |
| 280 |
$comment_total = (int) $comment->comment_total; |
| 281 |
// If Total Comments Is Below Threshold |
| 282 |
if($comment_total >= $threshhold) { |
| 283 |
$comment_author = strip_tags(stripslashes($comment->comment_author)); |
| 284 |
$comment_author_link = urlencode($comment_author); |
| 285 |
$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"; |
| 286 |
} |
| 287 |
} |
| 288 |
} else { |
| 289 |
$temp = '<li>'.__('N/A', 'wp-stats').'</li>'; |
| 290 |
} |
| 291 |
if($display) { |
| 292 |
echo $temp; |
| 293 |
} else { |
| 294 |
return $temp; |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
|
| 299 |
### Function: Get Post Categories Stats |
| 300 |
function get_postcats($display = true) { |
| 301 |
return wp_list_categories(array('style' => 'list', 'show_count' => 1, 'title_li' => '', 'hide_title_if_empty' => true, 'echo' => $display )); |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
### Function: Get Links Categories Stats |
| 306 |
function get_linkcats($display = true) { |
| 307 |
$temp = ''; |
| 308 |
$cats = get_categories('type=link'); |
| 309 |
if ($cats) { |
| 310 |
foreach ($cats as $cat) { |
| 311 |
$temp .= '<li>'.$cat->cat_name.' ('.number_format_i18n($cat->count).")</li>\n"; |
| 312 |
} |
| 313 |
} |
| 314 |
if($display) { |
| 315 |
echo $temp; |
| 316 |
} else { |
| 317 |
return $temp; |
| 318 |
} |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
### Function: Get Tags List |
| 323 |
function get_tags_list($display = true) { |
| 324 |
$temp = ''; |
| 325 |
$tags = get_tags('orderby=count&order=DESC'); |
| 326 |
if ($tags) { |
| 327 |
foreach ($tags as $tag) { |
| 328 |
$temp .= '<li><a href="'.clean_url(get_tag_link($tag->term_id)).'" title="'.sprintf(_n('%s topic', '%s topics', $tag->count, 'wp-stats'), number_format_i18n($tag->count)).'">'.$tag->name.'</a> ('.number_format_i18n($tag->count).")</li>\n"; |
| 329 |
} |
| 330 |
} |
| 331 |
if($display) { |
| 332 |
echo $temp; |
| 333 |
} else { |
| 334 |
return $temp; |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
### Function: Snippet Text |
| 340 |
if(!function_exists('snippet_text')) { |
| 341 |
function snippet_text($text, $length = 0) { |
| 342 |
$text = html_entity_decode($text, ENT_QUOTES, get_option('blog_charset')); |
| 343 |
if (mb_strlen($text) > $length) { |
| 344 |
return htmlentities(mb_substr($text,0,$length), ENT_COMPAT, get_option('blog_charset')).'...'; |
| 345 |
} |
| 346 |
|
| 347 |
return htmlentities($text, ENT_COMPAT, get_option('blog_charset')); |
| 348 |
} |
| 349 |
} |
| 350 |
|
| 351 |
|
| 352 |
### Function: Short Code For Inserting Stats Into Page |
| 353 |
add_shortcode('page_stats', 'stats_page_shortcode'); |
| 354 |
function stats_page_shortcode($atts) { |
| 355 |
return stats_page(); |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
### Function: Stats Page |
| 360 |
function stats_page_link($author, $page = 0) { |
| 361 |
$stats_url = esc_url( get_option( 'stats_url' ) ); |
| 362 |
$page_string = ''; |
| 363 |
if($page > 1) { |
| 364 |
$page_string = "&stats_page=$page"; |
| 365 |
} |
| 366 |
if(strpos($stats_url, '?') !== false) { |
| 367 |
$stats_url = "$stats_url&stats_author=$author$page_string"; |
| 368 |
} else { |
| 369 |
$stats_url = "$stats_url?stats_author=$author$page_string"; |
| 370 |
} |
| 371 |
return $stats_url; |
| 372 |
} |
| 373 |
|
| 374 |
|
| 375 |
### Function: Statistics Page |
| 376 |
function stats_page() { |
| 377 |
global $wpdb, $post; |
| 378 |
// Variables Variables Variables |
| 379 |
$comment_author = isset( $_GET['stats_author'] ) ? urldecode(strip_tags(stripslashes(trim($_GET['stats_author'])))) : ''; |
| 380 |
$page = isset( $_GET['stats_page'] ) ? (int) $_GET['stats_page'] : 1; |
| 381 |
$temp_stats = ''; |
| 382 |
$temp_post = $post; |
| 383 |
$stats_mostlimit = (int) get_option('stats_mostlimit'); |
| 384 |
$stats_display = get_option('stats_display'); |
| 385 |
|
| 386 |
// Default wp-stats.php Page |
| 387 |
if(empty($comment_author)) { |
| 388 |
// General Stats |
| 389 |
if($stats_display['total_stats'] === 1) { |
| 390 |
$temp_stats .= '<h2 id="GeneralStats">'.__('General Stats', 'wp-stats').'</h2>'."\n"; |
| 391 |
$temp_stats .= '<p><strong>'.__('Total Stats', 'wp-stats').'</strong></p>'."\n"; |
| 392 |
$temp_stats .= '<ul>'."\n"; |
| 393 |
$temp_stats .= '<li>'.sprintf(_n('<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"; |
| 394 |
$temp_stats .= '<li>'.sprintf(_n('<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"; |
| 395 |
$temp_stats .= '<li>'.sprintf(_n('<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"; |
| 396 |
$temp_stats .= '<li>'.sprintf(_n('<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"; |
| 397 |
|
| 398 |
$temp_stats .= '<li>'.sprintf(_n('<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"; |
| 399 |
$temp_stats .= '<li>'.sprintf(_n('<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"; |
| 400 |
|
| 401 |
$temp_stats .= '<li>'.sprintf(_n('<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"; |
| 402 |
$temp_stats .= '<li>'.sprintf(_n('<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"; |
| 403 |
$temp_stats .= '<li>'.sprintf(_n('<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"; |
| 404 |
if( class_exists( 'Akismet_Admin' ) ) { |
| 405 |
$spam_count = Akismet_Admin::get_spam_count(); |
| 406 |
$temp_stats .= '<li>' . sprintf( _n( '<strong>%s</strong> spam blocked.', '<strong>%s</strong> spam blocked.', $spam_count, 'wp-stats' ), number_format_i18n( $spam_count ) ) . '</li>' . "\n"; |
| 407 |
} |
| 408 |
// WP-Stats: General Stats Filter |
| 409 |
$temp_stats = apply_filters('wp_stats_page_general', $temp_stats); |
| 410 |
$temp_stats .= '</ul>'."\n"; |
| 411 |
} |
| 412 |
|
| 413 |
// Plugin Stats |
| 414 |
$temp_stats .= '<h2 id="PluginsStats">'.__('Plugins Stats', 'wp-stats').'</h2>'."\n"; |
| 415 |
|
| 416 |
// WP-Stats: Plugins Stats Filter |
| 417 |
$temp_stats = apply_filters('wp_stats_page_plugins', $temp_stats); |
| 418 |
|
| 419 |
// Top Recent Stats |
| 420 |
$temp_stats .= '<h2 id="TopRecentStats">'.sprintf(_n('Top %s Recent Stat', 'Top %s Recent Stats', $stats_mostlimit, 'wp-stats'), number_format_i18n($stats_mostlimit)).'</h2>'."\n"; |
| 421 |
|
| 422 |
// Recent Posts |
| 423 |
if($stats_display['recent_posts'] === 1) { |
| 424 |
$temp_stats .= '<p><strong>'.sprintf(_n('%s Recent Post', '%s Recent Posts', $stats_mostlimit, 'wp-stats'), number_format_i18n($stats_mostlimit)).'</strong></p>'."\n"; |
| 425 |
$temp_stats .= '<ul>'."\n"; |
| 426 |
$temp_stats .= get_recentposts('post', $stats_mostlimit, false); |
| 427 |
$temp_stats .= '</ul>'."\n"; |
| 428 |
} |
| 429 |
|
| 430 |
// Recent Comments |
| 431 |
if($stats_display['recent_comments'] === 1) { |
| 432 |
$temp_stats .= '<p><strong>'.sprintf(_n('%s Recent Comment', '%s Recent Comments', $stats_mostlimit, 'wp-stats'), number_format_i18n($stats_mostlimit)).'</strong></p>'."\n"; |
| 433 |
$temp_stats .= '<ul>'."\n"; |
| 434 |
$temp_stats .= get_recentcomments('both', $stats_mostlimit, false); |
| 435 |
$temp_stats .= '</ul>'."\n"; |
| 436 |
} |
| 437 |
|
| 438 |
// WP-Stats: Top Recent Stats Filter |
| 439 |
$temp_stats = apply_filters('wp_stats_page_recent', $temp_stats); |
| 440 |
|
| 441 |
// Top Most Stats |
| 442 |
$temp_stats .= '<h2 id="TopMostHighestStats">'.sprintf(_n('%s Most/Highest Stat', '%s Most/Highest Stats', $stats_mostlimit, 'wp-stats'), number_format_i18n($stats_mostlimit)).'</h2>'."\n"; |
| 443 |
|
| 444 |
// Most Commented Posts |
| 445 |
if($stats_display['commented_post'] === 1) { |
| 446 |
$temp_stats .= '<p><strong>'.sprintf(_n('%s Most Commented Post', '%s Most Commented Posts', $stats_mostlimit, 'wp-stats'), number_format_i18n($stats_mostlimit)).'</strong></p>'."\n"; |
| 447 |
$temp_stats .= '<ul>'."\n"; |
| 448 |
$temp_stats .= get_mostcommented('post', $stats_mostlimit, 0, false); |
| 449 |
$temp_stats .= '</ul>'."\n"; |
| 450 |
} |
| 451 |
|
| 452 |
// Most Commented Pages |
| 453 |
if($stats_display['commented_page'] === 1) { |
| 454 |
$temp_stats .= '<p><strong>'.sprintf(_n('%s Most Commented Page', '%s Most Commented Pages', $stats_mostlimit, 'wp-stats'), number_format_i18n($stats_mostlimit)).'</strong></p>'."\n"; |
| 455 |
$temp_stats .= '<ul>'."\n"; |
| 456 |
$temp_stats .= get_mostcommented('page', $stats_mostlimit, 0, false); |
| 457 |
$temp_stats .= '</ul>'."\n"; |
| 458 |
} |
| 459 |
|
| 460 |
// WP-Stats: Top Most/Highest Stats Filter |
| 461 |
$temp_stats = apply_filters('wp_stats_page_most', $temp_stats); |
| 462 |
|
| 463 |
// Authors Stats |
| 464 |
$temp_stats .= '<h2 id="AuthorsStats">'.__('Authors Stats', 'wp-stats').'</h2>'."\n"; |
| 465 |
|
| 466 |
// Authors |
| 467 |
if($stats_display['authors'] === 1) { |
| 468 |
$temp_stats .= '<p><strong>'.__('Authors', 'wp-stats').'</strong></p>'."\n"; |
| 469 |
$temp_stats .= '<ol>'."\n"; |
| 470 |
$temp_stats .= get_authorsstats('post', false); |
| 471 |
$temp_stats .= '</ol>'."\n"; |
| 472 |
} |
| 473 |
|
| 474 |
// WP-Stats: Authors Stats Filter |
| 475 |
$temp_stats = apply_filters('wp_stats_page_authors', $temp_stats); |
| 476 |
|
| 477 |
// Comments' Members Stats |
| 478 |
$temp_stats .= '<h2 id="CommentsMembersStats">'.__('Comments\' Members Stats', 'wp-stats').'</h2>'."\n"; |
| 479 |
|
| 480 |
// Comments' Member |
| 481 |
if($stats_display['comment_members'] === 1) { |
| 482 |
$temp_stats .= '<p><strong>'.__('Comment Members', 'wp-stats').'</strong></p>'."\n"; |
| 483 |
$temp_stats .= '<ol>'."\n"; |
| 484 |
$temp_stats .= get_commentmembersstats(5, 0, false); |
| 485 |
$temp_stats .= '</ol>'."\n"; |
| 486 |
} |
| 487 |
|
| 488 |
// WP-Stats: Comments' Members Stats Filter |
| 489 |
$temp_stats = apply_filters('wp_stats_page_comments_members', $temp_stats); |
| 490 |
|
| 491 |
// Misc Stats |
| 492 |
$temp_stats .= '<h2 id="MiscStats">'.__('Misc Stats', 'wp-stats').'</h2>'."\n"; |
| 493 |
|
| 494 |
// Post Categories |
| 495 |
if($stats_display['post_cats'] === 1) { |
| 496 |
$temp_stats .= '<p><strong>'.__('Post Categories', 'wp-stats').'</strong></p>'."\n"; |
| 497 |
$temp_stats .= '<ul>'."\n"; |
| 498 |
$temp_stats .= get_postcats(false); |
| 499 |
$temp_stats .= '</ul>'."\n"; |
| 500 |
} |
| 501 |
|
| 502 |
// Link Categories |
| 503 |
if($stats_display['link_cats'] === 1) { |
| 504 |
$temp_stats .= '<p><strong>'.__('Link Categories', 'wp-stats').'</strong></p>'."\n"; |
| 505 |
$temp_stats .= '<ul>'."\n"; |
| 506 |
$temp_stats .= get_linkcats(false); |
| 507 |
$temp_stats .= '</ul>'."\n"; |
| 508 |
} |
| 509 |
|
| 510 |
if($stats_display['tags_list'] === 1) { |
| 511 |
$temp_stats .= '<p><strong>'.__('Tags List', 'wp-stats').'</strong></p>'."\n"; |
| 512 |
$temp_stats .= '<ul>'."\n"; |
| 513 |
$temp_stats .= get_tags_list(false); |
| 514 |
$temp_stats .= '</ul>'."\n"; |
| 515 |
} |
| 516 |
|
| 517 |
// WP-Stats: Plugin Misc Filter |
| 518 |
$temp_stats = apply_filters('wp_stats_page_misc', $temp_stats); |
| 519 |
|
| 520 |
// Displaying Comments Posted By User |
| 521 |
} else { |
| 522 |
// Stats URL |
| 523 |
$stats_url = esc_url( get_option( 'stats_url' ) ); |
| 524 |
// Number Of Comments Per Page |
| 525 |
$perpage = 30; |
| 526 |
// Comment Author Link |
| 527 |
$comment_author_link = urlencode($comment_author); |
| 528 |
// Comment Author SQL |
| 529 |
$comment_author_sql = $wpdb->escape($comment_author); |
| 530 |
// Total Comments Posted By User |
| 531 |
$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 = 'commment' AND post_date < '".current_time('mysql')."' AND post_status = 'publish' AND post_password = ''"); |
| 532 |
// Calculate Paging |
| 533 |
$numposts = $totalcomments; |
| 534 |
$max_page = ceil($numposts/$perpage); |
| 535 |
if(empty($page) || $page == 0) { |
| 536 |
$page = 1; |
| 537 |
} |
| 538 |
$offset = ($page-1) * $perpage; |
| 539 |
$pages_to_show = 10; |
| 540 |
$pages_to_show_minus_1 = $pages_to_show-1; |
| 541 |
$half_page_start = floor($pages_to_show_minus_1/2); |
| 542 |
$half_page_end = ceil($pages_to_show_minus_1/2); |
| 543 |
$start_page = $page - $half_page_start; |
| 544 |
if($start_page <= 0) { |
| 545 |
$start_page = 1; |
| 546 |
} |
| 547 |
$end_page = $page + $half_page_end; |
| 548 |
if(($end_page - $start_page) !== $pages_to_show_minus_1) { |
| 549 |
$end_page = $start_page + $pages_to_show_minus_1; |
| 550 |
} |
| 551 |
if($end_page > $max_page) { |
| 552 |
$start_page = $max_page - $pages_to_show_minus_1; |
| 553 |
$end_page = $max_page; |
| 554 |
} |
| 555 |
if($start_page <= 0) { |
| 556 |
$start_page = 1; |
| 557 |
} |
| 558 |
if(($offset + $perpage) > $numposts) { |
| 559 |
$max_on_page = $numposts; |
| 560 |
} else { |
| 561 |
$max_on_page = ($offset + $perpage); |
| 562 |
} |
| 563 |
if (($offset + 1) > $numposts) { |
| 564 |
$display_on_page = $numposts; |
| 565 |
} else { |
| 566 |
$display_on_page = ($offset + 1); |
| 567 |
} |
| 568 |
|
| 569 |
// Getting The Comments |
| 570 |
$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"); |
| 571 |
$temp_stats .= '<h2>'.__('Comments Posted By', 'wp-stats').' '.$comment_author.'</h2>'; |
| 572 |
$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>'; |
| 573 |
|
| 574 |
|
| 575 |
// Get Comments |
| 576 |
if($gmz_comments) { |
| 577 |
$cache_post_title = ''; |
| 578 |
foreach($gmz_comments as $post) { |
| 579 |
$comment_id = (int) $post->comment_ID; |
| 580 |
$comment_author2 = htmlspecialchars(stripslashes($post->comment_author)); |
| 581 |
$comment_date = mysql2date(sprintf(__('%s @ %s', 'wp-stats'), get_option('date_format'), get_option('time_format')), $post->comment_date); |
| 582 |
$comment_content = apply_filters('comment_text', $post->comment_content); |
| 583 |
$post_date = get_the_time(sprintf(__('%s @ %s', 'wp-stats'), get_option('date_format'), get_option('time_format'))); |
| 584 |
$post_title = get_the_title(); |
| 585 |
|
| 586 |
// Check For Password Protected Post |
| 587 |
if(!empty($post->post_password) && stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) !== $post->post_password) { |
| 588 |
// If New Title, Print It Out |
| 589 |
if($post_title !== $cache_post_title) { |
| 590 |
$temp_stats .= '<p><strong><a href="'.get_permalink().'" title="'.__('Posted On', 'wp-stats')." $post_date\">".__('Protected', 'wp-stats').": $post_title</a></strong></p>"; |
| 591 |
$temp_stats .= '<blockquote>'.__('Comments Protected', 'wp-stats').'</blockquote>'; |
| 592 |
} |
| 593 |
} else { |
| 594 |
// If New Title, Print It Out |
| 595 |
if($post_title !== $cache_post_title) { |
| 596 |
$temp_stats .= "<p><strong><a href=\"".get_permalink()."\" title=\"".__('Posted On', 'wp-stats')." $post_date\">$post_title</a></strong></p>"; |
| 597 |
} |
| 598 |
$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)."\">»</a> ".__('Posted By', 'wp-stats')." <strong>$comment_author2</strong> ".__('On', 'wp-stats')." $comment_date</p></blockquote>"; |
| 599 |
} |
| 600 |
$cache_post_title = $post_title; |
| 601 |
} |
| 602 |
} else { |
| 603 |
$temp_stats .= "<p>$comment_author ".__('has not made any comments yet.', 'wp-stats')."</p>"; |
| 604 |
} |
| 605 |
|
| 606 |
// Comments Paging |
| 607 |
if($max_page > 1) { |
| 608 |
$temp_stats = apply_filters('wp_stats_paging_start', $temp_stats); |
| 609 |
$temp_stats .= '<div class="wp-pagenavi">'."\n"; |
| 610 |
$temp_stats .= '<span class="pages"> '.sprintf(__('Page %s of %s', 'wp-stats'), number_format_i18n($page), number_format_i18n($max_page)).' </span>'; |
| 611 |
if ($start_page >= 2 && $pages_to_show < $max_page) { |
| 612 |
$temp_stats .= '<a href="'.stats_page_link($comment_author_link, 1).'" title="'.__('« First', 'wp-stats').'"> '.__('« First', 'wp-stats').' </a>'; |
| 613 |
$temp_stats .= '<span class="extend">...</span>'; |
| 614 |
} |
| 615 |
if($page > 1) { |
| 616 |
$temp_stats .= '<a href="'.stats_page_link($comment_author_link, ($page-1)).'" title="'.__('«', 'wp-stats').'"> '.__('«', 'wp-stats').' </a>'; |
| 617 |
} |
| 618 |
for($i = $start_page; $i <= $end_page; $i++) { |
| 619 |
if($i === $page) { |
| 620 |
$temp_stats .= '<span class="current"> '.number_format_i18n($i).' </span>'; |
| 621 |
} else { |
| 622 |
$temp_stats .= '<a href="'.stats_page_link($comment_author_link, $i).'" title="'.number_format_i18n($i).'"> '.number_format_i18n($i).' </a>'; |
| 623 |
} |
| 624 |
} |
| 625 |
if(empty($page) || ($page+1) <= $max_page) { |
| 626 |
$temp_stats .= '<a href="'.stats_page_link($comment_author_link, ($page+1)).'" title="'.__('»', 'wp-stats').'"> '.__('»', 'wp-stats').' </a>'; |
| 627 |
} |
| 628 |
if ($end_page < $max_page) { |
| 629 |
$temp_stats .= '<span class="extend">...</span>'; |
| 630 |
$temp_stats .= '<a href="'.stats_page_link($comment_author_link, $max_page).'" title="'.__('Last »', 'wp-stats').'"> '.__('Last »', 'wp-stats').' </a>'; |
| 631 |
} |
| 632 |
$temp_stats .= '</div>'; |
| 633 |
$temp_stats = apply_filters('wp_stats_paging_end', $temp_stats); |
| 634 |
} |
| 635 |
$temp_stats .= '<strong>««</strong> <a href="'.$stats_url.'">'.__('Back To Stats Page', 'wp-stats').' </a>'; |
| 636 |
} // End If |
| 637 |
|
| 638 |
// Assign Back $post |
| 639 |
$post = $temp_post; |
| 640 |
|
| 641 |
// Output Stats Page |
| 642 |
return apply_filters('stats_page', $temp_stats); |
| 643 |
} |
| 644 |
|
| 645 |
|
| 646 |
### Class: WP-Stats Widget |
| 647 |
class WP_Widget_Stats extends WP_Widget { |
| 648 |
// Constructor |
| 649 |
public function __construct() { |
| 650 |
$widget_ops = array('description' => __('WP-Stats statistics', 'wp-stats')); |
| 651 |
parent::__construct('stats', __('Stats', 'wp-stats'), $widget_ops); |
| 652 |
} |
| 653 |
|
| 654 |
// Display Widget |
| 655 |
public function widget( $args, $instance ) { |
| 656 |
$title = isset( $instance['title'] ) ? apply_filters( 'widget_title', esc_attr( $instance['title'] ) ) : ''; |
| 657 |
$limit = isset( $instance['limit'] ) ? (int) $instance['limit'] : 10; |
| 658 |
$chars = isset( $instance['chars'] ) ? (int) $instance['chars'] : 200; |
| 659 |
$show_link = isset( $instance['show_link'] ) ? (int) $instance['show_link'] : 1; |
| 660 |
$stats_total_authors = isset( $instance['stats_total_authors'] ) ? (int) $instance['stats_total_authors'] : 1; |
| 661 |
$stats_total_posts = isset( $instance['stats_total_posts'] ) ? (int) $instance['stats_total_posts'] : 1; |
| 662 |
$stats_total_pages = isset( $instance['stats_total_pages'] ) ? (int) $instance['stats_total_pages'] : 1; |
| 663 |
$stats_total_tags = isset( $instance['stats_total_tags'] ) ? (int) $instance['stats_total_tags'] : 1; |
| 664 |
$stats_total_comments = isset( $instance['stats_total_comments'] ) ? (int) $instance['stats_total_comments'] : 1; |
| 665 |
$stats_total_commenters = isset( $instance['stats_total_commenters'] ) ? (int) $instance['stats_total_commenters'] : 1; |
| 666 |
$stats_total_links = isset( $instance['stats_total_links'] ) ? (int) $instance['stats_total_links'] : 1; |
| 667 |
$stats_total_post_cat = isset( $instance['stats_total_post_cat'] ) ? (int) $instance['stats_total_post_cat'] : 1; |
| 668 |
$stats_total_link_cat = isset( $instance['stats_total_link_cat'] ) ? (int) $instance['stats_total_link_cat'] : 1; |
| 669 |
$stats_total_spam = isset( $instance['stats_total_spam'] ) ? (int) $instance['stats_total_spam'] : 1; |
| 670 |
$stats_most_commented_post = isset( $instance['stats_most_commented_post'] ) ? (int) $instance['stats_most_commented_post'] : 1; |
| 671 |
echo $args['before_widget'] . $args['before_title'] . $title . $args['after_title']; |
| 672 |
echo '<ul>'."\n"; |
| 673 |
echo '<li><strong>'.__('Total Stats', 'wp-stats').'</strong>'."\n"; |
| 674 |
echo '<ul>'."\n"; |
| 675 |
// Total Authors |
| 676 |
if($stats_total_authors) { |
| 677 |
echo '<li>'.sprintf(_n('<strong>%s</strong> Author', '<strong>%s</strong> Authors', get_totalauthors(false), 'wp-stats'), number_format_i18n(get_totalauthors(false))).'</li>'."\n"; |
| 678 |
} |
| 679 |
// Total Posts |
| 680 |
if($stats_total_posts) { |
| 681 |
echo '<li>'.sprintf(_n('<strong>%s</strong> Post', '<strong>%s</strong> Posts', get_totalposts(false), 'wp-stats'), number_format_i18n(get_totalposts(false))).'</li>'."\n"; |
| 682 |
} |
| 683 |
// Total Pages |
| 684 |
if($stats_total_pages) { |
| 685 |
echo '<li>'.sprintf(_n('<strong>%s</strong> Page', '<strong>%s</strong> Pages', get_totalpages(false), 'wp-stats'), number_format_i18n(get_totalpages(false))).'</li>'."\n"; |
| 686 |
} |
| 687 |
// Total Tags |
| 688 |
if($stats_total_tags) { |
| 689 |
echo '<li>'.sprintf(_n('<strong>%s</strong> Tag', '<strong>%s</strong> Tags', wp_count_terms('post_tag'), 'wp-stats'), number_format_i18n(wp_count_terms('post_tag'))).'</li>'."\n"; |
| 690 |
} |
| 691 |
// Total Comments |
| 692 |
if($stats_total_comments) { |
| 693 |
echo '<li>'.sprintf(_n('<strong>%s</strong> Comment', '<strong>%s</strong> Comments', get_totalcomments(false), 'wp-stats'), number_format_i18n(get_totalcomments(false))).'</li>'."\n"; |
| 694 |
} |
| 695 |
// Total Comment Posters |
| 696 |
if($stats_total_commenters) { |
| 697 |
echo '<li>'.sprintf(_n('<strong>%s</strong> Comment Poster', '<strong>%s</strong> Comment Posters', get_totalcommentposters(false), 'wp-stats'), number_format_i18n(get_totalcommentposters(false))).'</li>'."\n"; |
| 698 |
} |
| 699 |
// Total Links |
| 700 |
if($stats_total_links) { |
| 701 |
echo '<li>'.sprintf(_n('<strong>%s</strong> Link', '<strong>%s</strong> Links', get_totallinks(false), 'wp-stats'), number_format_i18n(get_totallinks(false))).'</li>'."\n"; |
| 702 |
} |
| 703 |
// Total Post Categories |
| 704 |
if($stats_total_post_cat) { |
| 705 |
echo '<li>'.sprintf(_n('<strong>%s</strong> Post Category', '<strong>%s</strong> Post Categories', wp_count_terms('category'), 'wp-stats'), number_format_i18n(wp_count_terms('category'))).'</li>'."\n"; |
| 706 |
} |
| 707 |
// Total Link Categories |
| 708 |
if($stats_total_link_cat) { |
| 709 |
echo '<li>'.sprintf(_n('<strong>%s</strong> Link Category', '<strong>%s</strong> Link Categories', wp_count_terms('link_category'), 'wp-stats'), number_format_i18n(wp_count_terms('link_category'))).'</li>'."\n"; |
| 710 |
} |
| 711 |
// Total Spam |
| 712 |
if($stats_total_spam && class_exists( 'Akismet_Admin' ) ) { |
| 713 |
$spam_count = Akismet_Admin::get_spam_count(); |
| 714 |
echo '<li>' . sprintf( _n( '<strong>%s</strong> Spam Blocked', '<strong>%s</strong> Spam Blockeds', $spam_count, 'wp-stats' ), number_format_i18n( $spam_count ) ) . '</li>' . "\n"; |
| 715 |
} |
| 716 |
echo '</ul>'."\n"; |
| 717 |
echo '</li>'."\n"; |
| 718 |
echo '</ul>'."\n"; |
| 719 |
// Most Commented |
| 720 |
if($stats_most_commented_post) { |
| 721 |
echo '<ul>'."\n"; |
| 722 |
echo '<li><strong>'.number_format_i18n($limit).' '.__('Most Commented Posts', 'wp-stats').'</strong>'."\n"; |
| 723 |
echo '<ul>'."\n"; |
| 724 |
get_mostcommented('post', $limit, $chars); |
| 725 |
echo '</ul>'."\n"; |
| 726 |
echo '</li>'."\n"; |
| 727 |
echo '</ul>'."\n"; |
| 728 |
} |
| 729 |
if($show_link) { |
| 730 |
echo '<ul>'."\n"; |
| 731 |
echo '<li><a href="'.esc_url( get_option( 'stats_url' ) ).'">'.__('My Blog Statistics', 'wp-stats').'</a></li>'."\n"; |
| 732 |
echo '</ul>'."\n"; |
| 733 |
} |
| 734 |
echo $args['after_widget']; |
| 735 |
} |
| 736 |
|
| 737 |
// When Widget Control Form Is Posted |
| 738 |
public function update( $new_instance, $old_instance ) { |
| 739 |
if ( ! isset( $new_instance['submit'] ) ) { |
| 740 |
return false; |
| 741 |
} |
| 742 |
$instance = $old_instance; |
| 743 |
$instance['title'] = isset( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : ''; |
| 744 |
$instance['limit'] = isset( $new_instance['limit'] ) ? (int) $new_instance['limit'] : 10; |
| 745 |
$instance['chars'] = isset( $new_instance['chars'] ) ? (int) $new_instance['chars'] : 200; |
| 746 |
$instance['show_link'] = isset( $new_instance['show_link'] ) ? (int) $new_instance['show_link'] : 1; |
| 747 |
$instance['stats_total_authors'] = isset( $new_instance['stats_total_authors']) ? (int) $new_instance['stats_total_authors'] : 1; |
| 748 |
$instance['stats_total_posts'] = isset( $new_instance['stats_total_posts'] ) ? (int) $new_instance['stats_total_posts'] : 1; |
| 749 |
$instance['stats_total_pages'] = isset( $new_instance['stats_total_pages'] ) ? (int) $new_instance['stats_total_pages'] : 1; |
| 750 |
$instance['stats_total_tags'] = isset( $new_instance['stats_total_tags'] ) ? (int) $new_instance['stats_total_tags'] : 1; |
| 751 |
$instance['stats_total_comments'] = isset( $new_instance['stats_total_comments'] ) ? (int) $new_instance['stats_total_comments'] : 1; |
| 752 |
$instance['stats_total_commenters'] = isset( $new_instance['stats_total_commenters'] ) ? (int) $new_instance['stats_total_commenters'] : 1; |
| 753 |
$instance['stats_total_links'] = isset( $new_instance['stats_total_links'] ) ? (int) $new_instance['stats_total_links'] : 1; |
| 754 |
$instance['stats_total_post_cat'] = isset( $new_instance['stats_total_post_cat'] ) ? (int) $new_instance['stats_total_post_cat'] : 1; |
| 755 |
$instance['stats_total_link_cat'] = isset( $new_instance['stats_total_link_cat'] ) ? (int) $new_instance['stats_total_link_cat'] : 1; |
| 756 |
$instance['stats_total_spam'] = isset( $new_instance['stats_total_spam'] ) ? (int) $new_instance['stats_total_spam'] : 1; |
| 757 |
$instance['stats_most_commented_post'] = isset( $new_instance['stats_most_commented_post'] ) ? (int) $new_instance['stats_most_commented_post'] : 1; |
| 758 |
return $instance; |
| 759 |
} |
| 760 |
|
| 761 |
// DIsplay Widget Control Form |
| 762 |
public function form( $instance ) { |
| 763 |
$instance = wp_parse_args((array) $instance, array('title' => __('Stats', 'wp-stats'), 'limit' => 10, 'chars' => 200, 'show_link' => 1, 'stats_total_authors' => 1, 'stats_total_posts' => 1, 'stats_total_pages' => 1, 'stats_total_tags' => 1, 'stats_total_comments' => 1, 'stats_total_commenters' => 1, 'stats_total_links' => 1, 'stats_total_post_cat' => 1, 'stats_total_link_cat' => 1, 'stats_total_spam' => 1, 'stats_most_commented_post' => 1)); |
| 764 |
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
| 765 |
$limit = isset( $instance['limit'] ) ? (int) $instance['limit'] : 10; |
| 766 |
$chars = isset( $instance['chars'] ) ? (int) $instance['chars'] : 200; |
| 767 |
$show_link = isset( $instance['show_link'] ) ? (int) $instance['show_link'] : 1; |
| 768 |
$most_limit = get_option('stats_mostlimit'); |
| 769 |
?> |
| 770 |
<p> |
| 771 |
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'wp-stats'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label> |
| 772 |
</p> |
| 773 |
<p> |
| 774 |
<?php _e('Statistics To Display:', 'wp-postviews'); ?><br /> |
| 775 |
<input type="checkbox" id="<?php echo $this->get_field_id('stats_total_authors'); ?>" name="<?php echo $this->get_field_name('stats_total_authors'); ?>" value="1" <?php checked(1, $instance['stats_total_authors']); ?> /> <label for="<?php echo $this->get_field_id('stats_total_authors'); ?>"><?php _e('Total Authors', 'wp-stats'); ?></label> |
| 776 |
<br /> |
| 777 |
<input type="checkbox" id="<?php echo $this->get_field_id('stats_total_posts'); ?>" name="<?php echo $this->get_field_name('stats_total_posts'); ?>" value="1" <?php checked(1, $instance['stats_total_posts']); ?> /> <label for="<?php echo $this->get_field_id('stats_total_posts'); ?>"><?php _e('Total Posts', 'wp-stats'); ?></label> |
| 778 |
<br /> |
| 779 |
<input type="checkbox" id="<?php echo $this->get_field_id('stats_total_pages'); ?>" name="<?php echo $this->get_field_name('stats_total_pages'); ?>" value="1" <?php checked(1, $instance['stats_total_pages']); ?> /> <label for="<?php echo $this->get_field_id('stats_total_pages'); ?>"><?php _e('Total Pages', 'wp-stats'); ?></label> |
| 780 |
<br /> |
| 781 |
<input type="checkbox" id="<?php echo $this->get_field_id('stats_total_tags'); ?>" name="<?php echo $this->get_field_name('stats_total_tags'); ?>" value="1" <?php checked(1, $instance['stats_total_tags']); ?> /> <label for="<?php echo $this->get_field_id('stats_total_tags'); ?>"><?php _e('Total Tags', 'wp-stats'); ?></label> |
| 782 |
<br /> |
| 783 |
<input type="checkbox" id="<?php echo $this->get_field_id('stats_total_comments'); ?>" name="<?php echo $this->get_field_name('stats_total_comments'); ?>" value="1" <?php checked(1, $instance['stats_total_comments']); ?> /> <label for="<?php echo $this->get_field_id('stats_total_comments'); ?>"><?php _e('Total Comments', 'wp-stats'); ?></label> |
| 784 |
<br /> |
| 785 |
<input type="checkbox" id="<?php echo $this->get_field_id('stats_total_commenters'); ?>" name="<?php echo $this->get_field_name('stats_total_commenters'); ?>" value="1" <?php checked(1, $instance['stats_total_commenters']); ?> /> <label for="<?php echo $this->get_field_id('stats_total_commenters'); ?>"><?php _e('Total Comment Posters', 'wp-stats'); ?></label> |
| 786 |
<br /> |
| 787 |
<input type="checkbox" id="<?php echo $this->get_field_id('stats_total_links'); ?>" name="<?php echo $this->get_field_name('stats_total_links'); ?>" value="1" <?php checked(1, $instance['stats_total_links']); ?> /> <label for="<?php echo $this->get_field_id('stats_total_links'); ?>"><?php _e('Total Links', 'wp-stats'); ?></label> |
| 788 |
<br /> |
| 789 |
<input type="checkbox" id="<?php echo $this->get_field_id('stats_total_post_cat'); ?>" name="<?php echo $this->get_field_name('stats_total_post_cat'); ?>" value="1" <?php checked(1, $instance['stats_total_post_cat']); ?> /> <label for="<?php echo $this->get_field_id('stats_total_post_cat'); ?>"><?php _e('Total Post Categories', 'wp-stats'); ?></label> |
| 790 |
<br /> |
| 791 |
<input type="checkbox" id="<?php echo $this->get_field_id('stats_total_link_cat'); ?>" name="<?php echo $this->get_field_name('stats_total_link_cat'); ?>" value="1" <?php checked(1, $instance['stats_total_link_cat']); ?> /> <label for="<?php echo $this->get_field_id('stats_total_link_cat'); ?>"><?php _e('Total Link Categories', 'wp-stats'); ?></label> |
| 792 |
<br /> |
| 793 |
<?php if( class_exists( 'Akismet_Admin' ) ): ?> |
| 794 |
<input type="checkbox" id="<?php echo $this->get_field_id('stats_total_spam'); ?>" name="<?php echo $this->get_field_name('stats_total_spam'); ?>" value="1" <?php checked(1, $instance['stats_total_spam']); ?> /> <label for="<?php echo $this->get_field_id('stats_total_spam'); ?>"><?php _e('Total Spam Blocked', 'wp-stats'); ?></label> |
| 795 |
<br /> |
| 796 |
<?php endif; ?> |
| 797 |
<br /> |
| 798 |
<input type="checkbox" id="<?php echo $this->get_field_id('stats_most_commented_post'); ?>" name="<?php echo $this->get_field_name('stats_most_commented_post'); ?>" value="1" <?php checked(1, $instance['stats_most_commented_post']); ?> /> <label for="<?php echo $this->get_field_id('stats_most_commented_post'); ?>"><?php printf(_n('%s Most Commented Post', '%s Most Commented Posts', $most_limit, 'wp-stats'), $most_limit); ?></label> |
| 799 |
</p> |
| 800 |
<p> |
| 801 |
<label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e('No. Of Records To Show:', 'wp-stats'); ?> <span style="color: red;">*</span> <input class="widefat" id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="text" value="<?php echo $limit; ?>" /></label> |
| 802 |
</p> |
| 803 |
<p> |
| 804 |
<label for="<?php echo $this->get_field_id('chars'); ?>"><?php _e('Maximum Post Title Length (Characters):', 'wp-stats'); ?> <span style="color: red;">*</span> <input class="widefat" id="<?php echo $this->get_field_id('chars'); ?>" name="<?php echo $this->get_field_name('chars'); ?>" type="text" value="<?php echo $chars; ?>" /></label><br /> |
| 805 |
<small><?php _e('<strong>0</strong> to disable.', 'wp-stats'); ?></small> |
| 806 |
</p> |
| 807 |
<p> |
| 808 |
<label for="<?php echo $this->get_field_id('show_link'); ?>"><?php _e('Show Link To Statistics Page?', 'wp-stats'); ?> |
| 809 |
<select name="<?php echo $this->get_field_name('show_link'); ?>" id="<?php echo $this->get_field_id('show_link'); ?>" class="widefat"> |
| 810 |
<option value="0"<?php selected('0', $show_link); ?>><?php _e('No', 'wp-stats'); ?></option> |
| 811 |
<option value="1"<?php selected('1', $show_link); ?>><?php _e('Yes', 'wp-stats'); ?></option> |
| 812 |
</select> |
| 813 |
</label> |
| 814 |
</p> |
| 815 |
<p style="color: red;"> |
| 816 |
<small><?php _e('* Used only in most commented post.', 'wp-stats'); ?></small> |
| 817 |
<p> |
| 818 |
<input type="hidden" id="<?php echo $this->get_field_id('submit'); ?>" name="<?php echo $this->get_field_name('submit'); ?>" value="1" /> |
| 819 |
<?php |
| 820 |
} |
| 821 |
} |
| 822 |
|
| 823 |
|
| 824 |
### Function: Init WP-Stats Widget |
| 825 |
add_action('widgets_init', 'widget_stats_init'); |
| 826 |
function widget_stats_init() { |
| 827 |
stats_textdomain(); |
| 828 |
register_widget('WP_Widget_Stats'); |
| 829 |
} |
| 830 |
|
| 831 |
|
| 832 |
### Function: Activate Plugin |
| 833 |
register_activation_hook( __FILE__, 'stats_activation' ); |
| 834 |
function stats_activation( $network_wide ) { |
| 835 |
if ( is_multisite() && $network_wide ) { |
| 836 |
$ms_sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites(); |
| 837 |
|
| 838 |
if( 0 < count( $ms_sites ) ) { |
| 839 |
foreach ( $ms_sites as $ms_site ) { |
| 840 |
$blog_id = class_exists( 'WP_Site' ) ? $ms_site->blog_id : $ms_site['blog_id']; |
| 841 |
switch_to_blog( $blog_id ); |
| 842 |
stats_activate(); |
| 843 |
restore_current_blog(); |
| 844 |
} |
| 845 |
} |
| 846 |
} else { |
| 847 |
stats_activate(); |
| 848 |
} |
| 849 |
} |
| 850 |
|
| 851 |
function stats_activate() { |
| 852 |
$stats_display = array( 'total_stats' => 1, 'email' => 1, 'polls' => 1, 'ratings' => 1, 'views' => 1, 'useronline' => 1, 'recent_posts' => 1, 'recent_comments' => 1, 'commented_post' => 1, 'commented_page' => 0, 'emailed_most_post' => 1, 'emailed_most_page' => 0, 'rated_highest_post' => 1, 'rated_highest_page' => 0, 'rated_most_post' => 1, 'rated_most_page' => 0, 'viewed_most_post' => 1, 'viewed_most_page' => 0, 'authors' => 1, 'comment_members' => 1, 'post_cats' => 1, 'link_cats' => 1 ); |
| 853 |
add_option( 'stats_mostlimit', 10, 'Stats Most Limit' ); |
| 854 |
add_option( 'stats_display', $stats_display, 'Stats To Display' ); |
| 855 |
add_option( 'stats_url', esc_url( get_option( 'siteurl' ) ) .'/stats/', 'Stats URL' ); |
| 856 |
} |