PluginProbe
ManageWP Worker / 3.9.18
ManageWP Worker v3.9.18
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.18, at core.class.php

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