| 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: Prelovac Media |
| 7 |
Version: 3.9.10 |
| 8 |
Author URI: http://www.prelovac.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 |
|
| 22 |
if(!defined('MMB_WORKER_VERSION')) |
| 23 |
define('MMB_WORKER_VERSION', '3.9.10'); |
| 24 |
|
| 25 |
if ( function_exists('get_site_option') && !defined('MMB_XFRAME_COOKIE')) |
| 26 |
define('MMB_XFRAME_COOKIE', $xframe = 'wordpress_'.md5(get_site_option( 'siteurl' )).'_xframe'); |
| 27 |
|
| 28 |
global $wpdb, $mmb_plugin_dir, $mmb_plugin_url, $wp_version, $mmb_filters, $_mmb_item_filter; |
| 29 |
|
| 30 |
if (version_compare(PHP_VERSION, '5.0.0', '<')) // min version 5 supported |
| 31 |
exit("<p>ManageWP Worker plugin requires PHP 5 or higher.</p>"); |
| 32 |
|
| 33 |
|
| 34 |
$mmb_wp_version = $wp_version; |
| 35 |
$mmb_plugin_dir = WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__)); |
| 36 |
$mmb_plugin_url = WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)); |
| 37 |
|
| 38 |
require_once("$mmb_plugin_dir/helper.class.php"); |
| 39 |
require_once("$mmb_plugin_dir/core.class.php"); |
| 40 |
require_once("$mmb_plugin_dir/post.class.php"); |
| 41 |
require_once("$mmb_plugin_dir/comment.class.php"); |
| 42 |
require_once("$mmb_plugin_dir/stats.class.php"); |
| 43 |
require_once("$mmb_plugin_dir/backup.class.php"); |
| 44 |
require_once("$mmb_plugin_dir/installer.class.php"); |
| 45 |
require_once("$mmb_plugin_dir/link.class.php"); |
| 46 |
require_once("$mmb_plugin_dir/user.class.php"); |
| 47 |
require_once("$mmb_plugin_dir/api.php"); |
| 48 |
|
| 49 |
require_once("$mmb_plugin_dir/plugins/search/search.php"); |
| 50 |
require_once("$mmb_plugin_dir/plugins/cleanup/cleanup.php"); |
| 51 |
|
| 52 |
|
| 53 |
if( !function_exists ( 'mmb_parse_request' )) { |
| 54 |
function mmb_parse_request() |
| 55 |
{ |
| 56 |
|
| 57 |
if (!isset($HTTP_RAW_POST_DATA)) { |
| 58 |
$HTTP_RAW_POST_DATA = file_get_contents('php://input'); |
| 59 |
} |
| 60 |
ob_start(); |
| 61 |
|
| 62 |
global $current_user, $mmb_core, $new_actions, $wp_db_version, $wpmu_version, $_wp_using_ext_object_cache; |
| 63 |
$data = base64_decode($HTTP_RAW_POST_DATA); |
| 64 |
if ($data) |
| 65 |
$num = @extract(unserialize($data)); |
| 66 |
|
| 67 |
if (isset($action)) { |
| 68 |
$_wp_using_ext_object_cache = false; |
| 69 |
@set_time_limit(600); |
| 70 |
|
| 71 |
if (!$mmb_core->check_if_user_exists($params['username'])) |
| 72 |
mmb_response('Username <b>' . $params['username'] . '</b> does not have administrator capabilities. Enter the correct username in the site options.', false); |
| 73 |
|
| 74 |
if ($action == 'add_site') { |
| 75 |
mmb_add_site($params); |
| 76 |
mmb_response('You should never see this.', false); |
| 77 |
} |
| 78 |
|
| 79 |
$auth = $mmb_core->authenticate_message($action . $id, $signature, $id); |
| 80 |
if ($auth === true) { |
| 81 |
|
| 82 |
if(isset($params['username']) && !is_user_logged_in()){ |
| 83 |
$user = get_user_by('login', $params['username']); |
| 84 |
wp_set_current_user($user->ID); |
| 85 |
} |
| 86 |
|
| 87 |
/* in case database upgrade required, do database backup and perform upgrade ( wordpress wp_upgrade() function ) */ |
| 88 |
if( strlen(trim($wp_db_version)) && !defined('ACX_PLUGIN_DIR') ){ |
| 89 |
if ( get_option('db_version') != $wp_db_version ) { |
| 90 |
/* in multisite network, please update database manualy */ |
| 91 |
if (empty($wpmu_version) || (function_exists('is_multisite') && !is_multisite())){ |
| 92 |
if( ! function_exists('wp_upgrade')) |
| 93 |
include_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
| 94 |
|
| 95 |
ob_clean(); |
| 96 |
@wp_upgrade(); |
| 97 |
@do_action('after_db_upgrade'); |
| 98 |
ob_end_clean(); |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
if(isset($params['secure'])){ |
| 104 |
if($decrypted = $mmb_core->_secure_data($params['secure'])){ |
| 105 |
$decrypted = maybe_unserialize($decrypted); |
| 106 |
if(is_array($decrypted)){ |
| 107 |
foreach($decrypted as $key => $val){ |
| 108 |
if(!is_numeric($key)) |
| 109 |
$params[$key] = $val; |
| 110 |
} |
| 111 |
unset($params['secure']); |
| 112 |
} else $params['secure'] = $decrypted; |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
if( !$mmb_core->register_action_params( $action, $params ) ){ |
| 117 |
global $_mmb_plugin_actions; |
| 118 |
$_mmb_plugin_actions[$action] = $params; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
} else { |
| 123 |
mmb_response($auth['error'], false); |
| 124 |
} |
| 125 |
} |
| 126 |
ob_end_clean(); |
| 127 |
} |
| 128 |
} |
| 129 |
/* Main response function */ |
| 130 |
if( !function_exists ( 'mmb_response' )) { |
| 131 |
|
| 132 |
function mmb_response($response = false, $success = true) |
| 133 |
{ |
| 134 |
$return = array(); |
| 135 |
|
| 136 |
if ((is_array($response) && empty($response)) || (!is_array($response) && strlen($response) == 0)) |
| 137 |
$return['error'] = 'Empty response.'; |
| 138 |
else if ($success) |
| 139 |
$return['success'] = $response; |
| 140 |
else |
| 141 |
$return['error'] = $response; |
| 142 |
|
| 143 |
if( !headers_sent() ){ |
| 144 |
header('HTTP/1.0 200 OK'); |
| 145 |
header('Content-Type: text/plain'); |
| 146 |
} |
| 147 |
exit("<MWPHEADER>" . base64_encode(serialize($return))."<ENDMWPHEADER>"); |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
if( !function_exists ( 'mmb_add_site' )) { |
| 154 |
function mmb_add_site($params) |
| 155 |
{ |
| 156 |
global $mmb_core; |
| 157 |
$num = extract($params); |
| 158 |
|
| 159 |
if ($num) { |
| 160 |
if (!get_option('_action_message_id') && !get_option('_worker_public_key')) { |
| 161 |
$public_key = base64_decode($public_key); |
| 162 |
|
| 163 |
if (function_exists('openssl_verify')) { |
| 164 |
$verify = openssl_verify($action . $id, base64_decode($signature), $public_key); |
| 165 |
if ($verify == 1) { |
| 166 |
$mmb_core->set_master_public_key($public_key); |
| 167 |
$mmb_core->set_worker_message_id($id); |
| 168 |
$mmb_core->get_stats_instance(); |
| 169 |
if(is_array($notifications) && !empty($notifications)){ |
| 170 |
$mmb_core->stats_instance->set_notifications($notifications); |
| 171 |
} |
| 172 |
if(is_array($brand) && !empty($brand)){ |
| 173 |
update_option('mwp_worker_brand',$brand); |
| 174 |
} |
| 175 |
|
| 176 |
mmb_response($mmb_core->stats_instance->get_initial_stats(), true); |
| 177 |
} else if ($verify == 0) { |
| 178 |
mmb_response('Invalid message signature. Please contact us if you see this message often.', false); |
| 179 |
} else { |
| 180 |
mmb_response('Command not successful. Please try again.', false); |
| 181 |
} |
| 182 |
} else { |
| 183 |
if (!get_option('_worker_nossl_key')) { |
| 184 |
srand(); |
| 185 |
|
| 186 |
$random_key = md5(base64_encode($public_key) . rand(0, getrandmax())); |
| 187 |
|
| 188 |
$mmb_core->set_random_signature($random_key); |
| 189 |
$mmb_core->set_worker_message_id($id); |
| 190 |
$mmb_core->set_master_public_key($public_key); |
| 191 |
$mmb_core->get_stats_instance(); |
| 192 |
$mmb_core->get_stats_instance(); |
| 193 |
if(is_array($notifications) && !empty($notifications)){ |
| 194 |
$mmb_core->stats_instance->set_notifications($notifications); |
| 195 |
} |
| 196 |
|
| 197 |
if(is_array($brand) && !empty($brand)){ |
| 198 |
update_option('mwp_worker_brand',$brand); |
| 199 |
} |
| 200 |
|
| 201 |
mmb_response($mmb_core->stats_instance->get_initial_stats(), true); |
| 202 |
} else |
| 203 |
mmb_response('Please deactivate & activate ManageWP Worker plugin on your site, then re-add the site to your dashboard.', false); |
| 204 |
} |
| 205 |
} else { |
| 206 |
mmb_response('Please deactivate & activate ManageWP Worker plugin on your site and re-add the site to your dashboard.', false); |
| 207 |
} |
| 208 |
} else { |
| 209 |
mmb_response('Invalid parameters received. Please try again.', false); |
| 210 |
} |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
if( !function_exists ( 'mmb_remove_site' )) { |
| 215 |
function mmb_remove_site($params) |
| 216 |
{ |
| 217 |
extract($params); |
| 218 |
global $mmb_core; |
| 219 |
$mmb_core->uninstall( $deactivate ); |
| 220 |
|
| 221 |
include_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
| 222 |
$plugin_slug = basename(dirname(__FILE__)) . '/' . basename(__FILE__); |
| 223 |
|
| 224 |
if ($deactivate) { |
| 225 |
deactivate_plugins($plugin_slug, true); |
| 226 |
} |
| 227 |
|
| 228 |
if (!is_plugin_active($plugin_slug)) |
| 229 |
mmb_response(array( |
| 230 |
'deactivated' => 'Site removed successfully. <br /><br />ManageWP Worker plugin successfully deactivated.' |
| 231 |
), true); |
| 232 |
else |
| 233 |
mmb_response(array( |
| 234 |
'removed_data' => 'Site removed successfully. <br /><br /><b>ManageWP Worker plugin was not deactivated.</b>' |
| 235 |
), true); |
| 236 |
|
| 237 |
} |
| 238 |
} |
| 239 |
if( !function_exists ( 'mmb_stats_get' )) { |
| 240 |
function mmb_stats_get($params) |
| 241 |
{ |
| 242 |
global $mmb_core; |
| 243 |
$mmb_core->get_stats_instance(); |
| 244 |
mmb_response($mmb_core->stats_instance->get($params), true); |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
if( !function_exists ( 'mmb_worker_header' )) { |
| 249 |
function mmb_worker_header() |
| 250 |
{ global $mmb_core, $current_user; |
| 251 |
|
| 252 |
if(!headers_sent()){ |
| 253 |
if(isset($current_user->ID)) |
| 254 |
$expiration = time() + apply_filters('auth_cookie_expiration', 10800, $current_user->ID, false); |
| 255 |
else |
| 256 |
$expiration = time() + 10800; |
| 257 |
|
| 258 |
setcookie(MMB_XFRAME_COOKIE, md5(MMB_XFRAME_COOKIE), $expiration, COOKIEPATH, COOKIE_DOMAIN, false, true); |
| 259 |
$_COOKIE[MMB_XFRAME_COOKIE] = md5(MMB_XFRAME_COOKIE); |
| 260 |
} |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
if( !function_exists ( 'mmb_pre_init_stats' )) { |
| 265 |
function mmb_pre_init_stats( $params ) |
| 266 |
{ |
| 267 |
global $mmb_core; |
| 268 |
$mmb_core->get_stats_instance(); |
| 269 |
return $mmb_core->stats_instance->pre_init_stats($params); |
| 270 |
} |
| 271 |
} |
| 272 |
|
| 273 |
//post |
| 274 |
if( !function_exists ( 'mmb_post_create' )) { |
| 275 |
function mmb_post_create($params) |
| 276 |
{ |
| 277 |
global $mmb_core; |
| 278 |
$mmb_core->get_post_instance(); |
| 279 |
$return = $mmb_core->post_instance->create($params); |
| 280 |
if (is_int($return)) |
| 281 |
mmb_response($return, true); |
| 282 |
else |
| 283 |
mmb_response($return, false); |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
if( !function_exists ( 'mmb_change_post_status' )) { |
| 288 |
function mmb_change_post_status($params) |
| 289 |
{ |
| 290 |
global $mmb_core; |
| 291 |
$mmb_core->get_post_instance(); |
| 292 |
$return = $mmb_core->post_instance->change_status($params); |
| 293 |
//mmb_response($return, true); |
| 294 |
|
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
//comments |
| 299 |
if( !function_exists ( 'mmb_change_comment_status' )) { |
| 300 |
function mmb_change_comment_status($params) |
| 301 |
{ |
| 302 |
global $mmb_core; |
| 303 |
$mmb_core->get_comment_instance(); |
| 304 |
$return = $mmb_core->comment_instance->change_status($params); |
| 305 |
//mmb_response($return, true); |
| 306 |
if ($return){ |
| 307 |
$mmb_core->get_stats_instance(); |
| 308 |
mmb_response($mmb_core->stats_instance->get_comments_stats($params), true); |
| 309 |
}else |
| 310 |
mmb_response('Comment not updated', false); |
| 311 |
} |
| 312 |
|
| 313 |
} |
| 314 |
if( !function_exists ( 'mmb_comment_stats_get' )) { |
| 315 |
function mmb_comment_stats_get($params) |
| 316 |
{ |
| 317 |
global $mmb_core; |
| 318 |
$mmb_core->get_stats_instance(); |
| 319 |
mmb_response($mmb_core->stats_instance->get_comments_stats($params), true); |
| 320 |
} |
| 321 |
} |
| 322 |
|
| 323 |
if( !function_exists ( 'mmb_backup_now' )) { |
| 324 |
//backup |
| 325 |
function mmb_backup_now($params) |
| 326 |
{ |
| 327 |
global $mmb_core; |
| 328 |
|
| 329 |
$mmb_core->get_backup_instance(); |
| 330 |
$return = $mmb_core->backup_instance->backup($params); |
| 331 |
|
| 332 |
if (is_array($return) && array_key_exists('error', $return)) |
| 333 |
mmb_response($return['error'], false); |
| 334 |
else { |
| 335 |
mmb_response($return, true); |
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
if( !function_exists ( 'mmb_email_backup' )) { |
| 341 |
function mmb_email_backup($params) |
| 342 |
{ |
| 343 |
global $mmb_core; |
| 344 |
$mmb_core->get_backup_instance(); |
| 345 |
$return = $mmb_core->backup_instance->email_backup($params); |
| 346 |
|
| 347 |
if (is_array($return) && array_key_exists('error', $return)) |
| 348 |
mmb_response($return['error'], false); |
| 349 |
else { |
| 350 |
mmb_response($return, true); |
| 351 |
} |
| 352 |
} |
| 353 |
} |
| 354 |
if( !function_exists ( 'mmb_check_backup_compat' )) { |
| 355 |
function mmb_check_backup_compat($params) |
| 356 |
{ |
| 357 |
global $mmb_core; |
| 358 |
$mmb_core->get_backup_instance(); |
| 359 |
$return = $mmb_core->backup_instance->check_backup_compat($params); |
| 360 |
|
| 361 |
if (is_array($return) && array_key_exists('error', $return)) |
| 362 |
mmb_response($return['error'], false); |
| 363 |
else { |
| 364 |
mmb_response($return, true); |
| 365 |
} |
| 366 |
} |
| 367 |
} |
| 368 |
|
| 369 |
if( !function_exists ( 'mmb_scheduled_backup' )) { |
| 370 |
function mmb_scheduled_backup($params) |
| 371 |
{ |
| 372 |
|
| 373 |
global $mmb_core; |
| 374 |
$mmb_core->get_backup_instance(); |
| 375 |
$return = $mmb_core->backup_instance->set_backup_task($params); |
| 376 |
mmb_response($return, $return); |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
if( !function_exists ( 'mmm_delete_backup' )) { |
| 381 |
function mmm_delete_backup($params) |
| 382 |
{ |
| 383 |
global $mmb_core; |
| 384 |
$mmb_core->get_backup_instance(); |
| 385 |
$return = $mmb_core->backup_instance->delete_backup($params); |
| 386 |
mmb_response($return, $return); |
| 387 |
} |
| 388 |
} |
| 389 |
|
| 390 |
if( !function_exists ( 'mmb_optimize_tables' )) { |
| 391 |
function mmb_optimize_tables($params) |
| 392 |
{ |
| 393 |
global $mmb_core; |
| 394 |
$mmb_core->get_backup_instance(); |
| 395 |
$return = $mmb_core->backup_instance->optimize_tables(); |
| 396 |
if ($return) |
| 397 |
mmb_response($return, true); |
| 398 |
else |
| 399 |
mmb_response(false, false); |
| 400 |
} |
| 401 |
} |
| 402 |
if( !function_exists ( 'mmb_restore_now' )) { |
| 403 |
function mmb_restore_now($params) |
| 404 |
{ |
| 405 |
global $mmb_core; |
| 406 |
$mmb_core->get_backup_instance(); |
| 407 |
$return = $mmb_core->backup_instance->restore($params); |
| 408 |
if (is_array($return) && array_key_exists('error', $return)) |
| 409 |
mmb_response($return['error'], false); |
| 410 |
else |
| 411 |
mmb_response($return, true); |
| 412 |
|
| 413 |
} |
| 414 |
} |
| 415 |
|
| 416 |
if( !function_exists ( 'mmb_remote_backup_now' )) { |
| 417 |
function mmb_remote_backup_now($params) |
| 418 |
{ |
| 419 |
global $mmb_core; |
| 420 |
$backup_instance = $mmb_core->get_backup_instance(); |
| 421 |
$return = $mmb_core->backup_instance->remote_backup_now($params); |
| 422 |
if (is_array($return) && array_key_exists('error', $return)) |
| 423 |
mmb_response($return['error'], false); |
| 424 |
else |
| 425 |
mmb_response($return, true); |
| 426 |
} |
| 427 |
} |
| 428 |
|
| 429 |
|
| 430 |
if( !function_exists ( 'mmb_clean_orphan_backups' )) { |
| 431 |
function mmb_clean_orphan_backups() |
| 432 |
{ |
| 433 |
global $mmb_core; |
| 434 |
$backup_instance = $mmb_core->get_backup_instance(); |
| 435 |
$return = $mmb_core->backup_instance->cleanup(); |
| 436 |
if(is_array($return)) |
| 437 |
mmb_response($return, true); |
| 438 |
else |
| 439 |
mmb_response($return, false); |
| 440 |
} |
| 441 |
} |
| 442 |
|
| 443 |
if( !function_exists ( 'mmb_update_worker_plugin' )) { |
| 444 |
function mmb_update_worker_plugin($params) |
| 445 |
{ |
| 446 |
global $mmb_core; |
| 447 |
mmb_response($mmb_core->update_worker_plugin($params), true); |
| 448 |
} |
| 449 |
} |
| 450 |
|
| 451 |
if( !function_exists ( 'mmb_wp_checkversion' )) { |
| 452 |
function mmb_wp_checkversion($params) |
| 453 |
{ |
| 454 |
include_once(ABSPATH . 'wp-includes/version.php'); |
| 455 |
global $mmb_wp_version, $mmb_core; |
| 456 |
mmb_response($mmb_wp_version, true); |
| 457 |
} |
| 458 |
} |
| 459 |
if( !function_exists ( 'mmb_search_posts_by_term' )) { |
| 460 |
function mmb_search_posts_by_term($params) |
| 461 |
{ |
| 462 |
global $mmb_core; |
| 463 |
$mmb_core->get_search_instance(); |
| 464 |
|
| 465 |
$search_type = trim($params['search_type']); |
| 466 |
$search_term = strtolower(trim($params['search_term'])); |
| 467 |
|
| 468 |
switch ($search_type){ |
| 469 |
case 'page_post': |
| 470 |
$return = $mmb_core->search_instance->search_posts_by_term($params); |
| 471 |
if($return){ |
| 472 |
$return = serialize($return); |
| 473 |
mmb_response($return, true); |
| 474 |
}else{ |
| 475 |
mmb_response('No posts found', false); |
| 476 |
} |
| 477 |
break; |
| 478 |
|
| 479 |
case 'plugin': |
| 480 |
$plugins = get_option('active_plugins'); |
| 481 |
|
| 482 |
$have_plugin = false; |
| 483 |
foreach ($plugins as $plugin) { |
| 484 |
if(strpos($plugin, $search_term)>-1){ |
| 485 |
$have_plugin = true; |
| 486 |
} |
| 487 |
} |
| 488 |
if($have_plugin){ |
| 489 |
mmb_response(serialize($plugin), true); |
| 490 |
}else{ |
| 491 |
mmb_response(false, false); |
| 492 |
} |
| 493 |
break; |
| 494 |
case 'theme': |
| 495 |
$theme = strtolower(get_option('template')); |
| 496 |
if(strpos($theme, $search_term)>-1){ |
| 497 |
mmb_response($theme, true); |
| 498 |
}else{ |
| 499 |
mmb_response(false, false); |
| 500 |
} |
| 501 |
break; |
| 502 |
default: mmb_response(false, false); |
| 503 |
} |
| 504 |
$return = $mmb_core->search_instance->search_posts_by_term($params); |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
if ($return_if_true) { |
| 509 |
mmb_response($return_value, true); |
| 510 |
} else { |
| 511 |
mmb_response($return_if_false, false); |
| 512 |
} |
| 513 |
} |
| 514 |
} |
| 515 |
|
| 516 |
if( !function_exists ( 'mmb_install_addon' )) { |
| 517 |
function mmb_install_addon($params) |
| 518 |
{ |
| 519 |
global $mmb_core; |
| 520 |
$mmb_core->get_installer_instance(); |
| 521 |
$return = $mmb_core->installer_instance->install_remote_file($params); |
| 522 |
mmb_response($return, true); |
| 523 |
|
| 524 |
} |
| 525 |
} |
| 526 |
|
| 527 |
if( !function_exists ( 'mmb_do_upgrade' )) { |
| 528 |
function mmb_do_upgrade($params) |
| 529 |
{ |
| 530 |
global $mmb_core, $mmb_upgrading; |
| 531 |
$mmb_core->get_installer_instance(); |
| 532 |
$return = $mmb_core->installer_instance->do_upgrade($params); |
| 533 |
mmb_response($return, true); |
| 534 |
|
| 535 |
} |
| 536 |
} |
| 537 |
if( !function_exists ( 'mmb_add_link' )) { |
| 538 |
function mmb_add_link($params) |
| 539 |
{ |
| 540 |
global $mmb_core; |
| 541 |
$mmb_core->get_link_instance(); |
| 542 |
$return = $mmb_core->link_instance->add_link($params); |
| 543 |
if (is_array($return) && array_key_exists('error', $return)) |
| 544 |
|
| 545 |
mmb_response($return['error'], false); |
| 546 |
else { |
| 547 |
mmb_response($return, true); |
| 548 |
} |
| 549 |
|
| 550 |
} |
| 551 |
} |
| 552 |
|
| 553 |
if( !function_exists ( 'mmb_add_user' )) { |
| 554 |
function mmb_add_user($params) |
| 555 |
{ |
| 556 |
global $mmb_core; |
| 557 |
$mmb_core->get_user_instance(); |
| 558 |
$return = $mmb_core->user_instance->add_user($params); |
| 559 |
if (is_array($return) && array_key_exists('error', $return)) |
| 560 |
|
| 561 |
mmb_response($return['error'], false); |
| 562 |
else { |
| 563 |
mmb_response($return, true); |
| 564 |
} |
| 565 |
|
| 566 |
} |
| 567 |
} |
| 568 |
|
| 569 |
if( !function_exists ('mmb_get_users')) { |
| 570 |
function mmb_get_users($params) |
| 571 |
{ |
| 572 |
global $mmb_core; |
| 573 |
$mmb_core->get_user_instance(); |
| 574 |
$return = $mmb_core->user_instance->get_users($params); |
| 575 |
if (is_array($return) && array_key_exists('error', $return)) |
| 576 |
mmb_response($return['error'], false); |
| 577 |
else { |
| 578 |
mmb_response($return, true); |
| 579 |
} |
| 580 |
} |
| 581 |
} |
| 582 |
|
| 583 |
if( !function_exists ('mmb_edit_users')) { |
| 584 |
function mmb_edit_users($params) |
| 585 |
{ |
| 586 |
global $mmb_core; |
| 587 |
$mmb_core->get_user_instance(); |
| 588 |
$return = $mmb_core->user_instance->edit_users($params); |
| 589 |
mmb_response($return, true); |
| 590 |
} |
| 591 |
} |
| 592 |
|
| 593 |
if( !function_exists ( 'mmb_iframe_plugins_fix' )) { |
| 594 |
function mmb_iframe_plugins_fix($update_actions) |
| 595 |
{ |
| 596 |
foreach($update_actions as $key => $action) |
| 597 |
{ |
| 598 |
$update_actions[$key] = str_replace('target="_parent"','',$action); |
| 599 |
} |
| 600 |
|
| 601 |
return $update_actions; |
| 602 |
|
| 603 |
} |
| 604 |
} |
| 605 |
if( !function_exists ( 'mmb_execute_php_code' )) { |
| 606 |
function mmb_execute_php_code($params) |
| 607 |
{ |
| 608 |
ob_start(); |
| 609 |
eval($params['code']); |
| 610 |
$return = ob_get_flush(); |
| 611 |
mmb_response(print_r($return, true), true); |
| 612 |
} |
| 613 |
} |
| 614 |
|
| 615 |
if( !function_exists ( 'mmb_set_notifications' )) { |
| 616 |
function mmb_set_notifications($params) |
| 617 |
{ |
| 618 |
global $mmb_core; |
| 619 |
$mmb_core->get_stats_instance(); |
| 620 |
$return = $mmb_core->stats_instance->set_notifications($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 |
|
| 630 |
if(!function_exists('mmb_more_reccurences')){ |
| 631 |
//Backup Tasks |
| 632 |
add_filter('cron_schedules', 'mmb_more_reccurences'); |
| 633 |
function mmb_more_reccurences($schedules) { |
| 634 |
|
| 635 |
$schedules['minutely'] = array('interval' => 60, 'display' => 'Once in a minute'); |
| 636 |
$schedules['fiveminutes'] = array('interval' => 300, 'display' => 'Once every five minutes'); |
| 637 |
$schedules['tenminutes'] = array('interval' => 600, 'display' => 'Once every ten minutes'); |
| 638 |
|
| 639 |
return $schedules; |
| 640 |
} |
| 641 |
} |
| 642 |
|
| 643 |
|
| 644 |
if (!wp_next_scheduled('mwp_backup_tasks')) { |
| 645 |
wp_schedule_event( time(), 'tenminutes', 'mwp_backup_tasks' ); |
| 646 |
} |
| 647 |
add_action('mwp_backup_tasks', 'mwp_check_backup_tasks'); |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
if( !function_exists('mwp_check_backup_tasks') ){ |
| 652 |
function mwp_check_backup_tasks() { |
| 653 |
global $mmb_core, $_wp_using_ext_object_cache; |
| 654 |
$_wp_using_ext_object_cache = false; |
| 655 |
|
| 656 |
$mmb_core->get_backup_instance(); |
| 657 |
$mmb_core->backup_instance->check_backup_tasks(); |
| 658 |
} |
| 659 |
} |
| 660 |
|
| 661 |
if (!wp_next_scheduled('mwp_notifications')) { |
| 662 |
wp_schedule_event( time(), 'daily', 'mwp_notifications' ); |
| 663 |
} |
| 664 |
add_action('mwp_notifications', 'mwp_check_notifications'); |
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
if( !function_exists('mwp_check_notifications') ){ |
| 669 |
function mwp_check_notifications() { |
| 670 |
global $mmb_core, $_wp_using_ext_object_cache; |
| 671 |
$_wp_using_ext_object_cache = false; |
| 672 |
|
| 673 |
$mmb_core->get_stats_instance(); |
| 674 |
$mmb_core->stats_instance->check_notifications(); |
| 675 |
} |
| 676 |
} |
| 677 |
|
| 678 |
|
| 679 |
if( !function_exists('mmb_get_plugins_themes') ){ |
| 680 |
function mmb_get_plugins_themes($params) { |
| 681 |
global $mmb_core; |
| 682 |
$mmb_core->get_installer_instance(); |
| 683 |
$return = $mmb_core->installer_instance->get($params); |
| 684 |
mmb_response($return, true); |
| 685 |
} |
| 686 |
} |
| 687 |
|
| 688 |
if( !function_exists('mmb_edit_plugins_themes') ){ |
| 689 |
function mmb_edit_plugins_themes($params) { |
| 690 |
global $mmb_core; |
| 691 |
$mmb_core->get_installer_instance(); |
| 692 |
$return = $mmb_core->installer_instance->edit($params); |
| 693 |
mmb_response($return, true); |
| 694 |
} |
| 695 |
} |
| 696 |
|
| 697 |
if( !function_exists('mmb_worker_brand')){ |
| 698 |
function mmb_worker_brand($params) { |
| 699 |
update_option("mwp_worker_brand",$params['brand']); |
| 700 |
mmb_response(true, true); |
| 701 |
} |
| 702 |
} |
| 703 |
|
| 704 |
if( !function_exists('mmb_plugin_actions') ){ |
| 705 |
function mmb_plugin_actions() { |
| 706 |
global $mmb_actions, $mmb_core; |
| 707 |
|
| 708 |
if(!empty($mmb_actions)){ |
| 709 |
global $_mmb_plugin_actions; |
| 710 |
if(!empty($_mmb_plugin_actions)){ |
| 711 |
$failed = array(); |
| 712 |
foreach($_mmb_plugin_actions as $action => $params){ |
| 713 |
if(isset($mmb_actions[$action])) |
| 714 |
call_user_func($mmb_actions[$action], $params); |
| 715 |
else |
| 716 |
$failed[] = $action; |
| 717 |
} |
| 718 |
if(!empty($failed)){ |
| 719 |
$f = implode(', ', $failed); |
| 720 |
$s = count($f) > 1 ? 'Actions "' . $f . '" do' : 'Action "' . $f . '" does'; |
| 721 |
mmb_response($s.' not exist. Please update your Worker plugin.', false); |
| 722 |
} |
| 723 |
|
| 724 |
} |
| 725 |
} |
| 726 |
} |
| 727 |
} |
| 728 |
|
| 729 |
$mmb_core = new MMB_Core(); |
| 730 |
|
| 731 |
if(isset($_GET['auto_login'])) |
| 732 |
$mmb_core->automatic_login(); |
| 733 |
|
| 734 |
if (function_exists('register_activation_hook')) |
| 735 |
register_activation_hook( __FILE__ , array( $mmb_core, 'install' )); |
| 736 |
|
| 737 |
if (function_exists('register_deactivation_hook')) |
| 738 |
register_deactivation_hook(__FILE__, array( $mmb_core, 'uninstall' )); |
| 739 |
|
| 740 |
if (function_exists('add_action')) |
| 741 |
add_action('init', 'mmb_plugin_actions', 99999); |
| 742 |
|
| 743 |
if (function_exists('add_filter')) |
| 744 |
add_filter('install_plugin_complete_actions','mmb_iframe_plugins_fix'); |
| 745 |
|
| 746 |
if( isset($_COOKIE[MMB_XFRAME_COOKIE]) ){ |
| 747 |
remove_action( 'admin_init', 'send_frame_options_header'); |
| 748 |
remove_action( 'login_init', 'send_frame_options_header'); |
| 749 |
} |
| 750 |
|
| 751 |
?> |