PluginProbe
ManageWP Worker / 3.9.11
ManageWP Worker v3.9.11
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.11, at core.class.php

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