PluginProbe
ManageWP Worker / 3.9.20
ManageWP Worker v3.9.20
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.20, at core.class.php

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