PluginProbe
ManageWP Worker / 4.0.1
ManageWP Worker v4.0.1
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 / functions.php

functions.php in ManageWP Worker 4.0.1, at functions.php

1,483 lines 45.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 function mwp_autoload($class)
4 {
5 if (substr($class, 0, 8) === 'Dropbox_'
6 || substr($class, 0, 8) === 'Symfony_'
7 || substr($class, 0, 8) === 'Monolog_'
8 || substr($class, 0, 5) === 'Gelf_'
9 || substr($class, 0, 4) === 'MWP_'
10 || substr($class, 0, 4) === 'MMB_'
11 || substr($class, 0, 3) === 'S3_'
12 ) {
13 $file = dirname(__FILE__).'/src/'.str_replace('_', '/', $class).'.php';
14 if (file_exists($file)) {
15 include_once $file;
16 }
17 }
18 }
19
20 function mwp_register_autoload_google()
21 {
22 static $registered;
23
24 if ($registered) {
25 return;
26 } else {
27 $registered = true;
28 }
29
30 if (version_compare(PHP_VERSION, '5.3', '<')) {
31 spl_autoload_register('mwp_autoload_google');
32 } else {
33 spl_autoload_register('mwp_autoload_google', true, true);
34 }
35 }
36
37 function mwp_autoload_google($class)
38 {
39 if (substr($class, 0, 7) === 'Google_') {
40 $file = dirname(__FILE__).'/src/'.str_replace('_', '/', $class).'.php';
41 if (file_exists($file)) {
42 include_once $file;
43 }
44 }
45 }
46
47 /**
48 * @return Monolog_Psr_LoggerInterface
49 */
50 function mwp_logger()
51 {
52 return mwp_container()->getLogger();
53 }
54
55 /**
56 * @return MWP_WordPress_Context
57 */
58 function mwp_context()
59 {
60 return mwp_container()->getWordPressContext();
61 }
62
63 /**
64 * @param $appKey
65 * @param $appSecret
66 * @param $token
67 * @param $tokenSecret
68 *
69 * @return Dropbox_Client
70 */
71 function mwp_dropbox_oauth_factory($appKey, $appSecret, $token, $tokenSecret = null)
72 {
73 if ($tokenSecret) {
74 $oauthToken = 'OAuth oauth_version="1.0", oauth_signature_method="PLAINTEXT", oauth_consumer_key="'.$appKey.'", oauth_token="'.$token.'", oauth_signature="'.$appSecret.'&'.$tokenSecret.'"';
75 $clientIdentifier = $token;
76 } else {
77 $oauthToken = 'Bearer '.$token;
78 $clientIdentifier = 'PHP-ManageWp/1.0';
79 }
80
81 return new Dropbox_Client($oauthToken, $clientIdentifier);
82 }
83
84 function mwp_format_memory_limit($limit)
85 {
86 if ((string) (int) $limit === (string) $limit) {
87 // The number is numeric.
88 return mwp_format_bytes($limit);
89 }
90
91 $units = strtolower(substr($limit, -1));
92
93 if (!in_array($units, array('b', 'k', 'm', 'g'))) {
94 // Invalid size unit.
95 return $limit;
96 }
97
98 $number = substr($limit, 0, -1);
99
100 if ((string) (int) $number !== $number) {
101 // The number isn't numeric.
102 return $number;
103 }
104
105 switch ($units) {
106 case 'g':
107 return $number.' GB';
108 case 'm':
109 return $number.' MB';
110 case 'k':
111 return $number.' KB';
112 case 'b':
113 default:
114 return $number.' B';
115 }
116 }
117
118 function mwp_format_bytes($bytes)
119 {
120 $bytes = (int) $bytes;
121
122 if ($bytes > 1024 * 1024 * 1024) {
123 return round($bytes / 1024 / 1024 / 1024, 2).' GB';
124 } elseif ($bytes > 1024 * 1024) {
125 return round($bytes / 1024 / 1024, 2).' MB';
126 } elseif ($bytes > 1024) {
127 return round($bytes / 1024, 2).' KB';
128 }
129
130 return $bytes.' B';
131 }
132
133 function mwp_log_warnings()
134 {
135 // If mbstring.func_overload is set, it changes the behavior of the standard string functions in
136 // ways that makes external libraries like Dropbox break.
137 $mbstring_func_overload = ini_get("mbstring.func_overload");
138 if ($mbstring_func_overload & 2 == 2) {
139 mwp_logger()->warning('"mbstring.func_overload" changes the behavior of the standard string functions in ways that makes external libraries like Dropbox break');
140 }
141
142 if (strlen((string) PHP_INT_MAX) < 19) {
143 // Looks like we're running on a 32-bit build of PHP. This could cause problems because some of the numbers
144 // we use (file sizes, quota, etc) can be larger than 32-bit ints can handle.
145 mwp_logger()->warning("Some external libraries rely on 64-bit integers, but it looks like we're running on a version of PHP that doesn't support 64-bit integers (PHP_INT_MAX=".((string) PHP_INT_MAX).").");
146 }
147 }
148
149 function mmb_get_extended_info($stats)
150 {
151 $params = get_option('mmb_stats_filter');
152 $filter = isset($params['plugins']['cleanup']) ? $params['plugins']['cleanup'] : array();
153 $stats['num_revisions'] = mmb_num_revisions($filter['revisions']);
154 //$stats['num_revisions'] = 5;
155 $stats['overhead'] = mmb_handle_overhead(false);
156 $stats['num_spam_comments'] = mmb_num_spam_comments();
157
158 return $stats;
159 }
160
161 /* Revisions */
162 function cleanup_delete_worker($params = array())
163 {
164 $revision_params = get_option('mmb_stats_filter');
165 $revision_filter = isset($revision_params['plugins']['cleanup']) ? $revision_params['plugins']['cleanup'] : array();
166
167 $params_array = explode('_', $params['actions']);
168 $return_array = array();
169
170 foreach ($params_array as $param) {
171 switch ($param) {
172 case 'revision':
173 if (mmb_delete_all_revisions($revision_filter['revisions'])) {
174 $return_array['revision'] = 'OK';
175 } else {
176 $return_array['revision_error'] = 'OK, nothing to do';
177 }
178 break;
179 case 'overhead':
180 if (mmb_handle_overhead(true)) {
181 $return_array['overhead'] = 'OK';
182 } else {
183 $return_array['overhead_error'] = 'OK, nothing to do';
184 }
185 break;
186 case 'comment':
187 if (mmb_delete_spam_comments()) {
188 $return_array['comment'] = 'OK';
189 } else {
190 $return_array['comment_error'] = 'OK, nothing to do';
191 }
192 break;
193 default:
194 break;
195 }
196 }
197
198 unset($params);
199
200 mmb_response($return_array, true);
201 }
202
203 function mmb_num_revisions($filter)
204 {
205 global $wpdb;
206
207 $allRevisions = $wpdb->get_results("SELECT ID, post_name FROM {$wpdb->posts} WHERE post_type = 'revision'", ARRAY_A);
208
209 $revisionsToDelete = 0;
210 $revisionsToKeepCount = array();
211
212 if (isset($filter['num_to_keep']) && !empty($filter['num_to_keep'])) {
213 $num_rev = str_replace("r_", "", $filter['num_to_keep']);
214
215 foreach ($allRevisions as $revision) {
216 $revisionsToKeepCount[$revision['post_name']] = isset($revisionsToKeepCount[$revision['post_name']])
217 ? $revisionsToKeepCount[$revision['post_name']] + 1
218 : 1;
219
220 if ($revisionsToKeepCount[$revision['post_name']] > $num_rev) {
221 ++$revisionsToDelete;
222 }
223 }
224 } else {
225 $revisionsToDelete = count($allRevisions);
226 }
227
228 return $revisionsToDelete;
229 }
230
231 function mmb_select_all_revisions()
232 {
233 global $wpdb;
234 $sql = "SELECT * FROM $wpdb->posts WHERE post_type = 'revision'";
235 $revisions = $wpdb->get_results($sql);
236
237 return $revisions;
238 }
239
240 function mmb_delete_all_revisions($filter)
241 {
242 global $wpdb;
243 $where = '';
244 $keep = isset($filter['num_to_keep']) ? $filter['num_to_keep'] : false;
245 if ($keep) {
246 $num_rev = str_replace("r_", "", $keep);
247 $allRevisions = $wpdb->get_results("SELECT ID, post_name FROM {$wpdb->posts} WHERE post_type = 'revision' ORDER BY post_date DESC", ARRAY_A);
248 $revisionsToKeep = array(0 => 0);
249 $revisionsToKeepCount = array();
250
251 foreach ($allRevisions as $revision) {
252 $revisionsToKeepCount[$revision['post_name']] = isset($revisionsToKeepCount[$revision['post_name']])
253 ? $revisionsToKeepCount[$revision['post_name']] + 1
254 : 1;
255
256 if ($revisionsToKeepCount[$revision['post_name']] <= $num_rev) {
257 $revisionsToKeep[] = $revision['ID'];
258 }
259 }
260
261 $notInQuery = join(', ', $revisionsToKeep);
262
263 $where = "AND a.ID NOT IN ({$notInQuery})";
264 }
265
266 $sql = "DELETE a,b,c FROM $wpdb->posts a LEFT JOIN $wpdb->term_relationships b ON (a.ID = b.object_id) LEFT JOIN $wpdb->postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision' {$where}";
267
268 $revisions = $wpdb->query($sql);
269
270 return $revisions;
271 }
272
273 function mmb_handle_overhead($clear = false)
274 {
275 /** @var wpdb $wpdb */
276 global $wpdb;
277 $query = 'SHOW TABLE STATUS';
278 $tables = $wpdb->get_results($query, ARRAY_A);
279 $total_gain = 0;
280 $table_string = '';
281 foreach ($tables as $table) {
282 if (isset($table['Engine']) && $table['Engine'] === 'MyISAM') {
283 if ($wpdb->base_prefix != $wpdb->prefix) {
284 if (preg_match('/^'.$wpdb->prefix.'*/Ui', $table['Name'])) {
285 if ($table['Data_free'] > 0) {
286 $total_gain += $table['Data_free'] / 1024;
287 $table_string .= $table['Name'].",";
288 }
289 }
290 } else {
291 if (preg_match('/^'.$wpdb->prefix.'[0-9]{1,20}_*/Ui', $table['Name'])) {
292 continue;
293 } else {
294 if ($table['Data_free'] > 0) {
295 $total_gain += $table['Data_free'] / 1024;
296 $table_string .= $table['Name'].",";
297 }
298 }
299 }
300 // @todo check if the cleanup was successful, if not, set a flag always skip innodb cleanup
301 //} elseif (isset($table['Engine']) && $table['Engine'] == 'InnoDB') {
302 // $innodb_file_per_table = $wpdb->get_results("SHOW VARIABLES LIKE 'innodb_file_per_table'");
303 // if (isset($innodb_file_per_table[0]->Value) && $innodb_file_per_table[0]->Value === "ON") {
304 // if ($table['Data_free'] > 0) {
305 // $total_gain += $table['Data_free'] / 1024;
306 // $table_string .= $table['Name'].",";
307 // }
308 // }
309 }
310 }
311
312 if ($clear) {
313 $table_string = substr($table_string, 0, strlen($table_string) - 1); //remove last ,
314 $table_string = rtrim($table_string);
315 $query = "OPTIMIZE TABLE $table_string";
316 $optimize = $wpdb->query($query);
317
318 return (bool) $optimize;
319 } else {
320 return round($total_gain, 3);
321 }
322 }
323
324 /* Spam Comments */
325 function mmb_num_spam_comments()
326 {
327 global $wpdb;
328 $sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'spam'";
329 $num_spams = $wpdb->get_var($sql);
330
331 return $num_spams;
332 }
333
334 function mmb_delete_spam_comments()
335 {
336 global $wpdb;
337 $spam = 1;
338 $total = 0;
339 while (!empty($spam)) {
340 $getCommentIds = "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = 'spam' LIMIT 200";
341 $spam = $wpdb->get_results($getCommentIds);
342 foreach ($spam as $comment) {
343 wp_delete_comment($comment->comment_ID, true);
344 }
345 $total += count($spam);
346 if (!empty($spam)) {
347 usleep(100000);
348 }
349 }
350
351 return $total;
352 }
353
354 function mmb_get_spam_comments()
355 {
356 global $wpdb;
357 $sql = "SELECT * FROM $wpdb->comments as a LEFT JOIN $wpdb->commentmeta as b WHERE a.comment_ID = b.comment_id AND a.comment_approved = 'spam'";
358 $spams = $wpdb->get_results($sql);
359
360 return $spams;
361 }
362
363 function mwp_is_nio_shell_available()
364 {
365 static $check;
366 if (isset($check)) {
367 return $check;
368 }
369 try {
370 $process = new Symfony_Process_Process("cd .", dirname(__FILE__), array(), null, 1);
371 $process->run();
372 $check = $process->isSuccessful();
373 } catch (Exception $e) {
374 $check = false;
375 }
376
377 return $check;
378 }
379
380 function mwp_is_shell_available()
381 {
382 if (mwp_is_safe_mode()) {
383 return false;
384 }
385 if (!function_exists('proc_open') || !function_exists('escapeshellarg')) {
386 return false;
387 }
388
389 if (extension_loaded('suhosin') && $suhosin = ini_get('suhosin.executor.func.blacklist')) {
390 $suhosin = explode(',', $suhosin);
391 $blacklist = array_map('trim', $suhosin);
392 $blacklist = array_map('strtolower', $blacklist);
393 if (in_array('proc_open', $blacklist)) {
394 return false;
395 }
396 }
397
398 if (!mwp_is_nio_shell_available()) {
399 return false;
400 }
401
402 return true;
403 }
404
405 function mwp_get_disabled_functions()
406 {
407 $list = array_merge(explode(',', ini_get('disable_functions')), explode(',', ini_get('suhosin.executor.func.blacklist')));
408 $list = array_map('trim', $list);
409 $list = array_map('strtolower', $list);
410 $list = array_filter($list);
411
412 return $list;
413 }
414
415 function mwp_is_safe_mode()
416 {
417 $value = ini_get("safe_mode");
418 if ((int) $value === 0 || strtolower($value) === "off") {
419 return false;
420 }
421
422 return true;
423 }
424
425 // Everything below was moved from init.php
426
427 function mmb_parse_request()
428 {
429 global $mmb_core, $wp_db_version, $_wp_using_ext_object_cache, $_mwp_data, $_mwp_auth;
430 $_wp_using_ext_object_cache = false;
431 @set_time_limit(1200);
432
433 if (isset($_mwp_data['setting'])) {
434 if (array_key_exists("dataown", $_mwp_data['setting'])) {
435 $oldconfiguration = array("dataown" => $_mwp_data['setting']['dataown']);
436 $mmb_core->save_options($oldconfiguration);
437 unset($_mwp_data['setting']['dataown']);
438 }
439
440 $configurationService = new MWP_Configuration_Service();
441 $configuration = new MWP_Configuration_Conf($_mwp_data['setting']);
442 $configurationService->saveConfiguration($configuration);
443 }
444
445 if ($_mwp_data['action'] === 'add_site') {
446 mmb_add_site($_mwp_data['params']);
447 mmb_response('You should never see this.', false);
448 }
449
450 /* in case database upgrade required, do database backup and perform upgrade ( wordpress wp_upgrade() function ) */
451 if (strlen(trim($wp_db_version)) && !defined('ACX_PLUGIN_DIR')) {
452 if (get_option('db_version') != $wp_db_version) {
453 /* in multisite network, please update database manualy */
454 if (!is_multisite()) {
455 if (!function_exists('wp_upgrade')) {
456 include_once ABSPATH.'wp-admin/includes/upgrade.php';
457 }
458
459 ob_clean();
460 @wp_upgrade();
461 @do_action('after_db_upgrade');
462 ob_end_clean();
463 }
464 }
465 }
466
467 if (isset($_mwp_data['params']['secure'])) {
468 if (is_array($_mwp_data['params']['secure'])) {
469 $secureParams = $_mwp_data['params']['secure'];
470 foreach ($secureParams as $key => $value) {
471 $secureParams[$key] = base64_decode($value);
472 }
473 $_mwp_data['params']['secure'] = $secureParams;
474 } else {
475 $_mwp_data['params']['secure'] = base64_decode($_mwp_data['params']['secure']);
476 }
477 if ($decrypted = $mmb_core->_secure_data($_mwp_data['params']['secure'])) {
478 $decrypted = maybe_unserialize($decrypted);
479 if (is_array($decrypted)) {
480 foreach ($decrypted as $key => $val) {
481 if (!is_numeric($key)) {
482 $_mwp_data['params'][$key] = $val;
483 }
484 }
485 unset($_mwp_data['params']['secure']);
486 } else {
487 $_mwp_data['params']['secure'] = $decrypted;
488 }
489 }
490
491 if (!$decrypted && $mmb_core->get_random_signature() !== false) {
492 require_once dirname(__FILE__).'/src/PHPSecLib/Crypt/AES.php';
493 $cipher = new Crypt_AES(CRYPT_AES_MODE_ECB);
494 $cipher->setKey($mmb_core->get_random_signature());
495 $decrypted = $cipher->decrypt($_mwp_data['params']['secure']);
496 $_mwp_data['params']['account_info'] = json_decode($decrypted, true);
497 }
498 }
499
500 $logData = array(
501 'action' => $_mwp_data['action'],
502 'action_parameters' => $_mwp_data['params'],
503 'action_settings' => $_mwp_data['setting'],
504 );
505
506 if (!empty($_mwp_data['setting'])) {
507 $logData['settings'] = $_mwp_data['setting'];
508 }
509
510 mwp_logger()->debug('Master request: "{action}"', $logData);
511 }
512
513 function mmb_response($response = false, $success = true)
514 {
515 mwp_logger()->debug('Master response: {action_response_status}', array(
516 'action_response_status' => $success ? 'success' : 'error',
517 'action_response' => $response,
518 'headers_sent' => headers_sent(),
519 ));
520
521 if (!$success) {
522 if (!is_scalar($response)) {
523 $response = json_encode($response);
524 }
525 throw new MWP_Worker_Exception(MWP_Worker_Exception::GENERAL_ERROR, $response);
526 }
527
528 throw new MWP_Worker_ActionResponse($response);
529 }
530
531 function mmb_remove_site($params)
532 {
533 extract($params);
534 global $mmb_core;
535 $mmb_core->deactivate($deactivate);
536
537 include_once ABSPATH.'wp-admin/includes/plugin.php';
538 $plugin_slug = 'worker/init.php';
539
540 if ($deactivate) {
541 deactivate_plugins($plugin_slug, true);
542 } else {
543 // Prolong the worker deactivation upon site removal.
544 update_option('mmb_worker_activation_time', time());
545 }
546
547 if (!is_plugin_active($plugin_slug)) {
548 mmb_response(
549 array(
550 'deactivated' => 'Site removed successfully. <br /><br />ManageWP Worker plugin successfully deactivated.',
551 ),
552 true
553 );
554 } else {
555 mmb_response(
556 array(
557 'removed_data' => 'Site removed successfully. <br /><br /><b>ManageWP Worker plugin was not deactivated.</b>',
558 ),
559 true
560 );
561 }
562 }
563
564 function mmb_stats_get($params)
565 {
566 global $mmb_core;
567 $mmb_core->get_stats_instance();
568
569 mwp_context()->requireWpRewrite();
570 mwp_context()->requireTaxonomies();
571 mwp_context()->requirePostTypes();
572 mwp_context()->requireTheme();
573
574 $data = array_merge($mmb_core->stats_instance->get($params), mmb_pre_init_stats($params));
575 mmb_response($data, true);
576 }
577
578 function mmb_worker_header()
579 {
580 global $mmb_core, $current_user;
581
582 if (!headers_sent()) {
583 if (isset($current_user->ID)) {
584 $expiration = time() + apply_filters('auth_cookie_expiration', 10800, $current_user->ID, false);
585 } else {
586 $expiration = time() + 10800;
587 }
588
589 setcookie(MMB_XFRAME_COOKIE, md5(MMB_XFRAME_COOKIE), $expiration, COOKIEPATH, COOKIE_DOMAIN, false, true);
590 $_COOKIE[MMB_XFRAME_COOKIE] = md5(MMB_XFRAME_COOKIE);
591 }
592 }
593
594 function mmb_pre_init_stats($params)
595 {
596 global $mmb_core;
597
598 mwp_context()->requireWpRewrite();
599 mwp_context()->requireTaxonomies();
600 mwp_context()->requirePostTypes();
601 mwp_context()->requireTheme();
602
603 $mmb_core->get_stats_instance();
604
605 return $mmb_core->stats_instance->pre_init_stats($params);
606 }
607
608 function mwp_datasend($params = array())
609 {
610 global $mmb_core, $_mmb_item_filter, $_mmb_options;
611
612 $_mmb_remoteurl = get_option('home');
613 $_mmb_remoteown = isset($_mmb_options['dataown']) && !empty($_mmb_options['dataown']) ? $_mmb_options['dataown'] : false;
614
615 if (empty($_mmb_remoteown)) {
616 return;
617 }
618
619 $_mmb_item_filter['pre_init_stats'] = array('core_update', 'hit_counter', 'comments', 'backups', 'posts', 'drafts', 'scheduled', 'site_statistics');
620 $_mmb_item_filter['get'] = array('updates', 'errors');
621 $mmb_core->get_stats_instance();
622
623 $filter = array(
624 'refresh' => 'transient',
625 'item_filter' => array(
626 'get_stats' => array(
627 array('updates', array('plugins' => true, 'themes' => true, 'premium' => true)),
628 array('core_update', array('core' => true)),
629 array('posts', array('numberposts' => 5)),
630 array('drafts', array('numberposts' => 5)),
631 array('scheduled', array('numberposts' => 5)),
632 array('hit_counter'),
633 array('comments', array('numberposts' => 5)),
634 array('backups'),
635 'plugins' => array(
636 'cleanup' => array(
637 'overhead' => array(),
638 'revisions' => array('num_to_keep' => 'r_5'),
639 'spam' => array(),
640 ),
641 ),
642 ),
643 ),
644 );
645
646 $pre_init_data = $mmb_core->stats_instance->pre_init_stats($filter);
647 $init_data = $mmb_core->stats_instance->get($filter);
648
649 $data = array_merge($init_data, $pre_init_data);
650 $data['server_ip'] = $_SERVER['SERVER_ADDR'];
651 $data['uhost'] = php_uname('n');
652 $hash = $mmb_core->get_secure_hash();
653
654 if (mwp_datasend_trigger($data)) { // adds trigger to check if really need to send something
655 $configurationService = new MWP_Configuration_Service();
656 $configuration = $configurationService->getConfiguration();
657
658 set_transient("mwp_cache_notifications", $data);
659 set_transient("mwp_cache_notifications_time", time());
660
661 $datasend['datasend'] = $mmb_core->encrypt_data($data);
662 $datasend['sitehome'] = base64_encode($_mmb_remoteown.'[]'.$_mmb_remoteurl);
663 $datasend['sitehash'] = md5($hash.$_mmb_remoteown.$_mmb_remoteurl);
664 $datasend['setting_checksum_order'] = implode(",", array_keys($configuration->getVariables()));
665 $datasend['setting_checksum'] = md5(json_encode($configuration->toArray()));
666 if (!class_exists('WP_Http')) {
667 include_once ABSPATH.WPINC.'/class-http.php';
668 }
669
670 $remote = array();
671 $remote['body'] = $datasend;
672 $remote['timeout'] = 20;
673
674 $result = wp_remote_post($configuration->getMasterCronUrl(), $remote);
675 if (!is_wp_error($result)) {
676 if (isset($result['body']) && !empty($result['body'])) {
677 $settings = @unserialize($result['body']);
678 /* rebrand worker or set default */
679 $brand = '';
680 if ($settings['worker_brand']) {
681 $brand = $settings['worker_brand'];
682 }
683 update_option("mwp_worker_brand", $brand);
684 /* change worker version */
685 $w_version = @$settings['worker_updates']['version'];
686 $w_url = @$settings['worker_updates']['url'];
687 if (version_compare($GLOBALS['MMB_WORKER_VERSION'], $w_version, '<')) {
688 //automatic update
689 $mmb_core->update_worker_plugin(array("download_url" => $w_url));
690 }
691
692 if (!empty($settings['mwp_worker_configuration'])) {
693 require_once dirname(__FILE__).'/src/PHPSecLib/Crypt/RSA.php';
694 $rsa = new Crypt_RSA();
695 $keyName = $configuration->getKeyName();
696 $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
697 $rsa->loadKey(file_get_contents(dirname(__FILE__)."/publickeys/$keyName.pub")); // public key
698 $signature = base64_decode($settings['mwp_worker_configuration_signature']);
699 if ($rsa->verify(json_encode($settings['mwp_worker_configuration']), $signature)) {
700 $configuration = new MWP_Configuration_Conf($settings['mwp_worker_configuration']);
701 $configurationService->saveConfiguration($configuration);
702 }
703 }
704 }
705 } else {
706 //$mmb_core->_log($result);
707 }
708 }
709 }
710
711 // trigger function, returns true if notifications should be sent
712 function mwp_datasend_trigger($stats)
713 {
714 $configurationService = new MWP_Configuration_Service();
715 $configuration = $configurationService->getConfiguration();
716
717 $cachedData = get_transient("mwp_cache_notifications");
718 $cacheTime = (int) get_transient("mwp_cache_notifications_time");
719
720 $returnValue = false;
721 if (false == $cachedData || empty($configuration)) {
722 $returnValue = true;
723 }
724 /**
725 * Cache lifetime check
726 */
727 if (!$returnValue) {
728 $now = time();
729 if ($now - $configuration->getNotiCacheLifeTime() >= $cacheTime) {
730 $returnValue = true;
731 }
732 }
733
734 /**
735 * Themes difference check section
736 * First check if array differ in size. If same size,then check values difference
737 */
738 if (!$returnValue && empty($stats['upgradable_themes']) != empty($cachedData['upgradable_themes'])) {
739 $returnValue = true;
740 }
741 if (!$returnValue && !empty($stats['upgradable_themes'])) {
742 $themesArr = mwp_std_to_array($stats['upgradable_themes']);
743 $cachedThemesArr = mwp_std_to_array($cachedData['upgradable_themes']);
744 if ($themesArr != $cachedThemesArr) {
745 $returnValue = true;
746 }
747 }
748
749 /**
750 * Plugins difference check section
751 * First check if array differ in size. If same size,then check values difference
752 */
753 if (!$returnValue && empty($stats['upgradable_plugins']) != empty($cachedData['upgradable_plugins'])) {
754 $returnValue = true;
755 }
756
757 if (!$returnValue && !empty($stats['upgradable_plugins'])) { //we have hear stdclass
758 $pluginsArr = mwp_std_to_array($stats['upgradable_plugins']);
759 $cachedPluginsArr = mwp_std_to_array($cachedData['upgradable_plugins']);
760 if ($pluginsArr != $cachedPluginsArr) {
761 $returnValue = true;
762 }
763 }
764
765 /**
766 * Premium difference check section
767 * First check if array differ in size. If same size,then check values difference
768 */
769 if (!$returnValue && empty($stats['premium_updates']) != empty($cachedData['premium_updates'])) {
770 $returnValue = true;
771 }
772 if (!$returnValue && !empty($stats['premium_updates'])) {
773 $premiumArr = mwp_std_to_array($stats['premium_updates']);
774 $cachedPremiumArr = mwp_std_to_array($cachedData['premium_updates']);
775 if ($premiumArr != $cachedPremiumArr) {
776 $returnValue = true;
777 }
778 }
779 /**
780 * Comments
781 * Check if we have configs first, then check trasholds
782 */
783 if (!$returnValue && (int) $stats['num_spam_comments'] >= $configuration->getNotiTresholdSpamComments() && $stats['num_spam_comments'] != (int) $cachedData['num_spam_comments']) {
784 $returnValue = true;
785 }
786 if (!$returnValue && (int) $stats['num_spam_comments'] < (int) $cachedData['num_spam_comments']) {
787 $returnValue = true;
788 }
789
790 if (!$returnValue && !empty($stats['comments'])) {
791 if (!empty($stats['comments']['pending']) && count($stats['comments']['pending']) >= $configuration->getNotiTresholdPendingComments()) {
792 $pendingArr = mwp_std_to_array($stats['comments']['pending']);
793 $cachedPendingArr = mwp_std_to_array($cachedData['comments']['pending']);
794 if ($pendingArr != $cachedPendingArr) {
795 $returnValue = true;
796 }
797 }
798
799 if (!empty($stats['comments']['approved']) && count($stats['comments']['approved']) >= $configuration->getNotiTresholdApprovedComments()) {
800 $approvedArr = mwp_std_to_array($stats['comments']['approved']);
801 $cachedApprovedArr = mwp_std_to_array($cachedData['comments']['approved']);
802 if ($approvedArr != $cachedApprovedArr) {
803 $returnValue = true;
804 }
805 }
806 }
807
808 /**
809 * Drafts, posts
810 */
811
812 if (!$returnValue && !empty($stats['drafts']) && count($stats['drafts']) >= $configuration->getNotiTresholdDrafts()) {
813 if (count($stats['drafts']) > $configuration->getNotiTresholdDrafts() && empty($cachedData['drafts'])) {
814 $returnValue = true;
815 } else {
816 $draftsArr = mwp_std_to_array($stats['drafts']);
817 $cachedDraftsArr = mwp_std_to_array($cachedData['drafts']);
818 if ($draftsArr != $cachedDraftsArr) {
819 $returnValue = true;
820 }
821 }
822 }
823
824 if (!$returnValue && !empty($stats['posts']) && count($stats['posts']) >= $configuration->getNotiTresholdPosts()) {
825 if (count($stats['posts']) > $configuration->getNotiTresholdPosts() && empty($cachedData['posts'])) {
826 $returnValue = true;
827 } else {
828 $postsArr = mwp_std_to_array($stats['posts']);
829 $cachedPostsArr = mwp_std_to_array($cachedData['posts']);
830 if ($postsArr != $cachedPostsArr) {
831 $returnValue = true;
832 }
833 }
834 }
835
836 /**
837 * Core updates & backups
838 */
839 if (!$returnValue && empty($stats['core_updates']) != empty($cachedData['core_updates'])) {
840 $returnValue = true;
841 }
842 if (!$returnValue && !empty($stats['core_updates'])) {
843 $coreArr = mwp_std_to_array($stats['core_updates']);
844 $cachedCoreArr = mwp_std_to_array($cachedData['core_updates']);
845 if ($coreArr != $cachedCoreArr) {
846 $returnValue = true;
847 }
848 }
849
850 if (!$returnValue && empty($stats['mwp_backups']) != empty($cachedData['mwp_backups'])) {
851 $returnValue = true;
852 }
853 if (!$returnValue && !empty($stats['mwp_backups'])) {
854 $backupArr = mwp_std_to_array($stats['mwp_backups']);
855 $cachedBackupArr = mwp_std_to_array($cachedData['mwp_backups']);
856 if ($backupArr != $cachedBackupArr) {
857 $returnValue = true;
858 }
859 }
860
861 return $returnValue;
862 }
863
864 function mwp_std_to_array($obj)
865 {
866 if (is_object($obj)) {
867 $objArr = clone $obj;
868 } else {
869 $objArr = $obj;
870 }
871 if (!empty($objArr)) {
872 foreach ($objArr as &$element) {
873 if ($element instanceof stdClass || is_array($element)) {
874 $element = mwp_std_to_array($element);
875 }
876 }
877 $objArr = (array) $objArr;
878 }
879
880 return $objArr;
881 }
882
883 function mmb_post_create($params)
884 {
885 global $mmb_core;
886
887 mwp_context()->requireWpRewrite();
888 mwp_context()->requireTaxonomies();
889 mwp_context()->requirePostTypes();
890
891 $mmb_core->get_post_instance();
892 $return = $mmb_core->post_instance->create($params);
893 if (is_int($return)) {
894 mmb_response($return, true);
895 } else {
896 if (isset($return['error'])) {
897 mmb_response($return['error'], false);
898 } else {
899 mmb_response($return, false);
900 }
901 }
902 }
903
904 function mmb_change_post_status($params)
905 {
906 global $mmb_core;
907 $mmb_core->get_post_instance();
908 $return = $mmb_core->post_instance->change_status($params);
909 if (is_wp_error($return)) {
910 mmb_response($return->get_error_message(), false);
911 } elseif (empty($return)) {
912 mmb_response("Post status can not be changed", false);
913 } else {
914 mmb_response($return, true);
915 }
916 }
917
918 function mmb_backup_now($params)
919 {
920 global $mmb_core;
921
922 $mmb_core->get_backup_instance();
923 $return = $mmb_core->backup_instance->backup($params);
924
925 if (is_array($return) && array_key_exists('error', $return)) {
926 mmb_response($return['error'], false);
927 } else {
928 mmb_response($return, true);
929 }
930 }
931
932 function mwp_ping_backup($params)
933 {
934 global $mmb_core;
935
936 $mmb_core->get_backup_instance();
937 $return = $mmb_core->backup_instance->ping_backup($params);
938
939 if (is_array($return) && array_key_exists('error', $return)) {
940 mmb_response($return['error'], false);
941 } else {
942 mmb_response($return, true);
943 }
944 }
945
946 function mmb_run_task_now($params)
947 {
948 global $mmb_core;
949 $mmb_core->get_backup_instance();
950
951 $task_name = isset($params['task_name']) ? $params['task_name'] : false;
952 $google_drive_token = isset($params['google_drive_token']) ? $params['google_drive_token'] : false;
953 $resultUuid = !empty($params['resultUuid']) ? $params['resultUuid'] : false;
954
955 if ($task_name) {
956 $return = $mmb_core->backup_instance->task_now($task_name, $google_drive_token, $resultUuid);
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 } else {
963 mmb_response("Task name is not provided.", false);
964 }
965 }
966
967 function mmb_get_backup_req($params)
968 {
969 global $mmb_core;
970 $mmb_core->get_stats_instance();
971 $return = $mmb_core->stats_instance->get_backup_req($params);
972
973 mmb_response($return, true);
974 }
975
976 // Fires when Backup Now, or some backup task is saved.
977 function mmb_scheduled_backup($params)
978 {
979 global $mmb_core;
980 $mmb_core->get_backup_instance();
981 $return = $mmb_core->backup_instance->set_backup_task($params);
982 mmb_response($return, $return);
983 }
984
985 function mmm_delete_backup($params)
986 {
987 global $mmb_core;
988 $mmb_core->get_backup_instance();
989 $return = $mmb_core->backup_instance->delete_backup($params);
990 mmb_response($return, $return);
991 }
992
993 function mmb_restore_now($params)
994 {
995 global $mmb_core;
996 $mmb_core->get_backup_instance();
997 $return = $mmb_core->backup_instance->restore($params);
998 if (is_array($return) && array_key_exists('error', $return)) {
999 mmb_response($return['error'], false);
1000 } else {
1001 mmb_response($return, true);
1002 }
1003 }
1004
1005 function mmb_remote_backup_now($params)
1006 {
1007 global $mmb_core;
1008 $backup_instance = $mmb_core->get_backup_instance();
1009 $return = $mmb_core->backup_instance->remote_backup_now($params);
1010 if (is_array($return) && array_key_exists('error', $return)) {
1011 mmb_response($return['error'], false);
1012 } else {
1013 mmb_response($return, true);
1014 }
1015 }
1016
1017 function mmb_run_forked_action()
1018 {
1019 if (!isset($_POST['mmb_fork_nonce'])) {
1020 return false;
1021 }
1022
1023 $originalUser = wp_get_current_user();
1024 $usernameUsed = array_key_exists('username', $_POST) ? $_POST : null;
1025
1026 if ($usernameUsed && !is_user_logged_in()) {
1027 $user = function_exists('get_user_by') ? get_user_by('login', $_POST['username']) : get_user_by('login', $_POST['username']);
1028 }
1029
1030 if (isset($user) && isset($user->ID)) {
1031 wp_set_current_user($user->ID);
1032 // Compatibility with All In One Security
1033 update_user_meta($user->ID, 'last_login_time', current_time('mysql'));
1034 }
1035
1036 if (!wp_verify_nonce($_POST['mmb_fork_nonce'], 'mmb-fork-nonce')) {
1037 wp_set_current_user($originalUser->ID);
1038
1039 return false;
1040 }
1041
1042 $public_key = get_option('_worker_public_key');
1043 if (!isset($_POST['public_key']) || $public_key !== $_POST['public_key']) {
1044 wp_set_current_user($originalUser->ID);
1045
1046 return false;
1047 }
1048 $args = @json_decode(stripslashes($_POST['args']), true);
1049 $args['forked'] = true;
1050
1051 if (!isset($args)) {
1052 wp_set_current_user($originalUser->ID);
1053
1054 return false;
1055 }
1056 $cron_action = isset($_POST['mwp_forked_action']) ? $_POST['mwp_forked_action'] : false;
1057 if ($cron_action) {
1058 do_action($cron_action, $args);
1059 }
1060 //unset($_POST['public_key']);
1061 unset($_POST['mmb_fork_nonce']);
1062 unset($_POST['args']);
1063 unset($_POST['mwp_forked_action']);
1064
1065 wp_set_current_user($originalUser->ID);
1066
1067 return true;
1068 }
1069
1070 function mmb_update_worker_plugin($params)
1071 {
1072 global $mmb_core;
1073 mmb_response($mmb_core->update_worker_plugin($params), true);
1074 }
1075
1076 function mmb_install_addon($params)
1077 {
1078 global $mmb_core;
1079
1080 mwp_context()->requireTheme();
1081 mwp_load_required_components();
1082
1083 $mmb_core->get_installer_instance();
1084 $return = $mmb_core->installer_instance->install_remote_file($params);
1085 mmb_response($return, true);
1086 }
1087
1088 function mmb_do_upgrade($params)
1089 {
1090 global $mmb_core, $mmb_upgrading;
1091
1092 mwp_context()->requireTheme();
1093
1094 $mmb_core->get_installer_instance();
1095 $return = $mmb_core->installer_instance->do_upgrade($params);
1096 mmb_response($return, true);
1097 }
1098
1099 function mmb_get_comments($params)
1100 {
1101 global $mmb_core;
1102 $mmb_core->get_comment_instance();
1103 $return = $mmb_core->comment_instance->get_comments($params);
1104 if (is_array($return) && array_key_exists('error', $return)) {
1105 mmb_response($return['error'], false);
1106 } else {
1107 mmb_response($return, true);
1108 }
1109 }
1110
1111 function mmb_bulk_action_comments($params)
1112 {
1113 global $mmb_core;
1114 $mmb_core->get_comment_instance();
1115
1116 $return = $mmb_core->comment_instance->bulk_action_comments($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 function mmb_reply_comment($params)
1125 {
1126 global $mmb_core;
1127 $mmb_core->get_comment_instance();
1128
1129 $return = $mmb_core->comment_instance->reply_comment($params);
1130 if (is_array($return) && array_key_exists('error', $return)) {
1131 mmb_response($return['error'], false);
1132 } else {
1133 mmb_response($return, true);
1134 }
1135 }
1136
1137 function mmb_add_user($params)
1138 {
1139 global $mmb_core;
1140 $mmb_core->get_user_instance();
1141 $return = $mmb_core->user_instance->add_user($params);
1142 if (is_array($return) && array_key_exists('error', $return)) {
1143 mmb_response($return['error'], false);
1144 } else {
1145 mmb_response($return, true);
1146 }
1147 }
1148
1149 function mmb_get_users($params)
1150 {
1151 global $mmb_core;
1152 $mmb_core->get_user_instance();
1153 $return = $mmb_core->user_instance->get_users($params);
1154 if (is_array($return) && array_key_exists('error', $return)) {
1155 mmb_response($return['error'], false);
1156 } else {
1157 mmb_response($return, true);
1158 }
1159 }
1160
1161 function mmb_edit_users($params)
1162 {
1163 global $mmb_core;
1164 $mmb_core->get_user_instance();
1165 $users = $mmb_core->user_instance->edit_users($params);
1166 $response = 'User updated.';
1167 $check_error = false;
1168 foreach ($users as $username => $user) {
1169 $check_error = array_key_exists('error', $user);
1170 if ($check_error) {
1171 $response = $username.': '.$user['error'];
1172 }
1173 }
1174 mmb_response($response, !$check_error);
1175 }
1176
1177 function mmb_get_posts($params)
1178 {
1179 global $mmb_core;
1180 $mmb_core->get_post_instance();
1181
1182 $return = $mmb_core->post_instance->get_posts($params);
1183 if (is_array($return) && array_key_exists('error', $return)) {
1184 mmb_response($return['error'], false);
1185 } else {
1186 mmb_response($return, true);
1187 }
1188 }
1189
1190 function mmb_delete_post($params)
1191 {
1192 global $mmb_core;
1193 $mmb_core->get_post_instance();
1194
1195 $return = $mmb_core->post_instance->delete_post($params);
1196 if (is_array($return) && array_key_exists('error', $return)) {
1197 mmb_response($return['error'], false);
1198 } else {
1199 mmb_response($return, true);
1200 }
1201 }
1202
1203 function mmb_delete_posts($params)
1204 {
1205 global $mmb_core;
1206 $mmb_core->get_post_instance();
1207
1208 $return = $mmb_core->post_instance->delete_posts($params);
1209 if (is_array($return) && array_key_exists('error', $return)) {
1210 mmb_response($return['error'], false);
1211 } else {
1212 mmb_response($return, true);
1213 }
1214 }
1215
1216 function mmb_get_pages($params)
1217 {
1218 global $mmb_core;
1219 $mmb_core->get_post_instance();
1220
1221 $return = $mmb_core->post_instance->get_pages($params);
1222 if (is_array($return) && array_key_exists('error', $return)) {
1223 mmb_response($return['error'], false);
1224 } else {
1225 mmb_response($return, true);
1226 }
1227 }
1228
1229 function mmb_delete_page($params)
1230 {
1231 global $mmb_core;
1232 $mmb_core->get_post_instance();
1233
1234 $return = $mmb_core->post_instance->delete_page($params);
1235 if (is_array($return) && array_key_exists('error', $return)) {
1236 mmb_response($return['error'], false);
1237 } else {
1238 mmb_response($return, true);
1239 }
1240 }
1241
1242 function mmb_iframe_plugins_fix($update_actions)
1243 {
1244 foreach ($update_actions as $key => $action) {
1245 $update_actions[$key] = str_replace('target="_parent"', '', $action);
1246 }
1247
1248 return $update_actions;
1249 }
1250
1251 function mmb_execute_php_code($params)
1252 {
1253 ob_start();
1254 $errorHandler = new MWP_Debug_EvalErrorHandler();
1255 set_error_handler(array($errorHandler, 'handleError'));
1256 $returnValue = eval($params['code']);
1257 $errors = $errorHandler->getErrorMessages();
1258 restore_error_handler();
1259 $return = array('output' => ob_get_clean(), 'returnValue' => $returnValue);
1260
1261 if (count($errors)) {
1262 $return['errorLog'] = $errors;
1263 }
1264
1265 $lastError = error_get_last();
1266 $fatalError = null;
1267
1268 if (($lastError !== null)
1269 && ($lastError['type'] & (E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR))
1270 && (strpos($lastError['file'], __FILE__) !== false)
1271 && (strpos($lastError['file'], 'eval()') !== false)
1272 ) {
1273 $return['fatalError'] = $lastError;
1274 }
1275
1276 mmb_response($return, true);
1277 }
1278
1279 function mmb_more_reccurences($schedules)
1280 {
1281 $schedules['halfminute'] = array('interval' => 30, 'display' => 'Once in a half minute');
1282 $schedules['minutely'] = array('interval' => 60, 'display' => 'Once in a minute');
1283 $schedules['fiveminutes'] = array('interval' => 300, 'display' => 'Once every five minutes');
1284 $schedules['tenminutes'] = array('interval' => 600, 'display' => 'Once every ten minutes');
1285 $schedules['sixhours'] = array('interval' => 21600, 'display' => 'Every six hours');
1286 $schedules['fourhours'] = array('interval' => 14400, 'display' => 'Every four hours');
1287 $schedules['threehours'] = array('interval' => 10800, 'display' => 'Every three hours');
1288
1289 return $schedules;
1290 }
1291
1292 function mmb_call_scheduled_remote_upload($args)
1293 {
1294 global $mmb_core, $_wp_using_ext_object_cache;
1295 $_wp_using_ext_object_cache = false;
1296
1297 $mmb_core->get_backup_instance();
1298 if (isset($args['task_name'])) {
1299 $mmb_core->backup_instance->remote_backup_now($args);
1300 }
1301 }
1302
1303 function mwp_check_notifications()
1304 {
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 function mmb_get_plugins_themes($params)
1313 {
1314 global $mmb_core;
1315
1316 mwp_context()->requireTheme();
1317
1318 $mmb_core->get_installer_instance();
1319 $return = $mmb_core->installer_instance->get($params);
1320 mmb_response($return, true);
1321 }
1322
1323 function mmb_get_autoupdate_plugins_themes($params)
1324 {
1325 mwp_context()->requireTheme();
1326
1327 $return = MMB_Updater::getSettings($params);
1328 mmb_response($return, true);
1329 }
1330
1331 function mmb_edit_plugins_themes($params)
1332 {
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 function mmb_edit_autoupdate_plugins_themes($params)
1340 {
1341 $return = MMB_Updater::setSettings($params);
1342 mmb_response($return, true);
1343 }
1344
1345 function mmb_worker_brand($params)
1346 {
1347 update_option("mwp_worker_brand", $params['brand']);
1348 mmb_response(true, true);
1349 }
1350
1351 function mmb_maintenance_mode($params)
1352 {
1353 global $wp_object_cache;
1354
1355 $default = get_option('mwp_maintenace_mode');
1356 $params = empty($default) ? $params : array_merge($default, $params);
1357 update_option("mwp_maintenace_mode", $params);
1358
1359 if (!empty($wp_object_cache)) {
1360 @$wp_object_cache->flush();
1361 }
1362 mmb_response(true, true);
1363 }
1364
1365 function mmb_plugin_actions()
1366 {
1367 global $pagenow, $current_user, $mmode;
1368 if (!is_admin() && !in_array($pagenow, array('wp-login.php'))) {
1369 $mmode = get_option('mwp_maintenace_mode');
1370 if (!empty($mmode)) {
1371 if (isset($mmode['active']) && $mmode['active'] == true) {
1372 if (isset($current_user->data) && !empty($current_user->data) && isset($mmode['hidecaps']) && !empty($mmode['hidecaps'])) {
1373 $usercaps = array();
1374 if (isset($current_user->caps) && !empty($current_user->caps)) {
1375 $usercaps = $current_user->caps;
1376 }
1377 foreach ($mmode['hidecaps'] as $cap => $hide) {
1378 if (!$hide) {
1379 continue;
1380 }
1381
1382 foreach ($usercaps as $ucap => $val) {
1383 if ($ucap == $cap) {
1384 ob_end_clean();
1385 ob_end_flush();
1386 die($mmode['template']);
1387 }
1388 }
1389 }
1390 } else {
1391 die($mmode['template']);
1392 }
1393 }
1394 }
1395 }
1396
1397 if (file_exists(dirname(__FILE__).'/log')) {
1398 unlink(dirname(__FILE__).'/log');
1399 }
1400 }
1401
1402 function mwp_return_core_reference()
1403 {
1404 global $mmb_core, $mmb_core_backup;
1405 if (!$mmb_core instanceof MMB_Core) {
1406 $mmb_core = $mmb_core_backup;
1407 }
1408 }
1409
1410 function mwb_edit_redirect_override($location = false, $comment_id = false)
1411 {
1412 if (isset($_COOKIE[MMB_XFRAME_COOKIE])) {
1413 $location = get_site_url().'/wp-admin/edit-comments.php';
1414 }
1415
1416 return $location;
1417 }
1418
1419 function mwp_set_plugin_priority()
1420 {
1421 $pluginBasename = 'worker/init.php';
1422 $activePlugins = get_option('active_plugins');
1423
1424 if (reset($activePlugins) === $pluginBasename) {
1425 return;
1426 }
1427
1428 $workerKey = array_search($pluginBasename, $activePlugins);
1429
1430 if ($workerKey === false) {
1431 return;
1432 }
1433
1434 unset($activePlugins[$workerKey]);
1435 array_unshift($activePlugins, $pluginBasename);
1436 update_option('active_plugins', array_values($activePlugins));
1437 }
1438
1439 /**
1440 * @return MMB_Core
1441 */
1442 function mwp_core()
1443 {
1444 static $core;
1445
1446 global $mmb_core;
1447
1448 if (!$mmb_core instanceof MMB_Core) {
1449 $mmb_core = new MMB_Core();
1450 $core = $mmb_core;
1451 }
1452
1453 return $core;
1454 }
1455
1456 /**
1457 * Auto-loads classes that may not exists after this plugin's update.
1458 */
1459 function mwp_load_required_components()
1460 {
1461 class_exists('MWP_Http_ResponseInterface');
1462 class_exists('MWP_Http_Response');
1463 class_exists('MWP_Http_LegacyWorkerResponse');
1464 class_exists('MWP_Http_JsonResponse');
1465 class_exists('MWP_Worker_ActionResponse');
1466 class_exists('MWP_Worker_Exception');
1467 class_exists('MWP_Event_ActionResponse');
1468 class_exists('MWP_Event_MasterResponse');
1469 }
1470
1471 function mmb_change_comment_status($params)
1472 {
1473 global $mmb_core;
1474 $mmb_core->get_comment_instance();
1475 $return = $mmb_core->comment_instance->change_status($params);
1476 if ($return) {
1477 $mmb_core->get_stats_instance();
1478 mmb_response($mmb_core->stats_instance->get_comments_stats($params), true);
1479 } else {
1480 mmb_response('Comment not updated', false);
1481 }
1482 }
1483