PluginProbe
ManageWP Worker / 3.8.2
ManageWP Worker v3.8.2
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.2, at stats.class.php

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