PluginProbe
ManageWP Worker / 3.8.3
ManageWP Worker v3.8.3
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.3, at stats.class.php

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