| 1 |
<?php |
| 2 |
|
| 3 |
class Mmb_WP extends Mmb_Core |
| 4 |
{ |
| 5 |
function __construct() |
| 6 |
{ |
| 7 |
parent::__construct(); |
| 8 |
} |
| 9 |
|
| 10 |
/************************************************************* |
| 11 |
* FACADE functions |
| 12 |
* (functions to be called after a remote XMLRPC from Master) |
| 13 |
**************************************************************/ |
| 14 |
function check_version($args, $login_required = TRUE) |
| 15 |
{ |
| 16 |
$this->_escape($args); |
| 17 |
|
| 18 |
$username = $args[0]; |
| 19 |
if($login_required) |
| 20 |
$password = $args[1]; |
| 21 |
// $password = $this->ende_instance->decrypt(base64_decode($args[1])); |
| 22 |
$get_default_data = (bool) $args[2]; |
| 23 |
|
| 24 |
if ($login_required && !$user = $this->login($username, $password)) |
| 25 |
{ |
| 26 |
return $this->error; |
| 27 |
} |
| 28 |
|
| 29 |
if (!current_user_can('update_plugins')) |
| 30 |
{ |
| 31 |
return new IXR_Error(401, 'You do not have sufficient permissions to upgrade WordPress on the remote blog.'); |
| 32 |
} |
| 33 |
|
| 34 |
require_once(ABSPATH . 'wp-includes/version.php'); |
| 35 |
|
| 36 |
$updates = get_core_updates(); |
| 37 |
$update = $updates[0]; |
| 38 |
global $wp_version; |
| 39 |
if (!isset($update->response) || 'latest' == $update->response) |
| 40 |
{ |
| 41 |
if (!$get_default_data) |
| 42 |
return new IXR_Error(999, 'The remote blog has the latest version of WordPress. You do not need to upgrade.'); |
| 43 |
|
| 44 |
// return default (current version) data |
| 45 |
// this is used when initial blog row |
| 46 |
return array( |
| 47 |
'current_version' => $wp_version, |
| 48 |
'latest_version' => FALSE, |
| 49 |
); |
| 50 |
} |
| 51 |
else |
| 52 |
{ |
| 53 |
return array( |
| 54 |
'current_version' => $wp_version, |
| 55 |
'latest_version' => $update, |
| 56 |
); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Upgrades WordPress locally |
| 62 |
* |
| 63 |
*/ |
| 64 |
function upgrade($args){ |
| 65 |
|
| 66 |
$username = $args[0]; |
| 67 |
// $password = $this->ende_instance->decrypt(base64_decode($args[1])); |
| 68 |
$password = $args[1]; |
| 69 |
|
| 70 |
if (!$user = $this->login($username, $password)) |
| 71 |
{ |
| 72 |
$this->_last_worker_message(array('error' => $this->error)); |
| 73 |
} |
| 74 |
|
| 75 |
if(!current_user_can('administrator')){ |
| 76 |
$this->_last_worker_message(array('error' => "You don't have permissions to upgrade this blog.")); |
| 77 |
die(); |
| 78 |
} |
| 79 |
|
| 80 |
$upgrade_info = $this->check_version($args); |
| 81 |
if(empty($upgrade_info['latest_version'])){ |
| 82 |
$this->_last_worker_message(array('error' => print_r($upgrade_info, true))); |
| 83 |
die(); |
| 84 |
} |
| 85 |
ob_start(); |
| 86 |
|
| 87 |
include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 88 |
$upgrader = new Core_Upgrader(); |
| 89 |
$result = $upgrader->upgrade($upgrade_info['latest_version']); |
| 90 |
|
| 91 |
ob_end_clean(); |
| 92 |
if(!$result){ |
| 93 |
$this->_last_worker_message(array('success' => 'true', 'version' => $upgrade_info['latest_version'])); |
| 94 |
|
| 95 |
}else { |
| 96 |
$this->_last_worker_message(array('error' => $result)); |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Gets updates to core and plugins (just like Tool->Upgrade) |
| 102 |
* |
| 103 |
* @param mixed $args |
| 104 |
*/ |
| 105 |
function get_updates($args) |
| 106 |
{ |
| 107 |
$this->_escape($args); |
| 108 |
|
| 109 |
$username = $args[0]; |
| 110 |
$password = $args[1]; |
| 111 |
|
| 112 |
if (!$user = $this->login($username, $password)) |
| 113 |
{ |
| 114 |
return $this->error; |
| 115 |
} |
| 116 |
|
| 117 |
$args[] = 1; // get default data |
| 118 |
|
| 119 |
return array( |
| 120 |
'core' => $this->check_version($args, FALSE), |
| 121 |
'plugins' => $this->get_plugin_instance()->get_upgradable_plugins(), |
| 122 |
); |
| 123 |
} |
| 124 |
} |