| 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.28 |
| 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.28'); |
| 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 |
$mmb_wp_version = $wp_version; |
| 36 |
$mmb_plugin_dir = WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__)); |
| 37 |
$mmb_plugin_url = WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)); |
| 38 |
|
| 39 |
require_once("$mmb_plugin_dir/helper.class.php"); |
| 40 |
require_once("$mmb_plugin_dir/core.class.php"); |
| 41 |
require_once("$mmb_plugin_dir/post.class.php"); |
| 42 |
require_once("$mmb_plugin_dir/comment.class.php"); |
| 43 |
require_once("$mmb_plugin_dir/stats.class.php"); |
| 44 |
require_once("$mmb_plugin_dir/backup.class.php"); |
| 45 |
require_once("$mmb_plugin_dir/installer.class.php"); |
| 46 |
require_once("$mmb_plugin_dir/link.class.php"); |
| 47 |
require_once("$mmb_plugin_dir/user.class.php"); |
| 48 |
require_once("$mmb_plugin_dir/security.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 |
return; |
| 145 |
} else { |
| 146 |
$_mwp_auth = $mmb_core->authenticate_message($_mwp_data['action'] . $_mwp_data['id'], $_mwp_data['signature'], $_mwp_data['id']); |
| 147 |
} |
| 148 |
|
| 149 |
if($_mwp_auth !== true) { |
| 150 |
mmb_response($_mwp_auth['error'], false); |
| 151 |
} |
| 152 |
|
| 153 |
if(isset($_mwp_data['params']['username']) && !is_user_logged_in()){ |
| 154 |
$user = function_exists('get_user_by') ? get_user_by('login', $_mwp_data['params']['username']) : get_userdatabylogin( $_mwp_data['params']['username'] ); |
| 155 |
wp_set_current_user($user->ID); |
| 156 |
if(@getenv('IS_WPE')) |
| 157 |
wp_set_auth_cookie($user->ID); |
| 158 |
} |
| 159 |
if(!defined("WP_ADMIN")) |
| 160 |
define(WP_ADMIN,true); |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
if( !function_exists ( 'mmb_parse_request' )) { |
| 165 |
function mmb_parse_request(){ |
| 166 |
global $mmb_core, $wp_db_version, $wpmu_version, $_wp_using_ext_object_cache, $_mwp_data, $_mwp_auth; |
| 167 |
if(empty($_mwp_auth)) { |
| 168 |
MMB_Stats::set_hit_count(); |
| 169 |
return; |
| 170 |
} |
| 171 |
ob_start(); |
| 172 |
$_wp_using_ext_object_cache = false; |
| 173 |
@set_time_limit(1200); |
| 174 |
|
| 175 |
if ($_mwp_data['action'] === 'add_site') { |
| 176 |
mmb_add_site($_mwp_data['params']); |
| 177 |
mmb_response('You should never see this.', false); |
| 178 |
} |
| 179 |
|
| 180 |
/* in case database upgrade required, do database backup and perform upgrade ( wordpress wp_upgrade() function ) */ |
| 181 |
if( strlen(trim($wp_db_version)) && !defined('ACX_PLUGIN_DIR') ){ |
| 182 |
if ( get_option('db_version') != $wp_db_version ) { |
| 183 |
/* in multisite network, please update database manualy */ |
| 184 |
if (empty($wpmu_version) || (function_exists('is_multisite') && !is_multisite())){ |
| 185 |
if( ! function_exists('wp_upgrade')) |
| 186 |
include_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
| 187 |
|
| 188 |
ob_clean(); |
| 189 |
@wp_upgrade(); |
| 190 |
@do_action('after_db_upgrade'); |
| 191 |
ob_end_clean(); |
| 192 |
} |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
if(isset($_mwp_data['params']['secure'])){ |
| 197 |
if($decrypted = $mmb_core->_secure_data($_mwp_data['params']['secure'])){ |
| 198 |
$decrypted = maybe_unserialize($decrypted); |
| 199 |
if(is_array($decrypted)){ |
| 200 |
foreach($decrypted as $key => $val){ |
| 201 |
if(!is_numeric($key)) |
| 202 |
$_mwp_data['params'][$key] = $val; |
| 203 |
} |
| 204 |
unset($_mwp_data['params']['secure']); |
| 205 |
} else $_mwp_data['params']['secure'] = $decrypted; |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
if( isset($_mwp_data['setting']) ){ |
| 210 |
$mmb_core->save_options( $_mwp_data['setting'] ); |
| 211 |
} |
| 212 |
|
| 213 |
if( !$mmb_core->register_action_params( $_mwp_data['action'], $_mwp_data['params'] ) ){ |
| 214 |
global $_mmb_plugin_actions; |
| 215 |
$_mmb_plugin_actions[$_mwp_data['action']] = $_mwp_data['params']; |
| 216 |
} |
| 217 |
ob_end_clean(); |
| 218 |
} |
| 219 |
} |
| 220 |
/* Main response function */ |
| 221 |
if( !function_exists ( 'mmb_response' )) { |
| 222 |
|
| 223 |
function mmb_response($response = false, $success = true) |
| 224 |
{ |
| 225 |
$return = array(); |
| 226 |
|
| 227 |
if ((is_array($response) && empty($response)) || (!is_array($response) && strlen($response) == 0)) |
| 228 |
$return['error'] = 'Empty response.'; |
| 229 |
else if ($success) |
| 230 |
$return['success'] = $response; |
| 231 |
else |
| 232 |
$return['error'] = $response; |
| 233 |
|
| 234 |
if( !headers_sent() ){ |
| 235 |
header('HTTP/1.0 200 OK'); |
| 236 |
header('Content-Type: text/plain'); |
| 237 |
} |
| 238 |
exit("<MWPHEADER>" . base64_encode(serialize($return))."<ENDMWPHEADER>"); |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
if( !function_exists ( 'mmb_add_site' )) { |
| 245 |
function mmb_add_site($params) { |
| 246 |
global $mmb_core; |
| 247 |
$num = extract($params); |
| 248 |
|
| 249 |
if ($num) { |
| 250 |
if (!get_option('_action_message_id') && !get_option('_worker_public_key')) { |
| 251 |
$public_key = base64_decode($public_key); |
| 252 |
|
| 253 |
if (function_exists('openssl_verify')) { |
| 254 |
$verify = openssl_verify($action . $id, base64_decode($signature), $public_key); |
| 255 |
if ($verify == 1) { |
| 256 |
$mmb_core->set_master_public_key($public_key); |
| 257 |
$mmb_core->set_worker_message_id($id); |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
$mmb_core->get_stats_instance(); |
| 262 |
if(isset($notifications) && is_array($notifications) && !empty($notifications)){ |
| 263 |
$mmb_core->stats_instance->set_notifications($notifications); |
| 264 |
} |
| 265 |
if(isset($brand) && is_array($brand) && !empty($brand)){ |
| 266 |
update_option('mwp_worker_brand', $brand); |
| 267 |
} |
| 268 |
|
| 269 |
if( isset( $add_settigns ) && is_array($add_settigns) && !empty( $add_settigns ) ) |
| 270 |
apply_filters( 'mwp_website_add', $add_settigns ); |
| 271 |
|
| 272 |
mmb_response($mmb_core->stats_instance->get_initial_stats(), true); |
| 273 |
} else if ($verify == 0) { |
| 274 |
|
| 275 |
//mmb_response('Site could not be added. OpenSSL verification error: "'.openssl_error_string().'". Contact your hosting support to check the OpenSSL configuration.', false); |
| 276 |
|
| 277 |
} else { |
| 278 |
mmb_response('Command not successful. Please try again.', false); |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
if (!get_option('_worker_nossl_key')) { |
| 283 |
srand(); |
| 284 |
|
| 285 |
$random_key = md5(base64_encode($public_key) . rand(0, getrandmax())); |
| 286 |
|
| 287 |
$mmb_core->set_random_signature($random_key); |
| 288 |
$mmb_core->set_worker_message_id($id); |
| 289 |
$mmb_core->set_master_public_key($public_key); |
| 290 |
|
| 291 |
|
| 292 |
$mmb_core->get_stats_instance(); |
| 293 |
if(is_array($notifications) && !empty($notifications)){ |
| 294 |
$mmb_core->stats_instance->set_notifications($notifications); |
| 295 |
} |
| 296 |
|
| 297 |
if(is_array($brand) && !empty($brand)){ |
| 298 |
update_option('mwp_worker_brand',$brand); |
| 299 |
} |
| 300 |
|
| 301 |
mmb_response($mmb_core->stats_instance->get_initial_stats(), true); |
| 302 |
} else |
| 303 |
mmb_response('Handshake not successful. Please deactivate, then activate ManageWP Worker plugin on your site, and re-add this site to your dashboard.', false); |
| 304 |
|
| 305 |
} else { |
| 306 |
mmb_response('Handshake not successful. Please deactivate, then activate ManageWP Worker plugin on your site, and re-add this site to your dashboard.', false); |
| 307 |
} |
| 308 |
} else { |
| 309 |
mmb_response('Invalid parameters received. Please try again.', false); |
| 310 |
} |
| 311 |
} |
| 312 |
} |
| 313 |
|
| 314 |
if( !function_exists ( 'mmb_remove_site' )) { |
| 315 |
function mmb_remove_site($params) |
| 316 |
{ |
| 317 |
extract($params); |
| 318 |
global $mmb_core; |
| 319 |
$mmb_core->uninstall( $deactivate ); |
| 320 |
|
| 321 |
include_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
| 322 |
$plugin_slug = basename(dirname(__FILE__)) . '/' . basename(__FILE__); |
| 323 |
|
| 324 |
if ($deactivate) { |
| 325 |
deactivate_plugins($plugin_slug, true); |
| 326 |
} |
| 327 |
|
| 328 |
if (!is_plugin_active($plugin_slug)) |
| 329 |
mmb_response(array( |
| 330 |
'deactivated' => 'Site removed successfully. <br /><br />ManageWP Worker plugin successfully deactivated.' |
| 331 |
), true); |
| 332 |
else |
| 333 |
mmb_response(array( |
| 334 |
'removed_data' => 'Site removed successfully. <br /><br /><b>ManageWP Worker plugin was not deactivated.</b>' |
| 335 |
), true); |
| 336 |
|
| 337 |
} |
| 338 |
} |
| 339 |
if( !function_exists ( 'mmb_stats_get' )) { |
| 340 |
function mmb_stats_get($params) |
| 341 |
{ |
| 342 |
global $mmb_core; |
| 343 |
$mmb_core->get_stats_instance(); |
| 344 |
mmb_response($mmb_core->stats_instance->get($params), true); |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
if( !function_exists ( 'mmb_worker_header' )) { |
| 349 |
function mmb_worker_header() |
| 350 |
{ global $mmb_core, $current_user; |
| 351 |
|
| 352 |
if(!headers_sent()){ |
| 353 |
if(isset($current_user->ID)) |
| 354 |
$expiration = time() + apply_filters('auth_cookie_expiration', 10800, $current_user->ID, false); |
| 355 |
else |
| 356 |
$expiration = time() + 10800; |
| 357 |
|
| 358 |
setcookie(MMB_XFRAME_COOKIE, md5(MMB_XFRAME_COOKIE), $expiration, COOKIEPATH, COOKIE_DOMAIN, false, true); |
| 359 |
$_COOKIE[MMB_XFRAME_COOKIE] = md5(MMB_XFRAME_COOKIE); |
| 360 |
} |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
if( !function_exists ( 'mmb_pre_init_stats' )) { |
| 365 |
function mmb_pre_init_stats( $params ) |
| 366 |
{ |
| 367 |
global $mmb_core; |
| 368 |
$mmb_core->get_stats_instance(); |
| 369 |
return $mmb_core->stats_instance->pre_init_stats($params); |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
if( !function_exists ( 'mwp_datasend' )) { |
| 374 |
function mwp_datasend( $params = array() ) |
| 375 |
{ |
| 376 |
global $mmb_core, $_mmb_item_filter, $_mmb_options; |
| 377 |
if( isset($_mmb_options['datacron']) ){ |
| 378 |
|
| 379 |
$_mmb_remoteurl = get_option('home'); |
| 380 |
$_mmb_remoteown = isset($_mmb_options['dataown']) && !empty($_mmb_options['dataown']) ? $_mmb_options['dataown'] : false; |
| 381 |
|
| 382 |
if( empty($_mmb_remoteown) ) |
| 383 |
return; |
| 384 |
|
| 385 |
$_mmb_item_filter['pre_init_stats'] = array( 'core_update', 'hit_counter', 'comments', 'backups', 'posts', 'drafts', 'scheduled' ); |
| 386 |
$_mmb_item_filter['get'] = array( 'updates', 'errors' ); |
| 387 |
$mmb_core->get_stats_instance(); |
| 388 |
|
| 389 |
$filter = array( |
| 390 |
'refresh' => 'transient', |
| 391 |
'item_filter' => array( |
| 392 |
'get_stats' => array( |
| 393 |
array('updates', array('plugins' => true, 'themes' => true, 'premium' => true )), |
| 394 |
array('core_update', array('core' => true )), |
| 395 |
array('posts', array('numberposts' => 5 )), |
| 396 |
array('drafts', array('numberposts' => 5 )), |
| 397 |
array('scheduled', array('numberposts' => 5 )), |
| 398 |
array('hit_counter'), |
| 399 |
array('comments', array('numberposts' => 5 )), |
| 400 |
array('backups'), |
| 401 |
'plugins' => array('cleanup' => array( |
| 402 |
'overhead' => array(), |
| 403 |
'revisions' => array( 'num_to_keep' => 'r_5'), |
| 404 |
'spam' => array(), |
| 405 |
) |
| 406 |
), |
| 407 |
), |
| 408 |
) |
| 409 |
); |
| 410 |
|
| 411 |
$pre_init_data = $mmb_core->stats_instance->pre_init_stats($filter); |
| 412 |
$init_data = $mmb_core->stats_instance->get($filter); |
| 413 |
|
| 414 |
$data = array_merge($init_data, $pre_init_data); |
| 415 |
$hash = $mmb_core->get_secure_hash(); |
| 416 |
|
| 417 |
$datasend['datasend'] = $mmb_core->encrypt_data($data); |
| 418 |
$datasend['sitehome'] = base64_encode($_mmb_remoteown.'[]'.$_mmb_remoteurl); |
| 419 |
$datasend['sitehash'] = md5($hash.$_mmb_remoteown.$_mmb_remoteurl); |
| 420 |
if ( !class_exists('WP_Http') ) |
| 421 |
include_once(ABSPATH . WPINC . '/class-http.php'); |
| 422 |
|
| 423 |
$remote = array(); |
| 424 |
$remote['body'] = $datasend; |
| 425 |
|
| 426 |
$result = wp_remote_post($_mmb_options['datacron'], $remote); |
| 427 |
if(!is_wp_error($result)){ |
| 428 |
if(isset($result['body']) && !empty($result['body'])){ |
| 429 |
$settings = @unserialize($result['body']); |
| 430 |
/* rebrand worker or set default */ |
| 431 |
$brand = ''; |
| 432 |
if($settings['worker_brand']){ |
| 433 |
$brand = $settings['worker_brand']; |
| 434 |
} |
| 435 |
update_option("mwp_worker_brand",$brand); |
| 436 |
/* change worker version */ |
| 437 |
$w_version = $settings['worker_updates']['version']; |
| 438 |
$w_url = $settings['worker_updates']['url']; |
| 439 |
if(version_compare(MMB_WORKER_VERSION, $w_version, '<')){ |
| 440 |
//automatic update |
| 441 |
$mmb_core->update_worker_plugin(array("download_url" => $w_url)); |
| 442 |
} |
| 443 |
} |
| 444 |
}else{ |
| 445 |
//$mmb_core->_log($result); |
| 446 |
} |
| 447 |
|
| 448 |
} |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
//post |
| 453 |
if( !function_exists ( 'mmb_post_create' )) { |
| 454 |
function mmb_post_create($params) |
| 455 |
{ |
| 456 |
global $mmb_core; |
| 457 |
$mmb_core->get_post_instance(); |
| 458 |
$return = $mmb_core->post_instance->create($params); |
| 459 |
if (is_int($return)) |
| 460 |
mmb_response($return, true); |
| 461 |
else{ |
| 462 |
if(isset($return['error'])){ |
| 463 |
mmb_response($return['error'], false); |
| 464 |
} else { |
| 465 |
mmb_response($return, false); |
| 466 |
} |
| 467 |
} |
| 468 |
} |
| 469 |
} |
| 470 |
|
| 471 |
if( !function_exists ( 'mmb_change_post_status' )) { |
| 472 |
function mmb_change_post_status($params) |
| 473 |
{ |
| 474 |
global $mmb_core; |
| 475 |
$mmb_core->get_post_instance(); |
| 476 |
$return = $mmb_core->post_instance->change_status($params); |
| 477 |
//mmb_response($return, true); |
| 478 |
|
| 479 |
} |
| 480 |
} |
| 481 |
|
| 482 |
//comments |
| 483 |
if( !function_exists ( 'mmb_change_comment_status' )) { |
| 484 |
function mmb_change_comment_status($params) |
| 485 |
{ |
| 486 |
global $mmb_core; |
| 487 |
$mmb_core->get_comment_instance(); |
| 488 |
$return = $mmb_core->comment_instance->change_status($params); |
| 489 |
//mmb_response($return, true); |
| 490 |
if ($return){ |
| 491 |
$mmb_core->get_stats_instance(); |
| 492 |
mmb_response($mmb_core->stats_instance->get_comments_stats($params), true); |
| 493 |
}else |
| 494 |
mmb_response('Comment not updated', false); |
| 495 |
} |
| 496 |
|
| 497 |
} |
| 498 |
if( !function_exists ( 'mmb_comment_stats_get' )) { |
| 499 |
function mmb_comment_stats_get($params) |
| 500 |
{ |
| 501 |
global $mmb_core; |
| 502 |
$mmb_core->get_stats_instance(); |
| 503 |
mmb_response($mmb_core->stats_instance->get_comments_stats($params), true); |
| 504 |
} |
| 505 |
} |
| 506 |
|
| 507 |
if( !function_exists ( 'mmb_backup_now' )) { |
| 508 |
//backup |
| 509 |
function mmb_backup_now($params) |
| 510 |
{ |
| 511 |
global $mmb_core; |
| 512 |
|
| 513 |
$mmb_core->get_backup_instance(); |
| 514 |
$return = $mmb_core->backup_instance->backup($params); |
| 515 |
|
| 516 |
if (is_array($return) && array_key_exists('error', $return)) |
| 517 |
mmb_response($return['error'], false); |
| 518 |
else { |
| 519 |
mmb_response($return, true); |
| 520 |
} |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
if( !function_exists ( 'mmb_run_task_now' )) { |
| 525 |
function mmb_run_task_now($params) |
| 526 |
{ |
| 527 |
global $mmb_core; |
| 528 |
$mmb_core->get_backup_instance(); |
| 529 |
|
| 530 |
$task_name = isset($params['task_name']) ? $params['task_name'] : false; |
| 531 |
$google_drive_token = isset($params['google_drive_token']) ? $params['google_drive_token'] : false; |
| 532 |
|
| 533 |
if ($task_name) { |
| 534 |
$return = $mmb_core->backup_instance->task_now($task_name, $google_drive_token); |
| 535 |
if (is_array($return) && array_key_exists('error', $return)) |
| 536 |
mmb_response($return['error'], false); |
| 537 |
else { |
| 538 |
mmb_response($return, true); |
| 539 |
} |
| 540 |
} else { |
| 541 |
mmb_response("Task name is not provided.", false); |
| 542 |
} |
| 543 |
|
| 544 |
} |
| 545 |
} |
| 546 |
|
| 547 |
if( !function_exists ( 'mmb_email_backup' )) { |
| 548 |
function mmb_email_backup($params) |
| 549 |
{ |
| 550 |
global $mmb_core; |
| 551 |
$mmb_core->get_backup_instance(); |
| 552 |
$return = $mmb_core->backup_instance->email_backup($params); |
| 553 |
|
| 554 |
if (is_array($return) && array_key_exists('error', $return)) |
| 555 |
mmb_response($return['error'], false); |
| 556 |
else { |
| 557 |
mmb_response($return, true); |
| 558 |
} |
| 559 |
} |
| 560 |
} |
| 561 |
|
| 562 |
if( !function_exists ( 'mmb_check_backup_compat' )) { |
| 563 |
function mmb_check_backup_compat($params) |
| 564 |
{ |
| 565 |
global $mmb_core; |
| 566 |
$mmb_core->get_backup_instance(); |
| 567 |
$return = $mmb_core->backup_instance->check_backup_compat($params); |
| 568 |
|
| 569 |
if (is_array($return) && array_key_exists('error', $return)) |
| 570 |
mmb_response($return['error'], false); |
| 571 |
else { |
| 572 |
mmb_response($return, true); |
| 573 |
} |
| 574 |
} |
| 575 |
} |
| 576 |
|
| 577 |
if( !function_exists ( 'mmb_get_backup_req' )) { |
| 578 |
function mmb_get_backup_req( $params ) |
| 579 |
{ |
| 580 |
global $mmb_core; |
| 581 |
$mmb_core->get_stats_instance(); |
| 582 |
$return = $mmb_core->stats_instance->get_backup_req($params); |
| 583 |
|
| 584 |
mmb_response($return, true); |
| 585 |
} |
| 586 |
} |
| 587 |
|
| 588 |
// Fires when Backup Now, or some backup task is saved. |
| 589 |
if( !function_exists ( 'mmb_scheduled_backup' )) { |
| 590 |
function mmb_scheduled_backup($params) |
| 591 |
{ |
| 592 |
global $mmb_core; |
| 593 |
$mmb_core->get_backup_instance(); |
| 594 |
$return = $mmb_core->backup_instance->set_backup_task($params); |
| 595 |
mmb_response($return, $return); |
| 596 |
} |
| 597 |
} |
| 598 |
|
| 599 |
if( !function_exists ( 'mmm_delete_backup' )) { |
| 600 |
function mmm_delete_backup($params) |
| 601 |
{ |
| 602 |
global $mmb_core; |
| 603 |
$mmb_core->get_backup_instance(); |
| 604 |
$return = $mmb_core->backup_instance->delete_backup($params); |
| 605 |
mmb_response($return, $return); |
| 606 |
} |
| 607 |
} |
| 608 |
|
| 609 |
if( !function_exists ( 'mmb_optimize_tables' )) { |
| 610 |
function mmb_optimize_tables($params) |
| 611 |
{ |
| 612 |
global $mmb_core; |
| 613 |
$mmb_core->get_backup_instance(); |
| 614 |
$return = $mmb_core->backup_instance->optimize_tables(); |
| 615 |
if ($return) |
| 616 |
mmb_response($return, true); |
| 617 |
else |
| 618 |
mmb_response(false, false); |
| 619 |
} |
| 620 |
} |
| 621 |
if( !function_exists ( 'mmb_restore_now' )) { |
| 622 |
function mmb_restore_now($params) |
| 623 |
{ |
| 624 |
global $mmb_core; |
| 625 |
$mmb_core->get_backup_instance(); |
| 626 |
$return = $mmb_core->backup_instance->restore($params); |
| 627 |
if (is_array($return) && array_key_exists('error', $return)) |
| 628 |
mmb_response($return['error'], false); |
| 629 |
else |
| 630 |
mmb_response($return, true); |
| 631 |
|
| 632 |
} |
| 633 |
} |
| 634 |
|
| 635 |
if( !function_exists ( 'mmb_remote_backup_now' )) { |
| 636 |
function mmb_remote_backup_now($params) |
| 637 |
{ |
| 638 |
global $mmb_core; |
| 639 |
$backup_instance = $mmb_core->get_backup_instance(); |
| 640 |
$return = $mmb_core->backup_instance->remote_backup_now($params); |
| 641 |
if (is_array($return) && array_key_exists('error', $return)) |
| 642 |
mmb_response($return['error'], false); |
| 643 |
else |
| 644 |
mmb_response($return, true); |
| 645 |
} |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
if( !function_exists ( 'mmb_clean_orphan_backups' )) { |
| 650 |
function mmb_clean_orphan_backups() |
| 651 |
{ |
| 652 |
global $mmb_core; |
| 653 |
$backup_instance = $mmb_core->get_backup_instance(); |
| 654 |
$return = $mmb_core->backup_instance->cleanup(); |
| 655 |
if(is_array($return)) |
| 656 |
mmb_response($return, true); |
| 657 |
else |
| 658 |
mmb_response($return, false); |
| 659 |
} |
| 660 |
} |
| 661 |
|
| 662 |
function mmb_run_backup_action() { |
| 663 |
if(isset($_POST['mmb_backup_nonce'])) |
| 664 |
if (!wp_verify_nonce($_POST['mmb_backup_nonce'], 'mmb-backup-nonce')) return false; |
| 665 |
$public_key = get_option('_worker_public_key'); |
| 666 |
if (!isset($_POST['public_key']) || $public_key !== $_POST['public_key']) return false; |
| 667 |
$args = @json_decode(stripslashes($_POST['args']), true); |
| 668 |
if (!$args) return false; |
| 669 |
$cron_action = isset($_POST['backup_cron_action']) ? $_POST['backup_cron_action'] : false; |
| 670 |
if ($cron_action) { |
| 671 |
do_action($cron_action, $args); |
| 672 |
} |
| 673 |
//unset($_POST['public_key']); |
| 674 |
unset($_POST['mmb_backup_nonce']); |
| 675 |
unset($_POST['args']); |
| 676 |
unset($_POST['backup_cron_action']); |
| 677 |
return true; |
| 678 |
} |
| 679 |
|
| 680 |
add_filter( 'mwp_website_add', 'mmb_readd_backup_task' ); |
| 681 |
|
| 682 |
if (!function_exists('mmb_readd_backup_task')) { |
| 683 |
function mmb_readd_backup_task($params = array()) { |
| 684 |
global $mmb_core; |
| 685 |
$backup_instance = $mmb_core->get_backup_instance(); |
| 686 |
$settings = $backup_instance->readd_tasks($params); |
| 687 |
return $settings; |
| 688 |
} |
| 689 |
} |
| 690 |
|
| 691 |
if( !function_exists ( 'mmb_update_worker_plugin' )) { |
| 692 |
function mmb_update_worker_plugin($params) |
| 693 |
{ |
| 694 |
global $mmb_core; |
| 695 |
mmb_response($mmb_core->update_worker_plugin($params), true); |
| 696 |
} |
| 697 |
} |
| 698 |
|
| 699 |
if( !function_exists ( 'mmb_wp_checkversion' )) { |
| 700 |
function mmb_wp_checkversion($params) |
| 701 |
{ |
| 702 |
include_once(ABSPATH . 'wp-includes/version.php'); |
| 703 |
global $mmb_wp_version, $mmb_core; |
| 704 |
mmb_response($mmb_wp_version, true); |
| 705 |
} |
| 706 |
} |
| 707 |
if( !function_exists ( 'mmb_search_posts_by_term' )) { |
| 708 |
function mmb_search_posts_by_term($params) |
| 709 |
{ |
| 710 |
global $mmb_core; |
| 711 |
$mmb_core->get_search_instance(); |
| 712 |
|
| 713 |
$search_type = trim($params['search_type']); |
| 714 |
$search_term = strtolower(trim($params['search_term'])); |
| 715 |
|
| 716 |
switch ($search_type){ |
| 717 |
case 'page_post': |
| 718 |
$return = $mmb_core->search_instance->search_posts_by_term($params); |
| 719 |
if($return){ |
| 720 |
$return = serialize($return); |
| 721 |
mmb_response($return, true); |
| 722 |
}else{ |
| 723 |
mmb_response('No posts found', false); |
| 724 |
} |
| 725 |
break; |
| 726 |
|
| 727 |
case 'plugin': |
| 728 |
$plugins = get_option('active_plugins'); |
| 729 |
|
| 730 |
$have_plugin = false; |
| 731 |
foreach ($plugins as $plugin) { |
| 732 |
if(strpos($plugin, $search_term)>-1){ |
| 733 |
$have_plugin = true; |
| 734 |
} |
| 735 |
} |
| 736 |
if($have_plugin){ |
| 737 |
mmb_response(serialize($plugin), true); |
| 738 |
}else{ |
| 739 |
mmb_response(false, false); |
| 740 |
} |
| 741 |
break; |
| 742 |
case 'theme': |
| 743 |
$theme = strtolower(get_option('template')); |
| 744 |
if(strpos($theme, $search_term)>-1){ |
| 745 |
mmb_response($theme, true); |
| 746 |
}else{ |
| 747 |
mmb_response(false, false); |
| 748 |
} |
| 749 |
break; |
| 750 |
default: mmb_response(false, false); |
| 751 |
} |
| 752 |
$return = $mmb_core->search_instance->search_posts_by_term($params); |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
if ($return_if_true) { |
| 757 |
mmb_response($return_value, true); |
| 758 |
} else { |
| 759 |
mmb_response($return_if_false, false); |
| 760 |
} |
| 761 |
} |
| 762 |
} |
| 763 |
|
| 764 |
if( !function_exists ( 'mmb_install_addon' )) { |
| 765 |
function mmb_install_addon($params) |
| 766 |
{ |
| 767 |
global $mmb_core; |
| 768 |
$mmb_core->get_installer_instance(); |
| 769 |
$return = $mmb_core->installer_instance->install_remote_file($params); |
| 770 |
mmb_response($return, true); |
| 771 |
|
| 772 |
} |
| 773 |
} |
| 774 |
|
| 775 |
if( !function_exists ( 'mmb_do_upgrade' )) { |
| 776 |
function mmb_do_upgrade($params) |
| 777 |
{ |
| 778 |
global $mmb_core, $mmb_upgrading; |
| 779 |
$mmb_core->get_installer_instance(); |
| 780 |
$return = $mmb_core->installer_instance->do_upgrade($params); |
| 781 |
mmb_response($return, true); |
| 782 |
|
| 783 |
} |
| 784 |
} |
| 785 |
|
| 786 |
if( !function_exists ('mmb_get_links')) { |
| 787 |
function mmb_get_links($params) |
| 788 |
{ |
| 789 |
global $mmb_core; |
| 790 |
$mmb_core->get_link_instance(); |
| 791 |
$return = $mmb_core->link_instance->get_links($params); |
| 792 |
if (is_array($return) && array_key_exists('error', $return)) |
| 793 |
mmb_response($return['error'], false); |
| 794 |
else { |
| 795 |
mmb_response($return, true); |
| 796 |
} |
| 797 |
} |
| 798 |
} |
| 799 |
|
| 800 |
if( !function_exists ( 'mmb_add_link' )) { |
| 801 |
function mmb_add_link($params) |
| 802 |
{ |
| 803 |
global $mmb_core; |
| 804 |
$mmb_core->get_link_instance(); |
| 805 |
$return = $mmb_core->link_instance->add_link($params); |
| 806 |
if (is_array($return) && array_key_exists('error', $return)) |
| 807 |
|
| 808 |
mmb_response($return['error'], false); |
| 809 |
else { |
| 810 |
mmb_response($return, true); |
| 811 |
} |
| 812 |
|
| 813 |
} |
| 814 |
} |
| 815 |
|
| 816 |
if( !function_exists ('mmb_delete_link')) { |
| 817 |
function mmb_delete_link($params) |
| 818 |
{ |
| 819 |
global $mmb_core; |
| 820 |
$mmb_core->get_link_instance(); |
| 821 |
|
| 822 |
$return = $mmb_core->link_instance->delete_link($params); |
| 823 |
if (is_array($return) && array_key_exists('error', $return)) |
| 824 |
mmb_response($return['error'], false); |
| 825 |
else { |
| 826 |
mmb_response($return, true); |
| 827 |
} |
| 828 |
} |
| 829 |
} |
| 830 |
|
| 831 |
if( !function_exists ('mmb_delete_links')) { |
| 832 |
function mmb_delete_links($params) |
| 833 |
{ |
| 834 |
global $mmb_core; |
| 835 |
$mmb_core->get_link_instance(); |
| 836 |
|
| 837 |
$return = $mmb_core->link_instance->delete_links($params); |
| 838 |
if (is_array($return) && array_key_exists('error', $return)) |
| 839 |
mmb_response($return['error'], false); |
| 840 |
else { |
| 841 |
mmb_response($return, true); |
| 842 |
} |
| 843 |
} |
| 844 |
} |
| 845 |
|
| 846 |
if( !function_exists ('mmb_get_comments')) { |
| 847 |
function mmb_get_comments($params) |
| 848 |
{ |
| 849 |
global $mmb_core; |
| 850 |
$mmb_core->get_comment_instance(); |
| 851 |
$return = $mmb_core->comment_instance->get_comments($params); |
| 852 |
if (is_array($return) && array_key_exists('error', $return)) |
| 853 |
mmb_response($return['error'], false); |
| 854 |
else { |
| 855 |
mmb_response($return, true); |
| 856 |
} |
| 857 |
} |
| 858 |
} |
| 859 |
|
| 860 |
if( !function_exists ('mmb_action_comment')) { |
| 861 |
function mmb_action_comment($params) |
| 862 |
{ |
| 863 |
global $mmb_core; |
| 864 |
$mmb_core->get_comment_instance(); |
| 865 |
|
| 866 |
$return = $mmb_core->comment_instance->action_comment($params); |
| 867 |
if (is_array($return) && array_key_exists('error', $return)) |
| 868 |
mmb_response($return['error'], false); |
| 869 |
else { |
| 870 |
mmb_response($return, true); |
| 871 |
} |
| 872 |
} |
| 873 |
} |
| 874 |
|
| 875 |
if( !function_exists ('mmb_bulk_action_comments')) { |
| 876 |
function mmb_bulk_action_comments($params) |
| 877 |
{ |
| 878 |
global $mmb_core; |
| 879 |
$mmb_core->get_comment_instance(); |
| 880 |
|
| 881 |
$return = $mmb_core->comment_instance->bulk_action_comments($params); |
| 882 |
if (is_array($return) && array_key_exists('error', $return)) |
| 883 |
mmb_response($return['error'], false); |
| 884 |
else { |
| 885 |
mmb_response($return, true); |
| 886 |
} |
| 887 |
} |
| 888 |
} |
| 889 |
|
| 890 |
if( !function_exists ('mmb_reply_comment')) { |
| 891 |
function mmb_reply_comment($params) |
| 892 |
{ |
| 893 |
global $mmb_core; |
| 894 |
$mmb_core->get_comment_instance(); |
| 895 |
|
| 896 |
$return = $mmb_core->comment_instance->reply_comment($params); |
| 897 |
if (is_array($return) && array_key_exists('error', $return)) |
| 898 |
mmb_response($return['error'], false); |
| 899 |
else { |
| 900 |
mmb_response($return, true); |
| 901 |
} |
| 902 |
} |
| 903 |
} |
| 904 |
|
| 905 |
if( !function_exists ( 'mmb_add_user' )) { |
| 906 |
function mmb_add_user($params) |
| 907 |
{ |
| 908 |
global $mmb_core; |
| 909 |
$mmb_core->get_user_instance(); |
| 910 |
$return = $mmb_core->user_instance->add_user($params); |
| 911 |
if (is_array($return) && array_key_exists('error', $return)) |
| 912 |
|
| 913 |
mmb_response($return['error'], false); |
| 914 |
else { |
| 915 |
mmb_response($return, true); |
| 916 |
} |
| 917 |
|
| 918 |
} |
| 919 |
} |
| 920 |
|
| 921 |
if( !function_exists ( 'mbb_security_check' )) { |
| 922 |
function mbb_security_check($params) |
| 923 |
{ |
| 924 |
global $mmb_core; |
| 925 |
$mmb_core->get_security_instance(); |
| 926 |
$return = $mmb_core->security_instance->security_check($params); |
| 927 |
if (is_array($return) && array_key_exists('error', $return)) |
| 928 |
mmb_response($return['error'], false); |
| 929 |
else { |
| 930 |
mmb_response($return, true); |
| 931 |
} |
| 932 |
|
| 933 |
} |
| 934 |
} |
| 935 |
|
| 936 |
if( !function_exists ( 'mbb_security_fix_folder_listing' )) { |
| 937 |
function mbb_security_fix_folder_listing($params) |
| 938 |
{ |
| 939 |
global $mmb_core; |
| 940 |
$mmb_core->get_security_instance(); |
| 941 |
$return = $mmb_core->security_instance->security_fix_dir_listing($params); |
| 942 |
if (is_array($return) && array_key_exists('error', $return)) |
| 943 |
mmb_response($return['error'], false); |
| 944 |
else { |
| 945 |
mmb_response($return, true); |
| 946 |
} |
| 947 |
|
| 948 |
} |
| 949 |
} |
| 950 |
|
| 951 |
if( !function_exists ( 'mbb_security_fix_php_reporting' )) { |
| 952 |
function mbb_security_fix_php_reporting($params) |
| 953 |
{ |
| 954 |
global $mmb_core; |
| 955 |
$mmb_core->get_security_instance(); |
| 956 |
$return = $mmb_core->security_instance->security_fix_php_reporting($params); |
| 957 |
if (is_array($return) && array_key_exists('error', $return)) |
| 958 |
mmb_response($return['error'], false); |
| 959 |
else { |
| 960 |
mmb_response($return, true); |
| 961 |
} |
| 962 |
|
| 963 |
} |
| 964 |
} |
| 965 |
|
| 966 |
if( !function_exists ( 'mbb_security_fix_database_reporting' )) { |
| 967 |
function mbb_security_fix_database_reporting($params) |
| 968 |
{ |
| 969 |
global $mmb_core; |
| 970 |
$mmb_core->get_security_instance(); |
| 971 |
$return = $mmb_core->security_instance->security_fix_database_reporting($params); |
| 972 |
if (is_array($return) && array_key_exists('error', $return)) |
| 973 |
mmb_response($return['error'], false); |
| 974 |
else { |
| 975 |
mmb_response($return, true); |
| 976 |
} |
| 977 |
|
| 978 |
} |
| 979 |
} |
| 980 |
|
| 981 |
//security_fix_wp_version |
| 982 |
|
| 983 |
if( !function_exists ( 'mbb_security_fix_wp_version' )) { |
| 984 |
function mbb_security_fix_wp_version($params) |
| 985 |
{ |
| 986 |
global $mmb_core; |
| 987 |
$mmb_core->get_security_instance(); |
| 988 |
$return = $mmb_core->security_instance->security_fix_wp_version($params); |
| 989 |
if (is_array($return) && array_key_exists('error', $return)) |
| 990 |
mmb_response($return['error'], false); |
| 991 |
else { |
| 992 |
mmb_response($return, true); |
| 993 |
} |
| 994 |
|
| 995 |
} |
| 996 |
} |
| 997 |
|
| 998 |
//mbb_security_fix_admin_username |
| 999 |
|
| 1000 |
if( !function_exists ( 'mbb_security_fix_admin_username' )) { |
| 1001 |
function mbb_security_fix_admin_username($params) |
| 1002 |
{ |
| 1003 |
global $mmb_core; |
| 1004 |
$mmb_core->get_security_instance(); |
| 1005 |
$return = $mmb_core->security_instance->security_fix_admin_username($params); |
| 1006 |
if (is_array($return) && array_key_exists('error', $return)) |
| 1007 |
mmb_response($return['error'], false); |
| 1008 |
else { |
| 1009 |
mmb_response($return, true); |
| 1010 |
} |
| 1011 |
|
| 1012 |
} |
| 1013 |
} |
| 1014 |
|
| 1015 |
if( !function_exists ( 'mbb_security_fix_scripts_styles' )) { |
| 1016 |
function mbb_security_fix_scripts_styles($params) |
| 1017 |
{ |
| 1018 |
global $mmb_core; |
| 1019 |
$mmb_core->get_security_instance(); |
| 1020 |
$return = $mmb_core->security_instance->security_fix_scripts_styles($params); |
| 1021 |
if (is_array($return) && array_key_exists('error', $return)) |
| 1022 |
mmb_response($return['error'], false); |
| 1023 |
else { |
| 1024 |
mmb_response($return, true); |
| 1025 |
} |
| 1026 |
|
| 1027 |
} |
| 1028 |
} |
| 1029 |
|
| 1030 |
//mbb_security_fix_file_permission |
| 1031 |
if( !function_exists ( 'mbb_security_fix_file_permission' )) { |
| 1032 |
function mbb_security_fix_file_permission($params) |
| 1033 |
{ |
| 1034 |
global $mmb_core; |
| 1035 |
$mmb_core->get_security_instance(); |
| 1036 |
$return = $mmb_core->security_instance->security_fix_permissions($params); |
| 1037 |
if (is_array($return) && array_key_exists('error', $return)) |
| 1038 |
mmb_response($return['error'], false); |
| 1039 |
else { |
| 1040 |
mmb_response($return, true); |
| 1041 |
} |
| 1042 |
|
| 1043 |
} |
| 1044 |
} |
| 1045 |
|
| 1046 |
//mbb_security_fix_all |
| 1047 |
if( !function_exists ( 'mbb_security_fix_all' )) { |
| 1048 |
function mbb_security_fix_all($params) |
| 1049 |
{ |
| 1050 |
global $mmb_core; |
| 1051 |
$mmb_core->get_security_instance(); |
| 1052 |
$return = $mmb_core->security_instance->security_fix_all($params); |
| 1053 |
if (is_array($return) && array_key_exists('error', $return)) |
| 1054 |
mmb_response($return['error'], false); |
| 1055 |
else { |
| 1056 |
mmb_response($return, true); |
| 1057 |
} |
| 1058 |
} |
| 1059 |
} |
| 1060 |
|
| 1061 |
//mbb_security_fix_htaccess_permission |
| 1062 |
|
| 1063 |
if( !function_exists ( 'mbb_security_fix_htaccess_permission' )) { |
| 1064 |
function mbb_security_fix_htaccess_permission($params) |
| 1065 |
{ |
| 1066 |
global $mmb_core; |
| 1067 |
$mmb_core->get_security_instance(); |
| 1068 |
$return = $mmb_core->security_instance->security_fix_htaccess_permission($params); |
| 1069 |
if (is_array($return) && array_key_exists('error', $return)) |
| 1070 |
mmb_response($return['error'], false); |
| 1071 |
else { |
| 1072 |
mmb_response($return, true); |
| 1073 |
} |
| 1074 |
|
| 1075 |
} |
| 1076 |
} |
| 1077 |
|
| 1078 |
if( !function_exists ('mmb_get_users')) { |
| 1079 |
function mmb_get_users($params) |
| 1080 |
{ |
| 1081 |
global $mmb_core; |
| 1082 |
$mmb_core->get_user_instance(); |
| 1083 |
$return = $mmb_core->user_instance->get_users($params); |
| 1084 |
if (is_array($return) && array_key_exists('error', $return)) |
| 1085 |
mmb_response($return['error'], false); |
| 1086 |
else { |
| 1087 |
mmb_response($return, true); |
| 1088 |
} |
| 1089 |
} |
| 1090 |
} |
| 1091 |
|
| 1092 |
if( !function_exists ('mmb_edit_users')) { |
| 1093 |
function mmb_edit_users($params) |
| 1094 |
{ |
| 1095 |
global $mmb_core; |
| 1096 |
$mmb_core->get_user_instance(); |
| 1097 |
$users = $mmb_core->user_instance->edit_users($params); |
| 1098 |
$response = 'User updated.'; |
| 1099 |
$check_error = false; |
| 1100 |
foreach ($users as $username => $user) { |
| 1101 |
$check_error = array_key_exists('error', $user); |
| 1102 |
if($check_error){ |
| 1103 |
$response = $username.': '.$user['error']; |
| 1104 |
} |
| 1105 |
} |
| 1106 |
mmb_response($response, !$check_error); |
| 1107 |
} |
| 1108 |
} |
| 1109 |
|
| 1110 |
if( !function_exists ('mmb_get_posts')) { |
| 1111 |
function mmb_get_posts($params) |
| 1112 |
{ |
| 1113 |
global $mmb_core; |
| 1114 |
$mmb_core->get_post_instance(); |
| 1115 |
|
| 1116 |
$return = $mmb_core->post_instance->get_posts($params); |
| 1117 |
if (is_array($return) && array_key_exists('error', $return)) |
| 1118 |
mmb_response($return['error'], false); |
| 1119 |
else { |
| 1120 |
mmb_response($return, true); |
| 1121 |
} |
| 1122 |
} |
| 1123 |
} |
| 1124 |
|
| 1125 |
if( !function_exists ('mmb_delete_post')) { |
| 1126 |
function mmb_delete_post($params) |
| 1127 |
{ |
| 1128 |
global $mmb_core; |
| 1129 |
$mmb_core->get_post_instance(); |
| 1130 |
|
| 1131 |
$return = $mmb_core->post_instance->delete_post($params); |
| 1132 |
if (is_array($return) && array_key_exists('error', $return)) |
| 1133 |
mmb_response($return['error'], false); |
| 1134 |
else { |
| 1135 |
mmb_response($return, true); |
| 1136 |
} |
| 1137 |
} |
| 1138 |
} |
| 1139 |
|
| 1140 |
if( !function_exists ('mmb_delete_posts')) { |
| 1141 |
function mmb_delete_posts($params) |
| 1142 |
{ |
| 1143 |
global $mmb_core; |
| 1144 |
$mmb_core->get_post_instance(); |
| 1145 |
|
| 1146 |
$return = $mmb_core->post_instance->delete_posts($params); |
| 1147 |
if (is_array($return) && array_key_exists('error', $return)) |
| 1148 |
mmb_response($return['error'], false); |
| 1149 |
else { |
| 1150 |
mmb_response($return, true); |
| 1151 |
} |
| 1152 |
} |
| 1153 |
} |
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
if( !function_exists ('mmb_edit_posts')) { |
| 1158 |
function mmb_edit_posts($params) |
| 1159 |
{ |
| 1160 |
global $mmb_core; |
| 1161 |
$mmb_core->get_posts_instance(); |
| 1162 |
$return = $mmb_core->posts_instance->edit_posts($params); |
| 1163 |
mmb_response($return, true); |
| 1164 |
} |
| 1165 |
} |
| 1166 |
|
| 1167 |
if( !function_exists ('mmb_get_pages')) { |
| 1168 |
function mmb_get_pages($params) |
| 1169 |
{ |
| 1170 |
global $mmb_core; |
| 1171 |
$mmb_core->get_post_instance(); |
| 1172 |
|
| 1173 |
$return = $mmb_core->post_instance->get_pages($params); |
| 1174 |
if (is_array($return) && array_key_exists('error', $return)) |
| 1175 |
mmb_response($return['error'], false); |
| 1176 |
else { |
| 1177 |
mmb_response($return, true); |
| 1178 |
} |
| 1179 |
} |
| 1180 |
} |
| 1181 |
|
| 1182 |
if( !function_exists ('mmb_delete_page')) { |
| 1183 |
function mmb_delete_page($params) |
| 1184 |
{ |
| 1185 |
global $mmb_core; |
| 1186 |
$mmb_core->get_post_instance(); |
| 1187 |
|
| 1188 |
$return = $mmb_core->post_instance->delete_page($params); |
| 1189 |
if (is_array($return) && array_key_exists('error', $return)) |
| 1190 |
mmb_response($return['error'], false); |
| 1191 |
else { |
| 1192 |
mmb_response($return, true); |
| 1193 |
} |
| 1194 |
} |
| 1195 |
} |
| 1196 |
|
| 1197 |
if( !function_exists ( 'mmb_iframe_plugins_fix' )) { |
| 1198 |
function mmb_iframe_plugins_fix($update_actions) |
| 1199 |
{ |
| 1200 |
foreach($update_actions as $key => $action) |
| 1201 |
{ |
| 1202 |
$update_actions[$key] = str_replace('target="_parent"','',$action); |
| 1203 |
} |
| 1204 |
|
| 1205 |
return $update_actions; |
| 1206 |
|
| 1207 |
} |
| 1208 |
} |
| 1209 |
if( !function_exists ( 'mmb_execute_php_code' )) { |
| 1210 |
function mmb_execute_php_code($params) |
| 1211 |
{ |
| 1212 |
ob_start(); |
| 1213 |
eval($params['code']); |
| 1214 |
$return = ob_get_flush(); |
| 1215 |
mmb_response(print_r($return, true), true); |
| 1216 |
} |
| 1217 |
} |
| 1218 |
|
| 1219 |
if( !function_exists ( 'mmb_set_notifications' )) { |
| 1220 |
function mmb_set_notifications($params) |
| 1221 |
{ |
| 1222 |
global $mmb_core; |
| 1223 |
$mmb_core->get_stats_instance(); |
| 1224 |
$return = $mmb_core->stats_instance->set_notifications($params); |
| 1225 |
if (is_array($return) && array_key_exists('error', $return)) |
| 1226 |
mmb_response($return['error'], false); |
| 1227 |
else { |
| 1228 |
mmb_response($return, true); |
| 1229 |
} |
| 1230 |
|
| 1231 |
} |
| 1232 |
} |
| 1233 |
|
| 1234 |
if( !function_exists ('mmb_get_dbname')) { |
| 1235 |
function mmb_get_dbname($params) |
| 1236 |
{ |
| 1237 |
global $mmb_core; |
| 1238 |
$mmb_core->get_stats_instance(); |
| 1239 |
|
| 1240 |
$return = $mmb_core->stats_instance->get_active_db(); |
| 1241 |
if (is_array($return) && array_key_exists('error', $return)) |
| 1242 |
mmb_response($return['error'], false); |
| 1243 |
else { |
| 1244 |
mmb_response($return, true); |
| 1245 |
} |
| 1246 |
} |
| 1247 |
} |
| 1248 |
|
| 1249 |
if( !function_exists('mmb_more_reccurences') ){ |
| 1250 |
//Backup Tasks |
| 1251 |
add_filter('cron_schedules', 'mmb_more_reccurences'); |
| 1252 |
function mmb_more_reccurences($schedules) { |
| 1253 |
$schedules['halfminute'] = array('interval' => 30, 'display' => 'Once in a half minute'); |
| 1254 |
$schedules['minutely'] = array('interval' => 60, 'display' => 'Once in a minute'); |
| 1255 |
$schedules['fiveminutes'] = array('interval' => 300, 'display' => 'Once every five minutes'); |
| 1256 |
$schedules['tenminutes'] = array('interval' => 600, 'display' => 'Once every ten minutes'); |
| 1257 |
$schedules['sixhours'] = array('interval' => 21600, 'display' => 'Every six hours'); |
| 1258 |
$schedules['fourhours'] = array('interval' => 14400, 'display' => 'Every four hours'); |
| 1259 |
$schedules['threehours'] = array('interval' => 10800, 'display' => 'Every three hours'); |
| 1260 |
|
| 1261 |
return $schedules; |
| 1262 |
} |
| 1263 |
} |
| 1264 |
|
| 1265 |
add_action('mwp_backup_tasks', 'mwp_check_backup_tasks'); |
| 1266 |
|
| 1267 |
if( !function_exists('mwp_check_backup_tasks') ){ |
| 1268 |
function mwp_check_backup_tasks() { |
| 1269 |
global $mmb_core, $_wp_using_ext_object_cache; |
| 1270 |
$_wp_using_ext_object_cache = false; |
| 1271 |
$mmb_core->get_backup_instance(); |
| 1272 |
$mmb_core->backup_instance->check_backup_tasks(); |
| 1273 |
} |
| 1274 |
} |
| 1275 |
|
| 1276 |
// Remote upload in the second request. |
| 1277 |
// add_action('mmb_scheduled_remote_upload', 'mmb_call_scheduled_remote_upload'); |
| 1278 |
add_action('mmb_remote_upload', 'mmb_call_scheduled_remote_upload'); |
| 1279 |
|
| 1280 |
if( !function_exists('mmb_call_scheduled_remote_upload') ){ |
| 1281 |
function mmb_call_scheduled_remote_upload($args) { |
| 1282 |
global $mmb_core, $_wp_using_ext_object_cache; |
| 1283 |
$_wp_using_ext_object_cache = false; |
| 1284 |
|
| 1285 |
$mmb_core->get_backup_instance(); |
| 1286 |
if (isset($args['task_name'])) { |
| 1287 |
$mmb_core->backup_instance->remote_backup_now($args); |
| 1288 |
} |
| 1289 |
} |
| 1290 |
} |
| 1291 |
|
| 1292 |
// if (!wp_next_scheduled('mwp_notifications')) { |
| 1293 |
// wp_schedule_event( time(), 'twicedaily', 'mwp_notifications' ); |
| 1294 |
// } |
| 1295 |
// add_action('mwp_notifications', 'mwp_check_notifications'); |
| 1296 |
|
| 1297 |
if (!wp_next_scheduled('mwp_datasend')) { |
| 1298 |
wp_schedule_event( time(), 'threehours', 'mwp_datasend' ); |
| 1299 |
} |
| 1300 |
|
| 1301 |
add_action('mwp_datasend', 'mwp_datasend'); |
| 1302 |
|
| 1303 |
if( !function_exists('mwp_check_notifications') ){ |
| 1304 |
function mwp_check_notifications() { |
| 1305 |
global $mmb_core, $_wp_using_ext_object_cache; |
| 1306 |
$_wp_using_ext_object_cache = false; |
| 1307 |
|
| 1308 |
$mmb_core->get_stats_instance(); |
| 1309 |
$mmb_core->stats_instance->check_notifications(); |
| 1310 |
} |
| 1311 |
} |
| 1312 |
|
| 1313 |
|
| 1314 |
if( !function_exists('mmb_get_plugins_themes') ){ |
| 1315 |
function mmb_get_plugins_themes($params) { |
| 1316 |
global $mmb_core; |
| 1317 |
$mmb_core->get_installer_instance(); |
| 1318 |
$return = $mmb_core->installer_instance->get($params); |
| 1319 |
mmb_response($return, true); |
| 1320 |
} |
| 1321 |
} |
| 1322 |
|
| 1323 |
|
| 1324 |
if( !function_exists('mmb_get_autoupdate_plugins_themes') ){ |
| 1325 |
function mmb_get_autoupdate_plugins_themes($params) { |
| 1326 |
$return = MWP_Updater::getSettings($params); |
| 1327 |
mmb_response($return, true); |
| 1328 |
} |
| 1329 |
} |
| 1330 |
|
| 1331 |
if( !function_exists('mmb_edit_plugins_themes') ){ |
| 1332 |
function mmb_edit_plugins_themes($params) { |
| 1333 |
global $mmb_core; |
| 1334 |
$mmb_core->get_installer_instance(); |
| 1335 |
$return = $mmb_core->installer_instance->edit($params); |
| 1336 |
mmb_response($return, true); |
| 1337 |
} |
| 1338 |
} |
| 1339 |
|
| 1340 |
if( !function_exists('mmb_edit_autoupdate_plugins_themes') ){ |
| 1341 |
function mmb_edit_autoupdate_plugins_themes($params) { |
| 1342 |
$return = MWP_Updater::setSettings($params); |
| 1343 |
mmb_response($return, true); |
| 1344 |
} |
| 1345 |
} |
| 1346 |
|
| 1347 |
if( !function_exists('mmb_worker_brand')){ |
| 1348 |
function mmb_worker_brand($params) { |
| 1349 |
update_option("mwp_worker_brand",$params['brand']); |
| 1350 |
mmb_response(true, true); |
| 1351 |
} |
| 1352 |
} |
| 1353 |
|
| 1354 |
if( !function_exists('mmb_maintenance_mode')){ |
| 1355 |
function mmb_maintenance_mode( $params ) { |
| 1356 |
global $wp_object_cache; |
| 1357 |
|
| 1358 |
$default = get_option('mwp_maintenace_mode'); |
| 1359 |
$params = empty($default) ? $params : array_merge($default, $params); |
| 1360 |
update_option("mwp_maintenace_mode", $params); |
| 1361 |
|
| 1362 |
if(!empty($wp_object_cache)) |
| 1363 |
@$wp_object_cache->flush(); |
| 1364 |
mmb_response(true, true); |
| 1365 |
} |
| 1366 |
} |
| 1367 |
|
| 1368 |
if( !function_exists('mmb_plugin_actions') ){ |
| 1369 |
function mmb_plugin_actions() { |
| 1370 |
global $mmb_actions, $mmb_core; |
| 1371 |
|
| 1372 |
if(!empty($mmb_actions)){ |
| 1373 |
global $_mmb_plugin_actions; |
| 1374 |
if(!empty($_mmb_plugin_actions)){ |
| 1375 |
$failed = array(); |
| 1376 |
foreach($_mmb_plugin_actions as $action => $params){ |
| 1377 |
if(isset($mmb_actions[$action])) |
| 1378 |
call_user_func($mmb_actions[$action], $params); |
| 1379 |
else |
| 1380 |
$failed[] = $action; |
| 1381 |
} |
| 1382 |
if(!empty($failed)){ |
| 1383 |
$f = implode(', ', $failed); |
| 1384 |
$s = count($f) > 1 ? 'Actions "' . $f . '" do' : 'Action "' . $f . '" does'; |
| 1385 |
mmb_response($s.' not exist. Please update your Worker plugin.', false); |
| 1386 |
} |
| 1387 |
|
| 1388 |
} |
| 1389 |
} |
| 1390 |
|
| 1391 |
global $pagenow, $current_user, $mmode; |
| 1392 |
if( !is_admin() && !in_array($pagenow, array( 'wp-login.php' ))){ |
| 1393 |
$mmode = get_option('mwp_maintenace_mode'); |
| 1394 |
if( !empty($mmode) ){ |
| 1395 |
if(isset($mmode['active']) && $mmode['active'] == true){ |
| 1396 |
if(isset($current_user->data) && !empty($current_user->data) && isset($mmode['hidecaps']) && !empty($mmode['hidecaps'])){ |
| 1397 |
$usercaps = array(); |
| 1398 |
if(isset($current_user->caps) && !empty($current_user->caps)){ |
| 1399 |
$usercaps = $current_user->caps; |
| 1400 |
} |
| 1401 |
foreach($mmode['hidecaps'] as $cap => $hide){ |
| 1402 |
if(!$hide) |
| 1403 |
continue; |
| 1404 |
|
| 1405 |
foreach($usercaps as $ucap => $val){ |
| 1406 |
if($ucap == $cap){ |
| 1407 |
ob_end_clean(); |
| 1408 |
ob_end_flush(); |
| 1409 |
die($mmode['template']); |
| 1410 |
} |
| 1411 |
} |
| 1412 |
} |
| 1413 |
} else |
| 1414 |
die($mmode['template']); |
| 1415 |
} |
| 1416 |
} |
| 1417 |
} |
| 1418 |
|
| 1419 |
if (file_exists(dirname(__FILE__) . '/log')) { |
| 1420 |
unlink(dirname(__FILE__) . '/log'); |
| 1421 |
} |
| 1422 |
} |
| 1423 |
} |
| 1424 |
|
| 1425 |
$mmb_core = new MMB_Core(); |
| 1426 |
|
| 1427 |
if(isset($_GET['auto_login'])) |
| 1428 |
$mmb_core->automatic_login(); |
| 1429 |
|
| 1430 |
require_once dirname(__FILE__) . '/updater.php'; |
| 1431 |
MWP_Updater::register(); |
| 1432 |
|
| 1433 |
if (function_exists('register_activation_hook')) |
| 1434 |
register_activation_hook( __FILE__ , array( $mmb_core, 'install' )); |
| 1435 |
|
| 1436 |
if (function_exists('register_deactivation_hook')) |
| 1437 |
register_deactivation_hook(__FILE__, array( $mmb_core, 'uninstall' )); |
| 1438 |
|
| 1439 |
if (function_exists('add_action')) |
| 1440 |
add_action('init', 'mmb_plugin_actions', 99999); |
| 1441 |
|
| 1442 |
if (function_exists('add_filter')) |
| 1443 |
add_filter('install_plugin_complete_actions','mmb_iframe_plugins_fix'); |
| 1444 |
|
| 1445 |
if(!function_exists('mwb_edit_redirect_override')){ |
| 1446 |
function mwb_edit_redirect_override($location = false, $comment_id = false){ |
| 1447 |
if(isset($_COOKIE[MMB_XFRAME_COOKIE])){ |
| 1448 |
$location = get_site_url().'/wp-admin/edit-comments.php'; |
| 1449 |
} |
| 1450 |
return $location; |
| 1451 |
} |
| 1452 |
} |
| 1453 |
if (function_exists('add_filter')) |
| 1454 |
add_filter('comment_edit_redirect', 'mwb_edit_redirect_override'); |
| 1455 |
|
| 1456 |
if( isset($_COOKIE[MMB_XFRAME_COOKIE]) ){ |
| 1457 |
remove_action( 'admin_init', 'send_frame_options_header'); |
| 1458 |
remove_action( 'login_init', 'send_frame_options_header'); |
| 1459 |
} |
| 1460 |
function mwp_error_handler($errno, $errstr, $errfile, $errline, $errcontext) |
| 1461 |
{ |
| 1462 |
$errorId = 'mwp_error_' . md5($errfile . $errline); |
| 1463 |
$error = sprintf("%s\nError [%s]: %s\nIn file: %s:%s", date('Y-m-d H:i:s'), $errno, $errstr, $errfile, $errline); |
| 1464 |
set_transient($errorId, $error, 3600); |
| 1465 |
} |
| 1466 |
|
| 1467 |
function mwp_fatal_error_handler() |
| 1468 |
{ |
| 1469 |
$isError = false; |
| 1470 |
if ($error = error_get_last()) { |
| 1471 |
switch ($error['type']) { |
| 1472 |
case E_ERROR: |
| 1473 |
case E_CORE_ERROR: |
| 1474 |
case E_COMPILE_ERROR: |
| 1475 |
case E_USER_ERROR: |
| 1476 |
$isError = true; |
| 1477 |
break; |
| 1478 |
} |
| 1479 |
} |
| 1480 |
if ($isError) { |
| 1481 |
mwp_error_handler($error['type'], $error['message'], $error['file'], $error['line'], array()); |
| 1482 |
} |
| 1483 |
} |
| 1484 |
|
| 1485 |
|
| 1486 |
if (get_option('mwp_debug_enable')) { |
| 1487 |
set_error_handler('mwp_error_handler'); |
| 1488 |
register_shutdown_function('mwp_fatal_error_handler'); |
| 1489 |
} |
| 1490 |
|
| 1491 |
if (get_option('mwp_remove_php_reporting') == 'T') |
| 1492 |
{ |
| 1493 |
@error_reporting(0); |
| 1494 |
@ini_set('display_errors', 'off'); |
| 1495 |
@ini_set('display_startup_errors', "off"); |
| 1496 |
} |
| 1497 |
|
| 1498 |
if (get_option('mwp_remove_wp_version') == 'T') |
| 1499 |
{ |
| 1500 |
remove_action('wp_head', 'wp_generator'); |
| 1501 |
remove_filter('wp_head', 'wp_generator'); |
| 1502 |
} |
| 1503 |
if (get_option('managewp_remove_styles_version') == 'T') |
| 1504 |
{ |
| 1505 |
global $wp_styles; |
| 1506 |
if (!is_a($wp_styles, 'WP_Styles')) |
| 1507 |
return; |
| 1508 |
|
| 1509 |
foreach ($wp_styles->registered as $handle => $style) |
| 1510 |
$wp_styles->registered[$handle]->ver = null; |
| 1511 |
} |
| 1512 |
if (get_option('managewp_remove_scripts_version') == 'T') |
| 1513 |
{ |
| 1514 |
global $wp_scripts; |
| 1515 |
if (!is_a($wp_scripts, 'WP_Scripts')) |
| 1516 |
return; |
| 1517 |
|
| 1518 |
foreach ($wp_scripts->registered as $handle => $script) |
| 1519 |
$wp_scripts->registered[$handle]->ver = null; |
| 1520 |
} |
| 1521 |
|