| 1 |
<?php |
| 2 |
/************************************************************ |
| 3 |
* This plugin was modified by Revmakx * |
| 4 |
* Copyright (c) 2012 Revmakx * |
| 5 |
* www.revmakx.com * |
| 6 |
* * |
| 7 |
************************************************************/ |
| 8 |
/************************************************************* |
| 9 |
* |
| 10 |
* stats.class.php |
| 11 |
* |
| 12 |
* Get Site Stats |
| 13 |
* |
| 14 |
* |
| 15 |
* Copyright (c) 2011 Prelovac Media |
| 16 |
* www.prelovac.com |
| 17 |
**************************************************************/ |
| 18 |
if ( ! defined('ABSPATH') ) |
| 19 |
die(); |
| 20 |
|
| 21 |
class IWP_MMB_Stats extends IWP_MMB_Core |
| 22 |
{ |
| 23 |
function __construct() |
| 24 |
{ |
| 25 |
parent::__construct(); |
| 26 |
} |
| 27 |
|
| 28 |
/************************************************************* |
| 29 |
* FACADE functions |
| 30 |
* (functions to be called after a remote call from IWP Admin panel) |
| 31 |
**************************************************************/ |
| 32 |
|
| 33 |
function get_core_update($stats, $options = array()) |
| 34 |
{ |
| 35 |
global $wp_version; |
| 36 |
$locale = get_locale(); |
| 37 |
$update = null; |
| 38 |
if (isset($options['core']) && $options['core']) { |
| 39 |
$core = $this->iwp_mmb_get_transient('update_core'); |
| 40 |
if (isset($core->updates) && !empty($core->updates)) { |
| 41 |
|
| 42 |
foreach ($core->updates as $availableUpdate) { |
| 43 |
if ($availableUpdate->locale == $locale && strtolower($availableUpdate->response) === "upgrade") { |
| 44 |
$update = $availableUpdate; |
| 45 |
break; |
| 46 |
} |
| 47 |
} |
| 48 |
//fallback to first |
| 49 |
if (!$update) { |
| 50 |
$update = $core->updates[0]; |
| 51 |
} |
| 52 |
// WordPress can actually have an update to the same version and locale if locale has not been updated |
| 53 |
if ($update->response === 'development' && ( defined('IWP_SKIP_DEV_CORE_UPDATE') && IWP_SKIP_DEV_CORE_UPDATE)) { |
| 54 |
$stats['core_updates'] = false; |
| 55 |
return $stats; |
| 56 |
} |
| 57 |
if (($update->response === 'development') || $update->response === 'upgrade' || version_compare($wp_version, $update->current, '<')) { |
| 58 |
$update->current_version = $wp_version; |
| 59 |
$stats['core_updates'] = $update; |
| 60 |
} else { |
| 61 |
$stats['core_updates'] = false; |
| 62 |
} |
| 63 |
} else{ |
| 64 |
$stats['core_updates'] = false; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
return $stats; |
| 69 |
} |
| 70 |
|
| 71 |
function get_hit_counter($stats, $options = array()) |
| 72 |
{ |
| 73 |
$iwp_mmb_user_hits = get_option('iwp_client_user_hit_count'); |
| 74 |
if (is_array($iwp_mmb_user_hits)) { |
| 75 |
end($iwp_mmb_user_hits); |
| 76 |
$last_key_date = key($iwp_mmb_user_hits); |
| 77 |
$current_date = date('Y-m-d'); |
| 78 |
if ($last_key_date != $current_date) |
| 79 |
$this->set_hit_count(true); |
| 80 |
} |
| 81 |
$stats['hit_counter'] = get_option('iwp_client_user_hit_count'); |
| 82 |
|
| 83 |
return $stats; |
| 84 |
} |
| 85 |
|
| 86 |
function get_comments($stats, $options = array()) |
| 87 |
{ |
| 88 |
$nposts = ($options['numberposts'] > 0) ? (int) $options['numberposts'] : 100; |
| 89 |
$trimlen = isset($options['trimcontent']) ? (int) $options['trimcontent'] : 200; |
| 90 |
|
| 91 |
// if ($nposts) { |
| 92 |
$comments = get_comments('status=hold&number=' . $nposts); |
| 93 |
if (!empty($comments)) { |
| 94 |
foreach ($comments as &$comment) { |
| 95 |
$commented_post = get_post($comment->comment_post_ID); |
| 96 |
$comment->post_title = $commented_post->post_title; |
| 97 |
$comment->comment_content = $this->trim_content($comment->comment_content, $trimlen); |
| 98 |
unset($comment->comment_author_url); |
| 99 |
unset($comment->comment_author_email); |
| 100 |
unset($comment->comment_author_IP); |
| 101 |
unset($comment->comment_date_gmt); |
| 102 |
unset($comment->comment_karma); |
| 103 |
unset($comment->comment_agent); |
| 104 |
unset($comment->comment_type); |
| 105 |
unset($comment->comment_parent); |
| 106 |
unset($comment->user_id); |
| 107 |
} |
| 108 |
$stats['comments']['pending'] = $comments; |
| 109 |
} |
| 110 |
|
| 111 |
/* $comments = get_comments('status=approve&number=' . $nposts); |
| 112 |
if (!empty($comments)) { |
| 113 |
foreach ($comments as &$comment) { |
| 114 |
$commented_post = get_post($comment->comment_post_ID); |
| 115 |
$comment->post_title = $commented_post->post_title; |
| 116 |
$comment->comment_content = $this->trim_content($comment->comment_content, $trimlen); |
| 117 |
unset($comment->comment_author_url); |
| 118 |
unset($comment->comment_author_email); |
| 119 |
unset($comment->comment_author_IP); |
| 120 |
unset($comment->comment_date_gmt); |
| 121 |
unset($comment->comment_karma); |
| 122 |
unset($comment->comment_agent); |
| 123 |
unset($comment->comment_type); |
| 124 |
unset($comment->comment_parent); |
| 125 |
unset($comment->user_id); |
| 126 |
} |
| 127 |
$stats['comments']['approved'] = $comments; |
| 128 |
}*/ |
| 129 |
//} |
| 130 |
return $stats; |
| 131 |
} |
| 132 |
|
| 133 |
function get_posts($stats, $options = array()) |
| 134 |
{ |
| 135 |
$nposts = isset($options['numberposts']) ? (int) $options['numberposts'] : 20; |
| 136 |
|
| 137 |
if ($nposts) { |
| 138 |
$posts = get_posts('post_status=publish&numberposts=' . $nposts . '&orderby=post_date&order=desc'); |
| 139 |
$recent_posts = array(); |
| 140 |
if (!empty($posts)) { |
| 141 |
foreach ($posts as $id => $recent_post) { |
| 142 |
$recent = new stdClass(); |
| 143 |
$recent->post_permalink = get_permalink($recent_post->ID); |
| 144 |
$recent->ID = $recent_post->ID; |
| 145 |
$recent->post_date = $recent_post->post_date; |
| 146 |
$recent->post_title = $recent_post->post_title; |
| 147 |
$recent->comment_count = (int) $recent_post->comment_count; |
| 148 |
$recent_posts[] = $recent; |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
$posts = get_pages('post_status=publish&numberposts=' . $nposts . '&orderby=post_date&order=desc'); |
| 153 |
$recent_pages_published = array(); |
| 154 |
if (!empty($posts)) { |
| 155 |
foreach ((array) $posts as $id => $recent_page_published) { |
| 156 |
$recent = new stdClass(); |
| 157 |
$recent->post_permalink = get_permalink($recent_page_published->ID); |
| 158 |
|
| 159 |
$recent->ID = $recent_page_published->ID; |
| 160 |
$recent->post_date = $recent_page_published->post_date; |
| 161 |
$recent->post_title = $recent_page_published->post_title; |
| 162 |
|
| 163 |
$recent_posts[] = $recent; |
| 164 |
} |
| 165 |
} |
| 166 |
if (!empty($recent_posts)) { |
| 167 |
usort($recent_posts, array( |
| 168 |
$this, |
| 169 |
'cmp_posts_client' |
| 170 |
)); |
| 171 |
$stats['posts'] = array_slice($recent_posts, 0, $nposts); |
| 172 |
} |
| 173 |
} |
| 174 |
return $stats; |
| 175 |
} |
| 176 |
|
| 177 |
function get_drafts($stats, $options = array()) |
| 178 |
{ |
| 179 |
$nposts = isset($options['numberposts']) ? (int) $options['numberposts'] : 20; |
| 180 |
|
| 181 |
if ($nposts) { |
| 182 |
$drafts = get_posts('post_status=draft&numberposts=' . $nposts . '&orderby=post_date&order=desc'); |
| 183 |
$recent_drafts = array(); |
| 184 |
if (!empty($drafts)) { |
| 185 |
foreach ($drafts as $id => $recent_draft) { |
| 186 |
$recent = new stdClass(); |
| 187 |
$recent->post_permalink = get_permalink($recent_draft->ID); |
| 188 |
$recent->ID = $recent_draft->ID; |
| 189 |
$recent->post_date = $recent_draft->post_date; |
| 190 |
$recent->post_title = $recent_draft->post_title; |
| 191 |
|
| 192 |
$recent_drafts[] = $recent; |
| 193 |
} |
| 194 |
} |
| 195 |
$drafts = get_pages('post_status=draft&numberposts=' . $nposts . '&orderby=post_date&order=desc'); |
| 196 |
$recent_pages_drafts = array(); |
| 197 |
if (!empty($drafts)) { |
| 198 |
foreach ((array) $drafts as $id => $recent_pages_draft) { |
| 199 |
$recent = new stdClass(); |
| 200 |
$recent->post_permalink = get_permalink($recent_pages_draft->ID); |
| 201 |
$recent->ID = $recent_pages_draft->ID; |
| 202 |
$recent->post_date = $recent_pages_draft->post_date; |
| 203 |
$recent->post_title = $recent_pages_draft->post_title; |
| 204 |
|
| 205 |
$recent_drafts[] = $recent; |
| 206 |
} |
| 207 |
} |
| 208 |
if (!empty($recent_drafts)) { |
| 209 |
usort($recent_drafts, array( |
| 210 |
$this, |
| 211 |
'cmp_posts_client' |
| 212 |
)); |
| 213 |
$stats['drafts'] = array_slice($recent_drafts, 0, $nposts); |
| 214 |
} |
| 215 |
} |
| 216 |
return $stats; |
| 217 |
} |
| 218 |
|
| 219 |
function get_scheduled($stats, $options = array()) |
| 220 |
{ |
| 221 |
$nposts = isset($options['numberposts']) ? (int) $options['numberposts'] : 20; |
| 222 |
|
| 223 |
if ($nposts) { |
| 224 |
$scheduled = get_posts('post_status=future&numberposts=' . $nposts . '&orderby=post_date&order=desc'); |
| 225 |
$scheduled_posts = array(); |
| 226 |
if (!empty($scheduled)) { |
| 227 |
foreach ($scheduled as $id => $scheduled) { |
| 228 |
$recent = new stdClass(); |
| 229 |
$recent->post_permalink = get_permalink($scheduled->ID); |
| 230 |
$recent->ID = $scheduled->ID; |
| 231 |
$recent->post_date = $scheduled->post_date; |
| 232 |
$recent->post_title = $scheduled->post_title; |
| 233 |
$scheduled_posts[] = $recent; |
| 234 |
} |
| 235 |
} |
| 236 |
$scheduled = get_pages('post_status=future&numberposts=' . $nposts . '&orderby=post_date&order=desc'); |
| 237 |
$recent_pages_drafts = array(); |
| 238 |
if (!empty($scheduled)) { |
| 239 |
foreach ((array) $scheduled as $id => $scheduled) { |
| 240 |
$recent = new stdClass(); |
| 241 |
$recent->post_permalink = get_permalink($scheduled->ID); |
| 242 |
$recent->ID = $scheduled->ID; |
| 243 |
$recent->post_date = $scheduled->post_date; |
| 244 |
$recent->post_title = $scheduled->post_title; |
| 245 |
|
| 246 |
$scheduled_posts[] = $recent; |
| 247 |
} |
| 248 |
} |
| 249 |
if (!empty($scheduled_posts)) { |
| 250 |
usort($scheduled_posts, array( |
| 251 |
$this, |
| 252 |
'cmp_posts_client' |
| 253 |
)); |
| 254 |
$stats['scheduled'] = array_slice($scheduled_posts, 0, $nposts); |
| 255 |
} |
| 256 |
} |
| 257 |
return $stats; |
| 258 |
} |
| 259 |
|
| 260 |
function get_backups($stats, $options = array()) |
| 261 |
{ |
| 262 |
$stats['iwp_backups'] = $this->get_backup_instance()->get_backup_stats(); |
| 263 |
$stats['iwp_new_backups'] = $this->get_new_backup_instance()->get_backup_stats(); |
| 264 |
return $stats; |
| 265 |
} |
| 266 |
|
| 267 |
function get_backup_req($stats = array(), $options = array()) |
| 268 |
{ |
| 269 |
$stats['iwp_backups'] = $this->get_backup_instance()->get_backup_stats(); |
| 270 |
$stats['iwp_new_backups'] = $this->get_new_backup_instance()->get_backup_stats(); |
| 271 |
$stats['iwp_next_backups'] = $this->get_backup_instance()->get_next_schedules(); |
| 272 |
$stats['iwp_backup_req'] = $this->get_backup_instance()->check_backup_compat(); |
| 273 |
|
| 274 |
return $stats; |
| 275 |
} |
| 276 |
|
| 277 |
function get_updates($stats, $options = array()) |
| 278 |
{ |
| 279 |
$upgrades = false; |
| 280 |
/* No need to fetch this any more |
| 281 |
$premium = array(); |
| 282 |
if (isset($options['premium']) && $options['premium']) { |
| 283 |
$premium_updates = array(); |
| 284 |
$upgrades = apply_filters('mwp_premium_update_notification', $premium_updates); |
| 285 |
if (!empty($upgrades)) { |
| 286 |
foreach( $upgrades as $data ){ |
| 287 |
if( isset($data['Name']) ) |
| 288 |
$premium[] = $data['Name']; |
| 289 |
} |
| 290 |
$stats['premium_updates'] = $upgrades; |
| 291 |
$upgrades = false; |
| 292 |
} |
| 293 |
}*/ |
| 294 |
if (isset($options['themes']) && $options['themes']) { |
| 295 |
$this->get_installer_instance(); |
| 296 |
$upgrades = $this->installer_instance->get_upgradable_themes(); |
| 297 |
if (!empty($upgrades)) { |
| 298 |
$stats['upgradable_themes'] = $upgrades; |
| 299 |
$upgrades = false; |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
if (isset($options['plugins']) && $options['plugins']) { |
| 304 |
$this->get_installer_instance(); |
| 305 |
$upgrades = $this->installer_instance->get_upgradable_plugins(); |
| 306 |
if (!empty($upgrades)) { |
| 307 |
$stats['upgradable_plugins'] = $upgrades; |
| 308 |
$upgrades = false; |
| 309 |
} |
| 310 |
} |
| 311 |
if (isset($options['translations']) && $options['translations']) { |
| 312 |
$this->get_installer_instance(); |
| 313 |
$upgrades = $this->installer_instance->get_upgradable_translations(); |
| 314 |
if (!empty($upgrades)) { |
| 315 |
$stats['upgradable_translations'] = $upgrades; |
| 316 |
$upgrades = false; |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
if (isset($options['additional_updates']) && $options['additional_updates']) { |
| 321 |
$this->get_installer_instance(); |
| 322 |
$upgrades = $this->installer_instance->get_additional_plugin_updates(); |
| 323 |
if (!empty($upgrades)) { |
| 324 |
$stats['additional_updates'] = $upgrades; |
| 325 |
$upgrades = false; |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
return $stats; |
| 330 |
} |
| 331 |
|
| 332 |
function get_errors($stats, $options = array()) |
| 333 |
{ |
| 334 |
$period = isset($options['days']) ? (int) $options['days'] * 86400 : 86400; |
| 335 |
$maxerrors = isset($options['max']) ? (int) $options['max'] : 100; |
| 336 |
$errors = array(); |
| 337 |
if (isset($options['get']) && $options['get'] == true) { |
| 338 |
if (function_exists('ini_get')) { |
| 339 |
$logpath = ini_get('error_log'); |
| 340 |
if (!empty($logpath) && file_exists($logpath)) { |
| 341 |
$logfile = @fopen($logpath, 'r'); |
| 342 |
if ($logfile && filesize($logpath) > 0) { |
| 343 |
$maxlines = 1; |
| 344 |
$linesize = -4096; |
| 345 |
$lines = array(); |
| 346 |
$line = true; |
| 347 |
while ($line !== false) { |
| 348 |
if( fseek($logfile, ($maxlines * $linesize), SEEK_END) !== -1){ |
| 349 |
$maxlines++; |
| 350 |
if ($line) { |
| 351 |
$line = fread($logfile, ($linesize * -1)) . $line; |
| 352 |
|
| 353 |
foreach ((array) preg_split("/(\r|\n|\r\n)/U", $line) as $l) { |
| 354 |
preg_match('/\[(.*)\]/Ui', $l, $match); |
| 355 |
if (!empty($match)) { |
| 356 |
$key = str_replace($match[0], '', $l); |
| 357 |
if(!isset($errors[$key])){ |
| 358 |
$errors[$key] = 1; |
| 359 |
} else { |
| 360 |
$errors[$key] = $errors[$key] + 1; |
| 361 |
} |
| 362 |
|
| 363 |
if ((strtotime($match[1]) < ((int) time() - $period)) || count($errors) >= $maxerrors) { |
| 364 |
$line = false; |
| 365 |
break; |
| 366 |
} |
| 367 |
} |
| 368 |
} |
| 369 |
} |
| 370 |
} else |
| 371 |
break; |
| 372 |
} |
| 373 |
} |
| 374 |
if (!empty($errors)){ |
| 375 |
$stats['errors'] = $errors; |
| 376 |
$stats['logpath'] = $logpath; |
| 377 |
$stats['logsize'] = @filesize($logpath); |
| 378 |
} |
| 379 |
} |
| 380 |
} |
| 381 |
} |
| 382 |
|
| 383 |
return $stats; |
| 384 |
} |
| 385 |
|
| 386 |
function get_plugins_status($stats=array(), $options = array()){ |
| 387 |
$installedPlugins = get_plugins(); |
| 388 |
|
| 389 |
foreach ($installedPlugins as $installed=>$pluginDetails) { |
| 390 |
$pluginData = array('isInstalled' => true); |
| 391 |
$pluginData['name'] = $pluginDetails['Name']; |
| 392 |
$pluginData['pluginURI'] = $pluginDetails['PluginURI']; |
| 393 |
$pluginData['version'] = $pluginDetails['Version']; |
| 394 |
$pluginData['description'] = $pluginDetails['Description']; |
| 395 |
$pluginData['author'] = $pluginDetails['Author']; |
| 396 |
$pluginData['authorURI'] = $pluginDetails['AuthorURI']; |
| 397 |
$pluginData['textDomain'] = $pluginDetails['TextDomain']; |
| 398 |
$pluginData['domainPath'] = $pluginDetails['DomainPath']; |
| 399 |
$pluginData['network'] = $pluginDetails['Network']; |
| 400 |
$pluginData['title'] = $pluginDetails['Title']; |
| 401 |
$pluginData['authorName'] = $pluginDetails['AuthorName']; |
| 402 |
$pluginData['isActivated'] = $this->check_plugin_activated($installed); |
| 403 |
$stats['plugins_status'][$installed] = $pluginData; |
| 404 |
} |
| 405 |
return $stats; |
| 406 |
} |
| 407 |
function get_themes_status($stats=array(), $options = array()){ |
| 408 |
$params = array('items'=>array('themes')); |
| 409 |
global $iwp_mmb_core; |
| 410 |
$iwp_mmb_core->get_installer_instance(); |
| 411 |
$installedThemes = $iwp_mmb_core->installer_instance->get_themes($params); |
| 412 |
$stats['themes_status'] = $installedThemes; |
| 413 |
return $stats; |
| 414 |
} |
| 415 |
|
| 416 |
function pre_init_stats($params) |
| 417 |
{ |
| 418 |
global $_iwp_mmb_item_filter; |
| 419 |
|
| 420 |
include_once(ABSPATH . 'wp-includes/update.php'); |
| 421 |
include_once(ABSPATH . '/wp-admin/includes/update.php'); |
| 422 |
|
| 423 |
$stats = $this->iwp_mmb_parse_action_params('pre_init_stats', $params, $this); |
| 424 |
$num = extract($params); |
| 425 |
|
| 426 |
if (function_exists( 'w3tc_pgcache_flush' ) || function_exists( 'wp_cache_clear_cache' ) || !empty($force_refresh)) { |
| 427 |
$this->iwp_mmb_delete_transient('update_plugins'); |
| 428 |
@wp_update_plugins(); |
| 429 |
$this->iwp_mmb_delete_transient('update_themes'); |
| 430 |
@wp_update_themes(); |
| 431 |
$this->iwp_mmb_delete_transient('update_core'); |
| 432 |
@wp_version_check(); |
| 433 |
} |
| 434 |
elseif ($refresh == 'transient') { |
| 435 |
$current = $this->iwp_mmb_get_transient('update_core'); |
| 436 |
if (isset($current->last_checked) || get_option('iwp_client_forcerefresh')) { |
| 437 |
update_option('iwp_client_forcerefresh', false); |
| 438 |
// if (time() - $current->last_checked > 7200) { No need to check the wordpess 4hr once |
| 439 |
@wp_version_check(); |
| 440 |
@wp_update_plugins(); |
| 441 |
@wp_update_themes(); |
| 442 |
//} |
| 443 |
} |
| 444 |
} |
| 445 |
|
| 446 |
global $wpdb, $iwp_mmb_wp_version, $iwp_mmb_plugin_dir, $wp_version, $wp_local_package; |
| 447 |
|
| 448 |
$current = get_site_transient( 'update_plugins' ); |
| 449 |
if (isset($current->response['iwp-client/init.php'])) { |
| 450 |
$r = $current->response['iwp-client/init.php']; |
| 451 |
} |
| 452 |
|
| 453 |
//For WPE |
| 454 |
$use_cookie = 0; |
| 455 |
if(defined('WPE_APIKEY')){ |
| 456 |
$stats['wpe-auth'] = hash("sha256", 'wpe_auth_salty_dog|'.WPE_APIKEY); |
| 457 |
} |
| 458 |
|
| 459 |
$stats['client_version'] = IWP_MMB_CLIENT_VERSION; |
| 460 |
if (!empty($r)) { |
| 461 |
$stats['client_new_version'] = $r->new_version; |
| 462 |
$stats['client_new_package'] = $r->package; |
| 463 |
} |
| 464 |
$stats['wordpress_version'] = $wp_version; |
| 465 |
$stats['wordpress_locale_pckg'] = get_user_locale(); |
| 466 |
$stats['php_version'] = phpversion(); |
| 467 |
$stats['mysql_version'] = $wpdb->db_version(); |
| 468 |
$stats['wp_multisite'] = $this->iwp_mmb_multisite; |
| 469 |
$stats['network_install'] = $this->network_admin_install; |
| 470 |
$stats['use_cookie'] = $use_cookie; |
| 471 |
$stats['maintenance_mode'] = get_option('iwp_mmb_maintenance_mode'); |
| 472 |
$stats['site_home'] = get_home_url(); |
| 473 |
$stats['site_url'] = get_site_url(); |
| 474 |
$stats['SERVER_SOFTWARE'] = $_SERVER['SERVER_SOFTWARE']; |
| 475 |
$stats['PHP_SAPI'] = PHP_SAPI; |
| 476 |
|
| 477 |
if ( !function_exists('get_filesystem_method') ) |
| 478 |
include_once(ABSPATH . 'wp-admin/includes/file.php'); |
| 479 |
$mmode = get_option('iwp_client_maintenace_mode'); |
| 480 |
|
| 481 |
if( !empty($mmode) && isset($mmode['active']) && $mmode['active'] == true){ |
| 482 |
$stats['maintenance'] = true; |
| 483 |
} |
| 484 |
$stats['writable'] = $this->is_server_writable(); |
| 485 |
if ($this->iwp_mmb_multisite) { |
| 486 |
$details = get_blog_details($this->iwp_mmb_multisite); |
| 487 |
if (isset($details->site_id)) { |
| 488 |
$details = get_blog_details($details->site_id); |
| 489 |
if (isset($details->siteurl)) |
| 490 |
$stats['network_parent'] = $details->siteurl; |
| 491 |
} |
| 492 |
} |
| 493 |
if ($this->iwp_mmb_multisite) { |
| 494 |
$stats = array_merge($stats, $this->get_multisite_stats()); |
| 495 |
} |
| 496 |
return $stats; |
| 497 |
} |
| 498 |
|
| 499 |
function get($params) |
| 500 |
{ |
| 501 |
global $wpdb, $iwp_mmb_wp_version, $iwp_mmb_plugin_dir, $_iwp_mmb_item_filter; |
| 502 |
|
| 503 |
include_once(ABSPATH . 'wp-includes/update.php'); |
| 504 |
include_once(ABSPATH . '/wp-admin/includes/update.php'); |
| 505 |
|
| 506 |
$stats = $this->iwp_mmb_parse_action_params('get', $params, $this); |
| 507 |
$update_check = array(); |
| 508 |
$num = extract($params); |
| 509 |
if ($refresh == 'transient') { |
| 510 |
// $update_check = apply_filters('mwp_premium_update_check', $update_check); |
| 511 |
if (!empty($update_check)) { |
| 512 |
foreach ($update_check as $update) { |
| 513 |
if (is_array($update['callback'])) { |
| 514 |
$update_result = call_user_func(array( |
| 515 |
$update['callback'][0], |
| 516 |
$update['callback'][1] |
| 517 |
)); |
| 518 |
} else if (is_string($update['callback'])) { |
| 519 |
$update_result = call_user_func($update['callback']); |
| 520 |
} |
| 521 |
} |
| 522 |
} |
| 523 |
} |
| 524 |
|
| 525 |
if ($this->iwp_mmb_multisite) { |
| 526 |
$stats = $this->get_multisite($stats); |
| 527 |
} |
| 528 |
|
| 529 |
$stats = apply_filters('iwp_mmb_stats_filter', $stats); |
| 530 |
return $stats; |
| 531 |
} |
| 532 |
|
| 533 |
function get_multisite($stats = array()) |
| 534 |
{ |
| 535 |
global $current_user, $wpdb; |
| 536 |
$user_blogs = get_blogs_of_user( $current_user->ID ); |
| 537 |
$network_blogs = $wpdb->get_results( "select `blog_id`, `site_id` from `{$wpdb->blogs}`" ); |
| 538 |
if ($this->network_admin_install == '1' && is_super_admin()) { |
| 539 |
if (!empty($network_blogs)) { |
| 540 |
$blogs = array(); |
| 541 |
foreach ( $network_blogs as $details) { |
| 542 |
if($details->site_id == $details->blog_id) |
| 543 |
continue; |
| 544 |
else { |
| 545 |
$data = get_blog_details($details->blog_id); |
| 546 |
if(in_array($details->blog_id, array_keys($user_blogs))) |
| 547 |
$stats['network_blogs'][] = $data->siteurl; |
| 548 |
else { |
| 549 |
$user = get_users( array( 'blog_id' => $details->blog_id, 'number' => 1) ); |
| 550 |
if( !empty($user) ) |
| 551 |
$stats['other_blogs'][$data->siteurl] = $user[0]->user_login; |
| 552 |
} |
| 553 |
} |
| 554 |
} |
| 555 |
} |
| 556 |
} |
| 557 |
return $stats; |
| 558 |
} |
| 559 |
|
| 560 |
function get_comments_stats() |
| 561 |
{ |
| 562 |
$num_pending_comments = 3; |
| 563 |
$num_approved_comments = 3; |
| 564 |
$pending_comments = get_comments('status=hold&number=' . $num_pending_comments); |
| 565 |
foreach ($pending_comments as &$comment) { |
| 566 |
$commented_post = get_post($comment->comment_post_ID); |
| 567 |
$comment->post_title = $commented_post->post_title; |
| 568 |
} |
| 569 |
$stats['comments']['pending'] = $pending_comments; |
| 570 |
|
| 571 |
|
| 572 |
$approved_comments = get_comments('status=approve&number=' . $num_approved_comments); |
| 573 |
foreach ($approved_comments as &$comment) { |
| 574 |
$commented_post = get_post($comment->comment_post_ID); |
| 575 |
$comment->post_title = $commented_post->post_title; |
| 576 |
} |
| 577 |
$stats['comments']['approved'] = $approved_comments; |
| 578 |
|
| 579 |
return $stats; |
| 580 |
} |
| 581 |
|
| 582 |
function get_initial_stats() |
| 583 |
{ |
| 584 |
global $iwp_mmb_plugin_dir; |
| 585 |
|
| 586 |
$stats = array(); |
| 587 |
|
| 588 |
$current = get_site_transient( 'update_plugins' ); |
| 589 |
if (isset($current->response['iwp-client/init.php'])) { |
| 590 |
$r = $current->response['iwp-client/init.php']; |
| 591 |
} |
| 592 |
//For BWP |
| 593 |
$bwp = get_option("bit51_bwps"); |
| 594 |
$wp_admin_URL=admin_url(); |
| 595 |
if(!empty($bwp)) |
| 596 |
{ |
| 597 |
if($bwp['hb_enabled']==1) |
| 598 |
$wp_admin_URL = admin_url()."?".$bwp['hb_key']; |
| 599 |
|
| 600 |
|
| 601 |
} |
| 602 |
|
| 603 |
//For WPE |
| 604 |
$use_cookie = 0; |
| 605 |
if(@getenv('IS_WPE')) |
| 606 |
$use_cookie=1; |
| 607 |
|
| 608 |
$stats['email'] = get_option('admin_email'); |
| 609 |
$stats['no_openssl'] = $this->get_random_signature(); |
| 610 |
$stats['content_path'] = WP_CONTENT_DIR; |
| 611 |
$stats['client_path'] = $iwp_mmb_plugin_dir; |
| 612 |
$stats['client_version'] = IWP_MMB_CLIENT_VERSION; |
| 613 |
if (!empty($r)) { |
| 614 |
$stats['client_new_version'] = $r->new_version; |
| 615 |
$stats['client_new_package'] = $r->package; |
| 616 |
} |
| 617 |
$stats['site_title'] = get_bloginfo('name'); |
| 618 |
$stats['site_tagline'] = get_bloginfo('description'); |
| 619 |
$stats['site_home'] = get_option('home'); |
| 620 |
$stats['site_url'] = get_option('siteurl'); |
| 621 |
$stats['admin_url'] = $wp_admin_URL; |
| 622 |
$stats['wp_multisite'] = $this->iwp_mmb_multisite; |
| 623 |
$stats['network_install'] = $this->network_admin_install; |
| 624 |
$stats['use_cookie'] = $use_cookie; |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
if ($this->iwp_mmb_multisite) { |
| 629 |
$details = get_blog_details($this->iwp_mmb_multisite); |
| 630 |
if (isset($details->site_id)) { |
| 631 |
$details = get_blog_details($details->site_id); |
| 632 |
if (isset($details->siteurl)) |
| 633 |
$stats['network_parent'] = $details->siteurl; |
| 634 |
} |
| 635 |
} |
| 636 |
if (!function_exists('get_filesystem_method')) |
| 637 |
include_once(ABSPATH . 'wp-admin/includes/file.php'); |
| 638 |
|
| 639 |
$stats['writable'] = $this->is_server_writable(); |
| 640 |
if ($this->iwp_mmb_multisite) { |
| 641 |
$stats = array_merge($stats, $this->get_multisite_stats()); |
| 642 |
} |
| 643 |
return $stats; |
| 644 |
} |
| 645 |
|
| 646 |
public function get_multisite_stats() |
| 647 |
{ |
| 648 |
/** @var $wpdb wpdb */ |
| 649 |
global $current_user, $wpdb; |
| 650 |
$user_blogs = get_blogs_of_user($current_user->ID); |
| 651 |
$network_blogs = $wpdb->get_results("select `blog_id`, `site_id` from `{$wpdb->blogs}`", ARRAY_A); |
| 652 |
$mainBlogId = defined('BLOG_ID_CURRENT_SITE') ? BLOG_ID_CURRENT_SITE : false; |
| 653 |
|
| 654 |
if (/*$this->network_admin_install != '1' || !is_super_admin($current_user->ID)||*/ empty($network_blogs)) { |
| 655 |
return array(); |
| 656 |
} |
| 657 |
|
| 658 |
$stats = array('network_blogs' => array(), 'other_blogs' => array()); |
| 659 |
foreach ($network_blogs as $details) { |
| 660 |
if (($mainBlogId !== false && $details['blog_id'] == $mainBlogId) || ($mainBlogId === false && $details['site_id'] == $details['blog_id'])) { |
| 661 |
continue; |
| 662 |
} else { |
| 663 |
$data = get_blog_details($details['blog_id']); |
| 664 |
if (is_array($user_blogs) && in_array($details['blog_id'], array_keys($user_blogs))) { |
| 665 |
$stats['network_blogs'][] = $data->siteurl; |
| 666 |
} else { |
| 667 |
$user = get_users( |
| 668 |
array( |
| 669 |
'blog_id' => $details['blog_id'], |
| 670 |
'number' => 1, |
| 671 |
) |
| 672 |
); |
| 673 |
if (!empty($user)) { |
| 674 |
$stats['other_blogs'][$data->siteurl] = $user[0]->user_login; |
| 675 |
} |
| 676 |
} |
| 677 |
} |
| 678 |
} |
| 679 |
|
| 680 |
return $stats; |
| 681 |
} |
| 682 |
|
| 683 |
|
| 684 |
public static function set_hit_count($fix_count = false) |
| 685 |
{ |
| 686 |
global $iwp_mmb_core; |
| 687 |
if ($fix_count || (!is_admin() && !IWP_MMB_Stats::is_bot())) { |
| 688 |
$date = date('Y-m-d'); |
| 689 |
$iwp_client_user_hit_count = (array) get_option('iwp_client_user_hit_count'); |
| 690 |
if (!$iwp_client_user_hit_count) { |
| 691 |
$iwp_client_user_hit_count[$date] = 1; |
| 692 |
update_option('iwp_client_user_hit_count', $iwp_client_user_hit_count); |
| 693 |
} else { |
| 694 |
$dated_keys = array_keys($iwp_client_user_hit_count); |
| 695 |
$last_visit_date = $dated_keys[count($dated_keys) - 1]; |
| 696 |
|
| 697 |
$days = intval((strtotime($date) - strtotime($last_visit_date)) / 60 / 60 / 24); |
| 698 |
|
| 699 |
if ($days > 1) { |
| 700 |
$date_to_add = date('Y-m-d', strtotime($last_visit_date)); |
| 701 |
|
| 702 |
for ($i = 1; $i < $days; $i++) { |
| 703 |
if (count($iwp_client_user_hit_count) > 14) { |
| 704 |
$shifted = @array_shift($iwp_client_user_hit_count); |
| 705 |
} |
| 706 |
|
| 707 |
$next_key = strtotime('+1 day', strtotime($date_to_add)); |
| 708 |
if ($next_key == $date) { |
| 709 |
break; |
| 710 |
} else { |
| 711 |
$iwp_client_user_hit_count[$next_key] = 0; |
| 712 |
} |
| 713 |
} |
| 714 |
|
| 715 |
} |
| 716 |
|
| 717 |
if (!isset($iwp_client_user_hit_count[$date])) { |
| 718 |
$iwp_client_user_hit_count[$date] = 0; |
| 719 |
} |
| 720 |
if (!$fix_count) |
| 721 |
$iwp_client_user_hit_count[$date] = ((int) $iwp_client_user_hit_count[$date]) + 1; |
| 722 |
|
| 723 |
if (count($iwp_client_user_hit_count) > 14) { |
| 724 |
$shifted = @array_shift($iwp_client_user_hit_count); |
| 725 |
} |
| 726 |
|
| 727 |
update_option('iwp_client_user_hit_count', $iwp_client_user_hit_count); |
| 728 |
|
| 729 |
} |
| 730 |
} |
| 731 |
} |
| 732 |
|
| 733 |
function get_hit_count() |
| 734 |
{ |
| 735 |
// Check if there are no hits on last key date |
| 736 |
$iwp_mmb_user_hits = get_option('iwp_client_user_hit_count'); |
| 737 |
if (is_array($iwp_mmb_user_hits)) { |
| 738 |
end($iwp_mmb_user_hits); |
| 739 |
$last_key_date = key($iwp_mmb_user_hits); |
| 740 |
$current_date = date('Y-m-d'); |
| 741 |
if ($last_key_date != $current_date) |
| 742 |
$this->set_hit_count(true); |
| 743 |
} |
| 744 |
|
| 745 |
return get_option('iwp_client_user_hit_count'); |
| 746 |
} |
| 747 |
|
| 748 |
public static function is_bot() |
| 749 |
{ |
| 750 |
$agent = $_SERVER['HTTP_USER_AGENT']; |
| 751 |
|
| 752 |
if ($agent == '') |
| 753 |
return false; |
| 754 |
|
| 755 |
$bot_list = array( |
| 756 |
"Teoma", |
| 757 |
"alexa", |
| 758 |
"froogle", |
| 759 |
"Gigabot", |
| 760 |
"inktomi", |
| 761 |
"looksmart", |
| 762 |
"URL_Spider_SQL", |
| 763 |
"Firefly", |
| 764 |
"NationalDirectory", |
| 765 |
"Ask Jeeves", |
| 766 |
"TECNOSEEK", |
| 767 |
"InfoSeek", |
| 768 |
"WebFindBot", |
| 769 |
"girafabot", |
| 770 |
"crawler", |
| 771 |
"www.galaxy.com", |
| 772 |
"Googlebot", |
| 773 |
"Scooter", |
| 774 |
"Slurp", |
| 775 |
"msnbot", |
| 776 |
"appie", |
| 777 |
"FAST", |
| 778 |
"WebBug", |
| 779 |
"Spade", |
| 780 |
"ZyBorg", |
| 781 |
"rabaz", |
| 782 |
"Baiduspider", |
| 783 |
"Feedfetcher-Google", |
| 784 |
"TechnoratiSnoop", |
| 785 |
"Rankivabot", |
| 786 |
"Mediapartners-Google", |
| 787 |
"Sogou web spider", |
| 788 |
"WebAlta Crawler", |
| 789 |
"aolserver" |
| 790 |
); |
| 791 |
|
| 792 |
foreach ($bot_list as $bot) |
| 793 |
if (strpos($agent, $bot) !== false) |
| 794 |
return true; |
| 795 |
|
| 796 |
return false; |
| 797 |
} |
| 798 |
|
| 799 |
|
| 800 |
function set_notifications($params) |
| 801 |
{ |
| 802 |
if (empty($params)) |
| 803 |
return false; |
| 804 |
|
| 805 |
extract($params); |
| 806 |
|
| 807 |
if (!isset($delete)) { |
| 808 |
$iwp_client_notifications = array( |
| 809 |
'plugins' => $plugins, |
| 810 |
'themes' => $themes, |
| 811 |
'wp' => $wp, |
| 812 |
'backups' => $backups, |
| 813 |
'url' => $url, |
| 814 |
'notification_key' => $notification_key |
| 815 |
); |
| 816 |
update_option('iwp_client_notifications', $iwp_client_notifications); |
| 817 |
} else { |
| 818 |
delete_option('iwp_client_notifications'); |
| 819 |
} |
| 820 |
|
| 821 |
return true; |
| 822 |
|
| 823 |
} |
| 824 |
|
| 825 |
//Cron update check for notifications |
| 826 |
function check_notifications() |
| 827 |
{ |
| 828 |
global $wpdb, $iwp_mmb_wp_version, $iwp_mmb_plugin_dir, $wp_version, $wp_local_package; |
| 829 |
|
| 830 |
$iwp_client_notifications = get_option('iwp_client_notifications', true); |
| 831 |
|
| 832 |
$args = array(); |
| 833 |
$updates = array(); |
| 834 |
$send = 0; |
| 835 |
if (is_array($iwp_client_notifications) && $iwp_client_notifications != false) { |
| 836 |
include_once(ABSPATH . 'wp-includes/update.php'); |
| 837 |
include_once(ABSPATH . '/wp-admin/includes/update.php'); |
| 838 |
extract($iwp_client_notifications); |
| 839 |
|
| 840 |
//Check wordpress core updates |
| 841 |
if ($wp) { |
| 842 |
@wp_version_check(); |
| 843 |
if (function_exists('get_core_updates')) { |
| 844 |
$wp_updates = get_core_updates(); |
| 845 |
if (!empty($wp_updates)) { |
| 846 |
$current_transient = $wp_updates[0]; |
| 847 |
if ($current_transient->response == "development" || version_compare($wp_version, $current_transient->current, '<')) { |
| 848 |
$current_transient->current_version = $wp_version; |
| 849 |
$updates['core_updates'] = $current_transient; |
| 850 |
} else |
| 851 |
$updates['core_updates'] = array(); |
| 852 |
} else |
| 853 |
$updates['core_updates'] = array(); |
| 854 |
} |
| 855 |
} |
| 856 |
|
| 857 |
//Check plugin updates |
| 858 |
if ($plugins) { |
| 859 |
@wp_update_plugins(); |
| 860 |
$this->get_installer_instance(); |
| 861 |
$updates['upgradable_plugins'] = $this->installer_instance->get_upgradable_plugins(); |
| 862 |
} |
| 863 |
|
| 864 |
//Check theme updates |
| 865 |
if ($themes) { |
| 866 |
@wp_update_themes(); |
| 867 |
$this->get_installer_instance(); |
| 868 |
|
| 869 |
$updates['upgradable_themes'] = $this->installer_instance->get_upgradable_themes(); |
| 870 |
} |
| 871 |
|
| 872 |
if ($backups) { |
| 873 |
$this->get_backup_instance(); |
| 874 |
$backups = $this->backup_instance->get_backup_stats(); |
| 875 |
$updates['backups'] = $backups; |
| 876 |
foreach ($backups as $task_name => $backup_results) { |
| 877 |
foreach ($backup_results as $k => $backup) { |
| 878 |
if (isset($backups[$task_name][$k]['server']['file_path'])) { |
| 879 |
unset($backups[$task_name][$k]['server']['file_path']); |
| 880 |
} |
| 881 |
} |
| 882 |
} |
| 883 |
$updates['backups'] = $backups; |
| 884 |
} |
| 885 |
|
| 886 |
|
| 887 |
if (!empty($updates)) { |
| 888 |
$args['body']['updates'] = $updates; |
| 889 |
$args['body']['notification_key'] = $notification_key; |
| 890 |
$send = 1; |
| 891 |
} |
| 892 |
|
| 893 |
} |
| 894 |
|
| 895 |
|
| 896 |
$alert_data = get_option('iwp_client_pageview_alerts',true); |
| 897 |
if(is_array($alert_data) && $alert_data['alert']){ |
| 898 |
$pageviews = get_option('iwp_client_user_hit_count'); |
| 899 |
$args['body']['alerts']['pageviews'] = $pageviews; |
| 900 |
$args['body']['alerts']['site_id'] = $alert_data['site_id']; |
| 901 |
if(!isset($url)){ |
| 902 |
$url = $alert_data['url']; |
| 903 |
} |
| 904 |
$send = 1; |
| 905 |
} |
| 906 |
|
| 907 |
if($send){ |
| 908 |
if (!class_exists('WP_Http')) { |
| 909 |
include_once(ABSPATH . WPINC . '/class-http.php'); |
| 910 |
} |
| 911 |
$result = wp_remote_post($url, $args); |
| 912 |
|
| 913 |
if (is_array($result) && $result['body'] == 'iwp_delete_alert') { |
| 914 |
delete_option('iwp_client_pageview_alerts'); |
| 915 |
} |
| 916 |
} |
| 917 |
} |
| 918 |
|
| 919 |
|
| 920 |
function cmp_posts_client($a, $b) |
| 921 |
{ |
| 922 |
return ($a->post_date < $b->post_date); |
| 923 |
} |
| 924 |
|
| 925 |
function trim_content($content = '', $length = 200) |
| 926 |
{ |
| 927 |
if (function_exists('mb_strlen') && function_exists('mb_substr')) |
| 928 |
$content = (mb_strlen($content) > ($length + 3)) ? mb_substr($content, 0, $length) . '...' : $content; |
| 929 |
else |
| 930 |
$content = (strlen($content) > ($length + 3)) ? substr($content, 0, $length) . '...' : $content; |
| 931 |
|
| 932 |
return $content; |
| 933 |
} |
| 934 |
|
| 935 |
function set_alerts($args){ |
| 936 |
extract($args); |
| 937 |
update_option('iwp_client_pageview_alerts',array('site_id' => $site_id,'alert' => $alert,'url' => $url)); |
| 938 |
} |
| 939 |
|
| 940 |
public static function readd_alerts( $params = array() ){ |
| 941 |
if( empty($params) || !isset($params['alerts'])) |
| 942 |
return $params; |
| 943 |
|
| 944 |
if( !empty($params['alerts']) ){ |
| 945 |
update_option('iwp_client_pageview_alerts', $params['alerts']); |
| 946 |
unset($params['alerts']); |
| 947 |
} |
| 948 |
|
| 949 |
return $params; |
| 950 |
} |
| 951 |
} |
| 952 |
|
| 953 |
if( function_exists('add_filter') ){ |
| 954 |
add_filter( 'iwp_website_add', 'IWP_MMB_Stats::readd_alerts' ); |
| 955 |
} |
| 956 |
?> |