PluginProbe
ManageWP Worker / 3.8.4
ManageWP Worker v3.8.4
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.4, at stats.class.php

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