PluginProbe
ManageWP Worker / 3.8.6
ManageWP Worker v3.8.6
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.6, at stats.class.php

285 lines 9.4 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 $wp_version, $mmb_plugin_dir;
29 $stats = array();
30
31 //define constants
32 $num_pending_comments = 3;
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'] = $wp_version;
42
43 $updates = $this->mmb_get_transient('update_core');
44
45 if ($updates->updates[0]->response == 'development' || version_compare($wp_version, $updates->updates[0]->current, '<')) {
46 $updates->updates[0]->current_version = $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_theme_instance()->get_upgradable_themes();
63 $stats['upgradable_plugins'] = $this->get_plugin_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) {
86 $recent->post_permalink = get_permalink($recent->ID);
87 unset($recent->post_content);
88 unset($recent->post_author);
89 unset($recent->post_category);
90 unset($recent->post_date_gmt);
91 unset($recent->post_excerpt);
92 unset($recent->post_status);
93 unset($recent->comment_status);
94 unset($recent->ping_status);
95 unset($recent->post_password);
96 unset($recent->post_name);
97 unset($recent->to_ping);
98 unset($recent->pinged);
99 unset($recent->post_modified_gmt);
100 unset($recent->post_content_filtered);
101 unset($recent->post_parent);
102 unset($recent->guid);
103 unset($recent->menu_order);
104 unset($recent->post_type);
105 unset($recent->post_mime_type);
106 unset($recent->filter);
107 unset($recent->featured);
108 $recent_posts[] = $recent;
109 }
110 $stats['posts'] = $recent_posts;
111
112 $drafts = get_posts('post_status=draft&numberposts=3');
113 foreach ($drafts as $draft) {
114 $props = get_object_vars($draft);
115 foreach ($props as $name => $value) {
116 if ($name != 'post_title' && $name != 'ID' && $name != 'post_modified') {
117 unset($draft->$name);
118 } else {
119 $draft->post_title = get_the_title($draft->ID);
120 $draft->post_permalink = get_permalink($draft->ID);
121 }
122 }
123 }
124 $stats['draft_count'] = count($drafts);
125 $stats['drafts'] = $drafts;
126
127
128 if ((!defined('FTP_HOST') || !defined('FTP_USER') || !defined('FTP_PASS')) && !is_writable(WP_CONTENT_DIR)) {
129 $stats['writable'] = false;
130 } else
131 $stats['writable'] = true;
132
133 $stats = apply_filters('mmb_stats_filter', $stats);
134
135 return $stats;
136 }
137
138 function get_initial_stats()
139 {
140 global $mmb_plugin_dir;
141
142 $stats = array();
143
144 $stats['email'] = get_option('admin_email');
145 $stats['no_openssl'] = $this->get_random_signature();
146 $stats['content_path'] = WP_CONTENT_DIR;
147 $stats['worker_path'] = $mmb_plugin_dir;
148 $stats['worker_version'] = MMB_WORKER_VERSION;
149 $stats['site_title'] = get_bloginfo('name');
150 $stats['site_tagline'] = get_bloginfo('description');
151 $stats['site_url'] = get_bloginfo('home');
152
153
154 if ((!defined('FTP_HOST') || !defined('FTP_USER') || !defined('FTP_PASS')) && !is_writable(WP_CONTENT_DIR)) {
155 $stats['writable'] = false;
156 } else
157 $stats['writable'] = true;
158
159 return $stats;
160 }
161
162
163 function set_hit_count($fix_count = false)
164 {
165 if ($fix_count || (!is_admin() && !MMB_Stats::detect_bots())) {
166 $date = date('Y-m-d');
167 $user_hit_count = get_option('user_hit_count');
168 if (!$user_hit_count) {
169 $user_hit_count[$date] = 1;
170 update_option('user_hit_count', $user_hit_count);
171 } else {
172 $dated_keys = array_keys($user_hit_count);
173 $last_visit_date = $dated_keys[count($dated_keys) - 1];
174
175 $days = intval((strtotime($date) - strtotime($last_visit_date)) / 60 / 60 / 24);
176
177 if ($days > 1) {
178 $date_to_add = date('Y-m-d', strtotime($last_visit_date));
179
180 for ($i = 1; $i < $days; $i++) {
181 if (count($user_hit_count) > 14) {
182 $shifted = @array_shift($user_hit_count);
183 }
184
185 $next_key = strtotime('+1 day', strtotime($date_to_add));
186 if ($next_key == $date) {
187 break;
188 } else {
189 $user_hit_count[$next_key] = 0;
190 }
191 }
192
193 }
194
195 if (!isset($user_hit_count[$date])) {
196 $user_hit_count[$date] = 0;
197 }
198 if (!$fix_count)
199 $user_hit_count[$date] += 1;
200
201 if (count($user_hit_count) > 14) {
202 $shifted = @array_shift($user_hit_count);
203 }
204
205 update_option('user_hit_count', $user_hit_count);
206
207 }
208 }
209 }
210
211 function get_hit_count()
212 {
213 // Check if there are no hits on last key date
214 $mmb_user_hits = get_option('user_hit_count');
215 if (is_array($mmb_user_hits)) {
216 end($mmb_user_hits);
217 $last_key_date = key($mmb_user_hits);
218 $current_date = date('Y-m-d');
219 if ($last_key_date != $curent_date)
220 $this->set_hit_count(true);
221 }
222
223 return get_option('user_hit_count');
224 }
225
226 function detect_bots()
227 {
228 $agent = $_SERVER['HTTP_USER_AGENT'];
229
230 if ($agent == '')
231 return false;
232
233 $bot_list = array(
234 "Teoma",
235 "alexa",
236 "froogle",
237 "Gigabot",
238 "inktomi",
239 "looksmart",
240 "URL_Spider_SQL",
241 "Firefly",
242 "NationalDirectory",
243 "Ask Jeeves",
244 "TECNOSEEK",
245 "InfoSeek",
246 "WebFindBot",
247 "girafabot",
248 "crawler",
249 "www.galaxy.com",
250 "Googlebot",
251 "Scooter",
252 "Slurp",
253 "msnbot",
254 "appie",
255 "FAST",
256 "WebBug",
257 "Spade",
258 "ZyBorg",
259 "rabaz",
260 "Baiduspider",
261 "Feedfetcher-Google",
262 "TechnoratiSnoop",
263 "Rankivabot",
264 "Mediapartners-Google",
265 "Sogou web spider",
266 "WebAlta Crawler",
267 "aolserver"
268 );
269
270 $thebot = '';
271 foreach ($bot_list as $bot) {
272 if (ereg($bot, $agent)) {
273 $thebot = $bot;
274 break;
275 }
276 }
277
278 if ($thebot != '') {
279 return $thebot;
280 } else
281 return false;
282 }
283
284 }
285 ?>