PluginProbe
ManageWP Worker / 3.9.10
ManageWP Worker v3.9.10
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / stats.class.php

stats.class.php in ManageWP Worker 3.9.10, at stats.class.php

635 lines 20.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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_core_update( $stats, $options = array() ){
27 global $wp_version;
28
29 if(isset($options['core']) && $options['core']){
30 $core = $this->mmb_get_transient('update_core');
31 if (isset($core->updates) && !empty($core->updates)) {
32 $current_transient = $core->updates[0];
33 if ($current_transient->response == "development" || version_compare($wp_version, $current_transient->current, '<')) {
34 $current_transient->current_version = $wp_version;
35 $stats['core_updates'] = $current_transient;
36 } else
37 $stats['core_updates'] = false;
38 }else
39 $stats['core_updates'] = false;
40 }
41
42 return $stats;
43 }
44
45 function get_hit_counter( $stats, $options = array() ){
46
47 $mmb_user_hits = get_option('user_hit_count');
48 if (is_array($mmb_user_hits)) {
49 end($mmb_user_hits);
50 $last_key_date = key($mmb_user_hits);
51 $current_date = date('Y-m-d');
52 if ($last_key_date != $current_date)
53 $this->set_hit_count(true);
54 }
55 $stats['hit_counter'] = get_option('user_hit_count');
56
57 return $stats;
58 }
59
60 function get_comments( $stats, $options = array() ){
61
62 $nposts = isset($options['numberposts']) ? (int) $options['numberposts'] : 20;
63
64 if( $nposts ){
65 $pending_comments = get_comments('status=hold&number=' . $nposts);
66 foreach ($pending_comments as &$comment) {
67 $commented_post = get_post($comment->comment_post_ID);
68 $comment->post_title = $commented_post->post_title;
69 }
70 $stats['comments']['pending'] = $pending_comments;
71
72
73 $approved_comments = get_comments('status=approve&number=' . $nposts);
74 foreach ($approved_comments as &$comment) {
75 $commented_post = get_post($comment->comment_post_ID);
76 $comment->post_title = $commented_post->post_title;
77 }
78 $stats['comments']['approved'] = $approved_comments;
79 }
80 return $stats;
81 }
82
83 function get_posts( $stats, $options = array() ){
84
85 $nposts = isset($options['numberposts']) ? (int) $options['numberposts'] : 20;
86
87 if( $nposts ){
88 $all_posts = get_posts('post_status=publish&numberposts='.$nposts.'&orderby=modified&order=desc');
89 $recent_posts = array();
90
91 foreach ($all_posts as $id => $recent_post) {
92 $recent = new stdClass();
93 $recent->post_permalink = get_permalink($recent_post->ID);
94 $recent->ID = $recent_post->ID;
95 $recent->post_date = $recent_post->post_date;
96 $recent->post_title = $recent_post->post_title;
97 $recent->post_modified = $recent_post->post_modified;
98 $recent->comment_count = (int)$recent_post->comment_count;
99 $recent_posts[] = $recent;
100 }
101
102 $all_pages_published = get_pages('post_status=publish&numberposts='.$nposts.'&orderby=modified&order=desc');
103 $recent_pages_published = array();
104 foreach ((array)$all_pages_published as $id => $recent_page_published) {
105 $recent = new stdClass();
106 $recent->post_permalink = get_permalink($recent_page_published->ID);
107
108 $recent->ID = $recent_page_published->ID;
109 $recent->post_date = $recent_page_published->post_date;
110 $recent->post_title = $recent_page_published->post_title;
111 $recent->post_modified = $recent_page_published->post_modified;
112
113 $recent_posts[] = $recent;
114 }
115 usort($recent_posts, array($this, 'cmp_posts_worker'));
116 $stats['posts'] = array_slice($recent_posts, 0, $nposts);
117 }
118 return $stats;
119 }
120
121 function get_drafts( $stats, $options = array() ){
122
123 $nposts = isset($options['numberposts']) ? (int) $options['numberposts'] : 20;
124
125 if( $nposts ){
126 $all_drafts = get_posts('post_status=draft&numberposts='.$nposts.'&orderby=modified&order=desc');
127 $recent_drafts = array();
128 foreach ($all_drafts as $id => $recent_draft) {
129 $recent = new stdClass();
130 $recent->post_permalink = get_permalink($recent_draft->ID);
131 $recent->ID = $recent_draft->ID;
132 $recent->post_date = $recent_draft->post_date;
133 $recent->post_title = $recent_draft->post_title;
134 $recent->post_modified = $recent_draft->post_modified;
135
136 $recent_drafts[] = $recent;
137 }
138
139 $all_pages_drafts = get_pages('post_status=draft&numberposts='.$nposts.'&orderby=modified&order=desc');
140 $recent_pages_drafts = array();
141 foreach ((array)$all_pages_drafts as $id => $recent_pages_draft) {
142 $recent = new stdClass();
143 $recent->post_permalink = get_permalink($recent_pages_draft->ID);
144 $recent->ID = $recent_pages_draft->ID;
145 $recent->post_date = $recent_pages_draft->post_date;
146 $recent->post_title = $recent_pages_draft->post_title;
147 $recent->post_modified = $recent_pages_draft->post_modified;
148
149 $recent_drafts[] = $recent;
150 }
151 usort($recent_drafts, array($this, 'cmp_posts_worker'));
152 $stats['drafts'] = array_slice($recent_drafts, 0, $nposts);
153 }
154 return $stats;
155 }
156
157 function get_scheduled( $stats, $options = array() ){
158
159 $nposts = isset($options['numberposts']) ? (int) $options['numberposts'] : 20;
160
161 if( $nposts ){
162 $all_scheduled = get_posts('post_status=future&numberposts='.$nposts.'&orderby=post_date&order=desc');
163 $scheduled_posts = array();
164 foreach ($all_scheduled as $id => $scheduled) {
165 $recent = new stdClass();
166 $recent->post_permalink = get_permalink($scheduled->ID);
167 $recent->ID = $scheduled->ID;
168 $recent->post_date = $scheduled->post_date;
169 $recent->post_title = $scheduled->post_title;
170 $recent->post_modified = $scheduled->post_modified;
171 $scheduled_posts[] = $recent;
172 }
173
174 $pages_scheduled = get_pages('post_status=future&numberposts='.$nposts.'&orderby=modified&order=desc');
175 $recent_pages_drafts = array();
176 foreach ((array)$pages_scheduled as $id => $scheduled) {
177 $recent = new stdClass();
178 $recent->post_permalink = get_permalink($scheduled->ID);
179 $recent->ID = $scheduled->ID;
180 $recent->post_date = $scheduled->post_date;
181 $recent->post_title = $scheduled->post_title;
182 $recent->post_modified = $scheduled->post_modified;
183
184 $scheduled_posts[] = $recent;
185 }
186 usort($scheduled_posts, array($this, 'cmp_posts_worker'));
187 $stats['scheduled'] = array_slice($scheduled_posts, 0, $nposts);
188 }
189 return $stats;
190 }
191
192 function get_backups( $stats, $options = array() ){
193
194 $stats['mwp_backups'] = $this->get_backup_instance()->get_backup_stats();
195 $stats['mwp_next_backups'] = $this->get_backup_instance()->get_next_schedules();
196 $stats['mwp_backup_req'] = $this->get_backup_instance()->check_backup_compat();
197
198 return $stats;
199 }
200
201 function get_updates( $stats, $options = array() ){
202
203 if(isset($options['premium']) && $options['premium']){
204 $premium_updates = array();
205 $stats['premium_updates'] = apply_filters('mwp_premium_update_notification', $premium_updates);
206 }
207 if(isset($options['themes']) && $options['themes']){
208 $this->get_installer_instance();
209 $stats['upgradable_themes'] = $this->installer_instance->get_upgradable_themes();
210 }
211
212 if(isset($options['plugins']) && $options['plugins']){
213 $this->get_installer_instance();
214 $stats['upgradable_plugins'] = $this->installer_instance->get_upgradable_plugins();
215 }
216
217 return $stats;
218 }
219
220 function get_errors( $stats, $options = array() ){
221
222 $period = isset($options['days']) ? (int) $options['days'] * 86400 : 86400;
223 $errors = array();
224 if(isset($options['get']) && $options['get'] == true){
225 if( function_exists('ini_get') ){
226 $logpath = ini_get('error_log');
227 if(!empty($logpath) && file_exists($logpath)){
228 $logfile = @fopen($logpath, 'r');
229 if( $logfile ){
230 $maxlines = 1;
231 $linesize = -4096;
232 $lines = array();
233 $line = true;
234 while( $line !== false ){
235 fseek($logfile, ($maxlines * $linesize), SEEK_END);
236 $maxlines++;
237 if( $line ) {
238 $line = fread($logfile, ($linesize * -1)).$line;
239
240 foreach((array) preg_split("/(\r|\n|\r\n)/U", $line) as $l){
241 preg_match('/\[(.*)\]/Ui', $l, $match);
242 if(!empty($match)){
243 $errors[strtotime($match[1])][] = str_replace($match[0], '', $l);
244 if(strtotime($match[1]) < ((int) time() - $period)){
245 $line = false;
246 break;
247 }
248 }
249 }
250 }
251 }
252 }
253
254 }
255 }
256 }
257 $stats['errors'] = $errors;
258 return $stats;
259 }
260
261 function pre_init_stats( $params ){
262
263 global $_mmb_item_filter;
264
265 include_once(ABSPATH . 'wp-includes/update.php');
266 include_once(ABSPATH . '/wp-admin/includes/update.php');
267
268 $stats = $this->mmb_parse_action_params( 'pre_init_stats', $params, &$this );
269 $num = extract($params);
270
271 if ($refresh == 'transient') {
272 $current = $this->mmb_get_transient('update_core');
273 if(isset($current->last_checked)){
274 if(time() - $current->last_checked > 1800 ) {
275 @wp_version_check();
276 @wp_update_plugins();
277 @wp_update_themes();
278 }
279 }
280 }
281
282 global $wpdb, $mmb_wp_version, $mmb_plugin_dir, $wp_version, $wp_local_package;
283
284 $stats['worker_version'] = MMB_WORKER_VERSION;
285 $stats['wordpress_version'] = $wp_version;
286 $stats['wordpress_locale_pckg'] = $wp_local_package;
287 $stats['php_version'] = phpversion();
288 $stats['mysql_version'] = $wpdb->db_version();
289 $stats['wp_multisite'] = $this->mmb_multisite;
290 $stats['network_install'] = $this->network_admin_install;
291
292 if (!function_exists('get_filesystem_method'))
293 include_once(ABSPATH . 'wp-admin/includes/file.php');
294
295 $stats['writable'] = $this->is_server_writable();
296
297 return $stats;
298 }
299
300 function get( $params )
301 {
302 global $wpdb, $mmb_wp_version, $mmb_plugin_dir, $_mmb_item_filter;
303
304 include_once(ABSPATH . 'wp-includes/update.php');
305 include_once(ABSPATH . '/wp-admin/includes/update.php');
306
307 $stats = $this->mmb_parse_action_params( 'get', $params, &$this );
308 $update_check = array();
309 $num = extract($params);
310 if ($refresh == 'transient') {
311 $update_check = apply_filters('mwp_premium_update_check', $update_check);
312 if(!empty($update_check)){
313 foreach($update_check as $update){
314 if( is_array($update['callback']) ) {
315 $update_result = call_user_func( array( $update['callback'][0], $update['callback'][1] ) );
316 }
317 else if ( is_string($update['callback']) ) {
318 $update_result = call_user_func($update['callback']);
319 }
320 }
321 }
322 }
323
324 if( $this->mmb_multisite ){
325 $stats = $this->get_multisite( $stats );
326 }
327
328 $stats = apply_filters('mmb_stats_filter', $stats);
329 return $stats;
330 }
331
332 function get_multisite( $stats = array() ){
333 global $current_user;
334
335 if( $this->network_admin_install == '1' && current_user_can( 'update_core' )){
336 $user_blogs = get_blogs_of_user($current_user->ID);
337 if(!empty($user_blogs)){
338 $blogs = array();
339 foreach($user_blogs as $blog_id => $data){
340 if($this->mmb_multisite == $blog_id)
341 continue;
342
343 if(isset($data->siteurl))
344 $blogs[] = $data->siteurl;
345 }
346 if(!empty($blogs))
347 $stats['network_blogs'] = $blogs;
348 }
349 }
350 return $stats;
351 }
352
353 function get_comments_stats(){
354 $num_pending_comments = 3;
355 $num_approved_comments = 3;
356 $pending_comments = get_comments('status=hold&number=' . $num_pending_comments);
357 foreach ($pending_comments as &$comment) {
358 $commented_post = get_post($comment->comment_post_ID);
359 $comment->post_title = $commented_post->post_title;
360 }
361 $stats['comments']['pending'] = $pending_comments;
362
363
364 $approved_comments = get_comments('status=approve&number=' . $num_approved_comments);
365 foreach ($approved_comments as &$comment) {
366 $commented_post = get_post($comment->comment_post_ID);
367 $comment->post_title = $commented_post->post_title;
368 }
369 $stats['comments']['approved'] = $approved_comments;
370
371 return $stats;
372 }
373
374 function get_initial_stats()
375 {
376 global $mmb_plugin_dir;
377
378 $stats = array();
379
380 $stats['email'] = get_option('admin_email');
381 $stats['no_openssl'] = $this->get_random_signature();
382 $stats['content_path'] = WP_CONTENT_DIR;
383 $stats['worker_path'] = $mmb_plugin_dir;
384 $stats['worker_version'] = MMB_WORKER_VERSION;
385 $stats['site_title'] = get_bloginfo('name');
386 $stats['site_tagline'] = get_bloginfo('description');
387 $stats['site_home'] = get_option('home');
388 $stats['admin_url'] = admin_url();
389 $stats['wp_multisite'] = $this->mmb_multisite;
390 $stats['network_install'] = $this->network_admin_install;
391
392 if( $this->mmb_multisite ){
393 $details = get_blog_details($this->mmb_multisite);
394 if(isset($details->site_id)){
395 $details = get_blog_details($details->site_id);
396 if(isset($details->siteurl))
397 $stats['network_parent'] = $details->siteurl;
398 }
399 }
400 if (!function_exists('get_filesystem_method'))
401 include_once(ABSPATH . 'wp-admin/includes/file.php');
402
403 $stats['writable'] = $this->is_server_writable();
404
405 return $stats;
406 }
407
408 function set_hit_count($fix_count = false)
409 {
410 if ($fix_count || (!is_admin() && !MMB_Stats::detect_bots())) {
411 $date = date('Y-m-d');
412 $user_hit_count = (array) get_option('user_hit_count');
413 if (!$user_hit_count) {
414 $user_hit_count[$date] = 1;
415 update_option('user_hit_count', $user_hit_count);
416 } else {
417 $dated_keys = array_keys($user_hit_count);
418 $last_visit_date = $dated_keys[count($dated_keys) - 1];
419
420 $days = intval((strtotime($date) - strtotime($last_visit_date)) / 60 / 60 / 24);
421
422 if ($days > 1) {
423 $date_to_add = date('Y-m-d', strtotime($last_visit_date));
424
425 for ($i = 1; $i < $days; $i++) {
426 if (count($user_hit_count) > 14) {
427 $shifted = @array_shift($user_hit_count);
428 }
429
430 $next_key = strtotime('+1 day', strtotime($date_to_add));
431 if ($next_key == $date) {
432 break;
433 } else {
434 $user_hit_count[$next_key] = 0;
435 }
436 }
437
438 }
439
440 if (!isset($user_hit_count[$date])) {
441 $user_hit_count[$date] = 0;
442 }
443 if (!$fix_count)
444 $user_hit_count[$date] = ((int)$user_hit_count[$date] ) + 1;
445
446 if (count($user_hit_count) > 14) {
447 $shifted = @array_shift($user_hit_count);
448 }
449
450 update_option('user_hit_count', $user_hit_count);
451
452 }
453 }
454 }
455
456 function get_hit_count()
457 {
458 // Check if there are no hits on last key date
459 $mmb_user_hits = get_option('user_hit_count');
460 if (is_array($mmb_user_hits)) {
461 end($mmb_user_hits);
462 $last_key_date = key($mmb_user_hits);
463 $current_date = date('Y-m-d');
464 if ($last_key_date != $curent_date)
465 $this->set_hit_count(true);
466 }
467
468 return get_option('user_hit_count');
469 }
470
471 function detect_bots()
472 {
473 $agent = $_SERVER['HTTP_USER_AGENT'];
474
475 if ($agent == '')
476 return false;
477
478 $bot_list = array(
479 "Teoma",
480 "alexa",
481 "froogle",
482 "Gigabot",
483 "inktomi",
484 "looksmart",
485 "URL_Spider_SQL",
486 "Firefly",
487 "NationalDirectory",
488 "Ask Jeeves",
489 "TECNOSEEK",
490 "InfoSeek",
491 "WebFindBot",
492 "girafabot",
493 "crawler",
494 "www.galaxy.com",
495 "Googlebot",
496 "Scooter",
497 "Slurp",
498 "msnbot",
499 "appie",
500 "FAST",
501 "WebBug",
502 "Spade",
503 "ZyBorg",
504 "rabaz",
505 "Baiduspider",
506 "Feedfetcher-Google",
507 "TechnoratiSnoop",
508 "Rankivabot",
509 "Mediapartners-Google",
510 "Sogou web spider",
511 "WebAlta Crawler",
512 "aolserver"
513 );
514
515 $thebot = '';
516 foreach ($bot_list as $bot) {
517 if ((boolean)strpos($bot, $agent)) {
518 $thebot = $bot;
519 break;
520 }
521 }
522
523 if ($thebot != '') {
524 return $thebot;
525 } else
526 return false;
527 }
528
529
530 function set_notifications($params)
531 {
532 if(empty($params))
533 return false;
534
535 extract($params);
536
537 if(!isset($delete)){
538 $mwp_notifications = array(
539 'plugins' => $plugins,
540 'themes' => $themes,
541 'wp' => $wp,
542 'backups' => $backups,
543 'url' => $url,
544 'notification_key' => $notification_key
545 );
546 update_option('mwp_notifications',$mwp_notifications);
547 } else {
548 delete_option('mwp_notifications');
549 }
550
551 return true;
552
553 }
554
555 //Cron update check for notifications
556 function check_notifications(){
557 global $wpdb, $mmb_wp_version, $mmb_plugin_dir, $wp_version, $wp_local_package;
558
559 $mwp_notifications = get_option('mwp_notifications',true);
560 $updates = array();
561
562 if(is_array($mwp_notifications) && $mwp_notifications != false){
563 include_once(ABSPATH . 'wp-includes/update.php');
564 include_once(ABSPATH . '/wp-admin/includes/update.php');
565 extract($mwp_notifications);
566
567 //Check wordpress core updates
568 if($wp){
569 @wp_version_check();
570 if (function_exists('get_core_updates')) {
571 $wp_updates = get_core_updates();
572 if (!empty($wp_updates)) {
573 $current_transient = $wp_updates[0];
574 if ($current_transient->response == "development" || version_compare($wp_version, $current_transient->current, '<')) {
575 $current_transient->current_version = $wp_version;
576 $updates['core_updates'] = $current_transient;
577 } else
578 $updates['core_updates'] = array();
579 } else
580 $updates['core_updates'] = array();
581 }
582 }
583
584 //Check plugin updates
585 if($plugins){
586 @wp_update_plugins();
587 $this->get_installer_instance();
588 $updates['upgradable_plugins'] = $this->installer_instance->get_upgradable_plugins();
589 }
590
591 //Check theme updates
592 if($themes){
593 @wp_update_themes();
594 $this->get_installer_instance();
595
596 $updates['upgradable_themes'] = $this->installer_instance->get_upgradable_themes();
597 }
598
599
600
601 if($backups){
602 $this->get_backup_instance();
603 $backups = $this->backup_instance->get_backup_stats();
604 $updates['backups'] = $backups;
605 foreach($backups as $task_name => $backup_results){
606 foreach($backup_results as $k => $backup){
607 if(isset($backups[$task_name][$k]['server']['file_path'])){
608 unset($backups[$task_name][$k]['server']['file_path']);
609 }
610 }
611 }
612 $updates['backups'] = $backups;
613 }
614
615 if( !class_exists( 'WP_Http' ) ){
616 include_once( ABSPATH . WPINC. '/class-http.php' );
617 }
618
619 $args = array();
620 $args['body'] = array('updates' => $updates, 'notification_key' => $notification_key);
621 $result= wp_remote_post($url, $args);
622
623 }
624
625
626 }
627
628
629 function cmp_posts_worker($a, $b)
630 {
631 return ($a->post_modified < $b->post_modified);
632 }
633
634 }
635 ?>