PluginProbe
ManageWP Worker / 3.9.27
ManageWP Worker v3.9.27
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.27, at core.class.php

872 lines 29.6 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 'maintenance' => 'mmb_maintenance_mode',
136 'get_dbname' => 'mmb_get_dbname',
137 );
138
139 $mwp_worker_brand = get_option("mwp_worker_brand");
140 //!$mwp_worker_brand['hide_managed_remotely']
141 if ($mwp_worker_brand == false || (is_array($mwp_worker_brand) && !array_key_exists('hide_managed_remotely', $mwp_worker_brand))) {
142 add_action('rightnow_end', array( &$this, 'add_right_now_info' ));
143 }
144 if ($mwp_worker_brand != false && is_array($mwp_worker_brand) && isset($mwp_worker_brand['text_for_client']) && ($mwp_worker_brand['email_or_link'] != 0)) {
145 add_action('admin_init', array($this, 'enqueue_scripts'));
146 add_action('admin_init', array($this, 'enqueue_styles'));
147 add_action('admin_menu', array($this, 'add_support_page'));
148 add_action('admin_head', array($this, 'support_page_script'));
149 add_action('admin_footer', array($this, 'support_page_dialog'));
150 add_action('admin_init', array($this, 'send_email_to_admin'));
151 }
152 add_action( 'plugins_loaded', array( &$this, 'dissalow_text_editor' ) );
153
154 add_action('admin_init', array(&$this,'admin_actions'));
155 add_action('init', array( &$this, 'mmb_remote_action'), 9999);
156 add_action('setup_theme', 'mmb_run_backup_action', 1);
157 add_action('plugins_loaded', 'mmb_authenticate', 1);
158 add_action('setup_theme', 'mmb_parse_request');
159 add_action('set_auth_cookie', array( &$this, 'mmb_set_auth_cookie'));
160 add_action('set_logged_in_cookie', array( &$this, 'mmb_set_logged_in_cookie'));
161 }
162
163 function mmb_remote_action(){
164 if($this->action_call != null){
165 $params = isset($this->action_params) && $this->action_params != null ? $this->action_params : array();
166 call_user_func($this->action_call, $params);
167 }
168 }
169
170 function register_action_params( $action = false, $params = array() ){
171
172 if(isset($this->mmb_pre_init_actions[$action]) && function_exists($this->mmb_pre_init_actions[$action])){
173 call_user_func($this->mmb_pre_init_actions[$action], $params);
174 }
175
176 if(isset($this->mmb_init_actions[$action]) && function_exists($this->mmb_init_actions[$action])){
177 $this->action_call = $this->mmb_init_actions[$action];
178 $this->action_params = $params;
179
180 if( isset($this->mmb_pre_init_filters[$action]) && !empty($this->mmb_pre_init_filters[$action])){
181 global $mmb_filters;
182
183 foreach($this->mmb_pre_init_filters[$action] as $_name => $_functions){
184 if(!empty($_functions)){
185 $data = array();
186
187 foreach($_functions as $_k => $_callback){
188 if(is_array($_callback) && method_exists($_callback[0], $_callback[1]) ){
189 $data = call_user_func( $_callback, $params );
190 } elseif (is_string($_callback) && function_exists( $_callback )){
191 $data = call_user_func( $_callback, $params );
192 }
193 $mmb_filters[$_name] = isset($mmb_filters[$_name]) && !empty($mmb_filters[$_name]) ? array_merge($mmb_filters[$_name], $data) : $data;
194 add_filter( $_name, create_function( '$a' , 'global $mmb_filters; return array_merge($a, $mmb_filters["'.$_name.'"]);') );
195 }
196 }
197
198 }
199 }
200 return true;
201 }
202 return false;
203 }
204
205 /**
206 * Add notice to network admin dashboard for security reasons
207 *
208 */
209 function network_admin_notice()
210 {
211 echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">Attention !</p><p>
212 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>.
213 </p></div>';
214 }
215
216
217 /**
218 * Add notice to admin dashboard for security reasons
219 *
220 */
221 function admin_notice()
222 {
223 echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">Attention !</p><p>
224 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>.
225 </p></div>';
226 }
227
228 /**
229 * Add an item into the Right Now Dashboard widget
230 * to inform that the blog can be managed remotely
231 *
232 */
233 function add_right_now_info()
234 {
235 $mwp_worker_brand = get_option('mwp_worker_brand');
236 echo '<div class="mmb-slave-info">';
237 if($mwp_worker_brand && isset($mwp_worker_brand['remotely_managed_text'])){
238 /*$url = isset($mwp_worker_brand['author_url']) ? $mwp_worker_brand['author_url'] : null;
239 if($url) {
240 $scheme = parse_url($mwp_worker_brand['author_url'], PHP_URL_SCHEME);
241 if(empty($scheme)) {
242 $url = 'http://' . $url;
243 }
244 }
245 if($url) {
246 $managedBy = '<a target="_blank" href="'.htmlspecialchars($url).'">'
247 .htmlspecialchars($mwp_worker_brand['author'])
248 .'</a>';
249 } else {
250 $managedBy = htmlspecialchars($mwp_worker_brand['author']);
251 }
252 echo sprintf('<p>This site is managed by %s.</p>', $managedBy);*/
253 echo '<p>'.$mwp_worker_brand['remotely_managed_text'].'</p>';
254 }else{
255 echo '<p>This site can be managed remotely.</p>';
256 }
257 echo '</div>';
258 }
259
260 function enqueue_scripts()
261 {
262 wp_enqueue_script('jquery');
263 wp_enqueue_script('jquery-ui-core');
264 wp_enqueue_script('jquery-ui-dialog');
265 }
266
267 function enqueue_styles()
268 {
269 wp_enqueue_style('wp-jquery-ui');
270 wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/smoothness/jquery-ui.css');
271 }
272
273 function send_email_to_admin(){
274 if(!isset($_POST['support_mwp_message'])) {
275 return;
276 }
277 global $current_user;
278 if (empty($_POST['support_mwp_message'])) {
279 $this->mwp_send_ajax_response(false, "Please enter a message.");
280 }
281 $mwp_worker_brand = get_option('mwp_worker_brand');
282 if(empty($mwp_worker_brand['admin_email'])) {
283 $this->mwp_send_ajax_response(false, "Unable to send email to admin.");
284 }
285 $subject = 'New ticket for site '.get_bloginfo('url');
286 $message = <<<EOF
287 Hi,
288 User with a username {$current_user->user_login} has a new question:
289 {$_POST['support_mwp_message']}
290 EOF;
291 $has_been_sent = wp_mail($mwp_worker_brand['admin_email'], $subject, $message);
292 if(!$has_been_sent) {
293 $this->mwp_send_ajax_response(false, "Unable to send email. Please try again.");
294 }
295 $this->mwp_send_ajax_response(true, "Message successfully sent.");
296 }
297
298 function mwp_send_ajax_response($success = true, $message = '')
299 {
300 $response = json_encode(array(
301 'success' => $success,
302 'message' => $message,
303 ));
304 print $response;
305 exit;
306 }
307
308 function support_page_dialog()
309 {
310 $mwp_worker_brand = get_option('mwp_worker_brand');
311 if($mwp_worker_brand && isset($mwp_worker_brand['text_for_client']) && ($mwp_worker_brand['text_for_client'] != ''))
312 {
313 $notification_text = $mwp_worker_brand['text_for_client'];
314 }
315 ?>
316 <div id="support_dialog" style="display: none;">
317 <div>
318 <p><?php echo $notification_text; ?></p>
319 </div>
320 <div style="margin: 19px 0 0;">
321 <?php
322 if($mwp_worker_brand['email_or_link'] == 1)
323 {
324 ?>
325 <form method="post" id="support_form">
326 <textarea name="support_mwp_message" id="support_message" style="width:500px;height:150px;display:block;margin-left:auto;margin-right:auto;"></textarea>
327 <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>
328 </form>
329 <div id="support_response_id" style="margin-top: 14px"></div>
330 <style>
331 .ui-widget-overlay {
332 background-repeat: repeat;
333 }
334 </style>
335 </div>
336 <?php
337 }
338 else
339 {
340 }
341 echo '</div>';
342 }
343
344 function support_page_script()
345 {
346 ?>
347 <script type="text/javascript">
348 jQuery(document).ready(function ($) {
349 var $dialog = $('#support_dialog');
350 var $form = $('#support_form');
351 var $messageContainer = $('#support_response_id');
352 $form.submit(function (e) {
353 e.preventDefault();
354 var data = $(this).serialize();
355 $.ajax({
356 type: "POST",
357 url: 'index.php',
358 dataType: 'json',
359 data: data,
360 success: function (data, textStatus, jqXHR) {
361 if(data.success) {
362 $form.slideUp();
363 }
364 $messageContainer.html(data.message);
365 },
366 error: function (jqXHR, textStatus, errorThrown){
367 $messageContainer.html('An error occurred, please try again.');
368 }
369 });
370 });
371 $('.toplevel_page_mwp-support').click(function (e) {
372 e.preventDefault();
373 $form.show();
374 $messageContainer.empty();
375 $dialog.dialog({
376 draggable: false,
377 resizable: false,
378 modal: true,
379 width: '530px',
380 height: 'auto',
381 title: 'Contact Support',
382 close: function(){
383 $('#support_response_id').html('');
384 $( this ).dialog( "destroy" );
385 }
386 });
387 });
388 });
389 </script>
390 <?php
391 }
392
393 /**
394 * Add Support page on Top Menu
395 *
396 */
397 function add_support_page()
398 {
399 $mwp_worker_brand = get_option('mwp_worker_brand');
400 if ($mwp_worker_brand && isset($mwp_worker_brand['text_for_client']) && ($mwp_worker_brand['text_for_client'] != '')) {
401 add_menu_page(__('Support', 'wp-support'), __('Support', 'wp-support'), 'read', 'mwp-support', array(&$this, 'support_function'), '');
402 }
403 }
404
405 /**
406 * Support page handler
407 *
408 */
409 function support_function()
410 {
411 }
412
413
414 /**
415 * Remove editor from plugins&themes submenu page
416 *
417 */
418 function dissalow_text_editor(){
419 $mwp_worker_brand = get_option('mwp_worker_brand');
420 if($mwp_worker_brand && isset($mwp_worker_brand['dissalow_edit']) && ($mwp_worker_brand['dissalow_edit'] == 'checked')){
421 define('DISALLOW_FILE_EDIT',true);
422 define('DISALLOW_FILE_MODS',true);
423 }
424 }
425
426 /**
427 * Get parent blog options
428 *
429 */
430 private function get_parent_blog_option( $option_name = '' )
431 {
432 global $wpdb;
433 $option = $wpdb->get_var( $wpdb->prepare( "SELECT `option_value` FROM {$wpdb->base_prefix}options WHERE option_name = %s LIMIT 1", $option_name ) );
434 return $option;
435 }
436
437 /**
438 * Gets an instance of the Comment class
439 *
440 */
441 function get_comment_instance()
442 {
443 if (!isset($this->comment_instance)) {
444 $this->comment_instance = new MMB_Comment();
445 }
446
447 return $this->comment_instance;
448 }
449
450 /**
451 * Gets an instance of the Plugin class
452 *
453 */
454 function get_plugin_instance()
455 {
456 if (!isset($this->plugin_instance)) {
457 $this->plugin_instance = new MMB_Plugin();
458 }
459
460 return $this->plugin_instance;
461 }
462
463 /**
464 * Gets an instance of the Theme class
465 *
466 */
467 function get_theme_instance()
468 {
469 if (!isset($this->theme_instance)) {
470 $this->theme_instance = new MMB_Theme();
471 }
472
473 return $this->theme_instance;
474 }
475
476
477 /**
478 * Gets an instance of MMB_Post class
479 *
480 */
481 function get_post_instance()
482 {
483 if (!isset($this->post_instance)) {
484 $this->post_instance = new MMB_Post();
485 }
486
487 return $this->post_instance;
488 }
489
490 /**
491 * Gets an instance of Blogroll class
492 *
493 */
494 function get_blogroll_instance()
495 {
496 if (!isset($this->blogroll_instance)) {
497 $this->blogroll_instance = new MMB_Blogroll();
498 }
499
500 return $this->blogroll_instance;
501 }
502
503
504
505 /**
506 * Gets an instance of the WP class
507 *
508 */
509 function get_wp_instance()
510 {
511 if (!isset($this->wp_instance)) {
512 $this->wp_instance = new MMB_WP();
513 }
514
515 return $this->wp_instance;
516 }
517
518 /**
519 * Gets an instance of User
520 *
521 */
522 function get_user_instance()
523 {
524 if (!isset($this->user_instance)) {
525 $this->user_instance = new MMB_User();
526 }
527
528 return $this->user_instance;
529 }
530
531 /**
532 * Gets an instance of stats class
533 *
534 */
535 function get_stats_instance()
536 {
537 if (!isset($this->stats_instance)) {
538 $this->stats_instance = new MMB_Stats();
539 }
540 return $this->stats_instance;
541 }
542 /**
543 * Gets an instance of search class
544 *
545 */
546 function get_search_instance()
547 {
548 if (!isset($this->search_instance)) {
549 $this->search_instance = new MMB_Search();
550 }
551 //return $this->search_instance;
552 return $this->search_instance;
553 }
554 /**
555 * Gets an instance of stats class
556 *
557 */
558 function get_backup_instance()
559 {
560 if (!isset($this->backup_instance)) {
561 $this->backup_instance = new MMB_Backup();
562 }
563
564 return $this->backup_instance;
565 }
566
567 /**
568 * Gets an instance of links class
569 *
570 */
571 function get_link_instance()
572 {
573 if (!isset($this->link_instance)) {
574 $this->link_instance = new MMB_Link();
575 }
576
577 return $this->link_instance;
578 }
579
580 function get_installer_instance()
581 {
582 if (!isset($this->installer_instance)) {
583 $this->installer_instance = new MMB_Installer();
584 }
585 return $this->installer_instance;
586 }
587
588 /**
589 * Plugin install callback function
590 * Check PHP version
591 */
592 function install() {
593
594 global $wpdb, $_wp_using_ext_object_cache, $current_user;
595 $_wp_using_ext_object_cache = false;
596
597 //delete plugin options, just in case
598 if ($this->mmb_multisite != false) {
599 $network_blogs = $wpdb->get_results("select `blog_id`, `site_id` from `{$wpdb->blogs}`");
600 if(!empty($network_blogs)){
601 if( is_network_admin() ){
602 update_option('mmb_network_admin_install', 1);
603 foreach($network_blogs as $details){
604 if($details->site_id == $details->blog_id)
605 update_blog_option($details->blog_id, 'mmb_network_admin_install', 1);
606 else
607 update_blog_option($details->blog_id, 'mmb_network_admin_install', -1);
608
609 delete_blog_option($blog_id, '_worker_nossl_key');
610 delete_blog_option($blog_id, '_worker_public_key');
611 delete_blog_option($blog_id, '_action_message_id');
612 }
613 } else {
614 update_option('mmb_network_admin_install', -1);
615 delete_option('_worker_nossl_key');
616 delete_option('_worker_public_key');
617 delete_option('_action_message_id');
618 }
619 }
620 } else {
621 delete_option('_worker_nossl_key');
622 delete_option('_worker_public_key');
623 delete_option('_action_message_id');
624 }
625
626 //delete_option('mwp_backup_tasks');
627 delete_option('mwp_notifications');
628 delete_option('mwp_worker_brand');
629 delete_option('mwp_pageview_alerts');
630 }
631
632 /**
633 * Saves the (modified) options into the database
634 *
635 */
636 function save_options( $options = array() ){
637 global $_mmb_options;
638
639 $_mmb_options = array_merge( $_mmb_options, $options );
640 update_option('wrksettings', $options);
641 }
642
643 /**
644 * Deletes options for communication with master
645 *
646 */
647 function uninstall( $deactivate = false )
648 {
649 global $current_user, $wpdb, $_wp_using_ext_object_cache;
650 $_wp_using_ext_object_cache = false;
651
652 if ($this->mmb_multisite != false) {
653 $network_blogs = $wpdb->get_col("select `blog_id` from `{$wpdb->blogs}`");
654 if(!empty($network_blogs)){
655 if( is_network_admin() ){
656 if( $deactivate ) {
657 delete_option('mmb_network_admin_install');
658 foreach($network_blogs as $blog_id){
659 delete_blog_option($blog_id, 'mmb_network_admin_install');
660 delete_blog_option($blog_id, '_worker_nossl_key');
661 delete_blog_option($blog_id, '_worker_public_key');
662 delete_blog_option($blog_id, '_action_message_id');
663 delete_blog_option($blog_id, 'mwp_maintenace_mode');
664 //delete_blog_option($blog_id, 'mwp_backup_tasks');
665 delete_blog_option($blog_id, 'mwp_notifications');
666 delete_blog_option($blog_id, 'mwp_worker_brand');
667 delete_blog_option($blog_id, 'mwp_pageview_alerts');
668 delete_blog_option($blog_id, 'mwp_pageview_alerts');
669 }
670 }
671 } else {
672 if( $deactivate )
673 delete_option('mmb_network_admin_install');
674
675 delete_option('_worker_nossl_key');
676 delete_option('_worker_public_key');
677 delete_option('_action_message_id');
678 }
679 }
680 } else {
681 delete_option('_worker_nossl_key');
682 delete_option('_worker_public_key');
683 delete_option('_action_message_id');
684 }
685
686 //Delete options
687 delete_option('mwp_maintenace_mode');
688 //delete_option('mwp_backup_tasks');
689 delete_option('mwp_notifications');
690 delete_option('mwp_worker_brand');
691 delete_option('mwp_pageview_alerts');
692 wp_clear_scheduled_hook('mwp_backup_tasks');
693 wp_clear_scheduled_hook('mwp_notifications');
694 wp_clear_scheduled_hook('mwp_datasend');
695 }
696
697
698 /**
699 * Constructs a url (for ajax purpose)
700 *
701 * @param mixed $base_page
702 */
703 function construct_url($params = array(), $base_page = 'index.php')
704 {
705 $url = "$base_page?_wpnonce=" . wp_create_nonce($this->slug);
706 foreach ($params as $key => $value) {
707 $url .= "&$key=$value";
708 }
709
710 return $url;
711 }
712
713 /**
714 * Worker update
715 *
716 */
717 function update_worker_plugin($params)
718 {
719 extract($params);
720 if ($download_url) {
721 @include_once ABSPATH . 'wp-admin/includes/file.php';
722 @include_once ABSPATH . 'wp-admin/includes/misc.php';
723 @include_once ABSPATH . 'wp-admin/includes/template.php';
724 @include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
725 @include_once ABSPATH . 'wp-admin/includes/screen.php';
726
727 if (!$this->is_server_writable()) {
728 return array(
729 '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>'
730 );
731 }
732
733 ob_start();
734 @unlink(dirname(__FILE__));
735 $upgrader = new Plugin_Upgrader();
736 $result = $upgrader->run(array(
737 'package' => $download_url,
738 'destination' => WP_PLUGIN_DIR,
739 'clear_destination' => true,
740 'clear_working' => true,
741 'hook_extra' => array(
742 'plugin' => 'worker/init.php'
743 )
744 ));
745 ob_end_clean();
746 if (is_wp_error($result) || !$result) {
747 return array(
748 'error' => 'ManageWP Worker plugin could not be updated.'
749 );
750 } else {
751 return array(
752 'success' => 'ManageWP Worker plugin successfully updated.'
753 );
754 }
755 }
756 return array(
757 'error' => 'Bad download path for worker installation file.'
758 );
759 }
760
761 /**
762 * Automatically logs in when called from Master
763 *
764 */
765 function automatic_login()
766 {
767 $where = isset($_GET['mwp_goto']) ? $_GET['mwp_goto'] : false;
768 $username = isset($_GET['username']) ? $_GET['username'] : '';
769 $auto_login = isset($_GET['auto_login']) ? $_GET['auto_login'] : 0;
770
771 if( !function_exists('is_user_logged_in') )
772 include_once( ABSPATH.'wp-includes/pluggable.php' );
773
774 if (( $auto_login && strlen(trim($username)) && !is_user_logged_in() ) || (isset($this->mmb_multisite) && $this->mmb_multisite )) {
775 $signature = base64_decode($_GET['signature']);
776 $message_id = trim($_GET['message_id']);
777
778 $auth = $this->authenticate_message($where . $message_id, $signature, $message_id);
779 if ($auth === true) {
780
781 if (!headers_sent())
782 header('P3P: CP="CAO PSA OUR"');
783
784 if(!defined('MMB_USER_LOGIN'))
785 define('MMB_USER_LOGIN', true);
786
787 $siteurl = function_exists('get_site_option') ? get_site_option( 'siteurl' ) : get_option('siteurl');
788 $user = $this->mmb_get_user_info($username);
789 wp_set_current_user($user->ID);
790
791 if(!defined('COOKIEHASH') || (isset($this->mmb_multisite) && $this->mmb_multisite) )
792 wp_cookie_constants();
793
794 wp_set_auth_cookie($user->ID);
795 @mmb_worker_header();
796
797 if((isset($this->mmb_multisite) && $this->mmb_multisite ) || isset($_REQUEST['mwpredirect'])){
798 if(function_exists('wp_safe_redirect') && function_exists('admin_url')){
799 wp_safe_redirect(admin_url($where));
800 exit();
801 }
802 }
803 } else {
804 wp_die($auth['error']);
805 }
806 } elseif( is_user_logged_in() ) {
807 @mmb_worker_header();
808 if(isset($_REQUEST['mwpredirect'])){
809 if(function_exists('wp_safe_redirect') && function_exists('admin_url')){
810 wp_safe_redirect(admin_url($where));
811 exit();
812 }
813 }
814 }
815 }
816
817 function mmb_set_auth_cookie( $auth_cookie ){
818 if(!defined('MMB_USER_LOGIN'))
819 return false;
820
821 if( !defined('COOKIEHASH') )
822 wp_cookie_constants();
823
824 $_COOKIE['wordpress_'.COOKIEHASH] = $auth_cookie;
825
826 }
827 function mmb_set_logged_in_cookie( $logged_in_cookie ){
828 if(!defined('MMB_USER_LOGIN'))
829 return false;
830
831 if( !defined('COOKIEHASH') )
832 wp_cookie_constants();
833
834 $_COOKIE['wordpress_logged_in_'.COOKIEHASH] = $logged_in_cookie;
835 }
836
837 function admin_actions(){
838 add_filter('all_plugins', array($this, 'worker_replace'));
839 }
840
841 function worker_replace($all_plugins){
842 $replace = get_option("mwp_worker_brand");
843 if(is_array($replace)){
844 if($replace['name'] || $replace['desc'] || $replace['author'] || $replace['author_url']){
845 $all_plugins['worker/init.php']['Name'] = $replace['name'];
846 $all_plugins['worker/init.php']['Title'] = $replace['name'];
847 $all_plugins['worker/init.php']['Description'] = $replace['desc'];
848 $all_plugins['worker/init.php']['AuthorURI'] = $replace['author_url'];
849 $all_plugins['worker/init.php']['Author'] = $replace['author'];
850 $all_plugins['worker/init.php']['AuthorName'] = $replace['author'];
851 $all_plugins['worker/init.php']['PluginURI'] = '';
852 }
853
854 if($replace['hide']){
855 if (!function_exists('get_plugins')) {
856 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
857 }
858 $activated_plugins = get_option('active_plugins');
859 if (!$activated_plugins)
860 $activated_plugins = array();
861 if(in_array('worker/init.php',$activated_plugins))
862 unset($all_plugins['worker/init.php']);
863 }
864 }
865
866
867 return $all_plugins;
868 }
869
870 }
871 ?>
872