PluginProbe
ManageWP Worker / 3.9.7
ManageWP Worker v3.9.7
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.7, at stats.class.php

431 lines 15.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 = $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
137 $scheduled_posts[] = $recent;
138 }
139
140
141 $all_pages_published = get_pages('post_status=publish&numberposts=3&orderby=modified&order=desc');
142 $recent_pages_published = array();
143 foreach ((array)$all_pages_published as $id => $recent_page_published) {
144 $recent = new stdClass();
145 $recent->post_permalink = get_permalink($recent_page_published->ID);
146
147 $recent->ID = $recent_page_published->ID;
148 $recent->post_date = $recent_page_published->post_date;
149 $recent->post_title = $recent_page_published->post_title;
150 $recent->post_modified = $recent_page_published->post_modified;
151
152 $recent_posts[] = $recent;
153 }
154 usort($recent_posts, 'cmp_posts_worker');
155 $stats['posts'] = array_slice($recent_posts, 0, 20);
156
157 $all_pages_drafts = get_pages('post_status=draft&numberposts=20&orderby=modified&order=desc');
158 $recent_pages_drafts = array();
159 foreach ((array)$all_pages_drafts as $id => $recent_pages_draft) {
160 $recent = new stdClass();
161 $recent->post_permalink = get_permalink($recent_pages_draft->ID);
162 $recent->ID = $recent_pages_draft->ID;
163 $recent->post_date = $recent_pages_draft->post_date;
164 $recent->post_title = $recent_pages_draft->post_title;
165 $recent->post_modified = $recent_pages_draft->post_modified;
166
167 $recent_drafts[] = $recent;
168 }
169 usort($recent_drafts, 'cmp_posts_worker');
170 $stats['drafts'] = array_slice($recent_drafts, 0, 20);
171
172
173 $pages_scheduled = get_pages('post_status=future&numberposts=20&orderby=modified&order=desc');
174 $recent_pages_drafts = array();
175 foreach ((array)$pages_scheduled as $id => $scheduled) {
176 $recent = new stdClass();
177 $recent->post_permalink = get_permalink($scheduled->ID);
178 $recent->ID = $scheduled->ID;
179 $recent->post_date = $scheduled->post_date;
180 $recent->post_title = $scheduled->post_title;
181 $recent->post_modified = $scheduled->post_modified;
182
183 $scheduled_posts[] = $recent;
184 }
185 usort($scheduled_posts, 'cmp_posts_worker');
186 $stats['scheduled'] = array_slice($scheduled_posts, 0, 20);
187
188
189
190 if (!function_exists('get_filesystem_method'))
191 include_once(ABSPATH . 'wp-admin/includes/file.php');
192
193 $stats['writable'] = $this->is_server_writable();
194
195 //Backup Results
196 $stats['mwp_backups'] = $this->get_backup_instance()->get_backup_stats();
197
198 //Backup requirements
199 $stats['mwp_backup_req'] = $this->get_backup_instance()->check_backup_compat();
200
201 $stats['sheduled_backup'] = '12.07.2011 13:00';
202 $stats['sheduled_next'] = '12.08.2011 13:00';
203
204 $stats = apply_filters('mmb_stats_filter', $stats);
205
206 return $stats;
207 }
208
209 function get_stats_notification($params)
210 {
211
212 global $mmb_wp_version, $mmb_plugin_dir;
213 $stats = array();
214
215 //define constants
216 $num_pending_comments = 1000;
217
218
219 require_once(ABSPATH . '/wp-admin/includes/update.php');
220
221 $stats['worker_version'] = MMB_WORKER_VERSION;
222 $stats['wordpress_version'] = $mmb_wp_version;
223
224 $updates = $this->mmb_get_transient('update_core');
225
226 if ($updates->updates[0]->response == 'development' || version_compare($mmb_wp_version, $updates->updates[0]->current, '<')) {
227 $updates->updates[0]->current_version = $mmb_wp_version;
228 $stats['core_updates'] = $updates->updates[0];
229 } else
230 $stats['core_updates'] = false;
231
232 $mmb_user_hits = get_option('user_hit_count');
233 if (is_array($mmb_user_hits)) {
234 end($mmb_user_hits);
235 $last_key_date = key($mmb_user_hits);
236 $current_date = date('Y-m-d');
237 if ($last_key_date != $curent_date)
238 $this->set_hit_count(true);
239 }
240
241
242 $this->get_theme_instance();
243 $this->get_plugin_instance();
244 $stats['upgradable_themes'] = $this->theme_instance->get_upgradable_themes();
245 $stats['upgradable_plugins'] = $this->plugin_instance->get_upgradable_plugins();
246
247 $pending_comments = get_comments('status=hold&number=' . $num_pending_comments);
248
249 $stats['comments_pending'] = count($pending_comments);
250
251 return $stats;
252 }
253
254
255 function get_comments_stats(){
256 $num_pending_comments = 3;
257 $num_approved_comments = 3;
258 $pending_comments = get_comments('status=hold&number=' . $num_pending_comments);
259 foreach ($pending_comments as &$comment) {
260 $commented_post = get_post($comment->comment_post_ID);
261 $comment->post_title = $commented_post->post_title;
262 }
263 $stats['comments']['pending'] = $pending_comments;
264
265
266 $approved_comments = get_comments('status=approve&number=' . $num_approved_comments);
267 foreach ($approved_comments as &$comment) {
268 $commented_post = get_post($comment->comment_post_ID);
269 $comment->post_title = $commented_post->post_title;
270 }
271 $stats['comments']['approved'] = $approved_comments;
272
273 return $stats;
274 }
275 function get_initial_stats()
276 {
277 global $mmb_plugin_dir;
278
279 $stats = array();
280
281 $stats['email'] = get_option('admin_email');
282 $stats['no_openssl'] = $this->get_random_signature();
283 $stats['content_path'] = WP_CONTENT_DIR;
284 $stats['worker_path'] = $mmb_plugin_dir;
285 $stats['worker_version'] = MMB_WORKER_VERSION;
286 $stats['site_title'] = get_bloginfo('name');
287 $stats['site_tagline'] = get_bloginfo('description');
288 $stats['site_home'] = get_option('home');
289
290
291 if (!function_exists('get_filesystem_method'))
292 include_once(ABSPATH . 'wp-admin/includes/file.php');
293
294 $stats['writable'] = $this->is_server_writable();
295
296 return $stats;
297 }
298
299
300
301 function set_hit_count($fix_count = false)
302 {
303 if ($fix_count || (!is_admin() && !MMB_Stats::detect_bots())) {
304 $date = date('Y-m-d');
305 $user_hit_count = (array) get_option('user_hit_count');
306 if (!$user_hit_count) {
307 $user_hit_count[$date] = 1;
308 update_option('user_hit_count', $user_hit_count);
309 } else {
310 $dated_keys = array_keys($user_hit_count);
311 $last_visit_date = $dated_keys[count($dated_keys) - 1];
312
313 $days = intval((strtotime($date) - strtotime($last_visit_date)) / 60 / 60 / 24);
314
315 if ($days > 1) {
316 $date_to_add = date('Y-m-d', strtotime($last_visit_date));
317
318 for ($i = 1; $i < $days; $i++) {
319 if (count($user_hit_count) > 14) {
320 $shifted = @array_shift($user_hit_count);
321 }
322
323 $next_key = strtotime('+1 day', strtotime($date_to_add));
324 if ($next_key == $date) {
325 break;
326 } else {
327 $user_hit_count[$next_key] = 0;
328 }
329 }
330
331 }
332
333 if (!isset($user_hit_count[$date])) {
334 $user_hit_count[$date] = 0;
335 }
336 if (!$fix_count)
337 $user_hit_count[$date] = ((int)$user_hit_count[$date] ) + 1;
338
339 if (count($user_hit_count) > 14) {
340 $shifted = @array_shift($user_hit_count);
341 }
342
343 update_option('user_hit_count', $user_hit_count);
344
345 }
346 }
347 }
348
349 function get_hit_count()
350 {
351 // Check if there are no hits on last key date
352 $mmb_user_hits = get_option('user_hit_count');
353 if (is_array($mmb_user_hits)) {
354 end($mmb_user_hits);
355 $last_key_date = key($mmb_user_hits);
356 $current_date = date('Y-m-d');
357 if ($last_key_date != $curent_date)
358 $this->set_hit_count(true);
359 }
360
361 return get_option('user_hit_count');
362 }
363
364 function detect_bots()
365 {
366 $agent = $_SERVER['HTTP_USER_AGENT'];
367
368 if ($agent == '')
369 return false;
370
371 $bot_list = array(
372 "Teoma",
373 "alexa",
374 "froogle",
375 "Gigabot",
376 "inktomi",
377 "looksmart",
378 "URL_Spider_SQL",
379 "Firefly",
380 "NationalDirectory",
381 "Ask Jeeves",
382 "TECNOSEEK",
383 "InfoSeek",
384 "WebFindBot",
385 "girafabot",
386 "crawler",
387 "www.galaxy.com",
388 "Googlebot",
389 "Scooter",
390 "Slurp",
391 "msnbot",
392 "appie",
393 "FAST",
394 "WebBug",
395 "Spade",
396 "ZyBorg",
397 "rabaz",
398 "Baiduspider",
399 "Feedfetcher-Google",
400 "TechnoratiSnoop",
401 "Rankivabot",
402 "Mediapartners-Google",
403 "Sogou web spider",
404 "WebAlta Crawler",
405 "aolserver"
406 );
407
408 $thebot = '';
409 foreach ($bot_list as $bot) {
410 if ((boolean)strpos($bot, $agent)) {
411 $thebot = $bot;
412 break;
413 }
414 }
415
416 if ($thebot != '') {
417 return $thebot;
418 } else
419 return false;
420 }
421
422
423 }
424
425 function cmp_posts_worker($a, $b)
426 {
427 return ($a->post_modified < $b->post_modified);
428 }
429
430
431 ?>