| 1 |
<?php |
| 2 |
|
| 3 |
if (class_exists('UpdraftPlus_Host')) return; |
| 4 |
|
| 5 |
if (!defined('UPDRAFTCENTRAL_CLIENT_DIR')) define('UPDRAFTCENTRAL_CLIENT_DIR', dirname(__FILE__)); |
| 6 |
if (!defined('UPDRAFTCENTRAL_CLIENT_URL')) define('UPDRAFTCENTRAL_CLIENT_URL', plugins_url('', __FILE__)); |
| 7 |
if (!class_exists('UpdraftCentral_Host')) { |
| 8 |
include_once(UPDRAFTCENTRAL_CLIENT_DIR.'/host.php'); |
| 9 |
} |
| 10 |
|
| 11 |
/** |
| 12 |
* This class is the basic bridge between UpdraftCentral and UpdraftPlus. |
| 13 |
*/ |
| 14 |
class UpdraftPlus_Host extends UpdraftCentral_Host { |
| 15 |
|
| 16 |
public $plugin_name = 'updraftplus'; |
| 17 |
|
| 18 |
public $translations = array(); |
| 19 |
|
| 20 |
protected static $_instance = null; |
| 21 |
|
| 22 |
/** |
| 23 |
* Creates an instance of this class. Singleton Pattern |
| 24 |
* |
| 25 |
* @return object Instance of this class |
| 26 |
*/ |
| 27 |
public static function instance() { |
| 28 |
if (empty(self::$_instance)) { |
| 29 |
self::$_instance = new self(); |
| 30 |
} |
| 31 |
|
| 32 |
return self::$_instance; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Class constructor |
| 37 |
*/ |
| 38 |
public function __construct() { |
| 39 |
parent::__construct(); |
| 40 |
|
| 41 |
add_action('updraftplus_debugtools_dashboard', array($this, 'debugtools_dashboard'), 20); |
| 42 |
|
| 43 |
$this->maybe_initialize_required_objects(); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Loads the UpdraftCentral_Main instance |
| 48 |
* |
| 49 |
* @return void |
| 50 |
*/ |
| 51 |
public function load_updraftcentral() { |
| 52 |
$central_path = $this->is_host_dir_set() ? trailingslashit(UPDRAFTPLUS_DIR) : ''; |
| 53 |
|
| 54 |
if (file_exists($central_path.'central/bootstrap.php')) { |
| 55 |
include_once($central_path.'central/bootstrap.php'); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Whether the current user can perform key control AJAX actions |
| 61 |
* |
| 62 |
* @return Boolean |
| 63 |
*/ |
| 64 |
public function current_user_can_ajax() { |
| 65 |
return UpdraftPlus_Options::user_can_manage(); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Below are interface methods' implementations that are required by UpdraftCentral to function properly. Please |
| 70 |
* see the "interface.php" to check all the required interface methods. |
| 71 |
*/ |
| 72 |
|
| 73 |
/** |
| 74 |
* Checks whether the plugin's DIR constant is currently define or not |
| 75 |
* |
| 76 |
* @return bool |
| 77 |
*/ |
| 78 |
public function is_host_dir_set() { |
| 79 |
return defined('UPDRAFTPLUS_DIR') ? true : false; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Get the host plugin's dir path |
| 84 |
* |
| 85 |
* @return string |
| 86 |
*/ |
| 87 |
public function get_host_dir() { |
| 88 |
return defined('UPDRAFTPLUS_DIR') ? UPDRAFTPLUS_DIR : dirname(dirname(__FILE__)); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Retrieves the filter used by UpdraftPlus to log errors or certain events |
| 93 |
* |
| 94 |
* @return string |
| 95 |
*/ |
| 96 |
public function get_logline_filter() { |
| 97 |
return 'updraftplus_logline'; |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Checks whether debug mod is set |
| 102 |
* |
| 103 |
* @return bool |
| 104 |
*/ |
| 105 |
public function get_debug_mode() { |
| 106 |
if (class_exists('UpdraftPlus_Options')) { |
| 107 |
return UpdraftPlus_Options::get_updraft_option('updraft_debug_mode'); |
| 108 |
} |
| 109 |
return false; |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* Used as a central location (to avoid repetition) to register or de-register hooks into the WP HTTP API |
| 114 |
* |
| 115 |
* @param bool $register True to register, false to de-register |
| 116 |
* @return void |
| 117 |
*/ |
| 118 |
public function register_wp_http_option_hooks($register = true) { |
| 119 |
global $updraftplus; |
| 120 |
|
| 121 |
if ($updraftplus) { |
| 122 |
$updraftplus->register_wp_http_option_hooks($register); |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Retrieves the class name of the host plugin |
| 128 |
* |
| 129 |
* @return string|bool |
| 130 |
*/ |
| 131 |
public function get_class_name() { |
| 132 |
global $updraftplus; |
| 133 |
|
| 134 |
if ($updraftplus) { |
| 135 |
return get_class($updraftplus); |
| 136 |
} |
| 137 |
|
| 138 |
return false; |
| 139 |
} |
| 140 |
|
| 141 |
/** |
| 142 |
* Returns the instance of the host plugin |
| 143 |
* |
| 144 |
* @return object|bool |
| 145 |
*/ |
| 146 |
public function get_instance() { |
| 147 |
global $updraftplus; |
| 148 |
|
| 149 |
if ($updraftplus) { |
| 150 |
return $updraftplus; |
| 151 |
} |
| 152 |
|
| 153 |
return false; |
| 154 |
} |
| 155 |
|
| 156 |
/** |
| 157 |
* Returns the admin instance of the host plugin |
| 158 |
* |
| 159 |
* @return object|bool |
| 160 |
*/ |
| 161 |
public function get_admin_instance() { |
| 162 |
global $updraftplus_admin; |
| 163 |
|
| 164 |
if ($updraftplus_admin) { |
| 165 |
return $updraftplus_admin; |
| 166 |
} else { |
| 167 |
if (defined('UPDRAFTPLUS_DIR') && file_exists(UPDRAFTPLUS_DIR.'/admin.php')) { |
| 168 |
updraft_try_include_file('admin.php', 'include_once'); |
| 169 |
$updraftplus_admin = new UpdraftPlus_Admin(); |
| 170 |
return $updraftplus_admin; |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
return false; |
| 175 |
} |
| 176 |
|
| 177 |
/** |
| 178 |
* Logs the given line |
| 179 |
* |
| 180 |
* @param string $line The log line |
| 181 |
* @param string $level The log level: notice, warning, error, etc. |
| 182 |
* @param boolean|string $uniq_id Each of these will only be logged once |
| 183 |
* |
| 184 |
* @return void |
| 185 |
*/ |
| 186 |
public function log($line, $level = 'notice', $uniq_id = false) { |
| 187 |
global $updraftplus; |
| 188 |
|
| 189 |
if ($updraftplus) { |
| 190 |
if (is_callable(array($updraftplus, 'log'))) { |
| 191 |
call_user_func(array($updraftplus, 'log'), $line, $level, $uniq_id); |
| 192 |
} |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
/** |
| 197 |
* Returns the current version of the host plugin |
| 198 |
* |
| 199 |
* @return string|bool |
| 200 |
*/ |
| 201 |
public function get_version() { |
| 202 |
global $updraftplus; |
| 203 |
|
| 204 |
if ($updraftplus) { |
| 205 |
return $updraftplus->version; |
| 206 |
} |
| 207 |
|
| 208 |
return false; |
| 209 |
} |
| 210 |
|
| 211 |
/** |
| 212 |
* Returns the filesystem class of the host's plugin |
| 213 |
* |
| 214 |
* @return class|bool |
| 215 |
*/ |
| 216 |
public function get_filesystem_functions() { |
| 217 |
if ($this->has_filesystem_functions()) { |
| 218 |
return UpdraftPlus_Filesystem_Functions; |
| 219 |
} |
| 220 |
|
| 221 |
return false; |
| 222 |
} |
| 223 |
|
| 224 |
/** |
| 225 |
* Checks whether the filesystem class of the host plugin exists |
| 226 |
* |
| 227 |
* @return bool |
| 228 |
*/ |
| 229 |
public function has_filesystem_functions() { |
| 230 |
return class_exists('UpdraftPlus_Filesystem_Functions'); |
| 231 |
} |
| 232 |
|
| 233 |
/** |
| 234 |
* Checks whether force debugging is set |
| 235 |
* |
| 236 |
* @return bool |
| 237 |
*/ |
| 238 |
public function is_force_debug() { |
| 239 |
return (defined('UPDRAFTPLUS_UDRPC_FORCE_DEBUG') && UPDRAFTPLUS_UDRPC_FORCE_DEBUG) ? true : false; |
| 240 |
} |
| 241 |
|
| 242 |
/** |
| 243 |
* Initializes required objects (if not yet initialized) for UpdraftCentral usage |
| 244 |
* |
| 245 |
* @return void |
| 246 |
*/ |
| 247 |
private function maybe_initialize_required_objects() { |
| 248 |
global $updraftplus; |
| 249 |
|
| 250 |
if (!class_exists('UpdraftPlus')) { |
| 251 |
if (defined('UPDRAFTPLUS_DIR') && file_exists(UPDRAFTPLUS_DIR.'/class-updraftplus.php')) { |
| 252 |
updraft_try_include_file('class-updraftplus.php', 'include_once'); |
| 253 |
if (empty($updraftplus) || !is_a($updraftplus, 'UpdraftPlus')) { |
| 254 |
$updraftplus = new UpdraftPlus(); |
| 255 |
} |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
if (!class_exists('UpdraftPlus_Options')) { |
| 260 |
if (defined('UPDRAFTPLUS_DIR') && file_exists(UPDRAFTPLUS_DIR.'/options.php')) { |
| 261 |
updraft_try_include_file('options.php', 'require_once'); |
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
if (!class_exists('UpdraftPlus_Filesystem_Functions')) { |
| 266 |
if (defined('UPDRAFTPLUS_DIR') && file_exists(UPDRAFTPLUS_DIR.'/includes/class-filesystem-functions.php')) { |
| 267 |
updraft_try_include_file('includes/class-filesystem-functions.php', 'require_once'); |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
// Load updraftplus translations |
| 272 |
if (defined('UPDRAFTCENTRAL_CLIENT_DIR') && file_exists(UPDRAFTCENTRAL_CLIENT_DIR.'/translations-central.php')) { |
| 273 |
$this->translations = include_once(UPDRAFTCENTRAL_CLIENT_DIR.'/translations-central.php'); |
| 274 |
} |
| 275 |
} |
| 276 |
} |
| 277 |
|