PluginProbe
ManageWP Worker / 3.9.2
ManageWP Worker v3.9.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 / core.class.php

core.class.php in ManageWP Worker 3.9.2, at core.class.php

423 lines 11.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*************************************************************
3 *
4 * core.class.php
5 *
6 * Upgrade Plugins
7 *
8 *
9 * Copyright (c) 2011 Prelovac Media
10 * www.prelovac.com
11 **************************************************************/
12 class MMB_Core extends MMB_Helper
13 {
14 var $name;
15 var $slug;
16 var $settings;
17 var $remote_client;
18 var $comment_instance;
19 var $plugin_instance;
20 var $theme_instance;
21 var $wp_instance;
22 var $post_instance;
23 var $stats_instance;
24 var $search_instance;
25 var $links_instance;
26 var $user_instance;
27 var $backup_instance;
28 var $installer_instance;
29 var $mmb_multisite = false;
30
31
32 function __construct()
33 {
34 global $mmb_plugin_dir, $wpmu_version, $blog_id;
35
36 $this->name = 'Manage Multiple Blogs';
37 $this->slug = 'manage-multiple-blogs';
38 $this->settings = get_option($this->slug);
39 if (!$this->settings) {
40 $this->settings = array(
41 'blogs' => array(),
42 'current_blog' => array(
43 'type' => null
44 )
45 );
46 $this->save_options();
47 }
48
49 if (function_exists('is_multisite')){
50 if (is_multisite()) {
51 $this->mmb_multisite = $blog_id;
52 }
53 } else if (!empty($wpmu_version)) {
54 $this->mmb_multisite = $blog_id;
55 }
56
57 add_action('rightnow_end', array(
58 $this,
59 'add_right_now_info'
60 ));
61 add_action('wp_footer', array(
62 'MMB_Stats',
63 'set_hit_count'
64 ));
65 register_activation_hook($mmb_plugin_dir . '/init.php', array(
66 $this,
67 'install'
68 ));
69 add_action('init', array(
70 $this,
71 'automatic_login'
72 ));
73
74 if (!get_option('_worker_public_key'))
75 add_action('admin_notices', array(
76 $this,
77 'admin_notice'
78 ));
79 }
80
81 /**
82 * Add notice to admin dashboard for security reasons
83 *
84 */
85 function admin_notice()
86 {
87 echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">Attention !</p><p>
88 Please add this site to your <a target="_blank" href="http://managewp.com/user-guide#security">ManageWP.com</a> account now to remove this notice or deactivate the Worker plugin to avoid <a target="_blank" href="http://managewp.com/user-guide#security">security issues</a>.
89 </p></div>';
90 }
91
92 /**
93 * Add an item into the Right Now Dashboard widget
94 * to inform that the blog can be managed remotely
95 *
96 */
97 function add_right_now_info()
98 {
99 echo '<div class="mmb-slave-info">
100 <p>This site can be managed remotely.</p>
101 </div>';
102 }
103
104 /**
105 * Gets an instance of the Comment class
106 *
107 */
108 function get_comment_instance()
109 {
110 if (!isset($this->comment_instance)) {
111 $this->comment_instance = new MMB_Comment();
112 }
113
114 return $this->comment_instance;
115 }
116
117 /**
118 * Gets an instance of the Plugin class
119 *
120 */
121 function get_plugin_instance()
122 {
123 if (!isset($this->plugin_instance)) {
124 $this->plugin_instance = new MMB_Plugin();
125 }
126
127 return $this->plugin_instance;
128 }
129
130 /**
131 * Gets an instance of the Theme class
132 *
133 */
134 function get_theme_instance()
135 {
136 if (!isset($this->theme_instance)) {
137 $this->theme_instance = new MMB_Theme();
138 }
139
140 return $this->theme_instance;
141 }
142
143
144 /**
145 * Gets an instance of MMB_Post class
146 *
147 */
148 function get_post_instance()
149 {
150 if (!isset($this->post_instance)) {
151 $this->post_instance = new MMB_Post();
152 }
153
154 return $this->post_instance;
155 }
156
157 /**
158 * Gets an instance of Blogroll class
159 *
160 */
161 function get_blogroll_instance()
162 {
163 if (!isset($this->blogroll_instance)) {
164 $this->blogroll_instance = new MMB_Blogroll();
165 }
166
167 return $this->blogroll_instance;
168 }
169
170
171
172 /**
173 * Gets an instance of the WP class
174 *
175 */
176 function get_wp_instance()
177 {
178 if (!isset($this->wp_instance)) {
179 $this->wp_instance = new MMB_WP();
180 }
181
182 return $this->wp_instance;
183 }
184
185 /**
186 * Gets an instance of User
187 *
188 */
189 function get_user_instance()
190 {
191 if (!isset($this->user_instance)) {
192 $this->user_instance = new MMB_User();
193 }
194
195 return $this->user_instance;
196 }
197
198 /**
199 * Gets an instance of stats class
200 *
201 */
202 function get_stats_instance()
203 {
204 if (!isset($this->stats_instance)) {
205 $this->stats_instance = new MMB_Stats();
206 }
207 return $this->stats_instance;
208 }
209 /**
210 * Gets an instance of search class
211 *
212 */
213 function get_search_instance()
214 {
215 if (!isset($this->search_instance)) {
216 $this->search_instance = new MMB_Search();
217 }
218 //return $this->search_instance;
219 return $this->search_instance;
220 }
221 /**
222 * Gets an instance of stats class
223 *
224 */
225 function get_backup_instance()
226 {
227 if (!isset($this->backup_instance)) {
228 $this->backup_instance = new MMB_Backup();
229 }
230
231 return $this->backup_instance;
232 }
233
234 /**
235 * Gets an instance of links class
236 *
237 */
238 function get_link_instance()
239 {
240 if (!isset($this->link_instance)) {
241 $this->link_instance = new MMB_Link();
242 }
243
244 return $this->link_instance;
245 }
246
247 function get_installer_instance()
248 {
249 if (!isset($this->installer_instance)) {
250 $this->installer_instance = new MMB_Installer();
251 }
252 return $this->installer_instance;
253 }
254
255 /**
256 * Plugin install callback function
257 * Check PHP version
258 */
259 function install()
260 {
261 global $wp_object_cache, $wpdb;
262 if(!empty($wp_object_cache))
263 @$wp_object_cache->flush();
264
265 // delete plugin options, just in case
266 if($this->mmb_multisite != false){
267 $blog_ids = $wpdb->get_results($wpdb->prepare('SELECT blog_id FROM `wp_blogs`'));
268 if(!empty($blog_ids)){
269 foreach($blog_ids as $blog_id){
270 $wpdb->query($wpdb->prepare('DELETE FROM '.$wpdb->prefix.$blog->blog_id.'_options WHERE `option_name` = "_worker_nossl_key";'));
271 $wpdb->query($wpdb->prepare('DELETE FROM '.$wpdb->prefix.$blog->blog_id.'_options WHERE `option_name` = "_worker_public_key";'));
272 $wpdb->query($wpdb->prepare('DELETE FROM '.$wpdb->prefix.$blog->blog_id.'_options WHERE `option_name` = "_action_message_id";'));
273 }
274 }
275 } else {
276 delete_option('_worker_nossl_key');
277 delete_option('_worker_public_key');
278 delete_option('_action_message_id');
279 }
280
281 }
282
283 /**
284 * Saves the (modified) options into the database
285 *
286 */
287 function save_options()
288 {
289 if (get_option($this->slug)) {
290 update_option($this->slug, $this->settings);
291 } else {
292 add_option($this->slug, $this->settings);
293 }
294 }
295
296 /**
297 * Deletes options for communication with master
298 *
299 */
300 function uninstall()
301 {
302 global $wp_object_cache, $wpdb;
303 if(!empty($wp_object_cache))
304 @$wp_object_cache->flush();
305
306 if($this->mmb_multisite != false){
307 $blog_ids = $wpdb->get_results($wpdb->prepare('SELECT blog_id FROM `wp_blogs`'));
308 if(!empty($blog_ids)){
309 foreach($blog_ids as $blog){
310 $wpdb->query($wpdb->prepare('DELETE FROM '.$wpdb->prefix.$blog->blog_id.'_options WHERE `option_name` = "_worker_nossl_key";'));
311 $wpdb->query($wpdb->prepare('DELETE FROM '.$wpdb->prefix.$blog->blog_id.'_options WHERE `option_name` = "_worker_public_key";'));
312 $wpdb->query($wpdb->prepare('DELETE FROM '.$wpdb->prefix.$blog->blog_id.'_options WHERE `option_name` = "_action_message_id";'));
313 }
314 }
315 } else {
316 delete_option('_worker_nossl_key');
317 delete_option('_worker_public_key');
318 delete_option('_action_message_id');
319 }
320 }
321
322 /**
323 * Constructs a url (for ajax purpose)
324 *
325 * @param mixed $base_page
326 */
327 function construct_url($params = array(), $base_page = 'index.php')
328 {
329 $url = "$base_page?_wpnonce=" . wp_create_nonce($this->slug);
330 foreach ($params as $key => $value) {
331 $url .= "&$key=$value";
332 }
333
334 return $url;
335 }
336
337 /**
338 * Worker update
339 *
340 */
341 function update_worker_plugin($params)
342 {
343 extract($params);
344 if ($download_url) {
345 include_once ABSPATH . 'wp-admin/includes/file.php';
346 include_once ABSPATH . 'wp-admin/includes/misc.php';
347 include_once ABSPATH . 'wp-admin/includes/template.php';
348 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
349
350 if (!$this->is_server_writable()) {
351 return array(
352 'error' => 'Failed, please <a target="_blank" href="http://managewp.com/user-guide#ftp">add FTP details for automatic upgrades.</a></a>'
353 );
354 }
355
356 ob_start();
357 @unlink(dirname(__FILE__));
358 $upgrader = new Plugin_Upgrader();
359 $result = $upgrader->run(array(
360 'package' => $download_url,
361 'destination' => WP_PLUGIN_DIR,
362 'clear_destination' => true,
363 'clear_working' => true,
364 'hook_extra' => array(
365 'plugin' => 'worker/init.php'
366 )
367 ));
368 ob_end_clean();
369 if (is_wp_error($result) || !$result) {
370 return array(
371 'error' => 'ManageWP Worker could not been upgraded.'
372 );
373 } else {
374 return array(
375 'success' => 'ManageWP Worker plugin successfully upgraded.'
376 );
377 }
378 }
379 return array(
380 'error' => 'Bad download path for worker installation file.'
381 );
382 }
383
384 /**
385 * Automatically logs in when called from Master
386 *
387 */
388 function automatic_login()
389 {
390 global $current_user;
391 $where = ($_GET['mwp_goto']);
392
393 if ((!is_user_logged_in() || $_GET['username'] != $current_user->user_login) && $_GET['auto_login']) {
394
395 $signature = base64_decode($_GET['signature']);
396 $message_id = trim($_GET['message_id']);
397 $username = $_GET['username'];
398
399 $auth = $this->authenticate_message($where . $message_id, $signature, $message_id);
400 if ($auth === true) {
401 if(isset($current_user->user_login))
402 do_action('wp_logout');
403 $user = get_user_by('login', $username);
404 $user_id = $user->ID;
405 wp_set_current_user($user_id, $username);
406 wp_set_auth_cookie($user_id);
407 do_action('wp_login', $username);
408 } else {
409 unset($_SESSION['mwp_frame_options_header']);
410 wp_die($auth['error']);
411 }
412 }
413
414 if ($_GET['auto_login']) {
415 update_option('mwp_iframe_options_header', microtime(true));
416 wp_redirect(get_option('siteurl') . "/wp-admin/" . $where);
417 exit();
418 }
419 }
420
421
422 }
423 ?>