PluginProbe
ManageWP Worker / 3.9.3
ManageWP Worker v3.9.3
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.3, at stats.class.php

429 lines 15.0 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 $stats['backups'] = $this->get_backups();
196
197 $stats = apply_filters('mmb_stats_filter', $stats);
198 return $stats;
199 }
200
201 function get_stats_notification($params)
202 {
203
204 global $mmb_wp_version, $mmb_plugin_dir;
205 $stats = array();
206
207 //define constants
208 $num_pending_comments = 1000;
209
210
211 require_once(ABSPATH . '/wp-admin/includes/update.php');
212
213 $stats['worker_version'] = MMB_WORKER_VERSION;
214 $stats['wordpress_version'] = $mmb_wp_version;
215
216 $updates = $this->mmb_get_transient('update_core');
217
218 if ($updates->updates[0]->response == 'development' || version_compare($mmb_wp_version, $updates->updates[0]->current, '<')) {
219 $updates->updates[0]->current_version = $mmb_wp_version;
220 $stats['core_updates'] = $updates->updates[0];
221 } else
222 $stats['core_updates'] = false;
223
224 $mmb_user_hits = get_option('user_hit_count');
225 if (is_array($mmb_user_hits)) {
226 end($mmb_user_hits);
227 $last_key_date = key($mmb_user_hits);
228 $current_date = date('Y-m-d');
229 if ($last_key_date != $curent_date)
230 $this->set_hit_count(true);
231 }
232
233
234 $this->get_theme_instance();
235 $this->get_plugin_instance();
236 $stats['upgradable_themes'] = $this->theme_instance->get_upgradable_themes();
237 $stats['upgradable_plugins'] = $this->plugin_instance->get_upgradable_plugins();
238
239 $pending_comments = get_comments('status=hold&number=' . $num_pending_comments);
240
241 $stats['comments_pending'] = count($pending_comments);
242
243 return $stats;
244 }
245
246
247 function get_comments_stats(){
248 $num_pending_comments = 3;
249 $num_approved_comments = 3;
250 $pending_comments = get_comments('status=hold&number=' . $num_pending_comments);
251 foreach ($pending_comments as &$comment) {
252 $commented_post = get_post($comment->comment_post_ID);
253 $comment->post_title = $commented_post->post_title;
254 }
255 $stats['comments']['pending'] = $pending_comments;
256
257
258 $approved_comments = get_comments('status=approve&number=' . $num_approved_comments);
259 foreach ($approved_comments as &$comment) {
260 $commented_post = get_post($comment->comment_post_ID);
261 $comment->post_title = $commented_post->post_title;
262 }
263 $stats['comments']['approved'] = $approved_comments;
264
265 return $stats;
266 }
267 function get_initial_stats()
268 {
269 global $mmb_plugin_dir;
270
271 $stats = array();
272
273 $stats['email'] = get_option('admin_email');
274 $stats['no_openssl'] = $this->get_random_signature();
275 $stats['content_path'] = WP_CONTENT_DIR;
276 $stats['worker_path'] = $mmb_plugin_dir;
277 $stats['worker_version'] = MMB_WORKER_VERSION;
278 $stats['site_title'] = get_bloginfo('name');
279 $stats['site_tagline'] = get_bloginfo('description');
280 $stats['site_home'] = get_option('home');
281
282
283 if (!function_exists('get_filesystem_method'))
284 include_once(ABSPATH . 'wp-admin/includes/file.php');
285
286 $stats['writable'] = $this->is_server_writable();
287
288 return $stats;
289 }
290
291
292
293 function set_hit_count($fix_count = false)
294 {
295 if ($fix_count || (!is_admin() && !MMB_Stats::detect_bots())) {
296 $date = date('Y-m-d');
297 $user_hit_count = (array) get_option('user_hit_count');
298 if (!$user_hit_count) {
299 $user_hit_count[$date] = 1;
300 update_option('user_hit_count', $user_hit_count);
301 } else {
302 $dated_keys = array_keys($user_hit_count);
303 $last_visit_date = $dated_keys[count($dated_keys) - 1];
304
305 $days = intval((strtotime($date) - strtotime($last_visit_date)) / 60 / 60 / 24);
306
307 if ($days > 1) {
308 $date_to_add = date('Y-m-d', strtotime($last_visit_date));
309
310 for ($i = 1; $i < $days; $i++) {
311 if (count($user_hit_count) > 14) {
312 $shifted = @array_shift($user_hit_count);
313 }
314
315 $next_key = strtotime('+1 day', strtotime($date_to_add));
316 if ($next_key == $date) {
317 break;
318 } else {
319 $user_hit_count[$next_key] = 0;
320 }
321 }
322
323 }
324
325 if (!isset($user_hit_count[$date])) {
326 $user_hit_count[$date] = 0;
327 }
328 if (!$fix_count)
329 $user_hit_count[$date] = ((int)$user_hit_count[$date] ) + 1;
330
331 if (count($user_hit_count) > 14) {
332 $shifted = @array_shift($user_hit_count);
333 }
334
335 update_option('user_hit_count', $user_hit_count);
336
337 }
338 }
339 }
340
341 function get_hit_count()
342 {
343 // Check if there are no hits on last key date
344 $mmb_user_hits = get_option('user_hit_count');
345 if (is_array($mmb_user_hits)) {
346 end($mmb_user_hits);
347 $last_key_date = key($mmb_user_hits);
348 $current_date = date('Y-m-d');
349 if ($last_key_date != $curent_date)
350 $this->set_hit_count(true);
351 }
352
353 return get_option('user_hit_count');
354 }
355
356 function detect_bots()
357 {
358 $agent = $_SERVER['HTTP_USER_AGENT'];
359
360 if ($agent == '')
361 return false;
362
363 $bot_list = array(
364 "Teoma",
365 "alexa",
366 "froogle",
367 "Gigabot",
368 "inktomi",
369 "looksmart",
370 "URL_Spider_SQL",
371 "Firefly",
372 "NationalDirectory",
373 "Ask Jeeves",
374 "TECNOSEEK",
375 "InfoSeek",
376 "WebFindBot",
377 "girafabot",
378 "crawler",
379 "www.galaxy.com",
380 "Googlebot",
381 "Scooter",
382 "Slurp",
383 "msnbot",
384 "appie",
385 "FAST",
386 "WebBug",
387 "Spade",
388 "ZyBorg",
389 "rabaz",
390 "Baiduspider",
391 "Feedfetcher-Google",
392 "TechnoratiSnoop",
393 "Rankivabot",
394 "Mediapartners-Google",
395 "Sogou web spider",
396 "WebAlta Crawler",
397 "aolserver"
398 );
399
400 $thebot = '';
401 foreach ($bot_list as $bot) {
402 if ((boolean)strpos($bot, $agent)) {
403 $thebot = $bot;
404 break;
405 }
406 }
407
408 if ($thebot != '') {
409 return $thebot;
410 } else
411 return false;
412 }
413
414 function get_backups()
415 {
416 $worker_options = get_option('mmb-worker');
417 //$backup_file = $worker_options['backups'][$type]['path'];
418 return $worker_options['backups'];
419 }
420
421 }
422
423 function cmp_posts_worker($a, $b)
424 {
425 return ($a->post_modified < $b->post_modified);
426 }
427
428
429 ?>