PluginProbe
ManageWP Worker / 3.9.13
ManageWP Worker v3.9.13
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.13, at core.class.php

656 lines 20.2 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;
30 var $network_admin_install;
31 private $action_call;
32 private $action_params;
33 private $mmb_pre_init_actions;
34 private $mmb_pre_init_filters;
35 private $mmb_init_actions;
36
37
38 function __construct()
39 {
40 global $mmb_plugin_dir, $wpmu_version, $blog_id, $_mmb_plugin_actions, $_mmb_item_filter;
41
42 $_mmb_plugin_actions = array();
43 $this->name = 'Manage Multiple Blogs';
44 $this->slug = 'manage-multiple-blogs';
45 $this->action_call = null;
46 $this->action_params = null;
47
48
49 $this->settings = get_option($this->slug);
50 if (!$this->settings) {
51 $this->settings = array(
52 'blogs' => array(),
53 'current_blog' => array(
54 'type' => null
55 )
56 );
57 $this->save_options();
58 }
59 if ( function_exists('is_multisite') ) {
60 if ( is_multisite() ) {
61 $this->mmb_multisite = $blog_id;
62 $this->network_admin_install = get_option('mmb_network_admin_install');
63 }
64 } else if (!empty($wpmu_version)) {
65 $this->mmb_multisite = $blog_id;
66 $this->network_admin_install = get_option('mmb_network_admin_install');
67 } else {
68 $this->mmb_multisite = false;
69 $this->network_admin_install = null;
70 }
71
72 // admin notices
73 if ( !get_option('_worker_public_key') ){
74 if( $this->mmb_multisite ){
75 if( is_network_admin() && $this->network_admin_install == '1'){
76 add_action('network_admin_notices', array( &$this, 'network_admin_notice' ));
77 } else if( $this->network_admin_install != '1' ){
78 $parent_key = $this->get_parent_blog_option('_worker_public_key');
79 if(empty($parent_key))
80 add_action('admin_notices', array( &$this, 'admin_notice' ));
81 }
82 } else {
83 add_action('admin_notices', array( &$this, 'admin_notice' ));
84 }
85 }
86
87 // default filters
88 //$this->mmb_pre_init_filters['get_stats']['mmb_stats_filter'][] = array('MMB_Stats', 'pre_init_stats'); // called with class name, use global $mmb_core inside the function instead of $this
89 $this->mmb_pre_init_filters['get_stats']['mmb_stats_filter'][] = 'mmb_pre_init_stats';
90
91 $_mmb_item_filter['pre_init_stats'] = array( 'core_update', 'hit_counter', 'comments', 'backups', 'posts', 'drafts', 'scheduled' );
92 $_mmb_item_filter['get'] = array( 'updates', 'errors' );
93
94 $this->mmb_pre_init_actions = array(
95 'do_upgrade' => 'mmb_do_upgrade',
96 'backup_req' => 'mmb_get_backup_req'
97 );
98 $this->mmb_init_actions = array(
99 'get_stats' => 'mmb_stats_get',
100 'remove_site' => 'mmb_remove_site',
101 'backup_clone' => 'mmb_backup_now',
102 'restore' => 'mmb_restore_now',
103 'optimize_tables' => 'mmb_optimize_tables',
104 'check_wp_version' => 'mmb_wp_checkversion',
105 'create_post' => 'mmb_post_create',
106 'update_worker' => 'mmb_update_worker_plugin',
107 'change_comment_status' => 'mmb_change_comment_status',
108 'change_post_status' => 'mmb_change_post_status',
109 'get_comment_stats' => 'mmb_comment_stats_get',
110 'install_addon' => 'mmb_install_addon',
111 'add_link' => 'mmb_add_link',
112 'add_user' => 'mmb_add_user',
113 'email_backup' => 'mmb_email_backup',
114 'check_backup_compat' => 'mmb_check_backup_compat',
115 'scheduled_backup' => 'mmb_scheduled_backup',
116 'execute_php_code' => 'mmb_execute_php_code',
117 'delete_backup' => 'mmm_delete_backup',
118 'remote_backup_now' => 'mmb_remote_backup_now',
119 'set_notifications' => 'mmb_set_notifications',
120 'clean_orphan_backups' => 'mmb_clean_orphan_backups',
121 'get_users' => 'mmb_get_users',
122 'edit_users' => 'mmb_edit_users',
123 'get_plugins_themes' => 'mmb_get_plugins_themes',
124 'edit_plugins_themes' => 'mmb_edit_plugins_themes',
125 'worker_brand' => 'mmb_worker_brand'
126 );
127
128 add_action('rightnow_end', array( &$this, 'add_right_now_info' ));
129 add_action('admin_init', array(&$this,'admin_actions'));
130 add_action('init', array( &$this, 'mmb_remote_action'), 9999);
131 add_action('setup_theme', 'mmb_parse_request');
132 add_action('set_auth_cookie', array( &$this, 'mmb_set_auth_cookie'));
133 add_action('set_logged_in_cookie', array( &$this, 'mmb_set_logged_in_cookie'));
134 MMB_Stats::set_hit_count();
135 }
136
137 function mmb_remote_action(){
138 if($this->action_call != null){
139 $params = isset($this->action_params) && $this->action_params != null ? $this->action_params : array();
140 call_user_func($this->action_call, $params);
141 }
142 }
143
144 function register_action_params( $action = false, $params = array() ){
145
146 if(isset($this->mmb_pre_init_actions[$action]) && function_exists($this->mmb_pre_init_actions[$action])){
147 call_user_func($this->mmb_pre_init_actions[$action], $params);
148 }
149
150 if(isset($this->mmb_init_actions[$action]) && function_exists($this->mmb_init_actions[$action])){
151 $this->action_call = $this->mmb_init_actions[$action];
152 $this->action_params = $params;
153
154 if( isset($this->mmb_pre_init_filters[$action]) && !empty($this->mmb_pre_init_filters[$action])){
155 global $mmb_filters;
156
157 foreach($this->mmb_pre_init_filters[$action] as $_name => $_functions){
158 if(!empty($_functions)){
159 $data = array();
160
161 foreach($_functions as $_k => $_callback){
162 if(is_array($_callback) && method_exists($_callback[0], $_callback[1]) ){
163 $data = call_user_func( $_callback, $params );
164 } elseif (is_string($_callback) && function_exists( $_callback )){
165 $data = call_user_func( $_callback, $params );
166 }
167 $mmb_filters[$_name] = isset($mmb_filters[$_name]) && !empty($mmb_filters[$_name]) ? array_merge($mmb_filters[$_name], $data) : $data;
168 add_filter( $_name, create_function( '$a' , 'global $mmb_filters; return array_merge($a, $mmb_filters["'.$_name.'"]);') );
169 }
170 }
171
172 }
173 }
174 return true;
175 }
176 return false;
177 }
178
179 /**
180 * Add notice to network admin dashboard for security reasons
181 *
182 */
183 function network_admin_notice()
184 {
185 echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">Attention !</p><p>
186 Please add this site and your network blogs, with your network adminstrator username, to your <a target="_blank" href="http://managewp.com/wp-admin">ManageWP.com</a> account now to remove this notice or "Network Deactivate" the Worker plugin to avoid <a target="_blank" href="http://managewp.com/user-guide/security">security issues</a>.
187 </p></div>';
188 }
189
190
191 /**
192 * Add notice to admin dashboard for security reasons
193 *
194 */
195 function admin_notice()
196 {
197 echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">Attention !</p><p>
198 Please add this site now to your <a target="_blank" href="http://managewp.com/wp-admin">ManageWP.com</a> account. Or deactivate the Worker plugin to avoid <a target="_blank" href="http://managewp.com/user-guide/security">security issues</a>.
199 </p></div>';
200 }
201
202 /**
203 * Add an item into the Right Now Dashboard widget
204 * to inform that the blog can be managed remotely
205 *
206 */
207 function add_right_now_info()
208 {
209 echo '<div class="mmb-slave-info">
210 <p>This site can be managed remotely.</p>
211 </div>';
212 }
213
214 /**
215 * Get parent blog options
216 *
217 */
218 private function get_parent_blog_option( $option_name = '' )
219 {
220 global $wpdb;
221 $option = $wpdb->get_var( $wpdb->prepare( "SELECT `option_value` FROM {$wpdb->base_prefix}options WHERE option_name = '{$option_name}' LIMIT 1" ) );
222 return $option;
223 }
224
225 /**
226 * Gets an instance of the Comment class
227 *
228 */
229 function get_comment_instance()
230 {
231 if (!isset($this->comment_instance)) {
232 $this->comment_instance = new MMB_Comment();
233 }
234
235 return $this->comment_instance;
236 }
237
238 /**
239 * Gets an instance of the Plugin class
240 *
241 */
242 function get_plugin_instance()
243 {
244 if (!isset($this->plugin_instance)) {
245 $this->plugin_instance = new MMB_Plugin();
246 }
247
248 return $this->plugin_instance;
249 }
250
251 /**
252 * Gets an instance of the Theme class
253 *
254 */
255 function get_theme_instance()
256 {
257 if (!isset($this->theme_instance)) {
258 $this->theme_instance = new MMB_Theme();
259 }
260
261 return $this->theme_instance;
262 }
263
264
265 /**
266 * Gets an instance of MMB_Post class
267 *
268 */
269 function get_post_instance()
270 {
271 if (!isset($this->post_instance)) {
272 $this->post_instance = new MMB_Post();
273 }
274
275 return $this->post_instance;
276 }
277
278 /**
279 * Gets an instance of Blogroll class
280 *
281 */
282 function get_blogroll_instance()
283 {
284 if (!isset($this->blogroll_instance)) {
285 $this->blogroll_instance = new MMB_Blogroll();
286 }
287
288 return $this->blogroll_instance;
289 }
290
291
292
293 /**
294 * Gets an instance of the WP class
295 *
296 */
297 function get_wp_instance()
298 {
299 if (!isset($this->wp_instance)) {
300 $this->wp_instance = new MMB_WP();
301 }
302
303 return $this->wp_instance;
304 }
305
306 /**
307 * Gets an instance of User
308 *
309 */
310 function get_user_instance()
311 {
312 if (!isset($this->user_instance)) {
313 $this->user_instance = new MMB_User();
314 }
315
316 return $this->user_instance;
317 }
318
319 /**
320 * Gets an instance of stats class
321 *
322 */
323 function get_stats_instance()
324 {
325 if (!isset($this->stats_instance)) {
326 $this->stats_instance = new MMB_Stats();
327 }
328 return $this->stats_instance;
329 }
330 /**
331 * Gets an instance of search class
332 *
333 */
334 function get_search_instance()
335 {
336 if (!isset($this->search_instance)) {
337 $this->search_instance = new MMB_Search();
338 }
339 //return $this->search_instance;
340 return $this->search_instance;
341 }
342 /**
343 * Gets an instance of stats class
344 *
345 */
346 function get_backup_instance()
347 {
348 if (!isset($this->backup_instance)) {
349 $this->backup_instance = new MMB_Backup();
350 }
351
352 return $this->backup_instance;
353 }
354
355 /**
356 * Gets an instance of links class
357 *
358 */
359 function get_link_instance()
360 {
361 if (!isset($this->link_instance)) {
362 $this->link_instance = new MMB_Link();
363 }
364
365 return $this->link_instance;
366 }
367
368 function get_installer_instance()
369 {
370 if (!isset($this->installer_instance)) {
371 $this->installer_instance = new MMB_Installer();
372 }
373 return $this->installer_instance;
374 }
375
376 /**
377 * Plugin install callback function
378 * Check PHP version
379 */
380 function install() {
381
382 global $wpdb, $_wp_using_ext_object_cache, $current_user;
383 $_wp_using_ext_object_cache = false;
384
385 //delete plugin options, just in case
386 if ($this->mmb_multisite != false) {
387 $user_blogs = get_blogs_of_user($current_user->ID);
388 if(!empty($user_blogs)){
389 if( is_network_admin() ){
390 update_option('mmb_network_admin_install', 1);
391 foreach($user_blogs as $blog_id => $blog_data){
392 if($this->mmb_multisite != $blog_id)
393 update_blog_option($blog_id, 'mmb_network_admin_install', -1);
394
395 delete_blog_option($blog_id, '_worker_nossl_key');
396 delete_blog_option($blog_id, '_worker_public_key');
397 delete_blog_option($blog_id, '_action_message_id');
398 }
399 } else {
400 if(isset($user_blogs[$this->mmb_multisite])){
401 update_option('mmb_network_admin_install', -1);
402 delete_option('_worker_nossl_key');
403 delete_option('_worker_public_key');
404 delete_option('_action_message_id');
405 }
406 }
407 }
408 } else {
409 delete_option('_worker_nossl_key');
410 delete_option('_worker_public_key');
411 delete_option('_action_message_id');
412 }
413
414 delete_option('mwp_backup_tasks');
415 delete_option('mwp_notifications');
416 delete_option('mwp_worker_brand');
417
418 }
419
420 /**
421 * Saves the (modified) options into the database
422 *
423 */
424 function save_options()
425 {
426 if (get_option($this->slug)) {
427 update_option($this->slug, $this->settings);
428 } else {
429 add_option($this->slug, $this->settings);
430 }
431 }
432
433 /**
434 * Deletes options for communication with master
435 *
436 */
437 function uninstall( $deactivate = false )
438 {
439 global $current_user, $wpdb, $_wp_using_ext_object_cache;
440 $_wp_using_ext_object_cache = false;
441
442 if ($this->mmb_multisite != false) {
443 $user_blogs = get_blogs_of_user($current_user->ID);
444 if(!empty($user_blogs)){
445 if( is_network_admin() ){
446 if( $deactivate ) {
447 delete_option('mmb_network_admin_install');
448 foreach($user_blogs as $blog_id => $blog_data){
449 delete_blog_option($blog_id, 'mmb_network_admin_install');
450 delete_blog_option($blog_id, '_worker_nossl_key');
451 delete_blog_option($blog_id, '_worker_public_key');
452 delete_blog_option($blog_id, '_action_message_id');
453 }
454 }
455 } else {
456 if( $deactivate )
457 delete_option('mmb_network_admin_install');
458 if(isset($user_blogs[$this->mmb_multisite])){
459 delete_option('_worker_nossl_key');
460 delete_option('_worker_public_key');
461 delete_option('_action_message_id');
462 }
463 }
464 }
465 } else {
466 delete_option('_worker_nossl_key');
467 delete_option('_worker_public_key');
468 delete_option('_action_message_id');
469 }
470
471 //Delete backup tasks
472 delete_option('mwp_backup_tasks');
473 wp_clear_scheduled_hook('mwp_backup_tasks');
474
475 //Delete notifications
476 delete_option('mwp_notifications');
477 wp_clear_scheduled_hook('mwp_notifications');
478 delete_option('mwp_worker_brand');
479 }
480
481
482 /**
483 * Constructs a url (for ajax purpose)
484 *
485 * @param mixed $base_page
486 */
487 function construct_url($params = array(), $base_page = 'index.php')
488 {
489 $url = "$base_page?_wpnonce=" . wp_create_nonce($this->slug);
490 foreach ($params as $key => $value) {
491 $url .= "&$key=$value";
492 }
493
494 return $url;
495 }
496
497 /**
498 * Worker update
499 *
500 */
501 function update_worker_plugin($params)
502 {
503 extract($params);
504 if ($download_url) {
505 @include_once ABSPATH . 'wp-admin/includes/file.php';
506 @include_once ABSPATH . 'wp-admin/includes/misc.php';
507 @include_once ABSPATH . 'wp-admin/includes/template.php';
508 @include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
509 @include_once ABSPATH . 'wp-admin/includes/screen.php';
510
511 if (!$this->is_server_writable()) {
512 return array(
513 'error' => 'Failed, please <a target="_blank" href="http://managewp.com/user-guide#ftp">add FTP details for automatic upgrades.</a></a>'
514 );
515 }
516
517 ob_start();
518 @unlink(dirname(__FILE__));
519 $upgrader = new Plugin_Upgrader();
520 $result = $upgrader->run(array(
521 'package' => $download_url,
522 'destination' => WP_PLUGIN_DIR,
523 'clear_destination' => true,
524 'clear_working' => true,
525 'hook_extra' => array(
526 'plugin' => 'worker/init.php'
527 )
528 ));
529 ob_end_clean();
530 if (is_wp_error($result) || !$result) {
531 return array(
532 'error' => 'ManageWP Worker plugin could not be updated.'
533 );
534 } else {
535 return array(
536 'success' => 'ManageWP Worker plugin successfully updated.'
537 );
538 }
539 }
540 return array(
541 'error' => 'Bad download path for worker installation file.'
542 );
543 }
544
545 /**
546 * Automatically logs in when called from Master
547 *
548 */
549 function automatic_login()
550 {
551 $where = isset($_GET['mwp_goto']) ? $_GET['mwp_goto'] : false;
552 $username = isset($_GET['username']) ? $_GET['username'] : '';
553 $auto_login = isset($_GET['auto_login']) ? $_GET['auto_login'] : 0;
554
555 if( !function_exists('is_user_logged_in') )
556 include_once( ABSPATH.'wp-includes/pluggable.php' );
557
558 if (( $auto_login && strlen(trim($username)) && !is_user_logged_in() ) || (isset($this->mmb_multisite) && $this->mmb_multisite )) {
559 $signature = base64_decode($_GET['signature']);
560 $message_id = trim($_GET['message_id']);
561
562 $auth = $this->authenticate_message($where . $message_id, $signature, $message_id);
563 if ($auth === true) {
564
565 if (!headers_sent())
566 header('P3P: CP="CAO PSA OUR"');
567
568 if(!defined('MMB_USER_LOGIN'))
569 define('MMB_USER_LOGIN', true);
570
571 $siteurl = function_exists('get_site_option') ? get_site_option( 'siteurl' ) : get_option('siteurl');
572 $user = $this->mmb_get_user_info($username);
573 wp_set_current_user($user->ID);
574
575 if(!defined('COOKIEHASH') || (isset($this->mmb_multisite) && $this->mmb_multisite) )
576 wp_cookie_constants();
577
578 wp_set_auth_cookie($user->ID);
579 @mmb_worker_header();
580
581 if((isset($this->mmb_multisite) && $this->mmb_multisite ) || isset($_REQUEST['mwpredirect'])){
582 if(function_exists('wp_safe_redirect') && function_exists('admin_url')){
583 wp_safe_redirect(admin_url($where));
584 exit();
585 }
586 }
587 } else {
588 wp_die($auth['error']);
589 }
590 } elseif( is_user_logged_in() ) {
591 @mmb_worker_header();
592 if(isset($_REQUEST['mwpredirect'])){
593 if(function_exists('wp_safe_redirect') && function_exists('admin_url')){
594 wp_safe_redirect(admin_url($where));
595 exit();
596 }
597 }
598 }
599 }
600
601 function mmb_set_auth_cookie( $auth_cookie ){
602 if(!defined('MMB_USER_LOGIN'))
603 return false;
604
605 if( !defined('COOKIEHASH') )
606 wp_cookie_constants();
607
608 $_COOKIE['wordpress_'.COOKIEHASH] = $auth_cookie;
609
610 }
611 function mmb_set_logged_in_cookie( $logged_in_cookie ){
612 if(!defined('MMB_USER_LOGIN'))
613 return false;
614
615 if( !defined('COOKIEHASH') )
616 wp_cookie_constants();
617
618 $_COOKIE['wordpress_logged_in_'.COOKIEHASH] = $logged_in_cookie;
619 }
620
621 function admin_actions(){
622 add_filter('all_plugins', array($this, 'worker_replace'));
623 }
624
625 function worker_replace($all_plugins){
626 $replace = get_option("mwp_worker_brand");
627 if(is_array($replace)){
628 if($replace['name'] || $replace['desc'] || $replace['author'] || $replace['author_url']){
629 $all_plugins['worker/init.php']['Name'] = $replace['name'];
630 $all_plugins['worker/init.php']['Title'] = $replace['name'];
631 $all_plugins['worker/init.php']['Description'] = $replace['desc'];
632 $all_plugins['worker/init.php']['AuthorURI'] = $replace['author_url'];
633 $all_plugins['worker/init.php']['Author'] = $replace['author'];
634 $all_plugins['worker/init.php']['AuthorName'] = $replace['author'];
635 $all_plugins['worker/init.php']['PluginURI'] = '';
636 }
637
638 if($replace['hide']){
639 if (!function_exists('get_plugins')) {
640 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
641 }
642 $activated_plugins = get_option('active_plugins');
643 if (!$activated_plugins)
644 $activated_plugins = array();
645 if(in_array('worker/init.php',$activated_plugins))
646 unset($all_plugins['worker/init.php']);
647 }
648 }
649
650
651 return $all_plugins;
652 }
653
654
655 }
656 ?>