PluginProbe
ManageWP Worker / 3.9.8
ManageWP Worker v3.9.8
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.8, at stats.class.php

465 lines 16.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
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($params)
27 {
28 $num = extract($params);
29
30 if ($refresh == 'transient') {
31 include_once(ABSPATH . 'wp-includes/update.php');
32 @wp_update_plugins();
33 @wp_update_themes();
34 @wp_version_check();
35 }
36
37 global $wpdb, $mmb_wp_version, $mmb_plugin_dir, $wp_version, $wp_local_package;
38 $stats = array();
39
40 //define constants
41 $num_pending_comments = 10;
42 $num_approved_comments = 3;
43 $num_spam_comments = 0;
44 $num_draft_comments = 0;
45 $num_trash_comments = 0;
46
47 include_once(ABSPATH . '/wp-admin/includes/update.php');
48
49 $stats['worker_version'] = MMB_WORKER_VERSION;
50 $stats['wordpress_version'] = $wp_version;
51 $stats['wordpress_locale_pckg'] = $wp_local_package;
52 $stats['wp_multisite'] = $this->mmb_multisite;
53 $stats['php_version'] = phpversion();
54 $stats['mysql_version'] = $wpdb->db_version();
55
56 if (function_exists('get_core_updates')) {
57 $updates = get_core_updates();
58 if (!empty($updates)) {
59 $current_transient = $updates[0];
60 if ($current_transient->response == "development" || version_compare($wp_version, $current_transient->current, '<')) {
61 $current_transient->current_version = $wp_version;
62 $stats['core_updates'] = $current_transient;
63 } else
64 $stats['core_updates'] = false;
65 } else
66 $stats['core_updates'] = false;
67 }
68
69 $mmb_user_hits = get_option('user_hit_count');
70 if (is_array($mmb_user_hits)) {
71 end($mmb_user_hits);
72 $last_key_date = key($mmb_user_hits);
73 $current_date = date('Y-m-d');
74 if ($last_key_date != $curent_date)
75 $this->set_hit_count(true);
76 }
77 $stats['hit_counter'] = get_option('user_hit_count');
78
79 $this->get_installer_instance();
80 $stats['upgradable_themes'] = $this->installer_instance->get_upgradable_themes();
81 $stats['upgradable_plugins'] = $this->installer_instance->get_upgradable_plugins();
82
83 $pending_comments = get_comments('status=hold&number=' . $num_pending_comments);
84 foreach ($pending_comments as &$comment) {
85 $commented_post = get_post($comment->comment_post_ID);
86 $comment->post_title = $commented_post->post_title;
87 }
88 $stats['comments']['pending'] = $pending_comments;
89
90
91 $approved_comments = get_comments('status=approve&number=' . $num_approved_comments);
92 foreach ($approved_comments as &$comment) {
93 $commented_post = get_post($comment->comment_post_ID);
94 $comment->post_title = $commented_post->post_title;
95 }
96 $stats['comments']['approved'] = $approved_comments;
97
98
99 $all_posts = get_posts('post_status=publish&numberposts=3&orderby=modified&order=desc');
100 $recent_posts = array();
101
102 foreach ($all_posts as $id => $recent_post) {
103 $recent = new stdClass();
104 $recent->post_permalink = get_permalink($recent_post->ID);
105 $recent->ID = $recent_post->ID;
106 $recent->post_date = $recent_post->post_date;
107 $recent->post_title = $recent_post->post_title;
108 $recent->post_modified = $recent_post->post_modified;
109 $recent->comment_count = (int)$recent_post->comment_count;
110 $recent_posts[] = $recent;
111 }
112
113
114 $all_drafts = get_posts('post_status=draft&numberposts=20&orderby=modified&order=desc');
115 $recent_drafts = array();
116 foreach ($all_drafts as $id => $recent_draft) {
117 $recent = new stdClass();
118 $recent->post_permalink = get_permalink($recent_draft->ID);
119 $recent->ID = $recent_draft->ID;
120 $recent->post_date = $recent_draft->post_date;
121 $recent->post_title = $recent_draft->post_title;
122 $recent->post_modified = $recent_draft->post_modified;
123
124 $recent_drafts[] = $recent;
125 }
126
127 $all_scheduled = get_posts('post_status=future&numberposts=20&orderby=post_date&order=desc');
128 $scheduled_posts = array();
129 foreach ($all_scheduled as $id => $scheduled) {
130 $recent = new stdClass();
131 $recent->post_permalink = get_permalink($scheduled->ID);
132 $recent->ID = $scheduled->ID;
133 $recent->post_date = $scheduled->post_date;
134 $recent->post_title = $scheduled->post_title;
135 $recent->post_modified = $scheduled->post_modified;
136 $scheduled_posts[] = $recent;
137 }
138
139
140 $all_pages_published = get_pages('post_status=publish&numberposts=3&orderby=modified&order=desc');
141 $recent_pages_published = array();
142 foreach ((array)$all_pages_published as $id => $recent_page_published) {
143 $recent = new stdClass();
144 $recent->post_permalink = get_permalink($recent_page_published->ID);
145
146 $recent->ID = $recent_page_published->ID;
147 $recent->post_date = $recent_page_published->post_date;
148 $recent->post_title = $recent_page_published->post_title;
149 $recent->post_modified = $recent_page_published->post_modified;
150
151 $recent_posts[] = $recent;
152 }
153 usort($recent_posts, array($this, 'cmp_posts_worker'));
154 $stats['posts'] = array_slice($recent_posts, 0, 20);
155
156 $all_pages_drafts = get_pages('post_status=draft&numberposts=20&orderby=modified&order=desc');
157 $recent_pages_drafts = array();
158 foreach ((array)$all_pages_drafts as $id => $recent_pages_draft) {
159 $recent = new stdClass();
160 $recent->post_permalink = get_permalink($recent_pages_draft->ID);
161 $recent->ID = $recent_pages_draft->ID;
162 $recent->post_date = $recent_pages_draft->post_date;
163 $recent->post_title = $recent_pages_draft->post_title;
164 $recent->post_modified = $recent_pages_draft->post_modified;
165
166 $recent_drafts[] = $recent;
167 }
168 usort($recent_drafts, array($this, 'cmp_posts_worker'));
169 $stats['drafts'] = array_slice($recent_drafts, 0, 20);
170
171
172 $pages_scheduled = get_pages('post_status=future&numberposts=20&orderby=modified&order=desc');
173 $recent_pages_drafts = array();
174 foreach ((array)$pages_scheduled as $id => $scheduled) {
175 $recent = new stdClass();
176 $recent->post_permalink = get_permalink($scheduled->ID);
177 $recent->ID = $scheduled->ID;
178 $recent->post_date = $scheduled->post_date;
179 $recent->post_title = $scheduled->post_title;
180 $recent->post_modified = $scheduled->post_modified;
181
182 $scheduled_posts[] = $recent;
183 }
184 usort($scheduled_posts, array($this, 'cmp_posts_worker'));
185 $stats['scheduled'] = array_slice($scheduled_posts, 0, 20);
186
187
188
189 if (!function_exists('get_filesystem_method'))
190 include_once(ABSPATH . 'wp-admin/includes/file.php');
191
192 $stats['writable'] = $this->is_server_writable();
193
194 //Backup Results
195 $stats['mwp_backups'] = $this->get_backup_instance()->get_backup_stats();
196 $stats['mwp_next_backups'] = $this->get_backup_instance()->get_next_schedules();
197
198 $clone_backup = get_option('mwp_manual_backup');
199
200 if(!is_array($clone_backup) || !file_exists($clone_backup['file_path'])){
201 $clone_backup = '';
202 } else {
203 $clone_backup = $clone_backup['file_url'];
204 }
205 $stats['clone_backup'] = $clone_backup;
206
207 //Backup requirements
208 $stats['mwp_backup_req'] = $this->get_backup_instance()->check_backup_compat();
209
210 $stats = apply_filters('mmb_stats_filter', $stats);
211
212 return $stats;
213 }
214
215 function get_comments_stats(){
216 $num_pending_comments = 3;
217 $num_approved_comments = 3;
218 $pending_comments = get_comments('status=hold&number=' . $num_pending_comments);
219 foreach ($pending_comments as &$comment) {
220 $commented_post = get_post($comment->comment_post_ID);
221 $comment->post_title = $commented_post->post_title;
222 }
223 $stats['comments']['pending'] = $pending_comments;
224
225
226 $approved_comments = get_comments('status=approve&number=' . $num_approved_comments);
227 foreach ($approved_comments as &$comment) {
228 $commented_post = get_post($comment->comment_post_ID);
229 $comment->post_title = $commented_post->post_title;
230 }
231 $stats['comments']['approved'] = $approved_comments;
232
233 return $stats;
234 }
235
236 function get_initial_stats()
237 {
238 global $mmb_plugin_dir;
239
240 $stats = array();
241
242 $stats['email'] = get_option('admin_email');
243 $stats['no_openssl'] = $this->get_random_signature();
244 $stats['content_path'] = WP_CONTENT_DIR;
245 $stats['worker_path'] = $mmb_plugin_dir;
246 $stats['worker_version'] = MMB_WORKER_VERSION;
247 $stats['site_title'] = get_bloginfo('name');
248 $stats['site_tagline'] = get_bloginfo('description');
249 $stats['site_home'] = get_option('home');
250
251
252 if (!function_exists('get_filesystem_method'))
253 include_once(ABSPATH . 'wp-admin/includes/file.php');
254
255 $stats['writable'] = $this->is_server_writable();
256
257 return $stats;
258 }
259
260
261
262 function set_hit_count($fix_count = false)
263 {
264 if ($fix_count || (!is_admin() && !MMB_Stats::detect_bots())) {
265 $date = date('Y-m-d');
266 $user_hit_count = (array) get_option('user_hit_count');
267 if (!$user_hit_count) {
268 $user_hit_count[$date] = 1;
269 update_option('user_hit_count', $user_hit_count);
270 } else {
271 $dated_keys = array_keys($user_hit_count);
272 $last_visit_date = $dated_keys[count($dated_keys) - 1];
273
274 $days = intval((strtotime($date) - strtotime($last_visit_date)) / 60 / 60 / 24);
275
276 if ($days > 1) {
277 $date_to_add = date('Y-m-d', strtotime($last_visit_date));
278
279 for ($i = 1; $i < $days; $i++) {
280 if (count($user_hit_count) > 14) {
281 $shifted = @array_shift($user_hit_count);
282 }
283
284 $next_key = strtotime('+1 day', strtotime($date_to_add));
285 if ($next_key == $date) {
286 break;
287 } else {
288 $user_hit_count[$next_key] = 0;
289 }
290 }
291
292 }
293
294 if (!isset($user_hit_count[$date])) {
295 $user_hit_count[$date] = 0;
296 }
297 if (!$fix_count)
298 $user_hit_count[$date] = ((int)$user_hit_count[$date] ) + 1;
299
300 if (count($user_hit_count) > 14) {
301 $shifted = @array_shift($user_hit_count);
302 }
303
304 update_option('user_hit_count', $user_hit_count);
305
306 }
307 }
308 }
309
310 function get_hit_count()
311 {
312 // Check if there are no hits on last key date
313 $mmb_user_hits = get_option('user_hit_count');
314 if (is_array($mmb_user_hits)) {
315 end($mmb_user_hits);
316 $last_key_date = key($mmb_user_hits);
317 $current_date = date('Y-m-d');
318 if ($last_key_date != $curent_date)
319 $this->set_hit_count(true);
320 }
321
322 return get_option('user_hit_count');
323 }
324
325 function detect_bots()
326 {
327 $agent = $_SERVER['HTTP_USER_AGENT'];
328
329 if ($agent == '')
330 return false;
331
332 $bot_list = array(
333 "Teoma",
334 "alexa",
335 "froogle",
336 "Gigabot",
337 "inktomi",
338 "looksmart",
339 "URL_Spider_SQL",
340 "Firefly",
341 "NationalDirectory",
342 "Ask Jeeves",
343 "TECNOSEEK",
344 "InfoSeek",
345 "WebFindBot",
346 "girafabot",
347 "crawler",
348 "www.galaxy.com",
349 "Googlebot",
350 "Scooter",
351 "Slurp",
352 "msnbot",
353 "appie",
354 "FAST",
355 "WebBug",
356 "Spade",
357 "ZyBorg",
358 "rabaz",
359 "Baiduspider",
360 "Feedfetcher-Google",
361 "TechnoratiSnoop",
362 "Rankivabot",
363 "Mediapartners-Google",
364 "Sogou web spider",
365 "WebAlta Crawler",
366 "aolserver"
367 );
368
369 $thebot = '';
370 foreach ($bot_list as $bot) {
371 if ((boolean)strpos($bot, $agent)) {
372 $thebot = $bot;
373 break;
374 }
375 }
376
377 if ($thebot != '') {
378 return $thebot;
379 } else
380 return false;
381 }
382
383
384 function set_notifications($params)
385 {
386 if(empty($params))
387 return false;
388
389 extract($params);
390
391 if(!isset($delete)){
392 $mwp_notifications = array('plugins' => $plugins, 'themes' => $themes, 'wp' => $wp,'url' => $url, 'notification_key' => $notification_key);
393 update_option('mwp_notifications',$mwp_notifications);
394 } else {
395 delete_option('mwp_notifications');
396 }
397
398 return true;
399
400 }
401
402 //Cron update check for notifications
403 function check_notifications(){
404 global $wpdb, $mmb_wp_version, $mmb_plugin_dir, $wp_version, $wp_local_package;
405
406 $mwp_notifications = get_option('mwp_notifications',true);
407 $updates = array();
408
409 if(is_array($mwp_notifications) && $mwp_notifications != false){
410 include_once(ABSPATH . 'wp-includes/update.php');
411 include_once(ABSPATH . '/wp-admin/includes/update.php');
412 extract($mwp_notifications);
413
414 //Check wordpress core updates
415 if($wp){
416 @wp_version_check();
417 if (function_exists('get_core_updates')) {
418 $wp_updates = get_core_updates();
419 if (!empty($wp_updates)) {
420 $current_transient = $wp_updates[0];
421 if ($current_transient->response == "development" || version_compare($wp_version, $current_transient->current, '<')) {
422 $current_transient->current_version = $wp_version;
423 $updates['core_updates'] = $current_transient;
424 } else
425 $updates['core_updates'] = array();
426 } else
427 $updates['core_updates'] = array();
428 }
429
430 //Check plugin updates
431 if($plugins){
432 @wp_update_plugins();
433 $this->get_installer_instance();
434 $updates['upgradable_plugins'] = $this->installer_instance->get_upgradable_plugins();
435 }
436
437 //Check theme updates
438 if($themes)
439 {
440 @wp_update_themes();
441 $this->get_installer_instance();
442
443 $updates['upgradable_themes'] = $this->installer_instance->get_upgradable_themes();
444 }
445
446 }
447
448 if( !class_exists( 'WP_Http' ) ){
449 include_once( ABSPATH . WPINC. '/class-http.php' );
450 }
451
452 $args = array();
453 $args['body'] = array('updates' => $updates, 'notification_key' => $notification_key);
454 $result= wp_remote_post($url, $args);
455 }
456 }
457
458
459 function cmp_posts_worker($a, $b)
460 {
461 return ($a->post_modified < $b->post_modified);
462 }
463
464 }
465 ?>