PluginProbe
ManageWP Worker / 3.9.23
ManageWP Worker v3.9.23
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.23, at core.class.php

676 lines 22.1 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 $mwp_worker_brand = get_option("mwp_worker_brand");
141
142 if (!$mwp_worker_brand['hide_managed_remotely']) {
143 add_action('rightnow_end', array( &$this, 'add_right_now_info' ));
144 }
145
146 add_action('admin_init', array(&$this,'admin_actions'));
147 add_action('init', array( &$this, 'mmb_remote_action'), 9999);
148 //add_action('setup_theme', 'mmb_run_backup_action', 1);
149 add_action('setup_theme', 'mmb_parse_request');
150 add_action('set_auth_cookie', array( &$this, 'mmb_set_auth_cookie'));
151 add_action('set_logged_in_cookie', array( &$this, 'mmb_set_logged_in_cookie'));
152 }
153
154 function mmb_remote_action(){
155 if($this->action_call != null){
156 $params = isset($this->action_params) && $this->action_params != null ? $this->action_params : array();
157 call_user_func($this->action_call, $params);
158 }
159 }
160
161 function register_action_params( $action = false, $params = array() ){
162
163 if(isset($this->mmb_pre_init_actions[$action]) && function_exists($this->mmb_pre_init_actions[$action])){
164 call_user_func($this->mmb_pre_init_actions[$action], $params);
165 }
166
167 if(isset($this->mmb_init_actions[$action]) && function_exists($this->mmb_init_actions[$action])){
168 $this->action_call = $this->mmb_init_actions[$action];
169 $this->action_params = $params;
170
171 if( isset($this->mmb_pre_init_filters[$action]) && !empty($this->mmb_pre_init_filters[$action])){
172 global $mmb_filters;
173
174 foreach($this->mmb_pre_init_filters[$action] as $_name => $_functions){
175 if(!empty($_functions)){
176 $data = array();
177
178 foreach($_functions as $_k => $_callback){
179 if(is_array($_callback) && method_exists($_callback[0], $_callback[1]) ){
180 $data = call_user_func( $_callback, $params );
181 } elseif (is_string($_callback) && function_exists( $_callback )){
182 $data = call_user_func( $_callback, $params );
183 }
184 $mmb_filters[$_name] = isset($mmb_filters[$_name]) && !empty($mmb_filters[$_name]) ? array_merge($mmb_filters[$_name], $data) : $data;
185 add_filter( $_name, create_function( '$a' , 'global $mmb_filters; return array_merge($a, $mmb_filters["'.$_name.'"]);') );
186 }
187 }
188
189 }
190 }
191 return true;
192 }
193 return false;
194 }
195
196 /**
197 * Add notice to network admin dashboard for security reasons
198 *
199 */
200 function network_admin_notice()
201 {
202 echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">Attention !</p><p>
203 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>.
204 </p></div>';
205 }
206
207
208 /**
209 * Add notice to admin dashboard for security reasons
210 *
211 */
212 function admin_notice()
213 {
214 echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">Attention !</p><p>
215 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>.
216 </p></div>';
217 }
218
219 /**
220 * Add an item into the Right Now Dashboard widget
221 * to inform that the blog can be managed remotely
222 *
223 */
224 function add_right_now_info()
225 {
226 echo '<div class="mmb-slave-info">
227 <p>This site can be managed remotely.</p>
228 </div>';
229 }
230
231 /**
232 * Get parent blog options
233 *
234 */
235 private function get_parent_blog_option( $option_name = '' )
236 {
237 global $wpdb;
238 $option = $wpdb->get_var( $wpdb->prepare( "SELECT `option_value` FROM {$wpdb->base_prefix}options WHERE option_name = '{$option_name}' LIMIT 1" ) );
239 return $option;
240 }
241
242 /**
243 * Gets an instance of the Comment class
244 *
245 */
246 function get_comment_instance()
247 {
248 if (!isset($this->comment_instance)) {
249 $this->comment_instance = new MMB_Comment();
250 }
251
252 return $this->comment_instance;
253 }
254
255 /**
256 * Gets an instance of the Plugin class
257 *
258 */
259 function get_plugin_instance()
260 {
261 if (!isset($this->plugin_instance)) {
262 $this->plugin_instance = new MMB_Plugin();
263 }
264
265 return $this->plugin_instance;
266 }
267
268 /**
269 * Gets an instance of the Theme class
270 *
271 */
272 function get_theme_instance()
273 {
274 if (!isset($this->theme_instance)) {
275 $this->theme_instance = new MMB_Theme();
276 }
277
278 return $this->theme_instance;
279 }
280
281
282 /**
283 * Gets an instance of MMB_Post class
284 *
285 */
286 function get_post_instance()
287 {
288 if (!isset($this->post_instance)) {
289 $this->post_instance = new MMB_Post();
290 }
291
292 return $this->post_instance;
293 }
294
295 /**
296 * Gets an instance of Blogroll class
297 *
298 */
299 function get_blogroll_instance()
300 {
301 if (!isset($this->blogroll_instance)) {
302 $this->blogroll_instance = new MMB_Blogroll();
303 }
304
305 return $this->blogroll_instance;
306 }
307
308
309
310 /**
311 * Gets an instance of the WP class
312 *
313 */
314 function get_wp_instance()
315 {
316 if (!isset($this->wp_instance)) {
317 $this->wp_instance = new MMB_WP();
318 }
319
320 return $this->wp_instance;
321 }
322
323 /**
324 * Gets an instance of User
325 *
326 */
327 function get_user_instance()
328 {
329 if (!isset($this->user_instance)) {
330 $this->user_instance = new MMB_User();
331 }
332
333 return $this->user_instance;
334 }
335
336 /**
337 * Gets an instance of stats class
338 *
339 */
340 function get_stats_instance()
341 {
342 if (!isset($this->stats_instance)) {
343 $this->stats_instance = new MMB_Stats();
344 }
345 return $this->stats_instance;
346 }
347 /**
348 * Gets an instance of search class
349 *
350 */
351 function get_search_instance()
352 {
353 if (!isset($this->search_instance)) {
354 $this->search_instance = new MMB_Search();
355 }
356 //return $this->search_instance;
357 return $this->search_instance;
358 }
359 /**
360 * Gets an instance of stats class
361 *
362 */
363 function get_backup_instance()
364 {
365 if (!isset($this->backup_instance)) {
366 $this->backup_instance = new MMB_Backup();
367 }
368
369 return $this->backup_instance;
370 }
371
372 /**
373 * Gets an instance of links class
374 *
375 */
376 function get_link_instance()
377 {
378 if (!isset($this->link_instance)) {
379 $this->link_instance = new MMB_Link();
380 }
381
382 return $this->link_instance;
383 }
384
385 function get_installer_instance()
386 {
387 if (!isset($this->installer_instance)) {
388 $this->installer_instance = new MMB_Installer();
389 }
390 return $this->installer_instance;
391 }
392
393 /**
394 * Plugin install callback function
395 * Check PHP version
396 */
397 function install() {
398
399 global $wpdb, $_wp_using_ext_object_cache, $current_user;
400 $_wp_using_ext_object_cache = false;
401
402 //delete plugin options, just in case
403 if ($this->mmb_multisite != false) {
404 $network_blogs = $wpdb->get_results($wpdb->prepare("select `blog_id`, `site_id` from `{$wpdb->blogs}`"));
405 if(!empty($network_blogs)){
406 if( is_network_admin() ){
407 update_option('mmb_network_admin_install', 1);
408 foreach($network_blogs as $details){
409 if($details->site_id == $details->blog_id)
410 update_blog_option($details->blog_id, 'mmb_network_admin_install', 1);
411 else
412 update_blog_option($details->blog_id, 'mmb_network_admin_install', -1);
413
414 delete_blog_option($blog_id, '_worker_nossl_key');
415 delete_blog_option($blog_id, '_worker_public_key');
416 delete_blog_option($blog_id, '_action_message_id');
417 }
418 } else {
419 update_option('mmb_network_admin_install', -1);
420 delete_option('_worker_nossl_key');
421 delete_option('_worker_public_key');
422 delete_option('_action_message_id');
423 }
424 }
425 } else {
426 delete_option('_worker_nossl_key');
427 delete_option('_worker_public_key');
428 delete_option('_action_message_id');
429 }
430
431 //delete_option('mwp_backup_tasks');
432 delete_option('mwp_notifications');
433 delete_option('mwp_worker_brand');
434 delete_option('mwp_pageview_alerts');
435 }
436
437 /**
438 * Saves the (modified) options into the database
439 *
440 */
441 function save_options( $options = array() ){
442 global $_mmb_options;
443
444 $_mmb_options = array_merge( $_mmb_options, $options );
445 update_option('wrksettings', $options);
446 }
447
448 /**
449 * Deletes options for communication with master
450 *
451 */
452 function uninstall( $deactivate = false )
453 {
454 global $current_user, $wpdb, $_wp_using_ext_object_cache;
455 $_wp_using_ext_object_cache = false;
456
457 if ($this->mmb_multisite != false) {
458 $network_blogs = $wpdb->get_col($wpdb->prepare("select `blog_id` from `{$wpdb->blogs}`"));
459 if(!empty($network_blogs)){
460 if( is_network_admin() ){
461 if( $deactivate ) {
462 delete_option('mmb_network_admin_install');
463 foreach($network_blogs as $blog_id){
464 delete_blog_option($blog_id, 'mmb_network_admin_install');
465 delete_blog_option($blog_id, '_worker_nossl_key');
466 delete_blog_option($blog_id, '_worker_public_key');
467 delete_blog_option($blog_id, '_action_message_id');
468 delete_blog_option($blog_id, 'mwp_maintenace_mode');
469 //delete_blog_option($blog_id, 'mwp_backup_tasks');
470 delete_blog_option($blog_id, 'mwp_notifications');
471 delete_blog_option($blog_id, 'mwp_worker_brand');
472 delete_blog_option($blog_id, 'mwp_pageview_alerts');
473 delete_blog_option($blog_id, 'mwp_pageview_alerts');
474 }
475 }
476 } else {
477 if( $deactivate )
478 delete_option('mmb_network_admin_install');
479
480 delete_option('_worker_nossl_key');
481 delete_option('_worker_public_key');
482 delete_option('_action_message_id');
483 }
484 }
485 } else {
486 delete_option('_worker_nossl_key');
487 delete_option('_worker_public_key');
488 delete_option('_action_message_id');
489 }
490
491 //Delete options
492 delete_option('mwp_maintenace_mode');
493 //delete_option('mwp_backup_tasks');
494 delete_option('mwp_notifications');
495 delete_option('mwp_worker_brand');
496 delete_option('mwp_pageview_alerts');
497 wp_clear_scheduled_hook('mwp_backup_tasks');
498 wp_clear_scheduled_hook('mwp_notifications');
499 wp_clear_scheduled_hook('mwp_datasend');
500 }
501
502
503 /**
504 * Constructs a url (for ajax purpose)
505 *
506 * @param mixed $base_page
507 */
508 function construct_url($params = array(), $base_page = 'index.php')
509 {
510 $url = "$base_page?_wpnonce=" . wp_create_nonce($this->slug);
511 foreach ($params as $key => $value) {
512 $url .= "&$key=$value";
513 }
514
515 return $url;
516 }
517
518 /**
519 * Worker update
520 *
521 */
522 function update_worker_plugin($params)
523 {
524 extract($params);
525 if ($download_url) {
526 @include_once ABSPATH . 'wp-admin/includes/file.php';
527 @include_once ABSPATH . 'wp-admin/includes/misc.php';
528 @include_once ABSPATH . 'wp-admin/includes/template.php';
529 @include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
530 @include_once ABSPATH . 'wp-admin/includes/screen.php';
531
532 if (!$this->is_server_writable()) {
533 return array(
534 '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>'
535 );
536 }
537
538 ob_start();
539 @unlink(dirname(__FILE__));
540 $upgrader = new Plugin_Upgrader();
541 $result = $upgrader->run(array(
542 'package' => $download_url,
543 'destination' => WP_PLUGIN_DIR,
544 'clear_destination' => true,
545 'clear_working' => true,
546 'hook_extra' => array(
547 'plugin' => 'worker/init.php'
548 )
549 ));
550 ob_end_clean();
551 if (is_wp_error($result) || !$result) {
552 return array(
553 'error' => 'ManageWP Worker plugin could not be updated.'
554 );
555 } else {
556 return array(
557 'success' => 'ManageWP Worker plugin successfully updated.'
558 );
559 }
560 }
561 return array(
562 'error' => 'Bad download path for worker installation file.'
563 );
564 }
565
566 /**
567 * Automatically logs in when called from Master
568 *
569 */
570 function automatic_login()
571 {
572 $where = isset($_GET['mwp_goto']) ? $_GET['mwp_goto'] : false;
573 $username = isset($_GET['username']) ? $_GET['username'] : '';
574 $auto_login = isset($_GET['auto_login']) ? $_GET['auto_login'] : 0;
575
576 if( !function_exists('is_user_logged_in') )
577 include_once( ABSPATH.'wp-includes/pluggable.php' );
578
579 if (( $auto_login && strlen(trim($username)) && !is_user_logged_in() ) || (isset($this->mmb_multisite) && $this->mmb_multisite )) {
580 $signature = base64_decode($_GET['signature']);
581 $message_id = trim($_GET['message_id']);
582
583 $auth = $this->authenticate_message($where . $message_id, $signature, $message_id);
584 if ($auth === true) {
585
586 if (!headers_sent())
587 header('P3P: CP="CAO PSA OUR"');
588
589 if(!defined('MMB_USER_LOGIN'))
590 define('MMB_USER_LOGIN', true);
591
592 $siteurl = function_exists('get_site_option') ? get_site_option( 'siteurl' ) : get_option('siteurl');
593 $user = $this->mmb_get_user_info($username);
594 wp_set_current_user($user->ID);
595
596 if(!defined('COOKIEHASH') || (isset($this->mmb_multisite) && $this->mmb_multisite) )
597 wp_cookie_constants();
598
599 wp_set_auth_cookie($user->ID);
600 @mmb_worker_header();
601
602 if((isset($this->mmb_multisite) && $this->mmb_multisite ) || isset($_REQUEST['mwpredirect'])){
603 if(function_exists('wp_safe_redirect') && function_exists('admin_url')){
604 wp_safe_redirect(admin_url($where));
605 exit();
606 }
607 }
608 } else {
609 wp_die($auth['error']);
610 }
611 } elseif( is_user_logged_in() ) {
612 @mmb_worker_header();
613 if(isset($_REQUEST['mwpredirect'])){
614 if(function_exists('wp_safe_redirect') && function_exists('admin_url')){
615 wp_safe_redirect(admin_url($where));
616 exit();
617 }
618 }
619 }
620 }
621
622 function mmb_set_auth_cookie( $auth_cookie ){
623 if(!defined('MMB_USER_LOGIN'))
624 return false;
625
626 if( !defined('COOKIEHASH') )
627 wp_cookie_constants();
628
629 $_COOKIE['wordpress_'.COOKIEHASH] = $auth_cookie;
630
631 }
632 function mmb_set_logged_in_cookie( $logged_in_cookie ){
633 if(!defined('MMB_USER_LOGIN'))
634 return false;
635
636 if( !defined('COOKIEHASH') )
637 wp_cookie_constants();
638
639 $_COOKIE['wordpress_logged_in_'.COOKIEHASH] = $logged_in_cookie;
640 }
641
642 function admin_actions(){
643 add_filter('all_plugins', array($this, 'worker_replace'));
644 }
645
646 function worker_replace($all_plugins){
647 $replace = get_option("mwp_worker_brand");
648 if(is_array($replace)){
649 if($replace['name'] || $replace['desc'] || $replace['author'] || $replace['author_url']){
650 $all_plugins['worker/init.php']['Name'] = $replace['name'];
651 $all_plugins['worker/init.php']['Title'] = $replace['name'];
652 $all_plugins['worker/init.php']['Description'] = $replace['desc'];
653 $all_plugins['worker/init.php']['AuthorURI'] = $replace['author_url'];
654 $all_plugins['worker/init.php']['Author'] = $replace['author'];
655 $all_plugins['worker/init.php']['AuthorName'] = $replace['author'];
656 $all_plugins['worker/init.php']['PluginURI'] = '';
657 }
658
659 if($replace['hide']){
660 if (!function_exists('get_plugins')) {
661 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
662 }
663 $activated_plugins = get_option('active_plugins');
664 if (!$activated_plugins)
665 $activated_plugins = array();
666 if(in_array('worker/init.php',$activated_plugins))
667 unset($all_plugins['worker/init.php']);
668 }
669 }
670
671
672 return $all_plugins;
673 }
674
675 }
676 ?>