PluginProbe
ManageWP Worker / 3.9.24
ManageWP Worker v3.9.24
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.24, at init.php

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