PluginProbe
ManageWP Worker / 3.9.1
ManageWP Worker v3.9.1
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.1, at stats.class.php

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