PluginProbe
ManageWP Worker / 3.9.28
ManageWP Worker v3.9.28
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.28, at core.class.php

919 lines 31.4 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 $security_instance;
31 var $backup_instance;
32 var $installer_instance;
33 var $mmb_multisite;
34 var $network_admin_install;
35 private $action_call;
36 private $action_params;
37 private $mmb_pre_init_actions;
38 private $mmb_pre_init_filters;
39 private $mmb_init_actions;
40
41
42 function __construct()
43 {
44 global $mmb_plugin_dir, $wpmu_version, $blog_id, $_mmb_plugin_actions, $_mmb_item_filter, $_mmb_options;
45
46 $_mmb_plugin_actions = array();
47 $_mmb_options = get_option('wrksettings');
48 $_mmb_options = !empty($_mmb_options) ? $_mmb_options : array();
49
50 $this->name = 'Manage Multiple Blogs';
51 $this->action_call = null;
52 $this->action_params = null;
53
54 if ( function_exists('is_multisite') ) {
55 if ( is_multisite() ) {
56 $this->mmb_multisite = $blog_id;
57 $this->network_admin_install = get_option('mmb_network_admin_install');
58 }
59 } else if (!empty($wpmu_version)) {
60 $this->mmb_multisite = $blog_id;
61 $this->network_admin_install = get_option('mmb_network_admin_install');
62 } else {
63 $this->mmb_multisite = false;
64 $this->network_admin_install = null;
65 }
66
67 // admin notices
68 if ( !get_option('_worker_public_key') ){
69 if( $this->mmb_multisite ){
70 if( is_network_admin() && $this->network_admin_install == '1'){
71 add_action('network_admin_notices', array( &$this, 'network_admin_notice' ));
72 } else if( $this->network_admin_install != '1' ){
73 $parent_key = $this->get_parent_blog_option('_worker_public_key');
74 if(empty($parent_key))
75 add_action('admin_notices', array( &$this, 'admin_notice' ));
76 }
77 } else {
78 add_action('admin_notices', array( &$this, 'admin_notice' ));
79 }
80 }
81
82 // default filters
83 //$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
84 $this->mmb_pre_init_filters['get_stats']['mmb_stats_filter'][] = 'mmb_pre_init_stats';
85
86 $_mmb_item_filter['pre_init_stats'] = array( 'core_update', 'hit_counter', 'comments', 'backups', 'posts', 'drafts', 'scheduled' );
87 $_mmb_item_filter['get'] = array( 'updates', 'errors' );
88
89 $this->mmb_pre_init_actions = array(
90 'backup_req' => 'mmb_get_backup_req',
91 );
92
93 $this->mmb_init_actions = array(
94 'do_upgrade' => 'mmb_do_upgrade',
95 'get_stats' => 'mmb_stats_get',
96 'remove_site' => 'mmb_remove_site',
97 'backup_clone' => 'mmb_backup_now',
98 'restore' => 'mmb_restore_now',
99 'optimize_tables' => 'mmb_optimize_tables',
100 'check_wp_version' => 'mmb_wp_checkversion',
101 'create_post' => 'mmb_post_create',
102 'update_worker' => 'mmb_update_worker_plugin',
103 'change_comment_status' => 'mmb_change_comment_status',
104 'change_post_status' => 'mmb_change_post_status',
105 'get_comment_stats' => 'mmb_comment_stats_get',
106 'install_addon' => 'mmb_install_addon',
107 'get_links' => 'mmb_get_links',
108 'add_link' => 'mmb_add_link',
109 'delete_link' => 'mmb_delete_link',
110 'delete_links' => 'mmb_delete_links',
111 'get_comments' => 'mmb_get_comments',
112 'action_comment' => 'mmb_action_comment',
113 'bulk_action_comments' => 'mmb_bulk_action_comments',
114 'replyto_comment' => 'mmb_reply_comment',
115 'add_user' => 'mmb_add_user',
116 'email_backup' => 'mmb_email_backup',
117 'check_backup_compat' => 'mmb_check_backup_compat',
118 'scheduled_backup' => 'mmb_scheduled_backup',
119 'run_task' => 'mmb_run_task_now',
120 'execute_php_code' => 'mmb_execute_php_code',
121 'delete_backup' => 'mmm_delete_backup',
122 'remote_backup_now' => 'mmb_remote_backup_now',
123 'set_notifications' => 'mmb_set_notifications',
124 'clean_orphan_backups' => 'mmb_clean_orphan_backups',
125 'get_users' => 'mmb_get_users',
126 'edit_users' => 'mmb_edit_users',
127 'get_posts' => 'mmb_get_posts',
128 'delete_post' => 'mmb_delete_post',
129 'delete_posts' => 'mmb_delete_posts',
130 'edit_posts' => 'mmb_edit_posts',
131 'get_pages' => 'mmb_get_pages',
132 'delete_page' => 'mmb_delete_page',
133 'get_plugins_themes' => 'mmb_get_plugins_themes',
134 'edit_plugins_themes' => 'mmb_edit_plugins_themes',
135 'worker_brand' => 'mmb_worker_brand',
136 'maintenance' => 'mmb_maintenance_mode',
137 'get_dbname' => 'mmb_get_dbname',
138 'security_check' => 'mbb_security_check',
139 'security_fix_folder_listing'=> 'mbb_security_fix_folder_listing',
140 'security_fix_php_reporting'=> 'mbb_security_fix_php_reporting',
141 'security_fix_database_reporting'=> 'mbb_security_fix_database_reporting',
142 'security_fix_wp_version'=> 'mbb_security_fix_wp_version',
143 'security_fix_admin_username'=>'mbb_security_fix_admin_username',
144 'security_fix_htaccess_permission'=>'mbb_security_fix_htaccess_permission',
145 'security_fix_scripts_styles'=>'mbb_security_fix_scripts_styles',
146 'security_fix_file_permission'=>'mbb_security_fix_file_permission',
147 'security_fix_all' =>'mbb_security_fix_all',
148 'get_autoupdate_plugins_themes' => 'mmb_get_autoupdate_plugins_themes',
149 'edit_autoupdate_plugins_themes' => 'mmb_edit_autoupdate_plugins_themes',
150
151 );
152
153 $mwp_worker_brand = get_option("mwp_worker_brand");
154 //!$mwp_worker_brand['hide_managed_remotely']
155 if ($mwp_worker_brand == false || (is_array($mwp_worker_brand) && !array_key_exists('hide_managed_remotely', $mwp_worker_brand))) {
156 add_action('rightnow_end', array( &$this, 'add_right_now_info' ));
157 }
158 if ($mwp_worker_brand != false && is_array($mwp_worker_brand) && isset($mwp_worker_brand['text_for_client']) && ($mwp_worker_brand['email_or_link'] != 0)) {
159 add_action('admin_init', array($this, 'enqueue_scripts'));
160 add_action('admin_init', array($this, 'enqueue_styles'));
161 add_action('admin_menu', array($this, 'add_support_page'));
162 add_action('admin_head', array($this, 'support_page_script'));
163 add_action('admin_footer', array($this, 'support_page_dialog'));
164 add_action('admin_init', array($this, 'send_email_to_admin'));
165 }
166 add_action( 'plugins_loaded', array( &$this, 'dissalow_text_editor' ) );
167
168 add_action('admin_init', array(&$this,'admin_actions'));
169 add_action('init', array( &$this, 'mmb_remote_action'), 9999);
170 add_action('setup_theme', 'mmb_run_backup_action', 1);
171 add_action('plugins_loaded', 'mmb_authenticate', 1);
172 add_action('setup_theme', 'mmb_parse_request');
173 add_action('set_auth_cookie', array( &$this, 'mmb_set_auth_cookie'));
174 add_action('set_logged_in_cookie', array( &$this, 'mmb_set_logged_in_cookie'));
175
176
177 }
178
179 function mmb_remote_action(){
180 if($this->action_call != null){
181 $params = isset($this->action_params) && $this->action_params != null ? $this->action_params : array();
182 call_user_func($this->action_call, $params);
183 }
184 }
185
186 function register_action_params( $action = false, $params = array() ){
187
188 if(isset($this->mmb_pre_init_actions[$action]) && function_exists($this->mmb_pre_init_actions[$action])){
189 call_user_func($this->mmb_pre_init_actions[$action], $params);
190 }
191
192 if(isset($this->mmb_init_actions[$action]) && function_exists($this->mmb_init_actions[$action])){
193 $this->action_call = $this->mmb_init_actions[$action];
194 $this->action_params = $params;
195
196 if( isset($this->mmb_pre_init_filters[$action]) && !empty($this->mmb_pre_init_filters[$action])){
197 global $mmb_filters;
198
199 foreach($this->mmb_pre_init_filters[$action] as $_name => $_functions){
200 if(!empty($_functions)){
201 $data = array();
202
203 foreach($_functions as $_k => $_callback){
204 if(is_array($_callback) && method_exists($_callback[0], $_callback[1]) ){
205 $data = call_user_func( $_callback, $params );
206 } elseif (is_string($_callback) && function_exists( $_callback )){
207 $data = call_user_func( $_callback, $params );
208 }
209 $mmb_filters[$_name] = isset($mmb_filters[$_name]) && !empty($mmb_filters[$_name]) ? array_merge($mmb_filters[$_name], $data) : $data;
210 add_filter( $_name, create_function( '$a' , 'global $mmb_filters; return array_merge($a, $mmb_filters["'.$_name.'"]);') );
211 }
212 }
213
214 }
215 }
216 return true;
217 }
218 return false;
219 }
220
221 /**
222 * Add notice to network admin dashboard for security reasons
223 *
224 */
225 function network_admin_notice()
226 {
227 global $status, $page, $s;
228 $context = $status;
229 $plugin = 'worker/init.php';
230 $nonce = wp_create_nonce('deactivate-plugin_' . $plugin);
231 $actions = 'plugins.php?action=deactivate&amp;plugin='.urlencode($plugin).'&amp;plugin_status=' . $context . '&amp;paged=' . $page.'&amp;s=' . $s. '&amp;_wpnonce=' .$nonce ;
232 echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">ManageWP Notice</p><p>
233 Please <a href="https://managewp.com" target="_blank">add this site and your network blogs</a>, with your network administrator username, to your ManageWP account. <a target="_blank" href="https://managewp.com/features">What is ManageWP?</a> <br ><br > Otherwise, click to <a href="'.$actions.'">deactivate ManageWP plugin</a></em>.
234 </p></div>';
235 }
236
237
238 /**
239 * Add notice to admin dashboard for security reasons
240 *
241 */
242 function admin_notice()
243 {
244 global $status, $page, $s;
245 $context = $status;
246 $plugin = 'worker/init.php';
247 $nonce = wp_create_nonce('deactivate-plugin_' . $plugin);
248 $actions = 'plugins.php?action=deactivate&amp;plugin='.urlencode($plugin).'&amp;plugin_status=' . $context . '&amp;paged=' . $page.'&amp;s=' . $s. '&amp;_wpnonce=' .$nonce ;
249 $deactivation = 'click to <a href="'.$actions.'">deactivate ManageWP plugin</a>';
250 if($this->mmb_multisite && $this->network_admin_install != '1'){
251 $deactivation = "deactivate ManageWP plugin";
252 }
253 echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">ManageWP Notice</p><p>
254 Please <a href="https://managewp.com" target="_blank">add this site</a> to your ManageWP account. <a target="_blank" href="https://managewp.com/features">What is ManageWP?</a> <br ><br >
255 <em>Otherwise, '.$deactivation.'</em>.
256 </p></div>';
257 }
258
259 /**
260 * Add an item into the Right Now Dashboard widget
261 * to inform that the blog can be managed remotely
262 *
263 */
264 function add_right_now_info()
265 {
266 $mwp_worker_brand = get_option('mwp_worker_brand');
267 echo '<div class="mmb-slave-info">';
268 if($mwp_worker_brand && isset($mwp_worker_brand['remotely_managed_text'])){
269 /*$url = isset($mwp_worker_brand['author_url']) ? $mwp_worker_brand['author_url'] : null;
270 if($url) {
271 $scheme = parse_url($mwp_worker_brand['author_url'], PHP_URL_SCHEME);
272 if(empty($scheme)) {
273 $url = 'http://' . $url;
274 }
275 }
276 if($url) {
277 $managedBy = '<a target="_blank" href="'.htmlspecialchars($url).'">'
278 .htmlspecialchars($mwp_worker_brand['author'])
279 .'</a>';
280 } else {
281 $managedBy = htmlspecialchars($mwp_worker_brand['author']);
282 }
283 echo sprintf('<p>This site is managed by %s.</p>', $managedBy);*/
284 echo '<p>'.$mwp_worker_brand['remotely_managed_text'].'</p>';
285 }else{
286 echo '<p>This site can be managed remotely.</p>';
287 }
288 echo '</div>';
289 }
290
291 function enqueue_scripts()
292 {
293 wp_enqueue_script('jquery');
294 wp_enqueue_script('jquery-ui-core');
295 wp_enqueue_script('jquery-ui-dialog');
296 }
297
298 function enqueue_styles()
299 {
300 wp_enqueue_style('wp-jquery-ui');
301 wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/smoothness/jquery-ui.css');
302 }
303
304 function send_email_to_admin(){
305 if(!isset($_POST['support_mwp_message'])) {
306 return;
307 }
308 global $current_user;
309 if (empty($_POST['support_mwp_message'])) {
310 $this->mwp_send_ajax_response(false, "Please enter a message.");
311 }
312 $mwp_worker_brand = get_option('mwp_worker_brand');
313 if(empty($mwp_worker_brand['admin_email'])) {
314 $this->mwp_send_ajax_response(false, "Unable to send email to admin.");
315 }
316 $subject = 'New ticket for site '.get_bloginfo('url');
317 $message = <<<EOF
318 Hi,
319 User with a username {$current_user->user_login} has a new question:
320 {$_POST['support_mwp_message']}
321 EOF;
322 $has_been_sent = wp_mail($mwp_worker_brand['admin_email'], $subject, $message);
323 if(!$has_been_sent) {
324 $this->mwp_send_ajax_response(false, "Unable to send email. Please try again.");
325 }
326 $this->mwp_send_ajax_response(true, "Message successfully sent.");
327 }
328
329 function mwp_send_ajax_response($success = true, $message = '')
330 {
331 $response = json_encode(array(
332 'success' => $success,
333 'message' => $message,
334 ));
335 print $response;
336 exit;
337 }
338
339 function support_page_dialog()
340 {
341 $mwp_worker_brand = get_option('mwp_worker_brand');
342 if($mwp_worker_brand && isset($mwp_worker_brand['text_for_client']) && ($mwp_worker_brand['text_for_client'] != ''))
343 {
344 $notification_text = $mwp_worker_brand['text_for_client'];
345 }
346 ?>
347 <div id="support_dialog" style="display: none;">
348 <div>
349 <p><?php echo $notification_text; ?></p>
350 </div>
351 <div style="margin: 19px 0 0;">
352 <?php
353 if($mwp_worker_brand['email_or_link'] == 1)
354 {
355 ?>
356 <form method="post" id="support_form">
357 <textarea name="support_mwp_message" id="support_message" style="width:500px;height:150px;display:block;margin-left:auto;margin-right:auto;"></textarea>
358 <button type="submit" class="button-primary" style="display:block;margin:20px auto 7px auto;border:1px solid #a1a1a1;padding:0px 31px;border-radius: 4px;">Send</button>
359 </form>
360 <div id="support_response_id" style="margin-top: 14px"></div>
361 <style>
362 .ui-widget-content{
363 z-index: 300002;
364 }
365 .ui-widget-overlay {
366 background-repeat: repeat;
367 }
368 </style>
369 </div>
370 <?php
371 }
372 else
373 {
374 }
375 echo '</div>';
376 }
377
378 function support_page_script()
379 {
380 ?>
381 <script type="text/javascript">
382 jQuery(document).ready(function ($) {
383 var $dialog = $('#support_dialog');
384 var $form = $('#support_form');
385 var $messageContainer = $('#support_response_id');
386 $form.submit(function (e) {
387 e.preventDefault();
388 var data = $(this).serialize();
389 $.ajax({
390 type: "POST",
391 url: 'index.php',
392 dataType: 'json',
393 data: data,
394 success: function (data, textStatus, jqXHR) {
395 if(data.success) {
396 $form.slideUp();
397 }
398 $messageContainer.html(data.message);
399 },
400 error: function (jqXHR, textStatus, errorThrown){
401 $messageContainer.html('An error occurred, please try again.');
402 }
403 });
404 });
405 $('.toplevel_page_mwp-support').click(function (e) {
406 e.preventDefault();
407 $form.show();
408 $messageContainer.empty();
409 $dialog.dialog({
410 draggable: false,
411 resizable: false,
412 modal: true,
413 width: '530px',
414 height: 'auto',
415 title: 'Contact Support',
416 close: function(){
417 $('#support_response_id').html('');
418 $( this ).dialog( "destroy" );
419 }
420 });
421 });
422 });
423 </script>
424 <?php
425 }
426
427 /**
428 * Add Support page on Top Menu
429 *
430 */
431 function add_support_page()
432 {
433 $mwp_worker_brand = get_option('mwp_worker_brand');
434 if ($mwp_worker_brand && isset($mwp_worker_brand['text_for_client']) && ($mwp_worker_brand['text_for_client'] != '')) {
435 add_menu_page(__('Support', 'wp-support'), __('Support', 'wp-support'), 'read', 'mwp-support', array(&$this, 'support_function'), '');
436 }
437 }
438
439 /**
440 * Support page handler
441 *
442 */
443 function support_function()
444 {
445 }
446
447
448 /**
449 * Remove editor from plugins&themes submenu page
450 *
451 */
452 function dissalow_text_editor(){
453 $mwp_worker_brand = get_option('mwp_worker_brand');
454 if($mwp_worker_brand && isset($mwp_worker_brand['dissalow_edit']) && ($mwp_worker_brand['dissalow_edit'] == 'checked')){
455 define('DISALLOW_FILE_EDIT',true);
456 define('DISALLOW_FILE_MODS',true);
457 }
458 }
459
460 /**
461 * Get parent blog options
462 *
463 */
464 private function get_parent_blog_option( $option_name = '' )
465 {
466 global $wpdb;
467 $option = $wpdb->get_var( $wpdb->prepare( "SELECT `option_value` FROM {$wpdb->base_prefix}options WHERE option_name = %s LIMIT 1", $option_name ) );
468 return $option;
469 }
470
471 /**
472 * Gets an instance of the Comment class
473 *
474 */
475 function get_comment_instance()
476 {
477 if (!isset($this->comment_instance)) {
478 $this->comment_instance = new MMB_Comment();
479 }
480
481 return $this->comment_instance;
482 }
483
484 /**
485 * Gets an instance of the Plugin class
486 *
487 */
488 function get_plugin_instance()
489 {
490 if (!isset($this->plugin_instance)) {
491 $this->plugin_instance = new MMB_Plugin();
492 }
493
494 return $this->plugin_instance;
495 }
496
497 /**
498 * Gets an instance of the Theme class
499 *
500 */
501 function get_theme_instance()
502 {
503 if (!isset($this->theme_instance)) {
504 $this->theme_instance = new MMB_Theme();
505 }
506
507 return $this->theme_instance;
508 }
509
510
511 /**
512 * Gets an instance of MMB_Post class
513 *
514 */
515 function get_post_instance()
516 {
517 if (!isset($this->post_instance)) {
518 $this->post_instance = new MMB_Post();
519 }
520
521 return $this->post_instance;
522 }
523
524 /**
525 * Gets an instance of Blogroll class
526 *
527 */
528 function get_blogroll_instance()
529 {
530 if (!isset($this->blogroll_instance)) {
531 $this->blogroll_instance = new MMB_Blogroll();
532 }
533
534 return $this->blogroll_instance;
535 }
536
537
538
539 /**
540 * Gets an instance of the WP class
541 *
542 */
543 function get_wp_instance()
544 {
545 if (!isset($this->wp_instance)) {
546 $this->wp_instance = new MMB_WP();
547 }
548
549 return $this->wp_instance;
550 }
551
552 /**
553 * Gets an instance of User
554 *
555 */
556 function get_user_instance()
557 {
558 if (!isset($this->user_instance)) {
559 $this->user_instance = new MMB_User();
560 }
561
562 return $this->user_instance;
563 }
564 /**
565 * Gets an instance of Security
566 *
567 */
568 function get_security_instance()
569 {
570 if (!isset($this->security_instance)) {
571 $this->security_instance = new MMB_Security();
572 }
573
574 return $this->security_instance;
575 }
576
577
578 /**
579 * Gets an instance of stats class
580 *
581 */
582 function get_stats_instance()
583 {
584 if (!isset($this->stats_instance)) {
585 $this->stats_instance = new MMB_Stats();
586 }
587 return $this->stats_instance;
588 }
589 /**
590 * Gets an instance of search class
591 *
592 */
593 function get_search_instance()
594 {
595 if (!isset($this->search_instance)) {
596 $this->search_instance = new MMB_Search();
597 }
598 //return $this->search_instance;
599 return $this->search_instance;
600 }
601 /**
602 * Gets an instance of stats class
603 *
604 */
605 function get_backup_instance()
606 {
607 if (!isset($this->backup_instance)) {
608 $this->backup_instance = new MMB_Backup();
609 }
610
611 return $this->backup_instance;
612 }
613
614 /**
615 * Gets an instance of links class
616 *
617 */
618 function get_link_instance()
619 {
620 if (!isset($this->link_instance)) {
621 $this->link_instance = new MMB_Link();
622 }
623
624 return $this->link_instance;
625 }
626
627 function get_installer_instance()
628 {
629 if (!isset($this->installer_instance)) {
630 $this->installer_instance = new MMB_Installer();
631 }
632 return $this->installer_instance;
633 }
634
635 /**
636 * Plugin install callback function
637 * Check PHP version
638 */
639 function install() {
640
641 global $wpdb, $_wp_using_ext_object_cache, $current_user;
642 $_wp_using_ext_object_cache = false;
643
644 //delete plugin options, just in case
645 if ($this->mmb_multisite != false) {
646 $network_blogs = $wpdb->get_results("select `blog_id`, `site_id` from `{$wpdb->blogs}`");
647 if(!empty($network_blogs)){
648 if( is_network_admin() ){
649 update_option('mmb_network_admin_install', 1);
650 foreach($network_blogs as $details){
651 if($details->site_id == $details->blog_id)
652 update_blog_option($details->blog_id, 'mmb_network_admin_install', 1);
653 else
654 update_blog_option($details->blog_id, 'mmb_network_admin_install', -1);
655
656 delete_blog_option($blog_id, '_worker_nossl_key');
657 delete_blog_option($blog_id, '_worker_public_key');
658 delete_blog_option($blog_id, '_action_message_id');
659 }
660 } else {
661 update_option('mmb_network_admin_install', -1);
662 delete_option('_worker_nossl_key');
663 delete_option('_worker_public_key');
664 delete_option('_action_message_id');
665 }
666 }
667 } else {
668 delete_option('_worker_nossl_key');
669 delete_option('_worker_public_key');
670 delete_option('_action_message_id');
671 }
672
673 //delete_option('mwp_backup_tasks');
674 delete_option('mwp_notifications');
675 delete_option('mwp_worker_brand');
676 delete_option('mwp_pageview_alerts');
677 }
678
679 /**
680 * Saves the (modified) options into the database
681 *
682 */
683 function save_options( $options = array() ){
684 global $_mmb_options;
685
686 $_mmb_options = array_merge( $_mmb_options, $options );
687 update_option('wrksettings', $options);
688 }
689
690 /**
691 * Deletes options for communication with master
692 *
693 */
694 function uninstall( $deactivate = false )
695 {
696 global $current_user, $wpdb, $_wp_using_ext_object_cache;
697 $_wp_using_ext_object_cache = false;
698
699 if ($this->mmb_multisite != false) {
700 $network_blogs = $wpdb->get_col("select `blog_id` from `{$wpdb->blogs}`");
701 if(!empty($network_blogs)){
702 if( is_network_admin() ){
703 if( $deactivate ) {
704 delete_option('mmb_network_admin_install');
705 foreach($network_blogs as $blog_id){
706 delete_blog_option($blog_id, 'mmb_network_admin_install');
707 delete_blog_option($blog_id, '_worker_nossl_key');
708 delete_blog_option($blog_id, '_worker_public_key');
709 delete_blog_option($blog_id, '_action_message_id');
710 delete_blog_option($blog_id, 'mwp_maintenace_mode');
711 //delete_blog_option($blog_id, 'mwp_backup_tasks');
712 delete_blog_option($blog_id, 'mwp_notifications');
713 delete_blog_option($blog_id, 'mwp_worker_brand');
714 delete_blog_option($blog_id, 'mwp_pageview_alerts');
715 delete_blog_option($blog_id, 'mwp_pageview_alerts');
716 }
717 }
718 } else {
719 if( $deactivate )
720 delete_option('mmb_network_admin_install');
721
722 delete_option('_worker_nossl_key');
723 delete_option('_worker_public_key');
724 delete_option('_action_message_id');
725 }
726 }
727 } else {
728 delete_option('_worker_nossl_key');
729 delete_option('_worker_public_key');
730 delete_option('_action_message_id');
731 }
732
733 //Delete options
734 delete_option('mwp_maintenace_mode');
735 //delete_option('mwp_backup_tasks');
736 delete_option('mwp_notifications');
737 delete_option('mwp_worker_brand');
738 delete_option('mwp_pageview_alerts');
739 wp_clear_scheduled_hook('mwp_backup_tasks');
740 wp_clear_scheduled_hook('mwp_notifications');
741 wp_clear_scheduled_hook('mwp_datasend');
742 }
743
744
745 /**
746 * Constructs a url (for ajax purpose)
747 *
748 * @param mixed $base_page
749 */
750 function construct_url($params = array(), $base_page = 'index.php')
751 {
752 $url = "$base_page?_wpnonce=" . wp_create_nonce($this->slug);
753 foreach ($params as $key => $value) {
754 $url .= "&$key=$value";
755 }
756
757 return $url;
758 }
759
760 /**
761 * Worker update
762 *
763 */
764 function update_worker_plugin($params)
765 {
766 extract($params);
767 if ($download_url) {
768 @include_once ABSPATH . 'wp-admin/includes/file.php';
769 @include_once ABSPATH . 'wp-admin/includes/misc.php';
770 @include_once ABSPATH . 'wp-admin/includes/template.php';
771 @include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
772 @include_once ABSPATH . 'wp-admin/includes/screen.php';
773
774 if (!$this->is_server_writable()) {
775 return array(
776 '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>'
777 );
778 }
779
780 ob_start();
781 @unlink(dirname(__FILE__));
782 $upgrader = new Plugin_Upgrader();
783 $result = $upgrader->run(array(
784 'package' => $download_url,
785 'destination' => WP_PLUGIN_DIR,
786 'clear_destination' => true,
787 'clear_working' => true,
788 'hook_extra' => array(
789 'plugin' => 'worker/init.php'
790 )
791 ));
792 ob_end_clean();
793 if (is_wp_error($result) || !$result) {
794 return array(
795 'error' => 'ManageWP Worker plugin could not be updated.'
796 );
797 } else {
798 return array(
799 'success' => 'ManageWP Worker plugin successfully updated.'
800 );
801 }
802 }
803 return array(
804 'error' => 'Bad download path for worker installation file.'
805 );
806 }
807
808 /**
809 * Automatically logs in when called from Master
810 *
811 */
812 function automatic_login()
813 {
814 $where = isset($_GET['mwp_goto']) ? $_GET['mwp_goto'] : false;
815 $username = isset($_GET['username']) ? $_GET['username'] : '';
816 $auto_login = isset($_GET['auto_login']) ? $_GET['auto_login'] : 0;
817
818 if( !function_exists('is_user_logged_in') )
819 include_once( ABSPATH.'wp-includes/pluggable.php' );
820
821 if (( $auto_login && strlen(trim($username)) && !is_user_logged_in() ) || (isset($this->mmb_multisite) && $this->mmb_multisite )) {
822 $signature = base64_decode($_GET['signature']);
823 $message_id = trim($_GET['message_id']);
824
825 $auth = $this->authenticate_message($where . $message_id, $signature, $message_id);
826 if ($auth === true) {
827
828 if (!headers_sent())
829 header('P3P: CP="CAO PSA OUR"');
830
831 if(!defined('MMB_USER_LOGIN'))
832 define('MMB_USER_LOGIN', true);
833
834 $siteurl = function_exists('get_site_option') ? get_site_option( 'siteurl' ) : get_option('siteurl');
835 $user = $this->mmb_get_user_info($username);
836 wp_set_current_user($user->ID);
837
838 if(!defined('COOKIEHASH') || (isset($this->mmb_multisite) && $this->mmb_multisite) )
839 wp_cookie_constants();
840
841 wp_set_auth_cookie($user->ID);
842 @mmb_worker_header();
843
844 if((isset($this->mmb_multisite) && $this->mmb_multisite ) || isset($_REQUEST['mwpredirect'])){
845 if(function_exists('wp_safe_redirect') && function_exists('admin_url')){
846 wp_safe_redirect(admin_url($where));
847 exit();
848 }
849 }
850 } else {
851 wp_die($auth['error']);
852 }
853 } elseif( is_user_logged_in() ) {
854 @mmb_worker_header();
855 if(isset($_REQUEST['mwpredirect'])){
856 if(function_exists('wp_safe_redirect') && function_exists('admin_url')){
857 wp_safe_redirect(admin_url($where));
858 exit();
859 }
860 }
861 }
862 }
863
864 function mmb_set_auth_cookie( $auth_cookie ){
865 if(!defined('MMB_USER_LOGIN'))
866 return false;
867
868 if( !defined('COOKIEHASH') )
869 wp_cookie_constants();
870
871 $_COOKIE['wordpress_'.COOKIEHASH] = $auth_cookie;
872
873 }
874 function mmb_set_logged_in_cookie( $logged_in_cookie ){
875 if(!defined('MMB_USER_LOGIN'))
876 return false;
877
878 if( !defined('COOKIEHASH') )
879 wp_cookie_constants();
880
881 $_COOKIE['wordpress_logged_in_'.COOKIEHASH] = $logged_in_cookie;
882 }
883
884 function admin_actions(){
885 add_filter('all_plugins', array($this, 'worker_replace'));
886 }
887
888 function worker_replace($all_plugins){
889 $replace = get_option("mwp_worker_brand");
890 if(is_array($replace)){
891 if($replace['name'] || $replace['desc'] || $replace['author'] || $replace['author_url']){
892 $all_plugins['worker/init.php']['Name'] = $replace['name'];
893 $all_plugins['worker/init.php']['Title'] = $replace['name'];
894 $all_plugins['worker/init.php']['Description'] = $replace['desc'];
895 $all_plugins['worker/init.php']['AuthorURI'] = $replace['author_url'];
896 $all_plugins['worker/init.php']['Author'] = $replace['author'];
897 $all_plugins['worker/init.php']['AuthorName'] = $replace['author'];
898 $all_plugins['worker/init.php']['PluginURI'] = '';
899 }
900
901 if($replace['hide']){
902 if (!function_exists('get_plugins')) {
903 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
904 }
905 $activated_plugins = get_option('active_plugins');
906 if (!$activated_plugins)
907 $activated_plugins = array();
908 if(in_array('worker/init.php',$activated_plugins))
909 unset($all_plugins['worker/init.php']);
910 }
911 }
912
913
914 return $all_plugins;
915 }
916
917 }
918 ?>
919