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

247 lines 8.3 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 XMLRPC from Master)
12 **************************************************************/
13
14 function get($args)
15 {
16 $this->_escape($args);
17
18 $username = $args[0];
19 $password = $args[1];
20 // $this->_log($username);
21 // $this->_log($password);
22
23 if (!$user = $this->login($username, $password))
24 {
25 return $this->error;
26 }
27
28 // Things to get:
29 // pending comments
30 // drafts
31 // available plugin upgrades
32 // available wordpress upgrade
33 // version of worker plugin
34 // and???
35
36 $stats = array();
37
38 $mmb_user_hits = get_option('user_hit_count');
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
48 if (current_user_can('moderate_comments'))
49 {
50 // pending comments
51 $pending_comments = get_comments('status=hold&number=5');
52 // trim off unnecessary data
53 foreach ($pending_comments as &$comment)
54 {
55 $commented_post = get_post($comment->comment_post_ID);
56 $comment->post_title = $commented_post->post_title;
57 }
58
59 $stats['pending_comments'] = $pending_comments;
60 }
61
62 // drafts
63 $drafts = get_posts('post_status=draft&numberposts=0');
64 // trim off unnecessary data
65 foreach ($drafts as $draft)
66 {
67 if (!current_user_can('edit_post', $draft->ID)) continue;
68
69 $props = get_object_vars($draft);
70 foreach ($props as $name => $value)
71 {
72 if ($name != 'post_title' && $name != 'ID' && $name != 'post_modified')
73 {
74 unset($draft->$name);
75 }
76 }
77 }
78
79 if (!empty($drafts))
80 {
81 $stats['drafts'] = $drafts;
82 }
83
84 if (current_user_can('activate_plugins'))
85 {
86 // available plugin upgrades
87 $stats['upgradable_plugins'] = $this->get_plugin_instance()->get_upgradable_plugins();
88 }
89
90 if (current_user_can('update_plugins'))
91 {
92 // core upgrade
93 $new_version = $this->get_wp_instance()->check_version(NULL, FALSE);
94 if (!is_a($new_version, 'IXR_Error'))
95 {
96 $stats['new_version'] = $new_version;
97 }
98
99 //@lk worker version
100 //we can either store the version string in a file or a string or both
101 global $mmb_plugin_dir;
102 // $worker_version = file_get_contents($mmb_plugin_dir.'/version');
103 $stats['worker_version'] = MMB_WORKER_VERSION;
104 }
105 if (current_user_can('install_themes')){
106 $stats['upgradable_themes'] = $this->get_theme_instance()->get_upgradable_themes();
107 }
108 $stats['server_ftp'] = 0;
109 if((!defined('FTP_HOST') || !defined('FTP_USER') || !defined('FTP_PASS')) && !is_writable(WP_CONTENT_DIR)){
110 $stats['server_ftp'] = 1;
111 }
112
113 return $stats;
114 }
115
116 function get_server_stats($args) {
117 $this->_escape($args);
118
119 $username = $args[0];
120 $password = $args[1];
121 // $this->_log($username);
122 // $this->_log($password);
123
124 if (!$user = $this->login($username, $password)){
125 return $this->error;
126 }
127
128 $stats = array();
129
130 if(!current_user_can('administrator')){
131 return array('add_error'=>'You are not an administrator on %s. Please use an account with administrator privilege.');
132 }
133
134 if (current_user_can('upload_files')){
135 // check if wp-content is writable
136 // $this->_log(is_writable(WP_CONTENT_DIR));
137 // if(is_writable(WP_CONTENT_DIR) && is_writable(WP_CONTENT_DIR.'/plugins') && is_writable(WP_CONTENT_DIR.'/themes') && is_writable(WP_CONTENT_DIR.'/uploads') && is_writable(WP_CONTENT_DIR.'/upgrade')){
138 if(is_writable(WP_CONTENT_DIR) && is_writable(WP_CONTENT_DIR.'/plugins') && is_writable(WP_CONTENT_DIR.'/themes')){
139 $stats['writable'] = TRUE;
140 }else{
141 $stats['writable'] = FALSE;
142 }
143 global $mmb_plugin_dir;
144 $stats['worker_path'] = $mmb_plugin_dir;
145 $stats['content_path'] = WP_CONTENT_DIR;
146 }
147 return $stats;
148
149 }
150
151 function set_hit_count($fix_count = false) {
152 // TODO : IP based checking for hit count
153 //
154 // In activation hook
155 // if(!get_option('user_hit_count')){
156 // $user_hit_count = array();
157 // update_option('user_hit_count', $user_hit_count);
158 // }
159 //
160 // Save a transient to the database
161 // $transient = $_SERVER['REMOTE_ADDR'];
162 // $expiration = somethig; // equal to 8 hrs
163 //
164 // if(!(get_transient($transient)))
165 // set_transient($transient, $transient, $expiration);
166 //
167 // Fetch a saved transient
168 // $current_user_ip = get_transient($transient);
169 // if(!(get_transient($transient))) then increment the hit count
170
171 if(is_single () || $fix_count){
172 $date = date('Y-m-d');
173 $user_hit_count = get_option('user_hit_count');
174 if(!$user_hit_count){
175 $user_hit_count[$date] = 1;
176 update_option('user_hit_count', $user_hit_count);
177 }else{
178 $dated_keys = array_keys($user_hit_count);
179 $last_visit_date = $dated_keys[count($dated_keys)-1];
180
181 // $diff = strtotime($date) - strtotime($last_visit_date);
182 // $sec = $diff % 60;
183 // $diff = intval($diff / 60);
184 // $min = $diff % 60;
185 // $diff = intval($diff / 60);
186 // $hours = $diff % 24;
187 // $days = intval($diff / 24);
188
189 $days = intval ( ( strtotime($date) - strtotime($last_visit_date) ) / 60 / 60 / 24 );
190
191 if($days>1){
192 // $date_elems = getdate(strtotime($last_visit_date));
193 // $yr = $date_elems['year'];
194 // $mn = $date_elems['mon'];
195 // $dt = $date_elems['mday'];
196
197 $date_to_add = date('Y-m-d', strtotime($last_visit_date));
198
199 for($i = 1; $i<$days ; $i++){
200 if(count($user_hit_count) > 7)
201 {
202 $shifted = @array_shift($user_hit_count);
203 }
204 //$next_day = ($dt + $i);
205 //$next_key = $yr.'-'.$mn.'-'.$next_day;
206 $next_key = strtotime('+1 day', strtotime($date_to_add));
207 if($next_key == $date){
208 break;
209 }else{
210 $user_hit_count[$next_key] = 0;
211 }
212 }
213
214 // if($next_key == $date)
215 // $user_hit_count[$next_key] = 0;
216 }
217
218 if(!isset($user_hit_count[$date])){
219 $user_hit_count[$date] = 0;
220 }
221 if(!$fix_count)
222 $user_hit_count[$date] += 1;
223
224 if(count($user_hit_count) > 7)
225 {
226 $shifted = @array_shift($user_hit_count);
227 }
228
229 update_option('user_hit_count', $user_hit_count);
230 // $this->_log($user_hit_count);
231 }
232 }
233 }
234
235 function get_hit_count() {
236 // Check if there are no hits on last key date
237 $mmb_user_hits = get_option('user_hit_count');
238 end($mmb_user_hits);
239 $last_key_date = key($mmb_user_hits);
240 $current_date = date('Y-m-d');
241 if($last_key_date != $curent_date)
242 $this->set_hit_count(true);
243
244 return get_option('user_hit_count');
245 }
246
247 }