Version Description
- Added bucket location for Amazon S3 backups
- Better backup feature for larger sites
- Added Disable compression to further help with larger sites
- Backing up wp-admin, wp-includes and wp-content by default now, other folders can be included manually
Download this release
Release Info
| Developer | freediver |
| Plugin | |
| Version | 3.9.13 |
| Comparing to | |
| See all releases | |
Code changes from version 3.9.12 to 3.9.13
- backup.class.php +763 -579
- core.class.php +25 -9
- helper.class.php +1 -1
- init.php +6 -6
- installer.class.php +675 -642
- plugins/cleanup/cleanup.php +133 -116
- readme.txt +6 -0
- screenshot-1.png +0 -0
- stats.class.php +523 -513
- version +1 -1
backup.class.php
CHANGED
|
@@ -9,28 +9,80 @@
|
|
| 9 |
* Copyright (c) 2011 Prelovac Media
|
| 10 |
* www.prelovac.com
|
| 11 |
**************************************************************/
|
| 12 |
-
define
|
| 13 |
-
define
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
class MMB_Backup extends MMB_Core
|
| 16 |
-
{
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 20 |
function __construct()
|
| 21 |
-
{
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
}
|
| 35 |
|
| 36 |
function get_backup_settings()
|
|
@@ -43,12 +95,13 @@ class MMB_Backup extends MMB_Core
|
|
| 43 |
}
|
| 44 |
|
| 45 |
function set_backup_task($params)
|
| 46 |
-
{
|
| 47 |
//$params => [$task_name, $args, $error]
|
| 48 |
if (!empty($params)) {
|
| 49 |
extract($params);
|
| 50 |
|
| 51 |
-
|
|
|
|
| 52 |
if (!$before || empty($before))
|
| 53 |
$before = array();
|
| 54 |
|
|
@@ -58,10 +111,10 @@ class MMB_Backup extends MMB_Core
|
|
| 58 |
'removed' => true
|
| 59 |
);
|
| 60 |
} else {
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
$before[$task_name]['task_args'] = $args;
|
| 66 |
if (strlen($args['schedule']))
|
| 67 |
$before[$task_name]['task_args']['next'] = $this->schedule_next($args['type'], $args['schedule']);
|
|
@@ -71,25 +124,26 @@ class MMB_Backup extends MMB_Core
|
|
| 71 |
|
| 72 |
//Update with error
|
| 73 |
if ($error) {
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
}
|
| 80 |
|
| 81 |
-
if($time){ //set next result time before backup
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
}
|
| 87 |
|
| 88 |
-
|
|
|
|
| 89 |
|
| 90 |
if ($task_name == 'Backup Now') {
|
| 91 |
$result = $this->backup($args, $task_name);
|
| 92 |
-
$backup_settings = $this->
|
| 93 |
|
| 94 |
if (is_array($result) && array_key_exists('error', $result)) {
|
| 95 |
$return = $result;
|
|
@@ -104,24 +158,25 @@ class MMB_Backup extends MMB_Core
|
|
| 104 |
|
| 105 |
//Cron check
|
| 106 |
function check_backup_tasks()
|
| 107 |
-
{
|
| 108 |
-
|
|
|
|
| 109 |
if (is_array($settings) && !empty($settings)) {
|
| 110 |
foreach ($settings as $task_name => $setting) {
|
| 111 |
if ($setting['task_args']['next'] && $setting['task_args']['next'] < time()) {
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
$this->set_backup_task(array(
|
| 126 |
'task_name' => $task_name,
|
| 127 |
'args' => $settings[$task_name]['task_args'],
|
|
@@ -129,14 +184,14 @@ class MMB_Backup extends MMB_Core
|
|
| 129 |
));
|
| 130 |
|
| 131 |
$result = $this->backup($setting['task_args'], $task_name);
|
| 132 |
-
$error
|
| 133 |
if (is_array($result) && array_key_exists('error', $result)) {
|
| 134 |
$error = $result;
|
| 135 |
$this->set_backup_task(array(
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
} else {
|
| 141 |
$error = '';
|
| 142 |
}
|
|
@@ -159,19 +214,19 @@ class MMB_Backup extends MMB_Core
|
|
| 159 |
*/
|
| 160 |
|
| 161 |
function backup($args, $task_name = false)
|
| 162 |
-
{
|
| 163 |
if (!$args || empty($args))
|
| 164 |
return false;
|
| 165 |
|
| 166 |
extract($args); //extract settings
|
| 167 |
-
|
| 168 |
//Try increase memory limit and execution time
|
| 169 |
-
@ini_set('memory_limit', '
|
| 170 |
@set_time_limit(600); //ten minutes
|
| 171 |
|
| 172 |
//Remove old backup(s)
|
| 173 |
$this->remove_old_backups($task_name);
|
| 174 |
-
|
| 175 |
$new_file_path = MWP_BACKUP_DIR;
|
| 176 |
|
| 177 |
if (!file_exists($new_file_path)) {
|
|
@@ -197,10 +252,15 @@ class MMB_Backup extends MMB_Core
|
|
| 197 |
$backup_file = $new_file_path . '/' . $this->site_name . '_' . $label . '_' . $what . '_' . date('Y-m-d') . '_' . $hash . '.zip';
|
| 198 |
$backup_url = WP_CONTENT_URL . '/managewp/backups/' . $this->site_name . '_' . $label . '_' . $what . '_' . date('Y-m-d') . '_' . $hash . '.zip';
|
| 199 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
//What to backup - db or full?
|
| 201 |
-
if(trim($what) == 'db') {
|
| 202 |
//Take database backup
|
| 203 |
-
$this->update_status($task_name
|
| 204 |
$db_result = $this->backup_db();
|
| 205 |
if ($db_result == false) {
|
| 206 |
return array(
|
|
@@ -211,39 +271,47 @@ class MMB_Backup extends MMB_Core
|
|
| 211 |
'error' => $db_result['error']
|
| 212 |
);
|
| 213 |
} else {
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
|
| 225 |
$archive = new PclZip($backup_file);
|
| 226 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
@unlink($db_result);
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
return array(
|
| 240 |
'error' => 'Failed to zip database.'
|
| 241 |
);
|
| 242 |
-
|
| 243 |
-
|
| 244 |
}
|
| 245 |
} elseif (trim($what) == 'full') {
|
| 246 |
-
$content_backup = $this->backup_full($task_name
|
| 247 |
if (is_array($content_backup) && array_key_exists('error', $content_backup)) {
|
| 248 |
return array(
|
| 249 |
'error' => $content_backup['error']
|
|
@@ -254,12 +322,12 @@ class MMB_Backup extends MMB_Core
|
|
| 254 |
//Update backup info
|
| 255 |
if ($task_name) {
|
| 256 |
//backup task (scheduled)
|
| 257 |
-
$backup_settings = $this->
|
| 258 |
$paths = array();
|
| 259 |
$size = ceil(filesize($backup_file) / 1024);
|
| 260 |
|
| 261 |
if ($size > 1000) {
|
| 262 |
-
$paths['size'] = ceil($size / 1024)."Mb";
|
| 263 |
} else {
|
| 264 |
$paths['size'] = $size . 'kb';
|
| 265 |
}
|
|
@@ -290,85 +358,84 @@ class MMB_Backup extends MMB_Core
|
|
| 290 |
$paths['dropbox'] = basename($backup_url);
|
| 291 |
}
|
| 292 |
|
| 293 |
-
if ($backup_settings[$task_name]['task_args']['
|
| 294 |
-
//$paths['email'] = $backup_settings[$task_name]['task_args']['email_backup'];
|
| 295 |
$paths['email'] = basename($backup_url);
|
| 296 |
}
|
| 297 |
|
| 298 |
-
$temp
|
| 299 |
-
$temp
|
| 300 |
$paths['time'] = time();
|
| 301 |
-
|
| 302 |
-
if($task_name != 'Backup Now'){
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
|
|
|
| 309 |
$backup_settings[$task_name]['task_results'] = $temp;
|
| 310 |
-
|
|
|
|
| 311 |
}
|
| 312 |
|
| 313 |
|
| 314 |
//Additional: Email, ftp, amazon_s3, dropbox...
|
| 315 |
-
if (isset($optimize_tables) && !empty($optimize_tables)) {
|
| 316 |
-
$this->optimize_tables();
|
| 317 |
-
}
|
| 318 |
|
| 319 |
if ($task_name != 'Backup Now') {
|
| 320 |
if (isset($account_info['mwp_ftp']) && !empty($account_info['mwp_ftp'])) {
|
| 321 |
-
|
| 322 |
$account_info['mwp_ftp']['backup_file'] = $backup_file;
|
| 323 |
-
$ftp_result
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
}
|
| 328 |
|
| 329 |
-
if(is_array($ftp_result) && isset($ftp_result['error'])){
|
| 330 |
-
|
| 331 |
}
|
| 332 |
-
$this->update_status($task_name
|
| 333 |
}
|
| 334 |
|
| 335 |
if (isset($account_info['mwp_amazon_s3']) && !empty($account_info['mwp_amazon_s3'])) {
|
| 336 |
-
|
| 337 |
$account_info['mwp_amazon_s3']['backup_file'] = $backup_file;
|
| 338 |
-
$amazons3_result
|
| 339 |
-
if($amazons3_result !== true && $del_host_file){
|
| 340 |
-
|
| 341 |
}
|
| 342 |
-
if(is_array($amazons3_result) && isset($amazons3_result['error'])){
|
| 343 |
-
|
| 344 |
}
|
| 345 |
-
$this->update_status($task_name
|
| 346 |
}
|
| 347 |
|
| 348 |
if (isset($account_info['mwp_dropbox']) && !empty($account_info['mwp_dropbox'])) {
|
| 349 |
-
|
| 350 |
$account_info['mwp_dropbox']['backup_file'] = $backup_file;
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
}
|
| 359 |
-
|
| 360 |
-
|
| 361 |
}
|
| 362 |
|
| 363 |
-
if (isset($
|
| 364 |
-
|
| 365 |
-
$
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
)
|
| 370 |
-
|
| 371 |
-
|
|
|
|
| 372 |
}
|
| 373 |
|
| 374 |
if ($del_host_file) {
|
|
@@ -381,9 +448,12 @@ class MMB_Backup extends MMB_Core
|
|
| 381 |
return $backup_url; //Return url to backup file
|
| 382 |
}
|
| 383 |
|
| 384 |
-
function backup_full($task_name
|
| 385 |
-
{
|
| 386 |
-
|
|
|
|
|
|
|
|
|
|
| 387 |
$db_result = $this->backup_db();
|
| 388 |
|
| 389 |
if ($db_result == false) {
|
|
@@ -396,123 +466,214 @@ class MMB_Backup extends MMB_Core
|
|
| 396 |
);
|
| 397 |
}
|
| 398 |
|
| 399 |
-
$this->update_status($task_name
|
| 400 |
-
$this->update_status($task_name
|
|
|
|
|
|
|
| 401 |
|
| 402 |
$zip = $this->get_zip();
|
| 403 |
//Add database file
|
| 404 |
chdir(MWP_BACKUP_DIR);
|
| 405 |
-
$command = "$zip -r $backup_file 'mwp_db'";
|
| 406 |
ob_start();
|
| 407 |
$result = $this->mmb_exec($command);
|
| 408 |
ob_get_clean();
|
| 409 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
|
| 417 |
@unlink($db_result);
|
| 418 |
@rmdir(MWP_DB_DIR);
|
| 419 |
|
| 420 |
-
if(!$result_db){
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
}
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
$remove
|
| 435 |
-
"
|
| 436 |
-
"
|
| 437 |
-
);
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
//exclude paths
|
| 441 |
$exclude_data = "-x";
|
|
|
|
| 442 |
if (!empty($exclude)) {
|
| 443 |
-
|
| 444 |
-
|
|
|
|
|
|
|
|
|
|
| 445 |
$exclude_data .= " '$data/*'";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 446 |
}
|
|
|
|
| 447 |
}
|
| 448 |
-
|
| 449 |
-
|
|
|
|
|
|
|
|
|
|
| 450 |
$exclude_data .= " '$data/*'";
|
| 451 |
}
|
| 452 |
|
| 453 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 454 |
chdir(ABSPATH);
|
| 455 |
-
$command = "$zip -r $backup_file './' $exclude_data";
|
| 456 |
ob_start();
|
| 457 |
-
$
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
if (!$
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
$result = $archive->add(ABSPATH, PCLZIP_OPT_REMOVE_PATH, ABSPATH);
|
| 469 |
-
|
| 470 |
-
if(!$result){
|
| 471 |
-
@unlink($backup_file);
|
| 472 |
-
return array(
|
| 473 |
-
'error' => 'Failed to zip files. pclZip error ('.$archive->error_code.'): .'.$archive->error_string
|
| 474 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 475 |
}
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 480 |
foreach ($exclude as $data) {
|
| 481 |
-
if ($data)
|
| 482 |
$exclude_data[] = $data . '/';
|
|
|
|
|
|
|
| 483 |
}
|
| 484 |
}
|
| 485 |
-
|
| 486 |
-
|
| 487 |
$exclude_data[] = $rem . '/';
|
| 488 |
}
|
| 489 |
|
| 490 |
$result_excl = $archive->delete(PCLZIP_OPT_BY_NAME, $exclude_data);
|
| 491 |
-
if(!$
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
|
| 504 |
|
| 505 |
function backup_db()
|
| 506 |
{
|
| 507 |
-
$db_folder = MWP_DB_DIR.'/';
|
| 508 |
if (!file_exists($db_folder)) {
|
| 509 |
if (!mkdir($db_folder, 0755, true))
|
| 510 |
return array(
|
| 511 |
-
'error' => 'Error creating database backup folder ('
|
| 512 |
);
|
| 513 |
}
|
| 514 |
|
| 515 |
-
$file
|
| 516 |
$result = $this->backup_db_dump($file); // try mysqldump always then fallback to php dump
|
| 517 |
return $result;
|
| 518 |
}
|
|
@@ -520,11 +681,11 @@ class MMB_Backup extends MMB_Core
|
|
| 520 |
function backup_db_dump($file)
|
| 521 |
{
|
| 522 |
global $wpdb;
|
| 523 |
-
$paths
|
| 524 |
$brace = (substr(PHP_OS, 0, 3) == 'WIN') ? '"' : '';
|
| 525 |
-
$command = $brace . $paths['mysqldump'] . $brace . ' --host="' . DB_HOST . '" --user="' . DB_USER . '" --password="' . DB_PASSWORD . '" --add-drop-table --skip-lock-tables "' . DB_NAME . '" > ' . $brace . $file . $brace;
|
| 526 |
ob_start();
|
| 527 |
-
|
| 528 |
ob_get_clean();
|
| 529 |
|
| 530 |
if (!$result) { // Fallback to php
|
|
@@ -557,7 +718,6 @@ class MMB_Backup extends MMB_Core
|
|
| 557 |
else
|
| 558 |
$count = 1;
|
| 559 |
for ($i = 0; $i < $count; $i++) {
|
| 560 |
-
|
| 561 |
$low_limit = $i * 100;
|
| 562 |
$qry = "SELECT * FROM $table[0] LIMIT $low_limit, 100";
|
| 563 |
$rows = $wpdb->get_results($qry, ARRAY_A);
|
|
@@ -588,8 +748,8 @@ class MMB_Backup extends MMB_Core
|
|
| 588 |
if (filesize($file) == 0 || !is_file($file)) {
|
| 589 |
@unlink($file);
|
| 590 |
return array(
|
| 591 |
-
|
| 592 |
-
|
| 593 |
}
|
| 594 |
|
| 595 |
return $file;
|
|
@@ -597,15 +757,14 @@ class MMB_Backup extends MMB_Core
|
|
| 597 |
}
|
| 598 |
|
| 599 |
function restore($args)
|
| 600 |
-
{
|
| 601 |
-
|
| 602 |
global $wpdb;
|
| 603 |
if (empty($args)) {
|
| 604 |
return false;
|
| 605 |
}
|
| 606 |
|
| 607 |
extract($args);
|
| 608 |
-
@ini_set('memory_limit', '
|
| 609 |
@set_time_limit(600);
|
| 610 |
|
| 611 |
$unlink_file = true; //Delete file after restore
|
|
@@ -622,7 +781,7 @@ class MMB_Backup extends MMB_Core
|
|
| 622 |
}
|
| 623 |
$what = 'full';
|
| 624 |
} else {
|
| 625 |
-
$tasks = $this->
|
| 626 |
$task = $tasks[$task_name];
|
| 627 |
if (isset($task['task_results'][$result_id]['server'])) {
|
| 628 |
$backup_file = $task['task_results'][$result_id]['server']['file_path'];
|
|
@@ -656,7 +815,7 @@ class MMB_Backup extends MMB_Core
|
|
| 656 |
if ($overwrite) {
|
| 657 |
//Keep old db credentials before overwrite
|
| 658 |
if (!copy(ABSPATH . 'wp-config.php', ABSPATH . 'mwp-temp-wp-config.php')) {
|
| 659 |
-
|
| 660 |
return array(
|
| 661 |
'error' => 'Error creating wp-config. Please check your write permissions.'
|
| 662 |
);
|
|
@@ -665,29 +824,29 @@ class MMB_Backup extends MMB_Core
|
|
| 665 |
$db_host = DB_HOST;
|
| 666 |
$db_user = DB_USER;
|
| 667 |
$db_password = DB_PASSWORD;
|
| 668 |
-
$home = rtrim(get_option('home'),"/");
|
| 669 |
$site_url = get_option('site_url');
|
| 670 |
|
| 671 |
-
if(trim($clone_from_url) || trim($mwp_clone)){
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
|
|
|
| 677 |
|
| 678 |
-
|
| 679 |
}
|
| 680 |
|
| 681 |
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
if (!$result) { //fallback to pclzip
|
| 690 |
-
|
| 691 |
require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
|
| 692 |
$archive = new PclZip($backup_file);
|
| 693 |
$result = $archive->extract(PCLZIP_OPT_PATH, ABSPATH, PCLZIP_OPT_REPLACE_NEWER);
|
|
@@ -698,9 +857,9 @@ class MMB_Backup extends MMB_Core
|
|
| 698 |
}
|
| 699 |
|
| 700 |
if (!$result) {
|
| 701 |
-
|
| 702 |
-
|
| 703 |
-
|
| 704 |
}
|
| 705 |
|
| 706 |
$db_result = $this->restore_db();
|
|
@@ -710,7 +869,7 @@ class MMB_Backup extends MMB_Core
|
|
| 710 |
'error' => 'Error restoring database.'
|
| 711 |
);
|
| 712 |
}
|
| 713 |
-
|
| 714 |
} else {
|
| 715 |
return array(
|
| 716 |
'error' => 'Error restoring. Cannot find backup file.'
|
|
@@ -719,7 +878,6 @@ class MMB_Backup extends MMB_Core
|
|
| 719 |
|
| 720 |
//Replace options and content urls
|
| 721 |
if ($overwrite) {
|
| 722 |
-
|
| 723 |
//Get New Table prefix
|
| 724 |
$new_table_prefix = trim($this->get_table_prefix());
|
| 725 |
//Retrieve old wp_config
|
|
@@ -739,63 +897,60 @@ class MMB_Backup extends MMB_Core
|
|
| 739 |
//Replace options
|
| 740 |
$query = "SELECT option_value FROM " . $new_table_prefix . "options WHERE option_name = 'home'";
|
| 741 |
$old = $wpdb->get_var($wpdb->prepare($query));
|
| 742 |
-
$old
|
| 743 |
$query = "UPDATE " . $new_table_prefix . "options SET option_value = '$home' WHERE option_name = 'home'";
|
| 744 |
$wpdb->query($wpdb->prepare($query));
|
| 745 |
$query = "UPDATE " . $new_table_prefix . "options SET option_value = '$home' WHERE option_name = 'siteurl'";
|
| 746 |
$wpdb->query($wpdb->prepare($query));
|
| 747 |
//Replace content urls
|
| 748 |
$query = "UPDATE " . $new_table_prefix . "posts SET post_content = REPLACE (post_content, '$old','$home') WHERE post_content REGEXP 'src=\"(.*)$old(.*)\"' OR post_content REGEXP 'href=\"(.*)$old(.*)\"'";
|
| 749 |
-
$wpdb->query($wpdb->prepare($query));
|
| 750 |
|
| 751 |
-
if(trim($new_password)) {
|
| 752 |
-
|
| 753 |
}
|
| 754 |
-
if(!trim($clone_from_url) && !trim($mwp_clone)){
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
}
|
| 760 |
} else {
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
}
|
| 798 |
-
}
|
| 799 |
}
|
| 800 |
}
|
| 801 |
|
|
@@ -805,30 +960,29 @@ class MMB_Backup extends MMB_Core
|
|
| 805 |
function restore_db()
|
| 806 |
{
|
| 807 |
global $wpdb;
|
| 808 |
-
$paths
|
| 809 |
$file_path = ABSPATH . 'mwp_db';
|
| 810 |
$file_name = glob($file_path . '/*.sql');
|
| 811 |
$file_name = $file_name[0];
|
| 812 |
-
$brace
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
| 823 |
|
| 824 |
@unlink($file_name);
|
| 825 |
return true;
|
| 826 |
}
|
| 827 |
|
| 828 |
function restore_db_php($file_name)
|
| 829 |
-
{
|
| 830 |
-
|
| 831 |
-
global $wpdb;
|
| 832 |
$current_query = '';
|
| 833 |
// Read in entire file
|
| 834 |
$lines = file($file_name);
|
|
@@ -856,7 +1010,7 @@ class MMB_Backup extends MMB_Core
|
|
| 856 |
}
|
| 857 |
|
| 858 |
function get_table_prefix()
|
| 859 |
-
{
|
| 860 |
$lines = file(ABSPATH . 'wp-config.php');
|
| 861 |
foreach ($lines as $line) {
|
| 862 |
if (strstr($line, '$table_prefix')) {
|
|
@@ -914,17 +1068,16 @@ class MMB_Backup extends MMB_Core
|
|
| 914 |
$paths['mysqldump'] = 'mysqldump.exe';
|
| 915 |
}
|
| 916 |
} else {
|
| 917 |
-
|
| 918 |
-
|
| 919 |
-
|
| 920 |
-
|
| 921 |
-
|
| 922 |
-
|
| 923 |
-
|
| 924 |
-
$paths['mysqldump']='mysqldump'; // try anyway
|
| 925 |
|
| 926 |
}
|
| 927 |
-
|
| 928 |
|
| 929 |
return $paths;
|
| 930 |
}
|
|
@@ -945,7 +1098,7 @@ class MMB_Backup extends MMB_Core
|
|
| 945 |
|
| 946 |
}
|
| 947 |
|
| 948 |
-
function mmb_exec($command, $string = false)
|
| 949 |
{
|
| 950 |
if ($command == '')
|
| 951 |
return false;
|
|
@@ -955,36 +1108,49 @@ class MMB_Backup extends MMB_Core
|
|
| 955 |
|
| 956 |
if ($string)
|
| 957 |
return $log;
|
|
|
|
|
|
|
|
|
|
| 958 |
return $return ? false : true;
|
| 959 |
} elseif ($this->mmb_function_exists('system')) {
|
| 960 |
$log = @system($command, $return);
|
| 961 |
|
| 962 |
if ($string)
|
| 963 |
return $log;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 964 |
return $return ? false : true;
|
| 965 |
} elseif ($this->mmb_function_exists('passthru') && !$string) {
|
| 966 |
$log = passthru($command, $return);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 967 |
return $return ? false : true;
|
| 968 |
}
|
| 969 |
|
| 970 |
-
|
|
|
|
|
|
|
| 971 |
return false;
|
| 972 |
}
|
| 973 |
|
| 974 |
function get_zip()
|
| 975 |
{
|
| 976 |
-
|
| 977 |
-
|
| 978 |
-
|
| 979 |
-
|
| 980 |
}
|
| 981 |
|
| 982 |
function get_unzip()
|
| 983 |
{
|
| 984 |
-
|
| 985 |
-
|
| 986 |
-
|
| 987 |
-
|
| 988 |
}
|
| 989 |
|
| 990 |
function check_backup_compat()
|
|
@@ -1016,7 +1182,7 @@ class MMB_Backup extends MMB_Core
|
|
| 1016 |
}
|
| 1017 |
|
| 1018 |
|
| 1019 |
-
$file_path
|
| 1020 |
$reqs['Backup Folder']['status'] .= ' (' . $file_path . ')';
|
| 1021 |
|
| 1022 |
if ($func = $this->check_sys()) {
|
|
@@ -1029,15 +1195,15 @@ class MMB_Backup extends MMB_Core
|
|
| 1029 |
}
|
| 1030 |
$reqs['Zip']['status'] = $this->get_zip();
|
| 1031 |
|
| 1032 |
-
$reqs['Zip']['pass']
|
|
|
|
| 1033 |
|
| 1034 |
-
|
| 1035 |
|
| 1036 |
$reqs['Unzip']['status'] = $this->get_unzip();
|
| 1037 |
-
|
| 1038 |
-
$reqs['Unzip']['pass'] = true;
|
| 1039 |
|
| 1040 |
-
$
|
|
|
|
|
|
|
| 1041 |
|
| 1042 |
if (!empty($paths['mysqldump'])) {
|
| 1043 |
$reqs['MySQL Dump']['status'] = $paths['mysqldump'];
|
|
@@ -1048,29 +1214,44 @@ class MMB_Backup extends MMB_Core
|
|
| 1048 |
$reqs['MySQL Dump']['pass'] = false;
|
| 1049 |
}
|
| 1050 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1051 |
return $reqs;
|
| 1052 |
}
|
| 1053 |
|
| 1054 |
function email_backup($args)
|
| 1055 |
{
|
| 1056 |
-
$email
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1057 |
$backup_file = $args['file_path'];
|
| 1058 |
-
$task_name = isset($args['task_name']) ? $args['task_name']
|
| 1059 |
if (file_exists($backup_file) && $email) {
|
| 1060 |
$attachments = array(
|
| 1061 |
$backup_file
|
| 1062 |
);
|
| 1063 |
$headers = 'From: ManageWP <no-reply@managewp.com>' . "\r\n";
|
| 1064 |
-
$subject = "ManageWP - " . $task_name . " - "
|
| 1065 |
ob_start();
|
| 1066 |
$result = wp_mail($email, $subject, $subject, $headers, $attachments);
|
| 1067 |
ob_end_clean();
|
| 1068 |
|
| 1069 |
}
|
| 1070 |
|
| 1071 |
-
if(!$result){
|
| 1072 |
-
|
| 1073 |
-
'error' => 'Email not sent. Maybe your backup is too big for email or email server is not available on your website.'
|
| 1074 |
);
|
| 1075 |
}
|
| 1076 |
return true;
|
|
@@ -1081,49 +1262,49 @@ class MMB_Backup extends MMB_Core
|
|
| 1081 |
{
|
| 1082 |
extract($args);
|
| 1083 |
//Args: $ftp_username, $ftp_password, $ftp_hostname, $backup_file, $ftp_remote_folder, $ftp_site_folder
|
| 1084 |
-
if($ftp_ssl
|
| 1085 |
-
|
| 1086 |
-
|
| 1087 |
-
|
| 1088 |
-
return array(
|
| 1089 |
-
'error' => 'Your server doesn\'t support SFTP',
|
| 1090 |
-
'partial' => 1
|
| 1091 |
-
);
|
| 1092 |
-
}
|
| 1093 |
-
} else {
|
| 1094 |
-
if (function_exists('ftp_connect')) {
|
| 1095 |
-
$conn_id = ftp_connect($ftp_hostname);
|
| 1096 |
-
if ($conn_id === false) {
|
| 1097 |
return array(
|
| 1098 |
-
'error' => '
|
| 1099 |
'partial' => 1
|
| 1100 |
);
|
| 1101 |
}
|
| 1102 |
} else {
|
| 1103 |
-
|
| 1104 |
-
|
| 1105 |
-
|
| 1106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1107 |
}
|
| 1108 |
-
}
|
| 1109 |
$login = @ftp_login($conn_id, $ftp_username, $ftp_password);
|
| 1110 |
if ($login === false) {
|
| 1111 |
return array(
|
| 1112 |
'error' => 'FTP login failed for ' . $ftp_username . ', ' . $ftp_password,
|
| 1113 |
'partial' => 1
|
| 1114 |
);
|
| 1115 |
-
}
|
| 1116 |
|
| 1117 |
@ftp_mkdir($conn_id, $ftp_remote_folder);
|
| 1118 |
-
if($ftp_site_folder){
|
| 1119 |
-
|
| 1120 |
-
|
| 1121 |
-
|
| 1122 |
-
|
| 1123 |
$upload = @ftp_put($conn_id, $ftp_remote_folder . '/' . basename($backup_file), $backup_file, FTP_BINARY);
|
| 1124 |
|
| 1125 |
-
if($upload === false){ //Try ascii
|
| 1126 |
-
|
| 1127 |
}
|
| 1128 |
ftp_close($conn_id);
|
| 1129 |
|
|
@@ -1147,15 +1328,15 @@ class MMB_Backup extends MMB_Core
|
|
| 1147 |
$conn_id = ftp_connect($ftp_hostname);
|
| 1148 |
}
|
| 1149 |
|
| 1150 |
-
if($conn_id){
|
| 1151 |
-
|
| 1152 |
-
|
| 1153 |
-
|
| 1154 |
-
|
| 1155 |
-
|
| 1156 |
-
|
| 1157 |
-
|
| 1158 |
-
|
| 1159 |
|
| 1160 |
}
|
| 1161 |
|
|
@@ -1179,9 +1360,9 @@ class MMB_Backup extends MMB_Core
|
|
| 1179 |
} else {
|
| 1180 |
}
|
| 1181 |
|
| 1182 |
-
|
| 1183 |
-
|
| 1184 |
-
|
| 1185 |
$temp = ABSPATH . 'mwp_temp_backup.zip';
|
| 1186 |
$get = ftp_get($conn_id, $temp, $ftp_remote_folder . '/' . $backup_file, FTP_BINARY);
|
| 1187 |
if ($get === false) {
|
|
@@ -1194,24 +1375,24 @@ class MMB_Backup extends MMB_Core
|
|
| 1194 |
}
|
| 1195 |
|
| 1196 |
function dropbox_backup($args)
|
| 1197 |
-
{
|
| 1198 |
require_once('lib/dropbox.php');
|
| 1199 |
extract($args);
|
| 1200 |
|
| 1201 |
-
|
| 1202 |
-
|
| 1203 |
-
|
| 1204 |
-
|
| 1205 |
-
|
| 1206 |
'error' => 'Cannot upload file to Dropbox. Dropbox has upload limit of 300Mb per file.',
|
| 1207 |
'partial' => 1
|
| 1208 |
);
|
| 1209 |
-
|
| 1210 |
-
|
| 1211 |
-
|
| 1212 |
-
|
| 1213 |
-
|
| 1214 |
-
|
| 1215 |
$uploader = new DropboxUploader($dropbox_username, $dropbox_password);
|
| 1216 |
$uploader->upload($backup_file, $dropbox_destination);
|
| 1217 |
}
|
|
@@ -1228,42 +1409,43 @@ class MMB_Backup extends MMB_Core
|
|
| 1228 |
|
| 1229 |
function amazons3_backup($args)
|
| 1230 |
{
|
| 1231 |
-
|
| 1232 |
-
|
| 1233 |
-
|
| 1234 |
-
|
| 1235 |
-
|
| 1236 |
-
|
| 1237 |
-
|
| 1238 |
-
|
| 1239 |
-
|
| 1240 |
-
|
| 1241 |
-
|
| 1242 |
-
|
| 1243 |
-
|
| 1244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1245 |
} else {
|
| 1246 |
return array(
|
| 1247 |
-
'error' => '
|
| 1248 |
'partial' => 1
|
| 1249 |
);
|
| 1250 |
}
|
| 1251 |
-
} else {
|
| 1252 |
-
return array(
|
| 1253 |
-
'error' => 'You cannot use AmazonS3 on your server. Please enable curl first.',
|
| 1254 |
-
'partial' => 1
|
| 1255 |
-
);
|
| 1256 |
-
}
|
| 1257 |
}
|
| 1258 |
|
| 1259 |
function remove_amazons3_backup($args)
|
| 1260 |
{
|
| 1261 |
require_once('lib/s3.php');
|
| 1262 |
extract($args);
|
| 1263 |
-
if($as3_site_folder == true)
|
| 1264 |
-
|
| 1265 |
-
|
| 1266 |
-
$s3
|
| 1267 |
$s3->deleteObject($as3_bucket, $as3_directory . '/' . $backup_file);
|
| 1268 |
}
|
| 1269 |
|
|
@@ -1271,17 +1453,18 @@ class MMB_Backup extends MMB_Core
|
|
| 1271 |
{
|
| 1272 |
require_once('lib/s3.php');
|
| 1273 |
extract($args);
|
| 1274 |
-
$
|
| 1275 |
-
|
| 1276 |
-
|
| 1277 |
-
|
|
|
|
| 1278 |
$s3->getObject($as3_bucket, $as3_directory . '/' . $backup_file, $temp);
|
| 1279 |
$temp = ABSPATH . 'mwp_temp_backup.zip';
|
| 1280 |
return $temp;
|
| 1281 |
}
|
| 1282 |
|
| 1283 |
function schedule_next($type, $schedule)
|
| 1284 |
-
{
|
| 1285 |
$schedule = explode("|", $schedule);
|
| 1286 |
if (empty($schedule))
|
| 1287 |
return false;
|
|
@@ -1367,21 +1550,19 @@ class MMB_Backup extends MMB_Core
|
|
| 1367 |
function get_backup_stats()
|
| 1368 |
{
|
| 1369 |
$stats = array();
|
| 1370 |
-
$tasks =
|
| 1371 |
if (is_array($tasks) && !empty($tasks)) {
|
| 1372 |
foreach ($tasks as $task_name => $info) {
|
| 1373 |
-
|
| 1374 |
-
|
| 1375 |
-
|
| 1376 |
-
|
| 1377 |
-
|
| 1378 |
-
|
| 1379 |
-
|
| 1380 |
-
|
| 1381 |
-
|
| 1382 |
-
|
| 1383 |
-
}
|
| 1384 |
-
|
| 1385 |
$stats[$task_name] = array_values($info['task_results']);
|
| 1386 |
|
| 1387 |
}
|
|
@@ -1389,12 +1570,13 @@ class MMB_Backup extends MMB_Core
|
|
| 1389 |
return $stats;
|
| 1390 |
}
|
| 1391 |
|
| 1392 |
-
function get_next_schedules()
|
| 1393 |
-
|
| 1394 |
-
$
|
|
|
|
| 1395 |
if (is_array($tasks) && !empty($tasks)) {
|
| 1396 |
foreach ($tasks as $task_name => $info) {
|
| 1397 |
-
|
| 1398 |
}
|
| 1399 |
}
|
| 1400 |
return $stats;
|
|
@@ -1402,16 +1584,15 @@ class MMB_Backup extends MMB_Core
|
|
| 1402 |
|
| 1403 |
function remove_old_backups($task_name)
|
| 1404 |
{
|
| 1405 |
-
|
| 1406 |
-
|
| 1407 |
-
|
| 1408 |
-
|
| 1409 |
-
|
| 1410 |
-
$
|
| 1411 |
-
|
| 1412 |
-
$num = 0;
|
| 1413 |
} else {
|
| 1414 |
-
|
| 1415 |
}
|
| 1416 |
|
| 1417 |
|
|
@@ -1419,37 +1600,38 @@ class MMB_Backup extends MMB_Core
|
|
| 1419 |
//how many to remove ?
|
| 1420 |
$remove_num = (count($backups[$task_name]['task_results']) - $num - $backups[$task_name]['task_args']['limit']) + 1;
|
| 1421 |
for ($i = 0; $i < $remove_num; $i++) {
|
| 1422 |
-
|
| 1423 |
-
|
| 1424 |
-
|
| 1425 |
-
|
| 1426 |
-
|
| 1427 |
-
|
| 1428 |
-
|
| 1429 |
-
|
| 1430 |
-
|
| 1431 |
-
|
| 1432 |
-
|
| 1433 |
-
|
| 1434 |
-
|
| 1435 |
-
|
| 1436 |
-
|
| 1437 |
-
|
| 1438 |
-
|
| 1439 |
-
|
| 1440 |
-
|
| 1441 |
-
|
| 1442 |
-
|
| 1443 |
-
|
| 1444 |
-
|
| 1445 |
-
|
| 1446 |
//Remove database backup info
|
| 1447 |
unset($backups[$task_name]['task_results'][$i]);
|
| 1448 |
|
| 1449 |
} //end foreach
|
| 1450 |
|
| 1451 |
$backups[$task_name]['task_results'] = array_values($backups[$task_name]['task_results']);
|
| 1452 |
-
|
|
|
|
| 1453 |
}
|
| 1454 |
}
|
| 1455 |
|
|
@@ -1464,7 +1646,7 @@ class MMB_Backup extends MMB_Core
|
|
| 1464 |
return false;
|
| 1465 |
extract($args);
|
| 1466 |
|
| 1467 |
-
$tasks = $this->
|
| 1468 |
$task = $tasks[$task_name];
|
| 1469 |
$backups = $task['task_results'];
|
| 1470 |
$backup = $backups[$result_id];
|
|
@@ -1499,22 +1681,23 @@ class MMB_Backup extends MMB_Core
|
|
| 1499 |
unset($tasks[$task_name]['task_results']);
|
| 1500 |
}
|
| 1501 |
|
| 1502 |
-
|
|
|
|
| 1503 |
return true;
|
| 1504 |
|
| 1505 |
}
|
| 1506 |
|
| 1507 |
function cleanup()
|
| 1508 |
{
|
| 1509 |
-
$tasks
|
| 1510 |
-
$backup_folder
|
| 1511 |
-
$backup_folder_new = MWP_BACKUP_DIR.'/';
|
| 1512 |
-
$files
|
| 1513 |
-
$new
|
| 1514 |
|
| 1515 |
//Failed db files first
|
| 1516 |
-
$db_folder = MWP_DB_DIR.'/';
|
| 1517 |
-
$db_files
|
| 1518 |
if (is_array($db_files) && !empty($db_files)) {
|
| 1519 |
foreach ($db_files as $file) {
|
| 1520 |
@unlink($file);
|
|
@@ -1524,19 +1707,19 @@ class MMB_Backup extends MMB_Core
|
|
| 1524 |
|
| 1525 |
|
| 1526 |
//clean_old folder?
|
| 1527 |
-
if((basename($files[0]) == 'index.php' && count($files) == 1) || (empty($files))){
|
| 1528 |
-
|
| 1529 |
-
|
| 1530 |
-
|
| 1531 |
-
|
| 1532 |
-
|
| 1533 |
-
}
|
| 1534 |
-
|
| 1535 |
|
| 1536 |
-
foreach($new as $b){
|
| 1537 |
-
|
| 1538 |
}
|
| 1539 |
-
$deleted
|
| 1540 |
|
| 1541 |
if (is_array($files) && count($files)) {
|
| 1542 |
$results = array();
|
|
@@ -1572,7 +1755,8 @@ class MMB_Backup extends MMB_Core
|
|
| 1572 |
{
|
| 1573 |
if (!empty($args))
|
| 1574 |
extract($args);
|
| 1575 |
-
|
|
|
|
| 1576 |
$task = $tasks['Backup Now'];
|
| 1577 |
|
| 1578 |
if (!empty($task)) {
|
|
@@ -1586,48 +1770,38 @@ class MMB_Backup extends MMB_Core
|
|
| 1586 |
}
|
| 1587 |
|
| 1588 |
if ($backup_file && file_exists($backup_file)) {
|
| 1589 |
-
|
| 1590 |
-
|
| 1591 |
-
|
| 1592 |
-
|
| 1593 |
-
|
| 1594 |
-
|
| 1595 |
-
|
| 1596 |
-
$
|
| 1597 |
-
|
| 1598 |
-
|
| 1599 |
-
|
| 1600 |
-
|
| 1601 |
-
|
| 1602 |
-
|
| 1603 |
-
|
| 1604 |
-
|
| 1605 |
-
|
| 1606 |
-
|
| 1607 |
-
|
| 1608 |
-
|
| 1609 |
-
|
| 1610 |
-
|
| 1611 |
-
|
| 1612 |
-
|
| 1613 |
-
|
| 1614 |
-
|
| 1615 |
-
|
| 1616 |
-
|
| 1617 |
-
|
| 1618 |
-
if (isset($account_info['mwp_dropbox']) && !empty($account_info['mwp_dropbox'])) {
|
| 1619 |
-
$account_info['mwp_dropbox']['backup_file'] = $backup_file;
|
| 1620 |
-
$return = $this->dropbox_backup($account_info['mwp_dropbox']);
|
| 1621 |
-
}
|
| 1622 |
-
|
| 1623 |
-
if ($return == true && $del_host_file && !$email_backup) {
|
| 1624 |
-
@unlink($backup_file);
|
| 1625 |
-
unset($tasks['Backup Now']['task_results'][count($results) - 1]['server']);
|
| 1626 |
-
update_option('mwp_backup_tasks', $tasks);
|
| 1627 |
-
}
|
| 1628 |
-
|
| 1629 |
}
|
| 1630 |
|
|
|
|
|
|
|
| 1631 |
} else {
|
| 1632 |
$return = array(
|
| 1633 |
'error' => 'Backup file not found on your server. Please try again.'
|
|
@@ -1638,51 +1812,61 @@ class MMB_Backup extends MMB_Core
|
|
| 1638 |
|
| 1639 |
}
|
| 1640 |
|
| 1641 |
-
function validate_task($args
|
| 1642 |
-
|
| 1643 |
-
|
| 1644 |
-
|
| 1645 |
-
|
| 1646 |
-
|
| 1647 |
-
|
| 1648 |
-
|
| 1649 |
-
|
| 1650 |
-
|
| 1651 |
-
|
| 1652 |
-
|
| 1653 |
-
|
| 1654 |
-
|
|
|
|
|
|
|
| 1655 |
}
|
| 1656 |
|
| 1657 |
-
function update_status($task_name, $status, $completed = false)
|
| 1658 |
-
|
| 1659 |
-
|
| 1660 |
-
|
| 1661 |
-
|
| 1662 |
-
|
| 1663 |
-
|
| 1664 |
-
|
| 1665 |
-
|
| 1666 |
-
|
| 1667 |
-
|
| 1668 |
-
|
| 1669 |
-
|
| 1670 |
-
|
| 1671 |
-
|
| 1672 |
-
|
| 1673 |
-
|
| 1674 |
-
|
| 1675 |
-
|
| 1676 |
-
|
| 1677 |
-
|
| 1678 |
-
|
| 1679 |
-
|
| 1680 |
-
|
| 1681 |
-
|
| 1682 |
-
|
| 1683 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1684 |
}
|
| 1685 |
-
|
| 1686 |
}
|
| 1687 |
-
|
| 1688 |
?>
|
| 9 |
* Copyright (c) 2011 Prelovac Media
|
| 10 |
* www.prelovac.com
|
| 11 |
**************************************************************/
|
| 12 |
+
define('MWP_BACKUP_DIR', WP_CONTENT_DIR . '/managewp/backups');
|
| 13 |
+
define('MWP_DB_DIR', MWP_BACKUP_DIR . '/mwp_db');
|
| 14 |
+
|
| 15 |
+
$zip_errors = array(
|
| 16 |
+
'No error',
|
| 17 |
+
'No error',
|
| 18 |
+
'Unexpected end of zip file',
|
| 19 |
+
'A generic error in the zipfile format was detected.',
|
| 20 |
+
'zip was unable to allocate itself memory',
|
| 21 |
+
'A severe error in the zipfile format was detected',
|
| 22 |
+
'Entry too large to be split with zipsplit',
|
| 23 |
+
'Invalid comment format',
|
| 24 |
+
'zip -T failed or out of memory',
|
| 25 |
+
'The user aborted zip prematurely',
|
| 26 |
+
'zip encountered an error while using a temp file',
|
| 27 |
+
'Read or seek error',
|
| 28 |
+
'zip has nothing to do',
|
| 29 |
+
'Missing or empty zip file',
|
| 30 |
+
'Error writing to a file',
|
| 31 |
+
'zip was unable to create a file to write to',
|
| 32 |
+
'bad command line parameters',
|
| 33 |
+
'no error',
|
| 34 |
+
'zip could not open a specified file to read'
|
| 35 |
+
);
|
| 36 |
+
$unzip_errors = array(
|
| 37 |
+
'No error',
|
| 38 |
+
'One or more warning errors were encountered, but processing completed successfully anyway',
|
| 39 |
+
'A generic error in the zipfile format was detected',
|
| 40 |
+
'A severe error in the zipfile format was detected.',
|
| 41 |
+
'unzip was unable to allocate itself memory.',
|
| 42 |
+
'unzip was unable to allocate memory, or encountered an encryption error',
|
| 43 |
+
'unzip was unable to allocate memory during decompression to disk',
|
| 44 |
+
'unzip was unable allocate memory during in-memory decompression',
|
| 45 |
+
'unused',
|
| 46 |
+
'The specified zipfiles were not found',
|
| 47 |
+
'Bad command line parameters',
|
| 48 |
+
'No matching files were found',
|
| 49 |
+
50 => 'The disk is (or was) full during extraction',
|
| 50 |
+
51 => 'The end of the ZIP archive was encountered prematurely.',
|
| 51 |
+
80 => 'The user aborted unzip prematurely.',
|
| 52 |
+
81 => 'Testing or extraction of one or more files failed due to unsupported compression methods or unsupported decryption.',
|
| 53 |
+
82 => 'No files were found due to bad decryption password(s)'
|
| 54 |
+
);
|
| 55 |
+
|
| 56 |
|
| 57 |
class MMB_Backup extends MMB_Core
|
| 58 |
+
{
|
| 59 |
+
var $site_name;
|
| 60 |
+
var $statuses;
|
| 61 |
+
var $tasks;
|
| 62 |
+
var $s3;
|
| 63 |
+
var $ftp;
|
| 64 |
+
var $dropbox;
|
| 65 |
function __construct()
|
| 66 |
+
{
|
| 67 |
+
parent::__construct();
|
| 68 |
+
$this->site_name = str_replace(array(
|
| 69 |
+
"_",
|
| 70 |
+
"/"
|
| 71 |
+
), array(
|
| 72 |
+
"",
|
| 73 |
+
"-"
|
| 74 |
+
), rtrim($this->remove_http(get_bloginfo('url')), "/"));
|
| 75 |
+
$this->statuses = array(
|
| 76 |
+
'db_dump' => 1,
|
| 77 |
+
'db_zip' => 2,
|
| 78 |
+
'files_zip' => 3,
|
| 79 |
+
's3' => 4,
|
| 80 |
+
'dropbox' => 5,
|
| 81 |
+
'ftp' => 6,
|
| 82 |
+
'email' => 7,
|
| 83 |
+
'finished' => 100
|
| 84 |
+
);
|
| 85 |
+
$this->tasks = get_option('mwp_backup_tasks');
|
| 86 |
}
|
| 87 |
|
| 88 |
function get_backup_settings()
|
| 95 |
}
|
| 96 |
|
| 97 |
function set_backup_task($params)
|
| 98 |
+
{
|
| 99 |
//$params => [$task_name, $args, $error]
|
| 100 |
if (!empty($params)) {
|
| 101 |
extract($params);
|
| 102 |
|
| 103 |
+
//$before = $this->get_backup_settings();
|
| 104 |
+
$before = $this->tasks;
|
| 105 |
if (!$before || empty($before))
|
| 106 |
$before = array();
|
| 107 |
|
| 111 |
'removed' => true
|
| 112 |
);
|
| 113 |
} else {
|
| 114 |
+
if (is_array($params['account_info'])) { //only if sends from master first time(secure data)
|
| 115 |
+
$args['account_info'] = $account_info;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
$before[$task_name]['task_args'] = $args;
|
| 119 |
if (strlen($args['schedule']))
|
| 120 |
$before[$task_name]['task_args']['next'] = $this->schedule_next($args['type'], $args['schedule']);
|
| 124 |
|
| 125 |
//Update with error
|
| 126 |
if ($error) {
|
| 127 |
+
if (is_array($error)) {
|
| 128 |
+
$before[$task_name]['task_results'][count($before[$task_name]['task_results']) - 1]['error'] = $error['error'];
|
| 129 |
+
} else {
|
| 130 |
+
$before[$task_name]['task_results'][count($before[$task_name]['task_results'])]['error'] = $error;
|
| 131 |
+
}
|
| 132 |
}
|
| 133 |
|
| 134 |
+
if ($time) { //set next result time before backup
|
| 135 |
+
if (is_array($before[$task_name]['task_results'])) {
|
| 136 |
+
$before[$task_name]['task_results'] = array_values($before[$task_name]['task_results']);
|
| 137 |
+
}
|
| 138 |
+
$before[$task_name]['task_results'][count($before[$task_name]['task_results'])]['time'] = $time;
|
| 139 |
}
|
| 140 |
|
| 141 |
+
$this->update_tasks($before);
|
| 142 |
+
//update_option('mwp_backup_tasks', $before);
|
| 143 |
|
| 144 |
if ($task_name == 'Backup Now') {
|
| 145 |
$result = $this->backup($args, $task_name);
|
| 146 |
+
$backup_settings = $this->tasks;
|
| 147 |
|
| 148 |
if (is_array($result) && array_key_exists('error', $result)) {
|
| 149 |
$return = $result;
|
| 158 |
|
| 159 |
//Cron check
|
| 160 |
function check_backup_tasks()
|
| 161 |
+
{
|
| 162 |
+
//$settings = $this->get_backup_settings();
|
| 163 |
+
$settings = $this->tasks;
|
| 164 |
if (is_array($settings) && !empty($settings)) {
|
| 165 |
foreach ($settings as $task_name => $setting) {
|
| 166 |
if ($setting['task_args']['next'] && $setting['task_args']['next'] < time()) {
|
| 167 |
+
//if ($setting['task_args']['next'] && $_GET['force_backup']) {
|
| 168 |
+
if ($setting['task_args']['url'] && $setting['task_args']['task_id'] && $setting['task_args']['site_key']) {
|
| 169 |
+
//Check orphan task
|
| 170 |
+
$check_data = array(
|
| 171 |
+
'task_name' => $task_name,
|
| 172 |
+
'task_id' => $setting['task_args']['task_id'],
|
| 173 |
+
'site_key' => $setting['task_args']['site_key']
|
| 174 |
+
);
|
| 175 |
+
|
| 176 |
+
$this->validate_task($check_data, $setting['task_args']['url']);
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
//Update task with next schedule
|
| 180 |
$this->set_backup_task(array(
|
| 181 |
'task_name' => $task_name,
|
| 182 |
'args' => $settings[$task_name]['task_args'],
|
| 184 |
));
|
| 185 |
|
| 186 |
$result = $this->backup($setting['task_args'], $task_name);
|
| 187 |
+
$error = '';
|
| 188 |
if (is_array($result) && array_key_exists('error', $result)) {
|
| 189 |
$error = $result;
|
| 190 |
$this->set_backup_task(array(
|
| 191 |
+
'task_name' => $task_name,
|
| 192 |
+
'args' => $settings[$task_name]['task_args'],
|
| 193 |
+
'error' => $error
|
| 194 |
+
));
|
| 195 |
} else {
|
| 196 |
$error = '';
|
| 197 |
}
|
| 214 |
*/
|
| 215 |
|
| 216 |
function backup($args, $task_name = false)
|
| 217 |
+
{
|
| 218 |
if (!$args || empty($args))
|
| 219 |
return false;
|
| 220 |
|
| 221 |
extract($args); //extract settings
|
| 222 |
+
|
| 223 |
//Try increase memory limit and execution time
|
| 224 |
+
@ini_set('memory_limit', '256M');
|
| 225 |
@set_time_limit(600); //ten minutes
|
| 226 |
|
| 227 |
//Remove old backup(s)
|
| 228 |
$this->remove_old_backups($task_name);
|
| 229 |
+
|
| 230 |
$new_file_path = MWP_BACKUP_DIR;
|
| 231 |
|
| 232 |
if (!file_exists($new_file_path)) {
|
| 252 |
$backup_file = $new_file_path . '/' . $this->site_name . '_' . $label . '_' . $what . '_' . date('Y-m-d') . '_' . $hash . '.zip';
|
| 253 |
$backup_url = WP_CONTENT_URL . '/managewp/backups/' . $this->site_name . '_' . $label . '_' . $what . '_' . date('Y-m-d') . '_' . $hash . '.zip';
|
| 254 |
|
| 255 |
+
//Optimize tables?
|
| 256 |
+
if (isset($optimize_tables) && !empty($optimize_tables)) {
|
| 257 |
+
$this->optimize_tables();
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
//What to backup - db or full?
|
| 261 |
+
if (trim($what) == 'db') {
|
| 262 |
//Take database backup
|
| 263 |
+
$this->update_status($task_name, $this->statuses['db_dump']);
|
| 264 |
$db_result = $this->backup_db();
|
| 265 |
if ($db_result == false) {
|
| 266 |
return array(
|
| 271 |
'error' => $db_result['error']
|
| 272 |
);
|
| 273 |
} else {
|
| 274 |
+
$this->update_status($task_name, $this->statuses['db_dump'], true);
|
| 275 |
+
$this->update_status($task_name, $this->statuses['db_zip']);
|
| 276 |
+
|
| 277 |
+
$disable_comp = $this->tasks[$task_name]['task_args']['disable_comp'];
|
| 278 |
+
$comp_level = $disable_comp ? '-0' : '-1';
|
| 279 |
+
|
| 280 |
+
chdir(MWP_BACKUP_DIR);
|
| 281 |
+
$zip = $this->get_zip();
|
| 282 |
+
$command = "$zip -q -r $comp_level $backup_file 'mwp_db'";
|
| 283 |
+
ob_start();
|
| 284 |
+
$result = $this->mmb_exec($command);
|
| 285 |
+
ob_get_clean();
|
| 286 |
+
if (!$result) { // fallback to pclzip
|
| 287 |
+
define('PCLZIP_TEMPORARY_DIR', MWP_BACKUP_DIR . '/');
|
| 288 |
require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
|
| 289 |
$archive = new PclZip($backup_file);
|
| 290 |
+
if ($disable_comp) {
|
| 291 |
+
$result = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, MWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION);
|
| 292 |
+
} else {
|
| 293 |
+
$result = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, MWP_BACKUP_DIR);
|
| 294 |
+
}
|
| 295 |
@unlink($db_result);
|
| 296 |
+
@rmdir(MWP_DB_DIR);
|
| 297 |
+
if (!$result) {
|
| 298 |
+
return array(
|
| 299 |
+
'error' => 'Failed to zip database (pclZip - ' . $archive->error_code . '): .' . $archive->error_string
|
| 300 |
+
);
|
| 301 |
+
}
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
@unlink($db_result);
|
| 305 |
+
@rmdir(MWP_DB_DIR);
|
| 306 |
+
if (!$result) {
|
| 307 |
return array(
|
| 308 |
'error' => 'Failed to zip database.'
|
| 309 |
);
|
| 310 |
+
}
|
| 311 |
+
$this->update_status($task_name, $this->statuses['db_zip'], true);
|
| 312 |
}
|
| 313 |
} elseif (trim($what) == 'full') {
|
| 314 |
+
$content_backup = $this->backup_full($task_name, $backup_file, $exclude, $include);
|
| 315 |
if (is_array($content_backup) && array_key_exists('error', $content_backup)) {
|
| 316 |
return array(
|
| 317 |
'error' => $content_backup['error']
|
| 322 |
//Update backup info
|
| 323 |
if ($task_name) {
|
| 324 |
//backup task (scheduled)
|
| 325 |
+
$backup_settings = $this->tasks;
|
| 326 |
$paths = array();
|
| 327 |
$size = ceil(filesize($backup_file) / 1024);
|
| 328 |
|
| 329 |
if ($size > 1000) {
|
| 330 |
+
$paths['size'] = ceil($size / 1024) . "Mb";
|
| 331 |
} else {
|
| 332 |
$paths['size'] = $size . 'kb';
|
| 333 |
}
|
| 358 |
$paths['dropbox'] = basename($backup_url);
|
| 359 |
}
|
| 360 |
|
| 361 |
+
if (isset($backup_settings[$task_name]['task_args']['account_info']['mwp_email'])) {
|
|
|
|
| 362 |
$paths['email'] = basename($backup_url);
|
| 363 |
}
|
| 364 |
|
| 365 |
+
$temp = $backup_settings[$task_name]['task_results'];
|
| 366 |
+
$temp = array_values($temp);
|
| 367 |
$paths['time'] = time();
|
| 368 |
+
|
| 369 |
+
if ($task_name != 'Backup Now') {
|
| 370 |
+
$paths['status'] = $temp[count($temp) - 1]['status'];
|
| 371 |
+
$temp[count($temp) - 1] = $paths;
|
| 372 |
+
|
| 373 |
+
} else {
|
| 374 |
+
$temp[count($temp)] = $paths;
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
$backup_settings[$task_name]['task_results'] = $temp;
|
| 378 |
+
$this->update_tasks($backup_settings);
|
| 379 |
+
//update_option('mwp_backup_tasks', $backup_settings);
|
| 380 |
}
|
| 381 |
|
| 382 |
|
| 383 |
//Additional: Email, ftp, amazon_s3, dropbox...
|
|
|
|
|
|
|
|
|
|
| 384 |
|
| 385 |
if ($task_name != 'Backup Now') {
|
| 386 |
if (isset($account_info['mwp_ftp']) && !empty($account_info['mwp_ftp'])) {
|
| 387 |
+
$this->update_status($task_name, $this->statuses['ftp']);
|
| 388 |
$account_info['mwp_ftp']['backup_file'] = $backup_file;
|
| 389 |
+
$ftp_result = $this->ftp_backup($account_info['mwp_ftp']);
|
| 390 |
+
|
| 391 |
+
if ($ftp_result !== true && $del_host_file) {
|
| 392 |
+
@unlink($backup_file);
|
| 393 |
}
|
| 394 |
|
| 395 |
+
if (is_array($ftp_result) && isset($ftp_result['error'])) {
|
| 396 |
+
return $ftp_result;
|
| 397 |
}
|
| 398 |
+
$this->update_status($task_name, $this->statuses['ftp'], true);
|
| 399 |
}
|
| 400 |
|
| 401 |
if (isset($account_info['mwp_amazon_s3']) && !empty($account_info['mwp_amazon_s3'])) {
|
| 402 |
+
$this->update_status($task_name, $this->statuses['s3']);
|
| 403 |
$account_info['mwp_amazon_s3']['backup_file'] = $backup_file;
|
| 404 |
+
$amazons3_result = $this->amazons3_backup($account_info['mwp_amazon_s3']);
|
| 405 |
+
if ($amazons3_result !== true && $del_host_file) {
|
| 406 |
+
@unlink($backup_file);
|
| 407 |
}
|
| 408 |
+
if (is_array($amazons3_result) && isset($amazons3_result['error'])) {
|
| 409 |
+
return $amazons3_result;
|
| 410 |
}
|
| 411 |
+
$this->update_status($task_name, $this->statuses['s3'], true);
|
| 412 |
}
|
| 413 |
|
| 414 |
if (isset($account_info['mwp_dropbox']) && !empty($account_info['mwp_dropbox'])) {
|
| 415 |
+
$this->update_status($task_name, $this->statuses['dropbox']);
|
| 416 |
$account_info['mwp_dropbox']['backup_file'] = $backup_file;
|
| 417 |
+
$dropbox_result = $this->dropbox_backup($account_info['mwp_dropbox']);
|
| 418 |
+
if ($dropbox_result !== true && $del_host_file) {
|
| 419 |
+
@unlink($backup_file);
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
if (is_array($dropbox_result) && isset($dropbox_result['error'])) {
|
| 423 |
+
return $dropbox_result;
|
| 424 |
}
|
| 425 |
+
|
| 426 |
+
$this->update_status($task_name, $this->statuses['dropbox'], true);
|
| 427 |
}
|
| 428 |
|
| 429 |
+
if (isset($account_info['mwp_email']) && !empty($account_info['mwp_email'])) {
|
| 430 |
+
$this->update_status($task_name, $this->statuses['email']);
|
| 431 |
+
$account_info['mwp_email']['task_name'] = $task_name;
|
| 432 |
+
$account_info['mwp_email']['file_path'] = $backup_file;
|
| 433 |
+
|
| 434 |
+
$email_result = $this->email_backup($account_info['mwp_email']);
|
| 435 |
+
if (is_array($email_result) && isset($email_result['error'])) {
|
| 436 |
+
return $email_result;
|
| 437 |
+
}
|
| 438 |
+
$this->update_status($task_name, $this->statuses['email'], true);
|
| 439 |
}
|
| 440 |
|
| 441 |
if ($del_host_file) {
|
| 448 |
return $backup_url; //Return url to backup file
|
| 449 |
}
|
| 450 |
|
| 451 |
+
function backup_full($task_name, $backup_file, $exclude = array(), $include = array())
|
| 452 |
+
{
|
| 453 |
+
global $zip_errors;
|
| 454 |
+
$sys = substr(PHP_OS, 0, 3);
|
| 455 |
+
|
| 456 |
+
$this->update_status($task_name, $this->statuses['db_dump']);
|
| 457 |
$db_result = $this->backup_db();
|
| 458 |
|
| 459 |
if ($db_result == false) {
|
| 466 |
);
|
| 467 |
}
|
| 468 |
|
| 469 |
+
$this->update_status($task_name, $this->statuses['db_dump'], true);
|
| 470 |
+
$this->update_status($task_name, $this->statuses['db_zip']);
|
| 471 |
+
$disable_comp = $this->tasks[$task_name]['task_args']['disable_comp'];
|
| 472 |
+
$comp_level = $disable_comp ? '-0' : '-1';
|
| 473 |
|
| 474 |
$zip = $this->get_zip();
|
| 475 |
//Add database file
|
| 476 |
chdir(MWP_BACKUP_DIR);
|
| 477 |
+
$command = "$zip -q -r $comp_level $backup_file 'mwp_db'";
|
| 478 |
ob_start();
|
| 479 |
$result = $this->mmb_exec($command);
|
| 480 |
ob_get_clean();
|
| 481 |
|
| 482 |
+
|
| 483 |
+
if (!$result) {
|
| 484 |
+
define('PCLZIP_TEMPORARY_DIR', MWP_BACKUP_DIR . '/');
|
| 485 |
+
require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
|
| 486 |
+
$archive = new PclZip($backup_file);
|
| 487 |
|
| 488 |
+
if ($disable_comp) {
|
| 489 |
+
$result_db = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, MWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION);
|
| 490 |
+
} else {
|
| 491 |
+
$result_db = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, MWP_BACKUP_DIR);
|
| 492 |
+
}
|
| 493 |
|
| 494 |
@unlink($db_result);
|
| 495 |
@rmdir(MWP_DB_DIR);
|
| 496 |
|
| 497 |
+
if (!$result_db) {
|
| 498 |
+
return array(
|
| 499 |
+
'error' => 'Failed to zip database. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
|
| 500 |
+
);
|
| 501 |
}
|
| 502 |
+
}
|
| 503 |
+
|
| 504 |
+
@unlink($db_result);
|
| 505 |
+
@rmdir(MWP_DB_DIR);
|
| 506 |
+
|
| 507 |
+
$this->update_status($task_name, $this->statuses['db_zip'], true);
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
//Always remove backup folders
|
| 511 |
+
$remove = array(
|
| 512 |
+
trim(basename(WP_CONTENT_DIR)) . "/managewp/backups",
|
| 513 |
+
trim(basename(WP_CONTENT_DIR)) . "/" . md5('mmb-worker') . "/mwp_backups"
|
| 514 |
+
);
|
| 515 |
+
|
| 516 |
+
//Exclude paths
|
|
|
|
| 517 |
$exclude_data = "-x";
|
| 518 |
+
|
| 519 |
if (!empty($exclude)) {
|
| 520 |
+
foreach ($exclude as $data) {
|
| 521 |
+
if (is_dir(ABSPATH . $data)) {
|
| 522 |
+
if ($sys == 'WIN')
|
| 523 |
+
$exclude_data .= " $data/*.*";
|
| 524 |
+
else
|
| 525 |
$exclude_data .= " '$data/*'";
|
| 526 |
+
} else {
|
| 527 |
+
if ($sys == 'WIN')
|
| 528 |
+
$exclude_data .= " $data";
|
| 529 |
+
else
|
| 530 |
+
$exclude_data .= " '$data'";
|
| 531 |
}
|
| 532 |
+
}
|
| 533 |
}
|
| 534 |
+
|
| 535 |
+
foreach ($remove as $data) {
|
| 536 |
+
if ($sys == 'WIN')
|
| 537 |
+
$exclude_data .= " $data/*.*";
|
| 538 |
+
else
|
| 539 |
$exclude_data .= " '$data/*'";
|
| 540 |
}
|
| 541 |
|
| 542 |
+
//Include paths by default
|
| 543 |
+
$add = array(
|
| 544 |
+
trim(WPINC),
|
| 545 |
+
trim(basename(WP_CONTENT_DIR)),
|
| 546 |
+
"wp-admin"
|
| 547 |
+
);
|
| 548 |
+
|
| 549 |
+
$include_data = ". -i";
|
| 550 |
+
foreach ($add as $data) {
|
| 551 |
+
if ($sys == 'WIN')
|
| 552 |
+
$include_data .= " $data/*.*";
|
| 553 |
+
else
|
| 554 |
+
$include_data .= " '$data/*'";
|
| 555 |
+
}
|
| 556 |
+
|
| 557 |
+
//Additional includes?
|
| 558 |
+
if (!empty($include)) {
|
| 559 |
+
foreach ($include as $data) {
|
| 560 |
+
if ($data) {
|
| 561 |
+
if ($sys == 'WIN')
|
| 562 |
+
$include_data .= " $data/*.*";
|
| 563 |
+
else
|
| 564 |
+
$include_data .= " '$data/*'";
|
| 565 |
+
}
|
| 566 |
+
}
|
| 567 |
+
}
|
| 568 |
+
|
| 569 |
+
$this->update_status($task_name, $this->statuses['files_zip']);
|
| 570 |
chdir(ABSPATH);
|
|
|
|
| 571 |
ob_start();
|
| 572 |
+
$command = "$zip -q -j $comp_level $backup_file * $exclude_data";
|
| 573 |
+
$result_f = $this->mmb_exec($command, false, true);
|
| 574 |
+
|
| 575 |
+
if (!$result_f || $result_f == 18) { // disregard permissions error, file can't be accessed
|
| 576 |
+
$command = "$zip -q -r $comp_level $backup_file $include_data $exclude_data";
|
| 577 |
+
$result_d = $this->mmb_exec($command, false, true);
|
| 578 |
+
if ($result_d && $result_d != 18) {
|
| 579 |
+
@unlink($backup_file);
|
| 580 |
+
if ($result_d > 0 && $result_d < 18)
|
| 581 |
+
return array(
|
| 582 |
+
'error' => 'Failed to archive files (' . $zip_errors[$result_d] . ') .'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 583 |
);
|
| 584 |
+
else
|
| 585 |
+
return array(
|
| 586 |
+
'error' => 'Failed to archive files.'
|
| 587 |
+
);
|
| 588 |
+
}
|
| 589 |
}
|
| 590 |
+
ob_get_clean();
|
| 591 |
+
|
| 592 |
+
if ($result_f && $result_f != 18) { //Try pclZip
|
| 593 |
+
|
| 594 |
+
if (!isset($archive)) {
|
| 595 |
+
define('PCLZIP_TEMPORARY_DIR', MWP_BACKUP_DIR . '/');
|
| 596 |
+
require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
|
| 597 |
+
$archive = new PclZip($backup_file);
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
//Include paths
|
| 601 |
+
$include_data = array();
|
| 602 |
+
if (!empty($include)) {
|
| 603 |
+
foreach ($include as $data) {
|
| 604 |
+
if ($data && file_exists(ABSPATH . $data))
|
| 605 |
+
$include_data[] = ABSPATH . $data . '/';
|
| 606 |
+
}
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
+
foreach ($add as $data) {
|
| 610 |
+
if (file_exists(ABSPATH . $data))
|
| 611 |
+
$include_data[] = ABSPATH . $data . '/';
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
//Include root files
|
| 615 |
+
if ($handle = opendir(ABSPATH)) {
|
| 616 |
+
while (false !== ($file = readdir($handle))) {
|
| 617 |
+
if ($file != "." && $file != ".." && !is_dir($file) && file_exists(ABSPATH . $file)) {
|
| 618 |
+
$include_data[] = ABSPATH . $file;
|
| 619 |
+
}
|
| 620 |
+
}
|
| 621 |
+
closedir($handle);
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
if ($disable_comp) {
|
| 625 |
+
$result = $archive->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH, PCLZIP_OPT_NO_COMPRESSION);
|
| 626 |
+
} else {
|
| 627 |
+
$result = $archive->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH);
|
| 628 |
+
}
|
| 629 |
+
if (!$result) {
|
| 630 |
+
@unlink($backup_file);
|
| 631 |
+
return array(
|
| 632 |
+
'error' => 'Failed to zip files. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
|
| 633 |
+
);
|
| 634 |
+
}
|
| 635 |
+
|
| 636 |
+
//Now exclude paths
|
| 637 |
+
$exclude_data = array();
|
| 638 |
+
if (!empty($exclude)) {
|
| 639 |
foreach ($exclude as $data) {
|
| 640 |
+
if (is_dir(ABSPATH . $data))
|
| 641 |
$exclude_data[] = $data . '/';
|
| 642 |
+
else
|
| 643 |
+
$exclude_data[] = $data;
|
| 644 |
}
|
| 645 |
}
|
| 646 |
+
|
| 647 |
+
foreach ($remove as $rem) {
|
| 648 |
$exclude_data[] = $rem . '/';
|
| 649 |
}
|
| 650 |
|
| 651 |
$result_excl = $archive->delete(PCLZIP_OPT_BY_NAME, $exclude_data);
|
| 652 |
+
if (!$result_excl) {
|
| 653 |
+
@unlink($backup_file);
|
| 654 |
+
return array(
|
| 655 |
+
'error' => 'Failed to zip files. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
|
| 656 |
+
);
|
| 657 |
+
}
|
| 658 |
+
|
| 659 |
+
}
|
| 660 |
+
|
| 661 |
+
$this->update_status($task_name, $this->statuses['files_zip'], true);
|
| 662 |
+
return true;
|
| 663 |
+
}
|
| 664 |
|
| 665 |
|
| 666 |
function backup_db()
|
| 667 |
{
|
| 668 |
+
$db_folder = MWP_DB_DIR . '/';
|
| 669 |
if (!file_exists($db_folder)) {
|
| 670 |
if (!mkdir($db_folder, 0755, true))
|
| 671 |
return array(
|
| 672 |
+
'error' => 'Error creating database backup folder (' . $db_folder . '). Make sure you have corrrect write permissions.'
|
| 673 |
);
|
| 674 |
}
|
| 675 |
|
| 676 |
+
$file = $db_folder . DB_NAME . '.sql';
|
| 677 |
$result = $this->backup_db_dump($file); // try mysqldump always then fallback to php dump
|
| 678 |
return $result;
|
| 679 |
}
|
| 681 |
function backup_db_dump($file)
|
| 682 |
{
|
| 683 |
global $wpdb;
|
| 684 |
+
$paths = $this->check_mysql_paths();
|
| 685 |
$brace = (substr(PHP_OS, 0, 3) == 'WIN') ? '"' : '';
|
| 686 |
+
$command = $brace . $paths['mysqldump'] . $brace . ' --host="' . DB_HOST . '" --user="' . DB_USER . '" --password="' . DB_PASSWORD . '" --add-drop-table --skip-lock-tables "' . DB_NAME . '" > ' . $brace . $file . $brace;
|
| 687 |
ob_start();
|
| 688 |
+
$result = $this->mmb_exec($command);
|
| 689 |
ob_get_clean();
|
| 690 |
|
| 691 |
if (!$result) { // Fallback to php
|
| 718 |
else
|
| 719 |
$count = 1;
|
| 720 |
for ($i = 0; $i < $count; $i++) {
|
|
|
|
| 721 |
$low_limit = $i * 100;
|
| 722 |
$qry = "SELECT * FROM $table[0] LIMIT $low_limit, 100";
|
| 723 |
$rows = $wpdb->get_results($qry, ARRAY_A);
|
| 748 |
if (filesize($file) == 0 || !is_file($file)) {
|
| 749 |
@unlink($file);
|
| 750 |
return array(
|
| 751 |
+
'error' => 'Database backup failed. Try to enable MySQL dump on your server.'
|
| 752 |
+
);
|
| 753 |
}
|
| 754 |
|
| 755 |
return $file;
|
| 757 |
}
|
| 758 |
|
| 759 |
function restore($args)
|
| 760 |
+
{
|
|
|
|
| 761 |
global $wpdb;
|
| 762 |
if (empty($args)) {
|
| 763 |
return false;
|
| 764 |
}
|
| 765 |
|
| 766 |
extract($args);
|
| 767 |
+
@ini_set('memory_limit', '256M');
|
| 768 |
@set_time_limit(600);
|
| 769 |
|
| 770 |
$unlink_file = true; //Delete file after restore
|
| 781 |
}
|
| 782 |
$what = 'full';
|
| 783 |
} else {
|
| 784 |
+
$tasks = $this->tasks;
|
| 785 |
$task = $tasks[$task_name];
|
| 786 |
if (isset($task['task_results'][$result_id]['server'])) {
|
| 787 |
$backup_file = $task['task_results'][$result_id]['server']['file_path'];
|
| 815 |
if ($overwrite) {
|
| 816 |
//Keep old db credentials before overwrite
|
| 817 |
if (!copy(ABSPATH . 'wp-config.php', ABSPATH . 'mwp-temp-wp-config.php')) {
|
| 818 |
+
@unlink($backup_file);
|
| 819 |
return array(
|
| 820 |
'error' => 'Error creating wp-config. Please check your write permissions.'
|
| 821 |
);
|
| 824 |
$db_host = DB_HOST;
|
| 825 |
$db_user = DB_USER;
|
| 826 |
$db_password = DB_PASSWORD;
|
| 827 |
+
$home = rtrim(get_option('home'), "/");
|
| 828 |
$site_url = get_option('site_url');
|
| 829 |
|
| 830 |
+
if (trim($clone_from_url) || trim($mwp_clone)) {
|
| 831 |
+
$clone_options = array();
|
| 832 |
+
$clone_options['_worker_nossl_key'] = get_option('_worker_nossl_key');
|
| 833 |
+
$clone_options['_worker_public_key'] = get_option('_worker_public_key');
|
| 834 |
+
$clone_options['_action_message_id'] = get_option('_action_message_id');
|
| 835 |
+
}
|
| 836 |
+
|
| 837 |
|
|
|
|
| 838 |
}
|
| 839 |
|
| 840 |
|
| 841 |
+
chdir(ABSPATH);
|
| 842 |
+
$unzip = $this->get_unzip();
|
| 843 |
+
$command = "$unzip -o $backup_file";
|
| 844 |
+
ob_start();
|
| 845 |
+
$result = $this->mmb_exec($command);
|
| 846 |
+
ob_get_clean();
|
| 847 |
+
|
| 848 |
if (!$result) { //fallback to pclzip
|
| 849 |
+
define('PCLZIP_TEMPORARY_DIR', MWP_BACKUP_DIR . '/');
|
| 850 |
require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
|
| 851 |
$archive = new PclZip($backup_file);
|
| 852 |
$result = $archive->extract(PCLZIP_OPT_PATH, ABSPATH, PCLZIP_OPT_REPLACE_NEWER);
|
| 857 |
}
|
| 858 |
|
| 859 |
if (!$result) {
|
| 860 |
+
return array(
|
| 861 |
+
'error' => 'Failed to unzip files. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
|
| 862 |
+
);
|
| 863 |
}
|
| 864 |
|
| 865 |
$db_result = $this->restore_db();
|
| 869 |
'error' => 'Error restoring database.'
|
| 870 |
);
|
| 871 |
}
|
| 872 |
+
|
| 873 |
} else {
|
| 874 |
return array(
|
| 875 |
'error' => 'Error restoring. Cannot find backup file.'
|
| 878 |
|
| 879 |
//Replace options and content urls
|
| 880 |
if ($overwrite) {
|
|
|
|
| 881 |
//Get New Table prefix
|
| 882 |
$new_table_prefix = trim($this->get_table_prefix());
|
| 883 |
//Retrieve old wp_config
|
| 897 |
//Replace options
|
| 898 |
$query = "SELECT option_value FROM " . $new_table_prefix . "options WHERE option_name = 'home'";
|
| 899 |
$old = $wpdb->get_var($wpdb->prepare($query));
|
| 900 |
+
$old = rtrim($old, "/");
|
| 901 |
$query = "UPDATE " . $new_table_prefix . "options SET option_value = '$home' WHERE option_name = 'home'";
|
| 902 |
$wpdb->query($wpdb->prepare($query));
|
| 903 |
$query = "UPDATE " . $new_table_prefix . "options SET option_value = '$home' WHERE option_name = 'siteurl'";
|
| 904 |
$wpdb->query($wpdb->prepare($query));
|
| 905 |
//Replace content urls
|
| 906 |
$query = "UPDATE " . $new_table_prefix . "posts SET post_content = REPLACE (post_content, '$old','$home') WHERE post_content REGEXP 'src=\"(.*)$old(.*)\"' OR post_content REGEXP 'href=\"(.*)$old(.*)\"'";
|
| 907 |
+
$wpdb->query($wpdb->prepare($query));
|
| 908 |
|
| 909 |
+
if (trim($new_password)) {
|
| 910 |
+
$new_password = wp_hash_password($new_password);
|
| 911 |
}
|
| 912 |
+
if (!trim($clone_from_url) && !trim($mwp_clone)) {
|
| 913 |
+
if ($new_user && $new_password) {
|
| 914 |
+
$query = "UPDATE " . $new_table_prefix . "users SET user_login = '$new_user', user_pass = '$new_password' WHERE user_login = '$old_user'";
|
| 915 |
+
$wpdb->query($wpdb->prepare($query));
|
| 916 |
+
}
|
|
|
|
| 917 |
} else {
|
| 918 |
+
if ($clone_from_url) {
|
| 919 |
+
if ($new_user && $new_password) {
|
| 920 |
+
$query = "UPDATE " . $new_table_prefix . "users SET user_pass = '$new_password' WHERE user_login = '$new_user'";
|
| 921 |
+
$wpdb->query($wpdb->prepare($query));
|
| 922 |
+
}
|
| 923 |
+
}
|
| 924 |
+
|
| 925 |
+
if ($mwp_clone) {
|
| 926 |
+
if ($admin_email) {
|
| 927 |
+
//Clean Install
|
| 928 |
+
$query = "UPDATE " . $new_table_prefix . "options SET option_value = '$admin_email' WHERE option_name = 'admin_email'";
|
| 929 |
+
$wpdb->query($wpdb->prepare($query));
|
| 930 |
+
$query = "SELECT * FROM " . $new_table_prefix . "users LIMIT 1";
|
| 931 |
+
$temp_user = $wpdb->get_row($query);
|
| 932 |
+
if (!empty($temp_user)) {
|
| 933 |
+
$query = "UPDATE " . $new_table_prefix . "users SET user_email='$admin_email', user_login = '$new_user', user_pass = '$new_password' WHERE user_login = '$temp_user->user_login'";
|
| 934 |
+
$wpdb->query($wpdb->prepare($query));
|
| 935 |
+
}
|
| 936 |
+
}
|
| 937 |
+
}
|
| 938 |
+
}
|
| 939 |
+
|
| 940 |
+
if (is_array($clone_options)) {
|
| 941 |
+
foreach ($clone_options as $key => $option) {
|
| 942 |
+
if (!empty($key)) {
|
| 943 |
+
$query = "SELECT option_value FROM " . $new_table_prefix . "options WHERE option_name = '$key'";
|
| 944 |
+
$res = $wpdb->get_var($query);
|
| 945 |
+
if ($res == false) {
|
| 946 |
+
$query = "INSERT INTO " . $new_table_prefix . "options (option_value,option_name) VALUES('$option','$key')";
|
| 947 |
+
$wpdb->query($wpdb->prepare($query));
|
| 948 |
+
} else {
|
| 949 |
+
$query = "UPDATE " . $new_table_prefix . "options SET option_value = '$option' WHERE option_name = '$key'";
|
| 950 |
+
$wpdb->query($wpdb->prepare($query));
|
| 951 |
+
}
|
| 952 |
+
}
|
| 953 |
+
}
|
|
|
|
|
|
|
| 954 |
}
|
| 955 |
}
|
| 956 |
|
| 960 |
function restore_db()
|
| 961 |
{
|
| 962 |
global $wpdb;
|
| 963 |
+
$paths = $this->check_mysql_paths();
|
| 964 |
$file_path = ABSPATH . 'mwp_db';
|
| 965 |
$file_name = glob($file_path . '/*.sql');
|
| 966 |
$file_name = $file_name[0];
|
| 967 |
+
$brace = (substr(PHP_OS, 0, 3) == 'WIN') ? '"' : '';
|
| 968 |
+
$command = $brace . $paths['mysql'] . $brace . ' --host="' . DB_HOST . '" --user="' . DB_USER . '" --password="' . DB_PASSWORD . '" ' . DB_NAME . ' < ' . $brace . $file_name . $brace;
|
| 969 |
+
|
| 970 |
+
ob_start();
|
| 971 |
+
$result = $this->mmb_exec($command);
|
| 972 |
+
ob_get_clean();
|
| 973 |
+
if (!$result) {
|
| 974 |
+
//try php
|
| 975 |
+
$this->restore_db_php($file_name);
|
| 976 |
+
}
|
| 977 |
+
|
| 978 |
|
| 979 |
@unlink($file_name);
|
| 980 |
return true;
|
| 981 |
}
|
| 982 |
|
| 983 |
function restore_db_php($file_name)
|
| 984 |
+
{
|
| 985 |
+
global $wpdb;
|
|
|
|
| 986 |
$current_query = '';
|
| 987 |
// Read in entire file
|
| 988 |
$lines = file($file_name);
|
| 1010 |
}
|
| 1011 |
|
| 1012 |
function get_table_prefix()
|
| 1013 |
+
{
|
| 1014 |
$lines = file(ABSPATH . 'wp-config.php');
|
| 1015 |
foreach ($lines as $line) {
|
| 1016 |
if (strstr($line, '$table_prefix')) {
|
| 1068 |
$paths['mysqldump'] = 'mysqldump.exe';
|
| 1069 |
}
|
| 1070 |
} else {
|
| 1071 |
+
$paths['mysql'] = $this->mmb_exec('which mysql', true);
|
| 1072 |
+
if (empty($paths['mysql']))
|
| 1073 |
+
$paths['mysql'] = 'mysql'; // try anyway
|
| 1074 |
+
|
| 1075 |
+
$paths['mysqldump'] = $this->mmb_exec('which mysqldump', true);
|
| 1076 |
+
if (empty($paths['mysqldump']))
|
| 1077 |
+
$paths['mysqldump'] = 'mysqldump'; // try anyway
|
|
|
|
| 1078 |
|
| 1079 |
}
|
| 1080 |
+
|
| 1081 |
|
| 1082 |
return $paths;
|
| 1083 |
}
|
| 1098 |
|
| 1099 |
}
|
| 1100 |
|
| 1101 |
+
function mmb_exec($command, $string = false, $rawreturn = false)
|
| 1102 |
{
|
| 1103 |
if ($command == '')
|
| 1104 |
return false;
|
| 1108 |
|
| 1109 |
if ($string)
|
| 1110 |
return $log;
|
| 1111 |
+
if ($rawreturn)
|
| 1112 |
+
return $return;
|
| 1113 |
+
|
| 1114 |
return $return ? false : true;
|
| 1115 |
} elseif ($this->mmb_function_exists('system')) {
|
| 1116 |
$log = @system($command, $return);
|
| 1117 |
|
| 1118 |
if ($string)
|
| 1119 |
return $log;
|
| 1120 |
+
|
| 1121 |
+
if ($rawreturn)
|
| 1122 |
+
return $return;
|
| 1123 |
+
|
| 1124 |
return $return ? false : true;
|
| 1125 |
} elseif ($this->mmb_function_exists('passthru') && !$string) {
|
| 1126 |
$log = passthru($command, $return);
|
| 1127 |
+
|
| 1128 |
+
if ($rawreturn)
|
| 1129 |
+
return $return;
|
| 1130 |
+
|
| 1131 |
return $return ? false : true;
|
| 1132 |
}
|
| 1133 |
|
| 1134 |
+
if ($rawreturn)
|
| 1135 |
+
return -1;
|
| 1136 |
+
|
| 1137 |
return false;
|
| 1138 |
}
|
| 1139 |
|
| 1140 |
function get_zip()
|
| 1141 |
{
|
| 1142 |
+
$zip = $this->mmb_exec('which zip', true);
|
| 1143 |
+
if (!$zip)
|
| 1144 |
+
$zip = "zip";
|
| 1145 |
+
return $zip;
|
| 1146 |
}
|
| 1147 |
|
| 1148 |
function get_unzip()
|
| 1149 |
{
|
| 1150 |
+
$unzip = $this->mmb_exec('which unzip', true);
|
| 1151 |
+
if (!$unzip)
|
| 1152 |
+
$unzip = "unzip";
|
| 1153 |
+
return $unzip;
|
| 1154 |
}
|
| 1155 |
|
| 1156 |
function check_backup_compat()
|
| 1182 |
}
|
| 1183 |
|
| 1184 |
|
| 1185 |
+
$file_path = MWP_BACKUP_DIR;
|
| 1186 |
$reqs['Backup Folder']['status'] .= ' (' . $file_path . ')';
|
| 1187 |
|
| 1188 |
if ($func = $this->check_sys()) {
|
| 1195 |
}
|
| 1196 |
$reqs['Zip']['status'] = $this->get_zip();
|
| 1197 |
|
| 1198 |
+
$reqs['Zip']['pass'] = true;
|
| 1199 |
+
|
| 1200 |
|
|
|
|
| 1201 |
|
| 1202 |
$reqs['Unzip']['status'] = $this->get_unzip();
|
|
|
|
|
|
|
| 1203 |
|
| 1204 |
+
$reqs['Unzip']['pass'] = true;
|
| 1205 |
+
|
| 1206 |
+
$paths = $this->check_mysql_paths();
|
| 1207 |
|
| 1208 |
if (!empty($paths['mysqldump'])) {
|
| 1209 |
$reqs['MySQL Dump']['status'] = $paths['mysqldump'];
|
| 1214 |
$reqs['MySQL Dump']['pass'] = false;
|
| 1215 |
}
|
| 1216 |
|
| 1217 |
+
$exec_time = ini_get('max_execution_time');
|
| 1218 |
+
$reqs['Execution time']['status'] = $exec_time ? $exec_time . "s" : 'unknown';
|
| 1219 |
+
$reqs['Execution time']['pass'] = true;
|
| 1220 |
+
|
| 1221 |
+
$mem_limit = ini_get('memory_limit');
|
| 1222 |
+
$reqs['Memory limit']['status'] = $mem_limit ? $mem_limit : 'unknown';
|
| 1223 |
+
$reqs['Memory limit']['pass'] = true;
|
| 1224 |
+
|
| 1225 |
+
|
| 1226 |
return $reqs;
|
| 1227 |
}
|
| 1228 |
|
| 1229 |
function email_backup($args)
|
| 1230 |
{
|
| 1231 |
+
$email = $args['email'];
|
| 1232 |
+
|
| 1233 |
+
if (!is_email($email)) {
|
| 1234 |
+
return array(
|
| 1235 |
+
'error' => 'Your email (' . $email . ') is not correct'
|
| 1236 |
+
);
|
| 1237 |
+
}
|
| 1238 |
$backup_file = $args['file_path'];
|
| 1239 |
+
$task_name = isset($args['task_name']) ? $args['task_name'] : '';
|
| 1240 |
if (file_exists($backup_file) && $email) {
|
| 1241 |
$attachments = array(
|
| 1242 |
$backup_file
|
| 1243 |
);
|
| 1244 |
$headers = 'From: ManageWP <no-reply@managewp.com>' . "\r\n";
|
| 1245 |
+
$subject = "ManageWP - " . $task_name . " - " . $this->site_name;
|
| 1246 |
ob_start();
|
| 1247 |
$result = wp_mail($email, $subject, $subject, $headers, $attachments);
|
| 1248 |
ob_end_clean();
|
| 1249 |
|
| 1250 |
}
|
| 1251 |
|
| 1252 |
+
if (!$result) {
|
| 1253 |
+
return array(
|
| 1254 |
+
'error' => 'Email not sent. Maybe your backup is too big for email or email server is not available on your website.'
|
| 1255 |
);
|
| 1256 |
}
|
| 1257 |
return true;
|
| 1262 |
{
|
| 1263 |
extract($args);
|
| 1264 |
//Args: $ftp_username, $ftp_password, $ftp_hostname, $backup_file, $ftp_remote_folder, $ftp_site_folder
|
| 1265 |
+
if ($ftp_ssl) {
|
| 1266 |
+
if (function_exists('ftp_ssl_connect')) {
|
| 1267 |
+
$conn_id = ftp_ssl_connect($ftp_hostname);
|
| 1268 |
+
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1269 |
return array(
|
| 1270 |
+
'error' => 'Your server doesn\'t support SFTP',
|
| 1271 |
'partial' => 1
|
| 1272 |
);
|
| 1273 |
}
|
| 1274 |
} else {
|
| 1275 |
+
if (function_exists('ftp_connect')) {
|
| 1276 |
+
$conn_id = ftp_connect($ftp_hostname);
|
| 1277 |
+
if ($conn_id === false) {
|
| 1278 |
+
return array(
|
| 1279 |
+
'error' => 'Failed to connect to ' . $ftp_hostname,
|
| 1280 |
+
'partial' => 1
|
| 1281 |
+
);
|
| 1282 |
+
}
|
| 1283 |
+
} else {
|
| 1284 |
+
return array(
|
| 1285 |
+
'error' => 'Your server doesn\'t support FTP',
|
| 1286 |
+
'partial' => 1
|
| 1287 |
+
);
|
| 1288 |
+
}
|
| 1289 |
}
|
|
|
|
| 1290 |
$login = @ftp_login($conn_id, $ftp_username, $ftp_password);
|
| 1291 |
if ($login === false) {
|
| 1292 |
return array(
|
| 1293 |
'error' => 'FTP login failed for ' . $ftp_username . ', ' . $ftp_password,
|
| 1294 |
'partial' => 1
|
| 1295 |
);
|
| 1296 |
+
}
|
| 1297 |
|
| 1298 |
@ftp_mkdir($conn_id, $ftp_remote_folder);
|
| 1299 |
+
if ($ftp_site_folder) {
|
| 1300 |
+
$ftp_remote_folder .= '/' . $this->site_name;
|
| 1301 |
+
}
|
| 1302 |
+
@ftp_mkdir($conn_id, $ftp_remote_folder);
|
| 1303 |
+
|
| 1304 |
$upload = @ftp_put($conn_id, $ftp_remote_folder . '/' . basename($backup_file), $backup_file, FTP_BINARY);
|
| 1305 |
|
| 1306 |
+
if ($upload === false) { //Try ascii
|
| 1307 |
+
$upload = @ftp_put($conn_id, $ftp_remote_folder . '/' . basename($backup_file), $backup_file, FTP_ASCII);
|
| 1308 |
}
|
| 1309 |
ftp_close($conn_id);
|
| 1310 |
|
| 1328 |
$conn_id = ftp_connect($ftp_hostname);
|
| 1329 |
}
|
| 1330 |
|
| 1331 |
+
if ($conn_id) {
|
| 1332 |
+
$login = @ftp_login($conn_id, $ftp_username, $ftp_password);
|
| 1333 |
+
if ($ftp_site_folder)
|
| 1334 |
+
$ftp_remote_folder .= '/' . $this->site_name;
|
| 1335 |
+
|
| 1336 |
+
$delete = ftp_delete($conn_id, $ftp_remote_folder . '/' . $backup_file);
|
| 1337 |
+
|
| 1338 |
+
ftp_close($conn_id);
|
| 1339 |
+
}
|
| 1340 |
|
| 1341 |
}
|
| 1342 |
|
| 1360 |
} else {
|
| 1361 |
}
|
| 1362 |
|
| 1363 |
+
if ($ftp_site_folder)
|
| 1364 |
+
$ftp_remote_folder .= '/' . $this->site_name;
|
| 1365 |
+
|
| 1366 |
$temp = ABSPATH . 'mwp_temp_backup.zip';
|
| 1367 |
$get = ftp_get($conn_id, $temp, $ftp_remote_folder . '/' . $backup_file, FTP_BINARY);
|
| 1368 |
if ($get === false) {
|
| 1375 |
}
|
| 1376 |
|
| 1377 |
function dropbox_backup($args)
|
| 1378 |
+
{
|
| 1379 |
require_once('lib/dropbox.php');
|
| 1380 |
extract($args);
|
| 1381 |
|
| 1382 |
+
//$email, $password, $backup_file, $destination, $dropbox_site_folder
|
| 1383 |
+
|
| 1384 |
+
$size = ceil(filesize($backup_file) / 1024);
|
| 1385 |
+
if ($size > 300000) {
|
| 1386 |
+
return array(
|
| 1387 |
'error' => 'Cannot upload file to Dropbox. Dropbox has upload limit of 300Mb per file.',
|
| 1388 |
'partial' => 1
|
| 1389 |
);
|
| 1390 |
+
}
|
| 1391 |
+
|
| 1392 |
+
if ($dropbox_site_folder == true)
|
| 1393 |
+
$dropbox_destination .= '/' . $this->site_name;
|
| 1394 |
+
|
| 1395 |
+
try {
|
| 1396 |
$uploader = new DropboxUploader($dropbox_username, $dropbox_password);
|
| 1397 |
$uploader->upload($backup_file, $dropbox_destination);
|
| 1398 |
}
|
| 1409 |
|
| 1410 |
function amazons3_backup($args)
|
| 1411 |
{
|
| 1412 |
+
if ($this->mmb_function_exists('curl_init')) {
|
| 1413 |
+
require_once('lib/s3.php');
|
| 1414 |
+
extract($args);
|
| 1415 |
+
|
| 1416 |
+
if ($as3_site_folder == true)
|
| 1417 |
+
$as3_directory .= '/' . $this->site_name;
|
| 1418 |
+
|
| 1419 |
+
$endpoint = isset($as3_bucket_region) ? $as3_bucket_region : 's3.amazonaws.com';
|
| 1420 |
+
|
| 1421 |
+
$s3 = new S3(trim($as3_access_key), trim(str_replace(' ', '+', $as3_secure_key)), false, $endpoint);
|
| 1422 |
+
|
| 1423 |
+
$s3->putBucket($as3_bucket, S3::ACL_PUBLIC_READ);
|
| 1424 |
+
|
| 1425 |
+
if ($s3->putObjectFile($backup_file, $as3_bucket, $as3_directory . '/' . basename($backup_file), S3::ACL_PRIVATE)) {
|
| 1426 |
+
return true;
|
| 1427 |
+
} else {
|
| 1428 |
+
return array(
|
| 1429 |
+
'error' => 'Failed to upload to Amazon S3. Please check your details and set upload/delete permissions on your bucket.',
|
| 1430 |
+
'partial' => 1
|
| 1431 |
+
);
|
| 1432 |
+
}
|
| 1433 |
} else {
|
| 1434 |
return array(
|
| 1435 |
+
'error' => 'You cannot use Amazon S3 on your server. Please enable curl first.',
|
| 1436 |
'partial' => 1
|
| 1437 |
);
|
| 1438 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1439 |
}
|
| 1440 |
|
| 1441 |
function remove_amazons3_backup($args)
|
| 1442 |
{
|
| 1443 |
require_once('lib/s3.php');
|
| 1444 |
extract($args);
|
| 1445 |
+
if ($as3_site_folder == true)
|
| 1446 |
+
$as3_directory .= '/' . $this->site_name;
|
| 1447 |
+
$endpoint = isset($as3_bucket_region) ? $as3_bucket_region : 's3.amazonaws.com';
|
| 1448 |
+
$s3 = new S3($as3_access_key, str_replace(' ', '+', $as3_secure_key), false, $endpoint);
|
| 1449 |
$s3->deleteObject($as3_bucket, $as3_directory . '/' . $backup_file);
|
| 1450 |
}
|
| 1451 |
|
| 1453 |
{
|
| 1454 |
require_once('lib/s3.php');
|
| 1455 |
extract($args);
|
| 1456 |
+
$endpoint = isset($as3_bucket_region) ? $as3_bucket_region : 's3.amazonaws.com';
|
| 1457 |
+
$s3 = new S3($as3_access_key, str_replace(' ', '+', $as3_secure_key), false, $endpoint);
|
| 1458 |
+
if ($as3_site_folder == true)
|
| 1459 |
+
$as3_directory .= '/' . $this->site_name;
|
| 1460 |
+
|
| 1461 |
$s3->getObject($as3_bucket, $as3_directory . '/' . $backup_file, $temp);
|
| 1462 |
$temp = ABSPATH . 'mwp_temp_backup.zip';
|
| 1463 |
return $temp;
|
| 1464 |
}
|
| 1465 |
|
| 1466 |
function schedule_next($type, $schedule)
|
| 1467 |
+
{
|
| 1468 |
$schedule = explode("|", $schedule);
|
| 1469 |
if (empty($schedule))
|
| 1470 |
return false;
|
| 1550 |
function get_backup_stats()
|
| 1551 |
{
|
| 1552 |
$stats = array();
|
| 1553 |
+
$tasks = $this->tasks;
|
| 1554 |
if (is_array($tasks) && !empty($tasks)) {
|
| 1555 |
foreach ($tasks as $task_name => $info) {
|
| 1556 |
+
if (is_array($info['task_results']) && !empty($info['task_results'])) {
|
| 1557 |
+
foreach ($info['task_results'] as $key => $result) {
|
| 1558 |
+
if (isset($result['server']) && !isset($result['error'])) {
|
| 1559 |
+
if (!file_exists($result['server']['file_path'])) {
|
| 1560 |
+
$info['task_results'][$key]['error'] = 'Backup created but manually removed from server.';
|
| 1561 |
+
}
|
| 1562 |
+
}
|
| 1563 |
+
}
|
| 1564 |
+
}
|
| 1565 |
+
|
|
|
|
|
|
|
| 1566 |
$stats[$task_name] = array_values($info['task_results']);
|
| 1567 |
|
| 1568 |
}
|
| 1570 |
return $stats;
|
| 1571 |
}
|
| 1572 |
|
| 1573 |
+
function get_next_schedules()
|
| 1574 |
+
{
|
| 1575 |
+
$stats = array();
|
| 1576 |
+
$tasks = $this->tasks;
|
| 1577 |
if (is_array($tasks) && !empty($tasks)) {
|
| 1578 |
foreach ($tasks as $task_name => $info) {
|
| 1579 |
+
$stats[$task_name] = $info['task_args']['next'];
|
| 1580 |
}
|
| 1581 |
}
|
| 1582 |
return $stats;
|
| 1584 |
|
| 1585 |
function remove_old_backups($task_name)
|
| 1586 |
{
|
| 1587 |
+
//Check for previous failed backups first
|
| 1588 |
+
$this->cleanup();
|
| 1589 |
+
|
| 1590 |
+
//Remove by limit
|
| 1591 |
+
$backups = $this->tasks;
|
| 1592 |
+
if ($task_name == 'Backup Now') {
|
| 1593 |
+
$num = 0;
|
|
|
|
| 1594 |
} else {
|
| 1595 |
+
$num = 1;
|
| 1596 |
}
|
| 1597 |
|
| 1598 |
|
| 1600 |
//how many to remove ?
|
| 1601 |
$remove_num = (count($backups[$task_name]['task_results']) - $num - $backups[$task_name]['task_args']['limit']) + 1;
|
| 1602 |
for ($i = 0; $i < $remove_num; $i++) {
|
| 1603 |
+
//Remove from the server
|
| 1604 |
+
if (isset($backups[$task_name]['task_results'][$i]['server'])) {
|
| 1605 |
+
@unlink($backups[$task_name]['task_results'][$i]['server']['file_path']);
|
| 1606 |
+
}
|
| 1607 |
+
|
| 1608 |
+
//Remove from ftp
|
| 1609 |
+
if (isset($backups[$task_name]['task_results'][$i]['ftp'])) {
|
| 1610 |
+
$ftp_file = $backups[$task_name]['task_results'][$i]['ftp'];
|
| 1611 |
+
$args = $backups[$task_name]['task_args']['account_info']['mwp_ftp'];
|
| 1612 |
+
$args['backup_file'] = $ftp_file;
|
| 1613 |
+
$this->remove_ftp_backup($args);
|
| 1614 |
+
}
|
| 1615 |
+
|
| 1616 |
+
if (isset($backups[$task_name]['task_results'][$i]['amazons3'])) {
|
| 1617 |
+
$amazons3_file = $backups[$task_name]['task_results'][$i]['amazons3'];
|
| 1618 |
+
$args = $backups[$task_name]['task_args']['account_info']['mwp_amazon_s3'];
|
| 1619 |
+
$args['backup_file'] = $amazons3_file;
|
| 1620 |
+
$this->remove_amazons3_backup($args);
|
| 1621 |
+
}
|
| 1622 |
+
|
| 1623 |
+
if (isset($backups[$task_name]['task_results'][$i]['dropbox'])) {
|
| 1624 |
+
//To do: dropbox remove
|
| 1625 |
+
}
|
| 1626 |
+
|
| 1627 |
//Remove database backup info
|
| 1628 |
unset($backups[$task_name]['task_results'][$i]);
|
| 1629 |
|
| 1630 |
} //end foreach
|
| 1631 |
|
| 1632 |
$backups[$task_name]['task_results'] = array_values($backups[$task_name]['task_results']);
|
| 1633 |
+
$this->update_tasks($backups);
|
| 1634 |
+
//update_option('mwp_backup_tasks', $backups);
|
| 1635 |
}
|
| 1636 |
}
|
| 1637 |
|
| 1646 |
return false;
|
| 1647 |
extract($args);
|
| 1648 |
|
| 1649 |
+
$tasks = $this->tasks;
|
| 1650 |
$task = $tasks[$task_name];
|
| 1651 |
$backups = $task['task_results'];
|
| 1652 |
$backup = $backups[$result_id];
|
| 1681 |
unset($tasks[$task_name]['task_results']);
|
| 1682 |
}
|
| 1683 |
|
| 1684 |
+
$this->update_tasks($tasks);
|
| 1685 |
+
//update_option('mwp_backup_tasks', $tasks);
|
| 1686 |
return true;
|
| 1687 |
|
| 1688 |
}
|
| 1689 |
|
| 1690 |
function cleanup()
|
| 1691 |
{
|
| 1692 |
+
$tasks = $this->tasks;
|
| 1693 |
+
$backup_folder = WP_CONTENT_DIR . '/' . md5('mmb-worker') . '/mwp_backups/';
|
| 1694 |
+
$backup_folder_new = MWP_BACKUP_DIR . '/';
|
| 1695 |
+
$files = glob($backup_folder . "*");
|
| 1696 |
+
$new = glob($backup_folder_new . "*");
|
| 1697 |
|
| 1698 |
//Failed db files first
|
| 1699 |
+
$db_folder = MWP_DB_DIR . '/';
|
| 1700 |
+
$db_files = glob($db_folder . "*");
|
| 1701 |
if (is_array($db_files) && !empty($db_files)) {
|
| 1702 |
foreach ($db_files as $file) {
|
| 1703 |
@unlink($file);
|
| 1707 |
|
| 1708 |
|
| 1709 |
//clean_old folder?
|
| 1710 |
+
if ((basename($files[0]) == 'index.php' && count($files) == 1) || (empty($files))) {
|
| 1711 |
+
foreach ($files as $file) {
|
| 1712 |
+
@unlink($file);
|
| 1713 |
+
}
|
| 1714 |
+
@rmdir(WP_CONTENT_DIR . '/' . md5('mmb-worker') . '/mwp_backups');
|
| 1715 |
+
@rmdir(WP_CONTENT_DIR . '/' . md5('mmb-worker'));
|
| 1716 |
+
}
|
| 1717 |
+
|
| 1718 |
|
| 1719 |
+
foreach ($new as $b) {
|
| 1720 |
+
$files[] = $b;
|
| 1721 |
}
|
| 1722 |
+
$deleted = array();
|
| 1723 |
|
| 1724 |
if (is_array($files) && count($files)) {
|
| 1725 |
$results = array();
|
| 1755 |
{
|
| 1756 |
if (!empty($args))
|
| 1757 |
extract($args);
|
| 1758 |
+
|
| 1759 |
+
$tasks = $this->tasks;
|
| 1760 |
$task = $tasks['Backup Now'];
|
| 1761 |
|
| 1762 |
if (!empty($task)) {
|
| 1770 |
}
|
| 1771 |
|
| 1772 |
if ($backup_file && file_exists($backup_file)) {
|
| 1773 |
+
//FTP, Amazon S3 or Dropbox
|
| 1774 |
+
if (isset($account_info['mwp_ftp']) && !empty($account_info['mwp_ftp'])) {
|
| 1775 |
+
$account_info['mwp_ftp']['backup_file'] = $backup_file;
|
| 1776 |
+
$return = $this->ftp_backup($account_info['mwp_ftp']);
|
| 1777 |
+
}
|
| 1778 |
+
|
| 1779 |
+
if (isset($account_info['mwp_amazon_s3']) && !empty($account_info['mwp_amazon_s3'])) {
|
| 1780 |
+
$account_info['mwp_amazon_s3']['backup_file'] = $backup_file;
|
| 1781 |
+
$return = $this->amazons3_backup($account_info['mwp_amazon_s3']);
|
| 1782 |
+
}
|
| 1783 |
+
|
| 1784 |
+
if (isset($account_info['mwp_dropbox']) && !empty($account_info['mwp_dropbox'])) {
|
| 1785 |
+
$account_info['mwp_dropbox']['backup_file'] = $backup_file;
|
| 1786 |
+
$return = $this->dropbox_backup($account_info['mwp_dropbox']);
|
| 1787 |
+
}
|
| 1788 |
+
|
| 1789 |
+
if (isset($account_info['mwp_email']) && !empty($account_info['mwp_email'])) {
|
| 1790 |
+
$account_info['mwp_email']['file_path'] = $backup_file;
|
| 1791 |
+
$account_info['mwp_email']['task_name'] = 'Backup Now';
|
| 1792 |
+
$return = $this->email_backup($account_info['mwp_email']);
|
| 1793 |
+
}
|
| 1794 |
+
|
| 1795 |
+
|
| 1796 |
+
if ($return == true && $del_host_file) {
|
| 1797 |
+
@unlink($backup_file);
|
| 1798 |
+
unset($tasks['Backup Now']['task_results'][count($results) - 1]['server']);
|
| 1799 |
+
$this->update_tasks($tasks);
|
| 1800 |
+
//update_option('mwp_backup_tasks', $tasks);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1801 |
}
|
| 1802 |
|
| 1803 |
+
|
| 1804 |
+
|
| 1805 |
} else {
|
| 1806 |
$return = array(
|
| 1807 |
'error' => 'Backup file not found on your server. Please try again.'
|
| 1812 |
|
| 1813 |
}
|
| 1814 |
|
| 1815 |
+
function validate_task($args, $url)
|
| 1816 |
+
{
|
| 1817 |
+
if (!class_exists('WP_Http')) {
|
| 1818 |
+
include_once(ABSPATH . WPINC . '/class-http.php');
|
| 1819 |
+
}
|
| 1820 |
+
$params = array();
|
| 1821 |
+
$params['body'] = $args;
|
| 1822 |
+
$result = wp_remote_post($url, $params);
|
| 1823 |
+
if (is_array($result) && $result['body'] == 'mwp_delete_task') {
|
| 1824 |
+
//$tasks = $this->get_backup_settings();
|
| 1825 |
+
$tasks = $this->tasks;
|
| 1826 |
+
unset($tasks[$args['task_name']]);
|
| 1827 |
+
$this->update_tasks($tasks);
|
| 1828 |
+
$this->cleanup();
|
| 1829 |
+
exit;
|
| 1830 |
+
}
|
| 1831 |
}
|
| 1832 |
|
| 1833 |
+
function update_status($task_name, $status, $completed = false)
|
| 1834 |
+
{
|
| 1835 |
+
/* Statuses:
|
| 1836 |
+
0 - Backup started
|
| 1837 |
+
1 - DB dump
|
| 1838 |
+
2 - DB ZIP
|
| 1839 |
+
3 - Files ZIP
|
| 1840 |
+
4 - Amazon S3
|
| 1841 |
+
5 - Dropbox
|
| 1842 |
+
6 - FTP
|
| 1843 |
+
7 - Email
|
| 1844 |
+
100 - Finished
|
| 1845 |
+
*/
|
| 1846 |
+
if ($task_name != 'Backup Now') {
|
| 1847 |
+
$tasks = $this->tasks;
|
| 1848 |
+
$index = count($tasks[$task_name]['task_results']) - 1;
|
| 1849 |
+
if (!is_array($tasks[$task_name]['task_results'][$index]['status'])) {
|
| 1850 |
+
$tasks[$task_name]['task_results'][$index]['status'] = array();
|
| 1851 |
+
}
|
| 1852 |
+
if (!$completed) {
|
| 1853 |
+
$tasks[$task_name]['task_results'][$index]['status'][] = (int) $status * (-1);
|
| 1854 |
+
} else {
|
| 1855 |
+
$status_index = count($tasks[$task_name]['task_results'][$index]['status']) - 1;
|
| 1856 |
+
$tasks[$task_name]['task_results'][$index]['status'][$status_index] = abs($tasks[$task_name]['task_results'][$index]['status'][$status_index]);
|
| 1857 |
+
}
|
| 1858 |
+
|
| 1859 |
+
$this->update_tasks($tasks);
|
| 1860 |
+
//update_option('mwp_backup_tasks',$tasks);
|
| 1861 |
+
}
|
| 1862 |
+
}
|
| 1863 |
+
|
| 1864 |
+
function update_tasks($tasks)
|
| 1865 |
+
{
|
| 1866 |
+
$this->tasks = $tasks;
|
| 1867 |
+
update_option('mwp_backup_tasks', $tasks);
|
| 1868 |
}
|
| 1869 |
+
|
| 1870 |
}
|
| 1871 |
+
|
| 1872 |
?>
|
core.class.php
CHANGED
|
@@ -125,13 +125,13 @@ class MMB_Core extends MMB_Helper
|
|
| 125 |
'worker_brand' => 'mmb_worker_brand'
|
| 126 |
);
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
add_action('admin_init', array($this,'admin_actions'));
|
| 131 |
add_action('init', array( &$this, 'mmb_remote_action'), 9999);
|
| 132 |
add_action('setup_theme', 'mmb_parse_request');
|
| 133 |
add_action('set_auth_cookie', array( &$this, 'mmb_set_auth_cookie'));
|
| 134 |
add_action('set_logged_in_cookie', array( &$this, 'mmb_set_logged_in_cookie'));
|
|
|
|
| 135 |
}
|
| 136 |
|
| 137 |
function mmb_remote_action(){
|
|
@@ -183,7 +183,7 @@ class MMB_Core extends MMB_Helper
|
|
| 183 |
function network_admin_notice()
|
| 184 |
{
|
| 185 |
echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">Attention !</p><p>
|
| 186 |
-
Please add this site and your network blogs, with your network adminstrator username, to your <a target="_blank" href="http://managewp.com">ManageWP.com</a> account now to remove this notice or "Network Deactivate" the Worker plugin to avoid <a target="_blank" href="http://managewp.com/user-guide/security">security issues</a>.
|
| 187 |
</p></div>';
|
| 188 |
}
|
| 189 |
|
|
@@ -195,7 +195,7 @@ class MMB_Core extends MMB_Helper
|
|
| 195 |
function admin_notice()
|
| 196 |
{
|
| 197 |
echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">Attention !</p><p>
|
| 198 |
-
Please add this site now to your <a target="_blank" href="http://managewp.com">ManageWP.com</a> account. Or deactivate the Worker plugin to avoid <a target="_blank" href="http://managewp.com/user-guide/security">security issues</a>.
|
| 199 |
</p></div>';
|
| 200 |
}
|
| 201 |
|
|
@@ -576,10 +576,9 @@ class MMB_Core extends MMB_Helper
|
|
| 576 |
wp_cookie_constants();
|
| 577 |
|
| 578 |
wp_set_auth_cookie($user->ID);
|
| 579 |
-
|
| 580 |
-
$_COOKIE[MMB_XFRAME_COOKIE] = md5(MMB_XFRAME_COOKIE);
|
| 581 |
|
| 582 |
-
if(isset($this->mmb_multisite) && $this->mmb_multisite ){
|
| 583 |
if(function_exists('wp_safe_redirect') && function_exists('admin_url')){
|
| 584 |
wp_safe_redirect(admin_url($where));
|
| 585 |
exit();
|
|
@@ -590,6 +589,12 @@ class MMB_Core extends MMB_Helper
|
|
| 590 |
}
|
| 591 |
} elseif( is_user_logged_in() ) {
|
| 592 |
@mmb_worker_header();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 593 |
}
|
| 594 |
}
|
| 595 |
|
|
@@ -628,8 +633,19 @@ class MMB_Core extends MMB_Helper
|
|
| 628 |
$all_plugins['worker/init.php']['Author'] = $replace['author'];
|
| 629 |
$all_plugins['worker/init.php']['AuthorName'] = $replace['author'];
|
| 630 |
$all_plugins['worker/init.php']['PluginURI'] = '';
|
| 631 |
-
}
|
| 632 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 633 |
|
| 634 |
|
| 635 |
return $all_plugins;
|
| 125 |
'worker_brand' => 'mmb_worker_brand'
|
| 126 |
);
|
| 127 |
|
| 128 |
+
add_action('rightnow_end', array( &$this, 'add_right_now_info' ));
|
| 129 |
+
add_action('admin_init', array(&$this,'admin_actions'));
|
|
|
|
| 130 |
add_action('init', array( &$this, 'mmb_remote_action'), 9999);
|
| 131 |
add_action('setup_theme', 'mmb_parse_request');
|
| 132 |
add_action('set_auth_cookie', array( &$this, 'mmb_set_auth_cookie'));
|
| 133 |
add_action('set_logged_in_cookie', array( &$this, 'mmb_set_logged_in_cookie'));
|
| 134 |
+
MMB_Stats::set_hit_count();
|
| 135 |
}
|
| 136 |
|
| 137 |
function mmb_remote_action(){
|
| 183 |
function network_admin_notice()
|
| 184 |
{
|
| 185 |
echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">Attention !</p><p>
|
| 186 |
+
Please add this site and your network blogs, with your network adminstrator username, to your <a target="_blank" href="http://managewp.com/wp-admin">ManageWP.com</a> account now to remove this notice or "Network Deactivate" the Worker plugin to avoid <a target="_blank" href="http://managewp.com/user-guide/security">security issues</a>.
|
| 187 |
</p></div>';
|
| 188 |
}
|
| 189 |
|
| 195 |
function admin_notice()
|
| 196 |
{
|
| 197 |
echo '<div class="error" style="text-align: center;"><p style="color: red; font-size: 14px; font-weight: bold;">Attention !</p><p>
|
| 198 |
+
Please add this site now to your <a target="_blank" href="http://managewp.com/wp-admin">ManageWP.com</a> account. Or deactivate the Worker plugin to avoid <a target="_blank" href="http://managewp.com/user-guide/security">security issues</a>.
|
| 199 |
</p></div>';
|
| 200 |
}
|
| 201 |
|
| 576 |
wp_cookie_constants();
|
| 577 |
|
| 578 |
wp_set_auth_cookie($user->ID);
|
| 579 |
+
@mmb_worker_header();
|
|
|
|
| 580 |
|
| 581 |
+
if((isset($this->mmb_multisite) && $this->mmb_multisite ) || isset($_REQUEST['mwpredirect'])){
|
| 582 |
if(function_exists('wp_safe_redirect') && function_exists('admin_url')){
|
| 583 |
wp_safe_redirect(admin_url($where));
|
| 584 |
exit();
|
| 589 |
}
|
| 590 |
} elseif( is_user_logged_in() ) {
|
| 591 |
@mmb_worker_header();
|
| 592 |
+
if(isset($_REQUEST['mwpredirect'])){
|
| 593 |
+
if(function_exists('wp_safe_redirect') && function_exists('admin_url')){
|
| 594 |
+
wp_safe_redirect(admin_url($where));
|
| 595 |
+
exit();
|
| 596 |
+
}
|
| 597 |
+
}
|
| 598 |
}
|
| 599 |
}
|
| 600 |
|
| 633 |
$all_plugins['worker/init.php']['Author'] = $replace['author'];
|
| 634 |
$all_plugins['worker/init.php']['AuthorName'] = $replace['author'];
|
| 635 |
$all_plugins['worker/init.php']['PluginURI'] = '';
|
|
|
|
| 636 |
}
|
| 637 |
+
|
| 638 |
+
if($replace['hide']){
|
| 639 |
+
if (!function_exists('get_plugins')) {
|
| 640 |
+
include_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
| 641 |
+
}
|
| 642 |
+
$activated_plugins = get_option('active_plugins');
|
| 643 |
+
if (!$activated_plugins)
|
| 644 |
+
$activated_plugins = array();
|
| 645 |
+
if(in_array('worker/init.php',$activated_plugins))
|
| 646 |
+
unset($all_plugins['worker/init.php']);
|
| 647 |
+
}
|
| 648 |
+
}
|
| 649 |
|
| 650 |
|
| 651 |
return $all_plugins;
|
helper.class.php
CHANGED
|
@@ -85,7 +85,7 @@ class MMB_Helper
|
|
| 85 |
|
| 86 |
|
| 87 |
global $wp_version;
|
| 88 |
-
if (version_compare($wp_version, '3.2.
|
| 89 |
return get_userdatabylogin( $user_info );
|
| 90 |
} else {
|
| 91 |
return get_user_by( $info, $user_info );
|
| 85 |
|
| 86 |
|
| 87 |
global $wp_version;
|
| 88 |
+
if (version_compare($wp_version, '3.2.2', '<=')){
|
| 89 |
return get_userdatabylogin( $user_info );
|
| 90 |
} else {
|
| 91 |
return get_user_by( $info, $user_info );
|
init.php
CHANGED
|
@@ -4,7 +4,7 @@ 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.
|
| 8 |
Author URI: http://www.prelovac.com
|
| 9 |
*/
|
| 10 |
|
|
@@ -20,7 +20,7 @@ Author URI: http://www.prelovac.com
|
|
| 20 |
**************************************************************/
|
| 21 |
|
| 22 |
if(!defined('MMB_WORKER_VERSION'))
|
| 23 |
-
define('MMB_WORKER_VERSION', '3.9.
|
| 24 |
|
| 25 |
if ( !defined('MMB_XFRAME_COOKIE')){
|
| 26 |
$siteurl = function_exists('get_site_option') ? get_site_option( 'siteurl' ) : get_option('siteurl');
|
|
@@ -100,7 +100,7 @@ if( !function_exists ( 'mmb_parse_request' )) {
|
|
| 100 |
}
|
| 101 |
}
|
| 102 |
}
|
| 103 |
-
|
| 104 |
if(isset($params['secure'])){
|
| 105 |
if($decrypted = $mmb_core->_secure_data($params['secure'])){
|
| 106 |
$decrypted = maybe_unserialize($decrypted);
|
|
@@ -189,8 +189,7 @@ if( !function_exists ( 'mmb_add_site' )) {
|
|
| 189 |
$mmb_core->set_random_signature($random_key);
|
| 190 |
$mmb_core->set_worker_message_id($id);
|
| 191 |
$mmb_core->set_master_public_key($public_key);
|
| 192 |
-
$mmb_core->get_stats_instance();
|
| 193 |
-
$mmb_core->get_stats_instance();
|
| 194 |
if(is_array($notifications) && !empty($notifications)){
|
| 195 |
$mmb_core->stats_instance->set_notifications($notifications);
|
| 196 |
}
|
|
@@ -671,7 +670,7 @@ if( !function_exists('mwp_check_backup_tasks') ){
|
|
| 671 |
}
|
| 672 |
|
| 673 |
if (!wp_next_scheduled('mwp_notifications')) {
|
| 674 |
-
wp_schedule_event( time(), '
|
| 675 |
}
|
| 676 |
add_action('mwp_notifications', 'mwp_check_notifications');
|
| 677 |
|
|
@@ -760,4 +759,5 @@ if( isset($_COOKIE[MMB_XFRAME_COOKIE]) ){
|
|
| 760 |
remove_action( 'login_init', 'send_frame_options_header');
|
| 761 |
}
|
| 762 |
|
|
|
|
| 763 |
?>
|
| 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.13
|
| 8 |
Author URI: http://www.prelovac.com
|
| 9 |
*/
|
| 10 |
|
| 20 |
**************************************************************/
|
| 21 |
|
| 22 |
if(!defined('MMB_WORKER_VERSION'))
|
| 23 |
+
define('MMB_WORKER_VERSION', '3.9.13');
|
| 24 |
|
| 25 |
if ( !defined('MMB_XFRAME_COOKIE')){
|
| 26 |
$siteurl = function_exists('get_site_option') ? get_site_option( 'siteurl' ) : get_option('siteurl');
|
| 100 |
}
|
| 101 |
}
|
| 102 |
}
|
| 103 |
+
|
| 104 |
if(isset($params['secure'])){
|
| 105 |
if($decrypted = $mmb_core->_secure_data($params['secure'])){
|
| 106 |
$decrypted = maybe_unserialize($decrypted);
|
| 189 |
$mmb_core->set_random_signature($random_key);
|
| 190 |
$mmb_core->set_worker_message_id($id);
|
| 191 |
$mmb_core->set_master_public_key($public_key);
|
| 192 |
+
$mmb_core->get_stats_instance();
|
|
|
|
| 193 |
if(is_array($notifications) && !empty($notifications)){
|
| 194 |
$mmb_core->stats_instance->set_notifications($notifications);
|
| 195 |
}
|
| 670 |
}
|
| 671 |
|
| 672 |
if (!wp_next_scheduled('mwp_notifications')) {
|
| 673 |
+
wp_schedule_event( time(), 'twicedaily', 'mwp_notifications' );
|
| 674 |
}
|
| 675 |
add_action('mwp_notifications', 'mwp_check_notifications');
|
| 676 |
|
| 759 |
remove_action( 'login_init', 'send_frame_options_header');
|
| 760 |
}
|
| 761 |
|
| 762 |
+
|
| 763 |
?>
|
installer.class.php
CHANGED
|
@@ -14,21 +14,20 @@ class MMB_Installer extends MMB_Core
|
|
| 14 |
{
|
| 15 |
function __construct()
|
| 16 |
{
|
| 17 |
-
@set_time_limit(
|
| 18 |
parent::__construct();
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
if (!$wp_filesystem)
|
| 28 |
WP_Filesystem();
|
| 29 |
-
|
| 30 |
}
|
| 31 |
-
|
| 32 |
function mmb_maintenance_mode($enable = false, $maintenance_message = '')
|
| 33 |
{
|
| 34 |
global $wp_filesystem;
|
|
@@ -59,14 +58,14 @@ class MMB_Installer extends MMB_Core
|
|
| 59 |
'error' => '<p>Site under maintanace.</p>'
|
| 60 |
);
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
$destination
|
| 70 |
$clear_destination = isset($clear_destination) ? $clear_destination : false;
|
| 71 |
|
| 72 |
foreach ($package as $package_url) {
|
|
@@ -79,113 +78,116 @@ class MMB_Installer extends MMB_Core
|
|
| 79 |
'hook_extra' => array()
|
| 80 |
));
|
| 81 |
}
|
| 82 |
-
|
| 83 |
if ($activate) {
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
| 115 |
}
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
}
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
| 127 |
return array(
|
| 128 |
'error' => 'Failed, please <a target="_blank" href="http://managewp.com/user-guide#ftp">add FTP details</a></a>'
|
| 129 |
);
|
| 130 |
}
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
|
| 190 |
/**
|
| 191 |
* Upgrades WordPress locally
|
|
@@ -193,347 +195,355 @@ class MMB_Installer extends MMB_Core
|
|
| 193 |
*/
|
| 194 |
function upgrade_core($current)
|
| 195 |
{
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
}
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
|
|
|
| 350 |
'error' => 'No plugin files for upgrade.'
|
| 351 |
);
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
return array(
|
| 396 |
'error' => 'No theme files for upgrade.'
|
| 397 |
);
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
}
|
| 437 |
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
'error' => 'No premium files for upgrade.'
|
| 446 |
);
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
$upgradable_plugins = array();
|
| 514 |
if (!empty($current->response)) {
|
| 515 |
-
|
| 516 |
-
|
| 517 |
foreach ($current->response as $plugin_path => $plugin_data) {
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
$data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_path);
|
| 522 |
-
if(strlen($data['Name']) > 0 && strlen($data['Version']) > 0) {
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
|
|
|
| 528 |
}
|
| 529 |
return $upgradable_plugins;
|
| 530 |
} else
|
| 531 |
return array();
|
| 532 |
}
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
$upgrade_themes = array();
|
| 538 |
|
| 539 |
$current = $this->mmb_get_transient('update_themes');
|
|
@@ -541,212 +551,235 @@ class MMB_Installer extends MMB_Core
|
|
| 541 |
if (!empty($current->response)) {
|
| 542 |
foreach ($current->response as $current_themes => $theme) {
|
| 543 |
if ($theme_data['Template'] == $current_themes) {
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
}
|
| 551 |
}
|
| 552 |
}
|
| 553 |
}
|
| 554 |
|
| 555 |
return $upgrade_themes;
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
function get($args)
|
| 559 |
-
{
|
| 560 |
-
if(empty($args))
|
| 561 |
-
return false;
|
| 562 |
-
|
| 563 |
-
//Args: $items('plugins,'themes'), $type (active || inactive), $search(name string)
|
| 564 |
-
|
| 565 |
-
$return = array();
|
| 566 |
-
if(is_array($args['items']) && in_array('plugins',$args['items'])){
|
| 567 |
-
$return['plugins'] = $this->get_plugins($args);
|
| 568 |
-
}
|
| 569 |
-
if(is_array($args['items']) && in_array('themes',$args['items'])){
|
| 570 |
-
$return['themes'] = $this->get_themes($args);
|
| 571 |
-
}
|
| 572 |
-
|
| 573 |
-
return $return;
|
| 574 |
-
}
|
| 575 |
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 746 |
}
|
| 747 |
-
|
| 748 |
-
return $return;
|
| 749 |
-
|
| 750 |
-
}
|
| 751 |
}
|
| 752 |
?>
|
| 14 |
{
|
| 15 |
function __construct()
|
| 16 |
{
|
| 17 |
+
@set_time_limit(600);
|
| 18 |
parent::__construct();
|
| 19 |
+
@include_once(ABSPATH . 'wp-admin/includes/file.php');
|
| 20 |
+
@include_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
| 21 |
+
@include_once(ABSPATH . 'wp-admin/includes/theme.php');
|
| 22 |
+
@include_once(ABSPATH . 'wp-admin/includes/misc.php');
|
| 23 |
+
@include_once(ABSPATH . 'wp-admin/includes/template.php');
|
| 24 |
+
@include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
|
| 25 |
+
|
| 26 |
+
global $wp_filesystem;
|
| 27 |
if (!$wp_filesystem)
|
| 28 |
WP_Filesystem();
|
|
|
|
| 29 |
}
|
| 30 |
+
|
| 31 |
function mmb_maintenance_mode($enable = false, $maintenance_message = '')
|
| 32 |
{
|
| 33 |
global $wp_filesystem;
|
| 58 |
'error' => '<p>Site under maintanace.</p>'
|
| 59 |
);
|
| 60 |
|
| 61 |
+
if (!class_exists('WP_Upgrader'))
|
| 62 |
+
include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
|
| 63 |
|
| 64 |
+
$upgrader_skin = new WP_Upgrader_Skin();
|
| 65 |
+
$upgrader_skin->done_header = true;
|
| 66 |
+
|
| 67 |
+
$upgrader = new WP_Upgrader($upgrader_skin);
|
| 68 |
+
$destination = $type == 'themes' ? WP_CONTENT_DIR . '/themes' : WP_PLUGIN_DIR;
|
| 69 |
$clear_destination = isset($clear_destination) ? $clear_destination : false;
|
| 70 |
|
| 71 |
foreach ($package as $package_url) {
|
| 78 |
'hook_extra' => array()
|
| 79 |
));
|
| 80 |
}
|
| 81 |
+
|
| 82 |
if ($activate) {
|
| 83 |
+
if ($type == 'plugins') {
|
| 84 |
+
include_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
| 85 |
+
$all_plugins = get_plugins();
|
| 86 |
+
foreach ($all_plugins as $plugin_slug => $plugin) {
|
| 87 |
+
$plugin_dir = preg_split('/\//', $plugin_slug);
|
| 88 |
+
foreach ($install_info as $key => $install) {
|
| 89 |
+
if (!$install || is_wp_error($install))
|
| 90 |
+
continue;
|
| 91 |
+
if ($install['destination_name'] == $plugin_dir[0]) {
|
| 92 |
+
$install_info[$key]['activated'] = activate_plugin($plugin_slug, '', false);
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
} else if (count($install_info) == 1) {
|
| 97 |
+
global $wp_themes;
|
| 98 |
+
include_once(ABSPATH . 'wp-includes/theme.php');
|
| 99 |
+
|
| 100 |
+
$wp_themes = null;
|
| 101 |
+
unset($wp_themes); //prevent theme data caching
|
| 102 |
+
|
| 103 |
+
$all_themes = get_themes();
|
| 104 |
+
foreach ($all_themes as $theme_name => $theme_data) {
|
| 105 |
+
foreach ($install_info as $key => $install) {
|
| 106 |
+
if (!$install || is_wp_error($install))
|
| 107 |
+
continue;
|
| 108 |
+
|
| 109 |
+
if ($theme_data['Template'] == $install['destination_name']) {
|
| 110 |
+
$install_info[$key]['activated'] = switch_theme($theme_data['Template'], $theme_data['Stylesheet']);
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
}
|
| 116 |
+
ob_clean();
|
| 117 |
+
$this->mmb_maintenance_mode(false);
|
| 118 |
+
return $install_info;
|
| 119 |
}
|
| 120 |
+
|
| 121 |
+
function do_upgrade($params = null)
|
| 122 |
+
{
|
| 123 |
+
if ($params == null || empty($params))
|
| 124 |
+
return array(
|
| 125 |
+
'failed' => 'No upgrades passed.'
|
| 126 |
+
);
|
| 127 |
+
|
| 128 |
+
if (!$this->is_server_writable()) {
|
| 129 |
return array(
|
| 130 |
'error' => 'Failed, please <a target="_blank" href="http://managewp.com/user-guide#ftp">add FTP details</a></a>'
|
| 131 |
);
|
| 132 |
}
|
| 133 |
+
|
| 134 |
+
$params = isset($params['upgrades_all']) ? $params['upgrades_all'] : $params;
|
| 135 |
+
|
| 136 |
+
$core_upgrade = isset($params['wp_upgrade']) ? $params['wp_upgrade'] : array();
|
| 137 |
+
$upgrade_plugins = isset($params['upgrade_plugins']) ? $params['upgrade_plugins'] : array();
|
| 138 |
+
$upgrade_themes = isset($params['upgrade_themes']) ? $params['upgrade_themes'] : array();
|
| 139 |
+
|
| 140 |
+
$upgrades = array();
|
| 141 |
+
$premium_upgrades = array();
|
| 142 |
+
if (!empty($core_upgrade)) {
|
| 143 |
+
$upgrades['core'] = $this->upgrade_core($core_upgrade);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
if (!empty($upgrade_plugins)) {
|
| 147 |
+
$plugin_files = array();
|
| 148 |
+
foreach ($upgrade_plugins as $plugin) {
|
| 149 |
+
if (isset($plugin->file))
|
| 150 |
+
$plugin_files[$plugin->file] = $plugin->old_version;
|
| 151 |
+
else
|
| 152 |
+
$premium_upgrades[md5($plugin->name)] = $plugin;
|
| 153 |
+
}
|
| 154 |
+
if (!empty($plugin_files))
|
| 155 |
+
$upgrades['plugins'] = $this->upgrade_plugins($plugin_files);
|
| 156 |
+
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
if (!empty($upgrade_themes)) {
|
| 160 |
+
$theme_temps = array();
|
| 161 |
+
foreach ($upgrade_themes as $theme) {
|
| 162 |
+
if (isset($theme['theme_tmp']))
|
| 163 |
+
$theme_temps[] = $theme['theme_tmp'];
|
| 164 |
+
else
|
| 165 |
+
$premium_upgrades[md5($theme['name'])] = $theme;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
if (!empty($theme_temps))
|
| 169 |
+
$upgrades['themes'] = $this->upgrade_themes($theme_temps);
|
| 170 |
+
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
if (!empty($premium_upgrades)) {
|
| 174 |
+
$premium_upgrades = $this->upgrade_premium($premium_upgrades);
|
| 175 |
+
if (!empty($premium_upgrades)) {
|
| 176 |
+
if (!empty($upgrades)) {
|
| 177 |
+
foreach ($upgrades as $key => $val) {
|
| 178 |
+
if (isset($premium_upgrades[$key])) {
|
| 179 |
+
$upgrades[$key] = array_merge_recursive($upgrades[$key], $premium_upgrades[$key]);
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
} else {
|
| 183 |
+
$upgrades = $premium_upgrades;
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
ob_clean();
|
| 188 |
+
$this->mmb_maintenance_mode(false);
|
| 189 |
+
return $upgrades;
|
| 190 |
+
}
|
| 191 |
|
| 192 |
/**
|
| 193 |
* Upgrades WordPress locally
|
| 195 |
*/
|
| 196 |
function upgrade_core($current)
|
| 197 |
{
|
| 198 |
+
ob_start();
|
| 199 |
+
if (!function_exists('wp_version_check'))
|
| 200 |
+
include_once(ABSPATH . '/wp-admin/includes/update.php');
|
| 201 |
+
|
| 202 |
+
@wp_version_check();
|
| 203 |
+
|
| 204 |
+
$current_update = false;
|
| 205 |
+
ob_end_flush();
|
| 206 |
+
ob_end_clean();
|
| 207 |
+
$core = $this->mmb_get_transient('update_core');
|
| 208 |
+
|
| 209 |
+
if (isset($core->updates) && !empty($core->updates)) {
|
| 210 |
+
$updates = $core->updates[0];
|
| 211 |
+
$updated = $core->updates[0];
|
| 212 |
+
if (!isset($updated->response) || $updated->response == 'latest')
|
| 213 |
+
return array(
|
| 214 |
+
'upgraded' => ' updated'
|
| 215 |
+
);
|
| 216 |
+
|
| 217 |
+
if ($updated->response == "development" && $current->response == "upgrade") {
|
| 218 |
+
return array(
|
| 219 |
+
'upgraded' => '<font color="#900">Unexpected error. Please upgrade manually.</font>'
|
| 220 |
+
);
|
| 221 |
+
} else if ($updated->response == $current->response || ($updated->response == "upgrade" && $current->response == "development")) {
|
| 222 |
+
if ($updated->locale != $current->locale) {
|
| 223 |
+
foreach ($updates as $update) {
|
| 224 |
+
if ($update->locale == $current->locale) {
|
| 225 |
+
$current_update = $update;
|
| 226 |
+
break;
|
| 227 |
+
}
|
| 228 |
+
}
|
| 229 |
+
if ($current_update == false)
|
| 230 |
+
return array(
|
| 231 |
+
'error' => ' Localization mismatch. Try again.'
|
| 232 |
+
);
|
| 233 |
+
} else {
|
| 234 |
+
$current_update = $updated;
|
| 235 |
+
}
|
| 236 |
+
} else
|
| 237 |
+
return array(
|
| 238 |
+
'error' => ' Transient mismatch. Try again.'
|
| 239 |
+
);
|
| 240 |
+
} else
|
| 241 |
+
return array(
|
| 242 |
+
'error' => ' Refresh transient failed. Try again.'
|
| 243 |
+
);
|
| 244 |
+
if ($current_update != false) {
|
| 245 |
+
global $mmb_wp_version, $wp_filesystem, $wp_version;
|
| 246 |
+
|
| 247 |
+
if (version_compare($wp_version, '3.1.9', '>')) {
|
| 248 |
+
if (!class_exists('Core_Upgrader'))
|
| 249 |
+
include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
|
| 250 |
+
|
| 251 |
+
$core = new Core_Upgrader();
|
| 252 |
+
$result = $core->upgrade($current_update);
|
| 253 |
+
$this->mmb_maintenance_mode(false);
|
| 254 |
+
if (is_wp_error($result)) {
|
| 255 |
+
return array(
|
| 256 |
+
'error' => $this->mmb_get_error($result)
|
| 257 |
+
);
|
| 258 |
+
} else
|
| 259 |
+
return array(
|
| 260 |
+
'upgraded' => ' updated'
|
| 261 |
+
);
|
| 262 |
+
|
| 263 |
+
} else {
|
| 264 |
+
if (!class_exists('WP_Upgrader')) {
|
| 265 |
+
include_once(ABSPATH . 'wp-admin/includes/update.php');
|
| 266 |
+
if (function_exists('wp_update_core')) {
|
| 267 |
+
$result = wp_update_core($current_update);
|
| 268 |
+
if (is_wp_error($result)) {
|
| 269 |
+
return array(
|
| 270 |
+
'error' => $this->mmb_get_error($result)
|
| 271 |
+
);
|
| 272 |
+
} else
|
| 273 |
+
return array(
|
| 274 |
+
'upgraded' => ' updated'
|
| 275 |
+
);
|
| 276 |
+
}
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
if (class_exists('WP_Upgrader')) {
|
| 280 |
+
$upgrader_skin = new WP_Upgrader_Skin();
|
| 281 |
+
$upgrader_skin->done_header = true;
|
| 282 |
+
|
| 283 |
+
$upgrader = new WP_Upgrader($upgrader_skin);
|
| 284 |
+
|
| 285 |
+
// Is an update available?
|
| 286 |
+
if (!isset($current_update->response) || $current_update->response == 'latest')
|
| 287 |
+
return array(
|
| 288 |
+
'upgraded' => ' updated'
|
| 289 |
+
);
|
| 290 |
+
|
| 291 |
+
$res = $upgrader->fs_connect(array(
|
| 292 |
+
ABSPATH,
|
| 293 |
+
WP_CONTENT_DIR
|
| 294 |
+
));
|
| 295 |
+
if (is_wp_error($res))
|
| 296 |
+
return array(
|
| 297 |
+
'error' => $this->mmb_get_error($res)
|
| 298 |
+
);
|
| 299 |
+
|
| 300 |
+
$wp_dir = trailingslashit($wp_filesystem->abspath());
|
| 301 |
+
|
| 302 |
+
$core_package = false;
|
| 303 |
+
if (isset($current_update->package) && !empty($current_update->package))
|
| 304 |
+
$core_package = $current_update->package;
|
| 305 |
+
elseif (isset($current_update->packages->full) && !empty($current_update->packages->full))
|
| 306 |
+
$core_package = $current_update->packages->full;
|
| 307 |
+
|
| 308 |
+
$download = $upgrader->download_package($core_package);
|
| 309 |
+
if (is_wp_error($download))
|
| 310 |
+
return array(
|
| 311 |
+
'error' => $this->mmb_get_error($download)
|
| 312 |
+
);
|
| 313 |
+
|
| 314 |
+
$working_dir = $upgrader->unpack_package($download);
|
| 315 |
+
if (is_wp_error($working_dir))
|
| 316 |
+
return array(
|
| 317 |
+
'error' => $this->mmb_get_error($working_dir)
|
| 318 |
+
);
|
| 319 |
+
|
| 320 |
+
if (!$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true)) {
|
| 321 |
+
$wp_filesystem->delete($working_dir, true);
|
| 322 |
+
return array(
|
| 323 |
+
'error' => 'Unable to move update files.'
|
| 324 |
+
);
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
$wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
|
| 328 |
+
|
| 329 |
+
require(ABSPATH . 'wp-admin/includes/update-core.php');
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
$update_core = update_core($working_dir, $wp_dir);
|
| 333 |
+
ob_end_clean();
|
| 334 |
+
|
| 335 |
+
$this->mmb_maintenance_mode(false);
|
| 336 |
+
if (is_wp_error($update_core))
|
| 337 |
+
return array(
|
| 338 |
+
'error' => $this->mmb_get_error($update_core)
|
| 339 |
+
);
|
| 340 |
+
ob_end_flush();
|
| 341 |
+
return array(
|
| 342 |
+
'upgraded' => 'updated'
|
| 343 |
+
);
|
| 344 |
+
} else {
|
| 345 |
+
return array(
|
| 346 |
+
'error' => 'failed'
|
| 347 |
+
);
|
| 348 |
+
}
|
| 349 |
+
}
|
| 350 |
+
} else {
|
| 351 |
+
return array(
|
| 352 |
+
'error' => 'failed'
|
| 353 |
+
);
|
| 354 |
+
}
|
| 355 |
}
|
| 356 |
+
|
| 357 |
+
function upgrade_plugins($plugins = false)
|
| 358 |
+
{
|
| 359 |
+
if (!$plugins || empty($plugins))
|
| 360 |
+
return array(
|
| 361 |
'error' => 'No plugin files for upgrade.'
|
| 362 |
);
|
| 363 |
+
$return = array();
|
| 364 |
+
if (class_exists('Plugin_Upgrader') && class_exists('Bulk_Plugin_Upgrader_Skin')) {
|
| 365 |
+
$upgrader = new Plugin_Upgrader(new Bulk_Plugin_Upgrader_Skin(compact('nonce', 'url')));
|
| 366 |
+
$result = $upgrader->bulk_upgrade(array_keys($plugins));
|
| 367 |
+
|
| 368 |
+
if (!function_exists('wp_update_plugins'))
|
| 369 |
+
include_once(ABSPATH . 'wp-includes/update.php');
|
| 370 |
+
|
| 371 |
+
@wp_update_plugins();
|
| 372 |
+
$current_plugins = $this->mmb_get_transient('update_plugins');
|
| 373 |
+
|
| 374 |
+
if (!empty($result)) {
|
| 375 |
+
foreach ($result as $plugin_slug => $plugin_info) {
|
| 376 |
+
if (!$plugin_info || is_wp_error($plugin_info)) {
|
| 377 |
+
$return[$plugin_slug] = $this->mmb_get_error($plugin_info);
|
| 378 |
+
} else {
|
| 379 |
+
if (isset($current_plugins->response[$plugin_slug]) && !empty($current_plugins->response[$plugin_slug])) {
|
| 380 |
+
$return[$plugin_slug] = false;
|
| 381 |
+
} else {
|
| 382 |
+
$return[$plugin_slug] = 1;
|
| 383 |
+
}
|
| 384 |
+
}
|
| 385 |
+
}
|
| 386 |
+
ob_end_clean();
|
| 387 |
+
return array(
|
| 388 |
+
'upgraded' => $return
|
| 389 |
+
);
|
| 390 |
+
} else
|
| 391 |
+
return array(
|
| 392 |
+
'error' => 'Upgrade failed.'
|
| 393 |
+
);
|
| 394 |
+
} else {
|
| 395 |
+
ob_end_clean();
|
| 396 |
+
return array(
|
| 397 |
+
'error' => 'WordPress update required first.'
|
| 398 |
+
);
|
| 399 |
+
}
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
function upgrade_themes($themes = false)
|
| 403 |
+
{
|
| 404 |
+
if (!$themes || empty($themes))
|
| 405 |
+
return array(
|
|
|
|
| 406 |
'error' => 'No theme files for upgrade.'
|
| 407 |
);
|
| 408 |
+
if (class_exists('Theme_Upgrader') && class_exists('Bulk_Theme_Upgrader_Skin')) {
|
| 409 |
+
$upgrader = new Theme_Upgrader(new Bulk_Theme_Upgrader_Skin(compact('title', 'nonce', 'url', 'theme')));
|
| 410 |
+
$result = $upgrader->bulk_upgrade($themes);
|
| 411 |
+
|
| 412 |
+
if (!function_exists('wp_update_themes'))
|
| 413 |
+
include_once(ABSPATH . 'wp-includes/update.php');
|
| 414 |
+
|
| 415 |
+
@wp_update_themes();
|
| 416 |
+
$current_themes = $this->mmb_get_transient('update_themes');
|
| 417 |
+
|
| 418 |
+
$return = array();
|
| 419 |
+
if (!empty($result)) {
|
| 420 |
+
foreach ($result as $theme_tmp => $theme_info) {
|
| 421 |
+
if (is_wp_error($theme_info) || !$theme_info) {
|
| 422 |
+
$return[$theme_tmp] = $this->mmb_get_error($theme_info);
|
| 423 |
+
} else {
|
| 424 |
+
if (isset($current_themes->response[$theme_tmp]) && !empty($current_themes->response[$theme_tmp])) {
|
| 425 |
+
$return[$theme_tmp] = false;
|
| 426 |
+
} else {
|
| 427 |
+
$return[$theme_tmp] = 1;
|
| 428 |
+
}
|
| 429 |
+
}
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
return array(
|
| 433 |
+
'upgraded' => $return
|
| 434 |
+
);
|
| 435 |
+
} else
|
| 436 |
+
return array(
|
| 437 |
+
'error' => 'Upgrade failed.'
|
| 438 |
+
);
|
| 439 |
+
} else {
|
| 440 |
+
ob_end_clean();
|
| 441 |
+
return array(
|
| 442 |
+
'error' => 'WordPress update required first'
|
| 443 |
+
);
|
| 444 |
+
}
|
| 445 |
+
}
|
|
|
|
| 446 |
|
| 447 |
+
function upgrade_premium($premium = false)
|
| 448 |
+
{
|
| 449 |
+
if (!class_exists('WP_Upgrader'))
|
| 450 |
+
include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
|
| 451 |
+
|
| 452 |
+
if (!$premium || empty($premium))
|
| 453 |
+
return array(
|
| 454 |
'error' => 'No premium files for upgrade.'
|
| 455 |
);
|
| 456 |
+
|
| 457 |
+
$upgrader = false;
|
| 458 |
+
$pr_update = array();
|
| 459 |
+
$result = array();
|
| 460 |
+
$premium_update = array();
|
| 461 |
+
$premium_update = apply_filters('mwp_premium_perform_update', $premium_update);
|
| 462 |
+
|
| 463 |
+
if (!empty($premium_update)) {
|
| 464 |
+
foreach ($premium as $pr) {
|
| 465 |
+
foreach ($premium_update as $update) {
|
| 466 |
+
$update = array_change_key_case($update, CASE_LOWER);
|
| 467 |
+
|
| 468 |
+
if ($update['name'] == $pr['name']) {
|
| 469 |
+
$update_result = false;
|
| 470 |
+
if (isset($update['url'])) {
|
| 471 |
+
if (defined('WP_INSTALLING') && file_exists(ABSPATH . '.maintenance'))
|
| 472 |
+
$pr_update[$update['type'] . 's']['upgraded'][md5($update['name'])] = 'Site under maintanace.';
|
| 473 |
+
|
| 474 |
+
if ($upgrader == false) {
|
| 475 |
+
$upgrader_skin = new WP_Upgrader_Skin();
|
| 476 |
+
$upgrader_skin->done_header = true;
|
| 477 |
+
|
| 478 |
+
$upgrader = new WP_Upgrader();
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
@$update_result = $upgrader->run(array(
|
| 482 |
+
'package' => $update['url'],
|
| 483 |
+
'destination' => isset($update['type']) && $update['type'] == 'theme' ? WP_CONTENT_DIR . '/themes' : WP_PLUGIN_DIR,
|
| 484 |
+
'clear_destination' => true,
|
| 485 |
+
'clear_working' => true,
|
| 486 |
+
'hook_extra' => array()
|
| 487 |
+
));
|
| 488 |
+
$update_result = !$update_result || is_wp_error($update_result) ? $this->mmb_get_error($update_result) : 1;
|
| 489 |
+
|
| 490 |
+
} else if (isset($update['callback'])) {
|
| 491 |
+
if (is_array($update['callback'])) {
|
| 492 |
+
$update_result = call_user_func(array(
|
| 493 |
+
$update['callback'][0],
|
| 494 |
+
$update['callback'][1]
|
| 495 |
+
));
|
| 496 |
+
} else if (is_string($update['callback'])) {
|
| 497 |
+
$update_result = call_user_func($update['callback']);
|
| 498 |
+
} else {
|
| 499 |
+
$update_result = 'Upgrade function "' . $update['callback'] . '" does not exists.';
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
$update_result = $update_result !== true ? $this->mmb_get_error($update_result) : 1;
|
| 503 |
+
} else
|
| 504 |
+
$update_result = 'Bad update params.';
|
| 505 |
+
|
| 506 |
+
$pr_update[$update['type'] . 's']['upgraded'][md5($update['name'])] = $update_result;
|
| 507 |
+
}
|
| 508 |
+
}
|
| 509 |
+
}
|
| 510 |
+
return $pr_update;
|
| 511 |
+
} else {
|
| 512 |
+
foreach ($premium as $pr) {
|
| 513 |
+
$result[$pr['type'] . 's']['upgraded'][md5($pr['name'])] = 'This premium update is not registered.';
|
| 514 |
+
}
|
| 515 |
+
return $result;
|
| 516 |
+
}
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
function get_upgradable_plugins()
|
| 520 |
+
{
|
| 521 |
+
$current = $this->mmb_get_transient('update_plugins');
|
| 522 |
$upgradable_plugins = array();
|
| 523 |
if (!empty($current->response)) {
|
| 524 |
+
if (!function_exists('get_plugin_data'))
|
| 525 |
+
include_once ABSPATH . 'wp-admin/includes/plugin.php';
|
| 526 |
foreach ($current->response as $plugin_path => $plugin_data) {
|
| 527 |
+
if ($plugin_path == 'worker/init.php')
|
| 528 |
+
continue;
|
| 529 |
+
|
| 530 |
+
$data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_path);
|
| 531 |
+
if (strlen($data['Name']) > 0 && strlen($data['Version']) > 0) {
|
| 532 |
+
$current->response[$plugin_path]->name = $data['Name'];
|
| 533 |
+
$current->response[$plugin_path]->old_version = $data['Version'];
|
| 534 |
+
$current->response[$plugin_path]->file = $plugin_path;
|
| 535 |
+
unset($current->response[$plugin_path]->upgrade_notice);
|
| 536 |
+
$upgradable_plugins[] = $current->response[$plugin_path];
|
| 537 |
+
}
|
| 538 |
}
|
| 539 |
return $upgradable_plugins;
|
| 540 |
} else
|
| 541 |
return array();
|
| 542 |
}
|
| 543 |
+
|
| 544 |
+
function get_upgradable_themes()
|
| 545 |
+
{
|
| 546 |
+
$all_themes = get_themes();
|
| 547 |
$upgrade_themes = array();
|
| 548 |
|
| 549 |
$current = $this->mmb_get_transient('update_themes');
|
| 551 |
if (!empty($current->response)) {
|
| 552 |
foreach ($current->response as $current_themes => $theme) {
|
| 553 |
if ($theme_data['Template'] == $current_themes) {
|
| 554 |
+
if (strlen($theme_data['Name']) > 0 && strlen($theme_data['Version']) > 0) {
|
| 555 |
+
$current->response[$current_themes]['name'] = $theme_data['Name'];
|
| 556 |
+
$current->response[$current_themes]['old_version'] = $theme_data['Version'];
|
| 557 |
+
$current->response[$current_themes]['theme_tmp'] = $theme_data['Template'];
|
| 558 |
+
$upgrade_themes[] = $current->response[$current_themes];
|
| 559 |
+
}
|
| 560 |
}
|
| 561 |
}
|
| 562 |
}
|
| 563 |
}
|
| 564 |
|
| 565 |
return $upgrade_themes;
|
| 566 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 567 |
|
| 568 |
+
function get($args)
|
| 569 |
+
{
|
| 570 |
+
if (empty($args))
|
| 571 |
+
return false;
|
| 572 |
+
|
| 573 |
+
//Args: $items('plugins,'themes'), $type (active || inactive), $search(name string)
|
| 574 |
+
|
| 575 |
+
$return = array();
|
| 576 |
+
if (is_array($args['items']) && in_array('plugins', $args['items'])) {
|
| 577 |
+
$return['plugins'] = $this->get_plugins($args);
|
| 578 |
+
}
|
| 579 |
+
if (is_array($args['items']) && in_array('themes', $args['items'])) {
|
| 580 |
+
$return['themes'] = $this->get_themes($args);
|
| 581 |
+
}
|
| 582 |
+
|
| 583 |
+
return $return;
|
| 584 |
+
}
|
| 585 |
+
|
| 586 |
+
function get_plugins($args)
|
| 587 |
+
{
|
| 588 |
+
if (empty($args))
|
| 589 |
+
return false;
|
| 590 |
+
|
| 591 |
+
extract($args);
|
| 592 |
+
|
| 593 |
+
if (!function_exists('get_plugins')) {
|
| 594 |
+
include_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
| 595 |
+
}
|
| 596 |
+
$all_plugins = get_plugins();
|
| 597 |
+
$plugins = array(
|
| 598 |
+
'active' => array(),
|
| 599 |
+
'inactive' => array()
|
| 600 |
+
);
|
| 601 |
+
if (is_array($all_plugins) && !empty($all_plugins)) {
|
| 602 |
+
$activated_plugins = get_option('active_plugins');
|
| 603 |
+
if (!$activated_plugins)
|
| 604 |
+
$activated_plugins = array();
|
| 605 |
+
|
| 606 |
+
$br_a = 0;
|
| 607 |
+
$br_i = 0;
|
| 608 |
+
foreach ($all_plugins as $path => $plugin) {
|
| 609 |
+
if ($plugin['Name'] != 'ManageWP - Worker') {
|
| 610 |
+
if (in_array($path, $activated_plugins)) {
|
| 611 |
+
$plugins['active'][$br_a]['path'] = $path;
|
| 612 |
+
$plugins['active'][$br_a]['name'] = $plugin['Name'];
|
| 613 |
+
$br_a++;
|
| 614 |
+
}
|
| 615 |
+
|
| 616 |
+
if (!in_array($path, $activated_plugins)) {
|
| 617 |
+
$plugins['inactive'][$br_i]['path'] = $path;
|
| 618 |
+
$plugins['inactive'][$br_i]['name'] = $plugin['Name'];
|
| 619 |
+
$br_i++;
|
| 620 |
+
}
|
| 621 |
+
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
if ($search) {
|
| 625 |
+
foreach ($plugins['active'] as $k => $plugin) {
|
| 626 |
+
if (!stristr($plugin['name'], $search)) {
|
| 627 |
+
unset($plugins['active'][$k]);
|
| 628 |
+
}
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
foreach ($plugins['inactive'] as $k => $plugin) {
|
| 632 |
+
if (!stristr($plugin['name'], $search)) {
|
| 633 |
+
unset($plugins['inactive'][$k]);
|
| 634 |
+
}
|
| 635 |
+
}
|
| 636 |
+
}
|
| 637 |
+
}
|
| 638 |
+
}
|
| 639 |
+
|
| 640 |
+
return $plugins;
|
| 641 |
+
}
|
| 642 |
+
|
| 643 |
+
function get_themes($args)
|
| 644 |
+
{
|
| 645 |
+
if (empty($args))
|
| 646 |
+
return false;
|
| 647 |
+
|
| 648 |
+
extract($args);
|
| 649 |
+
|
| 650 |
+
if (!function_exists('get_themes')) {
|
| 651 |
+
include_once(ABSPATH . WPINC . '/theme.php');
|
| 652 |
+
}
|
| 653 |
+
$all_themes = get_themes();
|
| 654 |
+
$themes = array(
|
| 655 |
+
'active' => array(),
|
| 656 |
+
'inactive' => array()
|
| 657 |
+
);
|
| 658 |
+
|
| 659 |
+
if (is_array($all_themes) && !empty($all_themes)) {
|
| 660 |
+
$current_theme = get_current_theme();
|
| 661 |
+
|
| 662 |
+
$br_a = 0;
|
| 663 |
+
$br_i = 0;
|
| 664 |
+
foreach ($all_themes as $theme_name => $theme) {
|
| 665 |
+
if ($current_theme == $theme_name) {
|
| 666 |
+
$themes['active'][$br_a]['path'] = $theme['Template'];
|
| 667 |
+
$themes['active'][$br_a]['name'] = $theme['Name'];
|
| 668 |
+
$themes['active'][$br_a]['stylesheet'] = $theme['Stylesheet'];
|
| 669 |
+
$br_a++;
|
| 670 |
+
}
|
| 671 |
+
|
| 672 |
+
if ($current_theme != $theme_name) {
|
| 673 |
+
$themes['inactive'][$br_i]['path'] = $theme['Template'];
|
| 674 |
+
$themes['inactive'][$br_i]['name'] = $theme['Name'];
|
| 675 |
+
$themes['inactive'][$br_i]['stylesheet'] = $theme['Stylesheet'];
|
| 676 |
+
$br_i++;
|
| 677 |
+
}
|
| 678 |
+
|
| 679 |
+
}
|
| 680 |
+
|
| 681 |
+
if ($search) {
|
| 682 |
+
foreach ($themes['active'] as $k => $theme) {
|
| 683 |
+
if (!stristr($theme['name'], $search)) {
|
| 684 |
+
unset($themes['active'][$k]);
|
| 685 |
+
}
|
| 686 |
+
}
|
| 687 |
+
|
| 688 |
+
foreach ($themes['inactive'] as $k => $theme) {
|
| 689 |
+
if (!stristr($theme['name'], $search)) {
|
| 690 |
+
unset($themes['inactive'][$k]);
|
| 691 |
+
}
|
| 692 |
+
}
|
| 693 |
+
}
|
| 694 |
+
}
|
| 695 |
+
|
| 696 |
+
return $themes;
|
| 697 |
+
}
|
| 698 |
+
|
| 699 |
+
function edit($args)
|
| 700 |
+
{
|
| 701 |
+
extract($args);
|
| 702 |
+
$return = array();
|
| 703 |
+
if ($type == 'plugins') {
|
| 704 |
+
$return['plugins'] = $this->edit_plugins($args);
|
| 705 |
+
} elseif ($type == 'themes') {
|
| 706 |
+
$return['themes'] = $this->edit_themes($args);
|
| 707 |
+
}
|
| 708 |
+
return $return;
|
| 709 |
+
}
|
| 710 |
+
|
| 711 |
+
function edit_plugins($args)
|
| 712 |
+
{
|
| 713 |
+
extract($args);
|
| 714 |
+
$return = array();
|
| 715 |
+
foreach ($items as $item) {
|
| 716 |
+
switch ($items_edit_action) {
|
| 717 |
+
case 'activate':
|
| 718 |
+
$result = activate_plugin($item['path']);
|
| 719 |
+
break;
|
| 720 |
+
case 'deactivate':
|
| 721 |
+
$result = deactivate_plugins(array(
|
| 722 |
+
$item['path']
|
| 723 |
+
));
|
| 724 |
+
break;
|
| 725 |
+
case 'delete':
|
| 726 |
+
$result = delete_plugins(array(
|
| 727 |
+
$item['path']
|
| 728 |
+
));
|
| 729 |
+
break;
|
| 730 |
+
default:
|
| 731 |
+
break;
|
| 732 |
+
}
|
| 733 |
+
|
| 734 |
+
if (is_wp_error($result)) {
|
| 735 |
+
$result = array(
|
| 736 |
+
'error' => $result->get_error_message()
|
| 737 |
+
);
|
| 738 |
+
} elseif ($result === false) {
|
| 739 |
+
$result = array(
|
| 740 |
+
'error' => "Failed to perform action."
|
| 741 |
+
);
|
| 742 |
+
} else {
|
| 743 |
+
$result = "OK";
|
| 744 |
+
}
|
| 745 |
+
$return[$item['name']] = $result;
|
| 746 |
+
}
|
| 747 |
+
|
| 748 |
+
return $return;
|
| 749 |
+
}
|
| 750 |
+
|
| 751 |
+
function edit_themes($args)
|
| 752 |
+
{
|
| 753 |
+
extract($args);
|
| 754 |
+
$return = array();
|
| 755 |
+
foreach ($items as $item) {
|
| 756 |
+
switch ($items_edit_action) {
|
| 757 |
+
case 'activate':
|
| 758 |
+
switch_theme($item['path'], $item['stylesheet']);
|
| 759 |
+
break;
|
| 760 |
+
case 'delete':
|
| 761 |
+
$result = delete_theme($item['path']);
|
| 762 |
+
break;
|
| 763 |
+
default:
|
| 764 |
+
break;
|
| 765 |
+
}
|
| 766 |
+
|
| 767 |
+
if (is_wp_error($result)) {
|
| 768 |
+
$result = array(
|
| 769 |
+
'error' => $result->get_error_message()
|
| 770 |
+
);
|
| 771 |
+
} elseif ($result === false) {
|
| 772 |
+
$result = array(
|
| 773 |
+
'error' => "Failed to perform action."
|
| 774 |
+
);
|
| 775 |
+
} else {
|
| 776 |
+
$result = "OK";
|
| 777 |
+
}
|
| 778 |
+
$return[$item['name']] = $result;
|
| 779 |
+
}
|
| 780 |
+
|
| 781 |
+
return $return;
|
| 782 |
+
|
| 783 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 784 |
}
|
| 785 |
?>
|
plugins/cleanup/cleanup.php
CHANGED
|
@@ -10,140 +10,148 @@
|
|
| 10 |
* www.prelovac.com
|
| 11 |
**************************************************************/
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
|
| 27 |
mmb_add_action('cleanup_delete', 'cleanup_delete_worker');
|
| 28 |
-
|
| 29 |
-
function cleanup_delete_worker($params = array())
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
| 66 |
}
|
| 67 |
-
|
| 68 |
-
|
|
|
|
| 69 |
global $wpdb;
|
| 70 |
-
$sql
|
| 71 |
$num_revisions = $wpdb->get_var($wpdb->prepare($sql));
|
| 72 |
return $num_revisions;
|
| 73 |
}
|
| 74 |
|
| 75 |
-
|
|
|
|
| 76 |
global $wpdb;
|
| 77 |
-
$sql
|
| 78 |
$revisions = $wpdb->get_results($wpdb->prepare($sql));
|
| 79 |
return $revisions;
|
| 80 |
}
|
| 81 |
|
| 82 |
-
|
|
|
|
| 83 |
global $wpdb;
|
| 84 |
-
$
|
| 85 |
-
$
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
}
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
-
/* Optimize */
|
| 92 |
|
| 93 |
-
function mmb_get_overhead()
|
| 94 |
-
{
|
| 95 |
-
global $wpdb, $mmb_core;
|
| 96 |
-
$tot_data = 0;
|
| 97 |
-
$tot_idx = 0;
|
| 98 |
-
$tot_all = 0;
|
| 99 |
-
$query = 'SHOW TABLE STATUS FROM '. DB_NAME;
|
| 100 |
-
$tables = $wpdb->get_results($wpdb->prepare($query),ARRAY_A);
|
| 101 |
-
$total_gain = 0;
|
| 102 |
-
foreach($tables as $table)
|
| 103 |
-
{
|
| 104 |
-
if(in_array($table['Engine'], array('MyISAM', 'ISAM', 'HEAP', 'MEMORY', 'ARCHIVE'))){
|
| 105 |
-
|
| 106 |
-
if($wpdb->base_prefix != $wpdb->prefix){
|
| 107 |
-
if(preg_match('/^'.$wpdb->prefix.'*/Ui', $table['Name'])){
|
| 108 |
-
$total_gain += $table['Data_free'] / 1024;
|
| 109 |
-
}
|
| 110 |
-
} else if(preg_match('/^'.$wpdb->prefix.'[0-9]{1,20}_*/Ui', $table['Name'])){
|
| 111 |
-
continue;
|
| 112 |
-
}
|
| 113 |
-
else {
|
| 114 |
-
$total_gain += $table['Data_free'] / 1024;
|
| 115 |
-
}
|
| 116 |
-
} elseif ($table['Engine'] == 'InnoDB'){
|
| 117 |
-
//$total_gain += $table['Data_free'] > 100*1024*1024 ? $table['Data_free'] / 1024 : 0;
|
| 118 |
-
}
|
| 119 |
-
}
|
| 120 |
-
return round($total_gain,3);
|
| 121 |
-
}
|
| 122 |
|
|
|
|
| 123 |
|
| 124 |
-
function
|
| 125 |
{
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
}
|
| 139 |
-
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
| 141 |
$table_string = rtrim($table_string);
|
| 142 |
|
| 143 |
$query = "OPTIMIZE TABLE $table_string";
|
| 144 |
|
| 145 |
-
$optimize
|
| 146 |
-
|
|
|
|
|
|
|
|
|
|
| 147 |
}
|
| 148 |
|
| 149 |
|
|
@@ -153,25 +161,34 @@ function mmb_clear_overhead()
|
|
| 153 |
|
| 154 |
function mmb_num_spam_comments()
|
| 155 |
{
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
$num_spams =
|
| 159 |
return $num_spams;
|
| 160 |
}
|
| 161 |
|
| 162 |
function mmb_delete_spam_comments()
|
| 163 |
{
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
$
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
}
|
| 169 |
|
| 170 |
|
| 171 |
-
|
|
|
|
| 172 |
global $wpdb;
|
| 173 |
-
$sql
|
| 174 |
$spams = $wpdb->get_results($wpdb->prepare($sql));
|
| 175 |
return $spams;
|
| 176 |
}
|
|
|
|
| 177 |
?>
|
| 10 |
* www.prelovac.com
|
| 11 |
**************************************************************/
|
| 12 |
|
| 13 |
+
add_filter('mmb_stats_filter', 'mmb_get_extended_info');
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
function mmb_get_extended_info($stats)
|
| 17 |
+
{
|
| 18 |
+
$stats['num_revisions'] = mmb_num_revisions();
|
| 19 |
+
//$stats['num_revisions'] = 5;
|
| 20 |
+
$stats['overhead'] = mmb_handle_overhead(false);
|
| 21 |
+
$stats['num_spam_comments'] = mmb_num_spam_comments();
|
| 22 |
+
return $stats;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
/* Revisions */
|
| 26 |
|
| 27 |
mmb_add_action('cleanup_delete', 'cleanup_delete_worker');
|
| 28 |
+
|
| 29 |
+
function cleanup_delete_worker($params = array())
|
| 30 |
+
{
|
| 31 |
+
global $mmb_core;
|
| 32 |
+
|
| 33 |
+
$params_array = explode('_', $params['actions']);
|
| 34 |
+
$return_array = array();
|
| 35 |
+
foreach ($params_array as $param) {
|
| 36 |
+
switch ($param) {
|
| 37 |
+
case 'revision':
|
| 38 |
+
if (mmb_delete_all_revisions()) {
|
| 39 |
+
$return_array['revision'] = 'OK';
|
| 40 |
+
} else {
|
| 41 |
+
$return_array['revision_error'] = 'Failed, please try again';
|
| 42 |
+
}
|
| 43 |
+
break;
|
| 44 |
+
case 'overhead':
|
| 45 |
+
if (mmb_handle_overhead(true)) {
|
| 46 |
+
$return_array['overhead'] = 'OK';
|
| 47 |
+
} else {
|
| 48 |
+
$return_array['overhead_error'] = 'Failed, please try again';
|
| 49 |
+
}
|
| 50 |
+
break;
|
| 51 |
+
case 'comment':
|
| 52 |
+
if (mmb_delete_spam_comments()) {
|
| 53 |
+
$return_array['comment'] = 'OK';
|
| 54 |
+
} else {
|
| 55 |
+
$return_array['comment_error'] = 'Failed, please try again';
|
| 56 |
+
}
|
| 57 |
+
break;
|
| 58 |
+
default:
|
| 59 |
+
break;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
unset($params);
|
| 65 |
+
|
| 66 |
+
mmb_response($return_array, true);
|
| 67 |
}
|
| 68 |
+
|
| 69 |
+
function mmb_num_revisions()
|
| 70 |
+
{
|
| 71 |
global $wpdb;
|
| 72 |
+
$sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'revision'";
|
| 73 |
$num_revisions = $wpdb->get_var($wpdb->prepare($sql));
|
| 74 |
return $num_revisions;
|
| 75 |
}
|
| 76 |
|
| 77 |
+
function mmb_select_all_revisions()
|
| 78 |
+
{
|
| 79 |
global $wpdb;
|
| 80 |
+
$sql = "SELECT * FROM $wpdb->posts WHERE post_type = 'revision'";
|
| 81 |
$revisions = $wpdb->get_results($wpdb->prepare($sql));
|
| 82 |
return $revisions;
|
| 83 |
}
|
| 84 |
|
| 85 |
+
function mmb_delete_all_revisions()
|
| 86 |
+
{
|
| 87 |
global $wpdb;
|
| 88 |
+
$revisions = 1;
|
| 89 |
+
$total = 0;
|
| 90 |
+
while ($revisions) {
|
| 91 |
+
$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' LIMIT 200";
|
| 92 |
+
$revisions = $wpdb->query($wpdb->prepare($sql));
|
| 93 |
+
$total += $revisions;
|
| 94 |
+
if ($revisions)
|
| 95 |
+
usleep(100000);
|
| 96 |
+
}
|
| 97 |
+
return $total;
|
| 98 |
}
|
| 99 |
|
| 100 |
|
| 101 |
|
|
|
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
+
/* Optimize */
|
| 105 |
|
| 106 |
+
function mmb_handle_overhead($clear = false)
|
| 107 |
{
|
| 108 |
+
global $wpdb, $mmb_core;
|
| 109 |
+
$tot_data = 0;
|
| 110 |
+
$tot_idx = 0;
|
| 111 |
+
$tot_all = 0;
|
| 112 |
+
$query = 'SHOW TABLE STATUS FROM ' . DB_NAME;
|
| 113 |
+
$tables = $wpdb->get_results($wpdb->prepare($query), ARRAY_A);
|
| 114 |
+
$total_gain = 0;
|
| 115 |
+
foreach ($tables as $table) {
|
| 116 |
+
if (in_array($table['Engine'], array(
|
| 117 |
+
'MyISAM',
|
| 118 |
+
'ISAM',
|
| 119 |
+
'HEAP',
|
| 120 |
+
'MEMORY',
|
| 121 |
+
'ARCHIVE'
|
| 122 |
+
))) {
|
| 123 |
+
if ($wpdb->base_prefix != $wpdb->prefix) {
|
| 124 |
+
if (preg_match('/^' . $wpdb->prefix . '*/Ui', $table['Name'])) {
|
| 125 |
+
if ($table['Data_free'] > 0) {
|
| 126 |
+
$total_gain += $table['Data_free'] / 1024;
|
| 127 |
+
$table_string .= $table['Name'] . ",";
|
| 128 |
+
}
|
| 129 |
+
}
|
| 130 |
+
} else if (preg_match('/^' . $wpdb->prefix . '[0-9]{1,20}_*/Ui', $table['Name'])) {
|
| 131 |
+
continue;
|
| 132 |
+
} else {
|
| 133 |
+
if ($table['Data_free'] > 0) {
|
| 134 |
+
$total_gain += $table['Data_free'] / 1024;
|
| 135 |
+
$table_string .= $table['Name'] . ",";
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
} elseif ($table['Engine'] == 'InnoDB') {
|
| 139 |
+
//$total_gain += $table['Data_free'] > 100*1024*1024 ? $table['Data_free'] / 1024 : 0;
|
| 140 |
}
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
if ($clear) {
|
| 144 |
+
$table_string = substr($table_string, 0, strlen($table_string) - 1); //remove last ,
|
| 145 |
+
|
| 146 |
$table_string = rtrim($table_string);
|
| 147 |
|
| 148 |
$query = "OPTIMIZE TABLE $table_string";
|
| 149 |
|
| 150 |
+
$optimize = $wpdb->query($query);
|
| 151 |
+
|
| 152 |
+
return $optimize === FALSE ? false : true;
|
| 153 |
+
} else
|
| 154 |
+
return round($total_gain, 3);
|
| 155 |
}
|
| 156 |
|
| 157 |
|
| 161 |
|
| 162 |
function mmb_num_spam_comments()
|
| 163 |
{
|
| 164 |
+
global $wpdb;
|
| 165 |
+
$sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'spam'";
|
| 166 |
+
$num_spams = $wpdb->get_var($wpdb->prepare($sql));
|
| 167 |
return $num_spams;
|
| 168 |
}
|
| 169 |
|
| 170 |
function mmb_delete_spam_comments()
|
| 171 |
{
|
| 172 |
+
global $wpdb;
|
| 173 |
+
$spams = 1;
|
| 174 |
+
$total = 0;
|
| 175 |
+
while ($spams) {
|
| 176 |
+
$sql = "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam' LIMIT 200";
|
| 177 |
+
$spams = $wpdb->query($wpdb->prepare($sql));
|
| 178 |
+
$total += $spams;
|
| 179 |
+
if ($spams)
|
| 180 |
+
usleep(100000);
|
| 181 |
+
}
|
| 182 |
+
return $total;
|
| 183 |
}
|
| 184 |
|
| 185 |
|
| 186 |
+
function mmb_get_spam_comments()
|
| 187 |
+
{
|
| 188 |
global $wpdb;
|
| 189 |
+
$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'";
|
| 190 |
$spams = $wpdb->get_results($wpdb->prepare($sql));
|
| 191 |
return $spams;
|
| 192 |
}
|
| 193 |
+
|
| 194 |
?>
|
readme.txt
CHANGED
|
@@ -32,6 +32,12 @@ Check out [ManageWP.com](http://managewp.com/ "Manage Multiple Blogs").
|
|
| 32 |
|
| 33 |
== Changelog ==
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
= 3.9.12 =
|
| 36 |
* Minor bug fixes
|
| 37 |
* Backup, clone, favorites functionality improved
|
| 32 |
|
| 33 |
== Changelog ==
|
| 34 |
|
| 35 |
+
= 3.9.13 =
|
| 36 |
+
* Added bucket location for Amazon S3 backups
|
| 37 |
+
* Better backup feature for larger sites
|
| 38 |
+
* Added Disable compression to further help with larger sites
|
| 39 |
+
* Backing up wp-admin, wp-includes and wp-content by default now, other folders can be included manually
|
| 40 |
+
|
| 41 |
= 3.9.12 =
|
| 42 |
* Minor bug fixes
|
| 43 |
* Backup, clone, favorites functionality improved
|
screenshot-1.png
CHANGED
|
Binary file
|
stats.class.php
CHANGED
|
@@ -23,28 +23,29 @@ class MMB_Stats extends MMB_Core
|
|
| 23 |
* (functions to be called after a remote call from Master)
|
| 24 |
**************************************************************/
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
| 48 |
if (is_array($mmb_user_hits)) {
|
| 49 |
end($mmb_user_hits);
|
| 50 |
$last_key_date = key($mmb_user_hits);
|
|
@@ -53,365 +54,377 @@ class MMB_Stats extends MMB_Core
|
|
| 53 |
$this->set_hit_count(true);
|
| 54 |
}
|
| 55 |
$stats['hit_counter'] = get_option('user_hit_count');
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
$stats['mwp_next_backups'] = $this->get_backup_instance()->get_next_schedules();
|
| 229 |
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
$stats['mwp_next_backups'] = $this->get_backup_instance()->get_next_schedules();
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
global $wpdb, $mmb_wp_version, $mmb_plugin_dir, $wp_version, $wp_local_package;
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
$stats['wordpress_version']
|
| 343 |
-
|
| 344 |
-
$stats['php_version']
|
| 345 |
-
$stats['mysql_version']
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
if (!function_exists('get_filesystem_method'))
|
| 350 |
-
|
| 351 |
-
|
| 352 |
$stats['writable'] = $this->is_server_writable();
|
| 353 |
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
function get(
|
| 358 |
{
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
if( $this->mmb_multisite ){
|
| 383 |
-
$stats = $this->get_multisite( $stats );
|
| 384 |
}
|
| 385 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
$stats = apply_filters('mmb_stats_filter', $stats);
|
| 387 |
return $stats;
|
| 388 |
}
|
| 389 |
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
|
|
|
|
|
|
| 413 |
$num_approved_comments = 3;
|
| 414 |
-
$pending_comments
|
| 415 |
foreach ($pending_comments as &$comment) {
|
| 416 |
$commented_post = get_post($comment->comment_post_ID);
|
| 417 |
$comment->post_title = $commented_post->post_title;
|
|
@@ -435,37 +448,37 @@ class MMB_Stats extends MMB_Core
|
|
| 435 |
|
| 436 |
$stats = array();
|
| 437 |
|
| 438 |
-
$stats['email']
|
| 439 |
-
$stats['no_openssl']
|
| 440 |
-
$stats['content_path']
|
| 441 |
-
$stats['worker_path']
|
| 442 |
-
$stats['worker_version']
|
| 443 |
-
$stats['site_title']
|
| 444 |
-
$stats['site_tagline']
|
| 445 |
-
$stats['site_home']
|
| 446 |
-
$stats['admin_url']
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
$stats['writable'] = $this->is_server_writable();
|
| 462 |
-
|
| 463 |
return $stats;
|
| 464 |
}
|
| 465 |
|
| 466 |
function set_hit_count($fix_count = false)
|
| 467 |
{
|
| 468 |
-
if ($fix_count || (!is_admin() && !MMB_Stats::
|
| 469 |
$date = date('Y-m-d');
|
| 470 |
$user_hit_count = (array) get_option('user_hit_count');
|
| 471 |
if (!$user_hit_count) {
|
|
@@ -499,7 +512,7 @@ class MMB_Stats extends MMB_Core
|
|
| 499 |
$user_hit_count[$date] = 0;
|
| 500 |
}
|
| 501 |
if (!$fix_count)
|
| 502 |
-
$user_hit_count[$date] = ((int)$user_hit_count[$date]
|
| 503 |
|
| 504 |
if (count($user_hit_count) > 14) {
|
| 505 |
$shifted = @array_shift($user_hit_count);
|
|
@@ -526,7 +539,7 @@ class MMB_Stats extends MMB_Core
|
|
| 526 |
return get_option('user_hit_count');
|
| 527 |
}
|
| 528 |
|
| 529 |
-
function
|
| 530 |
{
|
| 531 |
$agent = $_SERVER['HTTP_USER_AGENT'];
|
| 532 |
|
|
@@ -570,134 +583,131 @@ class MMB_Stats extends MMB_Core
|
|
| 570 |
"aolserver"
|
| 571 |
);
|
| 572 |
|
| 573 |
-
$
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
$thebot = $bot;
|
| 577 |
-
break;
|
| 578 |
-
}
|
| 579 |
-
}
|
| 580 |
|
| 581 |
-
|
| 582 |
-
return $thebot;
|
| 583 |
-
} else
|
| 584 |
-
return false;
|
| 585 |
}
|
| 586 |
|
| 587 |
|
| 588 |
function set_notifications($params)
|
| 589 |
{
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
}
|
| 612 |
|
| 613 |
//Cron update check for notifications
|
| 614 |
-
function check_notifications()
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 619 |
|
| 620 |
-
if(is_array($mwp_notifications) && $mwp_notifications != false){
|
| 621 |
-
include_once(ABSPATH . 'wp-includes/update.php');
|
| 622 |
-
include_once(ABSPATH . '/wp-admin/includes/update.php');
|
| 623 |
-
extract($mwp_notifications);
|
| 624 |
-
|
| 625 |
-
//Check wordpress core updates
|
| 626 |
-
if($wp){
|
| 627 |
-
@wp_version_check();
|
| 628 |
-
if (function_exists('get_core_updates')) {
|
| 629 |
-
$wp_updates = get_core_updates();
|
| 630 |
-
if (!empty($wp_updates)) {
|
| 631 |
-
$current_transient = $wp_updates[0];
|
| 632 |
-
if ($current_transient->response == "development" || version_compare($wp_version, $current_transient->current, '<')) {
|
| 633 |
-
$current_transient->current_version = $wp_version;
|
| 634 |
-
$updates['core_updates'] = $current_transient;
|
| 635 |
-
} else
|
| 636 |
-
$updates['core_updates'] = array();
|
| 637 |
-
} else
|
| 638 |
-
$updates['core_updates'] = array();
|
| 639 |
-
}
|
| 640 |
-
}
|
| 641 |
-
|
| 642 |
-
//Check plugin updates
|
| 643 |
-
if($plugins){
|
| 644 |
-
@wp_update_plugins();
|
| 645 |
-
$this->get_installer_instance();
|
| 646 |
-
$updates['upgradable_plugins'] = $this->installer_instance->get_upgradable_plugins();
|
| 647 |
-
}
|
| 648 |
-
|
| 649 |
-
//Check theme updates
|
| 650 |
-
if($themes){
|
| 651 |
-
@wp_update_themes();
|
| 652 |
-
$this->get_installer_instance();
|
| 653 |
-
|
| 654 |
-
$updates['upgradable_themes'] = $this->installer_instance->get_upgradable_themes();
|
| 655 |
-
}
|
| 656 |
-
|
| 657 |
-
if($backups){
|
| 658 |
-
$this->get_backup_instance();
|
| 659 |
-
$backups = $this->backup_instance->get_backup_stats();
|
| 660 |
-
$updates['backups'] = $backups;
|
| 661 |
-
foreach($backups as $task_name => $backup_results){
|
| 662 |
-
foreach($backup_results as $k => $backup){
|
| 663 |
-
if(isset($backups[$task_name][$k]['server']['file_path'])){
|
| 664 |
-
unset($backups[$task_name][$k]['server']['file_path']);
|
| 665 |
-
}
|
| 666 |
-
}
|
| 667 |
-
}
|
| 668 |
-
$updates['backups'] = $backups;
|
| 669 |
-
}
|
| 670 |
-
|
| 671 |
-
if( !class_exists( 'WP_Http' ) ){
|
| 672 |
-
include_once( ABSPATH . WPINC. '/class-http.php' );
|
| 673 |
-
}
|
| 674 |
-
|
| 675 |
-
if(!empty($updates)){
|
| 676 |
-
$args = array();
|
| 677 |
-
$args['body'] = array('updates' => $updates, 'notification_key' => $notification_key);
|
| 678 |
-
$result= wp_remote_post($url, $args);
|
| 679 |
-
}
|
| 680 |
-
|
| 681 |
-
}
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
}
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
function cmp_posts_worker($a, $b)
|
| 688 |
-
{
|
| 689 |
-
return ($a->post_date < $b->post_date);
|
| 690 |
-
}
|
| 691 |
-
|
| 692 |
-
function trim_content($content = '', $length = 200){
|
| 693 |
-
|
| 694 |
-
if( function_exists('mb_strlen') && function_exists('mb_substr') )
|
| 695 |
-
$content = (mb_strlen($content) > ($length + 3)) ? mb_substr($content, 0, $length) . '...' : $content;
|
| 696 |
-
else
|
| 697 |
-
$content = (strlen($content) > ($length + 3)) ? substr($content, 0, $length) . '...' : $content;
|
| 698 |
-
|
| 699 |
-
return $content;
|
| 700 |
-
}
|
| 701 |
-
|
| 702 |
}
|
| 703 |
?>
|
| 23 |
* (functions to be called after a remote call from Master)
|
| 24 |
**************************************************************/
|
| 25 |
|
| 26 |
+
function get_core_update($stats, $options = array())
|
| 27 |
+
{
|
| 28 |
+
global $wp_version;
|
| 29 |
+
|
| 30 |
+
if (isset($options['core']) && $options['core']) {
|
| 31 |
+
$core = $this->mmb_get_transient('update_core');
|
| 32 |
+
if (isset($core->updates) && !empty($core->updates)) {
|
| 33 |
+
$current_transient = $core->updates[0];
|
| 34 |
+
if ($current_transient->response == "development" || version_compare($wp_version, $current_transient->current, '<')) {
|
| 35 |
+
$current_transient->current_version = $wp_version;
|
| 36 |
+
$stats['core_updates'] = $current_transient;
|
| 37 |
+
} else
|
| 38 |
+
$stats['core_updates'] = false;
|
| 39 |
+
} else
|
| 40 |
+
$stats['core_updates'] = false;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
return $stats;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
function get_hit_counter($stats, $options = array())
|
| 47 |
+
{
|
| 48 |
+
$mmb_user_hits = get_option('user_hit_count');
|
| 49 |
if (is_array($mmb_user_hits)) {
|
| 50 |
end($mmb_user_hits);
|
| 51 |
$last_key_date = key($mmb_user_hits);
|
| 54 |
$this->set_hit_count(true);
|
| 55 |
}
|
| 56 |
$stats['hit_counter'] = get_option('user_hit_count');
|
| 57 |
+
|
| 58 |
+
return $stats;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
function get_comments($stats, $options = array())
|
| 62 |
+
{
|
| 63 |
+
$nposts = isset($options['numberposts']) ? (int) $options['numberposts'] : 20;
|
| 64 |
+
$trimlen = isset($options['trimcontent']) ? (int) $options['trimcontent'] : 200;
|
| 65 |
+
|
| 66 |
+
if ($nposts) {
|
| 67 |
+
$comments = get_comments('status=hold&number=' . $nposts);
|
| 68 |
+
if (!empty($comments)) {
|
| 69 |
+
foreach ($comments as &$comment) {
|
| 70 |
+
$commented_post = get_post($comment->comment_post_ID);
|
| 71 |
+
$comment->post_title = $commented_post->post_title;
|
| 72 |
+
$comment->comment_content = $this->trim_content($comment->comment_content, $trimlen);
|
| 73 |
+
unset($comment->comment_author_url);
|
| 74 |
+
unset($comment->comment_author_email);
|
| 75 |
+
unset($comment->comment_author_IP);
|
| 76 |
+
unset($comment->comment_date_gmt);
|
| 77 |
+
unset($comment->comment_karma);
|
| 78 |
+
unset($comment->comment_agent);
|
| 79 |
+
unset($comment->comment_type);
|
| 80 |
+
unset($comment->comment_parent);
|
| 81 |
+
unset($comment->user_id);
|
| 82 |
+
}
|
| 83 |
+
$stats['comments']['pending'] = $comments;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
$comments = get_comments('status=approve&number=' . $nposts);
|
| 87 |
+
if (!empty($comments)) {
|
| 88 |
+
foreach ($comments as &$comment) {
|
| 89 |
+
$commented_post = get_post($comment->comment_post_ID);
|
| 90 |
+
$comment->post_title = $commented_post->post_title;
|
| 91 |
+
$comment->comment_content = $this->trim_content($comment->comment_content, $trimlen);
|
| 92 |
+
unset($comment->comment_author_url);
|
| 93 |
+
unset($comment->comment_author_email);
|
| 94 |
+
unset($comment->comment_author_IP);
|
| 95 |
+
unset($comment->comment_date_gmt);
|
| 96 |
+
unset($comment->comment_karma);
|
| 97 |
+
unset($comment->comment_agent);
|
| 98 |
+
unset($comment->comment_type);
|
| 99 |
+
unset($comment->comment_parent);
|
| 100 |
+
unset($comment->user_id);
|
| 101 |
+
}
|
| 102 |
+
$stats['comments']['approved'] = $comments;
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
return $stats;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
function get_posts($stats, $options = array())
|
| 109 |
+
{
|
| 110 |
+
$nposts = isset($options['numberposts']) ? (int) $options['numberposts'] : 20;
|
| 111 |
+
|
| 112 |
+
if ($nposts) {
|
| 113 |
+
$posts = get_posts('post_status=publish&numberposts=' . $nposts . '&orderby=post_date&order=desc');
|
| 114 |
+
$recent_posts = array();
|
| 115 |
+
if (!empty($posts)) {
|
| 116 |
+
foreach ($posts as $id => $recent_post) {
|
| 117 |
+
$recent = new stdClass();
|
| 118 |
+
$recent->post_permalink = get_permalink($recent_post->ID);
|
| 119 |
+
$recent->ID = $recent_post->ID;
|
| 120 |
+
$recent->post_date = $recent_post->post_date;
|
| 121 |
+
$recent->post_title = $recent_post->post_title;
|
| 122 |
+
$recent->comment_count = (int) $recent_post->comment_count;
|
| 123 |
+
$recent_posts[] = $recent;
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
$posts = get_pages('post_status=publish&numberposts=' . $nposts . '&orderby=post_date&order=desc');
|
| 128 |
+
$recent_pages_published = array();
|
| 129 |
+
if (!empty($posts)) {
|
| 130 |
+
foreach ((array) $posts as $id => $recent_page_published) {
|
| 131 |
+
$recent = new stdClass();
|
| 132 |
+
$recent->post_permalink = get_permalink($recent_page_published->ID);
|
| 133 |
+
|
| 134 |
+
$recent->ID = $recent_page_published->ID;
|
| 135 |
+
$recent->post_date = $recent_page_published->post_date;
|
| 136 |
+
$recent->post_title = $recent_page_published->post_title;
|
| 137 |
+
|
| 138 |
+
$recent_posts[] = $recent;
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
if (!empty($recent_posts)) {
|
| 142 |
+
usort($recent_posts, array(
|
| 143 |
+
$this,
|
| 144 |
+
'cmp_posts_worker'
|
| 145 |
+
));
|
| 146 |
+
$stats['posts'] = array_slice($recent_posts, 0, $nposts);
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
return $stats;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
function get_drafts($stats, $options = array())
|
| 153 |
+
{
|
| 154 |
+
$nposts = isset($options['numberposts']) ? (int) $options['numberposts'] : 20;
|
| 155 |
+
|
| 156 |
+
if ($nposts) {
|
| 157 |
+
$drafts = get_posts('post_status=draft&numberposts=' . $nposts . '&orderby=post_date&order=desc');
|
| 158 |
+
$recent_drafts = array();
|
| 159 |
+
if (!empty($drafts)) {
|
| 160 |
+
foreach ($drafts as $id => $recent_draft) {
|
| 161 |
+
$recent = new stdClass();
|
| 162 |
+
$recent->post_permalink = get_permalink($recent_draft->ID);
|
| 163 |
+
$recent->ID = $recent_draft->ID;
|
| 164 |
+
$recent->post_date = $recent_draft->post_date;
|
| 165 |
+
$recent->post_title = $recent_draft->post_title;
|
| 166 |
+
|
| 167 |
+
$recent_drafts[] = $recent;
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
$drafts = get_pages('post_status=draft&numberposts=' . $nposts . '&orderby=post_date&order=desc');
|
| 171 |
+
$recent_pages_drafts = array();
|
| 172 |
+
if (!empty($drafts)) {
|
| 173 |
+
foreach ((array) $drafts as $id => $recent_pages_draft) {
|
| 174 |
+
$recent = new stdClass();
|
| 175 |
+
$recent->post_permalink = get_permalink($recent_pages_draft->ID);
|
| 176 |
+
$recent->ID = $recent_pages_draft->ID;
|
| 177 |
+
$recent->post_date = $recent_pages_draft->post_date;
|
| 178 |
+
$recent->post_title = $recent_pages_draft->post_title;
|
| 179 |
+
|
| 180 |
+
$recent_drafts[] = $recent;
|
| 181 |
+
}
|
| 182 |
+
}
|
| 183 |
+
if (!empty($recent_drafts)) {
|
| 184 |
+
usort($recent_drafts, array(
|
| 185 |
+
$this,
|
| 186 |
+
'cmp_posts_worker'
|
| 187 |
+
));
|
| 188 |
+
$stats['drafts'] = array_slice($recent_drafts, 0, $nposts);
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
return $stats;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
function get_scheduled($stats, $options = array())
|
| 195 |
+
{
|
| 196 |
+
$nposts = isset($options['numberposts']) ? (int) $options['numberposts'] : 20;
|
| 197 |
+
|
| 198 |
+
if ($nposts) {
|
| 199 |
+
$scheduled = get_posts('post_status=future&numberposts=' . $nposts . '&orderby=post_date&order=desc');
|
| 200 |
+
$scheduled_posts = array();
|
| 201 |
+
if (!empty($scheduled)) {
|
| 202 |
+
foreach ($scheduled as $id => $scheduled) {
|
| 203 |
+
$recent = new stdClass();
|
| 204 |
+
$recent->post_permalink = get_permalink($scheduled->ID);
|
| 205 |
+
$recent->ID = $scheduled->ID;
|
| 206 |
+
$recent->post_date = $scheduled->post_date;
|
| 207 |
+
$recent->post_title = $scheduled->post_title;
|
| 208 |
+
$scheduled_posts[] = $recent;
|
| 209 |
+
}
|
| 210 |
+
}
|
| 211 |
+
$scheduled = get_pages('post_status=future&numberposts=' . $nposts . '&orderby=post_date&order=desc');
|
| 212 |
+
$recent_pages_drafts = array();
|
| 213 |
+
if (!empty($scheduled)) {
|
| 214 |
+
foreach ((array) $scheduled as $id => $scheduled) {
|
| 215 |
+
$recent = new stdClass();
|
| 216 |
+
$recent->post_permalink = get_permalink($scheduled->ID);
|
| 217 |
+
$recent->ID = $scheduled->ID;
|
| 218 |
+
$recent->post_date = $scheduled->post_date;
|
| 219 |
+
$recent->post_title = $scheduled->post_title;
|
| 220 |
+
|
| 221 |
+
$scheduled_posts[] = $recent;
|
| 222 |
+
}
|
| 223 |
+
}
|
| 224 |
+
if (!empty($scheduled_posts)) {
|
| 225 |
+
usort($scheduled_posts, array(
|
| 226 |
+
$this,
|
| 227 |
+
'cmp_posts_worker'
|
| 228 |
+
));
|
| 229 |
+
$stats['scheduled'] = array_slice($scheduled_posts, 0, $nposts);
|
| 230 |
+
}
|
| 231 |
+
}
|
| 232 |
+
return $stats;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
function get_backups($stats, $options = array())
|
| 236 |
+
{
|
| 237 |
+
$stats['mwp_backups'] = $this->get_backup_instance()->get_backup_stats();
|
| 238 |
$stats['mwp_next_backups'] = $this->get_backup_instance()->get_next_schedules();
|
| 239 |
|
| 240 |
+
return $stats;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
function get_backup_req($stats = array(), $options = array())
|
| 244 |
+
{
|
| 245 |
+
$stats['mwp_backups'] = $this->get_backup_instance()->get_backup_stats();
|
| 246 |
$stats['mwp_next_backups'] = $this->get_backup_instance()->get_next_schedules();
|
| 247 |
+
$stats['mwp_backup_req'] = $this->get_backup_instance()->check_backup_compat();
|
| 248 |
+
|
| 249 |
+
return $stats;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
function get_updates($stats, $options = array())
|
| 253 |
+
{
|
| 254 |
+
$upgrades = false;
|
| 255 |
+
|
| 256 |
+
if (isset($options['premium']) && $options['premium']) {
|
| 257 |
+
$premium_updates = array();
|
| 258 |
+
$upgrades = apply_filters('mwp_premium_update_notification', $premium_updates);
|
| 259 |
+
if (!empty($upgrades)) {
|
| 260 |
+
$stats['premium_updates'] = $upgrades;
|
| 261 |
+
$upgrades = false;
|
| 262 |
+
}
|
| 263 |
+
}
|
| 264 |
+
if (isset($options['themes']) && $options['themes']) {
|
| 265 |
+
$this->get_installer_instance();
|
| 266 |
+
$upgrades = $this->installer_instance->get_upgradable_themes();
|
| 267 |
+
if (!empty($upgrades)) {
|
| 268 |
+
$stats['upgradable_themes'] = $upgrades;
|
| 269 |
+
$upgrades = false;
|
| 270 |
+
}
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
if (isset($options['plugins']) && $options['plugins']) {
|
| 274 |
+
$this->get_installer_instance();
|
| 275 |
+
$upgrades = $this->installer_instance->get_upgradable_plugins();
|
| 276 |
+
if (!empty($upgrades)) {
|
| 277 |
+
$stats['upgradable_plugins'] = $upgrades;
|
| 278 |
+
$upgrades = false;
|
| 279 |
+
}
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
return $stats;
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
function get_errors($stats, $options = array())
|
| 286 |
+
{
|
| 287 |
+
$period = isset($options['days']) ? (int) $options['days'] * 86400 : 86400;
|
| 288 |
+
$errors = array();
|
| 289 |
+
if (isset($options['get']) && $options['get'] == true) {
|
| 290 |
+
if (function_exists('ini_get')) {
|
| 291 |
+
$logpath = ini_get('error_log');
|
| 292 |
+
if (!empty($logpath) && file_exists($logpath)) {
|
| 293 |
+
$logfile = @fopen($logpath, 'r');
|
| 294 |
+
if ($logfile) {
|
| 295 |
+
$maxlines = 1;
|
| 296 |
+
$linesize = -4096;
|
| 297 |
+
$lines = array();
|
| 298 |
+
$line = true;
|
| 299 |
+
while ($line !== false) {
|
| 300 |
+
fseek($logfile, ($maxlines * $linesize), SEEK_END);
|
| 301 |
+
$maxlines++;
|
| 302 |
+
if ($line) {
|
| 303 |
+
$line = fread($logfile, ($linesize * -1)) . $line;
|
| 304 |
+
|
| 305 |
+
foreach ((array) preg_split("/(\r|\n|\r\n)/U", $line) as $l) {
|
| 306 |
+
preg_match('/\[(.*)\]/Ui', $l, $match);
|
| 307 |
+
if (!empty($match)) {
|
| 308 |
+
$errors[strtotime($match[1])][] = str_replace($match[0], '', $l);
|
| 309 |
+
if (strtotime($match[1]) < ((int) time() - $period)) {
|
| 310 |
+
$line = false;
|
| 311 |
+
break;
|
| 312 |
+
}
|
| 313 |
+
}
|
| 314 |
+
}
|
| 315 |
+
}
|
| 316 |
+
}
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
}
|
| 320 |
+
}
|
| 321 |
+
}
|
| 322 |
+
if (!empty($errors))
|
| 323 |
+
$stats['errors'] = $errors;
|
| 324 |
+
|
| 325 |
+
return $stats;
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
function pre_init_stats($params)
|
| 329 |
+
{
|
| 330 |
+
global $_mmb_item_filter;
|
| 331 |
+
|
| 332 |
+
include_once(ABSPATH . 'wp-includes/update.php');
|
| 333 |
+
include_once(ABSPATH . '/wp-admin/includes/update.php');
|
| 334 |
+
|
| 335 |
+
$stats = $this->mmb_parse_action_params('pre_init_stats', $params, $this);
|
| 336 |
+
$num = extract($params);
|
| 337 |
+
|
| 338 |
+
if ($refresh == 'transient') {
|
| 339 |
+
$current = $this->mmb_get_transient('update_core');
|
| 340 |
+
if (isset($current->last_checked)) {
|
| 341 |
+
if (time() - $current->last_checked > 14400) {
|
| 342 |
+
@wp_version_check();
|
| 343 |
+
@wp_update_plugins();
|
| 344 |
+
@wp_update_themes();
|
| 345 |
+
}
|
| 346 |
+
}
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
global $wpdb, $mmb_wp_version, $mmb_plugin_dir, $wp_version, $wp_local_package;
|
| 350 |
+
|
| 351 |
+
$stats['worker_version'] = MMB_WORKER_VERSION;
|
| 352 |
+
$stats['wordpress_version'] = $wp_version;
|
| 353 |
+
$stats['wordpress_locale_pckg'] = $wp_local_package;
|
| 354 |
+
$stats['php_version'] = phpversion();
|
| 355 |
+
$stats['mysql_version'] = $wpdb->db_version();
|
| 356 |
+
$stats['wp_multisite'] = $this->mmb_multisite;
|
| 357 |
+
$stats['network_install'] = $this->network_admin_install;
|
| 358 |
+
|
| 359 |
if (!function_exists('get_filesystem_method'))
|
| 360 |
+
include_once(ABSPATH . 'wp-admin/includes/file.php');
|
| 361 |
+
|
| 362 |
$stats['writable'] = $this->is_server_writable();
|
| 363 |
|
| 364 |
+
return $stats;
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
function get($params)
|
| 368 |
{
|
| 369 |
+
global $wpdb, $mmb_wp_version, $mmb_plugin_dir, $_mmb_item_filter;
|
| 370 |
+
|
| 371 |
+
include_once(ABSPATH . 'wp-includes/update.php');
|
| 372 |
+
include_once(ABSPATH . '/wp-admin/includes/update.php');
|
| 373 |
+
|
| 374 |
+
$stats = $this->mmb_parse_action_params('get', $params, $this);
|
| 375 |
+
$update_check = array();
|
| 376 |
+
$num = extract($params);
|
| 377 |
+
if ($refresh == 'transient') {
|
| 378 |
+
$update_check = apply_filters('mwp_premium_update_check', $update_check);
|
| 379 |
+
if (!empty($update_check)) {
|
| 380 |
+
foreach ($update_check as $update) {
|
| 381 |
+
if (is_array($update['callback'])) {
|
| 382 |
+
$update_result = call_user_func(array(
|
| 383 |
+
$update['callback'][0],
|
| 384 |
+
$update['callback'][1]
|
| 385 |
+
));
|
| 386 |
+
} else if (is_string($update['callback'])) {
|
| 387 |
+
$update_result = call_user_func($update['callback']);
|
| 388 |
+
}
|
| 389 |
+
}
|
| 390 |
+
}
|
|
|
|
|
|
|
|
|
|
| 391 |
}
|
| 392 |
+
|
| 393 |
+
if ($this->mmb_multisite) {
|
| 394 |
+
$stats = $this->get_multisite($stats);
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
$stats = apply_filters('mmb_stats_filter', $stats);
|
| 398 |
return $stats;
|
| 399 |
}
|
| 400 |
|
| 401 |
+
function get_multisite($stats = array())
|
| 402 |
+
{
|
| 403 |
+
global $current_user;
|
| 404 |
+
|
| 405 |
+
if ($this->network_admin_install == '1' && current_user_can('update_core')) {
|
| 406 |
+
$user_blogs = get_blogs_of_user($current_user->ID);
|
| 407 |
+
if (!empty($user_blogs)) {
|
| 408 |
+
$blogs = array();
|
| 409 |
+
foreach ($user_blogs as $blog_id => $data) {
|
| 410 |
+
if ($this->mmb_multisite == $blog_id)
|
| 411 |
+
continue;
|
| 412 |
+
|
| 413 |
+
if (isset($data->siteurl))
|
| 414 |
+
$blogs[] = $data->siteurl;
|
| 415 |
+
}
|
| 416 |
+
if (!empty($blogs))
|
| 417 |
+
$stats['network_blogs'] = $blogs;
|
| 418 |
+
}
|
| 419 |
+
}
|
| 420 |
+
return $stats;
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
function get_comments_stats()
|
| 424 |
+
{
|
| 425 |
+
$num_pending_comments = 3;
|
| 426 |
$num_approved_comments = 3;
|
| 427 |
+
$pending_comments = get_comments('status=hold&number=' . $num_pending_comments);
|
| 428 |
foreach ($pending_comments as &$comment) {
|
| 429 |
$commented_post = get_post($comment->comment_post_ID);
|
| 430 |
$comment->post_title = $commented_post->post_title;
|
| 448 |
|
| 449 |
$stats = array();
|
| 450 |
|
| 451 |
+
$stats['email'] = get_option('admin_email');
|
| 452 |
+
$stats['no_openssl'] = $this->get_random_signature();
|
| 453 |
+
$stats['content_path'] = WP_CONTENT_DIR;
|
| 454 |
+
$stats['worker_path'] = $mmb_plugin_dir;
|
| 455 |
+
$stats['worker_version'] = MMB_WORKER_VERSION;
|
| 456 |
+
$stats['site_title'] = get_bloginfo('name');
|
| 457 |
+
$stats['site_tagline'] = get_bloginfo('description');
|
| 458 |
+
$stats['site_home'] = get_option('home');
|
| 459 |
+
$stats['admin_url'] = admin_url();
|
| 460 |
+
$stats['wp_multisite'] = $this->mmb_multisite;
|
| 461 |
+
$stats['network_install'] = $this->network_admin_install;
|
| 462 |
+
|
| 463 |
+
if ($this->mmb_multisite) {
|
| 464 |
+
$details = get_blog_details($this->mmb_multisite);
|
| 465 |
+
if (isset($details->site_id)) {
|
| 466 |
+
$details = get_blog_details($details->site_id);
|
| 467 |
+
if (isset($details->siteurl))
|
| 468 |
+
$stats['network_parent'] = $details->siteurl;
|
| 469 |
+
}
|
| 470 |
+
}
|
| 471 |
+
if (!function_exists('get_filesystem_method'))
|
| 472 |
+
include_once(ABSPATH . 'wp-admin/includes/file.php');
|
| 473 |
+
|
| 474 |
$stats['writable'] = $this->is_server_writable();
|
| 475 |
+
|
| 476 |
return $stats;
|
| 477 |
}
|
| 478 |
|
| 479 |
function set_hit_count($fix_count = false)
|
| 480 |
{
|
| 481 |
+
if ($fix_count || (!is_admin() && !MMB_Stats::is_bot())) {
|
| 482 |
$date = date('Y-m-d');
|
| 483 |
$user_hit_count = (array) get_option('user_hit_count');
|
| 484 |
if (!$user_hit_count) {
|
| 512 |
$user_hit_count[$date] = 0;
|
| 513 |
}
|
| 514 |
if (!$fix_count)
|
| 515 |
+
$user_hit_count[$date] = ((int) $user_hit_count[$date]) + 1;
|
| 516 |
|
| 517 |
if (count($user_hit_count) > 14) {
|
| 518 |
$shifted = @array_shift($user_hit_count);
|
| 539 |
return get_option('user_hit_count');
|
| 540 |
}
|
| 541 |
|
| 542 |
+
function is_bot()
|
| 543 |
{
|
| 544 |
$agent = $_SERVER['HTTP_USER_AGENT'];
|
| 545 |
|
| 583 |
"aolserver"
|
| 584 |
);
|
| 585 |
|
| 586 |
+
foreach ($bot_list as $bot)
|
| 587 |
+
if (strpos($agent, $bot) !== false)
|
| 588 |
+
return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 589 |
|
| 590 |
+
return false;
|
|
|
|
|
|
|
|
|
|
| 591 |
}
|
| 592 |
|
| 593 |
|
| 594 |
function set_notifications($params)
|
| 595 |
{
|
| 596 |
+
if (empty($params))
|
| 597 |
+
return false;
|
| 598 |
+
|
| 599 |
+
extract($params);
|
| 600 |
+
|
| 601 |
+
if (!isset($delete)) {
|
| 602 |
+
$mwp_notifications = array(
|
| 603 |
+
'plugins' => $plugins,
|
| 604 |
+
'themes' => $themes,
|
| 605 |
+
'wp' => $wp,
|
| 606 |
+
'backups' => $backups,
|
| 607 |
+
'url' => $url,
|
| 608 |
+
'notification_key' => $notification_key
|
| 609 |
+
);
|
| 610 |
+
update_option('mwp_notifications', $mwp_notifications);
|
| 611 |
+
} else {
|
| 612 |
+
delete_option('mwp_notifications');
|
| 613 |
+
}
|
| 614 |
+
|
| 615 |
+
return true;
|
| 616 |
+
|
| 617 |
}
|
| 618 |
|
| 619 |
//Cron update check for notifications
|
| 620 |
+
function check_notifications()
|
| 621 |
+
{
|
| 622 |
+
global $wpdb, $mmb_wp_version, $mmb_plugin_dir, $wp_version, $wp_local_package;
|
| 623 |
+
|
| 624 |
+
$mwp_notifications = get_option('mwp_notifications', true);
|
| 625 |
+
$updates = array();
|
| 626 |
+
|
| 627 |
+
if (is_array($mwp_notifications) && $mwp_notifications != false) {
|
| 628 |
+
include_once(ABSPATH . 'wp-includes/update.php');
|
| 629 |
+
include_once(ABSPATH . '/wp-admin/includes/update.php');
|
| 630 |
+
extract($mwp_notifications);
|
| 631 |
+
|
| 632 |
+
//Check wordpress core updates
|
| 633 |
+
if ($wp) {
|
| 634 |
+
@wp_version_check();
|
| 635 |
+
if (function_exists('get_core_updates')) {
|
| 636 |
+
$wp_updates = get_core_updates();
|
| 637 |
+
if (!empty($wp_updates)) {
|
| 638 |
+
$current_transient = $wp_updates[0];
|
| 639 |
+
if ($current_transient->response == "development" || version_compare($wp_version, $current_transient->current, '<')) {
|
| 640 |
+
$current_transient->current_version = $wp_version;
|
| 641 |
+
$updates['core_updates'] = $current_transient;
|
| 642 |
+
} else
|
| 643 |
+
$updates['core_updates'] = array();
|
| 644 |
+
} else
|
| 645 |
+
$updates['core_updates'] = array();
|
| 646 |
+
}
|
| 647 |
+
}
|
| 648 |
+
|
| 649 |
+
//Check plugin updates
|
| 650 |
+
if ($plugins) {
|
| 651 |
+
@wp_update_plugins();
|
| 652 |
+
$this->get_installer_instance();
|
| 653 |
+
$updates['upgradable_plugins'] = $this->installer_instance->get_upgradable_plugins();
|
| 654 |
+
}
|
| 655 |
+
|
| 656 |
+
//Check theme updates
|
| 657 |
+
if ($themes) {
|
| 658 |
+
@wp_update_themes();
|
| 659 |
+
$this->get_installer_instance();
|
| 660 |
+
|
| 661 |
+
$updates['upgradable_themes'] = $this->installer_instance->get_upgradable_themes();
|
| 662 |
+
}
|
| 663 |
+
|
| 664 |
+
if ($backups) {
|
| 665 |
+
$this->get_backup_instance();
|
| 666 |
+
$backups = $this->backup_instance->get_backup_stats();
|
| 667 |
+
$updates['backups'] = $backups;
|
| 668 |
+
foreach ($backups as $task_name => $backup_results) {
|
| 669 |
+
foreach ($backup_results as $k => $backup) {
|
| 670 |
+
if (isset($backups[$task_name][$k]['server']['file_path'])) {
|
| 671 |
+
unset($backups[$task_name][$k]['server']['file_path']);
|
| 672 |
+
}
|
| 673 |
+
}
|
| 674 |
+
}
|
| 675 |
+
$updates['backups'] = $backups;
|
| 676 |
+
}
|
| 677 |
+
|
| 678 |
+
if (!class_exists('WP_Http')) {
|
| 679 |
+
include_once(ABSPATH . WPINC . '/class-http.php');
|
| 680 |
+
}
|
| 681 |
+
|
| 682 |
+
if (!empty($updates)) {
|
| 683 |
+
$args = array();
|
| 684 |
+
$args['body'] = array(
|
| 685 |
+
'updates' => $updates,
|
| 686 |
+
'notification_key' => $notification_key
|
| 687 |
+
);
|
| 688 |
+
$result = wp_remote_post($url, $args);
|
| 689 |
+
}
|
| 690 |
+
|
| 691 |
+
}
|
| 692 |
+
|
| 693 |
+
|
| 694 |
+
}
|
| 695 |
+
|
| 696 |
+
|
| 697 |
+
function cmp_posts_worker($a, $b)
|
| 698 |
+
{
|
| 699 |
+
return ($a->post_date < $b->post_date);
|
| 700 |
+
}
|
| 701 |
+
|
| 702 |
+
function trim_content($content = '', $length = 200)
|
| 703 |
+
{
|
| 704 |
+
if (function_exists('mb_strlen') && function_exists('mb_substr'))
|
| 705 |
+
$content = (mb_strlen($content) > ($length + 3)) ? mb_substr($content, 0, $length) . '...' : $content;
|
| 706 |
+
else
|
| 707 |
+
$content = (strlen($content) > ($length + 3)) ? substr($content, 0, $length) . '...' : $content;
|
| 708 |
+
|
| 709 |
+
return $content;
|
| 710 |
+
}
|
| 711 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 712 |
}
|
| 713 |
?>
|
version
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
3.9.
|
| 1 |
+
3.9.13
|
