PluginProbe
ManageWP Worker / 3.8.0
ManageWP Worker v3.8.0
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.0, at stats.class.php

280 lines 9.1 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( function_exists( 'openssl_verify' ) ){
115 $stats['no_openssl'] = $this->_get_random_signature();
116 }
117 else {
118 delete_option('_worker_nossl_key');
119 $stats['no_openssl'] = false;
120 }
121
122 if ((!defined('FTP_HOST') || !defined('FTP_USER') || !defined('FTP_PASS')) && !is_writable(WP_CONTENT_DIR)) {
123 $stats['writable'] = false;
124 }
125 else $stats['writable'] = true;
126 return $stats;
127 }
128
129 function get_initial_stats()
130 {
131 global $mmb_plugin_dir;
132
133 $stats = array();
134
135 $stats['email'] = get_option('admin_email');
136 $stats['no_openssl'] = $this->_get_random_signature();
137 $stats['content_path'] = WP_CONTENT_DIR;
138 $stats['worker_path'] = $mmb_plugin_dir;
139 $stats['worker_version'] = MMB_WORKER_VERSION;
140 $stats['site_title'] = get_bloginfo('name');
141 $stats['site_tagline'] = get_bloginfo('description');
142
143
144 if ((!defined('FTP_HOST') || !defined('FTP_USER') || !defined('FTP_PASS')) && !is_writable(WP_CONTENT_DIR)) {
145 $stats['writable'] = false;
146 }
147 else $stats['writable'] = true;
148
149 return $stats;
150 }
151
152
153
154
155
156 function set_hit_count($fix_count = false)
157 {
158
159 if ($fix_count || (!is_admin() && !MMB_Stats::detect_bots() )) {
160 $date = date('Y-m-d');
161 $user_hit_count = get_option('user_hit_count');
162 if (!$user_hit_count) {
163 $user_hit_count[$date] = 1;
164 update_option('user_hit_count', $user_hit_count);
165 } else {
166 $dated_keys = array_keys($user_hit_count);
167 $last_visit_date = $dated_keys[count($dated_keys) - 1];
168
169 $days = intval((strtotime($date) - strtotime($last_visit_date)) / 60 / 60 / 24);
170
171 if ($days > 1) {
172
173 $date_to_add = date('Y-m-d', strtotime($last_visit_date));
174
175 for ($i = 1; $i < $days; $i++) {
176 if (count($user_hit_count) > 14) {
177 $shifted = @array_shift($user_hit_count);
178 }
179
180 $next_key = strtotime('+1 day', strtotime($date_to_add));
181 if ($next_key == $date) {
182 break;
183 } else {
184 $user_hit_count[$next_key] = 0;
185 }
186 }
187
188 }
189
190 if (!isset($user_hit_count[$date])) {
191 $user_hit_count[$date] = 0;
192 }
193 if (!$fix_count)
194 $user_hit_count[$date] += 1;
195
196 if (count($user_hit_count) > 7) {
197 $shifted = @array_shift($user_hit_count);
198 }
199
200 update_option('user_hit_count', $user_hit_count);
201
202 }
203 }
204 }
205
206 function get_hit_count()
207 {
208 // Check if there are no hits on last key date
209 $mmb_user_hits = get_option('user_hit_count');
210 if (is_array($mmb_user_hits)) {
211 end($mmb_user_hits);
212 $last_key_date = key($mmb_user_hits);
213 $current_date = date('Y-m-d');
214 if ($last_key_date != $curent_date)
215 $this->set_hit_count(true);
216 }
217
218 return get_option('user_hit_count');
219 }
220
221 function detect_bots()
222 {
223 $agent = $_SERVER['HTTP_USER_AGENT'];
224
225 if ($agent == '')
226 return false;
227
228 $bot_list = array(
229 "Teoma",
230 "alexa",
231 "froogle",
232 "Gigabot",
233 "inktomi",
234 "looksmart",
235 "URL_Spider_SQL",
236 "Firefly",
237 "NationalDirectory",
238 "Ask Jeeves",
239 "TECNOSEEK",
240 "InfoSeek",
241 "WebFindBot",
242 "girafabot",
243 "crawler",
244 "www.galaxy.com",
245 "Googlebot",
246 "Scooter",
247 "Slurp",
248 "msnbot",
249 "appie",
250 "FAST",
251 "WebBug",
252 "Spade",
253 "ZyBorg",
254 "rabaz",
255 "Baiduspider",
256 "Feedfetcher-Google",
257 "TechnoratiSnoop",
258 "Rankivabot",
259 "Mediapartners-Google",
260 "Sogou web spider",
261 "WebAlta Crawler",
262 "aolserver"
263 );
264
265 $thebot = '';
266 foreach ($bot_list as $bot) {
267 if (ereg($bot, $agent)) {
268 $thebot = $bot;
269 break;
270 }
271 }
272
273 if ($thebot != '') {
274 return $thebot;
275 } else
276 return false;
277 }
278
279 }
280 ?>