| 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 |
if (basename($_SERVER['SCRIPT_FILENAME']) == "stats.class.php"): |
| 13 |
exit; |
| 14 |
endif; |
| 15 |
|
| 16 |
class MMB_Stats extends MMB_Core |
| 17 |
{ |
| 18 |
function __construct() |
| 19 |
{ |
| 20 |
parent::__construct(); |
| 21 |
} |
| 22 |
|
| 23 |
/************************************************************* |
| 24 |
* FACADE functions |
| 25 |
* (functions to be called after a remote call from Master) |
| 26 |
**************************************************************/ |
| 27 |
|
| 28 |
function get_core_update($stats, $options = array()) |
| 29 |
{ |
| 30 |
global $wp_version; |
| 31 |
|
| 32 |
if (isset($options['core']) && $options['core']) { |
| 33 |
$core = $this->mmb_get_transient('update_core'); |
| 34 |
if (isset($core->updates) && !empty($core->updates)) { |
| 35 |
$current_transient = $core->updates[0]; |
| 36 |
if ($current_transient->response == "development" || version_compare($wp_version, $current_transient->current, '<')) { |
| 37 |
$current_transient->current_version = $wp_version; |
| 38 |
$stats['core_updates'] = $current_transient; |
| 39 |
} else |
| 40 |
$stats['core_updates'] = false; |
| 41 |
} else |
| 42 |
$stats['core_updates'] = false; |
| 43 |
} |
| 44 |
|
| 45 |
return $stats; |
| 46 |
} |
| 47 |
|
| 48 |
function get_hit_counter($stats, $options = array()) |
| 49 |
{ |
| 50 |
$mmb_user_hits = get_option('user_hit_count'); |
| 51 |
if (is_array($mmb_user_hits)) { |
| 52 |
end($mmb_user_hits); |
| 53 |
$last_key_date = key($mmb_user_hits); |
| 54 |
$current_date = date('Y-m-d'); |
| 55 |
if ($last_key_date != $current_date) |
| 56 |
$this->set_hit_count(true); |
| 57 |
} |
| 58 |
$stats['hit_counter'] = get_option('user_hit_count'); |
| 59 |
|
| 60 |
return $stats; |
| 61 |
} |
| 62 |
|
| 63 |
function get_comments($stats, $options = array()) |
| 64 |
{ |
| 65 |
$nposts = isset($options['numberposts']) ? (int) $options['numberposts'] : 20; |
| 66 |
$trimlen = isset($options['trimcontent']) ? (int) $options['trimcontent'] : 200; |
| 67 |
|
| 68 |
if ($nposts) { |
| 69 |
$comments = get_comments('status=hold&number=' . $nposts); |
| 70 |
if (!empty($comments)) { |
| 71 |
foreach ($comments as &$comment) { |
| 72 |
$commented_post = get_post($comment->comment_post_ID); |
| 73 |
$comment->post_title = $commented_post->post_title; |
| 74 |
$comment->comment_content = $this->trim_content($comment->comment_content, $trimlen); |
| 75 |
unset($comment->comment_author_url); |
| 76 |
unset($comment->comment_author_email); |
| 77 |
unset($comment->comment_author_IP); |
| 78 |
unset($comment->comment_date_gmt); |
| 79 |
unset($comment->comment_karma); |
| 80 |
unset($comment->comment_agent); |
| 81 |
unset($comment->comment_type); |
| 82 |
unset($comment->comment_parent); |
| 83 |
unset($comment->user_id); |
| 84 |
} |
| 85 |
$stats['comments']['pending'] = $comments; |
| 86 |
} |
| 87 |
|
| 88 |
$comments = get_comments('status=approve&number=' . $nposts); |
| 89 |
if (!empty($comments)) { |
| 90 |
foreach ($comments as &$comment) { |
| 91 |
$commented_post = get_post($comment->comment_post_ID); |
| 92 |
$comment->post_title = $commented_post->post_title; |
| 93 |
$comment->comment_content = $this->trim_content($comment->comment_content, $trimlen); |
| 94 |
unset($comment->comment_author_url); |
| 95 |
unset($comment->comment_author_email); |
| 96 |
unset($comment->comment_author_IP); |
| 97 |
unset($comment->comment_date_gmt); |
| 98 |
unset($comment->comment_karma); |
| 99 |
unset($comment->comment_agent); |
| 100 |
unset($comment->comment_type); |
| 101 |
unset($comment->comment_parent); |
| 102 |
unset($comment->user_id); |
| 103 |
} |
| 104 |
$stats['comments']['approved'] = $comments; |
| 105 |
} |
| 106 |
} |
| 107 |
return $stats; |
| 108 |
} |
| 109 |
|
| 110 |
function get_posts($stats, $options = array()) |
| 111 |
{ |
| 112 |
$nposts = isset($options['numberposts']) ? (int) $options['numberposts'] : 20; |
| 113 |
|
| 114 |
if ($nposts) { |
| 115 |
$posts = get_posts('post_status=publish&numberposts=' . $nposts . '&orderby=post_date&order=desc'); |
| 116 |
$recent_posts = array(); |
| 117 |
if (!empty($posts)) { |
| 118 |
foreach ($posts as $id => $recent_post) { |
| 119 |
$recent = new stdClass(); |
| 120 |
$recent->post_permalink = get_permalink($recent_post->ID); |
| 121 |
$recent->ID = $recent_post->ID; |
| 122 |
$recent->post_date = $recent_post->post_date; |
| 123 |
$recent->post_title = $recent_post->post_title; |
| 124 |
$recent->post_type = $recent_post->post_type; |
| 125 |
$recent->comment_count = (int) $recent_post->comment_count; |
| 126 |
$recent_posts[] = $recent; |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
$posts = get_pages('post_status=publish&numberposts=' . $nposts . '&orderby=post_date&order=desc'); |
| 131 |
$recent_pages_published = array(); |
| 132 |
if (!empty($posts)) { |
| 133 |
foreach ((array) $posts as $id => $recent_page_published) { |
| 134 |
$recent = new stdClass(); |
| 135 |
$recent->post_permalink = get_permalink($recent_page_published->ID); |
| 136 |
$recent->post_type = $recent_page_published->post_type; |
| 137 |
$recent->ID = $recent_page_published->ID; |
| 138 |
$recent->post_date = $recent_page_published->post_date; |
| 139 |
$recent->post_title = $recent_page_published->post_title; |
| 140 |
|
| 141 |
$recent_posts[] = $recent; |
| 142 |
} |
| 143 |
} |
| 144 |
if (!empty($recent_posts)) { |
| 145 |
usort($recent_posts, array( |
| 146 |
$this, |
| 147 |
'cmp_posts_worker' |
| 148 |
)); |
| 149 |
$stats['posts'] = array_slice($recent_posts, 0, $nposts); |
| 150 |
} |
| 151 |
} |
| 152 |
return $stats; |
| 153 |
} |
| 154 |
|
| 155 |
function get_drafts($stats, $options = array()) |
| 156 |
{ |
| 157 |
$nposts = isset($options['numberposts']) ? (int) $options['numberposts'] : 20; |
| 158 |
|
| 159 |
if ($nposts) { |
| 160 |
$drafts = get_posts('post_status=draft&numberposts=' . $nposts . '&orderby=post_date&order=desc'); |
| 161 |
$recent_drafts = array(); |
| 162 |
if (!empty($drafts)) { |
| 163 |
foreach ($drafts as $id => $recent_draft) { |
| 164 |
$recent = new stdClass(); |
| 165 |
$recent->post_permalink = get_permalink($recent_draft->ID); |
| 166 |
$recent->post_type = $recent_draft->post_type; |
| 167 |
$recent->ID = $recent_draft->ID; |
| 168 |
$recent->post_date = $recent_draft->post_date; |
| 169 |
$recent->post_title = $recent_draft->post_title; |
| 170 |
|
| 171 |
$recent_drafts[] = $recent; |
| 172 |
} |
| 173 |
} |
| 174 |
$drafts = get_pages('post_status=draft&numberposts=' . $nposts . '&orderby=post_date&order=desc'); |
| 175 |
$recent_pages_drafts = array(); |
| 176 |
if (!empty($drafts)) { |
| 177 |
foreach ((array) $drafts as $id => $recent_pages_draft) { |
| 178 |
$recent = new stdClass(); |
| 179 |
$recent->post_permalink = get_permalink($recent_pages_draft->ID); |
| 180 |
$recent->ID = $recent_pages_draft->ID; |
| 181 |
$recent->post_type = $recent_pages_draft->post_type; |
| 182 |
$recent->post_date = $recent_pages_draft->post_date; |
| 183 |
$recent->post_title = $recent_pages_draft->post_title; |
| 184 |
|
| 185 |
$recent_drafts[] = $recent; |
| 186 |
} |
| 187 |
} |
| 188 |
if (!empty($recent_drafts)) { |
| 189 |
usort($recent_drafts, array( |
| 190 |
$this, |
| 191 |
'cmp_posts_worker' |
| 192 |
)); |
| 193 |
$stats['drafts'] = array_slice($recent_drafts, 0, $nposts); |
| 194 |
} |
| 195 |
} |
| 196 |
return $stats; |
| 197 |
} |
| 198 |
|
| 199 |
function get_scheduled($stats, $options = array()) |
| 200 |
{ |
| 201 |
$nposts = isset($options['numberposts']) ? (int) $options['numberposts'] : 20; |
| 202 |
|
| 203 |
if ($nposts) { |
| 204 |
$scheduled = get_posts('post_status=future&numberposts=' . $nposts . '&orderby=post_date&order=desc'); |
| 205 |
$scheduled_posts = array(); |
| 206 |
if (!empty($scheduled)) { |
| 207 |
foreach ($scheduled as $id => $scheduled) { |
| 208 |
$recent = new stdClass(); |
| 209 |
$recent->post_permalink = get_permalink($scheduled->ID); |
| 210 |
$recent->ID = $scheduled->ID; |
| 211 |
$recent->post_date = $scheduled->post_date; |
| 212 |
$recent->post_type = $scheduled->post_type; |
| 213 |
$recent->post_title = $scheduled->post_title; |
| 214 |
$scheduled_posts[] = $recent; |
| 215 |
} |
| 216 |
} |
| 217 |
$scheduled = get_pages('post_status=future&numberposts=' . $nposts . '&orderby=post_date&order=desc'); |
| 218 |
$recent_pages_drafts = array(); |
| 219 |
if (!empty($scheduled)) { |
| 220 |
foreach ((array) $scheduled as $id => $scheduled) { |
| 221 |
$recent = new stdClass(); |
| 222 |
$recent->post_permalink = get_permalink($scheduled->ID); |
| 223 |
$recent->ID = $scheduled->ID; |
| 224 |
$recent->post_type = $scheduled->post_type; |
| 225 |
$recent->post_date = $scheduled->post_date; |
| 226 |
$recent->post_title = $scheduled->post_title; |
| 227 |
|
| 228 |
$scheduled_posts[] = $recent; |
| 229 |
} |
| 230 |
} |
| 231 |
if (!empty($scheduled_posts)) { |
| 232 |
usort($scheduled_posts, array( |
| 233 |
$this, |
| 234 |
'cmp_posts_worker' |
| 235 |
)); |
| 236 |
$stats['scheduled'] = array_slice($scheduled_posts, 0, $nposts); |
| 237 |
} |
| 238 |
} |
| 239 |
return $stats; |
| 240 |
} |
| 241 |
|
| 242 |
function get_backups($stats, $options = array()) |
| 243 |
{ |
| 244 |
$stats['mwp_backups'] = $this->get_backup_instance()->get_backup_stats(); |
| 245 |
$stats['mwp_next_backups'] = $this->get_backup_instance()->get_next_schedules(); |
| 246 |
|
| 247 |
return $stats; |
| 248 |
} |
| 249 |
|
| 250 |
function get_backup_req($stats = array(), $options = array()) |
| 251 |
{ |
| 252 |
$stats['mwp_backups'] = $this->get_backup_instance()->get_backup_stats(); |
| 253 |
$stats['mwp_next_backups'] = $this->get_backup_instance()->get_next_schedules(); |
| 254 |
$stats['mwp_backup_req'] = $this->get_backup_instance()->check_backup_compat(); |
| 255 |
|
| 256 |
return $stats; |
| 257 |
} |
| 258 |
|
| 259 |
function get_updates($stats, $options = array()) |
| 260 |
{ |
| 261 |
$upgrades = false; |
| 262 |
$premium = array(); |
| 263 |
if (isset($options['premium']) && $options['premium']) { |
| 264 |
$premium_updates = array(); |
| 265 |
$upgrades = apply_filters('mwp_premium_update_notification', $premium_updates); |
| 266 |
if (!empty($upgrades)) { |
| 267 |
foreach ($upgrades as $data) { |
| 268 |
if (isset($data['Name'])) |
| 269 |
$premium[] = $data['Name']; |
| 270 |
} |
| 271 |
$stats['premium_updates'] = $upgrades; |
| 272 |
$upgrades = false; |
| 273 |
} |
| 274 |
} |
| 275 |
if (isset($options['themes']) && $options['themes']) { |
| 276 |
$this->get_installer_instance(); |
| 277 |
$upgrades = $this->installer_instance->get_upgradable_themes($premium); |
| 278 |
if (!empty($upgrades)) { |
| 279 |
$stats['upgradable_themes'] = $upgrades; |
| 280 |
$upgrades = false; |
| 281 |
} |
| 282 |
} |
| 283 |
|
| 284 |
if (isset($options['plugins']) && $options['plugins']) { |
| 285 |
$this->get_installer_instance(); |
| 286 |
$upgrades = $this->installer_instance->get_upgradable_plugins($premium); |
| 287 |
if (!empty($upgrades)) { |
| 288 |
$stats['upgradable_plugins'] = $upgrades; |
| 289 |
$upgrades = false; |
| 290 |
} |
| 291 |
} |
| 292 |
|
| 293 |
return $stats; |
| 294 |
} |
| 295 |
|
| 296 |
function get_errors($stats, $options = array()) |
| 297 |
{ |
| 298 |
$period = isset($options['days']) ? (int) $options['days'] * 86400 : 86400; |
| 299 |
$maxerrors = isset($options['max']) ? (int) $options['max'] : 20; |
| 300 |
$errors = array(); |
| 301 |
if (isset($options['get']) && $options['get'] == true) { |
| 302 |
if (function_exists('ini_get')) { |
| 303 |
$logpath = ini_get('error_log'); |
| 304 |
if (!empty($logpath) && file_exists($logpath)) { |
| 305 |
$logfile = @fopen($logpath, 'r'); |
| 306 |
if ($logfile && filesize($logpath) > 0) { |
| 307 |
$maxlines = 1; |
| 308 |
$linesize = -4096; |
| 309 |
$lines = array(); |
| 310 |
$line = true; |
| 311 |
while ($line !== false) { |
| 312 |
if (fseek($logfile, ($maxlines * $linesize), SEEK_END) !== -1) { |
| 313 |
$maxlines++; |
| 314 |
if ($line) { |
| 315 |
$line = fread($logfile, ($linesize * -1)) . $line; |
| 316 |
|
| 317 |
foreach ((array) preg_split("/(\r|\n|\r\n)/U", $line) as $l) { |
| 318 |
preg_match('/\[(.*)\]/Ui', $l, $match); |
| 319 |
if (!empty($match)) { |
| 320 |
$key = str_replace($match[0], '', $l); |
| 321 |
if (!isset($errors[$key])) { |
| 322 |
$errors[$key] = 1; |
| 323 |
} else { |
| 324 |
$errors[$key] = $errors[$key] + 1; |
| 325 |
} |
| 326 |
|
| 327 |
if ((strtotime($match[1]) < ((int) time() - $period)) || count($errors) >= $maxerrors) { |
| 328 |
$line = false; |
| 329 |
break; |
| 330 |
} |
| 331 |
} |
| 332 |
} |
| 333 |
} |
| 334 |
} else |
| 335 |
break; |
| 336 |
} |
| 337 |
} |
| 338 |
if (!empty($errors)) { |
| 339 |
$stats['errors'] = $errors; |
| 340 |
$stats['logpath'] = $logpath; |
| 341 |
$stats['logsize'] = @filesize($logpath); |
| 342 |
} |
| 343 |
} |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
return $stats; |
| 348 |
} |
| 349 |
|
| 350 |
function pre_init_stats($params) |
| 351 |
{ |
| 352 |
global $_mmb_item_filter; |
| 353 |
|
| 354 |
include_once(ABSPATH . 'wp-includes/update.php'); |
| 355 |
include_once(ABSPATH . '/wp-admin/includes/update.php'); |
| 356 |
|
| 357 |
$stats = $this->mmb_parse_action_params('pre_init_stats', $params, $this); |
| 358 |
$num = extract($params); |
| 359 |
|
| 360 |
if (function_exists( 'w3tc_pgcache_flush' ) || function_exists( 'wp_cache_clear_cache' ) ) { |
| 361 |
$this->mmb_delete_transient('update_core'); |
| 362 |
$this->mmb_delete_transient('update_plugins'); |
| 363 |
$this->mmb_delete_transient('update_themes'); |
| 364 |
@wp_version_check(); |
| 365 |
@wp_update_plugins(); |
| 366 |
@wp_update_themes(); |
| 367 |
} |
| 368 |
|
| 369 |
if ($refresh == 'transient') { |
| 370 |
$current = $this->mmb_get_transient('update_core'); |
| 371 |
if (isset($current->last_checked) || get_option('mmb_forcerefresh')) { |
| 372 |
update_option('mmb_forcerefresh', false); |
| 373 |
if (time() - $current->last_checked > 7200) { |
| 374 |
@wp_version_check(); |
| 375 |
@wp_update_plugins(); |
| 376 |
@wp_update_themes(); |
| 377 |
} |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
global $wpdb, $mmb_wp_version, $mmb_plugin_dir, $wp_version, $wp_local_package; |
| 382 |
|
| 383 |
$stats['worker_version'] = MMB_WORKER_VERSION; |
| 384 |
$stats['wordpress_version'] = $wp_version; |
| 385 |
$stats['wordpress_locale_pckg'] = $wp_local_package; |
| 386 |
$stats['php_version'] = phpversion(); |
| 387 |
$stats['mysql_version'] = $wpdb->db_version(); |
| 388 |
$stats['wp_multisite'] = $this->mmb_multisite; |
| 389 |
$stats['network_install'] = $this->network_admin_install; |
| 390 |
|
| 391 |
if (!function_exists('get_filesystem_method')) |
| 392 |
include_once(ABSPATH . 'wp-admin/includes/file.php'); |
| 393 |
$mmode = get_option('mwp_maintenace_mode'); |
| 394 |
|
| 395 |
if (!empty($mmode) && isset($mmode['active']) && $mmode['active'] == true) { |
| 396 |
$stats['maintenance'] = true; |
| 397 |
} |
| 398 |
$stats['writable'] = $this->is_server_writable(); |
| 399 |
|
| 400 |
return $stats; |
| 401 |
} |
| 402 |
|
| 403 |
function get($params) |
| 404 |
{ |
| 405 |
global $wpdb, $mmb_wp_version, $mmb_plugin_dir, $_mmb_item_filter; |
| 406 |
|
| 407 |
include_once(ABSPATH . 'wp-includes/update.php'); |
| 408 |
include_once(ABSPATH . '/wp-admin/includes/update.php'); |
| 409 |
|
| 410 |
$stats = $this->mmb_parse_action_params('get', $params, $this); |
| 411 |
|
| 412 |
$update_check = array(); |
| 413 |
$num = extract($params); |
| 414 |
if ($refresh == 'transient') { |
| 415 |
$update_check = apply_filters('mwp_premium_update_check', $update_check); |
| 416 |
if (!empty($update_check)) { |
| 417 |
foreach ($update_check as $update) { |
| 418 |
if (is_array($update['callback'])) { |
| 419 |
$update_result = call_user_func(array( |
| 420 |
$update['callback'][0], |
| 421 |
$update['callback'][1] |
| 422 |
)); |
| 423 |
} else if (is_string($update['callback'])) { |
| 424 |
$update_result = call_user_func($update['callback']); |
| 425 |
} |
| 426 |
} |
| 427 |
} |
| 428 |
} |
| 429 |
|
| 430 |
if ($this->mmb_multisite) { |
| 431 |
$stats = $this->get_multisite($stats); |
| 432 |
} |
| 433 |
|
| 434 |
update_option('mmb_stats_filter', $params['item_filter']['get_stats']); |
| 435 |
$stats = apply_filters('mmb_stats_filter', $stats); |
| 436 |
|
| 437 |
return $stats; |
| 438 |
} |
| 439 |
|
| 440 |
function get_multisite($stats = array()) |
| 441 |
{ |
| 442 |
global $current_user, $wpdb; |
| 443 |
$user_blogs = get_blogs_of_user($current_user->ID); |
| 444 |
$network_blogs = $wpdb->get_results("select `blog_id`, `site_id` from `{$wpdb->blogs}`"); |
| 445 |
if ($this->network_admin_install == '1' && is_super_admin()) { |
| 446 |
if (!empty($network_blogs)) { |
| 447 |
$blogs = array(); |
| 448 |
foreach ($network_blogs as $details) { |
| 449 |
if ($details->site_id == $details->blog_id) |
| 450 |
continue; |
| 451 |
else { |
| 452 |
$data = get_blog_details($details->blog_id); |
| 453 |
if (in_array($details->blog_id, array_keys($user_blogs))) |
| 454 |
$stats['network_blogs'][] = $data->siteurl; |
| 455 |
else { |
| 456 |
$user = get_users(array( |
| 457 |
'blog_id' => $details->blog_id, |
| 458 |
'number' => 1 |
| 459 |
)); |
| 460 |
if (!empty($user)) |
| 461 |
$stats['other_blogs'][$data->siteurl] = $user[0]->user_login; |
| 462 |
} |
| 463 |
} |
| 464 |
} |
| 465 |
} |
| 466 |
} |
| 467 |
return $stats; |
| 468 |
} |
| 469 |
|
| 470 |
function get_comments_stats() |
| 471 |
{ |
| 472 |
$num_pending_comments = 3; |
| 473 |
$num_approved_comments = 3; |
| 474 |
$pending_comments = get_comments('status=hold&number=' . $num_pending_comments); |
| 475 |
foreach ($pending_comments as &$comment) { |
| 476 |
$commented_post = get_post($comment->comment_post_ID); |
| 477 |
$comment->post_title = $commented_post->post_title; |
| 478 |
} |
| 479 |
$stats['comments']['pending'] = $pending_comments; |
| 480 |
|
| 481 |
|
| 482 |
$approved_comments = get_comments('status=approve&number=' . $num_approved_comments); |
| 483 |
foreach ($approved_comments as &$comment) { |
| 484 |
$commented_post = get_post($comment->comment_post_ID); |
| 485 |
$comment->post_title = $commented_post->post_title; |
| 486 |
} |
| 487 |
$stats['comments']['approved'] = $approved_comments; |
| 488 |
|
| 489 |
return $stats; |
| 490 |
} |
| 491 |
|
| 492 |
function get_initial_stats() |
| 493 |
{ |
| 494 |
global $mmb_plugin_dir,$_mmb_item_filter;; |
| 495 |
|
| 496 |
$stats = array(); |
| 497 |
|
| 498 |
$stats['email'] = get_option('admin_email'); |
| 499 |
$stats['no_openssl'] = $this->get_random_signature(); |
| 500 |
$stats['content_path'] = WP_CONTENT_DIR; |
| 501 |
$stats['worker_path'] = $mmb_plugin_dir; |
| 502 |
$stats['worker_version'] = MMB_WORKER_VERSION; |
| 503 |
$stats['site_title'] = get_bloginfo('name'); |
| 504 |
$stats['site_tagline'] = get_bloginfo('description'); |
| 505 |
$stats['db_name'] = $this->get_active_db(); |
| 506 |
$stats['site_home'] = get_option('home'); |
| 507 |
$stats['admin_url'] = admin_url(); |
| 508 |
$stats['wp_multisite'] = $this->mmb_multisite; |
| 509 |
$stats['network_install'] = $this->network_admin_install; |
| 510 |
|
| 511 |
if ($this->mmb_multisite) { |
| 512 |
$details = get_blog_details($this->mmb_multisite); |
| 513 |
if (isset($details->site_id)) { |
| 514 |
$details = get_blog_details($details->site_id); |
| 515 |
if (isset($details->siteurl)) |
| 516 |
$stats['network_parent'] = $details->siteurl; |
| 517 |
} |
| 518 |
} |
| 519 |
if (!function_exists('get_filesystem_method')) |
| 520 |
include_once(ABSPATH . 'wp-admin/includes/file.php'); |
| 521 |
|
| 522 |
$stats['writable'] = $this->is_server_writable(); |
| 523 |
|
| 524 |
$_mmb_item_filter['pre_init_stats'] = array( 'core_update', 'hit_counter', 'comments', 'backups', 'posts', 'drafts', 'scheduled' ); |
| 525 |
$_mmb_item_filter['get'] = array( 'updates', 'errors' ); |
| 526 |
|
| 527 |
$filter = array( |
| 528 |
'refresh' => 'transient', |
| 529 |
'item_filter' => array( |
| 530 |
'get_stats' => array( |
| 531 |
array('updates', array('plugins' => true, 'themes' => true, 'premium' => true )), |
| 532 |
array('core_update', array('core' => true )), |
| 533 |
array('posts', array('numberposts' => 5 )), |
| 534 |
array('drafts', array('numberposts' => 5 )), |
| 535 |
array('scheduled', array('numberposts' => 5 )), |
| 536 |
array('hit_counter'), |
| 537 |
array('comments', array('numberposts' => 5 )), |
| 538 |
array('backups'), |
| 539 |
'plugins' => array('cleanup' => array( |
| 540 |
'overhead' => array(), |
| 541 |
'revisions' => array( 'num_to_keep' => 'r_5'), |
| 542 |
'spam' => array(), |
| 543 |
) |
| 544 |
), |
| 545 |
), |
| 546 |
) |
| 547 |
); |
| 548 |
|
| 549 |
$pre_init_data = $this->pre_init_stats($filter); |
| 550 |
$init_data = $this->get($filter); |
| 551 |
|
| 552 |
$stats['initial_stats']=array_merge($init_data, $pre_init_data); ; |
| 553 |
|
| 554 |
|
| 555 |
return $stats; |
| 556 |
} |
| 557 |
|
| 558 |
function get_active_db() |
| 559 |
{ |
| 560 |
global $wpdb; |
| 561 |
$sql = 'SELECT DATABASE() as db_name'; |
| 562 |
|
| 563 |
$sqlresult = $wpdb->get_row($sql); |
| 564 |
$active_db = $sqlresult->db_name; |
| 565 |
|
| 566 |
return $active_db; |
| 567 |
|
| 568 |
} |
| 569 |
|
| 570 |
static function set_hit_count($fix_count = false) |
| 571 |
{ |
| 572 |
global $mmb_core; |
| 573 |
$uptime_robot = array( |
| 574 |
"74.86.158.106", |
| 575 |
"74.86.179.130", |
| 576 |
"74.86.179.131", |
| 577 |
"46.137.190.132", |
| 578 |
"122.248.234.23", |
| 579 |
"74.86.158.107" |
| 580 |
); //don't let uptime robot to affect visit count |
| 581 |
|
| 582 |
if ($fix_count || (!is_admin() && !MMB_Stats::is_bot() && !isset($_GET['doing_wp_cron']) && !in_array($_SERVER['REMOTE_ADDR'], $uptime_robot))) { |
| 583 |
|
| 584 |
$date = date('Y-m-d'); |
| 585 |
$user_hit_count = (array) get_option('user_hit_count'); |
| 586 |
if (!$user_hit_count) { |
| 587 |
$user_hit_count[$date] = 1; |
| 588 |
update_option('user_hit_count', $user_hit_count); |
| 589 |
} else { |
| 590 |
$dated_keys = array_keys($user_hit_count); |
| 591 |
$last_visit_date = $dated_keys[count($dated_keys) - 1]; |
| 592 |
|
| 593 |
$days = intval((strtotime($date) - strtotime($last_visit_date)) / 60 / 60 / 24); |
| 594 |
|
| 595 |
if ($days > 1) { |
| 596 |
$date_to_add = date('Y-m-d', strtotime($last_visit_date)); |
| 597 |
|
| 598 |
for ($i = 1; $i < $days; $i++) { |
| 599 |
if (count($user_hit_count) > 14) { |
| 600 |
$shifted = @array_shift($user_hit_count); |
| 601 |
} |
| 602 |
|
| 603 |
$next_key = strtotime('+1 day', strtotime($date_to_add)); |
| 604 |
if ($next_key == $date) { |
| 605 |
break; |
| 606 |
} else { |
| 607 |
$user_hit_count[$next_key] = 0; |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
} |
| 612 |
|
| 613 |
if (!isset($user_hit_count[$date])) { |
| 614 |
$user_hit_count[$date] = 0; |
| 615 |
} |
| 616 |
if (!$fix_count) |
| 617 |
$user_hit_count[$date] = ((int) $user_hit_count[$date]) + 1; |
| 618 |
|
| 619 |
if (count($user_hit_count) > 14) { |
| 620 |
$shifted = @array_shift($user_hit_count); |
| 621 |
} |
| 622 |
|
| 623 |
update_option('user_hit_count', $user_hit_count); |
| 624 |
|
| 625 |
} |
| 626 |
} |
| 627 |
} |
| 628 |
|
| 629 |
function get_hit_count() |
| 630 |
{ |
| 631 |
// Check if there are no hits on last key date |
| 632 |
$mmb_user_hits = get_option('user_hit_count'); |
| 633 |
if (is_array($mmb_user_hits)) { |
| 634 |
end($mmb_user_hits); |
| 635 |
$last_key_date = key($mmb_user_hits); |
| 636 |
$current_date = date('Y-m-d'); |
| 637 |
if ($last_key_date != $curent_date) |
| 638 |
$this->set_hit_count(true); |
| 639 |
} |
| 640 |
|
| 641 |
return get_option('user_hit_count'); |
| 642 |
} |
| 643 |
|
| 644 |
|
| 645 |
static function is_bot() |
| 646 |
{ |
| 647 |
$agent = $_SERVER['HTTP_USER_AGENT']; |
| 648 |
|
| 649 |
if ($agent == '') |
| 650 |
return false; |
| 651 |
|
| 652 |
$bot_list = array( |
| 653 |
"Teoma", |
| 654 |
"alexa", |
| 655 |
"froogle", |
| 656 |
"Gigabot", |
| 657 |
"inktomi", |
| 658 |
"looksmart", |
| 659 |
"URL_Spider_SQL", |
| 660 |
"Firefly", |
| 661 |
"NationalDirectory", |
| 662 |
"Ask Jeeves", |
| 663 |
"TECNOSEEK", |
| 664 |
"InfoSeek", |
| 665 |
"WebFindBot", |
| 666 |
"girafabot", |
| 667 |
"crawler", |
| 668 |
"www.galaxy.com", |
| 669 |
"Googlebot", |
| 670 |
"Scooter", |
| 671 |
"Slurp", |
| 672 |
"msnbot", |
| 673 |
"appie", |
| 674 |
"FAST", |
| 675 |
"WebBug", |
| 676 |
"Spade", |
| 677 |
"ZyBorg", |
| 678 |
"rabaz", |
| 679 |
"Baiduspider", |
| 680 |
"Feedfetcher-Google", |
| 681 |
"TechnoratiSnoop", |
| 682 |
"Rankivabot", |
| 683 |
"Mediapartners-Google", |
| 684 |
"Sogou web spider", |
| 685 |
"WebAlta Crawler", |
| 686 |
"aolserver" |
| 687 |
); |
| 688 |
|
| 689 |
foreach ($bot_list as $bot) |
| 690 |
if (strpos($agent, $bot) !== false) |
| 691 |
return true; |
| 692 |
|
| 693 |
return false; |
| 694 |
} |
| 695 |
|
| 696 |
|
| 697 |
function set_notifications($params) |
| 698 |
{ |
| 699 |
if (empty($params)) |
| 700 |
return false; |
| 701 |
|
| 702 |
extract($params); |
| 703 |
|
| 704 |
if (!isset($delete)) { |
| 705 |
$mwp_notifications = array( |
| 706 |
'plugins' => $plugins, |
| 707 |
'themes' => $themes, |
| 708 |
'wp' => $wp, |
| 709 |
'backups' => $backups, |
| 710 |
'url' => $url, |
| 711 |
'notification_key' => $notification_key |
| 712 |
); |
| 713 |
update_option('mwp_notifications', $mwp_notifications); |
| 714 |
} else { |
| 715 |
delete_option('mwp_notifications'); |
| 716 |
} |
| 717 |
|
| 718 |
return true; |
| 719 |
|
| 720 |
} |
| 721 |
|
| 722 |
//Cron update check for notifications |
| 723 |
function check_notifications() |
| 724 |
{ |
| 725 |
global $wpdb, $mmb_wp_version, $mmb_plugin_dir, $wp_version, $wp_local_package; |
| 726 |
|
| 727 |
$mwp_notifications = get_option('mwp_notifications', true); |
| 728 |
|
| 729 |
$args = array(); |
| 730 |
$updates = array(); |
| 731 |
$send = 0; |
| 732 |
if (is_array($mwp_notifications) && $mwp_notifications != false) { |
| 733 |
include_once(ABSPATH . 'wp-includes/update.php'); |
| 734 |
include_once(ABSPATH . '/wp-admin/includes/update.php'); |
| 735 |
extract($mwp_notifications); |
| 736 |
|
| 737 |
//Check wordpress core updates |
| 738 |
if ($wp) { |
| 739 |
@wp_version_check(); |
| 740 |
if (function_exists('get_core_updates')) { |
| 741 |
$wp_updates = get_core_updates(); |
| 742 |
if (!empty($wp_updates)) { |
| 743 |
$current_transient = $wp_updates[0]; |
| 744 |
if ($current_transient->response == "development" || version_compare($wp_version, $current_transient->current, '<')) { |
| 745 |
$current_transient->current_version = $wp_version; |
| 746 |
$updates['core_updates'] = $current_transient; |
| 747 |
} else |
| 748 |
$updates['core_updates'] = array(); |
| 749 |
} else |
| 750 |
$updates['core_updates'] = array(); |
| 751 |
} |
| 752 |
} |
| 753 |
|
| 754 |
//Check plugin updates |
| 755 |
if ($plugins) { |
| 756 |
@wp_update_plugins(); |
| 757 |
$this->get_installer_instance(); |
| 758 |
$updates['upgradable_plugins'] = $this->installer_instance->get_upgradable_plugins(); |
| 759 |
} |
| 760 |
|
| 761 |
//Check theme updates |
| 762 |
if ($themes) { |
| 763 |
@wp_update_themes(); |
| 764 |
$this->get_installer_instance(); |
| 765 |
|
| 766 |
$updates['upgradable_themes'] = $this->installer_instance->get_upgradable_themes(); |
| 767 |
} |
| 768 |
|
| 769 |
if ($backups) { |
| 770 |
$this->get_backup_instance(); |
| 771 |
$backups = $this->backup_instance->get_backup_stats(); |
| 772 |
$updates['backups'] = $backups; |
| 773 |
foreach ($backups as $task_name => $backup_results) { |
| 774 |
foreach ($backup_results as $k => $backup) { |
| 775 |
if (isset($backups[$task_name][$k]['server']['file_path'])) { |
| 776 |
unset($backups[$task_name][$k]['server']['file_path']); |
| 777 |
} |
| 778 |
} |
| 779 |
} |
| 780 |
$updates['backups'] = $backups; |
| 781 |
} |
| 782 |
|
| 783 |
|
| 784 |
if (!empty($updates)) { |
| 785 |
$args['body']['updates'] = $updates; |
| 786 |
$args['body']['notification_key'] = $notification_key; |
| 787 |
$send = 1; |
| 788 |
} |
| 789 |
|
| 790 |
} |
| 791 |
|
| 792 |
|
| 793 |
$alert_data = get_option('mwp_pageview_alerts', true); |
| 794 |
if (is_array($alert_data) && $alert_data['alert']) { |
| 795 |
$pageviews = get_option('user_hit_count'); |
| 796 |
$args['body']['alerts']['pageviews'] = $pageviews; |
| 797 |
$args['body']['alerts']['site_id'] = $alert_data['site_id']; |
| 798 |
if (!isset($url)) { |
| 799 |
$url = $alert_data['url']; |
| 800 |
} |
| 801 |
$send = 1; |
| 802 |
} |
| 803 |
|
| 804 |
if ($send) { |
| 805 |
if (!class_exists('WP_Http')) { |
| 806 |
include_once(ABSPATH . WPINC . '/class-http.php'); |
| 807 |
} |
| 808 |
$result = wp_remote_post($url, $args); |
| 809 |
|
| 810 |
if (is_array($result) && $result['body'] == 'mwp_delete_alert') { |
| 811 |
delete_option('mwp_pageview_alerts'); |
| 812 |
} |
| 813 |
} |
| 814 |
|
| 815 |
|
| 816 |
} |
| 817 |
|
| 818 |
|
| 819 |
function cmp_posts_worker($a, $b) |
| 820 |
{ |
| 821 |
return ($a->post_date < $b->post_date); |
| 822 |
} |
| 823 |
|
| 824 |
function trim_content($content = '', $length = 200) |
| 825 |
{ |
| 826 |
if (function_exists('mb_strlen') && function_exists('mb_substr')) |
| 827 |
$content = (mb_strlen($content) > ($length + 3)) ? mb_substr($content, 0, $length) . '...' : $content; |
| 828 |
else |
| 829 |
$content = (strlen($content) > ($length + 3)) ? substr($content, 0, $length) . '...' : $content; |
| 830 |
|
| 831 |
return $content; |
| 832 |
} |
| 833 |
|
| 834 |
|
| 835 |
public static function readd_alerts( $params = array() ){ |
| 836 |
if( empty($params) || !isset($params['alerts'])) |
| 837 |
return $params; |
| 838 |
|
| 839 |
if( !empty($params['alerts']) ){ |
| 840 |
update_option('mwp_pageview_alerts', $params['alerts']); |
| 841 |
unset($params['alerts']); |
| 842 |
} |
| 843 |
|
| 844 |
return $params; |
| 845 |
} |
| 846 |
} |
| 847 |
|
| 848 |
if (function_exists('add_filter')) { |
| 849 |
add_filter('mwp_website_add', 'MMB_Stats::readd_alerts'); |
| 850 |
} |
| 851 |
|