| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('UPDRAFTCENTRAL_CLIENT_DIR')) die('No access.'); |
| 4 |
|
| 5 |
/** |
| 6 |
* - A container for all the RPC commands implemented. Commands map exactly onto method names (and hence this class should not implement anything else, beyond the constructor, and private methods) |
| 7 |
* - Return format is array('response' => (string - a code), 'data' => (mixed)); |
| 8 |
* |
| 9 |
* RPC commands are not allowed to begin with an underscore. So, any private methods can be prefixed with an underscore. |
| 10 |
*/ |
| 11 |
abstract class UpdraftCentral_Commands { |
| 12 |
|
| 13 |
protected $rc; |
| 14 |
|
| 15 |
protected $ud; |
| 16 |
|
| 17 |
public function __construct($rc) { |
| 18 |
$this->rc = $rc; |
| 19 |
global $updraftplus; |
| 20 |
$this->ud = $updraftplus; |
| 21 |
} |
| 22 |
|
| 23 |
final protected function _admin_include() { |
| 24 |
$files = func_get_args(); |
| 25 |
foreach ($files as $file) { |
| 26 |
include_once(ABSPATH.'/wp-admin/includes/'.$file); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
final protected function _frontend_include() { |
| 31 |
$files = func_get_args(); |
| 32 |
foreach ($files as $file) { |
| 33 |
include_once(ABSPATH.WPINC.'/'.$file); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
final protected function _response($data = null, $code = 'rpcok') { |
| 38 |
return array( |
| 39 |
'response' => $code, |
| 40 |
'data' => $data |
| 41 |
); |
| 42 |
} |
| 43 |
|
| 44 |
final protected function _generic_error_response($code = 'central_unspecified', $data = null) { |
| 45 |
return $this->_response( |
| 46 |
array( |
| 47 |
'code' => $code, |
| 48 |
'data' => $data |
| 49 |
), |
| 50 |
'rpcerror' |
| 51 |
); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Checks whether a backup and a security credentials is required for the given request |
| 56 |
* |
| 57 |
* @param array $dir The directory location to check |
| 58 |
* @return array |
| 59 |
*/ |
| 60 |
final protected function _get_backup_credentials_settings($dir) { |
| 61 |
// Do we need to ask the user for filesystem credentials? when installing and/or deleting items in the given directory |
| 62 |
$filesystem_method = get_filesystem_method(array(), $dir); |
| 63 |
ob_start(); |
| 64 |
$filesystem_credentials_are_stored = request_filesystem_credentials(site_url()); |
| 65 |
ob_end_clean(); |
| 66 |
$request_filesystem_credentials = ('direct' != $filesystem_method && !$filesystem_credentials_are_stored); |
| 67 |
|
| 68 |
// Do we need to execute a backup process before installing/managing items |
| 69 |
$automatic_backups = (class_exists('UpdraftPlus_Options') && class_exists('UpdraftPlus_Addon_Autobackup') && UpdraftPlus_Options::get_updraft_option('updraft_autobackup_default', true)) ? true : false; |
| 70 |
|
| 71 |
return array( |
| 72 |
'request_filesystem_credentials' => $request_filesystem_credentials, |
| 73 |
'automatic_backups' => $automatic_backups |
| 74 |
); |
| 75 |
} |
| 76 |
} |
| 77 |
|