PluginProbe
ManageWP Worker / 3.9.26
ManageWP Worker v3.9.26
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 / init.php

init.php in ManageWP Worker 3.9.26, at init.php

1,309 lines 38.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: ManageWP - Worker
4 Plugin URI: http://managewp.com/
5 Description: Manage Multiple WordPress sites from one dashboard. Visit <a href="https://managewp.com">ManageWP.com</a> to sign up.
6 Author: ManageWP
7 Version: 3.9.26
8 Author URI: http://managewp.com
9 */
10
11 /*************************************************************
12 *
13 * init.php
14 *
15 * Initialize the communication with master
16 *
17 *
18 * Copyright (c) 2011 Prelovac Media
19 * www.prelovac.com
20 **************************************************************/
21 if(basename($_SERVER['SCRIPT_FILENAME']) == "init.php"):
22 exit;
23 endif;
24 if(!defined('MMB_WORKER_VERSION'))
25 define('MMB_WORKER_VERSION', '3.9.26');
26
27 if ( !defined('MMB_XFRAME_COOKIE')){
28 $siteurl = function_exists( 'get_site_option' ) ? get_site_option( 'siteurl' ) : get_option( 'siteurl' );
29 define('MMB_XFRAME_COOKIE', $xframe = 'wordpress_'.md5($siteurl).'_xframe');
30 }
31 global $wpdb, $mmb_plugin_dir, $mmb_plugin_url, $wp_version, $mmb_filters, $_mmb_item_filter;
32 if (version_compare(PHP_VERSION, '5.0.0', '<')) // min version 5 supported
33 exit("<p>ManageWP Worker plugin requires PHP 5 or higher.</p>");
34
35
36 $mmb_wp_version = $wp_version;
37 $mmb_plugin_dir = WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__));
38 $mmb_plugin_url = WP_PLUGIN_URL . '/' . basename(dirname(__FILE__));
39
40 require_once("$mmb_plugin_dir/helper.class.php");
41 require_once("$mmb_plugin_dir/core.class.php");
42 require_once("$mmb_plugin_dir/post.class.php");
43 require_once("$mmb_plugin_dir/comment.class.php");
44 require_once("$mmb_plugin_dir/stats.class.php");
45 require_once("$mmb_plugin_dir/backup.class.php");
46 require_once("$mmb_plugin_dir/installer.class.php");
47 require_once("$mmb_plugin_dir/link.class.php");
48 require_once("$mmb_plugin_dir/user.class.php");
49 require_once("$mmb_plugin_dir/api.php");
50
51 require_once("$mmb_plugin_dir/plugins/search/search.php");
52 require_once("$mmb_plugin_dir/plugins/cleanup/cleanup.php");
53
54 require_once("$mmb_plugin_dir/widget.class.php");
55
56 if(!function_exists( 'json_decode' ) && !function_exists( 'json_encode' )){
57 global $mmb_plugin_dir;
58 require_once ($mmb_plugin_dir.'/lib/json/JSON.php' );
59
60 function json_decode($json_object, $assoc = false) {
61 $json = $assoc == true ? new Services_JSON(SERVICES_JSON_LOOSE_TYPE) : new Services_JSON();
62 return $json->decode($json_object);
63 }
64
65 function json_encode($object_data) {
66 $json = new Services_JSON();
67 return $json->encode($object_data);
68 }
69 }
70
71 if( !function_exists ( 'mmb_parse_data' )) {
72 function mmb_parse_data( $data = array() ){
73 if( empty($data) )
74 return $data;
75
76 $data = (array) $data;
77 if( isset($data['params']) )
78 $data['params'] = mmb_filter_params( $data['params'] );
79
80 $postkeys = array('action', 'params', 'id', 'signature', 'setting' );
81
82 if( !empty($data) ){
83 foreach($data as $key => $items){
84 if( !in_array($key, $postkeys) )
85 unset($data[$key]);
86 }
87 }
88 return $data;
89 }
90 }
91
92 if( !function_exists ( 'mmb_filter_params' )) {
93 function mmb_filter_params( $array = array() ){
94
95 $filter = array( 'current_user', 'wpdb' );
96 $return = array();
97 foreach ($array as $key => $val) {
98 if( !is_int($key) && in_array($key, $filter) )
99 continue;
100
101 if( is_array( $val ) ) {
102 $return[$key] = mmb_filter_params( $val );
103 } else {
104 $return[$key] = $val;
105 }
106 }
107
108 return $return;
109 }
110 }
111 if( !function_exists ( 'hex2bin' )) {
112 function hex2bin($h){
113 if (!is_string($h)) return null;
114 $r='';
115 for ($a=0; $a<strlen($h); $a+=2) { $r.=chr(hexdec($h{$a}.$h{($a+1)})); }
116 return $r;
117 }
118 }
119 if( !function_exists('mmb_authenticate')) {
120 function mmb_authenticate() {
121 global $_mwp_data, $_mwp_auth, $mmb_core;
122 if (!isset($HTTP_RAW_POST_DATA)) {
123 $HTTP_RAW_POST_DATA = file_get_contents('php://input');
124 }
125 if(substr($HTTP_RAW_POST_DATA, 0, 7) == "action="){
126 $HTTP_RAW_POST_DATA = str_replace("action=", "", $HTTP_RAW_POST_DATA);
127 }
128 $_mwp_data = base64_decode($HTTP_RAW_POST_DATA);
129 if (!$_mwp_data){
130 return;
131 }
132 $_mwp_data = mmb_parse_data( @unserialize($_mwp_data) );
133
134 if(empty($_mwp_data['action'])) {
135 return;
136 }
137
138 if (!$mmb_core->check_if_user_exists($_mwp_data['params']['username'])) {
139 mmb_response('Username <b>' . $_mwp_data['params']['username'] . '</b> does not have administrator capabilities. Please check the Admin username.', false);
140 }
141
142 if($_mwp_data['action'] === 'add_site') {
143 $_mwp_auth = true;
144 } else {
145 $_mwp_auth = $mmb_core->authenticate_message($_mwp_data['action'] . $_mwp_data['id'], $_mwp_data['signature'], $_mwp_data['id']);
146 }
147
148 if($_mwp_auth !== true) {
149 mmb_response($_mwp_auth['error'], false);
150 }
151
152 if(isset($_mwp_data['params']['username']) && !is_user_logged_in()){
153 $user = function_exists('get_user_by') ? get_user_by('login', $_mwp_data['params']['username']) : get_userdatabylogin( $_mwp_data['params']['username'] );
154 wp_set_current_user($user->ID);
155 }
156 }
157 }
158
159 if( !function_exists ( 'mmb_parse_request' )) {
160 function mmb_parse_request(){
161 global $mmb_core, $wp_db_version, $wpmu_version, $_wp_using_ext_object_cache, $_mwp_data, $_mwp_auth;
162 if(empty($_mwp_auth)) {
163 MMB_Stats::set_hit_count();
164 return;
165 }
166 ob_start();
167 $_wp_using_ext_object_cache = false;
168 @set_time_limit(600);
169
170 if ($_mwp_data['action'] === 'add_site') {
171 mmb_add_site($_mwp_data['params']);
172 mmb_response('You should never see this.', false);
173 }
174
175 /* in case database upgrade required, do database backup and perform upgrade ( wordpress wp_upgrade() function ) */
176 if( strlen(trim($wp_db_version)) && !defined('ACX_PLUGIN_DIR') ){
177 if ( get_option('db_version') != $wp_db_version ) {
178 /* in multisite network, please update database manualy */
179 if (empty($wpmu_version) || (function_exists('is_multisite') && !is_multisite())){
180 if( ! function_exists('wp_upgrade'))
181 include_once(ABSPATH.'wp-admin/includes/upgrade.php');
182
183 ob_clean();
184 @wp_upgrade();
185 @do_action('after_db_upgrade');
186 ob_end_clean();
187 }
188 }
189 }
190
191 if(isset($_mwp_data['params']['secure'])){
192 if($decrypted = $mmb_core->_secure_data($_mwp_data['params']['secure'])){
193 $decrypted = maybe_unserialize($decrypted);
194 if(is_array($decrypted)){
195 foreach($decrypted as $key => $val){
196 if(!is_numeric($key))
197 $_mwp_data['params'][$key] = $val;
198 }
199 unset($_mwp_data['params']['secure']);
200 } else $_mwp_data['params']['secure'] = $decrypted;
201 }
202 }
203
204 if( isset($_mwp_data['setting']) ){
205 $mmb_core->save_options( $_mwp_data['setting'] );
206 }
207
208 if( !$mmb_core->register_action_params( $_mwp_data['action'], $_mwp_data['params'] ) ){
209 global $_mmb_plugin_actions;
210 $_mmb_plugin_actions[$_mwp_data['action']] = $_mwp_data['params'];
211 }
212 ob_end_clean();
213 }
214 }
215 /* Main response function */
216 if( !function_exists ( 'mmb_response' )) {
217
218 function mmb_response($response = false, $success = true)
219 {
220 $return = array();
221
222 if ((is_array($response) && empty($response)) || (!is_array($response) && strlen($response) == 0))
223 $return['error'] = 'Empty response.';
224 else if ($success)
225 $return['success'] = $response;
226 else
227 $return['error'] = $response;
228
229 if( !headers_sent() ){
230 header('HTTP/1.0 200 OK');
231 header('Content-Type: text/plain');
232 }
233 exit("<MWPHEADER>" . base64_encode(serialize($return))."<ENDMWPHEADER>");
234 }
235 }
236
237
238
239 if( !function_exists ( 'mmb_add_site' )) {
240 function mmb_add_site($params) {
241 global $mmb_core;
242 $num = extract($params);
243
244 if ($num) {
245 if (!get_option('_action_message_id') && !get_option('_worker_public_key')) {
246 $public_key = base64_decode($public_key);
247
248 if (function_exists('openssl_verify')) {
249 $verify = openssl_verify($action . $id, base64_decode($signature), $public_key);
250 if ($verify == 1) {
251 $mmb_core->set_master_public_key($public_key);
252 $mmb_core->set_worker_message_id($id);
253
254
255
256 $mmb_core->get_stats_instance();
257 if(isset($notifications) && is_array($notifications) && !empty($notifications)){
258 $mmb_core->stats_instance->set_notifications($notifications);
259 }
260 if(isset($brand) && is_array($brand) && !empty($brand)){
261 update_option('mwp_worker_brand', $brand);
262 }
263
264 if( isset( $add_settigns ) && is_array($add_settigns) && !empty( $add_settigns ) )
265 apply_filters( 'mwp_website_add', $add_settigns );
266
267 mmb_response($mmb_core->stats_instance->get_initial_stats(), true);
268 } else if ($verify == 0) {
269
270 //mmb_response('Site could not be added. OpenSSL verification error: "'.openssl_error_string().'". Contact your hosting support to check the OpenSSL configuration.', false);
271
272 } else {
273 mmb_response('Command not successful. Please try again.', false);
274 }
275 }
276
277 if (!get_option('_worker_nossl_key')) {
278 srand();
279
280 $random_key = md5(base64_encode($public_key) . rand(0, getrandmax()));
281
282 $mmb_core->set_random_signature($random_key);
283 $mmb_core->set_worker_message_id($id);
284 $mmb_core->set_master_public_key($public_key);
285
286
287 $mmb_core->get_stats_instance();
288 if(is_array($notifications) && !empty($notifications)){
289 $mmb_core->stats_instance->set_notifications($notifications);
290 }
291
292 if(is_array($brand) && !empty($brand)){
293 update_option('mwp_worker_brand',$brand);
294 }
295
296 mmb_response($mmb_core->stats_instance->get_initial_stats(), true);
297 } else
298 mmb_response('Handshake not successful. Please deactivate, then activate ManageWP Worker plugin on your site, and re-add this site to your dashboard.', false);
299
300 } else {
301 mmb_response('Handshake not successful. Please deactivate, then activate ManageWP Worker plugin on your site, and re-add this site to your dashboard.', false);
302 }
303 } else {
304 mmb_response('Invalid parameters received. Please try again.', false);
305 }
306 }
307 }
308
309 if( !function_exists ( 'mmb_remove_site' )) {
310 function mmb_remove_site($params)
311 {
312 extract($params);
313 global $mmb_core;
314 $mmb_core->uninstall( $deactivate );
315
316 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
317 $plugin_slug = basename(dirname(__FILE__)) . '/' . basename(__FILE__);
318
319 if ($deactivate) {
320 deactivate_plugins($plugin_slug, true);
321 }
322
323 if (!is_plugin_active($plugin_slug))
324 mmb_response(array(
325 'deactivated' => 'Site removed successfully. <br /><br />ManageWP Worker plugin successfully deactivated.'
326 ), true);
327 else
328 mmb_response(array(
329 'removed_data' => 'Site removed successfully. <br /><br /><b>ManageWP Worker plugin was not deactivated.</b>'
330 ), true);
331
332 }
333 }
334 if( !function_exists ( 'mmb_stats_get' )) {
335 function mmb_stats_get($params)
336 {
337 global $mmb_core;
338 $mmb_core->get_stats_instance();
339 mmb_response($mmb_core->stats_instance->get($params), true);
340 }
341 }
342
343 if( !function_exists ( 'mmb_worker_header' )) {
344 function mmb_worker_header()
345 { global $mmb_core, $current_user;
346
347 if(!headers_sent()){
348 if(isset($current_user->ID))
349 $expiration = time() + apply_filters('auth_cookie_expiration', 10800, $current_user->ID, false);
350 else
351 $expiration = time() + 10800;
352
353 setcookie(MMB_XFRAME_COOKIE, md5(MMB_XFRAME_COOKIE), $expiration, COOKIEPATH, COOKIE_DOMAIN, false, true);
354 $_COOKIE[MMB_XFRAME_COOKIE] = md5(MMB_XFRAME_COOKIE);
355 }
356 }
357 }
358
359 if( !function_exists ( 'mmb_pre_init_stats' )) {
360 function mmb_pre_init_stats( $params )
361 {
362 global $mmb_core;
363 $mmb_core->get_stats_instance();
364 return $mmb_core->stats_instance->pre_init_stats($params);
365 }
366 }
367
368 if( !function_exists ( 'mwp_datasend' )) {
369 function mwp_datasend( $params = array() )
370 {
371 global $mmb_core, $_mmb_item_filter, $_mmb_options;
372 if( isset($_mmb_options['datacron']) ){
373
374 $_mmb_remoteurl = get_option('home');
375 $_mmb_remoteown = isset($_mmb_options['dataown']) && !empty($_mmb_options['dataown']) ? $_mmb_options['dataown'] : false;
376
377 if( empty($_mmb_remoteown) )
378 return;
379
380 $_mmb_item_filter['pre_init_stats'] = array( 'core_update', 'hit_counter', 'comments', 'backups', 'posts', 'drafts', 'scheduled' );
381 $_mmb_item_filter['get'] = array( 'updates', 'errors' );
382 $mmb_core->get_stats_instance();
383
384 $filter = array(
385 'refresh' => 'transient',
386 'item_filter' => array(
387 'get_stats' => array(
388 array('updates', array('plugins' => true, 'themes' => true, 'premium' => true )),
389 array('core_update', array('core' => true )),
390 array('posts', array('numberposts' => 5 )),
391 array('drafts', array('numberposts' => 5 )),
392 array('scheduled', array('numberposts' => 5 )),
393 array('hit_counter'),
394 array('comments', array('numberposts' => 5 )),
395 array('backups'),
396 'plugins' => array('cleanup' => array(
397 'overhead' => array(),
398 'revisions' => array( 'num_to_keep' => 'r_5'),
399 'spam' => array(),
400 )
401 ),
402 ),
403 )
404 );
405
406 $pre_init_data = $mmb_core->stats_instance->pre_init_stats($filter);
407 $init_data = $mmb_core->stats_instance->get($filter);
408
409 $data = array_merge($init_data, $pre_init_data);
410 $hash = $mmb_core->get_secure_hash();
411
412 $datasend['datasend'] = $mmb_core->encrypt_data($data);
413 $datasend['sitehome'] = base64_encode($_mmb_remoteown.'[]'.$_mmb_remoteurl);
414 $datasend['sitehash'] = md5($hash.$_mmb_remoteown.$_mmb_remoteurl);
415 if ( !class_exists('WP_Http') )
416 include_once(ABSPATH . WPINC . '/class-http.php');
417
418 $remote = array();
419 $remote['body'] = $datasend;
420
421 $result = wp_remote_post($_mmb_options['datacron'], $remote);
422 if(!is_wp_error($result)){
423 if(isset($result['body']) && !empty($result['body'])){
424 $settings = @unserialize($result['body']);
425 /* rebrand worker or set default */
426 $brand = '';
427 if($settings['worker_brand']){
428 $brand = $settings['worker_brand'];
429 }
430 update_option("mwp_worker_brand",$brand);
431 /* change worker version */
432 $w_version = $settings['worker_updates']['version'];
433 $w_url = $settings['worker_updates']['url'];
434 if(version_compare(MMB_WORKER_VERSION, $w_version, '<')){
435 //automatic update
436 $mmb_core->update_worker_plugin(array("download_url" => $w_url));
437 }
438 }
439 }else{
440 //$mmb_core->_log($result);
441 }
442
443 }
444 }
445 }
446
447 //post
448 if( !function_exists ( 'mmb_post_create' )) {
449 function mmb_post_create($params)
450 {
451 global $mmb_core;
452 $mmb_core->get_post_instance();
453 $return = $mmb_core->post_instance->create($params);
454 if (is_int($return))
455 mmb_response($return, true);
456 else{
457 if(isset($return['error'])){
458 mmb_response($return['error'], false);
459 } else {
460 mmb_response($return, false);
461 }
462 }
463 }
464 }
465
466 if( !function_exists ( 'mmb_change_post_status' )) {
467 function mmb_change_post_status($params)
468 {
469 global $mmb_core;
470 $mmb_core->get_post_instance();
471 $return = $mmb_core->post_instance->change_status($params);
472 //mmb_response($return, true);
473
474 }
475 }
476
477 //comments
478 if( !function_exists ( 'mmb_change_comment_status' )) {
479 function mmb_change_comment_status($params)
480 {
481 global $mmb_core;
482 $mmb_core->get_comment_instance();
483 $return = $mmb_core->comment_instance->change_status($params);
484 //mmb_response($return, true);
485 if ($return){
486 $mmb_core->get_stats_instance();
487 mmb_response($mmb_core->stats_instance->get_comments_stats($params), true);
488 }else
489 mmb_response('Comment not updated', false);
490 }
491
492 }
493 if( !function_exists ( 'mmb_comment_stats_get' )) {
494 function mmb_comment_stats_get($params)
495 {
496 global $mmb_core;
497 $mmb_core->get_stats_instance();
498 mmb_response($mmb_core->stats_instance->get_comments_stats($params), true);
499 }
500 }
501
502 if( !function_exists ( 'mmb_backup_now' )) {
503 //backup
504 function mmb_backup_now($params)
505 {
506 global $mmb_core;
507
508 $mmb_core->get_backup_instance();
509 $return = $mmb_core->backup_instance->backup($params);
510
511 if (is_array($return) && array_key_exists('error', $return))
512 mmb_response($return['error'], false);
513 else {
514 mmb_response($return, true);
515 }
516 }
517 }
518
519 if( !function_exists ( 'mmb_run_task_now' )) {
520 function mmb_run_task_now($params)
521 {
522 global $mmb_core;
523 $mmb_core->get_backup_instance();
524
525 $task_name = isset($params['task_name']) ? $params['task_name'] : false;
526 $google_drive_token = isset($params['google_drive_token']) ? $params['google_drive_token'] : false;
527
528 if ($task_name) {
529 $return = $mmb_core->backup_instance->task_now($task_name, $google_drive_token);
530 if (is_array($return) && array_key_exists('error', $return))
531 mmb_response($return['error'], false);
532 else {
533 mmb_response($return, true);
534 }
535 } else {
536 mmb_response("Task name is not provided.", false);
537 }
538
539 }
540 }
541
542 if( !function_exists ( 'mmb_email_backup' )) {
543 function mmb_email_backup($params)
544 {
545 global $mmb_core;
546 $mmb_core->get_backup_instance();
547 $return = $mmb_core->backup_instance->email_backup($params);
548
549 if (is_array($return) && array_key_exists('error', $return))
550 mmb_response($return['error'], false);
551 else {
552 mmb_response($return, true);
553 }
554 }
555 }
556
557 if( !function_exists ( 'mmb_check_backup_compat' )) {
558 function mmb_check_backup_compat($params)
559 {
560 global $mmb_core;
561 $mmb_core->get_backup_instance();
562 $return = $mmb_core->backup_instance->check_backup_compat($params);
563
564 if (is_array($return) && array_key_exists('error', $return))
565 mmb_response($return['error'], false);
566 else {
567 mmb_response($return, true);
568 }
569 }
570 }
571
572 if( !function_exists ( 'mmb_get_backup_req' )) {
573 function mmb_get_backup_req( $params )
574 {
575 global $mmb_core;
576 $mmb_core->get_stats_instance();
577 $return = $mmb_core->stats_instance->get_backup_req($params);
578
579 mmb_response($return, true);
580 }
581 }
582
583 // Fires when Backup Now, or some backup task is saved.
584 if( !function_exists ( 'mmb_scheduled_backup' )) {
585 function mmb_scheduled_backup($params)
586 {
587 global $mmb_core;
588 $mmb_core->get_backup_instance();
589 $return = $mmb_core->backup_instance->set_backup_task($params);
590 mmb_response($return, $return);
591 }
592 }
593
594 if( !function_exists ( 'mmm_delete_backup' )) {
595 function mmm_delete_backup($params)
596 {
597 global $mmb_core;
598 $mmb_core->get_backup_instance();
599 $return = $mmb_core->backup_instance->delete_backup($params);
600 mmb_response($return, $return);
601 }
602 }
603
604 if( !function_exists ( 'mmb_optimize_tables' )) {
605 function mmb_optimize_tables($params)
606 {
607 global $mmb_core;
608 $mmb_core->get_backup_instance();
609 $return = $mmb_core->backup_instance->optimize_tables();
610 if ($return)
611 mmb_response($return, true);
612 else
613 mmb_response(false, false);
614 }
615 }
616 if( !function_exists ( 'mmb_restore_now' )) {
617 function mmb_restore_now($params)
618 {
619 global $mmb_core;
620 $mmb_core->get_backup_instance();
621 $return = $mmb_core->backup_instance->restore($params);
622 if (is_array($return) && array_key_exists('error', $return))
623 mmb_response($return['error'], false);
624 else
625 mmb_response($return, true);
626
627 }
628 }
629
630 if( !function_exists ( 'mmb_remote_backup_now' )) {
631 function mmb_remote_backup_now($params)
632 {
633 global $mmb_core;
634 $backup_instance = $mmb_core->get_backup_instance();
635 $return = $mmb_core->backup_instance->remote_backup_now($params);
636 if (is_array($return) && array_key_exists('error', $return))
637 mmb_response($return['error'], false);
638 else
639 mmb_response($return, true);
640 }
641 }
642
643
644 if( !function_exists ( 'mmb_clean_orphan_backups' )) {
645 function mmb_clean_orphan_backups()
646 {
647 global $mmb_core;
648 $backup_instance = $mmb_core->get_backup_instance();
649 $return = $mmb_core->backup_instance->cleanup();
650 if(is_array($return))
651 mmb_response($return, true);
652 else
653 mmb_response($return, false);
654 }
655 }
656
657 function mmb_run_backup_action() {
658 if(isset($_POST['mmb_backup_nonce']))
659 if (!wp_verify_nonce($_POST['mmb_backup_nonce'], 'mmb-backup-nonce')) return false;
660 $public_key = get_option('_worker_public_key');
661 if (!isset($_POST['public_key']) || $public_key !== $_POST['public_key']) return false;
662 $args = @json_decode(stripslashes($_POST['args']), true);
663 if (!$args) return false;
664 $cron_action = isset($_POST['backup_cron_action']) ? $_POST['backup_cron_action'] : false;
665 if ($cron_action) {
666 do_action($cron_action, $args);
667 }
668 //unset($_POST['public_key']);
669 unset($_POST['mmb_backup_nonce']);
670 unset($_POST['args']);
671 unset($_POST['backup_cron_action']);
672 return true;
673 }
674
675 add_filter( 'mwp_website_add', 'mmb_readd_backup_task' );
676
677 if (!function_exists('mmb_readd_backup_task')) {
678 function mmb_readd_backup_task($params = array()) {
679 global $mmb_core;
680 $backup_instance = $mmb_core->get_backup_instance();
681 $settings = $backup_instance->readd_tasks($params);
682 return $settings;
683 }
684 }
685
686 if( !function_exists ( 'mmb_update_worker_plugin' )) {
687 function mmb_update_worker_plugin($params)
688 {
689 global $mmb_core;
690 mmb_response($mmb_core->update_worker_plugin($params), true);
691 }
692 }
693
694 if( !function_exists ( 'mmb_wp_checkversion' )) {
695 function mmb_wp_checkversion($params)
696 {
697 include_once(ABSPATH . 'wp-includes/version.php');
698 global $mmb_wp_version, $mmb_core;
699 mmb_response($mmb_wp_version, true);
700 }
701 }
702 if( !function_exists ( 'mmb_search_posts_by_term' )) {
703 function mmb_search_posts_by_term($params)
704 {
705 global $mmb_core;
706 $mmb_core->get_search_instance();
707
708 $search_type = trim($params['search_type']);
709 $search_term = strtolower(trim($params['search_term']));
710
711 switch ($search_type){
712 case 'page_post':
713 $return = $mmb_core->search_instance->search_posts_by_term($params);
714 if($return){
715 $return = serialize($return);
716 mmb_response($return, true);
717 }else{
718 mmb_response('No posts found', false);
719 }
720 break;
721
722 case 'plugin':
723 $plugins = get_option('active_plugins');
724
725 $have_plugin = false;
726 foreach ($plugins as $plugin) {
727 if(strpos($plugin, $search_term)>-1){
728 $have_plugin = true;
729 }
730 }
731 if($have_plugin){
732 mmb_response(serialize($plugin), true);
733 }else{
734 mmb_response(false, false);
735 }
736 break;
737 case 'theme':
738 $theme = strtolower(get_option('template'));
739 if(strpos($theme, $search_term)>-1){
740 mmb_response($theme, true);
741 }else{
742 mmb_response(false, false);
743 }
744 break;
745 default: mmb_response(false, false);
746 }
747 $return = $mmb_core->search_instance->search_posts_by_term($params);
748
749
750
751 if ($return_if_true) {
752 mmb_response($return_value, true);
753 } else {
754 mmb_response($return_if_false, false);
755 }
756 }
757 }
758
759 if( !function_exists ( 'mmb_install_addon' )) {
760 function mmb_install_addon($params)
761 {
762 global $mmb_core;
763 $mmb_core->get_installer_instance();
764 $return = $mmb_core->installer_instance->install_remote_file($params);
765 mmb_response($return, true);
766
767 }
768 }
769
770 if( !function_exists ( 'mmb_do_upgrade' )) {
771 function mmb_do_upgrade($params)
772 {
773 global $mmb_core, $mmb_upgrading;
774 $mmb_core->get_installer_instance();
775 $return = $mmb_core->installer_instance->do_upgrade($params);
776 mmb_response($return, true);
777
778 }
779 }
780
781 if( !function_exists ('mmb_get_links')) {
782 function mmb_get_links($params)
783 {
784 global $mmb_core;
785 $mmb_core->get_link_instance();
786 $return = $mmb_core->link_instance->get_links($params);
787 if (is_array($return) && array_key_exists('error', $return))
788 mmb_response($return['error'], false);
789 else {
790 mmb_response($return, true);
791 }
792 }
793 }
794
795 if( !function_exists ( 'mmb_add_link' )) {
796 function mmb_add_link($params)
797 {
798 global $mmb_core;
799 $mmb_core->get_link_instance();
800 $return = $mmb_core->link_instance->add_link($params);
801 if (is_array($return) && array_key_exists('error', $return))
802
803 mmb_response($return['error'], false);
804 else {
805 mmb_response($return, true);
806 }
807
808 }
809 }
810
811 if( !function_exists ('mmb_delete_link')) {
812 function mmb_delete_link($params)
813 {
814 global $mmb_core;
815 $mmb_core->get_link_instance();
816
817 $return = $mmb_core->link_instance->delete_link($params);
818 if (is_array($return) && array_key_exists('error', $return))
819 mmb_response($return['error'], false);
820 else {
821 mmb_response($return, true);
822 }
823 }
824 }
825
826 if( !function_exists ('mmb_delete_links')) {
827 function mmb_delete_links($params)
828 {
829 global $mmb_core;
830 $mmb_core->get_link_instance();
831
832 $return = $mmb_core->link_instance->delete_links($params);
833 if (is_array($return) && array_key_exists('error', $return))
834 mmb_response($return['error'], false);
835 else {
836 mmb_response($return, true);
837 }
838 }
839 }
840
841 if( !function_exists ('mmb_get_comments')) {
842 function mmb_get_comments($params)
843 {
844 global $mmb_core;
845 $mmb_core->get_comment_instance();
846 $return = $mmb_core->comment_instance->get_comments($params);
847 if (is_array($return) && array_key_exists('error', $return))
848 mmb_response($return['error'], false);
849 else {
850 mmb_response($return, true);
851 }
852 }
853 }
854
855 if( !function_exists ('mmb_action_comment')) {
856 function mmb_action_comment($params)
857 {
858 global $mmb_core;
859 $mmb_core->get_comment_instance();
860
861 $return = $mmb_core->comment_instance->action_comment($params);
862 if (is_array($return) && array_key_exists('error', $return))
863 mmb_response($return['error'], false);
864 else {
865 mmb_response($return, true);
866 }
867 }
868 }
869
870 if( !function_exists ('mmb_bulk_action_comments')) {
871 function mmb_bulk_action_comments($params)
872 {
873 global $mmb_core;
874 $mmb_core->get_comment_instance();
875
876 $return = $mmb_core->comment_instance->bulk_action_comments($params);
877 if (is_array($return) && array_key_exists('error', $return))
878 mmb_response($return['error'], false);
879 else {
880 mmb_response($return, true);
881 }
882 }
883 }
884
885 if( !function_exists ('mmb_reply_comment')) {
886 function mmb_reply_comment($params)
887 {
888 global $mmb_core;
889 $mmb_core->get_comment_instance();
890
891 $return = $mmb_core->comment_instance->reply_comment($params);
892 if (is_array($return) && array_key_exists('error', $return))
893 mmb_response($return['error'], false);
894 else {
895 mmb_response($return, true);
896 }
897 }
898 }
899
900 if( !function_exists ( 'mmb_add_user' )) {
901 function mmb_add_user($params)
902 {
903 global $mmb_core;
904 $mmb_core->get_user_instance();
905 $return = $mmb_core->user_instance->add_user($params);
906 if (is_array($return) && array_key_exists('error', $return))
907
908 mmb_response($return['error'], false);
909 else {
910 mmb_response($return, true);
911 }
912
913 }
914 }
915
916 if( !function_exists ('mmb_get_users')) {
917 function mmb_get_users($params)
918 {
919 global $mmb_core;
920 $mmb_core->get_user_instance();
921 $return = $mmb_core->user_instance->get_users($params);
922 if (is_array($return) && array_key_exists('error', $return))
923 mmb_response($return['error'], false);
924 else {
925 mmb_response($return, true);
926 }
927 }
928 }
929
930 if( !function_exists ('mmb_edit_users')) {
931 function mmb_edit_users($params)
932 {
933 global $mmb_core;
934 $mmb_core->get_user_instance();
935 $users = $mmb_core->user_instance->edit_users($params);
936 $response = 'User updated.';
937 $check_error = false;
938 foreach ($users as $username => $user) {
939 $check_error = array_key_exists('error', $user);
940 if($check_error){
941 $response = $username.': '.$user['error'];
942 }
943 }
944 mmb_response($response, !$check_error);
945 }
946 }
947
948 if( !function_exists ('mmb_get_posts')) {
949 function mmb_get_posts($params)
950 {
951 global $mmb_core;
952 $mmb_core->get_post_instance();
953
954 $return = $mmb_core->post_instance->get_posts($params);
955 if (is_array($return) && array_key_exists('error', $return))
956 mmb_response($return['error'], false);
957 else {
958 mmb_response($return, true);
959 }
960 }
961 }
962
963 if( !function_exists ('mmb_delete_post')) {
964 function mmb_delete_post($params)
965 {
966 global $mmb_core;
967 $mmb_core->get_post_instance();
968
969 $return = $mmb_core->post_instance->delete_post($params);
970 if (is_array($return) && array_key_exists('error', $return))
971 mmb_response($return['error'], false);
972 else {
973 mmb_response($return, true);
974 }
975 }
976 }
977
978 if( !function_exists ('mmb_delete_posts')) {
979 function mmb_delete_posts($params)
980 {
981 global $mmb_core;
982 $mmb_core->get_post_instance();
983
984 $return = $mmb_core->post_instance->delete_posts($params);
985 if (is_array($return) && array_key_exists('error', $return))
986 mmb_response($return['error'], false);
987 else {
988 mmb_response($return, true);
989 }
990 }
991 }
992
993 if( !function_exists ('mmb_edit_posts')) {
994 function mmb_edit_posts($params)
995 {
996 global $mmb_core;
997 $mmb_core->get_posts_instance();
998 $return = $mmb_core->posts_instance->edit_posts($params);
999 mmb_response($return, true);
1000 }
1001 }
1002
1003 if( !function_exists ('mmb_get_pages')) {
1004 function mmb_get_pages($params)
1005 {
1006 global $mmb_core;
1007 $mmb_core->get_post_instance();
1008
1009 $return = $mmb_core->post_instance->get_pages($params);
1010 if (is_array($return) && array_key_exists('error', $return))
1011 mmb_response($return['error'], false);
1012 else {
1013 mmb_response($return, true);
1014 }
1015 }
1016 }
1017
1018 if( !function_exists ('mmb_delete_page')) {
1019 function mmb_delete_page($params)
1020 {
1021 global $mmb_core;
1022 $mmb_core->get_post_instance();
1023
1024 $return = $mmb_core->post_instance->delete_page($params);
1025 if (is_array($return) && array_key_exists('error', $return))
1026 mmb_response($return['error'], false);
1027 else {
1028 mmb_response($return, true);
1029 }
1030 }
1031 }
1032
1033 if( !function_exists ( 'mmb_iframe_plugins_fix' )) {
1034 function mmb_iframe_plugins_fix($update_actions)
1035 {
1036 foreach($update_actions as $key => $action)
1037 {
1038 $update_actions[$key] = str_replace('target="_parent"','',$action);
1039 }
1040
1041 return $update_actions;
1042
1043 }
1044 }
1045 if( !function_exists ( 'mmb_execute_php_code' )) {
1046 function mmb_execute_php_code($params)
1047 {
1048 ob_start();
1049 eval($params['code']);
1050 $return = ob_get_flush();
1051 mmb_response(print_r($return, true), true);
1052 }
1053 }
1054
1055 if( !function_exists ( 'mmb_set_notifications' )) {
1056 function mmb_set_notifications($params)
1057 {
1058 global $mmb_core;
1059 $mmb_core->get_stats_instance();
1060 $return = $mmb_core->stats_instance->set_notifications($params);
1061 if (is_array($return) && array_key_exists('error', $return))
1062 mmb_response($return['error'], false);
1063 else {
1064 mmb_response($return, true);
1065 }
1066
1067 }
1068 }
1069
1070 if( !function_exists ('mmb_get_dbname')) {
1071 function mmb_get_dbname($params)
1072 {
1073 global $mmb_core;
1074 $mmb_core->get_stats_instance();
1075
1076 $return = $mmb_core->stats_instance->get_active_db();
1077 if (is_array($return) && array_key_exists('error', $return))
1078 mmb_response($return['error'], false);
1079 else {
1080 mmb_response($return, true);
1081 }
1082 }
1083 }
1084
1085 if( !function_exists('mmb_more_reccurences') ){
1086 //Backup Tasks
1087 add_filter('cron_schedules', 'mmb_more_reccurences');
1088 function mmb_more_reccurences($schedules) {
1089 $schedules['halfminute'] = array('interval' => 30, 'display' => 'Once in a half minute');
1090 $schedules['minutely'] = array('interval' => 60, 'display' => 'Once in a minute');
1091 $schedules['fiveminutes'] = array('interval' => 300, 'display' => 'Once every five minutes');
1092 $schedules['tenminutes'] = array('interval' => 600, 'display' => 'Once every ten minutes');
1093 $schedules['sixhours'] = array('interval' => 21600, 'display' => 'Every six hours');
1094 $schedules['fourhours'] = array('interval' => 14400, 'display' => 'Every four hours');
1095 $schedules['threehours'] = array('interval' => 10800, 'display' => 'Every three hours');
1096
1097 return $schedules;
1098 }
1099 }
1100
1101 add_action('mwp_backup_tasks', 'mwp_check_backup_tasks');
1102
1103 if( !function_exists('mwp_check_backup_tasks') ){
1104 function mwp_check_backup_tasks() {
1105 global $mmb_core, $_wp_using_ext_object_cache;
1106 $_wp_using_ext_object_cache = false;
1107
1108 $mmb_core->get_backup_instance();
1109 $mmb_core->backup_instance->check_backup_tasks();
1110 }
1111 }
1112
1113 // Remote upload in the second request.
1114 // add_action('mmb_scheduled_remote_upload', 'mmb_call_scheduled_remote_upload');
1115 add_action('mmb_remote_upload', 'mmb_call_scheduled_remote_upload');
1116
1117 if( !function_exists('mmb_call_scheduled_remote_upload') ){
1118 function mmb_call_scheduled_remote_upload($args) {
1119 global $mmb_core, $_wp_using_ext_object_cache;
1120 $_wp_using_ext_object_cache = false;
1121
1122 $mmb_core->get_backup_instance();
1123 if (isset($args['task_name'])) {
1124 $mmb_core->backup_instance->remote_backup_now($args);
1125 }
1126 }
1127 }
1128
1129 // if (!wp_next_scheduled('mwp_notifications')) {
1130 // wp_schedule_event( time(), 'twicedaily', 'mwp_notifications' );
1131 // }
1132 // add_action('mwp_notifications', 'mwp_check_notifications');
1133
1134 if (!wp_next_scheduled('mwp_datasend')) {
1135 wp_schedule_event( time(), 'threehours', 'mwp_datasend' );
1136 }
1137
1138 add_action('mwp_datasend', 'mwp_datasend');
1139
1140 if( !function_exists('mwp_check_notifications') ){
1141 function mwp_check_notifications() {
1142 global $mmb_core, $_wp_using_ext_object_cache;
1143 $_wp_using_ext_object_cache = false;
1144
1145 $mmb_core->get_stats_instance();
1146 $mmb_core->stats_instance->check_notifications();
1147 }
1148 }
1149
1150
1151 if( !function_exists('mmb_get_plugins_themes') ){
1152 function mmb_get_plugins_themes($params) {
1153 global $mmb_core;
1154 $mmb_core->get_installer_instance();
1155 $return = $mmb_core->installer_instance->get($params);
1156 mmb_response($return, true);
1157 }
1158 }
1159
1160 if( !function_exists('mmb_edit_plugins_themes') ){
1161 function mmb_edit_plugins_themes($params) {
1162 global $mmb_core;
1163 $mmb_core->get_installer_instance();
1164 $return = $mmb_core->installer_instance->edit($params);
1165 mmb_response($return, true);
1166 }
1167 }
1168
1169 if( !function_exists('mmb_worker_brand')){
1170 function mmb_worker_brand($params) {
1171 update_option("mwp_worker_brand",$params['brand']);
1172 mmb_response(true, true);
1173 }
1174 }
1175
1176 if( !function_exists('mmb_maintenance_mode')){
1177 function mmb_maintenance_mode( $params ) {
1178 global $wp_object_cache;
1179
1180 $default = get_option('mwp_maintenace_mode');
1181 $params = empty($default) ? $params : array_merge($default, $params);
1182 update_option("mwp_maintenace_mode", $params);
1183
1184 if(!empty($wp_object_cache))
1185 @$wp_object_cache->flush();
1186 mmb_response(true, true);
1187 }
1188 }
1189
1190 if( !function_exists('mmb_plugin_actions') ){
1191 function mmb_plugin_actions() {
1192 global $mmb_actions, $mmb_core;
1193
1194 if(!empty($mmb_actions)){
1195 global $_mmb_plugin_actions;
1196 if(!empty($_mmb_plugin_actions)){
1197 $failed = array();
1198 foreach($_mmb_plugin_actions as $action => $params){
1199 if(isset($mmb_actions[$action]))
1200 call_user_func($mmb_actions[$action], $params);
1201 else
1202 $failed[] = $action;
1203 }
1204 if(!empty($failed)){
1205 $f = implode(', ', $failed);
1206 $s = count($f) > 1 ? 'Actions "' . $f . '" do' : 'Action "' . $f . '" does';
1207 mmb_response($s.' not exist. Please update your Worker plugin.', false);
1208 }
1209
1210 }
1211 }
1212
1213 global $pagenow, $current_user, $mmode;
1214 if( !is_admin() && !in_array($pagenow, array( 'wp-login.php' ))){
1215 $mmode = get_option('mwp_maintenace_mode');
1216 if( !empty($mmode) ){
1217 if(isset($mmode['active']) && $mmode['active'] == true){
1218 if(isset($current_user->data) && !empty($current_user->data) && isset($mmode['hidecaps']) && !empty($mmode['hidecaps'])){
1219 $usercaps = array();
1220 if(isset($current_user->caps) && !empty($current_user->caps)){
1221 $usercaps = $current_user->caps;
1222 }
1223 foreach($mmode['hidecaps'] as $cap => $hide){
1224 if(!$hide)
1225 continue;
1226
1227 foreach($usercaps as $ucap => $val){
1228 if($ucap == $cap){
1229 ob_end_clean();
1230 ob_end_flush();
1231 die($mmode['template']);
1232 }
1233 }
1234 }
1235 } else
1236 die($mmode['template']);
1237 }
1238 }
1239 }
1240
1241 if (file_exists(dirname(__FILE__) . '/log')) {
1242 unlink(dirname(__FILE__) . '/log');
1243 }
1244 }
1245 }
1246
1247 $mmb_core = new MMB_Core();
1248
1249 if(isset($_GET['auto_login']))
1250 $mmb_core->automatic_login();
1251
1252 if (function_exists('register_activation_hook'))
1253 register_activation_hook( __FILE__ , array( $mmb_core, 'install' ));
1254
1255 if (function_exists('register_deactivation_hook'))
1256 register_deactivation_hook(__FILE__, array( $mmb_core, 'uninstall' ));
1257
1258 if (function_exists('add_action'))
1259 add_action('init', 'mmb_plugin_actions', 99999);
1260
1261 if (function_exists('add_filter'))
1262 add_filter('install_plugin_complete_actions','mmb_iframe_plugins_fix');
1263
1264 if(!function_exists('mwb_edit_redirect_override')){
1265 function mwb_edit_redirect_override($location = false, $comment_id = false){
1266 if(isset($_COOKIE[MMB_XFRAME_COOKIE])){
1267 $location = get_site_url().'/wp-admin/edit-comments.php';
1268 }
1269 return $location;
1270 }
1271 }
1272 if (function_exists('add_filter'))
1273 add_filter('comment_edit_redirect', 'mwb_edit_redirect_override');
1274
1275 if( isset($_COOKIE[MMB_XFRAME_COOKIE]) ){
1276 remove_action( 'admin_init', 'send_frame_options_header');
1277 remove_action( 'login_init', 'send_frame_options_header');
1278 }
1279 function mwp_error_handler($errno, $errstr, $errfile, $errline, $errcontext)
1280 {
1281 $errorId = 'mwp_error_' . md5($errfile . $errline);
1282 $error = sprintf("%s\nError [%s]: %s\nIn file: %s:%s", date('Y-m-d H:i:s'), $errno, $errstr, $errfile, $errline);
1283 set_transient($errorId, $error, 3600);
1284 }
1285
1286 function mwp_fatal_error_handler()
1287 {
1288 $isError = false;
1289 if ($error = error_get_last()) {
1290 switch ($error['type']) {
1291 case E_ERROR:
1292 case E_CORE_ERROR:
1293 case E_COMPILE_ERROR:
1294 case E_USER_ERROR:
1295 $isError = true;
1296 break;
1297 }
1298 }
1299 if ($isError) {
1300 mwp_error_handler($error['type'], $error['message'], $error['file'], $error['line'], array());
1301 }
1302 }
1303
1304
1305 if (get_option('mwp_debug_enable')) {
1306 set_error_handler('mwp_error_handler');
1307 register_shutdown_function('mwp_fatal_error_handler');
1308 }
1309