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

297 lines 10.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 global $mmb_wp_version, $mmb_plugin_dir;
29 $stats = array();
30
31 //define constants
32 $num_pending_comments = 1000;
33 $num_approved_comments = 3;
34 $num_spam_comments = 0;
35 $num_draft_comments = 0;
36 $num_trash_comments = 0;
37
38 require_once(ABSPATH . '/wp-admin/includes/update.php');
39
40 $stats['worker_version'] = MMB_WORKER_VERSION;
41 $stats['wordpress_version'] = $mmb_wp_version;
42
43 $updates = $this->mmb_get_transient('update_core');
44
45 if ($updates->updates[0]->response == 'development' || version_compare($mmb_wp_version, $updates->updates[0]->current, '<')) {
46 $updates->updates[0]->current_version = $mmb_wp_version;
47 $stats['core_updates'] = $updates->updates[0];
48 } else
49 $stats['core_updates'] = false;
50
51 $mmb_user_hits = get_option('user_hit_count');
52 if (is_array($mmb_user_hits)) {
53 end($mmb_user_hits);
54 $last_key_date = key($mmb_user_hits);
55 $current_date = date('Y-m-d');
56 if ($last_key_date != $curent_date)
57 $this->set_hit_count(true);
58 }
59 $stats['hit_counter'] = get_option('user_hit_count');
60
61
62 $stats['upgradable_themes'] = $this->get_installer_instance()->get_upgradable_themes();
63 $stats['upgradable_plugins'] = $this->get_installer_instance()->get_upgradable_plugins();
64
65 $pending_comments = get_comments('status=hold&number=' . $num_pending_comments);
66 foreach ($pending_comments as &$comment) {
67 $commented_post = get_post($comment->comment_post_ID);
68 $comment->post_title = $commented_post->post_title;
69 }
70 $stats['comments']['pending'] = $pending_comments;
71
72
73 $approved_comments = get_comments('status=approve&number=' . $num_approved_comments);
74 foreach ($approved_comments as &$comment) {
75 $commented_post = get_post($comment->comment_post_ID);
76 $comment->post_title = $commented_post->post_title;
77 }
78 $stats['comments']['approved'] = $approved_comments;
79
80
81 $all_posts = get_posts('post_status=publish&numberposts=3&orderby=modified&order=desc');
82 $stats['publish_count'] = count($all_posts);
83 $recent_posts = array();
84
85 foreach ($all_posts as $id => $recent_post) {
86 $recent = new stdClass();
87 $recent->post_permalink = get_permalink($recent->ID);
88 $recent->ID = $recent_post->ID;
89 $recent->post_date = $recent_post->post_date;
90 $recent->post_title = $recent_post->post_title;
91 $recent->post_modified = $recent_post->post_modified;
92 $recent->comment_count = $recent_post->comment_count;
93 $recent->post_permalink = $recent_post->post_permalink;
94
95
96 $recent_posts[] = $recent;
97 }
98 $stats['posts'] = $recent_posts;
99
100 $drafts = get_posts('post_status=draft&numberposts=3');
101 foreach ($drafts as $draft) {
102 $props = get_object_vars($draft);
103 foreach ($props as $name => $value) {
104 if ($name != 'post_title' && $name != 'ID' && $name != 'post_modified') {
105 unset($draft->$name);
106 } else {
107 $draft->post_title = get_the_title($draft->ID);
108 $draft->post_permalink = get_permalink($draft->ID);
109 }
110 }
111 }
112 $stats['draft_count'] = count($drafts);
113 $stats['drafts'] = $drafts;
114
115 if (!function_exists('get_filesystem_method'))
116 include_once(ABSPATH . 'wp-admin/includes/file.php');
117
118 if ((!defined('FTP_HOST') || !defined('FTP_USER') || !defined('FTP_PASS')) && (get_filesystem_method(array(), false) != 'direct')) {
119 $stats['writable'] = false;
120 } else
121 $stats['writable'] = true;
122
123 $stats = apply_filters('mmb_stats_filter', $stats);
124
125 return $stats;
126 }
127 function get_comments_stats(){
128 $num_pending_comments = 3;
129 $num_approved_comments = 3;
130 $pending_comments = get_comments('status=hold&number=' . $num_pending_comments);
131 foreach ($pending_comments as &$comment) {
132 $commented_post = get_post($comment->comment_post_ID);
133 $comment->post_title = $commented_post->post_title;
134 }
135 $stats['comments']['pending'] = $pending_comments;
136
137
138 $approved_comments = get_comments('status=approve&number=' . $num_approved_comments);
139 foreach ($approved_comments as &$comment) {
140 $commented_post = get_post($comment->comment_post_ID);
141 $comment->post_title = $commented_post->post_title;
142 }
143 $stats['comments']['approved'] = $approved_comments;
144
145 return $stats;
146 }
147 function get_initial_stats()
148 {
149 global $mmb_plugin_dir;
150
151 $stats = array();
152
153 $stats['email'] = get_option('admin_email');
154 $stats['no_openssl'] = $this->get_random_signature();
155 $stats['content_path'] = WP_CONTENT_DIR;
156 $stats['worker_path'] = $mmb_plugin_dir;
157 $stats['worker_version'] = MMB_WORKER_VERSION;
158 $stats['site_title'] = get_bloginfo('name');
159 $stats['site_tagline'] = get_bloginfo('description');
160 $stats['site_url'] = get_bloginfo('home');
161
162
163 if (!function_exists('get_filesystem_method'))
164 include_once(ABSPATH . 'wp-admin/includes/file.php');
165
166 if ((!defined('FTP_HOST') || !defined('FTP_USER') || !defined('FTP_PASS')) && (get_filesystem_method(array(), false) != 'direct')) {
167 $stats['writable'] = false;
168 } else
169 $stats['writable'] = true;
170
171 return $stats;
172 }
173
174
175 function set_hit_count($fix_count = false)
176 {
177 if ($fix_count || (!is_admin() && !MMB_Stats::detect_bots())) {
178 $date = date('Y-m-d');
179 $user_hit_count = get_option('user_hit_count');
180 if (!$user_hit_count) {
181 $user_hit_count[$date] = 1;
182 update_option('user_hit_count', $user_hit_count);
183 } else {
184 $dated_keys = array_keys($user_hit_count);
185 $last_visit_date = $dated_keys[count($dated_keys) - 1];
186
187 $days = intval((strtotime($date) - strtotime($last_visit_date)) / 60 / 60 / 24);
188
189 if ($days > 1) {
190 $date_to_add = date('Y-m-d', strtotime($last_visit_date));
191
192 for ($i = 1; $i < $days; $i++) {
193 if (count($user_hit_count) > 14) {
194 $shifted = @array_shift($user_hit_count);
195 }
196
197 $next_key = strtotime('+1 day', strtotime($date_to_add));
198 if ($next_key == $date) {
199 break;
200 } else {
201 $user_hit_count[$next_key] = 0;
202 }
203 }
204
205 }
206
207 if (!isset($user_hit_count[$date])) {
208 $user_hit_count[$date] = 0;
209 }
210 if (!$fix_count)
211 $user_hit_count[$date] += 1;
212
213 if (count($user_hit_count) > 14) {
214 $shifted = @array_shift($user_hit_count);
215 }
216
217 update_option('user_hit_count', $user_hit_count);
218
219 }
220 }
221 }
222
223 function get_hit_count()
224 {
225 // Check if there are no hits on last key date
226 $mmb_user_hits = get_option('user_hit_count');
227 if (is_array($mmb_user_hits)) {
228 end($mmb_user_hits);
229 $last_key_date = key($mmb_user_hits);
230 $current_date = date('Y-m-d');
231 if ($last_key_date != $curent_date)
232 $this->set_hit_count(true);
233 }
234
235 return get_option('user_hit_count');
236 }
237
238 function detect_bots()
239 {
240 $agent = $_SERVER['HTTP_USER_AGENT'];
241
242 if ($agent == '')
243 return false;
244
245 $bot_list = array(
246 "Teoma",
247 "alexa",
248 "froogle",
249 "Gigabot",
250 "inktomi",
251 "looksmart",
252 "URL_Spider_SQL",
253 "Firefly",
254 "NationalDirectory",
255 "Ask Jeeves",
256 "TECNOSEEK",
257 "InfoSeek",
258 "WebFindBot",
259 "girafabot",
260 "crawler",
261 "www.galaxy.com",
262 "Googlebot",
263 "Scooter",
264 "Slurp",
265 "msnbot",
266 "appie",
267 "FAST",
268 "WebBug",
269 "Spade",
270 "ZyBorg",
271 "rabaz",
272 "Baiduspider",
273 "Feedfetcher-Google",
274 "TechnoratiSnoop",
275 "Rankivabot",
276 "Mediapartners-Google",
277 "Sogou web spider",
278 "WebAlta Crawler",
279 "aolserver"
280 );
281
282 $thebot = '';
283 foreach ($bot_list as $bot) {
284 if (ereg($bot, $agent)) {
285 $thebot = $bot;
286 break;
287 }
288 }
289
290 if ($thebot != '') {
291 return $thebot;
292 } else
293 return false;
294 }
295
296 }
297 ?>