| 1 |
<?php |
| 2 |
/************************************************************* |
| 3 |
* |
| 4 |
* stats.class.php |
| 5 |
* |
| 6 |
* Get Site Stats |
| 7 |
* |
| 8 |
* |
| 9 |
* Copyright (c) 2011 Prelovac Media |
| 10 |
* www.prelovac.com |
| 11 |
**************************************************************/ |
| 12 |
|
| 13 |
|
| 14 |
class MMB_Stats extends MMB_Core |
| 15 |
{ |
| 16 |
function __construct() |
| 17 |
{ |
| 18 |
parent::__construct(); |
| 19 |
} |
| 20 |
|
| 21 |
/************************************************************* |
| 22 |
* FACADE functions |
| 23 |
* (functions to be called after a remote call from Master) |
| 24 |
**************************************************************/ |
| 25 |
|
| 26 |
function get($params) |
| 27 |
{ |
| 28 |
$num = extract($params); |
| 29 |
|
| 30 |
if($refresh == 'transient'){ |
| 31 |
include_once(ABSPATH.'wp-includes/update.php'); |
| 32 |
@wp_update_plugins(); |
| 33 |
@wp_update_themes(); |
| 34 |
@wp_version_check(); |
| 35 |
} |
| 36 |
|
| 37 |
global $wpdb, $mmb_wp_version, $mmb_plugin_dir, $wp_version; |
| 38 |
$stats = array(); |
| 39 |
|
| 40 |
//define constants |
| 41 |
$num_pending_comments = 20; |
| 42 |
$num_approved_comments = 3; |
| 43 |
$num_spam_comments = 0; |
| 44 |
$num_draft_comments = 0; |
| 45 |
$num_trash_comments = 0; |
| 46 |
|
| 47 |
include_once(ABSPATH . '/wp-admin/includes/update.php'); |
| 48 |
|
| 49 |
$stats['worker_version'] = MMB_WORKER_VERSION; |
| 50 |
$stats['wordpress_version'] = $wp_version; |
| 51 |
$stats['wp_multisite'] = $this->mmb_multisite; |
| 52 |
$stats['php_version'] = phpversion(); |
| 53 |
$stats['mysql_version'] = $wpdb->db_version(); |
| 54 |
|
| 55 |
if(function_exists('get_core_updates')) { |
| 56 |
$updates = get_core_updates(); |
| 57 |
if(!empty($updates)){ |
| 58 |
$current_transient = $updates[0]; |
| 59 |
if ($current_transient->response == "development" || version_compare($wp_version, $current_transient->current, '<')) { |
| 60 |
$current_transient->current_version = $wp_version; |
| 61 |
$stats['core_updates'] = $current_transient; |
| 62 |
} |
| 63 |
else $stats['core_updates'] = false; |
| 64 |
} |
| 65 |
else $stats['core_updates'] = false; |
| 66 |
} |
| 67 |
|
| 68 |
$mmb_user_hits = get_option('user_hit_count'); |
| 69 |
if (is_array($mmb_user_hits)) { |
| 70 |
end($mmb_user_hits); |
| 71 |
$last_key_date = key($mmb_user_hits); |
| 72 |
$current_date = date('Y-m-d'); |
| 73 |
if ($last_key_date != $curent_date) |
| 74 |
$this->set_hit_count(true); |
| 75 |
} |
| 76 |
$stats['hit_counter'] = get_option('user_hit_count'); |
| 77 |
|
| 78 |
$this->get_installer_instance(); |
| 79 |
$stats['upgradable_themes'] = $this->installer_instance->get_upgradable_themes(); |
| 80 |
$stats['upgradable_plugins'] = $this->installer_instance->get_upgradable_plugins(); |
| 81 |
|
| 82 |
$pending_comments = get_comments('status=hold&number=' . $num_pending_comments); |
| 83 |
foreach ($pending_comments as &$comment) { |
| 84 |
$commented_post = get_post($comment->comment_post_ID); |
| 85 |
$comment->post_title = $commented_post->post_title; |
| 86 |
} |
| 87 |
$stats['comments']['pending'] = $pending_comments; |
| 88 |
|
| 89 |
|
| 90 |
$approved_comments = get_comments('status=approve&number=' . $num_approved_comments); |
| 91 |
foreach ($approved_comments as &$comment) { |
| 92 |
$commented_post = get_post($comment->comment_post_ID); |
| 93 |
$comment->post_title = $commented_post->post_title; |
| 94 |
} |
| 95 |
$stats['comments']['approved'] = $approved_comments; |
| 96 |
|
| 97 |
|
| 98 |
$all_posts = get_posts('post_status=publish&numberposts=3&orderby=modified&order=desc'); |
| 99 |
$recent_posts = array(); |
| 100 |
|
| 101 |
foreach ($all_posts as $id => $recent_post) { |
| 102 |
$recent = new stdClass(); |
| 103 |
$recent->post_permalink = get_permalink($recent_post->ID); |
| 104 |
$recent->ID = $recent_post->ID; |
| 105 |
$recent->post_date = $recent_post->post_date; |
| 106 |
$recent->post_title = $recent_post->post_title; |
| 107 |
$recent->post_modified = $recent_post->post_modified; |
| 108 |
$recent->comment_count = $recent_post->comment_count; |
| 109 |
$recent_posts[] = $recent; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
$all_drafts = get_posts('post_status=draft&numberposts=20&orderby=modified&order=desc'); |
| 114 |
$recent_drafts = array(); |
| 115 |
foreach ($all_drafts as $id => $recent_draft) { |
| 116 |
$recent = new stdClass(); |
| 117 |
$recent->post_permalink = get_permalink($recent_draft->ID); |
| 118 |
$recent->ID = $recent_draft->ID; |
| 119 |
$recent->post_date = $recent_draft->post_date; |
| 120 |
$recent->post_title = $recent_draft->post_title; |
| 121 |
$recent->post_modified = $recent_draft->post_modified; |
| 122 |
|
| 123 |
$recent_drafts[] = $recent; |
| 124 |
} |
| 125 |
|
| 126 |
$all_scheduled = get_posts('post_status=future&numberposts=20&orderby=post_date&order=desc'); |
| 127 |
$scheduled_posts = array(); |
| 128 |
foreach ($all_scheduled as $id => $scheduled) { |
| 129 |
$recent = new stdClass(); |
| 130 |
$recent->post_permalink = get_permalink($scheduled->ID); |
| 131 |
$recent->ID = $scheduled->ID; |
| 132 |
$recent->post_date = $scheduled->post_date; |
| 133 |
$recent->post_title = $scheduled->post_title; |
| 134 |
$recent->post_modified = $scheduled->post_modified; |
| 135 |
|
| 136 |
$scheduled_posts[] = $recent; |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
$all_pages_published = get_pages('post_status=publish&numberposts=3&orderby=modified&order=desc'); |
| 141 |
$recent_pages_published = array(); |
| 142 |
foreach ((array)$all_pages_published as $id => $recent_page_published) { |
| 143 |
$recent = new stdClass(); |
| 144 |
$recent->post_permalink = get_permalink($recent_page_published->ID); |
| 145 |
|
| 146 |
$recent->ID = $recent_page_published->ID; |
| 147 |
$recent->post_date = $recent_page_published->post_date; |
| 148 |
$recent->post_title = $recent_page_published->post_title; |
| 149 |
$recent->post_modified = $recent_page_published->post_modified; |
| 150 |
|
| 151 |
$recent_posts[] = $recent; |
| 152 |
} |
| 153 |
usort($recent_posts, 'cmp_posts_worker'); |
| 154 |
$stats['posts'] = array_slice($recent_posts, 0, 20); |
| 155 |
|
| 156 |
$all_pages_drafts = get_pages('post_status=draft&numberposts=20&orderby=modified&order=desc'); |
| 157 |
$recent_pages_drafts = array(); |
| 158 |
foreach ((array)$all_pages_drafts as $id => $recent_pages_draft) { |
| 159 |
$recent = new stdClass(); |
| 160 |
$recent->post_permalink = get_permalink($recent_pages_draft->ID); |
| 161 |
$recent->ID = $recent_pages_draft->ID; |
| 162 |
$recent->post_date = $recent_pages_draft->post_date; |
| 163 |
$recent->post_title = $recent_pages_draft->post_title; |
| 164 |
$recent->post_modified = $recent_pages_draft->post_modified; |
| 165 |
|
| 166 |
$recent_drafts[] = $recent; |
| 167 |
} |
| 168 |
usort($recent_drafts, 'cmp_posts_worker'); |
| 169 |
$stats['drafts'] = array_slice($recent_drafts, 0, 20); |
| 170 |
|
| 171 |
|
| 172 |
$pages_scheduled = get_pages('post_status=future&numberposts=20&orderby=modified&order=desc'); |
| 173 |
$recent_pages_drafts = array(); |
| 174 |
foreach ((array)$pages_scheduled as $id => $scheduled) { |
| 175 |
$recent = new stdClass(); |
| 176 |
$recent->post_permalink = get_permalink($scheduled->ID); |
| 177 |
$recent->ID = $scheduled->ID; |
| 178 |
$recent->post_date = $scheduled->post_date; |
| 179 |
$recent->post_title = $scheduled->post_title; |
| 180 |
$recent->post_modified = $scheduled->post_modified; |
| 181 |
|
| 182 |
$scheduled_posts[] = $recent; |
| 183 |
} |
| 184 |
usort($scheduled_posts, 'cmp_posts_worker'); |
| 185 |
$stats['scheduled'] = array_slice($scheduled_posts, 0, 20); |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
if (!function_exists('get_filesystem_method')) |
| 190 |
include_once(ABSPATH . 'wp-admin/includes/file.php'); |
| 191 |
|
| 192 |
$stats['writable'] = $this->is_server_writable(); |
| 193 |
|
| 194 |
$stats['backups'] = $this->get_backups(); |
| 195 |
|
| 196 |
$stats = apply_filters('mmb_stats_filter', $stats); |
| 197 |
return $stats; |
| 198 |
} |
| 199 |
|
| 200 |
function get_stats_notification($params) |
| 201 |
{ |
| 202 |
|
| 203 |
global $mmb_wp_version, $mmb_plugin_dir; |
| 204 |
$stats = array(); |
| 205 |
|
| 206 |
//define constants |
| 207 |
$num_pending_comments = 1000; |
| 208 |
|
| 209 |
|
| 210 |
require_once(ABSPATH . '/wp-admin/includes/update.php'); |
| 211 |
|
| 212 |
$stats['worker_version'] = MMB_WORKER_VERSION; |
| 213 |
$stats['wordpress_version'] = $mmb_wp_version; |
| 214 |
|
| 215 |
$updates = $this->mmb_get_transient('update_core'); |
| 216 |
|
| 217 |
if ($updates->updates[0]->response == 'development' || version_compare($mmb_wp_version, $updates->updates[0]->current, '<')) { |
| 218 |
$updates->updates[0]->current_version = $mmb_wp_version; |
| 219 |
$stats['core_updates'] = $updates->updates[0]; |
| 220 |
} else |
| 221 |
$stats['core_updates'] = false; |
| 222 |
|
| 223 |
$mmb_user_hits = get_option('user_hit_count'); |
| 224 |
if (is_array($mmb_user_hits)) { |
| 225 |
end($mmb_user_hits); |
| 226 |
$last_key_date = key($mmb_user_hits); |
| 227 |
$current_date = date('Y-m-d'); |
| 228 |
if ($last_key_date != $curent_date) |
| 229 |
$this->set_hit_count(true); |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
$this->get_theme_instance(); |
| 234 |
$this->get_plugin_instance(); |
| 235 |
$stats['upgradable_themes'] = $this->theme_instance->get_upgradable_themes(); |
| 236 |
$stats['upgradable_plugins'] = $this->plugin_instance->get_upgradable_plugins(); |
| 237 |
|
| 238 |
$pending_comments = get_comments('status=hold&number=' . $num_pending_comments); |
| 239 |
|
| 240 |
$stats['comments_pending'] = count($pending_comments); |
| 241 |
|
| 242 |
return $stats; |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
function get_comments_stats(){ |
| 247 |
$num_pending_comments = 3; |
| 248 |
$num_approved_comments = 3; |
| 249 |
$pending_comments = get_comments('status=hold&number=' . $num_pending_comments); |
| 250 |
foreach ($pending_comments as &$comment) { |
| 251 |
$commented_post = get_post($comment->comment_post_ID); |
| 252 |
$comment->post_title = $commented_post->post_title; |
| 253 |
} |
| 254 |
$stats['comments']['pending'] = $pending_comments; |
| 255 |
|
| 256 |
|
| 257 |
$approved_comments = get_comments('status=approve&number=' . $num_approved_comments); |
| 258 |
foreach ($approved_comments as &$comment) { |
| 259 |
$commented_post = get_post($comment->comment_post_ID); |
| 260 |
$comment->post_title = $commented_post->post_title; |
| 261 |
} |
| 262 |
$stats['comments']['approved'] = $approved_comments; |
| 263 |
|
| 264 |
return $stats; |
| 265 |
} |
| 266 |
function get_initial_stats() |
| 267 |
{ |
| 268 |
global $mmb_plugin_dir; |
| 269 |
|
| 270 |
$stats = array(); |
| 271 |
|
| 272 |
$stats['email'] = get_option('admin_email'); |
| 273 |
$stats['no_openssl'] = $this->get_random_signature(); |
| 274 |
$stats['content_path'] = WP_CONTENT_DIR; |
| 275 |
$stats['worker_path'] = $mmb_plugin_dir; |
| 276 |
$stats['worker_version'] = MMB_WORKER_VERSION; |
| 277 |
$stats['site_title'] = get_bloginfo('name'); |
| 278 |
$stats['site_tagline'] = get_bloginfo('description'); |
| 279 |
$stats['site_home'] = get_option('home'); |
| 280 |
|
| 281 |
|
| 282 |
if (!function_exists('get_filesystem_method')) |
| 283 |
include_once(ABSPATH . 'wp-admin/includes/file.php'); |
| 284 |
|
| 285 |
$stats['writable'] = $this->is_server_writable(); |
| 286 |
|
| 287 |
return $stats; |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
function set_hit_count($fix_count = false) |
| 293 |
{ |
| 294 |
if ($fix_count || (!is_admin() && !MMB_Stats::detect_bots())) { |
| 295 |
$date = date('Y-m-d'); |
| 296 |
$user_hit_count = (array) get_option('user_hit_count'); |
| 297 |
if (!$user_hit_count) { |
| 298 |
$user_hit_count[$date] = 1; |
| 299 |
update_option('user_hit_count', $user_hit_count); |
| 300 |
} else { |
| 301 |
$dated_keys = array_keys($user_hit_count); |
| 302 |
$last_visit_date = $dated_keys[count($dated_keys) - 1]; |
| 303 |
|
| 304 |
$days = intval((strtotime($date) - strtotime($last_visit_date)) / 60 / 60 / 24); |
| 305 |
|
| 306 |
if ($days > 1) { |
| 307 |
$date_to_add = date('Y-m-d', strtotime($last_visit_date)); |
| 308 |
|
| 309 |
for ($i = 1; $i < $days; $i++) { |
| 310 |
if (count($user_hit_count) > 14) { |
| 311 |
$shifted = @array_shift($user_hit_count); |
| 312 |
} |
| 313 |
|
| 314 |
$next_key = strtotime('+1 day', strtotime($date_to_add)); |
| 315 |
if ($next_key == $date) { |
| 316 |
break; |
| 317 |
} else { |
| 318 |
$user_hit_count[$next_key] = 0; |
| 319 |
} |
| 320 |
} |
| 321 |
|
| 322 |
} |
| 323 |
|
| 324 |
if (!isset($user_hit_count[$date])) { |
| 325 |
$user_hit_count[$date] = 0; |
| 326 |
} |
| 327 |
if (!$fix_count) |
| 328 |
$user_hit_count[$date] = ((int)$user_hit_count[$date] ) + 1; |
| 329 |
|
| 330 |
if (count($user_hit_count) > 14) { |
| 331 |
$shifted = @array_shift($user_hit_count); |
| 332 |
} |
| 333 |
|
| 334 |
update_option('user_hit_count', $user_hit_count); |
| 335 |
|
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
function get_hit_count() |
| 341 |
{ |
| 342 |
// Check if there are no hits on last key date |
| 343 |
$mmb_user_hits = get_option('user_hit_count'); |
| 344 |
if (is_array($mmb_user_hits)) { |
| 345 |
end($mmb_user_hits); |
| 346 |
$last_key_date = key($mmb_user_hits); |
| 347 |
$current_date = date('Y-m-d'); |
| 348 |
if ($last_key_date != $curent_date) |
| 349 |
$this->set_hit_count(true); |
| 350 |
} |
| 351 |
|
| 352 |
return get_option('user_hit_count'); |
| 353 |
} |
| 354 |
|
| 355 |
function detect_bots() |
| 356 |
{ |
| 357 |
$agent = $_SERVER['HTTP_USER_AGENT']; |
| 358 |
|
| 359 |
if ($agent == '') |
| 360 |
return false; |
| 361 |
|
| 362 |
$bot_list = array( |
| 363 |
"Teoma", |
| 364 |
"alexa", |
| 365 |
"froogle", |
| 366 |
"Gigabot", |
| 367 |
"inktomi", |
| 368 |
"looksmart", |
| 369 |
"URL_Spider_SQL", |
| 370 |
"Firefly", |
| 371 |
"NationalDirectory", |
| 372 |
"Ask Jeeves", |
| 373 |
"TECNOSEEK", |
| 374 |
"InfoSeek", |
| 375 |
"WebFindBot", |
| 376 |
"girafabot", |
| 377 |
"crawler", |
| 378 |
"www.galaxy.com", |
| 379 |
"Googlebot", |
| 380 |
"Scooter", |
| 381 |
"Slurp", |
| 382 |
"msnbot", |
| 383 |
"appie", |
| 384 |
"FAST", |
| 385 |
"WebBug", |
| 386 |
"Spade", |
| 387 |
"ZyBorg", |
| 388 |
"rabaz", |
| 389 |
"Baiduspider", |
| 390 |
"Feedfetcher-Google", |
| 391 |
"TechnoratiSnoop", |
| 392 |
"Rankivabot", |
| 393 |
"Mediapartners-Google", |
| 394 |
"Sogou web spider", |
| 395 |
"WebAlta Crawler", |
| 396 |
"aolserver" |
| 397 |
); |
| 398 |
|
| 399 |
$thebot = ''; |
| 400 |
foreach ($bot_list as $bot) { |
| 401 |
if ((boolean)strpos($bot, $agent)) { |
| 402 |
$thebot = $bot; |
| 403 |
break; |
| 404 |
} |
| 405 |
} |
| 406 |
|
| 407 |
if ($thebot != '') { |
| 408 |
return $thebot; |
| 409 |
} else |
| 410 |
return false; |
| 411 |
} |
| 412 |
|
| 413 |
function get_backups() |
| 414 |
{ |
| 415 |
$worker_options = get_option('mmb-worker'); |
| 416 |
//$backup_file = $worker_options['backups'][$type]['path']; |
| 417 |
return $worker_options['backups']; |
| 418 |
} |
| 419 |
|
| 420 |
} |
| 421 |
|
| 422 |
function cmp_posts_worker($a, $b) |
| 423 |
{ |
| 424 |
return ($a->post_modified < $b->post_modified); |
| 425 |
} |
| 426 |
|
| 427 |
|
| 428 |
?> |