PluginProbe
ManageWP Worker / 3.9.19
ManageWP Worker v3.9.19
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.19, at stats.class.php

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