PluginProbe
ManageWP Worker / 3.9.19
ManageWP Worker v3.9.19
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.19, at core.class.php

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