| Total Complexity | 65 |
| Total Lines | 657 |
| Duplicated Lines | 0 % |
| Changes | 6 | ||
| Bugs | 3 | Features | 0 |
Complex classes like Xcloner often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Xcloner, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 44 | class Xcloner { |
||
| 45 | |||
| 46 | /** |
||
| 47 | * The loader that's responsible for maintaining and registering all hooks that power |
||
| 48 | * the plugin. |
||
| 49 | * |
||
| 50 | * @since 1.0.0 |
||
| 51 | * @access protected |
||
| 52 | * @var Xcloner_Loader $loader Maintains and registers all hooks for the plugin. |
||
| 53 | */ |
||
| 54 | protected $loader; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * The unique identifier of this plugin. |
||
| 58 | * |
||
| 59 | * @since 1.0.0 |
||
| 60 | * @access protected |
||
| 61 | * @var string $plugin_name The string used to uniquely identify this plugin. |
||
| 62 | */ |
||
| 63 | protected $plugin_name; |
||
| 64 | |||
| 65 | protected $plugin_admin; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * The current version of the plugin. |
||
| 69 | * |
||
| 70 | * @since 1.0.0 |
||
| 71 | * @access protected |
||
| 72 | * @var string $version The current version of the plugin. |
||
| 73 | */ |
||
| 74 | protected $version; |
||
| 75 | |||
| 76 | private $xcloner_settings; |
||
| 77 | private $xcloner_logger; |
||
| 78 | private $xcloner_sanitization; |
||
| 79 | private $xcloner_requirements; |
||
| 80 | private $xcloner_filesystem; |
||
| 81 | private $archive_system; |
||
| 82 | private $xcloner_database; |
||
| 83 | private $xcloner_scheduler; |
||
| 84 | private $xcloner_remote_storage; |
||
| 85 | private $xcloner_file_transfer; |
||
| 86 | private $xcloner_encryption; |
||
| 87 | /** |
||
| 88 | * Define the core functionality of the plugin. |
||
| 89 | * |
||
| 90 | * Set the plugin name and the plugin version that can be used throughout the plugin. |
||
| 91 | * Load the dependencies, define the locale, and set the hooks for the admin area and |
||
| 92 | * the public-facing side of the site. |
||
| 93 | * |
||
| 94 | * @since 1.0.0 |
||
| 95 | */ |
||
| 96 | public function init() |
||
| 97 | { |
||
| 98 | register_shutdown_function(array($this, 'exception_handler')); |
||
| 99 | |||
| 100 | $this->plugin_name = 'xcloner'; |
||
| 101 | $this->version = '4.0.4'; |
||
| 102 | |||
| 103 | $this->load_dependencies(); |
||
| 104 | $this->set_locale(); |
||
| 105 | $this->define_admin_hooks(); |
||
| 106 | $this->define_public_hooks(); |
||
| 107 | |||
| 108 | $this->define_admin_menu(); |
||
| 109 | $this->define_plugin_settings(); |
||
| 110 | |||
| 111 | $this->define_ajax_hooks(); |
||
| 112 | $this->define_cron_hooks(); |
||
| 113 | |||
| 114 | } |
||
| 115 | |||
| 116 | public function get_xcloner_settings() |
||
| 117 | { |
||
| 118 | return $this->xcloner_settings; |
||
| 119 | } |
||
| 120 | |||
| 121 | public function get_xcloner_filesystem() |
||
| 122 | { |
||
| 123 | return $this->xcloner_filesystem; |
||
| 124 | } |
||
| 125 | |||
| 126 | public function get_xcloner_logger() |
||
| 127 | { |
||
| 128 | return $this->xcloner_logger; |
||
| 129 | } |
||
| 130 | |||
| 131 | public function get_xcloner_sanitization() |
||
| 132 | { |
||
| 133 | return $this->xcloner_sanitization; |
||
| 134 | } |
||
| 135 | |||
| 136 | public function get_xcloner_requirements() |
||
| 137 | { |
||
| 138 | return $this->xcloner_requirements; |
||
| 139 | } |
||
| 140 | |||
| 141 | public function get_archive_system() |
||
| 142 | { |
||
| 143 | return $this->archive_system; |
||
| 144 | } |
||
| 145 | |||
| 146 | public function get_xcloner_database() |
||
| 147 | { |
||
| 148 | return $this->xcloner_database; |
||
| 149 | } |
||
| 150 | |||
| 151 | public function get_xcloner_scheduler() |
||
| 152 | { |
||
| 153 | return $this->xcloner_scheduler; |
||
| 154 | } |
||
| 155 | |||
| 156 | public function get_xcloner_remote_storage() |
||
| 157 | { |
||
| 158 | return $this->xcloner_remote_storage; |
||
| 159 | } |
||
| 160 | |||
| 161 | public function get_xcloner_file_transfer() |
||
| 162 | { |
||
| 163 | return $this->xcloner_file_transfer; |
||
| 164 | } |
||
| 165 | |||
| 166 | public function get_xcloner_encryption() |
||
| 167 | { |
||
| 168 | return $this->xcloner_encryption; |
||
| 169 | } |
||
| 170 | |||
| 171 | public function check_dependencies() { |
||
| 172 | |||
| 173 | $backup_storage_path = realpath(__DIR__.DS."..".DS."..".DS."..").DS."backups".DS; |
||
| 174 | |||
| 175 | define("XCLONER_STORAGE_PATH", realpath($backup_storage_path)); |
||
| 176 | |||
| 177 | if (!is_dir($backup_storage_path)) |
||
| 178 | { |
||
| 179 | if (!@mkdir($backup_storage_path)) |
||
| 180 | { |
||
| 181 | $status = "error"; |
||
| 182 | $message = sprintf(__("Unable to create the Backup Storage Location Folder %s . Please fix this before starting the backup process."), $backup_storage_path); |
||
|
|
|||
| 183 | $this->trigger_message($message, $status, $backup_storage_path); |
||
| 184 | return; |
||
| 185 | } |
||
| 186 | } |
||
| 187 | if (!is_writable($backup_storage_path)) |
||
| 188 | { |
||
| 189 | $status = "error"; |
||
| 190 | $message = sprintf(__("Unable to write to the Backup Storage Location Folder %s . Please fix this before starting the backup process."), $backup_storage_path); |
||
| 191 | $this->trigger_message($message, $status, $backup_storage_path); |
||
| 192 | |||
| 193 | return; |
||
| 194 | } |
||
| 195 | |||
| 196 | } |
||
| 197 | |||
| 198 | public function trigger_message($message, $status = "error", $message_param1 = "", $message_param2 = "", $message_param3 = "") |
||
| 199 | { |
||
| 200 | $message = sprintf(__($message), $message_param1, $message_param2, $message_param3); |
||
| 201 | add_action('xcloner_admin_notices', array($this, "trigger_message_notice"), 10, 2); |
||
| 202 | do_action('xcloner_admin_notices', $message, $status); |
||
| 203 | } |
||
| 204 | |||
| 205 | public function trigger_message_notice($message, $status = "success") |
||
| 206 | { |
||
| 207 | ?> |
||
| 208 | <div class="notice notice-<?php echo $status?> is-dismissible"> |
||
| 209 | <p><?php _e($message, 'xcloner-backup-and-restore'); ?></p> |
||
| 210 | </div> |
||
| 211 | <?php |
||
| 212 | } |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Load the required dependencies for this plugin. |
||
| 216 | * |
||
| 217 | * Include the following files that make up the plugin: |
||
| 218 | * |
||
| 219 | * - Xcloner_Loader. Orchestrates the hooks of the plugin. |
||
| 220 | * - Xcloner_i18n. Defines internationalization functionality. |
||
| 221 | * - Xcloner_Admin. Defines all hooks for the admin area. |
||
| 222 | * - Xcloner_Public. Defines all hooks for the public side of the site. |
||
| 223 | * |
||
| 224 | * Create an instance of the loader which will be used to register the hooks |
||
| 225 | * with WordPress. |
||
| 226 | * |
||
| 227 | * @since 1.0.0 |
||
| 228 | * @access private |
||
| 229 | */ |
||
| 230 | private function load_dependencies() { |
||
| 231 | |||
| 232 | /** |
||
| 233 | * The class responsible for orchestrating the actions and filters of the |
||
| 234 | * core plugin. |
||
| 235 | */ |
||
| 236 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-loader.php'; |
||
| 237 | |||
| 238 | /** |
||
| 239 | * The class responsible for defining internationalization functionality |
||
| 240 | * of the plugin. |
||
| 241 | */ |
||
| 242 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-i18n.php'; |
||
| 243 | |||
| 244 | /** |
||
| 245 | * The class responsible for defining all actions that occur in the admin area. |
||
| 246 | */ |
||
| 247 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-xcloner-admin.php'; |
||
| 248 | |||
| 249 | /** |
||
| 250 | * The class responsible for debugging XCloner. |
||
| 251 | */ |
||
| 252 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-logger.php'; |
||
| 253 | |||
| 254 | /** |
||
| 255 | * The class responsible for defining the admin settings area. |
||
| 256 | */ |
||
| 257 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-settings.php'; |
||
| 258 | |||
| 259 | /** |
||
| 260 | * The class responsible for defining the Remote Storage settings area. |
||
| 261 | */ |
||
| 262 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-remote-storage.php'; |
||
| 263 | |||
| 264 | /** |
||
| 265 | * The class responsible for implementing the database backup methods. |
||
| 266 | */ |
||
| 267 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-database.php'; |
||
| 268 | |||
| 269 | /** |
||
| 270 | * The class responsible for sanitization of users input. |
||
| 271 | */ |
||
| 272 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-sanitization.php'; |
||
| 273 | |||
| 274 | /** |
||
| 275 | * The class responsible for XCloner system requirements validation. |
||
| 276 | */ |
||
| 277 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-requirements.php'; |
||
| 278 | |||
| 279 | /** |
||
| 280 | * The class responsible for XCloner backup archive creation. |
||
| 281 | */ |
||
| 282 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-archive.php'; |
||
| 283 | |||
| 284 | /** |
||
| 285 | * The class responsible for XCloner API requests. |
||
| 286 | */ |
||
| 287 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-api.php'; |
||
| 288 | |||
| 289 | /** |
||
| 290 | * The class responsible for the XCloner File System methods. |
||
| 291 | */ |
||
| 292 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-file-system.php'; |
||
| 293 | |||
| 294 | /** |
||
| 295 | * The class responsible for the XCloner File Transfer methods. |
||
| 296 | */ |
||
| 297 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-file-transfer.php'; |
||
| 298 | |||
| 299 | /** |
||
| 300 | * The class responsible for the XCloner Scheduler methods. |
||
| 301 | */ |
||
| 302 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-scheduler.php'; |
||
| 303 | |||
| 304 | /** |
||
| 305 | * The class responsible for the XCloner Encryption methods. |
||
| 306 | */ |
||
| 307 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-encryption.php'; |
||
| 308 | |||
| 309 | /** |
||
| 310 | * The class responsible for defining all actions that occur in the public-facing |
||
| 311 | * side of the site. |
||
| 312 | */ |
||
| 313 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-xcloner-public.php'; |
||
| 314 | |||
| 315 | $this->loader = new Xcloner_Loader($this); |
||
| 316 | |||
| 317 | } |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Define the locale for this plugin for internationalization. |
||
| 321 | * |
||
| 322 | * Uses the Xcloner_i18n class in order to set the domain and to register the hook |
||
| 323 | * with WordPress. |
||
| 324 | * |
||
| 325 | * @since 1.0.0 |
||
| 326 | * @access private |
||
| 327 | */ |
||
| 328 | private function set_locale() { |
||
| 329 | |||
| 330 | $plugin_i18n = new Xcloner_i18n(); |
||
| 331 | |||
| 332 | $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain'); |
||
| 333 | |||
| 334 | //wp_localize_script( 'ajax-script', 'my_ajax_object', |
||
| 335 | // array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); |
||
| 336 | |||
| 337 | } |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Register all of the hooks related to the admin area functionality |
||
| 341 | * of the plugin. |
||
| 342 | * |
||
| 343 | * @since 1.0.0 |
||
| 344 | * @access private |
||
| 345 | */ |
||
| 346 | private function define_admin_hooks() { |
||
| 347 | |||
| 348 | $plugin_admin = new Xcloner_Admin($this); |
||
| 349 | $this->plugin_admin = $plugin_admin; |
||
| 350 | |||
| 351 | $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles'); |
||
| 352 | $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts'); |
||
| 353 | |||
| 354 | add_action('backup_archive_finished', array($this, 'do_action_after_backup_finished'), 10, 2); |
||
| 355 | } |
||
| 356 | |||
| 357 | /** |
||
| 358 | * Register the Admin Sidebar menu |
||
| 359 | * |
||
| 360 | * @access private |
||
| 361 | * |
||
| 362 | */ |
||
| 363 | private function define_admin_menu(){ |
||
| 364 | |||
| 365 | add_action('admin_menu', array($this->loader, 'xcloner_backup_add_admin_menu')); |
||
| 366 | |||
| 367 | } |
||
| 368 | |||
| 369 | private function define_plugin_settings(){ |
||
| 370 | /** |
||
| 371 | * register wporg_settings_init to the admin_init action hook |
||
| 372 | */ |
||
| 373 | |||
| 374 | $this->xcloner_settings = new XCloner_Settings($this); |
||
| 375 | |||
| 376 | if(defined('DOING_CRON') || isset($_POST['hash'])){ |
||
| 377 | |||
| 378 | if(defined('DOING_CRON') || $_POST['hash'] == "generate_hash"){ |
||
| 379 | $this->xcloner_settings->generate_new_hash(); |
||
| 380 | }else{ |
||
| 381 | $this->xcloner_settings->set_hash($_POST['hash']); |
||
| 382 | } |
||
| 383 | } |
||
| 384 | |||
| 385 | if(defined('DOING_CRON') || !isset($_POST['hash'])) |
||
| 386 | { |
||
| 387 | add_action( 'shutdown', function(){ |
||
| 388 | $this->xcloner_filesystem = new Xcloner_File_System($this); |
||
| 389 | $this->xcloner_filesystem->remove_tmp_filesystem(); |
||
| 390 | }); |
||
| 391 | } |
||
| 392 | |||
| 393 | $this->xcloner_sanitization = new Xcloner_Sanitization(); |
||
| 394 | $this->xcloner_requirements = new Xcloner_Requirements($this); |
||
| 395 | |||
| 396 | add_action('admin_init', array($this->xcloner_settings, 'settings_init')); |
||
| 397 | |||
| 398 | //adding links to the Manage Plugins Wordpress page for XCloner |
||
| 399 | add_filter('plugin_action_links', array($this, 'add_plugin_action_links'), 10, 2); |
||
| 400 | |||
| 401 | |||
| 402 | |||
| 403 | } |
||
| 404 | |||
| 405 | /* |
||
| 406 | * type = core|plugin|theme|translation |
||
| 407 | */ |
||
| 408 | public function pre_auto_update($type, $item, $context) |
||
| 409 | { |
||
| 410 | if (!$type) |
||
| 411 | { |
||
| 412 | return false; |
||
| 413 | } |
||
| 414 | |||
| 415 | $this->get_xcloner_logger()->info(sprintf("Doing automatic backup before %s upgrade, pre_auto_update hook.", $type)); |
||
| 416 | |||
| 417 | $content_dir = str_replace(ABSPATH, "", WP_CONTENT_DIR); |
||
| 418 | $plugins_dir = str_replace(ABSPATH, "", WP_PLUGIN_DIR); |
||
| 419 | $langs_dir = $content_dir.DS."languages"; |
||
| 420 | $themes_dir = $content_dir.DS."themes"; |
||
| 421 | |||
| 422 | switch ($type) { |
||
| 423 | case 'core': |
||
| 424 | $exclude_files = array( |
||
| 425 | "^(?!(wp-admin|wp-includes|(?!.*\/.*.php)))(.*)$", |
||
| 426 | ); |
||
| 427 | break; |
||
| 428 | case 'plugin': |
||
| 429 | |||
| 430 | $dir_array = explode(DS, $plugins_dir); |
||
| 431 | |||
| 432 | foreach ($dir_array as $dir) |
||
| 433 | { |
||
| 434 | $data .= "\/".$dir; |
||
| 435 | $regex .= $data."$|"; |
||
| 436 | } |
||
| 437 | |||
| 438 | $regex .= "\/".implode("\/", $dir_array); |
||
| 439 | |||
| 440 | $exclude_files = array( |
||
| 441 | "^(?!(".$regex."))(.*)$", |
||
| 442 | ); |
||
| 443 | break; |
||
| 444 | case 'theme': |
||
| 445 | |||
| 446 | $dir_array = explode(DS, $themes_dir); |
||
| 447 | |||
| 448 | foreach ($dir_array as $dir) |
||
| 449 | { |
||
| 450 | $data .= "\/".$dir; |
||
| 451 | $regex .= $data."$|"; |
||
| 452 | } |
||
| 453 | |||
| 454 | $regex .= "\/".implode("\/", $dir_array); |
||
| 455 | |||
| 456 | $exclude_files = array( |
||
| 457 | "^(?!(".$regex."))(.*)$", |
||
| 458 | ); |
||
| 459 | break; |
||
| 460 | case 'translation': |
||
| 461 | |||
| 462 | $dir_array = explode(DS, $langs_dir); |
||
| 463 | |||
| 464 | foreach ($dir_array as $dir) |
||
| 465 | { |
||
| 466 | $data .= "\/".$dir; |
||
| 467 | $regex .= $data."$|"; |
||
| 468 | } |
||
| 469 | |||
| 470 | $regex .= "\/".implode("\/", $dir_array); |
||
| 471 | |||
| 472 | $exclude_files = array( |
||
| 473 | "^(?!(".$regex."))(.*)$", |
||
| 474 | ); |
||
| 475 | break; |
||
| 476 | } |
||
| 477 | |||
| 478 | $schedule = array(); |
||
| 479 | |||
| 480 | $schedule['id'] = 0; |
||
| 481 | $schedule['name'] = "pre_auto_update"; |
||
| 482 | $schedule['recurrence'] = "single"; |
||
| 483 | $schedule['excluded_files'] = json_encode($exclude_files); |
||
| 484 | $schedule['table_params'] = json_encode(array("#" => array($this->get_xcloner_settings()->get_db_database()))); |
||
| 485 | |||
| 486 | $schedule['backup_params'] = new stdClass(); |
||
| 487 | $schedule['backup_params']->email_notification = get_option('admin_email'); |
||
| 488 | $schedule['backup_params']->backup_name = "backup_pre_auto_update_".$type."_[domain]-[time]-sql"; |
||
| 489 | |||
| 490 | try { |
||
| 491 | $this->xcloner_scheduler->xcloner_scheduler_callback(0, $schedule); |
||
| 492 | }catch (Exception $e) { |
||
| 493 | $this->get_xcloner_logger()->error($e->getMessage()); |
||
| 494 | } |
||
| 495 | |||
| 496 | } |
||
| 497 | |||
| 498 | /** |
||
| 499 | * Register all of the hooks related to the public-facing functionality |
||
| 500 | * of the plugin. |
||
| 501 | * |
||
| 502 | * @since 1.0.0 |
||
| 503 | * @access private |
||
| 504 | */ |
||
| 505 | private function define_public_hooks() { |
||
| 506 | |||
| 507 | $plugin_public = new Xcloner_Public($this); |
||
| 508 | |||
| 509 | $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles'); |
||
| 510 | $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts'); |
||
| 511 | |||
| 512 | } |
||
| 513 | |||
| 514 | public function exception_handler() { |
||
| 515 | |||
| 516 | $logger = new XCloner_Logger($this, "php_system"); |
||
| 517 | $error = error_get_last(); |
||
| 518 | |||
| 519 | if($error['type'] and $logger) |
||
| 520 | { |
||
| 521 | $logger->info($this->friendly_error_type ($error['type']).": ".var_export($error, true)); |
||
| 522 | } |
||
| 523 | |||
| 524 | } |
||
| 525 | |||
| 526 | function friendly_error_type($type) { |
||
| 527 | static $levels=null; |
||
| 528 | if ($levels===null) { |
||
| 529 | $levels=[]; |
||
| 530 | foreach (get_defined_constants() as $key=>$value) { |
||
| 531 | if (strpos($key,'E_')!==0) {continue;} |
||
| 532 | $levels[$value]= $key; //substr($key,2); |
||
| 533 | } |
||
| 534 | } |
||
| 535 | return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}"); |
||
| 536 | } |
||
| 537 | |||
| 538 | private function define_ajax_hooks() |
||
| 539 | { |
||
| 540 | //adding the pre-update hook |
||
| 541 | |||
| 542 | if(is_admin() || defined('DOING_CRON')) |
||
| 543 | { |
||
| 544 | $this->xcloner_logger = new XCloner_Logger($this, "xcloner_api"); |
||
| 545 | $this->xcloner_filesystem = new Xcloner_File_System($this); |
||
| 546 | |||
| 547 | //$this->xcloner_filesystem->set_diff_timestamp_start (strtotime("-15 days")); |
||
| 548 | |||
| 549 | $this->archive_system = new Xcloner_Archive($this); |
||
| 550 | $this->xcloner_database = new Xcloner_Database($this); |
||
| 551 | $this->xcloner_scheduler = new Xcloner_Scheduler($this); |
||
| 552 | $this->xcloner_remote_storage = new Xcloner_Remote_Storage($this); |
||
| 553 | $this->xcloner_file_transfer = new Xcloner_File_Transfer($this); |
||
| 554 | $this->xcloner_encryption = new Xcloner_Encryption($this); |
||
| 555 | |||
| 556 | $xcloner_api = new Xcloner_Api($this); |
||
| 557 | |||
| 558 | add_action( 'wp_ajax_get_database_tables_action', array($xcloner_api,'get_database_tables_action') ); |
||
| 559 | add_action( 'wp_ajax_get_file_system_action', array($xcloner_api,'get_file_system_action') ); |
||
| 560 | add_action( 'wp_ajax_scan_filesystem', array($xcloner_api,'scan_filesystem') ); |
||
| 561 | add_action( 'wp_ajax_backup_database', array($xcloner_api,'backup_database') ); |
||
| 562 | add_action( 'wp_ajax_backup_files' , array($xcloner_api,'backup_files') ); |
||
| 563 | add_action( 'wp_ajax_save_schedule' , array($xcloner_api,'save_schedule') ); |
||
| 564 | add_action( 'wp_ajax_get_schedule_by_id', array($xcloner_api,'get_schedule_by_id') ); |
||
| 565 | add_action( 'wp_ajax_get_scheduler_list', array($xcloner_api,'get_scheduler_list') ); |
||
| 566 | add_action( 'wp_ajax_delete_schedule_by_id' , array($xcloner_api,'delete_schedule_by_id') ); |
||
| 567 | add_action( 'wp_ajax_delete_backup_by_name' , array($xcloner_api,'delete_backup_by_name') ); |
||
| 568 | add_action( 'wp_ajax_download_backup_by_name', array($xcloner_api,'download_backup_by_name') ); |
||
| 569 | add_action( 'wp_ajax_remote_storage_save_status', array($xcloner_api,'remote_storage_save_status') ); |
||
| 570 | add_action( 'wp_ajax_upload_backup_to_remote', array($xcloner_api,'upload_backup_to_remote') ); |
||
| 571 | add_action( 'wp_ajax_list_backup_files' , array($xcloner_api,'list_backup_files') ); |
||
| 572 | add_action( 'wp_ajax_restore_upload_backup' , array($xcloner_api,'restore_upload_backup') ); |
||
| 573 | add_action( 'wp_ajax_download_restore_script', array($xcloner_api,'download_restore_script') ); |
||
| 574 | add_action( 'wp_ajax_copy_backup_remote_to_local', array($xcloner_api,'copy_backup_remote_to_local') ); |
||
| 575 | add_action( 'wp_ajax_restore_backup', array($xcloner_api,'restore_backup') ); |
||
| 576 | add_action( 'wp_ajax_backup_encryption', array($xcloner_api,'backup_encryption') ); |
||
| 577 | add_action( 'wp_ajax_backup_decryption', array($xcloner_api,'backup_decryption') ); |
||
| 578 | add_action( 'wp_ajax_get_manage_backups_list', array($xcloner_api,'get_manage_backups_list') ); |
||
| 579 | add_action( 'admin_notices', array($this, 'xcloner_error_admin_notices' )); |
||
| 580 | |||
| 581 | } |
||
| 582 | |||
| 583 | //Do a pre-update backup of targeted files |
||
| 584 | if($this->get_xcloner_settings()->get_xcloner_option('xcloner_enable_pre_update_backup')) |
||
| 585 | { |
||
| 586 | add_action("pre_auto_update", array($this, "pre_auto_update"), 1, 3); |
||
| 587 | } |
||
| 588 | } |
||
| 589 | |||
| 590 | function add_plugin_action_links($links, $file) { |
||
| 591 | if ($file == plugin_basename(dirname(dirname(__FILE__)) . '/xcloner.php')) |
||
| 592 | { |
||
| 593 | $links[] = '<a href="admin.php?page=xcloner_settings_page">'.__('Settings', 'xcloner-backup-and-restore').'</a>'; |
||
| 594 | $links[] = '<a href="admin.php?page=xcloner_generate_backups_page">'.__('Generate Backup', 'xcloner-backup-and-restore').'</a>'; |
||
| 595 | } |
||
| 596 | |||
| 597 | return $links; |
||
| 598 | } |
||
| 599 | |||
| 600 | public function xcloner_error_admin_notices() { |
||
| 601 | settings_errors('xcloner_error_message'); |
||
| 602 | } |
||
| 603 | |||
| 604 | public function define_cron_hooks() |
||
| 605 | { |
||
| 606 | //registering new schedule intervals |
||
| 607 | add_filter('cron_schedules', array($this, 'add_new_intervals')); |
||
| 608 | |||
| 609 | |||
| 610 | $xcloner_scheduler = $this->get_xcloner_scheduler(); |
||
| 611 | $xcloner_scheduler->update_wp_cron_hooks(); |
||
| 612 | |||
| 613 | } |
||
| 614 | |||
| 615 | function add_new_intervals($schedules) |
||
| 616 | { |
||
| 617 | //weekly scheduler interval |
||
| 618 | $schedules['weekly'] = array( |
||
| 619 | 'interval' => 604800, |
||
| 620 | 'display' => __('Once Weekly', 'xcloner-backup-and-restore') |
||
| 621 | ); |
||
| 622 | |||
| 623 | //monthly scheduler interval |
||
| 624 | $schedules['monthly'] = array( |
||
| 625 | 'interval' => 2635200, |
||
| 626 | 'display' => __('Once Monthly', 'xcloner-backup-and-restore') |
||
| 627 | ); |
||
| 628 | |||
| 629 | //monthly scheduler interval |
||
| 630 | $schedules['twicedaily'] = array( |
||
| 631 | 'interval' => 43200, |
||
| 632 | 'display' => __('Twice Daily', 'xcloner-backup-and-restore') |
||
| 633 | ); |
||
| 634 | |||
| 635 | return $schedules; |
||
| 636 | } |
||
| 637 | |||
| 638 | |||
| 639 | /** |
||
| 640 | * Run the loader to execute all of the hooks with WordPress. |
||
| 641 | * |
||
| 642 | * @since 1.0.0 |
||
| 643 | */ |
||
| 644 | public function run() { |
||
| 645 | $this->loader->run(); |
||
| 646 | } |
||
| 647 | |||
| 648 | /** |
||
| 649 | * The name of the plugin used to uniquely identify it within the context of |
||
| 650 | * WordPress and to define internationalization functionality. |
||
| 651 | * |
||
| 652 | * @since 1.0.0 |
||
| 653 | * @return string The name of the plugin. |
||
| 654 | */ |
||
| 655 | public function get_plugin_name() { |
||
| 656 | return $this->plugin_name; |
||
| 657 | } |
||
| 658 | |||
| 659 | /** |
||
| 660 | * The reference to the class that orchestrates the hooks with the plugin. |
||
| 661 | * |
||
| 662 | * @since 1.0.0 |
||
| 663 | * @return Xcloner_Loader Orchestrates the hooks of the plugin. |
||
| 664 | */ |
||
| 665 | public function get_loader() { |
||
| 666 | return $this->loader; |
||
| 667 | } |
||
| 668 | |||
| 669 | /** |
||
| 670 | * Retrieve the version number of the plugin. |
||
| 671 | * |
||
| 672 | * @since 1.0.0 |
||
| 673 | * @return string The version number of the plugin. |
||
| 674 | */ |
||
| 675 | public function get_version() { |
||
| 676 | return $this->version; |
||
| 677 | } |
||
| 678 | |||
| 679 | function xcloner_display() |
||
| 680 | { |
||
| 681 | // check user capabilities |
||
| 682 | if (!current_user_can('manage_options')) { |
||
| 683 | return; |
||
| 684 | } |
||
| 685 | |||
| 686 | $page = sanitize_key($_GET['page']); |
||
| 687 | |||
| 688 | if ($page) |
||
| 689 | { |
||
| 690 | $this->display($page); |
||
| 691 | } |
||
| 692 | |||
| 693 | } |
||
| 694 | |||
| 695 | public function display($page) |
||
| 701 | } |
||
| 702 | } |
||
| 703 |