PluginProbe
ManageWP Worker / 3.9.20
ManageWP Worker v3.9.20
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.20, at stats.class.php

801 lines 30.5 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 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 ($refresh == 'transient') {
361 $current = $this->mmb_get_transient('update_core');
362 if (isset($current->last_checked) || get_option('mmb_forcerefresh')) {
363 update_option('mmb_forcerefresh', false);
364 if (time() - $current->last_checked > 14400) {
365 @wp_version_check();
366 @wp_update_plugins();
367 @wp_update_themes();
368 }
369 }
370 }
371
372 global $wpdb, $mmb_wp_version, $mmb_plugin_dir, $wp_version, $wp_local_package;
373
374 $stats['worker_version'] = MMB_WORKER_VERSION;
375 $stats['wordpress_version'] = $wp_version;
376 $stats['wordpress_locale_pckg'] = $wp_local_package;
377 $stats['php_version'] = phpversion();
378 $stats['mysql_version'] = $wpdb->db_version();
379 $stats['wp_multisite'] = $this->mmb_multisite;
380 $stats['network_install'] = $this->network_admin_install;
381
382 if ( !function_exists('get_filesystem_method') )
383 include_once(ABSPATH . 'wp-admin/includes/file.php');
384 $mmode = get_option('mwp_maintenace_mode');
385
386 if( !empty($mmode) && isset($mmode['active']) && $mmode['active'] == true){
387 $stats['maintenance'] = true;
388 }
389 $stats['writable'] = $this->is_server_writable();
390
391 return $stats;
392 }
393
394 function get($params)
395 {
396 global $wpdb, $mmb_wp_version, $mmb_plugin_dir, $_mmb_item_filter;
397
398 include_once(ABSPATH . 'wp-includes/update.php');
399 include_once(ABSPATH . '/wp-admin/includes/update.php');
400
401 $stats = $this->mmb_parse_action_params('get', $params, $this);
402 $update_check = array();
403 $num = extract($params);
404 if ($refresh == 'transient') {
405 $update_check = apply_filters('mwp_premium_update_check', $update_check);
406 if (!empty($update_check)) {
407 foreach ($update_check as $update) {
408 if (is_array($update['callback'])) {
409 $update_result = call_user_func(array(
410 $update['callback'][0],
411 $update['callback'][1]
412 ));
413 } else if (is_string($update['callback'])) {
414 $update_result = call_user_func($update['callback']);
415 }
416 }
417 }
418 }
419
420 if ($this->mmb_multisite) {
421 $stats = $this->get_multisite($stats);
422 }
423
424 update_option('mmb_stats_filter', $params['item_filter']['get_stats']);
425 $stats = apply_filters('mmb_stats_filter', $stats);
426 return $stats;
427 }
428
429 function get_multisite($stats = array())
430 {
431 global $current_user, $wpdb;
432 $user_blogs = get_blogs_of_user( $current_user->ID );
433 $network_blogs = $wpdb->get_results( $wpdb->prepare("select `blog_id`, `site_id` from `{$wpdb->blogs}`") );
434 if ($this->network_admin_install == '1' && is_super_admin()) {
435 if (!empty($network_blogs)) {
436 $blogs = array();
437 foreach ( $network_blogs as $details) {
438 if($details->site_id == $details->blog_id)
439 continue;
440 else {
441 $data = get_blog_details($details->blog_id);
442 if(in_array($details->blog_id, array_keys($user_blogs)))
443 $stats['network_blogs'][] = $data->siteurl;
444 else {
445 $user = get_users( array( 'blog_id' => $details->blog_id, 'number' => 1) );
446 if( !empty($user) )
447 $stats['other_blogs'][$data->siteurl] = $user[0]->user_login;
448 }
449 }
450 }
451 }
452 }
453 return $stats;
454 }
455
456 function get_comments_stats()
457 {
458 $num_pending_comments = 3;
459 $num_approved_comments = 3;
460 $pending_comments = get_comments('status=hold&number=' . $num_pending_comments);
461 foreach ($pending_comments as &$comment) {
462 $commented_post = get_post($comment->comment_post_ID);
463 $comment->post_title = $commented_post->post_title;
464 }
465 $stats['comments']['pending'] = $pending_comments;
466
467
468 $approved_comments = get_comments('status=approve&number=' . $num_approved_comments);
469 foreach ($approved_comments as &$comment) {
470 $commented_post = get_post($comment->comment_post_ID);
471 $comment->post_title = $commented_post->post_title;
472 }
473 $stats['comments']['approved'] = $approved_comments;
474
475 return $stats;
476 }
477
478 function get_initial_stats()
479 {
480 global $mmb_plugin_dir;
481
482 $stats = array();
483
484 $stats['email'] = get_option('admin_email');
485 $stats['no_openssl'] = $this->get_random_signature();
486 $stats['content_path'] = WP_CONTENT_DIR;
487 $stats['worker_path'] = $mmb_plugin_dir;
488 $stats['worker_version'] = MMB_WORKER_VERSION;
489 $stats['site_title'] = get_bloginfo('name');
490 $stats['site_tagline'] = get_bloginfo('description');
491 $stats['db_name'] = $this->get_active_db();
492 $stats['site_home'] = get_option('home');
493 $stats['admin_url'] = admin_url();
494 $stats['wp_multisite'] = $this->mmb_multisite;
495 $stats['network_install'] = $this->network_admin_install;
496
497 if ($this->mmb_multisite) {
498 $details = get_blog_details($this->mmb_multisite);
499 if (isset($details->site_id)) {
500 $details = get_blog_details($details->site_id);
501 if (isset($details->siteurl))
502 $stats['network_parent'] = $details->siteurl;
503 }
504 }
505 if (!function_exists('get_filesystem_method'))
506 include_once(ABSPATH . 'wp-admin/includes/file.php');
507
508 $stats['writable'] = $this->is_server_writable();
509
510 return $stats;
511 }
512
513 function get_active_db(){
514 global $wpdb;
515 $sql='SELECT DATABASE() as db_name';
516
517 $sqlresult = $wpdb->get_row($sql);
518 $active_db=$sqlresult->db_name;
519
520 return $active_db;
521
522 }
523
524 function set_hit_count($fix_count = false)
525 {
526 global $mmb_core;
527 $uptime_robot = array("74.86.158.106", "74.86.179.130", "74.86.179.131", "46.137.190.132", "122.248.234.23", "74.86.158.107"); //don't let uptime robot to affect visit count
528
529 if ($fix_count || (!is_admin() && !MMB_Stats::is_bot() && !isset($_GET['doing_wp_cron']) && !in_array($_SERVER['REMOTE_ADDR'],$uptime_robot)) ) {
530
531 $date = date('Y-m-d');
532 $user_hit_count = (array) get_option('user_hit_count');
533 if (!$user_hit_count) {
534 $user_hit_count[$date] = 1;
535 update_option('user_hit_count', $user_hit_count);
536 } else {
537 $dated_keys = array_keys($user_hit_count);
538 $last_visit_date = $dated_keys[count($dated_keys) - 1];
539
540 $days = intval((strtotime($date) - strtotime($last_visit_date)) / 60 / 60 / 24);
541
542 if ($days > 1) {
543 $date_to_add = date('Y-m-d', strtotime($last_visit_date));
544
545 for ($i = 1; $i < $days; $i++) {
546 if (count($user_hit_count) > 14) {
547 $shifted = @array_shift($user_hit_count);
548 }
549
550 $next_key = strtotime('+1 day', strtotime($date_to_add));
551 if ($next_key == $date) {
552 break;
553 } else {
554 $user_hit_count[$next_key] = 0;
555 }
556 }
557
558 }
559
560 if (!isset($user_hit_count[$date])) {
561 $user_hit_count[$date] = 0;
562 }
563 if (!$fix_count)
564 $user_hit_count[$date] = ((int) $user_hit_count[$date]) + 1;
565
566 if (count($user_hit_count) > 14) {
567 $shifted = @array_shift($user_hit_count);
568 }
569
570 update_option('user_hit_count', $user_hit_count);
571
572 }
573 }
574 }
575
576 function get_hit_count()
577 {
578 // Check if there are no hits on last key date
579 $mmb_user_hits = get_option('user_hit_count');
580 if (is_array($mmb_user_hits)) {
581 end($mmb_user_hits);
582 $last_key_date = key($mmb_user_hits);
583 $current_date = date('Y-m-d');
584 if ($last_key_date != $curent_date)
585 $this->set_hit_count(true);
586 }
587
588 return get_option('user_hit_count');
589 }
590
591 function is_bot()
592 {
593 $agent = $_SERVER['HTTP_USER_AGENT'];
594
595 if ($agent == '')
596 return false;
597
598 $bot_list = array(
599 "Teoma",
600 "alexa",
601 "froogle",
602 "Gigabot",
603 "inktomi",
604 "looksmart",
605 "URL_Spider_SQL",
606 "Firefly",
607 "NationalDirectory",
608 "Ask Jeeves",
609 "TECNOSEEK",
610 "InfoSeek",
611 "WebFindBot",
612 "girafabot",
613 "crawler",
614 "www.galaxy.com",
615 "Googlebot",
616 "Scooter",
617 "Slurp",
618 "msnbot",
619 "appie",
620 "FAST",
621 "WebBug",
622 "Spade",
623 "ZyBorg",
624 "rabaz",
625 "Baiduspider",
626 "Feedfetcher-Google",
627 "TechnoratiSnoop",
628 "Rankivabot",
629 "Mediapartners-Google",
630 "Sogou web spider",
631 "WebAlta Crawler",
632 "aolserver"
633 );
634
635 foreach ($bot_list as $bot)
636 if (strpos($agent, $bot) !== false)
637 return true;
638
639 return false;
640 }
641
642
643 function set_notifications($params)
644 {
645 if (empty($params))
646 return false;
647
648 extract($params);
649
650 if (!isset($delete)) {
651 $mwp_notifications = array(
652 'plugins' => $plugins,
653 'themes' => $themes,
654 'wp' => $wp,
655 'backups' => $backups,
656 'url' => $url,
657 'notification_key' => $notification_key
658 );
659 update_option('mwp_notifications', $mwp_notifications);
660 } else {
661 delete_option('mwp_notifications');
662 }
663
664 return true;
665
666 }
667
668 //Cron update check for notifications
669 function check_notifications()
670 {
671 global $wpdb, $mmb_wp_version, $mmb_plugin_dir, $wp_version, $wp_local_package;
672
673 $mwp_notifications = get_option('mwp_notifications', true);
674
675 $args = array();
676 $updates = array();
677 $send = 0;
678 if (is_array($mwp_notifications) && $mwp_notifications != false) {
679 include_once(ABSPATH . 'wp-includes/update.php');
680 include_once(ABSPATH . '/wp-admin/includes/update.php');
681 extract($mwp_notifications);
682
683 //Check wordpress core updates
684 if ($wp) {
685 @wp_version_check();
686 if (function_exists('get_core_updates')) {
687 $wp_updates = get_core_updates();
688 if (!empty($wp_updates)) {
689 $current_transient = $wp_updates[0];
690 if ($current_transient->response == "development" || version_compare($wp_version, $current_transient->current, '<')) {
691 $current_transient->current_version = $wp_version;
692 $updates['core_updates'] = $current_transient;
693 } else
694 $updates['core_updates'] = array();
695 } else
696 $updates['core_updates'] = array();
697 }
698 }
699
700 //Check plugin updates
701 if ($plugins) {
702 @wp_update_plugins();
703 $this->get_installer_instance();
704 $updates['upgradable_plugins'] = $this->installer_instance->get_upgradable_plugins();
705 }
706
707 //Check theme updates
708 if ($themes) {
709 @wp_update_themes();
710 $this->get_installer_instance();
711
712 $updates['upgradable_themes'] = $this->installer_instance->get_upgradable_themes();
713 }
714
715 if ($backups) {
716 $this->get_backup_instance();
717 $backups = $this->backup_instance->get_backup_stats();
718 $updates['backups'] = $backups;
719 foreach ($backups as $task_name => $backup_results) {
720 foreach ($backup_results as $k => $backup) {
721 if (isset($backups[$task_name][$k]['server']['file_path'])) {
722 unset($backups[$task_name][$k]['server']['file_path']);
723 }
724 }
725 }
726 $updates['backups'] = $backups;
727 }
728
729
730 if (!empty($updates)) {
731 $args['body']['updates'] = $updates;
732 $args['body']['notification_key'] = $notification_key;
733 $send = 1;
734 }
735
736 }
737
738
739 $alert_data = get_option('mwp_pageview_alerts',true);
740 if(is_array($alert_data) && $alert_data['alert']){
741 $pageviews = get_option('user_hit_count');
742 $args['body']['alerts']['pageviews'] = $pageviews;
743 $args['body']['alerts']['site_id'] = $alert_data['site_id'];
744 if(!isset($url)){
745 $url = $alert_data['url'];
746 }
747 $send = 1;
748 }
749
750 if($send){
751 if (!class_exists('WP_Http')) {
752 include_once(ABSPATH . WPINC . '/class-http.php');
753 }
754 $result = wp_remote_post($url, $args);
755
756 if (is_array($result) && $result['body'] == 'mwp_delete_alert') {
757 delete_option('mwp_pageview_alerts');
758 }
759 }
760
761
762 }
763
764
765 function cmp_posts_worker($a, $b)
766 {
767 return ($a->post_date < $b->post_date);
768 }
769
770 function trim_content($content = '', $length = 200)
771 {
772 if (function_exists('mb_strlen') && function_exists('mb_substr'))
773 $content = (mb_strlen($content) > ($length + 3)) ? mb_substr($content, 0, $length) . '...' : $content;
774 else
775 $content = (strlen($content) > ($length + 3)) ? substr($content, 0, $length) . '...' : $content;
776
777 return $content;
778 }
779
780 function set_alerts($args){
781 extract($args);
782 update_option('mwp_pageview_alerts',array('site_id' => $site_id,'alert' => $alert,'url' => $url));
783 }
784
785 public static function readd_alerts( $params = array() ){
786 if( empty($params) || !isset($params['alerts']))
787 return $params;
788
789 if( !empty($params['alerts']) ){
790 update_option('mwp_pageview_alerts', $params['alerts']);
791 unset($params['alerts']);
792 }
793
794 return $params;
795 }
796 }
797
798 if( function_exists('add_filter') ){
799 add_filter( 'mwp_website_add', 'MMB_Stats::readd_alerts' );
800 }
801 ?>